Skip to content

Commit e462ded

Browse files
Phoebe Buckheisterdavem330
authored andcommitted
mac802154: make csma/cca parameters per-wpan
Commit 9b2777d (ieee802154: add TX power control to wpan_phy) and following erroneously added CSMA and CCA parameters for 802.15.4 devices as PHY parameters, while they are actually MAC parameters and can differ for any two WPAN instances. Since it is now sensible to have multiple WPAN devices with differing CSMA/CCA parameters, make these parameters MAC parameters instead. Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 336908f commit e462ded

11 files changed

Lines changed: 252 additions & 236 deletions

File tree

‎include/linux/nl802154.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ enum {
132132
IEEE802154_ADD_IFACE,
133133
IEEE802154_DEL_IFACE,
134134

135-
IEEE802154_SET_PHYPARAMS,
135+
IEEE802154_SET_MACPARAMS,
136136

137137
__IEEE802154_CMD_MAX,
138138
};

‎include/net/ieee802154_netdev.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,18 @@ static inline int mac_cb_type(struct sk_buff *skb)
229229
#define IEEE802154_MAC_SCAN_PASSIVE 2
230230
#define IEEE802154_MAC_SCAN_ORPHAN 3
231231

232+
struct ieee802154_mac_params {
233+
s8 transmit_power;
234+
u8 min_be;
235+
u8 max_be;
236+
u8 csma_retries;
237+
s8 frame_retries;
238+
239+
bool lbt;
240+
u8 cca_mode;
241+
s32 cca_ed_level;
242+
};
243+
232244
struct wpan_phy;
233245
/*
234246
* This should be located at net_device->ml_priv
@@ -255,6 +267,11 @@ struct ieee802154_mlme_ops {
255267
int (*scan_req)(struct net_device *dev,
256268
u8 type, u32 channels, u8 page, u8 duration);
257269

270+
int (*set_mac_params)(struct net_device *dev,
271+
const struct ieee802154_mac_params *params);
272+
void (*get_mac_params)(struct net_device *dev,
273+
struct ieee802154_mac_params *params);
274+
258275
/* The fields below are required. */
259276

260277
struct wpan_phy *(*get_phy)(const struct net_device *dev);

‎net/ieee802154/ieee802154.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ int ieee802154_list_phy(struct sk_buff *skb, struct genl_info *info);
5353
int ieee802154_dump_phy(struct sk_buff *skb, struct netlink_callback *cb);
5454
int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info);
5555
int ieee802154_del_iface(struct sk_buff *skb, struct genl_info *info);
56-
int ieee802154_set_phyparams(struct sk_buff *skb, struct genl_info *info);
5756

5857
enum ieee802154_mcgrp_ids {
5958
IEEE802154_COORD_MCGRP,
@@ -67,5 +66,6 @@ int ieee802154_scan_req(struct sk_buff *skb, struct genl_info *info);
6766
int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info);
6867
int ieee802154_list_iface(struct sk_buff *skb, struct genl_info *info);
6968
int ieee802154_dump_iface(struct sk_buff *skb, struct netlink_callback *cb);
69+
int ieee802154_set_macparams(struct sk_buff *skb, struct genl_info *info);
7070

7171
#endif

‎net/ieee802154/netlink.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ static const struct genl_ops ieee8021154_ops[] = {
115115
ieee802154_dump_phy),
116116
IEEE802154_OP(IEEE802154_ADD_IFACE, ieee802154_add_iface),
117117
IEEE802154_OP(IEEE802154_DEL_IFACE, ieee802154_del_iface),
118-
IEEE802154_OP(IEEE802154_SET_PHYPARAMS, ieee802154_set_phyparams),
119118
/* see nl-mac.c */
120119
IEEE802154_OP(IEEE802154_ASSOCIATE_REQ, ieee802154_associate_req),
121120
IEEE802154_OP(IEEE802154_ASSOCIATE_RESP, ieee802154_associate_resp),
@@ -124,6 +123,7 @@ static const struct genl_ops ieee8021154_ops[] = {
124123
IEEE802154_OP(IEEE802154_START_REQ, ieee802154_start_req),
125124
IEEE802154_DUMP(IEEE802154_LIST_IFACE, ieee802154_list_iface,
126125
ieee802154_dump_iface),
126+
IEEE802154_OP(IEEE802154_SET_MACPARAMS, ieee802154_set_macparams),
127127
};
128128

