Ignore:
File:
1 edited

Legend:

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

    r6b82009 r9934f7d  
    4444#include <ipc/net.h>
    4545#include <ipc/services.h>
     46
    4647#include <net/modules.h>
    4748#include <net/device.h>
     
    5253#include <netif_remote.h>
    5354#include <nil_skel.h>
     55
     56// FIXME: remove this header
     57#include <kernel/ipc/ipc_methods.h>
     58
    5459#include "nildummy.h"
    5560
     
    6570DEVICE_MAP_IMPLEMENT(nildummy_devices, nildummy_device_t);
    6671
    67 int nil_device_state_msg_local(device_id_t device_id, sysarg_t state)
     72int nil_device_state_msg_local(int nil_phone, device_id_t device_id, int state)
    6873{
    6974        fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
    70         if (nildummy_globals.proto.sess)
    71                 il_device_state_msg(nildummy_globals.proto.sess, device_id,
     75        if (nildummy_globals.proto.phone)
     76                il_device_state_msg(nildummy_globals.proto.phone, device_id,
    7277                    state, nildummy_globals.proto.service);
    7378        fibril_rwlock_read_unlock(&nildummy_globals.protos_lock);
     
    7681}
    7782
    78 int nil_initialize(async_sess_t *sess)
     83int nil_initialize(int net_phone)
    7984{
    8085        fibril_rwlock_initialize(&nildummy_globals.devices_lock);
     
    8388        fibril_rwlock_write_lock(&nildummy_globals.protos_lock);
    8489       
    85         nildummy_globals.net_sess = sess;
    86         nildummy_globals.proto.sess = NULL;
     90        nildummy_globals.net_phone = net_phone;
     91        nildummy_globals.proto.phone = 0;
    8792        int rc = nildummy_devices_initialize(&nildummy_globals.devices);
    8893       
     
    97102 * @param[in]     iid   Message identifier.
    98103 * @param[in,out] icall Message parameters.
    99  * @param[in]     arg    Local argument.
    100  *
     104 * @param[in]     arg   Local argument.
    101105 */
    102106static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     
    108112                switch (IPC_GET_IMETHOD(*icall)) {
    109113                case NET_NIL_DEVICE_STATE:
    110                         rc = nil_device_state_msg_local(IPC_GET_DEVICE(*icall),
    111                             IPC_GET_STATE(*icall));
     114                        rc = nil_device_state_msg_local(0,
     115                            IPC_GET_DEVICE(*icall), IPC_GET_STATE(*icall));
    112116                        async_answer_0(iid, (sysarg_t) rc);
    113117                        break;
    114118               
    115119                case NET_NIL_RECEIVED:
    116                         rc = packet_translate_remote(nildummy_globals.net_sess,
     120                        rc = packet_translate_remote(nildummy_globals.net_phone,
    117121                            &packet, IPC_GET_PACKET(*icall));
    118122                        if (rc == EOK)
    119                                 rc = nil_received_msg_local(IPC_GET_DEVICE(*icall),
    120                                     packet, 0);
     123                                rc = nil_received_msg_local(0,
     124                                    IPC_GET_DEVICE(*icall), packet, 0);
    121125                       
    122126                        async_answer_0(iid, (sysarg_t) rc);
     
    176180                /* Notify the upper layer module */
    177181                fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
    178                 if (nildummy_globals.proto.sess) {
    179                         il_mtu_changed_msg(nildummy_globals.proto.sess,
     182                if (nildummy_globals.proto.phone) {
     183                        il_mtu_changed_msg(nildummy_globals.proto.phone,
    180184                            device->device_id, device->mtu,
    181185                            nildummy_globals.proto.service);
     
    199203
    200204        /* Bind the device driver */
    201         device->sess = netif_bind_service(device->service, device->device_id,
     205        device->phone = netif_bind_service(device->service, device->device_id,
    202206            SERVICE_ETHERNET, nildummy_receiver);
    203         if (device->sess == NULL) {
     207        if (device->phone < 0) {
    204208                fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
    205209                free(device);
    206                 return ENOENT;
     210                return device->phone;
    207211        }
    208212       
    209213        /* Get hardware address */
    210         int rc = netif_get_addr_req(device->sess, device->device_id,
     214        int rc = netif_get_addr_req(device->phone, device->device_id,
    211215            &device->addr, &device->addr_data);
    212216        if (rc != EOK) {
     
    303307}
    304308
    305 int nil_received_msg_local(device_id_t device_id, packet_t *packet,
    306     services_t target)
     309int nil_received_msg_local(int nil_phone, device_id_t device_id,
     310    packet_t *packet, services_t target)
    307311{
    308312        fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
    309313       
    310         if (nildummy_globals.proto.sess) {
     314        if (nildummy_globals.proto.phone) {
    311315                do {
    312316                        packet_t *next = pq_detach(packet);
    313                         il_received_msg(nildummy_globals.proto.sess, device_id,
     317                        il_received_msg(nildummy_globals.proto.phone, device_id,
    314318                            packet, nildummy_globals.proto.service);
    315319                        packet = next;
     
    327331 *
    328332 * @param[in] service Module service.
    329  * @param[in] sess    Service session.
     333 * @param[in] phone   Service phone.
    330334 *
    331335 * @return EOK on success.
     
    334338 *
    335339 */
    336 static int nildummy_register_message(services_t service, async_sess_t *sess)
     340static int nildummy_register_message(services_t service, int phone)
    337341{
    338342        fibril_rwlock_write_lock(&nildummy_globals.protos_lock);
    339343        nildummy_globals.proto.service = service;
    340         nildummy_globals.proto.sess = sess;
    341        
    342         printf("%s: Protocol registered (service: %d)\n",
    343             NAME, nildummy_globals.proto.service);
     344        nildummy_globals.proto.phone = phone;
     345       
     346        printf("%s: Protocol registered (service: %d, phone: %d)\n",
     347            NAME, nildummy_globals.proto.service, nildummy_globals.proto.phone);
    344348       
    345349        fibril_rwlock_write_unlock(&nildummy_globals.protos_lock);
     
    372376        /* Send packet queue */
    373377        if (packet)
    374                 netif_send_msg(device->sess, device_id, packet,
     378                netif_send_msg(device->phone, device_id, packet,
    375379                    SERVICE_NILDUMMY);
    376380       
     
    396400                return EOK;
    397401       
    398         async_sess_t *callback =
    399             async_callback_receive_start(EXCHANGE_SERIALIZE, call);
    400         if (callback)
    401                 return nildummy_register_message(NIL_GET_PROTO(*call), callback);
    402        
    403402        switch (IPC_GET_IMETHOD(*call)) {
    404403        case NET_NIL_DEVICE:
     
    407406       
    408407        case NET_NIL_SEND:
    409                 rc = packet_translate_remote(nildummy_globals.net_sess,
     408                rc = packet_translate_remote(nildummy_globals.net_phone,
    410409                    &packet, IPC_GET_PACKET(*call));
    411410                if (rc != EOK)
     
    437436                        return rc;
    438437                return measured_strings_reply(address, 1);
     438       
     439        case IPC_M_CONNECT_TO_ME:
     440                return nildummy_register_message(NIL_GET_PROTO(*call),
     441                    IPC_GET_PHONE(*call));
    439442        }
    440443       
Note: See TracChangeset for help on using the changeset viewer.