Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/netif/netif_skel.c

    ree2fa30a r9934f7d  
    5454#include <nil_remote.h>
    5555
     56// FIXME: remove this header
     57#include <kernel/ipc/ipc_methods.h>
     58
    5659DEVICE_MAP_IMPLEMENT(netif_device_map, netif_device_t);
    5760
     
    6164/** Probe the existence of the device.
    6265 *
     66 * @param[in] netif_phone Network interface phone.
    6367 * @param[in] device_id   Device identifier.
    6468 * @param[in] irq         Device interrupt number.
     
    7074 *
    7175 */
    72 static int netif_probe_req_local(device_id_t device_id, int irq, void *io)
     76static int netif_probe_req_local(int netif_phone, device_id_t device_id,
     77    int irq, void *io)
    7378{
    7479        fibril_rwlock_write_lock(&netif_globals.lock);
     
    8186/** Send the packet queue.
    8287 *
     88 * @param[in] netif_phone Network interface phone.
    8389 * @param[in] device_id   Device identifier.
    8490 * @param[in] packet      Packet queue.
     
    9096 *
    9197 */
    92 static int netif_send_msg_local(device_id_t device_id, packet_t *packet,
    93     services_t sender)
     98static int netif_send_msg_local(int netif_phone, device_id_t device_id,
     99    packet_t *packet, services_t sender)
    94100{
    95101        fibril_rwlock_write_lock(&netif_globals.lock);
     
    102108/** Start the device.
    103109 *
     110 * @param[in] netif_phone Network interface phone.
    104111 * @param[in] device_id   Device identifier.
    105112 *
     
    111118 *
    112119 */
    113 static int netif_start_req_local(device_id_t device_id)
     120static int netif_start_req_local(int netif_phone, device_id_t device_id)
    114121{
    115122        fibril_rwlock_write_lock(&netif_globals.lock);
     
    124131        int result = netif_start_message(device);
    125132        if (result > NETIF_NULL) {
    126                 nil_device_state_msg(netif_globals.nil_sess, device_id, result);
     133                int phone = device->nil_phone;
     134                nil_device_state_msg(phone, device_id, result);
    127135                fibril_rwlock_write_unlock(&netif_globals.lock);
    128136                return EOK;
     
    136144/** Stop the device.
    137145 *
     146 * @param[in] netif_phone Network interface phone.
    138147 * @param[in] device_id   Device identifier.
    139148 *
     
    145154 *
    146155 */
    147 static int netif_stop_req_local(device_id_t device_id)
     156static int netif_stop_req_local(int netif_phone, device_id_t device_id)
    148157{
    149158        fibril_rwlock_write_lock(&netif_globals.lock);
     
    158167        int result = netif_stop_message(device);
    159168        if (result > NETIF_NULL) {
    160                 nil_device_state_msg(netif_globals.nil_sess, device_id, result);
     169                int phone = device->nil_phone;
     170                nil_device_state_msg(phone, device_id, result);
    161171                fibril_rwlock_write_unlock(&netif_globals.lock);
    162172                return EOK;
     
    212222void netif_pq_release(packet_id_t packet_id)
    213223{
    214         pq_release_remote(netif_globals.sess, packet_id);
     224        pq_release_remote(netif_globals.net_phone, packet_id);
    215225}
    216226
     
    225235packet_t *netif_packet_get_1(size_t content)
    226236{
    227         return packet_get_1_remote(netif_globals.sess, content);
     237        return packet_get_1_remote(netif_globals.net_phone, content);
    228238}
    229239
    230240/** Register the device notification receiver,
    231241 *
    232  * Register a network interface layer module as the device
     242 * Register a  network interface layer module as the device
    233243 * notification receiver.
    234244 *
    235  * @param[in] sess      Session to the network interface layer module.
    236  *
    237  * @return EOK on success.
     245 * @param[in] device_id Device identifier.
     246 * @param[in] phone     Network interface layer module phone.
     247 *
     248 * @return EOK on success.
     249 * @return ENOENT if there is no such device.
    238250 * @return ELIMIT if there is another module registered.
    239251 *
    240252 */
    241 static int register_message(async_sess_t *sess)
    242 {
    243         fibril_rwlock_write_lock(&netif_globals.lock);
    244         if (netif_globals.nil_sess != NULL) {
    245                 fibril_rwlock_write_unlock(&netif_globals.lock);
     253static int register_message(device_id_t device_id, int phone)
     254{
     255        netif_device_t *device;
     256        int rc = find_device(device_id, &device);
     257        if (rc != EOK)
     258                return rc;
     259       
     260        if (device->nil_phone >= 0)
    246261                return ELIMIT;
    247         }
    248        
    249         netif_globals.nil_sess = sess;
    250        
    251         fibril_rwlock_write_unlock(&netif_globals.lock);
     262       
     263        device->nil_phone = phone;
    252264        return EOK;
    253265}
     
    282294                return EOK;
    283295       
    284         async_sess_t *callback =
    285             async_callback_receive_start(EXCHANGE_SERIALIZE, call);
    286         if (callback)
    287                 return register_message(callback);
    288        
    289296        switch (IPC_GET_IMETHOD(*call)) {
    290297        case NET_NETIF_PROBE:
    291                 return netif_probe_req_local(IPC_GET_DEVICE(*call),
     298                return netif_probe_req_local(0, IPC_GET_DEVICE(*call),
    292299                    NETIF_GET_IRQ(*call), NETIF_GET_IO(*call));
    293300       
     301        case IPC_M_CONNECT_TO_ME:
     302                fibril_rwlock_write_lock(&netif_globals.lock);
     303               
     304                rc = register_message(IPC_GET_DEVICE(*call), IPC_GET_PHONE(*call));
     305               
     306                fibril_rwlock_write_unlock(&netif_globals.lock);
     307                return rc;
     308       
    294309        case NET_NETIF_SEND:
    295                 rc = packet_translate_remote(netif_globals.sess, &packet,
     310                rc = packet_translate_remote(netif_globals.net_phone, &packet,
    296311                    IPC_GET_PACKET(*call));
    297312                if (rc != EOK)
    298313                        return rc;
    299314               
    300                 return netif_send_msg_local(IPC_GET_DEVICE(*call), packet,
     315                return netif_send_msg_local(0, IPC_GET_DEVICE(*call), packet,
    301316                    IPC_GET_SENDER(*call));
    302317       
    303318        case NET_NETIF_START:
    304                 return netif_start_req_local(IPC_GET_DEVICE(*call));
     319                return netif_start_req_local(0, IPC_GET_DEVICE(*call));
    305320       
    306321        case NET_NETIF_STATS:
     
    328343       
    329344        case NET_NETIF_STOP:
    330                 return netif_stop_req_local(IPC_GET_DEVICE(*call));
     345                return netif_stop_req_local(0, IPC_GET_DEVICE(*call));
    331346       
    332347        case NET_NETIF_GET_ADDR:
     
    397412        async_set_client_connection(netif_client_connection);
    398413       
    399         netif_globals.sess = connect_to_service(SERVICE_NETWORKING);
    400         netif_globals.nil_sess = NULL;
     414        netif_globals.net_phone = connect_to_service(SERVICE_NETWORKING);
    401415        netif_device_map_initialize(&netif_globals.device_map);
    402416       
Note: See TracChangeset for help on using the changeset viewer.