129129
static const struct genl_multicast_group ieee802154_mcgrps[] = {

‎net/ieee802154/nl-mac.c‎

Lines changed: 119 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,
264264
{
265265
void *hdr;
266266
struct wpan_phy *phy;
267+
struct ieee802154_mlme_ops *ops;
267268
__le16 short_addr, pan_id;
268269

269270
pr_debug("%s\n", __func__);
@@ -273,11 +274,12 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,
273274
if (!hdr)
274275
goto out;
275276

276-
phy = ieee802154_mlme_ops(dev)->get_phy(dev);
277+
ops = ieee802154_mlme_ops(dev);
278+
phy = ops->get_phy(dev);
277279
BUG_ON(!phy);
278280

279-
short_addr = ieee802154_mlme_ops(dev)->get_short_addr(dev);
280-
pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
281+
short_addr = ops->get_short_addr(dev);
282+
pan_id = ops->get_pan_id(dev);
281283

282284
if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
283285
nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) ||
@@ -287,6 +289,30 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,
287289
nla_put_shortaddr(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr) ||
288290
nla_put_shortaddr(msg, IEEE802154_ATTR_PAN_ID, pan_id))
289291
goto nla_put_failure;
292+
293+
if (ops->get_mac_params) {
294+
struct ieee802154_mac_params params;
295+
296+
ops->get_mac_params(dev, &params);
297+
298+
if (nla_put_s8(msg, IEEE802154_ATTR_TXPOWER,
299+
params.transmit_power) ||
300+
nla_put_u8(msg, IEEE802154_ATTR_LBT_ENABLED, params.lbt) ||
301+
nla_put_u8(msg, IEEE802154_ATTR_CCA_MODE,
302+
params.cca_mode) ||
303+
nla_put_s32(msg, IEEE802154_ATTR_CCA_ED_LEVEL,
304+
params.cca_ed_level) ||
305+
nla_put_u8(msg, IEEE802154_ATTR_CSMA_RETRIES,
306+
params.csma_retries) ||
307+
nla_put_u8(msg, IEEE802154_ATTR_CSMA_MIN_BE,
308+
params.min_be) ||
309+
nla_put_u8(msg, IEEE802154_ATTR_CSMA_MAX_BE,
310+
params.max_be) ||
311+
nla_put_s8(msg, IEEE802154_ATTR_FRAME_RETRIES,
312+
params.frame_retries))
313+
goto nla_put_failure;
314+
}
315+
290316
wpan_phy_put(phy);
291317
return genlmsg_end(msg, hdr);
292318

@@ -599,3 +625,93 @@ int ieee802154_dump_iface(struct sk_buff *skb, struct netlink_callback *cb)
599625

