Subversion Repositories HelenOS

Rev

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

Rev 3886 Rev 3901
Line 50... Line 50...
50
//#include "../self_test.h"
50
//#include "../self_test.h"
51
 
51
 
52
#include "../structures/char_map.h"
52
#include "../structures/char_map.h"
53
#include "../structures/generic_char_map.h"
53
#include "../structures/generic_char_map.h"
54
#include "../structures/measured_strings.h"
54
#include "../structures/measured_strings.h"
-
 
55
#include "../structures/packet/packet.h"
-
 
56
#include "../structures/packet/packet_server.h"
55
 
57
 
56
#include "../il/ip/ip_messages.h"
58
#include "../il/ip/ip_messages.h"
57
#include "../netif/device.h"
59
#include "../netif/device.h"
58
 
60
 
59
#if IP_BUNDLE
61
#if IP_BUNDLE
Line 66... Line 68...
66
 
68
 
67
    #include "../tcp/tcp_module.h"
69
    #include "../tcp/tcp_module.h"
68
 
70
 
69
#endif
71
#endif
70
 
72
 
-
 
73
#define NAME    "Networking"
-
 
74
 
71
#define LO_NAME             "lo"
75
#define LO_NAME             "lo"
72
#define LO_FILENAME         "/sbin/lo"
76
#define LO_FILENAME         "/sbin/lo"
73
#define DP8390_ISA_NAME         "dp8390_isa"
77
#define DP8390_ISA_NAME         "dp8390_isa"
74
#define DP8390_ISA_FILENAME     "/sbin/dp8380_isa"
78
#define DP8390_ISA_FILENAME     "/sbin/dp8380_isa"
75
#define ETHERNET_NAME           "ethernet"
79
#define ETHERNET_NAME           "ethernet"
76
#define ETHERNET_FILENAME       "/sbin/ethernet"
80
#define ETHERNET_FILENAME       "/sbin/ethernet"
77
#define IP_NAME             "ip"
81
#define IP_NAME             "ip"
78
#define IP_FILENAME         "/sbin/ip"
82
#define IP_FILENAME         "/sbin/ip"
79
 
83
 
-
 
84
#define IPC_GET_DEVICE( call )  ( device_id_t ) IPC_GET_ARG1( * call )
-
 
85
#define IPC_GET_COUNT( call )   ( int ) IPC_GET_ARG2( * call )
-
 
86
 
80
typedef struct module_struct    module_t;
87
typedef struct module_struct    module_t;
81
typedef module_t *      module_ref;
88
typedef module_t *      module_ref;
82
 
89
 
83
typedef struct netif        netif_t;
90
typedef struct netif        netif_t;
84
typedef netif_t *       netif_ref;
91
typedef netif_t *       netif_ref;
Line 138... Line 145...
138
    /** Global configuration.
145
    /** Global configuration.
139
     */
146
     */
140
    measured_strings_t  configuration;
147
    measured_strings_t  configuration;
141
};
148
};
142
 
149
 
-
 
150
void    networking_print_name( void );
143
int     add_module( module_ref * module, modules_ref modules, const char const * name, const char const * filename, services_t service, task_id_t task_id );
151
int     add_module( module_ref * module, modules_ref modules, const char const * name, const char const * filename, services_t service, task_id_t task_id );
144
static void client_connection( ipc_callid_t iid, ipc_call_t * icall );
152
static void client_connection( ipc_callid_t iid, ipc_call_t * icall );
145
measured_string_ref configuration_find( measured_strings_ref configuration, const char * name );
153
measured_string_ref configuration_find( measured_strings_ref configuration, const char * name );
146
int     main( int argc, char * argv[] );
154
int networking_start_module( async_client_conn_t client_connection );
147
int     networking_initialize( void );
155
int     networking_initialize( void );
148
int     networking_message( ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 );
156
int networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
-
 
