Changeset 3f0a7971 in mainline for uspace/srv/net/nil/eth/eth.c
- Timestamp:
- 2010-11-18T22:34:23Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 63b4f90
- Parents:
- c7137738 (diff), 45f04f8 (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/nil/eth/eth.c
rc7137738 r3f0a7971 204 204 fibril_rwlock_write_lock(ð_globals.protos_lock); 205 205 eth_globals.net_phone = net_phone; 206 206 207 eth_globals.broadcast_addr = 207 208 measured_string_create_bulk("\xFF\xFF\xFF\xFF\xFF\xFF", … … 211 212 goto out; 212 213 } 214 213 215 rc = eth_devices_initialize(ð_globals.devices); 214 216 if (rc != EOK) { … … 216 218 goto out; 217 219 } 220 218 221 rc = eth_protos_initialize(ð_globals.protos); 219 222 if (rc != EOK) { … … 280 283 * netif_get_addr_req() function. 281 284 */ 282 static int 283 eth_device_message(device_id_t device_id, services_t service,size_t mtu)285 static int eth_device_message(device_id_t device_id, services_t service, 286 size_t mtu) 284 287 { 285 288 eth_device_ref device; … … 302 305 303 306 fibril_rwlock_write_lock(ð_globals.devices_lock); 304 / / an existing device?307 /* An existing device? */ 305 308 device = eth_devices_find(ð_globals.devices, device_id); 306 309 if (device) { … … 311 314 } 312 315 313 / / update mtu316 /* Update mtu */ 314 317 if ((mtu > 0) && (mtu <= ETH_MAX_TAGGED_CONTENT(device->flags))) 315 318 device->mtu = mtu; … … 321 324 fibril_rwlock_write_unlock(ð_globals.devices_lock); 322 325 323 / / notify all upper layer modules326 /* Notify all upper layer modules */ 324 327 fibril_rwlock_read_lock(ð_globals.protos_lock); 325 328 for (index = 0; index < eth_protos_count(ð_globals.protos); … … 333 336 } 334 337 } 338 335 339 fibril_rwlock_read_unlock(ð_globals.protos_lock); 336 340 return EOK; 337 341 } 338 342 339 / / create a new device343 /* Create a new device */ 340 344 device = (eth_device_ref) malloc(sizeof(eth_device_t)); 341 345 if (!device) … … 358 362 return rc; 359 363 } 364 360 365 if (configuration) { 361 366 if (!str_lcmp(configuration[0].value, "DIX", … … 378 383 } 379 384 380 / / bind the device driver385 /* Bind the device driver */ 381 386 device->phone = netif_bind_service(device->service, device->device_id, 382 387 SERVICE_ETHERNET, eth_receiver); … … 387 392 } 388 393 389 / / get hardware address394 /* Get hardware address */ 390 395 rc = netif_get_addr_req(device->phone, device->device_id, &device->addr, 391 396 &device->addr_data); … … 396 401 } 397 402 398 / / add to the cache403 /* Add to the cache */ 399 404 index = eth_devices_add(ð_globals.devices, device->device_id, 400 405 device); … … 453 458 454 459 if (type >= ETH_MIN_PROTO) { 455 / / DIX Ethernet460 /* DIX Ethernet */ 456 461 prefix = sizeof(eth_header_t); 457 462 suffix = 0; … … 459 464 length -= sizeof(eth_fcs_t); 460 465 } else if(type <= ETH_MAX_CONTENT) { 461 / / translate "LSAP" values466 /* Translate "LSAP" values */ 462 467 if ((header->lsap.dsap == ETH_LSAP_GLSAP) && 463 468 (header->lsap.ssap == ETH_LSAP_GLSAP)) { 464 // raw packet 465 // discard 469 /* Raw packet -- discard */ 466 470 return NULL; 467 471 } else if((header->lsap.dsap == ETH_LSAP_SNAP) && 468 472 (header->lsap.ssap == ETH_LSAP_SNAP)) { 469 // IEEE 802.3 + 802.2 + LSAP + SNAP 470 // organization code not supported 473 /* 474 * IEEE 802.3 + 802.2 + LSAP + SNAP 475 * organization code not supported 476 */ 471 477 type = ntohs(header->snap.ethertype); 472 478 prefix = sizeof(eth_header_t) + … … 474 480 sizeof(eth_header_snap_t); 475 481 } else { 476 / / IEEE 802.3 + 802.2 LSAP482 /* IEEE 802.3 + 802.2 LSAP */ 477 483 type = lsap_map(header->lsap.dsap); 478 484 prefix = sizeof(eth_header_t) + 479 485 sizeof(eth_header_lsap_t); 480 486 } 487 481 488 suffix = (type < ETH_MIN_CONTENT) ? ETH_MIN_CONTENT - type : 0U; 482 489 fcs = (eth_fcs_ref) data + prefix + type + suffix; … … 484 491 length = prefix + type + suffix; 485 492 } else { 486 / / invalid length/type, should not occurr493 /* Invalid length/type, should not occur */ 487 494 return NULL; 488 495 } … … 506 513 } 507 514 508 int 509 nil_received_msg_local(int nil_phone, device_id_t device_id, packet_t packet, 510 services_t target) 515 int nil_received_msg_local(int nil_phone, device_id_t device_id, 516 packet_t packet, services_t target) 511 517 { 512 518 eth_proto_ref proto; … … 521 527 return ENOENT; 522 528 } 529 523 530 flags = device->flags; 524 531 fibril_rwlock_read_unlock(ð_globals.devices_lock); … … 538 545 packet = next; 539 546 } while(packet); 547 540 548 fibril_rwlock_read_unlock(ð_globals.protos_lock); 541 542 549 return EOK; 543 550 } … … 554 561 * @returns ENOENT if there is no such device. 555 562 */ 556 static int 557 eth_packet_space_message(device_id_t device_id, size_t *addr_len, 563 static int eth_packet_space_message(device_id_t device_id, size_t *addr_len, 558 564 size_t *prefix, size_t *content, size_t *suffix) 559 565 { … … 569 575 return ENOENT; 570 576 } 577 571 578 *content = device->mtu; 572 579 fibril_rwlock_read_unlock(ð_globals.devices_lock); … … 575 582 *prefix = ETH_PREFIX; 576 583 *suffix = ETH_MIN_CONTENT + ETH_SUFFIX; 584 577 585 return EOK; 578 586 } … … 587 595 * @returns ENOENT if there no such device. 588 596 */ 589 static int 590 eth_addr_message(device_id_t device_id, eth_addr_type_t type, 597 static int eth_addr_message(device_id_t device_id, eth_addr_type_t type, 591 598 measured_string_ref *address) 592 599 { … … 644 651 return ENOMEM; 645 652 } 653 646 654 proto->service = service; 647 655 proto->protocol = protocol; 648 656 proto->phone = phone; 657 649 658 index = eth_protos_add(ð_globals.protos, protocol, proto); 650 659 if (index < 0) { … … 705 714 if (!padding) 706 715 return ENOMEM; 716 707 717 bzero(padding, ETH_MIN_TAGGED_CONTENT(flags) - length); 708 718 } … … 782 792 * @returns EINVAL if the service parameter is not known. 783 793 */ 784 static int 785 eth_send_message(device_id_t device_id, packet_t packet,services_t sender)794 static int eth_send_message(device_id_t device_id, packet_t packet, 795 services_t sender) 786 796 { 787 797 eth_device_ref device; … … 804 814 } 805 815 806 / / process packet queue816 /* Process packet queue */ 807 817 next = packet; 808 818 do { … … 810 820 (uint8_t *) device->addr->value, ethertype, device->mtu); 811 821 if (rc != EOK) { 812 / / release invalid packet822 /* Release invalid packet */ 813 823 tmp = pq_detach(next); 814 824 if (next == packet) … … 822 832 } while(next); 823 833 824 / / send packet queue834 /* Send packet queue */ 825 835 if (packet) { 826 836 netif_send_msg(device->phone, device_id, packet, 827 837 SERVICE_ETHERNET); 828 838 } 839 829 840 fibril_rwlock_read_unlock(ð_globals.devices_lock); 830 831 841 return EOK; 832 842 } 833 843 834 int 835 nil_message_standalone(const char *name, ipc_callid_t callid, ipc_call_t *call, 836 ipc_call_t *answer, int *answer_count) 844 int nil_message_standalone(const char *name, ipc_callid_t callid, 845 ipc_call_t *call, ipc_call_t *answer, int *answer_count) 837 846 { 838 847 measured_string_ref address; … … 894 903 * @param[in] iid The initial message identifier. 895 904 * @param[in] icall The initial message call structure. 896 *897 905 */ 898 906 static void nil_client_connection(ipc_callid_t iid, ipc_call_t *icall)
Note:
See TracChangeset
for help on using the changeset viewer.