Rev 4715 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3466 | mejdrech | 1 | /* |
3912 | mejdrech | 2 | * Copyright (c) 2009 Lukas Mejdrech |
3466 | mejdrech | 3 | * All rights reserved. |
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
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 |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
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 |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
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 |
||
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 |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
29 | /** @addtogroup net |
||
3912 | mejdrech | 30 | * @{ |
3466 | mejdrech | 31 | */ |
32 | |||
33 | /** @file |
||
4703 | mejdrech | 34 | * \todo |
3466 | mejdrech | 35 | */ |
36 | |||
3846 | mejdrech | 37 | #ifndef __NET_MESSAGES_H__ |
38 | #define __NET_MESSAGES_H__ |
||
39 | |||
4261 | mejdrech | 40 | #include <async.h> |
41 | |||
42 | #include <ipc/ipc.h> |
||
43 | #include <ipc/services.h> |
||
44 | |||
45 | #include "include/device.h" |
||
46 | |||
47 | #include "structures/measured_strings.h" |
||
48 | #include "structures/packet/packet.h" |
||
49 | |||
4703 | mejdrech | 50 | #define NET_NETIF_COUNT 6 |
3846 | mejdrech | 51 | #define NET_NET_COUNT 9 |
4261 | mejdrech | 52 | #define NET_NIL_COUNT 7 |
3846 | mejdrech | 53 | #define NET_ETH_COUNT 0 |
4695 | mejdrech | 54 | #define NET_IL_COUNT 6 |
4722 | mejdrech | 55 | #define NET_IP_COUNT 4 |
4695 | mejdrech | 56 | #define NET_ARP_COUNT 5 |
3666 | mejdrech | 57 | #define NET_RARP_COUNT 0 |
4715 | mejdrech | 58 | #define NET_ICMP_COUNT 7 |
4502 | mejdrech | 59 | #define NET_TL_COUNT 1 |
3666 | mejdrech | 60 | #define NET_UDP_COUNT 0 |
61 | #define NET_TCP_COUNT 0 |
||
3901 | mejdrech | 62 | #define NET_PACKET_COUNT 5 |
4578 | mejdrech | 63 | #define NET_SOCKET_COUNT 14 |
3666 | mejdrech | 64 | |
4307 | mejdrech | 65 | #define NET_FIRST 2000 |
3666 | mejdrech | 66 | |
67 | #define NET_NETIF_FIRST NET_FIRST |
||
68 | #define NET_NETIF_LAST ( NET_NETIF_FIRST + NET_NETIF_COUNT ) |
||
69 | |||
3846 | mejdrech | 70 | #define NET_NET_FIRST ( NET_NETIF_LAST + 0 ) |
71 | #define NET_NET_LAST ( NET_NET_FIRST + NET_NET_COUNT ) |
||
3666 | mejdrech | 72 | |
3846 | mejdrech | 73 | #define NET_NIL_FIRST ( NET_NET_LAST + 0 ) |
74 | #define NET_NIL_LAST ( NET_NIL_FIRST + NET_NIL_COUNT ) |
||
75 | #define NET_ETH_FIRST ( NET_NIL_LAST + 0 ) |
||
76 | #define NET_ETH_LAST ( NET_ETH_FIRST + NET_ETH_COUNT ) |
||
3666 | mejdrech | 77 | |
3846 | mejdrech | 78 | #define NET_IL_FIRST ( NET_ETH_LAST + 0 ) |
4307 | mejdrech | 79 | #define NET_IL_LAST ( NET_IL_FIRST + NET_IL_COUNT ) |
3666 | mejdrech | 80 | #define NET_IP_FIRST ( NET_IL_LAST + 0 ) |
4307 | mejdrech | 81 | #define NET_IP_LAST ( NET_IP_FIRST + NET_IP_COUNT ) |
3666 | mejdrech | 82 | |
3466 | mejdrech | 83 | #define NET_ARP_FIRST ( NET_IP_LAST + 0 ) |
3666 | mejdrech | 84 | #define NET_ARP_LAST ( NET_ARP_FIRST + NET_ARP_COUNT ) |
3466 | mejdrech | 85 | #define NET_RARP_FIRST ( NET_ARP_LAST + 0 ) |
3666 | mejdrech | 86 | #define NET_RARP_LAST ( NET_RARP_FIRST + NET_RARP_COUNT ) |
3466 | mejdrech | 87 | #define NET_ICMP_FIRST ( NET_RARP_LAST + 0 ) |
3666 | mejdrech | 88 | #define NET_ICMP_LAST ( NET_ICMP_FIRST + NET_ICMP_COUNT ) |
4502 | mejdrech | 89 | |
90 | #define NET_TL_FIRST ( NET_ICMP_LAST + 0 ) |
||
91 | #define NET_TL_LAST ( NET_TL_FIRST + NET_TL_COUNT ) |
||
92 | #define NET_UDP_FIRST ( NET_TL_LAST + 0 ) |
||
3666 | mejdrech | 93 | #define NET_UDP_LAST ( NET_UDP_FIRST + NET_UDP_COUNT ) |
3466 | mejdrech | 94 | #define NET_TCP_FIRST ( NET_UDP_LAST + 0 ) |
3666 | mejdrech | 95 | #define NET_TCP_LAST ( NET_TCP_FIRST + NET_TCP_COUNT ) |
96 | |||
3466 | mejdrech | 97 | #define NET_SOCKET_FIRST ( NET_TCP_LAST + 0 ) |
3666 | mejdrech | 98 | #define NET_SOCKET_LAST ( NET_SOCKET_FIRST + NET_SOCKET_COUNT ) |
3466 | mejdrech | 99 | |
3901 | mejdrech | 100 | #define NET_PACKET_FIRST ( NET_SOCKET_LAST + 0 ) |
101 | #define NET_PACKET_LAST ( NET_PACKET_FIRST + NET_PACKET_COUNT ) |
||
3666 | mejdrech | 102 | |
4307 | mejdrech | 103 | #define NET_LAST NET_PACKET_LAST |
3901 | mejdrech | 104 | |
4307 | mejdrech | 105 | #define NET_COUNT ( NET_LAST - NET_FIRST ) |
3666 | mejdrech | 106 | |
107 | #define IS_IN_INTERVAL( item, first_inclusive, last_exclusive ) ((( item ) >= ( first_inclusive )) && (( item ) < ( last_exclusive ))) |
||
108 | |||
3901 | mejdrech | 109 | #define IS_NET_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_FIRST, NET_LAST ) |
110 | #define IS_NET_NET_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_NET_FIRST, NET_NET_LAST ) |
||
111 | #define IS_NET_NIL_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_NIL_FIRST, NET_NIL_LAST ) |
||
112 | #define IS_NET_ETH_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_ETH_FIRST, NET_ETH_LAST ) |
||
113 | #define IS_NET_IL_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_IL_FIRST, NET_IL_LAST ) |
||
114 | #define IS_NET_IP_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_IP_FIRST, NET_IP_LAST ) |
||
115 | #define IS_NET_ARP_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_ARP_FIRST, NET_ARP_LAST ) |
||
116 | #define IS_NET_RARP_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_RARP_FIRST, NET_RARP_LAST ) |
||
4707 | mejdrech | 117 | #define IS_NET_ICMP_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_ICMP_FIRST, NET_ICMP_LAST ) |
4502 | mejdrech | 118 | #define IS_NET_TL_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_TL_FIRST, NET_TL_LAST ) |
3901 | mejdrech | 119 | #define IS_NET_UDP_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_UDP_FIRST, NET_UDP_LAST ) |
120 | #define IS_NET_TCP_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_TCP_FIRST, NET_TCP_LAST ) |
||
121 | #define IS_NET_SOCKET_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_SOCKET_FIRST, NET_SOCKET_LAST ) |
||
122 | #define IS_NET_PACKET_MESSAGE( call ) IS_IN_INTERVAL( IPC_GET_METHOD( * call ), NET_PACKET_FIRST, NET_PACKET_LAST ) |
||
3666 | mejdrech | 123 | |
4261 | mejdrech | 124 | /** Returns the device identifier message parameter. |
125 | */ |
||
126 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
||
127 | |||
128 | /** Returns the packet identifier message parameter. |
||
129 | */ |
||
130 | #define IPC_GET_PACKET( call ) ( packet_id_t ) IPC_GET_ARG2( * call ) |
||
4502 | mejdrech | 131 | #define IPC_GET_COUNT( call ) ( size_t ) IPC_GET_ARG2( * call ) |
4261 | mejdrech | 132 | #define IPC_GET_STATE( call ) ( device_state_t ) IPC_GET_ARG2( * call ) |
133 | |||
4695 | mejdrech | 134 | /** Returns the maximum transmission unit message parameter. |
135 | */ |
||
136 | #define IPC_GET_MTU( call ) ( size_t ) IPC_GET_ARG2( * call ) |
||
137 | |||
4261 | mejdrech | 138 | /** Returns the device driver service message parameter. |
139 | */ |
||
140 | #define IPC_GET_SERVICE( call ) ( services_t ) IPC_GET_ARG3( * call ) |
||
141 | #define IPC_GET_TARGET( call ) ( services_t ) IPC_GET_ARG3( * call ) |
||
142 | #define IPC_GET_SENDER( call ) ( services_t ) IPC_GET_ARG3( * call ) |
||
143 | |||
4707 | mejdrech | 144 | #define IPC_GET_ERROR( call ) ( services_t ) IPC_GET_ARG4( * call ) |
145 | |||
4243 | mejdrech | 146 | #define IPC_GET_PHONE( call ) ( int ) IPC_GET_ARG5( * call ) |
147 | |||
4722 | mejdrech | 148 | #define IPC_SET_DEVICE( answer ) (( device_id_t * ) & IPC_GET_ARG1( * answer )) |
149 | |||
4261 | mejdrech | 150 | #define IPC_SET_ADDR( answer ) (( size_t * ) & IPC_GET_ARG1( * answer )) |
151 | #define IPC_SET_PREFIX( answer ) (( size_t * ) & IPC_GET_ARG2( * answer )) |
||
152 | #define IPC_SET_CONTENT( answer ) (( size_t * ) & IPC_GET_ARG3( * answer )) |
||
153 | #define IPC_SET_SUFFIX( answer ) (( size_t * ) & IPC_GET_ARG4( * answer )) |
||
154 | |||
3466 | mejdrech | 155 | typedef enum { |
3846 | mejdrech | 156 | /* () not supported, registers new device */ |
157 | NET_NET_DEVICE = NET_NET_FIRST, |
||
3901 | mejdrech | 158 | /* ( NULL, count ), measured_strings_send( names ), measured_strings_return( values ) */ |
3846 | mejdrech | 159 | NET_NET_GET_CONF, |
3901 | mejdrech | 160 | /* ( device_id, count ), measured_strings_send( names ), measured_strings_return( values ) */ |
3846 | mejdrech | 161 | NET_NET_GET_DEVICE_CONF, |
162 | /* () not supported, measured_strings_send( names ), measured_strings_send( values ) */ |
||
163 | NET_NET_SET_CONF, |
||
3901 | mejdrech | 164 | /* ( device_id, count ) not supported, measured_strings_send( names ), measured_strings_send( values ) */ |
3846 | mejdrech | 165 | NET_NET_SET_DEVICE_CONF, |
166 | /* () */ |
||
167 | NET_NET_STARTUP, |
||
168 | /* ( device_id ) */ |
||
169 | NET_NET_START, |
||
170 | /* ( device_id ) */ |
||
171 | NET_NET_STOP, |
||
172 | /* ( device_id ) ipc_data_read( stats ) */ |
||
173 | NET_NET_STATS, |
||
3901 | mejdrech | 174 | } net_messages; |
3466 | mejdrech | 175 | |
4261 | mejdrech | 176 | static inline int generic_get_addr( int phone, int message, device_id_t device_id, measured_string_ref * address, char ** data ){ |
177 | aid_t message_id; |
||
178 | ipcarg_t result; |
||
179 | int string; |
||
180 | |||
181 | if( !( address && data )) return EBADMEM; |
||
4307 | mejdrech | 182 | message_id = async_send_1( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, NULL ); |
4261 | mejdrech | 183 | string = measured_strings_return( phone, address, data, 1 ); |
184 | async_wait_for( message_id, & result ); |
||
185 | if(( string == EOK ) && ( result != EOK )){ |
||
186 | free( * address ); |
||
187 | free( * data ); |
||
188 | } |
||
4307 | mejdrech | 189 | return ( int ) result; |
4261 | mejdrech | 190 | } |
191 | |||
4307 | mejdrech | 192 | static inline int generic_translate_req( int phone, int message, device_id_t device_id, services_t service, measured_string_ref configuration, size_t count, measured_string_ref * translation, char ** data ){ |
193 | aid_t message_id; |
||
194 | ipcarg_t result; |
||
195 | int string; |
||
196 | |||
197 | if( !( configuration && ( count > 0 ))) return EINVAL; |
||
198 | if( !( translation && data )) return EBADMEM; |
||
199 | message_id = async_send_3( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t ) count, ( ipcarg_t ) service, NULL ); |
||
200 | measured_strings_send( phone, configuration, count ); |
||
201 | string = measured_strings_return( phone, translation, data, count ); |
||
202 | async_wait_for( message_id, & result ); |
||
203 | if(( string == EOK ) && ( result != EOK )){ |
||
204 | free( * translation ); |
||
205 | free( * data ); |
||
206 | } |
||
207 | return ( int ) result; |
||
4261 | mejdrech | 208 | } |
209 | |||
4707 | mejdrech | 210 | static inline int generic_send_msg( int phone, int message, device_id_t device_id, packet_id_t packet_id, services_t sender, services_t error ){ |
211 | if( error ){ |
||
212 | async_msg_4( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t ) packet_id, ( ipcarg_t ) sender, ( ipcarg_t ) error ); |
||
213 | }else{ |
||
214 | async_msg_3( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t ) packet_id, ( ipcarg_t ) sender ); |
||
215 | } |
||
4307 | mejdrech | 216 | return EOK; |
217 | } |
||
218 | |||
4261 | mejdrech | 219 | static inline int generic_packet_size_req( int phone, int message, device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix ){ |
4307 | mejdrech | 220 | return ( int ) async_req_1_4( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t * ) addr_len, ( ipcarg_t * ) prefix, ( ipcarg_t * ) content, ( ipcarg_t * ) suffix ); |
4261 | mejdrech | 221 | } |
222 | |||
4351 | mejdrech | 223 | static inline int generic_device_state_msg( int phone, int message, device_id_t device_id, int state, services_t target ){ |
224 | async_msg_3( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t ) state, target ); |
||
4307 | mejdrech | 225 | return EOK; |
4261 | mejdrech | 226 | } |
227 | |||
4707 | mejdrech | 228 | static inline int generic_received_msg( int phone, int message, device_id_t device_id, packet_id_t packet_id, services_t target, services_t error ){ |
229 | if( error ){ |
||
230 | async_msg_4( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t ) packet_id, ( ipcarg_t ) target, ( ipcarg_t ) error ); |
||
231 | }else{ |
||
232 | async_msg_3( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t ) packet_id, ( ipcarg_t ) target ); |
||
233 | } |
||
4307 | mejdrech | 234 | return EOK; |
4261 | mejdrech | 235 | } |
236 | |||
237 | static inline int generic_device_req( int phone, int message, device_id_t device_id, int arg2, services_t service ){ |
||
4307 | mejdrech | 238 | return ( int ) async_req_3_0( phone, ( ipcarg_t ) message, ( ipcarg_t ) device_id, ( ipcarg_t ) arg2, ( ipcarg_t ) service ); |
4261 | mejdrech | 239 | } |
240 | |||
3846 | mejdrech | 241 | #endif |
242 | |||
3466 | mejdrech | 243 | /** @} |
244 | */ |