Changeset 24ab58b3 in mainline for uspace/lib/net


Ignore:
Timestamp:
2010-04-06T11:41:48Z (15 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/lib/net
Files:
9 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
Note: See TracChangeset for help on using the changeset viewer.