Subversion Repositories HelenOS

Rev

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

Rev 4271 Rev 4307
Line 48... Line 48...
48
#include "../structures/packet/packet.h"
48
#include "../structures/packet/packet.h"
49
#include "../structures/packet/packet_client.h"
49
#include "../structures/packet/packet_client.h"
50
#include "../structures/measured_strings.h"
50
#include "../structures/measured_strings.h"
51
 
51
 
52
#include "../include/device.h"
52
#include "../include/device.h"
53
#include "../include/netif_messages.h"
53
#include "../include/netif_interface.h"
54
#include "../include/nil_messages.h"
54
#include "../include/nil_interface.h"
55
 
55
 
56
#include "netif.h"
56
#include "netif.h"
57
#include "netif_interface.h"
57
#include "netif_messages.h"
58
#include "netif_wrappers.h"
58
#include "netif_module.h"
59
 
-
 
60
#if NIL_BUNDLE
-
 
61
 
-
 
62
    #include "../nil/nil_module.h"
-
 
63
 
-
 
64
#endif
-
 
65
 
59
 
66
extern netif_globals_t netif_globals;
60
extern netif_globals_t netif_globals;
67
 
61
 
68
DEVICE_MAP_IMPLEMENT( device_map, device_t )
62
DEVICE_MAP_IMPLEMENT( device_map, device_t )
69
 
63
 
70
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
-
 
71
int netif_start_module( async_client_conn_t client_connection );
-
 
72
int register_message( device_id_t device_id, int phone );
64
int register_message( device_id_t device_id, int phone );
73
 
65
 
74
int netif_probe_wrapper( device_id_t device_id, int irq, int io ){
66
int netif_probe_req( int netif_phone, device_id_t device_id, int irq, int io ){
75
    int result;
67
    int result;
76
 
68
 
77
    rwlock_write_lock( & netif_globals.lock );
69
    rwlock_write_lock( & netif_globals.lock );
78
    result = netif_probe_message( device_id, irq, io );
70
    result = netif_probe_message( device_id, irq, io );
79
    rwlock_write_unlock( & netif_globals.lock );
71
    rwlock_write_unlock( & netif_globals.lock );
80
    return result;
72
    return result;
81
}
73
}
82
 
74
 
83
int netif_send_wrapper( device_id_t device_id, packet_t packet, services_t sender ){
75
int netif_send_msg( int netif_phone, device_id_t device_id, packet_t packet, services_t sender ){
84
    int result;
76
    int result;
85
 
77
 
86
    rwlock_write_lock( & netif_globals.lock );
78
    rwlock_write_lock( & netif_globals.lock );
87
    result = netif_send_message( device_id, packet, sender );
79
    result = netif_send_message( device_id, packet, sender );
88
    rwlock_write_unlock( & netif_globals.lock );
80
    rwlock_write_unlock( & netif_globals.lock );
89
    return result;
81
    return result;
90
}
82
}
91
 
83
 
92
int netif_start_wrapper( device_id_t device_id ){
84
int netif_start_req( int netif_phone, device_id_t device_id ){
93
    ERROR_DECLARE;
85
    ERROR_DECLARE;
94
 
86
 
95
    device_ref  device;
87
    device_ref  device;
96
    int result;
88
    int result;
97
    int phone;
89
    int phone;
Line 111... Line 103...
111
        rwlock_write_unlock( & netif_globals.lock );
103
        rwlock_write_unlock( & netif_globals.lock );
112
    }
104
    }
113
    return result;
105
    return result;
114
}
106
}
115
 
107
 
116
int netif_stop_wrapper( device_id_t device_id ){
108
int netif_stop_req( int netif_phone, device_id_t device_id ){
117
    ERROR_DECLARE;
109
    ERROR_DECLARE;
118
 
110
 
119
    device_ref  device;
111
    device_ref  device;
120
    int result;
112
    int result;
121
    int phone;
113
    int phone;
Line 135... Line 127...
135
        rwlock_write_unlock( & netif_globals.lock );
127
        rwlock_write_unlock( & netif_globals.lock );
136
    }
128
    }
