Ignore:
Timestamp:
2011-01-14T14:23:33Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b65ca41d
Parents:
f40a1e2 (diff), 2f60e57d (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 from usb/development

File:
1 edited

Legend:

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

    rf40a1e2 r7a725b13  
    4242#include <str.h>
    4343#include <ipc/ipc.h>
     44#include <ipc/nil.h>
    4445#include <ipc/net.h>
    4546#include <ipc/services.h>
     
    4748#include <net/modules.h>
    4849#include <net/device.h>
    49 #include <nil_interface.h>
    50 #include <il_interface.h>
     50#include <il_remote.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_local.h>
     55#include <nil_skel.h>
    5656
    5757#include "nildummy.h"
     
    8181int nil_initialize(int net_phone)
    8282{
    83         int rc;
    84        
    8583        fibril_rwlock_initialize(&nildummy_globals.devices_lock);
    8684        fibril_rwlock_initialize(&nildummy_globals.protos_lock);
     
    9088        nildummy_globals.net_phone = net_phone;
    9189        nildummy_globals.proto.phone = 0;
    92         rc = nildummy_devices_initialize(&nildummy_globals.devices);
     90        int rc = nildummy_devices_initialize(&nildummy_globals.devices);
    9391       
    9492        fibril_rwlock_write_unlock(&nildummy_globals.protos_lock);
     
    9896}
    9997
    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.
     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 *
    105103 */
    106104static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall)
     
    108106        packet_t *packet;
    109107        int rc;
    110 
     108       
    111109        while (true) {
    112110                switch (IPC_GET_IMETHOD(*icall)) {
     
    120118                        rc = packet_translate_remote(nildummy_globals.net_phone,
    121119                            &packet, IPC_GET_PACKET(*icall));
    122                         if (rc == EOK) {
     120                        if (rc == EOK)
    123121                                rc = nil_received_msg_local(0,
    124122                                    IPC_GET_DEVICE(*icall), packet, 0);
    125                         }
     123                       
    126124                        ipc_answer_0(iid, (sysarg_t) rc);
    127125                        break;
     
    139137 * Determine the device local hardware address.
    140138 *
    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.
     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 *
    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 
    159155        fibril_rwlock_write_lock(&nildummy_globals.devices_lock);
    160 
     156       
    161157        /* An existing device? */
    162         device = nildummy_devices_find(&nildummy_globals.devices, device_id);
     158        nildummy_device_t *device =
     159            nildummy_devices_find(&nildummy_globals.devices, device_id);
    163160        if (device) {
    164161                if (device->service != service) {
     
    213210       
    214211        /* Get hardware address */
    215         rc = netif_get_addr_req(device->phone, device->device_id, &device->addr,
    216             &device->addr_data);
     212        int rc = netif_get_addr_req(device->phone, device->device_id,
     213            &device->addr, &device->addr_data);
    217214        if (rc != EOK) {
    218215                fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
     
    222219       
    223220        /* Add to the cache */
    224         index = nildummy_devices_add(&nildummy_globals.devices,
     221        int index = nildummy_devices_add(&nildummy_globals.devices,
    225222            device->device_id, device);
    226223        if (index < 0) {
     
    240237/** Return the device hardware address.
    241238 *
    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.
     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.
    247245 *
    248246 */
     
    250248    measured_string_t **address)
    251249{
    252         nildummy_device_t *device;
    253 
    254250        if (!address)
    255251                return EBADMEM;
    256252       
    257253        fibril_rwlock_read_lock(&nildummy_globals.devices_lock);
    258         device = nildummy_devices_find(&nildummy_globals.devices, device_id);
     254       
     255        nildummy_device_t *device =
     256            nildummy_devices_find(&nildummy_globals.devices, device_id);
    259257        if (!device) {
    260258                fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
    261259                return ENOENT;
    262260        }
     261       
    263262        *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 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.
     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.
    279280 *
    280281 */
     
    282283    size_t *prefix, size_t *content, size_t *suffix)
    283284{
    284         nildummy_device_t *device;
    285 
    286         if (!addr_len || !prefix || !content || !suffix)
     285        if ((!addr_len) || (!prefix) || (!content) || (!suffix))
    287286                return EBADMEM;
    288287       
    289288        fibril_rwlock_read_lock(&nildummy_globals.devices_lock);
    290         device = nildummy_devices_find(&nildummy_globals.devices, device_id);
     289       
     290        nildummy_device_t *device =
     291            nildummy_devices_find(&nildummy_globals.devices, device_id);
    291292        if (!device) {
    292293                fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
    293294                return ENOENT;
    294295        }
    295 
     296       
    296297        *content = device->mtu;
     298       
    297299        fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
    298300       
     
    306308    packet_t *packet, services_t target)
    307309{
    308         packet_t *next;
    309 
    310310        fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
     311       
    311312        if (nildummy_globals.proto.phone) {
    312313                do {
    313                         next = pq_detach(packet);
     314                        packet_t *next = pq_detach(packet);
    314315                        il_received_msg(nildummy_globals.proto.phone, device_id,
    315316                            packet, nildummy_globals.proto.service);
    316317                        packet = next;
    317                 } while(packet);
    318         }
     318                } while (packet);
     319        }
     320       
    319321        fibril_rwlock_read_unlock(&nildummy_globals.protos_lock);
    320322       
     
    326328 * Pass received packets for this service.
    327329 *
    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.
     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 *
    333337 */
    334338static int nildummy_register_message(services_t service, int phone)
     
    347351/** Send the packet queue.
    348352 *
    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.
     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 *
    355361 */
    356362static int nildummy_send_message(device_id_t device_id, packet_t *packet,
    357363    services_t sender)
    358364{
    359         nildummy_device_t *device;
    360 
    361365        fibril_rwlock_read_lock(&nildummy_globals.devices_lock);
    362         device = nildummy_devices_find(&nildummy_globals.devices, device_id);
     366       
     367        nildummy_device_t *device =
     368            nildummy_devices_find(&nildummy_globals.devices, device_id);
    363369        if (!device) {
    364370                fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
    365371                return ENOENT;
    366372        }
    367 
     373       
    368374        /* Send packet queue */
    369375        if (packet)
    370376                netif_send_msg(device->phone, device_id, packet,
    371377                    SERVICE_NILDUMMY);
     378       
    372379        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, size_t *answer_count)
     380       
     381        return EOK;
     382}
     383
     384int nil_module_message(ipc_callid_t callid, ipc_call_t *call,
     385    ipc_call_t *answer, size_t *answer_count)
    378386{
    379387        measured_string_t *address;
     
    434442}
    435443
    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                 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 
    477444int main(int argc, char *argv[])
    478445{
    479         int rc;
    480        
    481446        /* Start the module */
    482         rc = nil_module_start_standalone(nil_client_connection);
    483         return rc;
     447        return nil_module_start(SERVICE_NILDUMMY);
    484448}
    485449
Note: See TracChangeset for help on using the changeset viewer.