Changeset e7f6389 in mainline
- Timestamp:
- 2010-10-26T22:45:19Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f2d2c604
- Parents:
- e503d3a9 (diff), 3cd95ef (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/srv/net
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/netif/lo/lo.c
re503d3a9 re7f6389 28 28 29 29 /** @addtogroup lo 30 * 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 34 * Loopback network interface implementation. 35 35 */ 36 36 … … 53 53 #include <netif_local.h> 54 54 55 /** Default hardware address. 56 */ 55 /** Default hardware address. */ 57 56 #define DEFAULT_ADDR "\0\0\0\0\0\0" 58 57 59 /** Default address length. 60 */ 58 /** Default address length. */ 61 59 #define DEFAULT_ADDR_LEN (sizeof(DEFAULT_ADDR) / sizeof(char)) 62 60 63 /** Loopback module name. 64 */ 61 /** Loopback module name. */ 65 62 #define NAME "lo" 66 63 67 /** Network interface global data. 68 */ 64 /** Network interface global data. */ 69 65 netif_globals_t netif_globals; 70 66 71 /** Changes the loopback state. 72 * @param[in] device The device structure. 73 * @param[in] state The new device state. 74 * @returns The new state if changed. 75 * @returns EOK otherwise. 76 */ 77 int change_state_message(netif_device_t * device, device_state_t state); 78 79 /** Creates and returns the loopback network interface structure. 80 * @param[in] device_id The new devce identifier. 81 * @param[out] device The device structure. 82 * @returns EOK on success. 83 * @returns EXDEV if one loopback network interface already exists. 84 * @returns ENOMEM if there is not enough memory left. 85 */ 86 int create(device_id_t device_id, netif_device_t * * device); 87 88 int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 67 int 68 netif_specific_message(ipc_callid_t callid, ipc_call_t *call, 69 ipc_call_t *answer, int *answer_count) 70 { 89 71 return ENOTSUP; 90 72 } 91 73 92 int netif_get_addr_message(device_id_t device_id, measured_string_ref address){ 93 if(! address){ 74 int netif_get_addr_message(device_id_t device_id, measured_string_ref address) 75 { 76 if (!address) 94 77 return EBADMEM; 95 }96 78 address->value = str_dup(DEFAULT_ADDR); 97 79 address->length = DEFAULT_ADDR_LEN; … … 99 81 } 100 82 101 int netif_get_device_stats(device_id_t device_id, device_stats_ref stats){ 102 ERROR_DECLARE; 103 104 netif_device_t * device; 105 106 if(! stats){ 83 int netif_get_device_stats(device_id_t device_id, device_stats_ref stats) 84 { 85 ERROR_DECLARE; 86 87 netif_device_t *device; 88 89 if (!stats) 107 90 return EBADMEM; 108 }109 91 ERROR_PROPAGATE(find_device(device_id, &device)); 110 memcpy(stats, (device_stats_ref) device->specific, sizeof(device_stats_t)); 111 return EOK; 112 } 113 114 int change_state_message(netif_device_t * device, device_state_t state) 92 memcpy(stats, (device_stats_ref) device->specific, 93 sizeof(device_stats_t)); 94 return EOK; 95 } 96 97 /** Changes the loopback state. 98 * 99 * @param[in] device The device structure. 100 * @param[in] state The new device state. 101 * @returns The new state if changed. 102 * @returns EOK otherwise. 103 */ 104 static int change_state_message(netif_device_t *device, device_state_t state) 115 105 { 116 106 if (device->state != state) { … … 126 116 } 127 117 128 int create(device_id_t device_id, netif_device_t * * device){ 118 /** Creates and returns the loopback network interface structure. 119 * 120 * @param[in] device_id The new devce identifier. 121 * @param[out] device The device structure. 122 * @returns EOK on success. 123 * @returns EXDEV if one loopback network interface already exists. 124 * @returns ENOMEM if there is not enough memory left. 125 */ 126 static int create(device_id_t device_id, netif_device_t **device) 127 { 129 128 int index; 130 129 131 if (netif_device_map_count(&netif_globals.device_map) > 0){130 if (netif_device_map_count(&netif_globals.device_map) > 0) 132 131 return EXDEV; 133 }else{ 134 *device = (netif_device_t *) malloc(sizeof(netif_device_t)); 135 if(!(*device)){ 136 return ENOMEM; 137 } 138 (** device).specific = malloc(sizeof(device_stats_t)); 139 if(! (** device).specific){ 140 free(*device); 141 return ENOMEM; 142 } 143 null_device_stats((device_stats_ref)(** device).specific); 144 (** device).device_id = device_id; 145 (** device).nil_phone = -1; 146 (** device).state = NETIF_STOPPED; 147 index = netif_device_map_add(&netif_globals.device_map, (** device).device_id, * device); 148 if(index < 0){ 149 free(*device); 150 free((** device).specific); 151 *device = NULL; 152 return index; 153 } 154 } 155 return EOK; 156 } 157 158 int netif_initialize(void){ 132 133 *device = (netif_device_t *) malloc(sizeof(netif_device_t)); 134 if (!*device) 135 return ENOMEM; 136 (*device)->specific = (device_stats_t *) malloc(sizeof(device_stats_t)); 137 if (!(*device)->specific) { 138 free(*device); 139 return ENOMEM; 140 } 141 null_device_stats((device_stats_ref) (*device)->specific); 142 (*device)->device_id = device_id; 143 (*device)->nil_phone = -1; 144 (*device)->state = NETIF_STOPPED; 145 index = netif_device_map_add(&netif_globals.device_map, 146 (*device)->device_id, *device); 147 if (index < 0) { 148 free(*device); 149 free((*device)->specific); 150 *device = NULL; 151 return index; 152 } 153 154 return EOK; 155 } 156 157 int netif_initialize(void) 158 { 159 159 ipcarg_t phonehash; 160 160 … … 162 162 } 163 163 164 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io){ 165 ERROR_DECLARE; 166 167 netif_device_t * device; 164 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io) 165 { 166 ERROR_DECLARE; 167 168 netif_device_t *device; 168 169 169 170 // create a new device … … 174 175 } 175 176 176 int netif_send_message(device_id_t device_id, packet_t packet, services_t sender){ 177 ERROR_DECLARE; 178 179 netif_device_t * device; 177 int netif_send_message(device_id_t device_id, packet_t packet, services_t sender) 178 { 179 ERROR_DECLARE; 180 181 netif_device_t *device; 180 182 size_t length; 181 183 packet_t next; … … 183 185 184 186 ERROR_PROPAGATE(find_device(device_id, &device)); 185 if (device->state != NETIF_ACTIVE){187 if (device->state != NETIF_ACTIVE) { 186 188 netif_pq_release(packet_get_id(packet)); 187 189 return EFORWARD; 188 190 } 189 191 next = packet; 190 do {191 ++ ((device_stats_ref) device->specific)->send_packets;192 ++ ((device_stats_ref) device->specific)->receive_packets;192 do { 193 ((device_stats_ref) device->specific)->send_packets++; 194 ((device_stats_ref) device->specific)->receive_packets++; 193 195 length = packet_get_data_length(next); 194 196 ((device_stats_ref) device->specific)->send_bytes += length; 195 197 ((device_stats_ref) device->specific)->receive_bytes += length; 196 198 next = pq_next(next); 197 } while(next);199 } while(next); 198 200 phone = device->nil_phone; 199 201 fibril_rwlock_write_unlock(&netif_globals.lock); 200 202 nil_received_msg(phone, device_id, packet, sender); 201 203 fibril_rwlock_write_lock(&netif_globals.lock); 202 return EOK; 203 } 204 205 int netif_start_message(netif_device_t * device){ 204 205 return EOK; 206 } 207 208 int netif_start_message(netif_device_t *device) 209 { 206 210 return change_state_message(device, NETIF_ACTIVE); 207 211 } 208 212 209 int netif_stop_message(netif_device_t * device){ 213 int netif_stop_message(netif_device_t *device) 214 { 210 215 return change_state_message(device, NETIF_STOPPED); 211 216 } … … 213 218 /** Default thread for new connections. 214 219 * 215 * @param[in] iid The initial message identifier. 216 * @param[in] icall The initial message call structure. 217 * 220 * @param[in] iid The initial message identifier. 221 * @param[in] icall The initial message call structure. 218 222 */ 219 223 static void netif_client_connection(ipc_callid_t iid, ipc_call_t *icall) … … 225 229 ipc_answer_0(iid, EOK); 226 230 227 while (true) {231 while (true) { 228 232 ipc_call_t answer; 229 233 int answer_count; … … 240 244 &answer_count); 241 245 242 /* End if said to either by the message or the processing result */ 243 if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP)) 246 /* 247 * End if told to either by the message or the processing 248 * result. 249 */ 250 if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || 251 (res == EHANGUP)) 244 252 return; 245 253 … … 254 262 255 263 /* Start the module */ 256 if (ERROR_OCCURRED(netif_module_start(netif_client_connection))) 257 return ERROR_CODE; 258 264 ERROR_PROPAGATE(netif_module_start(netif_client_connection)); 259 265 return EOK; 260 266 } -
uspace/srv/net/nil/nildummy/nildummy.c
re503d3a9 re7f6389 58 58 #include "nildummy.h" 59 59 60 /** The module name. 61 * 62 */ 60 /** The module name. */ 63 61 #define NAME "nildummy" 64 62 65 /** Default maximum transmission unit. 66 * 67 */ 63 /** Default maximum transmission unit. */ 68 64 #define NET_DEFAULT_MTU 1500 69 65 70 /** Network interface layer module global data. 71 * 72 */ 66 /** Network interface layer module global data. */ 73 67 nildummy_globals_t nildummy_globals; 74 68 … … 78 72 { 79 73 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); 80 81 74 if (nildummy_globals.proto.phone) 82 il_device_state_msg(nildummy_globals.proto.phone, device_id, state, 83 nildummy_globals.proto.service); 84 75 il_device_state_msg(nildummy_globals.proto.phone, device_id, 76 state, nildummy_globals.proto.service); 85 77 fibril_rwlock_read_unlock(&nildummy_globals.protos_lock); 86 78 … … 99 91 nildummy_globals.net_phone = net_phone; 100 92 nildummy_globals.proto.phone = 0; 101 ERROR_ PROPAGATE(nildummy_devices_initialize(&nildummy_globals.devices));93 ERROR_CODE = nildummy_devices_initialize(&nildummy_globals.devices); 102 94 103 95 fibril_rwlock_write_unlock(&nildummy_globals.protos_lock); 104 96 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 105 97 106 return EOK; 107 } 108 109 /** Process IPC messages from the registered device driver modules in an infinite loop. 110 * 111 * @param[in] iid The message identifier. 112 * @param[in,out] icall The message parameters. 113 * 114 */ 115 static void nildummy_receiver(ipc_callid_t iid, ipc_call_t * icall){ 98 return ERROR_CODE; 99 } 100 101 /** Process IPC messages from the registered device driver modules in an 102 * infinite loop. 103 * 104 * @param[in] iid The message identifier. 105 * @param[in,out] icall The message parameters. 106 */ 107 static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall) 108 { 116 109 ERROR_DECLARE; 117 110 118 111 packet_t packet; 119 112 120 while(true){ 121 switch(IPC_GET_METHOD(*icall)){ 122 case NET_NIL_DEVICE_STATE: 123 ERROR_CODE = nil_device_state_msg_local(0, IPC_GET_DEVICE(icall), IPC_GET_STATE(icall)); 124 ipc_answer_0(iid, (ipcarg_t) ERROR_CODE); 125 break; 126 case NET_NIL_RECEIVED: 127 if(! ERROR_OCCURRED(packet_translate_remote(nildummy_globals.net_phone, &packet, IPC_GET_PACKET(icall)))){ 128 ERROR_CODE = nil_received_msg_local(0, IPC_GET_DEVICE(icall), packet, 0); 129 } 130 ipc_answer_0(iid, (ipcarg_t) ERROR_CODE); 131 break; 132 default: 133 ipc_answer_0(iid, (ipcarg_t) ENOTSUP); 113 while (true) { 114 switch (IPC_GET_METHOD(*icall)) { 115 case NET_NIL_DEVICE_STATE: 116 ERROR_CODE = nil_device_state_msg_local(0, 117 IPC_GET_DEVICE(icall), IPC_GET_STATE(icall)); 118 ipc_answer_0(iid, (ipcarg_t) ERROR_CODE); 119 break; 120 121 case NET_NIL_RECEIVED: 122 if (ERROR_NONE(packet_translate_remote( 123 nildummy_globals.net_phone, &packet, 124 IPC_GET_PACKET(icall)))) { 125 ERROR_CODE = nil_received_msg_local(0, 126 IPC_GET_DEVICE(icall), packet, 0); 127 } 128 ipc_answer_0(iid, (ipcarg_t) ERROR_CODE); 129 break; 130 131 default: 132 ipc_answer_0(iid, (ipcarg_t) ENOTSUP); 134 133 } 134 135 135 iid = async_get_call(icall); 136 136 } … … 141 141 * Determine the device local hardware address. 142 142 * 143 * @param[in] device_id 144 * @param[in] service 145 * @param[in] mtu 146 * 147 * @returns EOK on success.148 * @returns EEXIST if the device with the different service exists.149 * @returns ENOMEM if there is not enough memory left.150 * @returns Other error codes as defined for thenetif_bind_service() function.151 * @returns Other error codes as defined for the netif_get_addr_req() function.152 * 153 */ 154 static int nildummy_device_message(device_id_t device_id, services_t service,155 143 * @param[in] device_id The new device identifier. 144 * @param[in] service The device driver service. 145 * @param[in] mtu The device maximum transmission unit. 146 * @returns EOK on success. 147 * @returns EEXIST if the device with the different service exists. 148 * @returns ENOMEM if there is not enough memory left. 149 * @returns Other error codes as defined for the 150 * netif_bind_service() function. 151 * @returns Other error codes as defined for the 152 * netif_get_addr_req() function. 153 */ 154 static int 155 nildummy_device_message(device_id_t device_id, services_t service, size_t mtu) 156 156 { 157 157 ERROR_DECLARE; … … 161 161 162 162 fibril_rwlock_write_lock(&nildummy_globals.devices_lock); 163 163 164 // an existing device? 164 165 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 165 if (device){166 if (device->service != service){166 if (device) { 167 if (device->service != service) { 167 168 printf("Device %d already exists\n", device->device_id); 168 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 169 fibril_rwlock_write_unlock( 170 &nildummy_globals.devices_lock); 169 171 return EEXIST; 170 }else{171 // update mtu172 if(mtu > 0){173 device->mtu = mtu;174 }else{175 device->mtu = NET_DEFAULT_MTU;176 }177 printf("Device %d already exists:\tMTU\t= %d\n", device->device_id, device->mtu);178 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);179 // notify the upper layer module180 fibril_rwlock_read_lock(&nildummy_globals.protos_lock);181 if(nildummy_globals.proto.phone){182 il_mtu_changed_msg(nildummy_globals.proto.phone, device->device_id, device->mtu, nildummy_globals.proto.service);183 }184 fibril_rwlock_read_unlock(&nildummy_globals.protos_lock);185 return EOK;186 172 } 187 }else{ 188 // create a new device 189 device = (nildummy_device_ref) malloc(sizeof(nildummy_device_t)); 190 if(! device){ 191 return ENOMEM; 173 174 // update mtu 175 if (mtu > 0) 176 device->mtu = mtu; 177 else 178 device->mtu = NET_DEFAULT_MTU; 179 180 printf("Device %d already exists:\tMTU\t= %d\n", 181 device->device_id, device->mtu); 182 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 183 184 // notify the upper layer module 185 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); 186 if (nildummy_globals.proto.phone) { 187 il_mtu_changed_msg(nildummy_globals.proto.phone, 188 device->device_id, device->mtu, 189 nildummy_globals.proto.service); 192 190 } 193 device->device_id = device_id; 194 device->service = service; 195 if(mtu > 0){ 196 device->mtu = mtu; 197 }else{ 198 device->mtu = NET_DEFAULT_MTU; 199 } 200 // bind the device driver 201 device->phone = netif_bind_service(device->service, device->device_id, SERVICE_ETHERNET, nildummy_receiver); 202 if(device->phone < 0){ 203 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 204 free(device); 205 return device->phone; 206 } 207 // get hardware address 208 if(ERROR_OCCURRED(netif_get_addr_req(device->phone, device->device_id, &device->addr, &device->addr_data))){ 209 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 210 free(device); 211 return ERROR_CODE; 212 } 213 // add to the cache 214 index = nildummy_devices_add(&nildummy_globals.devices, device->device_id, device); 215 if(index < 0){ 216 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 217 free(device->addr); 218 free(device->addr_data); 219 free(device); 220 return index; 221 } 222 printf("%s: Device registered (id: %d, service: %d, mtu: %d)\n", 223 NAME, device->device_id, device->service, device->mtu); 224 } 191 fibril_rwlock_read_unlock(&nildummy_globals.protos_lock); 192 193 return EOK; 194 } 195 196 // create a new device 197 device = (nildummy_device_ref) malloc(sizeof(nildummy_device_t)); 198 if (!device) 199 return ENOMEM; 200 201 device->device_id = device_id; 202 device->service = service; 203 if (mtu > 0) 204 device->mtu = mtu; 205 else 206 device->mtu = NET_DEFAULT_MTU; 207 208 // bind the device driver 209 device->phone = netif_bind_service(device->service, device->device_id, 210 SERVICE_ETHERNET, nildummy_receiver); 211 if (device->phone < 0) { 212 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 213 free(device); 214 return device->phone; 215 } 216 217 // get hardware address 218 if (ERROR_OCCURRED(netif_get_addr_req(device->phone, device->device_id, 219 &device->addr, &device->addr_data))) { 220 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 221 free(device); 222 return ERROR_CODE; 223 } 224 225 // add to the cache 226 index = nildummy_devices_add(&nildummy_globals.devices, 227 device->device_id, device); 228 if (index < 0) { 229 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 230 free(device->addr); 231 free(device->addr_data); 232 free(device); 233 return index; 234 } 235 236 printf("%s: Device registered (id: %d, service: %d, mtu: %d)\n", 237 NAME, device->device_id, device->service, device->mtu); 225 238 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 226 239 return EOK; … … 229 242 /** Return the device hardware address. 230 243 * 231 * @param[in] device_id The device identifier. 232 * @param[out] address The device hardware address. 233 * 234 * @return EOK on success. 235 * @return EBADMEM if the address parameter is NULL. 236 * @return ENOENT if there no such device. 237 * 238 */ 239 static int nildummy_addr_message(device_id_t device_id, 240 measured_string_ref *address) 244 * @param[in] device_id The device identifier. 245 * @param[out] address The device hardware address. 246 * @return EOK on success. 247 * @return EBADMEM if the address parameter is NULL. 248 * @return ENOENT if there no such device. 249 * 250 */ 251 static int 252 nildummy_addr_message(device_id_t device_id, measured_string_ref *address) 241 253 { 242 254 nildummy_device_ref device; 243 255 244 if (! address){256 if (!address) 245 257 return EBADMEM; 246 }258 247 259 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 248 260 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 249 if (! device){261 if (!device) { 250 262 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 251 263 return ENOENT; … … 253 265 *address = device->addr; 254 266 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 267 255 268 return (*address) ? EOK : ENOENT; 256 269 } … … 258 271 /** Return the device packet dimensions for sending. 259 272 * 260 * @param[in] device_idThe device identifier.261 * @param[out] addr_len 262 * @param[out] prefix 263 * @param[out] content 264 * @param[out] suffix 265 * 266 * @return EOK on success.267 * @return EBADMEM if either one of the parameters is NULL.268 * @return ENOENT if there is no such device.269 * 270 */ 271 static int nildummy_packet_space_message(device_id_t device_id,272 size_t * addr_len, size_t *prefix, size_t *content, size_t *suffix)273 * @param[in] device_id The device identifier. 274 * @param[out] addr_len The minimum reserved address length. 275 * @param[out] prefix The minimum reserved prefix size. 276 * @param[out] content The maximum content size. 277 * @param[out] suffix The minimum reserved suffix size. 278 * @return EOK on success. 279 * @return EBADMEM if either one of the parameters is NULL. 280 * @return ENOENT if there is no such device. 281 * 282 */ 283 static int 284 nildummy_packet_space_message(device_id_t device_id, size_t *addr_len, 285 size_t *prefix, size_t *content, size_t *suffix) 273 286 { 274 287 nildummy_device_ref device; 275 288 276 if (!(addr_len && prefix && content && suffix)){289 if (!addr_len || !prefix || !content || !suffix) 277 290 return EBADMEM; 278 }291 279 292 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 280 293 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 281 if (! device){294 if (!device) { 282 295 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 283 296 return ENOENT; … … 285 298 *content = device->mtu; 286 299 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 300 287 301 *addr_len = 0; 288 302 *prefix = 0; … … 291 305 } 292 306 293 int nil_received_msg_local(int nil_phone, device_id_t device_id, packet_t packet, services_t target){ 307 int 308 nil_received_msg_local(int nil_phone, device_id_t device_id, packet_t packet, 309 services_t target) 310 { 294 311 packet_t next; 295 312 296 313 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); 297 if (nildummy_globals.proto.phone){298 do {314 if (nildummy_globals.proto.phone) { 315 do { 299 316 next = pq_detach(packet); 300 il_received_msg(nildummy_globals.proto.phone, device_id, packet, nildummy_globals.proto.service); 317 il_received_msg(nildummy_globals.proto.phone, device_id, 318 packet, nildummy_globals.proto.service); 301 319 packet = next; 302 } while(packet);320 } while(packet); 303 321 } 304 322 fibril_rwlock_read_unlock(&nildummy_globals.protos_lock); 323 305 324 return EOK; 306 325 } … … 310 329 * Pass received packets for this service. 311 330 * 312 * @param[in] service The module service. 313 * @param[in] phone The service phone. 314 * 315 * @return EOK on success. 316 * @return ENOENT if the service is not known. 317 * @return ENOMEM if there is not enough memory left. 318 * 331 * @param[in] service The module service. 332 * @param[in] phone The service phone. 333 * @return EOK on success. 334 * @return ENOENT if the service is not known. 335 * @return ENOMEM if there is not enough memory left. 319 336 */ 320 337 static int nildummy_register_message(services_t service, int phone) … … 333 350 /** Send the packet queue. 334 351 * 335 * @param[in] device_id The device identifier. 336 * @param[in] packet The packet queue. 337 * @param[in] sender The sending module service. 338 * 339 * @return EOK on success. 340 * @return ENOENT if there no such device. 341 * @return EINVAL if the service parameter is not known. 342 * 343 */ 344 static int nildummy_send_message(device_id_t device_id, packet_t packet, 345 services_t sender) 352 * @param[in] device_id The device identifier. 353 * @param[in] packet The packet queue. 354 * @param[in] sender The sending module service. 355 * @return EOK on success. 356 * @return ENOENT if there no such device. 357 * @return EINVAL if the service parameter is not known. 358 */ 359 static int 360 nildummy_send_message(device_id_t device_id, packet_t packet, services_t sender) 346 361 { 347 362 nildummy_device_ref device; … … 349 364 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 350 365 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 351 if (! device){366 if (!device) { 352 367 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 353 368 return ENOENT; 354 369 } 355 370 // send packet queue 356 if (packet){357 netif_send_msg(device->phone, device_id, packet, SERVICE_NILDUMMY);358 }371 if (packet) 372 netif_send_msg(device->phone, device_id, packet, 373 SERVICE_NILDUMMY); 359 374 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 360 375 return EOK; 361 376 } 362 377 363 int nil_message_standalone(const char *name, ipc_callid_t callid, ipc_call_t *call, 378 int 379 nil_message_standalone(const char *name, ipc_callid_t callid, ipc_call_t *call, 364 380 ipc_call_t *answer, int *answer_count) 365 381 { … … 375 391 *answer_count = 0; 376 392 switch (IPC_GET_METHOD(*call)) { 377 case IPC_M_PHONE_HUNGUP: 378 return EOK; 379 case NET_NIL_DEVICE: 380 return nildummy_device_message(IPC_GET_DEVICE(call), 381 IPC_GET_SERVICE(call), IPC_GET_MTU(call)); 382 case NET_NIL_SEND: 383 ERROR_PROPAGATE(packet_translate_remote(nildummy_globals.net_phone, 384 &packet, IPC_GET_PACKET(call))); 385 return nildummy_send_message(IPC_GET_DEVICE(call), packet, 386 IPC_GET_SERVICE(call)); 387 case NET_NIL_PACKET_SPACE: 388 ERROR_PROPAGATE(nildummy_packet_space_message(IPC_GET_DEVICE(call), 389 &addrlen, &prefix, &content, &suffix)); 390 IPC_SET_ADDR(answer, addrlen); 391 IPC_SET_PREFIX(answer, prefix); 392 IPC_SET_CONTENT(answer, content); 393 IPC_SET_SUFFIX(answer, suffix); 394 *answer_count = 4; 395 return EOK; 396 case NET_NIL_ADDR: 397 ERROR_PROPAGATE(nildummy_addr_message(IPC_GET_DEVICE(call), 398 &address)); 399 return measured_strings_reply(address, 1); 400 case NET_NIL_BROADCAST_ADDR: 401 ERROR_PROPAGATE(nildummy_addr_message(IPC_GET_DEVICE(call), 402 &address)); 403 return measured_strings_reply(address, 1); 404 case IPC_M_CONNECT_TO_ME: 405 return nildummy_register_message(NIL_GET_PROTO(call), 406 IPC_GET_PHONE(call)); 393 case IPC_M_PHONE_HUNGUP: 394 return EOK; 395 396 case NET_NIL_DEVICE: 397 return nildummy_device_message(IPC_GET_DEVICE(call), 398 IPC_GET_SERVICE(call), IPC_GET_MTU(call)); 399 400 case NET_NIL_SEND: 401 ERROR_PROPAGATE(packet_translate_remote( 402 nildummy_globals.net_phone, &packet, IPC_GET_PACKET(call))); 403 return nildummy_send_message(IPC_GET_DEVICE(call), packet, 404 IPC_GET_SERVICE(call)); 405 406 case NET_NIL_PACKET_SPACE: 407 ERROR_PROPAGATE(nildummy_packet_space_message( 408 IPC_GET_DEVICE(call), &addrlen, &prefix, &content, 409 &suffix)); 410 IPC_SET_ADDR(answer, addrlen); 411 IPC_SET_PREFIX(answer, prefix); 412 IPC_SET_CONTENT(answer, content); 413 IPC_SET_SUFFIX(answer, suffix); 414 *answer_count = 4; 415 return EOK; 416 417 case NET_NIL_ADDR: 418 ERROR_PROPAGATE(nildummy_addr_message(IPC_GET_DEVICE(call), 419 &address)); 420 return measured_strings_reply(address, 1); 421 422 case NET_NIL_BROADCAST_ADDR: 423 ERROR_PROPAGATE(nildummy_addr_message(IPC_GET_DEVICE(call), 424 &address)); 425 return measured_strings_reply(address, 1); 426 427 case IPC_M_CONNECT_TO_ME: 428 return nildummy_register_message(NIL_GET_PROTO(call), 429 IPC_GET_PHONE(call)); 407 430 } 408 431 … … 412 435 /** Default thread for new connections. 413 436 * 414 * @param[in] iid The initial message identifier. 415 * @param[in] icall The initial message call structure. 416 * 437 * @param[in] iid The initial message identifier. 438 * @param[in] icall The initial message call structure. 417 439 */ 418 440 static void nil_client_connection(ipc_callid_t iid, ipc_call_t *icall) … … 424 446 ipc_answer_0(iid, EOK); 425 447 426 while (true) {448 while (true) { 427 449 ipc_call_t answer; 428 450 int answer_count; … … 436 458 437 459 /* Process the message */ 438 int res = nil_module_message_standalone(NAME, callid, &call, &answer, 439 &answer_count); 440 441 /* End if said to either by the message or the processing result */ 442 if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP)) 460 int res = nil_module_message_standalone(NAME, callid, &call, 461 &answer, &answer_count); 462 463 /* 464 * End if told to either by the message or the processing 465 * result. 466 */ 467 if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || 468 (res == EHANGUP)) 443 469 return; 444 470 … … 453 479 454 480 /* Start the module */ 455 if (ERROR_OCCURRED(nil_module_start_standalone(nil_client_connection))) 456 return ERROR_CODE; 457 481 ERROR_PROPAGATE(nil_module_start_standalone(nil_client_connection)); 458 482 return EOK; 459 483 }
Note:
See TracChangeset
for help on using the changeset viewer.