Subversion Repositories HelenOS

Rev

Rev 4350 | Rev 4698 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4350 Rev 4582
Line 35... Line 35...
35
 *  @see netif.h
35
 *  @see netif.h
36
 */
36
 */
37
 
37
 
38
#include <async.h>
38
#include <async.h>
39
#include <mem.h>
39
#include <mem.h>
40
#include <rwlock.h>
40
#include <fibril_sync.h>
41
#include <stdio.h>
41
#include <stdio.h>
42
 
42
 
43
#include <ipc/ipc.h>
43
#include <ipc/ipc.h>
44
#include <ipc/services.h>
44
#include <ipc/services.h>
45
 
45
 
Line 75... Line 75...
75
int register_message( device_id_t device_id, int phone );
75
int register_message( device_id_t device_id, int phone );
76
 
76
 
77
int netif_probe_req( int netif_phone, device_id_t device_id, int irq, int io ){
77
int netif_probe_req( int netif_phone, device_id_t device_id, int irq, int io ){
78
    int result;
78
    int result;
79
 
79
 
80
    rwlock_write_lock( & netif_globals.lock );
80
    fibril_rwlock_write_lock( & netif_globals.lock );
81
    result = netif_probe_message( device_id, irq, io );
81
    result = netif_probe_message( device_id, irq, io );
82
    rwlock_write_unlock( & netif_globals.lock );
82
    fibril_rwlock_write_unlock( & netif_globals.lock );
83
    return result;
83
    return result;
84
}
84
}
85
 
85
 
86
int netif_send_msg( int netif_phone, device_id_t device_id, packet_t packet, services_t sender ){
86
int netif_send_msg( int netif_phone, device_id_t device_id, packet_t packet, services_t sender ){
87
    int result;
87
    int result;
88
 
88
 
89
    rwlock_write_lock( & netif_globals.lock );
89
    fibril_rwlock_write_lock( & netif_globals.lock );
90
    result = netif_send_message( device_id, packet, sender );
90
    result = netif_send_message( device_id, packet, sender );
91
    rwlock_write_unlock( & netif_globals.lock );
91
    fibril_rwlock_write_unlock( & netif_globals.lock );
92
    return result;
92
    return result;
93
}
93
}
94
 
94
 
95
int netif_start_req( int netif_phone, device_id_t device_id ){
95
int netif_start_req( int netif_phone, device_id_t device_id ){
96
    ERROR_DECLARE;
96
    ERROR_DECLARE;
97
 
97
 
98
    device_ref  device;
98
    device_ref  device;
99
    int result;
99
    int result;
100
    int phone;
100
    int phone;
101
 
101
 
102
    rwlock_write_lock( & netif_globals.lock );
102
    fibril_rwlock_write_lock( & netif_globals.lock );
103
    if( ERROR_OCCURRED( find_device( device_id, & device ))){
103
    if( ERROR_OCCURRED( find_device( device_id, & device ))){
104
        rwlock_write_unlock( & netif_globals.lock );
104
        fibril_rwlock_write_unlock( & netif_globals.lock );
105
        return ERROR_CODE;
105
        return ERROR_CODE;
106
    }
106
    }
107
    result = netif_start_message( device );
107
    result = netif_start_message( device );
108
    if( result > NETIF_NULL ){
108
    if( result > NETIF_NULL ){
109
        phone = device->nil_phone;
109
        phone = device->nil_phone;
110
        rwlock_write_unlock( & netif_globals.lock );
110
        fibril_rwlock_write_unlock( & netif_globals.lock );
111
        nil_device_state_msg( phone, device_id, result );
111
        nil_device_state_msg( phone, device_id, result );
112
        return EOK;
112
        return EOK;
113
    }else{
113
    }else{
114
        rwlock_write_unlock( & netif_globals.lock );
114
        fibril_rwlock_write_unlock( & netif_globals.lock );
115
    }
115
    }
116
    return result;
116
    return result;
117
}
117
}
118
 
118
 
