ROHC compression/decompression library
comp_list.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012,2013,2014 Didier Barvaux
00003  * Copyright 2008,2010,2012 Viveris Technologies
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 /**
00021  * @file comp_list.h
00022  * @brief Define list compression with its function
00023  * @author Didier Barvaux <didier@barvaux.org>
00024  */
00025 
00026 #ifndef ROHC_COMMON_COMP_LIST_H
00027 #define ROHC_COMMON_COMP_LIST_H
00028 
00029 #include "protocols/ipv6.h"
00030 #include "protocols/ip_numbers.h"
00031 
00032 #include <stdlib.h>
00033 
00034 #include "dllexport.h"
00035 
00036 
00037 /** The maximum number of items in compressed lists */
00038 #define ROHC_LIST_MAX_ITEM  16U
00039 #if ROHC_LIST_MAX_ITEM <= 7
00040 #  error "translation table must be larger enough for indexes stored on 3 bits"
00041 #endif
00042 
00043 
00044 /// Header version
00045 typedef enum
00046 {
00047         HBH    = ROHC_IPPROTO_HOPOPTS,  /**< Hop by hop header */
00048         RTHDR  = ROHC_IPPROTO_ROUTING,  /**< Routing header */
00049         AH     = ROHC_IPPROTO_AH,       /**< AH header */
00050         DEST   = ROHC_IPPROTO_DSTOPTS,  /**< Destination header */
00051         /* CSRC lists not supported yet */
00052 } ext_header_version;
00053 
00054 
00055 /** The largest gen_id value */
00056 #define ROHC_LIST_GEN_ID_MAX   0xffU
00057 #define ROHC_LIST_GEN_ID_NONE  (ROHC_LIST_GEN_ID_MAX + 1)
00058 #define ROHC_LIST_GEN_ID_ANON  (ROHC_LIST_GEN_ID_MAX + 2)
00059 
00060 
00061 /**
00062  * @brief Define a list for compression
00063  */
00064 struct rohc_list
00065 {
00066         /** The ID of the compressed list */
00067         unsigned int id;
00068 /** The maximum number of items in a list (required by packet formats) */
00069 #define ROHC_LIST_ITEMS_MAX  15U
00070         /** The items in the list */
00071         struct rohc_list_item *items[ROHC_LIST_ITEMS_MAX];
00072         /** The number of items in the list */
00073         size_t items_nr;
00074         /** How many times the list was transmitted? */
00075         size_t counter;
00076 };
00077 
00078 
00079 /**
00080  * @brief A list item
00081  */
00082 struct rohc_list_item
00083 {
00084         /** The type of the item */
00085         ext_header_version type;
00086 
00087         /** Is the compressor confident that the decompressor knows the item? */
00088         bool known;
00089         /** How many times the item was transmitted? */
00090         size_t counter;
00091 
00092 /**
00093  * @brief The maximum length (in bytes) of item data
00094  *
00095  * Sized for IPv6 extension headers that may reach:
00096  *   (0xff + 1) * 8 = 2048 bytes
00097  */
00098 #define ROHC_LIST_ITEM_DATA_MAX 2048U
00099 
00100         /** The length of the item data (in bytes) */
00101         size_t length;
00102         /** The item data */
00103         uint8_t data[ROHC_LIST_ITEM_DATA_MAX];
00104 };
00105 
00106 
00107 /** The handler used to compare two items */
00108 typedef bool (*rohc_list_item_cmp) (const struct rohc_list_item *const item,
00109                                     const uint8_t ext_type,
00110                                     const uint8_t *const ext_data,
00111                                     const size_t ext_len)
00112         __attribute__((warn_unused_result, nonnull(1, 3)));
00113 
00114 
00115 
00116 /**
00117  * Functions prototypes
00118  */
00119 
00120 void ROHC_EXPORT rohc_list_reset(struct rohc_list *const list)
00121         __attribute__((nonnull(1)));
00122 
00123 bool ROHC_EXPORT rohc_list_equal(const struct rohc_list *const list1,
00124                                  const struct rohc_list *const list2)
00125         __attribute__((warn_unused_result, nonnull(1, 2)));
00126 
00127 bool ROHC_EXPORT rohc_list_supersede(const struct rohc_list *const large,
00128                                      const struct rohc_list *const small)
00129         __attribute__((warn_unused_result, nonnull(1, 2)));
00130 
00131 void ROHC_EXPORT rohc_list_item_reset(struct rohc_list_item *const list_item)
00132         __attribute__((nonnull(1)));
00133 
00134 int ROHC_EXPORT rohc_list_item_update_if_changed(rohc_list_item_cmp cmp_item,
00135                                                  struct rohc_list_item *const list_item,
00136                                                  const uint8_t item_type,
00137                                                  const uint8_t *const item_data,
00138                                                  const size_t item_len)
00139         __attribute__((warn_unused_result, nonnull(2, 4)));
00140 
00141 #endif
00142