600626
return skb->len;
601627
}
628+
629+
int ieee802154_set_macparams(struct sk_buff *skb, struct genl_info *info)
630+
{
631+
struct net_device *dev = NULL;
632+
struct ieee802154_mlme_ops *ops;
633+
struct ieee802154_mac_params params;
634+
struct wpan_phy *phy;
635+
int rc = -EINVAL;
636+
637+
pr_debug("%s\n", __func__);
638+
639+
dev = ieee802154_nl_get_dev(info);
640+
if (!dev)
641+
return -ENODEV;
642+
643+
ops = ieee802154_mlme_ops(dev);
644+
645+
if (!ops->get_mac_params || !ops->set_mac_params) {
646+
rc = -EOPNOTSUPP;
647+
goto out;
648+
}
649+
650+
if (netif_running(dev)) {
651+
rc = -EBUSY;
652+
goto out;
653+
}
654+
655+
if (!info->attrs[IEEE802154_ATTR_LBT_ENABLED] &&
656+
!info->attrs[IEEE802154_ATTR_CCA_MODE] &&
657+
!info->attrs[IEEE802154_ATTR_CCA_ED_LEVEL] &&
658+
!info->attrs[IEEE802154_ATTR_CSMA_RETRIES] &&
659+
!info->attrs[IEEE802154_ATTR_CSMA_MIN_BE] &&
660+
!info->attrs[IEEE802154_ATTR_CSMA_MAX_BE] &&
661+
!info->attrs[IEEE802154_ATTR_FRAME_RETRIES])
662+
goto out;
663+
664+
phy = ops->get_phy(dev);
665+
666+
if ((!phy->set_lbt && info->attrs[IEEE802154_ATTR_LBT_ENABLED]) ||
667+
(!phy->set_cca_mode && info->attrs[IEEE802154_ATTR_CCA_MODE]) ||
668+
(!phy->set_cca_ed_level &&
669+
info->attrs[IEEE802154_ATTR_CCA_ED_LEVEL]) ||
670+
(!phy->set_csma_params &&
671+
(info->attrs[IEEE802154_ATTR_CSMA_RETRIES] ||
672+
info->attrs[IEEE802154_ATTR_CSMA_MIN_BE] ||
673+
info->attrs[IEEE802154_ATTR_CSMA_MAX_BE])) ||
674+
(!phy->set_frame_retries &&
675+
info->attrs[IEEE802154_ATTR_FRAME_RETRIES])) {
676+
rc = -EOPNOTSUPP;
677+
goto out_phy;
678+
}
679+
680+
ops->get_mac_params(dev, &params);
681+
682+
if (info->attrs[IEEE802154_ATTR_TXPOWER])
683+
params.transmit_power = nla_get_s8(info->attrs[IEEE802154_ATTR_TXPOWER]);
684+
685+
if (info->attrs[IEEE802154_ATTR_LBT_ENABLED])
686+
params.lbt = nla_get_u8(info->attrs[IEEE802154_ATTR_LBT_ENABLED]);
687+
688+
if (info->attrs[IEEE802154_ATTR_CCA_MODE])
689+
params.cca_mode = nla_get_u8(info->attrs[IEEE802154_ATTR_CCA_MODE]);
690+
691+
if (info->attrs[IEEE802154_ATTR_CCA_ED_LEVEL])
692+
params.cca_ed_level = nla_get_s32(info->attrs[IEEE802154_ATTR_CCA_ED_LEVEL]);
693+
694+
if (info->attrs[IEEE802154_ATTR_CSMA_RETRIES])
695+
params.csma_retries = nla_get_u8(info->attrs[IEEE802154_ATTR_CSMA_RETRIES]);
696+
697+
if (info->attrs[IEEE802154_ATTR_CSMA_MIN_BE])
698+
params.min_be = nla_get_u8(info->attrs[IEEE802154_ATTR_CSMA_MIN_BE]);
699+
700+
if (info->attrs[IEEE802154_ATTR_CSMA_MAX_BE])
701+
params.max_be = nla_get_u8(info->attrs[IEEE802154_ATTR_CSMA_MAX_BE]);
702+
703+
if (info->attrs[IEEE802154_ATTR_FRAME_RETRIES])
704+
params.frame_retries = nla_get_s8(info->attrs[IEEE802154_ATTR_FRAME_RETRIES]);
705+
706+
rc = ops->set_mac_params(dev, &params);
707+
708+
wpan_phy_put(phy);
709+
dev_put(dev);
710+
return rc;
711+
712+
out_phy:
713+
wpan_phy_put(phy);
714+
out:
715+
dev_put(dev);
716+
return rc;
717+
}

0 commit comments

Comments
 (0)