Changeset 8b5690f in mainline for uspace/srv/net/nil/eth/eth.c
- Timestamp:
- 2011-02-03T05:11:01Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ba38f72c
- Parents:
- 22027b6e (diff), 86d7bfa (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/nil/eth/eth.c
r22027b6e r8b5690f 43 43 #include <str.h> 44 44 #include <errno.h> 45 46 #include <ipc/ipc.h> 45 #include <ipc/nil.h> 47 46 #include <ipc/net.h> 48 47 #include <ipc/services.h> 49 50 48 #include <net/modules.h> 51 49 #include <net_checksum.h> … … 54 52 #include <protocol_map.h> 55 53 #include <net/device.h> 56 #include <netif_ interface.h>54 #include <netif_remote.h> 57 55 #include <net_interface.h> 58 #include <nil_interface.h> 59 #include <il_interface.h> 56 #include <il_remote.h> 60 57 #include <adt/measured_strings.h> 61 58 #include <packet_client.h> 62 59 #include <packet_remote.h> 63 #include <nil_ local.h>60 #include <nil_skel.h> 64 61 65 62 #include "eth.h" 66 #include "eth_header.h"67 63 68 64 /** The module name. */ … … 72 68 #define ETH_PREFIX \ 73 69 (sizeof(eth_header_t) + sizeof(eth_header_lsap_t) + \ 74 sizeof(eth_header_snap_t))70 sizeof(eth_header_snap_t)) 75 71 76 72 /** Reserved packet suffix length. */ 77 #define ETH_SUFFIX \ 78 sizeof(eth_fcs_t) 73 #define ETH_SUFFIX (sizeof(eth_fcs_t)) 79 74 80 75 /** Maximum packet content length. */ 81 #define ETH_MAX_CONTENT 1500u76 #define ETH_MAX_CONTENT 1500u 82 77 83 78 /** Minimum packet content length. */ 84 #define ETH_MIN_CONTENT 46u79 #define ETH_MIN_CONTENT 46u 85 80 86 81 /** Maximum tagged packet content length. */ 87 82 #define ETH_MAX_TAGGED_CONTENT(flags) \ 88 83 (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))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)) 92 87 93 88 /** Minimum tagged packet content length. */ 94 89 #define ETH_MIN_TAGGED_CONTENT(flags) \ 95 90 (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))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)) 99 94 100 95 /** Dummy flag shift value. */ 101 #define ETH_DUMMY_SHIFT 96 #define ETH_DUMMY_SHIFT 0 102 97 103 98 /** Mode flag shift value. */ 104 #define ETH_MODE_SHIFT 99 #define ETH_MODE_SHIFT 1 105 100 106 101 /** Dummy device flag. 107 102 * Preamble and FCS are mandatory part of the packets. 108 103 */ 109 #define ETH_DUMMY 104 #define ETH_DUMMY (1 << ETH_DUMMY_SHIFT) 110 105 111 106 /** Returns the dummy flag. 112 107 * @see ETH_DUMMY 113 108 */ 114 #define IS_DUMMY(flags) 109 #define IS_DUMMY(flags) ((flags) & ETH_DUMMY) 115 110 116 111 /** Device mode flags. … … 119 114 * @see ETH_8023_2_SNAP 120 115 */ 121 #define ETH_MODE_MASK 116 #define ETH_MODE_MASK (3 << ETH_MODE_SHIFT) 122 117 123 118 /** DIX Ethernet mode flag. */ 124 #define ETH_DIX 125 126 /** Return swhether the DIX Ethernet mode flag is set.127 * 128 * @param[in] flags The ethernet flags.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. 129 124 * @see ETH_DIX 130 */ 131 #define IS_DIX(flags) (((flags) & ETH_MODE_MASK) == ETH_DIX) 125 * 126 */ 127 #define IS_DIX(flags) (((flags) & ETH_MODE_MASK) == ETH_DIX) 132 128 133 129 /** 802.3 + 802.2 + LSAP mode flag. */ 134 #define ETH_8023_2_LSAP 135 136 /** Return swhether the 802.3 + 802.2 + LSAP mode flag is set.137 * 138 * @param[in] flags The ethernet flags.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. 139 135 * @see ETH_8023_2_LSAP 140 */ 141 #define IS_8023_2_LSAP(flags) (((flags) & ETH_MODE_MASK) == ETH_8023_2_LSAP) 136 * 137 */ 138 #define IS_8023_2_LSAP(flags) (((flags) & ETH_MODE_MASK) == ETH_8023_2_LSAP) 142 139 143 140 /** 802.3 + 802.2 + LSAP + SNAP mode flag. */ 144 #define ETH_8023_2_SNAP 145 146 /** Return swhether the 802.3 + 802.2 + LSAP + SNAP mode flag is set.147 * 148 * @param[in] flags The ethernet flags.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. 149 146 * @see ETH_8023_2_SNAP 150 */ 151 #define IS_8023_2_SNAP(flags) (((flags) & ETH_MODE_MASK) == ETH_8023_2_SNAP) 147 * 148 */ 149 #define IS_8023_2_SNAP(flags) (((flags) & ETH_MODE_MASK) == ETH_8023_2_SNAP) 152 150 153 151 /** Type definition of the ethernet address type. … … 239 237 switch (IPC_GET_IMETHOD(*icall)) { 240 238 case NET_NIL_DEVICE_STATE: 241 nil_device_state_msg_local(0, IPC_GET_DEVICE( icall),242 IPC_GET_STATE( icall));243 ipc_answer_0(iid, EOK);239 nil_device_state_msg_local(0, IPC_GET_DEVICE(*icall), 240 IPC_GET_STATE(*icall)); 241 async_answer_0(iid, EOK); 244 242 break; 245 243 case NET_NIL_RECEIVED: 246 244 rc = packet_translate_remote(eth_globals.net_phone, 247 &packet, IPC_GET_PACKET( icall));248 if (rc == EOK) {245 &packet, IPC_GET_PACKET(*icall)); 246 if (rc == EOK) 249 247 rc = nil_received_msg_local(0, 250 IPC_GET_DEVICE( icall), packet, 0);251 }252 ipc_answer_0(iid, (sysarg_t) rc);248 IPC_GET_DEVICE(*icall), packet, 0); 249 250 async_answer_0(iid, (sysarg_t) rc); 253 251 break; 254 252 default: 255 ipc_answer_0(iid, (sysarg_t) ENOTSUP);253 async_answer_0(iid, (sysarg_t) ENOTSUP); 256 254 } 257 255 … … 836 834 } 837 835 838 int nil_m essage_standalone(const char *name, ipc_callid_t callid,839 ipc_call_t * call, ipc_call_t *answer, int *answer_count)836 int nil_module_message(ipc_callid_t callid, ipc_call_t *call, 837 ipc_call_t *answer, size_t *answer_count) 840 838 { 841 839 measured_string_t *address; … … 853 851 854 852 case NET_NIL_DEVICE: 855 return eth_device_message(IPC_GET_DEVICE( call),856 IPC_GET_SERVICE( call), IPC_GET_MTU(call));853 return eth_device_message(IPC_GET_DEVICE(*call), 854 IPC_GET_SERVICE(*call), IPC_GET_MTU(*call)); 857 855 case NET_NIL_SEND: 858 856 rc = packet_translate_remote(eth_globals.net_phone, &packet, 859 IPC_GET_PACKET( call));857 IPC_GET_PACKET(*call)); 860 858 if (rc != EOK) 861 859 return rc; 862 return eth_send_message(IPC_GET_DEVICE( call), packet,863 IPC_GET_SERVICE( call));860 return eth_send_message(IPC_GET_DEVICE(*call), packet, 861 IPC_GET_SERVICE(*call)); 864 862 case NET_NIL_PACKET_SPACE: 865 rc = eth_packet_space_message(IPC_GET_DEVICE( call), &addrlen,863 rc = eth_packet_space_message(IPC_GET_DEVICE(*call), &addrlen, 866 864 &prefix, &content, &suffix); 867 865 if (rc != EOK) 868 866 return rc; 869 IPC_SET_ADDR( answer, addrlen);870 IPC_SET_PREFIX( answer, prefix);871 IPC_SET_CONTENT( answer, content);872 IPC_SET_SUFFIX( answer, suffix);867 IPC_SET_ADDR(*answer, addrlen); 868 IPC_SET_PREFIX(*answer, prefix); 869 IPC_SET_CONTENT(*answer, content); 870 IPC_SET_SUFFIX(*answer, suffix); 873 871 *answer_count = 4; 874 872 return EOK; 875 873 case NET_NIL_ADDR: 876 rc = eth_addr_message(IPC_GET_DEVICE( call), ETH_LOCAL_ADDR,874 rc = eth_addr_message(IPC_GET_DEVICE(*call), ETH_LOCAL_ADDR, 877 875 &address); 878 876 if (rc != EOK) … … 880 878 return measured_strings_reply(address, 1); 881 879 case NET_NIL_BROADCAST_ADDR: 882 rc = eth_addr_message(IPC_GET_DEVICE( call), ETH_BROADCAST_ADDR,880 rc = eth_addr_message(IPC_GET_DEVICE(*call), ETH_BROADCAST_ADDR, 883 881 &address); 884 882 if (rc != EOK) … … 886 884 return measured_strings_reply(address, 1); 887 885 case IPC_M_CONNECT_TO_ME: 888 return eth_register_message(NIL_GET_PROTO( call),889 IPC_GET_PHONE( call));886 return eth_register_message(NIL_GET_PROTO(*call), 887 IPC_GET_PHONE(*call)); 890 888 } 891 889 … … 893 891 } 894 892 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 connection904 * - 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 processing925 * 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 936 893 int main(int argc, char *argv[]) 937 894 { 938 int rc;939 940 895 /* Start the module */ 941 rc = nil_module_start_standalone(nil_client_connection); 942 return rc; 896 return nil_module_start(SERVICE_ETHERNET); 943 897 } 944 898
Note:
See TracChangeset
for help on using the changeset viewer.