Changeset 24ab58b3 in mainline
- 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
- Location:
- uspace
- Files:
-
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/il/ip_remote.c
r4dd8529 r24ab58b3 28 28 29 29 /** @addtogroup ip 30 * 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * IP interface implementation for standalone remote modules. 35 * @see ip_interface.h 36 * @see il_interface.h 34 * 35 * IP interface implementation for standalone remote modules. 36 * 37 * @see ip_interface.h 38 * @see il_interface.h 39 * 37 40 */ 38 41 … … 48 51 #include <ip_messages.h> 49 52 50 int ip_add_route_req(int ip_phone, device_id_t device_id, in_addr_t address, in_addr_t netmask, in_addr_t gateway){ 51 return (int) async_req_4_0(ip_phone, NET_IP_ADD_ROUTE, (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr, (ipcarg_t) address.s_addr, (ipcarg_t) netmask.s_addr); 53 int ip_add_route_req(int ip_phone, device_id_t device_id, in_addr_t address, 54 in_addr_t netmask, in_addr_t gateway) 55 { 56 return (int) async_req_4_0(ip_phone, NET_IP_ADD_ROUTE, 57 (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr, 58 (ipcarg_t) address.s_addr, (ipcarg_t) netmask.s_addr); 52 59 } 53 60 54 int ip_bind_service(services_t service, int protocol, services_t me, async_client_conn_t receiver, tl_received_msg_t tl_received_msg){ 55 return (int) bind_service(service, (ipcarg_t) protocol, me, service, receiver); 61 int ip_bind_service(services_t service, int protocol, services_t me, 62 async_client_conn_t receiver, tl_received_msg_t tl_received_msg) 63 { 64 return (int) bind_service(service, (ipcarg_t) protocol, me, service, 65 receiver); 56 66 } 57 67 58 int ip_connect_module(services_t service){ 68 int ip_connect_module(services_t service) 69 { 59 70 return connect_to_service(SERVICE_IP); 60 71 } 61 72 62 int ip_device_req(int ip_phone, device_id_t device_id, services_t service){ 73 int ip_device_req(int ip_phone, device_id_t device_id, services_t service) 74 { 63 75 return generic_device_req(ip_phone, NET_IL_DEVICE, device_id, 0, service); 64 76 } 65 77 66 int ip_get_route_req(int ip_phone, ip_protocol_t protocol, const struct sockaddr * destination, socklen_t addrlen, device_id_t * device_id, ip_pseudo_header_ref * header, size_t * headerlen){ 67 aid_t message_id; 68 ipcarg_t result; 78 int ip_get_route_req(int ip_phone, ip_protocol_t protocol, 79 const struct sockaddr *destination, socklen_t addrlen, 80 device_id_t *device_id, ip_pseudo_header_ref *header, size_t *headerlen) 81 { 82 if ((!destination) || (addrlen == 0)) 83 return EINVAL; 84 85 if ((!device_id) || (header) || (headerlen)) 86 return EBADMEM; 87 88 *header = NULL; 89 69 90 ipc_call_t answer; 70 71 if(!(destination && (addrlen > 0))){ 72 return EINVAL; 73 } 74 if(!(device_id && header && headerlen)){ 75 return EBADMEM; 76 } 77 78 *header = NULL; 79 message_id = async_send_1(ip_phone, NET_IP_GET_ROUTE, (ipcarg_t) protocol, &answer); 80 if((async_data_write_start(ip_phone, destination, addrlen) == EOK) 81 && (async_data_read_start(ip_phone, headerlen, sizeof(*headerlen)) == EOK) 82 && (*headerlen > 0)){ 91 aid_t message_id = async_send_1(ip_phone, NET_IP_GET_ROUTE, 92 (ipcarg_t) protocol, &answer); 93 94 if ((async_data_write_start(ip_phone, destination, addrlen) == EOK) 95 && (async_data_read_start(ip_phone, headerlen, sizeof(*headerlen)) == EOK) 96 && (*headerlen > 0)) { 83 97 *header = (ip_pseudo_header_ref) malloc(*headerlen); 84 if (*header){85 if (async_data_read_start(ip_phone, * header, * headerlen) != EOK){98 if (*header) { 99 if (async_data_read_start(ip_phone, *header, *headerlen) != EOK) 86 100 free(*header); 87 }88 101 } 89 102 } 103 104 ipcarg_t result; 90 105 async_wait_for(message_id, &result); 91 92 if ((result != EOK) && (*header)){106 107 if ((result != EOK) && (*header)) 93 108 free(*header); 94 }else{109 else 95 110 *device_id = IPC_GET_DEVICE(&answer); 96 }111 97 112 return (int) result; 98 113 } 99 114 100 int ip_packet_size_req(int ip_phone, device_id_t device_id, packet_dimension_ref packet_dimension){ 101 return generic_packet_size_req(ip_phone, NET_IL_PACKET_SPACE, device_id, packet_dimension); 115 int ip_packet_size_req(int ip_phone, device_id_t device_id, 116 packet_dimension_ref packet_dimension) 117 { 118 return generic_packet_size_req(ip_phone, NET_IL_PACKET_SPACE, device_id, 119 packet_dimension); 102 120 } 103 121 104 int ip_received_error_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t target, services_t error){ 105 return generic_received_msg(ip_phone, NET_IP_RECEIVED_ERROR, device_id, packet_get_id(packet), target, error); 122 int ip_received_error_msg(int ip_phone, device_id_t device_id, 123 packet_t packet, services_t target, services_t error) 124 { 125 return generic_received_msg(ip_phone, NET_IP_RECEIVED_ERROR, device_id, 126 packet_get_id(packet), target, error); 106 127 } 107 128 108 int ip_send_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t sender, services_t error){ 109 return generic_send_msg(ip_phone, NET_IL_SEND, device_id, packet_get_id(packet), sender, error); 129 int ip_send_msg(int ip_phone, device_id_t device_id, packet_t packet, 130 services_t sender, services_t error) 131 { 132 return generic_send_msg(ip_phone, NET_IL_SEND, device_id, 133 packet_get_id(packet), sender, error); 110 134 } 111 135 112 int ip_set_gateway_req(int ip_phone, device_id_t device_id, in_addr_t gateway){ 113 return (int) async_req_2_0(ip_phone, NET_IP_SET_GATEWAY, (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr); 136 int ip_set_gateway_req(int ip_phone, device_id_t device_id, in_addr_t gateway) 137 { 138 return (int) async_req_2_0(ip_phone, NET_IP_SET_GATEWAY, 139 (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr); 114 140 } 115 141 -
uspace/lib/net/include/netif.h
r4dd8529 r24ab58b3 129 129 extern packet_t netif_packet_get_1(size_t content); 130 130 131 /** Processes the netif module messages. 132 * @param[in] callid The message identifier. 133 * @param[in] call The message parameters. 134 * @param[out] answer The message answer parameters. 135 * @param[out] answer_count The last parameter for the actual answer in the answer parameter. 136 * @returns EOK on success. 137 * @returns ENOTSUP if the message is not known. 138 * @returns Other error codes as defined for each specific module message function. 139 * @see netif_interface.h 140 * @see IS_NET_NETIF_MESSAGE() 131 /** Process the netif module messages. 132 * 133 * @param[in] name Module name. 134 * @param[in] callid The message identifier. 135 * @param[in] call The message parameters. 136 * @param[out] answer The message answer parameters. 137 * @param[out] answer_count The last parameter for the actual answer 138 * in the answer parameter. 139 * 140 * @return EOK on success. 141 * @return ENOTSUP if the message is not known. 142 * @return Other error codes as defined for each specific module message function. 143 * 144 * @see netif_interface.h 145 * @see IS_NET_NETIF_MESSAGE() 146 * 141 147 */ 142 extern int netif_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count); 148 extern int netif_message(const char *, ipc_callid_t, ipc_call_t *, 149 ipc_call_t *, int *); 143 150 144 151 /** Initializes the netif module. -
uspace/lib/net/include/netif_nil_bundle.h
r4dd8529 r24ab58b3 37 37 #include <async.h> 38 38 39 extern int netif_nil_module_message( ipc_callid_t callid, ipc_call_t *call,40 ipc_call_t * answer, int *answer_count);41 extern int netif_nil_module_start(async_client_conn_t client_connection);39 extern int netif_nil_module_message(const char *, ipc_callid_t, ipc_call_t *, 40 ipc_call_t *, int *); 41 extern int netif_nil_module_start(async_client_conn_t); 42 42 43 43 #endif -
uspace/lib/net/include/netif_standalone.h
r4dd8529 r24ab58b3 37 37 #include <async.h> 38 38 39 extern int netif_module_message( ipc_callid_t callid, ipc_call_t *call,40 ipc_call_t * answer, int *answer_count);41 extern int netif_module_start(async_client_conn_t client_connection);39 extern int netif_module_message(const char *, ipc_callid_t, ipc_call_t *, 40 ipc_call_t *, int *); 41 extern int netif_module_start(async_client_conn_t); 42 42 43 43 #endif -
uspace/lib/net/include/nil_module.h
r4dd8529 r24ab58b3 42 42 43 43 /** Module initialization. 44 * Is called by the module_start() function. 45 * @param[in] net_phone The networking moduel phone. 46 * @returns EOK on success. 47 * @returns Other error codes as defined for each specific module initialize function. 44 * 45 * Is called by the module_start() function. 46 * 47 * @param[in] net_phone The networking moduel phone. 48 * 49 * @return EOK on success. 50 * @return Other error codes as defined for each specific module initialize function. 51 * 48 52 */ 49 extern int nil_initialize(int net_phone);53 extern int nil_initialize(int); 50 54 51 55 /** Message processing function. 52 * @param[in] callid The message identifier. 53 * @param[in] call The message parameters. 54 * @param[out] answer The message answer parameters. 55 * @param[out] answer_count The last parameter for the actual answer in the answer parameter. 56 * @returns EOK on success. 57 * @returns ENOTSUP if the message is not known. 58 * @returns Other error codes as defined for each specific module message function. 59 * @see nil_interface.h 60 * @see IS_NET_NIL_MESSAGE() 56 * 57 * @param[in] name Module name. 58 * @param[in] callid The message identifier. 59 * @param[in] call The message parameters. 60 * @param[out] answer The message answer parameters. 61 * @param[out] answer_count The last parameter for the actual answer 62 * in the answer parameter. 63 * 64 * @return EOK on success. 65 * @return ENOTSUP if the message is not known. 66 * @return Other error codes as defined for each specific 67 * module message function. 68 * 69 * @see nil_interface.h 70 * @see IS_NET_NIL_MESSAGE() 71 * 61 72 */ 62 extern int nil_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count); 73 extern int nil_message(const char *, ipc_callid_t, ipc_call_t *, ipc_call_t *, 74 int *); 63 75 64 76 #endif -
uspace/lib/net/include/nil_standalone.h
r4dd8529 r24ab58b3 37 37 #include <async.h> 38 38 39 extern int nil_module_message( ipc_callid_t callid, ipc_call_t *call,40 ipc_call_t * answer, int *answer_count);41 extern int nil_module_start(async_client_conn_t client_connection);39 extern int nil_module_message(const char *, ipc_callid_t, ipc_call_t *, 40 ipc_call_t *, int *); 41 extern int nil_module_start(async_client_conn_t); 42 42 43 43 #endif -
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 } -
uspace/lib/net/netif/netif_nil_bundle.c
r4dd8529 r24ab58b3 45 45 #include <netif.h> 46 46 47 /** Distributes the messages between the module parts. 48 * @param[in] callid The message identifier. 49 * @param[in] call The message parameters. 50 * @param[out] answer The message answer parameters. 51 * @param[out] answer_count The last parameter for the actual answer in the answer parameter. 52 * @returns EOK on success. 53 * @returns ENOTSUP if the message is not known. 54 * @returns Other error codes as defined for each specific module message function. 47 /** Distribute the messages between the module parts. 48 * 49 * @param[in] name Module name. 50 * @param[in] callid The message identifier. 51 * @param[in] call The message parameters. 52 * @param[out] answer The message answer parameters. 53 * @param[out] answer_count The last parameter for the actual 54 * answer in the answer parameter. 55 * 56 * @return EOK on success. 57 * @return ENOTSUP if the message is not known. 58 * @return Other error codes as defined for each specific module message function. 59 * 55 60 */ 56 int netif_nil_module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 57 if(IS_NET_NIL_MESSAGE(call) || (IPC_GET_METHOD(*call) == IPC_M_CONNECT_TO_ME)){ 58 return nil_message(callid, call, answer, answer_count); 59 }else{ 60 return netif_message(callid, call, answer, answer_count); 61 } 61 int netif_nil_module_message(const char *name, ipc_callid_t callid, 62 ipc_call_t *call, ipc_call_t *answer, int *answer_count) 63 { 64 if (IS_NET_NIL_MESSAGE(call) 65 || (IPC_GET_METHOD(*call) == IPC_M_CONNECT_TO_ME)) 66 return nil_message(name, callid, call, answer, answer_count); 67 else 68 return netif_message(name, callid, call, answer, answer_count); 62 69 } 63 70 -
uspace/lib/net/netif/netif_standalone.c
r4dd8529 r24ab58b3 41 41 #include <netif_standalone.h> 42 42 43 /** Delegates the messages to the netif_message() function. 44 * @param[in] callid The message identifier. 45 * @param[in] call The message parameters. 46 * @param[out] answer The message answer parameters. 47 * @param[out] answer_count The last parameter for the actual answer in the answer parameter. 48 * @returns EOK on success. 49 * @returns ENOTSUP if the message is not known. 50 * @returns Other error codes as defined for each specific module message function. 43 /** Delegate the messages to the netif_message() function. 44 * 45 * @param[in] name Module name. 46 * @param[in] callid The message identifier. 47 * @param[in] call The message parameters. 48 * @param[out] answer The message answer parameters. 49 * @param[out] answer_count The last parameter for the actual answer 50 * in the answer parameter. 51 * 52 * @return EOK on success. 53 * @return ENOTSUP if the message is not known. 54 * @return Other error codes as defined for each specific module message function. 55 * 51 56 */ 52 int netif_module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 53 return netif_message(callid, call, answer, answer_count); 57 int netif_module_message(const char *name, ipc_callid_t callid, 58 ipc_call_t *call, ipc_call_t *answer, int *answer_count) 59 { 60 return netif_message(name, callid, call, answer, answer_count); 54 61 } 55 62 -
uspace/srv/hw/netif/dp8390/dp8390_module.c
r4dd8529 r24ab58b3 59 59 /** DP8390 module name. 60 60 */ 61 #define NAME "dp8390 network interface"61 #define NAME "dp8390" 62 62 63 63 /** Returns the device from the interrupt call. … … 302 302 } 303 303 304 int change_state(device_ref device, device_state_t state){ 305 device->state = state; 306 printf("State changed to %s\n", (state == NETIF_ACTIVE) ? "ACTIVE" : "STOPPED"); 307 return state; 304 int change_state(device_ref device, device_state_t state) 305 { 306 if (device->state != state) { 307 device->state = state; 308 309 printf("%s: State changed to %s\n", NAME, 310 (state == NETIF_ACTIVE) ? "active" : "stopped"); 311 312 return state; 313 } 314 315 return EOK; 308 316 } 309 317 … … 346 354 347 355 /* Process the message */ 348 int res = netif_module_message(callid, &call, &answer, &answer_count); 356 int res = netif_module_message(NAME, callid, &call, &answer, 357 &answer_count); 349 358 350 359 /* End if said to either by the message or the processing result */ … … 370 379 ERROR_DECLARE; 371 380 372 /* Print the module label */ 373 printf("Task %d - %s\n", task_get_id(), NAME); 381 /* Start the module */ 382 if (ERROR_OCCURRED(netif_module_start(netif_client_connection))) 383 return ERROR_CODE; 374 384 375 /* Start the module */376 if (ERROR_OCCURRED(netif_module_start(netif_client_connection))) {377 printf(" - ERROR %i\n", ERROR_CODE);378 return ERROR_CODE;379 }380 381 385 return EOK; 382 386 } -
uspace/srv/net/il/arp/arp.c
r4dd8529 r24ab58b3 68 68 /** ARP module name. 69 69 */ 70 #define NAME "ARP protocol"70 #define NAME "arp" 71 71 72 72 /** ARP global data. … … 338 338 return ERROR_CODE; 339 339 } 340 printf("New device registered:\n\tid\t= %d\n\ttype\t= 0x%x\n\tservice\t= %d\n\tproto\t= %d\n", device->device_id, device->hardware, device->service, protocol); 340 printf("%s: Device registered (id: %d, type: 0x%x, service: %d, proto: %d)\n", 341 NAME, device->device_id, device->hardware, device->service, protocol); 341 342 } 342 343 fibril_rwlock_write_unlock(&arp_globals.lock); … … 673 674 ERROR_DECLARE; 674 675 675 /* Print the module label */ 676 printf("Task %d - %s\n", task_get_id(), NAME); 676 /* Start the module */ 677 if (ERROR_OCCURRED(il_module_start(il_client_connection))) 678 return ERROR_CODE; 677 679 678 /* Start the module */679 if (ERROR_OCCURRED(il_module_start(il_client_connection))) {680 printf(" - ERROR %i\n", ERROR_CODE);681 return ERROR_CODE;682 }683 684 680 return EOK; 685 681 } -
uspace/srv/net/il/ip/ip.c
r4dd8529 r24ab58b3 79 79 /** IP module name. 80 80 */ 81 #define NAME "IP protocol"81 #define NAME "ip" 82 82 83 83 /** IP version 4. … … 430 430 ip_route_ref route; 431 431 int index; 432 char * data;433 432 434 433 ip_netif = (ip_netif_ref) malloc(sizeof(ip_netif_t)); … … 454 453 } 455 454 // print the settings 456 printf("New device registered:\n\tid\t= %d\n\tphone\t= %d\n\tIPV\t= %d\n", ip_netif->device_id, ip_netif->phone, ip_netif->ipv); 457 printf("\tconfiguration\t= %s\n", ip_netif->dhcp ? "dhcp" : "static"); 455 printf("%s: Device registered (id: %d, phone: %d, ipv: %d, conf: %s)\n", 456 NAME, ip_netif->device_id, ip_netif->phone, ip_netif->ipv, 457 ip_netif->dhcp ? "dhcp" : "static"); 458 458 459 // TODO ipv6 addresses 459 data = (char *) malloc(INET_ADDRSTRLEN); 460 if(data){ 461 for(index = 0; index < ip_routes_count(&ip_netif->routes); ++ index){ 462 route = ip_routes_get_index(&ip_netif->routes, index); 463 if(route){ 464 printf("\tRouting %d:\n", index); 465 inet_ntop(AF_INET, (uint8_t *) &route->address.s_addr, data, INET_ADDRSTRLEN); 466 printf("\t\taddress\t= %s\n", data); 467 inet_ntop(AF_INET, (uint8_t *) &route->netmask.s_addr, data, INET_ADDRSTRLEN); 468 printf("\t\tnetmask\t= %s\n", data); 469 inet_ntop(AF_INET, (uint8_t *) &route->gateway.s_addr, data, INET_ADDRSTRLEN); 470 printf("\t\tgateway\t= %s\n", data); 471 } 472 } 473 inet_ntop(AF_INET, (uint8_t *) &ip_netif->broadcast.s_addr, data, INET_ADDRSTRLEN); 474 printf("\t\tbroadcast\t= %s\n", data); 475 free(data); 476 } 460 461 char address[INET_ADDRSTRLEN]; 462 char netmask[INET_ADDRSTRLEN]; 463 char gateway[INET_ADDRSTRLEN]; 464 465 for (index = 0; index < ip_routes_count(&ip_netif->routes); ++ index){ 466 route = ip_routes_get_index(&ip_netif->routes, index); 467 if (route) { 468 inet_ntop(AF_INET, (uint8_t *) &route->address.s_addr, address, INET_ADDRSTRLEN); 469 inet_ntop(AF_INET, (uint8_t *) &route->netmask.s_addr, netmask, INET_ADDRSTRLEN); 470 inet_ntop(AF_INET, (uint8_t *) &route->gateway.s_addr, gateway, INET_ADDRSTRLEN); 471 printf("%s: Route %d (address: %s, netmask: %s, gateway: %s)\n", 472 NAME, index, address, netmask, gateway); 473 } 474 } 475 476 inet_ntop(AF_INET, (uint8_t *) &ip_netif->broadcast.s_addr, address, INET_ADDRSTRLEN); 477 printf("%s: Broadcast (%s)\n", NAME, address); 478 477 479 fibril_rwlock_write_unlock(&ip_globals.netifs_lock); 478 480 return EOK; … … 595 597 } 596 598 netif->packet_dimension.content = mtu; 597 printf(" ip - device %d changed mtu to %d\n\n", device_id, mtu);599 printf("%s: Device %d changed MTU to %d\n", NAME, device_id, mtu); 598 600 fibril_rwlock_write_unlock(&ip_globals.netifs_lock); 599 601 return EOK; … … 611 613 } 612 614 netif->state = state; 613 printf(" ip - device %d changed state to %d\n\n", device_id, state);615 printf("%s: Device %d changed state to %d\n", NAME, device_id, state); 614 616 fibril_rwlock_write_unlock(&ip_globals.netifs_lock); 615 617 return EOK; … … 646 648 return index; 647 649 } 648 printf("New protocol registered:\n\tprotocol\t= %d\n\tphone\t= %d\n", proto->protocol, proto->phone); 650 651 printf("%s: Protocol registered (protocol: %d, phone: %d)\n", 652 NAME, proto->protocol, proto->phone); 653 649 654 fibril_rwlock_write_unlock(&ip_globals.protos_lock); 650 655 return EOK; … … 1677 1682 ERROR_DECLARE; 1678 1683 1679 /* Print the module label */1680 printf("Task %d - %s\n", task_get_id(), NAME);1681 1682 1684 /* Start the module */ 1683 if (ERROR_OCCURRED(il_module_start(il_client_connection))) { 1684 printf(" - ERROR %i\n", ERROR_CODE); 1685 if (ERROR_OCCURRED(il_module_start(il_client_connection))) 1685 1686 return ERROR_CODE; 1686 }1687 1687 1688 1688 return EOK; -
uspace/srv/net/net/net.c
r4dd8529 r24ab58b3 28 28 29 29 /** @addtogroup net 30 * 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Networking subsystem central module implementation. 34 * Networking subsystem central module implementation. 35 * 35 36 */ 36 37 … … 64 65 #include "net.h" 65 66 67 /** Networking module name. 68 * 69 */ 70 #define NAME "net" 71 66 72 /** File read buffer size. 67 */ 68 #define BUFFER_SIZE 256 69 70 /** Networking module name. 71 */ 72 #define NAME "Networking" 73 * 74 */ 75 #define BUFFER_SIZE 256 73 76 74 77 /** Networking module global data. 75 */ 76 net_globals_t net_globals; 77 78 /** Generates new system-unique device identifier. 79 * @returns The system-unique devic identifier. 80 */ 81 device_id_t generate_new_device_id(void); 82 83 /** Returns the configured values. 84 * The network interface configuration is searched first. 85 * @param[in] netif_conf The network interface configuration setting. 86 * @param[out] configuration The found configured values. 87 * @param[in] count The desired settings count. 88 * @param[out] data The found configuration settings data. 89 * @returns EOK. 90 */ 91 int net_get_conf(measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data); 92 93 /** Initializes the networking module. 94 * @param[in] client_connection The client connection processing function. The module skeleton propagates its own one. 95 * @returns EOK on success. 96 * @returns ENOMEM if there is not enough memory left. 97 */ 98 int net_initialize(async_client_conn_t client_connection); 99 100 /** \todo 101 */ 102 int parse_line(measured_strings_ref configuration, char * line); 103 104 /** Reads the networking subsystem global configuration. 105 * @returns EOK on success. 106 * @returns Other error codes as defined for the add_configuration() function. 107 */ 108 int read_configuration(void); 109 110 /** \todo 111 */ 112 int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration); 113 114 /** Reads the network interface specific configuration. 115 * @param[in] name The network interface name. 116 * @param[in,out] netif The network interface structure. 117 * @returns EOK on success. 118 * @returns Other error codes as defined for the add_configuration() function. 119 */ 120 int read_netif_configuration(const char * name, netif_ref netif); 121 122 /** Starts the network interface according to its configuration. 123 * Registers the network interface with the subsystem modules. 124 * Starts the needed subsystem modules. 125 * @param[in] netif The network interface specific data. 126 * @returns EOK on success. 127 * @returns EINVAL if there are some settings missing. 128 * @returns ENOENT if the internet protocol module is not known. 129 * @returns Other error codes as defined for the netif_probe_req() function. 130 * @returns Other error codes as defined for the nil_device_req() function. 131 * @returns Other error codes as defined for the needed internet layer registering function. 132 */ 133 int start_device(netif_ref netif); 134 135 /** Reads the configuration and starts all network interfaces. 136 * @returns EOK on success. 137 * @returns EXDEV if there is no available system-unique device identifier. 138 * @returns EINVAL if any of the network interface names are not configured. 139 * @returns ENOMEM if there is not enough memory left. 140 * @returns Other error codes as defined for the read_configuration() function. 141 * @returns Other error codes as defined for the read_netif_configuration() function. 142 * @returns Other error codes as defined for the start_device() function. 143 */ 144 int startup(void); 145 146 GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t) 147 148 DEVICE_MAP_IMPLEMENT(netifs, netif_t) 149 150 int add_configuration(measured_strings_ref configuration, const char * name, const char * value){ 151 ERROR_DECLARE; 152 153 measured_string_ref setting; 154 155 setting = measured_string_create_bulk(value, 0); 156 if(! setting){ 78 * 79 */ 80 net_globals_t net_globals; 81 82 GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t); 83 DEVICE_MAP_IMPLEMENT(netifs, netif_t); 84 85 /** Add the configured setting to the configuration map. 86 * 87 * @param[in] configuration The configuration map. 88 * @param[in] name The setting name. 89 * @param[in] value The setting value. 90 * 91 * @returns EOK on success. 92 * @returns ENOMEM if there is not enough memory left. 93 * 94 */ 95 int add_configuration(measured_strings_ref configuration, const char *name, 96 const char *value) 97 { 98 ERROR_DECLARE; 99 100 measured_string_ref setting = 101 measured_string_create_bulk(value, 0); 102 103 if (!setting) 157 104 return ENOMEM; 158 }159 / / add the configuration setting160 if (ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){105 106 /* Add the configuration setting */ 107 if (ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))) { 161 108 free(setting); 162 109 return ERROR_CODE; 163 110 } 164 return EOK; 165 } 166 167 device_id_t generate_new_device_id(void){ 111 112 return EOK; 113 } 114 115 /** Generate new system-unique device identifier. 116 * 117 * @returns The system-unique devic identifier. 118 * 119 */ 120 static device_id_t generate_new_device_id(void) 121 { 168 122 return device_assign_devno(); 169 123 } 170 124 171 /** Starts the networking module. 172 * Initializes the client connection serving function, initializes the module, registers the module service and starts the async manager, processing IPC messages in an infinite loop. 173 * @param[in] client_connection The client connection processing function. The module skeleton propagates its own one. 174 * @returns EOK on successful module termination. 175 * @returns Other error codes as defined for the net_initialize() function. 176 * @returns Other error codes as defined for the REGISTER_ME() macro function. 177 */ 178 static int net_module_start(async_client_conn_t client_connection){ 179 ERROR_DECLARE; 180 181 ipcarg_t phonehash; 182 183 async_set_client_connection(client_connection); 184 ERROR_PROPAGATE(pm_init()); 185 if(ERROR_OCCURRED(net_initialize(client_connection)) 186 || ERROR_OCCURRED(REGISTER_ME(SERVICE_NETWORKING, &phonehash))){ 187 pm_destroy(); 125 static int parse_line(measured_strings_ref configuration, char *line) 126 { 127 ERROR_DECLARE; 128 129 /* From the beginning */ 130 char *name = line; 131 132 /* Skip comments and blank lines */ 133 if ((*name == '#') || (*name == '\0')) 134 return EOK; 135 136 /* Skip spaces */ 137 while (isspace(*name)) 138 name++; 139 140 /* Remember the name start */ 141 char *value = name; 142 143 /* Skip the name */ 144 while (isalnum(*value) || (*value == '_')) 145 value++; 146 147 if (*value == '=') { 148 /* Terminate the name */ 149 *value = '\0'; 150 } else { 151 /* Terminate the name */ 152 *value = '\0'; 153 154 /* Skip until '=' */ 155 value++; 156 while ((*value) && (*value != '=')) 157 value++; 158 159 /* Not found? */ 160 if (*value != '=') 161 return EINVAL; 162 } 163 164 value++; 165 166 /* Skip spaces */ 167 while (isspace(*value)) 168 value++; 169 170 /* Create a bulk measured string till the end */ 171 measured_string_ref setting = 172 measured_string_create_bulk(value, 0); 173 if (!setting) 174 return ENOMEM; 175 176 /* Add the configuration setting */ 177 if (ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))) { 178 free(setting); 188 179 return ERROR_CODE; 189 180 } 190 191 async_manager(); 192 193 pm_destroy(); 194 return EOK; 195 } 196 197 int net_connect_module(services_t service){ 198 return EOK; 199 } 200 201 void net_free_settings(measured_string_ref settings, char * data){ 202 } 203 204 int net_get_conf(measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data){ 205 measured_string_ref setting; 206 size_t index; 207 208 if(data){ 209 *data = NULL; 210 } 211 212 for(index = 0; index < count; ++ index){ 213 setting = measured_strings_find(netif_conf, configuration[index].value, 0); 214 if(! setting){ 215 setting = measured_strings_find(&net_globals.configuration, configuration[index].value, 0); 181 182 return EOK; 183 } 184 185 static int read_configuration_file(const char *directory, const char *filename, 186 measured_strings_ref configuration) 187 { 188 ERROR_DECLARE; 189 190 printf("%s: Reading configuration file %s/%s\n", NAME, directory, filename); 191 192 /* Construct the full filename */ 193 char line[BUFFER_SIZE]; 194 if (snprintf(line, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE) 195 return EOVERFLOW; 196 197 /* Open the file */ 198 FILE *cfg = fopen(line, "r"); 199 if (!cfg) 200 return ENOENT; 201 202 /* 203 * Read the configuration line by line 204 * until an error or the end of file 205 */ 206 unsigned int line_number = 0; 207 size_t index = 0; 208 while ((!ferror(cfg)) && (!feof(cfg))) { 209 int read = fgetc(cfg); 210 if ((read > 0) && (read != '\n') && (read != '\r')) { 211 if (index >= BUFFER_SIZE) { 212 line[BUFFER_SIZE - 1] = '\0'; 213 fprintf(stderr, "%s: Configuration line %u too long: %s\n", 214 NAME, line_number, line); 215 216 /* No space left in the line buffer */ 217 return EOVERFLOW; 218 } else { 219 /* Append the character */ 220 line[index] = (char) read; 221 index++; 222 } 223 } else { 224 /* On error or new line */ 225 line[index] = '\0'; 226 line_number++; 227 if (ERROR_OCCURRED(parse_line(configuration, line))) 228 fprintf(stderr, "%s: Configuration error on line %u: %s\n", 229 NAME, line_number, line); 230 231 index = 0; 216 232 } 217 if(setting){ 218 configuration[index].length = setting->length; 219 configuration[index].value = setting->value; 220 }else{ 221 configuration[index].length = 0; 222 configuration[index].value = NULL; 223 } 224 } 225 return EOK; 226 } 227 228 int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data){ 229 if(!(configuration && (count > 0))){ 230 return EINVAL; 231 } 232 233 return net_get_conf(NULL, * configuration, count, data); 234 } 235 236 int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data){ 237 netif_ref netif; 238 239 if(!(configuration && (count > 0))){ 240 return EINVAL; 241 } 242 243 netif = netifs_find(&net_globals.netifs, device_id); 244 if(netif){ 245 return net_get_conf(&netif->configuration, * configuration, count, data); 246 }else{ 247 return net_get_conf(NULL, * configuration, count, data); 248 } 249 } 250 251 int net_initialize(async_client_conn_t client_connection){ 252 ERROR_DECLARE; 253 233 } 234 235 fclose(cfg); 236 return EOK; 237 } 238 239 /** Read the network interface specific configuration. 240 * 241 * @param[in] name The network interface name. 242 * @param[in,out] netif The network interface structure. 243 * 244 * @returns EOK on success. 245 * @returns Other error codes as defined for the add_configuration() function. 246 * 247 */ 248 static int read_netif_configuration(const char *name, netif_t *netif) 249 { 250 return read_configuration_file(CONF_DIR, name, &netif->configuration); 251 } 252 253 /** Read the networking subsystem global configuration. 254 * 255 * @returns EOK on success. 256 * @returns Other error codes as defined for the add_configuration() function. 257 * 258 */ 259 static int read_configuration(void) 260 { 261 return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, 262 &net_globals.configuration); 263 } 264 265 /** Initialize the networking module. 266 * 267 * @param[in] client_connection The client connection processing 268 * function. The module skeleton propagates 269 * its own one. 270 * 271 * @returns EOK on success. 272 * @returns ENOMEM if there is not enough memory left. 273 * 274 */ 275 static int net_initialize(async_client_conn_t client_connection) 276 { 277 ERROR_DECLARE; 278 254 279 netifs_initialize(&net_globals.netifs); 255 280 char_map_initialize(&net_globals.netif_names); 256 281 modules_initialize(&net_globals.modules); 257 282 measured_strings_initialize(&net_globals.configuration); 258 259 // TODO dynamic configuration283 284 // TODO: dynamic configuration 260 285 ERROR_PROPAGATE(read_configuration()); 261 262 ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service)); 263 ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service)); 264 ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service)); 265 ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service)); 266 267 // build specific initialization 286 287 ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, 288 LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service)); 289 ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, 290 DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service)); 291 ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, 292 ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0, 293 connect_to_service)); 294 ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, 295 NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, 296 connect_to_service)); 297 298 /* Build specific initialization */ 268 299 return net_initialize_build(client_connection); 269 300 } 270 301 271 int net_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 272 ERROR_DECLARE; 273 302 /** Start the networking module. 303 * 304 * Initializes the client connection serving function, 305 * initializes the module, registers the module service 306 * and starts the async manager, processing IPC messages 307 * in an infinite loop. 308 * 309 * @param[in] client_connection The client connection 310 * processing function. The 311 * module skeleton propagates 312 * its own one. 313 * 314 * @returns EOK on successful module termination. 315 * @returns Other error codes as defined for the net_initialize() function. 316 * @returns Other error codes as defined for the REGISTER_ME() macro function. 317 * 318 */ 319 static int net_module_start(async_client_conn_t client_connection) 320 { 321 ERROR_DECLARE; 322 323 async_set_client_connection(client_connection); 324 ERROR_PROPAGATE(pm_init()); 325 326 ipcarg_t phonehash; 327 328 if (ERROR_OCCURRED(net_initialize(client_connection)) 329 || ERROR_OCCURRED(REGISTER_ME(SERVICE_NETWORKING, &phonehash))){ 330 pm_destroy(); 331 return ERROR_CODE; 332 } 333 334 async_manager(); 335 336 pm_destroy(); 337 return EOK; 338 } 339 340 /** Return the configured values. 341 * 342 * The network interface configuration is searched first. 343 & 344 * @param[in] netif_conf The network interface configuration setting. 345 * @param[out] configuration The found configured values. 346 * @param[in] count The desired settings count. 347 * @param[out] data The found configuration settings data. 348 * 349 * @returns EOK. 350 * 351 */ 352 static int net_get_conf(measured_strings_ref netif_conf, 353 measured_string_ref configuration, size_t count, char **data) 354 { 355 if (data) 356 *data = NULL; 357 358 size_t index; 359 for (index = 0; index < count; index++) { 360 measured_string_ref setting = 361 measured_strings_find(netif_conf, configuration[index].value, 0); 362 if (!setting) 363 setting = measured_strings_find(&net_globals.configuration, 364 configuration[index].value, 0); 365 366 if (setting) { 367 configuration[index].length = setting->length; 368 configuration[index].value = setting->value; 369 } else { 370 configuration[index].length = 0; 371 configuration[index].value = NULL; 372 } 373 } 374 375 return EOK; 376 } 377 378 int net_get_conf_req(int net_phone, measured_string_ref *configuration, 379 size_t count, char **data) 380 { 381 if (!(configuration && (count > 0))) 382 return EINVAL; 383 384 return net_get_conf(NULL, *configuration, count, data); 385 } 386 387 int net_get_device_conf_req(int net_phone, device_id_t device_id, 388 measured_string_ref *configuration, size_t count, char **data) 389 { 390 if ((!configuration) || (count == 0)) 391 return EINVAL; 392 393 netif_t *netif = netifs_find(&net_globals.netifs, device_id); 394 if (netif) 395 return net_get_conf(&netif->configuration, *configuration, count, data); 396 else 397 return net_get_conf(NULL, *configuration, count, data); 398 } 399 400 void net_free_settings(measured_string_ref settings, char *data) 401 { 402 } 403 404 /** Start the network interface according to its configuration. 405 * 406 * Register the network interface with the subsystem modules. 407 * Start the needed subsystem modules. 408 * 409 * @param[in] netif The network interface specific data. 410 * 411 * @returns EOK on success. 412 * @returns EINVAL if there are some settings missing. 413 * @returns ENOENT if the internet protocol module is not known. 414 * @returns Other error codes as defined for the netif_probe_req() function. 415 * @returns Other error codes as defined for the nil_device_req() function. 416 * @returns Other error codes as defined for the needed internet layer 417 * registering function. 418 * 419 */ 420 static int start_device(netif_t *netif) 421 { 422 ERROR_DECLARE; 423 424 /* Mandatory netif */ 425 measured_string_ref setting = 426 measured_strings_find(&netif->configuration, CONF_NETIF, 0); 427 428 netif->driver = get_running_module(&net_globals.modules, setting->value); 429 if (!netif->driver) { 430 fprintf(stderr, "%s: Failed to start network interface driver '%s'\n", 431 NAME, setting->value); 432 return EINVAL; 433 } 434 435 /* Optional network interface layer */ 436 setting = measured_strings_find(&netif->configuration, CONF_NIL, 0); 437 if (setting) { 438 netif->nil = get_running_module(&net_globals.modules, setting->value); 439 if (!netif->nil) { 440 fprintf(stderr, "%s: Failed to start network interface layer '%s'\n", 441 NAME, setting->value); 442 return EINVAL; 443 } 444 } else 445 netif->nil = NULL; 446 447 /* Mandatory internet layer */ 448 setting = measured_strings_find(&netif->configuration, CONF_IL, 0); 449 netif->il = get_running_module(&net_globals.modules, setting->value); 450 if (!netif->il) { 451 fprintf(stderr, "%s: Failed to start internet layer '%s'\n", 452 NAME, setting->value); 453 return EINVAL; 454 } 455 456 /* Hardware configuration */ 457 setting = measured_strings_find(&netif->configuration, CONF_IRQ, 0); 458 int irq = setting ? strtol(setting->value, NULL, 10) : 0; 459 460 setting = measured_strings_find(&netif->configuration, CONF_IO, 0); 461 int io = setting ? strtol(setting->value, NULL, 16) : 0; 462 463 ERROR_PROPAGATE(netif_probe_req(netif->driver->phone, netif->id, irq, io)); 464 465 /* Network interface layer startup */ 466 services_t internet_service; 467 if (netif->nil) { 468 setting = measured_strings_find(&netif->configuration, CONF_MTU, 0); 469 if (!setting) 470 setting = measured_strings_find(&net_globals.configuration, 471 CONF_MTU, 0); 472 473 int mtu = setting ? strtol(setting->value, NULL, 10) : 0; 474 475 ERROR_PROPAGATE(nil_device_req(netif->nil->phone, netif->id, mtu, 476 netif->driver->service)); 477 478 internet_service = netif->nil->service; 479 } else 480 internet_service = netif->driver->service; 481 482 /* Inter-network layer startup */ 483 switch (netif->il->service) { 484 case SERVICE_IP: 485 ERROR_PROPAGATE(ip_device_req(netif->il->phone, netif->id, 486 internet_service)); 487 break; 488 default: 489 return ENOENT; 490 } 491 492 ERROR_PROPAGATE(netif_start_req(netif->driver->phone, netif->id)); 493 return EOK; 494 } 495 496 /** Read the configuration and start all network interfaces. 497 * 498 * @returns EOK on success. 499 * @returns EXDEV if there is no available system-unique device identifier. 500 * @returns EINVAL if any of the network interface names are not configured. 501 * @returns ENOMEM if there is not enough memory left. 502 * @returns Other error codes as defined for the read_configuration() 503 * function. 504 * @returns Other error codes as defined for the read_netif_configuration() 505 * function. 506 * @returns Other error codes as defined for the start_device() function. 507 * 508 */ 509 static int startup(void) 510 { 511 ERROR_DECLARE; 512 513 const char *conf_files[] = {"lo", "ne2k"}; 514 size_t count = sizeof(conf_files) / sizeof(char *); 515 516 size_t i; 517 for (i = 0; i < count; i++) { 518 netif_t *netif = (netif_t *) malloc(sizeof(netif_t)); 519 if (!netif) 520 return ENOMEM; 521 522 netif->id = generate_new_device_id(); 523 if (!netif->id) 524 return EXDEV; 525 526 ERROR_PROPAGATE(measured_strings_initialize(&netif->configuration)); 527 528 /* Read configuration files */ 529 if (ERROR_OCCURRED(read_netif_configuration(conf_files[i], netif))) { 530 measured_strings_destroy(&netif->configuration); 531 free(netif); 532 return ERROR_CODE; 533 } 534 535 /* Mandatory name */ 536 measured_string_ref setting = 537 measured_strings_find(&netif->configuration, CONF_NAME, 0); 538 if (!setting) { 539 fprintf(stderr, "%s: Network interface name is missing\n", NAME); 540 measured_strings_destroy(&netif->configuration); 541 free(netif); 542 return EINVAL; 543 } 544 netif->name = setting->value; 545 546 /* Add to the netifs map */ 547 int index = netifs_add(&net_globals.netifs, netif->id, netif); 548 if (index < 0) { 549 measured_strings_destroy(&netif->configuration); 550 free(netif); 551 return index; 552 } 553 554 /* 555 * Add to the netif names map and start network interfaces 556 * and needed modules. 557 */ 558 if ((ERROR_OCCURRED(char_map_add(&net_globals.netif_names, 559 netif->name, 0, index))) || (ERROR_OCCURRED(start_device(netif)))) { 560 measured_strings_destroy(&netif->configuration); 561 netifs_exclude_index(&net_globals.netifs, index); 562 return ERROR_CODE; 563 } 564 565 /* Increment modules' usage */ 566 netif->driver->usage++; 567 if (netif->nil) 568 netif->nil->usage++; 569 netif->il->usage++; 570 571 printf("%s: Network interface started (name: %s, id: %d, driver: %s, " 572 "nil: %s, il: %s)\n", NAME, netif->name, netif->id, 573 netif->driver->name, netif->nil ? netif->nil->name : "[none]", 574 netif->il->name); 575 } 576 577 return EOK; 578 } 579 580 /** Process the networking message. 581 * 582 * @param[in] callid The message identifier. 583 * @param[in] call The message parameters. 584 * @param[out] answer The message answer parameters. 585 * @param[out] answer_count The last parameter for the actual answer 586 * in the answer parameter. 587 * 588 * @returns EOK on success. 589 * @returns ENOTSUP if the message is not known. 590 * 591 * @see net_interface.h 592 * @see IS_NET_NET_MESSAGE() 593 * 594 */ 595 int net_message(ipc_callid_t callid, ipc_call_t *call, ipc_call_t *answer, 596 int *answer_count) 597 { 598 ERROR_DECLARE; 599 274 600 measured_string_ref strings; 275 char * 276 601 char *data; 602 277 603 *answer_count = 0; 278 switch (IPC_GET_METHOD(*call)){604 switch (IPC_GET_METHOD(*call)) { 279 605 case IPC_M_PHONE_HUNGUP: 280 606 return EOK; 281 607 case NET_NET_GET_DEVICE_CONF: 282 ERROR_PROPAGATE(measured_strings_receive(&strings, &data, IPC_GET_COUNT(call))); 283 net_get_device_conf_req(0, IPC_GET_DEVICE(call), &strings, IPC_GET_COUNT(call), NULL); 284 // strings should not contain received data anymore 608 ERROR_PROPAGATE(measured_strings_receive(&strings, &data, 609 IPC_GET_COUNT(call))); 610 net_get_device_conf_req(0, IPC_GET_DEVICE(call), &strings, 611 IPC_GET_COUNT(call), NULL); 612 613 /* Strings should not contain received data anymore */ 285 614 free(data); 615 286 616 ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call)); 287 617 free(strings); 288 618 return ERROR_CODE; 289 619 case NET_NET_GET_CONF: 290 ERROR_PROPAGATE(measured_strings_receive(&strings, &data, IPC_GET_COUNT(call))); 620 ERROR_PROPAGATE(measured_strings_receive(&strings, &data, 621 IPC_GET_COUNT(call))); 291 622 net_get_conf_req(0, &strings, IPC_GET_COUNT(call), NULL); 292 // strings should not contain received data anymore 623 624 /* Strings should not contain received data anymore */ 293 625 free(data); 626 294 627 ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call)); 295 628 free(strings); … … 301 634 } 302 635 303 int parse_line(measured_strings_ref configuration, char * line){304 ERROR_DECLARE;305 306 measured_string_ref setting;307 char * name;308 char * value;309 310 // from the beginning311 name = line;312 313 // skip comments and blank lines314 if((*name == '#') || (*name == '\0')){315 return EOK;316 }317 // skip spaces318 while(isspace(*name)){319 ++ name;320 }321 322 // remember the name start323 value = name;324 // skip the name325 while(isalnum(*value) || (*value == '_')){326 // make uppercase327 // *value = toupper(*value);328 ++ value;329 }330 331 if(*value == '='){332 // terminate the name333 *value = '\0';334 }else{335 // terminate the name336 *value = '\0';337 // skip until '='338 ++ value;339 while((*value) && (*value != '=')){340 ++ value;341 }342 // not found?343 if(*value != '='){344 return EINVAL;345 }346 }347 348 ++ value;349 // skip spaces350 while(isspace(*value)){351 ++ value;352 }353 // create a bulk measured string till the end354 setting = measured_string_create_bulk(value, 0);355 if(! setting){356 return ENOMEM;357 }358 359 // add the configuration setting360 if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){361 free(setting);362 return ERROR_CODE;363 }364 return EOK;365 }366 367 int read_configuration(void){368 // read the general configuration file369 return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, &net_globals.configuration);370 }371 372 int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration){373 ERROR_DECLARE;374 375 size_t index = 0;376 char line[BUFFER_SIZE];377 FILE * cfg;378 int read;379 int line_number = 0;380 381 // construct the full filename382 printf("Reading file %s/%s\n", directory, filename);383 if(snprintf(line, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE){384 return EOVERFLOW;385 }386 // open the file387 cfg = fopen(line, "r");388 if(! cfg){389 return ENOENT;390 }391 392 // read the configuration line by line393 // until an error or the end of file394 while((! ferror(cfg)) && (! feof(cfg))){395 read = fgetc(cfg);396 if((read > 0) && (read != '\n') && (read != '\r')){397 if(index >= BUFFER_SIZE){398 line[BUFFER_SIZE - 1] = '\0';399 printf("line %d too long: %s\n", line_number, line);400 // no space left in the line buffer401 return EOVERFLOW;402 }else{403 // append the character404 line[index] = (char) read;405 ++ index;406 }407 }else{408 // on error or new line409 line[index] = '\0';410 ++ line_number;411 if(ERROR_OCCURRED(parse_line(configuration, line))){412 printf("error on line %d: %s\n", line_number, line);413 //fclose(cfg);414 //return ERROR_CODE;415 }416 index = 0;417 }418 }419 fclose(cfg);420 return EOK;421 }422 423 int read_netif_configuration(const char * name, netif_ref netif){424 // read the netif configuration file425 return read_configuration_file(CONF_DIR, name, &netif->configuration);426 }427 428 int start_device(netif_ref netif){429 ERROR_DECLARE;430 431 measured_string_ref setting;432 services_t internet_service;433 int irq;434 int io;435 int mtu;436 437 // mandatory netif438 setting = measured_strings_find(&netif->configuration, CONF_NETIF, 0);439 netif->driver = get_running_module(&net_globals.modules, setting->value);440 if(! netif->driver){441 printf("Failed to start the network interface driver %s\n", setting->value);442 return EINVAL;443 }444 445 // optional network interface layer446 setting = measured_strings_find(&netif->configuration, CONF_NIL, 0);447 if(setting){448 netif->nil = get_running_module(&net_globals.modules, setting->value);449 if(! netif->nil){450 printf("Failed to start the network interface layer %s\n", setting->value);451 return EINVAL;452 }453 }else{454 netif->nil = NULL;455 }456 457 // mandatory internet layer458 setting = measured_strings_find(&netif->configuration, CONF_IL, 0);459 netif->il = get_running_module(&net_globals.modules, setting->value);460 if(! netif->il){461 printf("Failed to start the internet layer %s\n", setting->value);462 return EINVAL;463 }464 465 // hardware configuration466 setting = measured_strings_find(&netif->configuration, CONF_IRQ, 0);467 irq = setting ? strtol(setting->value, NULL, 10) : 0;468 setting = measured_strings_find(&netif->configuration, CONF_IO, 0);469 io = setting ? strtol(setting->value, NULL, 16) : 0;470 ERROR_PROPAGATE(netif_probe_req(netif->driver->phone, netif->id, irq, io));471 472 // network interface layer startup473 if(netif->nil){474 setting = measured_strings_find(&netif->configuration, CONF_MTU, 0);475 if(! setting){476 setting = measured_strings_find(&net_globals.configuration, CONF_MTU, 0);477 }478 mtu = setting ? strtol(setting->value, NULL, 10) : 0;479 ERROR_PROPAGATE(nil_device_req(netif->nil->phone, netif->id, mtu, netif->driver->service));480 internet_service = netif->nil->service;481 }else{482 internet_service = netif->driver->service;483 }484 485 // inter-network layer startup486 switch(netif->il->service){487 case SERVICE_IP:488 ERROR_PROPAGATE(ip_device_req(netif->il->phone, netif->id, internet_service));489 break;490 default:491 return ENOENT;492 }493 ERROR_PROPAGATE(netif_start_req(netif->driver->phone, netif->id));494 return EOK;495 }496 497 int startup(void){498 ERROR_DECLARE;499 500 const char * conf_files[] = {"lo", "ne2k"};501 502 int count = sizeof(conf_files) / sizeof(char *);503 int index;504 netif_ref netif;505 int i;506 measured_string_ref setting;507 508 for(i = 0; i < count; ++ i){509 netif = (netif_ref) malloc(sizeof(netif_t));510 if(! netif){511 return ENOMEM;512 }513 514 netif->id = generate_new_device_id();515 if(! netif->id){516 return EXDEV;517 }518 ERROR_PROPAGATE(measured_strings_initialize(&netif->configuration));519 520 // read configuration files521 if(ERROR_OCCURRED(read_netif_configuration(conf_files[i], netif))){522 measured_strings_destroy(&netif->configuration);523 free(netif);524 return ERROR_CODE;525 }526 527 // mandatory name528 setting = measured_strings_find(&netif->configuration, CONF_NAME, 0);529 if(! setting){530 printf("The name is missing\n");531 measured_strings_destroy(&netif->configuration);532 free(netif);533 return EINVAL;534 }535 netif->name = setting->value;536 537 // add to the netifs map538 index = netifs_add(&net_globals.netifs, netif->id, netif);539 if(index < 0){540 measured_strings_destroy(&netif->configuration);541 free(netif);542 return index;543 }544 545 // add to the netif names map546 if(ERROR_OCCURRED(char_map_add(&net_globals.netif_names, netif->name, 0, index))547 // start network interfaces and needed modules548 || ERROR_OCCURRED(start_device(netif))){549 measured_strings_destroy(&netif->configuration);550 netifs_exclude_index(&net_globals.netifs, index);551 return ERROR_CODE;552 }553 554 // increment modules' usage555 ++ netif->driver->usage;556 if(netif->nil){557 ++ netif->nil->usage;558 }559 ++ netif->il->usage;560 printf("New network interface started:\n\tname\t= %s\n\tid\t= %d\n\tdriver\t= %s\n\tnil\t= %s\n\til\t= %s\n", netif->name, netif->id, netif->driver->name, netif->nil ? netif->nil->name : NULL, netif->il->name);561 }562 return EOK;563 }564 565 636 /** Default thread for new connections. 566 637 * 567 * 568 * 569 * 570 */ 571 static void net_client_connection(ipc_callid_t iid, ipc_call_t * 638 * @param[in] iid The initial message identifier. 639 * @param[in] icall The initial message call structure. 640 * 641 */ 642 static void net_client_connection(ipc_callid_t iid, ipc_call_t *icall) 572 643 { 573 644 /* … … 577 648 ipc_answer_0(iid, EOK); 578 649 579 while(true) { 650 while (true) { 651 /* Clear the answer structure */ 580 652 ipc_call_t answer; 581 653 int answer_count; 582 583 /* Clear the answer structure */584 654 refresh_answer(&answer, &answer_count); 585 655 … … 600 670 } 601 671 602 /** Starts the module.603 *604 * @param argc The count of the command line arguments. Ignored parameter.605 * @param argv The command line parameters. Ignored parameter.606 *607 * @returns EOK on success.608 * @returns Other error codes as defined for each specific module start function.609 *610 */611 672 int main(int argc, char *argv[]) 612 673 { 613 674 ERROR_DECLARE; 614 675 615 /* Print the module label */616 printf("Task %d - %s\n", task_get_id(), NAME);617 618 /* Start the module */619 676 if (ERROR_OCCURRED(net_module_start(net_client_connection))) { 620 printf(" - ERROR %i\n", ERROR_CODE);677 fprintf(stderr, "%s: net_module_start error %i\n", NAME, ERROR_CODE); 621 678 return ERROR_CODE; 622 679 } -
uspace/srv/net/net/net.h
r4dd8529 r24ab58b3 28 28 29 29 /** @addtogroup net 30 * 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Networking subsystem central module. 34 * Networking subsystem central module. 35 * 35 36 */ 36 37 … … 48 49 49 50 /** @name Modules definitions 51 * @{ 50 52 */ 51 /*@{*/52 53 53 /** DP8390 network interface module full path filename. 54 #define DP8390_FILENAME "/srv/dp8390" 55 #define DP8390_NAME "dp8390" 56 57 #define ETHERNET_FILENAME "/srv/eth" 58 #define ETHERNET_NAME "eth" 59 60 #define IP_FILENAME "/srv/ip" 61 #define IP_NAME "ip" 62 63 #define LO_FILENAME "/srv/lo" 64 #define LO_NAME "lo" 65 66 #define NILDUMMY_FILENAME "/srv/nildummy" 67 #define NILDUMMY_NAME "nildummy" 68 69 /** @} 54 70 */ 55 #define DP8390_FILENAME "/srv/dp8390"56 57 /** DP8390 network interface module name.58 */59 #define DP8390_NAME "dp8390"60 61 /** Ethernet module full path filename.62 */63 #define ETHERNET_FILENAME "/srv/eth"64 65 /** Ethernet module name.66 */67 #define ETHERNET_NAME "ethernet"68 69 /** IP module full path filename.70 */71 #define IP_FILENAME "/srv/ip"72 73 /** IP module name.74 */75 #define IP_NAME "ip"76 77 /** Loopback network interface module full path filename.78 */79 #define LO_FILENAME "/srv/lo"80 81 /** Loopback network interface module name.82 */83 #define LO_NAME "lo"84 85 /** Ethernet module full path filename.86 */87 #define NILDUMMY_FILENAME "/srv/nildummy"88 89 /** Ethernet module name.90 */91 #define NILDUMMY_NAME "nildummy"92 93 /*@}*/94 71 95 72 /** @name Configuration setting names definitions 73 * @{ 96 74 */ 97 /*@{*/98 75 99 /** Internet protocol module name configuration label. 76 #define CONF_IL "IL" /**< Internet protocol module name configuration label. */ 77 #define CONF_IO "IO" /**< Device input/output address configuration label. */ 78 #define CONF_IRQ "IRQ" /**< Interrupt number configuration label. */ 79 #define CONF_MTU "MTU" /**< Maximum transmission unit configuration label. */ 80 #define CONF_NAME "NAME" /**< Network interface name configuration label. */ 81 #define CONF_NETIF "NETIF" /**< Network interface module name configuration label. */ 82 #define CONF_NIL "NIL" /**< Network interface layer module name configuration label. */ 83 84 /** @} 100 85 */ 101 #define CONF_IL "IL"102 86 103 /** Device input/output address configuration label. 104 */ 105 #define CONF_IO "IO" 106 107 /** Interrupt number configuration label. 108 */ 109 #define CONF_IRQ "IRQ" 110 111 /** Maximum transmission unit configuration label. 112 */ 113 #define CONF_MTU "MTU" 114 115 /** Network interface name configuration label. 116 */ 117 #define CONF_NAME "NAME" 118 119 /** Network interface module name configuration label. 120 */ 121 #define CONF_NETIF "NETIF" 122 123 /** Network interface layer module name configuration label. 124 */ 125 #define CONF_NIL "NIL" 126 127 /*@}*/ 128 129 /** Configuration directory. 130 */ 131 #define CONF_DIR "/cfg/net" 132 133 /** General configuration file. 134 */ 135 #define CONF_GENERAL_FILE "general" 136 137 /** Type definition of the networking module global data. 138 * @see net_globals 139 */ 140 typedef struct net_globals net_globals_t; 141 142 /** Type definition of the network interface specific data. 143 * @see netif 144 */ 145 typedef struct netif netif_t; 146 147 /** Type definition of the network interface specific data pointer. 148 * @see netif 149 */ 150 typedef netif_t * netif_ref; 87 #define CONF_DIR "/cfg/net" /**< Configuration directory. */ 88 #define CONF_GENERAL_FILE "general" /**< General configuration file. */ 151 89 152 90 /** Configuration settings. 153 * Maps setting names to the values. 154 * @see generic_char_map.h 91 * 92 * Maps setting names to the values. 93 * @see generic_char_map.h 94 * 155 95 */ 156 GENERIC_CHAR_MAP_DECLARE(measured_strings, measured_string_t) 96 GENERIC_CHAR_MAP_DECLARE(measured_strings, measured_string_t); 97 98 /** Present network interface device. 99 * 100 */ 101 typedef struct { 102 measured_strings_t configuration; /**< Configuration. */ 103 104 /** Serving network interface driver module index. */ 105 module_ref driver; 106 107 device_id_t id; /**< System-unique network interface identifier. */ 108 module_ref il; /**< Serving internet layer module index. */ 109 char *name; /**< System-unique network interface name. */ 110 module_ref nil; /**< Serving link layer module index. */ 111 } netif_t; 157 112 158 113 /** Present network interfaces. 159 * Maps devices to the networking device specific data. 160 * @see device.h 114 * 115 * Maps devices to the networking device specific data. 116 * @see device.h 117 * 161 118 */ 162 DEVICE_MAP_DECLARE(netifs, netif_t) 119 DEVICE_MAP_DECLARE(netifs, netif_t); 163 120 164 /** Networking module global variables. 121 /** Networking module global data. 122 * 165 123 */ 166 struct net_globals{ 167 /** Global configuration. 168 */ 169 measured_strings_t configuration; 170 /** Available modules. 171 */ 172 modules_t modules; 173 /** Network interface structure indices by names. 174 */ 124 typedef struct { 125 measured_strings_t configuration; /**< Global configuration. */ 126 modules_t modules; /**< Available modules. */ 127 128 /** Network interface structure indices by names. */ 175 129 char_map_t netif_names; 176 /** Present network interfaces.177 */130 131 /** Present network interfaces. */ 178 132 netifs_t netifs; 179 } ;133 } net_globals_t; 180 134 181 /** Present network interface device. 182 */ 183 struct netif{ 184 /** Configuration. 185 */ 186 measured_strings_t configuration; 187 /** Serving network interface driver module index. 188 */ 189 module_ref driver; 190 /** System-unique network interface identifier. 191 */ 192 device_id_t id; 193 /** Serving internet layer module index. 194 */ 195 module_ref il; 196 /** System-unique network interface name. 197 */ 198 char * name; 199 /** Serving link layer module index. 200 */ 201 module_ref nil; 202 }; 203 204 /** Adds the configured setting to the configuration map. 205 * @param[in] configuration The configuration map. 206 * @param[in] name The setting name. 207 * @param[in] value The setting value. 208 * @returns EOK on success. 209 * @returns ENOMEM if there is not enough memory left. 210 */ 211 int add_configuration(measured_strings_ref configuration, const char * name, const char * value); 212 213 /** Processes the module message. 214 * Distributes the message to the right bundled module. 215 * @param[in] callid The message identifier. 216 * @param[in] call The message parameters. 217 * @param[out] answer The message answer parameters. 218 * @param[out] answer_count The last parameter for the actual answer in the answer parameter. 219 * @returns EOK on success. 220 * @returns ENOTSUP if the message is not known. 221 * @returns Other error codes as defined for each bundled module message function. 222 */ 223 int net_module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count); 224 225 /** Initializes the networking module for the chosen subsystem build type. 226 * @param[in] client_connection The client connection processing function. The module skeleton propagates its own one. 227 * @returns EOK on success. 228 * @returns ENOMEM if there is not enough memory left. 229 */ 230 int net_initialize_build(async_client_conn_t client_connection); 231 232 /** Processes the networking message. 233 * @param[in] callid The message identifier. 234 * @param[in] call The message parameters. 235 * @param[out] answer The message answer parameters. 236 * @param[out] answer_count The last parameter for the actual answer in the answer parameter. 237 * @returns EOK on success. 238 * @returns ENOTSUP if the message is not known. 239 * @see net_interface.h 240 * @see IS_NET_NET_MESSAGE() 241 */ 242 int net_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count); 135 extern int add_configuration(measured_strings_ref, const char *, const char *); 136 extern int net_module_message(ipc_callid_t, ipc_call_t *, ipc_call_t *, int *); 137 extern int net_initialize_build(async_client_conn_t); 138 extern int net_message(ipc_callid_t, ipc_call_t *, ipc_call_t *, int *); 243 139 244 140 #endif -
uspace/srv/net/net/net_bundle.c
r4dd8529 r24ab58b3 60 60 extern net_globals_t net_globals; 61 61 62 /** Initializes the networking module for the chosen subsystem build type. 63 * @param[in] client_connection The client connection processing function. The module skeleton propagates its own one. 64 * @returns EOK on success. 65 * @returns ENOMEM if there is not enough memory left. 66 */ 62 67 int net_initialize_build(async_client_conn_t client_connection){ 63 68 ERROR_DECLARE; … … 79 84 } 80 85 86 /** Processes the module message. 87 * Distributes the message to the right bundled module. 88 * @param[in] callid The message identifier. 89 * @param[in] call The message parameters. 90 * @param[out] answer The message answer parameters. 91 * @param[out] answer_count The last parameter for the actual answer in the answer parameter. 92 * @returns EOK on success. 93 * @returns ENOTSUP if the message is not known. 94 * @returns Other error codes as defined for each bundled module message function. 95 */ 81 96 int net_module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 82 97 if((IPC_GET_METHOD(*call) == IPC_M_CONNECT_TO_ME) -
uspace/srv/net/net/net_standalone.c
r4dd8529 r24ab58b3 51 51 extern net_globals_t net_globals; 52 52 53 /** Initializes the networking module for the chosen subsystem build type. 54 * @param[in] client_connection The client connection processing function. The module skeleton propagates its own one. 55 * @returns EOK on success. 56 * @returns ENOMEM if there is not enough memory left. 57 */ 53 58 int net_initialize_build(async_client_conn_t client_connection){ 54 59 ERROR_DECLARE; … … 73 78 } 74 79 80 /** Processes the module message. 81 * Distributes the message to the right bundled module. 82 * @param[in] callid The message identifier. 83 * @param[in] call The message parameters. 84 * @param[out] answer The message answer parameters. 85 * @param[out] answer_count The last parameter for the actual answer in the answer parameter. 86 * @returns EOK on success. 87 * @returns ENOTSUP if the message is not known. 88 * @returns Other error codes as defined for each bundled module message function. 89 */ 75 90 int net_module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 76 91 if(IS_NET_PACKET_MESSAGE(call)){ -
uspace/srv/net/netif/lo/lo.c
r4dd8529 r24ab58b3 64 64 /** Loopback module name. 65 65 */ 66 #define NAME "lo - loopback interface"66 #define NAME "lo" 67 67 68 68 /** Network interface global data. … … 113 113 } 114 114 115 int change_state_message(device_ref device, device_state_t state){ 116 if(device->state != state){ 115 int change_state_message(device_ref device, device_state_t state) 116 { 117 if (device->state != state) { 117 118 device->state = state; 118 printf("State changed to %s\n", (state == NETIF_ACTIVE) ? "ACTIVE" : "STOPPED"); 119 120 printf("%s: State changed to %s\n", NAME, 121 (state == NETIF_ACTIVE) ? "active" : "stopped"); 122 119 123 return state; 120 124 } 125 121 126 return EOK; 122 127 } … … 166 171 ERROR_PROPAGATE(create(device_id, &device)); 167 172 // print the settings 168 printf(" New device created:\n\tid\t= %d\n", device->device_id);173 printf("%s: Device created (id: %d)\n", NAME, device->device_id); 169 174 return EOK; 170 175 } … … 237 242 238 243 /* Process the message */ 239 int res = netif_module_message(callid, &call, &answer, &answer_count); 244 int res = netif_module_message(NAME, callid, &call, &answer, 245 &answer_count); 240 246 241 247 /* End if said to either by the message or the processing result */ … … 261 267 ERROR_DECLARE; 262 268 263 /* Print the module label */264 printf("Task %d - %s\n", task_get_id(), NAME);265 266 269 /* Start the module */ 267 if (ERROR_OCCURRED(netif_module_start(netif_client_connection))) { 268 printf(" - ERROR %i\n", ERROR_CODE); 270 if (ERROR_OCCURRED(netif_module_start(netif_client_connection))) 269 271 return ERROR_CODE; 270 }271 272 272 273 return EOK; -
uspace/srv/net/netstart/netstart.c
r4dd8529 r24ab58b3 79 79 } 80 80 81 /** Network startup entry point.82 *83 * @param[in] argc The number of command line parameters.84 * @param[in] argv The command line parameters.85 *86 * @returns EOK on success.87 * @returns EINVAL if the net module cannot be started.88 * @returns Other error codes as defined for the self_test() function.89 * @returns Other error codes as defined for the NET_NET_STARTUP message.90 *91 */92 81 int main(int argc, char *argv[]) 93 82 { … … 105 94 int net_phone = connect_to_service(SERVICE_NETWORKING); 106 95 if (ERROR_OCCURRED(ipc_call_sync_0_0(net_phone, NET_NET_STARTUP))) { 107 fprintf(stderr, "%s: Networkingerror %d\n", NAME, ERROR_CODE);96 fprintf(stderr, "%s: Startup error %d\n", NAME, ERROR_CODE); 108 97 return ERROR_CODE; 109 98 } -
uspace/srv/net/netstart/self_test.c
r4dd8529 r24ab58b3 49 49 #include "self_test.h" 50 50 51 /** Test the function, compare the result and remember if the result differs. 52 * 53 * @param[in] name The test name. 54 * @param[in] function_call The function to be called and checked. 55 * @param[in] result The expected result. 51 /** Test the statement, compare the result and evaluate. 52 * 53 * @param[in] statement The statement to test. 54 * @param[in] result The expected result. 56 55 * 57 56 */ … … 85 84 INT_MAP_IMPLEMENT(int_map, int); 86 85 86 /** Self-test start function. 87 * 88 * Run all self-tests. 89 * 90 * @returns EOK on success. 91 * @returns The first error occurred. 92 * 93 */ 87 94 int self_test(void) 88 95 { -
uspace/srv/net/nil/eth/eth.c
r4dd8529 r24ab58b3 60 60 #include <adt/measured_strings.h> 61 61 #include <packet/packet_client.h> 62 #include <nil_module.h> 62 63 63 64 #include "eth.h" … … 66 67 /** The module name. 67 68 */ 68 #define NAME "Ethernet protocol"69 #define NAME "eth" 69 70 70 71 /** Reserved packet prefix length. … … 401 402 return index; 402 403 } 403 printf("New device registered:\n\tid\t= %d\n\tservice\t= %d\n\tMTU\t= %d\n\taddress\t= %X:%X:%X:%X:%X:%X\n\tflags\t= 0x%x\n", device->device_id, device->service, device->mtu, device->addr_data[0], device->addr_data[1], device->addr_data[2], device->addr_data[3], device->addr_data[4], device->addr_data[5], device->flags); 404 printf("%s: Device registered (id: %d, service: %d: mtu: %d, " 405 "mac: %x:%x:%x:%x:%x:%x, flags: 0x%x)\n", 406 NAME, device->device_id, device->service, device->mtu, 407 device->addr_data[0], device->addr_data[1], 408 device->addr_data[2], device->addr_data[3], 409 device->addr_data[4], device->addr_data[5], device->flags); 404 410 } 405 411 fibril_rwlock_write_unlock(ð_globals.devices_lock); … … 571 577 } 572 578 } 573 printf("New protocol registered:\n\tprotocol\t= 0x%x\n\tservice\t= %d\n\tphone\t= %d\n", proto->protocol, proto->service, proto->phone); 579 580 printf("%s: Protocol registered (protocol: %d, service: %d, phone: %d)\n", 581 NAME, proto->protocol, proto->service, proto->phone); 582 574 583 fibril_rwlock_write_unlock(ð_globals.protos_lock); 575 584 return EOK; … … 704 713 } 705 714 706 int nil_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 715 int nil_message(const char *name, ipc_callid_t callid, ipc_call_t *call, 716 ipc_call_t *answer, int *answer_count) 717 { 707 718 ERROR_DECLARE; 708 719 709 720 measured_string_ref address; 710 721 packet_t packet; … … 713 724 size_t suffix; 714 725 size_t content; 715 716 // printf("message %d - %d\n", IPC_GET_METHOD(*call), NET_NIL_FIRST); 726 717 727 *answer_count = 0; 718 switch (IPC_GET_METHOD(*call)){728 switch (IPC_GET_METHOD(*call)) { 719 729 case IPC_M_PHONE_HUNGUP: 720 730 return EOK; 721 731 case NET_NIL_DEVICE: 722 return eth_device_message(IPC_GET_DEVICE(call), IPC_GET_SERVICE(call), IPC_GET_MTU(call)); 732 return eth_device_message(IPC_GET_DEVICE(call), 733 IPC_GET_SERVICE(call), IPC_GET_MTU(call)); 723 734 case NET_NIL_SEND: 724 ERROR_PROPAGATE(packet_translate(eth_globals.net_phone, &packet, IPC_GET_PACKET(call))); 725 return eth_send_message(IPC_GET_DEVICE(call), packet, IPC_GET_SERVICE(call)); 735 ERROR_PROPAGATE(packet_translate(eth_globals.net_phone, &packet, 736 IPC_GET_PACKET(call))); 737 return eth_send_message(IPC_GET_DEVICE(call), packet, 738 IPC_GET_SERVICE(call)); 726 739 case NET_NIL_PACKET_SPACE: 727 ERROR_PROPAGATE(eth_packet_space_message(IPC_GET_DEVICE(call), &addrlen, &prefix, &content, &suffix)); 740 ERROR_PROPAGATE(eth_packet_space_message(IPC_GET_DEVICE(call), 741 &addrlen, &prefix, &content, &suffix)); 728 742 IPC_SET_ADDR(answer, addrlen); 729 743 IPC_SET_PREFIX(answer, prefix); … … 733 747 return EOK; 734 748 case NET_NIL_ADDR: 735 ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call), ETH_LOCAL_ADDR, &address)); 749 ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call), 750 ETH_LOCAL_ADDR, &address)); 736 751 return measured_strings_reply(address, 1); 737 752 case NET_NIL_BROADCAST_ADDR: 738 ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call), ETH_BROADCAST_ADDR, &address)); 753 ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call), 754 ETH_BROADCAST_ADDR, &address)); 739 755 return measured_strings_reply(address, 1); 740 756 case IPC_M_CONNECT_TO_ME: 741 return eth_register_message(NIL_GET_PROTO(call), IPC_GET_PHONE(call)); 742 } 757 return eth_register_message(NIL_GET_PROTO(call), 758 IPC_GET_PHONE(call)); 759 } 760 743 761 return ENOTSUP; 744 762 } … … 799 817 800 818 /* Process the message */ 801 int res = nil_module_message(callid, &call, &answer, &answer_count); 819 int res = nil_module_message(NAME, callid, &call, &answer, 820 &answer_count); 802 821 803 822 /* End if said to either by the message or the processing result */ … … 823 842 ERROR_DECLARE; 824 843 825 /* Print the module label */826 printf("Task %d - %s\n", task_get_id(), NAME);827 828 844 /* Start the module */ 829 if (ERROR_OCCURRED(nil_module_start(nil_client_connection))) { 830 printf(" - ERROR %i\n", ERROR_CODE); 845 if (ERROR_OCCURRED(nil_module_start(nil_client_connection))) 831 846 return ERROR_CODE; 832 }833 847 834 848 return EOK; -
uspace/srv/net/nil/eth/eth.h
r4dd8529 r24ab58b3 147 147 }; 148 148 149 /** Module initialization.150 * Is called by the module_start() function.151 * @param[in] net_phone The networking moduel phone.152 * @returns EOK on success.153 * @returns Other error codes as defined for each specific module initialize function.154 */155 extern int nil_initialize(int net_phone);156 157 /** Message processing function.158 * @param[in] callid The message identifier.159 * @param[in] call The message parameters.160 * @param[out] answer The message answer parameters.161 * @param[out] answer_count The last parameter for the actual answer in the answer parameter.162 * @returns EOK on success.163 * @returns ENOTSUP if the message is not known.164 * @returns Other error codes as defined for each specific module message function.165 * @see nil_interface.h166 * @see IS_NET_NIL_MESSAGE()167 */168 extern int nil_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);169 170 149 #endif 171 150 -
uspace/srv/net/nil/eth/eth_module.c
r4dd8529 r24ab58b3 46 46 #include <net_interface.h> 47 47 #include <packet/packet.h> 48 #include <nil_module.h> 48 49 #include <nil_standalone.h> 49 50 … … 79 80 } 80 81 81 /** Passes the parameters to the module specific nil_message() function. 82 * @param[in] callid The message identifier. 83 * @param[in] call The message parameters. 84 * @param[out] answer The message answer parameters. 85 * @param[out] answer_count The last parameter for the actual answer in the answer parameter. 86 * @returns EOK on success. 87 * @returns ENOTSUP if the message is not known. 88 * @returns Other error codes as defined for each specific module message function. 82 /** Pass the parameters to the module specific nil_message() function. 83 * 84 * @param[in] name Module name. 85 * @param[in] callid The message identifier. 86 * @param[in] call The message parameters. 87 * @param[out] answer The message answer parameters. 88 * @param[out] answer_count The last parameter for the actual answer 89 * in the answer parameter. 90 * 91 * @return EOK on success. 92 * @return ENOTSUP if the message is not known. 93 * @return Other error codes as defined for each 94 * specific module message function. 95 * 89 96 */ 90 int nil_module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 91 return nil_message(callid, call, answer, answer_count); 97 int nil_module_message(const char *name, ipc_callid_t callid, ipc_call_t *call, 98 ipc_call_t *answer, int *answer_count) 99 { 100 return nil_message(name, callid, call, answer, answer_count); 92 101 } 93 102 -
uspace/srv/net/nil/nildummy/nildummy.c
r4dd8529 r24ab58b3 60 60 /** The module name. 61 61 */ 62 #define NAME "Dummy nil protocol"62 #define NAME "nildummy" 63 63 64 64 /** Default maximum transmission unit. … … 228 228 return index; 229 229 } 230 printf("New device registered:\n\tid\t= %d\n\tservice\t= %d\n\tMTU\t= %d\n", device->device_id, device->service, device->mtu); 230 printf("%s: Device registered (id: %d, service: %d, mtu: %d)\n", 231 NAME, device->device_id, device->service, device->mtu); 231 232 } 232 233 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); … … 290 291 nildummy_globals.proto.service = service; 291 292 nildummy_globals.proto.phone = phone; 292 printf("New protocol registered:\n\tservice\t= %d\n\tphone\t= %d\n", nildummy_globals.proto.service, nildummy_globals.proto.phone); 293 294 printf("%s: Protocol registered (service: %d, phone: %d)\n", 295 NAME, nildummy_globals.proto.service, nildummy_globals.proto.phone); 296 293 297 fibril_rwlock_write_unlock(&nildummy_globals.protos_lock); 294 298 return EOK; … … 312 316 } 313 317 314 int nil_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 318 int nil_message(const char *name, ipc_callid_t callid, ipc_call_t *call, 319 ipc_call_t *answer, int *answer_count) 320 { 315 321 ERROR_DECLARE; 316 322 317 323 measured_string_ref address; 318 324 packet_t packet; … … 321 327 size_t suffix; 322 328 size_t content; 323 324 // printf("message %d - %d\n", IPC_GET_METHOD(*call), NET_NIL_FIRST); 329 325 330 *answer_count = 0; 326 switch (IPC_GET_METHOD(*call)){331 switch (IPC_GET_METHOD(*call)) { 327 332 case IPC_M_PHONE_HUNGUP: 328 333 return EOK; 329 334 case NET_NIL_DEVICE: 330 return nildummy_device_message(IPC_GET_DEVICE(call), IPC_GET_SERVICE(call), IPC_GET_MTU(call)); 335 return nildummy_device_message(IPC_GET_DEVICE(call), 336 IPC_GET_SERVICE(call), IPC_GET_MTU(call)); 331 337 case NET_NIL_SEND: 332 ERROR_PROPAGATE(packet_translate(nildummy_globals.net_phone, &packet, IPC_GET_PACKET(call))); 333 return nildummy_send_message(IPC_GET_DEVICE(call), packet, IPC_GET_SERVICE(call)); 338 ERROR_PROPAGATE(packet_translate(nildummy_globals.net_phone, 339 &packet, IPC_GET_PACKET(call))); 340 return nildummy_send_message(IPC_GET_DEVICE(call), packet, 341 IPC_GET_SERVICE(call)); 334 342 case NET_NIL_PACKET_SPACE: 335 ERROR_PROPAGATE(nildummy_packet_space_message(IPC_GET_DEVICE(call), &addrlen, &prefix, &content, &suffix)); 343 ERROR_PROPAGATE(nildummy_packet_space_message(IPC_GET_DEVICE(call), 344 &addrlen, &prefix, &content, &suffix)); 336 345 IPC_SET_ADDR(answer, addrlen); 337 346 IPC_SET_PREFIX(answer, prefix); … … 341 350 return EOK; 342 351 case NET_NIL_ADDR: 343 ERROR_PROPAGATE(nildummy_addr_message(IPC_GET_DEVICE(call), &address)); 352 ERROR_PROPAGATE(nildummy_addr_message(IPC_GET_DEVICE(call), 353 &address)); 344 354 return measured_strings_reply(address, 1); 345 355 case IPC_M_CONNECT_TO_ME: 346 return nildummy_register_message(NIL_GET_PROTO(call), IPC_GET_PHONE(call)); 347 } 356 return nildummy_register_message(NIL_GET_PROTO(call), 357 IPC_GET_PHONE(call)); 358 } 359 348 360 return ENOTSUP; 349 361 } … … 404 416 405 417 /* Process the message */ 406 int res = nil_module_message(callid, &call, &answer, &answer_count); 418 int res = nil_module_message(NAME, callid, &call, &answer, 419 &answer_count); 407 420 408 421 /* End if said to either by the message or the processing result */ … … 428 441 ERROR_DECLARE; 429 442 430 /* Print the module label */431 printf("Task %d - %s\n", task_get_id(), NAME);432 433 443 /* Start the module */ 434 if (ERROR_OCCURRED(nil_module_start(nil_client_connection))) { 435 printf(" - ERROR %i\n", ERROR_CODE); 444 if (ERROR_OCCURRED(nil_module_start(nil_client_connection))) 436 445 return ERROR_CODE; 437 }438 446 439 447 return EOK; -
uspace/srv/net/nil/nildummy/nildummy_module.c
r4dd8529 r24ab58b3 51 51 #include "nildummy.h" 52 52 53 /** Starts the dummy nil module. 54 * Initializes the client connection serving function, initializes the module, registers the module service and starts the async manager, processing IPC messages in an infinite loop. 55 * @param[in] client_connection The client connection processing function. The module skeleton propagates its own one. 56 * @returns EOK on success. 57 * @returns Other error codes as defined for the pm_init() function. 58 * @returns Other error codes as defined for the nil_initialize() function. 59 * @returns Other error codes as defined for the REGISTER_ME() macro function. 53 /** Start the dummy nil module. 54 * 55 * Initialize the client connection serving function, initialize 56 * the module, register the module service and start the async 57 * manager, processing IPC messages in an infinite loop. 58 * 59 * @param[in] client_connection The client connection processing 60 * function. The module skeleton propagates 61 * its own one. 62 * 63 * @return EOK on success. 64 * @return Other error codes as defined for the pm_init() function. 65 * @return Other error codes as defined for the nil_initialize() function. 66 * @return Other error codes as defined for the REGISTER_ME() macro function. 67 * 60 68 */ 61 int nil_module_start(async_client_conn_t client_connection){ 69 int nil_module_start(async_client_conn_t client_connection) 70 { 62 71 ERROR_DECLARE; 63 72 73 async_set_client_connection(client_connection); 74 int net_phone = net_connect_module(SERVICE_NETWORKING); 75 ERROR_PROPAGATE(pm_init()); 76 64 77 ipcarg_t phonehash; 65 int net_phone; 66 67 async_set_client_connection(client_connection); 68 net_phone = net_connect_module(SERVICE_NETWORKING); 69 ERROR_PROPAGATE(pm_init()); 70 if(ERROR_OCCURRED(nil_initialize(net_phone)) 71 || ERROR_OCCURRED(REGISTER_ME(SERVICE_NILDUMMY, &phonehash))){ 78 if (ERROR_OCCURRED(nil_initialize(net_phone)) 79 || ERROR_OCCURRED(REGISTER_ME(SERVICE_NILDUMMY, &phonehash))){ 72 80 pm_destroy(); 73 81 return ERROR_CODE; 74 82 } 75 83 76 84 async_manager(); 77 85 78 86 pm_destroy(); 79 87 return EOK; 80 88 } 81 89 82 /** Passes the parameters to the module specific nil_message() function. 83 * @param[in] callid The message identifier. 84 * @param[in] call The message parameters. 85 * @param[out] answer The message answer parameters. 86 * @param[out] answer_count The last parameter for the actual answer in the answer parameter. 87 * @returns EOK on success. 88 * @returns ENOTSUP if the message is not known. 89 * @returns Other error codes as defined for each specific module message function. 90 /** Pass the parameters to the module specific nil_message() function. 91 * 92 * @param[in] name Module name. 93 * @param[in] callid The message identifier. 94 * @param[in] call The message parameters. 95 * @param[out] answer The message answer parameters. 96 * @param[out] answer_count The last parameter for the actual answer 97 * in the answer parameter. 98 * 99 * @return EOK on success. 100 * @return ENOTSUP if the message is not known. 101 * @return Other error codes as defined for each specific 102 * module message function. 103 * 90 104 */ 91 int nil_module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 92 return nil_message(callid, call, answer, answer_count); 105 int nil_module_message(const char *name, ipc_callid_t callid, 106 ipc_call_t *call, ipc_call_t *answer, int *answer_count) 107 { 108 return nil_message(name, callid, call, answer, answer_count); 93 109 } 94 110 -
uspace/srv/net/tl/icmp/icmp.c
r4dd8529 r24ab58b3 873 873 ERROR_DECLARE; 874 874 875 /* Print the module label */876 printf("Task %d - %s\n", task_get_id(), NAME);877 878 875 /* Start the module */ 879 if (ERROR_OCCURRED(tl_module_start(tl_client_connection))) { 880 printf(" - ERROR %i\n", ERROR_CODE); 876 if (ERROR_OCCURRED(tl_module_start(tl_client_connection))) 881 877 return ERROR_CODE; 882 }883 878 884 879 return EOK; -
uspace/srv/net/tl/tcp/tcp.c
r4dd8529 r24ab58b3 2051 2051 ERROR_DECLARE; 2052 2052 2053 /* Print the module label */2054 printf("Task %d - %s\n", task_get_id(), NAME);2055 2056 2053 /* Start the module */ 2057 if (ERROR_OCCURRED(tl_module_start(tl_client_connection))) { 2058 printf(" - ERROR %i\n", ERROR_CODE); 2054 if (ERROR_OCCURRED(tl_module_start(tl_client_connection))) 2059 2055 return ERROR_CODE; 2060 }2061 2056 2062 2057 return EOK; -
uspace/srv/net/tl/udp/udp.c
r4dd8529 r24ab58b3 753 753 ERROR_DECLARE; 754 754 755 /* Print the module label */756 printf("Task %d - %s\n", task_get_id(), NAME);757 758 755 /* Start the module */ 759 if (ERROR_OCCURRED(tl_module_start(tl_client_connection))) { 760 printf(" - ERROR %i\n", ERROR_CODE); 756 if (ERROR_OCCURRED(tl_module_start(tl_client_connection))) 761 757 return ERROR_CODE; 762 }763 758 764 759 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.