Subversion Repositories HelenOS

Rev

Rev 3991 | Rev 4192 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3991 Rev 4163
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 "../../netif/device.h"
49
#include "../../netif/device.h"
50
#include "../../structures/measured_strings.h"
50
#include "../../structures/measured_strings.h"
51
#include "../../structures/packet/packet_client.h"
51
#include "../../structures/packet/packet_client.h"
52
 
52
 
53
#include "ip.h"
53
#include "ip.h"
54
#include "ip_messages.h"
54
#include "ip_messages.h"
55
#include "ip_module.h"
55
#include "ip_module.h"
56
 
56
 
57
#define DEFAULT_IPV     4
57
#define DEFAULT_IPV     4
58
 
58
 
59
#define IPC_GET_DEVICE( call )      ( device_id_t ) IPC_GET_ARG1( * call )
59
#define IPC_GET_DEVICE( call )      ( device_id_t ) IPC_GET_ARG1( * call )
60
#define IPC_GET_PACKET( call )      ( packet_id_t ) IPC_GET_ARG1( * call )
60
#define IPC_GET_PACKET( call )      ( packet_id_t ) IPC_GET_ARG1( * call )
61
#define IPC_GET_PROTO( call )       ( int ) IPC_GET_ARG1( * call )
61
#define IPC_GET_PROTO( call )       ( int ) IPC_GET_ARG1( * call )
62
#define IPC_GET_SERVICE( call )     ( services_t ) IPC_GET_ARG2( * call )
62
#define IPC_GET_SERVICE( call )     ( services_t ) IPC_GET_ARG2( * call )
63
#define IPC_GET_STATE( call )       ( device_state_t ) IPC_GET_ARG2( * call )
63
#define IPC_GET_STATE( call )       ( device_state_t ) IPC_GET_ARG2( * call )
64
#define IPC_GET_PHONE( call )       ( int ) IPC_GET_ARG5( * call )
64
#define IPC_GET_PHONE( call )       ( int ) IPC_GET_ARG5( * call )
65
 
65
 
66
ip_globals_t    ip_globals;
66
ip_globals_t    ip_globals;
67
 
67
 
68
DEVICE_MAP_IMPLEMENT( ip_netifs, ip_netif_t )
68
DEVICE_MAP_IMPLEMENT( ip_netifs, ip_netif_t )
69
 
69
 
70
INT_MAP_IMPLEMENT( ip_protos, ip_proto_t )
70
INT_MAP_IMPLEMENT( ip_protos, ip_proto_t )
71
 
71
 
72
int ip_register_message( int protocol, int phone );
72
int ip_register_message( int protocol, int phone );
73
int ip_state_message( device_id_t device_id, device_state_t state );
73
int ip_state_message( device_id_t device_id, device_state_t state );
74
void    ip_driver_receiver( ipc_callid_t iid, ipc_call_t * icall );
74
void    ip_driver_receiver( ipc_callid_t iid, ipc_call_t * icall );
75
 
75
 
76
/** Initializes the module.
76
/** Initializes the module.
77
 */
77
 */
78
int ip_initialize( void ){
78
int ip_initialize( void ){
79
    ip_netifs_initialize( & ip_globals.netifs );
79
    ip_netifs_initialize( & ip_globals.netifs );
80
    ip_protos_initialize( & ip_globals.protos );
80
    ip_protos_initialize( & ip_globals.protos );
81
    return EOK;
81
    return EOK;
82
}
82
}
83
 
83
 
84
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 ){
84
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 ){
85
    if( answer1 ) * answer1 = arg1;
85
    if( answer1 ) * answer1 = arg1;
86
    if( answer2 ) * answer2 = arg2;
86
    if( answer2 ) * answer2 = arg2;
87
    if( answer3 ) * answer3 = arg3;
87
    if( answer3 ) * answer3 = arg3;
88
    if( answer4 ) * answer4 = arg4;
88
    if( answer4 ) * answer4 = arg4;
89
    if( answer5 ) * answer5 = arg5;
89
    if( answer5 ) * answer5 = arg5;
90
    return EOK;
90
    return EOK;
91
}
91
}
92
 
92
 
