Changes in uspace/srv/net/nil/eth/eth.c [797b704:7837101] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified uspace/srv/net/nil/eth/eth.c ¶
r797b704 r7837101 45 45 46 46 #include <ipc/ipc.h> 47 #include <ipc/nil.h>48 47 #include <ipc/net.h> 49 48 #include <ipc/services.h> … … 55 54 #include <protocol_map.h> 56 55 #include <net/device.h> 57 #include <netif_ remote.h>56 #include <netif_interface.h> 58 57 #include <net_interface.h> 59 #include <il_remote.h> 58 #include <nil_interface.h> 59 #include <il_interface.h> 60 60 #include <adt/measured_strings.h> 61 61 #include <packet_client.h> 62 62 #include <packet_remote.h> 63 #include <nil_ skel.h>63 #include <nil_local.h> 64 64 65 65 #include "eth.h" 66 #include "eth_header.h" 66 67 67 68 /** The module name. */ … … 71 72 #define ETH_PREFIX \ 72 73 (sizeof(eth_header_t) + sizeof(eth_header_lsap_t) + \ 73 74 sizeof(eth_header_snap_t)) 74 75 75 76 /** Reserved packet suffix length. */ 76 #define ETH_SUFFIX (sizeof(eth_fcs_t)) 77 #define ETH_SUFFIX \ 78 sizeof(eth_fcs_t) 77 79 78 80 /** Maximum packet content length. */ 79 #define ETH_MAX_CONTENT 81 #define ETH_MAX_CONTENT 1500u 80 82 81 83 /** Minimum packet content length. */ 82 #define ETH_MIN_CONTENT 84 #define ETH_MIN_CONTENT 46u 83 85 84 86 /** Maximum tagged packet content length. */ 85 87 #define ETH_MAX_TAGGED_CONTENT(flags) \ 86 88 (ETH_MAX_CONTENT - \ 87 88 89 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)) 90 92 91 93 /** Minimum tagged packet content length. */ 92 94 #define ETH_MIN_TAGGED_CONTENT(flags) \ 93 95 (ETH_MIN_CONTENT - \ 94 95 96 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)) 97 99 98 100 /** Dummy flag shift value. */ 99 #define ETH_DUMMY_SHIFT 101 #define ETH_DUMMY_SHIFT 0 100 102 101 103 /** Mode flag shift value. */ 102 #define ETH_MODE_SHIFT 104 #define ETH_MODE_SHIFT 1 103 105 104 106 /** Dummy device flag. 105 107 * Preamble and FCS are mandatory part of the packets. 106 108 */ 107 #define ETH_DUMMY 109 #define ETH_DUMMY (1 << ETH_DUMMY_SHIFT) 108 110 109 111 /** Returns the dummy flag. 110 112 * @see ETH_DUMMY 111 113 */ 112 #define IS_DUMMY(flags) 114 #define IS_DUMMY(flags) ((flags) & ETH_DUMMY) 113 115 114 116 /** Device mode flags. … … 117 119 * @see ETH_8023_2_SNAP 118 120 */ 119 #define ETH_MODE_MASK 121 #define ETH_MODE_MASK (3 << ETH_MODE_SHIFT) 120 122 121 123 /** DIX Ethernet mode flag. */ 122 #define ETH_DIX 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. 127 129 * @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) 131 132 132 133 /** 802.3 + 802.2 + LSAP mode flag. */ 133 #define ETH_8023_2_LSAP 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. 138 139 * @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) 142 142 143 143 /** 802.3 + 802.2 + LSAP + SNAP mode flag. */ 144 #define ETH_8023_2_SNAP 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. 149 149 * @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) 153 152 154 153 /** Type definition of the ethernet address type. … … 202 201 203 202 eth_globals.broadcast_addr = 204 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", ETH_ADDR); 205 204 if (!eth_globals.broadcast_addr) { 206 205 rc = ENOMEM; … … 240 239 switch (IPC_GET_IMETHOD(*icall)) { 241 240 case NET_NIL_DEVICE_STATE: 242 nil_device_state_msg_local(0, IPC_GET_DEVICE( *icall),243 IPC_GET_STATE( *icall));241 nil_device_state_msg_local(0, IPC_GET_DEVICE(icall), 242 IPC_GET_STATE(icall)); 244 243 ipc_answer_0(iid, EOK); 245 244 break; 246 245 case NET_NIL_RECEIVED: 247 246 rc = packet_translate_remote(eth_globals.net_phone, 248 &packet, IPC_GET_PACKET( *icall));249 if (rc == EOK) 247 &packet, IPC_GET_PACKET(icall)); 248 if (rc == EOK) { 250 249 rc = nil_received_msg_local(0, 251 IPC_GET_DEVICE( *icall), packet, 0);252 250 IPC_GET_DEVICE(icall), packet, 0); 251 } 253 252 ipc_answer_0(iid, (sysarg_t) rc); 254 253 break; … … 285 284 measured_string_t names[2] = { 286 285 { 287 ( uint8_t*) "ETH_MODE",286 (char *) "ETH_MODE", 288 287 8 289 288 }, 290 289 { 291 ( uint8_t*) "ETH_DUMMY",290 (char *) "ETH_DUMMY", 292 291 9 293 292 } … … 295 294 measured_string_t *configuration; 296 295 size_t count = sizeof(names) / sizeof(measured_string_t); 297 uint8_t*data;296 char *data; 298 297 eth_proto_t *proto; 299 298 int rc; … … 359 358 360 359 if (configuration) { 361 if (!str_lcmp( (char *)configuration[0].value, "DIX",360 if (!str_lcmp(configuration[0].value, "DIX", 362 361 configuration[0].length)) { 363 362 device->flags |= ETH_DIX; 364 } else if(!str_lcmp( (char *)configuration[0].value, "8023_2_LSAP",363 } else if(!str_lcmp(configuration[0].value, "8023_2_LSAP", 365 364 configuration[0].length)) { 366 365 device->flags |= ETH_8023_2_LSAP; … … 408 407 409 408 printf("%s: Device registered (id: %d, service: %d: mtu: %zu, " 410 "mac: % 02x:%02x:%02x:%02x:%02x:%02x, flags: 0x%x)\n",409 "mac: %x:%x:%x:%x:%x:%x, flags: 0x%x)\n", 411 410 NAME, device->device_id, device->service, device->mtu, 412 411 device->addr_data[0], device->addr_data[1], … … 837 836 } 838 837 839 int nil_m odule_message(ipc_callid_t callid, ipc_call_t *call,840 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) 841 840 { 842 841 measured_string_t *address; … … 854 853 855 854 case NET_NIL_DEVICE: 856 return eth_device_message(IPC_GET_DEVICE( *call),857 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)); 858 857 case NET_NIL_SEND: 859 858 rc = packet_translate_remote(eth_globals.net_phone, &packet, 860 IPC_GET_PACKET( *call));859 IPC_GET_PACKET(call)); 861 860 if (rc != EOK) 862 861 return rc; 863 return eth_send_message(IPC_GET_DEVICE( *call), packet,864 IPC_GET_SERVICE( *call));862 return eth_send_message(IPC_GET_DEVICE(call), packet, 863 IPC_GET_SERVICE(call)); 865 864 case NET_NIL_PACKET_SPACE: 866 rc = eth_packet_space_message(IPC_GET_DEVICE( *call), &addrlen,865 rc = eth_packet_space_message(IPC_GET_DEVICE(call), &addrlen, 867 866 &prefix, &content, &suffix); 868 867 if (rc != EOK) 869 868 return rc; 870 IPC_SET_ADDR( *answer, addrlen);871 IPC_SET_PREFIX( *answer, prefix);872 IPC_SET_CONTENT( *answer, content);873 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); 874 873 *answer_count = 4; 875 874 return EOK; 876 875 case NET_NIL_ADDR: 877 rc = eth_addr_message(IPC_GET_DEVICE( *call), ETH_LOCAL_ADDR,876 rc = eth_addr_message(IPC_GET_DEVICE(call), ETH_LOCAL_ADDR, 878 877 &address); 879 878 if (rc != EOK) … … 881 880 return measured_strings_reply(address, 1); 882 881 case NET_NIL_BROADCAST_ADDR: 883 rc = eth_addr_message(IPC_GET_DEVICE( *call), ETH_BROADCAST_ADDR,882 rc = eth_addr_message(IPC_GET_DEVICE(call), ETH_BROADCAST_ADDR, 884 883 &address); 885 884 if (rc != EOK) … … 887 886 return measured_strings_reply(address, 1); 888 887 case IPC_M_CONNECT_TO_ME: 889 return eth_register_message(NIL_GET_PROTO( *call),890 IPC_GET_PHONE( *call));888 return eth_register_message(NIL_GET_PROTO(call), 889 IPC_GET_PHONE(call)); 891 890 } 892 891 … … 894 893 } 895 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 896 936 int main(int argc, char *argv[]) 897 937 { 938 int rc; 939 898 940 /* Start the module */ 899 return nil_module_start(SERVICE_ETHERNET); 941 rc = nil_module_start_standalone(nil_client_connection); 942 return rc; 900 943 } 901 944
Note:
See TracChangeset
for help on using the changeset viewer.