Rev 4307 | Rev 4332 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4307 | Rev 4327 | ||
---|---|---|---|
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 | #include <string.h> |
|
39 | 40 | ||
40 | #include <ipc/ipc.h> |
41 | #include <ipc/ipc.h> |
41 | #include <ipc/services.h> |
42 | #include <ipc/services.h> |
42 | 43 | ||
43 | #include "../../err.h" |
44 | #include "../../err.h" |
44 | #include "../../messages.h" |
45 | #include "../../messages.h" |
45 | #include "../../modules.h" |
46 | #include "../../modules.h" |
46 | 47 | ||
47 | #include "../../include/net_interface.h" |
48 | #include "../../include/net_interface.h" |
48 | #include "../../include/sockaddr.h" |
49 | #include "../../include/sockaddr.h" |
49 | #include "../../include/socket.h" |
50 | #include "../../include/socket.h" |
50 | #include "../../include/device.h" |
51 | #include "../../include/device.h" |
51 | #include "../../include/arp_interface.h" |
52 | #include "../../include/arp_interface.h" |
52 | #include "../../include/nil_interface.h" |
53 | #include "../../include/nil_interface.h" |
53 | #include "../../include/il_interface.h" |
54 | #include "../../include/il_interface.h" |
54 | #include "../../include/ip_interface.h" |
55 | #include "../../include/ip_interface.h" |
55 | #include "../../structures/measured_strings.h" |
56 | #include "../../structures/measured_strings.h" |
56 | #include "../../structures/module_map.h" |
57 | #include "../../structures/module_map.h" |
57 | #include "../../structures/packet/packet_client.h" |
58 | #include "../../structures/packet/packet_client.h" |
58 | 59 | ||
59 | #include "../../nil/nil_messages.h" |
60 | #include "../../nil/nil_messages.h" |
60 | 61 | ||
61 | #include "../il_messages.h" |
62 | #include "../il_messages.h" |
62 | 63 | ||
63 | #include "ip.h" |
64 | #include "ip.h" |
64 | #include "ip_module.h" |
65 | #include "ip_module.h" |
65 | 66 | ||
66 | #define DEFAULT_IPV 4 |
67 | #define DEFAULT_IPV 4 |
67 | 68 | ||
68 | #define ARP_NAME "arp" |
69 | #define ARP_NAME "arp" |
69 | #define ARP_FILENAME "/srv/arp" |
70 | #define ARP_FILENAME "/srv/arp" |
70 | 71 | ||
71 | ip_globals_t ip_globals; |
72 | ip_globals_t ip_globals; |
72 | 73 | ||
73 | DEVICE_MAP_IMPLEMENT( ip_netifs, ip_netif_t ) |
74 | DEVICE_MAP_IMPLEMENT( ip_netifs, ip_netif_t ) |
74 | 75 | ||
75 | INT_MAP_IMPLEMENT( ip_protos, ip_proto_t ) |
76 | INT_MAP_IMPLEMENT( ip_protos, ip_proto_t ) |
76 | 77 | ||
77 | void ip_driver_receiver( ipc_callid_t iid, ipc_call_t * icall ); |
78 | void ip_driver_receiver( ipc_callid_t iid, ipc_call_t * icall ); |
78 | int ip_device_state_msg( int il_phone, device_id_t device_id, device_state_t state ); |
79 | int ip_device_state_msg( int il_phone, device_id_t device_id, device_state_t state ); |
79 | int ip_register( int il_phone, int protocol, int phone ); |
80 | int ip_register( int il_phone, int protocol, int phone ); |
80 | 81 | ||
81 | /** Initializes the module. |
82 | /** Initializes the module. |
82 | */ |
83 | */ |
83 | int ip_initialize( void ){ |
84 | int ip_initialize( void ){ |
84 | ERROR_DECLARE; |
85 | ERROR_DECLARE; |
85 | 86 | ||
86 | ERROR_PROPAGATE( ip_netifs_initialize( & ip_globals.netifs )); |
87 | ERROR_PROPAGATE( ip_netifs_initialize( & ip_globals.netifs )); |
87 | ERROR_PROPAGATE( ip_protos_initialize( & ip_globals.protos )); |
88 | ERROR_PROPAGATE( ip_protos_initialize( & ip_globals.protos )); |
88 | ERROR_PROPAGATE( modules_initialize( & ip_globals.modules )); |
89 | ERROR_PROPAGATE( modules_initialize( & ip_globals.modules )); |
89 | ERROR_PROPAGATE( add_module( NULL, & ip_globals.modules, ARP_NAME, ARP_FILENAME, SERVICE_ARP, arp_task_get_id(), arp_connect_module )); |
90 | ERROR_PROPAGATE( add_module( NULL, & ip_globals.modules, ARP_NAME, ARP_FILENAME, SERVICE_ARP, arp_task_get_id(), arp_connect_module )); |
90 | return EOK; |
91 | return EOK; |
91 | } |
92 | } |
92 | 93 | ||
93 | int ip_device_req( int il_phone, device_id_t device_id, services_t service ){ |
94 | int ip_device_req( int il_phone, device_id_t device_id, services_t service ){ |
94 | ERROR_DECLARE; |
95 | ERROR_DECLARE; |
95 | 96 | ||
96 | ip_netif_ref ip_netif; |
97 | ip_netif_ref ip_netif; |
97 | measured_string_t names[ 9 ] = {{ "IPV", 3 }, { "IP_CONFIG", 9 }, { "IP_ADDR", 7 }, { "NETMASK", 7 }, { "GATEWAY", 7 }, { "BROADCAST", 9 }, { "DNS1", 4 }, { "DNS2", 4 }, { "ARP", 3 }}; |
98 | measured_string_t names[ 9 ] = {{ "IPV", 3 }, { "IP_CONFIG", 9 }, { "IP_ADDR", 7 }, { "NETMASK", 7 }, { "GATEWAY", 7 }, { "BROADCAST", 9 }, { "DNS1", 4 }, { "DNS2", 4 }, { "ARP", 3 }}; |
98 | measured_string_ref configuration; |
99 | measured_string_ref configuration; |
99 | int count = 9; |
100 | int count = 9; |
100 | char * data; |
101 | char * data; |
101 | int index; |
102 | int index; |
102 | 103 | ||
103 | configuration = & names[ 0 ]; |
104 | configuration = & names[ 0 ]; |
104 | ip_netif = ( ip_netif_ref ) malloc( sizeof( ip_netif_t )); |
105 | ip_netif = ( ip_netif_ref ) malloc( sizeof( ip_netif_t )); |
105 | if( ! ip_netif ) return ENOMEM; |
106 | if( ! ip_netif ) return ENOMEM; |
106 | ip_netif->device_id = device_id; |
107 | ip_netif->device_id = device_id; |
107 | // get configuration |
108 | // get configuration |
108 | ERROR_PROPAGATE( net_get_device_conf_req( ip_globals.net_phone, ip_netif->device_id, & configuration, count, & data )); |
109 | ERROR_PROPAGATE( net_get_device_conf_req( ip_globals.net_phone, ip_netif->device_id, & configuration, count, & data )); |
109 | if( configuration ){ |
110 | if( configuration ){ |
110 | if( configuration[ 0 ].value ){ |
111 | if( configuration[ 0 ].value ){ |
111 | ip_netif->ipv = strtol( configuration[ 0 ].value, NULL, 0 ); |
112 | ip_netif->ipv = strtol( configuration[ 0 ].value, NULL, 0 ); |
112 | }else{ |
113 | }else{ |
113 | ip_netif->ipv = DEFAULT_IPV; |
114 | ip_netif->ipv = DEFAULT_IPV; |
114 | } |
115 | } |
115 | ip_netif->dhcp = ! strncmp( configuration[ 1 ].value, "dhcp", 4 ); |
116 | ip_netif->dhcp = ! str_lcmp( configuration[ 1 ].value, "dhcp", 4 ); |
116 | if( ip_netif->dhcp ){ |
117 | if( ip_netif->dhcp ){ |
117 | // TODO dhcp |
118 | // TODO dhcp |
118 | net_free_settings( configuration, data ); |
119 | net_free_settings( configuration, data ); |
119 | free( ip_netif ); |
120 | free( ip_netif ); |
120 | return ENOTSUP; |
121 | return ENOTSUP; |
121 | }else if( ip_netif->ipv == 4 ){ |
122 | }else if( ip_netif->ipv == 4 ){ |
122 | if( ERROR_OCCURRED( inet_pton( AF_INET, configuration[ 2 ].value, ( uint8_t * ) & ip_netif->address )) |
123 | if( ERROR_OCCURRED( inet_pton( AF_INET, configuration[ 2 ].value, ( uint8_t * ) & ip_netif->address )) |
123 | || ERROR_OCCURRED( inet_pton( AF_INET, configuration[ 3 ].value, ( uint8_t * ) & ip_netif->netmask )) |
124 | || ERROR_OCCURRED( inet_pton( AF_INET, configuration[ 3 ].value, ( uint8_t * ) & ip_netif->netmask )) |
124 | || ( inet_pton( AF_INET, configuration[ 4 ].value, ( uint8_t * ) & ip_netif->gateway ) == EINVAL ) |
125 | || ( inet_pton( AF_INET, configuration[ 4 ].value, ( uint8_t * ) & ip_netif->gateway ) == EINVAL ) |
125 | || ( inet_pton( AF_INET, configuration[ 5 ].value, ( uint8_t * ) & ip_netif->broadcast ) == EINVAL ) |
126 | || ( inet_pton( AF_INET, configuration[ 5 ].value, ( uint8_t * ) & ip_netif->broadcast ) == EINVAL ) |
126 | || ( inet_pton( AF_INET, configuration[ 6 ].value, ( uint8_t * ) & ip_netif->dns1 ) == EINVAL ) |
127 | || ( inet_pton( AF_INET, configuration[ 6 ].value, ( uint8_t * ) & ip_netif->dns1 ) == EINVAL ) |
127 | || ( inet_pton( AF_INET, configuration[ 7 ].value, ( uint8_t * ) & ip_netif->dns2 ) == EINVAL )){ |
128 | || ( inet_pton( AF_INET, configuration[ 7 ].value, ( uint8_t * ) & ip_netif->dns2 ) == EINVAL )){ |
128 | net_free_settings( configuration, data ); |
129 | net_free_settings( configuration, data ); |
129 | free( ip_netif ); |
130 | free( ip_netif ); |
130 | return EINVAL; |
131 | return EINVAL; |
131 | } |
132 | } |
132 | }else{ |
133 | }else{ |
133 | // TODO ipv6 |
134 | // TODO ipv6 |
134 | net_free_settings( configuration, data ); |
135 | net_free_settings( configuration, data ); |
135 | free( ip_netif ); |
136 | free( ip_netif ); |
136 | return ENOTSUP; |
137 | return ENOTSUP; |
137 | } |
138 | } |
138 | if( configuration[ 8 ].value ){ |
139 | if( configuration[ 8 ].value ){ |
139 | ip_netif->arp = get_running_module( & ip_globals.modules, configuration[ 8 ].value ); |
140 | ip_netif->arp = get_running_module( & ip_globals.modules, configuration[ 8 ].value ); |
140 | if( ! ip_netif->arp ){ |
141 | if( ! ip_netif->arp ){ |
141 | printf( "Failed to start the arp %s\n", configuration[ 8 ].value ); |
142 | printf( "Failed to start the arp %s\n", configuration[ 8 ].value ); |
142 | net_free_settings( configuration, data ); |
143 | net_free_settings( configuration, data ); |
143 | free( ip_netif ); |
144 | free( ip_netif ); |
144 | return EINVAL; |
145 | return EINVAL; |
145 | } |
146 | } |
146 | }else{ |
147 | }else{ |
147 | ip_netif->arp = NULL; |
148 | ip_netif->arp = NULL; |
148 | } |
149 | } |
149 | net_free_settings( configuration, data ); |
150 | net_free_settings( configuration, data ); |
150 | } |
151 | } |
151 | ip_netif->phone = bind_service( service, ip_netif->device_id, SERVICE_IP, 0, ip_driver_receiver ); |
152 | ip_netif->phone = bind_service( service, ip_netif->device_id, SERVICE_IP, 0, ip_driver_receiver ); |
152 | if( ip_netif->phone < 0 ){ |
153 | if( ip_netif->phone < 0 ){ |
153 | printf( "Failed to contact the nil service %d\n", service ); |
154 | printf( "Failed to contact the nil service %d\n", service ); |
154 | free( ip_netif ); |
155 | free( ip_netif ); |
155 | return ip_netif->phone; |
156 | return ip_netif->phone; |
156 | } |
157 | } |
157 | if( ip_netif->arp ){ |
158 | if( ip_netif->arp ){ |
158 | configuration[ 0 ].value = ( char * ) & ip_netif->address; |
159 | configuration[ 0 ].value = ( char * ) & ip_netif->address; |
159 | configuration[ 0 ].length = CONVERT_SIZE( in_addr_t, char, 1 ); |
160 | configuration[ 0 ].length = CONVERT_SIZE( in_addr_t, char, 1 ); |
160 | if( ERROR_OCCURRED( arp_device_req( ip_netif->arp->phone, ip_netif->device_id, SERVICE_IP, service, & configuration[ 0 ] ))){ |
161 | if( ERROR_OCCURRED( arp_device_req( ip_netif->arp->phone, ip_netif->device_id, SERVICE_IP, service, & configuration[ 0 ] ))){ |
161 | free( ip_netif ); |
162 | free( ip_netif ); |
162 | return ERROR_CODE; |
163 | return ERROR_CODE; |
163 | } |
164 | } |
164 | } |
165 | } |
165 | index = ip_netifs_add( & ip_globals.netifs, ip_netif->device_id, ip_netif ); |
166 | index = ip_netifs_add( & ip_globals.netifs, ip_netif->device_id, ip_netif ); |
166 | if( index < 0 ){ |
167 | if( index < 0 ){ |
167 | free( ip_netif ); |
168 | free( ip_netif ); |
168 | return index; |
169 | return index; |
169 | } |
170 | } |
170 | if( ip_netif->arp ) ++ ip_netif->arp->usage; |
171 | if( ip_netif->arp ) ++ ip_netif->arp->usage; |
171 | // print the settings |
172 | // print the settings |
172 | printf( "New device registered:\n\tid\t= %d\n\tphone\t= %d\n\tIPV\t= %d\n", ip_netif->device_id, ip_netif->phone, ip_netif->ipv ); |
173 | printf( "New device registered:\n\tid\t= %d\n\tphone\t= %d\n\tIPV\t= %d\n", ip_netif->device_id, ip_netif->phone, ip_netif->ipv ); |
173 | printf( "\tconfiguration\t= %s\n", ip_netif->dhcp ? "dhcp" : "static" ); |
174 | printf( "\tconfiguration\t= %s\n", ip_netif->dhcp ? "dhcp" : "static" ); |
174 | // TODO ipv6 addresses |
175 | // TODO ipv6 addresses |
175 | data = malloc( INET_ADDRSTRLEN ); |
176 | data = malloc( INET_ADDRSTRLEN ); |
176 | if( data ){ |
177 | if( data ){ |
177 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->address, data, INET_ADDRSTRLEN ); |
178 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->address, data, INET_ADDRSTRLEN ); |
178 | printf( "\taddress\t= %s\n", data ); |
179 | printf( "\taddress\t= %s\n", data ); |
179 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->netmask, data, INET_ADDRSTRLEN ); |
180 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->netmask, data, INET_ADDRSTRLEN ); |
180 | printf( "\tnetmask\t= %s\n", data ); |
181 | printf( "\tnetmask\t= %s\n", data ); |
181 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->gateway, data, INET_ADDRSTRLEN ); |
182 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->gateway, data, INET_ADDRSTRLEN ); |
182 | printf( "\tgateway\t= %s\n", data ); |
183 | printf( "\tgateway\t= %s\n", data ); |
183 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->broadcast, data, INET_ADDRSTRLEN ); |
184 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->broadcast, data, INET_ADDRSTRLEN ); |
184 | printf( "\tbroadcast\t= %s\n", data ); |
185 | printf( "\tbroadcast\t= %s\n", data ); |
185 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns1, data, INET_ADDRSTRLEN ); |
186 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns1, data, INET_ADDRSTRLEN ); |
186 | printf( "\tdns1\t= %s\n", data ); |
187 | printf( "\tdns1\t= %s\n", data ); |
187 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns2, data, INET_ADDRSTRLEN ); |
188 | inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns2, data, INET_ADDRSTRLEN ); |
188 | printf( "\tdns2\t= %s\n", data ); |
189 | printf( "\tdns2\t= %s\n", data ); |
189 | free( data ); |
190 | free( data ); |
190 | } |
191 | } |
191 | return EOK; |
192 | return EOK; |
192 | } |
193 | } |
193 | 194 | ||
194 | void ip_driver_receiver( ipc_callid_t iid, ipc_call_t * icall ){ |
195 | void ip_driver_receiver( ipc_callid_t iid, ipc_call_t * icall ){ |
195 | ERROR_DECLARE; |
196 | ERROR_DECLARE; |
196 | 197 | ||
197 | ipc_callid_t callid; |
198 | ipc_callid_t callid; |
198 | ipc_call_t call; |
199 | ipc_call_t call; |
199 | // ipc_call_t answer; |
200 | // ipc_call_t answer; |
200 | // int count; |
201 | // int count; |
201 | int result; |
202 | int result; |
202 | packet_t packet; |
203 | packet_t packet; |
203 | 204 | ||
204 | /* |
205 | /* |
205 | * Accept the connection |
206 | * Accept the connection |
206 | * - Answer the first IPC_M_CONNECT_ME_TO call. |
207 | * - Answer the first IPC_M_CONNECT_ME_TO call. |
207 | */ |
208 | */ |
208 | ipc_answer_0( iid, EOK ); |
209 | ipc_answer_0( iid, EOK ); |
209 | 210 | ||
210 | while( true ){ |
211 | while( true ){ |
211 | /* // refresh data |
212 | /* // refresh data |
212 | count = 0; |
213 | count = 0; |
213 | IPC_SET_RETVAL( answer, 0 ); |
214 | IPC_SET_RETVAL( answer, 0 ); |
214 | // just to be precize |
215 | // just to be precize |
215 | IPC_SET_RETVAL( answer, 0 ); |
216 | IPC_SET_RETVAL( answer, 0 ); |
216 | IPC_SET_ARG1( answer, 0 ); |
217 | IPC_SET_ARG1( answer, 0 ); |
217 | IPC_SET_ARG2( answer, 0 ); |
218 | IPC_SET_ARG2( answer, 0 ); |
218 | IPC_SET_ARG3( answer, 0 ); |
219 | IPC_SET_ARG3( answer, 0 ); |
219 | IPC_SET_ARG4( answer, 0 ); |
220 | IPC_SET_ARG4( answer, 0 ); |
220 | IPC_SET_ARG5( answer, 0 ); |
221 | IPC_SET_ARG5( answer, 0 ); |
221 | */ |
222 | */ |
222 | callid = async_get_call( & call ); |
223 | callid = async_get_call( & call ); |
223 | switch( IPC_GET_METHOD( call )){ |
224 | switch( IPC_GET_METHOD( call )){ |
224 | case NET_IL_DEVICE_STATE: |
225 | case NET_IL_DEVICE_STATE: |
225 | case NET_NIL_DEVICE_STATE: |
226 | case NET_NIL_DEVICE_STATE: |
226 | result = ip_device_state_msg( 0, IPC_GET_DEVICE( & call ), IPC_GET_STATE( & call )); |
227 | result = ip_device_state_msg( 0, IPC_GET_DEVICE( & call ), IPC_GET_STATE( & call )); |
227 | ipc_answer_0( callid, result ); |
228 | ipc_answer_0( callid, result ); |
228 | break; |
229 | break; |
229 | // TODO packer received |
230 | // TODO packer received |
230 | case NET_IL_RECEIVED: |
231 | case NET_IL_RECEIVED: |
231 | case NET_NIL_RECEIVED: |
232 | case NET_NIL_RECEIVED: |
232 | if( ! ERROR_OCCURRED( result = packet_translate( ip_globals.net_phone, & packet, IPC_GET_PACKET( & call )))){ |
233 | if( ! ERROR_OCCURRED( result = packet_translate( ip_globals.net_phone, & packet, IPC_GET_PACKET( & call )))){ |
233 | //result = il_receive_msg( 0, IPC_GET_DEVICE( call ), packet ); |
234 | //result = il_receive_msg( 0, IPC_GET_DEVICE( call ), packet ); |
234 | } |
235 | } |
235 | ipc_answer_0( callid, result ); |
236 | ipc_answer_0( callid, result ); |
236 | break; |
237 | break; |
237 | } |
238 | } |
238 | } |
239 | } |
239 | } |
240 | } |
240 | 241 | ||
241 | int ip_device_state_msg( int il_phone, device_id_t device_id, device_state_t state ){ |
242 | int ip_device_state_msg( int il_phone, device_id_t device_id, device_state_t state ){ |
242 | ERROR_DECLARE; |
243 | ERROR_DECLARE; |
243 | 244 | ||
244 | ip_netif_ref netif; |
245 | ip_netif_ref netif; |
245 | 246 | ||
246 | measured_string_t address; |
247 | measured_string_t address; |
247 | measured_string_ref translation; |
248 | measured_string_ref translation; |
248 | char * data; |
249 | char * data; |
249 | 250 | ||
250 | netif = ip_netifs_find( & ip_globals.netifs, device_id ); |
251 | netif = ip_netifs_find( & ip_globals.netifs, device_id ); |
251 | if( ! netif ) return ENOENT; |
252 | if( ! netif ) return ENOENT; |
252 | // TODO state |
253 | // TODO state |
253 | printf( "ip - device %d changed state to %d\n\n", device_id, state ); |
254 | printf( "ip - device %d changed state to %d\n\n", device_id, state ); |
254 | if( netif->arp ){ |
255 | if( netif->arp ){ |
255 | address.value = ( char * ) & netif->gateway; |
256 | address.value = ( char * ) & netif->gateway; |
256 | address.length = CONVERT_SIZE( in_addr_t, char, 1 ); |
257 | address.length = CONVERT_SIZE( in_addr_t, char, 1 ); |
- | 258 | if( ERROR_OCCURRED( arp_translate_req( netif->arp->phone, netif->device_id, SERVICE_IP, & address, & translation, & data ))){ |
|
- | 259 | sleep( 2 ); |
|
257 | ERROR_PROPAGATE( arp_translate_req( netif->arp->phone, netif->device_id, SERVICE_IP, & address, & translation, & data )); |
260 | ERROR_PROPAGATE( arp_translate_req( netif->arp->phone, netif->device_id, SERVICE_IP, & address, & translation, & data )); |
- | 261 | } |
|
258 | printf( "\tgateway translated to\t= %X:%X:%X:%X:%X:%X\n", data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ] ); |
262 | printf( "\tgateway translated to\t= %X:%X:%X:%X:%X:%X\n", data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ] ); |
259 | free( translation ); |
263 | free( translation ); |
260 | free( data ); |
264 | free( data ); |
261 | } |
265 | } |
262 | return EOK; |
266 | return EOK; |
263 | } |
267 | } |
264 | 268 | ||
265 | int ip_bind_service( services_t service, services_t me, async_client_conn_t receiver ){ |
269 | int ip_bind_service( services_t service, services_t me, async_client_conn_t receiver ){ |
266 | //TODO receive function |
270 | //TODO receive function |
267 | return EOK; |
271 | return EOK; |
268 | } |
272 | } |
269 | 273 | ||
270 | int ip_connect_module( services_t service ){ |
274 | int ip_connect_module( services_t service ){ |
271 | return EOK; |
275 | return EOK; |
272 | } |
276 | } |
273 | 277 | ||
274 | int ip_register( int il_phone, int protocol, int phone ){ |
278 | int ip_register( int il_phone, int protocol, int phone ){ |
275 | ip_proto_ref proto; |
279 | ip_proto_ref proto; |
276 | int index; |
280 | int index; |
277 | 281 | ||
278 | proto = ( ip_proto_ref ) malloc( sizeof( ip_protos_t )); |
282 | proto = ( ip_proto_ref ) malloc( sizeof( ip_protos_t )); |
279 | if( ! proto ) return ENOMEM; |
283 | if( ! proto ) return ENOMEM; |
280 | proto->protocol = protocol; |
284 | proto->protocol = protocol; |
281 | proto->phone = phone; |
285 | proto->phone = phone; |
282 | index = ip_protos_add( & ip_globals.protos, proto->protocol, proto ); |
286 | index = ip_protos_add( & ip_globals.protos, proto->protocol, proto ); |
283 | if( index < 0 ){ |
287 | if( index < 0 ){ |
284 | free( proto ); |
288 | free( proto ); |
285 | return index; |
289 | return index; |
286 | } |
290 | } |
287 | printf( "New protocol registered:\n\tprotocol\t= %d\n\tphone\t= %d\n", proto->protocol, proto->phone ); |
291 | printf( "New protocol registered:\n\tprotocol\t= %d\n\tphone\t= %d\n", proto->protocol, proto->phone ); |
288 | return EOK; |
292 | return EOK; |
289 | } |
293 | } |
290 | 294 | ||
291 | int ip_send_msg( int il_phone, device_id_t device_id, packet_t packet, services_t target ){ |
295 | int ip_send_msg( int il_phone, device_id_t device_id, packet_t packet, services_t target ){ |
292 | // TODO send packet |
296 | // TODO send packet |
293 | printf( "Packet to send via %d: %s\n", device_id, packet_get_data( packet )); |
297 | printf( "Packet to send via %d: %s\n", device_id, packet_get_data( packet )); |
294 | pq_release( ip_globals.net_phone, packet_get_id( packet )); |
298 | pq_release( ip_globals.net_phone, packet_get_id( packet )); |
295 | return EOK; |
299 | return EOK; |
296 | } |
300 | } |
297 | 301 | ||
298 | int ip_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
302 | int ip_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
299 | ERROR_DECLARE; |
303 | ERROR_DECLARE; |
300 | 304 | ||
301 | packet_t packet; |
305 | packet_t packet; |
302 | 306 | ||
303 | * answer_count = 0; |
307 | * answer_count = 0; |
304 | switch( IPC_GET_METHOD( * call )){ |
308 | switch( IPC_GET_METHOD( * call )){ |
305 | case IPC_M_PHONE_HUNGUP: |
309 | case IPC_M_PHONE_HUNGUP: |
306 | return EOK; |
310 | return EOK; |
307 | case NET_IL_DEVICE: |
311 | case NET_IL_DEVICE: |
308 | return ip_device_req( 0, IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call )); |
312 | return ip_device_req( 0, IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call )); |
309 | case IPC_M_CONNECT_TO_ME: |
313 | case IPC_M_CONNECT_TO_ME: |
310 | return ip_register( 0, IL_GET_PROTO( call ), IPC_GET_PHONE( call )); |
314 | return ip_register( 0, IL_GET_PROTO( call ), IPC_GET_PHONE( call )); |
311 | case NET_IL_SEND: |
315 | case NET_IL_SEND: |
312 | ERROR_PROPAGATE( packet_translate( ip_globals.net_phone, & packet, IPC_GET_PACKET( call ))); |
316 | ERROR_PROPAGATE( packet_translate( ip_globals.net_phone, & packet, IPC_GET_PACKET( call ))); |
313 | return ip_send_msg( 0, IPC_GET_DEVICE( call ), packet, 0 ); |
317 | return ip_send_msg( 0, IPC_GET_DEVICE( call ), packet, 0 ); |
314 | } |
318 | } |
315 | return ENOTSUP; |
319 | return ENOTSUP; |
316 | } |
320 | } |
317 | 321 | ||
318 | /** @} |
322 | /** @} |
319 | */ |
323 | */ |
320 | 324 |