blob: e70a6520cc33dc94c01633fc903050e2b3bed366 [file] [log] [blame]
Mauro Carvalho Chehab107db7e2020-02-06 16:17:22 +01001.. SPDX-License-Identifier: GPL-2.0
Alexander Aringea9eb692015-08-11 21:44:10 +02002
Mauro Carvalho Chehab107db7e2020-02-06 16:17:22 +01003==============================================
4Netdev private dataroom for 6lowpan interfaces
5==============================================
Alexander Aringea9eb692015-08-11 21:44:10 +02006
7All 6lowpan able net devices, means all interfaces with ARPHRD_6LOWPAN,
8must have "struct lowpan_priv" placed at beginning of netdev_priv.
9
Mauro Carvalho Chehab107db7e2020-02-06 16:17:22 +010010The priv_size of each interface should be calculate by::
Alexander Aringea9eb692015-08-11 21:44:10 +020011
12 dev->priv_size = LOWPAN_PRIV_SIZE(LL_6LOWPAN_PRIV_DATA);
13
14Where LL_PRIV_6LOWPAN_DATA is sizeof linklayer 6lowpan private data struct.
Mauro Carvalho Chehab107db7e2020-02-06 16:17:22 +010015To access the LL_PRIV_6LOWPAN_DATA structure you can cast::
Alexander Aringea9eb692015-08-11 21:44:10 +020016
17 lowpan_priv(dev)-priv;
18
19to your LL_6LOWPAN_PRIV_DATA structure.
20
Mauro Carvalho Chehab107db7e2020-02-06 16:17:22 +010021Before registering the lowpan netdev interface you must run::
Alexander Aringea9eb692015-08-11 21:44:10 +020022
23 lowpan_netdev_setup(dev, LOWPAN_LLTYPE_FOOBAR);
24
25wheres LOWPAN_LLTYPE_FOOBAR is a define for your 6LoWPAN linklayer type of
26enum lowpan_lltypes.
27
Mauro Carvalho Chehab107db7e2020-02-06 16:17:22 +010028Example to evaluate the private usually you can do::
Alexander Aringea9eb692015-08-11 21:44:10 +020029
Mauro Carvalho Chehab107db7e2020-02-06 16:17:22 +010030 static inline struct lowpan_priv_foobar *
31 lowpan_foobar_priv(struct net_device *dev)
32 {
Olivier Gayotbb38ccc2018-06-04 12:07:37 +020033 return (struct lowpan_priv_foobar *)lowpan_priv(dev)->priv;
Mauro Carvalho Chehab107db7e2020-02-06 16:17:22 +010034 }
Alexander Aringea9eb692015-08-11 21:44:10 +020035
Mauro Carvalho Chehab107db7e2020-02-06 16:17:22 +010036 switch (dev->type) {
37 case ARPHRD_6LOWPAN:
Alexander Aringea9eb692015-08-11 21:44:10 +020038 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 Chehab107db7e2020-02-06 16:17:22 +010048 ...
49 }
Alexander Aringea9eb692015-08-11 21:44:10 +020050
51In case of generic 6lowpan branch ("net/6lowpan") you can remove the check
52on ARPHRD_6LOWPAN, because you can be sure that these function are called
53by ARPHRD_6LOWPAN interfaces.