source: mainline/uspace/lib/net/include/packet_client.h@ 86ffa27f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 86ffa27f was 6b82009, checked in by Martin Decky <martin@…>, 14 years ago

networking stack: convert to the new async framework

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2 * Copyright (c) 2009 Lukas 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 libnet
30 * @{
31 */
32
33/** @file
34 * Packet client.
35 *
36 * To function correctly, initialization of the packet map by the pm_init()
37 * function has to happen at the first place. The module should not send the
38 * packet messages to the packet server but use the functions provided. The
39 * packet map should be released by the pm_destroy() function during the module
40 * termination. The packets and the packet queues can't be locked at all. The
41 * processing modules should process them sequentially - by passing the packets
42 * to the next module and stopping using the passed ones.
43 *
44 * @see packet.h
45 */
46
47#ifndef LIBNET_PACKET_CLIENT_H_
48#define LIBNET_PACKET_CLIENT_H_
49
50#include <net/packet.h>
51#include <async.h>
52
53/** @name Packet client interface */
54/*@{*/
55
56/** Allocates the specified type right before the actual packet content and
57 * returns its pointer.
58 *
59 * The wrapper of the packet_prepend() function.
60 *
61 * @param[in] packet The packet to be used.
62 * @param[in] type The type to be allocated at the beginning of the packet
63 * content.
64 * @return The typed pointer to the allocated memory.
65 * @return NULL if the packet is not valid.
66 * @return NULL if there is not enough memory left.
67 */
68#define PACKET_PREFIX(packet, type) \
69 (type *) packet_prefix((packet), sizeof(type))
70
71/** Allocates the specified type right after the actual packet content and
72 * returns its pointer.
73 *
74 * The wrapper of the packet_append() function.
75 *
76 * @param[in] packet The packet to be used.
77 * @param[in] type The type to be allocated at the end of the packet
78 * content.
79 * @return The typed pointer to the allocated memory.
80 * @return NULL if the packet is not valid.
81 * @return NULL if there is not enough memory left.
82 */
83#define PACKET_SUFFIX(packet, type) \
84 (type *) packet_suffix((packet), sizeof(type))
85
86/** Trims the actual packet content by the specified prefix and suffix types.
87 *
88 * The wrapper of the packet_trim() function.
89 *
90 * @param[in] packet The packet to be trimmed.
91 * @param[in] prefix The type of the prefix to be removed from the beginning
92 * of the packet content.
93 * @param[in] suffix The type of the suffix to be removed from the end of
94 * the packet content.
95 * @return EOK on success.
96 * @return EINVAL if the packet is not valid.
97 * @return ENOMEM if there is not enough memory left.
98 */
99#define PACKET_TRIM(packet, prefix, suffix) \
100 packet_trim((packet), sizeof(prefix), sizeof(suffix))
101
102extern void *packet_prefix(packet_t *, size_t);
103extern void *packet_suffix(packet_t *, size_t);
104extern int packet_trim(packet_t *, size_t, size_t);
105extern int packet_copy_data(packet_t *, const void *, size_t);
106extern packet_id_t packet_get_id(const packet_t *);
107extern size_t packet_get_data_length(const packet_t *);
108extern void *packet_get_data(const packet_t *);
109extern int packet_get_addr(const packet_t *, uint8_t **, uint8_t **);
110extern int packet_set_addr(packet_t *, const uint8_t *, const uint8_t *, size_t);
111extern packet_t *packet_get_copy(async_sess_t *, packet_t *);
112
113/*@}*/
114
115#endif
116
117/** @}
118 */
Note: See TracBrowser for help on using the repository browser.