Rev 4707 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4707 | Rev 4719 | ||
---|---|---|---|
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 standalone networking module. |
34 | * Wrapper for the standalone networking module. |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <string.h> |
37 | #include <string.h> |
38 | 38 | ||
39 | #include <ipc/ipc.h> |
39 | #include <ipc/ipc.h> |
40 | 40 | ||
41 | #include "../messages.h" |
41 | #include "../messages.h" |
42 | 42 | ||
43 | #include "../include/ip_interface.h" |
43 | #include "../include/ip_interface.h" |
44 | 44 | ||
45 | #include "../structures/measured_strings.h" |
45 | #include "../structures/measured_strings.h" |
46 | #include "../structures/module_map.h" |
46 | #include "../structures/module_map.h" |
47 | #include "../structures/packet/packet_server.h" |
47 | #include "../structures/packet/packet_server.h" |
48 | 48 | ||
49 | #include "net.h" |
49 | #include "net.h" |
50 | 50 | ||
51 | /** Networking module global data. |
51 | /** Networking module global data. |
52 | */ |
52 | */ |
53 | extern net_globals_t net_globals; |
53 | extern net_globals_t net_globals; |
54 | 54 | ||
55 | int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
55 | int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
56 | if( IS_NET_PACKET_MESSAGE( call )){ |
56 | if( IS_NET_PACKET_MESSAGE( call )){ |
57 | return packet_server_message( callid, call, answer, answer_count ); |
57 | return packet_server_message( callid, call, answer, answer_count ); |
58 | }else{ |
58 | }else{ |
59 | return net_message( callid, call, answer, answer_count ); |
59 | return net_message( callid, call, answer, answer_count ); |
60 | } |
60 | } |
61 | } |
61 | } |
62 | 62 | ||
63 | int net_initialize( async_client_conn_t client_connection ){ |
63 | int net_initialize( async_client_conn_t client_connection ){ |
64 | ERROR_DECLARE; |
64 | ERROR_DECLARE; |
65 | 65 | ||
66 | task_id_t task_id; |
66 | task_id_t task_id; |
67 | 67 | ||
68 | netifs_initialize( & net_globals.netifs ); |
68 | netifs_initialize( & net_globals.netifs ); |
69 | char_map_initialize( & net_globals.netif_names ); |
69 | char_map_initialize( & net_globals.netif_names ); |
70 | modules_initialize( & net_globals.modules ); |
70 | modules_initialize( & net_globals.modules ); |
71 | measured_strings_initialize( & net_globals.configuration ); |
71 | measured_strings_initialize( & net_globals.configuration ); |
72 | 72 | ||
73 | // run self tests |
- | |
74 | // ERROR_PROPAGATE( self_test()); |
- | |
75 | - | ||
76 | ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service )); |
73 | ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service )); |
77 | ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service )); |
74 | ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service )); |
78 | ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service )); |
75 | ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service )); |
79 | ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service )); |
76 | ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service )); |
80 | 77 | ||
81 | task_id = spawn( "/srv/ip" ); |
78 | task_id = spawn( "/srv/ip" ); |
82 | if( ! task_id ) return EINVAL; |
79 | if( ! task_id ) return EINVAL; |
83 | ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_id, ip_connect_module )); |
80 | ERROR_PROPAGATE( add_module( NULL, & net_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_id, ip_connect_module )); |
84 | if( ! spawn( "/srv/icmp" )) return EINVAL; |
81 | if( ! spawn( "/srv/icmp" )) return EINVAL; |
85 | if( ! spawn( "/srv/udp" )) return EINVAL; |
82 | if( ! spawn( "/srv/udp" )) return EINVAL; |
86 | if( ! spawn( "/srv/tcp" )) return EINVAL; |
83 | if( ! spawn( "/srv/tcp" )) return EINVAL; |
87 | // if( ! spawn( "/srv/rarp" )) return EINVAL; |
- | |
88 | return EOK; |
84 | return EOK; |
89 | } |
85 | } |
90 | 86 | ||
91 | int read_netif_configuration( char * name, netif_ref netif ){ |
87 | int read_netif_configuration( char * name, netif_ref netif ){ |
92 | ERROR_DECLARE; |
88 | ERROR_DECLARE; |
93 | 89 | ||
94 | if( str_lcmp( name, "lo", 2 ) == 0 ){ |
90 | if( str_lcmp( name, "lo", 2 ) == 0 ){ |
95 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", LO_NAME )); |
91 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", LO_NAME )); |
96 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", LO_NAME )); |
92 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", LO_NAME )); |
97 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", NILDUMMY_NAME )); |
93 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", NILDUMMY_NAME )); |
98 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
94 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
99 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
95 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
100 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" )); |
96 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "127.0.0.1" )); |
101 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ROUTING", "yes" )); |
97 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ROUTING", "yes" )); |
102 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" )); |
98 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.0.0.0" )); |
103 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "15535" )); |
99 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "15535" )); |
104 | }else if( str_lcmp( name, "ne2k", 4 ) == 0 ){ |
100 | }else if( str_lcmp( name, "ne2k", 4 ) == 0 ){ |
105 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", "eth0" )); |
101 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NAME", "eth0" )); |
106 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", DP8390_NAME )); |
102 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETIF", DP8390_NAME )); |
107 | // standalone ethernet |
103 | // standalone ethernet |
108 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", ETHERNET_NAME )); |
104 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NIL", ETHERNET_NAME )); |
109 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "ETH_MODE", "DIX" )); //8023_2_LSAP( not supported ), 8023_2_SNAP |
105 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "ETH_MODE", "DIX" )); //8023_2_LSAP( not supported ), 8023_2_SNAP |
110 | // ERROR_PROPAGATE( add_configuration( & netif->configuration, "ETH_DUMMY", "yes" )); //anything else not starting with 'y' |
106 | // ERROR_PROPAGATE( add_configuration( & netif->configuration, "ETH_DUMMY", "yes" )); //anything else not starting with 'y' |
111 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
107 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IL", IP_NAME )); |
112 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IRQ", "9" )); |
108 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IRQ", "9" )); |
113 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IO", "300" )); |
109 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IO", "300" )); |
114 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "576" )); |
110 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "MTU", "576" )); |
115 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
111 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_CONFIG", "static" )); |
116 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "10.0.2.15" )); |
112 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ADDR", "10.0.2.15" )); |
117 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ROUTING", "yes" )); |
113 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "IP_ROUTING", "yes" )); |
118 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.255.255.240" )); |
114 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "NETMASK", "255.255.255.240" )); |
119 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "BROADCAST", "10.0.2.255" )); |
115 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "BROADCAST", "10.0.2.255" )); |
120 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "GATEWAY", "10.0.2.2" )); |
116 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "GATEWAY", "10.0.2.2" )); |
121 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS1", "10.0.2.2" )); |
117 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS1", "10.0.2.2" )); |
122 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS2", "10.0.2.2" )); |
118 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "DNS2", "10.0.2.2" )); |
123 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "ARP", "arp" )); |
119 | ERROR_PROPAGATE( add_configuration( & netif->configuration, "ARP", "arp" )); |
124 | } |
120 | } |
125 | return EOK; |
121 | return EOK; |
126 | } |
122 | } |
127 | 123 | ||
128 | /** @} |
124 | /** @} |
129 | */ |
125 | */ |
130 | 126 |