1 /*
2  * Copyright (c) 2016 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief 802.15.4 6LoWPAN adaptation layer
10  *
11  * This is not to be included by the application.
12  */
13 
14 #ifndef __NET_IEEE802154_6LO_H__
15 #define __NET_IEEE802154_6LO_H__
16 
17 #include <zephyr/net/net_pkt.h>
18 #include <zephyr/types.h>
19 
20 struct ieee802154_6lo_fragment_ctx {
21 	struct net_buf *buf; /* current original fragment pointer */
22 	uint8_t *pos;	     /* current position in buf */
23 	uint16_t pkt_size;   /* overall datagram size */
24 	uint16_t processed;  /* in bytes */
25 	uint8_t hdr_diff;    /* 6lo header size reduction due to compression in bytes */
26 	uint8_t offset;	     /* in multiples of 8 bytes */
27 };
28 
29 /**
30  *  @brief Decode and reassemble 6LoWPAN packets to IPv6 as per RFC 6282
31  *
32  *  @details Decompress and (if fragmented) reassemble 6LoWPAN packets for
33  *  received over 802.15.4.
34  *
35  *  @param iface A valid pointer on the network interface the package was
36  *               received from
37  *  @param pkt A valid pointer on a 6LoWPAN compressed packet to receive
38  *
39  *  @return NET_CONTINUE decoding successful, pkt is decompressed
40  *          NET_OK waiting for other fragments,
41  *          NET_DROP invalid fragment.
42  */
43 enum net_verdict ieee802154_6lo_decode_pkt(struct net_if *iface, struct net_pkt *pkt);
44 
45 /**
46  *  @brief Encode IPv6 packates to 6LoWPAN 802.15.4 as per RFC 6282
47  *
48  *  @details Compress IPv6 packet for transmission over 802.15.4 and
49  *           check whether additional fragmentation is needed.
50  *
51  *  @param iface A valid pointer on the network interface the package is
52  *               sent to
53  *  @param pkt A valid pointer on a non-compressed IPv6 packet
54  *  @param frag_ctx A valid pointer on a fragmentation context.
55  *  @param ll_hdr_len required headroom for the LL header (after fragmentation)
56  *  @param authtag_len required tailroom for the authentication tag in the frame (after
57  *                     fragmentation)
58  *
59  *  @return 1 if additional 6LoWPAN fragmentation is needed, 0 if no
60  *          fragmentation is needed, negative value on error
61  */
62 int ieee802154_6lo_encode_pkt(struct net_if *iface, struct net_pkt *pkt,
63 			      struct ieee802154_6lo_fragment_ctx *frag_ctx, uint8_t ll_hdr_len,
64 			      uint8_t authtag_len);
65 
66 #endif /* __NET_IEEE802154_6LO_H__ */
67