Ignore:
File:
1 edited

Legend:

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

    r6b82009 r9934f7d  
    5959#include <packet_remote.h>
    6060#include <nil_skel.h>
     61
     62// FIXME: remove this header
     63#include <kernel/ipc/ipc_methods.h>
     64
    6165#include "eth.h"
    6266
     
    167171INT_MAP_IMPLEMENT(eth_protos, eth_proto_t);
    168172
    169 int nil_device_state_msg_local(device_id_t device_id, sysarg_t state)
     173int nil_device_state_msg_local(int nil_phone, device_id_t device_id, int state)
    170174{
    171175        int index;
     
    176180            index--) {
    177181                proto = eth_protos_get_index(&eth_globals.protos, index);
    178                 if ((proto) && (proto->sess)) {
    179                         il_device_state_msg(proto->sess, device_id, state,
     182                if (proto && proto->phone) {
     183                        il_device_state_msg(proto->phone, device_id, state,
    180184                            proto->service);
    181185                }
     
    186190}
    187191
    188 int nil_initialize(async_sess_t *sess)
     192int nil_initialize(int net_phone)
    189193{
    190194        int rc;
     
    195199        fibril_rwlock_write_lock(&eth_globals.devices_lock);
    196200        fibril_rwlock_write_lock(&eth_globals.protos_lock);
    197         eth_globals.net_sess = sess;
     201        eth_globals.net_phone = net_phone;
    198202
    199203        eth_globals.broadcast_addr =
     
    222226}
    223227
    224 /** Process IPC messages from the registered device driver modules in an
     228/** Processes IPC messages from the registered device driver modules in an
    225229 * infinite loop.
    226230 *
    227  * @param[in]     iid   Message identifier.
    228  * @param[in,out] icall Message parameters.
    229  * @param[in]     arg   Local argument.
    230  *
     231 * @param[in] iid       The message identifier.
     232 * @param[in,out] icall The message parameters.
     233 * @param[in] arg       Local argument.
    231234 */
    232235static void eth_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     
    238241                switch (IPC_GET_IMETHOD(*icall)) {
    239242                case NET_NIL_DEVICE_STATE:
    240                         nil_device_state_msg_local(IPC_GET_DEVICE(*icall),
     243                        nil_device_state_msg_local(0, IPC_GET_DEVICE(*icall),
    241244                            IPC_GET_STATE(*icall));
    242245                        async_answer_0(iid, EOK);
    243246                        break;
    244247                case NET_NIL_RECEIVED:
    245                         rc = packet_translate_remote(eth_globals.net_sess,
     248                        rc = packet_translate_remote(eth_globals.net_phone,
    246249                            &packet, IPC_GET_PACKET(*icall));
    247250                        if (rc == EOK)
    248                                 rc = nil_received_msg_local(IPC_GET_DEVICE(*icall),
    249                                     packet, 0);
     251                                rc = nil_received_msg_local(0,
     252                                    IPC_GET_DEVICE(*icall), packet, 0);
    250253                       
    251254                        async_answer_0(iid, (sysarg_t) rc);
     
    323326                        proto = eth_protos_get_index(&eth_globals.protos,
    324327                            index);
    325                         if (proto->sess) {
    326                                 il_mtu_changed_msg(proto->sess,
     328                        if (proto->phone) {
     329                                il_mtu_changed_msg(proto->phone,
    327330                                    device->device_id, device->mtu,
    328331                                    proto->service);
     
    348351
    349352        configuration = &names[0];
    350         rc = net_get_device_conf_req(eth_globals.net_sess, device->device_id,
     353        rc = net_get_device_conf_req(eth_globals.net_phone, device->device_id,
    351354            &configuration, count, &data);
    352355        if (rc != EOK) {
     
    377380       
    378381        /* Bind the device driver */
    379         device->sess = netif_bind_service(device->service, device->device_id,
     382        device->phone = netif_bind_service(device->service, device->device_id,
    380383            SERVICE_ETHERNET, eth_receiver);
    381         if (device->sess == NULL) {
     384        if (device->phone < 0) {
    382385                fibril_rwlock_write_unlock(&eth_globals.devices_lock);
    383386                free(device);
    384                 return ENOENT;
     387                return device->phone;
    385388        }
    386389       
    387390        /* Get hardware address */
    388         rc = netif_get_addr_req(device->sess, device->device_id, &device->addr,
     391        rc = netif_get_addr_req(device->phone, device->device_id, &device->addr,
    389392            &device->addr_data);
    390393        if (rc != EOK) {
     
    506509}
    507510
    508 int nil_received_msg_local(device_id_t device_id, packet_t *packet,
    509     services_t target)
     511int nil_received_msg_local(int nil_phone, device_id_t device_id,
     512    packet_t *packet, services_t target)
    510513{
    511514        eth_proto_t *proto;
     
    529532                proto = eth_process_packet(flags, packet);
    530533                if (proto) {
    531                         il_received_msg(proto->sess, device_id, packet,
     534                        il_received_msg(proto->phone, device_id, packet,
    532535                            proto->service);
    533536                } else {
    534537                        /* Drop invalid/unknown */
    535                         pq_release_remote(eth_globals.net_sess,
     538                        pq_release_remote(eth_globals.net_phone,
    536539                            packet_get_id(packet));
    537540                }
     
    612615}
    613616
    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)
     617/** Registers receiving module service.
     618 *
     619 * Passes received packets for this service.
     620 *
     621 * @param[in] service   The module service.
     622 * @param[in] phone     The service phone.
     623 * @return              EOK on success.
     624 * @return              ENOENT if the service is not known.
     625 * @return              ENOMEM if there is not enough memory left.
     626 */
     627static int eth_register_message(services_t service, int phone)
    627628{
    628629        eth_proto_t *proto;
     
    637638        proto = eth_protos_find(&eth_globals.protos, protocol);
    638639        if (proto) {
    639                 proto->sess = sess;
     640                proto->phone = phone;
    640641                fibril_rwlock_write_unlock(&eth_globals.protos_lock);
    641642                return EOK;
     
    649650                proto->service = service;
    650651                proto->protocol = protocol;
    651                 proto->sess = sess;
     652                proto->phone = phone;
    652653
    653654                index = eth_protos_add(&eth_globals.protos, protocol, proto);
     
    659660        }
    660661       
    661         printf("%s: Protocol registered (protocol: %d, service: %d)\n",
    662             NAME, proto->protocol, proto->service);
     662        printf("%s: Protocol registered (protocol: %d, service: %d, phone: "
     663            "%d)\n", NAME, proto->protocol, proto->service, proto->phone);
    663664       
    664665        fibril_rwlock_write_unlock(&eth_globals.protos_lock);
     
    798799        ethertype = htons(protocol_map(SERVICE_ETHERNET, sender));
    799800        if (!ethertype) {
    800                 pq_release_remote(eth_globals.net_sess, packet_get_id(packet));
     801                pq_release_remote(eth_globals.net_phone, packet_get_id(packet));
    801802                return EINVAL;
    802803        }
     
    819820                        if (next == packet)
    820821                                packet = tmp;
    821                         pq_release_remote(eth_globals.net_sess,
     822                        pq_release_remote(eth_globals.net_phone,
    822823                            packet_get_id(next));
    823824                        next = tmp;
     
    829830        /* Send packet queue */
    830831        if (packet) {
    831                 netif_send_msg(device->sess, device_id, packet,
     832                netif_send_msg(device->phone, device_id, packet,
    832833                    SERVICE_ETHERNET);
    833834        }
     
    853854                return EOK;
    854855       
    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        
    860856        switch (IPC_GET_IMETHOD(*call)) {
    861857        case NET_NIL_DEVICE:
     
    863859                    IPC_GET_SERVICE(*call), IPC_GET_MTU(*call));
    864860        case NET_NIL_SEND:
    865                 rc = packet_translate_remote(eth_globals.net_sess, &packet,
     861                rc = packet_translate_remote(eth_globals.net_phone, &packet,
    866862                    IPC_GET_PACKET(*call));
    867863                if (rc != EOK)
     
    892888                        return EOK;
    893889                return measured_strings_reply(address, 1);
     890        case IPC_M_CONNECT_TO_ME:
     891                return eth_register_message(NIL_GET_PROTO(*call),
     892                    IPC_GET_PHONE(*call));
    894893        }
    895894       
Note: See TracChangeset for help on using the changeset viewer.