157
int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count );
149
//int       parse_line( measured_strings_ref configuration, char * line );
158
//int       parse_line( measured_strings_ref configuration, char * line );
150
int     add_configuration( measured_strings_ref configuration, const char * name, const char * value );
159
int     add_configuration( measured_strings_ref configuration, const char * name, const char * value );
151
int     read_configuration( void );
160
int     read_configuration( void );
152
task_id_t   spawn( const char * fname );
161
task_id_t   spawn( const char * fname );
153
int     startup( void );
162
int     startup( void );
Line 159... Line 168...
159
 
168
 
160
GENERIC_CHAR_MAP_IMPLEMENT( measured_strings, measured_string_t )
169
GENERIC_CHAR_MAP_IMPLEMENT( measured_strings, measured_string_t )
161
 
170
 
162
GENERIC_CHAR_MAP_IMPLEMENT( modules, module_t )
171
GENERIC_CHAR_MAP_IMPLEMENT( modules, module_t )
163
 
172
 
-
 
173
void networking_print_name( void ){
-
 
174
    printf( NAME );
-
 
175
}
-
 
176
 
164
int add_module( module_ref * module, modules_ref modules, const char * name, const char * filename, services_t service, task_id_t task_id ){
177
int add_module( module_ref * module, modules_ref modules, const char * name, const char * filename, services_t service, task_id_t task_id ){
165
    ERROR_DECLARE;
178
    ERROR_DECLARE;
166
 
179
 
167
    module_ref  tmp_module;
180
    module_ref  tmp_module;
168
 
181
 
Line 180... Line 193...
180
    }
193
    }
181
    if( module ) * module = tmp_module;
194
    if( module ) * module = tmp_module;
182
    return EOK;
195
    return EOK;
183
}
196
}
184
 
197
 
185
static void client_connection( ipc_callid_t iid, ipc_call_t * icall ){
198
int networking_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
186
    ipc_callid_t    callid;
-
 
187
    ipc_call_t  call;
-
 
188
    ipcarg_t    arg1, arg2, arg3;
-
 
189
    int     res;
-
 
190
 
-
 
191
    /*
-
 
192
     * Accept the connection
-
 
193
     *  - Answer the first IPC_M_CONNECT_ME_TO call.
-
 
194
     */
-
 
195
//  printf( "\nNET-%d got %d on %x from %x", fibril_get_id(), IPC_GET_METHOD( * icall ), icall->in_phone_hash, iid );
-
 
196
    ipc_answer_0( iid, EOK );
-
 
197
 
-
 
198
    while( true ){
-
 
199
        callid = async_get_call( & call );
-
 
200
        arg1 = 0;
-
 
201
        arg2 = 0;
-
 
202
        arg3 = 0;
-
 
203
//      printf( "\nNET-%d got %d on %x from %x", fibril_get_id(), IPC_GET_METHOD( call ), call.in_phone_hash, callid );
-
 
204
#ifdef NETWORKING_module
199
#ifdef NETWORKING_module
-
 
200
        //TODO map to *_message
205
        if( IS_NET_IL_MESSAGE( call ) || IS_NET_IP_MESSAGE( call )){
201
        if( IS_NET_IL_MESSAGE( call ) || IS_NET_IP_MESSAGE( call )){
206
            res = ip_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
202
            return ip_message( callid, call, answer, answer_count );
207
/*      }else if( IS_NET_ARP_MESSAGE( call )){
203
/*      }else if( IS_NET_ARP_MESSAGE( call )){
208
            res = arp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
204
            return arp_message( callid, call, answer, answer_count );
209
*//*        }else if( IS_NET_RARP_MESSAGE( call )){
205
*//*        }else if( IS_NET_RARP_MESSAGE( call )){
210
            res = rarp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
206
            return rarp_message( callid, call, answer, answer_count );
211
*//*        }else if( IS_NET_ICMP_MESSAGE( call )){
207
*//*        }else if( IS_NET_ICMP_MESSAGE( call )){
212
            res = icmp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
208
            return icmp_message( callid, call, answer, answer_count );
213
*//*        }else if( IS_NET_UDP_MESSAGE( call )){
209
*//*        }else if( IS_NET_UDP_MESSAGE( call )){
214
            res = udp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
210
            return udp_message( callid, call, answer, answer_count );
215
*/      }else if( IS_NET_TCP_MESSAGE( call )){
211
*/      }else if( IS_NET_TCP_MESSAGE( call )){
216
            res = tcp_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
212
            return tcp_message( callid, call, answer, answer_count );
217
/*      }else if( IS_NET_SOCKET_MESSAGE( call )){
213
/*      }else if( IS_NET_SOCKET_MESSAGE( call )){
218
            res = socket_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
214
            return socket_message( callid, call, answer, answer_count );
219
*//*        }else if( IS_NET_NIL_MESSAGE( call ) || IS_NET_ETHERNET_MESSAGE( call )){
215
*//*        }else if( IS_NET_NIL_MESSAGE( call ) || IS_NET_ETHERNET_MESSAGE( call )){
220
            res = ethernet_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
216
            return ethernet_message( callid, call, answer, answer_count );
221
*/      }else{
217
*/      }else{
222
#endif
218
#endif
-
 
219
            if( IS_NET_PACKET_MESSAGE( call )){
223
            res = networking_message( IPC_GET_METHOD( call ), IPC_GET_ARG1( call ), IPC_GET_ARG2( call ), IPC_GET_ARG3( call ), & arg1, & arg2, & arg3 );
220
                return packet_server_message( callid, call, answer, answer_count );
-
 
221
            }else{
-
 
222
                return net_message( callid, call, answer, answer_count );
-
 
223
            }
224
#ifdef NETWORKING_module
224
#ifdef NETWORKING_module
225
        }
225
        }
226
#endif
226
#endif
227
        ipc_answer_2( callid, res, arg1, arg2 );
-
 
228
    }
-
 
229
}
227
}
230
 