137
    return result;
129
    return result;
138
}
130
}
139
 
131
 
140
int netif_get_addr_wrapper( device_id_t device_id, measured_string_ref * address, char ** data ){
132
int netif_get_addr( int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data ){
141
    ERROR_DECLARE;
133
    ERROR_DECLARE;
142
 
134
 
143
    measured_string_t   translation;
135
    measured_string_t   translation;
144
 
136
 
145
    if( !( address && data )) return EBADMEM;
137
    if( !( address && data )) return EBADMEM;
Line 147... Line 139...
147
    if( ! ERROR_OCCURRED( netif_get_addr_message( device_id, & translation ))){
139
    if( ! ERROR_OCCURRED( netif_get_addr_message( device_id, & translation ))){
148
        * address = measured_string_copy( & translation );
140
        * address = measured_string_copy( & translation );
149
        ERROR_CODE = ( * address ) ? EOK : ENOMEM;
141
        ERROR_CODE = ( * address ) ? EOK : ENOMEM;
150
    }
142
    }
151
    rwlock_read_unlock( & netif_globals.lock );
143
    rwlock_read_unlock( & netif_globals.lock );
-
 
144
    * data = ( ** address ).value;
152
    return ERROR_CODE;
145
    return ERROR_CODE;
153
}
146
}
154
 
147
 
-
 
148
int netif_bind_service( services_t service, device_id_t device_id, services_t me, async_client_conn_t receiver ){
-
 
149
    return EOK;
-
 
150
}
-
 
151
 
155
int find_device( device_id_t device_id, device_ref * device ){
152
int find_device( device_id_t device_id, device_ref * device ){
156
    if( ! device ) return EBADMEM;
153
    if( ! device ) return EBADMEM;
157
    * device = device_map_find( & netif_globals.device_map, device_id );
154
    * device = device_map_find( & netif_globals.device_map, device_id );
158
    if( ! * device ) return ENOENT;
155
    if( ! * device ) return ENOENT;
159
    if(( ** device ).state == NETIF_NULL ) return EPERM;
156
    if(( ** device ).state == NETIF_NULL ) return EPERM;
Line 170... Line 167...
170
    device_ref  device;
167
    device_ref  device;
171
 
168
 
172
    ERROR_PROPAGATE( find_device( device_id, & device ));
169
    ERROR_PROPAGATE( find_device( device_id, & device ));
173
    if( device->nil_phone > 0 ) return ELIMIT;
170
    if( device->nil_phone > 0 ) return ELIMIT;
174
    device->nil_phone = phone;
171
    device->nil_phone = phone;
175
    printf( "\nNew receiver of the device %d registered:\n\tphone\t= %d", device->device_id, device->nil_phone );
172
    printf( "New receiver of the device %d registered:\n\tphone\t= %d\n", device->device_id, device->nil_phone );
176
    return EOK;
173
    return EOK;
177
}
174
}
178
 
175
 
179
int netif_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
176
int netif_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
180
    ERROR_DECLARE;
177
    ERROR_DECLARE;
Line 182... Line 179...
182
    size_t              length;
179
    size_t              length;
183
    device_stats_t      stats;
180
    device_stats_t      stats;
184
    packet_t            packet;
181
    packet_t            packet;
185
    measured_string_t   address;
182
    measured_string_t   address;
186
 
183
 
187
//  printf( "\nmessage %d - %d", IPC_GET_METHOD( * call ), NET_NETIF_FIRST );
184
//  printf( "message %d - %d\n", IPC_GET_METHOD( * call ), NET_NETIF_FIRST );
188
#if NIL_BUNDLE
-
 
