aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Aring <alex.aring@gmail.com>2015-10-20 02:31:22 -0400
committerMarcel Holtmann <marcel@holtmann.org>2015-10-20 18:49:25 -0400
commit6350047eb8dbd3dcf0ff29a637ece96db8f59d8d (patch)
treef6cd61e1ddf0b7602e1d73c0e929dbf5958a7cbd
parent607b0bd3f2b9ac118f2c67dbd18c55f1f5aefeb1 (diff)
6lowpan: move IPHC functionality defines
This patch removes the IPHC related defines for doing bit manipulation from global 6lowpan header to the iphc file which should the only one implementation which use these defines. Also move next header compression defines to their nhc implementation. Signed-off-by: Alexander Aring <alex.aring@gmail.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
-rw-r--r--include/net/6lowpan.h123
-rw-r--r--net/6lowpan/iphc.c88
-rw-r--r--net/6lowpan/nhc_udp.c22
-rw-r--r--net/ieee802154/6lowpan/tx.c3
4 files changed, 112 insertions, 124 deletions
diff --git a/include/net/6lowpan.h b/include/net/6lowpan.h
index 4afdbb3ab6d8..f127a92d1b94 100644
--- a/include/net/6lowpan.h
+++ b/include/net/6lowpan.h
@@ -56,11 +56,6 @@
56#include <net/ipv6.h> 56#include <net/ipv6.h>
57#include <net/net_namespace.h> 57#include <net/net_namespace.h>
58 58
59#define UIP_802154_SHORTADDR_LEN 2 /* compressed ipv6 address length */
60#define UIP_IPH_LEN 40 /* ipv6 fixed header size */
61#define UIP_PROTO_UDP 17 /* ipv6 next header value for UDP */
62#define UIP_FRAGH_LEN 8 /* ipv6 fragment header size */
63
64#define EUI64_ADDR_LEN 8 59#define EUI64_ADDR_LEN 8
65 60
66#define LOWPAN_NHC_MAX_ID_LEN 1 61#define LOWPAN_NHC_MAX_ID_LEN 1
@@ -79,61 +74,6 @@
79 LOWPAN_IPHC_MAX_HEADER_LEN + \ 74 LOWPAN_IPHC_MAX_HEADER_LEN + \
80 LOWPAN_NHC_MAX_HDR_LEN) 75 LOWPAN_NHC_MAX_HDR_LEN)
81 76
82/*
83 * ipv6 address based on mac
84 * second bit-flip (Universe/Local) is done according RFC2464
85 */
86#define is_addr_mac_addr_based(a, m) \
87 ((((a)->s6_addr[8]) == (((m)[0]) ^ 0x02)) && \
88 (((a)->s6_addr[9]) == (m)[1]) && \
89 (((a)->s6_addr[10]) == (m)[2]) && \
90 (((a)->s6_addr[11]) == (m)[3]) && \
91 (((a)->s6_addr[12]) == (m)[4]) && \
92 (((a)->s6_addr[13]) == (m)[5]) && \
93 (((a)->s6_addr[14]) == (m)[6]) && \
94 (((a)->s6_addr[15]) == (m)[7]))
95
96/*
97 * check whether we can compress the IID to 16 bits,
98 * it's possible for unicast adresses with first 49 bits are zero only.
99 */
100#define lowpan_is_iid_16_bit_compressable(a) \
101 ((((a)->s6_addr16[4]) == 0) && \
102 (((a)->s6_addr[10]) == 0) && \
103 (((a)->s6_addr[11]) == 0xff) && \
104 (((a)->s6_addr[12]) == 0xfe) && \
105 (((a)->s6_addr[13]) == 0))
106
107/* check whether the 112-bit gid of the multicast address is mappable to: */
108
109/* 48 bits, FFXX::00XX:XXXX:XXXX */
110#define lowpan_is_mcast_addr_compressable48(a) \
111 ((((a)->s6_addr16[1]) == 0) && \
112 (((a)->s6_addr16[2]) == 0) && \
113 (((a)->s6_addr16[3]) == 0) && \
114 (((a)->s6_addr16[4]) == 0) && \
115 (((a)->s6_addr[10]) == 0))
116
117/* 32 bits, FFXX::00XX:XXXX */
118#define lowpan_is_mcast_addr_compressable32(a) \
119 ((((a)->s6_addr16[1]) == 0) && \
120 (((a)->s6_addr16[2]) == 0) && \
121 (((a)->s6_addr16[3]) == 0) && \
122 (((a)->s6_addr16[4]) == 0) && \
123 (((a)->s6_addr16[5]) == 0) && \
124 (((a)->s6_addr[12]) == 0))
125
126/* 8 bits, FF02::00XX */
127#define lowpan_is_mcast_addr_compressable8(a) \
128 ((((a)->s6_addr[1]) == 2) && \
129 (((a)->s6_addr16[1]) == 0) && \
130 (((a)->s6_addr16[2]) == 0) && \
131 (((a)->s6_addr16[3]) == 0) && \
132 (((a)->s6_addr16[4]) == 0) && \
133 (((a)->s6_addr16[5]) == 0) && \
134 (((a)->s6_addr16[6]) == 0) && \
135 (((a)->s6_addr[14]) == 0))
136
137#define lowpan_is_addr_broadcast(a) \ 77#define lowpan_is_addr_broadcast(a) \
138 ((((a)[0]) == 0xFF) && \ 78 ((((a)[0]) == 0xFF) && \
139 (((a)[1]) == 0xFF) && \ 79 (((a)[1]) == 0xFF) && \
@@ -158,69 +98,6 @@ static inline bool lowpan_is_iphc(u8 dispatch)
158 return (dispatch & LOWPAN_DISPATCH_IPHC_MASK) == LOWPAN_DISPATCH_IPHC; 98 return (dispatch & LOWPAN_DISPATCH_IPHC_MASK) == LOWPAN_DISPATCH_IPHC;
159} 99}
160 100
161#define LOWPAN_FRAG_TIMEOUT (HZ * 60) /* time-out 60 sec */
162
163#define LOWPAN_FRAG1_HEAD_SIZE 0x4
164#define LOWPAN_FRAGN_HEAD_SIZE 0x5
165
166/*
167 * Values of fields within the IPHC encoding first byte
168 * (C stands for compressed and I for inline)
169 */
170#define LOWPAN_IPHC_TF 0x18
171
172#define LOWPAN_IPHC_FL_C 0x10
173#define LOWPAN_IPHC_TC_C 0x08
174#define LOWPAN_IPHC_NH_C 0x04
175#define LOWPAN_IPHC_TTL_1 0x01
176#define LOWPAN_IPHC_TTL_64 0x02
177#define LOWPAN_IPHC_TTL_255 0x03
178#define LOWPAN_IPHC_TTL_I 0x00
179
180
181/* Values of fields within the IPHC encoding second byte */
182#define LOWPAN_IPHC_CID 0x80
183
184#define LOWPAN_IPHC_ADDR_00 0x00
185#define LOWPAN_IPHC_ADDR_01 0x01
186#define LOWPAN_IPHC_ADDR_02 0x02
187#define LOWPAN_IPHC_ADDR_03 0x03
188
189#define LOWPAN_IPHC_SAC 0x40
190#define LOWPAN_IPHC_SAM 0x30
191
192#define LOWPAN_IPHC_SAM_BIT 4
193
194#define LOWPAN_IPHC_M 0x08
195#define LOWPAN_IPHC_DAC 0x04
196#define LOWPAN_IPHC_DAM_00 0x00
197#define LOWPAN_IPHC_DAM_01 0x01
198#define LOWPAN_IPHC_DAM_10 0x02
199#define LOWPAN_IPHC_DAM_11 0x03
200
201#define LOWPAN_IPHC_DAM_BIT 0
202/*
203 * LOWPAN_UDP encoding (works together with IPHC)
204 */
205#define LOWPAN_NHC_UDP_MASK 0xF8
206#define LOWPAN_NHC_UDP_ID 0xF0
207#define LOWPAN_NHC_UDP_CHECKSUMC 0x04
208#define LOWPAN_NHC_UDP_CHECKSUMI 0x00
209
210#define LOWPAN_NHC_UDP_4BIT_PORT 0xF0B0
211#define LOWPAN_NHC_UDP_4BIT_MASK 0xFFF0
212#define LOWPAN_NHC_UDP_8BIT_PORT 0xF000
213#define LOWPAN_NHC_UDP_8BIT_MASK 0xFF00
214
215/* values for port compression, _with checksum_ ie bit 5 set to 0 */
216#define LOWPAN_NHC_UDP_CS_P_00 0xF0 /* all inline */
217#define LOWPAN_NHC_UDP_CS_P_01 0xF1 /* source 16bit inline,
218 dest = 0xF0 + 8 bit inline */
219#define LOWPAN_NHC_UDP_CS_P_10 0xF2 /* source = 0xF0 + 8bit inline,
220 dest = 16 bit inline */
221#define LOWPAN_NHC_UDP_CS_P_11 0xF3 /* source & dest = 0xF0B + 4bit inline */
222#define LOWPAN_NHC_UDP_CS_C 0x04 /* checksum elided */
223
224#define LOWPAN_PRIV_SIZE(llpriv_size) \ 101#define LOWPAN_PRIV_SIZE(llpriv_size) \
225 (sizeof(struct lowpan_priv) + llpriv_size) 102 (sizeof(struct lowpan_priv) + llpriv_size)
226 103
diff --git a/net/6lowpan/iphc.c b/net/6lowpan/iphc.c
index afe36aab04ca..fcf583fe6791 100644
--- a/net/6lowpan/iphc.c
+++ b/net/6lowpan/iphc.c
@@ -58,6 +58,94 @@
58 58
59#include "nhc.h" 59#include "nhc.h"
60 60
61/* Values of fields within the IPHC encoding first byte
62 * (C stands for compressed and I for inline)
63 */
64#define LOWPAN_IPHC_TF 0x18
65
66#define LOWPAN_IPHC_FL_C 0x10
67#define LOWPAN_IPHC_TC_C 0x08
68#define LOWPAN_IPHC_NH_C 0x04
69#define LOWPAN_IPHC_TTL_1 0x01
70#define LOWPAN_IPHC_TTL_64 0x02
71#define LOWPAN_IPHC_TTL_255 0x03
72#define LOWPAN_IPHC_TTL_I 0x00
73
74/* Values of fields within the IPHC encoding second byte */
75#define LOWPAN_IPHC_CID 0x80
76
77#define LOWPAN_IPHC_ADDR_00 0x00
78#define LOWPAN_IPHC_ADDR_01 0x01
79#define LOWPAN_IPHC_ADDR_02 0x02
80#define LOWPAN_IPHC_ADDR_03 0x03
81
82#define LOWPAN_IPHC_SAC 0x40
83#define LOWPAN_IPHC_SAM 0x30
84
85#define LOWPAN_IPHC_SAM_BIT 4
86
87#define LOWPAN_IPHC_M 0x08
88#define LOWPAN_IPHC_DAC 0x04
89#define LOWPAN_IPHC_DAM_00 0x00
90#define LOWPAN_IPHC_DAM_01 0x01
91#define LOWPAN_IPHC_DAM_10 0x02
92#define LOWPAN_IPHC_DAM_11 0x03
93
94#define LOWPAN_IPHC_DAM_BIT 0
95
96/* ipv6 address based on mac
97 * second bit-flip (Universe/Local) is done according RFC2464
98 */
99#define is_addr_mac_addr_based(a, m) \
100 ((((a)->s6_addr[8]) == (((m)[0]) ^ 0x02)) && \
101 (((a)->s6_addr[9]) == (m)[1]) && \
102 (((a)->s6_addr[10]) == (m)[2]) && \
103 (((a)->s6_addr[11]) == (m)[3]) && \
104 (((a)->s6_addr[12]) == (m)[4]) && \
105 (((a)->s6_addr[13]) == (m)[5]) && \
106 (((a)->s6_addr[14]) == (m)[6]) && \
107 (((a)->s6_addr[15]) == (m)[7]))
108
109/* check whether we can compress the IID to 16 bits,
110 * it's possible for unicast addresses with first 49 bits are zero only.
111 */
112#define lowpan_is_iid_16_bit_compressable(a) \
113 ((((a)->s6_addr16[4]) == 0) && \
114 (((a)->s6_addr[10]) == 0) && \
115 (((a)->s6_addr[11]) == 0xff) && \
116 (((a)->s6_addr[12]) == 0xfe) && \
117 (((a)->s6_addr[13]) == 0))
118
119/* check whether the 112-bit gid of the multicast address is mappable to: */
120
121/* 48 bits, FFXX::00XX:XXXX:XXXX */
122#define lowpan_is_mcast_addr_compressable48(a) \
123 ((((a)->s6_addr16[1]) == 0) && \
124 (((a)->s6_addr16[2]) == 0) && \
125 (((a)->s6_addr16[3]) == 0) && \
126 (((a)->s6_addr16[4]) == 0) && \
127 (((a)->s6_addr[10]) == 0))
128
129/* 32 bits, FFXX::00XX:XXXX */
130#define lowpan_is_mcast_addr_compressable32(a) \
131 ((((a)->s6_addr16[1]) == 0) && \
132 (((a)->s6_addr16[2]) == 0) && \
133 (((a)->s6_addr16[3]) == 0) && \
134 (((a)->s6_addr16[4]) == 0) && \
135 (((a)->s6_addr16[5]) == 0) && \
136 (((a)->s6_addr[12]) == 0))
137
138/* 8 bits, FF02::00XX */
139#define lowpan_is_mcast_addr_compressable8(a) \
140 ((((a)->s6_addr[1]) == 2) && \
141 (((a)->s6_addr16[1]) == 0) && \
142 (((a)->s6_addr16[2]) == 0) && \
143 (((a)->s6_addr16[3]) == 0) && \
144 (((a)->s6_addr16[4]) == 0) && \
145 (((a)->s6_addr16[5]) == 0) && \
146 (((a)->s6_addr16[6]) == 0) && \
147 (((a)->s6_addr[14]) == 0))
148
61static inline void iphc_uncompress_eui64_lladdr(struct in6_addr *ipaddr, 149static inline void iphc_uncompress_eui64_lladdr(struct in6_addr *ipaddr,
62 const void *lladdr) 150 const void *lladdr)
63{ 151{
diff --git a/net/6lowpan/nhc_udp.c b/net/6lowpan/nhc_udp.c
index 72d0b57eb6e5..69537a2eaab1 100644
--- a/net/6lowpan/nhc_udp.c
+++ b/net/6lowpan/nhc_udp.c
@@ -17,7 +17,27 @@
17 17
18#include "nhc.h" 18#include "nhc.h"
19 19
20#define LOWPAN_NHC_UDP_IDLEN 1 20#define LOWPAN_NHC_UDP_MASK 0xF8
21#define LOWPAN_NHC_UDP_ID 0xF0
22#define LOWPAN_NHC_UDP_IDLEN 1
23
24#define LOWPAN_NHC_UDP_4BIT_PORT 0xF0B0
25#define LOWPAN_NHC_UDP_4BIT_MASK 0xFFF0
26#define LOWPAN_NHC_UDP_8BIT_PORT 0xF000
27#define LOWPAN_NHC_UDP_8BIT_MASK 0xFF00
28
29/* values for port compression, _with checksum_ ie bit 5 set to 0 */
30
31/* all inline */
32#define LOWPAN_NHC_UDP_CS_P_00 0xF0
33/* source 16bit inline, dest = 0xF0 + 8 bit inline */
34#define LOWPAN_NHC_UDP_CS_P_01 0xF1
35/* source = 0xF0 + 8bit inline, dest = 16 bit inline */
36#define LOWPAN_NHC_UDP_CS_P_10 0xF2
37/* source & dest = 0xF0B + 4bit inline */
38#define LOWPAN_NHC_UDP_CS_P_11 0xF3
39/* checksum elided */
40#define LOWPAN_NHC_UDP_CS_C 0x04
21 41
22static int udp_uncompress(struct sk_buff *skb, size_t needed) 42static int udp_uncompress(struct sk_buff *skb, size_t needed)
23{ 43{
diff --git a/net/ieee802154/6lowpan/tx.c b/net/ieee802154/6lowpan/tx.c
index 2a5b2c2b922b..f6594a87d6fc 100644
--- a/net/ieee802154/6lowpan/tx.c
+++ b/net/ieee802154/6lowpan/tx.c
@@ -14,6 +14,9 @@
14 14
15#include "6lowpan_i.h" 15#include "6lowpan_i.h"
16 16
17#define LOWPAN_FRAG1_HEAD_SIZE 0x4
18#define LOWPAN_FRAGN_HEAD_SIZE 0x5
19
17/* don't save pan id, it's intra pan */ 20/* don't save pan id, it's intra pan */
18struct lowpan_addr { 21struct lowpan_addr {
19 u8 mode; 22 u8 mode;