Subversion Repositories HelenOS

Rev

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

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