1 /* main.c - Application main entry point */
2
3 /*
4 * Copyright (c) 2016 Intel Corporation
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9 #include <zephyr/logging/log.h>
10 LOG_MODULE_REGISTER(net_test, CONFIG_NET_6LO_LOG_LEVEL);
11
12 #include <zephyr/kernel.h>
13 #include <zephyr/ztest.h>
14 #include <zephyr/linker/sections.h>
15
16 #include <zephyr/types.h>
17 #include <stddef.h>
18 #include <string.h>
19 #include <stdio.h>
20 #include <errno.h>
21 #include <zephyr/device.h>
22 #include <zephyr/init.h>
23 #include <zephyr/net/net_core.h>
24 #include <zephyr/net/net_pkt.h>
25 #include <zephyr/net/net_ip.h>
26 #include <zephyr/net/dummy.h>
27
28 #include <zephyr/tc_util.h>
29
30 #include "6lo.h"
31 #include "icmpv6.h"
32
33 #define NET_LOG_ENABLED 1
34 #include "net_private.h"
35
36 #define DEBUG 0
37
38 #define SIZE_OF_SMALL_DATA 40
39 #define SIZE_OF_LARGE_DATA 120
40
41 /* IPv6 Source and Destination address
42 * Example addresses are based on SAC (Source Address Compression),
43 * SAM (Source Address Mode), DAC (Destination Address Compression),
44 * DAM (Destination Address Mode) and also if the destination address
45 * is Multicast address.
46 */
47
48 #define src_sac1_sam00 \
49 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
50 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
51
52 #define src_sam00 \
53 { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
54 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
55
56 #define src_sam01 \
57 { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
58 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa }
59
60 #define src_sam10 \
61 { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
62 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xbb }
63 #define src_sam11 \
64 { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
65 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xbb }
66
67 #define dst_m1_dam00 \
68 { 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
69 0x00, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }
70
71 #define dst_m1_dam01 \
72 { 0xff, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
73 0x00, 0x00, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }
74
75 #define dst_m1_dam10 \
76 { 0xff, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
77 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x22, 0x33 }
78
79 #define dst_m1_dam11 \
80 { 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
81 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11 }
82
83 #define dst_dam00 \
84 { 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
85 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
86
87 #define dst_dam01 \
88 { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
89 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa }
90
91 #define dst_dam10 \
92 { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
93 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xbb }
94 #define dst_dam11 \
95 { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
96 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0xaa }
97
98 uint8_t src_mac[8] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xbb };
99 uint8_t dst_mac[8] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0xaa };
100
101 /* Source and Destination addresses are context related addresses. */
102 #if defined(CONFIG_NET_6LO_CONTEXT)
103 /* CONFIG_NET_MAX_6LO_CONTEXTS=2, defined in prj.conf, If you want
104 * to increase this value, then add extra contexts here.
105 */
106 #define ctx1_prefix \
107 { 0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
108 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
109
110 /* 6CO contexts */
111 static struct net_icmpv6_nd_opt_6co ctx1 = {
112 .context_len = 0x40,
113 .flag = 0x11,
114 .reserved = 0,
115 .lifetime = 0x1234,
116 .prefix = ctx1_prefix
117 };
118
119 #define ctx2_prefix \
120 { 0xcc, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
121 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
122
123 static struct net_icmpv6_nd_opt_6co ctx2 = {
124 .context_len = 0x80,
125 .flag = 0x12,
126 .reserved = 0,
127 .lifetime = 0x1234,
128 .prefix = ctx2_prefix
129 };
130
131 #define src_sac1_sam01 \
132 { 0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa }
134 #define dst_dac1_dam01 \
135 { 0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
136 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa }
137 #define src_sac1_sam10 \
138 { 0xcc, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
139 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xbb }
140 #define dst_dac1_dam10 \
141 { 0xcc, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
142 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0xbb }
143 #define src_sac1_sam11 \
144 { 0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
145 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xbb }
146 #define dst_dac1_dam11 \
147 { 0xcc, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
148 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0xaa }
149 #endif
150
151 /* UDP Ports */
152 /* 4 bit compressible udp ports */
153 #define udp_src_port_4bit 0xf0b1
154 #define udp_dst_port_4bit 0xf0b2
155
156 /* 8 bit compressible udp ports */
157 #define udp_src_port_8bit 0xf111
158 #define udp_dst_port_8bit_y 0xf022 /* compressible */
159
160 #define udp_src_port_8bit_y 0xf011 /* compressible */
161 #define udp_dst_port_8bit 0xf122
162
163 /* uncompressible ports */
164 #define udp_src_port_16bit 0xff11
165 #define udp_dst_port_16bit 0xff22
166
167 /* Inlinded data size */
168 #define TF_00 4
169 #define TF_01 3
170 #define TF_10 1
171 #define TF_11 0
172
173 #define CID_0 0
174 #define CID_1 1
175 #define NHC_0 1
176 #define NHC_1 0
177
178 #define HLIM_1 0
179 #define HLOM_0 1
180
181 #define SAC0_SAM00 16
182 #define SAC0_SAM01 8
183 #define SAC0_SAM10 2
184 #define SAC0_SAM11 0
185 #define SAC1_SAM00 0
186 #define SAC1_SAM01 8
187 #define SAC1_SAM10 2
188 #define SAC1_SAM11 0
189
190 #define M0_DAC0_DAM00 16
191 #define M0_DAC0_DAM01 8
192 #define M0_DAC0_DAM10 2
193 #define M0_DAC0_DAM11 0
194 #define M0_DAC1_DAM01 8
195 #define M0_DAC1_DAM10 2
196 #define M0_DAC1_DAM11 0
197 #define M1_DAC0_DAM00 16
198 #define M1_DAC0_DAM01 6
199 #define M1_DAC0_DAM10 4
200 #define M1_DAC0_DAM11 1
201 #define M1_DAC1_DAM00 6
202
203 #define UDP_CHKSUM_0 2
204 #define UDP_CHKSUM_1 0
205
206 #define UDP_P00 4
207 #define UDP_P01 3
208 #define UDP_P10 3
209 #define UDP_P11 1
210
211
212 #define IPHC_SIZE 2
213 #define NHC_SIZE 1
214
215 #define IPV6_DISPATCH_DIFF -1
216
217 static const char user_data[] =
218 "0123456789012345678901234567890123456789"
219 "0123456789012345678901234567890123456789"
220 "0123456789012345678901234567890123456789";
221
222 #if defined(CONFIG_NET_BUF_FIXED_DATA_SIZE)
223 #define TEST_FRAG_LEN CONFIG_NET_BUF_DATA_SIZE
224 #else
225 #define TEST_FRAG_LEN 128
226 #endif /* CONFIG_NET_BUF_FIXED_DATA_SIZE */
227
228 struct user_data_small {
229 char data[SIZE_OF_SMALL_DATA];
230 };
231
232 struct user_data_large {
233 char data[SIZE_OF_LARGE_DATA];
234 };
235
236
237 struct net_6lo_data {
238 struct net_ipv6_hdr ipv6;
239
240 union {
241 struct net_udp_hdr udp;
242 struct net_icmp_hdr icmp;
243 } nh;
244
245 int hdr_diff;
246
247 bool nh_udp;
248 bool nh_icmp;
249 bool iphc;
250 bool small;
251 } __packed;
252
253
net_6lo_dev_init(const struct device * dev)254 int net_6lo_dev_init(const struct device *dev)
255 {
256 struct net_6lo_context *net_6lo_context = dev->data;
257
258 net_6lo_context = net_6lo_context;
259
260 return 0;
261 }
262
net_6lo_iface_init(struct net_if * iface)263 static void net_6lo_iface_init(struct net_if *iface)
264 {
265 net_if_set_link_addr(iface, src_mac, 8, NET_LINK_IEEE802154);
266 }
267
tester_send(const struct device * dev,struct net_pkt * pkt)268 static int tester_send(const struct device *dev, struct net_pkt *pkt)
269 {
270 return 0;
271 }
272
273 static struct dummy_api net_6lo_if_api = {
274 .iface_api.init = net_6lo_iface_init,
275 .send = tester_send,
276 };
277
278 NET_DEVICE_INIT(net_6lo_test, "net_6lo_test",
279 net_6lo_dev_init, NULL, NULL, NULL,
280 CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
281 &net_6lo_if_api, DUMMY_L2, NET_L2_GET_CTX_TYPE(DUMMY_L2), 127);
282
compare_ipv6_hdr(struct net_pkt * pkt,struct net_6lo_data * data)283 static bool compare_ipv6_hdr(struct net_pkt *pkt, struct net_6lo_data *data)
284 {
285 NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(ipv6_access, struct net_ipv6_hdr);
286 struct net_ipv6_hdr *ipv6_hdr = net_pkt_get_data(pkt, &ipv6_access);
287 int res;
288
289 if (!ipv6_hdr) {
290 TC_PRINT("Failed to read IPv6 HDR\n");
291 return false;
292 }
293
294 net_pkt_acknowledge_data(pkt, &ipv6_access);
295
296 res = memcmp((uint8_t *)ipv6_hdr, (uint8_t *)&data->ipv6,
297 sizeof(struct net_ipv6_hdr));
298 if (res) {
299 TC_PRINT("Mismatch IPv6 HDR\n");
300 return false;
301 }
302
303 return true;
304 }
305
compare_udp_hdr(struct net_pkt * pkt,struct net_6lo_data * data)306 static bool compare_udp_hdr(struct net_pkt *pkt, struct net_6lo_data *data)
307 {
308 NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(udp_access, struct net_udp_hdr);
309 struct net_udp_hdr *udp_hdr = net_pkt_get_data(pkt, &udp_access);
310 int res;
311
312 if (!udp_hdr) {
313 TC_PRINT("Failed to read UDP HDR\n");
314 return false;
315 }
316
317 net_pkt_acknowledge_data(pkt, &udp_access);
318
319 res = memcmp((uint8_t *)udp_hdr, (uint8_t *)&data->nh.udp,
320 sizeof(struct net_udp_hdr));
321 if (res) {
322 TC_PRINT("Mismatch UDP HDR\n");
323 return false;
324 }
325
326 return true;
327 }
328
compare_icmp_hdr(struct net_pkt * pkt,struct net_6lo_data * data)329 static bool compare_icmp_hdr(struct net_pkt *pkt, struct net_6lo_data *data)
330 {
331 NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(icmp_access, struct net_icmp_hdr);
332 struct net_icmp_hdr *icmp_hdr = net_pkt_get_data(pkt, &icmp_access);
333 int res;
334
335 if (!icmp_hdr) {
336 TC_PRINT("Failed to read ICMP HDR\n");
337 return false;
338 }
339
340 net_pkt_acknowledge_data(pkt, &icmp_access);
341
342 res = memcmp((uint8_t *)icmp_hdr, (uint8_t *)&data->nh.icmp,
343 sizeof(struct net_icmp_hdr));
344 if (res) {
345 TC_PRINT("Mismatch ICMP HDR\n");
346 return false;
347 }
348
349 return true;
350 }
351
compare_data_small(struct net_pkt * pkt,const char * data)352 static bool compare_data_small(struct net_pkt *pkt, const char *data)
353 {
354 NET_PKT_DATA_ACCESS_DEFINE(data_access, struct user_data_small);
355 struct user_data_small *test_data = net_pkt_get_data(pkt, &data_access);
356 int res;
357
358 if (!test_data) {
359 TC_PRINT("Failed to read user data\n");
360 return false;
361 }
362
363 net_pkt_acknowledge_data(pkt, &data_access);
364
365 res = memcmp(test_data->data, data, sizeof(struct user_data_small));
366 if (res) {
367 TC_PRINT("User data mismatch\n");
368 return false;
369 }
370
371 return true;
372 }
373
compare_data_large(struct net_pkt * pkt,const char * data)374 static bool compare_data_large(struct net_pkt *pkt, const char *data)
375 {
376 NET_PKT_DATA_ACCESS_DEFINE(data_access, struct user_data_large);
377 struct user_data_large *test_data = net_pkt_get_data(pkt, &data_access);
378 int res;
379
380 if (!test_data) {
381 TC_PRINT("Failed to read user data\n");
382 return false;
383 }
384
385 net_pkt_acknowledge_data(pkt, &data_access);
386
387 res = memcmp(test_data->data, data, sizeof(struct user_data_large));
388 if (res) {
389 TC_PRINT("User data mismatch\n");
390 return false;
391 }
392
393 return true;
394 }
395
compare_pkt(struct net_pkt * pkt,struct net_6lo_data * data)396 static bool compare_pkt(struct net_pkt *pkt, struct net_6lo_data *data)
397 {
398 int remaining = data->small ? SIZE_OF_SMALL_DATA : SIZE_OF_LARGE_DATA;
399
400 if (data->nh_udp) {
401 if (net_pkt_get_len(pkt) !=
402 (NET_IPV6UDPH_LEN + remaining)) {
403
404 TC_PRINT("mismatch lengths, expected %d received %zu\n",
405 NET_IPV6UDPH_LEN + remaining,
406 net_pkt_get_len(pkt));
407
408 return false;
409 }
410 } else if (data->nh_icmp) {
411 if (net_pkt_get_len(pkt) !=
412 (NET_IPV6ICMPH_LEN + remaining)) {
413
414 TC_PRINT("mismatch lengths, expected %d received %zu\n",
415 NET_IPV6ICMPH_LEN + remaining,
416 net_pkt_get_len(pkt));
417
418 return false;
419 }
420 } else {
421 if (net_pkt_get_len(pkt) !=
422 (NET_IPV6H_LEN + remaining)) {
423
424 TC_PRINT("mismatch lengths, expected %d received %zu\n",
425 NET_IPV6H_LEN + remaining,
426 net_pkt_get_len(pkt));
427
428 return false;
429 }
430 }
431
432 net_pkt_set_overwrite(pkt, true);
433
434 if (!compare_ipv6_hdr(pkt, data)) {
435 return false;
436 }
437
438 if (data->nh_udp) {
439 if (!compare_udp_hdr(pkt, data)) {
440 return false;
441 }
442 } else if (data->nh_icmp) {
443 if (!compare_icmp_hdr(pkt, data)) {
444 return false;
445 }
446 }
447
448 if (data->small) {
449 if (!compare_data_small(pkt, user_data)) {
450 return false;
451 }
452 } else {
453 if (!compare_data_large(pkt, user_data)) {
454 return false;
455 }
456 }
457
458 return true;
459 }
460
create_pkt(struct net_6lo_data * data)461 static struct net_pkt *create_pkt(struct net_6lo_data *data)
462 {
463 struct net_pkt *pkt;
464 struct net_buf *frag;
465 uint8_t bytes, pos;
466 uint16_t len;
467 int remaining;
468
469 pkt = net_pkt_alloc_on_iface(
470 net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY)), K_FOREVER);
471 if (!pkt) {
472 return NULL;
473 }
474
475 net_pkt_set_ip_hdr_len(pkt, NET_IPV6H_LEN);
476
477 net_pkt_lladdr_src(pkt)->addr = src_mac;
478 net_pkt_lladdr_src(pkt)->len = 8U;
479
480 net_pkt_lladdr_dst(pkt)->addr = dst_mac;
481 net_pkt_lladdr_dst(pkt)->len = 8U;
482
483 frag = net_pkt_get_frag(pkt, NET_IPV6UDPH_LEN, K_FOREVER);
484 if (!frag) {
485 net_pkt_unref(pkt);
486 return NULL;
487 }
488
489 if (data->nh_udp) {
490 memcpy(frag->data, (uint8_t *) data, NET_IPV6UDPH_LEN);
491 net_buf_add(frag, NET_IPV6UDPH_LEN);
492 } else if (data->nh_icmp) {
493 memcpy(frag->data, (uint8_t *) data, NET_IPV6ICMPH_LEN);
494 net_buf_add(frag, NET_IPV6ICMPH_LEN);
495
496 } else {
497 memcpy(frag->data, (uint8_t *) data, NET_IPV6H_LEN);
498 net_buf_add(frag, NET_IPV6H_LEN);
499 }
500
501 pos = 0U;
502 remaining = data->small ? SIZE_OF_SMALL_DATA : SIZE_OF_LARGE_DATA;
503
504 if (data->nh_udp) {
505 len = NET_UDPH_LEN + remaining;
506 } else if (data->nh_icmp) {
507 len = NET_ICMPH_LEN + remaining;
508 } else {
509 len = remaining;
510 }
511
512 /* length is not set in net_6lo_data data pointer, calculate and set
513 * in ipv6, udp and in data pointer too (it's required in comparison)
514 */
515 frag->data[4] = len >> 8;
516 frag->data[5] = (uint8_t) len;
517
518 data->ipv6.len = htons(len);
519
520 if (data->nh_udp) {
521 frag->data[44] = len >> 8;
522 frag->data[45] = (uint8_t) len;
523
524 data->nh.udp.len = htons(len);
525 }
526
527 while (remaining > 0) {
528 uint8_t copy;
529
530 bytes = net_buf_tailroom(frag);
531 copy = remaining > bytes ? bytes : remaining;
532 memcpy(net_buf_add(frag, copy), &user_data[pos], copy);
533
534 pos += copy;
535 remaining -= copy;
536
537 if (net_buf_tailroom(frag) - (bytes - copy)) {
538 net_pkt_unref(pkt);
539 return NULL;
540 }
541
542 net_pkt_frag_add(pkt, frag);
543
544 if (remaining > 0) {
545 frag = net_pkt_get_frag(pkt, TEST_FRAG_LEN, K_FOREVER);
546 }
547 }
548
549 return pkt;
550 }
551
552 static struct net_6lo_data test_data_1 = {
553 .ipv6.vtc = 0x60,
554 .ipv6.tcflow = 0x00,
555 .ipv6.flow = 0x00,
556 .ipv6.len = 0,
557 .ipv6.nexthdr = IPPROTO_UDP,
558 .ipv6.hop_limit = 0xff,
559 .ipv6.src = src_sam00,
560 .ipv6.dst = dst_dam00,
561 .nh.udp.src_port = htons(udp_src_port_4bit),
562 .nh.udp.dst_port = htons(udp_dst_port_4bit),
563 .nh.udp.len = 0x00,
564 .nh.udp.chksum = 0x00,
565 .hdr_diff = NET_IPV6UDPH_LEN - IPHC_SIZE - NHC_SIZE -
566 (TF_11 + NHC_1 + CID_0 + SAC0_SAM00 + M0_DAC0_DAM00) -
567 UDP_CHKSUM_0 - UDP_P11,
568 .nh_udp = true,
569 .nh_icmp = false,
570 .small = true,
571 .iphc = true
572 };
573
574 static struct net_6lo_data test_data_2 = {
575 .ipv6.vtc = 0x60,
576 .ipv6.tcflow = 0x20,
577 .ipv6.flow = 0x3412,
578 .ipv6.len = 0,
579 .ipv6.nexthdr = IPPROTO_UDP,
580 .ipv6.hop_limit = 0xff,
581 .ipv6.src = src_sam01,
582 .ipv6.dst = dst_dam01,
583 .nh.udp.src_port = htons(udp_src_port_8bit_y),
584 .nh.udp.dst_port = htons(udp_dst_port_8bit),
585 .nh.udp.len = 0x00,
586 .nh.udp.chksum = 0x00,
587 .hdr_diff = NET_IPV6UDPH_LEN - IPHC_SIZE - NHC_SIZE -
588 (TF_01 + NHC_1 + CID_0 + SAC0_SAM01 + M0_DAC0_DAM01) -
589 UDP_CHKSUM_0 - UDP_P10,
590 .nh_udp = true,
591 .nh_icmp = false,
592 .small = false,
593 .iphc = true
594 };
595
596 static struct net_6lo_data test_data_3 = {
597 .ipv6.vtc = 0x60,
598 .ipv6.tcflow = 0x21,
599 .ipv6.flow = 0x3412,
600 .ipv6.len = 0,
601 .ipv6.nexthdr = IPPROTO_UDP,
602 .ipv6.hop_limit = 0xff,
603 .ipv6.src = src_sam10,
604 .ipv6.dst = dst_dam10,
605 .nh.udp.src_port = htons(udp_src_port_8bit),
606 .nh.udp.dst_port = htons(udp_dst_port_8bit_y),
607 .nh.udp.len = 0x00,
608 .nh.udp.chksum = 0x00,
609 .hdr_diff = NET_IPV6UDPH_LEN - IPHC_SIZE - NHC_SIZE -
610 (TF_01 + NHC_1 + CID_0 + SAC0_SAM10 + M0_DAC0_DAM10) -
611 UDP_CHKSUM_0 - UDP_P01,
612 .nh_udp = true,
613 .nh_icmp = false,
614 .small = true,
615 .iphc = true
616 };
617
618 static struct net_6lo_data test_data_4 = {
619 .ipv6.vtc = 0x61,
620 .ipv6.tcflow = 0x20,
621 .ipv6.flow = 0x00,
622 .ipv6.len = 0,
623 .ipv6.nexthdr = IPPROTO_UDP,
624 .ipv6.hop_limit = 0xff,
625 .ipv6.src = src_sam00,
626 .ipv6.dst = dst_m1_dam00,
627 .nh.udp.src_port = htons(udp_src_port_16bit),
628 .nh.udp.dst_port = htons(udp_dst_port_16bit),
629 .nh.udp.len = 0x00,
630 .nh.udp.chksum = 0x00,
631 .hdr_diff = NET_IPV6UDPH_LEN - IPHC_SIZE - NHC_SIZE -
632 (TF_10 + NHC_1 + CID_0 + SAC0_SAM00 + M1_DAC0_DAM00) -
633 UDP_CHKSUM_0 - UDP_P00,
634 .nh_udp = true,
635 .nh_icmp = false,
636 .small = false,
637 .iphc = true
638 };
639
640 static struct net_6lo_data test_data_5 = {
641 .ipv6.vtc = 0x61,
642 .ipv6.tcflow = 0x23,
643 .ipv6.flow = 0x4567,
644 .ipv6.len = 0,
645 .ipv6.nexthdr = IPPROTO_UDP,
646 .ipv6.hop_limit = 0xff,
647 .ipv6.src = src_sam01,
648 .ipv6.dst = dst_m1_dam01,
649 .nh.udp.src_port = htons(udp_src_port_16bit),
650 .nh.udp.dst_port = htons(udp_dst_port_16bit),
651 .nh.udp.len = 0x00,
652 .nh.udp.chksum = 0x00,
653 .hdr_diff = NET_IPV6UDPH_LEN - IPHC_SIZE - NHC_SIZE -
654 (TF_00 + NHC_1 + CID_0 + SAC0_SAM01 + M1_DAC0_DAM01) -
655 UDP_CHKSUM_0 - UDP_P00,
656 .nh_udp = true,
657 .nh_icmp = false,
658 .small = true,
659 .iphc = true
660 };
661
662 static struct net_6lo_data test_data_6 = {
663 .ipv6.vtc = 0x60,
664 .ipv6.tcflow = 0x0,
665 .ipv6.flow = 0x0,
666 .ipv6.len = 0,
667 .ipv6.nexthdr = IPPROTO_UDP,
668 .ipv6.hop_limit = 0xff,
669 .ipv6.src = src_sam10,
670 .ipv6.dst = dst_m1_dam10,
671 .nh.udp.src_port = htons(udp_src_port_8bit),
672 .nh.udp.dst_port = htons(udp_dst_port_8bit),
673 .nh.udp.len = 0x00,
674 .nh.udp.chksum = 0x00,
675 .hdr_diff = NET_IPV6UDPH_LEN - IPHC_SIZE - NHC_SIZE -
676 (TF_11 + NHC_1 + CID_0 + SAC0_SAM10 + M1_DAC0_DAM10) -
677 UDP_CHKSUM_0 - UDP_P00,
678 .nh_udp = true,
679 .nh_icmp = false,
680 .small = true,
681 .iphc = true
682 };
683
684 static struct net_6lo_data test_data_7 = {
685 .ipv6.vtc = 0x60,
686 .ipv6.tcflow = 0x0,
687 .ipv6.flow = 0x0,
688 .ipv6.len = 0,
689 .ipv6.nexthdr = 0,
690 .ipv6.hop_limit = 0xff,
691 .ipv6.src = src_sam10,
692 .ipv6.dst = dst_m1_dam10,
693 .hdr_diff = NET_IPV6H_LEN - IPHC_SIZE -
694 (TF_11 + NHC_0 + CID_0 + SAC0_SAM10 + M1_DAC0_DAM10),
695 .nh_udp = false,
696 .nh_icmp = false,
697 .small = true,
698 .iphc = true
699 };
700
701 static struct net_6lo_data test_data_8 = {
702 .ipv6.vtc = 0x60,
703 .ipv6.tcflow = 0x0,
704 .ipv6.flow = 0x0,
705 .ipv6.len = 0,
706 .ipv6.nexthdr = IPPROTO_ICMPV6,
707 .ipv6.hop_limit = 0xff,
708 .ipv6.src = src_sam10,
709 .ipv6.dst = dst_m1_dam10,
710 .nh.icmp.type = NET_ICMPV6_ECHO_REQUEST,
711 .nh.icmp.code = 0,
712 .nh.icmp.chksum = 0,
713 .hdr_diff = NET_IPV6H_LEN - IPHC_SIZE -
714 (TF_11 + NHC_0 + CID_0 + SAC0_SAM10 + M1_DAC0_DAM10),
715 .nh_udp = false,
716 .nh_icmp = true,
717 .small = true,
718 .iphc = true
719 };
720
721 static struct net_6lo_data test_data_9 = {
722 .ipv6.vtc = 0x61,
723 .ipv6.tcflow = 0x20,
724 .ipv6.flow = 0x00,
725 .ipv6.len = 0,
726 .ipv6.nexthdr = IPPROTO_UDP,
727 .ipv6.hop_limit = 0xff,
728 .ipv6.src = src_sac1_sam00,
729 .ipv6.dst = dst_m1_dam00,
730 .nh.udp.src_port = htons(udp_src_port_16bit),
731 .nh.udp.dst_port = htons(udp_dst_port_16bit),
732 .nh.udp.len = 0x00,
733 .nh.udp.chksum = 0x00,
734 .hdr_diff = IPV6_DISPATCH_DIFF,
735 .nh_udp = true,
736 .nh_icmp = false,
737 .small = true,
738 .iphc = false
739 };
740
741 static struct net_6lo_data test_data_10 = {
742 .ipv6.vtc = 0x61,
743 .ipv6.tcflow = 0x20,
744 .ipv6.flow = 0x00,
745 .ipv6.len = 0,
746 .ipv6.nexthdr = IPPROTO_UDP,
747 .ipv6.hop_limit = 0xff,
748 .ipv6.src = src_sac1_sam00,
749 .ipv6.dst = dst_m1_dam00,
750 .nh.udp.src_port = htons(udp_src_port_16bit),
751 .nh.udp.dst_port = htons(udp_dst_port_16bit),
752 .nh.udp.len = 0x00,
753 .nh.udp.chksum = 0x00,
754 .hdr_diff = IPV6_DISPATCH_DIFF,
755 .nh_udp = false,
756 .nh_icmp = false,
757 .small = false,
758 .iphc = false
759 };
760
761 static struct net_6lo_data test_data_11 = {
762 .ipv6.vtc = 0x61,
763 .ipv6.tcflow = 0x20,
764 .ipv6.flow = 0x00,
765 .ipv6.len = 0,
766 .ipv6.nexthdr = 0,
767 .ipv6.hop_limit = 0xff,
768 .ipv6.src = src_sac1_sam00,
769 .ipv6.dst = dst_m1_dam00,
770 .hdr_diff = IPV6_DISPATCH_DIFF,
771 .nh_udp = false,
772 .nh_icmp = false,
773 .small = false,
774 .iphc = false
775 };
776
777 static struct net_6lo_data test_data_12 = {
778 .ipv6.vtc = 0x61,
779 .ipv6.tcflow = 0x20,
780 .ipv6.flow = 0x00,
781 .ipv6.len = 0,
782 .ipv6.nexthdr = IPPROTO_ICMPV6,
783 .ipv6.hop_limit = 0xff,
784 .ipv6.src = src_sac1_sam00,
785 .ipv6.dst = dst_m1_dam00,
786 .nh.icmp.type = NET_ICMPV6_ECHO_REQUEST,
787 .nh.icmp.code = 0,
788 .nh.icmp.chksum = 0,
789 .hdr_diff = IPV6_DISPATCH_DIFF,
790 .nh_udp = false,
791 .nh_icmp = true,
792 .small = false,
793 .iphc = false
794 };
795
796 static struct net_6lo_data test_data_13 = {
797 .ipv6.vtc = 0x60,
798 .ipv6.tcflow = 0x21,
799 .ipv6.flow = 0x3412,
800 .ipv6.len = 0,
801 .ipv6.nexthdr = IPPROTO_UDP,
802 .ipv6.hop_limit = 0xff,
803 .ipv6.src = src_sam11,
804 .ipv6.dst = dst_dam11,
805 .nh.udp.src_port = htons(udp_src_port_8bit),
806 .nh.udp.dst_port = htons(udp_dst_port_8bit_y),
807 .nh.udp.len = 0x00,
808 .nh.udp.chksum = 0x00,
809 .hdr_diff = NET_IPV6UDPH_LEN - IPHC_SIZE - NHC_SIZE -
810 (TF_01 + NHC_1 + CID_0 + SAC0_SAM11 + M0_DAC0_DAM11) -
811 UDP_CHKSUM_0 - UDP_P01,
812 .nh_udp = true,
813 .nh_icmp = false,
814 .small = true,
815 .iphc = true
816 };
817
818 static struct net_6lo_data test_data_14 = {
819 .ipv6.vtc = 0x60,
820 .ipv6.tcflow = 0x00,
821 .ipv6.flow = 0x00,
822 .ipv6.len = 0,
823 .ipv6.nexthdr = NET_IPV6_NEXTHDR_NONE,
824 .ipv6.hop_limit = 0xff,
825 .ipv6.src = src_sac1_sam00,
826 .ipv6.dst = dst_m1_dam11,
827 .hdr_diff = NET_IPV6H_LEN - IPHC_SIZE -
828 (TF_11 + NHC_0 + CID_0 + SAC1_SAM00 + M1_DAC0_DAM11),
829 .nh_udp = false,
830 .nh_icmp = false,
831 .small = true,
832 .iphc = true
833 };
834
835 #if defined(CONFIG_NET_6LO_CONTEXT)
836 static struct net_6lo_data test_data_15 = {
837 .ipv6.vtc = 0x60,
838 .ipv6.tcflow = 0x20,
839 .ipv6.flow = 0x3412,
840 .ipv6.len = 0,
841 .ipv6.nexthdr = IPPROTO_UDP,
842 .ipv6.hop_limit = 0xff,
843 .ipv6.src = src_sac1_sam01,
844 .ipv6.dst = dst_dac1_dam01,
845 .nh.udp.src_port = htons(udp_src_port_8bit_y),
846 .nh.udp.dst_port = htons(udp_dst_port_8bit),
847 .nh.udp.len = 0x00,
848 .nh.udp.chksum = 0x00,
849 .hdr_diff = NET_IPV6UDPH_LEN - IPHC_SIZE - NHC_SIZE -
850 (TF_01 + NHC_1 + CID_1 + SAC1_SAM01 + M0_DAC1_DAM01) -
851 UDP_CHKSUM_0 - UDP_P10,
852 .nh_udp = true,
853 .nh_icmp = false,
854 .small = false,
855 .iphc = true
856 };
857
858 static struct net_6lo_data test_data_16 = {
859 .ipv6.vtc = 0x60,
860 .ipv6.tcflow = 0x21,
861 .ipv6.flow = 0x3412,
862 .ipv6.len = 0,
863 .ipv6.nexthdr = IPPROTO_UDP,
864 .ipv6.hop_limit = 0xff,
865 .ipv6.src = src_sac1_sam10,
866 .ipv6.dst = dst_dac1_dam10,
867 .nh.udp.src_port = htons(udp_src_port_8bit),
868 .nh.udp.dst_port = htons(udp_dst_port_8bit_y),
869 .nh.udp.len = 0x00,
870 .nh.udp.chksum = 0x00,
871 .hdr_diff = NET_IPV6UDPH_LEN - IPHC_SIZE - NHC_SIZE -
872 (TF_01 + NHC_1 + CID_1 + SAC1_SAM10 + M0_DAC1_DAM10) -
873 UDP_CHKSUM_0 - UDP_P01,
874 .nh_udp = true,
875 .nh_icmp = false,
876 .small = true,
877 .iphc = true
878 };
879
880 static struct net_6lo_data test_data_17 = {
881 .ipv6.vtc = 0x60,
882 .ipv6.tcflow = 0x21,
883 .ipv6.flow = 0x3412,
884 .ipv6.len = 0,
885 .ipv6.nexthdr = IPPROTO_UDP,
886 .ipv6.hop_limit = 0xff,
887 .ipv6.src = src_sac1_sam11,
888 .ipv6.dst = dst_dac1_dam11,
889 .nh.udp.src_port = htons(udp_src_port_8bit),
890 .nh.udp.dst_port = htons(udp_dst_port_8bit_y),
891 .nh.udp.len = 0x00,
892 .nh.udp.chksum = 0x00,
893 .hdr_diff = NET_IPV6UDPH_LEN - IPHC_SIZE - NHC_SIZE -
894 (TF_01 + NHC_1 + CID_1 + SAC1_SAM11 + M0_DAC1_DAM11) -
895 UDP_CHKSUM_0 - UDP_P10,
896 .nh_udp = true,
897 .nh_icmp = false,
898 .small = true,
899 .iphc = true
900 };
901
902 static struct net_6lo_data test_data_18 = {
903 .ipv6.vtc = 0x60,
904 .ipv6.tcflow = 0x20,
905 .ipv6.flow = 0x3412,
906 .ipv6.len = 0,
907 .ipv6.nexthdr = IPPROTO_UDP,
908 .ipv6.hop_limit = 0xff,
909 .ipv6.src = src_sam01,
910 .ipv6.dst = dst_dac1_dam01,
911 .nh.udp.src_port = htons(udp_src_port_8bit_y),
912 .nh.udp.dst_port = htons(udp_dst_port_8bit),
913 .nh.udp.len = 0x00,
914 .nh.udp.chksum = 0x00,
915 .hdr_diff = NET_IPV6UDPH_LEN - IPHC_SIZE - NHC_SIZE -
916 (TF_01 + NHC_1 + CID_1 + SAC0_SAM01 + M0_DAC1_DAM01) -
917 UDP_CHKSUM_0 - UDP_P10,
918 .nh_udp = true,
919 .nh_icmp = false,
920 .small = false,
921 .iphc = true
922 };
923
924 static struct net_6lo_data test_data_19 = {
925 .ipv6.vtc = 0x60,
926 .ipv6.tcflow = 0x20,
927 .ipv6.flow = 0x3412,
928 .ipv6.len = 0,
929 .ipv6.nexthdr = IPPROTO_UDP,
930 .ipv6.hop_limit = 0xff,
931 .ipv6.src = src_sac1_sam01,
932 .ipv6.dst = dst_dam01,
933 .nh.udp.src_port = htons(udp_src_port_8bit_y),
934 .nh.udp.dst_port = htons(udp_dst_port_8bit),
935 .nh.udp.len = 0x00,
936 .nh.udp.chksum = 0x00,
937 .hdr_diff = NET_IPV6UDPH_LEN - IPHC_SIZE - NHC_SIZE -
938 (TF_01 + NHC_1 + CID_1 + SAC1_SAM01 + M0_DAC0_DAM01) -
939 UDP_CHKSUM_0 - UDP_P10,
940 .nh_udp = true,
941 .nh_icmp = false,
942 .small = false,
943 .iphc = true
944 };
945
946 static struct net_6lo_data test_data_20 = {
947 .ipv6.vtc = 0x61,
948 .ipv6.tcflow = 0x23,
949 .ipv6.flow = 0x4567,
950 .ipv6.len = 0,
951 .ipv6.nexthdr = IPPROTO_UDP,
952 .ipv6.hop_limit = 0xff,
953 .ipv6.src = src_sac1_sam01,
954 .ipv6.dst = dst_m1_dam00,
955 .nh.udp.src_port = htons(udp_src_port_16bit),
956 .nh.udp.dst_port = htons(udp_dst_port_16bit),
957 .nh.udp.len = 0x00,
958 .nh.udp.chksum = 0x00,
959 .hdr_diff = NET_IPV6UDPH_LEN - IPHC_SIZE - NHC_SIZE -
960 (TF_00 + NHC_1 + CID_1 + SAC1_SAM01 + M1_DAC0_DAM00) -
961 UDP_CHKSUM_0 - UDP_P00,
962 .nh_udp = true,
963 .nh_icmp = false,
964 .small = true,
965 .iphc = true
966 };
967 static struct net_6lo_data test_data_21 = {
968 .ipv6.vtc = 0x61,
969 .ipv6.tcflow = 0x23,
970 .ipv6.flow = 0x4567,
971 .ipv6.len = 0,
972 .ipv6.nexthdr = IPPROTO_UDP,
973 .ipv6.hop_limit = 0xff,
974 .ipv6.src = src_sac1_sam01,
975 .ipv6.dst = dst_m1_dam01,
976 .nh.udp.src_port = htons(udp_src_port_16bit),
977 .nh.udp.dst_port = htons(udp_dst_port_16bit),
978 .nh.udp.len = 0x00,
979 .nh.udp.chksum = 0x00,
980 .hdr_diff = NET_IPV6UDPH_LEN - IPHC_SIZE - NHC_SIZE -
981 (TF_00 + NHC_1 + CID_1 + SAC1_SAM01 + M1_DAC0_DAM01) -
982 UDP_CHKSUM_0 - UDP_P00,
983 .nh_udp = true,
984 .nh_icmp = false,
985 .small = true,
986 .iphc = true
987 };
988
989 static struct net_6lo_data test_data_22 = {
990 .ipv6.vtc = 0x60,
991 .ipv6.tcflow = 0x0,
992 .ipv6.flow = 0x0,
993 .ipv6.len = 0,
994 .ipv6.nexthdr = IPPROTO_UDP,
995 .ipv6.hop_limit = 0xff,
996 .ipv6.src = src_sac1_sam10,
997 .ipv6.dst = dst_m1_dam10,
998 .nh.udp.src_port = htons(udp_src_port_8bit),
999 .nh.udp.dst_port = htons(udp_dst_port_8bit),
1000 .nh.udp.len = 0x00,
1001 .nh.udp.chksum = 0x00,
1002 .hdr_diff = NET_IPV6UDPH_LEN - IPHC_SIZE - NHC_SIZE -
1003 (TF_11 + NHC_1 + CID_1 + SAC1_SAM10 + M1_DAC0_DAM10) -
1004 UDP_CHKSUM_0 - UDP_P00,
1005 .nh_udp = true,
1006 .nh_icmp = false,
1007 .small = true,
1008 .iphc = true
1009 };
1010
1011 static struct net_6lo_data test_data_23 = {
1012 .ipv6.vtc = 0x60,
1013 .ipv6.tcflow = 0x0,
1014 .ipv6.flow = 0x0,
1015 .ipv6.len = 0,
1016 .ipv6.nexthdr = 0,
1017 .ipv6.hop_limit = 0xff,
1018 .ipv6.src = src_sac1_sam11,
1019 .ipv6.dst = dst_m1_dam10,
1020 .hdr_diff = NET_IPV6H_LEN - IPHC_SIZE -
1021 (TF_11 + NHC_0 + CID_1 + SAC0_SAM11 + M1_DAC0_DAM10),
1022 .nh_udp = false,
1023 .nh_icmp = false,
1024 .small = true,
1025 .iphc = true
1026 };
1027
1028 static struct net_6lo_data test_data_24 = {
1029 .ipv6.vtc = 0x60,
1030 .ipv6.tcflow = 0x20,
1031 .ipv6.flow = 0x3412,
1032 .ipv6.len = 0,
1033 .ipv6.nexthdr = IPPROTO_UDP,
1034 .ipv6.hop_limit = 0xff,
1035 .ipv6.src = src_sam00,
1036 .ipv6.dst = dst_dac1_dam01,
1037 .nh.udp.src_port = htons(udp_src_port_8bit_y),
1038 .nh.udp.dst_port = htons(udp_dst_port_8bit),
1039 .nh.udp.len = 0x00,
1040 .nh.udp.chksum = 0x00,
1041 .hdr_diff = NET_IPV6UDPH_LEN - IPHC_SIZE - NHC_SIZE -
1042 (TF_01 + NHC_1 + CID_1 + SAC0_SAM00 + M0_DAC1_DAM01) -
1043 UDP_CHKSUM_0 - UDP_P10,
1044 .nh_udp = true,
1045 .nh_icmp = false,
1046 .small = false,
1047 .iphc = true
1048 };
1049
1050 static struct net_6lo_data test_data_25 = {
1051 .ipv6.vtc = 0x60,
1052 .ipv6.tcflow = 0x00,
1053 .ipv6.flow = 0x00,
1054 .ipv6.len = 0,
1055 .ipv6.nexthdr = IPPROTO_UDP,
1056 .ipv6.hop_limit = 0xff,
1057 .ipv6.src = src_sac1_sam00,
1058 .ipv6.dst = dst_m1_dam00,
1059 .nh.udp.src_port = htons(udp_src_port_8bit_y),
1060 .nh.udp.dst_port = htons(udp_dst_port_8bit),
1061 .nh.udp.len = 0x00,
1062 .nh.udp.chksum = 0x00,
1063 .hdr_diff = NET_IPV6UDPH_LEN - IPHC_SIZE - NHC_SIZE -
1064 (TF_11 + NHC_1 + CID_0 + SAC1_SAM00 + M1_DAC0_DAM00) -
1065 UDP_CHKSUM_0 - UDP_P10,
1066 .nh_udp = true,
1067 .nh_icmp = false,
1068 .small = true,
1069 .iphc = true
1070 };
1071
1072 #endif
1073
test_6lo(struct net_6lo_data * data)1074 static void test_6lo(struct net_6lo_data *data)
1075 {
1076 struct net_pkt *pkt;
1077 int diff;
1078
1079 pkt = create_pkt(data);
1080 zassert_not_null(pkt, "failed to create buffer");
1081 #if DEBUG > 0
1082 TC_PRINT("length before compression %zu\n",
1083 net_pkt_get_len(pkt));
1084 net_pkt_hexdump(pkt, "before-compression");
1085 #endif
1086
1087 net_pkt_cursor_init(pkt);
1088
1089 zassert_true((net_6lo_compress(pkt, data->iphc) >= 0),
1090 "compression failed");
1091
1092 #if DEBUG > 0
1093 TC_PRINT("length after compression %zu\n",
1094 net_pkt_get_len(pkt));
1095 net_pkt_hexdump(pkt, "after-compression");
1096 #endif
1097
1098 diff = net_6lo_uncompress_hdr_diff(pkt);
1099 zassert_true(diff == data->hdr_diff, "unexpected HDR diff");
1100
1101 zassert_true(net_6lo_uncompress(pkt),
1102 "uncompression failed");
1103 #if DEBUG > 0
1104 TC_PRINT("length after uncompression %zu\n",
1105 net_pkt_get_len(pkt));
1106 net_pkt_hexdump(pkt, "after-uncompression");
1107 #endif
1108
1109 zassert_true(compare_pkt(pkt, data));
1110
1111 net_pkt_unref(pkt);
1112 }
1113
1114 /* tests names are based on traffic class, flow label, source address mode
1115 * (sam), destination address mode (dam), based on udp source and destination
1116 * ports compressible type.
1117 */
1118 static const struct {
1119 const char *name;
1120 struct net_6lo_data *data;
1121 } tests[] = {
1122 { "test_6lo_sam00_dam00", &test_data_1},
1123 { "test_6lo_sam01_dam01", &test_data_2},
1124 { "test_6lo_sam10_dam10", &test_data_3},
1125 { "test_6lo_sam00_m1_dam00", &test_data_4},
1126 { "test_6lo_sam01_m1_dam01", &test_data_5},
1127 { "test_6lo_sam10_m1_dam10", &test_data_6},
1128 { "test_6lo_sam10_m1_dam10_no_udp", &test_data_7},
1129 { "test_6lo_sam10_m1_dam10_iphc", &test_data_8},
1130 { "test_6lo_ipv6_dispatch_small", &test_data_9},
1131 { "test_6lo_ipv6_dispatch_big", &test_data_10},
1132 { "test_6lo_ipv6_dispatch_big_no_udp", &test_data_11},
1133 { "test_6lo_ipv6_dispatch_big_iphc", &test_data_12},
1134 { "test_6lo_sam11_dam11", &test_data_13},
1135 { "test_6lo_sac1_sam00_m1_dam11", &test_data_14},
1136 #if defined(CONFIG_NET_6LO_CONTEXT)
1137 { "test_6lo_sac1_sam01_dac1_dam01", &test_data_15},
1138 { "test_6lo_sac1_sam10_dac1_dam10", &test_data_16},
1139 { "test_6lo_sac1_sam11_dac1_dam11", &test_data_17},
1140 { "test_6lo_sac0_sam01_dac1_dam01", &test_data_18},
1141 { "test_6lo_sac1_sam01_dac0_dam01", &test_data_19},
1142 { "test_6lo_sac1_sam01_m1_dam00", &test_data_20},
1143 { "test_6lo_sac1_sam01_m1_dam01", &test_data_21},
1144 { "test_6lo_sac1_sam10_m1_dam10", &test_data_22},
1145 { "test_6lo_sac1_sam11_m1_dam10", &test_data_23},
1146 { "test_6lo_sac0_sam00_dac1_dam01", &test_data_24},
1147 { "test_6lo_sac1_sam00_m1_dam00", &test_data_25},
1148 #endif
1149 };
1150
ZTEST(t_6lo,test_loop)1151 ZTEST(t_6lo, test_loop)
1152 {
1153 int count;
1154
1155 if (IS_ENABLED(CONFIG_NET_TC_THREAD_COOPERATIVE)) {
1156 k_thread_priority_set(k_current_get(),
1157 K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1));
1158 } else {
1159 k_thread_priority_set(k_current_get(), K_PRIO_PREEMPT(9));
1160 }
1161
1162 #if defined(CONFIG_NET_6LO_CONTEXT)
1163 net_6lo_set_context(net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY)),
1164 &ctx1);
1165 net_6lo_set_context(net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY)),
1166 &ctx2);
1167 #endif
1168
1169 for (count = 0; count < ARRAY_SIZE(tests); count++) {
1170 TC_PRINT("Starting %s\n", tests[count].name);
1171
1172 test_6lo(tests[count].data);
1173 }
1174 net_pkt_print();
1175 }
1176
1177 /*test case main entry*/
1178 ZTEST_SUITE(t_6lo, NULL, NULL, NULL, NULL, NULL);
1179