Changeset 014dd57b in mainline


Ignore:
Timestamp:
2011-01-12T15:59:22Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ab6f2507
Parents:
797b704
Message:

streamline and create a common skeleton for the transport layer
(in the line of the previous updates to the lower layers)

Location:
uspace
Files:
1 added
6 deleted
13 edited
3 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/Makefile

    r797b704 r014dd57b  
    5252        tl/icmp_client.c \
    5353        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
    5657
    5758include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/net/il/il_skel.c

    r797b704 r014dd57b  
    104104        async_set_client_connection(il_client_connection);
    105105        int net_phone = net_connect_module();
     106        if (net_phone < 0)
     107                return net_phone;
    106108       
    107109        int rc = pm_init();
  • uspace/lib/net/include/il_skel.h

    r797b704 r014dd57b  
    6161extern int il_initialize(int net_phone);
    6262
    63 /** Process the Internet layer module message.
     63/** Process the internetwork layer module message.
    6464 *
    6565 * This has to be implemented in user code.
     
    7171 *
    7272 * @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.
    7574 *
    7675 */
  • uspace/lib/net/include/tl_remote.h

    r797b704 r014dd57b  
    3535 */
    3636
    37 #ifndef LIBNET_TL_INTERFACE_H_
    38 #define LIBNET_TL_INTERFACE_H_
     37#ifndef LIBNET_TL_REMOTE_H_
     38#define LIBNET_TL_REMOTE_H_
    3939
    4040#include <async.h>
     
    5252/*@{*/
    5353
    54 extern int tl_received_msg(int, device_id_t, packet_t *, services_t, services_t);
     54extern int tl_received_msg(int, device_id_t, packet_t *, services_t,
     55    services_t);
    5556
    5657/*@}*/
  • uspace/lib/net/include/tl_skel.h

    r797b704 r014dd57b  
    3131 */
    3232
    33 #ifndef LIBNET_TL_LOCAL_H_
    34 #define LIBNET_TL_LOCAL_H_
     33#ifndef LIBNET_TL_SKEL_H_
     34#define LIBNET_TL_SKEL_H_
    3535
     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>
    3643#include <ipc/ipc.h>
    37 #include <async.h>
     44#include <ipc/services.h>
    3845
    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.
    4051 *
    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.
    4453 *
    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 *
    5260 */
    53 extern int tl_module_message_standalone(ipc_callid_t, ipc_call_t *,
     61extern 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 */
     76extern int tl_module_message(ipc_callid_t, ipc_call_t *,
    5477    ipc_call_t *, size_t *);
    5578
    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);
     79extern int tl_module_start(int);
    6880
    6981#endif
  • uspace/lib/net/nil/nil_skel.c

    r797b704 r014dd57b  
    104104        async_set_client_connection(nil_client_connection);
    105105        int net_phone = net_connect_module();
     106        if (net_phone < 0)
     107                return net_phone;
    106108       
    107109        int rc = pm_init();
  • uspace/lib/net/tl/tl_common.c

    r797b704 r014dd57b  
    4242#include <ip_remote.h>
    4343#include <ip_interface.h>
    44 #include <tl_interface.h>
     44#include <tl_remote.h>
    4545
    4646#include <net/socket_codes.h>
  • uspace/lib/net/tl/tl_remote.c

    r797b704 r014dd57b  
    3131 */
    3232
    33 #include <tl_interface.h>
     33#include <tl_remote.h>
    3434#include <generic.h>
    3535#include <packet_client.h>
     
    5757 *
    5858 */
    59 int
    60 tl_received_msg(int tl_phone, device_id_t device_id, packet_t *packet,
     59int tl_received_msg(int tl_phone, device_id_t device_id, packet_t *packet,
    6160    services_t target, services_t error)
    6261{
  • uspace/srv/net/cfg/ne2k

    r797b704 r014dd57b  
    1 # NE2000 configuration
     1# DP8390 (NE2k) configuration
    22
    33NAME=ne2k
     
    1515
    1616IP_CONFIG=static
    17 IP_ADDR=10.0.2.15
     17IP_ADDR=10.10.16.86
    1818IP_ROUTING=yes
    1919IP_NETMASK=255.255.255.0
    20 IP_BROADCAST=10.0.2.255
    21 IP_GATEWAY=10.0.2.2
     20IP_BROADCAST=10.10.16.255
     21IP_GATEWAY=10.10.16.1
    2222ARP=arp
    2323
  • uspace/srv/net/il/ip/ip.c

    r797b704 r014dd57b  
    7373#include <net_interface.h>
    7474#include <nil_remote.h>
    75 #include <tl_interface.h>
     75#include <tl_remote.h>
    7676#include <packet_remote.h>
    7777#include <il_remote.h>
  • uspace/srv/net/tl/icmp/Makefile

    r797b704 r014dd57b  
    3434
    3535SOURCES = \
    36         icmp.c \
    37         icmp_module.c
     36        icmp.c
    3837
    3938include $(USPACE_PREFIX)/Makefile.common
  • uspace/srv/net/tl/icmp/icmp.c

    r797b704 r014dd57b  
    3535 * @see icmp.h
    3636 */
    37 
    38 #include "icmp.h"
    39 #include "icmp_module.h"
    4037
    4138#include <async.h>
     
    7269#include <ip_interface.h>
    7370#include <net_interface.h>
    74 #include <tl_interface.h>
    75 #include <tl_local.h>
     71#include <tl_remote.h>
     72#include <tl_skel.h>
    7673#include <icmp_header.h>
    7774
     75#include "icmp.h"
     76
    7877/** ICMP module name. */
    79 #define NAME    "ICMP protocol"
     78#define NAME  "icmp"
    8079
    8180/** Default ICMP error reporting. */
     
    394393}
    395394
    396 /** Initializes the ICMP module.
    397  *
    398  * @param[in] client_connection The client connection processing function. The
    399  *                      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                         20
    409                 },
    410                 {
    411                         (uint8_t *) "ICMP_ECHO_REPLYING",
    412                         18
    413                 }
    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 
    470395/** Tries to set the pending reply result as the received message type.
    471396 *
     
    667592                return icmp_release_and_return(packet, rc);
    668593
     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 */
     603static 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 */
     635int 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);
    669700        return EOK;
    670701}
     
    893924 * @see IS_NET_ICMP_MESSAGE()
    894925 */
    895 int icmp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     926int tl_module_message   (ipc_callid_t callid, ipc_call_t *call,
    896927    ipc_call_t *answer, size_t *answer_count)
    897928{
    898         packet_t *packet;
    899         int rc;
    900 
    901929        *answer_count = 0;
    902930        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        
    911931        case NET_ICMP_INIT:
    912932                return icmp_process_client_messages(callid, *call);
    913        
    914933        default:
    915934                return icmp_process_message(call);
    916935        }
    917 
     936       
    918937        return ENOTSUP;
    919938}
    920939
    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 connection
    932          *  - 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 processing
    953                  * 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 module
    968  *                      start function.
    969  */
    970940int main(int argc, char *argv[])
    971941{
    972         int rc;
    973        
    974942        /* Start the module */
    975         rc = tl_module_start_standalone(tl_client_connection);
    976         return rc;
     943        return tl_module_start(SERVICE_ICMP);
    977944}
    978945
    979946/** @}
    980947 */
    981 
  • uspace/srv/net/tl/tcp/Makefile

    r797b704 r014dd57b  
    3434
    3535SOURCES = \
    36         tcp.c \
    37         tcp_module.c
     36        tcp.c
    3837
    3938include $(USPACE_PREFIX)/Makefile.common
  • uspace/srv/net/tl/tcp/tcp.c

    r797b704 r014dd57b  
    3636 */
    3737
    38 #include "tcp.h"
    39 #include "tcp_header.h"
    40 #include "tcp_module.h"
    41 
    4238#include <assert.h>
    4339#include <async.h>
     
    7268#include <socket_core.h>
    7369#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"
    7675
    7776/** TCP module name. */
    78 #define NAME    "TCP protocol"
     77#define NAME  "tcp"
    7978
    8079/** The TCP window default value. */
     
    220219/** TCP global data. */
    221220tcp_globals_t tcp_globals;
    222 
    223 /** Initializes the TCP module.
    224  *
    225  * @param[in] client_connection The client connection processing function. The
    226  *                      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 }
    264221
    265222int tcp_received_msg(device_id_t device_id, packet_t *packet,
     
    12601217 * @see IS_NET_TCP_MESSAGE()
    12611218 */
    1262 int
    1263 tcp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     1219int tl_module_message(ipc_callid_t callid, ipc_call_t *call,
    12641220    ipc_call_t *answer, size_t *answer_count)
    12651221{
    1266         packet_t *packet;
    1267         int rc;
    1268 
    12691222        assert(call);
    12701223        assert(answer);
     
    12731226        *answer_count = 0;
    12741227        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;
    12871228        case IPC_M_CONNECT_TO_ME:
    12881229                return tcp_process_client_messages(callid, *call);
     
    24862427}
    24872428
    2488 /** Default thread for new connections.
     2429/** Process IPC messages from the IP module
    24892430 *
    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.
    24922433 *
    24932434 */
    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 
     2435static void tcp_receiver(ipc_callid_t iid, ipc_call_t *icall)
     2436{
     2437        packet_t *packet;
     2438        int rc;
     2439       
    25022440        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.
    25332460 *
    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 *
    25372466 */
    2538 int
    2539 main(int argc, char *argv[])
    2540 {
    2541         int rc;
    2542 
    2543         rc = tl_module_start_standalone(tl_client_connection);
     2467int 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
     2495out:
     2496        fibril_rwlock_write_unlock(&tcp_globals.lock);
    25442497        return rc;
     2498}
     2499
     2500int main(int argc, char *argv[])
     2501{
     2502        return tl_module_start(SERVICE_TCP);
    25452503}
    25462504
  • uspace/srv/net/tl/udp/Makefile

    r797b704 r014dd57b  
    3434
    3535SOURCES = \
    36         udp.c \
    37         udp_module.c
     36        udp.c
    3837
    3938include $(USPACE_PREFIX)/Makefile.common
  • uspace/srv/net/tl/udp/udp.c

    r797b704 r014dd57b  
    3535 * @see udp.h
    3636 */
    37 
    38 #include "udp.h"
    39 #include "udp_header.h"
    40 #include "udp_module.h"
    4137
    4238#include <async.h>
     
    6965#include <socket_core.h>
    7066#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"
    7372
    7473/** UDP module name. */
    75 #define NAME    "UDP protocol"
     74#define NAME  "udp"
    7675
    7776/** Default UDP checksum computing. */
     
    9291/** UDP global data.  */
    9392udp_globals_t udp_globals;
    94 
    95 /** Initializes the UDP module.
    96  *
    97  * @param[in] client_connection The client connection processing function. The
    98  *                      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                         22
    108                 },
    109                 {
    110                         (uint8_t *) "UDP_AUTOBINDING",
    111                         15
    112                 }
    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 }
    18593
    18694/** Releases the packet and returns the result.
     
    426334}
    427335
     336/** Process IPC messages from the IP module
     337 *
     338 * @param[in]     iid   Message identifier.
     339 * @param[in,out] icall Message parameters.
     340 *
     341 */
     342static 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 */
     374int 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
    428459/** Sends data from the socket to the remote address.
    429460 *
     
    860891 * @see IS_NET_UDP_MESSAGE()
    861892 */
    862 int udp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     893int tl_module_message(ipc_callid_t callid, ipc_call_t *call,
    863894    ipc_call_t *answer, size_t *answer_count)
    864895{
    865         packet_t *packet;
    866         int rc;
    867 
    868896        *answer_count = 0;
    869897
    870898        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));
    878899        case IPC_M_CONNECT_TO_ME:
    879900                return udp_process_client_messages(callid, *call);
     
    883904}
    884905
    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 connection
    894          *  - 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 processing
    915                  * 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 module
    930  *                      start function.
    931  */
    932906int main(int argc, char *argv[])
    933907{
    934         int rc;
    935        
    936908        /* Start the module */
    937         rc = tl_module_start_standalone(tl_client_connection);
    938         return rc;
     909        return tl_module_start(SERVICE_UDP);
    939910}
    940911
Note: See TracChangeset for help on using the changeset viewer.