[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>
|
---|
[21580dd] | 51 |
|
---|
[b69ceea] | 52 | /** @name Packet client interface */
|
---|
[21580dd] | 53 | /*@{*/
|
---|
| 54 |
|
---|
[b69ceea] | 55 | /** Allocates the specified type right before the actual packet content and
|
---|
| 56 | * returns its pointer.
|
---|
| 57 | *
|
---|
| 58 | * The wrapper of the packet_prepend() function.
|
---|
| 59 | *
|
---|
| 60 | * @param[in] packet The packet to be used.
|
---|
| 61 | * @param[in] type The type to be allocated at the beginning of the packet
|
---|
| 62 | * content.
|
---|
[1bfd3d3] | 63 | * @return The typed pointer to the allocated memory.
|
---|
| 64 | * @return NULL if the packet is not valid.
|
---|
| 65 | * @return NULL if there is not enough memory left.
|
---|
[b69ceea] | 66 | */
|
---|
| 67 | #define PACKET_PREFIX(packet, type) \
|
---|
| 68 | (type *) packet_prefix((packet), sizeof(type))
|
---|
| 69 |
|
---|
| 70 | /** Allocates the specified type right after the actual packet content and
|
---|
| 71 | * returns its pointer.
|
---|
| 72 | *
|
---|
| 73 | * The wrapper of the packet_append() function.
|
---|
| 74 | *
|
---|
| 75 | * @param[in] packet The packet to be used.
|
---|
| 76 | * @param[in] type The type to be allocated at the end of the packet
|
---|
| 77 | * content.
|
---|
[1bfd3d3] | 78 | * @return The typed pointer to the allocated memory.
|
---|
| 79 | * @return NULL if the packet is not valid.
|
---|
| 80 | * @return NULL if there is not enough memory left.
|
---|
[21580dd] | 81 | */
|
---|
[b69ceea] | 82 | #define PACKET_SUFFIX(packet, type) \
|
---|
| 83 | (type *) packet_suffix((packet), sizeof(type))
|
---|
[21580dd] | 84 |
|
---|
| 85 | /** Trims the actual packet content by the specified prefix and suffix types.
|
---|
[b69ceea] | 86 | *
|
---|
| 87 | * The wrapper of the packet_trim() function.
|
---|
| 88 | *
|
---|
| 89 | * @param[in] packet The packet to be trimmed.
|
---|
| 90 | * @param[in] prefix The type of the prefix to be removed from the beginning
|
---|
| 91 | * of the packet content.
|
---|
| 92 | * @param[in] suffix The type of the suffix to be removed from the end of
|
---|
| 93 | * the packet content.
|
---|
[1bfd3d3] | 94 | * @return EOK on success.
|
---|
| 95 | * @return EINVAL if the packet is not valid.
|
---|
| 96 | * @return ENOMEM if there is not enough memory left.
|
---|
[b69ceea] | 97 | */
|
---|
| 98 | #define PACKET_TRIM(packet, prefix, suffix) \
|
---|
| 99 | packet_trim((packet), sizeof(prefix), sizeof(suffix))
|
---|
| 100 |
|
---|
[46d4d9f] | 101 | extern void *packet_prefix(packet_t *, size_t);
|
---|
| 102 | extern void *packet_suffix(packet_t *, size_t);
|
---|
| 103 | extern int packet_trim(packet_t *, size_t, size_t);
|
---|
| 104 | extern int packet_copy_data(packet_t *, const void *, size_t);
|
---|
| 105 | extern packet_id_t packet_get_id(const packet_t *);
|
---|
| 106 | extern size_t packet_get_data_length(const packet_t *);
|
---|
| 107 | extern void *packet_get_data(const packet_t *);
|
---|
| 108 | extern int packet_get_addr(const packet_t *, uint8_t **, uint8_t **);
|
---|
| 109 | extern int packet_set_addr(packet_t *, const uint8_t *, const uint8_t *, size_t);
|
---|
| 110 | extern packet_t *packet_get_copy(int, packet_t *);
|
---|
[21580dd] | 111 |
|
---|
| 112 | /*@}*/
|
---|
| 113 |
|
---|
| 114 | #endif
|
---|
| 115 |
|
---|
| 116 | /** @}
|
---|
| 117 | */
|
---|