[21580dd] | 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 |
|
---|
[b69ceea] | 29 | /** @addtogroup libnet
|
---|
[21580dd] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | /** @file
|
---|
[b69ceea] | 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
|
---|
[21580dd] | 45 | */
|
---|
| 46 |
|
---|
[b69ceea] | 47 | #ifndef LIBNET_PACKET_CLIENT_H_
|
---|
| 48 | #define LIBNET_PACKET_CLIENT_H_
|
---|
[21580dd] | 49 |
|
---|
[c69d327] | 50 | #include <net/packet.h>
|
---|
[6b82009] | 51 | #include <async.h>
|
---|
[21580dd] | 52 |
|
---|
[b69ceea] | 53 | /** @name Packet client interface */
|
---|
[21580dd] | 54 | /*@{*/
|
---|
| 55 |
|
---|
[b69ceea] | 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.
|
---|
[1bfd3d3] | 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.
|
---|
[b69ceea] | 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.
|
---|
[1bfd3d3] | 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.
|
---|
[21580dd] | 82 | */
|
---|
[b69ceea] | 83 | #define PACKET_SUFFIX(packet, type) \
|
---|
| 84 | (type *) packet_suffix((packet), sizeof(type))
|
---|
[21580dd] | 85 |
|
---|
| 86 | /** Trims the actual packet content by the specified prefix and suffix types.
|
---|
[b69ceea] | 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.
|
---|
[1bfd3d3] | 95 | * @return EOK on success.
|
---|
| 96 | * @return EINVAL if the packet is not valid.
|
---|
| 97 | * @return ENOMEM if there is not enough memory left.
|
---|
[b69ceea] | 98 | */
|
---|
| 99 | #define PACKET_TRIM(packet, prefix, suffix) \
|
---|
| 100 | packet_trim((packet), sizeof(prefix), sizeof(suffix))
|
---|
| 101 |
|
---|
[46d4d9f] | 102 | extern void *packet_prefix(packet_t *, size_t);
|
---|
| 103 | extern void *packet_suffix(packet_t *, size_t);
|
---|
| 104 | extern int packet_trim(packet_t *, size_t, size_t);
|
---|
| 105 | extern int packet_copy_data(packet_t *, const void *, size_t);
|
---|
| 106 | extern packet_id_t packet_get_id(const packet_t *);
|
---|
| 107 | extern size_t packet_get_data_length(const packet_t *);
|
---|
| 108 | extern void *packet_get_data(const packet_t *);
|
---|
| 109 | extern int packet_get_addr(const packet_t *, uint8_t **, uint8_t **);
|
---|
| 110 | extern int packet_set_addr(packet_t *, const uint8_t *, const uint8_t *, size_t);
|
---|
[6b82009] | 111 | extern packet_t *packet_get_copy(async_sess_t *, packet_t *);
|
---|
[21580dd] | 112 |
|
---|
| 113 | /*@}*/
|
---|
| 114 |
|
---|
| 115 | #endif
|
---|
| 116 |
|
---|
| 117 | /** @}
|
---|
| 118 | */
|
---|