Rev 4163 | Rev 4197 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4163 | Rev 4192 | ||
---|---|---|---|
Line 46... | Line 46... | ||
46 | 46 | ||
47 | #include "../../structures/measured_strings.h" |
47 | #include "../../structures/measured_strings.h" |
48 | #include "../../structures/packet/packet_client.h" |
48 | #include "../../structures/packet/packet_client.h" |
49 | 49 | ||
50 | #include "../netif.h" |
50 | #include "../netif.h" |
- | 51 | #include "../netif_interface.h" |
|
51 | 52 | ||
52 | #define DEFAULT_MTU 1500 |
53 | #define DEFAULT_MTU 1500 |
53 | 54 | ||
- | 55 | #define DEFAULT_ADDR "\0\0\0\0\0\0" |
|
- | 56 | #define DEFAULT_ADDR_LEN ( sizeof( DEFAULT_ADDR ) / sizeof( char )) |
|
- | 57 | ||
54 | #define NAME "lo - loopback interface" |
58 | #define NAME "lo - loopback interface" |
55 | 59 | ||
56 | netif_globals_t netif_globals; |
60 | netif_globals_t netif_globals; |
57 | 61 | ||
58 | static struct lo_globals{ |
62 | static struct lo_globals{ |
59 | measured_string_ref addr; |
- | |
60 | int mtu; |
63 | int mtu; |
61 | } lo_globals; |
64 | } lo_globals; |
62 | 65 | ||
63 | int change_state_message( device_id_t device_id, device_state_t state ); |
66 | int change_state_message( device_id_t device_id, device_state_t state ); |
64 | int create( device_id_t device_id, device_ref * device ); |
67 | int create( device_id_t device_id, device_ref * device ); |
65 | int initialize( void ); |
- | |
66 | void netif_print_name( void ); |
68 | void netif_print_name( void ); |
67 | int probe_auto_message( void ); |
- | |
68 | int probe_message( device_id_t device_id, int irq, int io ); |
- | |
69 | int send_message( device_id_t device_id, packet_t packet ); |
- | |
70 | int start_message( device_id_t device_id ); |
- | |
71 | int stop_message( device_id_t device_id ); |
- | |
72 | measured_string_ref get_addr_message( device_id_t device_id ); |
- | |
73 | 69 | ||
- | 70 | int specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
|
- | 71 | return ENOTSUP; |
|
- | 72 | } |
|
- | 73 | ||
- | 74 | int get_addr_message( device_id_t device_id, measured_string_ref address ){ |
|
- | 75 | if( ! address ) return EBADMEM; |
|
- | 76 | address->value = DEFAULT_ADDR; |
|
- | 77 | address->length = DEFAULT_ADDR_LEN; |
|
- | 78 | } |
|
- | 79 | ||
- | 80 | int get_device_stats( device_id_t device_id, device_stats_ref stats ){ |
|
- | 81 | ERROR_DECLARE; |
|
- | 82 | ||
- | 83 | device_ref device; |
|
- | 84 | ||
- | 85 | if( ! stats ) return EBADMEM; |
|
74 | measured_string_ref get_addr_message( device_id_t device_id ){ |
86 | ERROR_PROPAGATE( find_device( device_id, & device )); |
- | 87 | memcpy( stats, ( device_stats_ref ) device->specific, sizeof( device_stats_t )); |
|
75 | return lo_globals.addr; |
88 | return EOK; |
76 | } |
89 | } |
77 | 90 | ||
78 | int change_state_message( device_id_t device_id, device_state_t state ){ |
91 | int change_state_message( device_id_t device_id, device_state_t state ){ |
79 | ERROR_DECLARE; |
92 | ERROR_DECLARE; |
80 | 93 | ||
Line 88... | Line 101... | ||
88 | } |
101 | } |
89 | return EOK; |
102 | return EOK; |
90 | } |
103 | } |
91 | 104 | ||
92 | int create( device_id_t device_id, device_ref * device ){ |
105 | int create( device_id_t device_id, device_ref * device ){ |
93 | ERROR_DECLARE; |
106 | int index; |
94 | 107 | ||
95 | if( device_map_count( & netif_globals.device_map ) > 0 ){ |
108 | if( device_map_count( & netif_globals.device_map ) > 0 ){ |
96 | return EXDEV; |
109 | return EXDEV; |
97 | }else{ |
110 | }else{ |
98 | * device = ( device_ref ) malloc( sizeof( device_t )); |
111 | * device = ( device_ref ) malloc( sizeof( device_t )); |
99 | if( !( * device )) return ENOMEM; |
112 | if( !( * device )) return ENOMEM; |
- | 113 | ( ** device ).specific = malloc( sizeof( device_stats_t )); |
|
- | 114 | if( ! ( ** device ).specific ){ |
|
- | 115 | free( * device ); |
|
- | 116 | return ENOMEM; |
|
- | 117 | } |
|
- | 118 | null_device_stats(( device_stats_ref )( ** device ).specific ); |
|
100 | ( ** device ).device_id = device_id; |
119 | ( ** device ).device_id = device_id; |
101 | ( ** device ).nil_phone = -1; |
120 | ( ** device ).nil_phone = -1; |
102 | ( ** device ).specific = NULL; |
- | |
103 | null_device_stats( &(( ** device ).stats )); |
- | |
104 | ( ** device ).state = NETIF_STOPPED; |
121 | ( ** device ).state = NETIF_STOPPED; |
105 | if( ERROR_OCCURRED( device_map_add( & netif_globals.device_map, ( ** device ).device_id, * device ))){ |
122 | index = device_map_add( & netif_globals.device_map, ( ** device ).device_id, * device ); |
- | 123 | if( index < 0 ){ |
|
106 | free( * device ); |
124 | free( * device ); |
- | 125 | free(( ** device ).specific ); |
|
107 | * device = NULL; |
126 | * device = NULL; |
108 | return ERROR_CODE; |
127 | return index; |
109 | } |
128 | } |
110 | } |
129 | } |
111 | return EOK; |
130 | return EOK; |
112 | } |
131 | } |
113 | 132 | ||
114 | int initialize( void ){ |
133 | int initialize( void ){ |
115 | ipcarg_t phonehash; |
134 | ipcarg_t phonehash; |
116 | 135 | ||
117 | lo_globals.addr = measured_string_create_bulk( "\0\0\0\0\0\0", 0 ); |
- | |
118 | if( ! lo_globals.addr ) return ENOMEM; |
- | |
119 | return REGISTER_ME( SERVICE_LO, & phonehash ); |
136 | return REGISTER_ME( SERVICE_LO, & phonehash ); |
120 | } |
137 | } |
121 | 138 | ||
122 | void netif_print_name( void ){ |
139 | void netif_print_name( void ){ |
123 | printf( NAME ); |
140 | printf( NAME ); |
Line 141... | Line 158... | ||
141 | ipc_call_t answer; |
158 | ipc_call_t answer; |
142 | measured_string_t configuration[ 1 ] = {{ "MTU", 3 }}; |
159 | measured_string_t configuration[ 1 ] = {{ "MTU", 3 }}; |
143 | int count = 1; |
160 | int count = 1; |
144 | measured_string_ref settings; |
161 | measured_string_ref settings; |
145 | char * data; |
162 | char * data; |
- | 163 | ipcarg_t result; |
|
146 | 164 | ||
147 | // create a new device |
165 | // create a new device |
148 | ERROR_PROPAGATE( create( device_id, & device )); |
166 | ERROR_PROPAGATE( create( device_id, & device )); |
149 | // get configuration |
167 | // get configuration |
150 | message = async_send_2( netif_globals.networking_phone, NET_NET_GET_DEVICE_CONF, device->device_id, count, & answer ); |
168 | message = async_send_2( netif_globals.networking_phone, NET_NET_GET_DEVICE_CONF, device->device_id, count, & answer ); |
Line 152... | Line 170... | ||
152 | if( ERROR_OCCURRED( measured_strings_send( netif_globals.networking_phone, configuration, count )) |
170 | if( ERROR_OCCURRED( measured_strings_send( netif_globals.networking_phone, configuration, count )) |
153 | || ERROR_OCCURRED( measured_strings_return( netif_globals.networking_phone, & settings, & data, count ))){ |
171 | || ERROR_OCCURRED( measured_strings_return( netif_globals.networking_phone, & settings, & data, count ))){ |
154 | async_wait_for( message, NULL ); |
172 | async_wait_for( message, NULL ); |
155 | return ERROR_CODE; |
173 | return ERROR_CODE; |
156 | } |
174 | } |
- | 175 | // end request |
|
- | 176 | async_wait_for( message, & result ); |
|
- | 177 | if( ERROR_OCCURRED( result )){ |
|
- | 178 | if( settings ){ |
|
- | 179 | free( settings ); |
|
- | 180 | free( data ); |
|
- | 181 | } |
|
- | 182 | return ERROR_CODE; |
|
- | 183 | } |
|
157 | // MTU is the first one |
184 | // MTU is the first one |
158 | if( settings && ( settings[ 0 ].value )){ |
185 | if( settings && ( settings[ 0 ].value )){ |
159 | lo_globals.mtu = strtoul( settings[ 0 ].value, NULL, 0 ); |
186 | lo_globals.mtu = strtoul( settings[ 0 ].value, NULL, 0 ); |
- | 187 | free( settings ); |
|
- | 188 | free( data ); |
|
160 | }else{ |
189 | }else{ |
161 | lo_globals.mtu = DEFAULT_MTU; |
190 | lo_globals.mtu = DEFAULT_MTU; |
162 | } |
191 | } |
163 | free( settings ); |
- | |
164 | free( data ); |
- | |
165 | // end request |
- | |
166 | async_wait_for( message, NULL ); |
- | |
167 | // print the settings |
192 | // print the settings |
168 | printf("\nNew device registered:\n\tid\t= %d\n\tMTU\t= %d", device->device_id, lo_globals.mtu ); |
193 | printf("\nNew device registered:\n\tid\t= %d\n\tMTU\t= %d", device->device_id, lo_globals.mtu ); |
169 | return EOK; |
194 | return EOK; |
170 | } |
195 | } |
171 | 196 | ||
Line 178... | Line 203... | ||
178 | 203 | ||
179 | ERROR_PROPAGATE( find_device( device_id, & device )); |
204 | ERROR_PROPAGATE( find_device( device_id, & device )); |
180 | if( device->state != NETIF_ACTIVE ) return EPERM; |
205 | if( device->state != NETIF_ACTIVE ) return EPERM; |
181 | next = packet; |
206 | next = packet; |
182 | do{ |
207 | do{ |
183 | ++ device->stats.tx_packets; |
208 | ++ (( device_stats_ref ) device->specific )->tx_packets; |
184 | ++ device->stats.rx_packets; |
209 | ++ (( device_stats_ref ) device->specific )->rx_packets; |
185 | length = packet_get_data_length( next ); |
210 | length = packet_get_data_length( next ); |
186 | device->stats.tx_bytes += length; |
211 | (( device_stats_ref ) device->specific )->tx_bytes += length; |
187 | device->stats.rx_bytes += length; |
212 | (( device_stats_ref ) device->specific )->rx_bytes += length; |
188 | next = pq_next( next ); |
213 | next = pq_next( next ); |
189 | }while( next ); |
214 | }while( next ); |
190 | nil_message( device, NET_NIL_RECEIVED, packet_get_id( packet ), PACKET_SELF ); |
215 | nil_message( device, NET_NIL_RECEIVED, packet_get_id( packet ), PACKET_SELF ); |
191 | return EOK; |
216 | return EOK; |
192 | } |
217 | } |