Ignore:
File:
1 edited

Legend:

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

    r6b82009 r28a3e74  
    5959#include <packet_remote.h>
    6060#include <nil_skel.h>
     61
    6162#include "eth.h"
    6263
     
    167168INT_MAP_IMPLEMENT(eth_protos, eth_proto_t);
    168169
    169 int nil_device_state_msg_local(device_id_t device_id, sysarg_t state)
     170int nil_device_state_msg_local(int nil_phone, device_id_t device_id, int state)
    170171{
    171172        int index;
     
    176177            index--) {
    177178                proto = eth_protos_get_index(&eth_globals.protos, index);
    178                 if ((proto) && (proto->sess)) {
    179                         il_device_state_msg(proto->sess, device_id, state,
     179                if (proto && proto->phone) {
     180                        il_device_state_msg(proto->phone, device_id, state,
    180181                            proto->service);
    181182                }
     
    186187}
    187188
    188 int nil_initialize(async_sess_t *sess)
     189int nil_initialize(int net_phone)
    189190{
    190191        int rc;
     
    195196        fibril_rwlock_write_lock(&eth_globals.devices_lock);
    196197        fibril_rwlock_write_lock(&eth_globals.protos_lock);
    197         eth_globals.net_sess = sess;
     198        eth_globals.net_phone = net_phone;
    198199
    199200        eth_globals.broadcast_addr =
     
    222223}
    223224
    224 /** Process IPC messages from the registered device driver modules in an
     225/** Processes IPC messages from the registered device driver modules in an
    225226 * infinite loop.
    226227 *
    227  * @param[in]     iid   Message identifier.
    228  * @param[in,out] icall Message parameters.
    229  * @param[in]     arg   Local argument.
    230  *
    231  */
    232 static void eth_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     228 * @param[in] iid       The message identifier.
     229 * @param[in,out] icall The message parameters.
     230 */
     231static void eth_receiver(ipc_callid_t iid, ipc_call_t *icall)
    233232{
    234233        packet_t *packet;
     
    238237                switch (IPC_GET_IMETHOD(*icall)) {
    239238                case NET_NIL_DEVICE_STATE:
    240                         nil_device_state_msg_local(IPC_GET_DEVICE(*icall),
     239                        nil_device_state_msg_local(0, IPC_GET_DEVICE(*icall),
    241240                            IPC_GET_STATE(*icall));
    242241                        async_answer_0(iid, EOK);
    243242                        break;
    244243                case NET_NIL_RECEIVED:
    245                         rc = packet_translate_remote(eth_globals.net_sess,
     244                        rc = packet_translate_remote(eth_globals.net_phone,
    246245                            &packet, IPC_GET_PACKET(*icall));
    247246                        if (rc == EOK)
    248                                 rc = nil_received_msg_local(IPC_GET_DEVICE(*icall),
    249                                     packet, 0);
     247                                rc = nil_received_msg_local(0,
     248                                    IPC_GET_DEVICE(*icall), packet, 0);
    250249                       
    251250                        async_answer_0(iid, (sysarg_t) rc);
     
    323322                        proto = eth_protos_get_index(&eth_globals.protos,
    324323                            index);
    325                         if (proto->sess) {
    326                                 il_mtu_changed_msg(proto->sess,
     324                        if (proto->phone) {
     325                                il_mtu_changed_msg(proto->phone,
    327326                                    device->device_id, device->mtu,
    328327                                    proto->service);
     
    348347
    349348        configuration = &names[0];
    350         rc = net_get_device_conf_req(eth_globals.net_sess, device->device_id,
     349        rc = net_get_device_conf_req(eth_globals.net_phone, device->device_id,
    351350            &configuration, count, &data);
    352351        if (rc != EOK) {
     
    377376       
    378377        /* Bind the device driver */
    379         device->sess = netif_bind_service(device->service, device->device_id,
     378        device->phone = netif_bind_service(device->service, device->device_id,
    380379            SERVICE_ETHERNET, eth_receiver);
    381         if (device->sess == NULL) {
     380        if (device->phone < 0) {
    382381                fibril_rwlock_write_unlock(&eth_globals.devices_lock);
    383382                free(device);
    384                 return ENOENT;
     383                return device->phone;
    385384        }
    386385       
    387386        /* Get hardware address */
    388         rc = netif_get_addr_req(device->sess, device->device_id, &device->addr,
     387        rc = netif_get_addr_req(device->phone, device->device_id, &device->addr,
    389388            &device->addr_data);
    390389        if (rc != EOK) {
     
    506505}
    507506
    508 int nil_received_msg_local(device_id_t device_id, packet_t *packet,
    509     services_t target)
     507int nil_received_msg_local(int nil_phone, device_id_t device_id,
     508    packet_t *packet, services_t target)
    510509{
    511510        eth_proto_t *proto;
     
    529528                proto = eth_process_packet(flags, packet);
    530529                if (proto) {
    531                         il_received_msg(proto->sess, device_id, packet,
     530                        il_received_msg(proto->phone, device_id, packet,
    532531                            proto->service);
    533532                } else {
    534533                        /* Drop invalid/unknown */
    535                         pq_release_remote(eth_globals.net_sess,
     534                        pq_release_remote(eth_globals.net_phone,
    536535                            packet_get_id(packet));
    537536                }
     
    612611}
    613612
    614 /** Register receiving module service.
    615  *
    616  * Pass received packets for this service.
    617  *
    618  * @param[in] service Module service.
    619  * @param[in] sess    Service session.
    620  *
    621  * @return EOK on success.
    622  * @return ENOENT if the service is not known.
    623  * @return ENOMEM if there is not enough memory left.
    624  *
    625  */
    626 static int eth_register_message(services_t service, async_sess_t *sess)
     613/** Registers receiving module service.
     614 *
     615 * Passes received packets for this service.
     616 *
     617 * @param[in] service   The module service.
     618 * @param[in] phone     The service phone.
     619 * @return              EOK on success.
     620 * @return              ENOENT if the service is not known.
     621 * @return              ENOMEM if there is not enough memory left.
     622 */
     623static int eth_register_message(services_t service, int phone)
    627624{
    628625        eth_proto_t *proto;
     
    637634        proto = eth_protos_find(&eth_globals.protos, protocol);
    638635        if (proto) {
    639                 proto->sess = sess;
     636                proto->phone = phone;
    640637                fibril_rwlock_write_unlock(&eth_globals.protos_lock);
    641638                return EOK;
     
    649646                proto->service = service;
    650647                proto->protocol = protocol;
    651                 proto->sess = sess;
     648                proto->phone = phone;
    652649
    653650                index = eth_protos_add(&eth_globals.protos, protocol, proto);
     
    659656        }
    660657       
    661         printf("%s: Protocol registered (protocol: %d, service: %d)\n",
    662             NAME, proto->protocol, proto->service);
     658        printf("%s: Protocol registered (protocol: %d, service: %d, phone: "
     659            "%d)\n", NAME, proto->protocol, proto->service, proto->phone);
    663660       
    664661        fibril_rwlock_write_unlock(&eth_globals.protos_lock);
     
    798795        ethertype = htons(protocol_map(SERVICE_ETHERNET, sender));
    799796        if (!ethertype) {
    800                 pq_release_remote(eth_globals.net_sess, packet_get_id(packet));
     797                pq_release_remote(eth_globals.net_phone, packet_get_id(packet));
    801798                return EINVAL;
    802799        }
     
    819816                        if (next == packet)
    820817                                packet = tmp;
    821                         pq_release_remote(eth_globals.net_sess,
     818                        pq_release_remote(eth_globals.net_phone,
    822819                            packet_get_id(next));
    823820                        next = tmp;
     
    829826        /* Send packet queue */
    830827        if (packet) {
    831                 netif_send_msg(device->sess, device_id, packet,
     828                netif_send_msg(device->phone, device_id, packet,
    832829                    SERVICE_ETHERNET);
    833830        }
     
    849846       
    850847        *answer_count = 0;
    851        
    852         if (!IPC_GET_IMETHOD(*call))
     848        switch (IPC_GET_IMETHOD(*call)) {
     849        case IPC_M_PHONE_HUNGUP:
    853850                return EOK;
    854851       
    855         async_sess_t *callback =
    856             async_callback_receive_start(EXCHANGE_SERIALIZE, call);
    857         if (callback)
    858                 return eth_register_message(NIL_GET_PROTO(*call), callback);
    859        
    860         switch (IPC_GET_IMETHOD(*call)) {
    861852        case NET_NIL_DEVICE:
    862853                return eth_device_message(IPC_GET_DEVICE(*call),
    863854                    IPC_GET_SERVICE(*call), IPC_GET_MTU(*call));
    864855        case NET_NIL_SEND:
    865                 rc = packet_translate_remote(eth_globals.net_sess, &packet,
     856                rc = packet_translate_remote(eth_globals.net_phone, &packet,
    866857                    IPC_GET_PACKET(*call));
    867858                if (rc != EOK)
     
    892883                        return EOK;
    893884                return measured_strings_reply(address, 1);
     885        case IPC_M_CONNECT_TO_ME:
     886                return eth_register_message(NIL_GET_PROTO(*call),
     887                    IPC_GET_PHONE(*call));
    894888        }
    895889       
Note: See TracChangeset for help on using the changeset viewer.