Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset c4fbf7fd in mainline


Ignore:
Timestamp:
2010-10-26T22:06:51Z (10 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
master
Children:
25271006
Parents:
a649e73
Message:

Cleanup lo.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/netif/lo/lo.c

    ra649e73 rc4fbf7fd  
    2828
    2929/** @addtogroup lo
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Loopback network interface implementation.
     34 * Loopback network interface implementation.
    3535 */
    3636
     
    5353#include <netif_local.h>
    5454
    55 /** Default hardware address.
    56  */
     55/** Default hardware address. */
    5756#define DEFAULT_ADDR            "\0\0\0\0\0\0"
    5857
    59 /** Default address length.
    60  */
     58/** Default address length. */
    6159#define DEFAULT_ADDR_LEN        (sizeof(DEFAULT_ADDR) / sizeof(char))
    6260
    63 /** Loopback module name.
    64  */
     61/** Loopback module name. */
    6562#define NAME  "lo"
    6663
    67 /** Network interface global data.
    68  */
     64/** Network interface global data. */
    6965netif_globals_t netif_globals;
    7066
    71 /** Changes the loopback state.
    72  *  @param[in] device The device structure.
    73  *  @param[in] state The new device state.
    74  *  @returns The new state if changed.
    75  *  @returns EOK otherwise.
    76  */
    77 int change_state_message(netif_device_t * device, device_state_t state);
    78 
    79 /** Creates and returns the loopback network interface structure.
    80  *  @param[in] device_id The new devce identifier.
    81  *  @param[out] device The device structure.
    82  *  @returns EOK on success.
    83  *  @returns EXDEV if one loopback network interface already exists.
    84  *  @returns ENOMEM if there is not enough memory left.
    85  */
    86 int create(device_id_t device_id, netif_device_t * * device);
    87 
    88 int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     67int
     68netif_specific_message(ipc_callid_t callid, ipc_call_t *call,
     69    ipc_call_t *answer, int *answer_count)
     70{
    8971        return ENOTSUP;
    9072}
    9173
    92 int netif_get_addr_message(device_id_t device_id, measured_string_ref address){
    93         if(! address){
     74int netif_get_addr_message(device_id_t device_id, measured_string_ref address)
     75{
     76        if (!address)
    9477                return EBADMEM;
    95         }
    9678        address->value = str_dup(DEFAULT_ADDR);
    9779        address->length = DEFAULT_ADDR_LEN;
     
    9981}
    10082
    101 int netif_get_device_stats(device_id_t device_id, device_stats_ref stats){
    102         ERROR_DECLARE;
    103 
    104         netif_device_t * device;
    105 
    106         if(! stats){
     83int netif_get_device_stats(device_id_t device_id, device_stats_ref stats)
     84{
     85        ERROR_DECLARE;
     86
     87        netif_device_t *device;
     88
     89        if (!stats)
    10790                return EBADMEM;
    108         }
    10991        ERROR_PROPAGATE(find_device(device_id, &device));
    110         memcpy(stats, (device_stats_ref) device->specific, sizeof(device_stats_t));
    111         return EOK;
    112 }
    113 
    114 int change_state_message(netif_device_t * device, device_state_t state)
     92        memcpy(stats, (device_stats_ref) device->specific,
     93            sizeof(device_stats_t));
     94        return EOK;
     95}
     96
     97/** Changes the loopback state.
     98 *
     99 * @param[in] device    The device structure.
     100 * @param[in] state     The new device state.
     101 * @returns             The new state if changed.
     102 * @returns             EOK otherwise.
     103 */
     104static int change_state_message(netif_device_t *device, device_state_t state)
    115105{
    116106        if (device->state != state) {
     
    126116}
    127117
    128 int create(device_id_t device_id, netif_device_t * * device){
     118/** Creates and returns the loopback network interface structure.
     119 *
     120 * @param[in] device_id The new devce identifier.
     121 * @param[out] device   The device structure.
     122 * @returns             EOK on success.
     123 * @returns             EXDEV if one loopback network interface already exists.
     124 * @returns             ENOMEM if there is not enough memory left.
     125 */
     126static int create(device_id_t device_id, netif_device_t **device)
     127{
    129128        int index;
    130129
    131         if(netif_device_map_count(&netif_globals.device_map) > 0){
     130        if (netif_device_map_count(&netif_globals.device_map) > 0)
    132131                return EXDEV;
    133         }else{
    134                 *device = (netif_device_t *) malloc(sizeof(netif_device_t));
    135                 if(!(*device)){
    136                         return ENOMEM;
    137                 }
    138                 (** device).specific = malloc(sizeof(device_stats_t));
    139                 if(! (** device).specific){
    140                         free(*device);
    141                         return ENOMEM;
    142                 }
    143                 null_device_stats((device_stats_ref)(** device).specific);
    144                 (** device).device_id = device_id;
    145                 (** device).nil_phone = -1;
    146                 (** device).state = NETIF_STOPPED;
    147                 index = netif_device_map_add(&netif_globals.device_map, (** device).device_id, * device);
    148                 if(index < 0){
    149                         free(*device);
    150                         free((** device).specific);
    151                         *device = NULL;
    152                         return index;
    153                 }
    154         }
    155         return EOK;
    156 }
    157 
    158 int netif_initialize(void){
     132
     133        *device = (netif_device_t *) malloc(sizeof(netif_device_t));
     134        if (!*device)
     135                return ENOMEM;
     136        (*device)->specific = (device_stats_t *) malloc(sizeof(device_stats_t));
     137        if (!(*device)->specific) {
     138                free(*device);
     139                return ENOMEM;
     140        }
     141        null_device_stats((device_stats_ref) (*device)->specific);
     142        (*device)->device_id = device_id;
     143        (*device)->nil_phone = -1;
     144        (*device)->state = NETIF_STOPPED;
     145        index = netif_device_map_add(&netif_globals.device_map,
     146            (*device)->device_id, *device);
     147        if (index < 0) {
     148                free(*device);
     149                free((*device)->specific);
     150                *device = NULL;
     151                return index;
     152        }
     153       
     154        return EOK;
     155}
     156
     157int netif_initialize(void)
     158{
    159159        ipcarg_t phonehash;
    160160
     
    162162}
    163163
    164 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io){
     164int netif_probe_message(device_id_t device_id, int irq, uintptr_t io)
     165{
    165166        ERROR_DECLARE;
    166167
     
    174175}
    175176
    176 int netif_send_message(device_id_t device_id, packet_t packet, services_t sender){
    177         ERROR_DECLARE;
    178 
    179         netif_device_t * device;
     177int netif_send_message(device_id_t device_id, packet_t packet, services_t sender)
     178{
     179        ERROR_DECLARE;
     180
     181        netif_device_t *device;
    180182        size_t length;
    181183        packet_t next;
     
    183185
    184186        ERROR_PROPAGATE(find_device(device_id, &device));
    185         if(device->state != NETIF_ACTIVE){
     187        if (device->state != NETIF_ACTIVE) {
    186188                netif_pq_release(packet_get_id(packet));
    187189                return EFORWARD;
    188190        }
    189191        next = packet;
    190         do{
    191                 ++ ((device_stats_ref) device->specific)->send_packets;
    192                 ++ ((device_stats_ref) device->specific)->receive_packets;
     192        do {
     193                ((device_stats_ref) device->specific)->send_packets++;
     194                ((device_stats_ref) device->specific)->receive_packets++;
    193195                length = packet_get_data_length(next);
    194196                ((device_stats_ref) device->specific)->send_bytes += length;
    195197                ((device_stats_ref) device->specific)->receive_bytes += length;
    196198                next = pq_next(next);
    197         }while(next);
     199        } while(next);
    198200        phone = device->nil_phone;
    199201        fibril_rwlock_write_unlock(&netif_globals.lock);
    200202        nil_received_msg(phone, device_id, packet, sender);
    201203        fibril_rwlock_write_lock(&netif_globals.lock);
    202         return EOK;
    203 }
    204 
    205 int netif_start_message(netif_device_t * device){
     204       
     205        return EOK;
     206}
     207
     208int netif_start_message(netif_device_t *device)
     209{
    206210        return change_state_message(device, NETIF_ACTIVE);
    207211}
    208212
    209 int netif_stop_message(netif_device_t * device){
     213int netif_stop_message(netif_device_t *device)
     214{
    210215        return change_state_message(device, NETIF_STOPPED);
    211216}
     
    213218/** Default thread for new connections.
    214219 *
    215  * @param[in] iid The initial message identifier.
    216  * @param[in] icall The initial message call structure.
    217  *
     220 * @param[in] iid       The initial message identifier.
     221 * @param[in] icall     The initial message call structure.
    218222 */
    219223static void netif_client_connection(ipc_callid_t iid, ipc_call_t *icall)
     
    225229        ipc_answer_0(iid, EOK);
    226230       
    227         while(true) {
     231        while (true) {
    228232                ipc_call_t answer;
    229233                int answer_count;
     
    240244                    &answer_count);
    241245               
    242                 /* End if said to either by the message or the processing result */
    243                 if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
     246                /*
     247                 * End if said to either by the message or the processing
     248                 * result.
     249                 */
     250                if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) ||
     251                    (res == EHANGUP))
    244252                        return;
    245253               
Note: See TracChangeset for help on using the changeset viewer.