Ignore:
File:
1 edited

Legend:

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

    rffa2c8ef r6b82009  
    4444#include <ipc/net.h>
    4545#include <ipc/services.h>
    46 
    4746#include <net/modules.h>
    4847#include <net/device.h>
     
    5352#include <netif_remote.h>
    5453#include <nil_skel.h>
    55 
    5654#include "nildummy.h"
    5755
     
    6765DEVICE_MAP_IMPLEMENT(nildummy_devices, nildummy_device_t);
    6866
    69 int nil_device_state_msg_local(int nil_phone, device_id_t device_id, int state)
     67int nil_device_state_msg_local(device_id_t device_id, sysarg_t state)
    7068{
    7169        fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
    72         if (nildummy_globals.proto.phone)
    73                 il_device_state_msg(nildummy_globals.proto.phone, device_id,
     70        if (nildummy_globals.proto.sess)
     71                il_device_state_msg(nildummy_globals.proto.sess, device_id,
    7472                    state, nildummy_globals.proto.service);
    7573        fibril_rwlock_read_unlock(&nildummy_globals.protos_lock);
     
    7876}
    7977
    80 int nil_initialize(int net_phone)
     78int nil_initialize(async_sess_t *sess)
    8179{
    8280        fibril_rwlock_initialize(&nildummy_globals.devices_lock);
     
    8583        fibril_rwlock_write_lock(&nildummy_globals.protos_lock);
    8684       
    87         nildummy_globals.net_phone = net_phone;
    88         nildummy_globals.proto.phone = 0;
     85        nildummy_globals.net_sess = sess;
     86        nildummy_globals.proto.sess = NULL;
    8987        int rc = nildummy_devices_initialize(&nildummy_globals.devices);
    9088       
     
    9997 * @param[in]     iid   Message identifier.
    10098 * @param[in,out] icall Message parameters.
    101  *
    102  */
    103 static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall)
     99 * @param[in]     arg    Local argument.
     100 *
     101 */
     102static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    104103{
    105104        packet_t *packet;
     
    109108                switch (IPC_GET_IMETHOD(*icall)) {
    110109                case NET_NIL_DEVICE_STATE:
    111                         rc = nil_device_state_msg_local(0,
    112                             IPC_GET_DEVICE(*icall), IPC_GET_STATE(*icall));
     110                        rc = nil_device_state_msg_local(IPC_GET_DEVICE(*icall),
     111                            IPC_GET_STATE(*icall));
    113112                        async_answer_0(iid, (sysarg_t) rc);
    114113                        break;
    115114               
    116115                case NET_NIL_RECEIVED:
    117                         rc = packet_translate_remote(nildummy_globals.net_phone,
     116                        rc = packet_translate_remote(nildummy_globals.net_sess,
    118117                            &packet, IPC_GET_PACKET(*icall));
    119118                        if (rc == EOK)
    120                                 rc = nil_received_msg_local(0,
    121                                     IPC_GET_DEVICE(*icall), packet, 0);
     119                                rc = nil_received_msg_local(IPC_GET_DEVICE(*icall),
     120                                    packet, 0);
    122121                       
    123122                        async_answer_0(iid, (sysarg_t) rc);
     
    177176                /* Notify the upper layer module */
    178177                fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
    179                 if (nildummy_globals.proto.phone) {
    180                         il_mtu_changed_msg(nildummy_globals.proto.phone,
     178                if (nildummy_globals.proto.sess) {
     179                        il_mtu_changed_msg(nildummy_globals.proto.sess,
    181180                            device->device_id, device->mtu,
    182181                            nildummy_globals.proto.service);
     
    200199
    201200        /* Bind the device driver */
    202         device->phone = netif_bind_service(device->service, device->device_id,
     201        device->sess = netif_bind_service(device->service, device->device_id,
    203202            SERVICE_ETHERNET, nildummy_receiver);
    204         if (device->phone < 0) {
     203        if (device->sess == NULL) {
    205204                fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
    206205                free(device);
    207                 return device->phone;
     206                return ENOENT;
    208207        }
    209208       
    210209        /* Get hardware address */
    211         int rc = netif_get_addr_req(device->phone, device->device_id,
     210        int rc = netif_get_addr_req(device->sess, device->device_id,
    212211            &device->addr, &device->addr_data);
    213212        if (rc != EOK) {
     
    304303}
    305304
    306 int nil_received_msg_local(int nil_phone, device_id_t device_id,
    307     packet_t *packet, services_t target)
     305int nil_received_msg_local(device_id_t device_id, packet_t *packet,
     306    services_t target)
    308307{
    309308        fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
    310309       
    311         if (nildummy_globals.proto.phone) {
     310        if (nildummy_globals.proto.sess) {
    312311                do {
    313312                        packet_t *next = pq_detach(packet);
    314                         il_received_msg(nildummy_globals.proto.phone, device_id,
     313                        il_received_msg(nildummy_globals.proto.sess, device_id,
    315314                            packet, nildummy_globals.proto.service);
    316315                        packet = next;
     
    328327 *
    329328 * @param[in] service Module service.
    330  * @param[in] phone   Service phone.
     329 * @param[in] sess    Service session.
    331330 *
    332331 * @return EOK on success.
     
    335334 *
    336335 */
    337 static int nildummy_register_message(services_t service, int phone)
     336static int nildummy_register_message(services_t service, async_sess_t *sess)
    338337{
    339338        fibril_rwlock_write_lock(&nildummy_globals.protos_lock);
    340339        nildummy_globals.proto.service = 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);
     340        nildummy_globals.proto.sess = sess;
     341       
     342        printf("%s: Protocol registered (service: %d)\n",
     343            NAME, nildummy_globals.proto.service);
    345344       
    346345        fibril_rwlock_write_unlock(&nildummy_globals.protos_lock);
     
    373372        /* Send packet queue */
    374373        if (packet)
    375                 netif_send_msg(device->phone, device_id, packet,
     374                netif_send_msg(device->sess, device_id, packet,
    376375                    SERVICE_NILDUMMY);
    377376       
     
    393392       
    394393        *answer_count = 0;
     394       
     395        if (!IPC_GET_IMETHOD(*call))
     396                return EOK;
     397       
     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       
    395403        switch (IPC_GET_IMETHOD(*call)) {
    396         case IPC_M_PHONE_HUNGUP:
    397                 return EOK;
    398        
    399404        case NET_NIL_DEVICE:
    400405                return nildummy_device_message(IPC_GET_DEVICE(*call),
     
    402407       
    403408        case NET_NIL_SEND:
    404                 rc = packet_translate_remote(nildummy_globals.net_phone,
     409                rc = packet_translate_remote(nildummy_globals.net_sess,
    405410                    &packet, IPC_GET_PACKET(*call));
    406411                if (rc != EOK)
     
    432437                        return rc;
    433438                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));
    438439        }
    439440       
Note: See TracChangeset for help on using the changeset viewer.