Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/netif/netif_local.c

    r42a9f27 r995689d1  
    2727 */
    2828
    29 /** @addtogroup libnet
     29/** @addtogroup netif
    3030 * @{
    3131 */
     
    5858DEVICE_MAP_IMPLEMENT(netif_device_map, netif_device_t);
    5959
    60 /** Network interface global data. */
     60/** Network interface global data.
     61 */
    6162netif_globals_t netif_globals;
    6263
     
    6465 *
    6566 * @param[in] netif_phone The network interface phone.
    66  * @param[in] device_id The device identifier.
    67  * @param[in] irq       The device interrupt number.
    68  * @param[in] io        The device input/output address.
    69  * @return              EOK on success.
    70  * @return              Other error codes as defined for the
    71  *                      netif_probe_message().
    72  */
    73 int
    74 netif_probe_req_local(int netif_phone, device_id_t device_id, int irq, int io)
     67 * @param[in] device_id   The device identifier.
     68 * @param[in] irq         The device interrupt number.
     69 * @param[in] io          The device input/output address.
     70 *
     71 * @return EOK on success.
     72 * @return Other errro codes as defined for the netif_probe_message().
     73 *
     74 */
     75int netif_probe_req_local(int netif_phone, device_id_t device_id, int irq, int io)
    7576{
    7677        fibril_rwlock_write_lock(&netif_globals.lock);
     
    8485 *
    8586 * @param[in] netif_phone The network interface phone.
    86  * @param[in] device_id The device identifier.
    87  * @param[in] packet    The packet queue.
    88  * @param[in] sender    The sending module service.
    89  * @return              EOK on success.
    90  * @return              Other error codes as defined for the generic_send_msg()
    91  *                      function.
     87 * @param[in] device_id   The device identifier.
     88 * @param[in] packet      The packet queue.
     89 * @param[in] sender      The sending module service.
     90 *
     91 * @return EOK on success.
     92 * @return Other error codes as defined for the generic_send_msg() function.
     93 *
    9294 */
    9395int netif_send_msg_local(int netif_phone, device_id_t device_id,
     
    104106 *
    105107 * @param[in] netif_phone The network interface phone.
    106  * @param[in] device_id The device identifier.
    107  * @return              EOK on success.
    108  * @return              Other error codes as defined for the find_device()
    109  *                      function.
    110  * @return              Other error codes as defined for the
    111  *                      netif_start_message() function.
     108 * @param[in] device_id   The device identifier.
     109 *
     110 * @return EOK on success.
     111 * @return Other error codes as defined for the find_device() function.
     112 * @return Other error codes as defined for the netif_start_message() function.
     113 *
    112114 */
    113115int netif_start_req_local(int netif_phone, device_id_t device_id)
     
    139141 *
    140142 * @param[in] netif_phone The network interface phone.
    141  * @param[in] device_id The device identifier.
    142  * @return              EOK on success.
    143  * @return              Other error codes as defined for the find_device()
    144  *                      function.
    145  * @return              Other error codes as defined for the
    146  *                      netif_stop_message() function.
     143 * @param[in] device_id   The device identifier.
     144 *
     145 * @return EOK on success.
     146 * @return Other error codes as defined for the find_device() function.
     147 * @return Other error codes as defined for the netif_stop_message() function.
     148 *
    147149 */
    148150int netif_stop_req_local(int netif_phone, device_id_t device_id)
     
    173175/** Return the device usage statistics.
    174176 *
    175  * @param[in] netif_phone The network interface phone.
    176  * @param[in] device_id The device identifier.
    177  * @param[out] stats    The device usage statistics.
    178  * @return EOK on success.
     177 * @param[in]  netif_phone The network interface phone.
     178 * @param[in]  device_id   The device identifier.
     179 * @param[out] stats       The device usage statistics.
     180 *
     181 * @return EOK on success.
     182 *
    179183 */
    180184int netif_stats_req_local(int netif_phone, device_id_t device_id,
     
    190194/** Return the device local hardware address.
    191195 *
    192  * @param[in] netif_phone The network interface phone.
    193  * @param[in] device_id The device identifier.
    194  * @param[out] address  The device local hardware address.
    195  * @param[out] data     The address data.
    196  * @return              EOK on success.
    197  * @return              EBADMEM if the address parameter is NULL.
    198  * @return              ENOENT if there no such device.
    199  * @return              Other error codes as defined for the
    200  *                      netif_get_addr_message() function.
     196 * @param[in]  netif_phone The network interface phone.
     197 * @param[in]  device_id   The device identifier.
     198 * @param[out] address     The device local hardware address.
     199 * @param[out] data        The address data.
     200 *
     201 * @return EOK on success.
     202 * @return EBADMEM if the address parameter is NULL.
     203 * @return ENOENT if there no such device.
     204 * @return Other error codes as defined for the netif_get_addr_message()
     205 *         function.
     206 *
    201207 */
    202208int netif_get_addr_req_local(int netif_phone, device_id_t device_id,
     
    205211        ERROR_DECLARE;
    206212       
    207         if (!address || !data)
     213        if ((!address) || (!data))
    208214                return EBADMEM;
    209215       
     
    225231/** Find the device specific data.
    226232 *
    227  * @param[in] device_id The device identifier.
    228  * @param[out] device   The device specific data.
    229  * @return              EOK on success.
    230  * @return              ENOENT if device is not found.
    231  * @return              EPERM if the device is not initialized.
     233 * @param[in]  device_id The device identifier.
     234 * @param[out] device    The device specific data.
     235 *
     236 * @return EOK on success.
     237 * @return ENOENT if device is not found.
     238 * @return EPERM if the device is not initialized.
     239 *
    232240 */
    233241int find_device(device_id_t device_id, netif_device_t **device)
     
    248256/** Clear the usage statistics.
    249257 *
    250  * @param[in] stats     The usage statistics.
     258 * @param[in] stats The usage statistics.
     259 *
    251260 */
    252261void null_device_stats(device_stats_ref stats)
     
    257266/** Initialize the netif module.
    258267 *
    259  * @param[in] client_connection The client connection functio to be registered.
    260  * @return              EOK on success.
    261  * @return              Other error codes as defined for each specific module
    262  *                      message function.
     268 *  @param[in] client_connection The client connection functio to be
     269 *                               registered.
     270 *
     271 *  @return EOK on success.
     272 *  @return Other error codes as defined for each specific module
     273 *          message function.
     274 *
    263275 */
    264276int netif_init_module(async_client_conn_t client_connection)
     
    286298 * Prepared for future optimization.
    287299 *
    288  * @param[in] packet_id The packet identifier.
     300 * @param[in] packet_id The packet identifier.
     301 *
    289302 */
    290303void netif_pq_release(packet_id_t packet_id)
     
    295308/** Allocate new packet to handle the given content size.
    296309 *
    297  * @param[in] content   The minimum content size.
    298  * @return              The allocated packet.
    299  * @return              NULL if there is an error.
     310 * @param[in] content The minimum content size.
     311 *
     312 * @return The allocated packet.
     313 * @return NULL if there is an error.
    300314 *
    301315 */
     
    305319}
    306320
    307 /** Register the device notification receiver, the network interface layer
    308  * module.
    309  *
    310  * @param[in] name      Module name.
    311  * @param[in] device_id The device identifier.
    312  * @param[in] phone     The network interface layer module phone.
    313  * @return              EOK on success.
    314  * @return              ENOENT if there is no such device.
    315  * @return              ELIMIT if there is another module registered.
     321/** Register the device notification receiver, the network interface layer module.
     322 *
     323 * @param[in] name      Module name.
     324 * @param[in] device_id The device identifier.
     325 * @param[in] phone     The network interface layer module phone.
     326 *
     327 * @return EOK on success.
     328 * @return ENOENT if there is no such device.
     329 * @return ELIMIT if there is another module registered.
     330 *
    316331 */
    317332static int register_message(const char *name, device_id_t device_id, int phone)
     
    332347/** Process the netif module messages.
    333348 *
    334  * @param[in] name      Module name.
    335  * @param[in] callid    The message identifier.
    336  * @param[in] call      The message parameters.
    337  * @param[out] answer   The message answer parameters.
    338  * @param[out] answer_count The last parameter for the actual answer in the
    339  *                      answer parameter.
    340  * @return              EOK on success.
    341  * @return              ENOTSUP if the message is not known.
    342  * @return              Other error codes as defined for each specific module
    343  *                      message function.
     349 * @param[in]  name         Module name.
     350 * @param[in]  callid       The message identifier.
     351 * @param[in]  call         The message parameters.
     352 * @param[out] answer       The message answer parameters.
     353 * @param[out] answer_count The last parameter for the actual answer
     354 *                          in the answer parameter.
     355 *
     356 * @return EOK on success.
     357 * @return ENOTSUP if the message is not known.
     358 * @return Other error codes as defined for each specific module message function.
    344359 *
    345360 * @see IS_NET_NETIF_MESSAGE()
     
    358373        *answer_count = 0;
    359374        switch (IPC_GET_METHOD(*call)) {
    360         case IPC_M_PHONE_HUNGUP:
    361                 return EOK;
    362        
    363         case NET_NETIF_PROBE:
    364                 return netif_probe_req_local(0, IPC_GET_DEVICE(call),
    365                     NETIF_GET_IRQ(call), NETIF_GET_IO(call));
    366                    
    367         case IPC_M_CONNECT_TO_ME:
    368                 fibril_rwlock_write_lock(&netif_globals.lock);
    369                 ERROR_CODE = register_message(name, IPC_GET_DEVICE(call),
    370                     IPC_GET_PHONE(call));
    371                 fibril_rwlock_write_unlock(&netif_globals.lock);
    372                 return ERROR_CODE;
    373                
    374         case NET_NETIF_SEND:
    375                 ERROR_PROPAGATE(packet_translate_remote(netif_globals.net_phone,
    376                     &packet, IPC_GET_PACKET(call)));
    377                 return netif_send_msg_local(0, IPC_GET_DEVICE(call), packet,
    378                     IPC_GET_SENDER(call));
    379                    
    380         case NET_NETIF_START:
    381                 return netif_start_req_local(0, IPC_GET_DEVICE(call));
    382                
    383         case NET_NETIF_STATS:
    384                 fibril_rwlock_read_lock(&netif_globals.lock);
    385 
    386                 if (ERROR_OCCURRED(async_data_read_receive(&callid, &length))) {
     375                case IPC_M_PHONE_HUNGUP:
     376                        return EOK;
     377                case NET_NETIF_PROBE:
     378                        return netif_probe_req_local(0, IPC_GET_DEVICE(call),
     379                            NETIF_GET_IRQ(call), NETIF_GET_IO(call));
     380                case IPC_M_CONNECT_TO_ME:
     381                        fibril_rwlock_write_lock(&netif_globals.lock);
     382                        ERROR_CODE = register_message(name, IPC_GET_DEVICE(call),
     383                            IPC_GET_PHONE(call));
     384                        fibril_rwlock_write_unlock(&netif_globals.lock);
     385                        return ERROR_CODE;
     386                case NET_NETIF_SEND:
     387                        ERROR_PROPAGATE(packet_translate_remote(netif_globals.net_phone,
     388                            &packet, IPC_GET_PACKET(call)));
     389                        return netif_send_msg_local(0, IPC_GET_DEVICE(call), packet,
     390                            IPC_GET_SENDER(call));
     391                case NET_NETIF_START:
     392                        return netif_start_req_local(0, IPC_GET_DEVICE(call));
     393                case NET_NETIF_STATS:
     394                        fibril_rwlock_read_lock(&netif_globals.lock);
     395                        if (!ERROR_OCCURRED(async_data_read_receive(&callid, &length))) {
     396                                if (length < sizeof(device_stats_t))
     397                                        ERROR_CODE = EOVERFLOW;
     398                                else {
     399                                        if (!ERROR_OCCURRED(netif_get_device_stats(
     400                                            IPC_GET_DEVICE(call), &stats)))
     401                                                ERROR_CODE = async_data_read_finalize(callid, &stats,
     402                                                    sizeof(device_stats_t));
     403                                }
     404                        }
    387405                        fibril_rwlock_read_unlock(&netif_globals.lock);
    388406                        return ERROR_CODE;
    389                 }
    390                 if (length < sizeof(device_stats_t)) {
     407                case NET_NETIF_STOP:
     408                        return netif_stop_req_local(0, IPC_GET_DEVICE(call));
     409                case NET_NETIF_GET_ADDR:
     410                        fibril_rwlock_read_lock(&netif_globals.lock);
     411                        if (!ERROR_OCCURRED(netif_get_addr_message(IPC_GET_DEVICE(call),
     412                            &address)))
     413                                ERROR_CODE = measured_strings_reply(&address, 1);
    391414                        fibril_rwlock_read_unlock(&netif_globals.lock);
    392                         return EOVERFLOW;
    393                 }
    394 
    395                 if (ERROR_NONE(netif_get_device_stats(IPC_GET_DEVICE(call),
    396                     &stats))) {
    397                         ERROR_CODE = async_data_read_finalize(callid, &stats,
    398                             sizeof(device_stats_t));
    399                 }
    400 
    401                 fibril_rwlock_read_unlock(&netif_globals.lock);
    402                 return ERROR_CODE;
    403 
    404         case NET_NETIF_STOP:
    405                 return netif_stop_req_local(0, IPC_GET_DEVICE(call));
    406                
    407         case NET_NETIF_GET_ADDR:
    408                 fibril_rwlock_read_lock(&netif_globals.lock);
    409                 if (ERROR_NONE(netif_get_addr_message(IPC_GET_DEVICE(call),
    410                     &address)))
    411                         ERROR_CODE = measured_strings_reply(&address, 1);
    412                 fibril_rwlock_read_unlock(&netif_globals.lock);
    413                 return ERROR_CODE;
     415                        return ERROR_CODE;
    414416        }
    415417       
     
    419421/** Start the network interface module.
    420422 *
    421  * Initialize the client connection serving function, initialize the module,
    422  * registers the module service and start the async manager, processing IPC
    423  * messages in an infinite loop.
    424  *
    425  * @param[in] client_connection The client connection processing function.
    426  *                      The module skeleton propagates its own one.
    427  * @return              EOK on success.
    428  * @return              Other error codes as defined for each specific module
    429  *                      message function.
     423 * Initialize the client connection serving function, initialize
     424 * the module, registers the module service and start the async
     425 * manager, processing IPC messages in an infinite loop.
     426 *
     427 * @param[in] client_connection The client connection processing
     428 *                              function. The module skeleton propagates
     429 *                              its own one.
     430 *
     431 * @return EOK on success.
     432 * @return Other error codes as defined for each specific module message
     433 *         function.
     434 *
    430435 */
    431436int netif_module_start_standalone(async_client_conn_t client_connection)
Note: See TracChangeset for help on using the changeset viewer.