Changeset 7715994 in mainline for uspace/srv/net/net/net.c
- Timestamp:
- 2010-03-13T12:17:02Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6ba20a6b
- Parents:
- d0febca (diff), 2070570 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/net/net.c
rd0febca r7715994 66 66 #include "net_messages.h" 67 67 68 /** File read buffer size. 69 */ 70 #define BUFFER_SIZE 256 71 68 72 /** Networking module name. 69 73 */ 70 74 #define NAME "Networking" 71 75 72 /** File read buffer size. 73 */ 74 #define BUFFER_SIZE 256 76 /** Networking module global data. 77 */ 78 net_globals_t net_globals; 79 80 /** Generates new system-unique device identifier. 81 * @returns The system-unique devic identifier. 82 */ 83 device_id_t generate_new_device_id(void); 75 84 76 85 /** Prints the module name. 77 86 * @see NAME 78 87 */ 79 void module_print_name( void);88 void module_print_name(void); 80 89 81 90 /** Starts the networking module. … … 86 95 * @returns Other error codes as defined for the REGISTER_ME() macro function. 87 96 */ 88 int module_start( async_client_conn_t client_connection ); 97 int module_start(async_client_conn_t client_connection); 98 99 /** Returns the configured values. 100 * The network interface configuration is searched first. 101 * @param[in] netif_conf The network interface configuration setting. 102 * @param[out] configuration The found configured values. 103 * @param[in] count The desired settings count. 104 * @param[out] data The found configuration settings data. 105 * @returns EOK. 106 */ 107 int net_get_conf(measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data); 108 109 /** Initializes the networking module. 110 * @param[in] client_connection The client connection processing function. The module skeleton propagates its own one. 111 * @returns EOK on success. 112 * @returns ENOMEM if there is not enough memory left. 113 */ 114 int net_initialize(async_client_conn_t client_connection); 89 115 90 116 /** \todo 91 117 */ 92 int read_configuration_file( const char * directory, const char * filename, measured_strings_ref configuration ); 93 94 /** \todo 95 */ 96 int parse_line( measured_strings_ref configuration, char * line ); 118 int parse_line(measured_strings_ref configuration, char * line); 97 119 98 120 /** Reads the networking subsystem global configuration. … … 100 122 * @returns Other error codes as defined for the add_configuration() function. 101 123 */ 102 int read_configuration( void ); 124 int read_configuration(void); 125 126 /** \todo 127 */ 128 int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration); 129 130 /** Reads the network interface specific configuration. 131 * @param[in] name The network interface name. 132 * @param[in,out] netif The network interface structure. 133 * @returns EOK on success. 134 * @returns Other error codes as defined for the add_configuration() function. 135 */ 136 int read_netif_configuration(const char * name, netif_ref netif); 103 137 104 138 /** Starts the network interface according to its configuration. … … 113 147 * @returns Other error codes as defined for the needed internet layer registering function. 114 148 */ 115 int start_device( netif_ref netif);149 int start_device(netif_ref netif); 116 150 117 151 /** Reads the configuration and starts all network interfaces. … … 124 158 * @returns Other error codes as defined for the start_device() function. 125 159 */ 126 int startup( void ); 127 128 /** Generates new system-unique device identifier. 129 * @returns The system-unique devic identifier. 130 */ 131 device_id_t generate_new_device_id( void ); 132 133 /** Returns the configured values. 134 * The network interface configuration is searched first. 135 * @param[in] netif_conf The network interface configuration setting. 136 * @param[out] configuration The found configured values. 137 * @param[in] count The desired settings count. 138 * @param[out] data The found configuration settings data. 139 * @returns EOK. 140 */ 141 int net_get_conf( measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data ); 142 143 /** Initializes the networking module. 144 * @param[in] client_connection The client connection processing function. The module skeleton propagates its own one. 145 * @returns EOK on success. 146 * @returns ENOMEM if there is not enough memory left. 147 */ 148 int net_initialize( async_client_conn_t client_connection ); 149 150 /** Reads the network interface specific configuration. 151 * @param[in] name The network interface name. 152 * @param[in,out] netif The network interface structure. 153 * @returns EOK on success. 154 * @returns Other error codes as defined for the add_configuration() function. 155 */ 156 int read_netif_configuration( char * name, netif_ref netif ); 157 158 /** Networking module global data. 159 */ 160 net_globals_t net_globals; 161 162 DEVICE_MAP_IMPLEMENT( netifs, netif_t ) 163 164 GENERIC_CHAR_MAP_IMPLEMENT( measured_strings, measured_string_t ) 165 166 void module_print_name( void ){ 167 printf( "%s", NAME ); 168 } 169 170 int module_start( async_client_conn_t client_connection ){ 171 ERROR_DECLARE; 172 173 ipcarg_t phonehash; 174 175 async_set_client_connection( client_connection ); 176 ERROR_PROPAGATE( pm_init()); 177 if( ERROR_OCCURRED( net_initialize( client_connection )) 178 || ERROR_OCCURRED( REGISTER_ME( SERVICE_NETWORKING, & phonehash ))){ 160 int startup(void); 161 162 GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t) 163 164 DEVICE_MAP_IMPLEMENT(netifs, netif_t) 165 166 int add_configuration(measured_strings_ref configuration, const char * name, const char * value){ 167 ERROR_DECLARE; 168 169 measured_string_ref setting; 170 171 setting = measured_string_create_bulk(value, 0); 172 if(! setting){ 173 return ENOMEM; 174 } 175 // add the configuration setting 176 if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){ 177 free(setting); 178 return ERROR_CODE; 179 } 180 return EOK; 181 } 182 183 device_id_t generate_new_device_id(void){ 184 return device_assign_devno(); 185 } 186 187 void module_print_name(void){ 188 printf("%s", NAME); 189 } 190 191 int module_start(async_client_conn_t client_connection){ 192 ERROR_DECLARE; 193 194 ipcarg_t phonehash; 195 196 async_set_client_connection(client_connection); 197 ERROR_PROPAGATE(pm_init()); 198 if(ERROR_OCCURRED(net_initialize(client_connection)) 199 || ERROR_OCCURRED(REGISTER_ME(SERVICE_NETWORKING, &phonehash))){ 179 200 pm_destroy(); 180 201 return ERROR_CODE; … … 187 208 } 188 209 189 int net_initialize( async_client_conn_t client_connection ){ 190 ERROR_DECLARE; 191 192 netifs_initialize( & net_globals.netifs ); 193 char_map_initialize( & net_globals.netif_names ); 194 modules_initialize( & net_globals.modules ); 195 measured_strings_initialize( & net_globals.configuration ); 210 int net_connect_module(services_t service){ 211 return EOK; 212 } 213 214 void net_free_settings(measured_string_ref settings, char * data){ 215 } 216 217 int net_get_conf(measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data){ 218 measured_string_ref setting; 219 size_t index; 220 221 if(data){ 222 *data = NULL; 223 } 224 225 for(index = 0; index < count; ++ index){ 226 setting = measured_strings_find(netif_conf, configuration[index].value, 0); 227 if(! setting){ 228 setting = measured_strings_find(&net_globals.configuration, configuration[index].value, 0); 229 } 230 if(setting){ 231 configuration[index].length = setting->length; 232 configuration[index].value = setting->value; 233 }else{ 234 configuration[index].length = 0; 235 configuration[index].value = NULL; 236 } 237 } 238 return EOK; 239 } 240 241 int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data){ 242 if(!(configuration && (count > 0))){ 243 return EINVAL; 244 } 245 246 return net_get_conf(NULL, * configuration, count, data); 247 } 248 249 int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data){ 250 netif_ref netif; 251 252 if(!(configuration && (count > 0))){ 253 return EINVAL; 254 } 255 256 netif = netifs_find(&net_globals.netifs, device_id); 257 if(netif){ 258 return net_get_conf(&netif->configuration, * configuration, count, data); 259 }else{ 260 return net_get_conf(NULL, * configuration, count, data); 261 } 262 } 263 264 int net_initialize(async_client_conn_t client_connection){ 265 ERROR_DECLARE; 266 267 netifs_initialize(&net_globals.netifs); 268 char_map_initialize(&net_globals.netif_names); 269 modules_initialize(&net_globals.modules); 270 measured_strings_initialize(&net_globals.configuration); 196 271 197 272 // TODO dynamic configuration 198 ERROR_PROPAGATE( 199 200 ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service));201 ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service));202 ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service));203 ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service));273 ERROR_PROPAGATE(read_configuration()); 274 275 ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service)); 276 ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service)); 277 ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service)); 278 ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service)); 204 279 205 280 // build specific initialization 206 return net_initialize_build( client_connection ); 207 } 208 209 int net_get_device_conf_req( int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data ){ 210 netif_ref netif; 211 212 if( !( configuration && ( count > 0 ))) return EINVAL; 213 netif = netifs_find( & net_globals.netifs, device_id ); 214 if( netif ){ 215 return net_get_conf( & netif->configuration, * configuration, count, data ); 216 }else{ 217 return net_get_conf( NULL, * configuration, count, data ); 218 } 219 } 220 221 int net_get_conf_req( int net_phone, measured_string_ref * configuration, size_t count, char ** data ){ 222 if( !( configuration && ( count > 0 ))) return EINVAL; 223 return net_get_conf( NULL, * configuration, count, data ); 224 } 225 226 int net_get_conf( measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data ){ 227 measured_string_ref setting; 228 size_t index; 229 230 if( data ) * data = NULL; 231 for( index = 0; index < count; ++ index ){ 232 setting = measured_strings_find( netif_conf, configuration[ index ].value, 0 ); 233 if( ! setting ){ 234 setting = measured_strings_find( & net_globals.configuration, configuration[ index ].value, 0 ); 235 } 236 if( setting ){ 237 configuration[ index ].length = setting->length; 238 configuration[ index ].value = setting->value; 239 }else{ 240 configuration[ index ].length = 0; 241 configuration[ index ].value = NULL; 242 } 243 } 244 return EOK; 245 } 246 247 void net_free_settings( measured_string_ref settings, char * data ){ 248 } 249 250 int net_connect_module( services_t service ){ 251 return EOK; 252 } 253 254 int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ 255 ERROR_DECLARE; 256 257 measured_string_ref strings; 258 char * data; 259 260 * answer_count = 0; 261 switch( IPC_GET_METHOD( * call )){ 281 return net_initialize_build(client_connection); 282 } 283 284 int net_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 285 ERROR_DECLARE; 286 287 measured_string_ref strings; 288 char * data; 289 290 *answer_count = 0; 291 switch(IPC_GET_METHOD(*call)){ 262 292 case IPC_M_PHONE_HUNGUP: 263 293 return EOK; 264 294 case NET_NET_GET_DEVICE_CONF: 265 ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call)));266 net_get_device_conf_req( 0, IPC_GET_DEVICE( call ), & strings, IPC_GET_COUNT( call ), NULL);295 ERROR_PROPAGATE(measured_strings_receive(&strings, &data, IPC_GET_COUNT(call))); 296 net_get_device_conf_req(0, IPC_GET_DEVICE(call), &strings, IPC_GET_COUNT(call), NULL); 267 297 // strings should not contain received data anymore 268 free( data);269 ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call));270 free( strings);298 free(data); 299 ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call)); 300 free(strings); 271 301 return ERROR_CODE; 272 302 case NET_NET_GET_CONF: 273 ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call)));274 net_get_conf_req( 0, & strings, IPC_GET_COUNT( call ), NULL);303 ERROR_PROPAGATE(measured_strings_receive(&strings, &data, IPC_GET_COUNT(call))); 304 net_get_conf_req(0, &strings, IPC_GET_COUNT(call), NULL); 275 305 // strings should not contain received data anymore 276 free( data);277 ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call));278 free( strings);306 free(data); 307 ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call)); 308 free(strings); 279 309 return ERROR_CODE; 280 310 case NET_NET_STARTUP: … … 284 314 } 285 315 286 int read_configuration_file( const char * directory, const char * filename, measured_strings_ref configuration ){ 287 ERROR_DECLARE; 288 289 size_t index = 0; 290 char line[ BUFFER_SIZE ]; 291 FILE * cfg; 292 int read; 293 int line_number = 0; 316 int parse_line(measured_strings_ref configuration, char * line){ 317 ERROR_DECLARE; 318 319 measured_string_ref setting; 320 char * name; 321 char * value; 322 323 // from the beginning 324 name = line; 325 326 // skip comments and blank lines 327 if((*name == '#') || (*name == '\0')){ 328 return EOK; 329 } 330 // skip spaces 331 while(isspace(*name)){ 332 ++ name; 333 } 334 335 // remember the name start 336 value = name; 337 // skip the name 338 while(isalnum(*value) || (*value == '_')){ 339 // make uppercase 340 // *value = toupper(*value); 341 ++ value; 342 } 343 344 if(*value == '='){ 345 // terminate the name 346 *value = '\0'; 347 }else{ 348 // terminate the name 349 *value = '\0'; 350 // skip until '=' 351 ++ value; 352 while((*value) && (*value != '=')){ 353 ++ value; 354 } 355 // not found? 356 if(*value != '='){ 357 return EINVAL; 358 } 359 } 360 361 ++ value; 362 // skip spaces 363 while(isspace(*value)){ 364 ++ value; 365 } 366 // create a bulk measured string till the end 367 setting = measured_string_create_bulk(value, 0); 368 if(! setting){ 369 return ENOMEM; 370 } 371 372 // add the configuration setting 373 if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){ 374 free(setting); 375 return ERROR_CODE; 376 } 377 return EOK; 378 } 379 380 int read_configuration(void){ 381 // read the general configuration file 382 return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, &net_globals.configuration); 383 } 384 385 int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration){ 386 ERROR_DECLARE; 387 388 size_t index = 0; 389 char line[BUFFER_SIZE]; 390 FILE * cfg; 391 int read; 392 int line_number = 0; 294 393 295 394 // construct the full filename 296 printf( "Reading file %s/%s\n", directory, filename);297 if( snprintf( line, BUFFER_SIZE, "%s/%s", directory, filename ) > BUFFER_SIZE){395 printf("Reading file %s/%s\n", directory, filename); 396 if(snprintf(line, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE){ 298 397 return EOVERFLOW; 299 398 } 300 399 // open the file 301 cfg = fopen( line, "r");302 if( ! cfg){400 cfg = fopen(line, "r"); 401 if(! cfg){ 303 402 return ENOENT; 304 403 } … … 306 405 // read the configuration line by line 307 406 // until an error or the end of file 308 while(( ! ferror( cfg )) && ( ! feof( cfg))){309 read = fgetc( cfg);310 if(( read > 0 ) && ( read != '\n' ) && ( read != '\r')){311 if( index >= BUFFER_SIZE){312 line[ BUFFER_SIZE - 1] = '\0';313 printf( "line %d too long: %s\n", line_number, line);407 while((! ferror(cfg)) && (! feof(cfg))){ 408 read = fgetc(cfg); 409 if((read > 0) && (read != '\n') && (read != '\r')){ 410 if(index >= BUFFER_SIZE){ 411 line[BUFFER_SIZE - 1] = '\0'; 412 printf("line %d too long: %s\n", line_number, line); 314 413 // no space left in the line buffer 315 414 return EOVERFLOW; 316 415 }else{ 317 416 // append the character 318 line[ index] = (char) read;417 line[index] = (char) read; 319 418 ++ index; 320 419 } 321 420 }else{ 322 421 // on error or new line 323 line[ index] = '\0';422 line[index] = '\0'; 324 423 ++ line_number; 325 if( ERROR_OCCURRED( parse_line( configuration, line))){326 printf( "error on line %d: %s\n", line_number, line);327 //fclose( cfg);424 if(ERROR_OCCURRED(parse_line(configuration, line))){ 425 printf("error on line %d: %s\n", line_number, line); 426 //fclose(cfg); 328 427 //return ERROR_CODE; 329 428 } … … 331 430 } 332 431 } 333 fclose( cfg ); 334 return EOK; 335 } 336 337 int parse_line( measured_strings_ref configuration, char * line ){ 338 ERROR_DECLARE; 339 340 measured_string_ref setting; 341 char * name; 342 char * value; 343 344 // from the beginning 345 name = line; 346 347 // skip comments and blank lines 348 if(( * name == '#' ) || ( * name == '\0' )){ 349 return EOK; 350 } 351 // skip spaces 352 while( isspace( * name )) ++ name; 353 354 // remember the name start 355 value = name; 356 // skip the name 357 while( isalnum( * value ) || ( * value == '_' )){ 358 // make uppercase 359 // * value = toupper( * value ); 360 ++ value; 361 } 362 363 if( * value == '=' ){ 364 // terminate the name 365 * value = '\0'; 366 }else{ 367 // terminate the name 368 * value = '\0'; 369 // skip until '=' 370 ++ value; 371 while(( * value ) && ( * value != '=' )) ++ value; 372 // not found? 373 if( * value != '=' ) return EINVAL; 374 } 375 376 ++ value; 377 // skip spaces 378 while( isspace( * value )) ++ value; 379 // create a bulk measured string till the end 380 setting = measured_string_create_bulk( value, 0 ); 381 if( ! setting ) return ENOMEM; 382 383 // add the configuration setting 384 if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting ))){ 385 free( setting ); 386 return ERROR_CODE; 387 } 388 return EOK; 389 } 390 391 int add_configuration( measured_strings_ref configuration, const char * name, const char * value ){ 392 ERROR_DECLARE; 393 394 measured_string_ref setting; 395 396 setting = measured_string_create_bulk( value, 0 ); 397 if( ! setting ) return ENOMEM; 398 // add the configuration setting 399 if( ERROR_OCCURRED( measured_strings_add( configuration, name, 0, setting ))){ 400 free( setting ); 401 return ERROR_CODE; 402 } 403 return EOK; 404 } 405 406 device_id_t generate_new_device_id( void ){ 407 return device_assign_devno(); 408 } 409 410 int read_configuration( void ){ 411 // read the general configuration file 412 return read_configuration_file( CONF_DIR, CONF_GENERAL_FILE, & net_globals.configuration ); 413 } 414 415 int read_netif_configuration( char * name, netif_ref netif ){ 432 fclose(cfg); 433 return EOK; 434 } 435 436 int read_netif_configuration(const char * name, netif_ref netif){ 416 437 // read the netif configuration file 417 return read_configuration_file( CONF_DIR, name, & netif->configuration);418 } 419 420 int start_device( netif_ref netif){421 ERROR_DECLARE; 422 423 measured_string_ref 424 services_t 425 int 426 int 427 int 438 return read_configuration_file(CONF_DIR, name, &netif->configuration); 439 } 440 441 int start_device(netif_ref netif){ 442 ERROR_DECLARE; 443 444 measured_string_ref setting; 445 services_t internet_service; 446 int irq; 447 int io; 448 int mtu; 428 449 429 450 // mandatory netif 430 setting = measured_strings_find( & netif->configuration, CONF_NETIF, 0);431 netif->driver = get_running_module( & net_globals.modules, setting->value);432 if( ! netif->driver){433 printf( "Failed to start the network interface driver %s\n", setting->value);451 setting = measured_strings_find(&netif->configuration, CONF_NETIF, 0); 452 netif->driver = get_running_module(&net_globals.modules, setting->value); 453 if(! netif->driver){ 454 printf("Failed to start the network interface driver %s\n", setting->value); 434 455 return EINVAL; 435 456 } 457 436 458 // optional network interface layer 437 setting = measured_strings_find( & netif->configuration, CONF_NIL, 0);438 if( setting){439 netif->nil = get_running_module( & net_globals.modules, setting->value);440 if( ! netif->nil){441 printf( "Failed to start the network interface layer %s\n", setting->value);459 setting = measured_strings_find(&netif->configuration, CONF_NIL, 0); 460 if(setting){ 461 netif->nil = get_running_module(&net_globals.modules, setting->value); 462 if(! netif->nil){ 463 printf("Failed to start the network interface layer %s\n", setting->value); 442 464 return EINVAL; 443 465 } … … 445 467 netif->nil = NULL; 446 468 } 469 447 470 // mandatory internet layer 448 setting = measured_strings_find( & netif->configuration, CONF_IL, 0);449 netif->il = get_running_module( & net_globals.modules, setting->value);450 if( ! netif->il){451 printf( "Failed to start the internet layer %s\n", setting->value);471 setting = measured_strings_find(&netif->configuration, CONF_IL, 0); 472 netif->il = get_running_module(&net_globals.modules, setting->value); 473 if(! netif->il){ 474 printf("Failed to start the internet layer %s\n", setting->value); 452 475 return EINVAL; 453 476 } 454 // end of the static loopback initialization 455 // startup the loopback interface 456 setting = measured_strings_find( & netif->configuration, CONF_IRQ, 0 ); 457 irq = setting ? strtol( setting->value, NULL, 10 ) : 0; 458 setting = measured_strings_find( & netif->configuration, CONF_IO, 0 ); 459 io = setting ? strtol( setting->value, NULL, 16 ) : 0; 460 ERROR_PROPAGATE( netif_probe_req( netif->driver->phone, netif->id, irq, io )); 461 if( netif->nil ){ 462 setting = measured_strings_find( & netif->configuration, CONF_MTU, 0 ); 463 if( ! setting ){ 464 setting = measured_strings_find( & net_globals.configuration, CONF_MTU, 0 ); 465 } 466 mtu = setting ? strtol( setting->value, NULL, 10 ) : 0; 467 ERROR_PROPAGATE( nil_device_req( netif->nil->phone, netif->id, mtu, netif->driver->service )); 477 478 // hardware configuration 479 setting = measured_strings_find(&netif->configuration, CONF_IRQ, 0); 480 irq = setting ? strtol(setting->value, NULL, 10) : 0; 481 setting = measured_strings_find(&netif->configuration, CONF_IO, 0); 482 io = setting ? strtol(setting->value, NULL, 16) : 0; 483 ERROR_PROPAGATE(netif_probe_req(netif->driver->phone, netif->id, irq, io)); 484 485 // network interface layer startup 486 if(netif->nil){ 487 setting = measured_strings_find(&netif->configuration, CONF_MTU, 0); 488 if(! setting){ 489 setting = measured_strings_find(&net_globals.configuration, CONF_MTU, 0); 490 } 491 mtu = setting ? strtol(setting->value, NULL, 10) : 0; 492 ERROR_PROPAGATE(nil_device_req(netif->nil->phone, netif->id, mtu, netif->driver->service)); 468 493 internet_service = netif->nil->service; 469 494 }else{ 470 495 internet_service = netif->driver->service; 471 496 } 472 switch( netif->il->service ){ 497 498 // inter-network layer startup 499 switch(netif->il->service){ 473 500 case SERVICE_IP: 474 ERROR_PROPAGATE( ip_device_req( netif->il->phone, netif->id, internet_service));501 ERROR_PROPAGATE(ip_device_req(netif->il->phone, netif->id, internet_service)); 475 502 break; 476 503 default: 477 504 return ENOENT; 478 505 } 479 ERROR_PROPAGATE( netif_start_req( netif->driver->phone, netif->id));480 return EOK; 481 } 482 483 int startup( void){506 ERROR_PROPAGATE(netif_start_req(netif->driver->phone, netif->id)); 507 return EOK; 508 } 509 510 int startup(void){ 484 511 ERROR_DECLARE; 485 512 486 513 #ifdef CONFIG_NETIF_DP8390 487 c har * conf_files[] = { "lo", "ne2k"};514 const char * conf_files[] = {"lo", "ne2k"}; 488 515 #else 489 c har * conf_files[] = { "lo"};516 const char * conf_files[] = {"lo"}; 490 517 #endif 491 518 492 int count = sizeof( conf_files ) / sizeof( char * ); 493 int index; 494 netif_ref netif; 495 int i; 496 measured_string_ref setting; 497 498 for( i = 0; i < count; ++ i ){ 499 netif = ( netif_ref ) malloc( sizeof( netif_t )); 500 if( ! netif ) return ENOMEM; 519 int count = sizeof(conf_files) / sizeof(char *); 520 int index; 521 netif_ref netif; 522 int i; 523 measured_string_ref setting; 524 525 for(i = 0; i < count; ++ i){ 526 netif = (netif_ref) malloc(sizeof(netif_t)); 527 if(! netif){ 528 return ENOMEM; 529 } 501 530 502 531 netif->id = generate_new_device_id(); 503 if( ! netif->id ) return EXDEV; 504 ERROR_PROPAGATE( measured_strings_initialize( & netif->configuration )); 532 if(! netif->id){ 533 return EXDEV; 534 } 535 ERROR_PROPAGATE(measured_strings_initialize(&netif->configuration)); 536 505 537 // read configuration files 506 if( ERROR_OCCURRED( read_netif_configuration( conf_files[ i ], netif))){507 measured_strings_destroy( & netif->configuration);508 free( netif);538 if(ERROR_OCCURRED(read_netif_configuration(conf_files[i], netif))){ 539 measured_strings_destroy(&netif->configuration); 540 free(netif); 509 541 return ERROR_CODE; 510 542 } 543 511 544 // mandatory name 512 setting = measured_strings_find( & netif->configuration, CONF_NAME, 0);513 if( ! setting){514 printf( "The name is missing\n");515 measured_strings_destroy( & netif->configuration);516 free( netif);545 setting = measured_strings_find(&netif->configuration, CONF_NAME, 0); 546 if(! setting){ 547 printf("The name is missing\n"); 548 measured_strings_destroy(&netif->configuration); 549 free(netif); 517 550 return EINVAL; 518 551 } 519 552 netif->name = setting->value; 553 520 554 // add to the netifs map 521 index = netifs_add( & net_globals.netifs, netif->id, netif);522 if( index < 0){523 measured_strings_destroy( & netif->configuration);524 free( netif);555 index = netifs_add(&net_globals.netifs, netif->id, netif); 556 if(index < 0){ 557 measured_strings_destroy(&netif->configuration); 558 free(netif); 525 559 return index; 526 560 } 561 527 562 // add to the netif names map 528 if( ERROR_OCCURRED( char_map_add( & net_globals.netif_names, netif->name, 0, index))563 if(ERROR_OCCURRED(char_map_add(&net_globals.netif_names, netif->name, 0, index)) 529 564 // start network interfaces and needed modules 530 || ERROR_OCCURRED( start_device( netif))){531 measured_strings_destroy( & netif->configuration);532 netifs_exclude_index( & net_globals.netifs, index);565 || ERROR_OCCURRED(start_device(netif))){ 566 measured_strings_destroy(&netif->configuration); 567 netifs_exclude_index(&net_globals.netifs, index); 533 568 return ERROR_CODE; 534 569 } 570 535 571 // increment modules' usage 536 572 ++ netif->driver->usage; 537 if( netif->nil ) ++ netif->nil->usage; 573 if(netif->nil){ 574 ++ netif->nil->usage; 575 } 538 576 ++ netif->il->usage; 539 printf( "New network interface started:\n\tname\t= %s\n\tid\t= %d\n\tdriver\t= %s\n\tnil\t= %s\n\til\t= %s\n", netif->name, netif->id, netif->driver->name, netif->nil ? netif->nil->name : NULL, netif->il->name);577 printf("New network interface started:\n\tname\t= %s\n\tid\t= %d\n\tdriver\t= %s\n\tnil\t= %s\n\til\t= %s\n", netif->name, netif->id, netif->driver->name, netif->nil ? netif->nil->name : NULL, netif->il->name); 540 578 } 541 579 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.