Changes in uspace/srv/net/nil/eth/eth.c [ffa2c8ef:61bfc370] in mainline
- File:
-
- 1 edited
-
uspace/srv/net/nil/eth/eth.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/nil/eth/eth.c
rffa2c8ef r61bfc370 43 43 #include <str.h> 44 44 #include <errno.h> 45 #include <ipc/nil.h> 45 46 #include <ipc/ipc.h> 46 47 #include <ipc/net.h> 47 48 #include <ipc/services.h> 49 48 50 #include <net/modules.h> 49 51 #include <net_checksum.h> … … 52 54 #include <protocol_map.h> 53 55 #include <net/device.h> 54 #include <netif_ remote.h>56 #include <netif_interface.h> 55 57 #include <net_interface.h> 56 #include <il_remote.h> 58 #include <nil_interface.h> 59 #include <il_interface.h> 57 60 #include <adt/measured_strings.h> 58 61 #include <packet_client.h> 59 62 #include <packet_remote.h> 60 #include <nil_ skel.h>63 #include <nil_local.h> 61 64 62 65 #include "eth.h" 66 #include "eth_header.h" 63 67 64 68 /** The module name. */ … … 68 72 #define ETH_PREFIX \ 69 73 (sizeof(eth_header_t) + sizeof(eth_header_lsap_t) + \ 70 sizeof(eth_header_snap_t))74 sizeof(eth_header_snap_t)) 71 75 72 76 /** Reserved packet suffix length. */ 73 #define ETH_SUFFIX (sizeof(eth_fcs_t)) 77 #define ETH_SUFFIX \ 78 sizeof(eth_fcs_t) 74 79 75 80 /** Maximum packet content length. */ 76 #define ETH_MAX_CONTENT 1500u81 #define ETH_MAX_CONTENT 1500u 77 82 78 83 /** Minimum packet content length. */ 79 #define ETH_MIN_CONTENT 46u84 #define ETH_MIN_CONTENT 46u 80 85 81 86 /** Maximum tagged packet content length. */ 82 87 #define ETH_MAX_TAGGED_CONTENT(flags) \ 83 88 (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)) 87 92 88 93 /** Minimum tagged packet content length. */ 89 94 #define ETH_MIN_TAGGED_CONTENT(flags) \ 90 95 (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)) 94 99 95 100 /** Dummy flag shift value. */ 96 #define ETH_DUMMY_SHIFT 0101 #define ETH_DUMMY_SHIFT 0 97 102 98 103 /** Mode flag shift value. */ 99 #define ETH_MODE_SHIFT 1104 #define ETH_MODE_SHIFT 1 100 105 101 106 /** Dummy device flag. 102 107 * Preamble and FCS are mandatory part of the packets. 103 108 */ 104 #define ETH_DUMMY (1 << ETH_DUMMY_SHIFT)109 #define ETH_DUMMY (1 << ETH_DUMMY_SHIFT) 105 110 106 111 /** Returns the dummy flag. 107 112 * @see ETH_DUMMY 108 113 */ 109 #define IS_DUMMY(flags) ((flags) & ETH_DUMMY)114 #define IS_DUMMY(flags) ((flags) & ETH_DUMMY) 110 115 111 116 /** Device mode flags. … … 114 119 * @see ETH_8023_2_SNAP 115 120 */ 116 #define ETH_MODE_MASK (3 << ETH_MODE_SHIFT)121 #define ETH_MODE_MASK (3 << ETH_MODE_SHIFT) 117 122 118 123 /** 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. 124 129 * @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) 128 132 129 133 /** 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. 135 139 * @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) 139 142 140 143 /** 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. 146 149 * @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) 150 152 151 153 /** Type definition of the ethernet address type. … … 237 239 switch (IPC_GET_IMETHOD(*icall)) { 238 240 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);241 nil_device_state_msg_local(0, IPC_GET_DEVICE(icall), 242 IPC_GET_STATE(icall)); 243 ipc_answer_0(iid, EOK); 242 244 break; 243 245 case NET_NIL_RECEIVED: 244 246 rc = packet_translate_remote(eth_globals.net_phone, 245 &packet, IPC_GET_PACKET( *icall));246 if (rc == EOK) 247 &packet, IPC_GET_PACKET(icall)); 248 if (rc == EOK) { 247 249 rc = nil_received_msg_local(0, 248 IPC_GET_DEVICE( *icall), packet, 0);249 250 async_answer_0(iid, (sysarg_t) rc);250 IPC_GET_DEVICE(icall), packet, 0); 251 } 252 ipc_answer_0(iid, (sysarg_t) rc); 251 253 break; 252 254 default: 253 async_answer_0(iid, (sysarg_t) ENOTSUP);255 ipc_answer_0(iid, (sysarg_t) ENOTSUP); 254 256 } 255 257 … … 834 836 } 835 837 836 int nil_m odule_message(ipc_callid_t callid, ipc_call_t *call,837 ipc_call_t * answer, size_t *answer_count)838 int nil_message_standalone(const char *name, ipc_callid_t callid, 839 ipc_call_t *call, ipc_call_t *answer, int *answer_count) 838 840 { 839 841 measured_string_t *address; … … 851 853 852 854 case NET_NIL_DEVICE: 853 return eth_device_message(IPC_GET_DEVICE( *call),854 IPC_GET_SERVICE( *call), IPC_GET_MTU(*call));855 return eth_device_message(IPC_GET_DEVICE(call), 856 IPC_GET_SERVICE(call), IPC_GET_MTU(call)); 855 857 case NET_NIL_SEND: 856 858 rc = packet_translate_remote(eth_globals.net_phone, &packet, 857 IPC_GET_PACKET( *call));859 IPC_GET_PACKET(call)); 858 860 if (rc != EOK) 859 861 return rc; 860 return eth_send_message(IPC_GET_DEVICE( *call), packet,861 IPC_GET_SERVICE( *call));862 return eth_send_message(IPC_GET_DEVICE(call), packet, 863 IPC_GET_SERVICE(call)); 862 864 case NET_NIL_PACKET_SPACE: 863 rc = eth_packet_space_message(IPC_GET_DEVICE( *call), &addrlen,865 rc = eth_packet_space_message(IPC_GET_DEVICE(call), &addrlen, 864 866 &prefix, &content, &suffix); 865 867 if (rc != EOK) 866 868 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);869 IPC_SET_ADDR(answer, addrlen); 870 IPC_SET_PREFIX(answer, prefix); 871 IPC_SET_CONTENT(answer, content); 872 IPC_SET_SUFFIX(answer, suffix); 871 873 *answer_count = 4; 872 874 return EOK; 873 875 case NET_NIL_ADDR: 874 rc = eth_addr_message(IPC_GET_DEVICE( *call), ETH_LOCAL_ADDR,876 rc = eth_addr_message(IPC_GET_DEVICE(call), ETH_LOCAL_ADDR, 875 877 &address); 876 878 if (rc != EOK) … … 878 880 return measured_strings_reply(address, 1); 879 881 case NET_NIL_BROADCAST_ADDR: 880 rc = eth_addr_message(IPC_GET_DEVICE( *call), ETH_BROADCAST_ADDR,882 rc = eth_addr_message(IPC_GET_DEVICE(call), ETH_BROADCAST_ADDR, 881 883 &address); 882 884 if (rc != EOK) … … 884 886 return measured_strings_reply(address, 1); 885 887 case IPC_M_CONNECT_TO_ME: 886 return eth_register_message(NIL_GET_PROTO( *call),887 IPC_GET_PHONE( *call));888 return eth_register_message(NIL_GET_PROTO(call), 889 IPC_GET_PHONE(call)); 888 890 } 889 891 … … 891 893 } 892 894 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 int answer_count; 911 912 /* Clear the answer structure */ 913 refresh_answer(&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, &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, answer_count); 933 } 934 } 935 893 936 int main(int argc, char *argv[]) 894 937 { 938 int rc; 939 895 940 /* Start the module */ 896 return nil_module_start(SERVICE_ETHERNET); 941 rc = nil_module_start_standalone(nil_client_connection); 942 return rc; 897 943 } 898 944
Note:
See TracChangeset
for help on using the changeset viewer.
