Changes in / [f2d2c604:e7f6389] in mainline
- Location:
- uspace
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/adt/measured_strings.c
rf2d2c604 re7f6389 52 52 * @param[in] string The initial character string to be stored. 53 53 * @param[in] length The length of the given string without the terminating 54 * zero (' \0') character. If the length is zero, the actual55 * length is computed. The given length is used and56 * appended with the terminating zero ('\ 0') character54 * zero ('/0') character. If the length is zero (0), the 55 * actual length is computed. The given length is used and 56 * appended with the terminating zero ('\\0') character 57 57 * otherwise. 58 58 * @returns The new bundled character string with measured length. … … 60 60 */ 61 61 measured_string_ref 62 measured_string_create_bulk(const char * string, size_t length)62 measured_string_create_bulk(const char * string, size_t length) 63 63 { 64 64 measured_string_ref new; … … 66 66 if (length == 0) { 67 67 while (string[length]) 68 length++;68 ++length; 69 69 } 70 70 new = (measured_string_ref) malloc(sizeof(measured_string_t) + … … 104 104 new->value[new->length] = '\0'; 105 105 return new; 106 } else { 107 free(new); 106 108 } 107 free(new);108 109 } 109 110 … … 155 156 return EINVAL; 156 157 } 157 if 158 length))) {158 if(ERROR_OCCURRED(async_data_write_finalize(callid, lengths, 159 sizeof(size_t) * (count + 1)))) { 159 160 free(lengths); 160 161 return ERROR_CODE; … … 162 163 163 164 *data = malloc(lengths[count]); 164 if (! *data) {165 if (!(*data)) { 165 166 free(lengths); 166 167 return ENOMEM; … … 170 171 *strings = (measured_string_ref) malloc(sizeof(measured_string_t) * 171 172 count); 172 if (! *strings) {173 if (!(*strings)) { 173 174 free(lengths); 174 175 free(*data); … … 177 178 178 179 next = *data; 179 for (index = 0; index < count; index++) {180 for (index = 0; index < count; ++index) { 180 181 (*strings)[index].length = lengths[index]; 181 182 if (lengths[index] > 0) { 182 if ( !async_data_write_receive(&callid, &length) ||183 if ((!async_data_write_receive(&callid, &length)) || 183 184 (length != lengths[index])) { 184 185 free(*data); … … 187 188 return EINVAL; 188 189 } 189 if (ERROR_OCCURRED(async_data_write_finalize(callid, 190 next, lengths[index]))) { 191 free(*data); 192 free(*strings); 193 free(lengths); 194 return ERROR_CODE; 195 } 190 ERROR_PROPAGATE(async_data_write_finalize(callid, next, 191 lengths[index])); 196 192 (*strings)[index].value = next; 197 193 next += lengths[index]; 198 *next++ = '\0'; 194 *next = '\0'; 195 ++next; 199 196 } else { 200 197 (*strings)[index].value = NULL; … … 224 221 225 222 length = 0; 226 for (index = 0; index < count; index++) {223 for (index = 0; index < count; ++ index) { 227 224 lengths[index] = strings[index].length; 228 225 length += lengths[index] + 1; … … 265 262 return ENOMEM; 266 263 267 if ( !async_data_read_receive(&callid, &length) ||264 if ((!async_data_read_receive(&callid, &length)) || 268 265 (length != sizeof(size_t) * (count + 1))) { 269 266 free(lengths); 270 267 return EINVAL; 271 268 } 272 if (ERROR_OCCURRED(async_data_read_finalize(callid, lengths, length))) { 269 if (ERROR_OCCURRED(async_data_read_finalize(callid, lengths, 270 sizeof(size_t) * (count + 1)))) { 273 271 free(lengths); 274 272 return ERROR_CODE; … … 276 274 free(lengths); 277 275 278 for (index = 0; index < count; index++) {276 for (index = 0; index < count; ++ index) { 279 277 if (strings[index].length > 0) { 280 if (!async_data_read_receive(&callid, &length)||278 if((!async_data_read_receive(&callid, &length)) || 281 279 (length != strings[index].length)) { 282 280 return EINVAL; … … 319 317 char *next; 320 318 321 if ((phone < 0) || (!strings) || (!data) || (count <= 0))319 if ((phone <= 0) || (!strings) || (!data) || (count <= 0)) 322 320 return EINVAL; 323 321 … … 333 331 334 332 *data = malloc(lengths[count]); 335 if (! *data) {333 if (!(*data)) { 336 334 free(lengths); 337 335 return ENOMEM; … … 340 338 *strings = (measured_string_ref) malloc(sizeof(measured_string_t) * 341 339 count); 342 if (! *strings) {340 if (!(*strings)) { 343 341 free(lengths); 344 342 free(*data); … … 347 345 348 346 next = *data; 349 for (index = 0; index < count; index++) {347 for (index = 0; index < count; ++ index) { 350 348 (*strings)[index].length = lengths[index]; 351 349 if (lengths[index] > 0) { 352 if (ERROR_OCCURRED(async_data_read_start(phone, next, 353 lengths[index]))) { 354 free(lengths); 355 free(data); 356 free(strings); 357 return ERROR_CODE; 358 } 350 ERROR_PROPAGATE(async_data_read_start(phone, next, 351 lengths[index])); 359 352 (*strings)[index].value = next; 360 353 next += lengths[index]; 361 *next++ = '\0'; 354 *next = '\0'; 355 ++ next; 362 356 } else { 363 357 (*strings)[index].value = NULL; … … 392 386 size_t index; 393 387 394 if ((phone < 0) || (!strings) || (count <= 0))388 if ((phone <= 0) || (!strings) || (count <= 0)) 395 389 return EINVAL; 396 390 … … 407 401 free(lengths); 408 402 409 for (index = 0; index < count; index++) {403 for (index = 0; index < count; ++index) { 410 404 if (strings[index].length > 0) { 411 405 ERROR_PROPAGATE(async_data_write_start(phone, -
uspace/lib/c/include/adt/measured_strings.h
rf2d2c604 re7f6389 43 43 44 44 /** Type definition of the character string with measured length. 45 * @see measured_string45 * @see measured_string 46 46 */ 47 47 typedef struct measured_string measured_string_t; 48 48 49 49 /** Type definition of the character string with measured length pointer. 50 * @see measured_string50 * @see measured_string 51 51 */ 52 52 typedef measured_string_t *measured_string_ref; … … 59 59 struct measured_string { 60 60 /** Character string data. */ 61 char * value;61 char * value; 62 62 /** Character string length. */ 63 63 size_t length; -
uspace/srv/net/nil/eth/eth.c
rf2d2c604 re7f6389 66 66 #include "eth_header.h" 67 67 68 /** The module name. */ 68 /** The module name. 69 */ 69 70 #define NAME "eth" 70 71 71 /** Reserved packet prefix length. */72 #define ETH_PREFIX \ 73 (sizeof(eth_header_t) + sizeof(eth_header_lsap_t) + \ 74 sizeof(eth_header_snap_t)) 75 76 /** Reserved packet suffix length.*/77 #define ETH_SUFFIX \78 sizeof(eth_fcs_t) 79 80 /** Maximum packet content length.*/72 /** Reserved packet prefix length. 73 */ 74 #define ETH_PREFIX (sizeof(eth_header_t) + sizeof(eth_header_lsap_t) + sizeof(eth_header_snap_t)) 75 76 /** Reserved packet suffix length. 77 */ 78 #define ETH_SUFFIX sizeof(eth_fcs_t) 79 80 /** Maximum packet content length. 81 */ 81 82 #define ETH_MAX_CONTENT 1500u 82 83 83 /** Minimum packet content length. */ 84 /** Minimum packet content length. 85 */ 84 86 #define ETH_MIN_CONTENT 46u 85 87 86 /** Maximum tagged packet content length. */ 87 #define ETH_MAX_TAGGED_CONTENT(flags) \ 88 (ETH_MAX_CONTENT - \ 89 ((IS_8023_2_LSAP(flags) || IS_8023_2_SNAP(flags)) ? \ 90 sizeof(eth_header_lsap_t) : 0) - \ 91 (IS_8023_2_SNAP(flags) ? sizeof(eth_header_snap_t) : 0)) 92 93 /** Minimum tagged packet content length. */ 94 #define ETH_MIN_TAGGED_CONTENT(flags) \ 95 (ETH_MIN_CONTENT - \ 96 ((IS_8023_2_LSAP(flags) || IS_8023_2_SNAP(flags)) ? \ 97 sizeof(eth_header_lsap_t) : 0) - \ 98 (IS_8023_2_SNAP(flags) ? sizeof(eth_header_snap_t) : 0)) 99 100 /** Dummy flag shift value. */ 88 /** Maximum tagged packet content length. 89 */ 90 #define ETH_MAX_TAGGED_CONTENT(flags) (ETH_MAX_CONTENT - ((IS_8023_2_LSAP(flags) || IS_8023_2_SNAP(flags)) ? sizeof(eth_header_lsap_t) : 0) - (IS_8023_2_SNAP(flags) ? sizeof(eth_header_snap_t) : 0)) 91 92 /** Minimum tagged packet content length. 93 */ 94 #define ETH_MIN_TAGGED_CONTENT(flags) (ETH_MIN_CONTENT - ((IS_8023_2_LSAP(flags) || IS_8023_2_SNAP(flags)) ? sizeof(eth_header_lsap_t) : 0) - (IS_8023_2_SNAP(flags) ? sizeof(eth_header_snap_t) : 0)) 95 96 /** Dummy flag shift value. 97 */ 101 98 #define ETH_DUMMY_SHIFT 0 102 99 103 /** Mode flag shift value. */ 100 /** Mode flag shift value. 101 */ 104 102 #define ETH_MODE_SHIFT 1 105 103 106 104 /** Dummy device flag. 107 * Preamble and FCS are mandatory part of the packets.108 */ 109 #define ETH_DUMMY (1 << ETH_DUMMY_SHIFT)105 * Preamble and FCS are mandatory part of the packets. 106 */ 107 #define ETH_DUMMY (1 << ETH_DUMMY_SHIFT) 110 108 111 109 /** Returns the dummy flag. 112 * @see ETH_DUMMY113 */ 114 #define IS_DUMMY(flags) ((flags) & 110 * @see ETH_DUMMY 111 */ 112 #define IS_DUMMY(flags) ((flags) Ð_DUMMY) 115 113 116 114 /** Device mode flags. 117 * @see ETH_DIX 118 * @see ETH_8023_2_LSAP 119 * @see ETH_8023_2_SNAP 120 */ 121 #define ETH_MODE_MASK (3 << ETH_MODE_SHIFT) 122 123 /** DIX Ethernet mode flag. */ 124 #define ETH_DIX (1 << ETH_MODE_SHIFT) 115 * @see ETH_DIX 116 * @see ETH_8023_2_LSAP 117 * @see ETH_8023_2_SNAP 118 */ 119 #define ETH_MODE_MASK (3 << ETH_MODE_SHIFT) 120 121 /** DIX Ethernet mode flag. 122 */ 123 #define ETH_DIX (1 << ETH_MODE_SHIFT) 125 124 126 125 /** Returns whether the DIX Ethernet mode flag is set. 127 * 128 * @param[in] flags The ethernet flags.129 * @see ETH_DIX130 */ 131 #define IS_DIX(flags) (((flags) & ETH_MODE_MASK) == ETH_DIX) 132 133 /** 802.3 + 802.2 + LSAP mode flag.*/134 #define ETH_8023_2_LSAP (2 << ETH_MODE_SHIFT)126 * @param[in] flags The ethernet flags. 127 * @see ETH_DIX 128 */ 129 #define IS_DIX(flags) (((flags) Ð_MODE_MASK) == ETH_DIX) 130 131 /** 802.3 + 802.2 + LSAP mode flag. 132 */ 133 #define ETH_8023_2_LSAP (2 << ETH_MODE_SHIFT) 135 134 136 135 /** Returns whether the 802.3 + 802.2 + LSAP mode flag is set. 137 * 138 * @param[in] flags The ethernet flags.139 * @see ETH_8023_2_LSAP140 */ 141 #define IS_8023_2_LSAP(flags) (((flags) & ETH_MODE_MASK) == ETH_8023_2_LSAP) 142 143 /** 802.3 + 802.2 + LSAP + SNAP mode flag.*/144 #define ETH_8023_2_SNAP (3 << ETH_MODE_SHIFT)136 * @param[in] flags The ethernet flags. 137 * @see ETH_8023_2_LSAP 138 */ 139 #define IS_8023_2_LSAP(flags) (((flags) Ð_MODE_MASK) == ETH_8023_2_LSAP) 140 141 /** 802.3 + 802.2 + LSAP + SNAP mode flag. 142 */ 143 #define ETH_8023_2_SNAP (3 << ETH_MODE_SHIFT) 145 144 146 145 /** Returns whether the 802.3 + 802.2 + LSAP + SNAP mode flag is set. 147 * 148 * @param[in] flags The ethernet flags. 149 * @see ETH_8023_2_SNAP 150 */ 151 #define IS_8023_2_SNAP(flags) (((flags) & ETH_MODE_MASK) == ETH_8023_2_SNAP) 146 * @param[in] flags The ethernet flags. 147 * @see ETH_8023_2_SNAP 148 */ 149 #define IS_8023_2_SNAP(flags) (((flags) Ð_MODE_MASK) == ETH_8023_2_SNAP) 152 150 153 151 /** Type definition of the ethernet address type. 154 * @see eth_addr_type155 */ 156 typedef enum eth_addr_type 152 * @see eth_addr_type 153 */ 154 typedef enum eth_addr_type eth_addr_type_t; 157 155 158 156 /** Type definition of the ethernet address type pointer. 159 * @see eth_addr_type 160 */ 161 typedef eth_addr_type_t *eth_addr_type_ref; 162 163 /** Ethernet address type. */ 164 enum eth_addr_type { 165 /** Local address. */ 157 * @see eth_addr_type 158 */ 159 typedef eth_addr_type_t * eth_addr_type_ref; 160 161 /** Ethernet address type. 162 */ 163 enum eth_addr_type{ 164 /** Local address. 165 */ 166 166 ETH_LOCAL_ADDR, 167 /** Broadcast address. */ 167 /** Broadcast address. 168 */ 168 169 ETH_BROADCAST_ADDR 169 170 }; 170 171 171 /** Ethernet module global data. */ 172 eth_globals_t eth_globals; 173 174 DEVICE_MAP_IMPLEMENT(eth_devices, eth_device_t); 175 INT_MAP_IMPLEMENT(eth_protos, eth_proto_t); 176 177 int nil_device_state_msg_local(int nil_phone, device_id_t device_id, int state) 178 { 172 /** Ethernet module global data. 173 */ 174 eth_globals_t eth_globals; 175 176 /** @name Message processing functions 177 */ 178 /*@{*/ 179 180 /** Processes IPC messages from the registered device driver modules in an infinite loop. 181 * @param[in] iid The message identifier. 182 * @param[in,out] icall The message parameters. 183 */ 184 void eth_receiver(ipc_callid_t iid, ipc_call_t * icall); 185 186 /** Registers new device or updates the MTU of an existing one. 187 * Determines the device local hardware address. 188 * @param[in] device_id The new device identifier. 189 * @param[in] service The device driver service. 190 * @param[in] mtu The device maximum transmission unit. 191 * @returns EOK on success. 192 * @returns EEXIST if the device with the different service exists. 193 * @returns ENOMEM if there is not enough memory left. 194 * @returns Other error codes as defined for the net_get_device_conf_req() function. 195 * @returns Other error codes as defined for the netif_bind_service() function. 196 * @returns Other error codes as defined for the netif_get_addr_req() function. 197 */ 198 int eth_device_message(device_id_t device_id, services_t service, size_t mtu); 199 200 /** Registers receiving module service. 201 * Passes received packets for this service. 202 * @param[in] service The module service. 203 * @param[in] phone The service phone. 204 * @returns EOK on success. 205 * @returns ENOENT if the service is not known. 206 * @returns ENOMEM if there is not enough memory left. 207 */ 208 int eth_register_message(services_t service, int phone); 209 210 /** Returns the device packet dimensions for sending. 211 * @param[in] device_id The device identifier. 212 * @param[out] addr_len The minimum reserved address length. 213 * @param[out] prefix The minimum reserved prefix size. 214 * @param[out] content The maximum content size. 215 * @param[out] suffix The minimum reserved suffix size. 216 * @returns EOK on success. 217 * @returns EBADMEM if either one of the parameters is NULL. 218 * @returns ENOENT if there is no such device. 219 */ 220 int eth_packet_space_message(device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix); 221 222 /** Returns the device hardware address. 223 * @param[in] device_id The device identifier. 224 * @param[in] type Type of the desired address. 225 * @param[out] address The device hardware address. 226 * @returns EOK on success. 227 * @returns EBADMEM if the address parameter is NULL. 228 * @returns ENOENT if there no such device. 229 */ 230 int eth_addr_message(device_id_t device_id, eth_addr_type_t type, measured_string_ref * address); 231 232 /** Sends the packet queue. 233 * Sends only packet successfully processed by the eth_prepare_packet() function. 234 * @param[in] device_id The device identifier. 235 * @param[in] packet The packet queue. 236 * @param[in] sender The sending module service. 237 * @returns EOK on success. 238 * @returns ENOENT if there no such device. 239 * @returns EINVAL if the service parameter is not known. 240 */ 241 int eth_send_message(device_id_t device_id, packet_t packet, services_t sender); 242 243 /*@}*/ 244 245 /** Processes the received packet and chooses the target registered module. 246 * @param[in] flags The device flags. 247 * @param[in] packet The packet. 248 * @returns The target registered module. 249 * @returns NULL if the packet is not long enough. 250 * @returns NULL if the packet is too long. 251 * @returns NULL if the raw ethernet protocol is used. 252 * @returns NULL if the dummy device FCS checksum is invalid. 253 * @returns NULL if the packet address length is not big enough. 254 */ 255 eth_proto_ref eth_process_packet(int flags, packet_t packet); 256 257 /** Prepares the packet for sending. 258 * @param[in] flags The device flags. 259 * @param[in] packet The packet. 260 * @param[in] src_addr The source hardware address. 261 * @param[in] ethertype The ethernet protocol type. 262 * @param[in] mtu The device maximum transmission unit. 263 * @returns EOK on success. 264 * @returns EINVAL if the packet addresses length is not long enough. 265 * @returns EINVAL if the packet is bigger than the device MTU. 266 * @returns ENOMEM if there is not enough memory in the packet. 267 */ 268 int eth_prepare_packet(int flags, packet_t packet, uint8_t * src_addr, int ethertype, size_t mtu); 269 270 DEVICE_MAP_IMPLEMENT(eth_devices, eth_device_t) 271 272 INT_MAP_IMPLEMENT(eth_protos, eth_proto_t) 273 274 int nil_device_state_msg_local(int nil_phone, device_id_t device_id, int state){ 179 275 int index; 180 276 eth_proto_ref proto; 181 277 182 278 fibril_rwlock_read_lock(ð_globals.protos_lock); 183 for (index = eth_protos_count(ð_globals.protos) - 1; index >= 0; 184 index--) { 279 for(index = eth_protos_count(ð_globals.protos) - 1; index >= 0; -- index){ 185 280 proto = eth_protos_get_index(ð_globals.protos, index); 186 if (proto && proto->phone) { 187 il_device_state_msg(proto->phone, device_id, state, 188 proto->service); 281 if(proto && proto->phone){ 282 il_device_state_msg(proto->phone, device_id, state, proto->service); 189 283 } 190 284 } 191 285 fibril_rwlock_read_unlock(ð_globals.protos_lock); 192 193 286 return EOK; 194 287 } 195 288 196 int nil_initialize(int net_phone) 197 { 289 int nil_initialize(int net_phone){ 198 290 ERROR_DECLARE; 199 291 200 292 fibril_rwlock_initialize(ð_globals.devices_lock); 201 293 fibril_rwlock_initialize(ð_globals.protos_lock); 202 203 294 fibril_rwlock_write_lock(ð_globals.devices_lock); 204 295 fibril_rwlock_write_lock(ð_globals.protos_lock); 205 296 eth_globals.net_phone = net_phone; 206 eth_globals.broadcast_addr = 207 measured_string_create_bulk("\xFF\xFF\xFF\xFF\xFF\xFF", 208 CONVERT_SIZE(uint8_t, char, ETH_ADDR)); 209 if (!eth_globals.broadcast_addr) { 210 ERROR_CODE = ENOMEM; 211 goto out; 212 } 213 if (ERROR_OCCURRED(eth_devices_initialize(ð_globals.devices))) { 214 free(eth_globals.broadcast_addr); 215 goto out; 216 } 217 if (ERROR_OCCURRED(eth_protos_initialize(ð_globals.protos))) { 218 free(eth_globals.broadcast_addr); 297 eth_globals.broadcast_addr = measured_string_create_bulk("\xFF\xFF\xFF\xFF\xFF\xFF", CONVERT_SIZE(uint8_t, char, ETH_ADDR)); 298 if(! eth_globals.broadcast_addr){ 299 return ENOMEM; 300 } 301 ERROR_PROPAGATE(eth_devices_initialize(ð_globals.devices)); 302 if(ERROR_OCCURRED(eth_protos_initialize(ð_globals.protos))){ 219 303 eth_devices_destroy(ð_globals.devices); 220 }221 out: 304 return ERROR_CODE; 305 } 222 306 fibril_rwlock_write_unlock(ð_globals.protos_lock); 223 307 fibril_rwlock_write_unlock(ð_globals.devices_lock); 224 225 return ERROR_CODE; 226 } 227 228 /** Processes IPC messages from the registered device driver modules in an 229 * infinite loop. 230 * 231 * @param[in] iid The message identifier. 232 * @param[in,out] icall The message parameters. 233 */ 234 static void eth_receiver(ipc_callid_t iid, ipc_call_t *icall) 235 { 236 ERROR_DECLARE; 237 238 packet_t packet; 239 240 while (true) { 241 switch (IPC_GET_METHOD(*icall)) { 242 case NET_NIL_DEVICE_STATE: 243 nil_device_state_msg_local(0, IPC_GET_DEVICE(icall), 244 IPC_GET_STATE(icall)); 245 ipc_answer_0(iid, EOK); 246 break; 247 case NET_NIL_RECEIVED: 248 if (ERROR_NONE(packet_translate_remote( 249 eth_globals.net_phone, &packet, 250 IPC_GET_PACKET(icall)))) { 251 ERROR_CODE = nil_received_msg_local(0, 252 IPC_GET_DEVICE(icall), packet, 0); 253 } 254 ipc_answer_0(iid, (ipcarg_t) ERROR_CODE); 255 break; 256 default: 257 ipc_answer_0(iid, (ipcarg_t) ENOTSUP); 258 } 259 260 iid = async_get_call(icall); 261 } 262 } 263 264 /** Registers new device or updates the MTU of an existing one. 265 * 266 * Determines the device local hardware address. 267 * 268 * @param[in] device_id The new device identifier. 269 * @param[in] service The device driver service. 270 * @param[in] mtu The device maximum transmission unit. 271 * @returns EOK on success. 272 * @returns EEXIST if the device with the different service exists. 273 * @returns ENOMEM if there is not enough memory left. 274 * @returns Other error codes as defined for the 275 * net_get_device_conf_req() function. 276 * @returns Other error codes as defined for the 277 * netif_bind_service() function. 278 * @returns Other error codes as defined for the 279 * netif_get_addr_req() function. 280 */ 281 static int 282 eth_device_message(device_id_t device_id, services_t service, size_t mtu) 283 { 308 return EOK; 309 } 310 311 int eth_device_message(device_id_t device_id, services_t service, size_t mtu){ 284 312 ERROR_DECLARE; 285 313 286 314 eth_device_ref device; 287 315 int index; 288 measured_string_t names[2] = { 289 { 290 (char *) "ETH_MODE", 291 8 292 }, 293 { 294 (char *) "ETH_DUMMY", 295 9 296 } 297 }; 316 measured_string_t names[2] = {{str_dup("ETH_MODE"), 8}, {str_dup("ETH_DUMMY"), 9}}; 298 317 measured_string_ref configuration; 299 318 size_t count = sizeof(names) / sizeof(measured_string_t); 300 char * data;319 char * data; 301 320 eth_proto_ref proto; 302 321 … … 304 323 // an existing device? 305 324 device = eth_devices_find(ð_globals.devices, device_id); 306 if (device){307 if (device->service != service){325 if(device){ 326 if(device->service != service){ 308 327 printf("Device %d already exists\n", device->device_id); 309 328 fibril_rwlock_write_unlock(ð_globals.devices_lock); 310 329 return EEXIST; 311 } 312 313 // update mtu 314 if ((mtu > 0) && (mtu <= ETH_MAX_TAGGED_CONTENT(device->flags))) 330 }else{ 331 // update mtu 332 if((mtu > 0) && (mtu <= ETH_MAX_TAGGED_CONTENT(device->flags))){ 333 device->mtu = mtu; 334 }else{ 335 device->mtu = ETH_MAX_TAGGED_CONTENT(device->flags); 336 } 337 printf("Device %d already exists:\tMTU\t= %d\n", device->device_id, device->mtu); 338 fibril_rwlock_write_unlock(ð_globals.devices_lock); 339 // notify all upper layer modules 340 fibril_rwlock_read_lock(ð_globals.protos_lock); 341 for(index = 0; index < eth_protos_count(ð_globals.protos); ++ index){ 342 proto = eth_protos_get_index(ð_globals.protos, index); 343 if (proto->phone){ 344 il_mtu_changed_msg(proto->phone, device->device_id, device->mtu, proto->service); 345 } 346 } 347 fibril_rwlock_read_unlock(ð_globals.protos_lock); 348 return EOK; 349 } 350 }else{ 351 // create a new device 352 device = (eth_device_ref) malloc(sizeof(eth_device_t)); 353 if(! device){ 354 return ENOMEM; 355 } 356 device->device_id = device_id; 357 device->service = service; 358 device->flags = 0; 359 if((mtu > 0) && (mtu <= ETH_MAX_TAGGED_CONTENT(device->flags))){ 315 360 device->mtu = mtu; 316 else317 device->mtu = ETH_MAX_TAGGED_CONTENT(device->flags);318 319 printf("Device %d already exists:\tMTU\t= %d\n",320 device->device_id, device->mtu);321 fibril_rwlock_write_unlock(ð_globals.devices_lock);322 323 // notify all upper layer modules324 fibril_rwlock_read_lock(ð_globals.protos_lock);325 for (index = 0; index < eth_protos_count(ð_globals.protos);326 index++){327 proto = eth_protos_get_index(ð_globals.protos,328 index);329 if (proto->phone) {330 il_mtu_changed_msg(proto->phone,331 device->device_id, device->mtu,332 proto->service);361 }else{ 362 device->mtu = ETH_MAX_TAGGED_CONTENT(device->flags); 363 } 364 configuration = &names[0]; 365 if(ERROR_OCCURRED(net_get_device_conf_req(eth_globals.net_phone, device->device_id, &configuration, count, &data))){ 366 fibril_rwlock_write_unlock(ð_globals.devices_lock); 367 free(device); 368 return ERROR_CODE; 369 } 370 if(configuration){ 371 if(! str_lcmp(configuration[0].value, "DIX", configuration[0].length)){ 372 device->flags |= ETH_DIX; 373 }else if(! str_lcmp(configuration[0].value, "8023_2_LSAP", configuration[0].length)){ 374 device->flags |= ETH_8023_2_LSAP; 375 }else device->flags |= ETH_8023_2_SNAP; 376 if((configuration[1].value) && (configuration[1].value[0] == 'y')){ 377 device->flags |= ETH_DUMMY; 333 378 } 334 } 335 fibril_rwlock_read_unlock(ð_globals.protos_lock); 336 return EOK; 337 } 338 339 // create a new device 340 device = (eth_device_ref) malloc(sizeof(eth_device_t)); 341 if (!device) 342 return ENOMEM; 343 344 device->device_id = device_id; 345 device->service = service; 346 device->flags = 0; 347 if ((mtu > 0) && (mtu <= ETH_MAX_TAGGED_CONTENT(device->flags))) 348 device->mtu = mtu; 349 else 350 device->mtu = ETH_MAX_TAGGED_CONTENT(device->flags); 351 352 configuration = &names[0]; 353 if (ERROR_OCCURRED(net_get_device_conf_req(eth_globals.net_phone, 354 device->device_id, &configuration, count, &data))) { 355 fibril_rwlock_write_unlock(ð_globals.devices_lock); 356 free(device); 357 return ERROR_CODE; 358 } 359 if (configuration) { 360 if (!str_lcmp(configuration[0].value, "DIX", 361 configuration[0].length)) { 362 device->flags |= ETH_DIX; 363 } else if(!str_lcmp(configuration[0].value, "8023_2_LSAP", 364 configuration[0].length)) { 365 device->flags |= ETH_8023_2_LSAP; 366 } else { 379 net_free_settings(configuration, data); 380 }else{ 367 381 device->flags |= ETH_8023_2_SNAP; 368 382 } 369 370 if (configuration[1].value && 371 (configuration[1].value[0] == 'y')) { 372 device->flags |= ETH_DUMMY; 373 } 374 net_free_settings(configuration, data); 375 } else { 376 device->flags |= ETH_8023_2_SNAP; 377 } 378 379 // bind the device driver 380 device->phone = netif_bind_service(device->service, device->device_id, 381 SERVICE_ETHERNET, eth_receiver); 382 if (device->phone < 0) { 383 fibril_rwlock_write_unlock(ð_globals.devices_lock); 384 free(device); 385 return device->phone; 386 } 387 388 // get hardware address 389 if (ERROR_OCCURRED(netif_get_addr_req(device->phone, device->device_id, 390 &device->addr, &device->addr_data))) { 391 fibril_rwlock_write_unlock(ð_globals.devices_lock); 392 free(device); 393 return ERROR_CODE; 394 } 395 396 // add to the cache 397 index = eth_devices_add(ð_globals.devices, device->device_id, 398 device); 399 if (index < 0) { 400 fibril_rwlock_write_unlock(ð_globals.devices_lock); 401 free(device->addr); 402 free(device->addr_data); 403 free(device); 404 return index; 405 } 406 407 printf("%s: Device registered (id: %d, service: %d: mtu: %d, " 408 "mac: %x:%x:%x:%x:%x:%x, flags: 0x%x)\n", 409 NAME, device->device_id, device->service, device->mtu, 410 device->addr_data[0], device->addr_data[1], 411 device->addr_data[2], device->addr_data[3], 412 device->addr_data[4], device->addr_data[5], device->flags); 413 383 // bind the device driver 384 device->phone = netif_bind_service(device->service, device->device_id, SERVICE_ETHERNET, eth_receiver); 385 if(device->phone < 0){ 386 fibril_rwlock_write_unlock(ð_globals.devices_lock); 387 free(device); 388 return device->phone; 389 } 390 // get hardware address 391 if(ERROR_OCCURRED(netif_get_addr_req(device->phone, device->device_id, &device->addr, &device->addr_data))){ 392 fibril_rwlock_write_unlock(ð_globals.devices_lock); 393 free(device); 394 return ERROR_CODE; 395 } 396 // add to the cache 397 index = eth_devices_add(ð_globals.devices, device->device_id, device); 398 if(index < 0){ 399 fibril_rwlock_write_unlock(ð_globals.devices_lock); 400 free(device->addr); 401 free(device->addr_data); 402 free(device); 403 return index; 404 } 405 printf("%s: Device registered (id: %d, service: %d: mtu: %d, " 406 "mac: %x:%x:%x:%x:%x:%x, flags: 0x%x)\n", 407 NAME, device->device_id, device->service, device->mtu, 408 device->addr_data[0], device->addr_data[1], 409 device->addr_data[2], device->addr_data[3], 410 device->addr_data[4], device->addr_data[5], device->flags); 411 } 414 412 fibril_rwlock_write_unlock(ð_globals.devices_lock); 415 413 return EOK; 416 414 } 417 415 418 /** Processes the received packet and chooses the target registered module. 419 * 420 * @param[in] flags The device flags. 421 * @param[in] packet The packet. 422 * @returns The target registered module. 423 * @returns NULL if the packet is not long enough. 424 * @returns NULL if the packet is too long. 425 * @returns NULL if the raw ethernet protocol is used. 426 * @returns NULL if the dummy device FCS checksum is invalid. 427 * @returns NULL if the packet address length is not big enough. 428 */ 429 static eth_proto_ref eth_process_packet(int flags, packet_t packet) 430 { 416 eth_proto_ref eth_process_packet(int flags, packet_t packet){ 431 417 ERROR_DECLARE; 432 418 … … 440 426 441 427 length = packet_get_data_length(packet); 442 443 if (IS_DUMMY(flags)) 428 if(IS_DUMMY(flags)){ 444 429 packet_trim(packet, sizeof(eth_preamble_t), 0); 445 if (length < sizeof(eth_header_t) + ETH_MIN_CONTENT + 446 (IS_DUMMY(flags) ? ETH_SUFFIX : 0)) 447 return NULL; 448 430 } 431 if(length < sizeof(eth_header_t) + ETH_MIN_CONTENT + (IS_DUMMY(flags) ? ETH_SUFFIX : 0)) return NULL; 449 432 data = packet_get_data(packet); 450 433 header = (eth_header_snap_ref) data; 451 434 type = ntohs(header->header.ethertype); 452 453 if (type >= ETH_MIN_PROTO) { 435 if(type >= ETH_MIN_PROTO){ 454 436 // DIX Ethernet 455 437 prefix = sizeof(eth_header_t); … … 457 439 fcs = (eth_fcs_ref) data + length - sizeof(eth_fcs_t); 458 440 length -= sizeof(eth_fcs_t); 459 } else if(type <= ETH_MAX_CONTENT){441 }else if(type <= ETH_MAX_CONTENT){ 460 442 // translate "LSAP" values 461 if ((header->lsap.dsap == ETH_LSAP_GLSAP) && 462 (header->lsap.ssap == ETH_LSAP_GLSAP)) { 443 if((header->lsap.dsap == ETH_LSAP_GLSAP) && (header->lsap.ssap == ETH_LSAP_GLSAP)){ 463 444 // raw packet 464 445 // discard 465 446 return NULL; 466 } else if((header->lsap.dsap == ETH_LSAP_SNAP) && 467 (header->lsap.ssap == ETH_LSAP_SNAP)) { 447 }else if((header->lsap.dsap == ETH_LSAP_SNAP) && (header->lsap.ssap == ETH_LSAP_SNAP)){ 468 448 // IEEE 802.3 + 802.2 + LSAP + SNAP 469 449 // organization code not supported 470 450 type = ntohs(header->snap.ethertype); 471 prefix = sizeof(eth_header_t) + 472 sizeof(eth_header_lsap_t) + 473 sizeof(eth_header_snap_t); 474 } else { 451 prefix = sizeof(eth_header_t) + sizeof(eth_header_lsap_t) + sizeof(eth_header_snap_t); 452 }else{ 475 453 // IEEE 802.3 + 802.2 LSAP 476 454 type = lsap_map(header->lsap.dsap); 477 prefix = sizeof(eth_header_t) + 478 sizeof(eth_header_lsap_t); 479 } 480 suffix = (type < ETH_MIN_CONTENT) ? ETH_MIN_CONTENT - type : 0U; 455 prefix = sizeof(eth_header_t) + sizeof(eth_header_lsap_t); 456 } 457 suffix = (type < ETH_MIN_CONTENT) ? ETH_MIN_CONTENT - type : 0u; 481 458 fcs = (eth_fcs_ref) data + prefix + type + suffix; 482 459 suffix += length - prefix - type; 483 460 length = prefix + type + suffix; 484 } else{461 }else{ 485 462 // invalid length/type, should not occurr 486 463 return NULL; 487 464 } 488 489 if (IS_DUMMY(flags)) { 490 if ((~compute_crc32(~0U, data, length * 8)) != ntohl(*fcs)) 465 if(IS_DUMMY(flags)){ 466 if((~ compute_crc32(~ 0u, data, length * 8)) != ntohl(*fcs)){ 491 467 return NULL; 468 } 492 469 suffix += sizeof(eth_fcs_t); 493 470 } 494 495 if (ERROR_OCCURRED(packet_set_addr(packet, 496 header->header.source_address, header->header.destination_address, 497 ETH_ADDR)) || ERROR_OCCURRED(packet_trim(packet, prefix, suffix))) { 471 if(ERROR_OCCURRED(packet_set_addr(packet, header->header.source_address, header->header.destination_address, ETH_ADDR)) 472 || ERROR_OCCURRED(packet_trim(packet, prefix, suffix))){ 498 473 return NULL; 499 474 } 500 501 475 return eth_protos_find(ð_globals.protos, type); 502 476 } 503 477 504 int 505 nil_received_msg_local(int nil_phone, device_id_t device_id, packet_t packet, 506 services_t target) 507 { 478 int nil_received_msg_local(int nil_phone, device_id_t device_id, packet_t packet, services_t target){ 508 479 eth_proto_ref proto; 509 480 packet_t next; … … 513 484 fibril_rwlock_read_lock(ð_globals.devices_lock); 514 485 device = eth_devices_find(ð_globals.devices, device_id); 515 if (!device){486 if(! device){ 516 487 fibril_rwlock_read_unlock(ð_globals.devices_lock); 517 488 return ENOENT; … … 519 490 flags = device->flags; 520 491 fibril_rwlock_read_unlock(ð_globals.devices_lock); 521 522 492 fibril_rwlock_read_lock(ð_globals.protos_lock); 523 do 493 do{ 524 494 next = pq_detach(packet); 525 495 proto = eth_process_packet(flags, packet); 526 if (proto) { 527 il_received_msg(proto->phone, device_id, packet, 528 proto->service); 529 } else { 496 if(proto){ 497 il_received_msg(proto->phone, device_id, packet, proto->service); 498 }else{ 530 499 // drop invalid/unknown 531 pq_release_remote(eth_globals.net_phone, 532 packet_get_id(packet)); 500 pq_release_remote(eth_globals.net_phone, packet_get_id(packet)); 533 501 } 534 502 packet = next; 535 } 503 }while(packet); 536 504 fibril_rwlock_read_unlock(ð_globals.protos_lock); 537 538 505 return EOK; 539 506 } 540 507 541 /** Returns the device packet dimensions for sending. 542 * 543 * @param[in] device_id The device identifier. 544 * @param[out] addr_len The minimum reserved address length. 545 * @param[out] prefix The minimum reserved prefix size. 546 * @param[out] content The maximum content size. 547 * @param[out] suffix The minimum reserved suffix size. 548 * @returns EOK on success. 549 * @returns EBADMEM if either one of the parameters is NULL. 550 * @returns ENOENT if there is no such device. 551 */ 552 static int 553 eth_packet_space_message(device_id_t device_id, size_t *addr_len, 554 size_t *prefix, size_t *content, size_t *suffix) 555 { 508 int eth_packet_space_message(device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix){ 556 509 eth_device_ref device; 557 510 558 if (!addr_len || !prefix || !content || !suffix)511 if(!(addr_len && prefix && content && suffix)){ 559 512 return EBADMEM; 560 513 } 561 514 fibril_rwlock_read_lock(ð_globals.devices_lock); 562 515 device = eth_devices_find(ð_globals.devices, device_id); 563 if (!device){516 if(! device){ 564 517 fibril_rwlock_read_unlock(ð_globals.devices_lock); 565 518 return ENOENT; … … 567 520 *content = device->mtu; 568 521 fibril_rwlock_read_unlock(ð_globals.devices_lock); 569 570 522 *addr_len = ETH_ADDR; 571 523 *prefix = ETH_PREFIX; … … 574 526 } 575 527 576 /** Returns the device hardware address. 577 * 578 * @param[in] device_id The device identifier. 579 * @param[in] type Type of the desired address. 580 * @param[out] address The device hardware address. 581 * @returns EOK on success. 582 * @returns EBADMEM if the address parameter is NULL. 583 * @returns ENOENT if there no such device. 584 */ 585 static int 586 eth_addr_message(device_id_t device_id, eth_addr_type_t type, 587 measured_string_ref *address) 588 { 528 int eth_addr_message(device_id_t device_id, eth_addr_type_t type, measured_string_ref * address){ 589 529 eth_device_ref device; 590 530 591 if (!address)531 if(! address){ 592 532 return EBADMEM; 593 594 if (type == ETH_BROADCAST_ADDR){533 } 534 if(type == ETH_BROADCAST_ADDR){ 595 535 *address = eth_globals.broadcast_addr; 596 } else{536 }else{ 597 537 fibril_rwlock_read_lock(ð_globals.devices_lock); 598 538 device = eth_devices_find(ð_globals.devices, device_id); 599 if (!device){539 if(! device){ 600 540 fibril_rwlock_read_unlock(ð_globals.devices_lock); 601 541 return ENOENT; … … 604 544 fibril_rwlock_read_unlock(ð_globals.devices_lock); 605 545 } 606 607 546 return (*address) ? EOK : ENOENT; 608 547 } 609 548 610 /** Registers receiving module service. 611 * 612 * Passes received packets for this service. 613 * 614 * @param[in] service The module service. 615 * @param[in] phone The service phone. 616 * @returns EOK on success. 617 * @returns ENOENT if the service is not known. 618 * @returns ENOMEM if there is not enough memory left. 619 */ 620 static int eth_register_message(services_t service, int phone) 621 { 549 int eth_register_message(services_t service, int phone){ 622 550 eth_proto_ref proto; 623 551 int protocol; … … 625 553 626 554 protocol = protocol_map(SERVICE_ETHERNET, service); 627 if (!protocol)555 if(! protocol){ 628 556 return ENOENT; 629 557 } 630 558 fibril_rwlock_write_lock(ð_globals.protos_lock); 631 559 proto = eth_protos_find(ð_globals.protos, protocol); 632 if (proto){560 if(proto){ 633 561 proto->phone = phone; 634 562 fibril_rwlock_write_unlock(ð_globals.protos_lock); 635 563 return EOK; 636 } else{564 }else{ 637 565 proto = (eth_proto_ref) malloc(sizeof(eth_proto_t)); 638 if (!proto){566 if(! proto){ 639 567 fibril_rwlock_write_unlock(ð_globals.protos_lock); 640 568 return ENOMEM; … … 644 572 proto->phone = phone; 645 573 index = eth_protos_add(ð_globals.protos, protocol, proto); 646 if (index < 0){574 if(index < 0){ 647 575 fibril_rwlock_write_unlock(ð_globals.protos_lock); 648 576 free(proto); … … 651 579 } 652 580 653 printf("%s: Protocol registered (protocol: %d, service: %d, phone: "654 "%d)\n",NAME, proto->protocol, proto->service, proto->phone);581 printf("%s: Protocol registered (protocol: %d, service: %d, phone: %d)\n", 582 NAME, proto->protocol, proto->service, proto->phone); 655 583 656 584 fibril_rwlock_write_unlock(ð_globals.protos_lock); … … 658 586 } 659 587 660 /** Prepares the packet for sending. 661 * 662 * @param[in] flags The device flags. 663 * @param[in] packet The packet. 664 * @param[in] src_addr The source hardware address. 665 * @param[in] ethertype The ethernet protocol type. 666 * @param[in] mtu The device maximum transmission unit. 667 * @returns EOK on success. 668 * @returns EINVAL if the packet addresses length is not long 669 * enough. 670 * @returns EINVAL if the packet is bigger than the device MTU. 671 * @returns ENOMEM if there is not enough memory in the packet. 672 */ 673 static int 674 eth_prepare_packet(int flags, packet_t packet, uint8_t *src_addr, int ethertype, 675 size_t mtu) 676 { 588 int eth_prepare_packet(int flags, packet_t packet, uint8_t * src_addr, int ethertype, size_t mtu){ 677 589 eth_header_snap_ref header; 678 590 eth_header_lsap_ref header_lsap; 679 591 eth_header_ref header_dix; 680 592 eth_fcs_ref fcs; 681 uint8_t * src;682 uint8_t * dest;593 uint8_t * src; 594 uint8_t * dest; 683 595 size_t length; 684 596 int i; 685 void * padding;597 void * padding; 686 598 eth_preamble_ref preamble; 687 599 688 600 i = packet_get_addr(packet, &src, &dest); 689 if (i < 0)601 if(i < 0){ 690 602 return i; 691 if (i != ETH_ADDR) 603 } 604 if(i != ETH_ADDR){ 692 605 return EINVAL; 693 606 } 694 607 length = packet_get_data_length(packet); 695 if (length > mtu)608 if(length > mtu){ 696 609 return EINVAL; 697 698 if (length < ETH_MIN_TAGGED_CONTENT(flags)) { 699 padding = packet_suffix(packet, 700 ETH_MIN_TAGGED_CONTENT(flags) - length); 701 if (!padding) 610 } 611 if(length < ETH_MIN_TAGGED_CONTENT(flags)){ 612 padding = packet_suffix(packet, ETH_MIN_TAGGED_CONTENT(flags) - length); 613 if(! padding){ 702 614 return ENOMEM; 615 } 703 616 bzero(padding, ETH_MIN_TAGGED_CONTENT(flags) - length); 704 617 } 705 706 if (IS_DIX(flags)) { 618 if(IS_DIX(flags)){ 707 619 header_dix = PACKET_PREFIX(packet, eth_header_t); 708 if (!header_dix)620 if(! header_dix){ 709 621 return ENOMEM; 710 622 } 711 623 header_dix->ethertype = (uint16_t) ethertype; 712 624 memcpy(header_dix->source_address, src_addr, ETH_ADDR); 713 625 memcpy(header_dix->destination_address, dest, ETH_ADDR); 714 626 src = &header_dix->destination_address[0]; 715 } else if(IS_8023_2_LSAP(flags)){627 }else if(IS_8023_2_LSAP(flags)){ 716 628 header_lsap = PACKET_PREFIX(packet, eth_header_lsap_t); 717 if (!header_lsap)629 if(! header_lsap){ 718 630 return ENOMEM; 719 720 header_lsap->header.ethertype = htons(length + 721 sizeof(eth_header_lsap_t)); 631 } 632 header_lsap->header.ethertype = htons(length + sizeof(eth_header_lsap_t)); 722 633 header_lsap->lsap.dsap = lsap_unmap(ntohs(ethertype)); 723 634 header_lsap->lsap.ssap = header_lsap->lsap.dsap; … … 726 637 memcpy(header_lsap->header.destination_address, dest, ETH_ADDR); 727 638 src = &header_lsap->header.destination_address[0]; 728 } else if(IS_8023_2_SNAP(flags)){639 }else if(IS_8023_2_SNAP(flags)){ 729 640 header = PACKET_PREFIX(packet, eth_header_snap_t); 730 if (!header)641 if(! header){ 731 642 return ENOMEM; 732 733 header->header.ethertype = htons(length + 734 sizeof(eth_header_lsap_t) + sizeof(eth_header_snap_t)); 643 } 644 header->header.ethertype = htons(length + sizeof(eth_header_lsap_t) + sizeof(eth_header_snap_t)); 735 645 header->lsap.dsap = (uint16_t) ETH_LSAP_SNAP; 736 646 header->lsap.ssap = header->lsap.dsap; 737 647 header->lsap.ctrl = IEEE_8023_2_UI; 738 739 for (i = 0; i < 3; ++ i) 648 for(i = 0; i < 3; ++ i){ 740 649 header->snap.protocol[i] = 0; 741 650 } 742 651 header->snap.ethertype = (uint16_t) ethertype; 743 652 memcpy(header->header.source_address, src_addr, ETH_ADDR); … … 745 654 src = &header->header.destination_address[0]; 746 655 } 747 748 if (IS_DUMMY(flags)) { 656 if(IS_DUMMY(flags)){ 749 657 preamble = PACKET_PREFIX(packet, eth_preamble_t); 750 if (!preamble)658 if(! preamble){ 751 659 return ENOMEM; 752 753 for (i = 0; i < 7; ++ i)660 } 661 for(i = 0; i < 7; ++ i){ 754 662 preamble->preamble[i] = ETH_PREAMBLE; 755 663 } 756 664 preamble->sfd = ETH_SFD; 757 758 665 fcs = PACKET_SUFFIX(packet, eth_fcs_t); 759 if (!fcs)666 if(! fcs){ 760 667 return ENOMEM; 761 762 *fcs = htonl(~compute_crc32(~0U, src, length * 8)); 763 } 764 668 } 669 *fcs = htonl(~ compute_crc32(~ 0u, src, length * 8)); 670 } 765 671 return EOK; 766 672 } 767 673 768 /** Sends the packet queue. 769 * 770 * Sends only packet successfully processed by the eth_prepare_packet() 771 * function. 772 * 773 * @param[in] device_id The device identifier. 774 * @param[in] packet The packet queue. 775 * @param[in] sender The sending module service. 776 * @returns EOK on success. 777 * @returns ENOENT if there no such device. 778 * @returns EINVAL if the service parameter is not known. 779 */ 780 static int 781 eth_send_message(device_id_t device_id, packet_t packet, services_t sender) 782 { 674 int eth_send_message(device_id_t device_id, packet_t packet, services_t sender){ 783 675 ERROR_DECLARE; 784 676 … … 789 681 790 682 ethertype = htons(protocol_map(SERVICE_ETHERNET, sender)); 791 if (!ethertype){683 if(! ethertype){ 792 684 pq_release_remote(eth_globals.net_phone, packet_get_id(packet)); 793 685 return EINVAL; 794 686 } 795 796 687 fibril_rwlock_read_lock(ð_globals.devices_lock); 797 688 device = eth_devices_find(ð_globals.devices, device_id); 798 if (!device){689 if(! device){ 799 690 fibril_rwlock_read_unlock(ð_globals.devices_lock); 800 691 return ENOENT; 801 692 } 802 803 693 // process packet queue 804 694 next = packet; 805 do { 806 if (ERROR_OCCURRED(eth_prepare_packet(device->flags, next, 807 (uint8_t *) device->addr->value, ethertype, device->mtu))) { 695 do{ 696 if(ERROR_OCCURRED(eth_prepare_packet(device->flags, next, (uint8_t *) device->addr->value, ethertype, device->mtu))){ 808 697 // release invalid packet 809 698 tmp = pq_detach(next); 810 if (next == packet)699 if(next == packet){ 811 700 packet = tmp; 812 pq_release_remote(eth_globals.net_phone,813 701 } 702 pq_release_remote(eth_globals.net_phone, packet_get_id(next)); 814 703 next = tmp; 815 } else{704 }else{ 816 705 next = pq_next(next); 817 706 } 818 } while(next); 819 707 }while(next); 820 708 // send packet queue 821 if (packet) { 822 netif_send_msg(device->phone, device_id, packet, 823 SERVICE_ETHERNET); 709 if(packet){ 710 netif_send_msg(device->phone, device_id, packet, SERVICE_ETHERNET); 824 711 } 825 712 fibril_rwlock_read_unlock(ð_globals.devices_lock); 826 827 713 return EOK; 828 714 } 829 715 830 int 831 nil_message_standalone(const char *name, ipc_callid_t callid, ipc_call_t *call, 716 int nil_message_standalone(const char *name, ipc_callid_t callid, ipc_call_t *call, 832 717 ipc_call_t *answer, int *answer_count) 833 718 { … … 843 728 *answer_count = 0; 844 729 switch (IPC_GET_METHOD(*call)) { 845 case IPC_M_PHONE_HUNGUP: 846 return EOK; 847 848 case NET_NIL_DEVICE: 849 return eth_device_message(IPC_GET_DEVICE(call), 850 IPC_GET_SERVICE(call), IPC_GET_MTU(call)); 851 case NET_NIL_SEND: 852 ERROR_PROPAGATE(packet_translate_remote(eth_globals.net_phone, 853 &packet, IPC_GET_PACKET(call))); 854 return eth_send_message(IPC_GET_DEVICE(call), packet, 855 IPC_GET_SERVICE(call)); 856 case NET_NIL_PACKET_SPACE: 857 ERROR_PROPAGATE(eth_packet_space_message(IPC_GET_DEVICE(call), 858 &addrlen, &prefix, &content, &suffix)); 859 IPC_SET_ADDR(answer, addrlen); 860 IPC_SET_PREFIX(answer, prefix); 861 IPC_SET_CONTENT(answer, content); 862 IPC_SET_SUFFIX(answer, suffix); 863 *answer_count = 4; 864 return EOK; 865 case NET_NIL_ADDR: 866 ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call), 867 ETH_LOCAL_ADDR, &address)); 868 return measured_strings_reply(address, 1); 869 case NET_NIL_BROADCAST_ADDR: 870 ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call), 871 ETH_BROADCAST_ADDR, &address)); 872 return measured_strings_reply(address, 1); 873 case IPC_M_CONNECT_TO_ME: 874 return eth_register_message(NIL_GET_PROTO(call), 875 IPC_GET_PHONE(call)); 730 case IPC_M_PHONE_HUNGUP: 731 return EOK; 732 case NET_NIL_DEVICE: 733 return eth_device_message(IPC_GET_DEVICE(call), 734 IPC_GET_SERVICE(call), IPC_GET_MTU(call)); 735 case NET_NIL_SEND: 736 ERROR_PROPAGATE(packet_translate_remote(eth_globals.net_phone, &packet, 737 IPC_GET_PACKET(call))); 738 return eth_send_message(IPC_GET_DEVICE(call), packet, 739 IPC_GET_SERVICE(call)); 740 case NET_NIL_PACKET_SPACE: 741 ERROR_PROPAGATE(eth_packet_space_message(IPC_GET_DEVICE(call), 742 &addrlen, &prefix, &content, &suffix)); 743 IPC_SET_ADDR(answer, addrlen); 744 IPC_SET_PREFIX(answer, prefix); 745 IPC_SET_CONTENT(answer, content); 746 IPC_SET_SUFFIX(answer, suffix); 747 *answer_count = 4; 748 return EOK; 749 case NET_NIL_ADDR: 750 ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call), 751 ETH_LOCAL_ADDR, &address)); 752 return measured_strings_reply(address, 1); 753 case NET_NIL_BROADCAST_ADDR: 754 ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call), 755 ETH_BROADCAST_ADDR, &address)); 756 return measured_strings_reply(address, 1); 757 case IPC_M_CONNECT_TO_ME: 758 return eth_register_message(NIL_GET_PROTO(call), 759 IPC_GET_PHONE(call)); 876 760 } 877 761 … … 879 763 } 880 764 765 void eth_receiver(ipc_callid_t iid, ipc_call_t * icall){ 766 ERROR_DECLARE; 767 768 packet_t packet; 769 770 while(true){ 771 // printf("message %d - %d\n", IPC_GET_METHOD(*icall), NET_NIL_FIRST); 772 switch(IPC_GET_METHOD(*icall)){ 773 case NET_NIL_DEVICE_STATE: 774 nil_device_state_msg_local(0, IPC_GET_DEVICE(icall), IPC_GET_STATE(icall)); 775 ipc_answer_0(iid, EOK); 776 break; 777 case NET_NIL_RECEIVED: 778 if(! ERROR_OCCURRED(packet_translate_remote(eth_globals.net_phone, &packet, IPC_GET_PACKET(icall)))){ 779 ERROR_CODE = nil_received_msg_local(0, IPC_GET_DEVICE(icall), packet, 0); 780 } 781 ipc_answer_0(iid, (ipcarg_t) ERROR_CODE); 782 break; 783 default: 784 ipc_answer_0(iid, (ipcarg_t) ENOTSUP); 785 } 786 iid = async_get_call(icall); 787 } 788 } 789 881 790 /** Default thread for new connections. 882 791 * 883 * @param[in] iid 884 * @param[in] icall 792 * @param[in] iid The initial message identifier. 793 * @param[in] icall The initial message call structure. 885 794 * 886 795 */ … … 893 802 ipc_answer_0(iid, EOK); 894 803 895 while 804 while(true) { 896 805 ipc_call_t answer; 897 806 int answer_count; … … 905 814 906 815 /* Process the message */ 907 int res = nil_module_message_standalone(NAME, callid, &call, 908 &answer , &answer_count);816 int res = nil_module_message_standalone(NAME, callid, &call, &answer, 817 &answer_count); 909 818 910 /* 911 * End if told to either by the message or the processing 912 * result. 913 */ 914 if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || 915 (res == EHANGUP)) 819 /* End if said to either by the message or the processing result */ 820 if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP)) 916 821 return; 917 822 … … 926 831 927 832 /* Start the module */ 928 ERROR_PROPAGATE(nil_module_start_standalone(nil_client_connection)); 833 if (ERROR_OCCURRED(nil_module_start_standalone(nil_client_connection))) 834 return ERROR_CODE; 835 929 836 return EOK; 930 837 } -
uspace/srv/net/nil/eth/eth.h
rf2d2c604 re7f6389 32 32 33 33 /** @file 34 * Ethernet module.34 * Ethernet module. 35 35 */ 36 36 37 #ifndef NET_ETH_H_38 #define NET_ETH_H_37 #ifndef __NET_ETH_H__ 38 #define __NET_ETH_H__ 39 39 40 40 #include <fibril_synch.h> … … 45 45 46 46 /** Type definition of the Ethernet global data. 47 * @see eth_globals47 * @see eth_globals 48 48 */ 49 typedef struct eth_globals 49 typedef struct eth_globals eth_globals_t; 50 50 51 51 /** Type definition of the Ethernet device specific data. 52 * @see eth_device52 * @see eth_device 53 53 */ 54 typedef struct eth_device 54 typedef struct eth_device eth_device_t; 55 55 56 56 /** Type definition of the Ethernet device specific data pointer. 57 * @see eth_device57 * @see eth_device 58 58 */ 59 typedef eth_device_t * eth_device_ref;59 typedef eth_device_t * eth_device_ref; 60 60 61 61 /** Type definition of the Ethernet protocol specific data. 62 * @see eth_proto62 * @see eth_proto 63 63 */ 64 typedef struct eth_proto 64 typedef struct eth_proto eth_proto_t; 65 65 66 66 /** Type definition of the Ethernet protocol specific data pointer. 67 * @see eth_proto67 * @see eth_proto 68 68 */ 69 typedef eth_proto_t * eth_proto_ref;69 typedef eth_proto_t * eth_proto_ref; 70 70 71 71 /** Ethernet device map. 72 * Maps devices to the Ethernet device specific data.73 * @see device.h72 * Maps devices to the Ethernet device specific data. 73 * @see device.h 74 74 */ 75 DEVICE_MAP_DECLARE(eth_devices, eth_device_t) ;75 DEVICE_MAP_DECLARE(eth_devices, eth_device_t) 76 76 77 77 /** Ethernet protocol map. 78 * Maps protocol identifiers to the Ethernet protocol specific data.79 * @see int_map.h78 * Maps protocol identifiers to the Ethernet protocol specific data. 79 * @see int_map.h 80 80 */ 81 INT_MAP_DECLARE(eth_protos, eth_proto_t) ;81 INT_MAP_DECLARE(eth_protos, eth_proto_t) 82 82 83 /** Ethernet device specific data. */ 84 struct eth_device { 85 /** Device identifier. */ 83 /** Ethernet device specific data. 84 */ 85 struct eth_device{ 86 /** Device identifier. 87 */ 86 88 device_id_t device_id; 87 /** Device driver service. */ 89 /** Device driver service. 90 */ 88 91 services_t service; 89 /** Driver phone. */ 92 /** Driver phone. 93 */ 90 94 int phone; 91 /** Maximal transmission unit. */ 95 /** Maximal transmission unit. 96 */ 92 97 size_t mtu; 93 94 /** 95 * Various device flags. 96 * @see ETH_DUMMY 97 * @see ETH_MODE_MASK 98 /** Various device flags. 99 * @see ETH_DUMMY 100 * @see ETH_MODE_MASK 98 101 */ 99 102 int flags; 100 101 /** Actual device hardware address.*/103 /** Actual device hardware address. 104 */ 102 105 measured_string_ref addr; 103 /** Actual device hardware address data. */ 104 char *addr_data; 106 /** Actual device hardware address data. 107 */ 108 char * addr_data; 105 109 }; 106 110 107 /** Ethernet protocol specific data. */ 108 struct eth_proto { 109 /** Protocol service. */ 111 /** Ethernet protocol specific data. 112 */ 113 struct eth_proto{ 114 /** Protocol service. 115 */ 110 116 services_t service; 111 /** Protocol identifier. */ 117 /** Protocol identifier. 118 */ 112 119 int protocol; 113 /** Protocol module phone. */ 120 /** Protocol module phone. 121 */ 114 122 int phone; 115 123 }; 116 124 117 /** Ethernet global data. */ 118 struct eth_globals { 119 /** Networking module phone. */ 125 /** Ethernet global data. 126 */ 127 struct eth_globals{ 128 /** Networking module phone. 129 */ 120 130 int net_phone; 121 /** Safety lock for devices. */ 131 /** Safety lock for devices. 132 */ 122 133 fibril_rwlock_t devices_lock; 123 /** All known Ethernet devices. */ 134 /** All known Ethernet devices. 135 */ 124 136 eth_devices_t devices; 125 /** Safety lock for protocols. */ 137 /** Safety lock for protocols. 138 */ 126 139 fibril_rwlock_t protos_lock; 127 128 /** 129 * Protocol map. 130 * Service phone map for each protocol. 140 /** Protocol map. 141 * Service phone map for each protocol. 131 142 */ 132 143 eth_protos_t protos; 133 134 /** Broadcast device hardware address.*/144 /** Broadcast device hardware address. 145 */ 135 146 measured_string_ref broadcast_addr; 136 147 }; -
uspace/srv/net/nil/eth/eth_header.h
rf2d2c604 re7f6389 32 32 33 33 /** @file 34 * Ethernet protocol header definitions.35 * Based on the IEEE802.3-200536 */ 37 38 #ifndef NET_ETH_HEADER_H_39 #define NET_ETH_HEADER_H_34 * Ethernet protocol header definitions. 35 * Based on the IEEE~802.3-2005 36 */ 37 38 #ifndef __NET_ETH_HEADER_H__ 39 #define __NET_ETH_HEADER_H__ 40 40 41 41 #include <sys/types.h> 42 42 43 /** Ethernet address length. */ 44 #define ETH_ADDR 6 45 46 /** Ethernet header preamble value. */ 43 /** Ethernet address length. 44 */ 45 #define ETH_ADDR 6 46 47 /** Ethernet header preamble value. 48 */ 47 49 #define ETH_PREAMBLE 0x55 48 50 49 /** Ethernet header start of frame value. */ 50 #define ETH_SFD 0xD5 51 52 /** IEEE 802.2 unordered information control field. */ 51 /** Ethernet header start of frame value. 52 */ 53 #define ETH_SFD 0xD5 54 55 /** IEEE 802.2 unordered information control field. 56 */ 53 57 #define IEEE_8023_2_UI 0x03 54 58 55 59 /** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions. 56 * @see eth_header_snap 57 */ 58 typedef struct eth_header_snap eth_header_snap_t; 59 60 /** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions 61 * pointer. 62 * 63 * @see eth_header_snap 64 */ 65 typedef eth_header_snap_t *eth_header_snap_ref; 60 * @see eth_header_snap 61 */ 62 typedef struct eth_header_snap eth_header_snap_t; 63 64 /** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions pointer. 65 * @see eth_header_snap 66 */ 67 typedef eth_header_snap_t * eth_header_snap_ref; 66 68 67 69 /** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions. 68 * @see eth_header_lsap69 */ 70 typedef struct eth_header_lsap 70 * @see eth_header_lsap 71 */ 72 typedef struct eth_header_lsap eth_header_lsap_t; 71 73 72 74 /** Type definition of the Ethernet header IEEE 802.3 + 802.2 extension pointer. 73 * @see eth_header_lsap74 */ 75 typedef eth_header_lsap_t * eth_header_lsap_ref;75 * @see eth_header_lsap 76 */ 77 typedef eth_header_lsap_t * eth_header_lsap_ref; 76 78 77 79 /** Type definition of the Ethernet header LSAP extension. 78 * @see eth_ieee_lsap79 */ 80 typedef struct eth_ieee_lsap 80 * @see eth_ieee_lsap 81 */ 82 typedef struct eth_ieee_lsap eth_ieee_lsap_t; 81 83 82 84 /** Type definition of the Ethernet header LSAP extension pointer. 83 * @see eth_ieee_lsap84 */ 85 typedef eth_ieee_lsap_t * eth_ieee_lsap_ref;85 * @see eth_ieee_lsap 86 */ 87 typedef eth_ieee_lsap_t * eth_ieee_lsap_ref; 86 88 87 89 /** Type definition of the Ethernet header SNAP extension. 88 * @see eth_snap89 */ 90 typedef struct eth_snap 90 * @see eth_snap 91 */ 92 typedef struct eth_snap eth_snap_t; 91 93 92 94 /** Type definition of the Ethernet header SNAP extension pointer. 93 * @see eth_snap94 */ 95 typedef eth_snap_t * eth_snap_ref;95 * @see eth_snap 96 */ 97 typedef eth_snap_t * eth_snap_ref; 96 98 97 99 /** Type definition of the Ethernet header preamble. 98 * @see preamble99 */ 100 typedef struct eth_preamble 100 * @see preamble 101 */ 102 typedef struct eth_preamble eth_preamble_t; 101 103 102 104 /** Type definition of the Ethernet header preamble pointer. 103 * @see eth_preamble104 */ 105 typedef eth_preamble_t * eth_preamble_ref;105 * @see eth_preamble 106 */ 107 typedef eth_preamble_t * eth_preamble_ref; 106 108 107 109 /** Type definition of the Ethernet header. 108 * @see eth_header109 */ 110 typedef struct eth_header 110 * @see eth_header 111 */ 112 typedef struct eth_header eth_header_t; 111 113 112 114 /** Type definition of the Ethernet header pointer. 113 * @see eth_header114 */ 115 typedef eth_header_t * eth_header_ref;116 117 /** Ethernet header Link Service Access Point extension. */118 struct eth_ieee_lsap { 119 /** 120 115 * @see eth_header 116 */ 117 typedef eth_header_t * eth_header_ref; 118 119 /** Ethernet header Link Service Access Point extension. 120 */ 121 struct eth_ieee_lsap{ 122 /** Destination Service Access Point identifier. 121 123 * The possible values are assigned by an IEEE committee. 122 124 */ 123 125 uint8_t dsap; 124 125 /** 126 * Source Service Access Point identifier. 126 /** Source Service Access Point identifier. 127 127 * The possible values are assigned by an IEEE committee. 128 128 */ 129 129 uint8_t ssap; 130 131 /** 132 * Control parameter. 130 /** Control parameter. 133 131 * The possible values are assigned by an IEEE committee. 134 132 */ … … 136 134 } __attribute__ ((packed)); 137 135 138 /** Ethernet header SNAP extension. */ 139 struct eth_snap { 140 /** Protocol identifier or organization code. */ 136 /** Ethernet header SNAP extension. 137 */ 138 struct eth_snap{ 139 /** Protocol identifier or organization code. 140 */ 141 141 uint8_t protocol[3]; 142 143 /** 144 * Ethernet protocol identifier in the network byte order (big endian). 145 * @see ethernet_protocols.h 142 /** Ethernet protocol identifier in the network byte order (big endian). 143 * @see ethernet_protocols.h 146 144 */ 147 145 uint16_t ethertype; … … 149 147 150 148 /** Ethernet header preamble. 151 * 152 * Used for dummy devices. 153 */ 154 struct eth_preamble { 155 /** 156 * Controlling preamble used for the frame transmission synchronization. 157 * All should be set to ETH_PREAMBLE. 149 * Used for dummy devices. 150 */ 151 struct eth_preamble{ 152 /** Controlling preamble used for the frame transmission synchronization. 153 * All should be set to ETH_PREAMBLE. 158 154 */ 159 155 uint8_t preamble[7]; 160 161 /** 162 * Start of Frame Delimiter used for the frame transmission 163 * synchronization. 164 * Should be set to ETH_SFD. 156 /** Start of Frame Delimiter used for the frame transmission synchronization. 157 * Should be set to ETH_SFD. 165 158 */ 166 159 uint8_t sfd; 167 160 } __attribute__ ((packed)); 168 161 169 /** Ethernet header. */ 170 struct eth_header { 171 /** Destination host Ethernet address (MAC address). */ 162 /** Ethernet header. 163 */ 164 struct eth_header{ 165 /** Destination host Ethernet address (MAC address). 166 */ 172 167 uint8_t destination_address[ETH_ADDR]; 173 /** Source host Ethernet address (MAC address). */ 168 /** Source host Ethernet address (MAC address). 169 */ 174 170 uint8_t source_address[ETH_ADDR]; 175 176 /** 177 * Ethernet protocol identifier in the network byte order (big endian). 178 * @see ethernet_protocols.h 171 /** Ethernet protocol identifier in the network byte order (big endian). 172 * @see ethernet_protocols.h 179 173 */ 180 174 uint16_t ethertype; 181 175 } __attribute__ ((packed)); 182 176 183 /** Ethernet header IEEE 802.3 + 802.2 extension. */ 184 struct eth_header_lsap { 185 /** Ethernet header. */ 177 /** Ethernet header IEEE 802.3 + 802.2 extension. 178 */ 179 struct eth_header_lsap{ 180 /** Ethernet header. 181 */ 186 182 eth_header_t header; 187 188 /** 189 * LSAP extension. 190 * If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being 191 * used. 192 * If DSAP and SSAP fields are equal to ETH_RAW the raw Ethernet packet 193 * without any extensions is being used and the frame content starts 194 * rigth after the two fields. 183 /** LSAP extension. 184 * If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being used. 185 * If DSAP and SSAP fields are equal to ETH_RAW the raw Ethernet packet without any extensions is being used and the frame content starts rigth after the two fields. 195 186 */ 196 187 eth_ieee_lsap_t lsap; 197 188 } __attribute__ ((packed)); 198 189 199 /** Ethernet header IEEE 802.3 + 802.2 + SNAP extensions. */ 200 struct eth_header_snap { 201 /** Ethernet header. */ 190 /** Ethernet header IEEE 802.3 + 802.2 + SNAP extensions. 191 */ 192 struct eth_header_snap{ 193 /** Ethernet header. 194 */ 202 195 eth_header_t header; 203 204 /** 205 * LSAP extension. 206 * If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being 207 * used. 208 * If DSAP and SSAP fields are equal to ETH_RAW the raw Ethernet packet 209 * without any extensions is being used and the frame content starts 210 * rigth after the two fields. 196 /** LSAP extension. 197 * If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being used. 198 * If DSAP and SSAP fields are equal to ETH_RAW the raw Ethernet packet without any extensions is being used and the frame content starts rigth after the two fields. 211 199 */ 212 200 eth_ieee_lsap_t lsap; 213 214 /** SNAP extension.*/201 /** SNAP extension. 202 */ 215 203 eth_snap_t snap; 216 204 } __attribute__ ((packed)); 217 205 218 /** Ethernet Frame Check Sequence. */ 219 typedef uint32_t eth_fcs_t; 220 221 /** Ethernet Frame Check Sequence pointer. */ 222 typedef eth_fcs_t *eth_fcs_ref; 206 /** Ethernet Frame Check Sequence. 207 */ 208 typedef uint32_t eth_fcs_t; 209 210 /** Ethernet Frame Check Sequence pointer. 211 */ 212 typedef eth_fcs_t * eth_fcs_ref; 223 213 224 214 #endif -
uspace/srv/net/nil/eth/eth_module.c
rf2d2c604 re7f6389 36 36 */ 37 37 38 #include "eth.h"39 40 38 #include <async.h> 41 39 #include <stdio.h> … … 50 48 #include <nil_local.h> 51 49 50 #include "eth.h" 51 52 52 int nil_module_start_standalone(async_client_conn_t client_connection) 53 53 { … … 59 59 60 60 ipcarg_t phonehash; 61 if (ERROR_OCCURRED(nil_initialize(net_phone)) ||62 ERROR_OCCURRED(REGISTER_ME(SERVICE_ETHERNET, &phonehash))) {61 if (ERROR_OCCURRED(nil_initialize(net_phone)) 62 || ERROR_OCCURRED(REGISTER_ME(SERVICE_ETHERNET, &phonehash))) { 63 63 pm_destroy(); 64 64 return ERROR_CODE; … … 71 71 } 72 72 73 int 74 nil_module_message_standalone(const char *name, ipc_callid_t callid, 75 ipc_call_t *call, ipc_call_t *answer, int *answer_count) 73 int nil_module_message_standalone(const char *name, ipc_callid_t callid, ipc_call_t *call, 74 ipc_call_t *answer, int *answer_count) 76 75 { 77 76 return nil_message_standalone(name, callid, call, answer, answer_count); -
uspace/srv/net/nil/nildummy/nildummy.h
rf2d2c604 re7f6389 28 28 29 29 /** @addtogroup nildummy 30 * @{30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Dummy network interface layer module.34 * Dummy network interface layer module. 35 35 */ 36 36 37 #ifndef NET_NILDUMMY_H_38 #define NET_NILDUMMY_H_37 #ifndef __NET_NILDUMMY_H__ 38 #define __NET_NILDUMMY_H__ 39 39 40 40 #include <fibril_synch.h> … … 45 45 46 46 /** Type definition of the dummy nil global data. 47 * @see nildummy_globals47 * @see nildummy_globals 48 48 */ 49 typedef struct nildummy_globals 49 typedef struct nildummy_globals nildummy_globals_t; 50 50 51 51 /** Type definition of the dummy nil device specific data. 52 * @see nildummy_device52 * @see nildummy_device 53 53 */ 54 typedef struct nildummy_device 54 typedef struct nildummy_device nildummy_device_t; 55 55 56 56 /** Type definition of the dummy nil device specific data pointer. 57 * @see nildummy_device57 * @see nildummy_device 58 58 */ 59 typedef nildummy_device_t * nildummy_device_ref;59 typedef nildummy_device_t * nildummy_device_ref; 60 60 61 61 /** Type definition of the dummy nil protocol specific data. 62 * @see nildummy_proto62 * @see nildummy_proto 63 63 */ 64 64 typedef struct nildummy_proto nildummy_proto_t; 65 65 66 66 /** Type definition of the dummy nil protocol specific data pointer. 67 * @see nildummy_proto67 * @see nildummy_proto 68 68 */ 69 typedef nildummy_proto_t * nildummy_proto_ref;69 typedef nildummy_proto_t * nildummy_proto_ref; 70 70 71 71 /** Dummy nil device map. 72 * Maps devices to the dummy nil device specific data.73 * @see device.h72 * Maps devices to the dummy nil device specific data. 73 * @see device.h 74 74 */ 75 DEVICE_MAP_DECLARE(nildummy_devices, nildummy_device_t) ;75 DEVICE_MAP_DECLARE(nildummy_devices, nildummy_device_t) 76 76 77 /** Dummy nil device specific data. */ 78 struct nildummy_device { 79 /** Device identifier. */ 77 /** Dummy nil device specific data. 78 */ 79 struct nildummy_device{ 80 /** Device identifier. 81 */ 80 82 device_id_t device_id; 81 /** Device driver service. */ 83 /** Device driver service. 84 */ 82 85 services_t service; 83 /** Driver phone. */ 86 /** Driver phone. 87 */ 84 88 int phone; 85 /** Maximal transmission unit. */ 89 /** Maximal transmission unit. 90 */ 86 91 size_t mtu; 87 /** Actual device hardware address. */ 92 /** Actual device hardware address. 93 */ 88 94 measured_string_ref addr; 89 /** Actual device hardware address data. */ 90 char *addr_data; 95 /** Actual device hardware address data. 96 */ 97 char * addr_data; 91 98 }; 92 99 93 /** Dummy nil protocol specific data. */ 94 struct nildummy_proto { 95 /** Protocol service. */ 100 /** Dummy nil protocol specific data. 101 */ 102 struct nildummy_proto{ 103 /** Protocol service. 104 */ 96 105 services_t service; 97 /** Protocol module phone. */ 106 /** Protocol module phone. 107 */ 98 108 int phone; 99 109 }; 100 110 101 /** Dummy nil global data. */ 102 struct nildummy_globals { 103 /** Networking module phone. */ 111 /** Dummy nil global data. 112 */ 113 struct nildummy_globals{ 114 /** Networking module phone. 115 */ 104 116 int net_phone; 105 /** Safety lock for devices. */ 117 /** Safety lock for devices. 118 */ 106 119 fibril_rwlock_t devices_lock; 107 /** All known Ethernet devices. */ 120 /** All known Ethernet devices. 121 */ 108 122 nildummy_devices_t devices; 109 /** Safety lock for protocols. */ 123 /** Safety lock for protocols. 124 */ 110 125 fibril_rwlock_t protos_lock; 111 /** Default protocol. */ 126 /** Default protocol. 127 */ 112 128 nildummy_proto_t proto; 113 129 }; -
uspace/srv/net/nil/nildummy/nildummy_module.c
rf2d2c604 re7f6389 59 59 60 60 ipcarg_t phonehash; 61 if (ERROR_OCCURRED(nil_initialize(net_phone)) ||62 ERROR_OCCURRED(REGISTER_ME(SERVICE_NILDUMMY, &phonehash))){61 if (ERROR_OCCURRED(nil_initialize(net_phone)) 62 || ERROR_OCCURRED(REGISTER_ME(SERVICE_NILDUMMY, &phonehash))){ 63 63 pm_destroy(); 64 64 return ERROR_CODE; … … 71 71 } 72 72 73 int 74 nil_module_message_standalone(const char *name, ipc_callid_t callid, 73 int nil_module_message_standalone(const char *name, ipc_callid_t callid, 75 74 ipc_call_t *call, ipc_call_t *answer, int *answer_count) 76 75 {
Note:
See TracChangeset
for help on using the changeset viewer.