Subversion Repositories HelenOS

Rev

Rev 3901 | Rev 3914 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3901 Rev 3912
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (c) 2008 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:
Line 24... Line 24...
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 net
29
/** @addtogroup packet
30
 *  @{
30
 *  @{
31
 */
31
 */
32
 
32
 
33
/** @file
33
/** @file
-
 
34
 *  Packet client.
-
 
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.
-
 
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.
-
 
39
 *  @see packet.h
34
 */
40
 */
35
 
41
 
36
#ifndef __NET_PACKET_CLIENT_H__
42
#ifndef __NET_PACKET_CLIENT_H__
37
#define __NET_PACKET_CLIENT_H__
43
#define __NET_PACKET_CLIENT_H__
38
 
44
 
39
#include "packet.h"
45
#include "packet.h"
40
 
46
 
-
 
47
/** Allocates the specified type right before the actual packet content and returns its pointer.
-
 
48
 *  The wrapper of the packet_prepend() function.
-
 
49
 *  @param packet The packet to be used. Input parameter.
-
 
50
 *  @param type The type to be allocated at the beginning of the packet content. Input parameter.
-
 
51
 *  @returns The typed pointer to the allocated memory.
-
 
52
 *  @returns NULL if the packet is not valid.
-
 
53
 *  @returns NULL if there is not enough memory left.
-
 
54
 */
41
#define PACKET_PREPEND( packet, type )  ( type * ) packet_prepend(( packet ), sizeof( type ))
55
#define PACKET_PREFIX( packet, type )   ( type * ) packet_prepend(( packet ), sizeof( type ))
-
 
56
 
-
 
57
/** Allocates the specified type right after the actual packet content and returns its pointer.
-
 
58
 *  The wrapper of the packet_append() function.
-
 
59
 *  @param packet The packet to be used. Input parameter.
-
 
60
 *  @param type The type to be allocated at the end of the packet content. Input parameter.
-
 
61
 *  @returns The typed pointer to the allocated memory.
-
 
62
 *  @returns NULL if the packet is not valid.
-
 
63
 *  @returns NULL if there is not enough memory left.
-
 
64
 */
42
#define PACKET_APPEND( packet, type )   ( type * ) packet_append(( packet ), sizeof( type ))
65
#define PACKET_SUFFIX( packet, type )   ( type * ) packet_append(( packet ), sizeof( type ))
-
 
66
 
-
 
67
/** Trims the actual packet content by the specified prefix and suffix types.
-
 
68
 *  The wrapper of the packet_trim() function.
-
 
69
 *  @param packet The packet to be trimmed. Input parameter.
-
 
70
 *  @param prefix The type of the prefix to be removed from the beginning of the packet content. Input parameter.
-
 
71
 *  @param suffix The type of the suffix to be removed from the end of the packet content. Input parameter.
-
 
72
 *  @returns EOK on success.
-
 
73
 *  @returns EINVAL if the packet is not valid.
-
 
74
 *  @returns EINVAL if there is not enough memory left.
-
 
75
 */
43
#define PACKET_TRIM( packet, prefix, sufix )    packet_trim(( packet ), sizeof( prefix ), sizeof( sufix ))
76
#define PACKET_TRIM( packet, prefix, suffix )   packet_trim(( packet ), sizeof( prefix ), sizeof( suffix ))
44
 
77
 
-
 
78
/** Allocates the specified space right before the actual packet content and returns its pointer.
-
 
79
 *  @param packet The packet to be used. Input parameter.
-
 
80
 *  @param length The space length to be allocated at the beginning of the packet content. Input parameter.
-
 
81
 *  @returns The pointer to the allocated memory.
-
 
82
 *  @returns NULL if there is not enough memory left.
-
 
83
 */
45
void *  packet_prepend( packet_t packet, size_t length );
84
void *  packet_prefix( packet_t packet, size_t length );
-
 
85
 
-
 
86
/** Allocates the specified space right after the actual packet content and returns its pointer.
-
 
87
 *  @param packet The packet to be used. Input parameter.
-
 
88
 *  @param length The space length to be allocated at the end of the packet content. Input parameter.
-
 
89
 *  @returns The pointer to the allocated memory.
-
 
90
 *  @returns NULL if there is not enough memory left.
-
 
91
 */
46
void *  packet_append( packet_t packet, size_t length );
92
void *  packet_suffix( packet_t packet, size_t length );
-
 
93
 
-
 