119
int netif_stop_req( int netif_phone, device_id_t device_id ){
119
int netif_stop_req( int netif_phone, device_id_t device_id ){
Line 121... Line 121...
121
 
121
 
122
    device_ref  device;
122
    device_ref  device;
123
    int result;
123
    int result;
124
    int phone;
124
    int phone;
125
 
125
 
126
    rwlock_write_lock( & netif_globals.lock );
126
    fibril_rwlock_write_lock( & netif_globals.lock );
127
    if( ERROR_OCCURRED( find_device( device_id, & device ))){
127
    if( ERROR_OCCURRED( find_device( device_id, & device ))){
128
        rwlock_write_unlock( & netif_globals.lock );
128
        fibril_rwlock_write_unlock( & netif_globals.lock );
129
        return ERROR_CODE;
129
        return ERROR_CODE;
130
    }
130
    }
131
    result = netif_stop_message( device );
131
    result = netif_stop_message( device );
132
    if( result > NETIF_NULL ){
132
    if( result > NETIF_NULL ){
133
        phone = device->nil_phone;
133
        phone = device->nil_phone;
134
        rwlock_write_unlock( & netif_globals.lock );
134
        fibril_rwlock_write_unlock( & netif_globals.lock );
135
        nil_device_state_msg( phone, device_id, result );
135
        nil_device_state_msg( phone, device_id, result );
136
        return EOK;
136
        return EOK;
137
    }else{
137
    }else{
138
        rwlock_write_unlock( & netif_globals.lock );
138
        fibril_rwlock_write_unlock( & netif_globals.lock );
139
    }
139
    }
140
    return result;
140
    return result;
141
}
141
}
142
 
142
 
143
int netif_get_addr( int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data ){
143
int netif_get_addr( int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data ){
144
    ERROR_DECLARE;
144
    ERROR_DECLARE;
145
 
145
 
146
    measured_string_t   translation;
146
    measured_string_t   translation;
147
 
147
 
148
    if( !( address && data )) return EBADMEM;
148
    if( !( address && data )) return EBADMEM;
149
    rwlock_read_lock( & netif_globals.lock );
149
    fibril_rwlock_read_lock( & netif_globals.lock );
150
    if( ! ERROR_OCCURRED( netif_get_addr_message( device_id, & translation ))){
150
    if( ! ERROR_OCCURRED( netif_get_addr_message( device_id, & translation ))){
151
        * address = measured_string_copy( & translation );
151
        * address = measured_string_copy( & translation );
152
        ERROR_CODE = ( * address ) ? EOK : ENOMEM;
152
        ERROR_CODE = ( * address ) ? EOK : ENOMEM;
153
    }
153
    }
154
    rwlock_read_unlock( & netif_globals.lock );
154
    fibril_rwlock_read_unlock( & netif_globals.lock );
155
    * data = ( ** address ).value;
155
    * data = ( ** address ).value;
156
    return ERROR_CODE;
156
    return ERROR_CODE;
157
}
157
}
158
 
158
 
