ROHC compression/decompression library
rohc_list.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012,2013,2014 Didier Barvaux
3  * Copyright 2008,2010,2012 Viveris Technologies
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /**
21  * @file rohc_list.h
22  * @brief Define list compression with its function
23  * @author Didier Barvaux <didier@barvaux.org>
24  */
25 
26 #ifndef ROHC_COMMON_LIST_H
27 #define ROHC_COMMON_LIST_H
28 
29 #include "protocols/ipv6.h"
30 #include "protocols/ip_numbers.h"
31 
32 #include <stdlib.h>
33 
34 
35 /** The maximum number of items in compressed lists */
36 #define ROHC_LIST_MAX_ITEM 16U
37 #if ROHC_LIST_MAX_ITEM <= 7
38 # error "translation table must be larger enough for indexes stored on 3 bits"
39 #endif
40 
41 
42 /// Header version
43 typedef enum
44 {
45  HBH = ROHC_IPPROTO_HOPOPTS, /**< Hop by hop header */
46  RTHDR = ROHC_IPPROTO_ROUTING, /**< Routing header */
47  AH = ROHC_IPPROTO_AH, /**< AH header */
48  DEST = ROHC_IPPROTO_DSTOPTS, /**< Destination header */
49  /* CSRC lists not supported yet */
51 
52 
53 /** The largest gen_id value */
54 #define ROHC_LIST_GEN_ID_MAX 0xffU
55 #define ROHC_LIST_GEN_ID_ANON (ROHC_LIST_GEN_ID_MAX + 1)
56 #define ROHC_LIST_GEN_ID_NONE (ROHC_LIST_GEN_ID_MAX + 2)
57 
58 
59 /**
60  * @brief Define a list for compression
61  */
62 struct rohc_list
63 {
64 /** The maximum number of items in a list (required by packet formats) */
65 #define ROHC_LIST_ITEMS_MAX 15U
66  /** The items in the list */
68  /** The ID of the compressed list */
69  uint16_t id;
70  /** The number of items in the list */
71  uint8_t items_nr;
72  /** How many times the list was transmitted? */
73  uint8_t counter;
74 };
75 
76 /* compiler sanity check for C11-compliant compilers and GCC >= 4.6 */
77 #if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
78  (defined(__GNUC__) && defined(__GNUC_MINOR__) && \
79  (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))))
80 _Static_assert((sizeof(struct rohc_list) % 8) == 0,
81  "struct rohc_list length should be multiple of 8 bytes");
82 #endif
83 
84 
85 /**
86  * @brief A list item
87  */
89 {
90  /** The type of the item */
92 
93  /** Is the compressor confident that the decompressor knows the item? */
94  bool known;
95  /** How many times the item was transmitted? */
96  uint8_t counter;
97 
98 /**
99  * @brief The maximum length (in bytes) of item data
100  *
101  * Sized for IPv6 extension headers that may reach:
102  * (0xff + 1) * 8 = 2048 bytes
103  */
104 #define ROHC_LIST_ITEM_DATA_MAX IPV6_OPT_HDR_LEN_MAX
105 
106  /** The length of the item data (in bytes) */
107  uint16_t length;
108  /** The item data */
110 };
111 
112 /* compiler sanity check for C11-compliant compilers and GCC >= 4.6 */
113 #if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
114  (defined(__GNUC__) && defined(__GNUC_MINOR__) && \
115  (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))))
116 _Static_assert((offsetof(struct rohc_list_item, data) % 8) == 0,
117  "data in struct rohc_list_item should be aligned on 8 bytes");
118 _Static_assert((sizeof(struct rohc_list_item) % 8) == 0,
119  "struct rohc_list_item length should be multiple of 8 bytes");
120 #endif
121 
122 
123 /** The handler used to compare two items */
124 typedef bool (*rohc_list_item_cmp) (const struct rohc_list_item *const item,
125  const uint8_t ext_type,
126  const uint8_t *const ext_data,
127  const size_t ext_len)
128  __attribute__((warn_unused_result, nonnull(1, 3)));
129 
130 
131 
132 /**
133  * Functions prototypes
134  */
135 
136 void rohc_list_reset(struct rohc_list *const list)
137  __attribute__((nonnull(1)));
138 
139 bool rohc_list_equal(const struct rohc_list *const list1,
140  const struct rohc_list *const list2)
141  __attribute__((warn_unused_result, nonnull(1, 2), pure));
142 
143 bool rohc_list_supersede(const struct rohc_list *const large,
144  const struct rohc_list *const small)
145  __attribute__((warn_unused_result, nonnull(1, 2), pure));
146 
147 void rohc_list_item_reset(struct rohc_list_item *const list_item)
148  __attribute__((nonnull(1)));
149 
151  struct rohc_list_item *const list_item,
152  const uint8_t item_type,
153  const uint8_t *const item_data,
154  const size_t item_len)
155  __attribute__((warn_unused_result, nonnull(2, 4)));
156 
157 #endif
158 
Definition: ip_numbers.h:62
Definition: ip_numbers.h:70
uint16_t length
Definition: rohc_list.h:107
uint8_t counter
Definition: rohc_list.h:96
bool known
Definition: rohc_list.h:94
void rohc_list_reset(struct rohc_list *const list)
Reset the state of the given compressed list.
Definition: rohc_list.c:45
Definition: rohc_list.h:46
uint8_t counter
Definition: rohc_list.h:73
bool rohc_list_supersede(const struct rohc_list *const large, const struct rohc_list *const small)
Does the first list contains the second list?
Definition: rohc_list.c:86
struct rohc_list_item * items[ROHC_LIST_ITEMS_MAX]
Definition: rohc_list.h:67
Definition: rohc_list.h:48
ext_header_version type
Definition: rohc_list.h:91
bool nonnull(1)))
bool rohc_list_equal(const struct rohc_list *const list1, const struct rohc_list *const list2)
Are the two given lists equal?
Definition: rohc_list.c:66
uint8_t data[ROHC_LIST_ITEM_DATA_MAX]
Definition: rohc_list.h:109
bool(* rohc_list_item_cmp)(const struct rohc_list_item *const item, const uint8_t ext_type, const uint8_t *const ext_data, const size_t ext_len)
Definition: rohc_list.h:124
int rohc_list_item_update_if_changed(rohc_list_item_cmp cmp_item, struct rohc_list_item *const list_item, const uint8_t item_type, const uint8_t *const item_data, const size_t item_len)
Update the content of the given compressed item if it changed.
Definition: rohc_list.c:143
#define ROHC_LIST_ITEMS_MAX
Definition: rohc_list.h:65
Definition: ip_numbers.h:74
The IPv6 header.
void rohc_list_item_reset(struct rohc_list_item *const list_item)
Reset the given list item.
Definition: rohc_list.c:120
Definition: rohc_list.h:45
Definition: ip_numbers.h:52
#define ROHC_LIST_ITEM_DATA_MAX
The maximum length (in bytes) of item data.
Definition: rohc_list.h:104
ext_header_version
Header version.
Definition: rohc_list.h:43
A list item.
Definition: rohc_list.h:88
Define a list for compression.
Definition: rohc_list.h:62
Definition: rohc_list.h:47
uint16_t id
Definition: rohc_list.h:69
uint8_t items_nr
Definition: rohc_list.h:71
Defines the IPv4 protocol numbers.