192aa7c65SAlexander Aring #ifndef __6LOWPAN_NHC_H 292aa7c65SAlexander Aring #define __6LOWPAN_NHC_H 392aa7c65SAlexander Aring 492aa7c65SAlexander Aring #include <linux/skbuff.h> 592aa7c65SAlexander Aring #include <linux/rbtree.h> 692aa7c65SAlexander Aring #include <linux/module.h> 792aa7c65SAlexander Aring 892aa7c65SAlexander Aring #include <net/6lowpan.h> 992aa7c65SAlexander Aring #include <net/ipv6.h> 1092aa7c65SAlexander Aring 1192aa7c65SAlexander Aring /** 1292aa7c65SAlexander Aring * LOWPAN_NHC - helper macro to generate nh id fields and lowpan_nhc struct 1392aa7c65SAlexander Aring * 1492aa7c65SAlexander Aring * @__nhc: variable name of the lowpan_nhc struct. 1592aa7c65SAlexander Aring * @_name: const char * of common header compression name. 1692aa7c65SAlexander Aring * @_nexthdr: ipv6 nexthdr field for the header compression. 1792aa7c65SAlexander Aring * @_nexthdrlen: ipv6 nexthdr len for the reserved space. 1892aa7c65SAlexander Aring * @_idsetup: callback to setup id and mask values. 1992aa7c65SAlexander Aring * @_idlen: len for the next header id and mask, should be always the same. 2092aa7c65SAlexander Aring * @_uncompress: callback for uncompression call. 2192aa7c65SAlexander Aring * @_compress: callback for compression call. 2292aa7c65SAlexander Aring */ 2392aa7c65SAlexander Aring #define LOWPAN_NHC(__nhc, _name, _nexthdr, \ 2492aa7c65SAlexander Aring _hdrlen, _idsetup, _idlen, \ 2592aa7c65SAlexander Aring _uncompress, _compress) \ 2692aa7c65SAlexander Aring static u8 __nhc##_val[_idlen]; \ 2792aa7c65SAlexander Aring static u8 __nhc##_mask[_idlen]; \ 2892aa7c65SAlexander Aring static struct lowpan_nhc __nhc = { \ 2992aa7c65SAlexander Aring .name = _name, \ 3092aa7c65SAlexander Aring .nexthdr = _nexthdr, \ 3192aa7c65SAlexander Aring .nexthdrlen = _hdrlen, \ 3292aa7c65SAlexander Aring .id = __nhc##_val, \ 3392aa7c65SAlexander Aring .idmask = __nhc##_mask, \ 3492aa7c65SAlexander Aring .idlen = _idlen, \ 3592aa7c65SAlexander Aring .idsetup = _idsetup, \ 3692aa7c65SAlexander Aring .uncompress = _uncompress, \ 3792aa7c65SAlexander Aring .compress = _compress, \ 3892aa7c65SAlexander Aring } 3992aa7c65SAlexander Aring 4092aa7c65SAlexander Aring #define module_lowpan_nhc(__nhc) \ 4192aa7c65SAlexander Aring static int __init __nhc##_init(void) \ 4292aa7c65SAlexander Aring { \ 4392aa7c65SAlexander Aring return lowpan_nhc_add(&(__nhc)); \ 4492aa7c65SAlexander Aring } \ 4592aa7c65SAlexander Aring module_init(__nhc##_init); \ 4692aa7c65SAlexander Aring static void __exit __nhc##_exit(void) \ 4792aa7c65SAlexander Aring { \ 4892aa7c65SAlexander Aring lowpan_nhc_del(&(__nhc)); \ 4992aa7c65SAlexander Aring } \ 5092aa7c65SAlexander Aring module_exit(__nhc##_exit); 5192aa7c65SAlexander Aring 5292aa7c65SAlexander Aring /** 5392aa7c65SAlexander Aring * struct lowpan_nhc - hold 6lowpan next hdr compression ifnformation 5492aa7c65SAlexander Aring * 5592aa7c65SAlexander Aring * @node: holder for the rbtree. 5692aa7c65SAlexander Aring * @name: name of the specific next header compression 5792aa7c65SAlexander Aring * @nexthdr: next header value of the protocol which should be compressed. 5892aa7c65SAlexander Aring * @nexthdrlen: ipv6 nexthdr len for the reserved space. 5992aa7c65SAlexander Aring * @id: array for nhc id. Note this need to be in network byteorder. 6092aa7c65SAlexander Aring * @mask: array for nhc id mask. Note this need to be in network byteorder. 6192aa7c65SAlexander Aring * @len: the length of the next header id and mask. 6292aa7c65SAlexander Aring * @setup: callback to setup fill the next header id value and mask. 6392aa7c65SAlexander Aring * @compress: callback to do the header compression. 6492aa7c65SAlexander Aring * @uncompress: callback to do the header uncompression. 6592aa7c65SAlexander Aring */ 6692aa7c65SAlexander Aring struct lowpan_nhc { 6792aa7c65SAlexander Aring struct rb_node node; 6892aa7c65SAlexander Aring const char *name; 6992aa7c65SAlexander Aring const u8 nexthdr; 7092aa7c65SAlexander Aring const size_t nexthdrlen; 7192aa7c65SAlexander Aring u8 *id; 7292aa7c65SAlexander Aring u8 *idmask; 7392aa7c65SAlexander Aring const size_t idlen; 7492aa7c65SAlexander Aring 7592aa7c65SAlexander Aring void (*idsetup)(struct lowpan_nhc *nhc); 7692aa7c65SAlexander Aring int (*uncompress)(struct sk_buff *skb, size_t needed); 7792aa7c65SAlexander Aring int (*compress)(struct sk_buff *skb, u8 **hc_ptr); 7892aa7c65SAlexander Aring }; 7992aa7c65SAlexander Aring 8092aa7c65SAlexander Aring /** 8192aa7c65SAlexander Aring * lowpan_nhc_by_nexthdr - return the 6lowpan nhc by ipv6 nexthdr. 8292aa7c65SAlexander Aring * 8392aa7c65SAlexander Aring * @nexthdr: ipv6 nexthdr value. 8492aa7c65SAlexander Aring */ 8592aa7c65SAlexander Aring struct lowpan_nhc *lowpan_nhc_by_nexthdr(u8 nexthdr); 8692aa7c65SAlexander Aring 8792aa7c65SAlexander Aring /** 8892aa7c65SAlexander Aring * lowpan_nhc_check_compression - checks if we support compression format. If 8992aa7c65SAlexander Aring * we support the nhc by nexthdr field, the 6LoWPAN iphc NHC bit will be 9092aa7c65SAlexander Aring * set. If we don't support nexthdr will be added as inline data to the 9192aa7c65SAlexander Aring * 6LoWPAN header. 9292aa7c65SAlexander Aring * 9392aa7c65SAlexander Aring * @skb: skb of 6LoWPAN header to read nhc and replace header. 9492aa7c65SAlexander Aring * @hdr: ipv6hdr to check the nexthdr value 9592aa7c65SAlexander Aring * @hc_ptr: pointer for 6LoWPAN header which should increment at the end of 9692aa7c65SAlexander Aring * replaced header. 9792aa7c65SAlexander Aring * @iphc0: iphc0 pointer to set the 6LoWPAN NHC bit 9892aa7c65SAlexander Aring */ 9992aa7c65SAlexander Aring int lowpan_nhc_check_compression(struct sk_buff *skb, 10092aa7c65SAlexander Aring const struct ipv6hdr *hdr, u8 **hc_ptr, 10192aa7c65SAlexander Aring u8 *iphc0); 10292aa7c65SAlexander Aring 10392aa7c65SAlexander Aring /** 10492aa7c65SAlexander Aring * lowpan_nhc_do_compression - calling compress callback for nhc 10592aa7c65SAlexander Aring * 10692aa7c65SAlexander Aring * @skb: skb of 6LoWPAN header to read nhc and replace header. 10792aa7c65SAlexander Aring * @hdr: ipv6hdr to set the nexthdr value 10892aa7c65SAlexander Aring * @hc_ptr: pointer for 6LoWPAN header which should increment at the end of 10992aa7c65SAlexander Aring * replaced header. 11092aa7c65SAlexander Aring */ 11192aa7c65SAlexander Aring int lowpan_nhc_do_compression(struct sk_buff *skb, const struct ipv6hdr *hdr, 11292aa7c65SAlexander Aring u8 **hc_ptr); 11392aa7c65SAlexander Aring 11492aa7c65SAlexander Aring /** 11592aa7c65SAlexander Aring * lowpan_nhc_do_uncompression - calling uncompress callback for nhc 11692aa7c65SAlexander Aring * 11792aa7c65SAlexander Aring * @nhc: 6LoWPAN nhc context, get by lowpan_nhc_by_ functions. 11892aa7c65SAlexander Aring * @skb: skb of 6LoWPAN header, skb->data should be pointed to nhc id value. 11992aa7c65SAlexander Aring * @dev: netdevice for print logging information. 12092aa7c65SAlexander Aring * @hdr: ipv6hdr for setting nexthdr value. 12192aa7c65SAlexander Aring */ 122*8911d774SAlexander Aring int lowpan_nhc_do_uncompression(struct sk_buff *skb, 123*8911d774SAlexander Aring const struct net_device *dev, 12492aa7c65SAlexander Aring struct ipv6hdr *hdr); 12592aa7c65SAlexander Aring 12692aa7c65SAlexander Aring /** 12792aa7c65SAlexander Aring * lowpan_nhc_add - register a next header compression to framework 12892aa7c65SAlexander Aring * 12992aa7c65SAlexander Aring * @nhc: nhc which should be add. 13092aa7c65SAlexander Aring */ 13192aa7c65SAlexander Aring int lowpan_nhc_add(struct lowpan_nhc *nhc); 13292aa7c65SAlexander Aring 13392aa7c65SAlexander Aring /** 13492aa7c65SAlexander Aring * lowpan_nhc_del - delete a next header compression from framework 13592aa7c65SAlexander Aring * 13692aa7c65SAlexander Aring * @nhc: nhc which should be delete. 13792aa7c65SAlexander Aring */ 13892aa7c65SAlexander Aring void lowpan_nhc_del(struct lowpan_nhc *nhc); 13992aa7c65SAlexander Aring 14092aa7c65SAlexander Aring /** 14192aa7c65SAlexander Aring * lowpan_nhc_init - adding all default nhcs 14292aa7c65SAlexander Aring */ 14392aa7c65SAlexander Aring void lowpan_nhc_init(void); 14492aa7c65SAlexander Aring 14592aa7c65SAlexander Aring #endif /* __6LOWPAN_NHC_H */ 146