Subversion Repositories HelenOS

Rev

Rev 4731 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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.  
  40. #include "../structures/packet/packet.h"
  41.  
  42. #include "../include/device.h"
  43. #include "../include/inet.h"
  44. #include "../include/socket_codes.h"
  45.  
  46. /** Type definition of the packet dimension.
  47.  *  @see packet_dimension
  48.  */
  49. typedef struct packet_dimension packet_dimension_t;
  50.  
  51. /** Type definition of the packet dimension pointer.
  52.  *  @see packet_dimension
  53.  */
  54. typedef packet_dimension_t *    packet_dimension_ref;
  55.  
  56. /** Packet dimension.
  57.  */
  58. struct packet_dimension{
  59.     /** Reserved packet prefix length.
  60.      */
  61.     size_t          prefix;
  62.     /** Maximal packet content length.
  63.      */
  64.     size_t          content;
  65.     /** Reserved packet suffix length.
  66.      */
  67.     size_t          suffix;
  68.     /** Maximal packet address length.
  69.      */
  70.     size_t          addr_len;
  71. };
  72.  
  73. /** Device packet dimensions.
  74.  *  Maps devices to the packet dimensions.
  75.  *  @see device.h
  76.  */
  77. DEVICE_MAP_DECLARE( packet_dimensions, packet_dimension_t );
  78.  
  79. /** Gets the address port.
  80.  *  Supports AF_INET and AF_INET6 address families.
  81.  *  @param addr The address to be updated. Input/output parameter.
  82.  *  @param addrlen The address length. Input parameter.
  83.  *  @param port The set port. Output parameter.
  84.  *  @returns EOK on success.
  85.  *  @returns EINVAL if the address length does not match the address family.
  86.  *  @returns EAFNOSUPPORT if the address family is not supported.
  87.  */
  88. int tl_get_address_port( const struct sockaddr * addr, int addrlen, uint16_t * port );
  89.  
  90. /** Gets IP packet dimensions.
  91.  *  Tries to search a cache and queries the IP module if not found.
  92.  *  The reply is cached then.
  93.  *  @param[in] ip_phone The IP moduel phone for (semi)remote calls.
  94.  *  @param[in] packet_dimensions The packet dimensions cache.
  95.  *  @param[in] device_id The device identifier.
  96.  *  @param[out] packet_dimention The IP packet dimensions.
  97.  *  @returns EOK on success.
  98.  *  @returns EBADMEM if the packet_dimension parameter is NULL.
  99.  *  @return ENOMEM if there is not enough memory left.
  100.  *  @returns EINVAL if the packet_dimensions cache is not valid.
  101.  *  @returns Other codes as defined for the ip_packet_size_req() function.
  102.  */
  103. int tl_get_ip_packet_dimension( int ip_phone, packet_dimensions_ref packet_dimensions, device_id_t device_id, packet_dimension_ref * packet_dimension );
  104.  
  105. /** Sets the address port.
  106.  *  Supports AF_INET and AF_INET6 address families.
  107.  *  @param addr The address to be updated. Input/output parameter.
  108.  *  @param addrlen The address length. Input parameter.
  109.  *  @param port The port to be set. Input parameter.
  110.  *  @returns EOK on success.
  111.  *  @returns EINVAL if the address length does not match the address family.
  112.  *  @returns EAFNOSUPPORT if the address family is not supported.
  113.  */
  114. int tl_set_address_port( struct sockaddr * addr, int addrlen, uint16_t port );
  115.  
  116. /** Prepares the packet for ICMP error notification.
  117.  *  Keeps the first packet and releases all the others.
  118.  *  Releases all the packets on error.
  119.  *  @param packet_phone The packet server module phone. Input parameter.
  120.  *  @param icmp_phone The ICMP module phone. Input parameter.
  121.  *  @param packet The packet to be send. Input parameter.
  122.  *  @param error The packet error reporting service. Prefixes the received packet. Input parameter.
  123.  *  @returns EOK on success.
  124.  *  @returns ENOENT if no packet may be sent.
  125.  */
  126. int tl_prepare_icmp_packet( int packet_phone, int icmp_phone, packet_t packet, services_t error );
  127.  
  128. /** Receives data from the socket into a packet.
  129.  *  @param packet_phone The packet server module phone. Input parameter.
  130.  *  @param packet The new created packet. Output parameter.
  131.  *  @param prefix Reserved packet data prefix length. Input parameter.
  132.  *  @param dimension The packet dimension. Input parameter.
  133.  *  @param addr The destination address. Input parameter.
  134.  *  @param addrlen The address length. Input parameter.
  135.  *  @returns Number of bytes received.
  136.  *  @returns EINVAL if the client does not send data.
  137.  *  @returns ENOMEM if there is not enough memory left.
  138.  *  @returns Other error codes as defined for the ipc_data_read_finalize() function.
  139.  */
  140. 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 );
  141.  
  142. #endif
  143.  
  144. /** @}
  145.  */
  146.  
  147.