Rev 4243 | Rev 4307 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4243 | Rev 4261 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Lukas Mejdrech |
2 | * Copyright (c) 2009 Lukas Mejdrech |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup eth |
29 | /** @addtogroup eth |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** @file |
33 | /** @file |
34 | * Ethernet module implementation. |
34 | * Ethernet module implementation. |
35 | * @see eth.h |
35 | * @see eth.h |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include <async.h> |
38 | #include <async.h> |
39 | #include <malloc.h> |
39 | #include <malloc.h> |
40 | #include <mem.h> |
40 | #include <mem.h> |
41 | #include <stdio.h> |
41 | #include <stdio.h> |
42 | 42 | ||
43 | #include <ipc/ipc.h> |
43 | #include <ipc/ipc.h> |
44 | #include <ipc/services.h> |
44 | #include <ipc/services.h> |
45 | 45 | ||
46 | #include "../../err.h" |
46 | #include "../../err.h" |
47 | #include "../../messages.h" |
47 | #include "../../messages.h" |
48 | #include "../../modules.h" |
48 | #include "../../modules.h" |
49 | 49 | ||
50 | #include "../../include/byteorder.h" |
50 | #include "../../include/byteorder.h" |
51 | #include "../../include/crc.h" |
51 | #include "../../include/crc.h" |
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_messages.h" |
56 | #include "../../include/netif_messages.h" |
- | 57 | #include "../../include/nil_messages.h" |
|
57 | 58 | ||
58 | #include "../../structures/measured_strings.h" |
59 | #include "../../structures/measured_strings.h" |
59 | #include "../../structures/packet/packet.h" |
- | |
60 | #include "../../structures/packet/packet_client.h" |
60 | #include "../../structures/packet/packet_client.h" |
61 | 61 | ||
- | 62 | #include "../nil_module.h" |
|
- | 63 | #include "../nil_wrappers.h" |
|
- | 64 | ||
62 | #include "eth.h" |
65 | #include "eth.h" |
63 | #include "eth_header.h" |
66 | #include "eth_header.h" |
64 | //#include "eth_messages.h" |
- | |
65 | #include "eth_module.h" |
- | |
66 | 67 | ||
67 | #define ETH_PREFIX ( sizeof( eth_header_t ) + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t )) |
68 | #define ETH_PREFIX ( sizeof( eth_header_t ) + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t )) |
68 | #define ETH_SUFFIX sizeof( eth_fcs_t ) |
69 | #define ETH_SUFFIX sizeof( eth_fcs_t ) |
69 | #define ETH_MAX_CONTENT 1500 |
70 | #define ETH_MAX_CONTENT 1500 |
70 | #define ETH_MIN_CONTENT 46 |
71 | #define ETH_MIN_CONTENT 46 |
71 | #define ETH_MAX_TAGGED_CONTENT ( ETH_MAX_CONTENT - sizeof( eth_header_lsap_t ) - sizeof( eth_header_snap_t )) |
72 | #define ETH_MAX_TAGGED_CONTENT ( ETH_MAX_CONTENT - sizeof( eth_header_lsap_t ) - sizeof( eth_header_snap_t )) |
72 | #define ETH_MIN_TAGGED_CONTENT ( ETH_MIN_CONTENT - sizeof( eth_header_lsap_t ) - sizeof( eth_header_snap_t )) |
73 | #define ETH_MIN_TAGGED_CONTENT ( ETH_MIN_CONTENT - sizeof( eth_header_lsap_t ) - sizeof( eth_header_snap_t )) |
73 | 74 | ||
74 | /** Returns the device identifier message parameter. |
- | |
75 | */ |
- | |
76 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
- | |
77 | - | ||
78 | /** Returns the packet identifier message parameter. |
- | |
79 | */ |
- | |
80 | #define IPC_GET_PACKET( call ) ( packet_id_t ) IPC_GET_ARG2( * call ) |
- | |
81 | - | ||
82 | #define IPC_GET_STATE( call ) ( device_state_t ) IPC_GET_ARG2( * call ) |
- | |
83 | - | ||
84 | /** Returns the protocol service message parameter. |
- | |
85 | */ |
- | |
86 | #define IPC_GET_PROTO( call ) ( services_t ) IPC_GET_ARG2( * call ) |
- | |
87 | - | ||
88 | /** Returns the device driver service message parameter. |
- | |
89 | */ |
- | |
90 | #define IPC_GET_SERVICE( call ) ( services_t ) IPC_GET_ARG3( * call ) |
- | |
91 | - | ||
92 | #define IPC_GET_MTU( call ) ( size_t ) IPC_GET_ARG2( * call ) |
- | |
93 | - | ||
94 | #define IPC_GET_PHONE( call ) ( int ) IPC_GET_ARG5( * call ) |
- | |
95 | - | ||
96 | #define IPC_SET_ADDR( answer ) (( size_t * ) & IPC_GET_ARG1( * answer )) |
- | |
97 | #define IPC_SET_PREFIX( answer ) (( size_t * ) & IPC_GET_ARG2( * answer )) |
- | |
98 | #define IPC_SET_CONTENT( answer ) (( size_t * ) & IPC_GET_ARG3( * answer )) |
- | |
99 | #define IPC_SET_SUFFIX( answer ) (( size_t * ) & IPC_GET_ARG4( * answer )) |
- | |
100 | - | ||
101 | typedef enum eth_addr_type eth_addr_type_t; |
75 | typedef enum eth_addr_type eth_addr_type_t; |
102 | typedef eth_addr_type_t * eth_addr_type_ref; |
76 | typedef eth_addr_type_t * eth_addr_type_ref; |
103 | 77 | ||
104 | enum eth_addr_type{ |
78 | enum eth_addr_type{ |
105 | ETH_LOCAL_ADDR, |
79 | ETH_LOCAL_ADDR, |
106 | ETH_BROADCAST_ADDR |
80 | ETH_BROADCAST_ADDR |
107 | }; |
81 | }; |
108 | 82 | ||
109 | /** Ethernet global data. |
83 | /** Ethernet global data. |
110 | */ |
84 | */ |
111 | eth_globals_t eth_globals; |
85 | eth_globals_t eth_globals; |
112 | 86 | ||
113 | /** Processes IPC messages from the registered device driver modules in an infinite loop. |
87 | /** Processes IPC messages from the registered device driver modules in an infinite loop. |
114 | * @param iid The message identifier. Input parameter. |
88 | * @param iid The message identifier. Input parameter. |
115 | * @param icall The message parameters. Input/output parameter. |
89 | * @param icall The message parameters. Input/output parameter. |
116 | */ |
90 | */ |
117 | void eth_receiver( ipc_callid_t iid, ipc_call_t * icall ); |
91 | void eth_receiver( ipc_callid_t iid, ipc_call_t * icall ); |
118 | 92 | ||
119 | DEVICE_MAP_IMPLEMENT( eth_devices, eth_device_t ) |
93 | DEVICE_MAP_IMPLEMENT( eth_devices, eth_device_t ) |
120 | 94 | ||
121 | INT_MAP_IMPLEMENT( eth_protos, eth_proto_t ) |
95 | INT_MAP_IMPLEMENT( eth_protos, eth_proto_t ) |
122 | 96 | ||
123 | int eth_device_message( device_id_t device_id, services_t service, size_t mtu ); |
97 | int eth_device_message( device_id_t device_id, services_t service, size_t mtu ); |
124 | int eth_receive_message( device_id_t device_id, packet_t packet ); |
98 | int eth_receive_message( device_id_t device_id, packet_t packet ); |
125 | int eth_packet_space_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ); |
99 | int eth_packet_space_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ); |
126 | int eth_addr_message( device_id_t device_id, eth_addr_type_t type, measured_string_ref * address ); |
100 | int eth_addr_message( device_id_t device_id, eth_addr_type_t type, measured_string_ref * address ); |
127 | int eth_register_message( services_t service, int phone ); |
- | |
128 | int eth_send_message( device_id_t device_id, packet_t packet, services_t sender ); |
101 | int eth_send_message( device_id_t device_id, packet_t packet, services_t sender ); |
129 | void eth_receiver( ipc_callid_t iid, ipc_call_t * icall ); |
- | |
130 | eth_proto_ref eth_process_packet( int dummy, packet_t packet ); |
102 | eth_proto_ref eth_process_packet( int dummy, packet_t packet ); |
131 | int eth_prepare_packet( int dummy, packet_t packet, uint8_t * src_addr, int ethertype ); |
103 | int eth_prepare_packet( int dummy, packet_t packet, uint8_t * src_addr, int ethertype ); |
132 | 104 | ||
- | 105 | void nil_device_state_wrapper( device_id_t device_id, int state ){ |
|
- | 106 | int index; |
|
- | 107 | eth_proto_ref proto; |
|
- | 108 | ||
- | 109 | //TODO clear device if off? |
|
- | 110 | rwlock_read_lock( & eth_globals.protos_lock ); |
|
- | 111 | for( index = eth_protos_count( & eth_globals.protos ) - 1; index >= 0; -- index ){ |
|
- | 112 | proto = eth_protos_get_index( & eth_globals.protos, index ); |
|
- | 113 | if( proto && proto->phone ) async_msg_2( proto->phone, NET_IL_DEVICE_STATE, device_id, state ); |
|
- | 114 | } |
|
- | 115 | rwlock_read_unlock( & eth_globals.protos_lock ); |
|
- | 116 | } |
|
- | 117 | ||
- | 118 | int nil_receive_wrapper( device_id_t device_id, packet_t packet ){ |
|
- | 119 | return eth_receive_message( device_id, packet ); |
|
- | 120 | } |
|
- | 121 | ||
133 | int eth_initialize( void ){ |
122 | int nil_initialize( int networking_phone ){ |
134 | ERROR_DECLARE; |
123 | ERROR_DECLARE; |
135 | 124 | ||
136 | rwlock_initialize( & eth_globals.devices_lock ); |
125 | rwlock_initialize( & eth_globals.devices_lock ); |
137 | rwlock_initialize( & eth_globals.protos_lock ); |
126 | rwlock_initialize( & eth_globals.protos_lock ); |
138 | rwlock_write_lock( & eth_globals.devices_lock ); |
127 | rwlock_write_lock( & eth_globals.devices_lock ); |
139 | rwlock_write_lock( & eth_globals.protos_lock ); |
128 | rwlock_write_lock( & eth_globals.protos_lock ); |
- | 129 | eth_globals.networking_phone = networking_phone; |
|
140 | eth_globals.broadcast_addr = measured_string_create_bulk( "\xFF\xFF\xFF\xFF\xFF\xFF", CONVERT_SIZE( uint8_t, char, ETH_ADDR )); |
130 | eth_globals.broadcast_addr = measured_string_create_bulk( "\xFF\xFF\xFF\xFF\xFF\xFF", CONVERT_SIZE( uint8_t, char, ETH_ADDR )); |
141 | if( ! eth_globals.broadcast_addr ) return ENOMEM; |
131 | if( ! eth_globals.broadcast_addr ) return ENOMEM; |
142 | ERROR_PROPAGATE( eth_devices_initialize( & eth_globals.devices )); |
132 | ERROR_PROPAGATE( eth_devices_initialize( & eth_globals.devices )); |
143 | if( ERROR_OCCURRED( eth_protos_initialize( & eth_globals.protos ))){ |
133 | if( ERROR_OCCURRED( eth_protos_initialize( & eth_globals.protos ))){ |
144 | eth_devices_destroy( & eth_globals.devices ); |
134 | eth_devices_destroy( & eth_globals.devices ); |
145 | return ERROR_CODE; |
135 | return ERROR_CODE; |
146 | } |
136 | } |
147 | rwlock_write_unlock( & eth_globals.protos_lock ); |
137 | rwlock_write_unlock( & eth_globals.protos_lock ); |
148 | rwlock_write_unlock( & eth_globals.devices_lock ); |
138 | rwlock_write_unlock( & eth_globals.devices_lock ); |
149 | return EOK; |
139 | return EOK; |
150 | } |
140 | } |
151 | 141 | ||
152 | int eth_device_message( device_id_t device_id, services_t service, size_t mtu ){ |
142 | int eth_device_message( device_id_t device_id, services_t service, size_t mtu ){ |
153 | ERROR_DECLARE; |
143 | ERROR_DECLARE; |
154 | 144 | ||
155 | eth_device_ref device; |
145 | eth_device_ref device; |
156 | int index; |
146 | int index; |
157 | 147 | ||
158 | rwlock_write_lock( & eth_globals.devices_lock ); |
148 | rwlock_write_lock( & eth_globals.devices_lock ); |
159 | // an existing device? |
149 | // an existing device? |
160 | device = eth_devices_find( & eth_globals.devices, device_id ); |
150 | device = eth_devices_find( & eth_globals.devices, device_id ); |
161 | if( device ){ |
151 | if( device ){ |
162 | if( device->service != service ){ |
152 | if( device->service != service ){ |
163 | printf( "\nDevice %d already exists", device->device_id ); |
153 | printf( "\nDevice %d already exists", device->device_id ); |
164 | rwlock_write_unlock( & eth_globals.devices_lock ); |
154 | rwlock_write_unlock( & eth_globals.devices_lock ); |
165 | return EEXIST; |
155 | return EEXIST; |
166 | }else{ |
156 | }else{ |
167 | // update mtu |
157 | // update mtu |
168 | device->mtu = mtu; |
158 | device->mtu = mtu; |
169 | printf( "\nDevice %d already exists:\tMTU\t= %d", device->device_id, device->mtu ); |
159 | printf( "\nDevice %d already exists:\tMTU\t= %d", device->device_id, device->mtu ); |
170 | } |
160 | } |
171 | }else{ |
161 | }else{ |
172 | // create a new device |
162 | // create a new device |
173 | device = ( eth_device_ref ) malloc( sizeof( eth_device_t )); |
163 | device = ( eth_device_ref ) malloc( sizeof( eth_device_t )); |
174 | if( ! device ) return ENOMEM; |
164 | if( ! device ) return ENOMEM; |
175 | device->device_id = device_id; |
165 | device->device_id = device_id; |
176 | device->service = service; |
166 | device->service = service; |
177 | device->mtu = (( mtu > 0 ) && ( mtu <= ETH_MAX_TAGGED_CONTENT )) ? mtu : ETH_MAX_TAGGED_CONTENT; |
167 | device->mtu = (( mtu > 0 ) && ( mtu <= ETH_MAX_TAGGED_CONTENT )) ? mtu : ETH_MAX_TAGGED_CONTENT; |
178 | // TODO get dummy setting |
168 | // TODO get dummy setting |
179 | device->dummy = 0; |
169 | device->dummy = 0; |
180 | // bind the device driver |
170 | // bind the device driver |
- | 171 | #if ! NETIF_BUNDLE |
|
181 | device->phone = bind_service( device->service, device->device_id, SERVICE_ETHERNET, 0, eth_receiver ); |
172 | device->phone = bind_service( device->service, device->device_id, SERVICE_ETHERNET, 0, eth_receiver ); |
182 | if( device->phone < 0 ){ |
173 | if( device->phone < 0 ){ |
183 | rwlock_write_unlock( & eth_globals.devices_lock ); |
174 | rwlock_write_unlock( & eth_globals.devices_lock ); |
184 | free( device ); |
175 | free( device ); |
185 | return device->phone; |
176 | return device->phone; |
186 | } |
177 | } |
- | 178 | #endif |
|
187 | // get hardware address |
179 | // get hardware address |
188 | if( ERROR_OCCURRED( netif_get_addr( device->phone, device->device_id, & device->addr, & device->addr_data ))){ |
180 | if( ERROR_OCCURRED( netif_get_addr( device->phone, device->device_id, & device->addr, & device->addr_data ))){ |
189 | rwlock_write_unlock( & eth_globals.devices_lock ); |
181 | rwlock_write_unlock( & eth_globals.devices_lock ); |
190 | free( device ); |
182 | free( device ); |
191 | return ERROR_CODE; |
183 | return ERROR_CODE; |
192 | } |
184 | } |
193 | // add to the cache |
185 | // add to the cache |
194 | index = eth_devices_add( & eth_globals.devices, device->device_id, device ); |
186 | index = eth_devices_add( & eth_globals.devices, device->device_id, device ); |
195 | if( index < 0 ){ |
187 | if( index < 0 ){ |
196 | rwlock_write_unlock( & eth_globals.devices_lock ); |
188 | rwlock_write_unlock( & eth_globals.devices_lock ); |
197 | free( device->addr ); |
189 | free( device->addr ); |
198 | free( device->addr_data ); |
190 | free( device->addr_data ); |
199 | free( device ); |
191 | free( device ); |
200 | return index; |
192 | return index; |
201 | } |
193 | } |
202 | printf( "\nNew device registered:\n\tid\t= %d\n\tservice\t= %d\n\tMTU\t= %d\n\taddress\t= %X:%X:%X:%X:%X:%X", 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 ] ); |
194 | printf( "\nNew device registered:\n\tid\t= %d\n\tservice\t= %d\n\tMTU\t= %d\n\taddress\t= %X:%X:%X:%X:%X:%X", 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 ] ); |
203 | } |
195 | } |
204 | rwlock_write_unlock( & eth_globals.devices_lock ); |
196 | rwlock_write_unlock( & eth_globals.devices_lock ); |
205 | return EOK; |
197 | return EOK; |
206 | } |
198 | } |
207 | 199 | ||
208 | eth_proto_ref eth_process_packet( int dummy, packet_t packet ){ |
200 | eth_proto_ref eth_process_packet( int dummy, packet_t packet ){ |
209 | ERROR_DECLARE; |
201 | ERROR_DECLARE; |
210 | 202 | ||
211 | eth_header_ex_ref header; |
203 | eth_header_ex_ref header; |
212 | size_t length; |
204 | size_t length; |
213 | int type; |
205 | int type; |
214 | size_t prefix; |
206 | size_t prefix; |
215 | size_t suffix; |
207 | size_t suffix; |
216 | eth_fcs_ref fcs; |
208 | eth_fcs_ref fcs; |
217 | 209 | ||
218 | length = packet_get_data_length( packet ); |
210 | length = packet_get_data_length( packet ); |
219 | if( dummy ){ |
211 | if( dummy ){ |
220 | packet_trim( packet, sizeof( eth_preamble_t ), 0 ); |
212 | packet_trim( packet, sizeof( eth_preamble_t ), 0 ); |
221 | } |
213 | } |
222 | if( length <= sizeof( eth_header_t ) + ETH_MIN_CONTENT + ETH_SUFFIX ) return NULL; |
214 | if( length <= sizeof( eth_header_t ) + ETH_MIN_CONTENT + ETH_SUFFIX ) return NULL; |
223 | header = ( eth_header_ex_ref ) packet_get_data( packet ); |
215 | header = ( eth_header_ex_ref ) packet_get_data( packet ); |
224 | type = ntohs( header->header.ethertype ); |
216 | type = ntohs( header->header.ethertype ); |
225 | if( type >= ETH_MIN_PROTO ){ |
217 | if( type >= ETH_MIN_PROTO ){ |
226 | // DIX Ethernet |
218 | // DIX Ethernet |
227 | prefix = sizeof( eth_header_t ); |
219 | prefix = sizeof( eth_header_t ); |
228 | suffix = sizeof( eth_fcs_t ); |
220 | suffix = sizeof( eth_fcs_t ); |
229 | fcs = (( void * ) header ) + length - suffix; |
221 | fcs = (( void * ) header ) + length - suffix; |
230 | }else if( type <= ETH_MAX_CONTENT ){ |
222 | }else if( type <= ETH_MAX_CONTENT ){ |
231 | // translate "LSAP" values |
223 | // translate "LSAP" values |
232 | if(( header->lsap.dsap == ETH_LSAP_GLSAP ) && ( header->lsap.ssap == ETH_LSAP_GLSAP )){ |
224 | if(( header->lsap.dsap == ETH_LSAP_GLSAP ) && ( header->lsap.ssap == ETH_LSAP_GLSAP )){ |
233 | // raw packet |
225 | // raw packet |
234 | // discard |
226 | // discard |
235 | return NULL; |
227 | return NULL; |
236 | }else if(( header->lsap.dsap == ETH_LSAP_SNAP ) && ( header->lsap.ssap == ETH_LSAP_SNAP )){ |
228 | }else if(( header->lsap.dsap == ETH_LSAP_SNAP ) && ( header->lsap.ssap == ETH_LSAP_SNAP )){ |
237 | // IEEE 802.3 + 802.2 + LSAP + SNAP |
229 | // IEEE 802.3 + 802.2 + LSAP + SNAP |
238 | // organization code not supported |
230 | // organization code not supported |
239 | type = ntohs( header->snap.ethertype ); |
231 | type = ntohs( header->snap.ethertype ); |
240 | prefix = sizeof( eth_header_t ) + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t ); |
232 | prefix = sizeof( eth_header_t ) + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t ); |
241 | }else{ |
233 | }else{ |
242 | // IEEE 802.3 + 802.2 LSAP |
234 | // IEEE 802.3 + 802.2 LSAP |
243 | type = lsap_map( header->lsap.dsap ); |
235 | type = lsap_map( header->lsap.dsap ); |
244 | prefix = sizeof( eth_header_t ) + sizeof( eth_header_lsap_t); |
236 | prefix = sizeof( eth_header_t ) + sizeof( eth_header_lsap_t); |
245 | } |
237 | } |
246 | suffix = ( type < ETH_MIN_CONTENT ) ? ETH_MIN_CONTENT - type : 0; |
238 | suffix = ( type < ETH_MIN_CONTENT ) ? ETH_MIN_CONTENT - type : 0; |
247 | fcs = (( void * ) header ) + prefix + type + suffix; |
239 | fcs = (( void * ) header ) + prefix + type + suffix; |
248 | suffix += length - prefix - type; |
240 | suffix += length - prefix - type; |
249 | }else{ |
241 | }else{ |
250 | // invalid length/type, should not occurr |
242 | // invalid length/type, should not occurr |
251 | return NULL; |
243 | return NULL; |
252 | } |
244 | } |
253 | if( dummy ){ |
245 | if( dummy ){ |
254 | if(( ~ compute_crc32( ~ 0, & header->header.dest, ((( void * ) fcs ) - (( void * ) & header->header.dest )) * 8 )) != ntohl( * fcs )){ |
246 | if(( ~ compute_crc32( ~ 0, & header->header.dest, ((( void * ) fcs ) - (( void * ) & header->header.dest )) * 8 )) != ntohl( * fcs )){ |
255 | return NULL; |
247 | return NULL; |
256 | } |
248 | } |
257 | } |
249 | } |
258 | if( ERROR_OCCURRED( packet_set_addr( packet, header->header.src, header->header.dest, ETH_ADDR )) |
250 | if( ERROR_OCCURRED( packet_set_addr( packet, header->header.src, header->header.dest, ETH_ADDR )) |
259 | || ERROR_OCCURRED( packet_trim( packet, prefix, suffix ))){ |
251 | || ERROR_OCCURRED( packet_trim( packet, prefix, suffix ))){ |
260 | return NULL; |
252 | return NULL; |
261 | } |
253 | } |
262 | return eth_protos_find( & eth_globals.protos, type ); |
254 | return eth_protos_find( & eth_globals.protos, type ); |
263 | } |
255 | } |
264 | 256 | ||
265 | int eth_receive_message( device_id_t device_id, packet_t packet ){ |
257 | int eth_receive_message( device_id_t device_id, packet_t packet ){ |
266 | eth_proto_ref proto; |
258 | eth_proto_ref proto; |
267 | packet_t next; |
259 | packet_t next; |
268 | eth_device_ref device; |
260 | eth_device_ref device; |
269 | int dummy; |
261 | int dummy; |
270 | 262 | ||
271 | rwlock_read_lock( & eth_globals.devices_lock ); |
263 | rwlock_read_lock( & eth_globals.devices_lock ); |
272 | device = eth_devices_find( & eth_globals.devices, device_id ); |
264 | device = eth_devices_find( & eth_globals.devices, device_id ); |
273 | if( ! device ){ |
265 | if( ! device ){ |
274 | rwlock_read_unlock( & eth_globals.devices_lock ); |
266 | rwlock_read_unlock( & eth_globals.devices_lock ); |
275 | return ENOENT; |
267 | return ENOENT; |
276 | } |
268 | } |
277 | dummy = device->dummy; |
269 | dummy = device->dummy; |
278 | rwlock_read_unlock( & eth_globals.devices_lock ); |
270 | rwlock_read_unlock( & eth_globals.devices_lock ); |
279 | rwlock_read_lock( & eth_globals.protos_lock ); |
271 | rwlock_read_lock( & eth_globals.protos_lock ); |
280 | do{ |
272 | do{ |
281 | next = pq_detach( packet ); |
273 | next = pq_detach( packet ); |
282 | proto = eth_process_packet( dummy, packet ); |
274 | proto = eth_process_packet( dummy, packet ); |
283 | if( proto ){ |
275 | if( proto ){ |
284 | async_msg_2( proto->phone, NET_IL_RECEIVED, device_id, packet_get_id( packet )); |
276 | async_msg_3( proto->phone, NET_IL_RECEIVED, device_id, packet_get_id( packet ), proto->service ); |
285 | }else{ |
277 | }else{ |
286 | // drop invalid/unknown |
278 | // drop invalid/unknown |
287 | pq_release( eth_globals.networking_phone, packet_get_id( packet )); |
279 | pq_release( eth_globals.networking_phone, packet_get_id( packet )); |
288 | } |
280 | } |
289 | packet = next; |
281 | packet = next; |
290 | }while( packet ); |
282 | }while( packet ); |
291 | rwlock_read_unlock( & eth_globals.protos_lock ); |
283 | rwlock_read_unlock( & eth_globals.protos_lock ); |
292 | return EOK; |
284 | return EOK; |
293 | } |
285 | } |
294 | 286 | ||
295 | int eth_packet_space_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ){ |
287 | int eth_packet_space_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ){ |
296 | eth_device_ref device; |
288 | eth_device_ref device; |
297 | 289 | ||
298 | if( !( addr_len && prefix && content && suffix )) return EINVAL; |
290 | if( !( addr_len && prefix && content && suffix )) return EINVAL; |
299 | rwlock_read_lock( & eth_globals.devices_lock ); |
291 | rwlock_read_lock( & eth_globals.devices_lock ); |
300 | device = eth_devices_find( & eth_globals.devices, device_id ); |
292 | device = eth_devices_find( & eth_globals.devices, device_id ); |
301 | if( ! device ){ |
293 | if( ! device ){ |
302 | rwlock_read_unlock( & eth_globals.devices_lock ); |
294 | rwlock_read_unlock( & eth_globals.devices_lock ); |
303 | return ENOENT; |
295 | return ENOENT; |
304 | } |
296 | } |
305 | * content = device->mtu; |
297 | * content = device->mtu; |
306 | rwlock_read_unlock( & eth_globals.devices_lock ); |
298 | rwlock_read_unlock( & eth_globals.devices_lock ); |
307 | * addr_len = ETH_ADDR; |
299 | * addr_len = ETH_ADDR; |
308 | * prefix = ETH_PREFIX; |
300 | * prefix = ETH_PREFIX; |
309 | * suffix = ETH_MIN_CONTENT + ETH_SUFFIX; |
301 | * suffix = ETH_MIN_CONTENT + ETH_SUFFIX; |
310 | return EOK; |
302 | return EOK; |
311 | } |
303 | } |
312 | 304 | ||
313 | int eth_addr_message( device_id_t device_id, eth_addr_type_t type, measured_string_ref * address ){ |
305 | int eth_addr_message( device_id_t device_id, eth_addr_type_t type, measured_string_ref * address ){ |
314 | eth_device_ref device; |
306 | eth_device_ref device; |
315 | 307 | ||
316 | if( ! address ) return EINVAL; |
308 | if( ! address ) return EINVAL; |
317 | if( type == ETH_BROADCAST_ADDR ){ |
309 | if( type == ETH_BROADCAST_ADDR ){ |
318 | * address = eth_globals.broadcast_addr; |
310 | * address = eth_globals.broadcast_addr; |
319 | }else{ |
311 | }else{ |
320 | rwlock_read_lock( & eth_globals.devices_lock ); |
312 | rwlock_read_lock( & eth_globals.devices_lock ); |
321 | device = eth_devices_find( & eth_globals.devices, device_id ); |
313 | device = eth_devices_find( & eth_globals.devices, device_id ); |
322 | if( ! device ){ |
314 | if( ! device ){ |
323 | rwlock_read_unlock( & eth_globals.devices_lock ); |
315 | rwlock_read_unlock( & eth_globals.devices_lock ); |
324 | return ENOENT; |
316 | return ENOENT; |
325 | } |
317 | } |
326 | * address = device->addr; |
318 | * address = device->addr; |
327 | rwlock_read_unlock( & eth_globals.devices_lock ); |
319 | rwlock_read_unlock( & eth_globals.devices_lock ); |
328 | } |
320 | } |
329 | return ( * address ) ? EOK : ENOENT; |
321 | return ( * address ) ? EOK : ENOENT; |
330 | } |
322 | } |
331 | 323 | ||
332 | int eth_register_message( services_t service, int phone ){ |
324 | int nil_register_message( services_t service, int phone ){ |
333 | eth_proto_ref proto; |
325 | eth_proto_ref proto; |
334 | int protocol; |
326 | int protocol; |
335 | int index; |
327 | int index; |
336 | 328 | ||
337 | protocol = protocol_map( SERVICE_ETHERNET, service ); |
329 | protocol = protocol_map( SERVICE_ETHERNET, service ); |
338 | if( ! protocol ) return ENOENT; |
330 | if( ! protocol ) return ENOENT; |
339 | rwlock_write_lock( & eth_globals.protos_lock ); |
331 | rwlock_write_lock( & eth_globals.protos_lock ); |
340 | proto = eth_protos_find( & eth_globals.protos, protocol ); |
332 | proto = eth_protos_find( & eth_globals.protos, protocol ); |
341 | if( proto ){ |
333 | if( proto ){ |
342 | proto->phone = phone; |
334 | proto->phone = phone; |
343 | rwlock_write_unlock( & eth_globals.protos_lock ); |
335 | rwlock_write_unlock( & eth_globals.protos_lock ); |
344 | return EOK; |
336 | return EOK; |
345 | }else{ |
337 | }else{ |
346 | proto = ( eth_proto_ref ) malloc( sizeof( eth_proto_t )); |
338 | proto = ( eth_proto_ref ) malloc( sizeof( eth_proto_t )); |
347 | if( ! proto ){ |
339 | if( ! proto ){ |
348 | rwlock_write_unlock( & eth_globals.protos_lock ); |
340 | rwlock_write_unlock( & eth_globals.protos_lock ); |
349 | return ENOMEM; |
341 | return ENOMEM; |
350 | } |
342 | } |
351 | proto->service = service; |
343 | proto->service = service; |
352 | proto->protocol = protocol; |
344 | proto->protocol = protocol; |
353 | proto->phone = phone; |
345 | proto->phone = phone; |
354 | index = eth_protos_add( & eth_globals.protos, protocol, proto ); |
346 | index = eth_protos_add( & eth_globals.protos, protocol, proto ); |
355 | if( index < 0 ){ |
347 | if( index < 0 ){ |
356 | rwlock_write_unlock( & eth_globals.protos_lock ); |
348 | rwlock_write_unlock( & eth_globals.protos_lock ); |
357 | free( proto ); |
349 | free( proto ); |
358 | return index; |
350 | return index; |
359 | } |
351 | } |
360 | } |
352 | } |
361 | printf( "\nNew protocol registered:\n\tprotocol\t= 0x%x\n\tservice\t= %d\n\tphone\t= %d", proto->protocol, proto->service, proto->phone ); |
353 | printf( "\nNew protocol registered:\n\tprotocol\t= 0x%x\n\tservice\t= %d\n\tphone\t= %d", proto->protocol, proto->service, proto->phone ); |
362 | rwlock_write_unlock( & eth_globals.protos_lock ); |
354 | rwlock_write_unlock( & eth_globals.protos_lock ); |
363 | return EOK; |
355 | return EOK; |
364 | } |
356 | } |
365 | 357 | ||
366 | int eth_prepare_packet( int dummy, packet_t packet, uint8_t * src_addr, int ethertype ){ |
358 | int eth_prepare_packet( int dummy, packet_t packet, uint8_t * src_addr, int ethertype ){ |
367 | eth_header_ex_ref header; |
359 | eth_header_ex_ref header; |
368 | eth_fcs_ref fcs; |
360 | eth_fcs_ref fcs; |
369 | uint8_t * src; |
361 | uint8_t * src; |
370 | uint8_t * dest; |
362 | uint8_t * dest; |
371 | int length; |
363 | int length; |
372 | int i; |
364 | int i; |
373 | void * padding; |
365 | void * padding; |
374 | eth_preamble_ref preamble; |
366 | eth_preamble_ref preamble; |
375 | 367 | ||
376 | length = packet_get_data_length( packet ); |
368 | length = packet_get_data_length( packet ); |
377 | if( length > ETH_MAX_TAGGED_CONTENT ) return EINVAL; |
369 | if( length > ETH_MAX_TAGGED_CONTENT ) return EINVAL; |
378 | if( length < ETH_MIN_TAGGED_CONTENT ){ |
370 | if( length < ETH_MIN_TAGGED_CONTENT ){ |
379 | padding = packet_suffix( packet, ETH_MIN_TAGGED_CONTENT - length ); |
371 | padding = packet_suffix( packet, ETH_MIN_TAGGED_CONTENT - length ); |
380 | if( ! padding ) return ENOMEM; |
372 | if( ! padding ) return ENOMEM; |
381 | bzero( padding, ETH_MIN_TAGGED_CONTENT - length ); |
373 | bzero( padding, ETH_MIN_TAGGED_CONTENT - length ); |
382 | } |
374 | } |
383 | if( dummy ){ |
375 | if( dummy ){ |
384 | preamble = PACKET_PREFIX( packet, eth_preamble_t ); |
376 | preamble = PACKET_PREFIX( packet, eth_preamble_t ); |
385 | if( ! preamble ) return ENOMEM; |
377 | if( ! preamble ) return ENOMEM; |
386 | for( i = 0; i < 7; ++ i ) preamble->preamble[ i ] = ETH_PREAMBLE; |
378 | for( i = 0; i < 7; ++ i ) preamble->preamble[ i ] = ETH_PREAMBLE; |
387 | preamble->sfd = ETH_SFD; |
379 | preamble->sfd = ETH_SFD; |
388 | } |
380 | } |
389 | header = PACKET_PREFIX( packet, eth_header_ex_t ); |
381 | header = PACKET_PREFIX( packet, eth_header_ex_t ); |
390 | if( ! header ) return ENOMEM; |
382 | if( ! header ) return ENOMEM; |
391 | header->header.ethertype = htons( length + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t )); |
383 | header->header.ethertype = htons( length + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t )); |
392 | header->lsap.dsap = 0xAA; |
384 | header->lsap.dsap = ( uint16_t ) ETH_LSAP_SNAP; |
393 | header->lsap.ssap = header->lsap.dsap; |
385 | header->lsap.ssap = header->lsap.dsap; |
394 | header->lsap.ctrl = 0; |
386 | header->lsap.ctrl = 0; |
395 | for( i = 0; i < 3; ++ i ) header->snap.proto[ i ] = 0; |
387 | for( i = 0; i < 3; ++ i ) header->snap.proto[ i ] = 0; |
396 | header->snap.ethertype = ethertype; |
388 | header->snap.ethertype = ( uint16_t ) ethertype; |
397 | length = packet_get_addr( packet, & src, & dest ); |
389 | length = packet_get_addr( packet, & src, & dest ); |
398 | if( length < 0 ) return length; |
390 | if( length < 0 ) return length; |
399 | if( length < ETH_ADDR ) return EINVAL; |
391 | if( length < ETH_ADDR ) return EINVAL; |
400 | memcpy( header->header.src, src_addr, ETH_ADDR ); |
392 | memcpy( header->header.src, src_addr, ETH_ADDR ); |
401 | memcpy( header->header.dest, dest, ETH_ADDR ); |
393 | memcpy( header->header.dest, dest, ETH_ADDR ); |
402 | if( dummy ){ |
394 | if( dummy ){ |
403 | fcs = PACKET_SUFFIX( packet, eth_fcs_t ); |
395 | fcs = PACKET_SUFFIX( packet, eth_fcs_t ); |
404 | if( ! fcs ) return ENOMEM; |
396 | if( ! fcs ) return ENOMEM; |
405 | * fcs = htonl( ~ compute_crc32( ~ 0, & header->header.dest, ((( void * ) fcs ) - (( void * ) & header->header.dest )) * 8 )); |
397 | * fcs = htonl( ~ compute_crc32( ~ 0, & header->header.dest, ((( void * ) fcs ) - (( void * ) & header->header.dest )) * 8 )); |
406 | } |
398 | } |
407 | return EOK; |
399 | return EOK; |
408 | } |
400 | } |
409 | 401 | ||
410 | int eth_send_message( device_id_t device_id, packet_t packet, services_t sender ){ |
402 | int eth_send_message( device_id_t device_id, packet_t packet, services_t sender ){ |
411 | ERROR_DECLARE; |
403 | ERROR_DECLARE; |
412 | 404 | ||
413 | eth_device_ref device; |
405 | eth_device_ref device; |
414 | packet_t next; |
406 | packet_t next; |
415 | packet_t tmp; |
407 | packet_t tmp; |
416 | int ethertype; |
408 | int ethertype; |
417 | 409 | ||
418 | ethertype = htons( protocol_map( SERVICE_ETHERNET, sender )); |
410 | ethertype = htons( protocol_map( SERVICE_ETHERNET, sender )); |
419 | if( ! ethertype ){ |
411 | if( ! ethertype ){ |
420 | pq_release( eth_globals.networking_phone, packet_get_id( packet )); |
412 | pq_release( eth_globals.networking_phone, packet_get_id( packet )); |
421 | return EINVAL; |
413 | return EINVAL; |
422 | } |
414 | } |
423 | rwlock_read_lock( & eth_globals.devices_lock ); |
415 | rwlock_read_lock( & eth_globals.devices_lock ); |
424 | device = eth_devices_find( & eth_globals.devices, device_id ); |
416 | device = eth_devices_find( & eth_globals.devices, device_id ); |
425 | if( ! device ){ |
417 | if( ! device ){ |
426 | rwlock_read_unlock( & eth_globals.devices_lock ); |
418 | rwlock_read_unlock( & eth_globals.devices_lock ); |
427 | return ENOENT; |
419 | return ENOENT; |
428 | } |
420 | } |
429 | // process packet queue |
421 | // process packet queue |
430 | next = packet; |
422 | next = packet; |
431 | do{ |
423 | do{ |
432 | if( ERROR_OCCURRED( eth_prepare_packet( device->dummy, next, ( uint8_t * ) device->addr->value, ethertype ))){ |
424 | if( ERROR_OCCURRED( eth_prepare_packet( device->dummy, next, ( uint8_t * ) device->addr->value, ethertype ))){ |
433 | // release invalid packet |
425 | // release invalid packet |
434 | tmp = pq_detach( next ); |
426 | tmp = pq_detach( next ); |
435 | pq_release( eth_globals.networking_phone, packet_get_id( next )); |
427 | pq_release( eth_globals.networking_phone, packet_get_id( next )); |
436 | next = tmp; |
428 | next = tmp; |
437 | }else{ |
429 | }else{ |
438 | next = pq_next( next ); |
430 | next = pq_next( next ); |
439 | } |
431 | } |
440 | }while( next ); |
432 | }while( next ); |
441 | // send packet queue |
433 | // send packet queue |
442 | netif_send_msg( device->phone, device_id, packet ); |
434 | netif_send_msg( device->phone, device_id, packet, SERVICE_ETHERNET ); |
443 | rwlock_read_unlock( & eth_globals.devices_lock ); |
435 | rwlock_read_unlock( & eth_globals.devices_lock ); |
444 | return EOK; |
436 | return EOK; |
445 | } |
437 | } |
446 | 438 | ||
447 | int eth_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
439 | int nil_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
448 | ERROR_DECLARE; |
440 | ERROR_DECLARE; |
449 | 441 | ||
450 | measured_string_ref address; |
442 | measured_string_ref address; |
451 | packet_t packet; |
443 | packet_t packet; |
452 | 444 | ||
453 | // printf( "\nmessage %d - %d", IPC_GET_METHOD( * call ), NET_NIL_FIRST ); |
445 | // printf( "\nmessage %d - %d", IPC_GET_METHOD( * call ), NET_NIL_FIRST ); |
454 | * answer_count = 0; |
446 | * answer_count = 0; |
455 | switch( IPC_GET_METHOD( * call )){ |
447 | switch( IPC_GET_METHOD( * call )){ |
456 | case IPC_M_PHONE_HUNGUP: |
448 | case IPC_M_PHONE_HUNGUP: |
457 | return EOK; |
449 | return EOK; |
458 | case NET_NIL_DEVICE: |
450 | case NET_NIL_DEVICE: |
459 | return eth_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), IPC_GET_MTU( call )); |
451 | return eth_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), NIL_GET_MTU( call )); |
460 | case NET_NIL_SEND: |
452 | case NET_NIL_SEND: |
461 | ERROR_PROPAGATE( packet_translate( eth_globals.networking_phone, & packet, IPC_GET_PACKET( call ))); |
453 | ERROR_PROPAGATE( packet_translate( eth_globals.networking_phone, & packet, IPC_GET_PACKET( call ))); |
462 | return eth_send_message( IPC_GET_DEVICE( call ), packet, IPC_GET_SERVICE( call )); |
454 | return eth_send_message( IPC_GET_DEVICE( call ), packet, IPC_GET_SERVICE( call )); |
463 | case NET_NIL_PACKET_SPACE: |
455 | case NET_NIL_PACKET_SPACE: |
464 | ERROR_PROPAGATE( eth_packet_space_message( IPC_GET_DEVICE( call ), IPC_SET_ADDR( answer ), IPC_SET_PREFIX( answer ), IPC_SET_CONTENT( answer ), IPC_SET_SUFFIX( answer ))); |
456 | ERROR_PROPAGATE( eth_packet_space_message( IPC_GET_DEVICE( call ), IPC_SET_ADDR( answer ), IPC_SET_PREFIX( answer ), IPC_SET_CONTENT( answer ), IPC_SET_SUFFIX( answer ))); |
465 | * answer_count = 3; |
457 | * answer_count = 3; |
466 | return EOK; |
458 | return EOK; |
467 | case NET_NIL_ADDR: |
459 | case NET_NIL_ADDR: |
468 | ERROR_PROPAGATE( eth_addr_message( IPC_GET_DEVICE( call ), ETH_LOCAL_ADDR, & address )); |
460 | ERROR_PROPAGATE( eth_addr_message( IPC_GET_DEVICE( call ), ETH_LOCAL_ADDR, & address )); |
469 | return measured_strings_reply( address, 1 ); |
461 | return measured_strings_reply( address, 1 ); |
470 | case NET_NIL_BROADCAST_ADDR: |
462 | case NET_NIL_BROADCAST_ADDR: |
471 | ERROR_PROPAGATE( eth_addr_message( IPC_GET_DEVICE( call ), ETH_BROADCAST_ADDR, & address )); |
463 | ERROR_PROPAGATE( eth_addr_message( IPC_GET_DEVICE( call ), ETH_BROADCAST_ADDR, & address )); |
472 | return measured_strings_reply( address, 1 ); |
464 | return measured_strings_reply( address, 1 ); |
473 | case IPC_M_CONNECT_TO_ME: |
465 | case IPC_M_CONNECT_TO_ME: |
474 | return eth_register_message( IPC_GET_PROTO( call ), IPC_GET_PHONE( call )); |
466 | return nil_register_message( NIL_GET_PROTO( call ), IPC_GET_PHONE( call )); |
475 | } |
467 | } |
476 | return ENOTSUP; |
468 | return ENOTSUP; |
477 | } |
469 | } |
478 | 470 | ||
479 | void eth_receiver( ipc_callid_t iid, ipc_call_t * icall ){ |
471 | void eth_receiver( ipc_callid_t iid, ipc_call_t * icall ){ |
480 | ERROR_DECLARE; |
472 | ERROR_DECLARE; |
481 | 473 | ||
482 | packet_t packet; |
474 | packet_t packet; |
483 | int index; |
- | |
484 | eth_proto_ref proto; |
- | |
485 | 475 | ||
486 | while( true ){ |
476 | while( true ){ |
487 | switch( IPC_GET_METHOD( * icall )){ |
477 | switch( IPC_GET_METHOD( * icall )){ |
488 | case NET_NIL_DEVICE_STATE: |
478 | case NET_NIL_DEVICE_STATE: |
489 | //TODO clear device if off? |
- | |
490 | rwlock_read_lock( & eth_globals.protos_lock ); |
- | |
491 | for( index = eth_protos_count( & eth_globals.protos ) - 1; index >= 0; -- index ){ |
- | |
492 | proto = eth_protos_get_index( & eth_globals.protos, index ); |
- | |
493 | if( proto && proto->phone ) async_msg_2( proto->phone, NET_IL_DEVICE_STATE, IPC_GET_DEVICE( icall ), IPC_GET_STATE( icall )); |
479 | nil_device_state_wrapper( IPC_GET_DEVICE( icall ), IPC_GET_STATE( icall )); |
494 | } |
- | |
495 | rwlock_read_unlock( & eth_globals.protos_lock ); |
- | |
496 | ipc_answer_0( iid, EOK ); |
480 | ipc_answer_0( iid, EOK ); |
497 | break; |
481 | break; |
498 | case NET_NIL_RECEIVED: |
482 | case NET_NIL_RECEIVED: |
499 | if( ! ERROR_OCCURRED( packet_translate( eth_globals.networking_phone, & packet, IPC_GET_PACKET( icall )))){ |
483 | if( ! ERROR_OCCURRED( packet_translate( eth_globals.networking_phone, & packet, IPC_GET_PACKET( icall )))){ |
500 | ERROR_CODE = eth_receive_message( IPC_GET_DEVICE( icall ), packet ); |
484 | ERROR_CODE = nil_receive_wrapper( IPC_GET_DEVICE( icall ), packet ); |
501 | } |
485 | } |
502 | ipc_answer_0( iid, ERROR_CODE ); |
486 | ipc_answer_0( iid, ERROR_CODE ); |
503 | break; |
487 | break; |
504 | default: |
488 | default: |
505 | ipc_answer_0( iid, ENOTSUP ); |
489 | ipc_answer_0( iid, ENOTSUP ); |
506 | } |
490 | } |
507 | iid = async_get_call( icall ); |
491 | iid = async_get_call( icall ); |
508 | } |
492 | } |
509 | } |
493 | } |
510 | 494 | ||
511 | /** @} |
495 | /** @} |
512 | */ |
496 | */ |
513 | 497 |