Changeset ad7a6c9 in mainline for uspace/srv/net/net/net.c
- Timestamp:
- 2011-03-30T13:10:24Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4ae90f9
- Parents:
- 6e50466 (diff), d6b81941 (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
-
uspace/srv/net/net/net.c (modified) (34 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/net/net.c
r6e50466 rad7a6c9 45 45 #include <stdio.h> 46 46 #include <str.h> 47 48 #include <ipc/ipc.h> 47 #include <str_error.h> 48 49 49 #include <ipc/services.h> 50 50 #include <ipc/net.h> 51 51 #include <ipc/net_net.h> 52 52 #include <ipc/il.h> 53 #include <ipc/nil.h> 53 54 54 55 #include <net/modules.h> … … 62 63 63 64 #include <netif_remote.h> 64 #include <nil_ interface.h>65 #include <nil_remote.h> 65 66 #include <net_interface.h> 66 67 #include <ip_interface.h> … … 90 91 * 91 92 */ 92 int add_configuration(measured_strings_t *configuration, const char*name,93 const char*value)93 int add_configuration(measured_strings_t *configuration, const uint8_t *name, 94 const uint8_t *value) 94 95 { 95 96 int rc; … … 119 120 } 120 121 121 static int parse_line(measured_strings_t *configuration, char*line)122 static int parse_line(measured_strings_t *configuration, uint8_t *line) 122 123 { 123 124 int rc; 124 125 125 126 /* From the beginning */ 126 char*name = line;127 uint8_t *name = line; 127 128 128 129 /* Skip comments and blank lines */ … … 135 136 136 137 /* Remember the name start */ 137 char*value = name;138 uint8_t *value = name; 138 139 139 140 /* Skip the name */ … … 186 187 187 188 /* Construct the full filename */ 188 char line[BUFFER_SIZE];189 if (snprintf( line, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE)189 char fname[BUFFER_SIZE]; 190 if (snprintf(fname, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE) 190 191 return EOVERFLOW; 191 192 192 193 /* Open the file */ 193 FILE *cfg = fopen( line, "r");194 FILE *cfg = fopen(fname, "r"); 194 195 if (!cfg) 195 196 return ENOENT; … … 201 202 unsigned int line_number = 0; 202 203 size_t index = 0; 204 uint8_t line[BUFFER_SIZE]; 205 203 206 while (!ferror(cfg) && !feof(cfg)) { 204 207 int read = fgetc(cfg); … … 207 210 line[BUFFER_SIZE - 1] = '\0'; 208 211 fprintf(stderr, "%s: Configuration line %u too " 209 "long: %s\n", NAME, line_number, line);212 "long: %s\n", NAME, line_number, (char *) line); 210 213 211 214 /* No space left in the line buffer */ … … 213 216 } 214 217 /* Append the character */ 215 line[index] = ( char) read;218 line[index] = (uint8_t) read; 216 219 index++; 217 220 } else { … … 221 224 if (parse_line(configuration, line) != EOK) { 222 225 fprintf(stderr, "%s: Configuration error on " 223 "line %u: %s\n", NAME, line_number, line);226 "line %u: %s\n", NAME, line_number, (char *) line); 224 227 } 225 228 … … 282 285 return rc; 283 286 284 rc = add_module(NULL, &net_globals.modules, LO_NAME, LO_FILENAME, 285 SERVICE_LO, 0, connect_to_service); 286 if (rc != EOK) 287 return rc; 288 rc = add_module(NULL, &net_globals.modules, DP8390_NAME, 289 DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service); 290 if (rc != EOK) 291 return rc; 292 rc = add_module(NULL, &net_globals.modules, ETHERNET_NAME, 293 ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service); 294 if (rc != EOK) 295 return rc; 296 rc = add_module(NULL, &net_globals.modules, NILDUMMY_NAME, 297 NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service); 287 rc = add_module(NULL, &net_globals.modules, (uint8_t *) LO_NAME, 288 (uint8_t *) LO_FILENAME, SERVICE_LO, 0, connect_to_service); 289 if (rc != EOK) 290 return rc; 291 292 rc = add_module(NULL, &net_globals.modules, (uint8_t *) NE2000_NAME, 293 (uint8_t *) NE2000_FILENAME, SERVICE_NE2000, 0, connect_to_service); 294 if (rc != EOK) 295 return rc; 296 297 rc = add_module(NULL, &net_globals.modules, (uint8_t *) ETHERNET_NAME, 298 (uint8_t *) ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service); 299 if (rc != EOK) 300 return rc; 301 302 rc = add_module(NULL, &net_globals.modules, (uint8_t *) NILDUMMY_NAME, 303 (uint8_t *) NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service); 298 304 if (rc != EOK) 299 305 return rc; … … 322 328 static int net_module_start(async_client_conn_t client_connection) 323 329 { 324 sysarg_t phonehash;325 330 int rc; 326 331 … … 330 335 return rc; 331 336 332 333 337 rc = net_initialize(client_connection); 334 338 if (rc != EOK) 335 339 goto out; 336 340 337 rc = ipc_connect_to_me(PHONE_NS, SERVICE_NETWORKING, 0, 0, &phonehash);341 rc = async_connect_to_me(PHONE_NS, SERVICE_NETWORKING, 0, 0, NULL); 338 342 if (rc != EOK) 339 343 goto out; … … 364 368 */ 365 369 static int net_get_conf(measured_strings_t *netif_conf, 366 measured_string_t *configuration, size_t count, char**data)370 measured_string_t *configuration, size_t count, uint8_t **data) 367 371 { 368 372 if (data) … … 390 394 391 395 int net_get_conf_req(int net_phone, measured_string_t **configuration, 392 size_t count, char**data)396 size_t count, uint8_t **data) 393 397 { 394 398 if (!configuration || (count <= 0)) … … 399 403 400 404 int net_get_device_conf_req(int net_phone, device_id_t device_id, 401 measured_string_t **configuration, size_t count, char**data)405 measured_string_t **configuration, size_t count, uint8_t **data) 402 406 { 403 407 if ((!configuration) || (count == 0)) … … 411 415 } 412 416 413 void net_free_settings(measured_string_t *settings, char*data)417 void net_free_settings(measured_string_t *settings, uint8_t *data) 414 418 { 415 419 } … … 437 441 /* Mandatory netif */ 438 442 measured_string_t *setting = 439 measured_strings_find(&netif->configuration, CONF_NETIF, 0);443 measured_strings_find(&netif->configuration, (uint8_t *) CONF_NETIF, 0); 440 444 441 445 netif->driver = get_running_module(&net_globals.modules, setting->value); … … 447 451 448 452 /* Optional network interface layer */ 449 setting = measured_strings_find(&netif->configuration, CONF_NIL, 0);453 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_NIL, 0); 450 454 if (setting) { 451 455 netif->nil = get_running_module(&net_globals.modules, setting->value); … … 459 463 460 464 /* Mandatory internet layer */ 461 setting = measured_strings_find(&netif->configuration, CONF_IL, 0);465 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IL, 0); 462 466 netif->il = get_running_module(&net_globals.modules, setting->value); 463 467 if (!netif->il) { … … 468 472 469 473 /* Hardware configuration */ 470 setting = measured_strings_find(&netif->configuration, CONF_IRQ, 0);471 int irq = setting ? strtol( setting->value, NULL, 10) : 0;472 473 setting = measured_strings_find(&netif->configuration, CONF_IO, 0);474 int io = setting ? strtol(setting->value, NULL, 16) : 0;475 476 rc = netif_probe_req _remote(netif->driver->phone, netif->id, irq,io);474 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IRQ, 0); 475 int irq = setting ? strtol((char *) setting->value, NULL, 10) : 0; 476 477 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IO, 0); 478 uintptr_t io = setting ? strtol((char *) setting->value, NULL, 16) : 0; 479 480 rc = netif_probe_req(netif->driver->phone, netif->id, irq, (void *) io); 477 481 if (rc != EOK) 478 482 return rc; … … 481 485 services_t internet_service; 482 486 if (netif->nil) { 483 setting = measured_strings_find(&netif->configuration, CONF_MTU, 0);487 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_MTU, 0); 484 488 if (!setting) 485 489 setting = measured_strings_find(&net_globals.configuration, 486 CONF_MTU, 0);487 488 int mtu = setting ? strtol( setting->value, NULL, 10) : 0;490 (uint8_t *) CONF_MTU, 0); 491 492 int mtu = setting ? strtol((char *) setting->value, NULL, 10) : 0; 489 493 490 494 rc = nil_device_req(netif->nil->phone, netif->id, mtu, … … 509 513 } 510 514 511 return netif_start_req _remote(netif->driver->phone, netif->id);515 return netif_start_req(netif->driver->phone, netif->id); 512 516 } 513 517 … … 551 555 rc = read_netif_configuration(conf_files[i], netif); 552 556 if (rc != EOK) { 553 measured_strings_destroy(&netif->configuration );557 measured_strings_destroy(&netif->configuration, free); 554 558 free(netif); 555 559 return rc; … … 558 562 /* Mandatory name */ 559 563 measured_string_t *setting = 560 measured_strings_find(&netif->configuration, CONF_NAME, 0);564 measured_strings_find(&netif->configuration, (uint8_t *) CONF_NAME, 0); 561 565 if (!setting) { 562 566 fprintf(stderr, "%s: Network interface name is missing\n", NAME); 563 measured_strings_destroy(&netif->configuration );567 measured_strings_destroy(&netif->configuration, free); 564 568 free(netif); 565 569 return EINVAL; … … 570 574 int index = netifs_add(&net_globals.netifs, netif->id, netif); 571 575 if (index < 0) { 572 measured_strings_destroy(&netif->configuration );576 measured_strings_destroy(&netif->configuration, free); 573 577 free(netif); 574 578 return index; … … 582 586 index); 583 587 if (rc != EOK) { 584 measured_strings_destroy(&netif->configuration );585 netifs_exclude_index(&net_globals.netifs, index );588 measured_strings_destroy(&netif->configuration, free); 589 netifs_exclude_index(&net_globals.netifs, index, free); 586 590 return rc; 587 591 } … … 589 593 rc = start_device(netif); 590 594 if (rc != EOK) { 591 measured_strings_destroy(&netif->configuration); 592 netifs_exclude_index(&net_globals.netifs, index); 593 return rc; 595 printf("%s: Ignoring failed interface %s (%s)\n", NAME, 596 netif->name, str_error(rc)); 597 measured_strings_destroy(&netif->configuration, free); 598 netifs_exclude_index(&net_globals.netifs, index, free); 599 continue; 594 600 } 595 601 … … 602 608 printf("%s: Network interface started (name: %s, id: %d, driver: %s, " 603 609 "nil: %s, il: %s)\n", NAME, netif->name, netif->id, 604 netif->driver->name, netif->nil ?netif->nil->name : "[none]",610 netif->driver->name, netif->nil ? (char *) netif->nil->name : "[none]", 605 611 netif->il->name); 606 612 } … … 611 617 /** Process the networking message. 612 618 * 613 * @param[in] callidThe message identifier.614 * @param[in] callThe message parameters.619 * @param[in] callid The message identifier. 620 * @param[in] call The message parameters. 615 621 * @param[out] answer The message answer parameters. 616 622 * @param[out] answer_count The last parameter for the actual answer … … 625 631 */ 626 632 int net_message(ipc_callid_t callid, ipc_call_t *call, ipc_call_t *answer, 627 int *answer_count)633 size_t *answer_count) 628 634 { 629 635 measured_string_t *strings; 630 char*data;636 uint8_t *data; 631 637 int rc; 632 638 … … 637 643 case NET_NET_GET_DEVICE_CONF: 638 644 rc = measured_strings_receive(&strings, &data, 639 IPC_GET_COUNT( call));645 IPC_GET_COUNT(*call)); 640 646 if (rc != EOK) 641 647 return rc; 642 net_get_device_conf_req(0, IPC_GET_DEVICE( call), &strings,643 IPC_GET_COUNT( call), NULL);648 net_get_device_conf_req(0, IPC_GET_DEVICE(*call), &strings, 649 IPC_GET_COUNT(*call), NULL); 644 650 645 651 /* Strings should not contain received data anymore */ 646 652 free(data); 647 653 648 rc = measured_strings_reply(strings, IPC_GET_COUNT( call));654 rc = measured_strings_reply(strings, IPC_GET_COUNT(*call)); 649 655 free(strings); 650 656 return rc; 651 657 case NET_NET_GET_CONF: 652 658 rc = measured_strings_receive(&strings, &data, 653 IPC_GET_COUNT( call));659 IPC_GET_COUNT(*call)); 654 660 if (rc != EOK) 655 661 return rc; 656 net_get_conf_req(0, &strings, IPC_GET_COUNT( call), NULL);662 net_get_conf_req(0, &strings, IPC_GET_COUNT(*call), NULL); 657 663 658 664 /* Strings should not contain received data anymore */ 659 665 free(data); 660 666 661 rc = measured_strings_reply(strings, IPC_GET_COUNT( call));667 rc = measured_strings_reply(strings, IPC_GET_COUNT(*call)); 662 668 free(strings); 663 669 return rc; … … 681 687 * - Answer the first IPC_M_CONNECT_ME_TO call. 682 688 */ 683 ipc_answer_0(iid, EOK);689 async_answer_0(iid, EOK); 684 690 685 691 while (true) { 686 692 /* Clear the answer structure */ 687 693 ipc_call_t answer; 688 int answer_count;694 size_t answer_count; 689 695 refresh_answer(&answer, &answer_count); 690 696 … … 707 713 int main(int argc, char *argv[]) 708 714 { 709 int rc; 710 711 rc = net_module_start(net_client_connection); 712 if (rc != EOK) { 713 fprintf(stderr, "%s: net_module_start error %i\n", NAME, rc); 714 return rc; 715 } 716 717 return EOK; 715 return net_module_start(net_client_connection); 718 716 } 719 717
Note:
See TracChangeset
for help on using the changeset viewer.
