Subversion Repositories HelenOS

Rev

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

Rev 3666 Rev 3685
Line 39... Line 39...
39
#include <ipc/ipc.h>
39
#include <ipc/ipc.h>
40
#include <ipc/services.h>
40
#include <ipc/services.h>
41
//#include <sys/mman.h>
41
//#include <sys/mman.h>
42
 
42
 
43
#include "../err.h"
43
#include "../err.h"
-
 
44
#include "../measured_strings.h"
44
#include "../messages.h"
45
#include "../messages.h"
45
#include "../modules.h"
46
#include "../modules.h"
46
#include "../netif/netif_device_id_type.h"
47
#include "../netif/netif_device_id_type.h"
47
 
48
 
48
#include "ip.h"
49
#include "ip.h"
49
 
50
 
-
 
51
#define DEFAULT_IPV 4
-
 
52
 
50
ip_globals_t    ip_globals;
53
ip_globals_t    ip_globals;
51
 
54
 
52
DEVICE_MAP_IMPLEMENT( ip_netifs, ip_netif_t )
55
DEVICE_MAP_IMPLEMENT( ip_netifs, ip_netif_t )
53
 
56
 
-
 
57
int parse_address( char * value, address_ref address );
-
 
58
 
54
/** Initializes the module.
59
/** Initializes the module.
55
 */
60
 */
