Changeset 80cd7cd in mainline for uspace/srv/net/net/net.c
- Timestamp:
- 2011-01-13T20:58:24Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 87e373b
- Parents:
- eaef141 (diff), a613fea1 (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
reaef141 r80cd7cd 45 45 #include <stdio.h> 46 46 #include <str.h> 47 #include <str_error.h> 47 48 48 49 #include <ipc/ipc.h> … … 51 52 #include <ipc/net_net.h> 52 53 #include <ipc/il.h> 54 #include <ipc/nil.h> 53 55 54 56 #include <net/modules.h> … … 62 64 63 65 #include <netif_remote.h> 64 #include <nil_ interface.h>66 #include <nil_remote.h> 65 67 #include <net_interface.h> 66 68 #include <ip_interface.h> … … 90 92 * 91 93 */ 92 int add_configuration(measured_strings_t *configuration, const char*name,93 const char*value)94 int add_configuration(measured_strings_t *configuration, const uint8_t *name, 95 const uint8_t *value) 94 96 { 95 97 int rc; … … 119 121 } 120 122 121 static int parse_line(measured_strings_t *configuration, char*line)123 static int parse_line(measured_strings_t *configuration, uint8_t *line) 122 124 { 123 125 int rc; 124 126 125 127 /* From the beginning */ 126 char*name = line;128 uint8_t *name = line; 127 129 128 130 /* Skip comments and blank lines */ … … 135 137 136 138 /* Remember the name start */ 137 char*value = name;139 uint8_t *value = name; 138 140 139 141 /* Skip the name */ … … 186 188 187 189 /* Construct the full filename */ 188 char line[BUFFER_SIZE];189 if (snprintf( line, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE)190 char fname[BUFFER_SIZE]; 191 if (snprintf(fname, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE) 190 192 return EOVERFLOW; 191 193 192 194 /* Open the file */ 193 FILE *cfg = fopen( line, "r");195 FILE *cfg = fopen(fname, "r"); 194 196 if (!cfg) 195 197 return ENOENT; … … 201 203 unsigned int line_number = 0; 202 204 size_t index = 0; 205 uint8_t line[BUFFER_SIZE]; 206 203 207 while (!ferror(cfg) && !feof(cfg)) { 204 208 int read = fgetc(cfg); … … 207 211 line[BUFFER_SIZE - 1] = '\0'; 208 212 fprintf(stderr, "%s: Configuration line %u too " 209 "long: %s\n", NAME, line_number, line);213 "long: %s\n", NAME, line_number, (char *) line); 210 214 211 215 /* No space left in the line buffer */ … … 213 217 } 214 218 /* Append the character */ 215 line[index] = ( char) read;219 line[index] = (uint8_t) read; 216 220 index++; 217 221 } else { … … 221 225 if (parse_line(configuration, line) != EOK) { 222 226 fprintf(stderr, "%s: Configuration error on " 223 "line %u: %s\n", NAME, line_number, line);227 "line %u: %s\n", NAME, line_number, (char *) line); 224 228 } 225 229 … … 282 286 return rc; 283 287 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);288 rc = add_module(NULL, &net_globals.modules, (uint8_t *) LO_NAME, 289 (uint8_t *) LO_FILENAME, SERVICE_LO, 0, connect_to_service); 290 if (rc != EOK) 291 return rc; 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 rc = add_module(NULL, &net_globals.modules, (uint8_t *) ETHERNET_NAME, 297 (uint8_t *) ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service); 298 if (rc != EOK) 299 return rc; 300 rc = add_module(NULL, &net_globals.modules, (uint8_t *) NILDUMMY_NAME, 301 (uint8_t *) NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service); 298 302 if (rc != EOK) 299 303 return rc; … … 330 334 return rc; 331 335 332 333 336 rc = net_initialize(client_connection); 334 337 if (rc != EOK) … … 364 367 */ 365 368 static int net_get_conf(measured_strings_t *netif_conf, 366 measured_string_t *configuration, size_t count, char**data)369 measured_string_t *configuration, size_t count, uint8_t **data) 367 370 { 368 371 if (data) … … 390 393 391 394 int net_get_conf_req(int net_phone, measured_string_t **configuration, 392 size_t count, char**data)395 size_t count, uint8_t **data) 393 396 { 394 397 if (!configuration || (count <= 0)) … … 399 402 400 403 int net_get_device_conf_req(int net_phone, device_id_t device_id, 401 measured_string_t **configuration, size_t count, char**data)404 measured_string_t **configuration, size_t count, uint8_t **data) 402 405 { 403 406 if ((!configuration) || (count == 0)) … … 411 414 } 412 415 413 void net_free_settings(measured_string_t *settings, char*data)416 void net_free_settings(measured_string_t *settings, uint8_t *data) 414 417 { 415 418 } … … 437 440 /* Mandatory netif */ 438 441 measured_string_t *setting = 439 measured_strings_find(&netif->configuration, CONF_NETIF, 0);442 measured_strings_find(&netif->configuration, (uint8_t *) CONF_NETIF, 0); 440 443 441 444 netif->driver = get_running_module(&net_globals.modules, setting->value); … … 447 450 448 451 /* Optional network interface layer */ 449 setting = measured_strings_find(&netif->configuration, CONF_NIL, 0);452 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_NIL, 0); 450 453 if (setting) { 451 454 netif->nil = get_running_module(&net_globals.modules, setting->value); … … 459 462 460 463 /* Mandatory internet layer */ 461 setting = measured_strings_find(&netif->configuration, CONF_IL, 0);464 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IL, 0); 462 465 netif->il = get_running_module(&net_globals.modules, setting->value); 463 466 if (!netif->il) { … … 468 471 469 472 /* 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);473 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IRQ, 0); 474 int irq = setting ? strtol((char *) setting->value, NULL, 10) : 0; 475 476 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IO, 0); 477 uintptr_t io = setting ? strtol((char *) setting->value, NULL, 16) : 0; 478 479 rc = netif_probe_req(netif->driver->phone, netif->id, irq, (void *) io); 477 480 if (rc != EOK) 478 481 return rc; … … 481 484 services_t internet_service; 482 485 if (netif->nil) { 483 setting = measured_strings_find(&netif->configuration, CONF_MTU, 0);486 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_MTU, 0); 484 487 if (!setting) 485 488 setting = measured_strings_find(&net_globals.configuration, 486 CONF_MTU, 0);487 488 int mtu = setting ? strtol( setting->value, NULL, 10) : 0;489 (uint8_t *) CONF_MTU, 0); 490 491 int mtu = setting ? strtol((char *) setting->value, NULL, 10) : 0; 489 492 490 493 rc = nil_device_req(netif->nil->phone, netif->id, mtu, … … 509 512 } 510 513 511 return netif_start_req _remote(netif->driver->phone, netif->id);514 return netif_start_req(netif->driver->phone, netif->id); 512 515 } 513 516 … … 558 561 /* Mandatory name */ 559 562 measured_string_t *setting = 560 measured_strings_find(&netif->configuration, CONF_NAME, 0);563 measured_strings_find(&netif->configuration, (uint8_t *) CONF_NAME, 0); 561 564 if (!setting) { 562 565 fprintf(stderr, "%s: Network interface name is missing\n", NAME); … … 589 592 rc = start_device(netif); 590 593 if (rc != EOK) { 594 printf("%s: Error starting interface %s (%s)\n", NAME, 595 netif->name, str_error(rc)); 591 596 measured_strings_destroy(&netif->configuration); 592 597 netifs_exclude_index(&net_globals.netifs, index); 598 593 599 return rc; 594 600 } … … 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; … … 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.