diff options
author | Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de> | 2014-05-14 11:43:06 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-05-15 15:51:42 -0400 |
commit | c3a6114f31600b94ee10ebf62e4d493b401ade87 (patch) | |
tree | a854819cfede389764da13bcc0d7670e1f1e964f /net/ieee802154/header_ops.c | |
parent | 9dbccc30f3306114e1ca4a89da69be6d5f675782 (diff) |
ieee802154: add definitions for link-layer security and header functions
When dealing with 802.15.4, one often has to know the maximum payload
size for a given packet. This depends on many factors, one of which is
whether or not a security header is present in the frame. These
definitions and functions provide an easy way for any upper layer to
calculate the maximum payload size for a packet. The first obvious user
for this is 6lowpan, which duplicates this calculation and gets it
partially wrong because it ignores security headers.
Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ieee802154/header_ops.c')
-rw-r--r-- | net/ieee802154/header_ops.c | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/net/ieee802154/header_ops.c b/net/ieee802154/header_ops.c index bed42a48408c..c09294e39ca6 100644 --- a/net/ieee802154/header_ops.c +++ b/net/ieee802154/header_ops.c | |||
@@ -195,15 +195,16 @@ ieee802154_hdr_get_sechdr(const u8 *buf, struct ieee802154_sechdr *hdr) | |||
195 | return pos; | 195 | return pos; |
196 | } | 196 | } |
197 | 197 | ||
198 | static int ieee802154_sechdr_lengths[4] = { | ||
199 | [IEEE802154_SCF_KEY_IMPLICIT] = 5, | ||
200 | [IEEE802154_SCF_KEY_INDEX] = 6, | ||
201 | [IEEE802154_SCF_KEY_SHORT_INDEX] = 10, | ||
202 | [IEEE802154_SCF_KEY_HW_INDEX] = 14, | ||
203 | }; | ||
204 | |||
198 | static int ieee802154_hdr_sechdr_len(u8 sc) | 205 | static int ieee802154_hdr_sechdr_len(u8 sc) |
199 | { | 206 | { |
200 | switch (IEEE802154_SCF_KEY_ID_MODE(sc)) { | 207 | return ieee802154_sechdr_lengths[IEEE802154_SCF_KEY_ID_MODE(sc)]; |
201 | case IEEE802154_SCF_KEY_IMPLICIT: return 5; | ||
202 | case IEEE802154_SCF_KEY_INDEX: return 6; | ||
203 | case IEEE802154_SCF_KEY_SHORT_INDEX: return 10; | ||
204 | case IEEE802154_SCF_KEY_HW_INDEX: return 14; | ||
205 | default: return -EINVAL; | ||
206 | } | ||
207 | } | 208 | } |
208 | 209 | ||
209 | static int ieee802154_hdr_minlen(const struct ieee802154_hdr *hdr) | 210 | static int ieee802154_hdr_minlen(const struct ieee802154_hdr *hdr) |
@@ -285,3 +286,40 @@ ieee802154_hdr_peek_addrs(const struct sk_buff *skb, struct ieee802154_hdr *hdr) | |||
285 | return pos; | 286 | return pos; |
286 | } | 287 | } |
287 | EXPORT_SYMBOL_GPL(ieee802154_hdr_peek_addrs); | 288 | EXPORT_SYMBOL_GPL(ieee802154_hdr_peek_addrs); |
289 | |||
290 | int | ||
291 | ieee802154_hdr_peek(const struct sk_buff *skb, struct ieee802154_hdr *hdr) | ||
292 | { | ||
293 | const u8 *buf = skb_mac_header(skb); | ||
294 | int pos; | ||
295 | |||
296 | pos = ieee802154_hdr_peek_addrs(skb, hdr); | ||
297 | if (pos < 0) | ||
298 | return -EINVAL; | ||
299 | |||
300 | if (hdr->fc.security_enabled) { | ||
301 | u8 key_id_mode = IEEE802154_SCF_KEY_ID_MODE(*(buf + pos)); | ||
302 | int want = pos + ieee802154_sechdr_lengths[key_id_mode]; | ||
303 | |||
304 | if (buf + want > skb_tail_pointer(skb)) | ||
305 | return -EINVAL; | ||
306 | |||
307 | pos += ieee802154_hdr_get_sechdr(buf + pos, &hdr->sec); | ||
308 | } | ||
309 | |||
310 | return pos; | ||
311 | } | ||
312 | EXPORT_SYMBOL_GPL(ieee802154_hdr_peek); | ||
313 | |||
314 | int ieee802154_max_payload(const struct ieee802154_hdr *hdr) | ||
315 | { | ||
316 | int hlen = ieee802154_hdr_minlen(hdr); | ||
317 | |||
318 | if (hdr->fc.security_enabled) { | ||
319 | hlen += ieee802154_sechdr_lengths[hdr->sec.key_id_mode] - 1; | ||
320 | hlen += ieee802154_sechdr_authtag_len(&hdr->sec); | ||
321 | } | ||
322 | |||
323 | return IEEE802154_MTU - hlen - IEEE802154_MFR_SIZE; | ||
324 | } | ||
325 | EXPORT_SYMBOL_GPL(ieee802154_max_payload); | ||