Rev 4699 | Rev 4708 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4699 | Rev 4704 | ||
---|---|---|---|
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 nildummy |
29 | /** @addtogroup nildummy |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** @file |
33 | /** @file |
34 | * Dummy network interface layer module implementation. |
34 | * Dummy network interface layer module implementation. |
35 | * @see nildummy.h |
35 | * @see nildummy.h |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include <async.h> |
38 | #include <async.h> |
39 | #include <malloc.h> |
39 | #include <malloc.h> |
40 | #include <mem.h> |
40 | #include <mem.h> |
41 | #include <stdio.h> |
41 | #include <stdio.h> |
42 | #include <string.h> |
42 | #include <string.h> |
43 | 43 | ||
44 | #include <ipc/ipc.h> |
44 | #include <ipc/ipc.h> |
45 | #include <ipc/services.h> |
45 | #include <ipc/services.h> |
46 | 46 | ||
47 | #include "../../err.h" |
47 | #include "../../err.h" |
48 | #include "../../messages.h" |
48 | #include "../../messages.h" |
49 | #include "../../modules.h" |
49 | #include "../../modules.h" |
50 | 50 | ||
51 | #include "../../include/device.h" |
51 | #include "../../include/device.h" |
52 | #include "../../include/netif_interface.h" |
52 | #include "../../include/netif_interface.h" |
53 | #include "../../include/nil_interface.h" |
53 | #include "../../include/nil_interface.h" |
54 | #include "../../include/il_interface.h" |
54 | #include "../../include/il_interface.h" |
55 | 55 | ||
56 | #include "../../structures/measured_strings.h" |
56 | #include "../../structures/measured_strings.h" |
57 | #include "../../structures/packet/packet.h" |
57 | #include "../../structures/packet/packet.h" |
58 | 58 | ||
59 | #include "../nil_module.h" |
59 | #include "../nil_module.h" |
60 | 60 | ||
61 | #include "nildummy.h" |
61 | #include "nildummy.h" |
62 | 62 | ||
63 | /** Default maximum transmission unit. |
63 | /** Default maximum transmission unit. |
64 | */ |
64 | */ |
65 | #define DEFAULT_MTU 1500 |
65 | #define DEFAULT_MTU 1500 |
66 | 66 | ||
67 | /** Network interface layer module global data. |
67 | /** Network interface layer module global data. |
68 | */ |
68 | */ |
69 | nildummy_globals_t nildummy_globals; |
69 | nildummy_globals_t nildummy_globals; |
70 | 70 | ||
- | 71 | /** @name Message processing functions |
|
- | 72 | */ |
|
- | 73 | /*@{*/ |
|
- | 74 | ||
71 | /** Processes IPC messages from the registered device driver modules in an infinite loop. |
75 | /** Processes IPC messages from the registered device driver modules in an infinite loop. |
72 | * @param iid The message identifier. Input parameter. |
76 | * @param iid The message identifier. Input parameter. |
73 | * @param icall The message parameters. Input/output parameter. |
77 | * @param icall The message parameters. Input/output parameter. |
74 | */ |
78 | */ |
75 | void nildummy_receiver( ipc_callid_t iid, ipc_call_t * icall ); |
79 | void nildummy_receiver( ipc_callid_t iid, ipc_call_t * icall ); |
76 | 80 | ||
77 | /** Registers new device or updates the MTU of an existing one. |
81 | /** Registers new device or updates the MTU of an existing one. |
78 | * Determines the device local hardware address. |
82 | * Determines the device local hardware address. |
79 | * @param device_id The new device identifier. Input parameter. |
83 | * @param device_id The new device identifier. Input parameter. |
80 | * @param service The device driver service. Input parameter. |
84 | * @param service The device driver service. Input parameter. |
81 | * @param mtu The device maximum transmission unit. Input parameter. |
85 | * @param mtu The device maximum transmission unit. Input parameter. |
82 | * @returns EOK on success. |
86 | * @returns EOK on success. |
83 | * @returns EEXIST if the device with the different service exists. |
87 | * @returns EEXIST if the device with the different service exists. |
84 | * @returns ENOMEM if there is not enough memory left. |
88 | * @returns ENOMEM if there is not enough memory left. |
85 | * @returns Other error codes as defined for the netif_bind_service() function. |
89 | * @returns Other error codes as defined for the netif_bind_service() function. |
86 | * @returns Other error codes as defined for the netif_get_addr() function. |
90 | * @returns Other error codes as defined for the netif_get_addr() function. |
87 | */ |
91 | */ |
88 | int nildummy_device_message( device_id_t device_id, services_t service, size_t mtu ); |
92 | int nildummy_device_message( device_id_t device_id, services_t service, size_t mtu ); |
89 | 93 | ||
90 | /** Returns the device packet dimensions for sending. |
94 | /** Returns the device packet dimensions for sending. |
91 | * @param device_id The device identifier. Input parameter. |
95 | * @param device_id The device identifier. Input parameter. |
92 | * @param addr_len The minimum reserved address length. Output parameter. |
96 | * @param addr_len The minimum reserved address length. Output parameter. |
93 | * @param prefix The minimum reserved prefix size. Output parameter. |
97 | * @param prefix The minimum reserved prefix size. Output parameter. |
94 | * @param content The maximum content size. Output parameter. |
98 | * @param content The maximum content size. Output parameter. |
95 | * @param suffix The minimum reserved suffix size. Output parameter. |
99 | * @param suffix The minimum reserved suffix size. Output parameter. |
96 | * @returns EOK on success. |
100 | * @returns EOK on success. |
97 | * @returns EBADMEM if either one of the parameters is NULL. |
101 | * @returns EBADMEM if either one of the parameters is NULL. |
98 | * @returns ENOENT if there is no such device. |
102 | * @returns ENOENT if there is no such device. |
99 | */ |
103 | */ |
100 | int nildummy_packet_space_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ); |
104 | int nildummy_packet_space_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ); |
101 | 105 | ||
102 | /** Registers receiving module service. |
106 | /** Registers receiving module service. |
103 | * Passes received packets for this service. |
107 | * Passes received packets for this service. |
104 | * @param service The module service. Input parameter. |
108 | * @param service The module service. Input parameter. |
105 | * @param phone The service phone. Input parameter. |
109 | * @param phone The service phone. Input parameter. |
106 | * @returns EOK on success. |
110 | * @returns EOK on success. |
107 | * @returns ENOENT if the service is not known. |
111 | * @returns ENOENT if the service is not known. |
108 | * @returns ENOMEM if there is not enough memory left. |
112 | * @returns ENOMEM if there is not enough memory left. |
109 | */ |
113 | */ |
110 | int nildummy_register_message( services_t service, int phone ); |
114 | int nildummy_register_message( services_t service, int phone ); |
111 | 115 | ||
112 | /** Sends the packet queue. |
116 | /** Sends the packet queue. |
113 | * @param device_id The device identifier. Input parameter. |
117 | * @param device_id The device identifier. Input parameter. |
114 | * @param packet The packet queue. Input parameter. |
118 | * @param packet The packet queue. Input parameter. |
115 | * @param sender The sending module service. Input parameter. |
119 | * @param sender The sending module service. Input parameter. |
116 | * @returns EOK on success. |
120 | * @returns EOK on success. |
117 | * @returns ENOENT if there no such device. |
121 | * @returns ENOENT if there no such device. |
118 | * @returns EINVAL if the service parameter is not known. |
122 | * @returns EINVAL if the service parameter is not known. |
119 | */ |
123 | */ |
120 | int nildummy_send_message( device_id_t device_id, packet_t packet, services_t sender ); |
124 | int nildummy_send_message( device_id_t device_id, packet_t packet, services_t sender ); |
121 | 125 | ||
122 | /** Returns the device hardware address. |
126 | /** Returns the device hardware address. |
123 | * @param device_id The device identifier. Input parameter. |
127 | * @param device_id The device identifier. Input parameter. |
124 | * @param address The device hardware address. Output parameter. |
128 | * @param address The device hardware address. Output parameter. |
125 | * @returns EOK on success. |
129 | * @returns EOK on success. |
126 | * @returns EBADMEM if the address parameter is NULL. |
130 | * @returns EBADMEM if the address parameter is NULL. |
127 | * @returns ENOENT if there no such device. |
131 | * @returns ENOENT if there no such device. |
128 | */ |
132 | */ |
129 | int nildummy_addr_message( device_id_t device_id, measured_string_ref * address ); |
133 | int nildummy_addr_message( device_id_t device_id, measured_string_ref * address ); |
130 | 134 | ||
- | 135 | /*@}*/ |
|
- | 136 | ||
131 | DEVICE_MAP_IMPLEMENT( nildummy_devices, nildummy_device_t ) |
137 | DEVICE_MAP_IMPLEMENT( nildummy_devices, nildummy_device_t ) |
132 | 138 | ||
133 | int nil_device_state_msg( int nil_phone, device_id_t device_id, int state ){ |
139 | int nil_device_state_msg( int nil_phone, device_id_t device_id, int state ){ |
134 | fibril_rwlock_read_lock( & nildummy_globals.protos_lock ); |
140 | fibril_rwlock_read_lock( & nildummy_globals.protos_lock ); |
135 | if( nildummy_globals.proto.phone ) il_device_state_msg( nildummy_globals.proto.phone, device_id, state, nildummy_globals.proto.service ); |
141 | if( nildummy_globals.proto.phone ) il_device_state_msg( nildummy_globals.proto.phone, device_id, state, nildummy_globals.proto.service ); |
136 | fibril_rwlock_read_unlock( & nildummy_globals.protos_lock ); |
142 | fibril_rwlock_read_unlock( & nildummy_globals.protos_lock ); |
137 | return EOK; |
143 | return EOK; |
138 | } |
144 | } |
139 | 145 | ||
140 | int nil_initialize( int net_phone ){ |
146 | int nil_initialize( int net_phone ){ |
141 | ERROR_DECLARE; |
147 | ERROR_DECLARE; |
142 | 148 | ||
143 | fibril_rwlock_initialize( & nildummy_globals.devices_lock ); |
149 | fibril_rwlock_initialize( & nildummy_globals.devices_lock ); |
144 | fibril_rwlock_initialize( & nildummy_globals.protos_lock ); |
150 | fibril_rwlock_initialize( & nildummy_globals.protos_lock ); |
145 | fibril_rwlock_write_lock( & nildummy_globals.devices_lock ); |
151 | fibril_rwlock_write_lock( & nildummy_globals.devices_lock ); |
146 | fibril_rwlock_write_lock( & nildummy_globals.protos_lock ); |
152 | fibril_rwlock_write_lock( & nildummy_globals.protos_lock ); |
147 | nildummy_globals.net_phone = net_phone; |
153 | nildummy_globals.net_phone = net_phone; |
148 | nildummy_globals.proto.phone = 0; |
154 | nildummy_globals.proto.phone = 0; |
149 | ERROR_PROPAGATE( nildummy_devices_initialize( & nildummy_globals.devices )); |
155 | ERROR_PROPAGATE( nildummy_devices_initialize( & nildummy_globals.devices )); |
150 | fibril_rwlock_write_unlock( & nildummy_globals.protos_lock ); |
156 | fibril_rwlock_write_unlock( & nildummy_globals.protos_lock ); |
151 | fibril_rwlock_write_unlock( & nildummy_globals.devices_lock ); |
157 | fibril_rwlock_write_unlock( & nildummy_globals.devices_lock ); |
152 | return EOK; |
158 | return EOK; |
153 | } |
159 | } |
154 | 160 | ||
155 | int nildummy_device_message( device_id_t device_id, services_t service, size_t mtu ){ |
161 | int nildummy_device_message( device_id_t device_id, services_t service, size_t mtu ){ |
156 | ERROR_DECLARE; |
162 | ERROR_DECLARE; |
157 | 163 | ||
158 | nildummy_device_ref device; |
164 | nildummy_device_ref device; |
159 | int index; |
165 | int index; |
160 | 166 | ||
161 | fibril_rwlock_write_lock( & nildummy_globals.devices_lock ); |
167 | fibril_rwlock_write_lock( & nildummy_globals.devices_lock ); |
162 | // an existing device? |
168 | // an existing device? |
163 | device = nildummy_devices_find( & nildummy_globals.devices, device_id ); |
169 | device = nildummy_devices_find( & nildummy_globals.devices, device_id ); |
164 | if( device ){ |
170 | if( device ){ |
165 | if( device->service != service ){ |
171 | if( device->service != service ){ |
166 | printf( "Device %d already exists\n", device->device_id ); |
172 | printf( "Device %d already exists\n", device->device_id ); |
167 | fibril_rwlock_write_unlock( & nildummy_globals.devices_lock ); |
173 | fibril_rwlock_write_unlock( & nildummy_globals.devices_lock ); |
168 | return EEXIST; |
174 | return EEXIST; |
169 | }else{ |
175 | }else{ |
170 | // update mtu |
176 | // update mtu |
171 | device->mtu = mtu; |
177 | device->mtu = mtu; |
172 | printf( "Device %d already exists:\tMTU\t= %d\n", device->device_id, device->mtu ); |
178 | printf( "Device %d already exists:\tMTU\t= %d\n", device->device_id, device->mtu ); |
173 | fibril_rwlock_write_unlock( & nildummy_globals.devices_lock ); |
179 | fibril_rwlock_write_unlock( & nildummy_globals.devices_lock ); |
174 | // notify the upper layer module |
180 | // notify the upper layer module |
175 | fibril_rwlock_read_lock( & nildummy_globals.protos_lock ); |
181 | fibril_rwlock_read_lock( & nildummy_globals.protos_lock ); |
176 | if( nildummy_globals.proto.phone ){ |
182 | if( nildummy_globals.proto.phone ){ |
177 | il_mtu_changed_msg( nildummy_globals.proto.phone, device->device_id, device->mtu, nildummy_globals.proto.service ); |
183 | il_mtu_changed_msg( nildummy_globals.proto.phone, device->device_id, device->mtu, nildummy_globals.proto.service ); |
178 | } |
184 | } |
179 | fibril_rwlock_read_unlock( & nildummy_globals.protos_lock ); |
185 | fibril_rwlock_read_unlock( & nildummy_globals.protos_lock ); |
180 | return EOK; |
186 | return EOK; |
181 | } |
187 | } |
182 | }else{ |
188 | }else{ |
183 | // create a new device |
189 | // create a new device |
184 | device = ( nildummy_device_ref ) malloc( sizeof( nildummy_device_t )); |
190 | device = ( nildummy_device_ref ) malloc( sizeof( nildummy_device_t )); |
185 | if( ! device ) return ENOMEM; |
191 | if( ! device ) return ENOMEM; |
186 | device->device_id = device_id; |
192 | device->device_id = device_id; |
187 | device->service = service; |
193 | device->service = service; |
188 | if( mtu > 0 ){ |
194 | if( mtu > 0 ){ |
189 | device->mtu = mtu; |
195 | device->mtu = mtu; |
190 | }else{ |
196 | }else{ |
191 | device->mtu = DEFAULT_MTU; |
197 | device->mtu = DEFAULT_MTU; |
192 | } |
198 | } |
193 | // bind the device driver |
199 | // bind the device driver |
194 | device->phone = netif_bind_service( device->service, device->device_id, SERVICE_ETHERNET, nildummy_receiver ); |
200 | device->phone = netif_bind_service( device->service, device->device_id, SERVICE_ETHERNET, nildummy_receiver ); |
195 | if( device->phone < 0 ){ |
201 | if( device->phone < 0 ){ |
196 | fibril_rwlock_write_unlock( & nildummy_globals.devices_lock ); |
202 | fibril_rwlock_write_unlock( & nildummy_globals.devices_lock ); |
197 | free( device ); |
203 | free( device ); |
198 | return device->phone; |
204 | return device->phone; |
199 | } |
205 | } |
200 | // get hardware address |
206 | // get hardware address |
201 | if( ERROR_OCCURRED( netif_get_addr( device->phone, device->device_id, & device->addr, & device->addr_data ))){ |
207 | if( ERROR_OCCURRED( netif_get_addr( device->phone, device->device_id, & device->addr, & device->addr_data ))){ |
202 | fibril_rwlock_write_unlock( & nildummy_globals.devices_lock ); |
208 | fibril_rwlock_write_unlock( & nildummy_globals.devices_lock ); |
203 | free( device ); |
209 | free( device ); |
204 | return ERROR_CODE; |
210 | return ERROR_CODE; |
205 | } |
211 | } |
206 | // add to the cache |
212 | // add to the cache |
207 | index = nildummy_devices_add( & nildummy_globals.devices, device->device_id, device ); |
213 | index = nildummy_devices_add( & nildummy_globals.devices, device->device_id, device ); |
208 | if( index < 0 ){ |
214 | if( index < 0 ){ |
209 | fibril_rwlock_write_unlock( & nildummy_globals.devices_lock ); |
215 | fibril_rwlock_write_unlock( & nildummy_globals.devices_lock ); |
210 | free( device->addr ); |
216 | free( device->addr ); |
211 | free( device->addr_data ); |
217 | free( device->addr_data ); |
212 | free( device ); |
218 | free( device ); |
213 | return index; |
219 | return index; |
214 | } |
220 | } |
215 | printf( "New device registered:\n\tid\t= %d\n\tservice\t= %d\n\tMTU\t= %d\n", device->device_id, device->service, device->mtu ); |
221 | printf( "New device registered:\n\tid\t= %d\n\tservice\t= %d\n\tMTU\t= %d\n", device->device_id, device->service, device->mtu ); |
216 | } |
222 | } |
217 | fibril_rwlock_write_unlock( & nildummy_globals.devices_lock ); |
223 | fibril_rwlock_write_unlock( & nildummy_globals.devices_lock ); |
218 | return EOK; |
224 | return EOK; |
219 | } |
225 | } |
220 | 226 | ||
221 | int nildummy_addr_message( device_id_t device_id, measured_string_ref * address ){ |
227 | int nildummy_addr_message( device_id_t device_id, measured_string_ref * address ){ |
222 | nildummy_device_ref device; |
228 | nildummy_device_ref device; |
223 | 229 | ||
224 | if( ! address ) return EBADMEM; |
230 | if( ! address ) return EBADMEM; |
225 | fibril_rwlock_read_lock( & nildummy_globals.devices_lock ); |
231 | fibril_rwlock_read_lock( & nildummy_globals.devices_lock ); |
226 | device = nildummy_devices_find( & nildummy_globals.devices, device_id ); |
232 | device = nildummy_devices_find( & nildummy_globals.devices, device_id ); |
227 | if( ! device ){ |
233 | if( ! device ){ |
228 | fibril_rwlock_read_unlock( & nildummy_globals.devices_lock ); |
234 | fibril_rwlock_read_unlock( & nildummy_globals.devices_lock ); |
229 | return ENOENT; |
235 | return ENOENT; |
230 | } |
236 | } |
231 | * address = device->addr; |
237 | * address = device->addr; |
232 | fibril_rwlock_read_unlock( & nildummy_globals.devices_lock ); |
238 | fibril_rwlock_read_unlock( & nildummy_globals.devices_lock ); |
233 | return ( * address ) ? EOK : ENOENT; |
239 | return ( * address ) ? EOK : ENOENT; |
234 | } |
240 | } |
235 | 241 | ||
236 | int nildummy_packet_space_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ){ |
242 | int nildummy_packet_space_message( device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ){ |
237 | nildummy_device_ref device; |
243 | nildummy_device_ref device; |
238 | 244 | ||
239 | if( !( addr_len && prefix && content && suffix )) return EBADMEM; |
245 | if( !( addr_len && prefix && content && suffix )) return EBADMEM; |
240 | fibril_rwlock_read_lock( & nildummy_globals.devices_lock ); |
246 | fibril_rwlock_read_lock( & nildummy_globals.devices_lock ); |
241 | device = nildummy_devices_find( & nildummy_globals.devices, device_id ); |
247 | device = nildummy_devices_find( & nildummy_globals.devices, device_id ); |
242 | if( ! device ){ |
248 | if( ! device ){ |
243 | fibril_rwlock_read_unlock( & nildummy_globals.devices_lock ); |
249 | fibril_rwlock_read_unlock( & nildummy_globals.devices_lock ); |
244 | return ENOENT; |
250 | return ENOENT; |
245 | } |
251 | } |
246 | * content = device->mtu; |
252 | * content = device->mtu; |
247 | fibril_rwlock_read_unlock( & nildummy_globals.devices_lock ); |
253 | fibril_rwlock_read_unlock( & nildummy_globals.devices_lock ); |
248 | * addr_len = 0; |
254 | * addr_len = 0; |
249 | * prefix = 0; |
255 | * prefix = 0; |
250 | * suffix = 0; |
256 | * suffix = 0; |
251 | return EOK; |
257 | return EOK; |
252 | } |
258 | } |
253 | 259 | ||
254 | int nil_received_msg( int nil_phone, device_id_t device_id, packet_t packet, services_t target ){ |
260 | int nil_received_msg( int nil_phone, device_id_t device_id, packet_t packet, services_t target ){ |
255 | packet_t next; |
261 | packet_t next; |
256 | 262 | ||
257 | fibril_rwlock_read_lock( & nildummy_globals.protos_lock ); |
263 | fibril_rwlock_read_lock( & nildummy_globals.protos_lock ); |
258 | if( nildummy_globals.proto.phone ){ |
264 | if( nildummy_globals.proto.phone ){ |
259 | do{ |
265 | do{ |
260 | next = pq_detach( packet ); |
266 | next = pq_detach( packet ); |
261 | il_received_msg( nildummy_globals.proto.phone, device_id, packet, nildummy_globals.proto.service ); |
267 | il_received_msg( nildummy_globals.proto.phone, device_id, packet, nildummy_globals.proto.service ); |
262 | packet = next; |
268 | packet = next; |
263 | }while( packet ); |
269 | }while( packet ); |
264 | } |
270 | } |
265 | fibril_rwlock_read_unlock( & nildummy_globals.protos_lock ); |
271 | fibril_rwlock_read_unlock( & nildummy_globals.protos_lock ); |
266 | return EOK; |
272 | return EOK; |
267 | } |
273 | } |
268 | 274 | ||
269 | int nildummy_register_message( services_t service, int phone ){ |
275 | int nildummy_register_message( services_t service, int phone ){ |
270 | fibril_rwlock_write_lock( & nildummy_globals.protos_lock ); |
276 | fibril_rwlock_write_lock( & nildummy_globals.protos_lock ); |
271 | nildummy_globals.proto.service = service; |
277 | nildummy_globals.proto.service = service; |
272 | nildummy_globals.proto.phone = phone; |
278 | nildummy_globals.proto.phone = phone; |
273 | printf( "New protocol registered:\n\tservice\t= %d\n\tphone\t= %d\n", nildummy_globals.proto.service, nildummy_globals.proto.phone ); |
279 | printf( "New protocol registered:\n\tservice\t= %d\n\tphone\t= %d\n", nildummy_globals.proto.service, nildummy_globals.proto.phone ); |
274 | fibril_rwlock_write_unlock( & nildummy_globals.protos_lock ); |
280 | fibril_rwlock_write_unlock( & nildummy_globals.protos_lock ); |
275 | return EOK; |
281 | return EOK; |
276 | } |
282 | } |
277 | 283 | ||
278 | int nildummy_send_message( device_id_t device_id, packet_t packet, services_t sender ){ |
284 | int nildummy_send_message( device_id_t device_id, packet_t packet, services_t sender ){ |
279 | nildummy_device_ref device; |
285 | nildummy_device_ref device; |
280 | 286 | ||
281 | fibril_rwlock_read_lock( & nildummy_globals.devices_lock ); |
287 | fibril_rwlock_read_lock( & nildummy_globals.devices_lock ); |
282 | device = nildummy_devices_find( & nildummy_globals.devices, device_id ); |
288 | device = nildummy_devices_find( & nildummy_globals.devices, device_id ); |
283 | if( ! device ){ |
289 | if( ! device ){ |
284 | fibril_rwlock_read_unlock( & nildummy_globals.devices_lock ); |
290 | fibril_rwlock_read_unlock( & nildummy_globals.devices_lock ); |
285 | return ENOENT; |
291 | return ENOENT; |
286 | } |
292 | } |
287 | // send packet queue |
293 | // send packet queue |
288 | if( packet ){ |
294 | if( packet ){ |
289 | netif_send_msg( device->phone, device_id, packet, SERVICE_NILDUMMY ); |
295 | netif_send_msg( device->phone, device_id, packet, SERVICE_NILDUMMY ); |
290 | } |
296 | } |
291 | fibril_rwlock_read_unlock( & nildummy_globals.devices_lock ); |
297 | fibril_rwlock_read_unlock( & nildummy_globals.devices_lock ); |
292 | return EOK; |
298 | return EOK; |
293 | } |
299 | } |
294 | 300 | ||
295 | int nil_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
301 | int nil_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
296 | ERROR_DECLARE; |
302 | ERROR_DECLARE; |
297 | 303 | ||
298 | measured_string_ref address; |
304 | measured_string_ref address; |
299 | packet_t packet; |
305 | packet_t packet; |
300 | 306 | ||
301 | // printf( "message %d - %d\n", IPC_GET_METHOD( * call ), NET_NIL_FIRST ); |
307 | // printf( "message %d - %d\n", IPC_GET_METHOD( * call ), NET_NIL_FIRST ); |
302 | * answer_count = 0; |
308 | * answer_count = 0; |
303 | switch( IPC_GET_METHOD( * call )){ |
309 | switch( IPC_GET_METHOD( * call )){ |
304 | case IPC_M_PHONE_HUNGUP: |
310 | case IPC_M_PHONE_HUNGUP: |
305 | return EOK; |
311 | return EOK; |
306 | case NET_NIL_DEVICE: |
312 | case NET_NIL_DEVICE: |
307 | return nildummy_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), IPC_GET_MTU( call )); |
313 | return nildummy_device_message( IPC_GET_DEVICE( call ), IPC_GET_SERVICE( call ), IPC_GET_MTU( call )); |
308 | case NET_NIL_SEND: |
314 | case NET_NIL_SEND: |
309 | ERROR_PROPAGATE( packet_translate( nildummy_globals.net_phone, & packet, IPC_GET_PACKET( call ))); |
315 | ERROR_PROPAGATE( packet_translate( nildummy_globals.net_phone, & packet, IPC_GET_PACKET( call ))); |
310 | return nildummy_send_message( IPC_GET_DEVICE( call ), packet, IPC_GET_SERVICE( call )); |
316 | return nildummy_send_message( IPC_GET_DEVICE( call ), packet, IPC_GET_SERVICE( call )); |
311 | case NET_NIL_PACKET_SPACE: |
317 | case NET_NIL_PACKET_SPACE: |
312 | ERROR_PROPAGATE( nildummy_packet_space_message( IPC_GET_DEVICE( call ), IPC_SET_ADDR( answer ), IPC_SET_PREFIX( answer ), IPC_SET_CONTENT( answer ), IPC_SET_SUFFIX( answer ))); |
318 | ERROR_PROPAGATE( nildummy_packet_space_message( IPC_GET_DEVICE( call ), IPC_SET_ADDR( answer ), IPC_SET_PREFIX( answer ), IPC_SET_CONTENT( answer ), IPC_SET_SUFFIX( answer ))); |
313 | * answer_count = 4; |
319 | * answer_count = 4; |
314 | return EOK; |
320 | return EOK; |
315 | case NET_NIL_ADDR: |
321 | case NET_NIL_ADDR: |
316 | ERROR_PROPAGATE( nildummy_addr_message( IPC_GET_DEVICE( call ), & address )); |
322 | ERROR_PROPAGATE( nildummy_addr_message( IPC_GET_DEVICE( call ), & address )); |
317 | return measured_strings_reply( address, 1 ); |
323 | return measured_strings_reply( address, 1 ); |
318 | case IPC_M_CONNECT_TO_ME: |
324 | case IPC_M_CONNECT_TO_ME: |
319 | return nildummy_register_message( NIL_GET_PROTO( call ), IPC_GET_PHONE( call )); |
325 | return nildummy_register_message( NIL_GET_PROTO( call ), IPC_GET_PHONE( call )); |
320 | } |
326 | } |
321 | return ENOTSUP; |
327 | return ENOTSUP; |
322 | } |
328 | } |
323 | 329 | ||
324 | void nildummy_receiver( ipc_callid_t iid, ipc_call_t * icall ){ |
330 | void nildummy_receiver( ipc_callid_t iid, ipc_call_t * icall ){ |
325 | ERROR_DECLARE; |
331 | ERROR_DECLARE; |
326 | 332 | ||
327 | packet_t packet; |
333 | packet_t packet; |
328 | 334 | ||
329 | while( true ){ |
335 | while( true ){ |
330 | // printf( "message %d - %d\n", IPC_GET_METHOD( * icall ), NET_NIL_FIRST ); |
336 | // printf( "message %d - %d\n", IPC_GET_METHOD( * icall ), NET_NIL_FIRST ); |
331 | switch( IPC_GET_METHOD( * icall )){ |
337 | switch( IPC_GET_METHOD( * icall )){ |
332 | case NET_NIL_DEVICE_STATE: |
338 | case NET_NIL_DEVICE_STATE: |
333 | ERROR_CODE = nil_device_state_msg( 0, IPC_GET_DEVICE( icall ), IPC_GET_STATE( icall )); |
339 | ERROR_CODE = nil_device_state_msg( 0, IPC_GET_DEVICE( icall ), IPC_GET_STATE( icall )); |
334 | ipc_answer_0( iid, ERROR_CODE ); |
340 | ipc_answer_0( iid, ERROR_CODE ); |
335 | break; |
341 | break; |
336 | case NET_NIL_RECEIVED: |
342 | case NET_NIL_RECEIVED: |
337 | if( ! ERROR_OCCURRED( packet_translate( nildummy_globals.net_phone, & packet, IPC_GET_PACKET( icall )))){ |
343 | if( ! ERROR_OCCURRED( packet_translate( nildummy_globals.net_phone, & packet, IPC_GET_PACKET( icall )))){ |
338 | ERROR_CODE = nil_received_msg( 0, IPC_GET_DEVICE( icall ), packet, 0 ); |
344 | ERROR_CODE = nil_received_msg( 0, IPC_GET_DEVICE( icall ), packet, 0 ); |
339 | } |
345 | } |
340 | ipc_answer_0( iid, ( ipcarg_t ) ERROR_CODE ); |
346 | ipc_answer_0( iid, ( ipcarg_t ) ERROR_CODE ); |
341 | break; |
347 | break; |
342 | default: |
348 | default: |
343 | ipc_answer_0( iid, ( ipcarg_t ) ENOTSUP ); |
349 | ipc_answer_0( iid, ( ipcarg_t ) ENOTSUP ); |
344 | } |
350 | } |
345 | iid = async_get_call( icall ); |
351 | iid = async_get_call( icall ); |
346 | } |
352 | } |
347 | } |
353 | } |
348 | 354 | ||
349 | /** @} |
355 | /** @} |
350 | */ |
356 | */ |
351 | 357 |