Changeset 014dd57b in mainline
- Timestamp:
- 2011-01-12T15:59:22Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ab6f2507
- Parents:
- 797b704
- Location:
- uspace
- Files:
-
- 1 added
- 6 deleted
- 13 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/Makefile
r797b704 r014dd57b 52 52 tl/icmp_client.c \ 53 53 tl/socket_core.c \ 54 tl/tl_interface.c \ 55 tl/tl_common.c 54 tl/tl_common.c \ 55 tl/tl_remote.c \ 56 tl/tl_skel.c 56 57 57 58 include $(USPACE_PREFIX)/Makefile.common -
uspace/lib/net/il/il_skel.c
r797b704 r014dd57b 104 104 async_set_client_connection(il_client_connection); 105 105 int net_phone = net_connect_module(); 106 if (net_phone < 0) 107 return net_phone; 106 108 107 109 int rc = pm_init(); -
uspace/lib/net/include/il_skel.h
r797b704 r014dd57b 61 61 extern int il_initialize(int net_phone); 62 62 63 /** Process the Internetlayer module message.63 /** Process the internetwork layer module message. 64 64 * 65 65 * This has to be implemented in user code. … … 71 71 * 72 72 * @return EOK on success. 73 * @return Other error codes as defined for the arp_message() 74 * function. 73 * @return Other error codes as defined for each specific module. 75 74 * 76 75 */ -
uspace/lib/net/include/tl_remote.h
r797b704 r014dd57b 35 35 */ 36 36 37 #ifndef LIBNET_TL_ INTERFACE_H_38 #define LIBNET_TL_ INTERFACE_H_37 #ifndef LIBNET_TL_REMOTE_H_ 38 #define LIBNET_TL_REMOTE_H_ 39 39 40 40 #include <async.h> … … 52 52 /*@{*/ 53 53 54 extern int tl_received_msg(int, device_id_t, packet_t *, services_t, services_t); 54 extern int tl_received_msg(int, device_id_t, packet_t *, services_t, 55 services_t); 55 56 56 57 /*@}*/ -
uspace/lib/net/include/tl_skel.h
r797b704 r014dd57b 31 31 */ 32 32 33 #ifndef LIBNET_TL_ LOCAL_H_34 #define LIBNET_TL_ LOCAL_H_33 #ifndef LIBNET_TL_SKEL_H_ 34 #define LIBNET_TL_SKEL_H_ 35 35 36 /** @file 37 * Transport layer module skeleton. 38 * The skeleton has to be part of each transport layer module. 39 */ 40 41 #include <async.h> 42 #include <fibril_synch.h> 36 43 #include <ipc/ipc.h> 37 #include < async.h>44 #include <ipc/services.h> 38 45 39 /** Starts the TL module. 46 #include <adt/measured_strings.h> 47 #include <net/device.h> 48 #include <net/packet.h> 49 50 /** Module initialization. 40 51 * 41 * Initializes the client connection serving function, initializes the module, 42 * registers the module service and starts the async manager, processing IPC 43 * messages in an infinite loop. 52 * This has to be implemented in user code. 44 53 * 45 * @param[in] client_connection The client connection processing function. The 46 * module skeleton propagates its own one. 47 * @return EOK on successful module termination. 48 * @return Other error codes as defined for the module initialize 49 * function. 50 * @return Other error codes as defined for the REGISTER_ME() macro 51 * function. 54 * @param[in] net_phone Networking module phone. 55 * 56 * @return EOK on success. 57 * @return Other error codes as defined for each specific module 58 * initialize function. 59 * 52 60 */ 53 extern int tl_module_message_standalone(ipc_callid_t, ipc_call_t *, 61 extern int tl_initialize(int net_phone); 62 63 /** Process the transport layer module message. 64 * 65 * This has to be implemented in user code. 66 * 67 * @param[in] callid Message identifier. 68 * @param[in] call Message parameters. 69 * @param[out] answer Answer. 70 * @param[out] count Number of arguments of the answer. 71 * 72 * @return EOK on success. 73 * @return Other error codes as defined for each specific module. 74 * 75 */ 76 extern int tl_module_message(ipc_callid_t, ipc_call_t *, 54 77 ipc_call_t *, size_t *); 55 78 56 /** Processes the TL module message. 57 * 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 in the 62 * answer parameter. 63 * @return EOK on success. 64 * @return Other error codes as defined for the module's message 65 * standalone function. 66 */ 67 extern int tl_module_start_standalone(async_client_conn_t); 79 extern int tl_module_start(int); 68 80 69 81 #endif -
uspace/lib/net/nil/nil_skel.c
r797b704 r014dd57b 104 104 async_set_client_connection(nil_client_connection); 105 105 int net_phone = net_connect_module(); 106 if (net_phone < 0) 107 return net_phone; 106 108 107 109 int rc = pm_init(); -
uspace/lib/net/tl/tl_common.c
r797b704 r014dd57b 42 42 #include <ip_remote.h> 43 43 #include <ip_interface.h> 44 #include <tl_ interface.h>44 #include <tl_remote.h> 45 45 46 46 #include <net/socket_codes.h> -
uspace/lib/net/tl/tl_remote.c
r797b704 r014dd57b 31 31 */ 32 32 33 #include <tl_ interface.h>33 #include <tl_remote.h> 34 34 #include <generic.h> 35 35 #include <packet_client.h> … … 57 57 * 58 58 */ 59 int 60 tl_received_msg(int tl_phone, device_id_t device_id, packet_t *packet, 59 int tl_received_msg(int tl_phone, device_id_t device_id, packet_t *packet, 61 60 services_t target, services_t error) 62 61 { -
uspace/srv/net/cfg/ne2k
r797b704 r014dd57b 1 # NE2000configuration1 # DP8390 (NE2k) configuration 2 2 3 3 NAME=ne2k … … 15 15 16 16 IP_CONFIG=static 17 IP_ADDR=10. 0.2.1517 IP_ADDR=10.10.16.86 18 18 IP_ROUTING=yes 19 19 IP_NETMASK=255.255.255.0 20 IP_BROADCAST=10. 0.2.25521 IP_GATEWAY=10. 0.2.220 IP_BROADCAST=10.10.16.255 21 IP_GATEWAY=10.10.16.1 22 22 ARP=arp 23 23 -
uspace/srv/net/il/ip/ip.c
r797b704 r014dd57b 73 73 #include <net_interface.h> 74 74 #include <nil_remote.h> 75 #include <tl_ interface.h>75 #include <tl_remote.h> 76 76 #include <packet_remote.h> 77 77 #include <il_remote.h> -
uspace/srv/net/tl/icmp/Makefile
r797b704 r014dd57b 34 34 35 35 SOURCES = \ 36 icmp.c \ 37 icmp_module.c 36 icmp.c 38 37 39 38 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/net/tl/icmp/icmp.c
r797b704 r014dd57b 35 35 * @see icmp.h 36 36 */ 37 38 #include "icmp.h"39 #include "icmp_module.h"40 37 41 38 #include <async.h> … … 72 69 #include <ip_interface.h> 73 70 #include <net_interface.h> 74 #include <tl_ interface.h>75 #include <tl_ local.h>71 #include <tl_remote.h> 72 #include <tl_skel.h> 76 73 #include <icmp_header.h> 77 74 75 #include "icmp.h" 76 78 77 /** ICMP module name. */ 79 #define NAME "ICMP protocol"78 #define NAME "icmp" 80 79 81 80 /** Default ICMP error reporting. */ … … 394 393 } 395 394 396 /** Initializes the ICMP module.397 *398 * @param[in] client_connection The client connection processing function. The399 * module skeleton propagates its own one.400 * @return EOK on success.401 * @return ENOMEM if there is not enough memory left.402 */403 int icmp_initialize(async_client_conn_t client_connection)404 {405 measured_string_t names[] = {406 {407 (uint8_t *) "ICMP_ERROR_REPORTING",408 20409 },410 {411 (uint8_t *) "ICMP_ECHO_REPLYING",412 18413 }414 };415 measured_string_t *configuration;416 size_t count = sizeof(names) / sizeof(measured_string_t);417 uint8_t *data;418 int rc;419 420 fibril_rwlock_initialize(&icmp_globals.lock);421 fibril_rwlock_write_lock(&icmp_globals.lock);422 icmp_replies_initialize(&icmp_globals.replies);423 icmp_echo_data_initialize(&icmp_globals.echo_data);424 425 icmp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_ICMP,426 SERVICE_ICMP, client_connection);427 if (icmp_globals.ip_phone < 0) {428 fibril_rwlock_write_unlock(&icmp_globals.lock);429 return icmp_globals.ip_phone;430 }431 432 rc = ip_packet_size_req(icmp_globals.ip_phone, -1,433 &icmp_globals.packet_dimension);434 if (rc != EOK) {435 fibril_rwlock_write_unlock(&icmp_globals.lock);436 return rc;437 }438 439 icmp_globals.packet_dimension.prefix += ICMP_HEADER_SIZE;440 icmp_globals.packet_dimension.content -= ICMP_HEADER_SIZE;441 442 icmp_globals.error_reporting = NET_DEFAULT_ICMP_ERROR_REPORTING;443 icmp_globals.echo_replying = NET_DEFAULT_ICMP_ECHO_REPLYING;444 445 /* Get configuration */446 configuration = &names[0];447 rc = net_get_conf_req(icmp_globals.net_phone, &configuration, count,448 &data);449 if (rc != EOK) {450 fibril_rwlock_write_unlock(&icmp_globals.lock);451 return rc;452 }453 454 if (configuration) {455 if (configuration[0].value) {456 icmp_globals.error_reporting =457 (configuration[0].value[0] == 'y');458 }459 if (configuration[1].value) {460 icmp_globals.echo_replying =461 (configuration[1].value[0] == 'y');462 }463 net_free_settings(configuration, data);464 }465 466 fibril_rwlock_write_unlock(&icmp_globals.lock);467 return EOK;468 }469 470 395 /** Tries to set the pending reply result as the received message type. 471 396 * … … 667 592 return icmp_release_and_return(packet, rc); 668 593 594 return EOK; 595 } 596 597 /** Process IPC messages from the IP module 598 * 599 * @param[in] iid Message identifier. 600 * @param[in,out] icall Message parameters. 601 * 602 */ 603 static void icmp_receiver(ipc_callid_t iid, ipc_call_t *icall) 604 { 605 packet_t *packet; 606 int rc; 607 608 while (true) { 609 switch (IPC_GET_IMETHOD(*icall)) { 610 case NET_TL_RECEIVED: 611 rc = packet_translate_remote(icmp_globals.net_phone, &packet, 612 IPC_GET_PACKET(*icall)); 613 if (rc == EOK) 614 rc = icmp_received_msg_local(IPC_GET_DEVICE(*icall), packet, 615 SERVICE_ICMP, IPC_GET_ERROR(*icall)); 616 617 ipc_answer_0(iid, (sysarg_t) rc); 618 break; 619 default: 620 ipc_answer_0(iid, (sysarg_t) ENOTSUP); 621 } 622 623 iid = async_get_call(icall); 624 } 625 } 626 627 /** Initialize the ICMP module. 628 * 629 * @param[in] net_phone Network module phone. 630 * 631 * @return EOK on success. 632 * @return ENOMEM if there is not enough memory left. 633 * 634 */ 635 int tl_initialize(int net_phone) 636 { 637 measured_string_t names[] = { 638 { 639 (uint8_t *) "ICMP_ERROR_REPORTING", 640 20 641 }, 642 { 643 (uint8_t *) "ICMP_ECHO_REPLYING", 644 18 645 } 646 }; 647 measured_string_t *configuration; 648 size_t count = sizeof(names) / sizeof(measured_string_t); 649 uint8_t *data; 650 651 fibril_rwlock_initialize(&icmp_globals.lock); 652 fibril_rwlock_write_lock(&icmp_globals.lock); 653 icmp_replies_initialize(&icmp_globals.replies); 654 icmp_echo_data_initialize(&icmp_globals.echo_data); 655 656 icmp_globals.net_phone = net_phone; 657 658 icmp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_ICMP, 659 SERVICE_ICMP, icmp_receiver); 660 if (icmp_globals.ip_phone < 0) { 661 fibril_rwlock_write_unlock(&icmp_globals.lock); 662 return icmp_globals.ip_phone; 663 } 664 665 int rc = ip_packet_size_req(icmp_globals.ip_phone, -1, 666 &icmp_globals.packet_dimension); 667 if (rc != EOK) { 668 fibril_rwlock_write_unlock(&icmp_globals.lock); 669 return rc; 670 } 671 672 icmp_globals.packet_dimension.prefix += ICMP_HEADER_SIZE; 673 icmp_globals.packet_dimension.content -= ICMP_HEADER_SIZE; 674 675 icmp_globals.error_reporting = NET_DEFAULT_ICMP_ERROR_REPORTING; 676 icmp_globals.echo_replying = NET_DEFAULT_ICMP_ECHO_REPLYING; 677 678 /* Get configuration */ 679 configuration = &names[0]; 680 rc = net_get_conf_req(icmp_globals.net_phone, &configuration, count, 681 &data); 682 if (rc != EOK) { 683 fibril_rwlock_write_unlock(&icmp_globals.lock); 684 return rc; 685 } 686 687 if (configuration) { 688 if (configuration[0].value) { 689 icmp_globals.error_reporting = 690 (configuration[0].value[0] == 'y'); 691 } 692 if (configuration[1].value) { 693 icmp_globals.echo_replying = 694 (configuration[1].value[0] == 'y'); 695 } 696 net_free_settings(configuration, data); 697 } 698 699 fibril_rwlock_write_unlock(&icmp_globals.lock); 669 700 return EOK; 670 701 } … … 893 924 * @see IS_NET_ICMP_MESSAGE() 894 925 */ 895 int icmp_message_standalone(ipc_callid_t callid, ipc_call_t *call,926 int tl_module_message (ipc_callid_t callid, ipc_call_t *call, 896 927 ipc_call_t *answer, size_t *answer_count) 897 928 { 898 packet_t *packet;899 int rc;900 901 929 *answer_count = 0; 902 930 switch (IPC_GET_IMETHOD(*call)) { 903 case NET_TL_RECEIVED:904 rc = packet_translate_remote(icmp_globals.net_phone, &packet,905 IPC_GET_PACKET(*call));906 if (rc != EOK)907 return rc;908 return icmp_received_msg_local(IPC_GET_DEVICE(*call), packet,909 SERVICE_ICMP, IPC_GET_ERROR(*call));910 911 931 case NET_ICMP_INIT: 912 932 return icmp_process_client_messages(callid, *call); 913 914 933 default: 915 934 return icmp_process_message(call); 916 935 } 917 936 918 937 return ENOTSUP; 919 938 } 920 939 921 922 /** Default thread for new connections.923 *924 * @param[in] iid The initial message identifier.925 * @param[in] icall The initial message call structure.926 *927 */928 static void tl_client_connection(ipc_callid_t iid, ipc_call_t *icall)929 {930 /*931 * Accept the connection932 * - Answer the first IPC_M_CONNECT_ME_TO call.933 */934 ipc_answer_0(iid, EOK);935 936 while (true) {937 ipc_call_t answer;938 size_t answer_count;939 940 /* Clear the answer structure */941 refresh_answer(&answer, &answer_count);942 943 /* Fetch the next message */944 ipc_call_t call;945 ipc_callid_t callid = async_get_call(&call);946 947 /* Process the message */948 int res = tl_module_message_standalone(callid, &call, &answer,949 &answer_count);950 951 /*952 * End if told to either by the message or the processing953 * result.954 */955 if ((IPC_GET_IMETHOD(call) == IPC_M_PHONE_HUNGUP) ||956 (res == EHANGUP))957 return;958 959 /* Answer the message */960 answer_call(callid, res, &answer, answer_count);961 }962 }963 964 /** Starts the module.965 *966 * @return EOK on success.967 * @return Other error codes as defined for each specific module968 * start function.969 */970 940 int main(int argc, char *argv[]) 971 941 { 972 int rc;973 974 942 /* Start the module */ 975 rc = tl_module_start_standalone(tl_client_connection); 976 return rc; 943 return tl_module_start(SERVICE_ICMP); 977 944 } 978 945 979 946 /** @} 980 947 */ 981 -
uspace/srv/net/tl/tcp/Makefile
r797b704 r014dd57b 34 34 35 35 SOURCES = \ 36 tcp.c \ 37 tcp_module.c 36 tcp.c 38 37 39 38 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/net/tl/tcp/tcp.c
r797b704 r014dd57b 36 36 */ 37 37 38 #include "tcp.h"39 #include "tcp_header.h"40 #include "tcp_module.h"41 42 38 #include <assert.h> 43 39 #include <async.h> … … 72 68 #include <socket_core.h> 73 69 #include <tl_common.h> 74 #include <tl_local.h> 75 #include <tl_interface.h> 70 #include <tl_remote.h> 71 #include <tl_skel.h> 72 73 #include "tcp.h" 74 #include "tcp_header.h" 76 75 77 76 /** TCP module name. */ 78 #define NAME "TCP protocol"77 #define NAME "tcp" 79 78 80 79 /** The TCP window default value. */ … … 220 219 /** TCP global data. */ 221 220 tcp_globals_t tcp_globals; 222 223 /** Initializes the TCP module.224 *225 * @param[in] client_connection The client connection processing function. The226 * module skeleton propagates its own one.227 * @return EOK on success.228 * @return ENOMEM if there is not enough memory left.229 */230 int tcp_initialize(async_client_conn_t client_connection)231 {232 int rc;233 234 assert(client_connection);235 236 fibril_rwlock_initialize(&tcp_globals.lock);237 fibril_rwlock_write_lock(&tcp_globals.lock);238 239 tcp_globals.icmp_phone = icmp_connect_module(SERVICE_ICMP,240 ICMP_CONNECT_TIMEOUT);241 tcp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_TCP,242 SERVICE_TCP, client_connection);243 if (tcp_globals.ip_phone < 0) {244 fibril_rwlock_write_unlock(&tcp_globals.lock);245 return tcp_globals.ip_phone;246 }247 248 rc = socket_ports_initialize(&tcp_globals.sockets);249 if (rc != EOK)250 goto out;251 252 rc = packet_dimensions_initialize(&tcp_globals.dimensions);253 if (rc != EOK) {254 socket_ports_destroy(&tcp_globals.sockets);255 goto out;256 }257 258 tcp_globals.last_used_port = TCP_FREE_PORTS_START - 1;259 260 out:261 fibril_rwlock_write_unlock(&tcp_globals.lock);262 return rc;263 }264 221 265 222 int tcp_received_msg(device_id_t device_id, packet_t *packet, … … 1260 1217 * @see IS_NET_TCP_MESSAGE() 1261 1218 */ 1262 int 1263 tcp_message_standalone(ipc_callid_t callid, ipc_call_t *call, 1219 int tl_module_message(ipc_callid_t callid, ipc_call_t *call, 1264 1220 ipc_call_t *answer, size_t *answer_count) 1265 1221 { 1266 packet_t *packet;1267 int rc;1268 1269 1222 assert(call); 1270 1223 assert(answer); … … 1273 1226 *answer_count = 0; 1274 1227 switch (IPC_GET_IMETHOD(*call)) { 1275 case NET_TL_RECEIVED:1276 // fibril_rwlock_read_lock(&tcp_globals.lock);1277 rc = packet_translate_remote(tcp_globals.net_phone, &packet,1278 IPC_GET_PACKET(*call));1279 if (rc != EOK) {1280 // fibril_rwlock_read_unlock(&tcp_globals.lock);1281 return rc;1282 }1283 rc = tcp_received_msg(IPC_GET_DEVICE(*call), packet, SERVICE_TCP,1284 IPC_GET_ERROR(*call));1285 // fibril_rwlock_read_unlock(&tcp_globals.lock);1286 return rc;1287 1228 case IPC_M_CONNECT_TO_ME: 1288 1229 return tcp_process_client_messages(callid, *call); … … 2486 2427 } 2487 2428 2488 /** Default thread for new connections.2429 /** Process IPC messages from the IP module 2489 2430 * 2490 * @param[in] iid The initial message identifier.2491 * @param[in ] icall The initial message call structure.2431 * @param[in] iid Message identifier. 2432 * @param[in,out] icall Message parameters. 2492 2433 * 2493 2434 */ 2494 static void tl_client_connection(ipc_callid_t iid, ipc_call_t * icall) 2495 { 2496 /* 2497 * Accept the connection 2498 * - Answer the first IPC_M_CONNECT_ME_TO call. 2499 */ 2500 ipc_answer_0(iid, EOK); 2501 2435 static void tcp_receiver(ipc_callid_t iid, ipc_call_t *icall) 2436 { 2437 packet_t *packet; 2438 int rc; 2439 2502 2440 while (true) { 2503 ipc_call_t answer; 2504 size_t answer_count; 2505 2506 /* Clear the answer structure */ 2507 refresh_answer(&answer, &answer_count); 2508 2509 /* Fetch the next message */ 2510 ipc_call_t call; 2511 ipc_callid_t callid = async_get_call(&call); 2512 2513 /* Process the message */ 2514 int res = tl_module_message_standalone(callid, &call, &answer, 2515 &answer_count); 2516 2517 /* 2518 * End if told to either by the message or the processing 2519 * result. 2520 */ 2521 if ((IPC_GET_IMETHOD(call) == IPC_M_PHONE_HUNGUP) || 2522 (res == EHANGUP)) 2523 return; 2524 2525 /* 2526 * Answer the message 2527 */ 2528 answer_call(callid, res, &answer, answer_count); 2529 } 2530 } 2531 2532 /** Starts the module. 2441 switch (IPC_GET_IMETHOD(*icall)) { 2442 case NET_TL_RECEIVED: 2443 rc = packet_translate_remote(tcp_globals.net_phone, &packet, 2444 IPC_GET_PACKET(*icall)); 2445 if (rc == EOK) 2446 rc = tcp_received_msg(IPC_GET_DEVICE(*icall), packet, 2447 SERVICE_TCP, IPC_GET_ERROR(*icall)); 2448 2449 ipc_answer_0(iid, (sysarg_t) rc); 2450 break; 2451 default: 2452 ipc_answer_0(iid, (sysarg_t) ENOTSUP); 2453 } 2454 2455 iid = async_get_call(icall); 2456 } 2457 } 2458 2459 /** Initialize the TCP module. 2533 2460 * 2534 * @return EOK on success. 2535 * @return Other error codes as defined for each specific module 2536 * start function. 2461 * @param[in] net_phone Network module phone. 2462 * 2463 * @return EOK on success. 2464 * @return ENOMEM if there is not enough memory left. 2465 * 2537 2466 */ 2538 int 2539 main(int argc, char *argv[]) 2540 { 2541 int rc; 2542 2543 rc = tl_module_start_standalone(tl_client_connection); 2467 int tl_initialize(int net_phone) 2468 { 2469 fibril_rwlock_initialize(&tcp_globals.lock); 2470 fibril_rwlock_write_lock(&tcp_globals.lock); 2471 2472 tcp_globals.net_phone = net_phone; 2473 2474 tcp_globals.icmp_phone = icmp_connect_module(SERVICE_ICMP, 2475 ICMP_CONNECT_TIMEOUT); 2476 tcp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_TCP, 2477 SERVICE_TCP, tcp_receiver); 2478 if (tcp_globals.ip_phone < 0) { 2479 fibril_rwlock_write_unlock(&tcp_globals.lock); 2480 return tcp_globals.ip_phone; 2481 } 2482 2483 int rc = socket_ports_initialize(&tcp_globals.sockets); 2484 if (rc != EOK) 2485 goto out; 2486 2487 rc = packet_dimensions_initialize(&tcp_globals.dimensions); 2488 if (rc != EOK) { 2489 socket_ports_destroy(&tcp_globals.sockets); 2490 goto out; 2491 } 2492 2493 tcp_globals.last_used_port = TCP_FREE_PORTS_START - 1; 2494 2495 out: 2496 fibril_rwlock_write_unlock(&tcp_globals.lock); 2544 2497 return rc; 2498 } 2499 2500 int main(int argc, char *argv[]) 2501 { 2502 return tl_module_start(SERVICE_TCP); 2545 2503 } 2546 2504 -
uspace/srv/net/tl/udp/Makefile
r797b704 r014dd57b 34 34 35 35 SOURCES = \ 36 udp.c \ 37 udp_module.c 36 udp.c 38 37 39 38 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/net/tl/udp/udp.c
r797b704 r014dd57b 35 35 * @see udp.h 36 36 */ 37 38 #include "udp.h"39 #include "udp_header.h"40 #include "udp_module.h"41 37 42 38 #include <async.h> … … 69 65 #include <socket_core.h> 70 66 #include <tl_common.h> 71 #include <tl_local.h> 72 #include <tl_interface.h> 67 #include <tl_remote.h> 68 #include <tl_skel.h> 69 70 #include "udp.h" 71 #include "udp_header.h" 73 72 74 73 /** UDP module name. */ 75 #define NAME "UDP protocol"74 #define NAME "udp" 76 75 77 76 /** Default UDP checksum computing. */ … … 92 91 /** UDP global data. */ 93 92 udp_globals_t udp_globals; 94 95 /** Initializes the UDP module.96 *97 * @param[in] client_connection The client connection processing function. The98 * module skeleton propagates its own one.99 * @return EOK on success.100 * @return ENOMEM if there is not enough memory left.101 */102 int udp_initialize(async_client_conn_t client_connection)103 {104 measured_string_t names[] = {105 {106 (uint8_t *) "UDP_CHECKSUM_COMPUTING",107 22108 },109 {110 (uint8_t *) "UDP_AUTOBINDING",111 15112 }113 };114 measured_string_t *configuration;115 size_t count = sizeof(names) / sizeof(measured_string_t);116 uint8_t *data;117 int rc;118 119 fibril_rwlock_initialize(&udp_globals.lock);120 fibril_rwlock_write_lock(&udp_globals.lock);121 122 udp_globals.icmp_phone = icmp_connect_module(SERVICE_ICMP,123 ICMP_CONNECT_TIMEOUT);124 125 udp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_UDP,126 SERVICE_UDP, client_connection);127 if (udp_globals.ip_phone < 0) {128 fibril_rwlock_write_unlock(&udp_globals.lock);129 return udp_globals.ip_phone;130 }131 132 /* Read default packet dimensions */133 rc = ip_packet_size_req(udp_globals.ip_phone, -1,134 &udp_globals.packet_dimension);135 if (rc != EOK) {136 fibril_rwlock_write_unlock(&udp_globals.lock);137 return rc;138 }139 140 rc = socket_ports_initialize(&udp_globals.sockets);141 if (rc != EOK) {142 fibril_rwlock_write_unlock(&udp_globals.lock);143 return rc;144 }145 146 rc = packet_dimensions_initialize(&udp_globals.dimensions);147 if (rc != EOK) {148 socket_ports_destroy(&udp_globals.sockets);149 fibril_rwlock_write_unlock(&udp_globals.lock);150 return rc;151 }152 153 udp_globals.packet_dimension.prefix += sizeof(udp_header_t);154 udp_globals.packet_dimension.content -= sizeof(udp_header_t);155 udp_globals.last_used_port = UDP_FREE_PORTS_START - 1;156 157 udp_globals.checksum_computing = NET_DEFAULT_UDP_CHECKSUM_COMPUTING;158 udp_globals.autobinding = NET_DEFAULT_UDP_AUTOBINDING;159 160 /* Get configuration */161 configuration = &names[0];162 rc = net_get_conf_req(udp_globals.net_phone, &configuration, count,163 &data);164 if (rc != EOK) {165 socket_ports_destroy(&udp_globals.sockets);166 fibril_rwlock_write_unlock(&udp_globals.lock);167 return rc;168 }169 170 if (configuration) {171 if (configuration[0].value)172 udp_globals.checksum_computing =173 (configuration[0].value[0] == 'y');174 175 if (configuration[1].value)176 udp_globals.autobinding =177 (configuration[1].value[0] == 'y');178 179 net_free_settings(configuration, data);180 }181 182 fibril_rwlock_write_unlock(&udp_globals.lock);183 return EOK;184 }185 93 186 94 /** Releases the packet and returns the result. … … 426 334 } 427 335 336 /** Process IPC messages from the IP module 337 * 338 * @param[in] iid Message identifier. 339 * @param[in,out] icall Message parameters. 340 * 341 */ 342 static void udp_receiver(ipc_callid_t iid, ipc_call_t *icall) 343 { 344 packet_t *packet; 345 int rc; 346 347 while (true) { 348 switch (IPC_GET_IMETHOD(*icall)) { 349 case NET_TL_RECEIVED: 350 rc = packet_translate_remote(udp_globals.net_phone, &packet, 351 IPC_GET_PACKET(*icall)); 352 if (rc == EOK) 353 rc = udp_received_msg(IPC_GET_DEVICE(*icall), packet, 354 SERVICE_UDP, IPC_GET_ERROR(*icall)); 355 356 ipc_answer_0(iid, (sysarg_t) rc); 357 break; 358 default: 359 ipc_answer_0(iid, (sysarg_t) ENOTSUP); 360 } 361 362 iid = async_get_call(icall); 363 } 364 } 365 366 /** Initialize the UDP module. 367 * 368 * @param[in] net_phone Network module phone. 369 * 370 * @return EOK on success. 371 * @return ENOMEM if there is not enough memory left. 372 * 373 */ 374 int tl_initialize(int net_phone) 375 { 376 measured_string_t names[] = { 377 { 378 (uint8_t *) "UDP_CHECKSUM_COMPUTING", 379 22 380 }, 381 { 382 (uint8_t *) "UDP_AUTOBINDING", 383 15 384 } 385 }; 386 measured_string_t *configuration; 387 size_t count = sizeof(names) / sizeof(measured_string_t); 388 uint8_t *data; 389 390 fibril_rwlock_initialize(&udp_globals.lock); 391 fibril_rwlock_write_lock(&udp_globals.lock); 392 393 udp_globals.net_phone = net_phone; 394 395 udp_globals.icmp_phone = icmp_connect_module(SERVICE_ICMP, 396 ICMP_CONNECT_TIMEOUT); 397 398 udp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_UDP, 399 SERVICE_UDP, udp_receiver); 400 if (udp_globals.ip_phone < 0) { 401 fibril_rwlock_write_unlock(&udp_globals.lock); 402 return udp_globals.ip_phone; 403 } 404 405 /* Read default packet dimensions */ 406 int rc = ip_packet_size_req(udp_globals.ip_phone, -1, 407 &udp_globals.packet_dimension); 408 if (rc != EOK) { 409 fibril_rwlock_write_unlock(&udp_globals.lock); 410 return rc; 411 } 412 413 rc = socket_ports_initialize(&udp_globals.sockets); 414 if (rc != EOK) { 415 fibril_rwlock_write_unlock(&udp_globals.lock); 416 return rc; 417 } 418 419 rc = packet_dimensions_initialize(&udp_globals.dimensions); 420 if (rc != EOK) { 421 socket_ports_destroy(&udp_globals.sockets); 422 fibril_rwlock_write_unlock(&udp_globals.lock); 423 return rc; 424 } 425 426 udp_globals.packet_dimension.prefix += sizeof(udp_header_t); 427 udp_globals.packet_dimension.content -= sizeof(udp_header_t); 428 udp_globals.last_used_port = UDP_FREE_PORTS_START - 1; 429 430 udp_globals.checksum_computing = NET_DEFAULT_UDP_CHECKSUM_COMPUTING; 431 udp_globals.autobinding = NET_DEFAULT_UDP_AUTOBINDING; 432 433 /* Get configuration */ 434 configuration = &names[0]; 435 rc = net_get_conf_req(udp_globals.net_phone, &configuration, count, 436 &data); 437 if (rc != EOK) { 438 socket_ports_destroy(&udp_globals.sockets); 439 fibril_rwlock_write_unlock(&udp_globals.lock); 440 return rc; 441 } 442 443 if (configuration) { 444 if (configuration[0].value) 445 udp_globals.checksum_computing = 446 (configuration[0].value[0] == 'y'); 447 448 if (configuration[1].value) 449 udp_globals.autobinding = 450 (configuration[1].value[0] == 'y'); 451 452 net_free_settings(configuration, data); 453 } 454 455 fibril_rwlock_write_unlock(&udp_globals.lock); 456 return EOK; 457 } 458 428 459 /** Sends data from the socket to the remote address. 429 460 * … … 860 891 * @see IS_NET_UDP_MESSAGE() 861 892 */ 862 int udp_message_standalone(ipc_callid_t callid, ipc_call_t *call,893 int tl_module_message(ipc_callid_t callid, ipc_call_t *call, 863 894 ipc_call_t *answer, size_t *answer_count) 864 895 { 865 packet_t *packet;866 int rc;867 868 896 *answer_count = 0; 869 897 870 898 switch (IPC_GET_IMETHOD(*call)) { 871 case NET_TL_RECEIVED:872 rc = packet_translate_remote(udp_globals.net_phone, &packet,873 IPC_GET_PACKET(*call));874 if (rc != EOK)875 return rc;876 return udp_received_msg(IPC_GET_DEVICE(*call), packet,877 SERVICE_UDP, IPC_GET_ERROR(*call));878 899 case IPC_M_CONNECT_TO_ME: 879 900 return udp_process_client_messages(callid, *call); … … 883 904 } 884 905 885 /** Default thread for new connections.886 *887 * @param[in] iid The initial message identifier.888 * @param[in] icall The initial message call structure.889 */890 static void tl_client_connection(ipc_callid_t iid, ipc_call_t * icall)891 {892 /*893 * Accept the connection894 * - Answer the first IPC_M_CONNECT_ME_TO call.895 */896 ipc_answer_0(iid, EOK);897 898 while (true) {899 ipc_call_t answer;900 size_t answer_count;901 902 /* Clear the answer structure */903 refresh_answer(&answer, &answer_count);904 905 /* Fetch the next message */906 ipc_call_t call;907 ipc_callid_t callid = async_get_call(&call);908 909 /* Process the message */910 int res = tl_module_message_standalone(callid, &call, &answer,911 &answer_count);912 913 /*914 * End if told to either by the message or the processing915 * result.916 */917 if ((IPC_GET_IMETHOD(call) == IPC_M_PHONE_HUNGUP) ||918 (res == EHANGUP))919 return;920 921 /* Answer the message */922 answer_call(callid, res, &answer, answer_count);923 }924 }925 926 /** Starts the module.927 *928 * @return EOK on success.929 * @return Other error codes as defined for each specific module930 * start function.931 */932 906 int main(int argc, char *argv[]) 933 907 { 934 int rc;935 936 908 /* Start the module */ 937 rc = tl_module_start_standalone(tl_client_connection); 938 return rc; 909 return tl_module_start(SERVICE_UDP); 939 910 } 940 911
Note:
See TracChangeset
for help on using the changeset viewer.