[21580dd] | 1 | /*
|
---|
| 2 | * Copyright (c) 2008 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 net_tl
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | /** @file
|
---|
| 34 | * Transport layer common functions.
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #ifndef __NET_TL_COMMON_H__
|
---|
| 38 | #define __NET_TL_COMMON_H__
|
---|
| 39 |
|
---|
[058edb6] | 40 | #include <net/socket_codes.h>
|
---|
| 41 |
|
---|
[849ed54] | 42 | #include <packet/packet.h>
|
---|
| 43 | #include <net_device.h>
|
---|
[e4554d4] | 44 | #include <net/inet.h>
|
---|
[21580dd] | 45 |
|
---|
| 46 | /** Device packet dimensions.
|
---|
| 47 | * Maps devices to the packet dimensions.
|
---|
| 48 | * @see device.h
|
---|
| 49 | */
|
---|
[aadf01e] | 50 | DEVICE_MAP_DECLARE(packet_dimensions, packet_dimension_t);
|
---|
[21580dd] | 51 |
|
---|
[14f1db0] | 52 | extern int tl_get_ip_packet_dimension(int, packet_dimensions_ref,
|
---|
| 53 | device_id_t, packet_dimension_ref *);
|
---|
| 54 |
|
---|
[21580dd] | 55 | /** Gets the address port.
|
---|
| 56 | * Supports AF_INET and AF_INET6 address families.
|
---|
| 57 | * @param[in,out] addr The address to be updated.
|
---|
| 58 | * @param[in] addrlen The address length.
|
---|
| 59 | * @param[out] port The set port.
|
---|
| 60 | * @returns EOK on success.
|
---|
| 61 | * @returns EINVAL if the address length does not match the address family.
|
---|
| 62 | * @returns EAFNOSUPPORT if the address family is not supported.
|
---|
| 63 | */
|
---|
[849ed54] | 64 | extern int tl_get_address_port(const struct sockaddr * addr, int addrlen, uint16_t * port);
|
---|
[21580dd] | 65 |
|
---|
[b4ff8a6d] | 66 | /** Updates IP device packet dimensions cache.
|
---|
| 67 | * @param[in,out] packet_dimensions The packet dimensions cache.
|
---|
| 68 | * @param[in] device_id The device identifier.
|
---|
| 69 | * @param[in] content The new maximum content size.
|
---|
| 70 | * @returns EOK on success.
|
---|
| 71 | * @returns ENOENT if the packet dimension is not cached.
|
---|
| 72 | */
|
---|
[849ed54] | 73 | extern int tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions, device_id_t device_id, size_t content);
|
---|
[b4ff8a6d] | 74 |
|
---|
[21580dd] | 75 | /** Sets the address port.
|
---|
| 76 | * Supports AF_INET and AF_INET6 address families.
|
---|
| 77 | * @param[in,out] addr The address to be updated.
|
---|
| 78 | * @param[in] addrlen The address length.
|
---|
| 79 | * @param[in] port The port to be set.
|
---|
| 80 | * @returns EOK on success.
|
---|
| 81 | * @returns EINVAL if the address length does not match the address family.
|
---|
| 82 | * @returns EAFNOSUPPORT if the address family is not supported.
|
---|
| 83 | */
|
---|
[849ed54] | 84 | extern int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port);
|
---|
[21580dd] | 85 |
|
---|
| 86 | /** Prepares the packet for ICMP error notification.
|
---|
| 87 | * Keeps the first packet and releases all the others.
|
---|
| 88 | * Releases all the packets on error.
|
---|
| 89 | * @param[in] packet_phone The packet server module phone.
|
---|
| 90 | * @param[in] icmp_phone The ICMP module phone.
|
---|
| 91 | * @param[in] packet The packet to be send.
|
---|
| 92 | * @param[in] error The packet error reporting service. Prefixes the received packet.
|
---|
| 93 | * @returns EOK on success.
|
---|
| 94 | * @returns ENOENT if no packet may be sent.
|
---|
| 95 | */
|
---|
[849ed54] | 96 | extern int tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet, services_t error);
|
---|
[21580dd] | 97 |
|
---|
| 98 | /** Receives data from the socket into a packet.
|
---|
| 99 | * @param[in] packet_phone The packet server module phone.
|
---|
| 100 | * @param[out] packet The new created packet.
|
---|
| 101 | * @param[in] prefix Reserved packet data prefix length.
|
---|
| 102 | * @param[in] dimension The packet dimension.
|
---|
| 103 | * @param[in] addr The destination address.
|
---|
| 104 | * @param[in] addrlen The address length.
|
---|
| 105 | * @returns Number of bytes received.
|
---|
| 106 | * @returns EINVAL if the client does not send data.
|
---|
| 107 | * @returns ENOMEM if there is not enough memory left.
|
---|
| 108 | * @returns Other error codes as defined for the async_data_read_finalize() function.
|
---|
| 109 | */
|
---|
[849ed54] | 110 | extern int tl_socket_read_packet_data(int packet_phone, packet_ref packet, size_t prefix, const packet_dimension_ref dimension, const struct sockaddr * addr, socklen_t addrlen);
|
---|
[21580dd] | 111 |
|
---|
| 112 | #endif
|
---|
| 113 |
|
---|
| 114 | /** @}
|
---|
| 115 | */
|
---|
| 116 |
|
---|