189
    if( IS_NET_NIL_MESSAGE( call )){
-
 
190
        return nil_message( callid, call, answer, answer_count );
-
 
191
    }
-
 
192
#endif
-
 
193
    * answer_count = 0;
185
    * answer_count = 0;
194
    switch( IPC_GET_METHOD( * call )){
186
    switch( IPC_GET_METHOD( * call )){
195
        case IPC_M_PHONE_HUNGUP:
187
        case IPC_M_PHONE_HUNGUP:
196
            return EOK;
188
            return EOK;
197
        case NET_NETIF_PROBE_AUTO:
189
        case NET_NETIF_PROBE_AUTO:
198
            rwlock_write_lock( & netif_globals.lock );
190
            rwlock_write_lock( & netif_globals.lock );
199
            ERROR_CODE = netif_probe_auto_message();
191
            ERROR_CODE = netif_probe_auto_message();
200
            rwlock_write_unlock( & netif_globals.lock );
192
            rwlock_write_unlock( & netif_globals.lock );
201
            return ERROR_CODE;
193
            return ERROR_CODE;
202
        case NET_NETIF_PROBE:
194
        case NET_NETIF_PROBE:
203
            return netif_probe_wrapper( IPC_GET_DEVICE( call ), NETIF_GET_IRQ( call ), NETIF_GET_IO( call ));
195
            return netif_probe_req( 0, IPC_GET_DEVICE( call ), NETIF_GET_IRQ( call ), NETIF_GET_IO( call ));
204
        case IPC_M_CONNECT_TO_ME:
196
        case IPC_M_CONNECT_TO_ME:
205
#if NIL_BUNDLE
-
 
206
            return nil_register_message( NIL_GET_PROTO( call ), IPC_GET_PHONE( call ));
-
 
207
#else
-
 
208
            rwlock_write_lock( & netif_globals.lock );
197
            rwlock_write_lock( & netif_globals.lock );
209
            ERROR_CODE = register_message( IPC_GET_DEVICE( call ), IPC_GET_PHONE( call ));
198
            ERROR_CODE = register_message( IPC_GET_DEVICE( call ), IPC_GET_PHONE( call ));
210
            rwlock_write_unlock( & netif_globals.lock );
199
            rwlock_write_unlock( & netif_globals.lock );
211
            return ERROR_CODE;
200
            return ERROR_CODE;
212
#endif
-
 
213
        case NET_NETIF_SEND:
201
        case NET_NETIF_SEND:
214
        case NET_NIL_SEND:
202
        case NET_NIL_SEND:
215
            ERROR_PROPAGATE( packet_translate( netif_globals.networking_phone, & packet, IPC_GET_PACKET( call )));
203
            ERROR_PROPAGATE( packet_translate( netif_globals.net_phone, & packet, IPC_GET_PACKET( call )));
216
            return netif_send_wrapper( IPC_GET_DEVICE( call ), packet, IPC_GET_SENDER( call ));
204
            return netif_send_msg( 0, IPC_GET_DEVICE( call ), packet, IPC_GET_SENDER( call ));
217
        case NET_NETIF_START:
205
        case NET_NETIF_START:
218
            return netif_start_wrapper( IPC_GET_DEVICE( call ));
206
            return netif_start_req( 0, IPC_GET_DEVICE( call ));
219
        case NET_NETIF_STATS:
207
        case NET_NETIF_STATS:
220
            rwlock_read_lock( & netif_globals.lock );
208
            rwlock_read_lock( & netif_globals.lock );
221
            if( ! ERROR_OCCURRED( ipc_data_read_receive( & callid, & length ))){
209
            if( ! ERROR_OCCURRED( ipc_data_read_receive( & callid, & length ))){
222
                if( length < sizeof( device_stats_t )){
210
                if( length < sizeof( device_stats_t )){
223
                    ERROR_CODE = EOVERFLOW;
211
                    ERROR_CODE = EOVERFLOW;
Line 228... Line 216...
228
                }
216
                }
229
            }
217
            }
230
            rwlock_read_unlock( & netif_globals.lock );
218
            rwlock_read_unlock( & netif_globals.lock );
231
            return ERROR_CODE;
219
            return ERROR_CODE;
232
        case NET_NETIF_STOP:
220
        case NET_NETIF_STOP:
233
            return netif_stop_wrapper( IPC_GET_DEVICE( call ));
221
            return netif_stop_req( 0, IPC_GET_DEVICE( call ));
234
        case NET_NETIF_GET_ADDR:
222
        case NET_NETIF_GET_ADDR:
235
        case NET_NIL_ADDR:
223
        case NET_NIL_ADDR:
236
            rwlock_read_lock( & netif_globals.lock );
224
            rwlock_read_lock( & netif_globals.lock );
237
            if( ! ERROR_OCCURRED( netif_get_addr_message( IPC_GET_DEVICE( call ), & address ))){
225
            if( ! ERROR_OCCURRED( netif_get_addr_message( IPC_GET_DEVICE( call ), & address ))){
238
                ERROR_CODE = measured_strings_reply( & address, 1 );
226
                ERROR_CODE = measured_strings_reply( & address, 1 );
Line 241... Line 229...
241
            return ERROR_CODE;
229
            return ERROR_CODE;
242
    }
230
    }
243
    return netif_specific_message( callid, call, answer, answer_count );
231
    return netif_specific_message( callid, call, answer, answer_count );
244
}
232
}
245
 