93
int ip_device_message( device_id_t device_id, services_t service ){
93
int ip_device_message( device_id_t device_id, services_t service ){
94
    ERROR_DECLARE;
94
    ERROR_DECLARE;
95
 
95
 
96
    ip_netif_ref        ip_netif;
96
    ip_netif_ref        ip_netif;
97
    aid_t           message;
97
    aid_t           message;
98
    ipc_call_t      answer;
98
    ipc_call_t      answer;
99
    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 }};
99
    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 }};
100
    int         count = 9;
100
    int         count = 9;
101
    measured_string_ref settings;
101
    measured_string_ref settings;
102
    char *          data;
102
    char *          data;
103
 
103
 
104
    ip_netif = ( ip_netif_ref ) malloc( sizeof( ip_netif_t ));
104
    ip_netif = ( ip_netif_ref ) malloc( sizeof( ip_netif_t ));
105
    if( ! ip_netif ) return ENOMEM;
105
    if( ! ip_netif ) return ENOMEM;
106
    ip_netif->device_id = device_id;
106
    ip_netif->device_id = device_id;
107
    // get configuration
107
    // get configuration
108
    // TODO mapping
108
    // TODO mapping
109
    message = async_send_2( ip_globals.networking_phone, NET_NET_GET_DEVICE_CONF, ip_netif->device_id, count, & answer );
109
    message = async_send_2( ip_globals.networking_phone, NET_NET_GET_DEVICE_CONF, ip_netif->device_id, count, & answer );
110
    // send names and get settings
110
    // send names and get settings
111
    if( ERROR_OCCURRED( measured_strings_send( ip_globals.networking_phone, configuration, count ))
111
    if( ERROR_OCCURRED( measured_strings_send( ip_globals.networking_phone, configuration, count ))
112
    || ERROR_OCCURRED( measured_strings_return( ip_globals.networking_phone, & settings, & data, count ))){
112
    || ERROR_OCCURRED( measured_strings_return( ip_globals.networking_phone, & settings, & data, count ))){
113
        async_wait_for( message, NULL );
113
        async_wait_for( message, NULL );
114
        return ERROR_CODE;
114
        return ERROR_CODE;
115
    }
115
    }
116
    if( settings ){
116
    if( settings ){
117
        if( settings[ 0 ].value ){
117
        if( settings[ 0 ].value ){
118
            ip_netif->ipv = strtol( settings[ 0 ].value, NULL, 0 );
118
            ip_netif->ipv = strtol( settings[ 0 ].value, NULL, 0 );
119
        }else{
119
        }else{
120
            ip_netif->ipv = DEFAULT_IPV;
120
            ip_netif->ipv = DEFAULT_IPV;
121
        }
121
        }
122
        ip_netif->dhcp = ! strcmp( settings[ 1 ].value, "DHCP" );
122
        ip_netif->dhcp = ! strcmp( settings[ 1 ].value, "DHCP" );
123
        if( ip_netif->dhcp ){
123
        if( ip_netif->dhcp ){
124
            // TODO dhcp
124
            // TODO dhcp
125
            free( ip_netif );
125
            free( ip_netif );
126
            return ENOTSUP;
126
            return ENOTSUP;
127
        }else if( ip_netif->ipv == 4 ){
127
        }else if( ip_netif->ipv == 4 ){
128
            if( ERROR_OCCURRED( inet_pton( AF_INET, settings[ 2 ].value, ( uint8_t * ) & ip_netif->address ))
128
            if( ERROR_OCCURRED( inet_pton( AF_INET, settings[ 2 ].value, ( uint8_t * ) & ip_netif->address ))
129
            || ERROR_OCCURRED( inet_pton( AF_INET, settings[ 3 ].value, ( uint8_t * ) & ip_netif->netmask ))
129
            || ERROR_OCCURRED( inet_pton( AF_INET, settings[ 3 ].value, ( uint8_t * ) & ip_netif->netmask ))
130
            || ( inet_pton( AF_INET, settings[ 4 ].value, ( uint8_t * ) & ip_netif->gateway ) == EINVAL )
130
            || ( inet_pton( AF_INET, settings[ 4 ].value, ( uint8_t * ) & ip_netif->gateway ) == EINVAL )
131
            || ( inet_pton( AF_INET, settings[ 5 ].value, ( uint8_t * ) & ip_netif->broadcast ) == EINVAL )
131
            || ( inet_pton( AF_INET, settings[ 5 ].value, ( uint8_t * ) & ip_netif->broadcast ) == EINVAL )
132
            || ( inet_pton( AF_INET, settings[ 6 ].value, ( uint8_t * ) & ip_netif->dns1 ) == EINVAL )
132
            || ( inet_pton( AF_INET, settings[ 6 ].value, ( uint8_t * ) & ip_netif->dns1 ) == EINVAL )
133
            || ( inet_pton( AF_INET, settings[ 7 ].value, ( uint8_t * ) & ip_netif->dns2 ) == EINVAL )){
133
            || ( inet_pton( AF_INET, settings[ 7 ].value, ( uint8_t * ) & ip_netif->dns2 ) == EINVAL )){
134
                free( ip_netif );
134
                free( ip_netif );
135
                return EINVAL;
135
                return EINVAL;
136
            }
136
            }
137
        }else{
137
        }else{
138
            // TODO ipv6
138
            // TODO ipv6
139
            free( ip_netif );
139
            free( ip_netif );
140
            return ENOTSUP;
140
            return ENOTSUP;
141
        }
141
        }
142
        // TODO ARP module
142
        // TODO ARP module
143
    }
143
    }
