Changeset a64c64d in mainline for uspace/srv/net/net/net.c
- Timestamp:
- 2010-03-09T22:24:31Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 74520daf
- Parents:
- 9f2ea28
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/net/net.c
r9f2ea28 ra64c64d 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. … … 88 97 int module_start(async_client_conn_t client_connection); 89 98 90 /** \todo 91 */ 92 int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration); 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); 93 115 94 116 /** \todo … … 101 123 */ 102 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. … … 126 160 int startup(void); 127 161 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; 162 GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t) 161 163 162 164 DEVICE_MAP_IMPLEMENT(netifs, netif_t) 163 165 164 GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t) 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 } 165 186 166 187 void module_print_name(void){ … … 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); 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); 210 int net_connect_module(services_t service){ 211 return EOK; 212 } 213 214 void net_free_settings(measured_string_ref settings, char * data){ 228 215 } 229 216 … … 235 222 *data = NULL; 236 223 } 224 237 225 for(index = 0; index < count; ++ index){ 238 226 setting = measured_strings_find(netif_conf, configuration[index].value, 0); … … 251 239 } 252 240 253 void net_free_settings(measured_string_ref settings, char * data){ 254 } 255 256 int net_connect_module(services_t service){ 257 return EOK; 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); 258 282 } 259 283 … … 288 312 } 289 313 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 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); 290 383 } 291 384 … … 341 434 } 342 435 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 beginning351 name = line;352 353 // skip comments and blank lines354 if((*name == '#') || (*name == '\0')){355 return EOK;356 }357 // skip spaces358 while(isspace(*name)){359 ++ name;360 }361 362 // remember the name start363 value = name;364 // skip the name365 while(isalnum(*value) || (*value == '_')){366 // make uppercase367 // *value = toupper(*value);368 ++ value;369 }370 371 if(*value == '='){372 // terminate the name373 *value = '\0';374 }else{375 // terminate the name376 *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 spaces390 while(isspace(*value)){391 ++ value;392 }393 // create a bulk measured string till the end394 setting = measured_string_create_bulk(value, 0);395 if(! setting){396 return ENOMEM;397 }398 399 // add the configuration setting400 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 setting417 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 file430 return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, &net_globals.configuration);431 }432 433 436 int read_netif_configuration(const char * name, netif_ref netif){ 434 437 // read the netif configuration file … … 452 455 return EINVAL; 453 456 } 457 454 458 // optional network interface layer 455 459 setting = measured_strings_find(&netif->configuration, CONF_NIL, 0); … … 463 467 netif->nil = NULL; 464 468 } 469 465 470 // mandatory internet layer 466 471 setting = measured_strings_find(&netif->configuration, CONF_IL, 0); … … 470 475 return EINVAL; 471 476 } 472 // end of the static loopback initialization 473 // startup the loopback interface477 478 // hardware configuration 474 479 setting = measured_strings_find(&netif->configuration, CONF_IRQ, 0); 475 480 irq = setting ? strtol(setting->value, NULL, 10) : 0; … … 477 482 io = setting ? strtol(setting->value, NULL, 16) : 0; 478 483 ERROR_PROPAGATE(netif_probe_req(netif->driver->phone, netif->id, irq, io)); 484 485 // network interface layer startup 479 486 if(netif->nil){ 480 487 setting = measured_strings_find(&netif->configuration, CONF_MTU, 0); … … 488 495 internet_service = netif->driver->service; 489 496 } 497 498 // inter-network layer startup 490 499 switch(netif->il->service){ 491 500 case SERVICE_IP: … … 525 534 } 526 535 ERROR_PROPAGATE(measured_strings_initialize(&netif->configuration)); 536 527 537 // read configuration files 528 538 if(ERROR_OCCURRED(read_netif_configuration(conf_files[i], netif))){ … … 531 541 return ERROR_CODE; 532 542 } 543 533 544 // mandatory name 534 545 setting = measured_strings_find(&netif->configuration, CONF_NAME, 0); … … 540 551 } 541 552 netif->name = setting->value; 553 542 554 // add to the netifs map 543 555 index = netifs_add(&net_globals.netifs, netif->id, netif); … … 547 559 return index; 548 560 } 561 549 562 // add to the netif names map 550 563 if(ERROR_OCCURRED(char_map_add(&net_globals.netif_names, netif->name, 0, index)) … … 555 568 return ERROR_CODE; 556 569 } 570 557 571 // increment modules' usage 558 572 ++ netif->driver->usage;
Note:
See TracChangeset
for help on using the changeset viewer.