Ignore:
Timestamp:
2011-02-03T05:11:01Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ba38f72c
Parents:
22027b6e (diff), 86d7bfa (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 mainline changes.

File:
1 edited

Legend:

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

    r22027b6e r8b5690f  
    4141#include <stdio.h>
    4242#include <str.h>
    43 #include <ipc/ipc.h>
     43#include <ipc/nil.h>
    4444#include <ipc/net.h>
    4545#include <ipc/services.h>
     
    4747#include <net/modules.h>
    4848#include <net/device.h>
    49 #include <netif_interface.h>
    50 #include <nil_interface.h>
    51 #include <il_interface.h>
     49#include <il_remote.h>
    5250#include <adt/measured_strings.h>
    5351#include <net/packet.h>
    5452#include <packet_remote.h>
    55 #include <nil_local.h>
     53#include <netif_remote.h>
     54#include <nil_skel.h>
    5655
    5756#include "nildummy.h"
     
    8180int nil_initialize(int net_phone)
    8281{
    83         int rc;
    84        
    8582        fibril_rwlock_initialize(&nildummy_globals.devices_lock);
    8683        fibril_rwlock_initialize(&nildummy_globals.protos_lock);
     
    9087        nildummy_globals.net_phone = net_phone;
    9188        nildummy_globals.proto.phone = 0;
    92         rc = nildummy_devices_initialize(&nildummy_globals.devices);
     89        int rc = nildummy_devices_initialize(&nildummy_globals.devices);
    9390       
    9491        fibril_rwlock_write_unlock(&nildummy_globals.protos_lock);
     
    9895}
    9996
    100 /** Process IPC messages from the registered device driver modules in an
    101  * infinite loop.
    102  *
    103  * @param[in] iid       The message identifier.
    104  * @param[in,out]       icall The message parameters.
     97/** Process IPC messages from the registered device driver modules
     98 *
     99 * @param[in]     iid   Message identifier.
     100 * @param[in,out] icall Message parameters.
     101 *
    105102 */
    106103static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall)
     
    108105        packet_t *packet;
    109106        int rc;
    110 
     107       
    111108        while (true) {
    112109                switch (IPC_GET_IMETHOD(*icall)) {
    113110                case NET_NIL_DEVICE_STATE:
    114111                        rc = nil_device_state_msg_local(0,
    115                             IPC_GET_DEVICE(icall), IPC_GET_STATE(icall));
    116                         ipc_answer_0(iid, (sysarg_t) rc);
     112                            IPC_GET_DEVICE(*icall), IPC_GET_STATE(*icall));
     113                        async_answer_0(iid, (sysarg_t) rc);
    117114                        break;
    118115               
    119116                case NET_NIL_RECEIVED:
    120117                        rc = packet_translate_remote(nildummy_globals.net_phone,
    121                             &packet, IPC_GET_PACKET(icall));
    122                         if (rc == EOK) {
     118                            &packet, IPC_GET_PACKET(*icall));
     119                        if (rc == EOK)
    123120                                rc = nil_received_msg_local(0,
    124                                     IPC_GET_DEVICE(icall), packet, 0);
    125                         }
    126                         ipc_answer_0(iid, (sysarg_t) rc);
     121                                    IPC_GET_DEVICE(*icall), packet, 0);
     122                       
     123                        async_answer_0(iid, (sysarg_t) rc);
    127124                        break;
    128125               
    129126                default:
    130                         ipc_answer_0(iid, (sysarg_t) ENOTSUP);
     127                        async_answer_0(iid, (sysarg_t) ENOTSUP);
    131128                }
    132129               
     
    139136 * Determine the device local hardware address.
    140137 *
    141  * @param[in] device_id The new device identifier.
    142  * @param[in] service   The device driver service.
    143  * @param[in] mtu       The device maximum transmission unit.
    144  * @return              EOK on success.
    145  * @return              EEXIST if the device with the different service exists.
    146  * @return              ENOMEM if there is not enough memory left.
    147  * @return              Other error codes as defined for the
    148  *                      netif_bind_service() function.
    149  * @return              Other error codes as defined for the
    150  *                      netif_get_addr_req() function.
     138 * @param[in] device_id New device identifier.
     139 * @param[in] service   Device driver service.
     140 * @param[in] mtu       Device maximum transmission unit.
     141 *
     142 * @return EOK on success.
     143 * @return EEXIST if the device with the different service exists.
     144 * @return ENOMEM if there is not enough memory left.
     145 * @return Other error codes as defined for the
     146 *         netif_bind_service() function.
     147 * @return Other error codes as defined for the
     148 *         netif_get_addr_req() function.
     149 *
    151150 */
    152151static int nildummy_device_message(device_id_t device_id, services_t service,
    153152    size_t mtu)
    154153{
    155         nildummy_device_t *device;
    156         int index;
    157         int rc;
    158 
    159154        fibril_rwlock_write_lock(&nildummy_globals.devices_lock);
    160 
     155       
    161156        /* An existing device? */
    162         device = nildummy_devices_find(&nildummy_globals.devices, device_id);
     157        nildummy_device_t *device =
     158            nildummy_devices_find(&nildummy_globals.devices, device_id);
    163159        if (device) {
    164160                if (device->service != service) {
     
    213209       
    214210        /* Get hardware address */
    215         rc = netif_get_addr_req(device->phone, device->device_id, &device->addr,
    216             &device->addr_data);
     211        int rc = netif_get_addr_req(device->phone, device->device_id,
     212            &device->addr, &device->addr_data);
    217213        if (rc != EOK) {
    218214                fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
     
    222218       
    223219        /* Add to the cache */
    224         index = nildummy_devices_add(&nildummy_globals.devices,
     220        int index = nildummy_devices_add(&nildummy_globals.devices,
    225221            device->device_id, device);
    226222        if (index < 0) {
     
    240236/** Return the device hardware address.
    241237 *
    242  * @param[in] device_id The device identifier.
    243  * @param[out] address  The device hardware address.
    244  * @return               EOK on success.
    245  * @return              EBADMEM if the address parameter is NULL.
    246  * @return              ENOENT if there no such device.
     238 * @param[in]  device_id Device identifier.
     239 * @param[out] address   Device hardware address.
     240 *
     241 * @return EOK on success.
     242 * @return EBADMEM if the address parameter is NULL.
     243 * @return ENOENT if there no such device.
    247244 *
    248245 */
     
    250247    measured_string_t **address)
    251248{
    252         nildummy_device_t *device;
    253 
    254249        if (!address)
    255250                return EBADMEM;
    256251       
    257252        fibril_rwlock_read_lock(&nildummy_globals.devices_lock);
    258         device = nildummy_devices_find(&nildummy_globals.devices, device_id);
     253       
     254        nildummy_device_t *device =
     255            nildummy_devices_find(&nildummy_globals.devices, device_id);
    259256        if (!device) {
    260257                fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
    261258                return ENOENT;
    262259        }
     260       
    263261        *address = device->addr;
     262       
    264263        fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
    265264       
     
    269268/** Return the device packet dimensions for sending.
    270269 *
    271  * @param[in] device_id The device identifier.
    272  * @param[out] addr_len The minimum reserved address length.
    273  * @param[out] prefix   The minimum reserved prefix size.
    274  * @param[out] content  The maximum content size.
    275  * @param[out] suffix   The minimum reserved suffix size.
    276  * @return              EOK on success.
    277  * @return              EBADMEM if either one of the parameters is NULL.
    278  * @return              ENOENT if there is no such device.
     270 * @param[in]  device_id Device identifier.
     271 * @param[out] addr_len  Minimum reserved address length.
     272 * @param[out] prefix    Minimum reserved prefix size.
     273 * @param[out] content   Maximum content size.
     274 * @param[out] suffix    Minimum reserved suffix size.
     275 *
     276 * @return EOK on success.
     277 * @return EBADMEM if either one of the parameters is NULL.
     278 * @return ENOENT if there is no such device.
    279279 *
    280280 */
     
    282282    size_t *prefix, size_t *content, size_t *suffix)
    283283{
    284         nildummy_device_t *device;
    285 
    286         if (!addr_len || !prefix || !content || !suffix)
     284        if ((!addr_len) || (!prefix) || (!content) || (!suffix))
    287285                return EBADMEM;
    288286       
    289287        fibril_rwlock_read_lock(&nildummy_globals.devices_lock);
    290         device = nildummy_devices_find(&nildummy_globals.devices, device_id);
     288       
     289        nildummy_device_t *device =
     290            nildummy_devices_find(&nildummy_globals.devices, device_id);
    291291        if (!device) {
    292292                fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
    293293                return ENOENT;
    294294        }
    295 
     295       
    296296        *content = device->mtu;
     297       
    297298        fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
    298299       
     
    306307    packet_t *packet, services_t target)
    307308{
    308         packet_t *next;
    309 
    310309        fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
     310       
    311311        if (nildummy_globals.proto.phone) {
    312312                do {
    313                         next = pq_detach(packet);
     313                        packet_t *next = pq_detach(packet);
    314314                        il_received_msg(nildummy_globals.proto.phone, device_id,
    315315                            packet, nildummy_globals.proto.service);
    316316                        packet = next;
    317                 } while(packet);
    318         }
     317                } while (packet);
     318        }
     319       
    319320        fibril_rwlock_read_unlock(&nildummy_globals.protos_lock);
    320321       
     
    326327 * Pass received packets for this service.
    327328 *
    328  * @param[in] service   The module service.
    329  * @param[in] phone     The service phone.
    330  * @return              EOK on success.
    331  * @return              ENOENT if the service is not known.
    332  * @return              ENOMEM if there is not enough memory left.
     329 * @param[in] service Module service.
     330 * @param[in] phone   Service phone.
     331 *
     332 * @return EOK on success.
     333 * @return ENOENT if the service is not known.
     334 * @return ENOMEM if there is not enough memory left.
     335 *
    333336 */
    334337static int nildummy_register_message(services_t service, int phone)
     
    347350/** Send the packet queue.
    348351 *
    349  * @param[in] device_id The device identifier.
    350  * @param[in] packet    The packet queue.
    351  * @param[in] sender    The sending module service.
    352  * @return              EOK on success.
    353  * @return              ENOENT if there no such device.
    354  * @return              EINVAL if the service parameter is not known.
     352 * @param[in] device_id Device identifier.
     353 * @param[in] packet    Packet queue.
     354 * @param[in] sender    Sending module service.
     355 *
     356 * @return EOK on success.
     357 * @return ENOENT if there no such device.
     358 * @return EINVAL if the service parameter is not known.
     359 *
    355360 */
    356361static int nildummy_send_message(device_id_t device_id, packet_t *packet,
    357362    services_t sender)
    358363{
    359         nildummy_device_t *device;
    360 
    361364        fibril_rwlock_read_lock(&nildummy_globals.devices_lock);
    362         device = nildummy_devices_find(&nildummy_globals.devices, device_id);
     365       
     366        nildummy_device_t *device =
     367            nildummy_devices_find(&nildummy_globals.devices, device_id);
    363368        if (!device) {
    364369                fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
    365370                return ENOENT;
    366371        }
    367 
     372       
    368373        /* Send packet queue */
    369374        if (packet)
    370375                netif_send_msg(device->phone, device_id, packet,
    371376                    SERVICE_NILDUMMY);
     377       
    372378        fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
    373         return EOK;
    374 }
    375 
    376 int nil_message_standalone(const char *name, ipc_callid_t callid,
    377     ipc_call_t *call, ipc_call_t *answer, int *answer_count)
     379       
     380        return EOK;
     381}
     382
     383int nil_module_message(ipc_callid_t callid, ipc_call_t *call,
     384    ipc_call_t *answer, size_t *answer_count)
    378385{
    379386        measured_string_t *address;
     
    391398       
    392399        case NET_NIL_DEVICE:
    393                 return nildummy_device_message(IPC_GET_DEVICE(call),
    394                     IPC_GET_SERVICE(call), IPC_GET_MTU(call));
     400                return nildummy_device_message(IPC_GET_DEVICE(*call),
     401                    IPC_GET_SERVICE(*call), IPC_GET_MTU(*call));
    395402       
    396403        case NET_NIL_SEND:
    397404                rc = packet_translate_remote(nildummy_globals.net_phone,
    398                     &packet, IPC_GET_PACKET(call));
     405                    &packet, IPC_GET_PACKET(*call));
    399406                if (rc != EOK)
    400407                        return rc;
    401                 return nildummy_send_message(IPC_GET_DEVICE(call), packet,
    402                     IPC_GET_SERVICE(call));
     408                return nildummy_send_message(IPC_GET_DEVICE(*call), packet,
     409                    IPC_GET_SERVICE(*call));
    403410       
    404411        case NET_NIL_PACKET_SPACE:
    405                 rc = nildummy_packet_space_message(IPC_GET_DEVICE(call),
     412                rc = nildummy_packet_space_message(IPC_GET_DEVICE(*call),
    406413                    &addrlen, &prefix, &content, &suffix);
    407414                if (rc != EOK)
    408415                        return rc;
    409                 IPC_SET_ADDR(answer, addrlen);
    410                 IPC_SET_PREFIX(answer, prefix);
    411                 IPC_SET_CONTENT(answer, content);
    412                 IPC_SET_SUFFIX(answer, suffix);
     416                IPC_SET_ADDR(*answer, addrlen);
     417                IPC_SET_PREFIX(*answer, prefix);
     418                IPC_SET_CONTENT(*answer, content);
     419                IPC_SET_SUFFIX(*answer, suffix);
    413420                *answer_count = 4;
    414421                return EOK;
    415422       
    416423        case NET_NIL_ADDR:
    417                 rc = nildummy_addr_message(IPC_GET_DEVICE(call), &address);
     424                rc = nildummy_addr_message(IPC_GET_DEVICE(*call), &address);
    418425                if (rc != EOK)
    419426                        return rc;
     
    421428       
    422429        case NET_NIL_BROADCAST_ADDR:
    423                 rc = nildummy_addr_message(IPC_GET_DEVICE(call), &address);
     430                rc = nildummy_addr_message(IPC_GET_DEVICE(*call), &address);
    424431                if (rc != EOK)
    425432                        return rc;
     
    427434       
    428435        case IPC_M_CONNECT_TO_ME:
    429                 return nildummy_register_message(NIL_GET_PROTO(call),
    430                     IPC_GET_PHONE(call));
     436                return nildummy_register_message(NIL_GET_PROTO(*call),
     437                    IPC_GET_PHONE(*call));
    431438        }
    432439       
     
    434441}
    435442
    436 /** Default thread for new connections.
    437  *
    438  * @param[in] iid       The initial message identifier.
    439  * @param[in] icall     The initial message call structure.
    440  */
    441 static void nil_client_connection(ipc_callid_t iid, ipc_call_t *icall)
    442 {
    443         /*
    444          * Accept the connection
    445          *  - Answer the first IPC_M_CONNECT_ME_TO call.
    446          */
    447         ipc_answer_0(iid, EOK);
    448        
    449         while (true) {
    450                 ipc_call_t answer;
    451                 int answer_count;
    452                
    453                 /* Clear the answer structure */
    454                 refresh_answer(&answer, &answer_count);
    455                
    456                 /* Fetch the next message */
    457                 ipc_call_t call;
    458                 ipc_callid_t callid = async_get_call(&call);
    459                
    460                 /* Process the message */
    461                 int res = nil_module_message_standalone(NAME, callid, &call,
    462                     &answer, &answer_count);
    463                
    464                 /*
    465                  * End if told to either by the message or the processing
    466                  * result.
    467                  */
    468                 if ((IPC_GET_IMETHOD(call) == IPC_M_PHONE_HUNGUP) ||
    469                     (res == EHANGUP))
    470                         return;
    471                
    472                 /* Answer the message */
    473                 answer_call(callid, res, &answer, answer_count);
    474         }
    475 }
    476 
    477443int main(int argc, char *argv[])
    478444{
    479         int rc;
    480        
    481445        /* Start the module */
    482         rc = nil_module_start_standalone(nil_client_connection);
    483         return rc;
     446        return nil_module_start(SERVICE_NILDUMMY);
    484447}
    485448
Note: See TracChangeset for help on using the changeset viewer.