144
    // TODO arp module
144
    // TODO arp module
-
 
145
    // TODO register
145
    free( settings );
146
    free( settings );
146
    free( data );
147
    free( data );
147
    // end request
148
    // end request
148
    // TODO mapping
149
    // TODO mapping
149
    async_wait_for( message, NULL );
150
    async_wait_for( message, NULL );
150
    // print the settings
151
    // print the settings
151
    printf( "\n -IPV =\t%d", ip_netif->ipv );
152
    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 );
152
    printf( "\n -configuration =\t%s", ip_netif->dhcp ? "dhcp" : "static" );
153
    printf( "\n\tconfiguration\t= %s", ip_netif->dhcp ? "dhcp" : "static" );
153
    // TODO ipv6
154
    // TODO ipv6
154
    data = malloc( INET_ADDRSTRLEN );
155
    data = malloc( INET_ADDRSTRLEN );
155
    if( data ){
156
    if( data ){
156
        inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->address, data, INET_ADDRSTRLEN );
157
        inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->address, data, INET_ADDRSTRLEN );
157
        printf( "\n -address =\t%s", data );
158
        printf( "\n\taddress\t= %s", data );
158
        inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->netmask, data, INET_ADDRSTRLEN );
159
        inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->netmask, data, INET_ADDRSTRLEN );
159
        printf( "\n -netmask =\t%s", data );
160
        printf( "\n\tnetmask\t= %s", data );
160
        inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->gateway, data, INET_ADDRSTRLEN );
161
        inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->gateway, data, INET_ADDRSTRLEN );
161
        printf( "\n -gateway =\t%s", data );
162
        printf( "\n\tgateway\t= %s", data );
162
        inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->broadcast, data, INET_ADDRSTRLEN );
163
        inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->broadcast, data, INET_ADDRSTRLEN );
163
        printf( "\n -broadcast =\t%s", data );
164
        printf( "\n\tbroadcast\t= %s", data );
164
        inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns1, data, INET_ADDRSTRLEN );
165
        inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns1, data, INET_ADDRSTRLEN );
165
        printf( "\n -dns1 =\t%s", data );
166
        printf( "\n\tdns1\t= %s", data );
166
        inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns2, data, INET_ADDRSTRLEN );
167
        inet_ntop( AF_INET, ( uint8_t * ) & ip_netif->dns2, data, INET_ADDRSTRLEN );
167
        printf( "\n -dns2 =\t%s", data );
168
        printf( "\n\tdns2\t= %s", data );
168
        free( data );
169
        free( data );
169
    }
170
    }
170
    // TODO mapping
171
    // TODO mapping
171
    ip_netif->phone = bind_service( service, ip_netif->device_id, SERVICE_IP, 0, ip_driver_receiver );
172
    ip_netif->phone = bind_service( service, ip_netif->device_id, SERVICE_IP, 0, ip_driver_receiver );
172
    if( ERROR_OCCURRED( ip_netifs_add( & ip_globals.netifs, ip_netif->device_id, ip_netif ))){
173
    if( ERROR_OCCURRED( ip_netifs_add( & ip_globals.netifs, ip_netif->device_id, ip_netif ))){
173
        free( ip_netif );
174
        free( ip_netif );
174
        return ERROR_CODE;
175
        return ERROR_CODE;
175
    }
176
    }
