Subversion Repositories HelenOS

Rev

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

Rev 4574 Rev 4695
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 net
29
/** @addtogroup net
30
 *  @{
30
 *  @{
31
 */
31
 */
32
 
32
 
33
/** @file
33
/** @file
34
 *  Wrapper for the bundled networking and TCP/IP stact modules.
34
 *  Wrapper for the bundled networking and TCP/IP stact modules.
35
 *  Distributes messages and initializes all module parts.
35
 *  Distributes messages and initializes all module parts.
36
 */
36
 */
37
 
37
 
38
#include <stdio.h>
38
#include <string.h>
39
 
39
 
40
#include <ipc/ipc.h>
40
#include <ipc/ipc.h>
41
 
41
 
42
#include "../messages.h"
42
#include "../messages.h"
43
 
43
 
44
#include "../include/ip_interface.h"
44
#include "../include/ip_interface.h"
45
 
45
 
46
#include "../structures/measured_strings.h"
46
#include "../structures/measured_strings.h"
47
#include "../structures/module_map.h"
47
#include "../structures/module_map.h"
48
#include "../structures/packet/packet_server.h"
48
#include "../structures/packet/packet_server.h"
49
 
49
 
50
#include "../il/arp/arp_module.h"
50
#include "../il/arp/arp_module.h"
51
#include "../il/ip/ip_module.h"
51
#include "../il/ip/ip_module.h"
52
#include "../tl/udp/udp_module.h"
52
#include "../tl/udp/udp_module.h"
53
#include "../tl/tcp/tcp_module.h"
53
#include "../tl/tcp/tcp_module.h"
54
 
54
 
55
#include "net.h"
55
#include "net.h"
56
 
56
 
57
/** Networking module global data.
57
/** Networking module global data.
58
 */
58
 */
59
extern net_globals_t    net_globals;
59
extern net_globals_t    net_globals;
60
 
60
 
61
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
61
int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){
62
    if(( IPC_GET_METHOD( * call ) == IPC_M_CONNECT_TO_ME )
62
    if(( IPC_GET_METHOD( * call ) == IPC_M_CONNECT_TO_ME )
63
    || IS_NET_IL_MESSAGE( call )
63
    || IS_NET_IL_MESSAGE( call )
64
    || IS_NET_TL_MESSAGE( call )
64
    || IS_NET_TL_MESSAGE( call )
65
    || IS_NET_SOCKET_MESSAGE( call )){
65
    || IS_NET_SOCKET_MESSAGE( call )){
66
        switch( IPC_GET_TARGET( call )){
66
        switch( IPC_GET_TARGET( call )){
67
            case SERVICE_IP:
67
            case SERVICE_IP:
68
                return ip_message( callid, call, answer, answer_count );
68
                return ip_message( callid, call, answer, answer_count );
69
            case SERVICE_ARP:
69
            case SERVICE_ARP:
70
                return arp_message( callid, call, answer, answer_count );
70
                return arp_message( callid, call, answer, answer_count );
71
            case SERVICE_UDP:
71
            case SERVICE_UDP:
72
                return udp_message( callid, call, answer, answer_count );
72
                return udp_message( callid, call, answer, answer_count );
73
            case SERVICE_TCP:
73
            case SERVICE_TCP:
74
                return tcp_message( callid, call, answer, answer_count );
74
                return tcp_message( callid, call, answer, answer_count );
75
            default:
75
            default:
76
                return EINVAL;
76
                return EINVAL;
77
        }
77
        }
78
    }else if( IS_NET_IP_MESSAGE( call ) || IS_NET_NIL_MESSAGE( call )){
78
    }else if( IS_NET_IP_MESSAGE( call )){
79
        return ip_message( callid, call, answer, answer_count );
79
        return ip_message( callid, call, answer, answer_count );
80
    }else if( IS_NET_ARP_MESSAGE( call )){
80
    }else if( IS_NET_ARP_MESSAGE( call )){
81
        return arp_message( callid, call, answer, answer_count );
81
        return arp_message( callid, call, answer, answer_count );
82
/*  }else if( IS_NET_RARP_MESSAGE( call )){
82
/*  }else if( IS_NET_RARP_MESSAGE( call )){
83
        return rarp_message( callid, call, answer, answer_count );
83
        return rarp_message( callid, call, answer, answer_count );
84
    }else if( IS_NET_ICMP_MESSAGE( call )){
84
    }else if( IS_NET_ICMP_MESSAGE( call )){
85
        return icmp_message( callid, call, answer, answer_count );
85
        return icmp_message( callid, call, answer, answer_count );
86
*/  }else if( IS_NET_UDP_MESSAGE( call )){
86
*/  }else if( IS_NET_UDP_MESSAGE( call )){
87
        return udp_message( callid, call, answer, answer_count );
87
        return udp_message( callid, call, answer, answer_count );
88
    }else if( IS_NET_TCP_MESSAGE( call )){
88
    }else if( IS_NET_TCP_MESSAGE( call )){
89
        return tcp_message( callid, call, answer, answer_count );
89
        return tcp_message( callid, call, answer, answer_count );
90
    }else{
90
    }else{
91
        if( IS_NET_PACKET_MESSAGE( call )){
91
        if( IS_NET_PACKET_MESSAGE( call )){
92
            return packet_server_message( callid, call, answer, answer_count );
92
            return packet_server_message( callid, call, answer, answer_count );
93
        }else{
93
        }else{
94
            return net_message( callid, call, answer, answer_count );
94
            return net_message( callid, call, answer, answer_count );
95
        }
95
        }
96
    }
96
    }
97
}
97
}
98
 
