Changeset fe8dfa6 in mainline


Ignore:
Timestamp:
2011-01-11T15:57:39Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
77429d3
Parents:
04aade50
Message:

networking: streamline NIL skeleton and NIL modules (nildummy, eth)

Location:
uspace
Files:
1 added
4 deleted
15 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/Makefile

    r04aade50 rfe8dfa6  
    4343        netif/netif_skel.c \
    4444        nil/nil_remote.c \
     45        nil/nil_skel.c \
    4546        il/il_interface.c \
    4647        il/ip_remote.c \
  • uspace/lib/net/include/nil_remote.h

    r04aade50 rfe8dfa6  
    3737#include <net/device.h>
    3838#include <net/packet.h>
     39#include <generic.h>
    3940
    40 extern int nil_device_state_msg_remote(int, device_id_t, int);
    41 extern int nil_received_msg_remote(int, device_id_t, packet_t *, services_t);
     41#define nil_bind_service(service, device_id, me, receiver) \
     42        bind_service(service, device_id, me, 0, receiver)
     43
     44#define nil_packet_size_req(nil_phone, device_id, packet_dimension) \
     45        generic_packet_size_req_remote(nil_phone, NET_NIL_PACKET_SPACE, \
     46            device_id, packet_dimension)
     47
     48#define nil_get_addr_req(nil_phone, device_id, address, data) \
     49        generic_get_addr_req(nil_phone, NET_NIL_ADDR, device_id, address, data)
     50
     51#define nil_get_broadcast_addr_req(nil_phone, device_id, address, data) \
     52        generic_get_addr_req(nil_phone, NET_NIL_BROADCAST_ADDR, device_id, \
     53            address, data)
     54
     55#define nil_send_msg(nil_phone, device_id, packet, sender) \
     56        generic_send_msg_remote(nil_phone, NET_NIL_SEND, device_id, \
     57            packet_get_id(packet), sender, 0)
     58
     59#define nil_device_req(nil_phone, device_id, mtu, netif_service) \
     60        generic_device_req_remote(nil_phone, NET_NIL_DEVICE, device_id, mtu, \
     61            netif_service)
     62
     63extern int nil_device_state_msg(int, device_id_t, int);
     64extern int nil_received_msg(int, device_id_t, packet_t *, services_t);
    4265
    4366#endif
  • uspace/lib/net/netif/netif_skel.c

    r04aade50 rfe8dfa6  
    3333/** @file
    3434 * Network interface module skeleton implementation.
    35  * @see netif.h
     35 * @see netif_skel.h
    3636 */
    3737
     
    5252#include <adt/measured_strings.h>
    5353#include <net/device.h>
    54 #include <nil_interface.h>
    5554#include <netif_skel.h>
     55#include <nil_remote.h>
    5656
    5757DEVICE_MAP_IMPLEMENT(netif_device_map, netif_device_t);
  • uspace/lib/net/nil/nil_remote.c

    r04aade50 rfe8dfa6  
    3333/** @file
    3434 * Network interface layer interface implementation for remote modules.
    35  * @see nil_interface.h
     35 * @see nil_remote.h
    3636 */
    3737
    3838#include <nil_remote.h>
    39 #include <nil_interface.h>
    4039#include <generic.h>
    4140#include <net/device.h>
    4241#include <net/packet.h>
    4342#include <packet_client.h>
    44 
    4543#include <ipc/nil.h>
    4644
    4745/** Notify the network interface layer about the device state change.
    4846 *
    49  * @param[in] nil_phone The network interface layer phone.
    50  * @param[in] device_id The device identifier.
    51  * @param[in] state     The new device state.
    52  * @return              EOK on success.
    53  * @return              Other error codes as defined for each specific module
    54  *                      device state function.
     47 * @param[in] nil_phone Network interface layer phone.
     48 * @param[in] device_id Device identifier.
     49 * @param[in] state     New device state.
     50 *
     51 * @return EOK on success.
     52 * @return Other error codes as defined for each specific module
     53 *         device state function.
     54 *
    5555 */
    56 int nil_device_state_msg_remote(int nil_phone, device_id_t device_id, int state)
     56int nil_device_state_msg(int nil_phone, device_id_t device_id, int state)
    5757{
    5858        return generic_device_state_msg_remote(nil_phone, NET_NIL_DEVICE_STATE,
     
    6565 * upper layers.
    6666 *
    67  * @param[in] nil_phone The network interface layer phone.
    68  * @param[in] device_id The source device identifier.
    69  * @param[in] packet    The received packet or the received packet queue.
    70  * @param target        The target service. Ignored parameter.
    71  * @return              EOK on success.
    72  * @return              Other error codes as defined for each specific module
    73  *                      received function.
     67 * @param[in] nil_phone Network interface layer phone.
     68 * @param[in] device_id Source device identifier.
     69 * @param[in] packet    Received packet or the received packet queue.
     70 * @param[in] target    Target service. Ignored parameter.
     71 *
     72 * @return EOK on success.
     73 * @return Other error codes as defined for each specific module
     74 *         received function.
     75 *
    7476 */
    75 int nil_received_msg_remote(int nil_phone, device_id_t device_id,
     77int nil_received_msg(int nil_phone, device_id_t device_id,
    7678    packet_t *packet, services_t target)
    7779{
  • uspace/lib/net/nil/nil_skel.c

    r04aade50 rfe8dfa6  
    2727 */
    2828
    29 /** @addtogroup nildummy
     29/** @addtogroup libnet
    3030 * @{
    3131 */
    3232
    3333/** @file
    34  *  Dummy network interface layer module stub.
    35  *  @see module.c
     34 * Network network interface layer module implementation.
     35 * @see nil_skel.h
    3636 */
    3737
    38 #include <async.h>
    39 #include <stdio.h>
     38#include <bool.h>
    4039#include <errno.h>
     40#include <nil_skel.h>
     41#include <net_interface.h>
     42#include <net/modules.h>
    4143
    42 #include <ipc/ipc.h>
    43 #include <ipc/services.h>
     44/** Default thread for new connections.
     45 *
     46 * @param[in] iid   The initial message identifier.
     47 * @param[in] icall The initial message call structure.
     48 *
     49 */
     50static void nil_client_connection(ipc_callid_t iid, ipc_call_t *icall)
     51{
     52        /*
     53         * Accept the connection by answering
     54         * the initial IPC_M_CONNECT_ME_TO call.
     55         */
     56        ipc_answer_0(iid, EOK);
     57       
     58        while (true) {
     59                ipc_call_t answer;
     60                size_t count;
     61               
     62                /* Clear the answer structure */
     63                refresh_answer(&answer, &count);
     64               
     65                /* Fetch the next message */
     66                ipc_call_t call;
     67                ipc_callid_t callid = async_get_call(&call);
     68               
     69                /* Process the message */
     70                int res = nil_module_message(callid, &call, &answer,
     71                    &count);
     72               
     73                /*
     74                 * End if told to either by the message or the processing
     75                 * result.
     76                 */
     77                if ((IPC_GET_IMETHOD(call) == IPC_M_PHONE_HUNGUP) ||
     78                    (res == EHANGUP))
     79                        return;
     80               
     81                /* Answer the message */
     82                answer_call(callid, res, &answer, count);
     83        }
     84}
    4485
    45 #include <net/modules.h>
    46 #include <net_interface.h>
    47 #include <net/packet.h>
    48 #include <nil_local.h>
    49 
    50 #include "nildummy.h"
    51 
    52 int nil_module_start_standalone(async_client_conn_t client_connection)
     86/** Start the network interface layer module.
     87 *
     88 * Initialize the client connection serving function, initialize
     89 * the module, register the module service and start the async
     90 * manager, processing IPC messages in an infinite loop.
     91 *
     92 * @param[in] service Service identification.
     93 *
     94 * @return EOK on success.
     95 * @return Other error codes as defined for the pm_init() function.
     96 * @return Other error codes as defined for the nil_initialize()
     97 *         function.
     98 * @return Other error codes as defined for the REGISTER_ME() macro
     99 *         function.
     100 *
     101 */
     102int nil_module_start(int service)
    53103{
    54         sysarg_t phonehash;
    55         int rc;
    56        
    57         async_set_client_connection(client_connection);
     104        async_set_client_connection(nil_client_connection);
    58105        int net_phone = net_connect_module();
    59106       
    60         rc = pm_init();
     107        int rc = pm_init();
    61108        if (rc != EOK)
    62109                return rc;
    63        
    64110       
    65111        rc = nil_initialize(net_phone);
     
    67113                goto out;
    68114       
    69         rc = ipc_connect_to_me(PHONE_NS, SERVICE_NILDUMMY, 0, 0, &phonehash);
     115        sysarg_t phonehash;
     116        rc = ipc_connect_to_me(PHONE_NS, service, 0, 0, &phonehash);
    70117        if (rc != EOK)
    71118                goto out;
    72119       
    73120        async_manager();
    74 
     121       
    75122out:
    76123        pm_destroy();
     
    78125}
    79126
    80 int nil_module_message_standalone(const char *name, ipc_callid_t callid,
    81     ipc_call_t *call, ipc_call_t *answer, size_t *count)
    82 {
    83         return nil_message_standalone(name, callid, call, answer, count);
    84 }
    85 
    86127/** @}
    87128 */
  • uspace/srv/hw/netif/ne2000/ne2000.c

    r04aade50 rfe8dfa6  
    5151#include <net/device.h>
    5252#include <netif_skel.h>
    53 #include <nil_interface.h>
     53#include <nil_remote.h>
    5454#include "dp8390.h"
    5555
     
    346346        }
    347347       
    348         return EOK;
     348        return device->state;
    349349}
    350350
  • uspace/srv/net/il/arp/arp.c

    r04aade50 rfe8dfa6  
    5454#include <ipc/arp.h>
    5555#include <ipc/il.h>
     56#include <ipc/nil.h>
    5657#include <byteorder.h>
    5758#include <errno.h>
    58 
    5959#include <net/modules.h>
    6060#include <net/device.h>
    6161#include <net/packet.h>
    62 
    63 #include <nil_interface.h>
     62#include <nil_remote.h>
    6463#include <protocol_map.h>
    6564#include <packet_client.h>
  • uspace/srv/net/il/ip/ip.c

    r04aade50 rfe8dfa6  
    7575#include <ip_header.h>
    7676#include <net_interface.h>
    77 #include <nil_interface.h>
     77#include <nil_remote.h>
    7878#include <tl_interface.h>
    7979#include <packet_remote.h>
  • uspace/srv/net/net/net.c

    r04aade50 rfe8dfa6  
    5151#include <ipc/net_net.h>
    5252#include <ipc/il.h>
     53#include <ipc/nil.h>
    5354
    5455#include <net/modules.h>
     
    6263
    6364#include <netif_remote.h>
    64 #include <nil_interface.h>
     65#include <nil_remote.h>
    6566#include <net_interface.h>
    6667#include <ip_interface.h>
  • uspace/srv/net/netif/lo/lo.c

    r04aade50 rfe8dfa6  
    4848#include <packet_client.h>
    4949#include <net/device.h>
    50 #include <nil_interface.h>
    5150#include <netif_skel.h>
    52 
    53 /** Default hardware address. */
    54 #define DEFAULT_ADDR  0
     51#include <nil_remote.h>
    5552
    5653/** Default address length. */
     
    6057#define NAME  "lo"
    6158
    62 /** Network interface global data. */
    63 netif_globals_t netif_globals;
     59static uint8_t default_addr[DEFAULT_ADDR_LEN] =
     60    {0, 0, 0, 0, 0, 0};
    6461
    6562int netif_specific_message(ipc_callid_t callid, ipc_call_t *call,
     
    7471                return EBADMEM;
    7572       
    76         uint8_t *addr = (uint8_t *) malloc(DEFAULT_ADDR_LEN);
    77         memset(addr, DEFAULT_ADDR, DEFAULT_ADDR_LEN);
    78        
    79         address->value = addr;
     73        address->value = default_addr;
    8074        address->length = DEFAULT_ADDR_LEN;
    8175       
     
    8579int netif_get_device_stats(device_id_t device_id, device_stats_t *stats)
    8680{
    87         netif_device_t *device;
    88         int rc;
    89 
    9081        if (!stats)
    9182                return EBADMEM;
    92 
    93         rc = find_device(device_id, &device);
     83       
     84        netif_device_t *device;
     85        int rc = find_device(device_id, &device);
    9486        if (rc != EOK)
    9587                return rc;
    96 
     88       
    9789        memcpy(stats, (device_stats_t *) device->specific,
    9890            sizeof(device_stats_t));
    99 
    100         return EOK;
    101 }
    102 
    103 /** Changes the loopback state.
    104  *
    105  * @param[in] device    The device structure.
    106  * @param[in] state     The new device state.
    107  * @return              The new state if changed.
    108  * @return              EOK otherwise.
    109  */
    110 static int change_state_message(netif_device_t *device, device_state_t state)
     91       
     92        return EOK;
     93}
     94
     95/** Change the loopback state.
     96 *
     97 * @param[in] device The device structure.
     98 * @param[in] state  The new device state.
     99 *
     100 * @return New state if changed.
     101 * @return EOK otherwise.
     102 *
     103 */
     104static void change_state_message(netif_device_t *device, device_state_t state)
    111105{
    112106        if (device->state != state) {
    113107                device->state = state;
    114108               
    115                 printf("%s: State changed to %s\n", NAME,
    116                     (state == NETIF_ACTIVE) ? "active" : "stopped");
     109                const char *desc;
     110                switch (state) {
     111                case NETIF_ACTIVE:
     112                        desc = "active";
     113                        break;
     114                case NETIF_STOPPED:
     115                        desc = "stopped";
     116                        break;
     117                default:
     118                        desc = "unknown";
     119                }
    117120               
    118                 return state;
    119         }
    120        
    121         return EOK;
    122 }
    123 
    124 /** Creates and returns the loopback network interface structure.
    125  *
    126  * @param[in] device_id The new devce identifier.
    127  * @param[out] device   The device structure.
    128  * @return              EOK on success.
    129  * @return              EXDEV if one loopback network interface already exists.
    130  * @return              ENOMEM if there is not enough memory left.
    131  */
    132 static int create(device_id_t device_id, netif_device_t **device)
    133 {
    134         int index;
    135 
     121                printf("%s: State changed to %s\n", NAME, desc);
     122        }
     123}
     124
     125/** Create and return the loopback network interface structure.
     126 *
     127 * @param[in]  device_id New devce identifier.
     128 * @param[out] device    Device structure.
     129 *
     130 * @return EOK on success.
     131 * @return EXDEV if one loopback network interface already exists.
     132 * @return ENOMEM if there is not enough memory left.
     133 *
     134 */
     135static int lo_create(device_id_t device_id, netif_device_t **device)
     136{
    136137        if (netif_device_map_count(&netif_globals.device_map) > 0)
    137138                return EXDEV;
    138 
     139       
    139140        *device = (netif_device_t *) malloc(sizeof(netif_device_t));
    140141        if (!*device)
    141142                return ENOMEM;
    142 
     143       
    143144        (*device)->specific = (device_stats_t *) malloc(sizeof(device_stats_t));
    144145        if (!(*device)->specific) {
     
    146147                return ENOMEM;
    147148        }
    148 
     149       
    149150        null_device_stats((device_stats_t *) (*device)->specific);
    150151        (*device)->device_id = device_id;
    151152        (*device)->nil_phone = -1;
    152153        (*device)->state = NETIF_STOPPED;
    153         index = netif_device_map_add(&netif_globals.device_map,
     154        int index = netif_device_map_add(&netif_globals.device_map,
    154155            (*device)->device_id, *device);
    155 
     156       
    156157        if (index < 0) {
    157158                free(*device);
     
    167168{
    168169        sysarg_t phonehash;
    169 
    170170        return ipc_connect_to_me(PHONE_NS, SERVICE_LO, 0, 0, &phonehash);
    171171}
     
    173173int netif_probe_message(device_id_t device_id, int irq, void *io)
    174174{
     175        /* Create a new device */
    175176        netif_device_t *device;
    176         int rc;
    177 
    178         /* Create a new device */
    179         rc = create(device_id, &device);
     177        int rc = lo_create(device_id, &device);
    180178        if (rc != EOK)
    181179                return rc;
    182 
    183         /* Print the settings */
     180       
    184181        printf("%s: Device created (id: %d)\n", NAME, device->device_id);
    185 
    186182        return EOK;
    187183}
     
    190186{
    191187        netif_device_t *device;
    192         size_t length;
    193         packet_t *next;
    194         int phone;
    195         int rc;
    196 
    197         rc = find_device(device_id, &device);
     188        int rc = find_device(device_id, &device);
    198189        if (rc != EOK)
    199190                return EOK;
    200 
     191       
    201192        if (device->state != NETIF_ACTIVE) {
    202193                netif_pq_release(packet_get_id(packet));
    203194                return EFORWARD;
    204195        }
    205 
    206         next = packet;
     196       
     197        packet_t *next = packet;
    207198        do {
    208199                ((device_stats_t *) device->specific)->send_packets++;
    209200                ((device_stats_t *) device->specific)->receive_packets++;
    210                 length = packet_get_data_length(next);
     201                size_t length = packet_get_data_length(next);
    211202                ((device_stats_t *) device->specific)->send_bytes += length;
    212203                ((device_stats_t *) device->specific)->receive_bytes += length;
    213204                next = pq_next(next);
    214         } while(next);
    215 
    216         phone = device->nil_phone;
     205        } while (next);
     206       
     207        int phone = device->nil_phone;
    217208        fibril_rwlock_write_unlock(&netif_globals.lock);
     209       
    218210        nil_received_msg(phone, device_id, packet, sender);
     211       
    219212        fibril_rwlock_write_lock(&netif_globals.lock);
    220        
    221213        return EOK;
    222214}
     
    224216int netif_start_message(netif_device_t *device)
    225217{
    226         return change_state_message(device, NETIF_ACTIVE);
     218        change_state_message(device, NETIF_ACTIVE);
     219        return device->state;
    227220}
    228221
    229222int netif_stop_message(netif_device_t *device)
    230223{
    231         return change_state_message(device, NETIF_STOPPED);
     224        change_state_message(device, NETIF_STOPPED);
     225        return device->state;
    232226}
    233227
  • uspace/srv/net/nil/eth/Makefile

    r04aade50 rfe8dfa6  
    4242
    4343SOURCES = \
    44         eth.c \
    45         eth_module.c
     44        eth.c
    4645
    4746include $(USPACE_PREFIX)/Makefile.common
  • uspace/srv/net/nil/eth/eth.c

    r04aade50 rfe8dfa6  
    4545
    4646#include <ipc/ipc.h>
     47#include <ipc/nil.h>
    4748#include <ipc/net.h>
    4849#include <ipc/services.h>
     
    5657#include <netif_remote.h>
    5758#include <net_interface.h>
    58 #include <nil_interface.h>
    5959#include <il_interface.h>
    6060#include <adt/measured_strings.h>
    6161#include <packet_client.h>
    6262#include <packet_remote.h>
    63 #include <nil_local.h>
     63#include <nil_skel.h>
    6464
    6565#include "eth.h"
    66 #include "eth_header.h"
    6766
    6867/** The module name. */
     
    7271#define ETH_PREFIX \
    7372        (sizeof(eth_header_t) + sizeof(eth_header_lsap_t) + \
    74         sizeof(eth_header_snap_t))
     73            sizeof(eth_header_snap_t))
    7574
    7675/** Reserved packet suffix length. */
    77 #define ETH_SUFFIX \
    78         sizeof(eth_fcs_t)
     76#define ETH_SUFFIX  (sizeof(eth_fcs_t))
    7977
    8078/** Maximum packet content length. */
    81 #define ETH_MAX_CONTENT 1500u
     79#define ETH_MAX_CONTENT  1500u
    8280
    8381/** Minimum packet content length. */
    84 #define ETH_MIN_CONTENT 46u
     82#define ETH_MIN_CONTENT  46u
    8583
    8684/** Maximum tagged packet content length. */
    8785#define ETH_MAX_TAGGED_CONTENT(flags) \
    8886        (ETH_MAX_CONTENT - \
    89         ((IS_8023_2_LSAP(flags) || IS_8023_2_SNAP(flags)) ? \
    90         sizeof(eth_header_lsap_t) : 0) - \
    91         (IS_8023_2_SNAP(flags) ? sizeof(eth_header_snap_t) : 0))
     87            ((IS_8023_2_LSAP(flags) || IS_8023_2_SNAP(flags)) ? \
     88            sizeof(eth_header_lsap_t) : 0) - \
     89            (IS_8023_2_SNAP(flags) ? sizeof(eth_header_snap_t) : 0))
    9290
    9391/** Minimum tagged packet content length. */
    9492#define ETH_MIN_TAGGED_CONTENT(flags) \
    9593        (ETH_MIN_CONTENT - \
    96         ((IS_8023_2_LSAP(flags) || IS_8023_2_SNAP(flags)) ? \
    97         sizeof(eth_header_lsap_t) : 0) - \
    98         (IS_8023_2_SNAP(flags) ? sizeof(eth_header_snap_t) : 0))
     94            ((IS_8023_2_LSAP(flags) || IS_8023_2_SNAP(flags)) ? \
     95            sizeof(eth_header_lsap_t) : 0) - \
     96            (IS_8023_2_SNAP(flags) ? sizeof(eth_header_snap_t) : 0))
    9997
    10098/** Dummy flag shift value. */
    101 #define ETH_DUMMY_SHIFT 0
     99#define ETH_DUMMY_SHIFT  0
    102100
    103101/** Mode flag shift value. */
    104 #define ETH_MODE_SHIFT  1
     102#define ETH_MODE_SHIFT  1
    105103
    106104/** Dummy device flag.
    107105 * Preamble and FCS are mandatory part of the packets.
    108106 */
    109 #define ETH_DUMMY               (1 << ETH_DUMMY_SHIFT)
     107#define ETH_DUMMY  (1 << ETH_DUMMY_SHIFT)
    110108
    111109/** Returns the dummy flag.
    112110 * @see ETH_DUMMY
    113111 */
    114 #define IS_DUMMY(flags)         ((flags) & ETH_DUMMY)
     112#define IS_DUMMY(flags)  ((flags) & ETH_DUMMY)
    115113
    116114/** Device mode flags.
     
    119117 * @see ETH_8023_2_SNAP
    120118 */
    121 #define ETH_MODE_MASK           (3 << ETH_MODE_SHIFT)
     119#define ETH_MODE_MASK  (3 << ETH_MODE_SHIFT)
    122120
    123121/** DIX Ethernet mode flag. */
    124 #define ETH_DIX                 (1 << ETH_MODE_SHIFT)
    125 
    126 /** Returns whether the DIX Ethernet mode flag is set.
    127  *
    128  * @param[in] flags     The ethernet flags.
     122#define ETH_DIX  (1 << ETH_MODE_SHIFT)
     123
     124/** Return whether the DIX Ethernet mode flag is set.
     125 *
     126 * @param[in] flags Ethernet flags.
    129127 * @see ETH_DIX
    130  */
    131 #define IS_DIX(flags)           (((flags) & ETH_MODE_MASK) == ETH_DIX)
     128 *
     129 */
     130#define IS_DIX(flags)  (((flags) & ETH_MODE_MASK) == ETH_DIX)
    132131
    133132/** 802.3 + 802.2 + LSAP mode flag. */
    134 #define ETH_8023_2_LSAP         (2 << ETH_MODE_SHIFT)
    135 
    136 /** Returns whether the 802.3 + 802.2 + LSAP mode flag is set.
    137  *
    138  * @param[in] flags     The ethernet flags.
     133#define ETH_8023_2_LSAP  (2 << ETH_MODE_SHIFT)
     134
     135/** Return whether the 802.3 + 802.2 + LSAP mode flag is set.
     136 *
     137 * @param[in] flags Ethernet flags.
    139138 * @see ETH_8023_2_LSAP
    140  */
    141 #define IS_8023_2_LSAP(flags)   (((flags) & ETH_MODE_MASK) == ETH_8023_2_LSAP)
     139 *
     140 */
     141#define IS_8023_2_LSAP(flags)  (((flags) & ETH_MODE_MASK) == ETH_8023_2_LSAP)
    142142
    143143/** 802.3 + 802.2 + LSAP + SNAP mode flag. */
    144 #define ETH_8023_2_SNAP         (3 << ETH_MODE_SHIFT)
    145 
    146 /** Returns whether the 802.3 + 802.2 + LSAP + SNAP mode flag is set.
    147  *
    148  * @param[in] flags     The ethernet flags.
     144#define ETH_8023_2_SNAP  (3 << ETH_MODE_SHIFT)
     145
     146/** Return whether the 802.3 + 802.2 + LSAP + SNAP mode flag is set.
     147 *
     148 * @param[in] flags Ethernet flags.
    149149 * @see ETH_8023_2_SNAP
    150  */
    151 #define IS_8023_2_SNAP(flags)   (((flags) & ETH_MODE_MASK) == ETH_8023_2_SNAP)
     150 *
     151 */
     152#define IS_8023_2_SNAP(flags)  (((flags) & ETH_MODE_MASK) == ETH_8023_2_SNAP)
    152153
    153154/** Type definition of the ethernet address type.
     
    836837}
    837838
    838 int nil_message_standalone(const char *name, ipc_callid_t callid,
    839     ipc_call_t *call, ipc_call_t *answer, size_t *answer_count)
     839int nil_module_message(ipc_callid_t callid, ipc_call_t *call,
     840    ipc_call_t *answer, size_t *answer_count)
    840841{
    841842        measured_string_t *address;
     
    893894}
    894895
    895 /** Default thread for new connections.
    896  *
    897  * @param[in] iid       The initial message identifier.
    898  * @param[in] icall     The initial message call structure.
    899  */
    900 static void nil_client_connection(ipc_callid_t iid, ipc_call_t *icall)
    901 {
    902         /*
    903          * Accept the connection
    904          *  - Answer the first IPC_M_CONNECT_ME_TO call.
    905          */
    906         ipc_answer_0(iid, EOK);
    907        
    908         while (true) {
    909                 ipc_call_t answer;
    910                 size_t count;
    911                
    912                 /* Clear the answer structure */
    913                 refresh_answer(&answer, &count);
    914                
    915                 /* Fetch the next message */
    916                 ipc_call_t call;
    917                 ipc_callid_t callid = async_get_call(&call);
    918                
    919                 /* Process the message */
    920                 int res = nil_module_message_standalone(NAME, callid, &call,
    921                     &answer, &count);
    922                
    923                 /*
    924                  * End if told to either by the message or the processing
    925                  * result.
    926                  */
    927                 if ((IPC_GET_IMETHOD(call) == IPC_M_PHONE_HUNGUP) ||
    928                     (res == EHANGUP))
    929                         return;
    930                
    931                 /* Answer the message */
    932                 answer_call(callid, res, &answer, count);
    933         }
    934 }
    935 
    936896int main(int argc, char *argv[])
    937897{
    938         int rc;
    939        
    940898        /* Start the module */
    941         rc = nil_module_start_standalone(nil_client_connection);
    942         return rc;
     899        return nil_module_start(SERVICE_ETHERNET);
    943900}
    944901
  • uspace/srv/net/nil/eth/eth.h

    r04aade50 rfe8dfa6  
    4444#include <adt/measured_strings.h>
    4545
     46/** Ethernet address length. */
     47#define ETH_ADDR  6
     48
     49/** Ethernet header preamble value. */
     50#define ETH_PREAMBLE  0x55
     51
     52/** Ethernet header start of frame value. */
     53#define ETH_SFD  0xD5
     54
     55/** IEEE 802.2 unordered information control field. */
     56#define IEEE_8023_2_UI  0x03
     57
     58/** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions.
     59 * @see eth_header_snap
     60 */
     61typedef struct eth_header_snap eth_header_snap_t;
     62
     63/** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions.
     64 * @see eth_header_lsap
     65 */
     66typedef struct eth_header_lsap eth_header_lsap_t;
     67
     68/** Type definition of the Ethernet header LSAP extension.
     69 * @see eth_ieee_lsap
     70 */
     71typedef struct eth_ieee_lsap eth_ieee_lsap_t;
     72
     73/** Type definition of the Ethernet header SNAP extension.
     74 * @see eth_snap
     75 */
     76typedef struct eth_snap eth_snap_t;
     77
     78/** Type definition of the Ethernet header preamble.
     79 * @see preamble
     80 */
     81typedef struct eth_preamble eth_preamble_t;
     82
     83/** Type definition of the Ethernet header.
     84 * @see eth_header
     85 */
     86typedef struct eth_header eth_header_t;
     87
     88/** Ethernet header Link Service Access Point extension. */
     89struct eth_ieee_lsap {
     90        /**
     91         * Destination Service Access Point identifier.
     92         * The possible values are assigned by an IEEE committee.
     93         */
     94        uint8_t dsap;
     95       
     96        /**
     97         * Source Service Access Point identifier.
     98         * The possible values are assigned by an IEEE committee.
     99         */
     100        uint8_t ssap;
     101       
     102        /**
     103         * Control parameter.
     104         * The possible values are assigned by an IEEE committee.
     105         */
     106        uint8_t ctrl;
     107} __attribute__ ((packed));
     108
     109/** Ethernet header SNAP extension. */
     110struct eth_snap {
     111        /** Protocol identifier or organization code. */
     112        uint8_t protocol[3];
     113       
     114        /**
     115         * Ethernet protocol identifier in the network byte order (big endian).
     116         * @see ethernet_protocols.h
     117         */
     118        uint16_t ethertype;
     119} __attribute__ ((packed));
     120
     121/** Ethernet header preamble.
     122 *
     123 * Used for dummy devices.
     124 */
     125struct eth_preamble {
     126        /**
     127         * Controlling preamble used for the frame transmission synchronization.
     128         * All should be set to ETH_PREAMBLE.
     129         */
     130        uint8_t preamble[7];
     131       
     132        /**
     133         * Start of Frame Delimiter used for the frame transmission
     134         * synchronization.
     135         * Should be set to ETH_SFD.
     136         */
     137        uint8_t sfd;
     138} __attribute__ ((packed));
     139
     140/** Ethernet header. */
     141struct eth_header {
     142        /** Destination host Ethernet address (MAC address). */
     143        uint8_t destination_address[ETH_ADDR];
     144        /** Source host Ethernet address (MAC address). */
     145        uint8_t source_address[ETH_ADDR];
     146       
     147        /**
     148         * Ethernet protocol identifier in the network byte order (big endian).
     149         * @see ethernet_protocols.h
     150         */
     151        uint16_t ethertype;
     152} __attribute__ ((packed));
     153
     154/** Ethernet header IEEE 802.3 + 802.2 extension. */
     155struct eth_header_lsap {
     156        /** Ethernet header. */
     157        eth_header_t header;
     158       
     159        /**
     160         * LSAP extension.
     161         * If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being
     162         * used.
     163         * If DSAP and SSAP fields are equal to ETH_RAW the raw Ethernet packet
     164         * without any extensions is being used and the frame content starts
     165         * rigth after the two fields.
     166         */
     167        eth_ieee_lsap_t lsap;
     168} __attribute__ ((packed));
     169
     170/** Ethernet header IEEE 802.3 + 802.2 + SNAP extensions. */
     171struct eth_header_snap {
     172        /** Ethernet header. */
     173        eth_header_t header;
     174       
     175        /**
     176         * LSAP extension.
     177         * If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being
     178         * used.
     179         * If DSAP and SSAP fields are equal to ETH_RAW the raw Ethernet packet
     180         * without any extensions is being used and the frame content starts
     181         * rigth after the two fields.
     182         */
     183        eth_ieee_lsap_t lsap;
     184       
     185        /** SNAP extension. */
     186        eth_snap_t snap;
     187} __attribute__ ((packed));
     188
     189/** Ethernet Frame Check Sequence. */
     190typedef uint32_t eth_fcs_t;
     191
    46192/** Type definition of the Ethernet global data.
    47193 * @see eth_globals
  • uspace/srv/net/nil/nildummy/Makefile

    r04aade50 rfe8dfa6  
    4242
    4343SOURCES = \
    44         nildummy.c \
    45         nildummy_module.c
     44        nildummy.c
    4645
    4746include $(USPACE_PREFIX)/Makefile.common
  • uspace/srv/net/nil/nildummy/nildummy.c

    r04aade50 rfe8dfa6  
    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>
    5050#include <il_interface.h>
    5151#include <adt/measured_strings.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)) {
     
    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
  • uspace/srv/net/nil/nildummy/nildummy.h

    r04aade50 rfe8dfa6  
    4545
    4646/** Type definition of the dummy nil global data.
     47 *
    4748 * @see nildummy_globals
     49 *
    4850 */
    4951typedef struct nildummy_globals nildummy_globals_t;
    5052
    5153/** Type definition of the dummy nil device specific data.
     54 *
    5255 * @see nildummy_device
     56 *
    5357 */
    5458typedef struct nildummy_device nildummy_device_t;
    5559
    5660/** Type definition of the dummy nil protocol specific data.
     61 *
    5762 * @see nildummy_proto
     63 *
    5864 */
    5965typedef struct nildummy_proto nildummy_proto_t;
    6066
    6167/** Dummy nil device map.
    62  * Maps devices to the dummy nil device specific data.
     68 *
     69 * Map devices to the dummy nil device specific data.
    6370 * @see device.h
     71 *
    6472 */
    6573DEVICE_MAP_DECLARE(nildummy_devices, nildummy_device_t);
     
    6977        /** Device identifier. */
    7078        device_id_t device_id;
     79       
    7180        /** Device driver service. */
    7281        services_t service;
     82       
    7383        /** Driver phone. */
    7484        int phone;
     85       
    7586        /** Maximal transmission unit. */
    7687        size_t mtu;
     88       
    7789        /** Actual device hardware address. */
    7890        measured_string_t *addr;
     91       
    7992        /** Actual device hardware address data. */
    8093        uint8_t *addr_data;
     
    8598        /** Protocol service. */
    8699        services_t service;
     100       
    87101        /** Protocol module phone. */
    88102        int phone;
     
    93107        /** Networking module phone. */
    94108        int net_phone;
    95         /** Safety lock for devices. */
     109       
     110        /** Lock for devices. */
    96111        fibril_rwlock_t devices_lock;
     112       
    97113        /** All known Ethernet devices. */
    98114        nildummy_devices_t devices;
     115       
    99116        /** Safety lock for protocols. */
    100117        fibril_rwlock_t protos_lock;
     118       
    101119        /** Default protocol. */
    102120        nildummy_proto_t proto;
Note: See TracChangeset for help on using the changeset viewer.