Rev 4243 | Rev 4350 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4243 | Rev 4261 | ||
---|---|---|---|
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 "../../include/device.h" |
50 | #include "../../include/device.h" |
- | 51 | #include "../../include/nil_messages.h" |
|
51 | 52 | ||
52 | #include "../netif.h" |
53 | #include "../netif.h" |
53 | #include "../netif_interface.h" |
54 | #include "../netif_interface.h" |
54 | 55 | ||
55 | #define DEFAULT_MTU 1500 |
56 | #define DEFAULT_MTU 1500 |
Line 63... | Line 64... | ||
63 | 64 | ||
64 | static struct lo_globals{ |
65 | static struct lo_globals{ |
65 | int mtu; |
66 | int mtu; |
66 | } lo_globals; |
67 | } lo_globals; |
67 | 68 | ||
68 | static int change_state_message( device_id_t device_id, device_state_t state ); |
69 | static int change_state_message( device_ref device, device_state_t state ); |
69 | static int create( device_id_t device_id, device_ref * device ); |
70 | static int create( device_id_t device_id, device_ref * device ); |
70 | void netif_print_name( void ); |
71 | void netif_print_name( void ); |
71 | 72 | ||
72 | int netif_specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
73 | int netif_specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
73 | //TODO nil send message |
74 | //TODO nil send message |
Line 90... | Line 91... | ||
90 | ERROR_PROPAGATE( find_device( device_id, & device )); |
91 | ERROR_PROPAGATE( find_device( device_id, & device )); |
91 | memcpy( stats, ( device_stats_ref ) device->specific, sizeof( device_stats_t )); |
92 | memcpy( stats, ( device_stats_ref ) device->specific, sizeof( device_stats_t )); |
92 | return EOK; |
93 | return EOK; |
93 | } |
94 | } |
94 | 95 | ||
95 | static int change_state_message( device_id_t device_id, device_state_t state ){ |
96 | static int change_state_message( device_ref device, device_state_t state ){ |
96 | ERROR_DECLARE; |
- | |
97 | - | ||
98 | device_ref device; |
- | |
99 | - | ||
100 | ERROR_PROPAGATE( find_device( device_id, & device )); |
- | |
101 | if( device->state != state ){ |
97 | if( device->state != state ){ |
102 | device->state = state; |
98 | device->state = state; |
103 | nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL ); |
- | |
104 | printf( "\nState changed to %s", ( state == NETIF_ACTIVE ) ? "ACTIVE" : "STOPPED" ); |
99 | printf( "\nState changed to %s", ( state == NETIF_ACTIVE ) ? "ACTIVE" : "STOPPED" ); |
- | 100 | return state; |
|
105 | } |
101 | } |
106 | return EOK; |
102 | return EOK; |
107 | } |
103 | } |
108 | 104 | ||
109 | static int create( device_id_t device_id, device_ref * device ){ |
105 | static int create( device_id_t device_id, device_ref * device ){ |
Line 196... | Line 192... | ||
196 | // print the settings |
192 | // print the settings |
197 | 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 ); |
198 | return EOK; |
194 | return EOK; |
199 | } |
195 | } |
200 | 196 | ||
201 | int netif_send_message( device_id_t device_id, packet_t packet ){ |
197 | int netif_send_message( device_id_t device_id, packet_t packet, services_t sender ){ |
202 | ERROR_DECLARE; |
198 | ERROR_DECLARE; |
203 | 199 | ||
204 | device_ref device; |
200 | device_ref device; |
205 | size_t length; |
201 | size_t length; |
206 | packet_t next; |
202 | packet_t next; |
- | 203 | int phone; |
|
207 | 204 | ||
208 | ERROR_PROPAGATE( find_device( device_id, & device )); |
205 | ERROR_PROPAGATE( find_device( device_id, & device )); |
209 | if( device->state != NETIF_ACTIVE ) return EPERM; |
206 | if( device->state != NETIF_ACTIVE ) return EPERM; |
210 | next = packet; |
207 | next = packet; |
211 | do{ |
208 | do{ |
Line 214... | Line 211... | ||
214 | length = packet_get_data_length( next ); |
211 | length = packet_get_data_length( next ); |
215 | (( device_stats_ref ) device->specific )->tx_bytes += length; |
212 | (( device_stats_ref ) device->specific )->tx_bytes += length; |
216 | (( device_stats_ref ) device->specific )->rx_bytes += length; |
213 | (( device_stats_ref ) device->specific )->rx_bytes += length; |
217 | next = pq_next( next ); |
214 | next = pq_next( next ); |
218 | }while( next ); |
215 | }while( next ); |
- | 216 | phone = device->nil_phone; |
|
- | 217 | rwlock_write_unlock( & netif_globals.lock ); |
|
219 | nil_message( device, NET_NIL_RECEIVED, packet_get_id( packet ), PACKET_SELF ); |
218 | nil_received_msg( phone, device_id, packet, sender ); |
- | 219 | rwlock_write_lock( & netif_globals.lock ); |
|
220 | return EOK; |
220 | return EOK; |
221 | } |
221 | } |
222 | 222 | ||
223 | int netif_start_message( device_id_t device_id ){ |
223 | int netif_start_message( device_ref device ){ |
224 | return change_state_message( device_id, NETIF_ACTIVE ); |
224 | return change_state_message( device, NETIF_ACTIVE ); |
225 | } |
225 | } |
226 | 226 | ||
227 | int netif_stop_message( device_id_t device_id ){ |
227 | int netif_stop_message( device_ref device ){ |
228 | return change_state_message( device_id, NETIF_STOPPED ); |
228 | return change_state_message( device, NETIF_STOPPED ); |
229 | } |
229 | } |
230 | 230 | ||
231 | /** @} |
231 | /** @} |
232 | */ |
232 | */ |