94
/** Trims the actual packet content by the specified prefix and suffix lengths.
-
 
95
 *  @param packet The packet to be trimmed. Input parameter.
-
 
96
 *  @param prefix The prefix length to be removed from the beginning of the packet content. Input parameter.
-
 
97
 *  @param suffix The suffix length to be removed from the end of the packet content. Input parameter.
-
 
98
 *  @returns EOK on success.
-
 
99
 *  @returns EINVAL if the packet is not valid.
-
 
100
 *  @returns ENOMEM if there is not enough memory left.
-
 
101
 */
-
 
102
int packet_trim( packet_t packet, size_t prefix, size_t suffix );
-
 
103
 
-
 
104
/** Copies the packet content.
-
 
105
 *  Obtains the new packet from the packet server.
-
 
106
 *  @param phone The packet server module phone. Input parameter.
-
 
107
 *  @param owner The owner of the new packet. Input parameter.
-
 
108
 *  @param packet The packet reference. Input parameter.
-
 
109
 *  @returns The packet copy.
-
 
110
 *  @returns NULL if the source packet ids not valid.
-
 
111
 *  @returns NULL on error.
-
 
112
 *  \todo other error?
-
 
113
 */
47
packet_t    packet_copy( int phone, services_t owner, const packet_t packet );
114
packet_t    packet_copy( int phone, services_t owner, const packet_t packet );
-
 
115
 
-
 
116
/** Copies the specified data to the beginning of the actual packet content.
-
 
117
 *  Pushes the content end if needed.
-
 
118
 *  @param packet The packet to be filled. Input parameter.
-
 
119
 *  @param data The data to be copied. Input parameter.
-
 
120
 *  @param length The length of the copied data. Input parameter.
-
 
121
 *  @returns EOK on success.
-
 
122
 *  @returns EINVAL if the packet is not valid.
-
 
123
 *  @returns ENOMEM if there is not enough memory left.
-
 
124
 */
48
int packet_copy_data( packet_t packet, const void * data, size_t length );
125
int packet_copy_data( packet_t packet, const void * data, size_t length );
-
 
126
 
-
 
127
/** Returns the packet identifier.
49
int packet_trim( packet_t packet, size_t prefix, size_t sufix );
128
 *  @param packet The packet. Input parameter.
50
int packet_destroy( packet_t packet );
129
 *  @returns The packet identifier.
-
 
130
 *  @returns Zero (0) if the packet is not valid.
-
 
131
 */
51
packet_id_t packet_get_id( packet_t packet );
132
packet_id_t packet_get_id( const packet_t packet );
-
 
133
 
-
 
134
/** Returns the packet content length.
-
 
135
 *  @param packet The packet. Input parameter.
-
 
136
 *  @returns The packet content length in bytes.
-
 
137
 *  @returns Zero (0) if the packet is not valid.
-
 
138
 */
52
size_t  packet_get_data_length( const packet_t packet );
139
size_t  packet_get_data_length( const packet_t packet );
-
 
140
 
-
 
141
/** Returns the pointer to the beginning of the packet content.
-
 
142
 *  @param packet The packet. Input parameter.
-
 
143
 *  @returns The pointer to the beginning of the packet content.
-
 
144
 *  @returns NULL if the packet is not valid.
-
 
145
 */
53
void *  packet_get_data( const packet_t packet );
146
void *  packet_get_data( const packet_t packet );
-
 
147
 
-
 
148
/** Returns the stored packet addresses and their length.
-
 
149
 *  @param packet The packet. Input parameter.
-
 
150
 *  @param src The source address. Output parameter.
-
 
151
 *  @param dest The destination address. Output parameter.
-
 
152
 *  @returns The addresses length.
-
 
153
 *  @returns Zero (0) if the addresses are not present.
-
 
154
 *  @returns EINVAL if the packet is not valid.
-
 
155
 *  @returns EINVAL if the src and/or the dest parameter is NULL.
-
 
156
 */
54
int packet_get_addr( const packet_t packet, uint8_t ** src, uint8_t ** dest );
157
int packet_get_addr( const packet_t packet, uint8_t ** src, uint8_t ** dest );
-
 
158
 
-
 
159
/** Returns the packet operation mode.
-
 
160
 *  @param packet The packet. Input parameter.
-
 
161
 *  @returns The packet operation mode.
-
 
162
 *  @see packet_mode
-
 
163
 */
55
packet_mode_t   packet_get_mode( const packet_t packet );
164
packet_mode_t   packet_get_mode( const packet_t packet );
-
 
165
 
-
 
166
/** Sets the packet addresses.
-
 
167
 *  @param packet The packet. Input parameter.
-
 
168
 *  @param src The new source address. Output parameter.
-
 
169
 *  @param dest The new destination address. Output parameter.
-
 
170
 *  @param addr_len The addresses length.
-
 
171
 *  @returns EOK on success.
-
 
172
 *  @returns EINVAL if the packet is not valid.
-
 
173
 *  @returns ENOMEM if there is not enough memory left.
-
 
174
 */
