Rev 4075 | Rev 4351 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4075 | Rev 4192 | ||
---|---|---|---|
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 packet |
29 | /** @addtogroup packet |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** @file |
33 | /** @file |
34 | * Packet client. |
34 | * Packet client. |
35 | * The hosting module has to be compiled with both the packet.c and the packet_client.c source files. |
35 | * The hosting module has to be compiled with both the packet.c and the packet_client.c source files. |
36 | * To function correctly, initialization of the packet map by the pm_init() function has to happen at the first place. |
36 | * To function correctly, initialization of the packet map by the pm_init() function has to happen at the first place. |
37 | * The module should not send the packet messages to the packet server but use the functions provided. |
37 | * The module should not send the packet messages to the packet server but use the functions provided. |
38 | * The packet map should be released by the pm_destroy() function during the module termination. |
38 | * The packet map should be released by the pm_destroy() function during the module termination. |
39 | * The packets and the packet queues can't be locked at all. |
39 | * The packets and the packet queues can't be locked at all. |
40 | * The processing modules should process them sequentially - by passing the packets to the next module and stopping using the passed ones. |
40 | * The processing modules should process them sequentially - by passing the packets to the next module and stopping using the passed ones. |
41 | * @see packet.h |
41 | * @see packet.h |
42 | */ |
42 | */ |
43 | 43 | ||
44 | #ifndef __NET_PACKET_CLIENT_H__ |
44 | #ifndef __NET_PACKET_CLIENT_H__ |
45 | #define __NET_PACKET_CLIENT_H__ |
45 | #define __NET_PACKET_CLIENT_H__ |
46 | 46 | ||
47 | #include "packet.h" |
47 | #include "packet.h" |
48 | 48 | ||
49 | /** Allocates the specified type right before the actual packet content and returns its pointer. |
49 | /** Allocates the specified type right before the actual packet content and returns its pointer. |
50 | * The wrapper of the packet_prepend() function. |
50 | * The wrapper of the packet_prepend() function. |
51 | * @param packet The packet to be used. Input parameter. |
51 | * @param packet The packet to be used. Input parameter. |
52 | * @param type The type to be allocated at the beginning of the packet content. Input parameter. |
52 | * @param type The type to be allocated at the beginning of the packet content. Input parameter. |
53 | * @returns The typed pointer to the allocated memory. |
53 | * @returns The typed pointer to the allocated memory. |
54 | * @returns NULL if the packet is not valid. |
54 | * @returns NULL if the packet is not valid. |
55 | * @returns NULL if there is not enough memory left. |
55 | * @returns NULL if there is not enough memory left. |
56 | */ |
56 | */ |
57 | #define PACKET_PREFIX( packet, type ) ( type * ) packet_prefix(( packet ), sizeof( type )) |
57 | #define PACKET_PREFIX( packet, type ) ( type * ) packet_prefix(( packet ), sizeof( type )) |
58 | 58 | ||
59 | /** Allocates the specified type right after the actual packet content and returns its pointer. |
59 | /** Allocates the specified type right after the actual packet content and returns its pointer. |
60 | * The wrapper of the packet_append() function. |
60 | * The wrapper of the packet_append() function. |
61 | * @param packet The packet to be used. Input parameter. |
61 | * @param packet The packet to be used. Input parameter. |
62 | * @param type The type to be allocated at the end of the packet content. Input parameter. |
62 | * @param type The type to be allocated at the end of the packet content. Input parameter. |
63 | * @returns The typed pointer to the allocated memory. |
63 | * @returns The typed pointer to the allocated memory. |
64 | * @returns NULL if the packet is not valid. |
64 | * @returns NULL if the packet is not valid. |
65 | * @returns NULL if there is not enough memory left. |
65 | * @returns NULL if there is not enough memory left. |
66 | */ |
66 | */ |
67 | #define PACKET_SUFFIX( packet, type ) ( type * ) packet_suffix(( packet ), sizeof( type )) |
67 | #define PACKET_SUFFIX( packet, type ) ( type * ) packet_suffix(( packet ), sizeof( type )) |
68 | 68 | ||
69 | /** Trims the actual packet content by the specified prefix and suffix types. |
69 | /** Trims the actual packet content by the specified prefix and suffix types. |
70 | * The wrapper of the packet_trim() function. |
70 | * The wrapper of the packet_trim() function. |
71 | * @param packet The packet to be trimmed. Input parameter. |
71 | * @param packet The packet to be trimmed. Input parameter. |
72 | * @param prefix The type of the prefix to be removed from the beginning of the packet content. Input parameter. |
72 | * @param prefix The type of the prefix to be removed from the beginning of the packet content. Input parameter. |
73 | * @param suffix The type of the suffix to be removed from the end of the packet content. Input parameter. |
73 | * @param suffix The type of the suffix to be removed from the end of the packet content. Input parameter. |
74 | * @returns EOK on success. |
74 | * @returns EOK on success. |
75 | * @returns EINVAL if the packet is not valid. |
75 | * @returns EINVAL if the packet is not valid. |
76 | * @returns EINVAL if there is not enough memory left. |
76 | * @returns EINVAL if there is not enough memory left. |
77 | */ |
77 | */ |
78 | #define PACKET_TRIM( packet, prefix, suffix ) packet_trim(( packet ), sizeof( prefix ), sizeof( suffix )) |
78 | #define PACKET_TRIM( packet, prefix, suffix ) packet_trim(( packet ), sizeof( prefix ), sizeof( suffix )) |
79 | 79 | ||
80 | /** Allocates the specified space right before the actual packet content and returns its pointer. |
80 | /** Allocates the specified space right before the actual packet content and returns its pointer. |
81 | * @param packet The packet to be used. Input parameter. |
81 | * @param packet The packet to be used. Input parameter. |
82 | * @param length The space length to be allocated at the beginning of the packet content. Input parameter. |
82 | * @param length The space length to be allocated at the beginning of the packet content. Input parameter. |
83 | * @returns The pointer to the allocated memory. |
83 | * @returns The pointer to the allocated memory. |
84 | * @returns NULL if there is not enough memory left. |
84 | * @returns NULL if there is not enough memory left. |
85 | */ |
85 | */ |
86 | void * packet_prefix( packet_t packet, size_t length ); |
86 | void * packet_prefix( packet_t packet, size_t length ); |
87 | 87 | ||
88 | /** Allocates the specified space right after the actual packet content and returns its pointer. |
88 | /** Allocates the specified space right after the actual packet content and returns its pointer. |
89 | * @param packet The packet to be used. Input parameter. |
89 | * @param packet The packet to be used. Input parameter. |
90 | * @param length The space length to be allocated at the end of the packet content. Input parameter. |
90 | * @param length The space length to be allocated at the end of the packet content. Input parameter. |
91 | * @returns The pointer to the allocated memory. |
91 | * @returns The pointer to the allocated memory. |
92 | * @returns NULL if there is not enough memory left. |
92 | * @returns NULL if there is not enough memory left. |
93 | */ |
93 | */ |
94 | void * packet_suffix( packet_t packet, size_t length ); |
94 | void * packet_suffix( packet_t packet, size_t length ); |
95 | 95 | ||
96 | /** Trims the actual packet content by the specified prefix and suffix lengths. |
96 | /** Trims the actual packet content by the specified prefix and suffix lengths. |
97 | * @param packet The packet to be trimmed. Input parameter. |
97 | * @param packet The packet to be trimmed. Input parameter. |
98 | * @param prefix The prefix length to be removed from the beginning of the packet content. Input parameter. |
98 | * @param prefix The prefix length to be removed from the beginning of the packet content. Input parameter. |
99 | * @param suffix The suffix length to be removed from the end of the packet content. Input parameter. |
99 | * @param suffix The suffix length to be removed from the end of the packet content. Input parameter. |
100 | * @returns EOK on success. |
100 | * @returns EOK on success. |
101 | * @returns EINVAL if the packet is not valid. |
101 | * @returns EINVAL if the packet is not valid. |
102 | * @returns ENOMEM if there is not enough memory left. |
102 | * @returns ENOMEM if there is not enough memory left. |
103 | */ |
103 | */ |
104 | int packet_trim( packet_t packet, size_t prefix, size_t suffix ); |
104 | int packet_trim( packet_t packet, size_t prefix, size_t suffix ); |
105 | 105 | ||
106 | /** Copies the specified data to the beginning of the actual packet content. |
106 | /** Copies the specified data to the beginning of the actual packet content. |
107 | * Pushes the content end if needed. |
107 | * Pushes the content end if needed. |
108 | * @param packet The packet to be filled. Input parameter. |
108 | * @param packet The packet to be filled. Input parameter. |
109 | * @param data The data to be copied. Input parameter. |
109 | * @param data The data to be copied. Input parameter. |
110 | * @param length The length of the copied data. Input parameter. |
110 | * @param length The length of the copied data. Input parameter. |
111 | * @returns EOK on success. |
111 | * @returns EOK on success. |
112 | * @returns EINVAL if the packet is not valid. |
112 | * @returns EINVAL if the packet is not valid. |
113 | * @returns ENOMEM if there is not enough memory left. |
113 | * @returns ENOMEM if there is not enough memory left. |
114 | */ |
114 | */ |
115 | int packet_copy_data( packet_t packet, const void * data, size_t length ); |
115 | int packet_copy_data( packet_t packet, const void * data, size_t length ); |
116 | 116 | ||
117 | /** Returns the packet identifier. |
117 | /** Returns the packet identifier. |
118 | * @param packet The packet. Input parameter. |
118 | * @param packet The packet. Input parameter. |
119 | * @returns The packet identifier. |
119 | * @returns The packet identifier. |
120 | * @returns Zero (0) if the packet is not valid. |
120 | * @returns Zero (0) if the packet is not valid. |
121 | */ |
121 | */ |
122 | packet_id_t packet_get_id( const packet_t packet ); |
122 | packet_id_t packet_get_id( const packet_t packet ); |
123 | 123 | ||
124 | /** Returns the packet content length. |
124 | /** Returns the packet content length. |
125 | * @param packet The packet. Input parameter. |
125 | * @param packet The packet. Input parameter. |
126 | * @returns The packet content length in bytes. |
126 | * @returns The packet content length in bytes. |
127 | * @returns Zero (0) if the packet is not valid. |
127 | * @returns Zero (0) if the packet is not valid. |
128 | */ |
128 | */ |
129 | size_t packet_get_data_length( const packet_t packet ); |
129 | size_t packet_get_data_length( const packet_t packet ); |
130 | 130 | ||
131 | /** Returns the pointer to the beginning of the packet content. |
131 | /** Returns the pointer to the beginning of the packet content. |
132 | * @param packet The packet. Input parameter. |
132 | * @param packet The packet. Input parameter. |
133 | * @returns The pointer to the beginning of the packet content. |
133 | * @returns The pointer to the beginning of the packet content. |
134 | * @returns NULL if the packet is not valid. |
134 | * @returns NULL if the packet is not valid. |
135 | */ |
135 | */ |
136 | void * packet_get_data( const packet_t packet ); |
136 | void * packet_get_data( const packet_t packet ); |
137 | 137 | ||
138 | /** Returns the stored packet addresses and their length. |
138 | /** Returns the stored packet addresses and their length. |
139 | * @param packet The packet. Input parameter. |
139 | * @param packet The packet. Input parameter. |
140 | * @param src The source address. Output parameter. |
140 | * @param src The source address. Output parameter. |
141 | * @param dest The destination address. Output parameter. |
141 | * @param dest The destination address. Output parameter. |
142 | * @returns The addresses length. |
142 | * @returns The addresses length. |
143 | * @returns Zero (0) if the addresses are not present. |
143 | * @returns Zero (0) if the addresses are not present. |
144 | * @returns EINVAL if the packet is not valid. |
144 | * @returns EINVAL if the packet is not valid. |
145 | * @returns EINVAL if the src and/or the dest parameter is NULL. |
145 | * @returns EINVAL if the src and/or the dest parameter is NULL. |
146 | */ |
146 | */ |
147 | int packet_get_addr( const packet_t packet, uint8_t ** src, uint8_t ** dest ); |
147 | int packet_get_addr( const packet_t packet, uint8_t ** src, uint8_t ** dest ); |
148 | 148 | ||
149 | /** Sets the packet addresses. |
149 | /** Sets the packet addresses. |
150 | * @param packet The packet. Input parameter. |
150 | * @param packet The packet. Input parameter. |
151 | * @param src The new source address. Output parameter. |
151 | * @param src The new source address. Output parameter. |
152 | * @param dest The new destination address. Output parameter. |
152 | * @param dest The new destination address. Output parameter. |
153 | * @param addr_len The addresses length. |
153 | * @param addr_len The addresses length. |
154 | * @returns EOK on success. |
154 | * @returns EOK on success. |
155 | * @returns EINVAL if the packet is not valid. |
155 | * @returns EINVAL if the packet is not valid. |
156 | * @returns ENOMEM if there is not enough memory left. |
156 | * @returns ENOMEM if there is not enough memory left. |
157 | */ |
157 | */ |
158 | int packet_set_addr( packet_t packet, const uint8_t * src, const uint8_t * dest, size_t addr_len ); |
158 | int packet_set_addr( packet_t packet, const uint8_t * src, const uint8_t * dest, size_t addr_len ); |
159 | 159 | ||
160 | /** Translates the packet identifier to the packet reference. |
160 | /** Translates the packet identifier to the packet reference. |
161 | * Tries to find mapping first. |
161 | * Tries to find mapping first. |
162 | * Contacts the packet server to share the packet if the mapping is not present. |
162 | * Contacts the packet server to share the packet if the mapping is not present. |
163 | * @param phone The packet server module phone. Input parameter. |
163 | * @param phone The packet server module phone. Input parameter. |
164 | * @param packet The packet reference. Output parameter. |
164 | * @param packet The packet reference. Output parameter. |
165 | * @param packet_id The packet identifier. Input parameter. |
165 | * @param packet_id The packet identifier. Input parameter. |
166 | * @returns EOK on success. |
166 | * @returns EOK on success. |
167 | * @returns EINVAL if the packet parameter is NULL. |
167 | * @returns EINVAL if the packet parameter is NULL. |
168 | * @returns Other error codes as defined for the NET_PACKET_GET_SIZE message. |
168 | * @returns Other error codes as defined for the NET_PACKET_GET_SIZE message. |
169 | * \todo errors as packet_return() |
169 | * \todo errors as packet_return() |
170 | */ |
170 | */ |
171 | int packet_translate( int phone, packet_ref packet, packet_id_t packet_id ); |
171 | int packet_translate( int phone, packet_ref packet, packet_id_t packet_id ); |
172 | 172 | ||
173 | /** Obtains the packet of the given dimensions. |
173 | /** Obtains the packet of the given dimensions. |
174 | * Contacts the packet server to return the appropriate packet. |
174 | * Contacts the packet server to return the appropriate packet. |
175 | * @param phone The packet server module phone. Input parameter. |
175 | * @param phone The packet server module phone. Input parameter. |
176 | * @param addr_len The source and destination addresses maximal length in bytes. Input parameter. |
176 | * @param addr_len The source and destination addresses maximal length in bytes. Input parameter. |
177 | * @param max_prefix The maximal prefix length in bytes. Input parameter. |
177 | * @param max_prefix The maximal prefix length in bytes. Input parameter. |
178 | * @param max_content The maximal content length in bytes. Input parameter. |
178 | * @param max_content The maximal content length in bytes. Input parameter. |
179 | * @param max_suffix The maximal suffix length in bytes. Input parameter. |
179 | * @param max_suffix The maximal suffix length in bytes. Input parameter. |
180 | * @returns The packet reference. |
180 | * @returns The packet reference. |
181 | * @returns NULL on error. |
181 | * @returns NULL on error. |
182 | * \todo error as NET_PACKET_CREATE_4, packet_return() |
182 | * \todo error as NET_PACKET_CREATE_4, packet_return() |
183 | */ |
183 | */ |
184 | packet_t packet_get_4( int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix ); |
184 | packet_t packet_get_4( int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix ); |
185 | 185 | ||
186 | /** Obtains the packet of the given content size. |
186 | /** Obtains the packet of the given content size. |
187 | * Contacts the packet server to return the appropriate packet. |
187 | * Contacts the packet server to return the appropriate packet. |
188 | * @param phone The packet server module phone. Input parameter. |
188 | * @param phone The packet server module phone. Input parameter. |
189 | * @param content The maximal content length in bytes. Input parameter. |
189 | * @param content The maximal content length in bytes. Input parameter. |
190 | * @returns The packet reference. |
190 | * @returns The packet reference. |
191 | * @returns NULL on error. |
191 | * @returns NULL on error. |
192 | * \todo error as NET_PACKET_CREATE_1, packet_return() |
192 | * \todo error as NET_PACKET_CREATE_1, packet_return() |
193 | */ |
193 | */ |
194 | packet_t packet_get_1( int phone, size_t content ); |
194 | packet_t packet_get_1( int phone, size_t content ); |
195 | 195 | ||
196 | /** Releases the packet queue. |
196 | /** Releases the packet queue. |
197 | * All packets in the queue are marked as free for use. |
197 | * All packets in the queue are marked as free for use. |
198 | * The packet queue may be one packet only. |
198 | * The packet queue may be one packet only. |
199 | * The module should not use the packets after this point until they are received or obtained again. |
199 | * The module should not use the packets after this point until they are received or obtained again. |
200 | * @param phone The packet server module phone. Input parameter. |
200 | * @param phone The packet server module phone. Input parameter. |
201 | * @param packet_id The packet identifier. Input parameter. |
201 | * @param packet_id The packet identifier. Input parameter. |
202 | */ |
202 | */ |
203 | void packet_release( int phone, packet_id_t packet_id ); |
203 | void pq_release( int phone, packet_id_t packet_id ); |
204 | 204 | ||
205 | #endif |
205 | #endif |
206 | 206 | ||
207 | /** @} |
207 | /** @} |
208 | */ |
208 | */ |
209 | 209 |