^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) .. SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) ==============================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) Netdev private dataroom for 6lowpan interfaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) ==============================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) All 6lowpan able net devices, means all interfaces with ARPHRD_6LOWPAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) must have "struct lowpan_priv" placed at beginning of netdev_priv.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) The priv_size of each interface should be calculate by::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) dev->priv_size = LOWPAN_PRIV_SIZE(LL_6LOWPAN_PRIV_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) Where LL_PRIV_6LOWPAN_DATA is sizeof linklayer 6lowpan private data struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) To access the LL_PRIV_6LOWPAN_DATA structure you can cast::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) lowpan_priv(dev)-priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) to your LL_6LOWPAN_PRIV_DATA structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) Before registering the lowpan netdev interface you must run::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) lowpan_netdev_setup(dev, LOWPAN_LLTYPE_FOOBAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) wheres LOWPAN_LLTYPE_FOOBAR is a define for your 6LoWPAN linklayer type of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) enum lowpan_lltypes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) Example to evaluate the private usually you can do::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static inline struct lowpan_priv_foobar *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) lowpan_foobar_priv(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) return (struct lowpan_priv_foobar *)lowpan_priv(dev)->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) switch (dev->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) case ARPHRD_6LOWPAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) lowpan_priv = lowpan_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* do great stuff which is ARPHRD_6LOWPAN related */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) switch (lowpan_priv->lltype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) case LOWPAN_LLTYPE_FOOBAR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* do 802.15.4 6LoWPAN handling here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) lowpan_foobar_priv(dev)->bar = foo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) In case of generic 6lowpan branch ("net/6lowpan") you can remove the check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) on ARPHRD_6LOWPAN, because you can be sure that these function are called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) by ARPHRD_6LOWPAN interfaces.