228
 
231
int main( int argc, char * argv[] ){
229
int networking_start_module( async_client_conn_t client_connection ){
232
    ERROR_DECLARE;
230
    ERROR_DECLARE;
233
 
231
 
234
    ipcarg_t    phonehash;
232
    ipcarg_t    phonehash;
235
 
233
 
236
    printf("\nTask %d - HelenOS Networking subsystem", task_get_id());
-
 
237
 
-
 
238
    async_set_client_connection( client_connection );
234
    async_set_client_connection( client_connection );
239
    ERROR_PROPAGATE( networking_initialize());
235
    ERROR_PROPAGATE( networking_initialize());
240
    ERROR_PROPAGATE( REGISTER_ME( SERVICE_NETWORKING, & phonehash ));
236
    ERROR_PROPAGATE( REGISTER_ME( SERVICE_NETWORKING, & phonehash ));
241
 
-
 
-
 
237
    ERROR_PROPAGATE( pm_init());
242
    async_manager();
238
    async_manager();
243
 
239
 
244
    return EOK;
240
    return EOK;
245
}
241
}
246
 
242
 
Line 298... Line 294...
298
#endif
294
#endif
299
 
295
 
300
    return EOK;
296
    return EOK;
301
}
297
}
302
 
298
 
-
 
299
//TODO as ip.c
303
int networking_message( ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){
300
int net_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
304
    ERROR_DECLARE;
301
    ERROR_DECLARE;
305
 
302
 
306
    measured_string_ref strings;
303
    measured_string_ref strings;
307
    char *          data;
304
    char *          data;
308
    int         index;
305
    int         index;
309
    measured_string_ref setting;
306
    measured_string_ref setting;
310
    measured_strings_ref    configuration;
307
    measured_strings_ref    configuration;
311
    netif_ref       netif;
308
    netif_ref       netif;
312
 
309
 
-
 
310
    * answer_count = 0;
313
    switch( method ){
311
    switch( IPC_GET_METHOD( * call )){
314
        case IPC_M_PHONE_HUNGUP:
312
        case IPC_M_PHONE_HUNGUP:
315
            return EOK;
313
            return EOK;
316
        case NET_NET_DEVICE:
314
        case NET_NET_DEVICE:
317
            // TODO configure, register
315
            // TODO configure, register
318
            // arg1 = netif id
-
 
319
            printf( "\nNetworking: new netif %d", arg1 );
316
            printf( "\nNetworking: new netif %d", IPC_GET_DEVICE( call ));
320
            return EOK;
317
            return EOK;
321
        case NET_NET_GET_DEVICE_CONF:
318
        case NET_NET_GET_DEVICE_CONF:
322
            // arg1 = netif id
-
 
323
            // arg2 = count
-
 
324
            ERROR_PROPAGATE( measured_strings_receive( & strings, & data, arg2 ));
319
            ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call )));
