Changeset 24ab58b3 in mainline


Ignore:
Timestamp:
2010-04-06T11:41:48Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
14f1db0
Parents:
4dd8529
Message:

more compact network startup messages (usually one line instead of multiple lines)
pass module name as an argument to nil_message() and friends
deeper cstyle changes (replace forward prototypes with proper extern declarations and static functions, change doxygen comments, stick more closely to the 80-column rule, no argument names in header files, spacing, comments, etc.)

Location:
uspace
Files:
27 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/il/ip_remote.c

    r4dd8529 r24ab58b3  
    2828
    2929/** @addtogroup ip
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @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 *
    3740 */
    3841
     
    4851#include <ip_messages.h>
    4952
    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);
     53int 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);
    5259}
    5360
    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);
     61int 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);
    5666}
    5767
    58 int ip_connect_module(services_t service){
     68int ip_connect_module(services_t service)
     69{
    5970        return connect_to_service(SERVICE_IP);
    6071}
    6172
    62 int ip_device_req(int ip_phone, device_id_t device_id, services_t service){
     73int ip_device_req(int ip_phone, device_id_t device_id, services_t service)
     74{
    6375        return generic_device_req(ip_phone, NET_IL_DEVICE, device_id, 0, service);
    6476}
    6577
    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;
     78int 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       
    6990        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)) {
    8397                *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)
    86100                                free(*header);
    87                         }
    88101                }
    89102        }
     103       
     104        ipcarg_t result;
    90105        async_wait_for(message_id, &result);
    91 
    92         if((result != EOK) && (*header)){
     106       
     107        if ((result != EOK) && (*header))
    93108                free(*header);
    94         }else{
     109        else
    95110                *device_id = IPC_GET_DEVICE(&answer);
    96         }
     111       
    97112        return (int) result;
    98113}
    99114
    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);
     115int 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);
    102120}
    103121
    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);
     122int 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);
    106127}
    107128
    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);
     129int 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);
    110134}
    111135
    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);
     136int 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);
    114140}
    115141
  • uspace/lib/net/include/netif.h

    r4dd8529 r24ab58b3  
    129129extern packet_t netif_packet_get_1(size_t content);
    130130
    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 *
    141147 */
    142 extern int netif_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
     148extern int netif_message(const char *, ipc_callid_t, ipc_call_t *,
     149    ipc_call_t *, int *);
    143150
    144151/** Initializes the netif module.
  • uspace/lib/net/include/netif_nil_bundle.h

    r4dd8529 r24ab58b3  
    3737#include <async.h>
    3838
    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);
     39extern int netif_nil_module_message(const char *, ipc_callid_t, ipc_call_t *,
     40    ipc_call_t *, int *);
     41extern int netif_nil_module_start(async_client_conn_t);
    4242
    4343#endif
  • uspace/lib/net/include/netif_standalone.h

    r4dd8529 r24ab58b3  
    3737#include <async.h>
    3838
    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);
     39extern int netif_module_message(const char *, ipc_callid_t, ipc_call_t *,
     40    ipc_call_t *, int *);
     41extern int netif_module_start(async_client_conn_t);
    4242
    4343#endif
  • uspace/lib/net/include/nil_module.h

    r4dd8529 r24ab58b3  
    4242
    4343/** 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 *
    4852 */
    49 extern int nil_initialize(int net_phone);
     53extern int nil_initialize(int);
    5054
    5155/** 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 *
    6172 */
    62 extern int nil_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
     73extern int nil_message(const char *, ipc_callid_t, ipc_call_t *, ipc_call_t *,
     74    int *);
    6375
    6476#endif
  • uspace/lib/net/include/nil_standalone.h

    r4dd8529 r24ab58b3  
    3737#include <async.h>
    3838
    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);
     39extern int nil_module_message(const char *, ipc_callid_t, ipc_call_t *,
     40    ipc_call_t *, int *);
     41extern int nil_module_start(async_client_conn_t);
    4242
    4343#endif
  • uspace/lib/net/netif/netif.c

    r4dd8529 r24ab58b3  
    176176}
    177177
    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 */
     189static int register_message(const char *name, device_id_t device_id, int phone)
     190{
     191        ERROR_DECLARE;
     192       
    188193        device_ref device;
    189 
    190194        ERROR_PROPAGATE(find_device(device_id, &device));
    191         if(device->nil_phone > 0){
     195        if(device->nil_phone > 0)
    192196                return ELIMIT;
    193         }
     197       
    194198        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
     204int 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       
    202209        size_t length;
    203210        device_stats_t stats;
    204211        packet_t packet;
    205212        measured_string_t address;
    206 
    207 //      printf("message %d - %d\n", IPC_GET_METHOD(*call), NET_NETIF_FIRST);
     213       
    208214        *answer_count = 0;
    209215        switch(IPC_GET_METHOD(*call)){
     
    211217                        return EOK;
    212218                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));
    214221                case IPC_M_CONNECT_TO_ME:
    215222                        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));
    217225                        fibril_rwlock_write_unlock(&netif_globals.lock);
    218226                        return ERROR_CODE;
    219227                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));
    222232                case NET_NETIF_START:
    223233                        return netif_start_req(0, IPC_GET_DEVICE(call));
    224234                case NET_NETIF_STATS:
    225235                        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))
    228238                                        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));
    233244                                }
    234245                        }
     
    239250                case NET_NETIF_GET_ADDR:
    240251                        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)))
    242254                                ERROR_CODE = measured_strings_reply(&address, 1);
    243                         }
    244255                        fibril_rwlock_read_unlock(&netif_globals.lock);
    245256                        return ERROR_CODE;
    246257        }
     258       
    247259        return netif_specific_message(callid, call, answer, answer_count);
    248260}
  • uspace/lib/net/netif/netif_nil_bundle.c

    r4dd8529 r24ab58b3  
    4545#include <netif.h>
    4646
    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 *
    5560 */
    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         }
     61int 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);
    6269}
    6370
  • uspace/lib/net/netif/netif_standalone.c

    r4dd8529 r24ab58b3  
    4141#include <netif_standalone.h>
    4242
    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 *
    5156 */
    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);
     57int 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);
    5461}
    5562
  • uspace/srv/hw/netif/dp8390/dp8390_module.c

    r4dd8529 r24ab58b3  
    5959/** DP8390 module name.
    6060 */
    61 #define NAME    "dp8390 network interface"
     61#define NAME  "dp8390"
    6262
    6363/** Returns the device from the interrupt call.
     
    302302}
    303303
    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;
     304int 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;
    308316}
    309317
     
    346354               
    347355                /* 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);
    349358               
    350359                /* End if said to either by the message or the processing result */
     
    370379        ERROR_DECLARE;
    371380       
    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;
    374384       
    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        
    381385        return EOK;
    382386}
  • uspace/srv/net/il/arp/arp.c

    r4dd8529 r24ab58b3  
    6868/** ARP module name.
    6969 */
    70 #define NAME    "ARP protocol"
     70#define NAME  "arp"
    7171
    7272/** ARP global data.
     
    338338                        return ERROR_CODE;
    339339                }
    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);
    341342        }
    342343        fibril_rwlock_write_unlock(&arp_globals.lock);
     
    673674        ERROR_DECLARE;
    674675       
    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;
    677679       
    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        
    684680        return EOK;
    685681}
  • uspace/srv/net/il/ip/ip.c

    r4dd8529 r24ab58b3  
    7979/** IP module name.
    8080 */
    81 #define NAME    "IP protocol"
     81#define NAME  "ip"
    8282
    8383/** IP version 4.
     
    430430        ip_route_ref route;
    431431        int index;
    432         char * data;
    433432
    434433        ip_netif = (ip_netif_ref) malloc(sizeof(ip_netif_t));
     
    454453        }
    455454        // 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       
    458459        // 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       
    477479        fibril_rwlock_write_unlock(&ip_globals.netifs_lock);
    478480        return EOK;
     
    595597        }
    596598        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);
    598600        fibril_rwlock_write_unlock(&ip_globals.netifs_lock);
    599601        return EOK;
     
    611613        }
    612614        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);
    614616        fibril_rwlock_write_unlock(&ip_globals.netifs_lock);
    615617        return EOK;
     
    646648                return index;
    647649        }
    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       
    649654        fibril_rwlock_write_unlock(&ip_globals.protos_lock);
    650655        return EOK;
     
    16771682        ERROR_DECLARE;
    16781683       
    1679         /* Print the module label */
    1680         printf("Task %d - %s\n", task_get_id(), NAME);
    1681        
    16821684        /* 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)))
    16851686                return ERROR_CODE;
    1686         }
    16871687       
    16881688        return EOK;
  • uspace/srv/net/net/net.c

    r4dd8529 r24ab58b3  
    2828
    2929/** @addtogroup net
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Networking subsystem central module implementation.
     34 * Networking subsystem central module implementation.
     35 *
    3536 */
    3637
     
    6465#include "net.h"
    6566
     67/** Networking module name.
     68 *
     69 */
     70#define NAME  "net"
     71
    6672/** 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
    7376
    7477/** 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 */
     80net_globals_t net_globals;
     81
     82GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t);
     83DEVICE_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 */
     95int 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)
    157104                return ENOMEM;
    158         }
    159         // add the configuration setting
    160         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))) {
    161108                free(setting);
    162109                return ERROR_CODE;
    163110        }
    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 */
     120static device_id_t generate_new_device_id(void)
     121{
    168122        return device_assign_devno();
    169123}
    170124
    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();
     125static 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);
    188179                return ERROR_CODE;
    189180        }
    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
     185static 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;
    216232                }
    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 */
     248static 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 */
     259static 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 */
     275static int net_initialize(async_client_conn_t client_connection)
     276{
     277        ERROR_DECLARE;
     278       
    254279        netifs_initialize(&net_globals.netifs);
    255280        char_map_initialize(&net_globals.netif_names);
    256281        modules_initialize(&net_globals.modules);
    257282        measured_strings_initialize(&net_globals.configuration);
    258 
    259         // TODO dynamic configuration
     283       
     284        // TODO: dynamic configuration
    260285        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 */
    268299        return net_initialize_build(client_connection);
    269300}
    270301
    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 */
     319static 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 */
     352static 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
     378int 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
     387int 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
     400void 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 */
     420static 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 */
     509static 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 */
     595int net_message(ipc_callid_t callid, ipc_call_t *call, ipc_call_t *answer,
     596    int *answer_count)
     597{
     598        ERROR_DECLARE;
     599       
    274600        measured_string_ref strings;
    275         char * data;
    276 
     601        char *data;
     602       
    277603        *answer_count = 0;
    278         switch(IPC_GET_METHOD(*call)){
     604        switch (IPC_GET_METHOD(*call)) {
    279605                case IPC_M_PHONE_HUNGUP:
    280606                        return EOK;
    281607                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 */
    285614                        free(data);
     615                       
    286616                        ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call));
    287617                        free(strings);
    288618                        return ERROR_CODE;
    289619                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)));
    291622                        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 */
    293625                        free(data);
     626                       
    294627                        ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call));
    295628                        free(strings);
     
    301634}
    302635
    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 beginning
    311         name = line;
    312 
    313         // skip comments and blank lines
    314         if((*name == '#') || (*name == '\0')){
    315                 return EOK;
    316         }
    317         // skip spaces
    318         while(isspace(*name)){
    319                 ++ name;
    320         }
    321 
    322         // remember the name start
    323         value = name;
    324         // skip the name
    325         while(isalnum(*value) || (*value == '_')){
    326                 // make uppercase
    327 //              *value = toupper(*value);
    328                 ++ value;
    329         }
    330 
    331         if(*value == '='){
    332                 // terminate the name
    333                 *value = '\0';
    334         }else{
    335                 // terminate the name
    336                 *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 spaces
    350         while(isspace(*value)){
    351                 ++ value;
    352         }
    353         // create a bulk measured string till the end
    354         setting = measured_string_create_bulk(value, 0);
    355         if(! setting){
    356                 return ENOMEM;
    357         }
    358 
    359         // add the configuration setting
    360         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 file
    369         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 filename
    382         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 file
    387         cfg = fopen(line, "r");
    388         if(! cfg){
    389                 return ENOENT;
    390         }
    391 
    392         // read the configuration line by line
    393         // until an error or the end of file
    394         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 buffer
    401                                 return EOVERFLOW;
    402                         }else{
    403                                 // append the character
    404                                 line[index] = (char) read;
    405                                 ++ index;
    406                         }
    407                 }else{
    408                         // on error or new line
    409                         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 file
    425         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 netif
    438         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 layer
    446         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 layer
    458         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 configuration
    466         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 startup
    473         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 startup
    486         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 files
    521                 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 name
    528                 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 map
    538                 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 map
    546                 if(ERROR_OCCURRED(char_map_add(&net_globals.netif_names, netif->name, 0, index))
    547                 // start network interfaces and needed modules
    548                         || 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' usage
    555                 ++ 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 
    565636/** Default thread for new connections.
    566637 *
    567  *  @param[in] iid The initial message identifier.
    568  *  @param[in] icall The initial message call structure.
    569  *
    570  */
    571 static void net_client_connection(ipc_callid_t iid, ipc_call_t * icall)
     638 * @param[in] iid The initial message identifier.
     639 * @param[in] icall The initial message call structure.
     640 *
     641 */
     642static void net_client_connection(ipc_callid_t iid, ipc_call_t *icall)
    572643{
    573644        /*
     
    577648        ipc_answer_0(iid, EOK);
    578649       
    579         while(true) {
     650        while (true) {
     651                /* Clear the answer structure */
    580652                ipc_call_t answer;
    581653                int answer_count;
    582                
    583                 /* Clear the answer structure */
    584654                refresh_answer(&answer, &answer_count);
    585655               
     
    600670}
    601671
    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  */
    611672int main(int argc, char *argv[])
    612673{
    613674        ERROR_DECLARE;
    614675       
    615         /* Print the module label */
    616         printf("Task %d - %s\n", task_get_id(), NAME);
    617        
    618         /* Start the module */
    619676        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);
    621678                return ERROR_CODE;
    622679        }
  • uspace/srv/net/net/net.h

    r4dd8529 r24ab58b3  
    2828
    2929/** @addtogroup net
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Networking subsystem central module.
     34 * Networking subsystem central module.
     35 *
    3536 */
    3637
     
    4849
    4950/** @name Modules definitions
     51 * @{
    5052 */
    51 /*@{*/
    5253
    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/** @}
    5470 */
    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 /*@}*/
    9471
    9572/** @name Configuration setting names definitions
     73 * @{
    9674 */
    97 /*@{*/
    9875
    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/** @}
    10085 */
    101 #define CONF_IL                         "IL"
    10286
    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. */
    15189
    15290/** 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 *
    15595 */
    156 GENERIC_CHAR_MAP_DECLARE(measured_strings, measured_string_t)
     96GENERIC_CHAR_MAP_DECLARE(measured_strings, measured_string_t);
     97
     98/** Present network interface device.
     99 *
     100 */
     101typedef 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;
    157112
    158113/** 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 *
    161118 */
    162 DEVICE_MAP_DECLARE(netifs, netif_t)
     119DEVICE_MAP_DECLARE(netifs, netif_t);
    163120
    164 /** Networking module global variables.
     121/** Networking module global data.
     122 *
    165123 */
    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          */
     124typedef struct {
     125        measured_strings_t configuration;  /**< Global configuration. */
     126        modules_t modules;                 /**< Available modules. */
     127       
     128        /** Network interface structure indices by names. */
    175129        char_map_t netif_names;
    176         /** Present network interfaces.
    177         */
     130       
     131        /** Present network interfaces. */
    178132        netifs_t netifs;
    179 };
     133} net_globals_t;
    180134
    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);
     135extern int add_configuration(measured_strings_ref, const char *, const char *);
     136extern int net_module_message(ipc_callid_t, ipc_call_t *, ipc_call_t *, int *);
     137extern int net_initialize_build(async_client_conn_t);
     138extern int net_message(ipc_callid_t, ipc_call_t *, ipc_call_t *, int *);
    243139
    244140#endif
  • uspace/srv/net/net/net_bundle.c

    r4dd8529 r24ab58b3  
    6060extern net_globals_t    net_globals;
    6161
     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 */
    6267int net_initialize_build(async_client_conn_t client_connection){
    6368        ERROR_DECLARE;
     
    7984}
    8085
     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 */
    8196int net_module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    8297        if((IPC_GET_METHOD(*call) == IPC_M_CONNECT_TO_ME)
  • uspace/srv/net/net/net_standalone.c

    r4dd8529 r24ab58b3  
    5151extern net_globals_t    net_globals;
    5252
     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 */
    5358int net_initialize_build(async_client_conn_t client_connection){
    5459        ERROR_DECLARE;
     
    7378}
    7479
     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 */
    7590int net_module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    7691        if(IS_NET_PACKET_MESSAGE(call)){
  • uspace/srv/net/netif/lo/lo.c

    r4dd8529 r24ab58b3  
    6464/** Loopback module name.
    6565 */
    66 #define NAME    "lo - loopback interface"
     66#define NAME  "lo"
    6767
    6868/** Network interface global data.
     
    113113}
    114114
    115 int change_state_message(device_ref device, device_state_t state){
    116         if(device->state != state){
     115int change_state_message(device_ref device, device_state_t state)
     116{
     117        if (device->state != state) {
    117118                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               
    119123                return state;
    120124        }
     125       
    121126        return EOK;
    122127}
     
    166171        ERROR_PROPAGATE(create(device_id, &device));
    167172        // 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);
    169174        return EOK;
    170175}
     
    237242               
    238243                /* 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);
    240246               
    241247                /* End if said to either by the message or the processing result */
     
    261267        ERROR_DECLARE;
    262268       
    263         /* Print the module label */
    264         printf("Task %d - %s\n", task_get_id(), NAME);
    265        
    266269        /* 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)))
    269271                return ERROR_CODE;
    270         }
    271272       
    272273        return EOK;
  • uspace/srv/net/netstart/netstart.c

    r4dd8529 r24ab58b3  
    7979}
    8080
    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  */
    9281int main(int argc, char *argv[])
    9382{
     
    10594        int net_phone = connect_to_service(SERVICE_NETWORKING);
    10695        if (ERROR_OCCURRED(ipc_call_sync_0_0(net_phone, NET_NET_STARTUP))) {
    107                 fprintf(stderr, "%s: Networking error %d\n", NAME, ERROR_CODE);
     96                fprintf(stderr, "%s: Startup error %d\n", NAME, ERROR_CODE);
    10897                return ERROR_CODE;
    10998        }
  • uspace/srv/net/netstart/self_test.c

    r4dd8529 r24ab58b3  
    4949#include "self_test.h"
    5050
    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.
    5655 *
    5756 */
     
    8584INT_MAP_IMPLEMENT(int_map, int);
    8685
     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 */
    8794int self_test(void)
    8895{
  • uspace/srv/net/nil/eth/eth.c

    r4dd8529 r24ab58b3  
    6060#include <adt/measured_strings.h>
    6161#include <packet/packet_client.h>
     62#include <nil_module.h>
    6263
    6364#include "eth.h"
     
    6667/** The module name.
    6768 */
    68 #define NAME    "Ethernet protocol"
     69#define NAME  "eth"
    6970
    7071/** Reserved packet prefix length.
     
    401402                        return index;
    402403                }
    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);
    404410        }
    405411        fibril_rwlock_write_unlock(&eth_globals.devices_lock);
     
    571577                }
    572578        }
    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       
    574583        fibril_rwlock_write_unlock(&eth_globals.protos_lock);
    575584        return EOK;
     
    704713}
    705714
    706 int nil_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     715int nil_message(const char *name, ipc_callid_t callid, ipc_call_t *call,
     716    ipc_call_t *answer, int *answer_count)
     717{
    707718        ERROR_DECLARE;
    708 
     719       
    709720        measured_string_ref address;
    710721        packet_t packet;
     
    713724        size_t suffix;
    714725        size_t content;
    715 
    716 //      printf("message %d - %d\n", IPC_GET_METHOD(*call), NET_NIL_FIRST);
     726       
    717727        *answer_count = 0;
    718         switch(IPC_GET_METHOD(*call)){
     728        switch (IPC_GET_METHOD(*call)) {
    719729                case IPC_M_PHONE_HUNGUP:
    720730                        return EOK;
    721731                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));
    723734                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));
    726739                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));
    728742                        IPC_SET_ADDR(answer, addrlen);
    729743                        IPC_SET_PREFIX(answer, prefix);
     
    733747                        return EOK;
    734748                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));
    736751                        return measured_strings_reply(address, 1);
    737752                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));
    739755                        return measured_strings_reply(address, 1);
    740756                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       
    743761        return ENOTSUP;
    744762}
     
    799817               
    800818                /* 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);
    802821               
    803822                /* End if said to either by the message or the processing result */
     
    823842        ERROR_DECLARE;
    824843       
    825         /* Print the module label */
    826         printf("Task %d - %s\n", task_get_id(), NAME);
    827        
    828844        /* 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)))
    831846                return ERROR_CODE;
    832         }
    833847       
    834848        return EOK;
  • uspace/srv/net/nil/eth/eth.h

    r4dd8529 r24ab58b3  
    147147};
    148148
    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.h
    166  *  @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 
    170149#endif
    171150
  • uspace/srv/net/nil/eth/eth_module.c

    r4dd8529 r24ab58b3  
    4646#include <net_interface.h>
    4747#include <packet/packet.h>
     48#include <nil_module.h>
    4849#include <nil_standalone.h>
    4950
     
    7980}
    8081
    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 *
    8996 */
    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);
     97int 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);
    92101}
    93102
  • uspace/srv/net/nil/nildummy/nildummy.c

    r4dd8529 r24ab58b3  
    6060/** The module name.
    6161 */
    62 #define NAME    "Dummy nil protocol"
     62#define NAME  "nildummy"
    6363
    6464/** Default maximum transmission unit.
     
    228228                        return index;
    229229                }
    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);
    231232        }
    232233        fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
     
    290291        nildummy_globals.proto.service = service;
    291292        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       
    293297        fibril_rwlock_write_unlock(&nildummy_globals.protos_lock);
    294298        return EOK;
     
    312316}
    313317
    314 int nil_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     318int nil_message(const char *name, ipc_callid_t callid, ipc_call_t *call,
     319    ipc_call_t *answer, int *answer_count)
     320{
    315321        ERROR_DECLARE;
    316 
     322       
    317323        measured_string_ref address;
    318324        packet_t packet;
     
    321327        size_t suffix;
    322328        size_t content;
    323 
    324 //      printf("message %d - %d\n", IPC_GET_METHOD(*call), NET_NIL_FIRST);
     329       
    325330        *answer_count = 0;
    326         switch(IPC_GET_METHOD(*call)){
     331        switch (IPC_GET_METHOD(*call)) {
    327332                case IPC_M_PHONE_HUNGUP:
    328333                        return EOK;
    329334                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));
    331337                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));
    334342                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));
    336345                        IPC_SET_ADDR(answer, addrlen);
    337346                        IPC_SET_PREFIX(answer, prefix);
     
    341350                        return EOK;
    342351                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));
    344354                        return measured_strings_reply(address, 1);
    345355                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       
    348360        return ENOTSUP;
    349361}
     
    404416               
    405417                /* 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);
    407420               
    408421                /* End if said to either by the message or the processing result */
     
    428441        ERROR_DECLARE;
    429442       
    430         /* Print the module label */
    431         printf("Task %d - %s\n", task_get_id(), NAME);
    432        
    433443        /* 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)))
    436445                return ERROR_CODE;
    437         }
    438446       
    439447        return EOK;
  • uspace/srv/net/nil/nildummy/nildummy_module.c

    r4dd8529 r24ab58b3  
    5151#include "nildummy.h"
    5252
    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 *
    6068 */
    61 int nil_module_start(async_client_conn_t client_connection){
     69int nil_module_start(async_client_conn_t client_connection)
     70{
    6271        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       
    6477        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))){
    7280                pm_destroy();
    7381                return ERROR_CODE;
    7482        }
    75 
     83       
    7684        async_manager();
    77 
     85       
    7886        pm_destroy();
    7987        return EOK;
    8088}
    8189
    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 *
    90104 */
    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);
     105int 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);
    93109}
    94110
  • uspace/srv/net/tl/icmp/icmp.c

    r4dd8529 r24ab58b3  
    873873        ERROR_DECLARE;
    874874       
    875         /* Print the module label */
    876         printf("Task %d - %s\n", task_get_id(), NAME);
    877        
    878875        /* 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)))
    881877                return ERROR_CODE;
    882         }
    883878       
    884879        return EOK;
  • uspace/srv/net/tl/tcp/tcp.c

    r4dd8529 r24ab58b3  
    20512051        ERROR_DECLARE;
    20522052       
    2053         /* Print the module label */
    2054         printf("Task %d - %s\n", task_get_id(), NAME);
    2055        
    20562053        /* 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)))
    20592055                return ERROR_CODE;
    2060         }
    20612056       
    20622057        return EOK;
  • uspace/srv/net/tl/udp/udp.c

    r4dd8529 r24ab58b3  
    753753        ERROR_DECLARE;
    754754       
    755         /* Print the module label */
    756         printf("Task %d - %s\n", task_get_id(), NAME);
    757        
    758755        /* 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)))
    761757                return ERROR_CODE;
    762         }
    763758       
    764759        return EOK;
Note: See TracChangeset for help on using the changeset viewer.