Ignore:
File:
1 edited

Legend:

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

    r6b82009 rffa2c8ef  
    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
    5456#include "nildummy.h"
    5557
     
    6567DEVICE_MAP_IMPLEMENT(nildummy_devices, nildummy_device_t);
    6668
    67 int nil_device_state_msg_local(device_id_t device_id, sysarg_t state)
     69int nil_device_state_msg_local(int nil_phone, device_id_t device_id, int state)
    6870{
    6971        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,
     72        if (nildummy_globals.proto.phone)
     73                il_device_state_msg(nildummy_globals.proto.phone, device_id,
    7274                    state, nildummy_globals.proto.service);
    7375        fibril_rwlock_read_unlock(&nildummy_globals.protos_lock);
     
    7678}
    7779
    78 int nil_initialize(async_sess_t *sess)
     80int nil_initialize(int net_phone)
    7981{
    8082        fibril_rwlock_initialize(&nildummy_globals.devices_lock);
     
    8385        fibril_rwlock_write_lock(&nildummy_globals.protos_lock);
    8486       
    85         nildummy_globals.net_sess = sess;
    86         nildummy_globals.proto.sess = NULL;
     87        nildummy_globals.net_phone = net_phone;
     88        nildummy_globals.proto.phone = 0;
    8789        int rc = nildummy_devices_initialize(&nildummy_globals.devices);
    8890       
     
    9799 * @param[in]     iid   Message identifier.
    98100 * @param[in,out] icall Message parameters.
    99  * @param[in]     arg    Local argument.
    100  *
    101  */
    102 static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     101 *
     102 */
     103static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall)
    103104{
    104105        packet_t *packet;
     
    108109                switch (IPC_GET_IMETHOD(*icall)) {
    109110                case NET_NIL_DEVICE_STATE:
    110                         rc = nil_device_state_msg_local(IPC_GET_DEVICE(*icall),
    111                             IPC_GET_STATE(*icall));
     111                        rc = nil_device_state_msg_local(0,
     112                            IPC_GET_DEVICE(*icall), IPC_GET_STATE(*icall));
    112113                        async_answer_0(iid, (sysarg_t) rc);
    113114                        break;
    114115               
    115116                case NET_NIL_RECEIVED:
    116                         rc = packet_translate_remote(nildummy_globals.net_sess,
     117                        rc = packet_translate_remote(nildummy_globals.net_phone,
    117118                            &packet, IPC_GET_PACKET(*icall));
    118119                        if (rc == EOK)
    119                                 rc = nil_received_msg_local(IPC_GET_DEVICE(*icall),
    120                                     packet, 0);
     120                                rc = nil_received_msg_local(0,
     121                                    IPC_GET_DEVICE(*icall), packet, 0);
    121122                       
    122123                        async_answer_0(iid, (sysarg_t) rc);
     
    176177                /* Notify the upper layer module */
    177178                fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
    178                 if (nildummy_globals.proto.sess) {
    179                         il_mtu_changed_msg(nildummy_globals.proto.sess,
     179                if (nildummy_globals.proto.phone) {
     180                        il_mtu_changed_msg(nildummy_globals.proto.phone,
    180181                            device->device_id, device->mtu,
    181182                            nildummy_globals.proto.service);
     
    199200
    200201        /* Bind the device driver */
    201         device->sess = netif_bind_service(device->service, device->device_id,
     202        device->phone = netif_bind_service(device->service, device->device_id,
    202203            SERVICE_ETHERNET, nildummy_receiver);
    203         if (device->sess == NULL) {
     204        if (device->phone < 0) {
    204205                fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
    205206                free(device);
    206                 return ENOENT;
     207                return device->phone;
    207208        }
    208209       
    209210        /* Get hardware address */
    210         int rc = netif_get_addr_req(device->sess, device->device_id,
     211        int rc = netif_get_addr_req(device->phone, device->device_id,
    211212            &device->addr, &device->addr_data);
    212213        if (rc != EOK) {
     
    303304}
    304305
    305 int nil_received_msg_local(device_id_t device_id, packet_t *packet,
    306     services_t target)
     306int nil_received_msg_local(int nil_phone, device_id_t device_id,
     307    packet_t *packet, services_t target)
    307308{
    308309        fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
    309310       
    310         if (nildummy_globals.proto.sess) {
     311        if (nildummy_globals.proto.phone) {
    311312                do {
    312313                        packet_t *next = pq_detach(packet);
    313                         il_received_msg(nildummy_globals.proto.sess, device_id,
     314                        il_received_msg(nildummy_globals.proto.phone, device_id,
    314315                            packet, nildummy_globals.proto.service);
    315316                        packet = next;
     
    327328 *
    328329 * @param[in] service Module service.
    329  * @param[in] sess    Service session.
     330 * @param[in] phone   Service phone.
    330331 *
    331332 * @return EOK on success.
     
    334335 *
    335336 */
    336 static int nildummy_register_message(services_t service, async_sess_t *sess)
     337static int nildummy_register_message(services_t service, int phone)
    337338{
    338339        fibril_rwlock_write_lock(&nildummy_globals.protos_lock);
    339340        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);
     341        nildummy_globals.proto.phone = phone;
     342       
     343        printf("%s: Protocol registered (service: %d, phone: %d)\n",
     344            NAME, nildummy_globals.proto.service, nildummy_globals.proto.phone);
    344345       
    345346        fibril_rwlock_write_unlock(&nildummy_globals.protos_lock);
     
    372373        /* Send packet queue */
    373374        if (packet)
    374                 netif_send_msg(device->sess, device_id, packet,
     375                netif_send_msg(device->phone, device_id, packet,
    375376                    SERVICE_NILDUMMY);
    376377       
     
    392393       
    393394        *answer_count = 0;
    394        
    395         if (!IPC_GET_IMETHOD(*call))
     395        switch (IPC_GET_IMETHOD(*call)) {
     396        case IPC_M_PHONE_HUNGUP:
    396397                return EOK;
    397398       
    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        
    403         switch (IPC_GET_IMETHOD(*call)) {
    404399        case NET_NIL_DEVICE:
    405400                return nildummy_device_message(IPC_GET_DEVICE(*call),
     
    407402       
    408403        case NET_NIL_SEND:
    409                 rc = packet_translate_remote(nildummy_globals.net_sess,
     404                rc = packet_translate_remote(nildummy_globals.net_phone,
    410405                    &packet, IPC_GET_PACKET(*call));
    411406                if (rc != EOK)
     
    437432                        return rc;
    438433                return measured_strings_reply(address, 1);
     434       
     435        case IPC_M_CONNECT_TO_ME:
     436                return nildummy_register_message(NIL_GET_PROTO(*call),
     437                    IPC_GET_PHONE(*call));
    439438        }
    440439       
Note: See TracChangeset for help on using the changeset viewer.