Changeset cb569e6 in mainline for uspace/srv/net/nil/eth/eth.c


Ignore:
Timestamp:
2010-11-18T21:58:27Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4e5c7ba
Parents:
69e0d6d (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.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/nil/eth/eth.c

    r69e0d6d rcb569e6  
    204204        fibril_rwlock_write_lock(&eth_globals.protos_lock);
    205205        eth_globals.net_phone = net_phone;
     206
    206207        eth_globals.broadcast_addr =
    207208            measured_string_create_bulk("\xFF\xFF\xFF\xFF\xFF\xFF",
     
    211212                goto out;
    212213        }
     214
    213215        rc = eth_devices_initialize(&eth_globals.devices);
    214216        if (rc != EOK) {
     
    216218                goto out;
    217219        }
     220
    218221        rc = eth_protos_initialize(&eth_globals.protos);
    219222        if (rc != EOK) {
     
    280283 *                      netif_get_addr_req() function.
    281284 */
    282 static int
    283 eth_device_message(device_id_t device_id, services_t service, size_t mtu)
     285static int eth_device_message(device_id_t device_id, services_t service,
     286    size_t mtu)
    284287{
    285288        eth_device_ref device;
     
    302305
    303306        fibril_rwlock_write_lock(&eth_globals.devices_lock);
    304         // an existing device?
     307        /* An existing device? */
    305308        device = eth_devices_find(&eth_globals.devices, device_id);
    306309        if (device) {
     
    311314                }
    312315               
    313                 // update mtu
     316                /* Update mtu */
    314317                if ((mtu > 0) && (mtu <= ETH_MAX_TAGGED_CONTENT(device->flags)))
    315318                        device->mtu = mtu;
     
    321324                fibril_rwlock_write_unlock(&eth_globals.devices_lock);
    322325               
    323                 // notify all upper layer modules
     326                /* Notify all upper layer modules */
    324327                fibril_rwlock_read_lock(&eth_globals.protos_lock);
    325328                for (index = 0; index < eth_protos_count(&eth_globals.protos);
     
    333336                        }
    334337                }
     338
    335339                fibril_rwlock_read_unlock(&eth_globals.protos_lock);
    336340                return EOK;
    337341        }
    338342       
    339         // create a new device
     343        /* Create a new device */
    340344        device = (eth_device_ref) malloc(sizeof(eth_device_t));
    341345        if (!device)
     
    358362                return rc;
    359363        }
     364
    360365        if (configuration) {
    361366                if (!str_lcmp(configuration[0].value, "DIX",
     
    378383        }
    379384       
    380         // bind the device driver
     385        /* Bind the device driver */
    381386        device->phone = netif_bind_service(device->service, device->device_id,
    382387            SERVICE_ETHERNET, eth_receiver);
     
    387392        }
    388393       
    389         // get hardware address
     394        /* Get hardware address */
    390395        rc = netif_get_addr_req(device->phone, device->device_id, &device->addr,
    391396            &device->addr_data);
     
    396401        }
    397402       
    398         // add to the cache
     403        /* Add to the cache */
    399404        index = eth_devices_add(&eth_globals.devices, device->device_id,
    400405            device);
     
    453458       
    454459        if (type >= ETH_MIN_PROTO) {
    455                 // DIX Ethernet
     460                /* DIX Ethernet */
    456461                prefix = sizeof(eth_header_t);
    457462                suffix = 0;
     
    459464                length -= sizeof(eth_fcs_t);
    460465        } else if(type <= ETH_MAX_CONTENT) {
    461                 // translate "LSAP" values
     466                /* Translate "LSAP" values */
    462467                if ((header->lsap.dsap == ETH_LSAP_GLSAP) &&
    463468                    (header->lsap.ssap == ETH_LSAP_GLSAP)) {
    464                         // raw packet
    465                         // discard
     469                        /* Raw packet -- discard */
    466470                        return NULL;
    467471                } else if((header->lsap.dsap == ETH_LSAP_SNAP) &&
    468472                    (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                         */
    471477                        type = ntohs(header->snap.ethertype);
    472478                        prefix = sizeof(eth_header_t) +
     
    474480                            sizeof(eth_header_snap_t);
    475481                } else {
    476                         // IEEE 802.3 + 802.2 LSAP
     482                        /* IEEE 802.3 + 802.2 LSAP */
    477483                        type = lsap_map(header->lsap.dsap);
    478484                        prefix = sizeof(eth_header_t) +
    479485                            sizeof(eth_header_lsap_t);
    480486                }
     487
    481488                suffix = (type < ETH_MIN_CONTENT) ? ETH_MIN_CONTENT - type : 0U;
    482489                fcs = (eth_fcs_ref) data + prefix + type + suffix;
     
    484491                length = prefix + type + suffix;
    485492        } else {
    486                 // invalid length/type, should not occurr
     493                /* Invalid length/type, should not occur */
    487494                return NULL;
    488495        }
     
    506513}
    507514
    508 int
    509 nil_received_msg_local(int nil_phone, device_id_t device_id, packet_t packet,
    510     services_t target)
     515int nil_received_msg_local(int nil_phone, device_id_t device_id,
     516    packet_t packet, services_t target)
    511517{
    512518        eth_proto_ref proto;
     
    521527                return ENOENT;
    522528        }
     529
    523530        flags = device->flags;
    524531        fibril_rwlock_read_unlock(&eth_globals.devices_lock);
     
    538545                packet = next;
    539546        } while(packet);
     547
    540548        fibril_rwlock_read_unlock(&eth_globals.protos_lock);
    541        
    542549        return EOK;
    543550}
     
    554561 * @returns             ENOENT if there is no such device.
    555562 */
    556 static int
    557 eth_packet_space_message(device_id_t device_id, size_t *addr_len,
     563static int eth_packet_space_message(device_id_t device_id, size_t *addr_len,
    558564    size_t *prefix, size_t *content, size_t *suffix)
    559565{
     
    569575                return ENOENT;
    570576        }
     577
    571578        *content = device->mtu;
    572579        fibril_rwlock_read_unlock(&eth_globals.devices_lock);
     
    575582        *prefix = ETH_PREFIX;
    576583        *suffix = ETH_MIN_CONTENT + ETH_SUFFIX;
     584
    577585        return EOK;
    578586}
     
    587595 * @returns             ENOENT if there no such device.
    588596 */
    589 static int
    590 eth_addr_message(device_id_t device_id, eth_addr_type_t type,
     597static int eth_addr_message(device_id_t device_id, eth_addr_type_t type,
    591598    measured_string_ref *address)
    592599{
     
    644651                        return ENOMEM;
    645652                }
     653
    646654                proto->service = service;
    647655                proto->protocol = protocol;
    648656                proto->phone = phone;
     657
    649658                index = eth_protos_add(&eth_globals.protos, protocol, proto);
    650659                if (index < 0) {
     
    705714                if (!padding)
    706715                        return ENOMEM;
     716
    707717                bzero(padding, ETH_MIN_TAGGED_CONTENT(flags) - length);
    708718        }
     
    782792 * @returns             EINVAL if the service parameter is not known.
    783793 */
    784 static int
    785 eth_send_message(device_id_t device_id, packet_t packet, services_t sender)
     794static int eth_send_message(device_id_t device_id, packet_t packet,
     795    services_t sender)
    786796{
    787797        eth_device_ref device;
     
    804814        }
    805815       
    806         // process packet queue
     816        /* Process packet queue */
    807817        next = packet;
    808818        do {
     
    810820                    (uint8_t *) device->addr->value, ethertype, device->mtu);
    811821                if (rc != EOK) {
    812                         // release invalid packet
     822                        /* Release invalid packet */
    813823                        tmp = pq_detach(next);
    814824                        if (next == packet)
     
    822832        } while(next);
    823833       
    824         // send packet queue
     834        /* Send packet queue */
    825835        if (packet) {
    826836                netif_send_msg(device->phone, device_id, packet,
    827837                    SERVICE_ETHERNET);
    828838        }
     839
    829840        fibril_rwlock_read_unlock(&eth_globals.devices_lock);
    830        
    831841        return EOK;
    832842}
    833843
    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)
     844int nil_message_standalone(const char *name, ipc_callid_t callid,
     845    ipc_call_t *call, ipc_call_t *answer, int *answer_count)
    837846{
    838847        measured_string_ref address;
     
    894903 * @param[in] iid       The initial message identifier.
    895904 * @param[in] icall     The initial message call structure.
    896  *
    897905 */
    898906static void nil_client_connection(ipc_callid_t iid, ipc_call_t *icall)
Note: See TracChangeset for help on using the changeset viewer.