Changeset 24ab58b3 in mainline for uspace/lib/net/netif/netif.c
- Timestamp:
- 2010-04-06T11:41:48Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 14f1db0
- Parents:
- 4dd8529
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/netif/netif.c
r4dd8529 r24ab58b3 176 176 } 177 177 178 /** Registers the device notification receiver, the network interface layer module. 179 * @param[in] device_id The device identifier. 180 * @param[in] phone The network interface layer module phone. 181 * @returns EOK on success. 182 * @returns ENOENT if there is no such device. 183 * @returns ELIMIT if there is another module registered. 184 */ 185 static int register_message(device_id_t device_id, int phone){ 186 ERROR_DECLARE; 187 178 /** Register the device notification receiver, the network interface layer module. 179 * 180 * @param[in] name Module name. 181 * @param[in] device_id The device identifier. 182 * @param[in] phone The network interface layer module phone. 183 * 184 * @return EOK on success. 185 * @return ENOENT if there is no such device. 186 * @return ELIMIT if there is another module registered. 187 * 188 */ 189 static int register_message(const char *name, device_id_t device_id, int phone) 190 { 191 ERROR_DECLARE; 192 188 193 device_ref device; 189 190 194 ERROR_PROPAGATE(find_device(device_id, &device)); 191 if(device->nil_phone > 0) {195 if(device->nil_phone > 0) 192 196 return ELIMIT; 193 }197 194 198 device->nil_phone = phone; 195 printf("New receiver of the device %d registered:\n\tphone\t= %d\n", device->device_id, device->nil_phone); 196 return EOK; 197 } 198 199 int netif_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 200 ERROR_DECLARE; 201 199 printf("%s: Receiver of device %d registered (phone: %d)\n", 200 name, device->device_id, device->nil_phone); 201 return EOK; 202 } 203 204 int netif_message(const char *name, ipc_callid_t callid, ipc_call_t *call, 205 ipc_call_t *answer, int *answer_count) 206 { 207 ERROR_DECLARE; 208 202 209 size_t length; 203 210 device_stats_t stats; 204 211 packet_t packet; 205 212 measured_string_t address; 206 207 // printf("message %d - %d\n", IPC_GET_METHOD(*call), NET_NETIF_FIRST); 213 208 214 *answer_count = 0; 209 215 switch(IPC_GET_METHOD(*call)){ … … 211 217 return EOK; 212 218 case NET_NETIF_PROBE: 213 return netif_probe_req(0, IPC_GET_DEVICE(call), NETIF_GET_IRQ(call), NETIF_GET_IO(call)); 219 return netif_probe_req(0, IPC_GET_DEVICE(call), 220 NETIF_GET_IRQ(call), NETIF_GET_IO(call)); 214 221 case IPC_M_CONNECT_TO_ME: 215 222 fibril_rwlock_write_lock(&netif_globals.lock); 216 ERROR_CODE = register_message(IPC_GET_DEVICE(call), IPC_GET_PHONE(call)); 223 ERROR_CODE = register_message(name, IPC_GET_DEVICE(call), 224 IPC_GET_PHONE(call)); 217 225 fibril_rwlock_write_unlock(&netif_globals.lock); 218 226 return ERROR_CODE; 219 227 case NET_NETIF_SEND: 220 ERROR_PROPAGATE(packet_translate(netif_globals.net_phone, &packet, IPC_GET_PACKET(call))); 221 return netif_send_msg(0, IPC_GET_DEVICE(call), packet, IPC_GET_SENDER(call)); 228 ERROR_PROPAGATE(packet_translate(netif_globals.net_phone, 229 &packet, IPC_GET_PACKET(call))); 230 return netif_send_msg(0, IPC_GET_DEVICE(call), packet, 231 IPC_GET_SENDER(call)); 222 232 case NET_NETIF_START: 223 233 return netif_start_req(0, IPC_GET_DEVICE(call)); 224 234 case NET_NETIF_STATS: 225 235 fibril_rwlock_read_lock(&netif_globals.lock); 226 if (! ERROR_OCCURRED(async_data_read_receive(&callid, &length))){227 if (length < sizeof(device_stats_t)){236 if (!ERROR_OCCURRED(async_data_read_receive(&callid, &length))) { 237 if (length < sizeof(device_stats_t)) 228 238 ERROR_CODE = EOVERFLOW; 229 }else{ 230 if(! ERROR_OCCURRED(netif_get_device_stats(IPC_GET_DEVICE(call), &stats))){ 231 ERROR_CODE = async_data_read_finalize(callid, &stats, sizeof(device_stats_t)); 232 } 239 else { 240 if (!ERROR_OCCURRED(netif_get_device_stats( 241 IPC_GET_DEVICE(call), &stats))) 242 ERROR_CODE = async_data_read_finalize(callid, &stats, 243 sizeof(device_stats_t)); 233 244 } 234 245 } … … 239 250 case NET_NETIF_GET_ADDR: 240 251 fibril_rwlock_read_lock(&netif_globals.lock); 241 if(! ERROR_OCCURRED(netif_get_addr_message(IPC_GET_DEVICE(call), &address))){ 252 if (!ERROR_OCCURRED(netif_get_addr_message(IPC_GET_DEVICE(call), 253 &address))) 242 254 ERROR_CODE = measured_strings_reply(&address, 1); 243 }244 255 fibril_rwlock_read_unlock(&netif_globals.lock); 245 256 return ERROR_CODE; 246 257 } 258 247 259 return netif_specific_message(callid, call, answer, answer_count); 248 260 }
Note:
See TracChangeset
for help on using the changeset viewer.