Rev 4261 | Rev 4350 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4261 | Rev 4307 | ||
---|---|---|---|
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 | #include "../../include/nil_interface.h" |
- | 52 | #include "../../include/net_interface.h" |
|
52 | 53 | ||
53 | #include "../netif.h" |
54 | #include "../netif.h" |
54 | #include "../netif_interface.h" |
55 | #include "../netif_module.h" |
55 | 56 | ||
56 | #define DEFAULT_MTU 1500 |
57 | #define DEFAULT_MTU 1500 |
57 | 58 | ||
58 | #define DEFAULT_ADDR "\0\0\0\0\0\0" |
59 | #define DEFAULT_ADDR "\0\0\0\0\0\0" |
59 | #define DEFAULT_ADDR_LEN ( sizeof( DEFAULT_ADDR ) / sizeof( char )) |
60 | #define DEFAULT_ADDR_LEN ( sizeof( DEFAULT_ADDR ) / sizeof( char )) |
Line 61... | Line 62... | ||
61 | #define NAME "lo - loopback interface" |
62 | #define NAME "lo - loopback interface" |
62 | 63 | ||
63 | netif_globals_t netif_globals; |
64 | netif_globals_t netif_globals; |
64 | 65 | ||
65 | static struct lo_globals{ |
66 | static struct lo_globals{ |
66 | int mtu; |
67 | unsigned int mtu; |
67 | } lo_globals; |
68 | } lo_globals; |
68 | 69 | ||
69 | static int change_state_message( device_ref device, device_state_t state ); |
70 | static int change_state_message( device_ref device, device_state_t state ); |
70 | static int create( device_id_t device_id, device_ref * device ); |
71 | static int create( device_id_t device_id, device_ref * device ); |
71 | void netif_print_name( void ); |
72 | void module_print_name( void ); |
72 | 73 | ||
73 | int netif_specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
74 | int netif_specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
74 | //TODO nil send message |
75 | //TODO nil send message |
75 | return ENOTSUP; |
76 | return ENOTSUP; |
76 | } |
77 | } |
Line 94... | Line 95... | ||
94 | } |
95 | } |
95 | 96 | ||
96 | static int change_state_message( device_ref device, device_state_t state ){ |
97 | static int change_state_message( device_ref device, device_state_t state ){ |
97 | if( device->state != state ){ |
98 | if( device->state != state ){ |
98 | device->state = state; |
99 | device->state = state; |
99 | printf( "\nState changed to %s", ( state == NETIF_ACTIVE ) ? "ACTIVE" : "STOPPED" ); |
100 | printf( "State changed to %s\n", ( state == NETIF_ACTIVE ) ? "ACTIVE" : "STOPPED" ); |
100 | return state; |
101 | return state; |
101 | } |
102 | } |
102 | return EOK; |
103 | return EOK; |
103 | } |
104 | } |
104 | 105 | ||
Line 134... | Line 135... | ||
134 | ipcarg_t phonehash; |
135 | ipcarg_t phonehash; |
135 | 136 | ||
136 | return REGISTER_ME( SERVICE_LO, & phonehash ); |
137 | return REGISTER_ME( SERVICE_LO, & phonehash ); |
137 | } |
138 | } |
138 | 139 | ||
139 | void netif_print_name( void ){ |
140 | void module_print_name( void ){ |
140 | printf( "%s", NAME ); |
141 | printf( "%s", NAME ); |
141 | } |
142 | } |
142 | 143 | ||
143 | int netif_probe_auto_message( void ){ |
144 | int netif_probe_auto_message( void ){ |
144 | /* ERROR_DECLARE; |
145 | /* ERROR_DECLARE; |
145 | 146 | ||
146 | device_ref device; |
147 | device_ref device; |
147 | 148 | ||
148 | ERROR_PROPAGATE( create( arg1, & device )); |
149 | ERROR_PROPAGATE( create( arg1, & device )); |
149 | ipc_call_sync_3_3( netif_globals.networking_phone, NET_NET_DEVICE, device->device_id, NULL, NULL, NULL, NULL, NULL ); |
150 | ipc_call_sync_3_3( netif_globals.net_phone, NET_NET_DEVICE, device->device_id, NULL, NULL, NULL, NULL, NULL ); |
150 | */ return ENOTSUP; |
151 | */ return ENOTSUP; |
151 | } |
152 | } |
152 | 153 | ||
153 | int netif_probe_message( device_id_t device_id, int irq, int io ){ |
154 | int netif_probe_message( device_id_t device_id, int irq, int io ){ |
154 | ERROR_DECLARE; |
155 | ERROR_DECLARE; |
155 | 156 | ||
156 | device_ref device; |
157 | device_ref device; |
157 | aid_t message; |
158 | measured_string_t names[ 1 ] = {{ "MTU", 3 }}; |
158 | ipc_call_t answer; |
- | |
159 | measured_string_t configuration[ 1 ] = {{ "MTU", 3 }}; |
159 | measured_string_ref configuration; |
160 | int count = 1; |
160 | int count = 1; |
161 | measured_string_ref settings; |
- | |
162 | char * data; |
161 | char * data; |
163 | ipcarg_t result; |
- | |
164 | 162 | ||
- | 163 | configuration = & names[ 0 ]; |
|
165 | // create a new device |
164 | // create a new device |
166 | ERROR_PROPAGATE( create( device_id, & device )); |
165 | ERROR_PROPAGATE( create( device_id, & device )); |
167 | // get configuration |
166 | // get configuration |
168 | message = async_send_2( netif_globals.networking_phone, NET_NET_GET_DEVICE_CONF, device->device_id, count, & answer ); |
- | |
169 | // send names and get settings |
- | |
170 | if( ERROR_OCCURRED( measured_strings_send( netif_globals.networking_phone, configuration, count )) |
167 | ERROR_PROPAGATE( net_get_device_conf_req( netif_globals.net_phone, device->device_id, & configuration, count, & data )); |
171 | || ERROR_OCCURRED( measured_strings_return( netif_globals.networking_phone, & settings, & data, count ))){ |
- | |
172 | async_wait_for( message, NULL ); |
- | |
173 | return ERROR_CODE; |
- | |
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 | } |
- | |
184 | // MTU is the first one |
168 | // MTU is the first one |
185 | if( settings && ( settings[ 0 ].value )){ |
169 | if( configuration && configuration[ 0 ].value ){ |
186 | lo_globals.mtu = strtoul( settings[ 0 ].value, NULL, 0 ); |
170 | lo_globals.mtu = strtoul( configuration[ 0 ].value, NULL, 0 ); |
187 | free( settings ); |
171 | net_free_settings( configuration, data ); |
188 | free( data ); |
- | |
189 | }else{ |
172 | }else{ |
190 | lo_globals.mtu = DEFAULT_MTU; |
173 | lo_globals.mtu = DEFAULT_MTU; |
191 | } |
174 | } |
192 | // print the settings |
175 | // print the settings |
193 | printf("\nNew device registered:\n\tid\t= %d\n\tMTU\t= %d", device->device_id, lo_globals.mtu ); |
176 | printf("New device registered:\n\tid\t= %d\n\tMTU\t= %d\n", device->device_id, lo_globals.mtu ); |
194 | return EOK; |
177 | return EOK; |
195 | } |
178 | } |
196 | 179 | ||
197 | int netif_send_message( device_id_t device_id, packet_t packet, services_t sender ){ |
180 | int netif_send_message( device_id_t device_id, packet_t packet, services_t sender ){ |
198 | ERROR_DECLARE; |
181 | ERROR_DECLARE; |