56
int packet_set_addr( packet_t packet, const uint8_t * src, const uint8_t * dest, size_t addr_len );
175
int packet_set_addr( packet_t packet, const uint8_t * src, const uint8_t * dest, size_t addr_len );
-
 
176
 
-
 
177
/** Sets the packet operation mode.
-
 
178
 *  @param packet The packet. Input parameter.
-
 
179
 *  @param mode The new packet operation mode. Input parameter.
-
 
180
 *  @returns EOK on success.
-
 
181
 *  @returns EINVAL if the packet is not valid.
-
 
182
 *  @see packet_mode
-
 
183
 */
57
int packet_set_mode( packet_t packet, packet_mode_t mode );
184
int packet_set_mode( packet_t packet, packet_mode_t mode );
-
 
185
 
-
 
186
/** Sets the packet owner.
-
 
187
 *  @param packet The packet. Input parameter.
-
 
188
 *  @param owner The new packet owner. Input parameter.
-
 
189
 *  @returns EOK on success.
-
 
190
 *  @returns EINVAL if the packet is not valid.
-
 
191
 */
58
int packet_set_owner( packet_t packet, services_t owner );
192
int packet_set_owner( packet_t packet, services_t owner );
59
 
193
 
-
 
194
/** Translates the packet identifier to the packet reference.
-
 
195
 *  Tries to find mapping first.
-
 
196
 *  Contacts the packet server to share the packet if the mapping is not present.
-
 
197
 *  @param phone The packet server module phone. Input parameter.
-
 
198
 *  @param packet The packet reference. Output parameter.
-
 
199
 *  @param packet_id The packet identifier. Input parameter.
-
 
200
 *  @returns EOK on success.
-
 
201
 *  @returns EINVAL if the packet parameter is NULL.
-
 
202
 *  @returns Other error codes as defined for the NET_PACKET_GET_SIZE message.
-
 
203
 *  \todo errors as packet_return()
-
 
204
 */
60
int packet_translate( int phone, packet_ref packet, packet_id_t packet_id );
205
int packet_translate( int phone, packet_ref packet, packet_id_t packet_id );
-
 
206
 
-
 
207
/** Obtains the packet of the given dimensions.
-
 
208
 *  Contacts the packet server to return the appropriate packet.
-
 
209
 *  @param phone The packet server module phone. Input parameter.
-
 
210
 *  @param owner The owner of the new packet. Input parameter.
-
 
211
 *  @param addr_len The source and destination addresses maximal length in bytes. Input parameter.
-
 
212
 *  @param max_prefix The maximal prefix length in bytes. Input parameter.
-
 
213
 *  @param max_content The maximal content length in bytes. Input parameter.
-
 
214
 *  @param max_suffix The maximal suffix length in bytes. Input parameter.
-
 
215
 *  @returns The packet reference.
-
 
216
 *  @returns NULL on error.
-
 
217
 *  \todo error as NET_PACKET_CREATE_5, packet_return()
-
 
218
 */
61
packet_t packet_get_5( int phone, services_t owner, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_sufix );
219
packet_t packet_get_5( int phone, services_t owner, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix );
-
 
220
 
-
 
221
/** Obtains the packet of the given content size.
-
 
222
 *  Contacts the packet server to return the appropriate packet.
-
 
223
 *  @param phone The packet server module phone. Input parameter.
-
 
224
 *  @param owner The owner of the new packet. Input parameter.
-
 
225
 *  @param content The maximal content length in bytes. Input parameter.
-
 
226
 *  @returns The packet reference.
-
 
227
 *  @returns NULL on error.
-
 
228
 *  \todo error as NET_PACKET_CREATE_1, packet_return()
-
 
229
 */
62
packet_t packet_get_1( int phone, services_t owner, size_t content );
230
packet_t packet_get_1( int phone, services_t owner, size_t content );
-
 
231
 
-
 
232
/** Releases the packet.
-
 
233
 *  The packet is marked as free for use.
-
 
234
 *  The module should not use the packet after this point until it is received or obtained again.
-
 
235
 *  @param phone The packet server module phone. Input parameter.
-
 
236
 *  @param packet_id The packet identifier. Input parameter.
-
 
237
 */
63
void packet_release( int phone, packet_id_t packet_id );
238
void packet_release( int phone, packet_id_t packet_id );
64
 
239
 
65
#endif
240
#endif
66
 
241
 
67
/** @}
242
/** @}