1 /** @file 2 @brief 6lowpan private header 3 4 This is not to be included by the application. 5 */ 6 7 /* 8 * Copyright (c) 2016 Intel Corporation 9 * 10 * SPDX-License-Identifier: Apache-2.0 11 */ 12 13 #include <stdio.h> 14 15 /* 6lopan dispatches */ 16 #define NET_6LO_DISPATCH_IPV6 0x41 /* 01000001 */ 17 #define NET_6LO_DISPATCH_BROADCAST 0x50 /* 01010000 */ 18 #define NET_6LO_DISPATCH_IPHC 0x60 /* 01100000 */ 19 #define NET_6LO_DISPATCH_MESH 0x80 /* 10xxxxxx */ 20 #define NET_6LO_DISPATCH_FRAG1 0xC0 /* 11000xxx */ 21 #define NET_6LO_DISPATCH_FRAGN 0xE0 /* 11100xxx */ 22 23 #define NET_6LO_DISPATCH_IPHC_MASK 0xE0 24 /** 25 * TF (Traffic class and Flow label) 26 * 00: ECN + DSCP + 4-bit Pad + Flow Label (4 bytes) 27 * 01: ECN + 2-bit Pad + Flow Label (3 bytes), DSCP is elided. 28 * 10: ECN + DSCP (1 byte), Flow Label is elided. 29 * 11: Traffic Class and Flow Label are elided. 30 */ 31 #define NET_6LO_IPHC_TF_POS 11 32 #define NET_6LO_IPHC_TF_MASK (0x03 << NET_6LO_IPHC_TF_POS) 33 #define NET_6LO_IPHC_TF_00 (0x00 << NET_6LO_IPHC_TF_POS) 34 #define NET_6LO_IPHC_TF_01 (0x01 << NET_6LO_IPHC_TF_POS) 35 #define NET_6LO_IPHC_TF_10 (0x02 << NET_6LO_IPHC_TF_POS) 36 #define NET_6LO_IPHC_TF_11 (0x03 << NET_6LO_IPHC_TF_POS) 37 38 /* NH (next header) */ 39 #define NET_6LO_IPHC_NH_POS 10 40 #define NET_6LO_IPHC_NH_MASK (0x01 << NET_6LO_IPHC_NH_POS) 41 #define NET_6LO_IPHC_NH_0 (0x00 << NET_6LO_IPHC_NH_POS) 42 #define NET_6LO_IPHC_NH_1 (0x01 << NET_6LO_IPHC_NH_POS) 43 44 /* HLIM (Hop Limit) */ 45 #define NET_6LO_IPHC_HLIM_POS 8 46 #define NET_6LO_IPHC_HLIM_MASK (0x03 << NET_6LO_IPHC_HLIM_POS) 47 #define NET_6LO_IPHC_HLIM (0x00 << NET_6LO_IPHC_HLIM_POS) /* 00 */ 48 #define NET_6LO_IPHC_HLIM1 (0x01 << NET_6LO_IPHC_HLIM_POS) /* 01 */ 49 #define NET_6LO_IPHC_HLIM64 (0x02 << NET_6LO_IPHC_HLIM_POS) /* 10 */ 50 #define NET_6LO_IPHC_HLIM255 (0x03 << NET_6LO_IPHC_HLIM_POS) /* 11 */ 51 52 /* CID (Context Identifier Extension) */ 53 #define NET_6LO_IPHC_CID_POS 7 54 #define NET_6LO_IPHC_CID_MASK (0x01 << NET_6LO_IPHC_CID_POS) 55 #define NET_6LO_IPHC_CID_0 (0x00 << NET_6LO_IPHC_CID_POS) 56 #define NET_6LO_IPHC_CID_1 (0x01 << NET_6LO_IPHC_CID_POS) 57 58 /* SAC (Source Address Compression) */ 59 #define NET_6LO_IPHC_SAC_POS 6 60 #define NET_6LO_IPHC_SAC_MASK (0x01 << NET_6LO_IPHC_SAC_POS) 61 #define NET_6LO_IPHC_SAC_0 (0x00 << NET_6LO_IPHC_SAC_POS) 62 #define NET_6LO_IPHC_SAC_1 (0x01 << NET_6LO_IPHC_SAC_POS) 63 64 /* SAM (Source Address Mode) */ 65 #define NET_6LO_IPHC_SAM_POS 4 66 #define NET_6LO_IPHC_SAM_MASK (0x03 << NET_6LO_IPHC_SAM_POS) 67 #define NET_6LO_IPHC_SAM_00 (0x00 << NET_6LO_IPHC_SAM_POS) 68 #define NET_6LO_IPHC_SAM_01 (0x01 << NET_6LO_IPHC_SAM_POS) 69 #define NET_6LO_IPHC_SAM_10 (0x02 << NET_6LO_IPHC_SAM_POS) 70 #define NET_6LO_IPHC_SAM_11 (0x03 << NET_6LO_IPHC_SAM_POS) 71 72 #define NET_6LO_IPHC_SA_MASK (NET_6LO_IPHC_SAC_MASK | \ 73 NET_6LO_IPHC_SAM_MASK) 74 75 /* M (Multicast compression) */ 76 #define NET_6LO_IPHC_M_POS 3 77 #define NET_6LO_IPHC_M_MASK (0x01 << NET_6LO_IPHC_M_POS) 78 #define NET_6LO_IPHC_M_0 (0x00 << NET_6LO_IPHC_M_POS) 79 #define NET_6LO_IPHC_M_1 (0x01 << NET_6LO_IPHC_M_POS) 80 81 /* DAC (Destination Address Compression) */ 82 #define NET_6LO_IPHC_DAC_POS 2 83 #define NET_6LO_IPHC_DAC_MASK (0x01 << NET_6LO_IPHC_DAC_POS) 84 #define NET_6LO_IPHC_DAC_0 (0x00 << NET_6LO_IPHC_DAC_POS) 85 #define NET_6LO_IPHC_DAC_1 (0x01 << NET_6LO_IPHC_DAC_POS) 86 87 /* DAM (Destination Address Mode) */ 88 #define NET_6LO_IPHC_DAM_POS 0 89 #define NET_6LO_IPHC_DAM_MASK (0x03 << NET_6LO_IPHC_DAM_POS) 90 #define NET_6LO_IPHC_DAM_00 (0x00 << NET_6LO_IPHC_DAM_POS) 91 #define NET_6LO_IPHC_DAM_01 (0x01 << NET_6LO_IPHC_DAM_POS) 92 #define NET_6LO_IPHC_DAM_10 (0x02 << NET_6LO_IPHC_DAM_POS) 93 #define NET_6LO_IPHC_DAM_11 (0x03 << NET_6LO_IPHC_DAM_POS) 94 95 #define NET_6LO_IPHC_DA_MASK (NET_6LO_IPHC_DAC_MASK | \ 96 NET_6LO_IPHC_DAM_MASK | \ 97 NET_6LO_IPHC_M_MASK) 98 99 /* Next Header UDP */ 100 #define NET_6LO_NHC_UDP_BARE 0xF0 101 102 #define NET_6LO_NHC_UDP_CHKSUM_0 0x00 103 #define NET_6LO_NHC_UDP_CHKSUM_1 0x08 104 105 #define NET_6LO_NHC_UDP_PORT_MASK 0x03 106 #define NET_6LO_NHC_UDP_PORT_00 0x00 107 #define NET_6LO_NHC_UDP_PORT_01 0x01 108 #define NET_6LO_NHC_UDP_PORT_10 0x02 109 #define NET_6LO_NHC_UDP_PORT_11 0x03 110 #define NET_6LO_NHC_UDP_CHECKSUM 0x04 111 #define NET_6LO_NHC_UDP_8_BIT_PORT 0xF0 112 #define NET_6LO_NHC_UDP_4_BIT_PORT 0xF0B 113 114 #define NET_6LO_FRAG1_HDR_LEN 4 115 #define NET_6LO_FRAGN_HDR_LEN 5 116 117 #define NET_6LO_FRAG_DATAGRAM_SIZE_LEN 2 118 #define NET_6LO_FRAG_DATAGRAM_OFFSET_LEN 2 119 120 /* Timeout when getting net_buf in RX path. In RX, we must not wait forever as 121 * that can cause the stack to deadlock. This can happen if RX side is flooding 122 * incoming data and we cannot get process the packet in 6lo side. 123 */ 124 #define NET_6LO_RX_PKT_TIMEOUT K_MSEC(100) /* in ms */ 125