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