Subversion Repositories HelenOS

Rev

Rev 4153 | Rev 4243 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4153 Rev 4163
Line 155... Line 155...
155
 
155
 
156
    rwlock_write_lock( & eth_globals.devices_lock );
156
    rwlock_write_lock( & eth_globals.devices_lock );
157
    // an existing device?
157
    // an existing device?
158
    device = eth_devices_find( & eth_globals.devices, device_id );
158
    device = eth_devices_find( & eth_globals.devices, device_id );
159
    if( device ){
159
    if( device ){
160
        if( device->service == service ){
160
        if( device->service != service ){
161
            // update mtu
-
 
162
            device->mtu = mtu;
-
 
163
            rwlock_write_unlock( & eth_globals.devices_lock );
161
            printf( "\nDevice %d already exists", device->device_id );
164
            return EOK;
-
 
165
        }else{
-
 
166
            rwlock_write_unlock( & eth_globals.devices_lock );
162
            rwlock_write_unlock( & eth_globals.devices_lock );
167
            return EEXIST;
163
            return EEXIST;
-
 
164
        }else{
-
 
165
            // update mtu
-
 
166
            device->mtu = mtu;
-
 
167
            printf( "\nDevice %d already exists:\tMTU\t= %d", device->device_id, device->mtu );
168
        }
168
        }
169
    }else{
169
    }else{
170
        // create a new device
170
        // create a new device
171
        device = ( eth_device_ref ) malloc( sizeof( eth_device_t ));
171
        device = ( eth_device_ref ) malloc( sizeof( eth_device_t ));
172
        if( ! device ) return ENOMEM;
172
        if( ! device ) return ENOMEM;
173
        device->device_id = device_id;
173
        device->device_id = device_id;
174
        device->service = service;
174
        device->service = service;
175
        device->mtu = mtu;
175
        device->mtu = ( mtu > 0 ) ? mtu : ETH_MAX_CONTENT;
176
        // TODO get dummy setting
176
        // TODO get dummy setting
177
        device->dummy = 0;
177
        device->dummy = 0;
178
        // bind the device driver
178
        // bind the device driver
179
        device->phone = bind_service( device->service, device->device_id, SERVICE_ETHERNET, 0, eth_receiver );
179
        device->phone = bind_service( device->service, device->device_id, SERVICE_ETHERNET, 0, eth_receiver );
-
 
180
        if( device->phone < 0 ){
-
 
181
            rwlock_write_unlock( & eth_globals.devices_lock );
-
 
182
            free( device );
-
 
183
            return device->phone;
-
 
184
        }
180
        // get hardware address
185
        // get hardware address
181
        message = async_send_1( device->phone, NET_NETIF_GET_ADDR, device->device_id, & answer );
186
        message = async_send_1( device->phone, NET_NETIF_GET_ADDR, device->device_id, & answer );
182
        if( ERROR_OCCURRED( measured_strings_return( device->phone, & device->addr, & device->addr_data, 1 ))){
187
        if( ERROR_OCCURRED( measured_strings_return( device->phone, & device->addr, & device->addr_data, 1 ))){
183
            rwlock_write_unlock( & eth_globals.devices_lock );
188
            rwlock_write_unlock( & eth_globals.devices_lock );
184
            free( device );
189
            free( device );
Line 199... Line 204...
199
            free( device->addr );
204
            free( device->addr );
200
            free( device->addr_data );
205
            free( device->addr_data );
201
            free( device );
206
            free( device );
202
            return ERROR_CODE;
207
            return ERROR_CODE;
203
        }
208
        }
-
 
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 ] );
204
    }
210
    }
205
    rwlock_write_unlock( & eth_globals.devices_lock );
211
    rwlock_write_unlock( & eth_globals.devices_lock );
206
    return EOK;
212
    return EOK;
207
}
213
}
208
 
214
 
Line 301... Line 307...
301
    device = eth_devices_find( & eth_globals.devices, device_id );
307
    device = eth_devices_find( & eth_globals.devices, device_id );
302
    if( ! device ){
308
    if( ! device ){
303
        rwlock_write_unlock( & eth_globals.devices_lock );
309
        rwlock_write_unlock( & eth_globals.devices_lock );
304
        return ENOENT;
310
        return ENOENT;
305
    }
311
    }
306
    * content = (  ETH_MAX_CONTENT > device->mtu ) ? device->mtu : ETH_MAX_CONTENT;
312
    * content = ( ETH_MAX_CONTENT > device->mtu ) ? device->mtu : ETH_MAX_CONTENT;
307
    rwlock_write_unlock( & eth_globals.devices_lock );
313
    rwlock_write_unlock( & eth_globals.devices_lock );
308
    * addr_len = ETH_ADDR;
314
    * addr_len = ETH_ADDR;
309
    * prefix = ETH_PREFIX;
315
    * prefix = ETH_PREFIX;
310
    * suffix = ETH_MIN_CONTENT + ETH_SUFFIX;
316
    * suffix = ETH_MIN_CONTENT + ETH_SUFFIX;
311
    return EOK;
317
    return EOK;
Line 357... Line 363...
357
            rwlock_write_unlock( & eth_globals.protos_lock );
363
            rwlock_write_unlock( & eth_globals.protos_lock );
358
            free( proto );
364
            free( proto );
359
            return ERROR_CODE;
365
            return ERROR_CODE;
360
        }
366
        }
361
    }
367
    }
-
 
368
    printf( "\nNew protocol registered:\n\tprotocol\t= %d\n\tservice\t= %d\n\tphone\t= %d", proto->protocol, proto->service, proto->phone );
362
    rwlock_write_unlock( & eth_globals.protos_lock );
369
    rwlock_write_unlock( & eth_globals.protos_lock );
363
    return EOK;
370
    return EOK;
364
}
371
}
365
 
372
 
366
int eth_prepare_packet( int dummy, packet_t packet, uint8_t * src_addr, int ethertype ){
373
int eth_prepare_packet( int dummy, packet_t packet, uint8_t * src_addr, int ethertype ){