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