Changeset 4687a26c in mainline for uspace/lib/net/netif/netif_local.c


Ignore:
Timestamp:
2010-11-02T18:29:01Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4f35b9ff
Parents:
76e1121f (diff), 28f4adb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    r76e1121f r4687a26c  
    2727 */
    2828
    29 /** @addtogroup netif
     29/** @addtogroup libnet
    3030 * @{
    3131 */
     
    4242#include <ipc/ipc.h>
    4343#include <ipc/services.h>
    44 
    45 #include <net_err.h>
    46 #include <net_messages.h>
    47 #include <net_modules.h>
    48 #include <packet/packet.h>
    49 #include <packet/packet_client.h>
    50 #include <packet/packet_server.h>
     44#include <ipc/netif.h>
     45#include <err.h>
     46
     47#include <generic.h>
     48#include <net/modules.h>
     49#include <net/packet.h>
     50#include <packet_client.h>
    5151#include <packet_remote.h>
    5252#include <adt/measured_strings.h>
    53 #include <net_device.h>
     53#include <net/device.h>
    5454#include <nil_interface.h>
    5555#include <netif_local.h>
    56 #include <netif_messages.h>
    5756#include <netif_interface.h>
    5857
    5958DEVICE_MAP_IMPLEMENT(netif_device_map, netif_device_t);
    6059
    61 /** Network interface global data.
    62  */
     60/** Network interface global data. */
    6361netif_globals_t netif_globals;
    6462
     
    6664 *
    6765 * @param[in] netif_phone The network interface phone.
    68  * @param[in] device_id   The device identifier.
    69  * @param[in] irq         The device interrupt number.
    70  * @param[in] io          The device input/output address.
    71  *
    72  * @return EOK on success.
    73  * @return Other errro codes as defined for the netif_probe_message().
    74  *
    75  */
    76 int netif_probe_req_local(int netif_phone, device_id_t device_id, int irq, int io)
     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 */
     73int
     74netif_probe_req_local(int netif_phone, device_id_t device_id, int irq, int io)
    7775{
    7876        fibril_rwlock_write_lock(&netif_globals.lock);
     
    8684 *
    8785 * @param[in] netif_phone The network interface phone.
    88  * @param[in] device_id   The device identifier.
    89  * @param[in] packet      The packet queue.
    90  * @param[in] sender      The sending module service.
    91  *
    92  * @return EOK on success.
    93  * @return Other error codes as defined for the generic_send_msg() function.
    94  *
     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.
    9592 */
    9693int netif_send_msg_local(int netif_phone, device_id_t device_id,
     
    107104 *
    108105 * @param[in] netif_phone The network interface phone.
    109  * @param[in] device_id   The device identifier.
    110  *
    111  * @return EOK on success.
    112  * @return Other error codes as defined for the find_device() function.
    113  * @return Other error codes as defined for the netif_start_message() function.
    114  *
     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.
    115112 */
    116113int netif_start_req_local(int netif_phone, device_id_t device_id)
     
    142139 *
    143140 * @param[in] netif_phone The network interface phone.
    144  * @param[in] device_id   The device identifier.
    145  *
    146  * @return EOK on success.
    147  * @return Other error codes as defined for the find_device() function.
    148  * @return Other error codes as defined for the netif_stop_message() function.
    149  *
     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.
    150147 */
    151148int netif_stop_req_local(int netif_phone, device_id_t device_id)
     
    176173/** Return the device usage statistics.
    177174 *
    178  * @param[in]  netif_phone The network interface phone.
    179  * @param[in]  device_id   The device identifier.
    180  * @param[out] stats       The device usage statistics.
    181  *
     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.
    182178 * @return EOK on success.
    183  *
    184179 */
    185180int netif_stats_req_local(int netif_phone, device_id_t device_id,
     
    195190/** Return the device local hardware address.
    196191 *
    197  * @param[in]  netif_phone The network interface phone.
    198  * @param[in]  device_id   The device identifier.
    199  * @param[out] address     The device local hardware address.
    200  * @param[out] data        The address data.
    201  *
    202  * @return EOK on success.
    203  * @return EBADMEM if the address parameter is NULL.
    204  * @return ENOENT if there no such device.
    205  * @return Other error codes as defined for the netif_get_addr_message()
    206  *         function.
    207  *
     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.
    208201 */
    209202int netif_get_addr_req_local(int netif_phone, device_id_t device_id,
     
    212205        ERROR_DECLARE;
    213206       
    214         if ((!address) || (!data))
     207        if (!address || !data)
    215208                return EBADMEM;
    216209       
     
    230223}
    231224
    232 /** Create bidirectional connection with the network interface module and registers the message receiver.
    233  *
    234  * @param[in] service   The network interface module service.
    235  * @param[in] device_id The device identifier.
    236  * @param[in] me        The requesting module service.
    237  * @param[in] receiver  The message receiver.
    238  *
    239  * @return The phone of the needed service.
    240  * @return EOK on success.
    241  * @return Other error codes as defined for the bind_service() function.
    242  *
    243  */
    244 int netif_bind_service_local(services_t service, device_id_t device_id,
    245     services_t me, async_client_conn_t receiver)
    246 {
    247         return EOK;
    248 }
    249 
    250225/** Find the device specific data.
    251226 *
    252  * @param[in]  device_id The device identifier.
    253  * @param[out] device    The device specific data.
    254  *
    255  * @return EOK on success.
    256  * @return ENOENT if device is not found.
    257  * @return EPERM if the device is not initialized.
    258  *
     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.
    259232 */
    260233int find_device(device_id_t device_id, netif_device_t **device)
     
    275248/** Clear the usage statistics.
    276249 *
    277  * @param[in] stats The usage statistics.
    278  *
     250 * @param[in] stats     The usage statistics.
    279251 */
    280252void null_device_stats(device_stats_ref stats)
     
    285257/** Initialize the netif module.
    286258 *
    287  *  @param[in] client_connection The client connection functio to be
    288  *                               registered.
    289  *
    290  *  @return EOK on success.
    291  *  @return Other error codes as defined for each specific module
    292  *          message function.
    293  *
     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.
    294263 */
    295264int netif_init_module(async_client_conn_t client_connection)
     
    317286 * Prepared for future optimization.
    318287 *
    319  * @param[in] packet_id The packet identifier.
    320  *
     288 * @param[in] packet_id The packet identifier.
    321289 */
    322290void netif_pq_release(packet_id_t packet_id)
     
    327295/** Allocate new packet to handle the given content size.
    328296 *
    329  * @param[in] content The minimum content size.
    330  *
    331  * @return The allocated packet.
    332  * @return NULL if there is an error.
     297 * @param[in] content   The minimum content size.
     298 * @return              The allocated packet.
     299 * @return              NULL if there is an error.
    333300 *
    334301 */
     
    338305}
    339306
    340 /** Register the device notification receiver, the network interface layer module.
    341  *
    342  * @param[in] name      Module name.
    343  * @param[in] device_id The device identifier.
    344  * @param[in] phone     The network interface layer module phone.
    345  *
    346  * @return EOK on success.
    347  * @return ENOENT if there is no such device.
    348  * @return ELIMIT if there is another module registered.
    349  *
     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.
    350316 */
    351317static int register_message(const char *name, device_id_t device_id, int phone)
     
    366332/** Process the netif module messages.
    367333 *
    368  * @param[in]  name         Module name.
    369  * @param[in]  callid       The message identifier.
    370  * @param[in]  call         The message parameters.
    371  * @param[out] answer       The message answer parameters.
    372  * @param[out] answer_count The last parameter for the actual answer
    373  *                          in the answer parameter.
    374  *
    375  * @return EOK on success.
    376  * @return ENOTSUP if the message is not known.
    377  * @return Other error codes as defined for each specific module message function.
     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.
    378344 *
    379345 * @see IS_NET_NETIF_MESSAGE()
     
    392358        *answer_count = 0;
    393359        switch (IPC_GET_METHOD(*call)) {
    394                 case IPC_M_PHONE_HUNGUP:
    395                         return EOK;
    396                 case NET_NETIF_PROBE:
    397                         return netif_probe_req_local(0, IPC_GET_DEVICE(call),
    398                             NETIF_GET_IRQ(call), NETIF_GET_IO(call));
    399                 case IPC_M_CONNECT_TO_ME:
    400                         fibril_rwlock_write_lock(&netif_globals.lock);
    401                         ERROR_CODE = register_message(name, IPC_GET_DEVICE(call),
    402                             IPC_GET_PHONE(call));
    403                         fibril_rwlock_write_unlock(&netif_globals.lock);
    404                         return ERROR_CODE;
    405                 case NET_NETIF_SEND:
    406                         ERROR_PROPAGATE(packet_translate_remote(netif_globals.net_phone,
    407                             &packet, IPC_GET_PACKET(call)));
    408                         return netif_send_msg_local(0, IPC_GET_DEVICE(call), packet,
    409                             IPC_GET_SENDER(call));
    410                 case NET_NETIF_START:
    411                         return netif_start_req_local(0, IPC_GET_DEVICE(call));
    412                 case NET_NETIF_STATS:
    413                         fibril_rwlock_read_lock(&netif_globals.lock);
    414                         if (!ERROR_OCCURRED(async_data_read_receive(&callid, &length))) {
    415                                 if (length < sizeof(device_stats_t))
    416                                         ERROR_CODE = EOVERFLOW;
    417                                 else {
    418                                         if (!ERROR_OCCURRED(netif_get_device_stats(
    419                                             IPC_GET_DEVICE(call), &stats)))
    420                                                 ERROR_CODE = async_data_read_finalize(callid, &stats,
    421                                                     sizeof(device_stats_t));
    422                                 }
    423                         }
     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))) {
    424387                        fibril_rwlock_read_unlock(&netif_globals.lock);
    425388                        return ERROR_CODE;
    426                 case NET_NETIF_STOP:
    427                         return netif_stop_req_local(0, IPC_GET_DEVICE(call));
    428                 case NET_NETIF_GET_ADDR:
    429                         fibril_rwlock_read_lock(&netif_globals.lock);
    430                         if (!ERROR_OCCURRED(netif_get_addr_message(IPC_GET_DEVICE(call),
    431                             &address)))
    432                                 ERROR_CODE = measured_strings_reply(&address, 1);
     389                }
     390                if (length < sizeof(device_stats_t)) {
    433391                        fibril_rwlock_read_unlock(&netif_globals.lock);
    434                         return ERROR_CODE;
     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;
    435414        }
    436415       
     
    440419/** Start the network interface module.
    441420 *
    442  * Initialize the client connection serving function, initialize
    443  * the module, registers the module service and start the async
    444  * manager, processing IPC messages in an infinite loop.
    445  *
    446  * @param[in] client_connection The client connection processing
    447  *                              function. The module skeleton propagates
    448  *                              its own one.
    449  *
    450  * @return EOK on success.
    451  * @return Other error codes as defined for each specific module message
    452  *         function.
    453  *
     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.
    454430 */
    455431int netif_module_start_standalone(async_client_conn_t client_connection)
Note: See TracChangeset for help on using the changeset viewer.