325
            netif = netifs_find( & networking_globals.netifs, arg1 );
320
            netif = netifs_find( & networking_globals.netifs, IPC_GET_DEVICE( call ));
326
            if( netif ){
321
            if( netif ){
327
                configuration = & netif->configuration;
322
                configuration = & netif->configuration;
328
            }else{
323
            }else{
329
                configuration = NULL;
324
                configuration = NULL;
330
            }
325
            }
331
            for( index = 0; index < arg2; ++ index ){
326
            for( index = 0; index < IPC_GET_COUNT( call ); ++ index ){
332
                setting = measured_strings_find( configuration, strings[ index ].value, 0 );
327
                setting = measured_strings_find( configuration, strings[ index ].value, 0 );
333
                if( ! setting ){
328
                if( ! setting ){
334
                    setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value, 0 );
329
                    setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value, 0 );
335
                }
330
                }
336
                if( setting ){
331
                if( setting ){
Line 341... Line 336...
341
                    strings[ index ].value = NULL;
336
                    strings[ index ].value = NULL;
342
                }
337
                }
343
            }
338
            }
344
            // strings should not contain received data anymore
339
            // strings should not contain received data anymore
345
            free( data );
340
            free( data );
346
            ERROR_CODE = measured_strings_reply( strings, arg2 );
341
            ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call ));
347
            free( strings );
342
            free( strings );
348
            return ERROR_CODE;
343
            return ERROR_CODE;
349
        case NET_NET_GET_CONF:
344
        case NET_NET_GET_CONF:
350
            // arg1 = count
345
            // arg1 = count
351
            ERROR_PROPAGATE( measured_strings_receive( & strings, & data, arg1 ));
346
            ERROR_PROPAGATE( measured_strings_receive( & strings, & data, IPC_GET_COUNT( call )));
352
            for( index = 0; index < arg1; ++ index ){
347
            for( index = 0; index < IPC_GET_COUNT( call ); ++ index ){
353
                setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value, 0 );
348
                setting = measured_strings_find( & networking_globals.configuration, strings[ index ].value, 0 );
354
                if( setting ){
349
                if( setting ){
355
                    strings[ index ].length = setting->length;
350
                    strings[ index ].length = setting->length;
356
                    strings[ index ].value = setting->value;
351
                    strings[ index ].value = setting->value;
357
                }else{
352
                }else{
Line 359... Line 354...
359
                    strings[ index ].value = NULL;
354
                    strings[ index ].value = NULL;
360
                }
355
                }
361
            }
356
            }
362
            // strings should not contain received data anymore
357
            // strings should not contain received data anymore
363
            free( data );
358
            free( data );
364
            ERROR_CODE = measured_strings_reply( strings, arg1 );
359
            ERROR_CODE = measured_strings_reply( strings, IPC_GET_COUNT( call ));
365
            free( strings );
360
            free( strings );
366
            return ERROR_CODE;
361
            return ERROR_CODE;
367
        case NET_NET_STARTUP:
362
        case NET_NET_STARTUP:
368
            return startup();
363
            return startup();
369
    }
364
    }