Subversion Repositories HelenOS

Rev

Rev 4192 | Rev 4261 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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