Changeset 71b00dcc in mainline for uspace/srv/net/netif/netif.c


Ignore:
Timestamp:
2010-03-07T22:51:38Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
60ab6c3
Parents:
b5cbff4 (diff), 31c80a5 (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 from lp:~lukasmejdrech/helenos/network.

File:
1 edited

Legend:

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

    rb5cbff4 r71b00dcc  
    6464extern netif_globals_t netif_globals;
    6565
    66 DEVICE_MAP_IMPLEMENT( device_map, device_t )
     66DEVICE_MAP_IMPLEMENT(device_map, device_t)
    6767
    6868/** @name Message processing functions
     
    7777 *  @returns ELIMIT if there is another module registered.
    7878 */
    79 int     register_message( device_id_t device_id, int phone );
     79int register_message(device_id_t device_id, int phone);
    8080
    8181/*@}*/
    8282
    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 );
     83int 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
     92int 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
     101int 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);
    111111                return ERROR_CODE;
    112112        }
    113         result = netif_start_message( device );
    114         if( result > NETIF_NULL ){
     113        result = netif_start_message(device);
     114        if(result > NETIF_NULL){
    115115                phone = device->nil_phone;
    116                 fibril_rwlock_write_unlock( & netif_globals.lock );
    117                 nil_device_state_msg( phone, device_id, result );
     116                fibril_rwlock_write_unlock(&netif_globals.lock);
     117                nil_device_state_msg(phone, device_id, result);
    118118                return EOK;
    119119        }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 );
     120                fibril_rwlock_write_unlock(&netif_globals.lock);
     121        }
     122        return result;
     123}
     124
     125int 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);
    135135                return ERROR_CODE;
    136136        }
    137         result = netif_stop_message( device );
    138         if( result > NETIF_NULL ){
     137        result = netif_stop_message(device);
     138        if(result > NETIF_NULL){
    139139                phone = device->nil_phone;
    140                 fibril_rwlock_write_unlock( & netif_globals.lock );
    141                 nil_device_state_msg( phone, device_id, result );
     140                fibril_rwlock_write_unlock(&netif_globals.lock);
     141                nil_device_state_msg(phone, device_id, result);
    142142                return EOK;
    143143        }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 ){
     144                fibril_rwlock_write_unlock(&netif_globals.lock);
     145        }
     146        return result;
     147}
     148
     149int netif_stats_req(int netif_phone, device_id_t device_id, device_stats_ref stats){
    150150        int res;
    151151
    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 );
     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);
    155155        return res;
    156156}
    157157
    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 )) return EBADMEM;
    164         fibril_rwlock_read_lock( & netif_globals.lock );
    165         if( ! ERROR_OCCURRED( netif_get_addr_message( device_id, & translation ))){
    166                 * address = measured_string_copy( & translation );
    167                 ERROR_CODE = ( * address ) ? EOK : ENOMEM;
    168         }
    169         fibril_rwlock_read_unlock( & netif_globals.lock );
    170         * data = ( ** address ).value;
     158int 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;
    171173        return ERROR_CODE;
    172174}
    173175
    174 int netif_bind_service( services_t service, device_id_t device_id, services_t me, async_client_conn_t receiver ){
    175         return EOK;
    176 }
    177 
    178 int find_device( device_id_t device_id, device_ref * device ){
    179         if( ! device ) return EBADMEM;
    180         * device = device_map_find( & netif_globals.device_map, device_id );
    181         if( ! * device ) return ENOENT;
    182         if(( ** device ).state == NETIF_NULL ) return EPERM;
    183         return EOK;
    184 }
    185 
    186 void null_device_stats( device_stats_ref stats ){
    187         bzero( stats, sizeof( device_stats_t ));
    188 }
    189 
    190 int register_message( device_id_t device_id, int phone ){
    191         ERROR_DECLARE;
    192 
    193         device_ref      device;
    194 
    195         ERROR_PROPAGATE( find_device( device_id, & device ));
    196         if( device->nil_phone > 0 ) return ELIMIT;
     176int netif_bind_service(services_t service, device_id_t device_id, services_t me, async_client_conn_t receiver){
     177        return EOK;
     178}
     179
     180int 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
     192void null_device_stats(device_stats_ref stats){
     193        bzero(stats, sizeof(device_stats_t));
     194}
     195
     196int register_message(device_id_t device_id, int phone){
     197        ERROR_DECLARE;
     198
     199        device_ref device;
     200
     201        ERROR_PROPAGATE(find_device(device_id, &device));
     202        if(device->nil_phone > 0){
     203                return ELIMIT;
     204        }
    197205        device->nil_phone = phone;
    198         printf( "New receiver of the device %d registered:\n\tphone\t= %d\n", device->device_id, device->nil_phone );
    199         return EOK;
    200 }
    201 
    202 int netif_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
    203         ERROR_DECLARE;
    204 
    205         size_t                          length;
    206         device_stats_t          stats;
    207         packet_t                        packet;
    208         measured_string_t       address;
    209 
    210 //      printf( "message %d - %d\n", IPC_GET_METHOD( * call ), NET_NETIF_FIRST );
    211         * answer_count = 0;
    212         switch( IPC_GET_METHOD( * call )){
     206        printf("New receiver of the device %d registered:\n\tphone\t= %d\n", device->device_id, device->nil_phone);
     207        return EOK;
     208}
     209
     210int netif_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
     211        ERROR_DECLARE;
     212
     213        size_t length;
     214        device_stats_t stats;
     215        packet_t packet;
     216        measured_string_t address;
     217
     218//      printf("message %d - %d\n", IPC_GET_METHOD(*call), NET_NETIF_FIRST);
     219        *answer_count = 0;
     220        switch(IPC_GET_METHOD(*call)){
    213221                case IPC_M_PHONE_HUNGUP:
    214222                        return EOK;
    215223                case NET_NETIF_PROBE:
    216                         return netif_probe_req( 0, IPC_GET_DEVICE( call ), NETIF_GET_IRQ( call ), NETIF_GET_IO( call ));
     224                        return netif_probe_req(0, IPC_GET_DEVICE(call), NETIF_GET_IRQ(call), NETIF_GET_IO(call));
    217225                case IPC_M_CONNECT_TO_ME:
    218                         fibril_rwlock_write_lock( & netif_globals.lock );
    219                         ERROR_CODE = register_message( IPC_GET_DEVICE( call ), IPC_GET_PHONE( call ));
    220                         fibril_rwlock_write_unlock( & netif_globals.lock );
     226                        fibril_rwlock_write_lock(&netif_globals.lock);
     227                        ERROR_CODE = register_message(IPC_GET_DEVICE(call), IPC_GET_PHONE(call));
     228                        fibril_rwlock_write_unlock(&netif_globals.lock);
    221229                        return ERROR_CODE;
    222230                case NET_NETIF_SEND:
    223                         ERROR_PROPAGATE( packet_translate( netif_globals.net_phone, & packet, IPC_GET_PACKET( call )));
    224                         return netif_send_msg( 0, IPC_GET_DEVICE( call ), packet, IPC_GET_SENDER( call ));
     231                        ERROR_PROPAGATE(packet_translate(netif_globals.net_phone, &packet, IPC_GET_PACKET(call)));
     232                        return netif_send_msg(0, IPC_GET_DEVICE(call), packet, IPC_GET_SENDER(call));
    225233                case NET_NETIF_START:
    226                         return netif_start_req( 0, IPC_GET_DEVICE( call ));
     234                        return netif_start_req(0, IPC_GET_DEVICE(call));
    227235                case NET_NETIF_STATS:
    228                         fibril_rwlock_read_lock( & netif_globals.lock );
    229                         if( ! ERROR_OCCURRED( async_data_read_receive( & callid, & length ))){
    230                                 if( length < sizeof( device_stats_t )){
     236                        fibril_rwlock_read_lock(&netif_globals.lock);
     237                        if(! ERROR_OCCURRED(async_data_read_receive(&callid, &length))){
     238                                if(length < sizeof(device_stats_t)){
    231239                                        ERROR_CODE = EOVERFLOW;
    232240                                }else{
    233                                         if( ! ERROR_OCCURRED( netif_get_device_stats( IPC_GET_DEVICE( call ), & stats ))){
    234                                                 ERROR_CODE = async_data_read_finalize( callid, & stats, sizeof( device_stats_t ));
     241                                        if(! ERROR_OCCURRED(netif_get_device_stats(IPC_GET_DEVICE(call), &stats))){
     242                                                ERROR_CODE = async_data_read_finalize(callid, &stats, sizeof(device_stats_t));
    235243                                        }
    236244                                }
    237245                        }
    238                         fibril_rwlock_read_unlock( & netif_globals.lock );
     246                        fibril_rwlock_read_unlock(&netif_globals.lock);
    239247                        return ERROR_CODE;
    240248                case NET_NETIF_STOP:
    241                         return netif_stop_req( 0, IPC_GET_DEVICE( call ));
     249                        return netif_stop_req(0, IPC_GET_DEVICE(call));
    242250                case NET_NETIF_GET_ADDR:
    243                         fibril_rwlock_read_lock( & netif_globals.lock );
    244                         if( ! ERROR_OCCURRED( netif_get_addr_message( IPC_GET_DEVICE( call ), & address ))){
    245                                 ERROR_CODE = measured_strings_reply( & address, 1 );
     251                        fibril_rwlock_read_lock(&netif_globals.lock);
     252                        if(! ERROR_OCCURRED(netif_get_addr_message(IPC_GET_DEVICE(call), &address))){
     253                                ERROR_CODE = measured_strings_reply(&address, 1);
    246254                        }
    247                         fibril_rwlock_read_unlock( & netif_globals.lock );
     255                        fibril_rwlock_read_unlock(&netif_globals.lock);
    248256                        return ERROR_CODE;
    249257        }
    250         return netif_specific_message( callid, call, answer, answer_count );
    251 }
    252 
    253 int netif_init_module( async_client_conn_t client_connection ){
    254         ERROR_DECLARE;
    255 
    256         async_set_client_connection( client_connection );
    257         netif_globals.net_phone = connect_to_service( SERVICE_NETWORKING );
    258         device_map_initialize( & netif_globals.device_map );
    259         ERROR_PROPAGATE( pm_init());
    260         fibril_rwlock_initialize( & netif_globals.lock );
    261         if( ERROR_OCCURRED( netif_initialize())){
     258        return netif_specific_message(callid, call, answer, answer_count);
     259}
     260
     261int netif_init_module(async_client_conn_t client_connection){
     262        ERROR_DECLARE;
     263
     264        async_set_client_connection(client_connection);
     265        netif_globals.net_phone = connect_to_service(SERVICE_NETWORKING);
     266        device_map_initialize(&netif_globals.device_map);
     267        ERROR_PROPAGATE(pm_init());
     268        fibril_rwlock_initialize(&netif_globals.lock);
     269        if(ERROR_OCCURRED(netif_initialize())){
    262270                pm_destroy();
    263271                return ERROR_CODE;
     
    266274}
    267275
    268 int netif_run_module( void ){
     276int netif_run_module(void){
    269277        async_manager();
    270278
     
    273281}
    274282
    275 void netif_pq_release( packet_id_t packet_id ){
    276         pq_release( netif_globals.net_phone, packet_id );
    277 }
    278 
    279 packet_t netif_packet_get_1( size_t content ){
    280         return packet_get_1( netif_globals.net_phone, content );
     283void netif_pq_release(packet_id_t packet_id){
     284        pq_release(netif_globals.net_phone, packet_id);
     285}
     286
     287packet_t netif_packet_get_1(size_t content){
     288        return packet_get_1(netif_globals.net_phone, content);
    281289}
    282290
Note: See TracChangeset for help on using the changeset viewer.