159
int netif_bind_service( services_t service, device_id_t device_id, services_t me, async_client_conn_t receiver ){
159
int netif_bind_service( services_t service, device_id_t device_id, services_t me, async_client_conn_t receiver ){
Line 196... Line 196...
196
    * answer_count = 0;
196
    * answer_count = 0;
197
    switch( IPC_GET_METHOD( * call )){
197
    switch( IPC_GET_METHOD( * call )){
198
        case IPC_M_PHONE_HUNGUP:
198
        case IPC_M_PHONE_HUNGUP:
199
            return EOK;
199
            return EOK;
200
        case NET_NETIF_PROBE_AUTO:
200
        case NET_NETIF_PROBE_AUTO:
201
            rwlock_write_lock( & netif_globals.lock );
201
            fibril_rwlock_write_lock( & netif_globals.lock );
202
            ERROR_CODE = netif_probe_auto_message();
202
            ERROR_CODE = netif_probe_auto_message();
203
            rwlock_write_unlock( & netif_globals.lock );
203
            fibril_rwlock_write_unlock( & netif_globals.lock );
204
            return ERROR_CODE;
204
            return ERROR_CODE;
205
        case NET_NETIF_PROBE:
205
        case NET_NETIF_PROBE:
206
            return netif_probe_req( 0, IPC_GET_DEVICE( call ), NETIF_GET_IRQ( call ), NETIF_GET_IO( call ));
206
            return netif_probe_req( 0, IPC_GET_DEVICE( call ), NETIF_GET_IRQ( call ), NETIF_GET_IO( call ));
207
        case IPC_M_CONNECT_TO_ME:
207
        case IPC_M_CONNECT_TO_ME:
208
            rwlock_write_lock( & netif_globals.lock );
208
            fibril_rwlock_write_lock( & netif_globals.lock );
209
            ERROR_CODE = register_message( IPC_GET_DEVICE( call ), IPC_GET_PHONE( call ));
209
            ERROR_CODE = register_message( IPC_GET_DEVICE( call ), IPC_GET_PHONE( call ));
210
            rwlock_write_unlock( & netif_globals.lock );
210
            fibril_rwlock_write_unlock( & netif_globals.lock );
211
            return ERROR_CODE;
211
            return ERROR_CODE;
212
        case NET_NETIF_SEND:
212
        case NET_NETIF_SEND:
213
        case NET_NIL_SEND:
213
        case NET_NIL_SEND:
214
            ERROR_PROPAGATE( packet_translate( netif_globals.net_phone, & packet, IPC_GET_PACKET( call )));
214
            ERROR_PROPAGATE( packet_translate( netif_globals.net_phone, & packet, IPC_GET_PACKET( call )));
215
            return netif_send_msg( 0, IPC_GET_DEVICE( call ), packet, IPC_GET_SENDER( call ));
215
            return netif_send_msg( 0, IPC_GET_DEVICE( call ), packet, IPC_GET_SENDER( call ));
216
        case NET_NETIF_START:
216
        case NET_NETIF_START:
217
            return netif_start_req( 0, IPC_GET_DEVICE( call ));
217
            return netif_start_req( 0, IPC_GET_DEVICE( call ));
218
        case NET_NETIF_STATS:
218
        case NET_NETIF_STATS:
219
            rwlock_read_lock( & netif_globals.lock );
219
            fibril_rwlock_read_lock( & netif_globals.lock );
220
            if( ! ERROR_OCCURRED( ipc_data_read_receive( & callid, & length ))){
220
            if( ! ERROR_OCCURRED( ipc_data_read_receive( & callid, & length ))){
221
                if( length < sizeof( device_stats_t )){
221
                if( length < sizeof( device_stats_t )){
222
                    ERROR_CODE = EOVERFLOW;
222
                    ERROR_CODE = EOVERFLOW;
223
                }else{
223
                }else{
224
                    if( ! ERROR_OCCURRED( netif_get_device_stats( IPC_GET_DEVICE( call ), & stats ))){
224
                    if( ! ERROR_OCCURRED( netif_get_device_stats( IPC_GET_DEVICE( call ), & stats ))){
225
                        ERROR_CODE = ipc_data_read_finalize( callid, & stats, sizeof( device_stats_t ));
225
                        ERROR_CODE = ipc_data_read_finalize( callid, & stats, sizeof( device_stats_t ));
226
                    }
226
                    }
227
                }
227
                }
228
            }
228
            }
229
            rwlock_read_unlock( & netif_globals.lock );
229
            fibril_rwlock_read_unlock( & netif_globals.lock );
230
            return ERROR_CODE;
230
            return ERROR_CODE;
231
        case NET_NETIF_STOP:
231
        case NET_NETIF_STOP:
232
            return netif_stop_req( 0, IPC_GET_DEVICE( call ));
232
            return netif_stop_req( 0, IPC_GET_DEVICE( call ));
233
        case NET_NETIF_GET_ADDR:
233
        case NET_NETIF_GET_ADDR:
234
        case NET_NIL_ADDR:
234
        case NET_NIL_ADDR:
235
            rwlock_read_lock( & netif_globals.lock );
235
            fibril_rwlock_read_lock( & netif_globals.lock );
236
            if( ! ERROR_OCCURRED( netif_get_addr_message( IPC_GET_DEVICE( call ), & address ))){
236
            if( ! ERROR_OCCURRED( netif_get_addr_message( IPC_GET_DEVICE( call ), & address ))){
237
                ERROR_CODE = measured_strings_reply( & address, 1 );
237
                ERROR_CODE = measured_strings_reply( & address, 1 );
238
            }
238
            }
239
            rwlock_read_unlock( & netif_globals.lock );
239
            fibril_rwlock_read_unlock( & netif_globals.lock );
240
            return ERROR_CODE;
240
            return ERROR_CODE;
241
    }
241
    }
242
    return netif_specific_message( callid, call, answer, answer_count );
242
    return netif_specific_message( callid, call, answer, answer_count );
243
}
243
}
244
 
244
 
Line 247... Line 247...
247
 
247
 
248
    async_set_client_connection( client_connection );
248
    async_set_client_connection( client_connection );
249
    netif_globals.net_phone = connect_to_service( SERVICE_NETWORKING );
249
    netif_globals.net_phone = connect_to_service( SERVICE_NETWORKING );
250
    device_map_initialize( & netif_globals.device_map );
250
    device_map_initialize( & netif_globals.device_map );
251
    ERROR_PROPAGATE( pm_init());
251
    ERROR_PROPAGATE( pm_init());
252
    rwlock_initialize( & netif_globals.lock );
252
    fibril_rwlock_initialize( & netif_globals.lock );
253
    if( ERROR_OCCURRED( netif_initialize())){
253
    if( ERROR_OCCURRED( netif_initialize())){
254
        pm_destroy();
254
        pm_destroy();
255
        return ERROR_CODE;
255
        return ERROR_CODE;
256
    }
256
    }
257
    return EOK;
257
    return EOK;