56
int ip_initialize( void ){
61
int ip_initialize( void ){
57
    ip_netifs_initialize( & ip_globals.netifs );
62
    ip_netifs_initialize( & ip_globals.netifs );
58
    return EOK;
63
    return EOK;
Line 60... Line 65...
60
 
65
 
61
int ip_call( ipc_callid_t callid ){
66
int ip_call( ipc_callid_t callid ){
62
    return EOK;
67
    return EOK;
63
}
68
}
64
 
69
 
-
 
70
int parse_address( char * value, address_ref address ){
-
 
71
    char *  next;
-
 
72
    int index;
-
 
73
 
-
 
74
    if( ! value ){
-
 
75
        ( * address )[ 0 ] = ( * address )[ 1 ] = ( * address )[ 2 ] = ( * address )[ 3 ] = 0;
-
 
76
        return ENOENT;
-
 
77
    }
-
 
78
    next = value;
-
 
79
    for( index = 0; index < 4; ++ index ){
-
 
80
        if(( ! next ) || ( ! * next )) return EINVAL;
-
 
81
        if( index ) ++ next;
-
 
82
        ( * address )[ index ] = strtoul( next, & next, 0 );
-
 
83
    }
-
 
84
    return EOK;
-
 
85
}
-
 
86
 
65
int ip_message( ipc_callid_t callid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){
87
int ip_message( ipc_callid_t callid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){
66
    ERROR_DECLARE;
88
    ERROR_DECLARE;
67
 
89
 
68
    ip_netif_ref    ip_netif;
90
    ip_netif_ref        ip_netif;
-
 
91
    aid_t           message;
-
 
92
    ipc_call_t      answer;
-
 
93
    measured_string_t   configuration[ 9 ] = {{ "IPV", 3 }, { "IP_CONFIG", 9 }, { "IP_ADDR", 7 }, { "NETMASK", 7 }, { "GATEWAY", 7 }, { "BROADCAST", 9 }, { "DNS1", 4 }, { "DNS2", 4 }, { "ARP", 3 }};
-
 
94
    int         count = 9;
-
 
95
    measured_string_ref settings;
-
 
96
    char *          data;
69
 
97
 
70
//  printf( "\nIP message %d", method );
-
 
71
    switch( method ){
98
    switch( method ){
72
//      case IPC_M_CONNECT_ME_TO:
-
 
73
//      case IPC_M_CONNECT_TO_ME:
-
 
74
        case IPC_M_PHONE_HUNGUP:
99
        case IPC_M_PHONE_HUNGUP:
75
            return EOK;
100
            return EOK;
76
        case NET_IP_ECHO:
101
        case NET_IP_ECHO:
77
            if( result1 ) * result1 = arg1;
102
            if( result1 ) * result1 = arg1;
78
            if( result2 ) * result2 = arg2;
103
            if( result2 ) * result2 = arg2;
Line 80... Line 105...
80
            return EOK;
105
            return EOK;
81
        case NET_IL_DEVICE:
106
        case NET_IL_DEVICE:
82
            ip_netif = ( ip_netif_ref ) malloc( sizeof( ip_netif_t ));
107
            ip_netif = ( ip_netif_ref ) malloc( sizeof( ip_netif_t ));
83
            if( ! ip_netif ) return ENOMEM;
108
            if( ! ip_netif ) return ENOMEM;
84
            ip_netif->device_id = arg1;
109
            ip_netif->device_id = arg1;
-
 
110
            // get configuration
-
 
111
            message = async_send_2( ip_globals.networking_phone, NET_NETWORKING_GET_DEVICE_CONFIGURATION, ip_netif->device_id, count, & answer );
85
            ip_netif->phone = connect_to_service( arg2 );
112
            // send names and get settings
86
            if( ERROR_OCCURED( ipc_call_sync_1_0( ip_netif->phone, NET_LL_REGISTER, arg1 ))){
113
            if( ERROR_OCCURED( measured_strings_send( ip_globals.networking_phone, configuration, count ))
-
 
114
            || ERROR_OCCURED( measured_strings_return( ip_globals.networking_phone, & settings, & data, count ))){
87
                free( ip_netif );
115
                async_wait_for( message, NULL );
88
                return ERROR_CODE;
116
                return ERROR_CODE;
89
            }
117
            }
-
 
118
            if( settings ){
-
 
119
                if( settings[ 0 ].value ){
-
 
120
                    ip_netif->ipv = strtol( settings[ 0 ].value, NULL, 0 );
-
 
121
                }else{
-
 
122
                    ip_netif->ipv = DEFAULT_IPV;
-
 
123
                }
-
 
124
                ip_netif->dhcp = ! strcmp( settings[ 1 ].value, "DHCP" );
-
 
125
                if( ip_netif->dhcp ){
-
 
126
                    // TODO dhcp
-
 
127
                    free( ip_netif );
-
 
128
                    return ENOTSUP;
-
 
129
                }else if( ip_netif->ipv == 4 ){
-
 
130
                    if( ERROR_OCCURED( parse_address( settings[ 2 ].value, & ip_netif->address ))
-
 
131
                    || ERROR_OCCURED( parse_address( settings[ 3 ].value, & ip_netif->netmask ))
-
 
132
                    || ( parse_address( settings[ 4 ].value, & ip_netif->gateway ) == EINVAL )
-
 
133
                    || ( parse_address( settings[ 5 ].value, & ip_netif->broadcast ) == EINVAL )
-
 
134
                    || ( parse_address( settings[ 6 ].value, & ip_netif->dns1 ) == EINVAL )
-
 
135
                    || ( parse_address( settings[ 7 ].value, & ip_netif->dns2 ) == EINVAL )){
-
 
136
                        free( ip_netif );
-
 
137
                        return EINVAL;
-
 
138
                    }
-
 
139
                }else{
-
 
140
                    // TODO ipv6
-
 
141
                    free( ip_netif );
-
 
142
                    return ENOTSUP;
-
 
143
                }
-
 
144
                // TODO ARP module
-
 
145
            }
-
 
146
            // print the settings
-
 
147
            printf( "\n -IPV=%d", ip_netif->ipv );
-
 
148
            printf( "\n -configuration=%s", ip_netif->dhcp ? "dhcp" : "static" );
-
 
149
            // TODO ipv6
-
 
150
            printf( "\n -address=%d.%d.%d.%d", ip_netif->address[ 0 ], ip_netif->address[ 1 ], ip_netif->address[ 2 ], ip_netif->address[ 3 ] );
-
 
151
            printf( "\n -netmask=%d.%d.%d.%d", ip_netif->netmask[ 0 ], ip_netif->netmask[ 1 ], ip_netif->netmask[ 2 ], ip_netif->netmask[ 3 ] );
-
 
152
            printf( "\n -gateway=%d.%d.%d.%d", ip_netif->gateway[ 0 ], ip_netif->gateway[ 1 ], ip_netif->gateway[ 2 ], ip_netif->gateway[ 3 ] );
-
 
153
            printf( "\n -broadcast=%d.%d.%d.%d", ip_netif->broadcast[ 0 ], ip_netif->broadcast[ 1 ], ip_netif->broadcast[ 2 ], ip_netif->broadcast[ 3 ] );
-
 
154
            printf( "\n -dns1=%d.%d.%d.%d", ip_netif->dns1[ 0 ], ip_netif->dns1[ 1 ], ip_netif->dns1[ 2 ], ip_netif->dns1[ 3 ] );
-
 
155
            printf( "\n -dns2=%d.%d.%d.%d", ip_netif->dns2[ 0 ], ip_netif->dns2[ 1 ], ip_netif->dns2[ 2 ], ip_netif->dns2[ 3 ] );
-
 
156
            // TODO arp module
-
 
157
            free( settings );
-
 
158
            free( data );
-
 
159
            // end request
-
 
160
            async_wait_for( message, NULL );
-
 
161
            ip_netif->phone = connect_to_service( arg2 );
-
 
162
            if( ERROR_OCCURED( async_req_2_0( ip_netif->phone, NET_LL_REGISTER, arg1, SERVICE_IP ))
90
            if( ERROR_OCCURED( ip_netifs_add( & ip_globals.netifs, ip_netif->device_id, ip_netif ))){
163
            || ERROR_OCCURED( ip_netifs_add( & ip_globals.netifs, ip_netif->device_id, ip_netif ))){
91
                free( ip_netif );
164
                free( ip_netif );
92
                return ERROR_CODE;
165
                return ERROR_CODE;
93
            }
166
            }
94
            return EOK;
167
            return EOK;
-
 
168
        case NET_IL_DEVICE_STATE_CHANGED:
-
 
169
        case NET_LL_DEVICE_STATE_CHANGED:
-
 
170
            // arg1 device id
-
 
171
            // arg2 state
-
 
172
            // TODO state
-
 
173
            printf( "\nip - device %d changed state to %d\n", arg1, arg2 );
95
        case NET_IP_TCP_REGISTER:
174
        case NET_IP_TCP_REGISTER:
96
            ip_globals.tcp_phone = ipc_connect_to_me( callid, 0, 0, 0, 0 );
175
            ip_globals.tcp_phone = connect_to_service( arg1 );
97
            return EOK;
176
            return EOK;
98
    }
177
    }
99
    return ENOTSUP;
178
    return ENOTSUP;
100
}
179
}
101
 
180