Rev 3666 | Rev 3846 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3666 | Rev 3685 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2008 Lukas Mejdrech |
2 | * Copyright (c) 2008 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 | */ |
34 | */ |
35 | 35 | ||
36 | #include <async.h> |
36 | #include <async.h> |
37 | #include <stdio.h> |
37 | #include <stdio.h> |
38 | #include <ipc/ipc.h> |
38 | #include <ipc/ipc.h> |
39 | #include <ipc/services.h> |
39 | #include <ipc/services.h> |
40 | //#include <sys/mman.h> |
40 | //#include <sys/mman.h> |
41 | 41 | ||
42 | #include "../err.h" |
42 | #include "../err.h" |
43 | #include "../messages.h" |
43 | #include "../messages.h" |
44 | #include "../modules.h" |
44 | #include "../modules.h" |
45 | 45 | ||
46 | #include "netif.h" |
46 | #include "netif.h" |
47 | #include "netif_device_id_type.h" |
47 | #include "netif_device_id_type.h" |
48 | 48 | ||
49 | extern netif_globals_t netif_globals; |
49 | extern netif_globals_t netif_globals; |
50 | 50 | ||
51 | extern int netif_initialize( void ); |
51 | extern int netif_initialize( void ); |
52 | extern void netif_print_name( void ); |
52 | extern void netif_print_name( void ); |
53 | extern int netif_probe_auto_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
53 | extern int netif_probe_auto_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
54 | extern int netif_probe_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
54 | extern int netif_probe_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
55 | extern int netif_send_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
55 | extern int netif_send_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
56 | extern int netif_start_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
56 | extern int netif_start_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
57 | extern int netif_stop_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
57 | extern int netif_stop_message( ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
58 | 58 | ||
59 | DEVICE_MAP_IMPLEMENT( netif_device_map, netif_device_t ) |
59 | DEVICE_MAP_IMPLEMENT( netif_device_map, netif_device_t ) |
60 | 60 | ||
61 | int netif_message( ipc_callid_t callid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
61 | int netif_message( ipc_callid_t callid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ); |
62 | int netif_start_module( void ( * client_connection )( ipc_callid_t iid, ipc_call_t * icall )); |
62 | int netif_start_module( void ( * client_connection )( ipc_callid_t iid, ipc_call_t * icall )); |
63 | 63 | ||
64 | int netif_device_find( netif_device_id_t device_id, netif_device_ref * device ){ |
64 | int netif_device_find( netif_device_id_t device_id, netif_device_ref * device ){ |
65 | * device = netif_device_map_find( & netif_globals.netif_device_map, device_id ); |
65 | * device = netif_device_map_find( & netif_globals.netif_device_map, device_id ); |
66 | if( ! * device ) return ENOENT; |
66 | if( ! * device ) return ENOENT; |
67 | if(( ** device ).status == NETIF_NULL ) return EPERM; |
67 | if(( ** device ).state == NETIF_NULL ) return EPERM; |
68 | return EOK; |
68 | return EOK; |
69 | } |
69 | } |
70 | 70 | ||
71 | void netif_device_stats_null( netif_device_stats_ref stats ) |
71 | void netif_device_stats_null( netif_device_stats_ref stats ) |
72 | { |
72 | { |
73 | //memset( stats, 0, sizeof( netif_device_t )); |
73 | //memset( stats, 0, sizeof( netif_device_t )); |
74 | stats->rx_packets = 0; |
74 | stats->rx_packets = 0; |
75 | stats->tx_packets = 0; |
75 | stats->tx_packets = 0; |
76 | stats->rx_bytes = 0; |
76 | stats->rx_bytes = 0; |
77 | stats->tx_bytes = 0; |
77 | stats->tx_bytes = 0; |
78 | stats->rx_errors = 0; |
78 | stats->rx_errors = 0; |
79 | stats->tx_errors = 0; |
79 | stats->tx_errors = 0; |
80 | stats->rx_dropped = 0; |
80 | stats->rx_dropped = 0; |
81 | stats->tx_dropped = 0; |
81 | stats->tx_dropped = 0; |
82 | stats->multicast = 0; |
82 | stats->multicast = 0; |
83 | stats->collisions = 0; |
83 | stats->collisions = 0; |
84 | stats->rx_length_errors = 0; |
84 | stats->rx_length_errors = 0; |
85 | stats->rx_over_errors = 0; |
85 | stats->rx_over_errors = 0; |
86 | stats->rx_crc_errors = 0; |
86 | stats->rx_crc_errors = 0; |
87 | stats->rx_frame_errors = 0; |
87 | stats->rx_frame_errors = 0; |
88 | stats->rx_fifo_errors = 0; |
88 | stats->rx_fifo_errors = 0; |
89 | stats->rx_missed_errors = 0; |
89 | stats->rx_missed_errors = 0; |
90 | stats->tx_aborted_errors = 0; |
90 | stats->tx_aborted_errors = 0; |
91 | stats->tx_carrier_errors = 0; |
91 | stats->tx_carrier_errors = 0; |
92 | stats->tx_fifo_errors = 0; |
92 | stats->tx_fifo_errors = 0; |
93 | stats->tx_heartbeat_errors = 0; |
93 | stats->tx_heartbeat_errors = 0; |
94 | stats->tx_window_errors = 0; |
94 | stats->tx_window_errors = 0; |
95 | stats->rx_compressed = 0; |
95 | stats->rx_compressed = 0; |
96 | stats->tx_compressed = 0; |
96 | stats->tx_compressed = 0; |
97 | } |
97 | } |
98 | 98 | ||
99 | int netif_message( ipc_callid_t callid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){ |
99 | int netif_message( ipc_callid_t callid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, ipcarg_t * result1, ipcarg_t * result2, ipcarg_t * result3 ){ |
100 | ERROR_DECLARE; |
100 | ERROR_DECLARE; |
101 | 101 | ||
102 | size_t length; |
102 | size_t length; |
103 | netif_device_ref device; |
103 | netif_device_ref device; |
104 | 104 | ||
105 | // printf( "\nNETIF message %d", method ); |
105 | // printf( "\nNETIF message %d", method ); |
106 | switch( method ){ |
106 | switch( method ){ |
107 | case IPC_M_PHONE_HUNGUP: |
107 | case IPC_M_PHONE_HUNGUP: |
108 | return EOK; |
108 | return EOK; |
109 | case NET_NETIF_PROBE_AUTO: |
109 | case NET_NETIF_PROBE_AUTO: |
110 | return netif_probe_auto_message( arg1, arg2, arg3, result1, result2, result3 ); |
110 | return netif_probe_auto_message( arg1, arg2, arg3, result1, result2, result3 ); |
111 | case NET_NETIF_PROBE: |
111 | case NET_NETIF_PROBE: |
112 | return netif_probe_message( arg1, arg2, arg3, result1, result2, result3 ); |
112 | return netif_probe_message( arg1, arg2, arg3, result1, result2, result3 ); |
113 | case NET_NETIF_REGISTER: |
113 | case NET_NETIF_REGISTER: |
114 | case NET_LL_REGISTER: |
114 | case NET_LL_REGISTER: |
115 | ERROR_PROPAGATE( netif_device_find( arg1, & device )); |
115 | ERROR_PROPAGATE( netif_device_find( arg1, & device )); |
116 | // TODO back phone |
- | |
117 | device->ll_registered = callid; |
116 | device->ll_registered = connect_to_service( arg2 ); |
118 | return EOK; |
117 | return EOK; |
119 | case NET_NETIF_SEND: |
118 | case NET_NETIF_SEND: |
120 | return netif_send_message( arg1, arg2, arg3, result1, result2, result3 ); |
119 | return netif_send_message( arg1, arg2, arg3, result1, result2, result3 ); |
121 | case NET_NETIF_START: |
120 | case NET_NETIF_START: |
122 | return netif_start_message( arg1, arg2, arg3, result1, result2, result3 ); |
121 | return netif_start_message( arg1, arg2, arg3, result1, result2, result3 ); |
123 | case NET_NETIF_STATS: |
122 | case NET_NETIF_STATS: |
124 | ERROR_PROPAGATE( ipc_data_read_receive( & callid, & length )); |
123 | ERROR_PROPAGATE( ipc_data_read_receive( & callid, & length )); |
125 | if( length < sizeof( netif_device_stats_t )){ |
124 | if( length < sizeof( netif_device_stats_t )){ |
126 | ipc_answer_0( callid, EOVERFLOW ); |
125 | ipc_answer_0( callid, EOVERFLOW ); |
127 | return EOVERFLOW; |
126 | return EOVERFLOW; |
128 | } |
127 | } |
129 | if( ERROR_OCCURED( netif_device_find( arg1, & device ))){ |
128 | if( ERROR_OCCURED( netif_device_find( arg1, & device ))){ |
130 | ipc_answer_0( callid, ERROR_CODE ); |
129 | ipc_answer_0( callid, ERROR_CODE ); |
131 | return ERROR_CODE; |
130 | return ERROR_CODE; |
132 | } |
131 | } |
133 | return ipc_data_read_finalize( callid, & device->stats, sizeof( netif_device_stats_t )); |
132 | return ipc_data_read_finalize( callid, & device->stats, sizeof( netif_device_stats_t )); |
134 | case NET_NETIF_STOP: |
133 | case NET_NETIF_STOP: |
135 | return netif_stop_message( arg1, arg2, arg3, result1, result2, result3 ); |
134 | return netif_stop_message( arg1, arg2, arg3, result1, result2, result3 ); |
136 | } |
135 | } |
137 | return ENOTSUP; |
136 | return ENOTSUP; |
138 | } |
137 | } |
139 | 138 | ||
140 | int netif_start_module( void ( * client_connection )( ipc_callid_t iid, ipc_call_t * icall )){ |
139 | int netif_start_module( void ( * client_connection )( ipc_callid_t iid, ipc_call_t * icall )){ |
141 | /* services_t need[ 2 ]; |
140 | services_t need[ 2 ]; |
142 | int * need_phone[ 2 ]; |
141 | int * need_phone[ 2 ]; |
143 | 142 | ||
144 | need[ 0 ] = SERVICE_NETWORKING; |
143 | need[ 0 ] = SERVICE_NETWORKING; |
145 | need[ 1 ] = NULL; |
144 | need[ 1 ] = NULL; |
146 | need_phone[ 0 ] = & netif_globals.networking_phone; |
145 | need_phone[ 0 ] = & netif_globals.networking_phone; |
147 | need_phone[ 1 ] = NULL; |
146 | need_phone[ 1 ] = NULL; |
148 | */ netif_device_map_initialize( & netif_globals.netif_device_map ); |
147 | netif_device_map_initialize( & netif_globals.netif_device_map ); |
149 | return start_service( NULL, /*need, need_phone*/ NULL, NULL, client_connection, netif_initialize ); |
148 | return start_service( NULL, need, need_phone, client_connection, netif_initialize ); |
150 | } |
149 | } |
151 | 150 | ||
152 | /** @} |
151 | /** @} |
153 | */ |
152 | */ |
154 | 153 |