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 ID of the compressed list */
65  unsigned int id;
66 /** The maximum number of items in a list (required by packet formats) */
67 #define ROHC_LIST_ITEMS_MAX 15U
68  /** The items in the list */
70  /** The number of items in the list */
71  size_t items_nr;
72  /** How many times the list was transmitted? */
73  size_t counter;
74 };
75 
76 
77 /**
78  * @brief A list item
79  */
81 {
82  /** The type of the item */
84 
85  /** Is the compressor confident that the decompressor knows the item? */
86  bool known;
87  /** How many times the item was transmitted? */
88  size_t counter;
89 
90 /**
91  * @brief The maximum length (in bytes) of item data
92  *
93  * Sized for IPv6 extension headers that may reach:
94  * (0xff + 1) * 8 = 2048 bytes
95  */
96 #define ROHC_LIST_ITEM_DATA_MAX 2048U
97 
98  /** The length of the item data (in bytes) */
99  size_t length;
100  /** The item data */
101  uint8_t data[ROHC_LIST_ITEM_DATA_MAX];
102 };
103 
104 
105 /** The handler used to compare two items */
106 typedef bool (*rohc_list_item_cmp) (const struct rohc_list_item *const item,
107  const uint8_t ext_type,
108  const uint8_t *const ext_data,
109  const size_t ext_len)
110  __attribute__((warn_unused_result, nonnull(1, 3)));
111 
112 
113 
114 /**
115  * Functions prototypes
116  */
117 
118 void rohc_list_reset(struct rohc_list *const list)
119  __attribute__((nonnull(1)));
120 
121 bool rohc_list_equal(const struct rohc_list *const list1,
122  const struct rohc_list *const list2)
123  __attribute__((warn_unused_result, nonnull(1, 2), pure));
124 
125 bool rohc_list_supersede(const struct rohc_list *const large,
126  const struct rohc_list *const small)
127  __attribute__((warn_unused_result, nonnull(1, 2), pure));
128 
129 void rohc_list_item_reset(struct rohc_list_item *const list_item)
130  __attribute__((nonnull(1)));
131 
133  struct rohc_list_item *const list_item,
134  const uint8_t item_type,
135  const uint8_t *const item_data,
136  const size_t item_len)
137  __attribute__((warn_unused_result, nonnull(2, 4)));
138 
139 #endif
140 
Definition: ip_numbers.h:62
Definition: ip_numbers.h:70
bool known
Definition: rohc_list.h:86
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
unsigned int id
Definition: rohc_list.h:65
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:87
size_t items_nr
Definition: rohc_list.h:71
struct rohc_list_item * items[ROHC_LIST_ITEMS_MAX]
Definition: rohc_list.h:69
Definition: rohc_list.h:48
ext_header_version type
Definition: rohc_list.h:83
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:67
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:106
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:146
#define ROHC_LIST_ITEMS_MAX
Definition: rohc_list.h:67
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:121
size_t counter
Definition: rohc_list.h:88
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:96
ext_header_version
Header version.
Definition: rohc_list.h:43
size_t length
Definition: rohc_list.h:99
A list item.
Definition: rohc_list.h:80
size_t counter
Definition: rohc_list.h:73
Define a list for compression.
Definition: rohc_list.h:62
Definition: rohc_list.h:47
Defines the IPv4 protocol numbers.