/* SPDX-License-Identifier: GPL-2.0 */1#ifndef __6LOWPAN_NHC_H2#define __6LOWPAN_NHC_H34#include <linux/skbuff.h>5#include <linux/rbtree.h>6#include <linux/module.h>78#include <net/6lowpan.h>9#include <net/ipv6.h>1011/**12* LOWPAN_NHC - helper macro to generate nh id fields and lowpan_nhc struct13*14* @__nhc: variable name of the lowpan_nhc struct.15* @_name: const char * of common header compression name.16* @_nexthdr: ipv6 nexthdr field for the header compression.17* @_nexthdrlen: ipv6 nexthdr len for the reserved space.18* @_id: one byte nhc id value.19* @_idmask: one byte nhc id mask value.20* @_uncompress: callback for uncompression call.21* @_compress: callback for compression call.22*/23#define LOWPAN_NHC(__nhc, _name, _nexthdr, \24_hdrlen, _id, _idmask, \25_uncompress, _compress) \26static const struct lowpan_nhc __nhc = { \27.name = _name, \28.nexthdr = _nexthdr, \29.nexthdrlen = _hdrlen, \30.id = _id, \31.idmask = _idmask, \32.uncompress = _uncompress, \33.compress = _compress, \34}3536#define module_lowpan_nhc(__nhc) \37static int __init __nhc##_init(void) \38{ \39return lowpan_nhc_add(&(__nhc)); \40} \41module_init(__nhc##_init); \42static void __exit __nhc##_exit(void) \43{ \44lowpan_nhc_del(&(__nhc)); \45} \46module_exit(__nhc##_exit);4748/**49* struct lowpan_nhc - hold 6lowpan next hdr compression ifnformation50*51* @name: name of the specific next header compression52* @nexthdr: next header value of the protocol which should be compressed.53* @nexthdrlen: ipv6 nexthdr len for the reserved space.54* @id: one byte nhc id value.55* @idmask: one byte nhc id mask value.56* @compress: callback to do the header compression.57* @uncompress: callback to do the header uncompression.58*/59struct lowpan_nhc {60const char *name;61u8 nexthdr;62size_t nexthdrlen;63u8 id;64u8 idmask;6566int (*uncompress)(struct sk_buff *skb, size_t needed);67int (*compress)(struct sk_buff *skb, u8 **hc_ptr);68};6970/**71* lowpan_nhc_by_nexthdr - return the 6lowpan nhc by ipv6 nexthdr.72*73* @nexthdr: ipv6 nexthdr value.74*/75struct lowpan_nhc *lowpan_nhc_by_nexthdr(u8 nexthdr);7677/**78* lowpan_nhc_check_compression - checks if we support compression format. If79* we support the nhc by nexthdr field, the function will return 0. If we80* don't support the nhc by nexthdr this function will return -ENOENT.81*82* @skb: skb of 6LoWPAN header to read nhc and replace header.83* @hdr: ipv6hdr to check the nexthdr value84* @hc_ptr: pointer for 6LoWPAN header which should increment at the end of85* replaced header.86*/87int lowpan_nhc_check_compression(struct sk_buff *skb,88const struct ipv6hdr *hdr, u8 **hc_ptr);8990/**91* lowpan_nhc_do_compression - calling compress callback for nhc92*93* @skb: skb of 6LoWPAN header to read nhc and replace header.94* @hdr: ipv6hdr to set the nexthdr value95* @hc_ptr: pointer for 6LoWPAN header which should increment at the end of96* replaced header.97*/98int lowpan_nhc_do_compression(struct sk_buff *skb, const struct ipv6hdr *hdr,99u8 **hc_ptr);100101/**102* lowpan_nhc_do_uncompression - calling uncompress callback for nhc103*104* @nhc: 6LoWPAN nhc context, get by lowpan_nhc_by_ functions.105* @skb: skb of 6LoWPAN header, skb->data should be pointed to nhc id value.106* @dev: netdevice for print logging information.107* @hdr: ipv6hdr for setting nexthdr value.108*/109int lowpan_nhc_do_uncompression(struct sk_buff *skb,110const struct net_device *dev,111struct ipv6hdr *hdr);112113/**114* lowpan_nhc_add - register a next header compression to framework115*116* @nhc: nhc which should be add.117*/118int lowpan_nhc_add(const struct lowpan_nhc *nhc);119120/**121* lowpan_nhc_del - delete a next header compression from framework122*123* @nhc: nhc which should be delete.124*/125void lowpan_nhc_del(const struct lowpan_nhc *nhc);126127/**128* lowpan_nhc_init - adding all default nhcs129*/130void lowpan_nhc_init(void);131132#endif /* __6LOWPAN_NHC_H */133134135