Ignore:
Timestamp:
2011-07-13T22:39:18Z (13 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e6910c8
Parents:
5974661 (diff), 8ecef91 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge libposix.

File:
1 edited

Legend:

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

    r5974661 re4f8c77  
    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 
    56 // FIXME: remove this header
    57 #include <kernel/ipc/ipc_methods.h>
    58 
    5954#include "nildummy.h"
    6055
     
    7065DEVICE_MAP_IMPLEMENT(nildummy_devices, nildummy_device_t);
    7166
    72 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)
    7368{
    7469        fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
    75         if (nildummy_globals.proto.phone)
    76                 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,
    7772                    state, nildummy_globals.proto.service);
    7873        fibril_rwlock_read_unlock(&nildummy_globals.protos_lock);
     
    8176}
    8277
    83 int nil_initialize(int net_phone)
     78int nil_initialize(async_sess_t *sess)
    8479{
    8580        fibril_rwlock_initialize(&nildummy_globals.devices_lock);
     
    8883        fibril_rwlock_write_lock(&nildummy_globals.protos_lock);
    8984       
    90         nildummy_globals.net_phone = net_phone;
    91         nildummy_globals.proto.phone = 0;
     85        nildummy_globals.net_sess = sess;
     86        nildummy_globals.proto.sess = NULL;
    9287        int rc = nildummy_devices_initialize(&nildummy_globals.devices);
    9388       
     
    10297 * @param[in]     iid   Message identifier.
    10398 * @param[in,out] icall Message parameters.
    104  *
    105  */
    106 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)
    107103{
    108104        packet_t *packet;
     
    112108                switch (IPC_GET_IMETHOD(*icall)) {
    113109                case NET_NIL_DEVICE_STATE:
    114                         rc = nil_device_state_msg_local(0,
    115                             IPC_GET_DEVICE(*icall), IPC_GET_STATE(*icall));
     110                        rc = nil_device_state_msg_local(IPC_GET_DEVICE(*icall),
     111                            IPC_GET_STATE(*icall));
    116112                        async_answer_0(iid, (sysarg_t) rc);
    117113                        break;
    118114               
    119115                case NET_NIL_RECEIVED:
    120                         rc = packet_translate_remote(nildummy_globals.net_phone,
     116                        rc = packet_translate_remote(nildummy_globals.net_sess,
    121117                            &packet, IPC_GET_PACKET(*icall));
    122118                        if (rc == EOK)
    123                                 rc = nil_received_msg_local(0,
    124                                     IPC_GET_DEVICE(*icall), packet, 0);
     119                                rc = nil_received_msg_local(IPC_GET_DEVICE(*icall),
     120                                    packet, 0);
    125121                       
    126122                        async_answer_0(iid, (sysarg_t) rc);
     
    180176                /* Notify the upper layer module */
    181177                fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
    182                 if (nildummy_globals.proto.phone) {
    183                         il_mtu_changed_msg(nildummy_globals.proto.phone,
     178                if (nildummy_globals.proto.sess) {
     179                        il_mtu_changed_msg(nildummy_globals.proto.sess,
    184180                            device->device_id, device->mtu,
    185181                            nildummy_globals.proto.service);
     
    203199
    204200        /* Bind the device driver */
    205         device->phone = netif_bind_service(device->service, device->device_id,
     201        device->sess = netif_bind_service(device->service, device->device_id,
    206202            SERVICE_ETHERNET, nildummy_receiver);
    207         if (device->phone < 0) {
     203        if (device->sess == NULL) {
    208204                fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
    209205                free(device);
    210                 return device->phone;
     206                return ENOENT;
    211207        }
    212208       
    213209        /* Get hardware address */
    214         int rc = netif_get_addr_req(device->phone, device->device_id,
     210        int rc = netif_get_addr_req(device->sess, device->device_id,
    215211            &device->addr, &device->addr_data);
    216212        if (rc != EOK) {
     
    307303}
    308304
    309 int nil_received_msg_local(int nil_phone, device_id_t device_id,
    310     packet_t *packet, services_t target)
     305int nil_received_msg_local(device_id_t device_id, packet_t *packet,
     306    services_t target)
    311307{
    312308        fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
    313309       
    314         if (nildummy_globals.proto.phone) {
     310        if (nildummy_globals.proto.sess) {
    315311                do {
    316312                        packet_t *next = pq_detach(packet);
    317                         il_received_msg(nildummy_globals.proto.phone, device_id,
     313                        il_received_msg(nildummy_globals.proto.sess, device_id,
    318314                            packet, nildummy_globals.proto.service);
    319315                        packet = next;
     
    331327 *
    332328 * @param[in] service Module service.
    333  * @param[in] phone   Service phone.
     329 * @param[in] sess    Service session.
    334330 *
    335331 * @return EOK on success.
     
    338334 *
    339335 */
    340 static int nildummy_register_message(services_t service, int phone)
     336static int nildummy_register_message(services_t service, async_sess_t *sess)
    341337{
    342338        fibril_rwlock_write_lock(&nildummy_globals.protos_lock);
    343339        nildummy_globals.proto.service = 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);
     340        nildummy_globals.proto.sess = sess;
     341       
     342        printf("%s: Protocol registered (service: %d)\n",
     343            NAME, nildummy_globals.proto.service);
    348344       
    349345        fibril_rwlock_write_unlock(&nildummy_globals.protos_lock);
     
    376372        /* Send packet queue */
    377373        if (packet)
    378                 netif_send_msg(device->phone, device_id, packet,
     374                netif_send_msg(device->sess, device_id, packet,
    379375                    SERVICE_NILDUMMY);
    380376       
     
    400396                return EOK;
    401397       
     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       
    402403        switch (IPC_GET_IMETHOD(*call)) {
    403404        case NET_NIL_DEVICE:
     
    406407       
    407408        case NET_NIL_SEND:
    408                 rc = packet_translate_remote(nildummy_globals.net_phone,
     409                rc = packet_translate_remote(nildummy_globals.net_sess,
    409410                    &packet, IPC_GET_PACKET(*call));
    410411                if (rc != EOK)
     
    436437                        return rc;
    437438                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));
    442439        }
    443440       
Note: See TracChangeset for help on using the changeset viewer.