Changeset fe8dfa6 in mainline
- Timestamp:
- 2011-01-11T15:57:39Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 77429d3
- Parents:
- 04aade50
- Location:
- uspace
- Files:
-
- 1 added
- 4 deleted
- 15 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/Makefile
r04aade50 rfe8dfa6 43 43 netif/netif_skel.c \ 44 44 nil/nil_remote.c \ 45 nil/nil_skel.c \ 45 46 il/il_interface.c \ 46 47 il/ip_remote.c \ -
uspace/lib/net/include/nil_remote.h
r04aade50 rfe8dfa6 37 37 #include <net/device.h> 38 38 #include <net/packet.h> 39 #include <generic.h> 39 40 40 extern int nil_device_state_msg_remote(int, device_id_t, int); 41 extern int nil_received_msg_remote(int, device_id_t, packet_t *, services_t); 41 #define nil_bind_service(service, device_id, me, receiver) \ 42 bind_service(service, device_id, me, 0, receiver) 43 44 #define nil_packet_size_req(nil_phone, device_id, packet_dimension) \ 45 generic_packet_size_req_remote(nil_phone, NET_NIL_PACKET_SPACE, \ 46 device_id, packet_dimension) 47 48 #define nil_get_addr_req(nil_phone, device_id, address, data) \ 49 generic_get_addr_req(nil_phone, NET_NIL_ADDR, device_id, address, data) 50 51 #define nil_get_broadcast_addr_req(nil_phone, device_id, address, data) \ 52 generic_get_addr_req(nil_phone, NET_NIL_BROADCAST_ADDR, device_id, \ 53 address, data) 54 55 #define nil_send_msg(nil_phone, device_id, packet, sender) \ 56 generic_send_msg_remote(nil_phone, NET_NIL_SEND, device_id, \ 57 packet_get_id(packet), sender, 0) 58 59 #define nil_device_req(nil_phone, device_id, mtu, netif_service) \ 60 generic_device_req_remote(nil_phone, NET_NIL_DEVICE, device_id, mtu, \ 61 netif_service) 62 63 extern int nil_device_state_msg(int, device_id_t, int); 64 extern int nil_received_msg(int, device_id_t, packet_t *, services_t); 42 65 43 66 #endif -
uspace/lib/net/netif/netif_skel.c
r04aade50 rfe8dfa6 33 33 /** @file 34 34 * Network interface module skeleton implementation. 35 * @see netif .h35 * @see netif_skel.h 36 36 */ 37 37 … … 52 52 #include <adt/measured_strings.h> 53 53 #include <net/device.h> 54 #include <nil_interface.h>55 54 #include <netif_skel.h> 55 #include <nil_remote.h> 56 56 57 57 DEVICE_MAP_IMPLEMENT(netif_device_map, netif_device_t); -
uspace/lib/net/nil/nil_remote.c
r04aade50 rfe8dfa6 33 33 /** @file 34 34 * Network interface layer interface implementation for remote modules. 35 * @see nil_ interface.h35 * @see nil_remote.h 36 36 */ 37 37 38 38 #include <nil_remote.h> 39 #include <nil_interface.h>40 39 #include <generic.h> 41 40 #include <net/device.h> 42 41 #include <net/packet.h> 43 42 #include <packet_client.h> 44 45 43 #include <ipc/nil.h> 46 44 47 45 /** Notify the network interface layer about the device state change. 48 46 * 49 * @param[in] nil_phone The network interface layer phone. 50 * @param[in] device_id The device identifier. 51 * @param[in] state The new device state. 52 * @return EOK on success. 53 * @return Other error codes as defined for each specific module 54 * device state function. 47 * @param[in] nil_phone Network interface layer phone. 48 * @param[in] device_id Device identifier. 49 * @param[in] state New device state. 50 * 51 * @return EOK on success. 52 * @return Other error codes as defined for each specific module 53 * device state function. 54 * 55 55 */ 56 int nil_device_state_msg _remote(int nil_phone, device_id_t device_id, int state)56 int nil_device_state_msg(int nil_phone, device_id_t device_id, int state) 57 57 { 58 58 return generic_device_state_msg_remote(nil_phone, NET_NIL_DEVICE_STATE, … … 65 65 * upper layers. 66 66 * 67 * @param[in] nil_phone The network interface layer phone. 68 * @param[in] device_id The source device identifier. 69 * @param[in] packet The received packet or the received packet queue. 70 * @param target The target service. Ignored parameter. 71 * @return EOK on success. 72 * @return Other error codes as defined for each specific module 73 * received function. 67 * @param[in] nil_phone Network interface layer phone. 68 * @param[in] device_id Source device identifier. 69 * @param[in] packet Received packet or the received packet queue. 70 * @param[in] target Target service. Ignored parameter. 71 * 72 * @return EOK on success. 73 * @return Other error codes as defined for each specific module 74 * received function. 75 * 74 76 */ 75 int nil_received_msg _remote(int nil_phone, device_id_t device_id,77 int nil_received_msg(int nil_phone, device_id_t device_id, 76 78 packet_t *packet, services_t target) 77 79 { -
uspace/lib/net/nil/nil_skel.c
r04aade50 rfe8dfa6 27 27 */ 28 28 29 /** @addtogroup nildummy29 /** @addtogroup libnet 30 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Dummy network interface layer module stub.35 * @see module.c34 * Network network interface layer module implementation. 35 * @see nil_skel.h 36 36 */ 37 37 38 #include <async.h> 39 #include <stdio.h> 38 #include <bool.h> 40 39 #include <errno.h> 40 #include <nil_skel.h> 41 #include <net_interface.h> 42 #include <net/modules.h> 41 43 42 #include <ipc/ipc.h> 43 #include <ipc/services.h> 44 /** Default thread for new connections. 45 * 46 * @param[in] iid The initial message identifier. 47 * @param[in] icall The initial message call structure. 48 * 49 */ 50 static void nil_client_connection(ipc_callid_t iid, ipc_call_t *icall) 51 { 52 /* 53 * Accept the connection by answering 54 * the initial IPC_M_CONNECT_ME_TO call. 55 */ 56 ipc_answer_0(iid, EOK); 57 58 while (true) { 59 ipc_call_t answer; 60 size_t count; 61 62 /* Clear the answer structure */ 63 refresh_answer(&answer, &count); 64 65 /* Fetch the next message */ 66 ipc_call_t call; 67 ipc_callid_t callid = async_get_call(&call); 68 69 /* Process the message */ 70 int res = nil_module_message(callid, &call, &answer, 71 &count); 72 73 /* 74 * End if told to either by the message or the processing 75 * result. 76 */ 77 if ((IPC_GET_IMETHOD(call) == IPC_M_PHONE_HUNGUP) || 78 (res == EHANGUP)) 79 return; 80 81 /* Answer the message */ 82 answer_call(callid, res, &answer, count); 83 } 84 } 44 85 45 #include <net/modules.h> 46 #include <net_interface.h> 47 #include <net/packet.h> 48 #include <nil_local.h> 49 50 #include "nildummy.h" 51 52 int nil_module_start_standalone(async_client_conn_t client_connection) 86 /** Start the network interface layer module. 87 * 88 * Initialize the client connection serving function, initialize 89 * the module, register the module service and start the async 90 * manager, processing IPC messages in an infinite loop. 91 * 92 * @param[in] service Service identification. 93 * 94 * @return EOK on success. 95 * @return Other error codes as defined for the pm_init() function. 96 * @return Other error codes as defined for the nil_initialize() 97 * function. 98 * @return Other error codes as defined for the REGISTER_ME() macro 99 * function. 100 * 101 */ 102 int nil_module_start(int service) 53 103 { 54 sysarg_t phonehash; 55 int rc; 56 57 async_set_client_connection(client_connection); 104 async_set_client_connection(nil_client_connection); 58 105 int net_phone = net_connect_module(); 59 106 60 rc = pm_init();107 int rc = pm_init(); 61 108 if (rc != EOK) 62 109 return rc; 63 64 110 65 111 rc = nil_initialize(net_phone); … … 67 113 goto out; 68 114 69 rc = ipc_connect_to_me(PHONE_NS, SERVICE_NILDUMMY, 0, 0, &phonehash); 115 sysarg_t phonehash; 116 rc = ipc_connect_to_me(PHONE_NS, service, 0, 0, &phonehash); 70 117 if (rc != EOK) 71 118 goto out; 72 119 73 120 async_manager(); 74 121 75 122 out: 76 123 pm_destroy(); … … 78 125 } 79 126 80 int nil_module_message_standalone(const char *name, ipc_callid_t callid,81 ipc_call_t *call, ipc_call_t *answer, size_t *count)82 {83 return nil_message_standalone(name, callid, call, answer, count);84 }85 86 127 /** @} 87 128 */ -
uspace/srv/hw/netif/ne2000/ne2000.c
r04aade50 rfe8dfa6 51 51 #include <net/device.h> 52 52 #include <netif_skel.h> 53 #include <nil_ interface.h>53 #include <nil_remote.h> 54 54 #include "dp8390.h" 55 55 … … 346 346 } 347 347 348 return EOK;348 return device->state; 349 349 } 350 350 -
uspace/srv/net/il/arp/arp.c
r04aade50 rfe8dfa6 54 54 #include <ipc/arp.h> 55 55 #include <ipc/il.h> 56 #include <ipc/nil.h> 56 57 #include <byteorder.h> 57 58 #include <errno.h> 58 59 59 #include <net/modules.h> 60 60 #include <net/device.h> 61 61 #include <net/packet.h> 62 63 #include <nil_interface.h> 62 #include <nil_remote.h> 64 63 #include <protocol_map.h> 65 64 #include <packet_client.h> -
uspace/srv/net/il/ip/ip.c
r04aade50 rfe8dfa6 75 75 #include <ip_header.h> 76 76 #include <net_interface.h> 77 #include <nil_ interface.h>77 #include <nil_remote.h> 78 78 #include <tl_interface.h> 79 79 #include <packet_remote.h> -
uspace/srv/net/net/net.c
r04aade50 rfe8dfa6 51 51 #include <ipc/net_net.h> 52 52 #include <ipc/il.h> 53 #include <ipc/nil.h> 53 54 54 55 #include <net/modules.h> … … 62 63 63 64 #include <netif_remote.h> 64 #include <nil_ interface.h>65 #include <nil_remote.h> 65 66 #include <net_interface.h> 66 67 #include <ip_interface.h> -
uspace/srv/net/netif/lo/lo.c
r04aade50 rfe8dfa6 48 48 #include <packet_client.h> 49 49 #include <net/device.h> 50 #include <nil_interface.h>51 50 #include <netif_skel.h> 52 53 /** Default hardware address. */ 54 #define DEFAULT_ADDR 0 51 #include <nil_remote.h> 55 52 56 53 /** Default address length. */ … … 60 57 #define NAME "lo" 61 58 62 /** Network interface global data. */ 63 netif_globals_t netif_globals;59 static uint8_t default_addr[DEFAULT_ADDR_LEN] = 60 {0, 0, 0, 0, 0, 0}; 64 61 65 62 int netif_specific_message(ipc_callid_t callid, ipc_call_t *call, … … 74 71 return EBADMEM; 75 72 76 uint8_t *addr = (uint8_t *) malloc(DEFAULT_ADDR_LEN); 77 memset(addr, DEFAULT_ADDR, DEFAULT_ADDR_LEN); 78 79 address->value = addr; 73 address->value = default_addr; 80 74 address->length = DEFAULT_ADDR_LEN; 81 75 … … 85 79 int netif_get_device_stats(device_id_t device_id, device_stats_t *stats) 86 80 { 87 netif_device_t *device;88 int rc;89 90 81 if (!stats) 91 82 return EBADMEM; 92 93 rc = find_device(device_id, &device); 83 84 netif_device_t *device; 85 int rc = find_device(device_id, &device); 94 86 if (rc != EOK) 95 87 return rc; 96 88 97 89 memcpy(stats, (device_stats_t *) device->specific, 98 90 sizeof(device_stats_t)); 99 100 return EOK; 101 } 102 103 /** Changes the loopback state. 104 * 105 * @param[in] device The device structure. 106 * @param[in] state The new device state. 107 * @return The new state if changed. 108 * @return EOK otherwise. 109 */ 110 static int change_state_message(netif_device_t *device, device_state_t state) 91 92 return EOK; 93 } 94 95 /** Change the loopback state. 96 * 97 * @param[in] device The device structure. 98 * @param[in] state The new device state. 99 * 100 * @return New state if changed. 101 * @return EOK otherwise. 102 * 103 */ 104 static void change_state_message(netif_device_t *device, device_state_t state) 111 105 { 112 106 if (device->state != state) { 113 107 device->state = state; 114 108 115 printf("%s: State changed to %s\n", NAME, 116 (state == NETIF_ACTIVE) ? "active" : "stopped"); 109 const char *desc; 110 switch (state) { 111 case NETIF_ACTIVE: 112 desc = "active"; 113 break; 114 case NETIF_STOPPED: 115 desc = "stopped"; 116 break; 117 default: 118 desc = "unknown"; 119 } 117 120 118 return state; 119 } 120 121 return EOK; 122 } 123 124 /** Creates and returns the loopback network interface structure. 125 * 126 * @param[in] device_id The new devce identifier. 127 * @param[out] device The device structure. 128 * @return EOK on success. 129 * @return EXDEV if one loopback network interface already exists. 130 * @return ENOMEM if there is not enough memory left. 131 */ 132 static int create(device_id_t device_id, netif_device_t **device) 133 { 134 int index; 135 121 printf("%s: State changed to %s\n", NAME, desc); 122 } 123 } 124 125 /** Create and return the loopback network interface structure. 126 * 127 * @param[in] device_id New devce identifier. 128 * @param[out] device Device structure. 129 * 130 * @return EOK on success. 131 * @return EXDEV if one loopback network interface already exists. 132 * @return ENOMEM if there is not enough memory left. 133 * 134 */ 135 static int lo_create(device_id_t device_id, netif_device_t **device) 136 { 136 137 if (netif_device_map_count(&netif_globals.device_map) > 0) 137 138 return EXDEV; 138 139 139 140 *device = (netif_device_t *) malloc(sizeof(netif_device_t)); 140 141 if (!*device) 141 142 return ENOMEM; 142 143 143 144 (*device)->specific = (device_stats_t *) malloc(sizeof(device_stats_t)); 144 145 if (!(*device)->specific) { … … 146 147 return ENOMEM; 147 148 } 148 149 149 150 null_device_stats((device_stats_t *) (*device)->specific); 150 151 (*device)->device_id = device_id; 151 152 (*device)->nil_phone = -1; 152 153 (*device)->state = NETIF_STOPPED; 153 in dex = netif_device_map_add(&netif_globals.device_map,154 int index = netif_device_map_add(&netif_globals.device_map, 154 155 (*device)->device_id, *device); 155 156 156 157 if (index < 0) { 157 158 free(*device); … … 167 168 { 168 169 sysarg_t phonehash; 169 170 170 return ipc_connect_to_me(PHONE_NS, SERVICE_LO, 0, 0, &phonehash); 171 171 } … … 173 173 int netif_probe_message(device_id_t device_id, int irq, void *io) 174 174 { 175 /* Create a new device */ 175 176 netif_device_t *device; 176 int rc; 177 178 /* Create a new device */ 179 rc = create(device_id, &device); 177 int rc = lo_create(device_id, &device); 180 178 if (rc != EOK) 181 179 return rc; 182 183 /* Print the settings */ 180 184 181 printf("%s: Device created (id: %d)\n", NAME, device->device_id); 185 186 182 return EOK; 187 183 } … … 190 186 { 191 187 netif_device_t *device; 192 size_t length; 193 packet_t *next; 194 int phone; 195 int rc; 196 197 rc = find_device(device_id, &device); 188 int rc = find_device(device_id, &device); 198 189 if (rc != EOK) 199 190 return EOK; 200 191 201 192 if (device->state != NETIF_ACTIVE) { 202 193 netif_pq_release(packet_get_id(packet)); 203 194 return EFORWARD; 204 195 } 205 206 next = packet;196 197 packet_t *next = packet; 207 198 do { 208 199 ((device_stats_t *) device->specific)->send_packets++; 209 200 ((device_stats_t *) device->specific)->receive_packets++; 210 length = packet_get_data_length(next);201 size_t length = packet_get_data_length(next); 211 202 ((device_stats_t *) device->specific)->send_bytes += length; 212 203 ((device_stats_t *) device->specific)->receive_bytes += length; 213 204 next = pq_next(next); 214 } while (next);215 216 phone = device->nil_phone;205 } while (next); 206 207 int phone = device->nil_phone; 217 208 fibril_rwlock_write_unlock(&netif_globals.lock); 209 218 210 nil_received_msg(phone, device_id, packet, sender); 211 219 212 fibril_rwlock_write_lock(&netif_globals.lock); 220 221 213 return EOK; 222 214 } … … 224 216 int netif_start_message(netif_device_t *device) 225 217 { 226 return change_state_message(device, NETIF_ACTIVE); 218 change_state_message(device, NETIF_ACTIVE); 219 return device->state; 227 220 } 228 221 229 222 int netif_stop_message(netif_device_t *device) 230 223 { 231 return change_state_message(device, NETIF_STOPPED); 224 change_state_message(device, NETIF_STOPPED); 225 return device->state; 232 226 } 233 227 -
uspace/srv/net/nil/eth/Makefile
r04aade50 rfe8dfa6 42 42 43 43 SOURCES = \ 44 eth.c \ 45 eth_module.c 44 eth.c 46 45 47 46 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/net/nil/eth/eth.c
r04aade50 rfe8dfa6 45 45 46 46 #include <ipc/ipc.h> 47 #include <ipc/nil.h> 47 48 #include <ipc/net.h> 48 49 #include <ipc/services.h> … … 56 57 #include <netif_remote.h> 57 58 #include <net_interface.h> 58 #include <nil_interface.h>59 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_ local.h>63 #include <nil_skel.h> 64 64 65 65 #include "eth.h" 66 #include "eth_header.h"67 66 68 67 /** The module name. */ … … 72 71 #define ETH_PREFIX \ 73 72 (sizeof(eth_header_t) + sizeof(eth_header_lsap_t) + \ 74 sizeof(eth_header_snap_t))73 sizeof(eth_header_snap_t)) 75 74 76 75 /** Reserved packet suffix length. */ 77 #define ETH_SUFFIX \ 78 sizeof(eth_fcs_t) 76 #define ETH_SUFFIX (sizeof(eth_fcs_t)) 79 77 80 78 /** Maximum packet content length. */ 81 #define ETH_MAX_CONTENT 1500u79 #define ETH_MAX_CONTENT 1500u 82 80 83 81 /** Minimum packet content length. */ 84 #define ETH_MIN_CONTENT 46u82 #define ETH_MIN_CONTENT 46u 85 83 86 84 /** Maximum tagged packet content length. */ 87 85 #define ETH_MAX_TAGGED_CONTENT(flags) \ 88 86 (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))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)) 92 90 93 91 /** Minimum tagged packet content length. */ 94 92 #define ETH_MIN_TAGGED_CONTENT(flags) \ 95 93 (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))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)) 99 97 100 98 /** Dummy flag shift value. */ 101 #define ETH_DUMMY_SHIFT 99 #define ETH_DUMMY_SHIFT 0 102 100 103 101 /** Mode flag shift value. */ 104 #define ETH_MODE_SHIFT 102 #define ETH_MODE_SHIFT 1 105 103 106 104 /** Dummy device flag. 107 105 * Preamble and FCS are mandatory part of the packets. 108 106 */ 109 #define ETH_DUMMY 107 #define ETH_DUMMY (1 << ETH_DUMMY_SHIFT) 110 108 111 109 /** Returns the dummy flag. 112 110 * @see ETH_DUMMY 113 111 */ 114 #define IS_DUMMY(flags) 112 #define IS_DUMMY(flags) ((flags) & ETH_DUMMY) 115 113 116 114 /** Device mode flags. … … 119 117 * @see ETH_8023_2_SNAP 120 118 */ 121 #define ETH_MODE_MASK 119 #define ETH_MODE_MASK (3 << ETH_MODE_SHIFT) 122 120 123 121 /** 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.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. 129 127 * @see ETH_DIX 130 */ 131 #define IS_DIX(flags) (((flags) & ETH_MODE_MASK) == ETH_DIX) 128 * 129 */ 130 #define IS_DIX(flags) (((flags) & ETH_MODE_MASK) == ETH_DIX) 132 131 133 132 /** 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.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. 139 138 * @see ETH_8023_2_LSAP 140 */ 141 #define IS_8023_2_LSAP(flags) (((flags) & ETH_MODE_MASK) == ETH_8023_2_LSAP) 139 * 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 swhether the 802.3 + 802.2 + LSAP + SNAP mode flag is set.147 * 148 * @param[in] flags The ethernet flags.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. 149 149 * @see ETH_8023_2_SNAP 150 */ 151 #define IS_8023_2_SNAP(flags) (((flags) & ETH_MODE_MASK) == ETH_8023_2_SNAP) 150 * 151 */ 152 #define IS_8023_2_SNAP(flags) (((flags) & ETH_MODE_MASK) == ETH_8023_2_SNAP) 152 153 153 154 /** Type definition of the ethernet address type. … … 836 837 } 837 838 838 int nil_m essage_standalone(const char *name, ipc_callid_t callid,839 ipc_call_t * call, ipc_call_t *answer, size_t *answer_count)839 int nil_module_message(ipc_callid_t callid, ipc_call_t *call, 840 ipc_call_t *answer, size_t *answer_count) 840 841 { 841 842 measured_string_t *address; … … 893 894 } 894 895 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 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 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, count);933 }934 }935 936 896 int main(int argc, char *argv[]) 937 897 { 938 int rc;939 940 898 /* Start the module */ 941 rc = nil_module_start_standalone(nil_client_connection); 942 return rc; 899 return nil_module_start(SERVICE_ETHERNET); 943 900 } 944 901 -
uspace/srv/net/nil/eth/eth.h
r04aade50 rfe8dfa6 44 44 #include <adt/measured_strings.h> 45 45 46 /** Ethernet address length. */ 47 #define ETH_ADDR 6 48 49 /** Ethernet header preamble value. */ 50 #define ETH_PREAMBLE 0x55 51 52 /** Ethernet header start of frame value. */ 53 #define ETH_SFD 0xD5 54 55 /** IEEE 802.2 unordered information control field. */ 56 #define IEEE_8023_2_UI 0x03 57 58 /** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions. 59 * @see eth_header_snap 60 */ 61 typedef struct eth_header_snap eth_header_snap_t; 62 63 /** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions. 64 * @see eth_header_lsap 65 */ 66 typedef struct eth_header_lsap eth_header_lsap_t; 67 68 /** Type definition of the Ethernet header LSAP extension. 69 * @see eth_ieee_lsap 70 */ 71 typedef struct eth_ieee_lsap eth_ieee_lsap_t; 72 73 /** Type definition of the Ethernet header SNAP extension. 74 * @see eth_snap 75 */ 76 typedef struct eth_snap eth_snap_t; 77 78 /** Type definition of the Ethernet header preamble. 79 * @see preamble 80 */ 81 typedef struct eth_preamble eth_preamble_t; 82 83 /** Type definition of the Ethernet header. 84 * @see eth_header 85 */ 86 typedef struct eth_header eth_header_t; 87 88 /** Ethernet header Link Service Access Point extension. */ 89 struct eth_ieee_lsap { 90 /** 91 * Destination Service Access Point identifier. 92 * The possible values are assigned by an IEEE committee. 93 */ 94 uint8_t dsap; 95 96 /** 97 * Source Service Access Point identifier. 98 * The possible values are assigned by an IEEE committee. 99 */ 100 uint8_t ssap; 101 102 /** 103 * Control parameter. 104 * The possible values are assigned by an IEEE committee. 105 */ 106 uint8_t ctrl; 107 } __attribute__ ((packed)); 108 109 /** Ethernet header SNAP extension. */ 110 struct eth_snap { 111 /** Protocol identifier or organization code. */ 112 uint8_t protocol[3]; 113 114 /** 115 * Ethernet protocol identifier in the network byte order (big endian). 116 * @see ethernet_protocols.h 117 */ 118 uint16_t ethertype; 119 } __attribute__ ((packed)); 120 121 /** Ethernet header preamble. 122 * 123 * Used for dummy devices. 124 */ 125 struct eth_preamble { 126 /** 127 * Controlling preamble used for the frame transmission synchronization. 128 * All should be set to ETH_PREAMBLE. 129 */ 130 uint8_t preamble[7]; 131 132 /** 133 * Start of Frame Delimiter used for the frame transmission 134 * synchronization. 135 * Should be set to ETH_SFD. 136 */ 137 uint8_t sfd; 138 } __attribute__ ((packed)); 139 140 /** Ethernet header. */ 141 struct eth_header { 142 /** Destination host Ethernet address (MAC address). */ 143 uint8_t destination_address[ETH_ADDR]; 144 /** Source host Ethernet address (MAC address). */ 145 uint8_t source_address[ETH_ADDR]; 146 147 /** 148 * Ethernet protocol identifier in the network byte order (big endian). 149 * @see ethernet_protocols.h 150 */ 151 uint16_t ethertype; 152 } __attribute__ ((packed)); 153 154 /** Ethernet header IEEE 802.3 + 802.2 extension. */ 155 struct eth_header_lsap { 156 /** Ethernet header. */ 157 eth_header_t header; 158 159 /** 160 * LSAP extension. 161 * If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being 162 * used. 163 * If DSAP and SSAP fields are equal to ETH_RAW the raw Ethernet packet 164 * without any extensions is being used and the frame content starts 165 * rigth after the two fields. 166 */ 167 eth_ieee_lsap_t lsap; 168 } __attribute__ ((packed)); 169 170 /** Ethernet header IEEE 802.3 + 802.2 + SNAP extensions. */ 171 struct eth_header_snap { 172 /** Ethernet header. */ 173 eth_header_t header; 174 175 /** 176 * LSAP extension. 177 * If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being 178 * used. 179 * If DSAP and SSAP fields are equal to ETH_RAW the raw Ethernet packet 180 * without any extensions is being used and the frame content starts 181 * rigth after the two fields. 182 */ 183 eth_ieee_lsap_t lsap; 184 185 /** SNAP extension. */ 186 eth_snap_t snap; 187 } __attribute__ ((packed)); 188 189 /** Ethernet Frame Check Sequence. */ 190 typedef uint32_t eth_fcs_t; 191 46 192 /** Type definition of the Ethernet global data. 47 193 * @see eth_globals -
uspace/srv/net/nil/nildummy/Makefile
r04aade50 rfe8dfa6 42 42 43 43 SOURCES = \ 44 nildummy.c \ 45 nildummy_module.c 44 nildummy.c 46 45 47 46 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/net/nil/nildummy/nildummy.c
r04aade50 rfe8dfa6 42 42 #include <str.h> 43 43 #include <ipc/ipc.h> 44 #include <ipc/nil.h> 44 45 #include <ipc/net.h> 45 46 #include <ipc/services.h> … … 47 48 #include <net/modules.h> 48 49 #include <net/device.h> 49 #include <nil_interface.h>50 50 #include <il_interface.h> 51 51 #include <adt/measured_strings.h> … … 53 53 #include <packet_remote.h> 54 54 #include <netif_remote.h> 55 #include <nil_ local.h>55 #include <nil_skel.h> 56 56 57 57 #include "nildummy.h" … … 81 81 int nil_initialize(int net_phone) 82 82 { 83 int rc;84 85 83 fibril_rwlock_initialize(&nildummy_globals.devices_lock); 86 84 fibril_rwlock_initialize(&nildummy_globals.protos_lock); … … 90 88 nildummy_globals.net_phone = net_phone; 91 89 nildummy_globals.proto.phone = 0; 92 rc = nildummy_devices_initialize(&nildummy_globals.devices);90 int rc = nildummy_devices_initialize(&nildummy_globals.devices); 93 91 94 92 fibril_rwlock_write_unlock(&nildummy_globals.protos_lock); … … 98 96 } 99 97 100 /** Process IPC messages from the registered device driver modules in an101 * infinite loop.102 * 103 * @param[in ] iid The message identifier.104 * @param[in,out] icall The message parameters.98 /** Process IPC messages from the registered device driver modules 99 * 100 * @param[in] iid Message identifier. 101 * @param[in,out] icall Message parameters. 102 * 105 103 */ 106 104 static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall) … … 108 106 packet_t *packet; 109 107 int rc; 110 108 111 109 while (true) { 112 110 switch (IPC_GET_IMETHOD(*icall)) { … … 139 137 * Determine the device local hardware address. 140 138 * 141 * @param[in] device_id The new device identifier. 142 * @param[in] service The device driver service. 143 * @param[in] mtu The device maximum transmission unit. 144 * @return EOK on success. 145 * @return EEXIST if the device with the different service exists. 146 * @return ENOMEM if there is not enough memory left. 147 * @return Other error codes as defined for the 148 * netif_bind_service() function. 149 * @return Other error codes as defined for the 150 * netif_get_addr_req() function. 139 * @param[in] device_id New device identifier. 140 * @param[in] service Device driver service. 141 * @param[in] mtu Device maximum transmission unit. 142 * 143 * @return EOK on success. 144 * @return EEXIST if the device with the different service exists. 145 * @return ENOMEM if there is not enough memory left. 146 * @return Other error codes as defined for the 147 * netif_bind_service() function. 148 * @return Other error codes as defined for the 149 * netif_get_addr_req() function. 150 * 151 151 */ 152 152 static int nildummy_device_message(device_id_t device_id, services_t service, 153 153 size_t mtu) 154 154 { 155 nildummy_device_t *device;156 int index;157 int rc;158 159 155 fibril_rwlock_write_lock(&nildummy_globals.devices_lock); 160 156 161 157 /* An existing device? */ 162 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 158 nildummy_device_t *device = 159 nildummy_devices_find(&nildummy_globals.devices, device_id); 163 160 if (device) { 164 161 if (device->service != service) { … … 213 210 214 211 /* Get hardware address */ 215 rc = netif_get_addr_req(device->phone, device->device_id, &device->addr,216 &device->addr _data);212 int rc = netif_get_addr_req(device->phone, device->device_id, 213 &device->addr, &device->addr_data); 217 214 if (rc != EOK) { 218 215 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); … … 222 219 223 220 /* Add to the cache */ 224 in dex = nildummy_devices_add(&nildummy_globals.devices,221 int index = nildummy_devices_add(&nildummy_globals.devices, 225 222 device->device_id, device); 226 223 if (index < 0) { … … 240 237 /** Return the device hardware address. 241 238 * 242 * @param[in] device_id The device identifier. 243 * @param[out] address The device hardware address. 244 * @return EOK on success. 245 * @return EBADMEM if the address parameter is NULL. 246 * @return ENOENT if there no such device. 239 * @param[in] device_id Device identifier. 240 * @param[out] address Device hardware address. 241 * 242 * @return EOK on success. 243 * @return EBADMEM if the address parameter is NULL. 244 * @return ENOENT if there no such device. 247 245 * 248 246 */ … … 250 248 measured_string_t **address) 251 249 { 252 nildummy_device_t *device;253 254 250 if (!address) 255 251 return EBADMEM; 256 252 257 253 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 258 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 254 255 nildummy_device_t *device = 256 nildummy_devices_find(&nildummy_globals.devices, device_id); 259 257 if (!device) { 260 258 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 261 259 return ENOENT; 262 260 } 261 263 262 *address = device->addr; 263 264 264 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 265 265 … … 269 269 /** Return the device packet dimensions for sending. 270 270 * 271 * @param[in] device_id The device identifier. 272 * @param[out] addr_len The minimum reserved address length. 273 * @param[out] prefix The minimum reserved prefix size. 274 * @param[out] content The maximum content size. 275 * @param[out] suffix The minimum reserved suffix size. 276 * @return EOK on success. 277 * @return EBADMEM if either one of the parameters is NULL. 278 * @return ENOENT if there is no such device. 271 * @param[in] device_id Device identifier. 272 * @param[out] addr_len Minimum reserved address length. 273 * @param[out] prefix Minimum reserved prefix size. 274 * @param[out] content Maximum content size. 275 * @param[out] suffix Minimum reserved suffix size. 276 * 277 * @return EOK on success. 278 * @return EBADMEM if either one of the parameters is NULL. 279 * @return ENOENT if there is no such device. 279 280 * 280 281 */ … … 282 283 size_t *prefix, size_t *content, size_t *suffix) 283 284 { 284 nildummy_device_t *device; 285 286 if (!addr_len || !prefix || !content || !suffix) 285 if ((!addr_len) || (!prefix) || (!content) || (!suffix)) 287 286 return EBADMEM; 288 287 289 288 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 290 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 289 290 nildummy_device_t *device = 291 nildummy_devices_find(&nildummy_globals.devices, device_id); 291 292 if (!device) { 292 293 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 293 294 return ENOENT; 294 295 } 295 296 296 297 *content = device->mtu; 298 297 299 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 298 300 … … 306 308 packet_t *packet, services_t target) 307 309 { 308 packet_t *next;309 310 310 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); 311 311 312 if (nildummy_globals.proto.phone) { 312 313 do { 313 next = pq_detach(packet);314 packet_t *next = pq_detach(packet); 314 315 il_received_msg(nildummy_globals.proto.phone, device_id, 315 316 packet, nildummy_globals.proto.service); 316 317 packet = next; 317 } while(packet); 318 } 318 } while (packet); 319 } 320 319 321 fibril_rwlock_read_unlock(&nildummy_globals.protos_lock); 320 322 … … 326 328 * Pass received packets for this service. 327 329 * 328 * @param[in] service The module service. 329 * @param[in] phone The service phone. 330 * @return EOK on success. 331 * @return ENOENT if the service is not known. 332 * @return ENOMEM if there is not enough memory left. 330 * @param[in] service Module service. 331 * @param[in] phone Service phone. 332 * 333 * @return EOK on success. 334 * @return ENOENT if the service is not known. 335 * @return ENOMEM if there is not enough memory left. 336 * 333 337 */ 334 338 static int nildummy_register_message(services_t service, int phone) … … 347 351 /** Send the packet queue. 348 352 * 349 * @param[in] device_id The device identifier. 350 * @param[in] packet The packet queue. 351 * @param[in] sender The sending module service. 352 * @return EOK on success. 353 * @return ENOENT if there no such device. 354 * @return EINVAL if the service parameter is not known. 353 * @param[in] device_id Device identifier. 354 * @param[in] packet Packet queue. 355 * @param[in] sender Sending module service. 356 * 357 * @return EOK on success. 358 * @return ENOENT if there no such device. 359 * @return EINVAL if the service parameter is not known. 360 * 355 361 */ 356 362 static int nildummy_send_message(device_id_t device_id, packet_t *packet, 357 363 services_t sender) 358 364 { 359 nildummy_device_t *device;360 361 365 fibril_rwlock_read_lock(&nildummy_globals.devices_lock); 362 device = nildummy_devices_find(&nildummy_globals.devices, device_id); 366 367 nildummy_device_t *device = 368 nildummy_devices_find(&nildummy_globals.devices, device_id); 363 369 if (!device) { 364 370 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 365 371 return ENOENT; 366 372 } 367 373 368 374 /* Send packet queue */ 369 375 if (packet) 370 376 netif_send_msg(device->phone, device_id, packet, 371 377 SERVICE_NILDUMMY); 378 372 379 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 373 return EOK; 374 } 375 376 int nil_message_standalone(const char *name, ipc_callid_t callid, 377 ipc_call_t *call, ipc_call_t *answer, size_t *answer_count) 380 381 return EOK; 382 } 383 384 int nil_module_message(ipc_callid_t callid, ipc_call_t *call, 385 ipc_call_t *answer, size_t *answer_count) 378 386 { 379 387 measured_string_t *address; … … 434 442 } 435 443 436 /** Default thread for new connections.437 *438 * @param[in] iid The initial message identifier.439 * @param[in] icall The initial message call structure.440 */441 static void nil_client_connection(ipc_callid_t iid, ipc_call_t *icall)442 {443 /*444 * Accept the connection445 * - Answer the first IPC_M_CONNECT_ME_TO call.446 */447 ipc_answer_0(iid, EOK);448 449 while (true) {450 ipc_call_t answer;451 size_t count;452 453 /* Clear the answer structure */454 refresh_answer(&answer, &count);455 456 /* Fetch the next message */457 ipc_call_t call;458 ipc_callid_t callid = async_get_call(&call);459 460 /* Process the message */461 int res = nil_module_message_standalone(NAME, callid, &call,462 &answer, &count);463 464 /*465 * End if told to either by the message or the processing466 * result.467 */468 if ((IPC_GET_IMETHOD(call) == IPC_M_PHONE_HUNGUP) ||469 (res == EHANGUP))470 return;471 472 /* Answer the message */473 answer_call(callid, res, &answer, count);474 }475 }476 477 444 int main(int argc, char *argv[]) 478 445 { 479 int rc;480 481 446 /* Start the module */ 482 rc = nil_module_start_standalone(nil_client_connection); 483 return rc; 447 return nil_module_start(SERVICE_NILDUMMY); 484 448 } 485 449 -
uspace/srv/net/nil/nildummy/nildummy.h
r04aade50 rfe8dfa6 45 45 46 46 /** Type definition of the dummy nil global data. 47 * 47 48 * @see nildummy_globals 49 * 48 50 */ 49 51 typedef struct nildummy_globals nildummy_globals_t; 50 52 51 53 /** Type definition of the dummy nil device specific data. 54 * 52 55 * @see nildummy_device 56 * 53 57 */ 54 58 typedef struct nildummy_device nildummy_device_t; 55 59 56 60 /** Type definition of the dummy nil protocol specific data. 61 * 57 62 * @see nildummy_proto 63 * 58 64 */ 59 65 typedef struct nildummy_proto nildummy_proto_t; 60 66 61 67 /** Dummy nil device map. 62 * Maps devices to the dummy nil device specific data. 68 * 69 * Map devices to the dummy nil device specific data. 63 70 * @see device.h 71 * 64 72 */ 65 73 DEVICE_MAP_DECLARE(nildummy_devices, nildummy_device_t); … … 69 77 /** Device identifier. */ 70 78 device_id_t device_id; 79 71 80 /** Device driver service. */ 72 81 services_t service; 82 73 83 /** Driver phone. */ 74 84 int phone; 85 75 86 /** Maximal transmission unit. */ 76 87 size_t mtu; 88 77 89 /** Actual device hardware address. */ 78 90 measured_string_t *addr; 91 79 92 /** Actual device hardware address data. */ 80 93 uint8_t *addr_data; … … 85 98 /** Protocol service. */ 86 99 services_t service; 100 87 101 /** Protocol module phone. */ 88 102 int phone; … … 93 107 /** Networking module phone. */ 94 108 int net_phone; 95 /** Safety lock for devices. */ 109 110 /** Lock for devices. */ 96 111 fibril_rwlock_t devices_lock; 112 97 113 /** All known Ethernet devices. */ 98 114 nildummy_devices_t devices; 115 99 116 /** Safety lock for protocols. */ 100 117 fibril_rwlock_t protos_lock; 118 101 119 /** Default protocol. */ 102 120 nildummy_proto_t proto;
Note:
See TracChangeset
for help on using the changeset viewer.