Rev 4163 | Rev 4243 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4163 | Rev 4192 | ||
---|---|---|---|
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 <stdio.h> |
41 | #include <stdio.h> |
41 | #include <string.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 "../../netif/device.h" |
55 | #include "../../netif/device.h" |
56 | 56 | ||
57 | #include "../../structures/measured_strings.h" |
57 | #include "../../structures/measured_strings.h" |
58 | #include "../../structures/packet/packet.h" |
58 | #include "../../structures/packet/packet.h" |
59 | #include "../../structures/packet/packet_client.h" |
59 | #include "../../structures/packet/packet_client.h" |
60 | 60 | ||
61 | #include "eth.h" |
61 | #include "eth.h" |
62 | #include "eth_header.h" |
62 | #include "eth_header.h" |
63 | //#include "eth_messages.h" |
63 | //#include "eth_messages.h" |
64 | #include "eth_module.h" |
64 | #include "eth_module.h" |
65 | 65 | ||
66 | #define ETH_PREFIX ( sizeof( eth_header_t ) + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t )) |
66 | #define ETH_PREFIX ( sizeof( eth_header_t ) + sizeof( eth_header_lsap_t ) + sizeof( eth_header_snap_t )) |
67 | #define ETH_SUFFIX sizeof( eth_fcs_t ) |
67 | #define ETH_SUFFIX sizeof( eth_fcs_t ) |
68 | #define ETH_MAX_CONTENT 1500 |
68 | #define ETH_MAX_CONTENT 1500 |
69 | #define ETH_MIN_CONTENT 46 |
69 | #define ETH_MIN_CONTENT 46 |
70 | 70 | ||
71 | /** Returns the device identifier message parameter. |
71 | /** Returns the device identifier message parameter. |
72 | */ |
72 | */ |
73 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
73 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
74 | 74 | ||
75 | /** Returns the packet identifier message parameter. |
75 | /** Returns the packet identifier message parameter. |
76 | */ |
76 | */ |
77 | #define IPC_GET_PACKET( call ) ( packet_id_t ) IPC_GET_ARG2( * call ) |
77 | #define IPC_GET_PACKET( call ) ( packet_id_t ) IPC_GET_ARG2( * call ) |
78 | 78 | ||
- | 79 | #define IPC_GET_STATE( call ) ( device_state_t ) IPC_GET_ARG2( * call ) |
|
- | 80 | ||
79 | /** Returns the protocol service message parameter. |
81 | /** Returns the protocol service message parameter. |
80 | */ |
82 | */ |
81 | #define IPC_GET_PROTO( call ) ( services_t ) IPC_GET_ARG1( * call ) |
83 | #define IPC_GET_PROTO( call ) ( services_t ) IPC_GET_ARG2( * call ) |
82 | 84 | ||
83 | /** Returns the device driver service message parameter. |
85 | /** Returns the device driver service message parameter. |
84 | */ |
86 | */ |
85 | #define IPC_GET_SERVICE( call ) ( services_t ) IPC_GET_ARG2( * call ) |
87 | #define IPC_GET_SERVICE( call ) ( services_t ) IPC_GET_ARG2( * call ) |
86 | 88 | ||
87 | #define IPC_GET_MTU( call ) ( size_t ) IPC_GET_ARG3( * call ) |
89 | #define IPC_GET_MTU( call ) ( size_t ) IPC_GET_ARG3( * call ) |
88 | 90 | ||
89 | #define IPC_GET_PHONE( call ) ( int ) IPC_GET_ARG5( * call ) |
91 | #define IPC_GET_PHONE( call ) ( int ) IPC_GET_ARG5( * call ) |
90 | 92 | ||
91 | #define IPC_SET_ADDR( answer ) (( size_t * ) & IPC_GET_ARG1( * answer )) |
93 | #define IPC_SET_ADDR( answer ) (( size_t * ) & IPC_GET_ARG1( * answer )) |
92 | #define IPC_SET_PREFIX( answer ) (( size_t * ) & IPC_GET_ARG2( * answer )) |
94 | #define IPC_SET_PREFIX( answer ) (( size_t * ) & IPC_GET_ARG2( * answer )) |
93 | #define IPC_SET_CONTENT( answer ) (( size_t * ) & IPC_GET_ARG3( * answer )) |
95 | #define IPC_SET_CONTENT( answer ) (( size_t * ) & IPC_GET_ARG3( * answer )) |
94 | #define IPC_SET_SUFFIX( answer ) (( size_t * ) & IPC_GET_ARG4( * answer )) |
96 | #define IPC_SET_SUFFIX( answer ) (( size_t * ) & IPC_GET_ARG4( * answer )) |
95 | 97 | ||
96 | typedef enum eth_addr_type eth_addr_type_t; |
98 | typedef enum eth_addr_type eth_addr_type_t; |
97 | typedef eth_addr_type_t * eth_addr_type_ref; |
99 | typedef eth_addr_type_t * eth_addr_type_ref; |
98 | 100 | ||
99 | enum eth_addr_type{ |
101 | enum eth_addr_type{ |
100 | ETH_LOCAL_ADDR, |
102 | ETH_LOCAL_ADDR, |
101 | ETH_BROADCAST_ADDR |
103 | ETH_BROADCAST_ADDR |
102 | }; |
104 | }; |
103 | 105 | ||
104 | /** Ethernet global data. |
106 | /** Ethernet global data. |
105 | */ |
107 | */ |
106 | eth_globals_t eth_globals; |
108 | eth_globals_t eth_globals; |
107 | 109 | ||
108 | /** Processes IPC messages from the registered device driver modules in an infinite loop. |
110 | /** Processes IPC messages from the registered device driver modules in an infinite loop. |
109 | * @param iid The message identifier. Input parameter. |
111 | * @param iid The message identifier. Input parameter. |
110 | * @param icall The message parameters. Input/output parameter. |
112 | * @param icall The message parameters. Input/output parameter. |
111 | */ |
113 | */ |
112 | void eth_receiver( ipc_callid_t iid, ipc_call_t * icall ); |
114 | void eth_receiver( ipc_callid_t iid, ipc_call_t * icall ); |
113 | 115 | ||
114 | DEVICE_MAP_IMPLEMENT( eth_devices, eth_device_t ) |
116 | DEVICE_MAP_IMPLEMENT( eth_devices, eth_device_t ) |
115 | 117 | ||
116 | INT_MAP_IMPLEMENT( eth_protos, eth_proto_t ) |
118 | INT_MAP_IMPLEMENT( eth_protos, eth_proto_t ) |
117 | 119 | ||
118 | int eth_device_message( device_id_t device_id, services_t service, size_t mtu ); |
120 | int eth_device_message( device_id_t device_id, services_t service, size_t mtu ); |
119 | int eth_receive_message( device_id_t device_id, packet_t packet ); |
121 | int eth_receive_message( device_id_t device_id, packet_t packet ); |
120 | int eth_packet_space_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ); |
122 | int eth_packet_space_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ); |
121 | int eth_addr_message( device_id_t device_id, eth_addr_type_t type, measured_string_ref * address ); |
123 | int eth_addr_message( device_id_t device_id, eth_addr_type_t type, measured_string_ref * address ); |
122 | int eth_register_message( services_t service, int phone ); |
124 | int eth_register_message( services_t service, int phone ); |
123 | 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 ); |
124 | int eth_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
126 | int eth_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
125 | void eth_receiver( ipc_callid_t iid, ipc_call_t * icall ); |
127 | void eth_receiver( ipc_callid_t iid, ipc_call_t * icall ); |
126 | eth_proto_ref eth_proccess_packet( int dummy, packet_t packet ); |
128 | eth_proto_ref eth_process_packet( int dummy, packet_t packet ); |
127 | int eth_prepare_packet( int dummy, packet_t packet, uint8_t * src_addr, int ethertype ); |
129 | int eth_prepare_packet( int dummy, packet_t packet, uint8_t * src_addr, int ethertype ); |
128 | 130 | ||
129 | int eth_initialize( void ){ |
131 | int eth_initialize( void ){ |
130 | ERROR_DECLARE; |
132 | ERROR_DECLARE; |
131 | 133 | ||
132 | rwlock_initialize( & eth_globals.devices_lock ); |
134 | rwlock_initialize( & eth_globals.devices_lock ); |
133 | rwlock_initialize( & eth_globals.protos_lock ); |
135 | rwlock_initialize( & eth_globals.protos_lock ); |
134 | rwlock_write_lock( & eth_globals.devices_lock ); |
136 | rwlock_write_lock( & eth_globals.devices_lock ); |
135 | rwlock_write_lock( & eth_globals.protos_lock ); |
137 | rwlock_write_lock( & eth_globals.protos_lock ); |
136 | eth_globals.broadcast_addr = measured_string_create_bulk( "\xFF\xFF\xFF\xFF\xFF\xFF", CONVERT_SIZE( uint8_t, char, ETH_ADDR )); |
138 | eth_globals.broadcast_addr = measured_string_create_bulk( "\xFF\xFF\xFF\xFF\xFF\xFF", CONVERT_SIZE( uint8_t, char, ETH_ADDR )); |
137 | if( ! eth_globals.broadcast_addr ) return ENOMEM; |
139 | if( ! eth_globals.broadcast_addr ) return ENOMEM; |
138 | ERROR_PROPAGATE( eth_devices_initialize( & eth_globals.devices )); |
140 | ERROR_PROPAGATE( eth_devices_initialize( & eth_globals.devices )); |
139 | if( ERROR_OCCURRED( eth_protos_initialize( & eth_globals.protos ))){ |
141 | if( ERROR_OCCURRED( eth_protos_initialize( & eth_globals.protos ))){ |
140 | eth_devices_destroy( & eth_globals.devices ); |
142 | eth_devices_destroy( & eth_globals.devices ); |
141 | return ERROR_CODE; |
143 | return ERROR_CODE; |
142 | } |
144 | } |
143 | rwlock_write_unlock( & eth_globals.protos_lock ); |
145 | rwlock_write_unlock( & eth_globals.protos_lock ); |
144 | rwlock_write_unlock( & eth_globals.devices_lock ); |
146 | rwlock_write_unlock( & eth_globals.devices_lock ); |
145 | return EOK; |
147 | return EOK; |
146 | } |
148 | } |
147 | 149 | ||
148 | int eth_device_message( device_id_t device_id, services_t service, size_t mtu ){ |
150 | int eth_device_message( device_id_t device_id, services_t service, size_t mtu ){ |
149 | ERROR_DECLARE; |
151 | ERROR_DECLARE; |
150 | 152 | ||
151 | aid_t message; |
153 | aid_t message; |
152 | ipc_call_t answer; |
154 | ipc_call_t answer; |
153 | eth_device_ref device; |
155 | eth_device_ref device; |
- | 156 | ipcarg_t result; |
|
154 | int result; |
157 | int index; |
155 | 158 | ||
156 | rwlock_write_lock( & eth_globals.devices_lock ); |
159 | rwlock_write_lock( & eth_globals.devices_lock ); |
157 | // an existing device? |
160 | // an existing device? |
158 | device = eth_devices_find( & eth_globals.devices, device_id ); |
161 | device = eth_devices_find( & eth_globals.devices, device_id ); |
159 | if( device ){ |
162 | if( device ){ |
160 | if( device->service != service ){ |
163 | if( device->service != service ){ |
161 | printf( "\nDevice %d already exists", device->device_id ); |
164 | printf( "\nDevice %d already exists", device->device_id ); |
162 | rwlock_write_unlock( & eth_globals.devices_lock ); |
165 | rwlock_write_unlock( & eth_globals.devices_lock ); |
163 | return EEXIST; |
166 | return EEXIST; |
164 | }else{ |
167 | }else{ |
165 | // update mtu |
168 | // update mtu |
166 | device->mtu = mtu; |
169 | device->mtu = mtu; |
167 | printf( "\nDevice %d already exists:\tMTU\t= %d", device->device_id, device->mtu ); |
170 | printf( "\nDevice %d already exists:\tMTU\t= %d", device->device_id, device->mtu ); |
168 | } |
171 | } |
169 | }else{ |
172 | }else{ |
170 | // create a new device |
173 | // create a new device |
171 | device = ( eth_device_ref ) malloc( sizeof( eth_device_t )); |
174 | device = ( eth_device_ref ) malloc( sizeof( eth_device_t )); |
172 | if( ! device ) return ENOMEM; |
175 | if( ! device ) return ENOMEM; |
173 | device->device_id = device_id; |
176 | device->device_id = device_id; |
174 | device->service = service; |
177 | device->service = service; |
175 | device->mtu = ( mtu > 0 ) ? mtu : ETH_MAX_CONTENT; |
178 | device->mtu = ( mtu > 0 ) ? mtu : ETH_MAX_CONTENT; |
176 | // TODO get dummy setting |
179 | // TODO get dummy setting |
177 | device->dummy = 0; |
180 | device->dummy = 0; |
178 | // bind the device driver |
181 | // bind the device driver |
179 | device->phone = bind_service( device->service, device->device_id, SERVICE_ETHERNET, 0, eth_receiver ); |
182 | device->phone = bind_service( device->service, device->device_id, SERVICE_ETHERNET, 0, eth_receiver ); |
180 | if( device->phone < 0 ){ |
183 | if( device->phone < 0 ){ |
181 | rwlock_write_unlock( & eth_globals.devices_lock ); |
184 | rwlock_write_unlock( & eth_globals.devices_lock ); |
182 | free( device ); |
185 | free( device ); |
183 | return device->phone; |
186 | return device->phone; |
184 | } |
187 | } |
185 | // get hardware address |
188 | // get hardware address |
186 | message = async_send_1( device->phone, NET_NETIF_GET_ADDR, device->device_id, & answer ); |
189 | message = async_send_1( device->phone, NET_NETIF_GET_ADDR, device->device_id, & answer ); |
187 | if( ERROR_OCCURRED( measured_strings_return( device->phone, & device->addr, & device->addr_data, 1 ))){ |
190 | if( ERROR_OCCURRED( measured_strings_return( device->phone, & device->addr, & device->addr_data, 1 ))){ |
188 | rwlock_write_unlock( & eth_globals.devices_lock ); |
191 | rwlock_write_unlock( & eth_globals.devices_lock ); |
189 | free( device ); |
192 | free( device ); |
190 | async_wait_for( message, NULL ); |
193 | async_wait_for( message, NULL ); |
191 | return ERROR_CODE; |
194 | return ERROR_CODE; |
192 | } |
195 | } |
193 | async_wait_for( message, ( ipcarg_t * ) & result ); |
196 | async_wait_for( message, & result ); |
194 | if( ERROR_OCCURRED( result )){ |
197 | if( ERROR_OCCURRED( result )){ |
195 | rwlock_write_unlock( & eth_globals.devices_lock ); |
198 | rwlock_write_unlock( & eth_globals.devices_lock ); |
196 | free( device->addr ); |
199 | free( device->addr ); |
197 | free( device->addr_data ); |
200 | free( device->addr_data ); |
198 | free( device ); |
201 | free( device ); |
199 | return ERROR_CODE; |
202 | return ERROR_CODE; |
200 | } |
203 | } |
201 | // add to the cache |
204 | // add to the cache |
202 | if( ERROR_OCCURRED( eth_devices_add( & eth_globals.devices, device->device_id, device ))){ |
205 | index = eth_devices_add( & eth_globals.devices, device->device_id, device ); |
- | 206 | if( index < 0 ){ |
|
203 | rwlock_write_unlock( & eth_globals.devices_lock ); |
207 | rwlock_write_unlock( & eth_globals.devices_lock ); |
204 | free( device->addr ); |
208 | free( device->addr ); |
205 | free( device->addr_data ); |
209 | free( device->addr_data ); |
206 | free( device ); |
210 | free( device ); |
207 | return ERROR_CODE; |
211 | return index; |
208 | } |
212 | } |
209 | 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 ] ); |
213 | 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 ] ); |
210 | } |
214 | } |
211 | rwlock_write_unlock( & eth_globals.devices_lock ); |
215 | rwlock_write_unlock( & eth_globals.devices_lock ); |
212 | return EOK; |
216 | return EOK; |
213 | } |
217 | } |
214 | 218 | ||
215 | eth_proto_ref eth_proccess_packet( int dummy, packet_t packet ){ |
219 | eth_proto_ref eth_process_packet( int dummy, packet_t packet ){ |
216 | ERROR_DECLARE; |
220 | ERROR_DECLARE; |
217 | 221 | ||
218 | eth_header_ex_ref header; |
222 | eth_header_ex_ref header; |
219 | size_t length; |
223 | size_t length; |
220 | int type; |
224 | int type; |
221 | size_t prefix; |
225 | size_t prefix; |
222 | size_t suffix; |
226 | size_t suffix; |
223 | eth_fcs_ref fcs; |
227 | eth_fcs_ref fcs; |
224 | 228 | ||
225 | length = packet_get_data_length( packet ); |
229 | length = packet_get_data_length( packet ); |
226 | if( dummy ){ |
230 | if( dummy ){ |
227 | packet_trim( packet, sizeof( eth_preamble_t ), 0 ); |
231 | packet_trim( packet, sizeof( eth_preamble_t ), 0 ); |
228 | } |
232 | } |
229 | if( length <= sizeof( eth_header_t ) + ETH_MIN_CONTENT + ETH_SUFFIX ) return NULL; |
233 | if( length <= sizeof( eth_header_t ) + ETH_MIN_CONTENT + ETH_SUFFIX ) return NULL; |
230 | header = ( eth_header_ex_ref ) packet_get_data( packet ); |
234 | header = ( eth_header_ex_ref ) packet_get_data( packet ); |
231 | type = ntohs( header->header.ethertype ); |
235 | type = ntohs( header->header.ethertype ); |
232 | if( type >= ETH_MIN_PROTO ){ |
236 | if( type >= ETH_MIN_PROTO ){ |
233 | // DIX Ethernet |
237 | // DIX Ethernet |
234 | prefix = sizeof( eth_header_t ); |
238 | prefix = sizeof( eth_header_t ); |
235 | suffix = sizeof( eth_fcs_t ); |
239 | suffix = sizeof( eth_fcs_t ); |
236 | fcs = (( void * ) header ) + length - suffix; |
240 | fcs = (( void * ) header ) + length - suffix; |
237 | }else if( type <= ETH_MAX_CONTENT ){ |
241 | }else if( type <= ETH_MAX_CONTENT ){ |
238 | // translate "LSAP" values |
242 | // translate "LSAP" values |
239 | if(( header->lsap.dsap == ETH_LSAP_GLSAP ) && ( header->lsap.ssap == ETH_LSAP_GLSAP )){ |
243 | if(( header->lsap.dsap == ETH_LSAP_GLSAP ) && ( header->lsap.ssap == ETH_LSAP_GLSAP )){ |
240 | // raw packet |
244 | // raw packet |
241 | // discard |
245 | // discard |
242 | return NULL; |
246 | return NULL; |
243 | }else if(( header->lsap.dsap == ETH_LSAP_SNAP ) && ( header->lsap.ssap == ETH_LSAP_SNAP )){ |
247 | }else if(( header->lsap.dsap == ETH_LSAP_SNAP ) && ( header->lsap.ssap == ETH_LSAP_SNAP )){ |
244 | // IEEE 802.3 + 802.2 + LSAP + SNAP |
248 | // IEEE 802.3 + 802.2 + LSAP + SNAP |
245 | // organization code not supported |
249 | // organization code not supported |
246 | type = ntohs( header->snap.ethertype ); |
250 | type = ntohs( header->snap.ethertype ); |
247 | prefix = sizeof( eth_header_t ) + sizeof( eth_header_lsap_t) + sizeof( eth_header_snap_t); |
251 | prefix = sizeof( eth_header_t ) + sizeof( eth_header_lsap_t) + sizeof( eth_header_snap_t); |
248 | }else{ |
252 | }else{ |
249 | // IEEE 802.3 + 802.2 LSAP |
253 | // IEEE 802.3 + 802.2 LSAP |
250 | type = lsap_map( header->lsap.dsap ); |
254 | type = lsap_map( header->lsap.dsap ); |
251 | prefix = sizeof( eth_header_t ) + sizeof( eth_header_lsap_t); |
255 | prefix = sizeof( eth_header_t ) + sizeof( eth_header_lsap_t); |
252 | } |
256 | } |
253 | suffix = ( type < ETH_MIN_CONTENT ) ? ETH_MIN_CONTENT - type : 0; |
257 | suffix = ( type < ETH_MIN_CONTENT ) ? ETH_MIN_CONTENT - type : 0; |
254 | fcs = (( void * ) header ) + prefix + type + suffix; |
258 | fcs = (( void * ) header ) + prefix + type + suffix; |
255 | suffix += length - prefix - type; |
259 | suffix += length - prefix - type; |
256 | }else{ |
260 | }else{ |
257 | // invalid length/type, should not occurr |
261 | // invalid length/type, should not occurr |
258 | return NULL; |
262 | return NULL; |
259 | } |
263 | } |
260 | if( dummy ){ |
264 | if( dummy ){ |
261 | if(( ~ compute_crc32( ~ 0, & header->header.dest, ((( void * ) fcs ) - (( void * ) & header->header.dest )) * 8 )) != ntohl( * fcs )){ |
265 | if(( ~ compute_crc32( ~ 0, & header->header.dest, ((( void * ) fcs ) - (( void * ) & header->header.dest )) * 8 )) != ntohl( * fcs )){ |
262 | return NULL; |
266 | return NULL; |
263 | } |
267 | } |
264 | } |
268 | } |
265 | if( ERROR_OCCURRED( packet_set_addr( packet, header->header.src, header->header.dest, ETH_ADDR )) |
269 | if( ERROR_OCCURRED( packet_set_addr( packet, header->header.src, header->header.dest, ETH_ADDR )) |
266 | || ERROR_OCCURRED( packet_trim( packet, prefix, suffix ))){ |
270 | || ERROR_OCCURRED( packet_trim( packet, prefix, suffix ))){ |
267 | return NULL; |
271 | return NULL; |
268 | } |
272 | } |
269 | return eth_protos_find( & eth_globals.protos, type ); |
273 | return eth_protos_find( & eth_globals.protos, type ); |
270 | } |
274 | } |
271 | 275 | ||
272 | int eth_receive_message( device_id_t device_id, packet_t packet ){ |
276 | int eth_receive_message( device_id_t device_id, packet_t packet ){ |
273 | eth_proto_ref proto; |
277 | eth_proto_ref proto; |
274 | packet_t next; |
278 | packet_t next; |
275 | eth_device_ref device; |
279 | eth_device_ref device; |
276 | int dummy; |
280 | int dummy; |
277 | 281 | ||
278 | rwlock_read_lock( & eth_globals.devices_lock ); |
282 | rwlock_read_lock( & eth_globals.devices_lock ); |
279 | device = eth_devices_find( & eth_globals.devices, device_id ); |
283 | device = eth_devices_find( & eth_globals.devices, device_id ); |
280 | if( ! device ){ |
284 | if( ! device ){ |
281 | rwlock_read_unlock( & eth_globals.devices_lock ); |
285 | rwlock_read_unlock( & eth_globals.devices_lock ); |
282 | return ENOENT; |
286 | return ENOENT; |
283 | } |
287 | } |
284 | dummy = device->dummy; |
288 | dummy = device->dummy; |
285 | rwlock_read_unlock( & eth_globals.devices_lock ); |
289 | rwlock_read_unlock( & eth_globals.devices_lock ); |
286 | rwlock_read_lock( & eth_globals.protos_lock ); |
290 | rwlock_read_lock( & eth_globals.protos_lock ); |
287 | do{ |
291 | do{ |
288 | next = pq_detach( packet ); |
292 | next = pq_detach( packet ); |
289 | proto = eth_proccess_packet( dummy, packet ); |
293 | proto = eth_process_packet( dummy, packet ); |
290 | if( proto ){ |
294 | if( proto ){ |
291 | async_msg_2( proto->phone, NET_IL_RECEIVED, device_id, packet_get_id( packet )); |
295 | async_msg_2( proto->phone, NET_IL_RECEIVED, device_id, packet_get_id( packet )); |
292 | }else{ |
296 | }else{ |
293 | // drop invalid/unknown |
297 | // drop invalid/unknown |
294 | packet_release( eth_globals.networking_phone, packet_get_id( packet )); |
298 | pq_release( eth_globals.networking_phone, packet_get_id( packet )); |
295 | } |
299 | } |
296 | packet = next; |
300 | packet = next; |
297 | }while( packet ); |
301 | }while( packet ); |
298 | rwlock_read_unlock( & eth_globals.protos_lock ); |
302 | rwlock_read_unlock( & eth_globals.protos_lock ); |
299 | return EOK; |
303 | return EOK; |
300 | } |
304 | } |
301 | 305 | ||
302 | int eth_packet_space_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ){ |
306 | int eth_packet_space_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ){ |
303 | eth_device_ref device; |
307 | eth_device_ref device; |
304 | 308 | ||
305 | if( !( addr_len && prefix && content && suffix )) return EINVAL; |
309 | if( !( addr_len && prefix && content && suffix )) return EINVAL; |
306 | rwlock_write_lock( & eth_globals.devices_lock ); |
310 | rwlock_read_lock( & eth_globals.devices_lock ); |
307 | device = eth_devices_find( & eth_globals.devices, device_id ); |
311 | device = eth_devices_find( & eth_globals.devices, device_id ); |
308 | if( ! device ){ |
312 | if( ! device ){ |
309 | rwlock_write_unlock( & eth_globals.devices_lock ); |
313 | rwlock_read_unlock( & eth_globals.devices_lock ); |
310 | return ENOENT; |
314 | return ENOENT; |
311 | } |
315 | } |
312 | * content = ( ETH_MAX_CONTENT > device->mtu ) ? device->mtu : ETH_MAX_CONTENT; |
316 | * content = ( ETH_MAX_CONTENT > device->mtu ) ? device->mtu : ETH_MAX_CONTENT; |
313 | rwlock_write_unlock( & eth_globals.devices_lock ); |
317 | rwlock_read_unlock( & eth_globals.devices_lock ); |
314 | * addr_len = ETH_ADDR; |
318 | * addr_len = ETH_ADDR; |
315 | * prefix = ETH_PREFIX; |
319 | * prefix = ETH_PREFIX; |
316 | * suffix = ETH_MIN_CONTENT + ETH_SUFFIX; |
320 | * suffix = ETH_MIN_CONTENT + ETH_SUFFIX; |
317 | return EOK; |
321 | return EOK; |
318 | } |
322 | } |
319 | 323 | ||
320 | int eth_addr_message( device_id_t device_id, eth_addr_type_t type, measured_string_ref * address ){ |
324 | int eth_addr_message( device_id_t device_id, eth_addr_type_t type, measured_string_ref * address ){ |
321 | eth_device_ref device; |
325 | eth_device_ref device; |
322 | 326 | ||
323 | if( ! address ) return EINVAL; |
327 | if( ! address ) return EINVAL; |
324 | if( type == ETH_BROADCAST_ADDR ){ |
328 | if( type == ETH_BROADCAST_ADDR ){ |
325 | * address = eth_globals.broadcast_addr; |
329 | * address = eth_globals.broadcast_addr; |
326 | }else{ |
330 | }else{ |
327 | rwlock_write_lock( & eth_globals.devices_lock ); |
331 | rwlock_read_lock( & eth_globals.devices_lock ); |
328 | device = eth_devices_find( & eth_globals.devices, device_id ); |
332 | device = eth_devices_find( & eth_globals.devices, device_id ); |
329 | if( ! device ){ |
333 | if( ! device ){ |
330 | rwlock_write_unlock( & eth_globals.devices_lock ); |
334 | rwlock_read_unlock( & eth_globals.devices_lock ); |
331 | return ENOENT; |
335 | return ENOENT; |
332 | } |
336 | } |
333 | * address = device->addr; |
337 | * address = device->addr; |
334 | rwlock_write_unlock( & eth_globals.devices_lock ); |
338 | rwlock_read_unlock( & eth_globals.devices_lock ); |
335 | } |
339 | } |
336 | return ( * address ) ? EOK : ENOENT; |
340 | return ( * address ) ? EOK : ENOENT; |
337 | } |
341 | } |
338 | 342 | ||
339 | int eth_register_message( services_t service, int phone ){ |
343 | int eth_register_message( services_t service, int phone ){ |
340 | ERROR_DECLARE; |
- | |
341 | - | ||
342 | eth_proto_ref proto; |
344 | eth_proto_ref proto; |
343 | int protocol; |
345 | int protocol; |
- | 346 | int index; |
|
344 | 347 | ||
345 | protocol = protocol_map( SERVICE_ETHERNET, service ); |
348 | protocol = protocol_map( SERVICE_ETHERNET, service ); |
346 | if( ! protocol ) return ENOENT; |
349 | if( ! protocol ) return ENOENT; |
347 | rwlock_write_lock( & eth_globals.protos_lock ); |
350 | rwlock_write_lock( & eth_globals.protos_lock ); |
348 | proto = eth_protos_find( & eth_globals.protos, protocol ); |
351 | proto = eth_protos_find( & eth_globals.protos, protocol ); |
349 | if( proto ){ |
352 | if( proto ){ |
350 | proto->phone = phone; |
353 | proto->phone = phone; |
351 | rwlock_write_unlock( & eth_globals.protos_lock ); |
354 | rwlock_write_unlock( & eth_globals.protos_lock ); |
352 | return EOK; |
355 | return EOK; |
353 | }else{ |
356 | }else{ |
354 | proto = ( eth_proto_ref ) malloc( sizeof( eth_proto_t )); |
357 | proto = ( eth_proto_ref ) malloc( sizeof( eth_proto_t )); |
355 | if( ! proto ){ |
358 | if( ! proto ){ |
356 | rwlock_write_unlock( & eth_globals.protos_lock ); |
359 | rwlock_write_unlock( & eth_globals.protos_lock ); |
357 | return ENOMEM; |
360 | return ENOMEM; |
358 | } |
361 | } |
359 | proto->service = service; |
362 | proto->service = service; |
360 | proto->protocol = protocol; |
363 | proto->protocol = protocol; |
361 | proto->phone = phone; |
364 | proto->phone = phone; |
362 | if( ERROR_OCCURRED( eth_protos_add( & eth_globals.protos, protocol, proto ))){ |
365 | index = eth_protos_add( & eth_globals.protos, protocol, proto ); |
- | 366 | if( index < 0 ){ |
|
363 | rwlock_write_unlock( & eth_globals.protos_lock ); |
367 | rwlock_write_unlock( & eth_globals.protos_lock ); |
364 | free( proto ); |
368 | free( proto ); |
365 | return ERROR_CODE; |
369 | return index; |
366 | } |
370 | } |
367 | } |
371 | } |
368 | printf( "\nNew protocol registered:\n\tprotocol\t= %d\n\tservice\t= %d\n\tphone\t= %d", proto->protocol, proto->service, proto->phone ); |
372 | printf( "\nNew protocol registered:\n\tprotocol\t= 0x%x\n\tservice\t= %d\n\tphone\t= %d", proto->protocol, proto->service, proto->phone ); |
369 | rwlock_write_unlock( & eth_globals.protos_lock ); |
373 | rwlock_write_unlock( & eth_globals.protos_lock ); |
370 | return EOK; |
374 | return EOK; |
371 | } |
375 | } |
372 | 376 | ||
373 | int eth_prepare_packet( int dummy, packet_t packet, uint8_t * src_addr, int ethertype ){ |
377 | int eth_prepare_packet( int dummy, packet_t packet, uint8_t * src_addr, int ethertype ){ |
374 | eth_header_ex_ref header; |
378 | eth_header_ex_ref header; |
375 | eth_fcs_ref fcs; |
379 | eth_fcs_ref fcs; |
376 | uint8_t * src; |
380 | uint8_t * src; |
377 | uint8_t * dest; |
381 | uint8_t * dest; |
378 | int length; |
382 | int length; |
379 | int i; |
383 | int i; |
380 | void * padding; |
384 | void * padding; |
381 | eth_preamble_ref preamble; |
385 | eth_preamble_ref preamble; |
382 | 386 | ||
383 | if( dummy ){ |
387 | if( dummy ){ |
384 | preamble = PACKET_PREFIX( packet, eth_preamble_t ); |
388 | preamble = PACKET_PREFIX( packet, eth_preamble_t ); |
385 | if( ! preamble ) return ENOMEM; |
389 | if( ! preamble ) return ENOMEM; |
386 | for( i = 0; i < 7; ++ i ) preamble->preamble[ i ] = ETH_PREAMBLE; |
390 | for( i = 0; i < 7; ++ i ) preamble->preamble[ i ] = ETH_PREAMBLE; |
387 | preamble->sfd = ETH_SFD; |
391 | preamble->sfd = ETH_SFD; |
388 | } |
392 | } |
389 | header = PACKET_PREFIX( packet, eth_header_ex_t ); |
393 | header = PACKET_PREFIX( packet, eth_header_ex_t ); |
390 | if( ! header ) return ENOMEM; |
394 | if( ! header ) return ENOMEM; |
391 | length = packet_get_addr( packet, & src, & dest ); |
395 | length = packet_get_addr( packet, & src, & dest ); |
392 | if( length < 0 ) return length; |
396 | if( length < 0 ) return length; |
393 | if( length < ETH_ADDR ) return EINVAL; |
397 | if( length < ETH_ADDR ) return EINVAL; |
394 | memcpy( header->header.src, src_addr, ETH_ADDR ); |
398 | memcpy( header->header.src, src_addr, ETH_ADDR ); |
395 | memcpy( & header->header.dest, dest, ETH_ADDR ); |
399 | memcpy( & header->header.dest, dest, ETH_ADDR ); |
396 | length = packet_get_data_length( packet ); |
400 | length = packet_get_data_length( packet ); |
397 | if( length > ETH_MAX_CONTENT ) return EINVAL; |
401 | if( length > ETH_MAX_CONTENT ) return EINVAL; |
398 | if( length < ETH_MIN_CONTENT ){ |
402 | if( length < ETH_MIN_CONTENT ){ |
399 | padding = packet_suffix( packet, ETH_MIN_CONTENT - length ); |
403 | padding = packet_suffix( packet, ETH_MIN_CONTENT - length ); |
400 | if( ! padding ) return ENOMEM; |
404 | if( ! padding ) return ENOMEM; |
401 | memset( padding, 0, ETH_MIN_CONTENT - length ); |
405 | bzero( padding, ETH_MIN_CONTENT - length ); |
402 | } |
406 | } |
403 | header->header.ethertype = htons( length ); |
407 | header->header.ethertype = htons( length ); |
404 | header->lsap.dsap = 0xAA; |
408 | header->lsap.dsap = 0xAA; |
405 | header->lsap.ssap = header->lsap.dsap; |
409 | header->lsap.ssap = header->lsap.dsap; |
406 | header->lsap.ctrl = 0; |
410 | header->lsap.ctrl = 0; |
407 | for( i = 0; i < 3; ++ i ) header->snap.proto[ i ] = 0; |
411 | for( i = 0; i < 3; ++ i ) header->snap.proto[ i ] = 0; |
408 | header->snap.ethertype = ethertype; |
412 | header->snap.ethertype = ethertype; |
409 | if( dummy ){ |
413 | if( dummy ){ |
410 | fcs = PACKET_SUFFIX( packet, eth_fcs_t ); |
414 | fcs = PACKET_SUFFIX( packet, eth_fcs_t ); |
411 | if( ! fcs ) return ENOMEM; |
415 | if( ! fcs ) return ENOMEM; |
412 | * fcs = htonl( ~ compute_crc32( ~ 0, & header->header.dest, ((( void * ) fcs ) - (( void * ) & header->header.dest )) * 8 )); |
416 | * fcs = htonl( ~ compute_crc32( ~ 0, & header->header.dest, ((( void * ) fcs ) - (( void * ) & header->header.dest )) * 8 )); |
413 | } |
417 | } |
414 | return EOK; |
418 | return EOK; |
415 | } |
419 | } |
416 | 420 | ||
417 | int eth_send_message( device_id_t device_id, packet_t packet, services_t sender ){ |
421 | int eth_send_message( device_id_t device_id, packet_t packet, services_t sender ){ |
418 | ERROR_DECLARE; |
422 | ERROR_DECLARE; |
419 | 423 | ||
420 | eth_device_ref device; |
424 | eth_device_ref device; |
421 | packet_t next; |
425 | packet_t next; |
422 | packet_t tmp; |
426 | packet_t tmp; |
423 | int ethertype; |
427 | int ethertype; |
424 | 428 | ||
425 | ethertype = htons( protocol_map( SERVICE_ETHERNET, sender )); |
429 | ethertype = htons( protocol_map( SERVICE_ETHERNET, sender )); |
426 | if( ! ethertype ){ |
430 | if( ! ethertype ){ |
427 | packet_release( eth_globals.networking_phone, packet_get_id( packet )); |
431 | pq_release( eth_globals.networking_phone, packet_get_id( packet )); |
428 | return EINVAL; |
432 | return EINVAL; |
429 | } |
433 | } |
430 | rwlock_read_lock( & eth_globals.devices_lock ); |
434 | rwlock_read_lock( & eth_globals.devices_lock ); |
431 | device = eth_devices_find( & eth_globals.devices, device_id ); |
435 | device = eth_devices_find( & eth_globals.devices, device_id ); |
432 | if( ! device ){ |
436 | if( ! device ){ |
433 | rwlock_read_unlock( & eth_globals.devices_lock ); |
437 | rwlock_read_unlock( & eth_globals.devices_lock ); |
434 | return ENOENT; |
438 | return ENOENT; |
435 | } |
439 | } |
436 | // proccess packet queue |
440 | // process packet queue |
437 | next = packet; |
441 | next = packet; |
438 | do{ |
442 | do{ |
439 | if( ERROR_OCCURRED( eth_prepare_packet( device->dummy, next, ( uint8_t * ) device->addr->value, ethertype ))){ |
443 | if( ERROR_OCCURRED( eth_prepare_packet( device->dummy, next, ( uint8_t * ) device->addr->value, ethertype ))){ |
440 | // release invalid packet |
444 | // release invalid packet |
441 | tmp = pq_detach( next ); |
445 | tmp = pq_detach( next ); |
442 | packet_release( eth_globals.networking_phone, packet_get_id( next )); |
446 | pq_release( eth_globals.networking_phone, packet_get_id( next )); |
443 | next = tmp; |
447 | next = tmp; |
444 | }else{ |
448 | }else{ |
445 | next = pq_next( next ); |
449 | next = pq_next( next ); |
446 | } |
450 | } |
447 | }while( next ); |
451 | }while( next ); |
448 | // send packet queue |
452 | // send packet queue |
449 | async_msg_2( device->phone, NET_NETIF_SEND, device_id, packet_get_id( packet )); |
453 | async_msg_2( device->phone, NET_NETIF_SEND, device_id, packet_get_id( packet )); |
450 | rwlock_read_unlock( & eth_globals.devices_lock ); |
454 | rwlock_read_unlock( & eth_globals.devices_lock ); |
451 | return EOK; |
455 | return EOK; |
452 | } |
456 | } |
453 | 457 | ||
454 | int eth_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
458 | int eth_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
455 | ERROR_DECLARE; |
459 | ERROR_DECLARE; |
456 | 460 | ||
457 | measured_string_ref address; |
461 | measured_string_ref address; |
458 | packet_t packet; |
462 | packet_t packet; |
459 | 463 | ||
460 | * answer_count = 0; |
464 | * answer_count = 0; |
461 | switch( IPC_GET_METHOD( * call )){ |
465 | switch( IPC_GET_METHOD( * call )){ |
462 | case IPC_M_PHONE_HUNGUP: |
466 | case IPC_M_PHONE_HUNGUP: |
463 | return EOK; |
467 | return EOK; |
464 | case NET_NIL_DEVICE: |
468 | case NET_NIL_DEVICE: |
465 | return eth_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), IPC_GET_MTU( call )); |
469 | return eth_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), IPC_GET_MTU( call )); |
466 | case NET_NIL_SEND: |
470 | case NET_NIL_SEND: |
467 | ERROR_PROPAGATE( packet_translate( eth_globals.networking_phone, & packet, IPC_GET_PACKET( call ))); |
471 | ERROR_PROPAGATE( packet_translate( eth_globals.networking_phone, & packet, IPC_GET_PACKET( call ))); |
468 | return eth_send_message( IPC_GET_DEVICE( call ), packet, IPC_GET_SERVICE( call )); |
472 | return eth_send_message( IPC_GET_DEVICE( call ), packet, IPC_GET_SERVICE( call )); |
469 | case NET_NIL_PACKET_SPACE: |
473 | case NET_NIL_PACKET_SPACE: |
470 | 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 ))); |
474 | 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 ))); |
471 | * answer_count = 3; |
475 | * answer_count = 3; |
472 | return EOK; |
476 | return EOK; |
473 | case NET_NIL_ADDR: |
477 | case NET_NIL_ADDR: |
474 | rwlock_read_lock( & eth_globals.devices_lock ); |
- | |
475 | if( ! ERROR_OCCURRED( eth_addr_message( IPC_GET_DEVICE( call ), ETH_LOCAL_ADDR, & address ))){ |
478 | ERROR_PROPAGATE( eth_addr_message( IPC_GET_DEVICE( call ), ETH_LOCAL_ADDR, & address )); |
476 | ERROR_CODE = measured_strings_reply( address, 1 ); |
479 | return measured_strings_reply( address, 1 ); |
477 | } |
- | |
478 | rwlock_read_unlock( & eth_globals.devices_lock ); |
- | |
479 | return ERROR_CODE; |
- | |
480 | case NET_NIL_BROADCAST_ADDR: |
480 | case NET_NIL_BROADCAST_ADDR: |
481 | rwlock_read_lock( & eth_globals.devices_lock ); |
- | |
482 | if( ! ERROR_OCCURRED( eth_addr_message( IPC_GET_DEVICE( call ), ETH_BROADCAST_ADDR, & address ))){ |
481 | ERROR_PROPAGATE( eth_addr_message( IPC_GET_DEVICE( call ), ETH_BROADCAST_ADDR, & address )); |
483 | ERROR_CODE = measured_strings_reply( address, 1 ); |
482 | return measured_strings_reply( address, 1 ); |
484 | } |
- | |
485 | rwlock_read_unlock( & eth_globals.devices_lock ); |
- | |
486 | return ERROR_CODE; |
483 | return ERROR_CODE; |
487 | case IPC_M_CONNECT_TO_ME: |
484 | case IPC_M_CONNECT_TO_ME: |
488 | return eth_register_message( IPC_GET_PROTO( call ), IPC_GET_PHONE( call )); |
485 | return eth_register_message( IPC_GET_PROTO( call ), IPC_GET_PHONE( call )); |
489 | } |
486 | } |
490 | return ENOTSUP; |
487 | return ENOTSUP; |
491 | } |
488 | } |
492 | 489 | ||
493 | void eth_receiver( ipc_callid_t iid, ipc_call_t * icall ){ |
490 | void eth_receiver( ipc_callid_t iid, ipc_call_t * icall ){ |
494 | ERROR_DECLARE; |
491 | ERROR_DECLARE; |
495 | 492 | ||
496 | packet_t packet; |
493 | packet_t packet; |
- | 494 | int index; |
|
- | 495 | eth_proto_ref proto; |
|
497 | 496 | ||
498 | while( true ){ |
497 | while( true ){ |
499 | switch( IPC_GET_METHOD( * icall )){ |
498 | switch( IPC_GET_METHOD( * icall )){ |
500 | case NET_NIL_DEVICE_STATE: |
499 | case NET_NIL_DEVICE_STATE: |
501 | //TODO clear device if off? |
500 | //TODO clear device if off? |
- | 501 | rwlock_read_lock( & eth_globals.protos_lock ); |
|
- | 502 | for( index = eth_protos_count( & eth_globals.protos ) - 1; index >= 0; -- index ){ |
|
- | 503 | proto = eth_protos_get_index( & eth_globals.protos, index ); |
|
- | 504 | if( proto && proto->phone ) async_msg_2( proto->phone, NET_IL_DEVICE_STATE, IPC_GET_DEVICE( icall ), IPC_GET_STATE( icall )); |
|
- | 505 | } |
|
- | 506 | rwlock_read_unlock( & eth_globals.protos_lock ); |
|
- | 507 | ipc_answer_0( iid, EOK ); |
|
502 | break; |
508 | break; |
503 | case NET_NIL_RECEIVED: |
509 | case NET_NIL_RECEIVED: |
504 | if( ! ERROR_OCCURRED( packet_translate( eth_globals.networking_phone, & packet, IPC_GET_PACKET( icall )))){ |
510 | if( ! ERROR_OCCURRED( packet_translate( eth_globals.networking_phone, & packet, IPC_GET_PACKET( icall )))){ |
505 | ERROR_CODE = eth_receive_message( IPC_GET_DEVICE( icall ), packet ); |
511 | ERROR_CODE = eth_receive_message( IPC_GET_DEVICE( icall ), packet ); |
506 | } |
512 | } |
507 | ipc_answer_0( iid, ERROR_CODE ); |
513 | ipc_answer_0( iid, ERROR_CODE ); |
508 | break; |
514 | break; |
509 | default: |
515 | default: |
510 | ipc_answer_0( iid, ENOTSUP ); |
516 | ipc_answer_0( iid, ENOTSUP ); |
511 | } |
517 | } |
512 | iid = async_get_call( icall ); |
518 | iid = async_get_call( icall ); |
513 | } |
519 | } |
514 | } |
520 | } |
515 | 521 | ||
516 | /** @} |
522 | /** @} |
517 | */ |
523 | */ |
518 | 524 |