98
 
99
int net_initialize( async_client_conn_t client_connection ){
99
int net_initialize( async_client_conn_t client_connection ){
100
    ERROR_DECLARE;
100
    ERROR_DECLARE;
101
 
101
 
102
    ipcarg_t    phonehash;
102
    ipcarg_t    phonehash;
103
 
103
 
104
    netifs_initialize( & net_globals.netifs );
104
    netifs_initialize( & net_globals.netifs );
105
    char_map_initialize( & net_globals.netif_names );
105
    char_map_initialize( & net_globals.netif_names );
106
    modules_initialize( & net_globals.modules );
106
    modules_initialize( & net_globals.modules );
107
    measured_strings_initialize( & net_globals.configuration );
107
    measured_strings_initialize( & net_globals.configuration );
108
 
108
 
109
    // run self tests
109
    // run self tests
110
//  ERROR_PROPAGATE( self_test());
110
//  ERROR_PROPAGATE( self_test());
111
 
111
 
112
    ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service ));
112
    ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service ));
113
    ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service ));
113
    ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service ));
-
 
114
    ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service ));
-
 
115
    ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service ));
114
 
116
 
115
    ERROR_PROPAGATE( REGISTER_ME( SERVICE_IP, & phonehash ));
117
    ERROR_PROPAGATE( REGISTER_ME( SERVICE_IP, & phonehash ));
116
    ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_get_id(), ip_connect_module ));
118
    ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_get_id(), ip_connect_module ));
117
    ERROR_PROPAGATE( ip_initialize( client_connection ));
119
    ERROR_PROPAGATE( ip_initialize( client_connection ));
118
    ERROR_PROPAGATE( REGISTER_ME( SERVICE_ARP, & phonehash ));
120
    ERROR_PROPAGATE( REGISTER_ME( SERVICE_ARP, & phonehash ));
119
    ERROR_PROPAGATE( arp_initialize( client_connection ));
121
    ERROR_PROPAGATE( arp_initialize( client_connection ));