176
    return EOK;
177
    return EOK;
177
}
178
}
178
 
179
 
179
void ip_driver_receiver( ipc_callid_t iid, ipc_call_t * icall ){
180
void ip_driver_receiver( ipc_callid_t iid, ipc_call_t * icall ){
180
    ERROR_DECLARE;
181
    ERROR_DECLARE;
181
 
182
 
182
    ipc_callid_t    callid;
183
    ipc_callid_t    callid;
183
    ipc_call_t  call;
184
    ipc_call_t  call;
184
//  ipc_call_t  answer;
185
//  ipc_call_t  answer;
185
//  int     count;
186
//  int     count;
186
    int     result;
187
    int     result;
187
    packet_t    packet;
188
    packet_t    packet;
188
 
189
 
189
    /*
190
    /*
190
     * Accept the connection
191
     * Accept the connection
191
     *  - Answer the first IPC_M_CONNECT_ME_TO call.
192
     *  - Answer the first IPC_M_CONNECT_ME_TO call.
192
     */
193
     */
193
    ipc_answer_0( iid, EOK );
194
    ipc_answer_0( iid, EOK );
194
 
195
 
195
    while( true ){
196
    while( true ){
196
/*      // refresh data
197
/*      // refresh data
197
        count = 0;
198
        count = 0;
198
        IPC_SET_RETVAL( answer, 0 );
199
        IPC_SET_RETVAL( answer, 0 );
199
        // just to be precize
200
        // just to be precize
200
        IPC_SET_RETVAL( answer, 0 );
201
        IPC_SET_RETVAL( answer, 0 );
201
        IPC_SET_ARG1( answer, 0 );
202
        IPC_SET_ARG1( answer, 0 );
202
        IPC_SET_ARG2( answer, 0 );
203
        IPC_SET_ARG2( answer, 0 );
203
        IPC_SET_ARG3( answer, 0 );
204
        IPC_SET_ARG3( answer, 0 );
204
        IPC_SET_ARG4( answer, 0 );
205
        IPC_SET_ARG4( answer, 0 );
205
        IPC_SET_ARG5( answer, 0 );
206
        IPC_SET_ARG5( answer, 0 );
206
*/
207
*/
207
        callid = async_get_call( & call );
208
        callid = async_get_call( & call );
208
        switch( IPC_GET_METHOD( call )){
209
        switch( IPC_GET_METHOD( call )){
209
            case NET_IL_DEVICE_STATE:
210
            case NET_IL_DEVICE_STATE:
210
            case NET_NIL_DEVICE_STATE:
211
            case NET_NIL_DEVICE_STATE:
211
                result = ip_state_message( IPC_GET_DEVICE( & call ), IPC_GET_STATE( & call ));
212
                result = ip_state_message( IPC_GET_DEVICE( & call ), IPC_GET_STATE( & call ));
212
                ipc_answer_0( callid, result );
213
                ipc_answer_0( callid, result );
213
            // TODO packer received
214
            // TODO packer received
214
            case NET_IL_RECEIVED:
215
            case NET_IL_RECEIVED:
215
            case NET_NIL_RECEIVED:
216
            case NET_NIL_RECEIVED:
216
                if( ! ERROR_OCCURRED( result = packet_translate( ip_globals.networking_phone, & packet, IPC_GET_PACKET( & call )))){
217
                if( ! ERROR_OCCURRED( result = packet_translate( ip_globals.networking_phone, & packet, IPC_GET_PACKET( & call )))){
217
                    //result = ip_receive_message( IPC_GET_DEVICE( call ), packet );
218
                    //result = ip_receive_message( IPC_GET_DEVICE( call ), packet );
218
                }
219
                }
219
                ipc_answer_0( callid, result );
220
                ipc_answer_0( callid, result );
220
        }
221
        }
221
    }
222
    }
222
}
223
}
223
 
224
 
224
int ip_state_message( device_id_t device_id, device_state_t state ){
225
int ip_state_message( device_id_t device_id, device_state_t state ){
225
    // TODO state
226
    // TODO state
226
    printf( "\nip - device %d changed state to %d\n", device_id, state );
227
    printf( "\nip - device %d changed state to %d\n", device_id, state );
227
    return EOK;
228
    return EOK;
228
}
229
}
229
 