233
 
246
int netif_start_module( async_client_conn_t client_connection ){
234
int netif_init_module( async_client_conn_t client_connection ){
247
    ERROR_DECLARE;
235
    ERROR_DECLARE;
248
 
236
 
249
    async_set_client_connection( client_connection );
237
    async_set_client_connection( client_connection );
250
    netif_globals.networking_phone = connect_to_service( SERVICE_NETWORKING );
238
    netif_globals.net_phone = connect_to_service( SERVICE_NETWORKING );
251
    device_map_initialize( & netif_globals.device_map );
239
    device_map_initialize( & netif_globals.device_map );
252
    ERROR_PROPAGATE( pm_init());
240
    ERROR_PROPAGATE( pm_init());
253
    rwlock_initialize( & netif_globals.lock );
241
    rwlock_initialize( & netif_globals.lock );
254
    if( ERROR_OCCURRED( netif_initialize())){
242
    if( ERROR_OCCURRED( netif_initialize())){
255
        pm_destroy();
243
        pm_destroy();
256
        return ERROR_CODE;
244
        return ERROR_CODE;
257
    }
245
    }
258
#if NIL_BUNDLE
-
 
259
    if( ERROR_OCCURRED( nil_initialize( netif_globals.networking_phone ))){
-
 
260
        pm_destroy();
-
 
261
        return ERROR_CODE;
246
    return EOK;
262
    }
247
}
263
#endif
-
 
264
 
248
 
-
 
249
int netif_run_module( void ){
265
    async_manager();
250
    async_manager();
266
 
251
 
267
    pm_destroy();
252
    pm_destroy();
268
    return EOK;
253
    return EOK;
269
}
254
}
270
 
255
 
271
void netif_pq_release( packet_id_t packet_id ){
256
void netif_pq_release( packet_id_t packet_id ){
272
    pq_release( netif_globals.networking_phone, packet_id );
257
    pq_release( netif_globals.net_phone, packet_id );
273
}
258
}
274
 
259
 
275
packet_t netif_packet_get_1( size_t content ){
260
packet_t netif_packet_get_1( size_t content ){
276
    return packet_get_1( netif_globals.networking_phone, content );
261
    return packet_get_1( netif_globals.net_phone, content );
277
}
262
}
278
 
263
 
279
/** @}
264
/** @}
280
 */
265
 */