Rev 4243 | Rev 4271 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4243 | Rev 4261 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Lukas Mejdrech |
2 | * Copyright (c) 2009 Lukas Mejdrech |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup ip |
29 | /** @addtogroup ip |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** @file |
33 | /** @file |
34 | */ |
34 | */ |
35 | 35 | ||
36 | #include <async.h> |
36 | #include <async.h> |
37 | #include <errno.h> |
37 | #include <errno.h> |
38 | #include <stdio.h> |
38 | #include <stdio.h> |
39 | 39 | ||
40 | #include <ipc/ipc.h> |
40 | #include <ipc/ipc.h> |
41 | #include <ipc/services.h> |
41 | #include <ipc/services.h> |
42 | 42 | ||
43 | #include "../../err.h" |
43 | #include "../../err.h" |
44 | #include "../../messages.h" |
44 | #include "../../messages.h" |
45 | #include "../../modules.h" |
45 | #include "../../modules.h" |
46 | 46 | ||
47 | #include "../../include/sockaddr.h" |
47 | #include "../../include/sockaddr.h" |
48 | #include "../../include/socket.h" |
48 | #include "../../include/socket.h" |
49 | #include "../../include/device.h" |
49 | #include "../../include/device.h" |
- | 50 | #include "../../include/nil_messages.h" |
|
50 | #include "../../structures/measured_strings.h" |
51 | #include "../../structures/measured_strings.h" |
51 | #include "../../structures/module_map.h" |
52 | #include "../../structures/module_map.h" |
52 | #include "../../structures/packet/packet_client.h" |
53 | #include "../../structures/packet/packet_client.h" |
53 | 54 | ||
54 | #include "ip.h" |
55 | #include "ip.h" |
55 | #include "ip_messages.h" |
56 | #include "ip_messages.h" |
56 | #include "ip_module.h" |
57 | #include "ip_module.h" |
57 | 58 | ||
58 | #define DEFAULT_IPV 4 |
59 | #define DEFAULT_IPV 4 |
59 | 60 | ||
60 | #define ARP_NAME "arp" |
61 | #define ARP_NAME "arp" |
61 | #define ARP_FILENAME "/srv/arp" |
62 | #define ARP_FILENAME "/srv/arp" |
62 | 63 | ||
63 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
- | |
64 | #define IPC_GET_PACKET( call ) ( packet_id_t ) IPC_GET_ARG1( * call ) |
- | |
65 | #define IPC_GET_PROTO( call ) ( int ) IPC_GET_ARG1( * call ) |
64 | #define IPC_GET_PROTO( call ) ( int ) IPC_GET_ARG1( * call ) |
66 | #define IPC_GET_SERVICE( call ) ( services_t ) IPC_GET_ARG2( * call ) |
- | |
67 | #define IPC_GET_STATE( call ) ( device_state_t ) IPC_GET_ARG2( * call ) |
65 | #define IPC_GET_STATE( call ) ( device_state_t ) IPC_GET_ARG2( * call ) |
68 | #define IPC_GET_PHONE( call ) ( int ) IPC_GET_ARG5( * call ) |
66 | #define IPC_GET_PHONE( call ) ( int ) IPC_GET_ARG5( * call ) |
69 | 67 | ||
70 | ip_globals_t ip_globals; |
68 | ip_globals_t ip_globals; |
71 | 69 | ||
72 | DEVICE_MAP_IMPLEMENT( ip_netifs, ip_netif_t ) |
70 | DEVICE_MAP_IMPLEMENT( ip_netifs, ip_netif_t ) |
73 | 71 | ||
74 | INT_MAP_IMPLEMENT( ip_protos, ip_proto_t ) |
72 | INT_MAP_IMPLEMENT( ip_protos, ip_proto_t ) |
75 | 73 | ||
76 | int ip_register_message( int protocol, int phone ); |
74 | int ip_register_message( int protocol, int phone ); |
77 | int ip_state_message( device_id_t device_id, device_state_t state ); |
75 | int ip_state_message( device_id_t device_id, device_state_t state ); |
78 | void ip_driver_receiver( ipc_callid_t iid, ipc_call_t * icall ); |
76 | void ip_driver_receiver( ipc_callid_t iid, ipc_call_t * icall ); |
79 | 77 | ||
80 | /** Initializes the module. |
78 | /** Initializes the module. |
81 | */ |
79 | */ |
82 | int ip_initialize( void ){ |
80 | int ip_initialize( void ){ |
83 | ERROR_DECLARE; |
81 | ERROR_DECLARE; |
84 | 82 | ||
85 | ERROR_PROPAGATE( ip_netifs_initialize( & ip_globals.netifs )); |
83 | ERROR_PROPAGATE( ip_netifs_initialize( & ip_globals.netifs )); |
86 | ERROR_PROPAGATE( ip_protos_initialize( & ip_globals.protos )); |
84 | ERROR_PROPAGATE( ip_protos_initialize( & ip_globals.protos )); |
87 | ERROR_PROPAGATE( modules_initialize( & ip_globals.modules )); |
85 | ERROR_PROPAGATE( modules_initialize( & ip_globals.modules )); |
88 | ERROR_PROPAGATE( add_module( NULL, & ip_globals.modules, ARP_NAME, ARP_FILENAME, SERVICE_ARP, 0 )); |
86 | ERROR_PROPAGATE( add_module( NULL, & ip_globals.modules, ARP_NAME, ARP_FILENAME, SERVICE_ARP, 0 )); |
89 | return EOK; |
87 | return EOK; |
90 | } |
88 | } |
91 | 89 | ||
92 | int ip_echo_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipcarg_t arg5, ipcarg_t * answer1, ipcarg_t * answer2, ipcarg_t * answer3, ipcarg_t * answer4, ipcarg_t * answer5 ){ |
90 | int ip_echo_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipcarg_t arg5, ipcarg_t * answer1, ipcarg_t * answer2, ipcarg_t * answer3, ipcarg_t * answer4, ipcarg_t * answer5 ){ |
93 | if( answer1 ) * answer1 = arg1; |
91 | if( answer1 ) * answer1 = arg1; |
94 | if( answer2 ) * answer2 = arg2; |
92 | if( answer2 ) * answer2 = arg2; |
95 | if( answer3 ) * answer3 = arg3; |
93 | if( answer3 ) * answer3 = arg3; |
96 | if( answer4 ) * answer4 = arg4; |
94 | if( answer4 ) * answer4 = arg4; |
97 | if( answer5 ) * answer5 = arg5; |
95 | if( answer5 ) * answer5 = arg5; |
98 | return EOK; |
96 | return EOK; |
99 | } |
97 | } |
100 | 98 | ||
101 | int ip_device_message( device_id_t device_id, services_t service ){ |
99 | int ip_device_message( device_id_t device_id, services_t service ){ |
102 | ERROR_DECLARE; |
100 | ERROR_DECLARE; |
103 | 101 | ||
104 | ip_netif_ref ip_netif; |
102 | ip_netif_ref ip_netif; |
105 | aid_t message; |
103 | aid_t message; |
106 | ipc_call_t answer; |
104 | ipc_call_t answer; |
107 | 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 }}; |
105 | 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 }}; |
108 | int count = 9; |
106 | int count = 9; |
109 | measured_string_ref settings; |
107 | measured_string_ref settings; |
110 | char * data; |
108 | char * data; |
111 | ipcarg_t result; |
109 | ipcarg_t result; |
112 | int index; |
110 | int index; |
113 | 111 | ||
114 | ip_netif = ( ip_netif_ref ) malloc( sizeof( ip_netif_t )); |
112 | ip_netif = ( ip_netif_ref ) malloc( sizeof( ip_netif_t )); |
115 | if( ! ip_netif ) return ENOMEM; |
113 | if( ! ip_netif ) return ENOMEM; |
116 | ip_netif->device_id = device_id; |
114 | ip_netif->device_id = device_id; |
117 | // get configuration |
115 | // get configuration |
118 | // TODO mapping |
116 | // TODO mapping |
119 | message = async_send_2( ip_globals.networking_phone, NET_NET_GET_DEVICE_CONF, ip_netif->device_id, count, & answer ); |
117 | message = async_send_2( ip_globals.networking_phone, NET_NET_GET_DEVICE_CONF, ip_netif->device_id, count, & answer ); |
120 | // send names and get settings |
118 | // send names and get settings |
121 | if( ERROR_OCCURRED( measured_strings_send( ip_globals.networking_phone, configuration, count )) |
119 | if( ERROR_OCCURRED( measured_strings_send( ip_globals.networking_phone, configuration, count )) |
122 | || ERROR_OCCURRED( measured_strings_return( ip_globals.networking_phone, & settings, & data, count ))){ |
120 | || ERROR_OCCURRED( measured_strings_return( ip_globals.networking_phone, & settings, & data, count ))){ |
123 | async_wait_for( message, NULL ); |
121 | async_wait_for( message, NULL ); |
124 | free( ip_netif ); |
122 | free( ip_netif ); |
125 | return ERROR_CODE; |
123 | return ERROR_CODE; |
126 | } |
124 | } |
127 | async_wait_for( message, & result ); |
125 | async_wait_for( message, & result ); |
128 | if( ERROR_OCCURRED( result )){ |
126 | if( ERROR_OCCURRED( result )){ |
129 | if( settings ){ |
127 | if( settings ){ |
130 | free( settings ); |
128 | free( settings ); |
131 | free( data ); |
129 | free( data ); |
132 | }; |
130 | }; |
133 | free( ip_netif ); |
131 | free( ip_netif ); |
134 | return ERROR_CODE; |
132 | return ERROR_CODE; |
135 | } |
133 | } |
136 | if( settings ){ |
134 | if( settings ){ |
137 | if( settings[ 0 ].value ){ |
135 | if( settings[ 0 ].value ){ |
138 | ip_netif->ipv = strtol( settings[ 0 ].value, NULL, 0 ); |
136 | ip_netif->ipv = strtol( settings[ 0 ].value, NULL, 0 ); |
139 | }else{ |
137 | }else{ |
140 | ip_netif->ipv = DEFAULT_IPV; |
138 | ip_netif->ipv = DEFAULT_IPV; |
141 | } |
139 | } |
142 | ip_netif->dhcp = ! strncmp( settings[ 1 ].value, "dhcp", 4 ); |
140 | ip_netif->dhcp = ! strncmp( settings[ 1 ].value, "dhcp", 4 ); |
143 | if( ip_netif->dhcp ){ |
141 | if( ip_netif->dhcp ){ |
144 | // TODO dhcp |
142 | // TODO dhcp |
145 | free( settings ); |
143 | free( settings ); |
146 | free( data ); |
144 | free( data ); |
147 | free( ip_netif ); |
145 | free( ip_netif ); |
148 | return ENOTSUP; |
146 | return ENOTSUP; |
149 | }else if( ip_netif->ipv == 4 ){ |
147 | }else if( ip_netif->ipv == 4 ){ |
150 | if( ERROR_OCCURRED( inet_pton( AF_INET, settings[ 2 ].value, ( uint8_t * ) & ip_netif->address )) |
148 | if( ERROR_OCCURRED( inet_pton( AF_INET, settings[ 2 ].value, ( uint8_t * ) & ip_netif->address )) |
151 | || ERROR_OCCURRED( inet_pton( AF_INET, settings[ 3 ].value, ( uint8_t * ) & ip_netif->netmask )) |
149 | || ERROR_OCCURRED( inet_pton( AF_INET, settings[ 3 ].value, ( uint8_t * ) & ip_netif->netmask )) |
152 | || ( inet_pton( AF_INET, settings[ 4 ].value, ( uint8_t * ) & ip_netif->gateway ) == EINVAL ) |
150 | || ( inet_pton( AF_INET, settings[ 4 ].value, ( uint8_t * ) & ip_netif->gateway ) == EINVAL ) |
153 | || ( inet_pton( AF_INET, settings[ 5 ].value, ( uint8_t * ) & ip_netif->broadcast ) == EINVAL ) |
151 | || ( inet_pton( AF_INET, settings[ 5 ].value, ( uint8_t * ) & ip_netif->broadcast ) == EINVAL ) |
154 | || ( inet_pton( AF_INET, settings[ 6 ].value, ( uint8_t * ) & ip_netif->dns1 ) == EINVAL ) |
152 | || ( inet_pton( AF_INET, settings[ 6 ].value, ( uint8_t * ) & ip_netif->dns1 ) == EINVAL ) |
155 | || ( inet_pton( AF_INET, settings[ 7 ].value, ( uint8_t * ) & ip_netif->dns2 ) == EINVAL )){ |
153 | || ( inet_pton( AF_INET, settings[ 7 ].value, ( uint8_t * ) & ip_netif->dns2 ) == EINVAL )){ |
156 | free( settings ); |
154 | free( settings ); |
157 | free( data ); |
155 | free( data ); |
158 | free( ip_netif ); |
156 | free( ip_netif ); |
159 | return EINVAL; |
157 | return EINVAL; |
160 | } |
158 | } |
161 | }else{ |
159 | }else{ |
162 | // TODO ipv6 |
160 | // TODO ipv6 |
163 | free( settings ); |
161 | free( settings ); |
164 | free( data ); |
162 | free( data ); |
165 | free( ip_netif ); |
163 | free( ip_netif ); |
166 | return ENOTSUP; |
164 | return ENOTSUP; |
167 | } |
165 | } |
168 | if( settings[ 8 ].value ){ |
166 | if( settings[ 8 ].value ){ |
169 | ip_netif->arp = get_running_module( & ip_globals.modules, settings[ 8 ].value ); |
167 | ip_netif->arp = get_running_module( & ip_globals.modules, settings[ 8 ].value ); |
170 | if( ! ip_netif->arp ){ |
168 | if( ! ip_netif->arp ){ |
171 | printf( "\nFailed to start the arp %s", settings[ 8 ].value ); |
169 | printf( "\nFailed to start the arp %s", settings[ 8 ].value ); |
172 | free( settings ); |
170 | free( settings ); |
173 | free( data ); |
171 | free( data ); |
174 | free( ip_netif ); |
172 | free( ip_netif ); |
175 | return EINVAL; |
173 | return EINVAL; |
176 | } |
174 | } |
177 | }else{ |
175 | }else{ |
178 | ip_netif->arp = NULL; |
176 | ip_netif->arp = NULL; |
179 | } |
177 | } |
180 | free( settings ); |
178 | free( settings ); |
181 | free( data ); |
179 | free( data ); |
182 | } |
180 | } |
183 | // TODO mapping |
- | |
184 | ip_netif->phone = bind_service( service, ip_netif->device_id, SERVICE_IP, 0, ip_driver_receiver ); |
181 | ip_netif->phone = bind_service( service, ip_netif->device_id, SERVICE_IP, 0, ip_driver_receiver ); |
185 | if( ip_netif->phone < 0 ){ |
182 | if( ip_netif->phone < 0 ){ |
186 | printf( "\nFailed to contact the nil service %d", service ); |
183 | printf( "\nFailed to contact the nil service %d", service ); |
187 | free( ip_netif ); |
184 | free( ip_netif ); |
188 | return ip_netif->phone; |
185 | return ip_netif->phone; |
189 | } |
186 | } |
190 | if( ip_netif->arp ){ |
187 | if( ip_netif->arp ){ |
191 | message = async_send_3( ip_netif->arp->phone, NET_ARP_DEVICE, ip_netif->device_id, SERVICE_IP, service, & answer ); |
188 | message = async_send_3( ip_netif->arp->phone, NET_ARP_DEVICE, ip_netif->device_id, SERVICE_IP, service, & answer ); |
192 | configuration[ 0 ].value = ( char * ) & ip_netif->address; |
189 | configuration[ 0 ].value = ( char * ) & ip_netif->address; |
193 | configuration[ 0 ].length = CONVERT_SIZE( in_addr_t, char, 1 ); |
190 | configuration[ 0 ].length = CONVERT_SIZE( in_addr_t, char, 1 ); |
194 | if( ERROR_OCCURRED( measured_strings_send( ip_netif->arp->phone, & configuration[ 0 ], 1 ))){ |
191 | if( ERROR_OCCURRED( measured_strings_send( ip_netif->arp->phone, & configuration[ 0 ], 1 ))){ |
195 | free( ip_netif ); |
192 | free( ip_netif ); |
196 | return ERROR_CODE; |
193 | return ERROR_CODE; |
197 | } |
194 | } |
198 | async_wait_for( message, & result ); |
195 | async_wait_for( message, & result ); |
199 | if( ERROR_OCCURRED( result )){ |
196 | if( ERROR_OCCURRED( result )){ |
200 | free( ip_netif ); |
197 | free( ip_netif ); |
201 | return ERROR_CODE; |
198 | return ERROR_CODE; |
202 | } |
199 | } |
203 | } |
200 | } |
204 | index = ip_netifs_add( & ip_globals.netifs, ip_netif->device_id, ip_netif ); |
201 | index = ip_netifs_add( & ip_globals.netifs, ip_netif->device_id, ip_netif ); |
205 | if( index < 0 ){ |
202 | if( index < 0 ){ |
206 | free( ip_netif ); |
203 | free( ip_netif ); |
207 | return index; |
204 | return index; |
208 | } |
205 | } |
209 | if( ip_netif->arp ) ++ ip_netif->arp->usage; |
206 | if( ip_netif->arp ) ++ ip_netif->arp->usage; |
210 | // print the settings |
207 | // print the settings |
211 | printf( "\nNew device registered:\n\tid\t= %d\n\tphone\t= %d\n\tIPV\t= %d", ip_netif->device_id, ip_netif->phone, ip_netif->ipv ); |
208 | printf( "\nNew device registered:\n\tid\t= %d\n\tphone\t= %d\n\tIPV\t= %d", ip_netif->device_id, ip_netif->phone, ip_netif->ipv ); |
212 | printf( "\n\tconfiguration\t= %s", ip_netif->dhcp ? "dhcp" : "static" ); |
209 | printf( "\n\tconfiguration\t= %s", ip_netif->dhcp ? "dhcp" : "static" ); |
213 | // TODO ipv6 addresses |
210 | // TODO ipv6 addresses |
214 | data = malloc( INET_ADDRSTRLEN ); |
211 | data = malloc( INET_ADDRSTRLEN ); |
215 | if( data ){ |
212 | if( data ){ |
216 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->address, data, INET_ADDRSTRLEN ); |
213 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->address, data, INET_ADDRSTRLEN ); |
217 | printf( "\n\taddress\t= %s", data ); |
214 | printf( "\n\taddress\t= %s", data ); |
218 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->netmask, data, INET_ADDRSTRLEN ); |
215 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->netmask, data, INET_ADDRSTRLEN ); |
219 | printf( "\n\tnetmask\t= %s", data ); |
216 | printf( "\n\tnetmask\t= %s", data ); |
220 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->gateway, data, INET_ADDRSTRLEN ); |
217 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->gateway, data, INET_ADDRSTRLEN ); |
221 | printf( "\n\tgateway\t= %s", data ); |
218 | printf( "\n\tgateway\t= %s", data ); |
222 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->broadcast, data, INET_ADDRSTRLEN ); |
219 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->broadcast, data, INET_ADDRSTRLEN ); |
223 | printf( "\n\tbroadcast\t= %s", data ); |
220 | printf( "\n\tbroadcast\t= %s", data ); |
224 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns1, data, INET_ADDRSTRLEN ); |
221 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns1, data, INET_ADDRSTRLEN ); |
225 | printf( "\n\tdns1\t= %s", data ); |
222 | printf( "\n\tdns1\t= %s", data ); |
226 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns2, data, INET_ADDRSTRLEN ); |
223 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns2, data, INET_ADDRSTRLEN ); |
227 | printf( "\n\tdns2\t= %s", data ); |
224 | printf( "\n\tdns2\t= %s", data ); |
228 | free( data ); |
225 | free( data ); |
229 | } |
226 | } |
230 | return EOK; |
227 | return EOK; |
231 | } |
228 | } |
232 | 229 | ||
233 | void ip_driver_receiver( ipc_callid_t iid, ipc_call_t * icall ){ |
230 | void ip_driver_receiver( ipc_callid_t iid, ipc_call_t * icall ){ |
234 | ERROR_DECLARE; |
231 | ERROR_DECLARE; |
235 | 232 | ||
236 | ipc_callid_t callid; |
233 | ipc_callid_t callid; |
237 | ipc_call_t call; |
234 | ipc_call_t call; |
238 | // ipc_call_t answer; |
235 | // ipc_call_t answer; |
239 | // int count; |
236 | // int count; |
240 | int result; |
237 | int result; |
241 | packet_t packet; |
238 | packet_t packet; |
242 | 239 | ||
243 | /* |
240 | /* |
244 | * Accept the connection |
241 | * Accept the connection |
245 | * - Answer the first IPC_M_CONNECT_ME_TO call. |
242 | * - Answer the first IPC_M_CONNECT_ME_TO call. |
246 | */ |
243 | */ |
247 | ipc_answer_0( iid, EOK ); |
244 | ipc_answer_0( iid, EOK ); |
248 | 245 | ||
249 | while( true ){ |
246 | while( true ){ |
250 | /* // refresh data |
247 | /* // refresh data |
251 | count = 0; |
248 | count = 0; |
252 | IPC_SET_RETVAL( answer, 0 ); |
249 | IPC_SET_RETVAL( answer, 0 ); |
253 | // just to be precize |
250 | // just to be precize |
254 | IPC_SET_RETVAL( answer, 0 ); |
251 | IPC_SET_RETVAL( answer, 0 ); |
255 | IPC_SET_ARG1( answer, 0 ); |
252 | IPC_SET_ARG1( answer, 0 ); |
256 | IPC_SET_ARG2( answer, 0 ); |
253 | IPC_SET_ARG2( answer, 0 ); |
257 | IPC_SET_ARG3( answer, 0 ); |
254 | IPC_SET_ARG3( answer, 0 ); |
258 | IPC_SET_ARG4( answer, 0 ); |
255 | IPC_SET_ARG4( answer, 0 ); |
259 | IPC_SET_ARG5( answer, 0 ); |
256 | IPC_SET_ARG5( answer, 0 ); |
260 | */ |
257 | */ |
261 | callid = async_get_call( & call ); |
258 | callid = async_get_call( & call ); |
262 | switch( IPC_GET_METHOD( call )){ |
259 | switch( IPC_GET_METHOD( call )){ |
263 | case NET_IL_DEVICE_STATE: |
260 | case NET_IL_DEVICE_STATE: |
264 | case NET_NIL_DEVICE_STATE: |
261 | case NET_NIL_DEVICE_STATE: |
265 | result = ip_state_message( IPC_GET_DEVICE( & call ), IPC_GET_STATE( & call )); |
262 | result = ip_state_message( IPC_GET_DEVICE( & call ), IPC_GET_STATE( & call )); |
266 | ipc_answer_0( callid, result ); |
263 | ipc_answer_0( callid, result ); |
267 | // TODO packer received |
264 | // TODO packer received |
268 | case NET_IL_RECEIVED: |
265 | case NET_IL_RECEIVED: |
269 | case NET_NIL_RECEIVED: |
266 | case NET_NIL_RECEIVED: |
270 | if( ! ERROR_OCCURRED( result = packet_translate( ip_globals.networking_phone, & packet, IPC_GET_PACKET( & call )))){ |
267 | if( ! ERROR_OCCURRED( result = packet_translate( ip_globals.networking_phone, & packet, IPC_GET_PACKET( & call )))){ |
271 | //result = ip_receive_message( IPC_GET_DEVICE( call ), packet ); |
268 | //result = ip_receive_message( IPC_GET_DEVICE( call ), packet ); |
272 | } |
269 | } |
273 | ipc_answer_0( callid, result ); |
270 | ipc_answer_0( callid, result ); |
274 | } |
271 | } |
275 | } |
272 | } |
276 | } |
273 | } |
277 | 274 | ||
278 | int ip_state_message( device_id_t device_id, device_state_t state ){ |
275 | int ip_state_message( device_id_t device_id, device_state_t state ){ |
279 | ERROR_DECLARE; |
276 | ERROR_DECLARE; |
280 | 277 | ||
281 | ip_netif_ref netif; |
278 | ip_netif_ref netif; |
282 | 279 | ||
283 | aid_t message; |
280 | aid_t message; |
284 | ipc_call_t answer; |
281 | ipc_call_t answer; |
285 | measured_string_t address; |
282 | measured_string_t address; |
286 | measured_string_ref translation; |
283 | measured_string_ref translation; |
287 | char * data; |
284 | char * data; |
288 | ipcarg_t result; |
285 | ipcarg_t result; |
289 | 286 | ||
290 | netif = ip_netifs_find( & ip_globals.netifs, device_id ); |
287 | netif = ip_netifs_find( & ip_globals.netifs, device_id ); |
291 | if( ! netif ) return ENOENT; |
288 | if( ! netif ) return ENOENT; |
292 | // TODO state |
289 | // TODO state |
293 | printf( "\nip - device %d changed state to %d\n", device_id, state ); |
290 | printf( "\nip - device %d changed state to %d\n", device_id, state ); |
294 | if( netif->arp ){ |
291 | if( netif->arp ){ |
295 | message = async_send_2( netif->arp->phone, NET_ARP_TRANSLATE, netif->device_id, SERVICE_IP, & answer ); |
292 | message = async_send_2( netif->arp->phone, NET_ARP_TRANSLATE, netif->device_id, SERVICE_IP, & answer ); |
296 | address.value = ( char * ) & netif->gateway; |
293 | address.value = ( char * ) & netif->gateway; |
297 | address.length = CONVERT_SIZE( in_addr_t, char, 1 ); |
294 | address.length = CONVERT_SIZE( in_addr_t, char, 1 ); |
298 | if( ERROR_OCCURRED( measured_strings_send( netif->arp->phone, & address, 1 )) |
295 | if( ERROR_OCCURRED( measured_strings_send( netif->arp->phone, & address, 1 )) |
299 | || ERROR_OCCURRED( measured_strings_return( netif->arp->phone, & translation, & data, 1 ))){ |
296 | || ERROR_OCCURRED( measured_strings_return( netif->arp->phone, & translation, & data, 1 ))){ |
300 | async_wait_for( message, & result ); |
297 | async_wait_for( message, & result ); |
301 | return result; |
298 | return result; |
302 | } |
299 | } |
303 | async_wait_for( message, & result ); |
300 | async_wait_for( message, & result ); |
304 | if( ! ERROR_OCCURRED( result )){ |
301 | if( ! ERROR_OCCURRED( result )){ |
305 | printf( "\n\tgateway translated to\t= %X:%X:%X:%X:%X:%X", data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ] ); |
302 | printf( "\n\tgateway translated to\t= %X:%X:%X:%X:%X:%X", data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ] ); |
306 | } |
303 | } |
307 | free( translation ); |
304 | free( translation ); |
308 | free( data ); |
305 | free( data ); |
309 | return result; |
306 | return result; |
310 | } |
307 | } |
311 | return EOK; |
308 | return EOK; |
312 | } |
309 | } |
313 | 310 | ||
314 | int ip_register_message( int protocol, int phone ){ |
311 | int ip_register_message( int protocol, int phone ){ |
315 | ip_proto_ref proto; |
312 | ip_proto_ref proto; |
316 | int index; |
313 | int index; |
317 | 314 | ||
318 | proto = ( ip_proto_ref ) malloc( sizeof( ip_protos_t )); |
315 | proto = ( ip_proto_ref ) malloc( sizeof( ip_protos_t )); |
319 | if( ! proto ) return ENOMEM; |
316 | if( ! proto ) return ENOMEM; |
320 | proto->protocol = protocol; |
317 | proto->protocol = protocol; |
321 | proto->phone = phone; |
318 | proto->phone = phone; |
322 | index = ip_protos_add( & ip_globals.protos, proto->protocol, proto ); |
319 | index = ip_protos_add( & ip_globals.protos, proto->protocol, proto ); |
323 | if( index < 0 ){ |
320 | if( index < 0 ){ |
324 | free( proto ); |
321 | free( proto ); |
325 | return index; |
322 | return index; |
326 | } |
323 | } |
327 | printf( "\nNew protocol registered:\n\tprotocol\t= %d\n\tphone\t= %d", proto->protocol, proto->phone ); |
324 | printf( "\nNew protocol registered:\n\tprotocol\t= %d\n\tphone\t= %d", proto->protocol, proto->phone ); |
328 | return EOK; |
325 | return EOK; |
329 | } |
326 | } |
330 | 327 | ||
331 | int ip_send_message( device_id_t device_id, packet_t packet ){ |
328 | int ip_send_message( device_id_t device_id, packet_t packet ){ |
332 | // TODO send packet |
329 | // TODO send packet |
333 | printf( "Packet to send via %d: %s", device_id, packet_get_data( packet )); |
330 | printf( "Packet to send via %d: %s", device_id, packet_get_data( packet )); |
334 | pq_release( ip_globals.networking_phone, packet_get_id( packet )); |
331 | pq_release( ip_globals.networking_phone, packet_get_id( packet )); |
335 | return EOK; |
332 | return EOK; |
336 | } |
333 | } |
337 | 334 | ||
338 | int ip_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
335 | int ip_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
339 | ERROR_DECLARE; |
336 | ERROR_DECLARE; |
340 | 337 | ||
341 | packet_t packet; |
338 | packet_t packet; |
342 | 339 | ||
343 | * answer_count = 0; |
340 | * answer_count = 0; |
344 | switch( IPC_GET_METHOD( * call )){ |
341 | switch( IPC_GET_METHOD( * call )){ |
345 | case IPC_M_PHONE_HUNGUP: |
342 | case IPC_M_PHONE_HUNGUP: |
346 | return EOK; |
343 | return EOK; |
347 | case NET_IP_ECHO: |
344 | case NET_IP_ECHO: |
348 | * answer_count = 5; |
345 | * answer_count = 5; |
349 | return ip_echo_message( IPC_GET_ARG1( * call ), IPC_GET_ARG2( * call ), IPC_GET_ARG3( * call ), IPC_GET_ARG4( * call ), IPC_GET_ARG5( * call ), & IPC_GET_ARG1( * answer ), & IPC_GET_ARG2( * answer ), & IPC_GET_ARG3( * answer ), & IPC_GET_ARG4( * answer ), & IPC_GET_ARG5( * answer ) ); |
346 | return ip_echo_message( IPC_GET_ARG1( * call ), IPC_GET_ARG2( * call ), IPC_GET_ARG3( * call ), IPC_GET_ARG4( * call ), IPC_GET_ARG5( * call ), & IPC_GET_ARG1( * answer ), & IPC_GET_ARG2( * answer ), & IPC_GET_ARG3( * answer ), & IPC_GET_ARG4( * answer ), & IPC_GET_ARG5( * answer ) ); |
350 | case NET_IL_DEVICE: |
347 | case NET_IL_DEVICE: |
351 | return ip_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call )); |
348 | return ip_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call )); |
352 | case IPC_M_CONNECT_TO_ME: |
349 | case IPC_M_CONNECT_TO_ME: |
353 | return ip_register_message( IPC_GET_PROTO( call ), IPC_GET_PHONE( call )); |
350 | return ip_register_message( IPC_GET_PROTO( call ), IPC_GET_PHONE( call )); |
354 | case NET_IP_SEND: |
351 | case NET_IP_SEND: |
355 | ERROR_PROPAGATE( packet_translate( ip_globals.networking_phone, & packet, IPC_GET_PACKET( call ))); |
352 | ERROR_PROPAGATE( packet_translate( ip_globals.networking_phone, & packet, IPC_GET_PACKET( call ))); |
356 | return ip_send_message( IPC_GET_DEVICE( call ), packet ); |
353 | return ip_send_message( IPC_GET_DEVICE( call ), packet ); |
357 | } |
354 | } |
358 | return ENOTSUP; |
355 | return ENOTSUP; |
359 | } |
356 | } |
360 | 357 | ||
361 | /** @} |
358 | /** @} |
362 | */ |
359 | */ |
363 | 360 |