230
 
230
int ip_register_message( int protocol, int phone ){
231
int ip_register_message( int protocol, int phone ){
231
    ERROR_DECLARE;
232
    ERROR_DECLARE;
232
 
233
 
233
    ip_proto_ref    proto;
234
    ip_proto_ref    proto;
234
 
235
 
235
    proto = ( ip_proto_ref ) malloc( sizeof( ip_protos_t ));
236
    proto = ( ip_proto_ref ) malloc( sizeof( ip_protos_t ));
236
    if( ! proto ) return ENOMEM;
237
    if( ! proto ) return ENOMEM;
237
    proto->protocol = protocol;
238
    proto->protocol = protocol;
238
    proto->phone = phone;
239
    proto->phone = phone;
239
    if( ERROR_OCCURRED( ip_protos_add( & ip_globals.protos, proto->protocol, proto ))){
240
    if( ERROR_OCCURRED( ip_protos_add( & ip_globals.protos, proto->protocol, proto ))){
240
        free( proto );
241
        free( proto );
241
        return ERROR_CODE;
242
        return ERROR_CODE;
242
    }
243
    }
-
 
244
    printf( "\nNew protocol registered:\n\tprotocol\t= %d\n\tphone\t= %d", proto->protocol, proto->phone );
243
    return EOK;
245
    return EOK;
244
}
246
}
245
 
247
 
246
int ip_send_message( device_id_t device_id, packet_t packet ){
248
int ip_send_message( device_id_t device_id, packet_t packet ){
247
    // TODO send packet
249
    // TODO send packet
248
    printf( "Packet to send via %d: %s", device_id, packet_get_data( packet ));
250
    printf( "Packet to send via %d: %s", device_id, packet_get_data( packet ));
249
    packet_release( ip_globals.networking_phone, packet_get_id( packet ));
251
    packet_release( ip_globals.networking_phone, packet_get_id( packet ));
250
    return EOK;
252
    return EOK;
251
}
253
}
252
 
254
 
253
int ip_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
255
int ip_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
254
    ERROR_DECLARE;
256
    ERROR_DECLARE;
255
 
257
 
256
    packet_t    packet;
258
    packet_t    packet;
257
 
259
 
258
    * answer_count = 0;
260
    * answer_count = 0;
259
    switch( IPC_GET_METHOD( * call )){
261
    switch( IPC_GET_METHOD( * call )){
260
        case IPC_M_PHONE_HUNGUP:
262
        case IPC_M_PHONE_HUNGUP:
261
            return EOK;
263
            return EOK;
262
        case NET_IP_ECHO:
264
        case NET_IP_ECHO:
263
            * answer_count = 5;
265
            * answer_count = 5;
264
            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 ) );
266
            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 ) );
265
        case NET_IL_DEVICE:
267
        case NET_IL_DEVICE:
266
            return ip_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ));
268
            return ip_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ));
267
        case IPC_M_CONNECT_TO_ME:
269
        case IPC_M_CONNECT_TO_ME:
268
            return ip_register_message( IPC_GET_PROTO( call ), IPC_GET_PHONE( call ));
270
            return ip_register_message( IPC_GET_PROTO( call ), IPC_GET_PHONE( call ));
269
        case NET_IP_SEND:
271
        case NET_IP_SEND:
270
            if( ERROR_OCCURRED( packet_translate( ip_globals.networking_phone, & packet, IPC_GET_PACKET( call )))){
272
            if( ERROR_OCCURRED( packet_translate( ip_globals.networking_phone, & packet, IPC_GET_PACKET( call )))){
271
                printf( "\nIP send E %d", ERROR_CODE );
273
                printf( "\nIP send E %d", ERROR_CODE );
272
                return ERROR_CODE;
274
                return ERROR_CODE;
273
            }
275
            }
274
            return ip_send_message( IPC_GET_DEVICE( call ), packet );
276
            return ip_send_message( IPC_GET_DEVICE( call ), packet );
275
    }
277
    }
276
    return ENOTSUP;
278
    return ENOTSUP;
277
}
279
}
278
 
280
 
279
/** @}
281
/** @}
280
 */
282
 */
281
 
283