Changeset 849ed54 in mainline for uspace/lib/net/netif/netif.c


Ignore:
Timestamp:
2010-03-30T18:39:04Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7553689
Parents:
7d6fe4db
Message:

Networking work:
Split the networking stack into end-user library (libsocket) and two helper libraries (libnet and libnetif).
Don't use over-the-hand compiling and linking, but rather separation of conserns.
There might be still some issues and the non-modular networking architecture is currently broken, but this will be fixed soon.

File:
1 moved

Legend:

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

    r7d6fe4db r849ed54  
    4444#include <ipc/services.h>
    4545
    46 #include "../err.h"
    47 #include "../messages.h"
    48 #include "../modules.h"
    49 
    50 #include "../structures/packet/packet.h"
    51 #include "../structures/packet/packet_client.h"
    52 #include "../structures/measured_strings.h"
    53 
    54 #include "../include/device.h"
    55 #include "../include/netif_interface.h"
    56 #include "../include/nil_interface.h"
    57 
    58 #include "netif.h"
    59 #include "netif_messages.h"
    60 #include "netif_module.h"
    61 
    62 /** Network interface module global data.
    63  */
    64 extern netif_globals_t netif_globals;
     46#include <net_err.h>
     47#include <net_messages.h>
     48#include <net_modules.h>
     49#include <packet/packet.h>
     50#include <packet/packet_client.h>
     51#include <adt/measured_strings.h>
     52#include <net_device.h>
     53#include <netif_interface.h>
     54#include <nil_interface.h>
     55#include <netif.h>
     56#include <netif_messages.h>
     57#include <netif_module.h>
    6558
    6659DEVICE_MAP_IMPLEMENT(device_map, device_t)
    6760
    68 /** @name Message processing functions
    69  */
    70 /*@{*/
     61/** Network interface global data.
     62 */
     63netif_globals_t netif_globals;
     64
     65int netif_probe_req(int netif_phone, device_id_t device_id, int irq, int io){
     66        int result;
     67
     68        fibril_rwlock_write_lock(&netif_globals.lock);
     69        result = netif_probe_message(device_id, irq, io);
     70        fibril_rwlock_write_unlock(&netif_globals.lock);
     71        return result;
     72}
     73
     74int netif_send_msg(int netif_phone, device_id_t device_id, packet_t packet, services_t sender){
     75        int result;
     76
     77        fibril_rwlock_write_lock(&netif_globals.lock);
     78        result = netif_send_message(device_id, packet, sender);
     79        fibril_rwlock_write_unlock(&netif_globals.lock);
     80        return result;
     81}
     82
     83int netif_start_req(int netif_phone, device_id_t device_id){
     84        ERROR_DECLARE;
     85
     86        device_ref device;
     87        int result;
     88        int phone;
     89
     90        fibril_rwlock_write_lock(&netif_globals.lock);
     91        if(ERROR_OCCURRED(find_device(device_id, &device))){
     92                fibril_rwlock_write_unlock(&netif_globals.lock);
     93                return ERROR_CODE;
     94        }
     95        result = netif_start_message(device);
     96        if(result > NETIF_NULL){
     97                phone = device->nil_phone;
     98                fibril_rwlock_write_unlock(&netif_globals.lock);
     99                nil_device_state_msg(phone, device_id, result);
     100                return EOK;
     101        }else{
     102                fibril_rwlock_write_unlock(&netif_globals.lock);
     103        }
     104        return result;
     105}
     106
     107int netif_stop_req(int netif_phone, device_id_t device_id){
     108        ERROR_DECLARE;
     109
     110        device_ref device;
     111        int result;
     112        int phone;
     113
     114        fibril_rwlock_write_lock(&netif_globals.lock);
     115        if(ERROR_OCCURRED(find_device(device_id, &device))){
     116                fibril_rwlock_write_unlock(&netif_globals.lock);
     117                return ERROR_CODE;
     118        }
     119        result = netif_stop_message(device);
     120        if(result > NETIF_NULL){
     121                phone = device->nil_phone;
     122                fibril_rwlock_write_unlock(&netif_globals.lock);
     123                nil_device_state_msg(phone, device_id, result);
     124                return EOK;
     125        }else{
     126                fibril_rwlock_write_unlock(&netif_globals.lock);
     127        }
     128        return result;
     129}
     130
     131int netif_stats_req(int netif_phone, device_id_t device_id, device_stats_ref stats){
     132        int res;
     133
     134        fibril_rwlock_read_lock(&netif_globals.lock);
     135        res = netif_get_device_stats(device_id, stats);
     136        fibril_rwlock_read_unlock(&netif_globals.lock);
     137        return res;
     138}
     139
     140int netif_get_addr_req(int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data){
     141        ERROR_DECLARE;
     142
     143        measured_string_t translation;
     144
     145        if(!(address && data)){
     146                return EBADMEM;
     147        }
     148        fibril_rwlock_read_lock(&netif_globals.lock);
     149        if(! ERROR_OCCURRED(netif_get_addr_message(device_id, &translation))){
     150                *address = measured_string_copy(&translation);
     151                ERROR_CODE = (*address) ? EOK : ENOMEM;
     152        }
     153        fibril_rwlock_read_unlock(&netif_globals.lock);
     154        *data = (** address).value;
     155        return ERROR_CODE;
     156}
     157
     158int netif_bind_service(services_t service, device_id_t device_id, services_t me, async_client_conn_t receiver){
     159        return EOK;
     160}
     161
     162int find_device(device_id_t device_id, device_ref * device){
     163        if(! device){
     164                return EBADMEM;
     165        }
     166        *device = device_map_find(&netif_globals.device_map, device_id);
     167        if(! * device){
     168                return ENOENT;
     169        }
     170        if((** device).state == NETIF_NULL) return EPERM;
     171        return EOK;
     172}
     173
     174void null_device_stats(device_stats_ref stats){
     175        bzero(stats, sizeof(device_stats_t));
     176}
    71177
    72178/** Registers the device notification receiver, the network interface layer module.
     
    77183 *  @returns ELIMIT if there is another module registered.
    78184 */
    79 int register_message(device_id_t device_id, int phone);
    80 
    81 /*@}*/
    82 
    83 int netif_probe_req(int netif_phone, device_id_t device_id, int irq, int io){
    84         int result;
    85 
    86         fibril_rwlock_write_lock(&netif_globals.lock);
    87         result = netif_probe_message(device_id, irq, io);
    88         fibril_rwlock_write_unlock(&netif_globals.lock);
    89         return result;
    90 }
    91 
    92 int netif_send_msg(int netif_phone, device_id_t device_id, packet_t packet, services_t sender){
    93         int result;
    94 
    95         fibril_rwlock_write_lock(&netif_globals.lock);
    96         result = netif_send_message(device_id, packet, sender);
    97         fibril_rwlock_write_unlock(&netif_globals.lock);
    98         return result;
    99 }
    100 
    101 int netif_start_req(int netif_phone, device_id_t device_id){
    102         ERROR_DECLARE;
    103 
    104         device_ref device;
    105         int result;
    106         int phone;
    107 
    108         fibril_rwlock_write_lock(&netif_globals.lock);
    109         if(ERROR_OCCURRED(find_device(device_id, &device))){
    110                 fibril_rwlock_write_unlock(&netif_globals.lock);
    111                 return ERROR_CODE;
    112         }
    113         result = netif_start_message(device);
    114         if(result > NETIF_NULL){
    115                 phone = device->nil_phone;
    116                 fibril_rwlock_write_unlock(&netif_globals.lock);
    117                 nil_device_state_msg(phone, device_id, result);
    118                 return EOK;
    119         }else{
    120                 fibril_rwlock_write_unlock(&netif_globals.lock);
    121         }
    122         return result;
    123 }
    124 
    125 int netif_stop_req(int netif_phone, device_id_t device_id){
    126         ERROR_DECLARE;
    127 
    128         device_ref device;
    129         int result;
    130         int phone;
    131 
    132         fibril_rwlock_write_lock(&netif_globals.lock);
    133         if(ERROR_OCCURRED(find_device(device_id, &device))){
    134                 fibril_rwlock_write_unlock(&netif_globals.lock);
    135                 return ERROR_CODE;
    136         }
    137         result = netif_stop_message(device);
    138         if(result > NETIF_NULL){
    139                 phone = device->nil_phone;
    140                 fibril_rwlock_write_unlock(&netif_globals.lock);
    141                 nil_device_state_msg(phone, device_id, result);
    142                 return EOK;
    143         }else{
    144                 fibril_rwlock_write_unlock(&netif_globals.lock);
    145         }
    146         return result;
    147 }
    148 
    149 int netif_stats_req(int netif_phone, device_id_t device_id, device_stats_ref stats){
    150         int res;
    151 
    152         fibril_rwlock_read_lock(&netif_globals.lock);
    153         res = netif_get_device_stats(device_id, stats);
    154         fibril_rwlock_read_unlock(&netif_globals.lock);
    155         return res;
    156 }
    157 
    158 int netif_get_addr_req(int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data){
    159         ERROR_DECLARE;
    160 
    161         measured_string_t translation;
    162 
    163         if(!(address && data)){
    164                 return EBADMEM;
    165         }
    166         fibril_rwlock_read_lock(&netif_globals.lock);
    167         if(! ERROR_OCCURRED(netif_get_addr_message(device_id, &translation))){
    168                 *address = measured_string_copy(&translation);
    169                 ERROR_CODE = (*address) ? EOK : ENOMEM;
    170         }
    171         fibril_rwlock_read_unlock(&netif_globals.lock);
    172         *data = (** address).value;
    173         return ERROR_CODE;
    174 }
    175 
    176 int netif_bind_service(services_t service, device_id_t device_id, services_t me, async_client_conn_t receiver){
    177         return EOK;
    178 }
    179 
    180 int find_device(device_id_t device_id, device_ref * device){
    181         if(! device){
    182                 return EBADMEM;
    183         }
    184         *device = device_map_find(&netif_globals.device_map, device_id);
    185         if(! * device){
    186                 return ENOENT;
    187         }
    188         if((** device).state == NETIF_NULL) return EPERM;
    189         return EOK;
    190 }
    191 
    192 void null_device_stats(device_stats_ref stats){
    193         bzero(stats, sizeof(device_stats_t));
    194 }
    195 
    196 int register_message(device_id_t device_id, int phone){
     185static int register_message(device_id_t device_id, int phone){
    197186        ERROR_DECLARE;
    198187
Note: See TracChangeset for help on using the changeset viewer.