Changes in uspace/srv/net/netif/lo/lo.c [fe8dfa6:774e6d1a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/netif/lo/lo.c
rfe8dfa6 r774e6d1a 48 48 #include <packet_client.h> 49 49 #include <net/device.h> 50 #include <nil_interface.h> 50 51 #include <netif_skel.h> 51 #include <nil_remote.h> 52 53 /** Default hardware address. */ 54 #define DEFAULT_ADDR 0 52 55 53 56 /** Default address length. */ … … 57 60 #define NAME "lo" 58 61 59 static uint8_t default_addr[DEFAULT_ADDR_LEN] = 60 {0, 0, 0, 0, 0, 0};62 /** Network interface global data. */ 63 netif_globals_t netif_globals; 61 64 62 65 int netif_specific_message(ipc_callid_t callid, ipc_call_t *call, … … 71 74 return EBADMEM; 72 75 73 address->value = default_addr; 76 uint8_t *addr = (uint8_t *) malloc(DEFAULT_ADDR_LEN); 77 memset(addr, DEFAULT_ADDR, DEFAULT_ADDR_LEN); 78 79 address->value = addr; 74 80 address->length = DEFAULT_ADDR_LEN; 75 81 … … 79 85 int netif_get_device_stats(device_id_t device_id, device_stats_t *stats) 80 86 { 87 netif_device_t *device; 88 int rc; 89 81 90 if (!stats) 82 91 return EBADMEM; 83 84 netif_device_t *device; 85 int rc = find_device(device_id, &device); 92 93 rc = find_device(device_id, &device); 86 94 if (rc != EOK) 87 95 return rc; 88 96 89 97 memcpy(stats, (device_stats_t *) device->specific, 90 98 sizeof(device_stats_t)); 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) 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) 105 111 { 106 112 if (device->state != state) { 107 113 device->state = state; 108 114 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 } 115 printf("%s: State changed to %s\n", NAME, 116 (state == NETIF_ACTIVE) ? "active" : "stopped"); 120 117 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 { 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 137 136 if (netif_device_map_count(&netif_globals.device_map) > 0) 138 137 return EXDEV; 139 138 140 139 *device = (netif_device_t *) malloc(sizeof(netif_device_t)); 141 140 if (!*device) 142 141 return ENOMEM; 143 142 144 143 (*device)->specific = (device_stats_t *) malloc(sizeof(device_stats_t)); 145 144 if (!(*device)->specific) { … … 147 146 return ENOMEM; 148 147 } 149 148 150 149 null_device_stats((device_stats_t *) (*device)->specific); 151 150 (*device)->device_id = device_id; 152 151 (*device)->nil_phone = -1; 153 152 (*device)->state = NETIF_STOPPED; 154 in t index = netif_device_map_add(&netif_globals.device_map,153 index = netif_device_map_add(&netif_globals.device_map, 155 154 (*device)->device_id, *device); 156 155 157 156 if (index < 0) { 158 157 free(*device); … … 168 167 { 169 168 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 netif_device_t *device; 176 int rc; 177 175 178 /* Create a new device */ 176 netif_device_t *device; 177 int rc = lo_create(device_id, &device); 179 rc = create(device_id, &device); 178 180 if (rc != EOK) 179 181 return rc; 180 182 183 /* Print the settings */ 181 184 printf("%s: Device created (id: %d)\n", NAME, device->device_id); 185 182 186 return EOK; 183 187 } … … 186 190 { 187 191 netif_device_t *device; 188 int rc = find_device(device_id, &device); 192 size_t length; 193 packet_t *next; 194 int phone; 195 int rc; 196 197 rc = find_device(device_id, &device); 189 198 if (rc != EOK) 190 199 return EOK; 191 200 192 201 if (device->state != NETIF_ACTIVE) { 193 202 netif_pq_release(packet_get_id(packet)); 194 203 return EFORWARD; 195 204 } 196 197 packet_t *next = packet;205 206 next = packet; 198 207 do { 199 208 ((device_stats_t *) device->specific)->send_packets++; 200 209 ((device_stats_t *) device->specific)->receive_packets++; 201 size_tlength = packet_get_data_length(next);210 length = packet_get_data_length(next); 202 211 ((device_stats_t *) device->specific)->send_bytes += length; 203 212 ((device_stats_t *) device->specific)->receive_bytes += length; 204 213 next = pq_next(next); 205 } while 206 207 intphone = device->nil_phone;214 } while(next); 215 216 phone = device->nil_phone; 208 217 fibril_rwlock_write_unlock(&netif_globals.lock); 209 210 218 nil_received_msg(phone, device_id, packet, sender); 211 212 219 fibril_rwlock_write_lock(&netif_globals.lock); 220 213 221 return EOK; 214 222 } … … 216 224 int netif_start_message(netif_device_t *device) 217 225 { 218 change_state_message(device, NETIF_ACTIVE); 219 return device->state; 226 return change_state_message(device, NETIF_ACTIVE); 220 227 } 221 228 222 229 int netif_stop_message(netif_device_t *device) 223 230 { 224 change_state_message(device, NETIF_STOPPED); 225 return device->state; 231 return change_state_message(device, NETIF_STOPPED); 226 232 } 227 233
Note:
See TracChangeset
for help on using the changeset viewer.