120
//  ERROR_PROPAGATE( REGISTER_ME( SERVICE_RARP, & phonehash ));
122
//  ERROR_PROPAGATE( REGISTER_ME( SERVICE_RARP, & phonehash ));
121
//  ERROR_PROPAGATE( rarp_initialize( client_connection ));
123
//  ERROR_PROPAGATE( rarp_initialize( client_connection ));
122
//  ERROR_PROPAGATE( REGISTER_ME( SERVICE_ICMP, & phonehash ));
124
//  ERROR_PROPAGATE( REGISTER_ME( SERVICE_ICMP, & phonehash ));
123
//  ERROR_PROPAGATE( icmp_initialize( client_connection ));
125
//  ERROR_PROPAGATE( icmp_initialize( client_connection ));
124
    ERROR_PROPAGATE( REGISTER_ME( SERVICE_UDP, & phonehash ));
126
    ERROR_PROPAGATE( REGISTER_ME( SERVICE_UDP, & phonehash ));
125
    ERROR_PROPAGATE( udp_initialize( client_connection ));
127
    ERROR_PROPAGATE( udp_initialize( client_connection ));
126
    ERROR_PROPAGATE( REGISTER_ME( SERVICE_TCP, & phonehash ));
128
    ERROR_PROPAGATE( REGISTER_ME( SERVICE_TCP, & phonehash ));
127
    ERROR_PROPAGATE( tcp_initialize( client_connection ));
129
    ERROR_PROPAGATE( tcp_initialize( client_connection ));
128
    return EOK;
130
    return EOK;
129
}
131
}
130
 
132
 
131
int read_netif_configuration( char * name, netif_ref netif ){
133
int read_netif_configuration( char * name, netif_ref netif ){
132
    ERROR_DECLARE;
134
    ERROR_DECLARE;
133
 
135
 
134
    if( str_lcmp( name, "lo", 2 ) == 0 ){
136
    if( str_lcmp( name, "lo", 2 ) == 0 ){
135
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", LO_NAME ));
137
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", LO_NAME ));
136
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", LO_NAME ));
138
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", LO_NAME ));
-
 
139
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", NILDUMMY_NAME ));
137
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME ));
140
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME ));
138
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" ));
141
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" ));
139
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" ));
142
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" ));
-
 
143
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ROUTING", "yes" ));
140
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" ));
144
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" ));
141
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "15535" ));
145
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "15535" ));
142
    }else if( str_lcmp( name, "ne2k", 4 ) == 0 ){
146
    }else if( str_lcmp( name, "ne2k", 4 ) == 0 ){
143
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", "eth0" ));
147
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", "eth0" ));
144
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", DP8390_NAME ));
148
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", DP8390_NAME ));
145
        // ethernet bundled in dp8390
149
        // ethernet bundled in dp8390
146
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", DP8390_NAME ));
150
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", DP8390_NAME ));
147
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "ETH_MODE", "DIX" ));
151
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "ETH_MODE", "DIX" ));
148
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME ));
152
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME ));
149
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "IRQ", "9" ));
153
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "IRQ", "9" ));
150
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "IO", "300" ));
154
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "IO", "300" ));
151
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "1492" ));
155
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "1492" ));
152
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" ));
156
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" ));
153
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "10.0.2.15" ));
157
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "10.0.2.15" ));
-
 
158
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ROUTING", "yes" ));
154
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.255.255.240" ));
159
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.255.255.240" ));
155
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "BROADCAST", "10.0.2.255" ));
160
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "BROADCAST", "10.0.2.255" ));
156
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "GATEWAY", "10.0.2.2" ));
161
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "GATEWAY", "10.0.2.2" ));
157
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS1", "10.0.2.2" ));
162
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS1", "10.0.2.2" ));
158
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS2", "10.0.2.2" ));
163
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS2", "10.0.2.2" ));
159
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "ARP", "arp" ));
164
        ERROR_PROPAGATE( add_configuration( & netif->configuration, "ARP", "arp" ));
160
    }
165
    }
161
    return EOK;
166
    return EOK;
162
}
167
}
163
 
168
 
164
/** @}
169
/** @}
165
 */
170
 */
166
 
171