Changes in uspace/srv/net/net/net.c [a64c64d:aadf01e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/net/net.c
ra64c64d raadf01e 66 66 #include "net_messages.h" 67 67 68 /** Networking module name. 69 */ 70 #define NAME "Networking" 71 68 72 /** File read buffer size. 69 73 */ 70 74 #define BUFFER_SIZE 256 71 72 /** Networking module name.73 */74 #define NAME "Networking"75 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);84 75 85 76 /** Prints the module name. … … 97 88 int module_start(async_client_conn_t client_connection); 98 89 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); 90 /** \todo 91 */ 92 int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration); 115 93 116 94 /** \todo … … 123 101 */ 124 102 int read_configuration(void); 125 126 /** \todo127 */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);137 103 138 104 /** Starts the network interface according to its configuration. … … 160 126 int startup(void); 161 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(const 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 162 164 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 setting176 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 165 187 166 void module_print_name(void){ … … 208 187 } 209 188 210 int net_connect_module(services_t service){ 211 return EOK; 212 } 213 214 void net_free_settings(measured_string_ref settings, char * data){ 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); 196 197 // TODO dynamic configuration 198 ERROR_PROPAGATE(read_configuration()); 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)); 204 205 // 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))){ 213 return EINVAL; 214 } 215 netif = netifs_find(&net_globals.netifs, device_id); 216 if(netif){ 217 return net_get_conf(&netif->configuration, * configuration, count, data); 218 }else{ 219 return net_get_conf(NULL, * configuration, count, data); 220 } 221 } 222 223 int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data){ 224 if(!(configuration && (count > 0))){ 225 return EINVAL; 226 } 227 return net_get_conf(NULL, * configuration, count, data); 215 228 } 216 229 … … 222 235 *data = NULL; 223 236 } 224 225 237 for(index = 0; index < count; ++ index){ 226 238 setting = measured_strings_find(netif_conf, configuration[index].value, 0); … … 239 251 } 240 252 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); 271 272 // TODO dynamic configuration 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)); 279 280 // build specific initialization 281 return net_initialize_build(client_connection); 253 void net_free_settings(measured_string_ref settings, char * data){ 254 } 255 256 int net_connect_module(services_t service){ 257 return EOK; 282 258 } 283 259 … … 312 288 } 313 289 return ENOTSUP; 314 }315 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 beginning324 name = line;325 326 // skip comments and blank lines327 if((*name == '#') || (*name == '\0')){328 return EOK;329 }330 // skip spaces331 while(isspace(*name)){332 ++ name;333 }334 335 // remember the name start336 value = name;337 // skip the name338 while(isalnum(*value) || (*value == '_')){339 // make uppercase340 // *value = toupper(*value);341 ++ value;342 }343 344 if(*value == '='){345 // terminate the name346 *value = '\0';347 }else{348 // terminate the name349 *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 spaces363 while(isspace(*value)){364 ++ value;365 }366 // create a bulk measured string till the end367 setting = measured_string_create_bulk(value, 0);368 if(! setting){369 return ENOMEM;370 }371 372 // add the configuration setting373 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 file382 return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, &net_globals.configuration);383 290 } 384 291 … … 434 341 } 435 342 343 int parse_line(measured_strings_ref configuration, char * line){ 344 ERROR_DECLARE; 345 346 measured_string_ref setting; 347 char * name; 348 char * value; 349 350 // from the beginning 351 name = line; 352 353 // skip comments and blank lines 354 if((*name == '#') || (*name == '\0')){ 355 return EOK; 356 } 357 // skip spaces 358 while(isspace(*name)){ 359 ++ name; 360 } 361 362 // remember the name start 363 value = name; 364 // skip the name 365 while(isalnum(*value) || (*value == '_')){ 366 // make uppercase 367 // *value = toupper(*value); 368 ++ value; 369 } 370 371 if(*value == '='){ 372 // terminate the name 373 *value = '\0'; 374 }else{ 375 // terminate the name 376 *value = '\0'; 377 // skip until '=' 378 ++ value; 379 while((*value) && (*value != '=')){ 380 ++ value; 381 } 382 // not found? 383 if(*value != '='){ 384 return EINVAL; 385 } 386 } 387 388 ++ value; 389 // skip spaces 390 while(isspace(*value)){ 391 ++ value; 392 } 393 // create a bulk measured string till the end 394 setting = measured_string_create_bulk(value, 0); 395 if(! setting){ 396 return ENOMEM; 397 } 398 399 // add the configuration setting 400 if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){ 401 free(setting); 402 return ERROR_CODE; 403 } 404 return EOK; 405 } 406 407 int add_configuration(measured_strings_ref configuration, const char * name, const char * value){ 408 ERROR_DECLARE; 409 410 measured_string_ref setting; 411 412 setting = measured_string_create_bulk(value, 0); 413 if(! setting){ 414 return ENOMEM; 415 } 416 // add the configuration setting 417 if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){ 418 free(setting); 419 return ERROR_CODE; 420 } 421 return EOK; 422 } 423 424 device_id_t generate_new_device_id(void){ 425 return device_assign_devno(); 426 } 427 428 int read_configuration(void){ 429 // read the general configuration file 430 return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, &net_globals.configuration); 431 } 432 436 433 int read_netif_configuration(const char * name, netif_ref netif){ 437 434 // read the netif configuration file … … 455 452 return EINVAL; 456 453 } 457 458 454 // optional network interface layer 459 455 setting = measured_strings_find(&netif->configuration, CONF_NIL, 0); … … 467 463 netif->nil = NULL; 468 464 } 469 470 465 // mandatory internet layer 471 466 setting = measured_strings_find(&netif->configuration, CONF_IL, 0); … … 475 470 return EINVAL; 476 471 } 477 478 // hardware configuration472 // end of the static loopback initialization 473 // startup the loopback interface 479 474 setting = measured_strings_find(&netif->configuration, CONF_IRQ, 0); 480 475 irq = setting ? strtol(setting->value, NULL, 10) : 0; … … 482 477 io = setting ? strtol(setting->value, NULL, 16) : 0; 483 478 ERROR_PROPAGATE(netif_probe_req(netif->driver->phone, netif->id, irq, io)); 484 485 // network interface layer startup486 479 if(netif->nil){ 487 480 setting = measured_strings_find(&netif->configuration, CONF_MTU, 0); … … 495 488 internet_service = netif->driver->service; 496 489 } 497 498 // inter-network layer startup499 490 switch(netif->il->service){ 500 491 case SERVICE_IP: … … 534 525 } 535 526 ERROR_PROPAGATE(measured_strings_initialize(&netif->configuration)); 536 537 527 // read configuration files 538 528 if(ERROR_OCCURRED(read_netif_configuration(conf_files[i], netif))){ … … 541 531 return ERROR_CODE; 542 532 } 543 544 533 // mandatory name 545 534 setting = measured_strings_find(&netif->configuration, CONF_NAME, 0); … … 551 540 } 552 541 netif->name = setting->value; 553 554 542 // add to the netifs map 555 543 index = netifs_add(&net_globals.netifs, netif->id, netif); … … 559 547 return index; 560 548 } 561 562 549 // add to the netif names map 563 550 if(ERROR_OCCURRED(char_map_add(&net_globals.netif_names, netif->name, 0, index)) … … 568 555 return ERROR_CODE; 569 556 } 570 571 557 // increment modules' usage 572 558 ++ netif->driver->usage;
Note:
See TracChangeset
for help on using the changeset viewer.