Ignore:
File:
1 edited

Legend:

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

    r797b704 r774e6d1a  
    4545
    4646#include <ipc/ipc.h>
    47 #include <ipc/nil.h>
    4847#include <ipc/net.h>
    4948#include <ipc/services.h>
     
    5756#include <netif_remote.h>
    5857#include <net_interface.h>
    59 #include <il_remote.h>
     58#include <nil_interface.h>
     59#include <il_interface.h>
    6060#include <adt/measured_strings.h>
    6161#include <packet_client.h>
    6262#include <packet_remote.h>
    63 #include <nil_skel.h>
     63#include <nil_local.h>
    6464
    6565#include "eth.h"
     66#include "eth_header.h"
    6667
    6768/** The module name. */
     
    7172#define ETH_PREFIX \
    7273        (sizeof(eth_header_t) + sizeof(eth_header_lsap_t) + \
    73             sizeof(eth_header_snap_t))
     74        sizeof(eth_header_snap_t))
    7475
    7576/** Reserved packet suffix length. */
    76 #define ETH_SUFFIX  (sizeof(eth_fcs_t))
     77#define ETH_SUFFIX \
     78        sizeof(eth_fcs_t)
    7779
    7880/** Maximum packet content length. */
    79 #define ETH_MAX_CONTENT  1500u
     81#define ETH_MAX_CONTENT 1500u
    8082
    8183/** Minimum packet content length. */
    82 #define ETH_MIN_CONTENT  46u
     84#define ETH_MIN_CONTENT 46u
    8385
    8486/** Maximum tagged packet content length. */
    8587#define ETH_MAX_TAGGED_CONTENT(flags) \
    8688        (ETH_MAX_CONTENT - \
    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))
     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))
    9092
    9193/** Minimum tagged packet content length. */
    9294#define ETH_MIN_TAGGED_CONTENT(flags) \
    9395        (ETH_MIN_CONTENT - \
    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))
     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))
    9799
    98100/** Dummy flag shift value. */
    99 #define ETH_DUMMY_SHIFT  0
     101#define ETH_DUMMY_SHIFT 0
    100102
    101103/** Mode flag shift value. */
    102 #define ETH_MODE_SHIFT  1
     104#define ETH_MODE_SHIFT  1
    103105
    104106/** Dummy device flag.
    105107 * Preamble and FCS are mandatory part of the packets.
    106108 */
    107 #define ETH_DUMMY  (1 << ETH_DUMMY_SHIFT)
     109#define ETH_DUMMY               (1 << ETH_DUMMY_SHIFT)
    108110
    109111/** Returns the dummy flag.
    110112 * @see ETH_DUMMY
    111113 */
    112 #define IS_DUMMY(flags)  ((flags) & ETH_DUMMY)
     114#define IS_DUMMY(flags)         ((flags) & ETH_DUMMY)
    113115
    114116/** Device mode flags.
     
    117119 * @see ETH_8023_2_SNAP
    118120 */
    119 #define ETH_MODE_MASK  (3 << ETH_MODE_SHIFT)
     121#define ETH_MODE_MASK           (3 << ETH_MODE_SHIFT)
    120122
    121123/** DIX Ethernet mode flag. */
    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.
     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.
    127129 * @see ETH_DIX
    128  *
    129  */
    130 #define IS_DIX(flags)  (((flags) & ETH_MODE_MASK) == ETH_DIX)
     130 */
     131#define IS_DIX(flags)           (((flags) & ETH_MODE_MASK) == ETH_DIX)
    131132
    132133/** 802.3 + 802.2 + LSAP mode flag. */
    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.
     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.
    138139 * @see ETH_8023_2_LSAP
    139  *
    140  */
    141 #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)
    142142
    143143/** 802.3 + 802.2 + LSAP + SNAP mode flag. */
    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.
     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.
    149149 * @see ETH_8023_2_SNAP
    150  *
    151  */
    152 #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)
    153152
    154153/** Type definition of the ethernet address type.
     
    247246                        rc = packet_translate_remote(eth_globals.net_phone,
    248247                            &packet, IPC_GET_PACKET(*icall));
    249                         if (rc == EOK)
     248                        if (rc == EOK) {
    250249                                rc = nil_received_msg_local(0,
    251250                                    IPC_GET_DEVICE(*icall), packet, 0);
    252                        
     251                        }
    253252                        ipc_answer_0(iid, (sysarg_t) rc);
    254253                        break;
     
    837836}
    838837
    839 int nil_module_message(ipc_callid_t callid, ipc_call_t *call,
    840     ipc_call_t *answer, size_t *answer_count)
     838int nil_message_standalone(const char *name, ipc_callid_t callid,
     839    ipc_call_t *call, ipc_call_t *answer, size_t *answer_count)
    841840{
    842841        measured_string_t *address;
     
    894893}
    895894
     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 */
     900static 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
    896936int main(int argc, char *argv[])
    897937{
     938        int rc;
     939       
    898940        /* Start the module */
    899         return nil_module_start(SERVICE_ETHERNET);
     941        rc = nil_module_start_standalone(nil_client_connection);
     942        return rc;
    900943}
    901944
Note: See TracChangeset for help on using the changeset viewer.