libschc
rules_example.h
Go to the documentation of this file.
1 #ifndef _RULES_H_
2 #define _RULES_H_
3 
4 #include "schc_config.h"
5 
6 #if USE_IPv6
7 const static struct schc_ipv6_rule_t ipv6_rule1 = {
8  // id, up, down, length
9  1, 10, 10, 10,
10  {
11  // field, MSB,len, pos,dir, val, MO, CDA
12  { "version", 0, 1, 1, BI, {6}, &equal, NOTSENT },
13  { "traffic class", 0, 1, 1, BI, {0}, &ignore, NOTSENT },
14  { "flow label", 0, 3, 1, BI, {0, 0, 0}, &ignore, NOTSENT },
15  { "length", 0, 2, 1, BI, {0, 0}, &ignore, COMPLENGTH },
16  { "next header", 0, 1, 1, BI, {17}, &equal, NOTSENT },
17  { "hop limit", 0, 1, 1, BI, {64}, &ignore, NOTSENT },
18  { "src prefix", 0, 8, 1, BI, {0xAA, 0xAA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
19  &equal, NOTSENT },
20  { "src iid", 0, 8, 1, BI, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
21  &equal, NOTSENT },
22  { "dest prefix", 0, 8, 1, BI, {0xAA, 0xAA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
23  &equal, NOTSENT },
24  { "dest iid", 56, 8, 1, BI, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
25  &MSB, LSB },
26  }
27 };
28 
29 const static struct schc_ipv6_rule_t ipv6_rule2 = {
30  2, 10, 10, 10,
31  {
32  { "version", 0, 1, 1, BI, {6}, &equal, NOTSENT },
33  { "traffic class", 0, 1, 1, BI, {0}, &equal, NOTSENT },
34  { "flow label", 0, 3, 1, BI, {0, 0, 0x20}, &equal, NOTSENT },
35  { "length", 0, 2, 1, BI, {0, 0}, &ignore, COMPLENGTH },
36  { "next header", 0, 1, 1, BI, {17}, &equal, NOTSENT },
37  { "hop limit", 0, 1, 1, BI, {64}, &ignore, NOTSENT },
38  { "src prefix", 0, 8, 1, BI, {0x20, 0x01, 0x06, 0xA8, 0x1D, 0x80, 0x20, 0x21},
39  &equal, NOTSENT },
40  { "src iid", 48, 8, 1, BI, {0x02, 0x30, 0x48, 0xFF, 0xFE, 0x5A, 0x00, 0x00},
41  &MSB, LSB }, // by setting the last 2 bytes to 0x00, we allow 16 bit variations
42  { "dest prefix", 0, 8, 1, BI, {0x20, 0x01, 0x06, 0xA8, 0x1D, 0x80, 0x20, 0x21},
43  &equal, NOTSENT },
44  { "dest iid", 48, 8, 1, BI, {0x50, 0x74, 0xF2, 0xFF, 0xFE, 0xB1, 0x00, 0x00},
45  &MSB, LSB },
46  }
47 };
48 
49 const static struct schc_ipv6_rule_t ipv6_rule3 = {
50  // id, up, down, length
51  3, 10, 10, 10,
52  {
53  // field, MSB,len, pos,dir, val, MO, CDA
54  { "version", 0, 1, 1, BI, {6}, &equal, NOTSENT },
55  { "traffic class", 0, 1, 1, BI, {0}, &ignore, NOTSENT },
56  { "flow label", 0, 3, 1, BI, {0, 0, 0}, &ignore, NOTSENT },
57  { "length", 0, 2, 1, BI, {0, 0}, &ignore, COMPLENGTH },
58  { "next header", 0, 1, 1, BI, {17}, &equal, NOTSENT },
59  { "hop limit", 0, 1, 1, BI, {64}, &ignore, NOTSENT },
60  { "src prefix", 0, 8, 1, BI, {0xAA, 0xAA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
61  &equal, NOTSENT },
62  { "src iid", 0, 8, 1, BI, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
63  &equal, NOTSENT },
64  { "dest prefix", 0, 8, 1, BI, {0xAA, 0xAA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
65  &equal, NOTSENT },
66  { "dest iid", 56, 8, 1, BI, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
67  &MSB, LSB },
68  }
69 };
70 #endif
71 
72 #if USE_UDP
73 const static struct schc_udp_rule_t udp_rule1 = {
74  1, 4, 4, 4,
75  {
76  { "src port", 0, 2, 1, BI, {0x33, 0x16}, &equal, NOTSENT }, // 5683
77  { "dest port", 0, 2, 1, BI, {0x33, 0x16}, &equal, NOTSENT },
78  { "length", 0, 2, 1, BI, {0, 0}, &ignore, COMPLENGTH },
79  { "checksum", 0, 2, 1, BI, {0, 0}, &ignore, COMPCHK },
80  }
81 };
82 
83 const static struct schc_udp_rule_t udp_rule2 = {
84  2, 4, 4, 4,
85  {
86  { "src port", 12, 2, 1, BI, {0x33, 0x16}, &MSB, LSB }, // 1072 - 1087 | {4, 48}
87  { "dest port", 12, 2, 1, BI, {0x33, 0x16}, &MSB, LSB }, // 1072 - 1087 | {4, 48}
88  { "length", 0, 2, 1, BI, {0, 0}, &ignore, COMPLENGTH },
89  { "checksum", 0, 2, 1, BI, {0, 0}, &ignore, COMPCHK },
90  }
91 };
92 
93 const static struct schc_udp_rule_t udp_rule3 = {
94  3, 4, 4, 4,
95  {
96  { "src port", 0, 2, 1, BI, {0x13, 0x89}, &equal, NOTSENT },
97  { "dest port", 0, 2, 1, BI, {0x13, 0x88}, &equal, NOTSENT },
98  { "length", 0, 2, 1, BI, {0, 0}, &ignore, COMPLENGTH },
99  { "checksum", 0, 2, 1, BI, {0, 0}, &ignore, COMPCHK },
100  }
101 };
102 #endif
103 
104 #if USE_COAP
105 // it is important to use strings, identical to the ones
106 // defined in coap.h for the options
107 
108 // GET usage
109 const static struct schc_coap_rule_t coap_rule1 = {
110  1, 9, 7, 9,
111  {
112  { "version", 0, 1, 1, BI, {COAP_V1}, &equal, NOTSENT },
113  { "type", 0, 1, 1, BI, {CT_NON}, &equal, NOTSENT },
114  { "token length", 0, 1, 1, BI, {4}, &equal, NOTSENT },
115  { "code", 0, 1, 1, UP, {CC_PUT}, &equal, NOTSENT },
116  { "message ID", 0, 2, 1, UP, {0x23, 0xBB}, &equal, NOTSENT },
117  { "token", 24, 4, 1, BI, {0x21, 0xFA, 0x01, 0x00},
118  &MSB, LSB }, // by setting the last byte to 0x00, we allow 8 bit variations
119  { "uri-path", 0, 5, 1, BI, "usage", &equal, NOTSENT },
120  { "no-response", 0, 1, 1, BI, {0x1A}, &equal, NOTSENT },
121  { "payload marker", 0, 1, 1, BI, {255}, &equal, NOTSENT }
122 
123  }
124 };
125 
126 // POST temperature value
127 const static struct schc_coap_rule_t coap_rule2 = {
128  2, 8, 8, 10,
129  {
130  { "version", 0, 1, 1, BI, {COAP_V1}, &equal, NOTSENT },
131  { "type", 0, 3, 1, BI, {CT_CON, CT_ACK, CT_NON},
132  &matchmap, MAPPINGSENT },
133  { "token length", 0, 1, 1, BI, {4}, &equal, NOTSENT },
134  { "code", 0, 1, 1, UP, {CC_CONTENT}, &equal, NOTSENT },
135  { "code", 0, 1, 1, DOWN, {CC_GET}, &equal, NOTSENT },
136  { "message ID", 12, 2, 1, UP, {0x23, 0xBB}, &MSB, LSB },
137  { "message ID", 12, 2, 1, DOWN, {0x7A, 0x10}, &MSB, LSB },
138  { "token", 0, 4, 1, BI, {0, 0, 0, 0}, &ignore, VALUESENT }, // GET sensor value
139  { "uri-path", 0, 4, 2, BI, "[\"temp\",\"humi\",\"batt\",\"r\"]\0",
140  &matchmap, MAPPINGSENT },
141  { "payload marker", 0, 1, 1, BI, {255}, &equal, NOTSENT } // respond with CONTENT
142  }
143 };
144 
145 // GET usage
146 const static struct schc_coap_rule_t coap_rule3 = {
147  3, 8, 6, 8,
148  {
149  { "version", 0, 1, 1, BI, {COAP_V1}, &equal, NOTSENT },
150  { "type", 0, 1, 1, BI, {CT_NON}, &equal, NOTSENT },
151  { "token length", 0, 1, 1, BI, {4}, &equal, NOTSENT },
152  { "code", 0, 1, 1, UP, {CC_PUT}, &equal, NOTSENT },
153  { "message ID", 0, 2, 1, UP, {0x23, 0xBB}, &equal, NOTSENT },
154  { "token", 24, 4, 1, BI, {0x21, 0xFA, 0x01, 0x00},
155  &MSB, LSB }, // by setting the last byte to 0x00, we allow 8 bit variations
156  { "uri-path", 0, 5, 1, BI, "usage", &equal, NOTSENT },
157  { "no-response", 0, 1, 1, BI, {0x1A}, &equal, NOTSENT }
158 
159  }
160 };
161 
162 const static struct schc_coap_rule_t coap_rule4 = {
163  4, 12, 12, 12,
164  {
165  { "version", 0, 1, 1, BI, {COAP_V1}, &equal, NOTSENT },
166  { "type", 0, 1, 1, BI, {CT_CON}, &equal, NOTSENT },
167  { "token length", 0, 1, 1, BI, {8}, &equal, NOTSENT },
168  { "code", 0, 1, 1, BI, {CC_POST}, &equal, NOTSENT },
169  { "message ID", 0, 2, 1, BI, {0x23, 0xBB}, &ignore, VALUESENT },
170  { "token", 24, 8, 1, BI, {0x21, 0xFA, 0x01, 0x00},
171  &ignore, VALUESENT }, // by setting the last byte to 0x00, we allow 8 bit variations
172  { "uri-path", 0, 2, 1, BI, "rd", &equal, NOTSENT },
173  { "content-format", 0, 1, 1, BI, {0x28}, &equal, NOTSENT },
174  { "uri-query", 0, 9, 1, BI, {0x6C, 0x77, 0x6D, 0x32, 0x6D, 0x3D, 0x31, 0x2E, 0x30},
175  &equal, NOTSENT },
176  { "uri-query", 0, 11, 1, BI, {0x65, 0x70, 0x3D, 0x6D, 0x61, 0x67, 0x69, 0x63, 0x69, 0x61, 0x6E},
177  &equal, NOTSENT },
178  { "uri-query", 0, 6, 1, BI, {0x6C, 0x74, 0x3D, 0x31, 0x32, 0x31},
179  &equal, NOTSENT },
180  { "payload marker", 0, 1, 1, BI, {255}, &equal, NOTSENT } // respond with CONTENT
181  }
182 
183 };
184 #endif
185 
187 #if USE_IPv6
188  &ipv6_rule1,
189 #endif
190 #if USE_UDP
191  &udp_rule1,
192 #endif
193 #if USE_COAP
194  &coap_rule1,
195 #endif
196 };
197 
199 #if USE_IPv6
200  &ipv6_rule1,
201 #endif
202 #if USE_UDP
203  &udp_rule1,
204 #endif
205 #if USE_COAP
206  &coap_rule2,
207 #endif
208 };
209 
211 #if USE_IPv6
212  &ipv6_rule1,
213 #endif
214 #if USE_UDP
215  &udp_rule1,
216 #endif
217 #if USE_COAP
218  &coap_rule3,
219 #endif
220 };
221 
223 #if USE_IPv6
224  &ipv6_rule1,
225 #endif
226 #if USE_UDP
227  &udp_rule1,
228 #endif
229 #if USE_COAP
230  &coap_rule4,
231 #endif
232 };
233 
234 const struct schc_rule_t schc_rule_1 = { 0x01, &compression_rule_1, NOT_FRAGMENTED, 0, 0, 0, 0 };
235 const struct schc_rule_t schc_rule_2 = { 0x02, &compression_rule_1, NO_ACK, 1, 0, 0, 0 };
236 const struct schc_rule_t schc_rule_3 = { 0x03, &compression_rule_1, ACK_ON_ERROR, 3, 6, 1, 0 };
237 const struct schc_rule_t schc_rule_4 = { 0x04, &compression_rule_1, ACK_ALWAYS, 3, 6, 1, 0 };
238 
239 const struct schc_rule_t schc_rule_5 = { 0x05, &compression_rule_2, NOT_FRAGMENTED, 0, 0, 0, 0 };
240 const struct schc_rule_t schc_rule_6 = { 0x06, &compression_rule_2, NO_ACK, 1, 0, 0, 0 };
241 const struct schc_rule_t schc_rule_7 = { 0x07, &compression_rule_2, ACK_ON_ERROR, 3, 6, 1, 0 };
242 const struct schc_rule_t schc_rule_8 = { 0x08, &compression_rule_2, ACK_ALWAYS, 3, 6, 1, 0 };
243 
244 /* define total rules per layer */
245 #define IPV6_RULES 3
246 #define UDP_RULES 3
247 #define COAP_RULES 4
248 
249 /* save rules in flash */
252  &schc_rule_8 };
253 
254 /* rules for a particular device */
255 const struct schc_device node1 = { 1, 8, &node1_schc_rules };
256 const struct schc_device node2 = { 2, 8, &node2_schc_rules};
257 
258 #define DEVICE_COUNT 2
259 
260 /* server keeps track of multiple devices: add devices to device list */
261 const struct schc_device* devices[DEVICE_COUNT] = { &node1, &node2 };
262 
263 #endif
schc_coap_rule_t
Definition: config.h:69
NOTSENT
Definition: config.h:26
compression_rule_2
const struct schc_compression_rule_t compression_rule_2
Definition: rules_example.h:198
NO_ACK
Definition: schc_config.h:97
schc_rule_8
const struct schc_rule_t schc_rule_8
Definition: rules_example.h:242
schc_rule_6
const struct schc_rule_t schc_rule_6
Definition: rules_example.h:240
devices
const struct schc_device * devices[DEVICE_COUNT]
Definition: rules_example.h:261
coap_rule1
const static struct schc_coap_rule_t coap_rule1
Definition: rules_example.h:109
schc_rule_5
const struct schc_rule_t schc_rule_5
Definition: rules_example.h:239
CC_GET
Definition: picocoap.h:119
schc_rule_4
const struct schc_rule_t schc_rule_4
Definition: rules_example.h:237
schc_rule_7
const struct schc_rule_t schc_rule_7
Definition: rules_example.h:241
MSB
static uint8_t MSB(struct schc_field *target_field, unsigned char *field_value)
The MSB matching operator.
Definition: compressor.c:1088
schc_device
Definition: config.h:119
ACK_ALWAYS
Definition: schc_config.h:97
schc_rule_t
Definition: config.h:102
equal
static uint8_t equal(struct schc_field *target_field, unsigned char *field_value)
The equal matching operator.
Definition: compressor.c:1047
ipv6_rule2
const static struct schc_ipv6_rule_t ipv6_rule2
Definition: rules_example.h:29
schc_ipv6_rule_t
Definition: config.h:49
schc_compression_rule_t
Definition: config.h:87
schc_rule_3
const struct schc_rule_t schc_rule_3
Definition: rules_example.h:236
schc_config.h
CT_CON
Definition: picocoap.h:105
DEVICE_COUNT
#define DEVICE_COUNT
Definition: rules_example.h:258
CT_ACK
Definition: picocoap.h:107
udp_rule3
const static struct schc_udp_rule_t udp_rule3
Definition: rules_example.h:93
schc_rule_2
const struct schc_rule_t schc_rule_2
Definition: rules_example.h:235
COMPCHK
Definition: config.h:31
compression_rule_1
const struct schc_compression_rule_t compression_rule_1
Definition: rules_example.h:186
DOWN
Definition: config.h:18
MAPPINGSENT
Definition: config.h:28
schc_rule_1
const struct schc_rule_t schc_rule_1
Definition: rules_example.h:234
LSB
Definition: config.h:29
udp_rule1
const static struct schc_udp_rule_t udp_rule1
Definition: rules_example.h:73
CC_PUT
Definition: picocoap.h:121
COAP_V1
Definition: picocoap.h:96
ipv6_rule1
const static struct schc_ipv6_rule_t ipv6_rule1
Definition: rules_example.h:7
NOT_FRAGMENTED
Definition: schc_config.h:97
compression_rule_4
const struct schc_compression_rule_t compression_rule_4
Definition: rules_example.h:222
ACK_ON_ERROR
Definition: schc_config.h:97
UP
Definition: config.h:18
coap_rule3
const static struct schc_coap_rule_t coap_rule3
Definition: rules_example.h:146
coap_rule4
const static struct schc_coap_rule_t coap_rule4
Definition: rules_example.h:162
CC_POST
Definition: picocoap.h:120
ipv6_rule3
const static struct schc_ipv6_rule_t ipv6_rule3
Definition: rules_example.h:49
schc_udp_rule_t
Definition: config.h:59
CC_CONTENT
Definition: picocoap.h:128
matchmap
static uint8_t matchmap(struct schc_field *target_field, unsigned char *field_value)
The match-map matching operator.
Definition: compressor.c:1145
ignore
static uint8_t ignore(struct schc_field *target_field, unsigned char *field_value)
The ignore matching operator.
Definition: compressor.c:1073
udp_rule2
const static struct schc_udp_rule_t udp_rule2
Definition: rules_example.h:83
node1
const struct schc_device node1
Definition: rules_example.h:255
coap_rule2
const static struct schc_coap_rule_t coap_rule2
Definition: rules_example.h:127
CT_NON
Definition: picocoap.h:106
BI
Definition: config.h:18
COMPLENGTH
Definition: config.h:30
node1_schc_rules
const struct schc_rule_t * node1_schc_rules[]
Definition: rules_example.h:250
node2
const struct schc_device node2
Definition: rules_example.h:256
VALUESENT
Definition: config.h:27
compression_rule_3
const struct schc_compression_rule_t compression_rule_3
Definition: rules_example.h:210