Ignore:
File:
1 edited

Legend:

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

    rffa2c8ef r7e752b2  
    4343#include <str.h>
    4444#include <errno.h>
    45 #include <ipc/nil.h>
     45
     46#include <ipc/ipc.h>
    4647#include <ipc/net.h>
    4748#include <ipc/services.h>
     49
    4850#include <net/modules.h>
    4951#include <net_checksum.h>
     
    5254#include <protocol_map.h>
    5355#include <net/device.h>
    54 #include <netif_remote.h>
     56#include <netif_interface.h>
    5557#include <net_interface.h>
    56 #include <il_remote.h>
     58#include <nil_interface.h>
     59#include <il_interface.h>
    5760#include <adt/measured_strings.h>
    5861#include <packet_client.h>
    5962#include <packet_remote.h>
    60 #include <nil_skel.h>
     63#include <nil_local.h>
    6164
    6265#include "eth.h"
     66#include "eth_header.h"
    6367
    6468/** The module name. */
     
    6872#define ETH_PREFIX \
    6973        (sizeof(eth_header_t) + sizeof(eth_header_lsap_t) + \
    70             sizeof(eth_header_snap_t))
     74        sizeof(eth_header_snap_t))
    7175
    7276/** Reserved packet suffix length. */
    73 #define ETH_SUFFIX  (sizeof(eth_fcs_t))
     77#define ETH_SUFFIX \
     78        sizeof(eth_fcs_t)
    7479
    7580/** Maximum packet content length. */
    76 #define ETH_MAX_CONTENT  1500u
     81#define ETH_MAX_CONTENT 1500u
    7782
    7883/** Minimum packet content length. */
    79 #define ETH_MIN_CONTENT  46u
     84#define ETH_MIN_CONTENT 46u
    8085
    8186/** Maximum tagged packet content length. */
    8287#define ETH_MAX_TAGGED_CONTENT(flags) \
    8388        (ETH_MAX_CONTENT - \
    84             ((IS_8023_2_LSAP(flags) || IS_8023_2_SNAP(flags)) ? \
    85             sizeof(eth_header_lsap_t) : 0) - \
    86             (IS_8023_2_SNAP(flags) ? sizeof(eth_header_snap_t) : 0))
     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))
    8792
    8893/** Minimum tagged packet content length. */
    8994#define ETH_MIN_TAGGED_CONTENT(flags) \
    9095        (ETH_MIN_CONTENT - \
    91             ((IS_8023_2_LSAP(flags) || IS_8023_2_SNAP(flags)) ? \
    92             sizeof(eth_header_lsap_t) : 0) - \
    93             (IS_8023_2_SNAP(flags) ? sizeof(eth_header_snap_t) : 0))
     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))
    9499
    95100/** Dummy flag shift value. */
    96 #define ETH_DUMMY_SHIFT  0
     101#define ETH_DUMMY_SHIFT 0
    97102
    98103/** Mode flag shift value. */
    99 #define ETH_MODE_SHIFT  1
     104#define ETH_MODE_SHIFT  1
    100105
    101106/** Dummy device flag.
    102107 * Preamble and FCS are mandatory part of the packets.
    103108 */
    104 #define ETH_DUMMY  (1 << ETH_DUMMY_SHIFT)
     109#define ETH_DUMMY               (1 << ETH_DUMMY_SHIFT)
    105110
    106111/** Returns the dummy flag.
    107112 * @see ETH_DUMMY
    108113 */
    109 #define IS_DUMMY(flags)  ((flags) & ETH_DUMMY)
     114#define IS_DUMMY(flags)         ((flags) & ETH_DUMMY)
    110115
    111116/** Device mode flags.
     
    114119 * @see ETH_8023_2_SNAP
    115120 */
    116 #define ETH_MODE_MASK  (3 << ETH_MODE_SHIFT)
     121#define ETH_MODE_MASK           (3 << ETH_MODE_SHIFT)
    117122
    118123/** DIX Ethernet mode flag. */
    119 #define ETH_DIX  (1 << ETH_MODE_SHIFT)
    120 
    121 /** Return whether the DIX Ethernet mode flag is set.
    122  *
    123  * @param[in] flags Ethernet flags.
     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.
    124129 * @see ETH_DIX
    125  *
    126  */
    127 #define IS_DIX(flags)  (((flags) & ETH_MODE_MASK) == ETH_DIX)
     130 */
     131#define IS_DIX(flags)           (((flags) & ETH_MODE_MASK) == ETH_DIX)
    128132
    129133/** 802.3 + 802.2 + LSAP mode flag. */
    130 #define ETH_8023_2_LSAP  (2 << ETH_MODE_SHIFT)
    131 
    132 /** Return whether the 802.3 + 802.2 + LSAP mode flag is set.
    133  *
    134  * @param[in] flags Ethernet flags.
     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.
    135139 * @see ETH_8023_2_LSAP
    136  *
    137  */
    138 #define IS_8023_2_LSAP(flags)  (((flags) & ETH_MODE_MASK) == ETH_8023_2_LSAP)
     140 */
     141#define IS_8023_2_LSAP(flags)   (((flags) & ETH_MODE_MASK) == ETH_8023_2_LSAP)
    139142
    140143/** 802.3 + 802.2 + LSAP + SNAP mode flag. */
    141 #define ETH_8023_2_SNAP  (3 << ETH_MODE_SHIFT)
    142 
    143 /** Return whether the 802.3 + 802.2 + LSAP + SNAP mode flag is set.
    144  *
    145  * @param[in] flags Ethernet flags.
     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.
    146149 * @see ETH_8023_2_SNAP
    147  *
    148  */
    149 #define IS_8023_2_SNAP(flags)  (((flags) & ETH_MODE_MASK) == ETH_8023_2_SNAP)
     150 */
     151#define IS_8023_2_SNAP(flags)   (((flags) & ETH_MODE_MASK) == ETH_8023_2_SNAP)
    150152
    151153/** Type definition of the ethernet address type.
     
    199201
    200202        eth_globals.broadcast_addr =
    201             measured_string_create_bulk((uint8_t *) "\xFF\xFF\xFF\xFF\xFF\xFF", ETH_ADDR);
     203            measured_string_create_bulk("\xFF\xFF\xFF\xFF\xFF\xFF",
     204            CONVERT_SIZE(uint8_t, char, ETH_ADDR));
    202205        if (!eth_globals.broadcast_addr) {
    203206                rc = ENOMEM;
     
    235238
    236239        while (true) {
    237                 switch (IPC_GET_IMETHOD(*icall)) {
     240                switch (IPC_GET_METHOD(*icall)) {
    238241                case NET_NIL_DEVICE_STATE:
    239                         nil_device_state_msg_local(0, IPC_GET_DEVICE(*icall),
    240                             IPC_GET_STATE(*icall));
    241                         async_answer_0(iid, EOK);
     242                        nil_device_state_msg_local(0, IPC_GET_DEVICE(icall),
     243                            IPC_GET_STATE(icall));
     244                        ipc_answer_0(iid, EOK);
    242245                        break;
    243246                case NET_NIL_RECEIVED:
    244247                        rc = packet_translate_remote(eth_globals.net_phone,
    245                             &packet, IPC_GET_PACKET(*icall));
    246                         if (rc == EOK)
     248                            &packet, IPC_GET_PACKET(icall));
     249                        if (rc == EOK) {
    247250                                rc = nil_received_msg_local(0,
    248                                     IPC_GET_DEVICE(*icall), packet, 0);
    249                        
    250                         async_answer_0(iid, (sysarg_t) rc);
     251                                    IPC_GET_DEVICE(icall), packet, 0);
     252                        }
     253                        ipc_answer_0(iid, (ipcarg_t) rc);
    251254                        break;
    252255                default:
    253                         async_answer_0(iid, (sysarg_t) ENOTSUP);
     256                        ipc_answer_0(iid, (ipcarg_t) ENOTSUP);
    254257                }
    255258               
     
    282285        measured_string_t names[2] = {
    283286                {
    284                         (uint8_t *) "ETH_MODE",
     287                        (char *) "ETH_MODE",
    285288                        8
    286289                },
    287290                {
    288                         (uint8_t *) "ETH_DUMMY",
     291                        (char *) "ETH_DUMMY",
    289292                        9
    290293                }
     
    292295        measured_string_t *configuration;
    293296        size_t count = sizeof(names) / sizeof(measured_string_t);
    294         uint8_t *data;
     297        char *data;
    295298        eth_proto_t *proto;
    296299        int rc;
     
    356359
    357360        if (configuration) {
    358                 if (!str_lcmp((char *) configuration[0].value, "DIX",
     361                if (!str_lcmp(configuration[0].value, "DIX",
    359362                    configuration[0].length)) {
    360363                        device->flags |= ETH_DIX;
    361                 } else if(!str_lcmp((char *) configuration[0].value, "8023_2_LSAP",
     364                } else if(!str_lcmp(configuration[0].value, "8023_2_LSAP",
    362365                    configuration[0].length)) {
    363366                        device->flags |= ETH_8023_2_LSAP;
     
    405408       
    406409        printf("%s: Device registered (id: %d, service: %d: mtu: %zu, "
    407             "mac: %02x:%02x:%02x:%02x:%02x:%02x, flags: 0x%x)\n",
     410            "mac: %x:%x:%x:%x:%x:%x, flags: 0x%x)\n",
    408411            NAME, device->device_id, device->service, device->mtu,
    409412            device->addr_data[0], device->addr_data[1],
     
    834837}
    835838
    836 int nil_module_message(ipc_callid_t callid, ipc_call_t *call,
    837     ipc_call_t *answer, size_t *answer_count)
     839int nil_message_standalone(const char *name, ipc_callid_t callid,
     840    ipc_call_t *call, ipc_call_t *answer, int *answer_count)
    838841{
    839842        measured_string_t *address;
     
    846849       
    847850        *answer_count = 0;
    848         switch (IPC_GET_IMETHOD(*call)) {
     851        switch (IPC_GET_METHOD(*call)) {
    849852        case IPC_M_PHONE_HUNGUP:
    850853                return EOK;
    851854       
    852855        case NET_NIL_DEVICE:
    853                 return eth_device_message(IPC_GET_DEVICE(*call),
    854                     IPC_GET_SERVICE(*call), IPC_GET_MTU(*call));
     856                return eth_device_message(IPC_GET_DEVICE(call),
     857                    IPC_GET_SERVICE(call), IPC_GET_MTU(call));
    855858        case NET_NIL_SEND:
    856859                rc = packet_translate_remote(eth_globals.net_phone, &packet,
    857                     IPC_GET_PACKET(*call));
     860                    IPC_GET_PACKET(call));
    858861                if (rc != EOK)
    859862                        return rc;
    860                 return eth_send_message(IPC_GET_DEVICE(*call), packet,
    861                     IPC_GET_SERVICE(*call));
     863                return eth_send_message(IPC_GET_DEVICE(call), packet,
     864                    IPC_GET_SERVICE(call));
    862865        case NET_NIL_PACKET_SPACE:
    863                 rc = eth_packet_space_message(IPC_GET_DEVICE(*call), &addrlen,
     866                rc = eth_packet_space_message(IPC_GET_DEVICE(call), &addrlen,
    864867                    &prefix, &content, &suffix);
    865868                if (rc != EOK)
    866869                        return rc;
    867                 IPC_SET_ADDR(*answer, addrlen);
    868                 IPC_SET_PREFIX(*answer, prefix);
    869                 IPC_SET_CONTENT(*answer, content);
    870                 IPC_SET_SUFFIX(*answer, suffix);
     870                IPC_SET_ADDR(answer, addrlen);
     871                IPC_SET_PREFIX(answer, prefix);
     872                IPC_SET_CONTENT(answer, content);
     873                IPC_SET_SUFFIX(answer, suffix);
    871874                *answer_count = 4;
    872875                return EOK;
    873876        case NET_NIL_ADDR:
    874                 rc = eth_addr_message(IPC_GET_DEVICE(*call), ETH_LOCAL_ADDR,
     877                rc = eth_addr_message(IPC_GET_DEVICE(call), ETH_LOCAL_ADDR,
    875878                    &address);
    876879                if (rc != EOK)
     
    878881                return measured_strings_reply(address, 1);
    879882        case NET_NIL_BROADCAST_ADDR:
    880                 rc = eth_addr_message(IPC_GET_DEVICE(*call), ETH_BROADCAST_ADDR,
     883                rc = eth_addr_message(IPC_GET_DEVICE(call), ETH_BROADCAST_ADDR,
    881884                    &address);
    882885                if (rc != EOK)
     
    884887                return measured_strings_reply(address, 1);
    885888        case IPC_M_CONNECT_TO_ME:
    886                 return eth_register_message(NIL_GET_PROTO(*call),
    887                     IPC_GET_PHONE(*call));
     889                return eth_register_message(NIL_GET_PROTO(call),
     890                    IPC_GET_PHONE(call));
    888891        }
    889892       
     
    891894}
    892895
     896/** Default thread for new connections.
     897 *
     898 * @param[in] iid       The initial message identifier.
     899 * @param[in] icall     The initial message call structure.
     900 */
     901static void nil_client_connection(ipc_callid_t iid, ipc_call_t *icall)
     902{
     903        /*
     904         * Accept the connection
     905         *  - Answer the first IPC_M_CONNECT_ME_TO call.
     906         */
     907        ipc_answer_0(iid, EOK);
     908       
     909        while (true) {
     910                ipc_call_t answer;
     911                int answer_count;
     912               
     913                /* Clear the answer structure */
     914                refresh_answer(&answer, &answer_count);
     915               
     916                /* Fetch the next message */
     917                ipc_call_t call;
     918                ipc_callid_t callid = async_get_call(&call);
     919               
     920                /* Process the message */
     921                int res = nil_module_message_standalone(NAME, callid, &call,
     922                    &answer, &answer_count);
     923               
     924                /*
     925                 * End if told to either by the message or the processing
     926                 * result.
     927                 */
     928                if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) ||
     929                    (res == EHANGUP))
     930                        return;
     931               
     932                /* Answer the message */
     933                answer_call(callid, res, &answer, answer_count);
     934        }
     935}
     936
    893937int main(int argc, char *argv[])
    894938{
     939        int rc;
     940       
    895941        /* Start the module */
    896         return nil_module_start(SERVICE_ETHERNET);
     942        rc = nil_module_start_standalone(nil_client_connection);
     943        return rc;
    897944}
    898945
Note: See TracChangeset for help on using the changeset viewer.