Ignore:
File:
1 edited

Legend:

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

    r797b704 r774e6d1a  
    4242#include <str.h>
    4343#include <ipc/ipc.h>
    44 #include <ipc/nil.h>
    4544#include <ipc/net.h>
    4645#include <ipc/services.h>
     
    4847#include <net/modules.h>
    4948#include <net/device.h>
    50 #include <il_remote.h>
     49#include <nil_interface.h>
     50#include <il_interface.h>
    5151#include <adt/measured_strings.h>
    5252#include <net/packet.h>
    5353#include <packet_remote.h>
    5454#include <netif_remote.h>
    55 #include <nil_skel.h>
     55#include <nil_local.h>
    5656
    5757#include "nildummy.h"
     
    8181int nil_initialize(int net_phone)
    8282{
     83        int rc;
     84       
    8385        fibril_rwlock_initialize(&nildummy_globals.devices_lock);
    8486        fibril_rwlock_initialize(&nildummy_globals.protos_lock);
     
    8890        nildummy_globals.net_phone = net_phone;
    8991        nildummy_globals.proto.phone = 0;
    90         int rc = nildummy_devices_initialize(&nildummy_globals.devices);
     92        rc = nildummy_devices_initialize(&nildummy_globals.devices);
    9193       
    9294        fibril_rwlock_write_unlock(&nildummy_globals.protos_lock);
     
    9698}
    9799
    98 /** Process IPC messages from the registered device driver modules
    99  *
    100  * @param[in]     iid   Message identifier.
    101  * @param[in,out] icall Message parameters.
    102  *
     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.
    103105 */
    104106static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall)
     
    106108        packet_t *packet;
    107109        int rc;
    108        
     110
    109111        while (true) {
    110112                switch (IPC_GET_IMETHOD(*icall)) {
     
    118120                        rc = packet_translate_remote(nildummy_globals.net_phone,
    119121                            &packet, IPC_GET_PACKET(*icall));
    120                         if (rc == EOK)
     122                        if (rc == EOK) {
    121123                                rc = nil_received_msg_local(0,
    122124                                    IPC_GET_DEVICE(*icall), packet, 0);
    123                        
     125                        }
    124126                        ipc_answer_0(iid, (sysarg_t) rc);
    125127                        break;
     
    137139 * Determine the device local hardware address.
    138140 *
    139  * @param[in] device_id New device identifier.
    140  * @param[in] service   Device driver service.
    141  * @param[in] mtu       Device maximum transmission unit.
    142  *
    143  * @return EOK on success.
    144  * @return EEXIST if the device with the different service exists.
    145  * @return ENOMEM if there is not enough memory left.
    146  * @return Other error codes as defined for the
    147  *         netif_bind_service() function.
    148  * @return Other error codes as defined for the
    149  *         netif_get_addr_req() function.
    150  *
     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.
    151151 */
    152152static int nildummy_device_message(device_id_t device_id, services_t service,
    153153    size_t mtu)
    154154{
     155        nildummy_device_t *device;
     156        int index;
     157        int rc;
     158
    155159        fibril_rwlock_write_lock(&nildummy_globals.devices_lock);
    156        
     160
    157161        /* An existing device? */
    158         nildummy_device_t *device =
    159             nildummy_devices_find(&nildummy_globals.devices, device_id);
     162        device = nildummy_devices_find(&nildummy_globals.devices, device_id);
    160163        if (device) {
    161164                if (device->service != service) {
     
    210213       
    211214        /* Get hardware address */
    212         int rc = netif_get_addr_req(device->phone, device->device_id,
    213             &device->addr, &device->addr_data);
     215        rc = netif_get_addr_req(device->phone, device->device_id, &device->addr,
     216            &device->addr_data);
    214217        if (rc != EOK) {
    215218                fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
     
    219222       
    220223        /* Add to the cache */
    221         int index = nildummy_devices_add(&nildummy_globals.devices,
     224        index = nildummy_devices_add(&nildummy_globals.devices,
    222225            device->device_id, device);
    223226        if (index < 0) {
     
    237240/** Return the device hardware address.
    238241 *
    239  * @param[in]  device_id Device identifier.
    240  * @param[out] address   Device hardware address.
    241  *
    242  * @return EOK on success.
    243  * @return EBADMEM if the address parameter is NULL.
    244  * @return ENOENT if there no such device.
     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.
    245247 *
    246248 */
     
    248250    measured_string_t **address)
    249251{
     252        nildummy_device_t *device;
     253
    250254        if (!address)
    251255                return EBADMEM;
    252256       
    253257        fibril_rwlock_read_lock(&nildummy_globals.devices_lock);
    254        
    255         nildummy_device_t *device =
    256             nildummy_devices_find(&nildummy_globals.devices, device_id);
     258        device = nildummy_devices_find(&nildummy_globals.devices, device_id);
    257259        if (!device) {
    258260                fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
    259261                return ENOENT;
    260262        }
    261        
    262263        *address = device->addr;
    263        
    264264        fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
    265265       
     
    269269/** Return the device packet dimensions for sending.
    270270 *
    271  * @param[in]  device_id Device identifier.
    272  * @param[out] addr_len  Minimum reserved address length.
    273  * @param[out] prefix    Minimum reserved prefix size.
    274  * @param[out] content   Maximum content size.
    275  * @param[out] suffix    Minimum reserved suffix size.
    276  *
    277  * @return EOK on success.
    278  * @return EBADMEM if either one of the parameters is NULL.
    279  * @return ENOENT if there is no such device.
     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.
    280279 *
    281280 */
     
    283282    size_t *prefix, size_t *content, size_t *suffix)
    284283{
    285         if ((!addr_len) || (!prefix) || (!content) || (!suffix))
     284        nildummy_device_t *device;
     285
     286        if (!addr_len || !prefix || !content || !suffix)
    286287                return EBADMEM;
    287288       
    288289        fibril_rwlock_read_lock(&nildummy_globals.devices_lock);
    289        
    290         nildummy_device_t *device =
    291             nildummy_devices_find(&nildummy_globals.devices, device_id);
     290        device = nildummy_devices_find(&nildummy_globals.devices, device_id);
    292291        if (!device) {
    293292                fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
    294293                return ENOENT;
    295294        }
    296        
     295
    297296        *content = device->mtu;
    298        
    299297        fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
    300298       
     
    308306    packet_t *packet, services_t target)
    309307{
     308        packet_t *next;
     309
    310310        fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
    311        
    312311        if (nildummy_globals.proto.phone) {
    313312                do {
    314                         packet_t *next = pq_detach(packet);
     313                        next = pq_detach(packet);
    315314                        il_received_msg(nildummy_globals.proto.phone, device_id,
    316315                            packet, nildummy_globals.proto.service);
    317316                        packet = next;
    318                 } while (packet);
    319         }
    320        
     317                } while(packet);
     318        }
    321319        fibril_rwlock_read_unlock(&nildummy_globals.protos_lock);
    322320       
     
    328326 * Pass received packets for this service.
    329327 *
    330  * @param[in] service Module service.
    331  * @param[in] phone   Service phone.
    332  *
    333  * @return EOK on success.
    334  * @return ENOENT if the service is not known.
    335  * @return ENOMEM if there is not enough memory left.
    336  *
     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.
    337333 */
    338334static int nildummy_register_message(services_t service, int phone)
     
    351347/** Send the packet queue.
    352348 *
    353  * @param[in] device_id Device identifier.
    354  * @param[in] packet    Packet queue.
    355  * @param[in] sender    Sending module service.
    356  *
    357  * @return EOK on success.
    358  * @return ENOENT if there no such device.
    359  * @return EINVAL if the service parameter is not known.
    360  *
     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.
    361355 */
    362356static int nildummy_send_message(device_id_t device_id, packet_t *packet,
    363357    services_t sender)
    364358{
     359        nildummy_device_t *device;
     360
    365361        fibril_rwlock_read_lock(&nildummy_globals.devices_lock);
    366        
    367         nildummy_device_t *device =
    368             nildummy_devices_find(&nildummy_globals.devices, device_id);
     362        device = nildummy_devices_find(&nildummy_globals.devices, device_id);
    369363        if (!device) {
    370364                fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
    371365                return ENOENT;
    372366        }
    373        
     367
    374368        /* Send packet queue */
    375369        if (packet)
    376370                netif_send_msg(device->phone, device_id, packet,
    377371                    SERVICE_NILDUMMY);
    378        
    379372        fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
    380        
    381         return EOK;
    382 }
    383 
    384 int nil_module_message(ipc_callid_t callid, ipc_call_t *call,
    385     ipc_call_t *answer, size_t *answer_count)
     373        return EOK;
     374}
     375
     376int nil_message_standalone(const char *name, ipc_callid_t callid,
     377    ipc_call_t *call, ipc_call_t *answer, size_t *answer_count)
    386378{
    387379        measured_string_t *address;
     
    442434}
    443435
     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 */
     441static 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                size_t count;
     452               
     453                /* Clear the answer structure */
     454                refresh_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, &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, count);
     474        }
     475}
     476
    444477int main(int argc, char *argv[])
    445478{
     479        int rc;
     480       
    446481        /* Start the module */
    447         return nil_module_start(SERVICE_NILDUMMY);
     482        rc = nil_module_start_standalone(nil_client_connection);
     483        return rc;
    448484}
    449485
Note: See TracChangeset for help on using the changeset viewer.