Rev 4307 | Rev 4350 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4307 | Rev 4332 | ||
|---|---|---|---|
| Line 52... | Line 52... | ||
| 52 | #include "../../include/ethernet_lsap.h" |
52 | #include "../../include/ethernet_lsap.h" |
| 53 | #include "../../include/ethernet_protocols.h" |
53 | #include "../../include/ethernet_protocols.h" |
| 54 | #include "../../include/protocol_map.h" |
54 | #include "../../include/protocol_map.h" |
| 55 | #include "../../include/device.h" |
55 | #include "../../include/device.h" |
| 56 | #include "../../include/netif_interface.h" |
56 | #include "../../include/netif_interface.h" |
| - | 57 | #include "../../include/net_interface.h" |
|
| 57 | #include "../../include/nil_interface.h" |
58 | #include "../../include/nil_interface.h" |
| 58 | #include "../../include/il_interface.h" |
59 | #include "../../include/il_interface.h" |
| 59 | 60 | ||
| 60 | #include "../../structures/measured_strings.h" |
61 | #include "../../structures/measured_strings.h" |
| 61 | #include "../../structures/packet/packet_client.h" |
62 | #include "../../structures/packet/packet_client.h" |
| Line 67... | Line 68... | ||
| 67 | 68 | ||
| 68 | #define ETH_PREFIX ( sizeof( eth_header_t ) + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t )) |
69 | #define ETH_PREFIX ( sizeof( eth_header_t ) + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t )) |
| 69 | #define ETH_SUFFIX sizeof( eth_fcs_t ) |
70 | #define ETH_SUFFIX sizeof( eth_fcs_t ) |
| 70 | #define ETH_MAX_CONTENT 1500 |
71 | #define ETH_MAX_CONTENT 1500 |
| 71 | #define ETH_MIN_CONTENT 46 |
72 | #define ETH_MIN_CONTENT 46 |
| 72 | #define ETH_MAX_TAGGED_CONTENT ( ETH_MAX_CONTENT - sizeof( eth_header_lsap_t ) - sizeof( eth_header_snap_t )) |
73 | #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 )) |
| 73 | #define ETH_MIN_TAGGED_CONTENT ( ETH_MIN_CONTENT - sizeof( eth_header_lsap_t ) - sizeof( eth_header_snap_t )) |
74 | #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 )) |
| - | 75 | ||
| - | 76 | #define ETH_DUMMY_SHIFT 0 |
|
| - | 77 | #define ETH_MODE_SHIFT 1 |
|
| - | 78 | ||
| - | 79 | /** Dummy device flag. |
|
| - | 80 | * Preamble and FCS are mandatory part of the packets. |
|
| - | 81 | */ |
|
| - | 82 | #define ETH_DUMMY ( 1 << ETH_DUMMY_SHIFT ) |
|
| - | 83 | #define IS_DUMMY( flags ) (( flags ) & ETH_DUMMY ) |
|
| - | 84 | ||
| - | 85 | /** Device mode flags. |
|
| - | 86 | * @see ETH_DIX |
|
| - | 87 | * @see ETH_8023_2_LSAP |
|
| - | 88 | * @see ETH_8023_2_SNAP |
|
| - | 89 | */ |
|
| - | 90 | #define ETH_MODE_MASK ( 3 << ETH_MODE_SHIFT ) |
|
| - | 91 | #define ETH_DIX ( 1 << ETH_MODE_SHIFT ) |
|
| - | 92 | #define IS_DIX( flags ) ((( flags ) & ETH_MODE_MASK ) == ETH_DIX ) |
|
| - | 93 | #define ETH_8023_2_LSAP ( 2 << ETH_MODE_SHIFT ) |
|
| - | 94 | #define IS_8023_2_LSAP( flags ) ((( flags ) & ETH_MODE_MASK ) == ETH_8023_2_LSAP ) |
|
| - | 95 | #define ETH_8023_2_SNAP ( 3 << ETH_MODE_SHIFT ) |
|
| - | 96 | #define IS_8023_2_SNAP( flags ) ((( flags ) & ETH_MODE_MASK ) == ETH_8023_2_SNAP ) |
|
| 74 | 97 | ||
| 75 | typedef enum eth_addr_type eth_addr_type_t; |
98 | typedef enum eth_addr_type eth_addr_type_t; |
| 76 | typedef eth_addr_type_t * eth_addr_type_ref; |
99 | typedef eth_addr_type_t * eth_addr_type_ref; |
| 77 | 100 | ||
| 78 | enum eth_addr_type{ |
101 | enum eth_addr_type{ |
| Line 98... | Line 121... | ||
| 98 | int nil_receive_msg( int nil_phone, device_id_t device_id, packet_t packet ); |
121 | int nil_receive_msg( int nil_phone, device_id_t device_id, packet_t packet ); |
| 99 | int nil_register_message( services_t service, int phone ); |
122 | int nil_register_message( services_t service, int phone ); |
| 100 | int eth_packet_space_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ); |
123 | int eth_packet_space_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ); |
| 101 | int eth_addr_message( device_id_t device_id, eth_addr_type_t type, measured_string_ref * address ); |
124 | int eth_addr_message( device_id_t device_id, eth_addr_type_t type, measured_string_ref * address ); |
| 102 | int eth_send_message( device_id_t device_id, packet_t packet, services_t sender ); |
125 | int eth_send_message( device_id_t device_id, packet_t packet, services_t sender ); |
| 103 | eth_proto_ref eth_process_packet( int dummy, packet_t packet ); |
126 | eth_proto_ref eth_process_packet( int flags, packet_t packet ); |
| 104 | int eth_prepare_packet( int dummy, packet_t packet, uint8_t * src_addr, int ethertype ); |
127 | int eth_prepare_packet( int flags, packet_t packet, uint8_t * src_addr, int ethertype ); |
| 105 | 128 | ||
| 106 | int nil_device_state_msg( int nil_phone, device_id_t device_id, int state ){ |
129 | int nil_device_state_msg( int nil_phone, device_id_t device_id, int state ){ |
| 107 | int index; |
130 | int index; |
| 108 | eth_proto_ref proto; |
131 | eth_proto_ref proto; |
| 109 | 132 | ||
| Line 140... | Line 163... | ||
| 140 | int eth_device_message( device_id_t device_id, services_t service, size_t mtu ){ |
163 | int eth_device_message( device_id_t device_id, services_t service, size_t mtu ){ |
| 141 | ERROR_DECLARE; |
164 | ERROR_DECLARE; |
| 142 | 165 | ||
| 143 | eth_device_ref device; |
166 | eth_device_ref device; |
| 144 | int index; |
167 | int index; |
| - | 168 | measured_string_t names[ 2 ] = {{ "ETH_MODE", 8 }, { "ETH_DUMMY", 9 }}; |
|
| - | 169 | measured_string_ref configuration; |
|
| - | 170 | int count = 2; |
|
| - | 171 | char * data; |
|
| 145 | 172 | ||
| 146 | rwlock_write_lock( & eth_globals.devices_lock ); |
173 | rwlock_write_lock( & eth_globals.devices_lock ); |
| 147 | // an existing device? |
174 | // an existing device? |
| 148 | device = eth_devices_find( & eth_globals.devices, device_id ); |
175 | device = eth_devices_find( & eth_globals.devices, device_id ); |
| 149 | if( device ){ |
176 | if( device ){ |
| Line 160... | Line 187... | ||
| 160 | // create a new device |
187 | // create a new device |
| 161 | device = ( eth_device_ref ) malloc( sizeof( eth_device_t )); |
188 | device = ( eth_device_ref ) malloc( sizeof( eth_device_t )); |
| 162 | if( ! device ) return ENOMEM; |
189 | if( ! device ) return ENOMEM; |
| 163 | device->device_id = device_id; |
190 | device->device_id = device_id; |
| 164 | device->service = service; |
191 | device->service = service; |
| - | 192 | device->flags = 0; |
|
| 165 | device->mtu = (( mtu > 0 ) && ( mtu <= ETH_MAX_TAGGED_CONTENT )) ? mtu : ETH_MAX_TAGGED_CONTENT; |
193 | device->mtu = (( mtu > 0 ) && ( mtu <= ETH_MAX_TAGGED_CONTENT( device->flags ))) ? mtu : ETH_MAX_TAGGED_CONTENT( device->flags ); |
| - | 194 | configuration = & names[ 0 ]; |
|
| - | 195 | if( ERROR_OCCURRED( net_get_device_conf_req( eth_globals.net_phone, device->device_id, & configuration, count, & data ))){ |
|
| - | 196 | rwlock_write_unlock( & eth_globals.devices_lock ); |
|
| - | 197 | free( device ); |
|
| - | 198 | return ERROR_CODE; |
|
| - | 199 | } |
|
| - | 200 | if( configuration ){ |
|
| - | 201 | if( ! str_lcmp( configuration[ 0 ].value, "DIX", configuration[ 0 ].length )){ |
|
| - | 202 | device->flags |= ETH_DIX; |
|
| - | 203 | }else if( ! str_lcmp( configuration[ 0 ].value, "8023_2_LSAP", configuration[ 0 ].length )){ |
|
| 166 | // TODO get dummy setting |
204 | // TODO 8023_2_LSAP |
| - | 205 | printf( "8023_2_LSAP is not supported (yet?), DIX used instead\n" ); |
|
| 167 | device->dummy = 0; |
206 | device->flags |= ETH_DIX; |
| - | 207 | }else device->flags |= ETH_8023_2_SNAP; |
|
| - | 208 | if(( configuration[ 1 ].value ) && ( configuration[ 1 ].value[ 0 ] == 'y' )){ |
|
| - | 209 | device->flags |= ETH_DUMMY; |
|
| - | 210 | } |
|
| - | 211 | net_free_settings( configuration, data ); |
|
| - | 212 | }else{ |
|
| - | 213 | device->flags |= ETH_8023_2_SNAP; |
|
| - | 214 | } |
|
| 168 | // bind the device driver |
215 | // bind the device driver |
| 169 | device->phone = netif_bind_service( device->service, device->device_id, SERVICE_ETHERNET, eth_receiver ); |
216 | device->phone = netif_bind_service( device->service, device->device_id, SERVICE_ETHERNET, eth_receiver ); |
| 170 | if( device->phone < 0 ){ |
217 | if( device->phone < 0 ){ |
| 171 | rwlock_write_unlock( & eth_globals.devices_lock ); |
218 | rwlock_write_unlock( & eth_globals.devices_lock ); |
| 172 | free( device ); |
219 | free( device ); |
| Line 185... | Line 232... | ||
| 185 | free( device->addr ); |
232 | free( device->addr ); |
| 186 | free( device->addr_data ); |
233 | free( device->addr_data ); |
| 187 | free( device ); |
234 | free( device ); |
| 188 | return index; |
235 | return index; |
| 189 | } |
236 | } |
| 190 | printf( "New device registered:\n\tid\t= %d\n\tservice\t= %d\n\tMTU\t= %d\n\taddress\t= %X:%X:%X:%X:%X:%X\n", device->device_id, device->service, device->mtu, device->addr_data[ 0 ], device->addr_data[ 1 ], device->addr_data[ 2 ], device->addr_data[ 3 ], device->addr_data[ 4 ], device->addr_data[ 5 ] ); |
237 | printf( "New device registered:\n\tid\t= %d\n\tservice\t= %d\n\tMTU\t= %d\n\taddress\t= %X:%X:%X:%X:%X:%X\n\tflags\t= 0x%x\n", device->device_id, device->service, device->mtu, device->addr_data[ 0 ], device->addr_data[ 1 ], device->addr_data[ 2 ], device->addr_data[ 3 ], device->addr_data[ 4 ], device->addr_data[ 5 ], device->flags ); |
| 191 | } |
238 | } |
| 192 | rwlock_write_unlock( & eth_globals.devices_lock ); |
239 | rwlock_write_unlock( & eth_globals.devices_lock ); |
| 193 | return EOK; |
240 | return EOK; |
| 194 | } |
241 | } |
| 195 | 242 | ||
| 196 | eth_proto_ref eth_process_packet( int dummy, packet_t packet ){ |
243 | eth_proto_ref eth_process_packet( int flags, packet_t packet ){ |
| 197 | ERROR_DECLARE; |
244 | ERROR_DECLARE; |
| 198 | 245 | ||
| 199 | eth_header_ex_ref header; |
246 | eth_header_ex_ref header; |
| 200 | size_t length; |
247 | size_t length; |
| 201 | int type; |
248 | int type; |
| 202 | size_t prefix; |
249 | size_t prefix; |
| 203 | size_t suffix; |
250 | size_t suffix; |
| 204 | eth_fcs_ref fcs; |
251 | eth_fcs_ref fcs; |
| 205 | 252 | ||
| 206 | length = packet_get_data_length( packet ); |
253 | length = packet_get_data_length( packet ); |
| 207 | if( dummy ){ |
254 | if( IS_DUMMY( flags )){ |
| 208 | packet_trim( packet, sizeof( eth_preamble_t ), 0 ); |
255 | packet_trim( packet, sizeof( eth_preamble_t ), 0 ); |
| 209 | } |
256 | } |
| 210 | if( length <= sizeof( eth_header_t ) + ETH_MIN_CONTENT + ETH_SUFFIX ) return NULL; |
257 | if( length < sizeof( eth_header_t ) + ETH_MIN_CONTENT + ( IS_DUMMY( flags ) ? ETH_SUFFIX : 0 )) return NULL; |
| 211 | header = ( eth_header_ex_ref ) packet_get_data( packet ); |
258 | header = ( eth_header_ex_ref ) packet_get_data( packet ); |
| 212 | type = ntohs( header->header.ethertype ); |
259 | type = ntohs( header->header.ethertype ); |
| 213 | if( type >= ETH_MIN_PROTO ){ |
260 | if( type >= ETH_MIN_PROTO ){ |
| 214 | // DIX Ethernet |
261 | // DIX Ethernet |
| 215 | prefix = sizeof( eth_header_t ); |
262 | prefix = sizeof( eth_header_t ); |
| 216 | suffix = sizeof( eth_fcs_t ); |
263 | suffix = 0; |
| 217 | fcs = (( void * ) header ) + length - suffix; |
264 | fcs = (( void * ) header ) + length - sizeof( eth_fcs_t ); |
| 218 | }else if( type <= ETH_MAX_CONTENT ){ |
265 | }else if( type <= ETH_MAX_CONTENT ){ |
| 219 | // translate "LSAP" values |
266 | // translate "LSAP" values |
| 220 | if(( header->lsap.dsap == ETH_LSAP_GLSAP ) && ( header->lsap.ssap == ETH_LSAP_GLSAP )){ |
267 | if(( header->lsap.dsap == ETH_LSAP_GLSAP ) && ( header->lsap.ssap == ETH_LSAP_GLSAP )){ |
| 221 | // raw packet |
268 | // raw packet |
| 222 | // discard |
269 | // discard |
| Line 236... | Line 283... | ||
| 236 | suffix += length - prefix - type; |
283 | suffix += length - prefix - type; |
| 237 | }else{ |
284 | }else{ |
| 238 | // invalid length/type, should not occurr |
285 | // invalid length/type, should not occurr |
| 239 | return NULL; |
286 | return NULL; |
| 240 | } |
287 | } |
| 241 | if( dummy ){ |
288 | if( IS_DUMMY( flags )){ |
| 242 | if(( ~ compute_crc32( ~ 0, & header->header.dest, ((( void * ) fcs ) - (( void * ) & header->header.dest )) * 8 )) != ntohl( * fcs )){ |
289 | if(( ~ compute_crc32( ~ 0, & header->header.dest, ((( void * ) fcs ) - (( void * ) & header->header.dest )) * 8 )) != ntohl( * fcs )){ |
| 243 | return NULL; |
290 | return NULL; |
| 244 | } |
291 | } |
| - | 292 | suffix += sizeof( eth_fcs_t ); |
|
| 245 | } |
293 | } |
| 246 | if( ERROR_OCCURRED( packet_set_addr( packet, header->header.src, header->header.dest, ETH_ADDR )) |
294 | if( ERROR_OCCURRED( packet_set_addr( packet, header->header.src, header->header.dest, ETH_ADDR )) |
| 247 | || ERROR_OCCURRED( packet_trim( packet, prefix, suffix ))){ |
295 | || ERROR_OCCURRED( packet_trim( packet, prefix, suffix ))){ |
| 248 | return NULL; |
296 | return NULL; |
| 249 | } |
297 | } |
| Line 252... | Line 300... | ||
| 252 | 300 | ||
| 253 | int nil_received_msg( int nil_phone, device_id_t device_id, packet_t packet, services_t target ){ |
301 | int nil_received_msg( int nil_phone, device_id_t device_id, packet_t packet, services_t target ){ |
| 254 | eth_proto_ref proto; |
302 | eth_proto_ref proto; |
| 255 | packet_t next; |
303 | packet_t next; |
| 256 | eth_device_ref device; |
304 | eth_device_ref device; |
| 257 | int dummy; |
305 | int flags; |
| 258 | 306 | ||
| 259 | rwlock_read_lock( & eth_globals.devices_lock ); |
307 | rwlock_read_lock( & eth_globals.devices_lock ); |
| 260 | device = eth_devices_find( & eth_globals.devices, device_id ); |
308 | device = eth_devices_find( & eth_globals.devices, device_id ); |
| 261 | if( ! device ){ |
309 | if( ! device ){ |
| 262 | rwlock_read_unlock( & eth_globals.devices_lock ); |
310 | rwlock_read_unlock( & eth_globals.devices_lock ); |
| 263 | return ENOENT; |
311 | return ENOENT; |
| 264 | } |
312 | } |
| 265 | dummy = device->dummy; |
313 | flags = device->flags; |
| 266 | rwlock_read_unlock( & eth_globals.devices_lock ); |
314 | rwlock_read_unlock( & eth_globals.devices_lock ); |
| 267 | rwlock_read_lock( & eth_globals.protos_lock ); |
315 | rwlock_read_lock( & eth_globals.protos_lock ); |
| 268 | do{ |
316 | do{ |
| 269 | next = pq_detach( packet ); |
317 | next = pq_detach( packet ); |
| 270 | proto = eth_process_packet( dummy, packet ); |
318 | proto = eth_process_packet( flags, packet ); |
| 271 | if( proto ){ |
319 | if( proto ){ |
| 272 | il_received_msg( proto->phone, device_id, packet, proto->service ); |
320 | il_received_msg( proto->phone, device_id, packet, proto->service ); |
| 273 | }else{ |
321 | }else{ |
| 274 | // drop invalid/unknown |
322 | // drop invalid/unknown |
| 275 | pq_release( eth_globals.net_phone, packet_get_id( packet )); |
323 | pq_release( eth_globals.net_phone, packet_get_id( packet )); |
| Line 349... | Line 397... | ||
| 349 | printf( "New protocol registered:\n\tprotocol\t= 0x%x\n\tservice\t= %d\n\tphone\t= %d\n", proto->protocol, proto->service, proto->phone ); |
397 | printf( "New protocol registered:\n\tprotocol\t= 0x%x\n\tservice\t= %d\n\tphone\t= %d\n", proto->protocol, proto->service, proto->phone ); |
| 350 | rwlock_write_unlock( & eth_globals.protos_lock ); |
398 | rwlock_write_unlock( & eth_globals.protos_lock ); |
| 351 | return EOK; |
399 | return EOK; |
| 352 | } |
400 | } |
| 353 | 401 | ||
| 354 | int eth_prepare_packet( int dummy, packet_t packet, uint8_t * src_addr, int ethertype ){ |
402 | int eth_prepare_packet( int flags, packet_t packet, uint8_t * src_addr, int ethertype ){ |
| 355 | eth_header_ex_ref header; |
403 | eth_header_ex_ref header; |
| - | 404 | eth_header_ref header_dix; |
|
| 356 | eth_fcs_ref fcs; |
405 | eth_fcs_ref fcs; |
| 357 | uint8_t * src; |
406 | uint8_t * src; |
| 358 | uint8_t * dest; |
407 | uint8_t * dest; |
| 359 | int length; |
408 | int length; |
| 360 | int i; |
409 | int i; |
| 361 | void * padding; |
410 | void * padding; |
| 362 | eth_preamble_ref preamble; |
411 | eth_preamble_ref preamble; |
| 363 | 412 | ||
| - | 413 | length = packet_get_addr( packet, & src, & dest ); |
|
| - | 414 | if( length < 0 ) return length; |
|
| - | 415 | if( length < ETH_ADDR ) return EINVAL; |
|
| 364 | length = packet_get_data_length( packet ); |
416 | length = packet_get_data_length( packet ); |
| 365 | if( length > ETH_MAX_TAGGED_CONTENT ) return EINVAL; |
417 | if( length > ETH_MAX_TAGGED_CONTENT( flags )) return EINVAL; |
| 366 | if( length < ETH_MIN_TAGGED_CONTENT ){ |
418 | if( length < ETH_MIN_TAGGED_CONTENT( flags )){ |
| 367 | padding = packet_suffix( packet, ETH_MIN_TAGGED_CONTENT - length ); |
419 | padding = packet_suffix( packet, ETH_MIN_TAGGED_CONTENT( flags ) - length ); |
| 368 | if( ! padding ) return ENOMEM; |
420 | if( ! padding ) return ENOMEM; |
| 369 | bzero( padding, ETH_MIN_TAGGED_CONTENT - length ); |
421 | bzero( padding, ETH_MIN_TAGGED_CONTENT( flags ) - length ); |
| 370 | } |
422 | } |
| 371 | if( dummy ){ |
423 | if( IS_DUMMY( flags )){ |
| 372 | preamble = PACKET_PREFIX( packet, eth_preamble_t ); |
424 | preamble = PACKET_PREFIX( packet, eth_preamble_t ); |
| 373 | if( ! preamble ) return ENOMEM; |
425 | if( ! preamble ) return ENOMEM; |
| 374 | for( i = 0; i < 7; ++ i ) preamble->preamble[ i ] = ETH_PREAMBLE; |
426 | for( i = 0; i < 7; ++ i ) preamble->preamble[ i ] = ETH_PREAMBLE; |
| 375 | preamble->sfd = ETH_SFD; |
427 | preamble->sfd = ETH_SFD; |
| 376 | } |
428 | } |
| - | 429 | // TODO LSAP only device |
|
| - | 430 | if( IS_DIX( flags ) || IS_8023_2_LSAP( flags )){ |
|
| - | 431 | header_dix = PACKET_PREFIX( packet, eth_header_t ); |
|
| - | 432 | header_dix->ethertype = ( uint16_t ) ethertype; |
|
| - | 433 | memcpy( header_dix->src, src_addr, ETH_ADDR ); |
|
| - | 434 | memcpy( header_dix->dest, dest, ETH_ADDR ); |
|
| - | 435 | src = & header_dix->dest[ 0 ]; |
|
| - | 436 | }else if( IS_8023_2_SNAP( flags )){ |
|
| 377 | header = PACKET_PREFIX( packet, eth_header_ex_t ); |
437 | header = PACKET_PREFIX( packet, eth_header_ex_t ); |
| 378 | if( ! header ) return ENOMEM; |
438 | if( ! header ) return ENOMEM; |
| 379 | header->header.ethertype = htons( length + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t )); |
439 | header->header.ethertype = htons( length + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t )); |
| 380 | header->lsap.dsap = ( uint16_t ) ETH_LSAP_SNAP; |
440 | header->lsap.dsap = ( uint16_t ) ETH_LSAP_SNAP; |
| 381 | header->lsap.ssap = header->lsap.dsap; |
441 | header->lsap.ssap = header->lsap.dsap; |
| 382 | header->lsap.ctrl = 0; |
442 | header->lsap.ctrl = 0; |
| 383 | for( i = 0; i < 3; ++ i ) header->snap.proto[ i ] = 0; |
443 | for( i = 0; i < 3; ++ i ) header->snap.proto[ i ] = 0; |
| 384 | header->snap.ethertype = ( uint16_t ) ethertype; |
444 | header->snap.ethertype = ( uint16_t ) ethertype; |
| 385 | length = packet_get_addr( packet, & src, & dest ); |
445 | memcpy( header->header.src, src_addr, ETH_ADDR ); |
| 386 | if( length < 0 ) return length; |
- | |
| 387 | if( length < ETH_ADDR ) return EINVAL; |
- | |
| 388 | memcpy( header->header.src, src_addr, ETH_ADDR ); |
446 | memcpy( header->header.dest, dest, ETH_ADDR ); |
| 389 | memcpy( header->header.dest, dest, ETH_ADDR ); |
447 | src = & header->header.dest[ 0 ]; |
| - | 448 | } |
|
| 390 | if( dummy ){ |
449 | if( IS_DUMMY( flags )){ |
| 391 | fcs = PACKET_SUFFIX( packet, eth_fcs_t ); |
450 | fcs = PACKET_SUFFIX( packet, eth_fcs_t ); |
| 392 | if( ! fcs ) return ENOMEM; |
451 | if( ! fcs ) return ENOMEM; |
| 393 | * fcs = htonl( ~ compute_crc32( ~ 0, & header->header.dest, ((( void * ) fcs ) - (( void * ) & header->header.dest )) * 8 )); |
452 | * fcs = htonl( ~ compute_crc32( ~ 0, src, ((( void * ) fcs ) - (( void * ) src )) * 8 )); |
| 394 | } |
453 | } |
| 395 | return EOK; |
454 | return EOK; |
| 396 | } |
455 | } |
| 397 | 456 | ||
| 398 | int eth_send_message( device_id_t device_id, packet_t packet, services_t sender ){ |
457 | int eth_send_message( device_id_t device_id, packet_t packet, services_t sender ){ |
| Line 415... | Line 474... | ||
| 415 | return ENOENT; |
474 | return ENOENT; |
| 416 | } |
475 | } |
| 417 | // process packet queue |
476 | // process packet queue |
| 418 | next = packet; |
477 | next = packet; |
| 419 | do{ |
478 | do{ |
| 420 | if( ERROR_OCCURRED( eth_prepare_packet( device->dummy, next, ( uint8_t * ) device->addr->value, ethertype ))){ |
479 | if( ERROR_OCCURRED( eth_prepare_packet( device->flags, next, ( uint8_t * ) device->addr->value, ethertype ))){ |
| 421 | // release invalid packet |
480 | // release invalid packet |
| 422 | tmp = pq_detach( next ); |
481 | tmp = pq_detach( next ); |
| 423 | pq_release( eth_globals.net_phone, packet_get_id( next )); |
482 | pq_release( eth_globals.net_phone, packet_get_id( next )); |
| 424 | next = tmp; |
483 | next = tmp; |
| 425 | }else{ |
484 | }else{ |
| Line 468... | Line 527... | ||
| 468 | ERROR_DECLARE; |
527 | ERROR_DECLARE; |
| 469 | 528 | ||
| 470 | packet_t packet; |
529 | packet_t packet; |
| 471 | 530 | ||
| 472 | while( true ){ |
531 | while( true ){ |
| - | 532 | // printf( "message %d - %d\n", IPC_GET_METHOD( * icall ), NET_NIL_FIRST ); |
|
| 473 | switch( IPC_GET_METHOD( * icall )){ |
533 | switch( IPC_GET_METHOD( * icall )){ |
| 474 | case NET_NIL_DEVICE_STATE: |
534 | case NET_NIL_DEVICE_STATE: |
| 475 | nil_device_state_msg( 0, IPC_GET_DEVICE( icall ), IPC_GET_STATE( icall )); |
535 | nil_device_state_msg( 0, IPC_GET_DEVICE( icall ), IPC_GET_STATE( icall )); |
| 476 | ipc_answer_0( iid, EOK ); |
536 | ipc_answer_0( iid, EOK ); |
| 477 | break; |
537 | break; |