ieee802154: add set transmit power support
Subsystems (2)
PATCH v3 1/1 ieee802154: add set transmit power support
This patch adds transmission power setting support for IEEE-802.15.4 devices via nl802154.
--- include/net/cfg802154.h | 1 + net/ieee802154/nl802154.c | 29 +++++++++++++++++++++++++++++ net/ieee802154/rdev-ops.h | 12 ++++++++++++ net/ieee802154/trace.h | 15 +++++++++++++++ net/mac802154/cfg.c | 19 +++++++++++++++++++ 5 files changed, 76 insertions(+)
include/net/cfg802154.h +1 -0
@@ -44,6 +44,7 @@ struct cfg802154_ops {int (*set_channel)(struct wpan_phy *wpan_phy,u8 page,u8 channel);int (*set_cca_mode)(struct wpan_phy *wpan_phy,const struct wpan_phy_cca *cca); +int (*set_tx_power)(struct wpan_phy *wpan_phy,s32 power);int (*set_pan_id)(struct wpan_phy *wpan_phy,struct wpan_dev *wpan_dev,__le16 pan_id); int (*set_short_addr)(struct wpan_phy *wpan_phy,
net/ieee802154/nl802154.c +29 -0
@@ -783,6 +783,27 @@ static int nl802154_set_cca_mode(struct sk_buff *skb, struct genl_info *info)return rdev_set_cca_mode (rdev, &cca); } +static int nl802154_set_tx_power (struct sk_buff *skb,struct genl_info *info) +{ +struct cfg802154_registered_device *rdev = info->user_ptr[0 ]; +s32 power; +int i; + +if (rdev->wpan_phy.flags &WPAN_PHY_FLAG_TXPOWER ) +return -EOPNOTSUPP ; + +if (!info->attrs[NL802154_ATTR_TX_POWER ]) +return -EINVAL ; + + power =nla_get_s32 (info->attrs[NL802154_ATTR_TX_POWER ]); + +for (i =0 ; i < rdev->wpan_phy.supported.tx_powers_size; i++) +if (power == rdev->wpan_phy.supported.tx_powers[i]) +return rdev_set_tx_power (rdev, power); + +return -EINVAL ; +} +static int nl802154_set_pan_id (struct sk_buff *skb,struct genl_info *info) {struct cfg802154_registered_device *rdev = info->user_ptr[0 ];
@@ -1094,6 +1115,14 @@ static const struct genl_ops nl802154_ops[] = { NL802154_FLAG_NEED_RTNL, }, { + .cmd = NL802154_CMD_SET_TX_POWER, + .doit = nl802154_set_tx_power, + .policy = nl802154_policy, + .flags = GENL_ADMIN_PERM, + .internal_flags = NL802154_FLAG_NEED_WPAN_PHY | + NL802154_FLAG_NEED_RTNL, + }, + { .cmd = NL802154_CMD_SET_PAN_ID, .doit = nl802154_set_pan_id, .policy = nl802154_policy,
net/ieee802154/rdev-ops.h +12 -0
@@ -75,6 +75,18 @@ rdev_set_cca_mode(struct cfg802154_registered_device *rdev, }static inline int +rdev_set_tx_power (struct cfg802154_registered_device *rdev, +s32 power) +{ +int ret; + +trace_802154_rdev_set_tx_power (&rdev->wpan_phy, power); + ret = rdev->ops->set_tx_power (&rdev->wpan_phy, power); +trace_802154_rdev_return_int (&rdev->wpan_phy, ret); +return ret; +} + +static inline int rdev_set_pan_id (struct cfg802154_registered_device *rdev,struct wpan_dev *wpan_dev,__le16 pan_id) {
net/ieee802154/trace.h +15 -0
@@ -93,6 +93,21 @@ TRACE_EVENT(802154_rdev_set_channel, __entry->page, __entry->channel) ); +TRACE_EVENT(802154_rdev_set_tx_power, + TP_PROTO(struct wpan_phy *wpan_phy, s32 power), +TP_ARGS (wpan_phy, power), +TP_STRUCT__entry ( + WPAN_PHY_ENTRY +__field (s32, power) + ), +TP_fast_assign ( + WPAN_PHY_ASSIGN; + __entry->power = power; + ), +TP_printk (WPAN_PHY_PR_FMT ", power: %d" ,WPAN_PHY_PR_ARG , + __entry->power) +); + TRACE_EVENT(802154_rdev_set_cca_mode, TP_PROTO(struct wpan_phy *wpan_phy, const struct wpan_phy_cca *cca), TP_ARGS(wpan_phy, cca),
net/mac802154/cfg.c +19 -0
@@ -106,6 +106,24 @@ ieee802154_set_cca_mode(struct wpan_phy *wpan_phy, }static int +ieee802154_set_tx_power (struct wpan_phy *wpan_phy,s32 power) +{ +struct ieee802154_local *local =wpan_phy_priv (wpan_phy); +int ret; + +ASSERT_RTNL (); + +if (wpan_phy->transmit_power == power) +return 0 ; + + ret =drv_set_tx_power (local, power); +if (!ret) + wpan_phy->transmit_power = power; + +return ret; +} + +static int ieee802154_set_pan_id (struct wpan_phy *wpan_phy,struct wpan_dev *wpan_dev,__le16 pan_id) {
@@ -195,6 +213,7 @@ const struct cfg802154_ops mac802154_config_ops = { .del_virtual_intf = ieee802154_del_iface, .set_channel = ieee802154_set_channel, .set_cca_mode = ieee802154_set_cca_mode, + .set_tx_power = ieee802154_set_tx_power, .set_pan_id = ieee802154_set_pan_id, .set_short_addr = ieee802154_set_short_addr, .set_backoff_exponent = ieee802154_set_backoff_exponent,
Signature · 1 line
1.7.9.5
Alexander Aring
maintainerHi,
Quoted 30 lines · Varka Bhadram
This patch adds transmission power setting support for IEEE-802.15.4 devices via nl802154.
Signed-off-by Varka Bhadram <[email protected]>--- include/net/cfg802154.h | 1 + net/ieee802154/nl802154.c | 29 +++++++++++++++++++++++++++++ net/ieee802154/rdev-ops.h | 12 ++++++++++++ net/ieee802154/trace.h | 15 +++++++++++++++ net/mac802154/cfg.c | 19 +++++++++++++++++++ 5 files changed, 76 insertions(+)include/net/cfg802154.h +1
-0@@ -44,6 +44,7 @@ struct cfg802154_ops {int (*set_channel)(struct wpan_phy *wpan_phy,u8 page,u8 channel);int (*set_cca_mode)(struct wpan_phy *wpan_phy,const struct wpan_phy_cca *cca); +int (*set_tx_power)(struct wpan_phy *wpan_phy,s32 power);int (*set_pan_id)(struct wpan_phy *wpan_phy,struct wpan_dev *wpan_dev,__le16 pan_id); int (*set_short_addr)(struct wpan_phy *wpan_phy,net/ieee802154/nl802154.c +0
-0@@ -783,6 +783,27 @@ static int nl802154_set_cca_mode(struct sk_buff *skb, struct genl_info *info)return rdev_set_cca_mode (rdev, &cca);
net/ieee802154/nl802154.c static int nl802154_set_cca_mode(struct sk_buff *skb, struct genl_info *info) · line 793
Quoted 10 lines
net/ieee802154/nl802154.c +8
-0} +static int nl802154_set_tx_power (struct sk_buff *skb,struct genl_info *info) +{ +struct cfg802154_registered_device *rdev = info->user_ptr[0 ]; +s32 power; +int i; + +if (rdev->wpan_phy.flags &WPAN_PHY_FLAG_TXPOWER ) +return -EOPNOTSUPP ;
if (!(rdev->wpan_phy.flags & WPAN_PHY_FLAG_TXPOWER)) return -EOPNOTSUPP;
I did it also wrong in the cca mode setting. I recently send a patch for fixing this.
net/ieee802154/nl802154.c static int nl802154_set_cca_mode(struct sk_buff *skb, struct genl_info *info) · line 802
Quoted 9 lines
net/ieee802154/nl802154.c +9
-0+ +if (!info->attrs[NL802154_ATTR_TX_POWER ]) +return -EINVAL ; + + power =nla_get_s32 (info->attrs[NL802154_ATTR_TX_POWER ]); + +for (i =0 ; i < rdev->wpan_phy.supported.tx_powers_size; i++) +if (power == rdev->wpan_phy.supported.tx_powers[i]) +return rdev_set_tx_power (rdev, power);
please add brackets for the for loop.
Otherwise it's looking good. Do you want also change the stuff for wpan-tools? I have the following solution currently for a fast testing which works in my first tests:
src/phy.c +2 -2
@@ -53,14 +53,14 @@ static int handle_tx_power_set(struct nl802154_state *state, int argc, char **argv, enum id_input id) { - long dbm; + float dbm;char *end;if (argc <1 )return 1 ;/* TX_POWER */ - dbm =strtol (argv[0 ], &end,10 ); + dbm =strtof (argv[0 ], &end);if (*end !='\0' )return 1 ;
- Alex
Hi,
Quoted 49 lines · Alexander Aring
Hi,
Quoted 30 lines · Varka Bhadram
This patch adds transmission power setting support for IEEE-802.15.4 devices via nl802154.
Signed-off-by Varka Bhadram <[email protected]>--- include/net/cfg802154.h | 1 + net/ieee802154/nl802154.c | 29 +++++++++++++++++++++++++++++ net/ieee802154/rdev-ops.h | 12 ++++++++++++ net/ieee802154/trace.h | 15 +++++++++++++++ net/mac802154/cfg.c | 19 +++++++++++++++++++ 5 files changed, 76 insertions(+)include/net/cfg802154.h +1
-0@@ -44,6 +44,7 @@ struct cfg802154_ops {int (*set_channel)(struct wpan_phy *wpan_phy,u8 page,u8 channel);int (*set_cca_mode)(struct wpan_phy *wpan_phy,const struct wpan_phy_cca *cca); +int (*set_tx_power)(struct wpan_phy *wpan_phy,s32 power);int (*set_pan_id)(struct wpan_phy *wpan_phy,struct wpan_dev *wpan_dev,__le16 pan_id); int (*set_short_addr)(struct wpan_phy *wpan_phy,net/ieee802154/nl802154.c +0
-0@@ -783,6 +783,27 @@ static int nl802154_set_cca_mode(struct sk_buff *skb, struct genl_info *info)return rdev_set_cca_mode (rdev, &cca);net/ieee802154/nl802154.c static int nl802154_set_cca_mode(struct sk_buff *skb, struct genl_info *info) · line 793
Quoted 10 lines
net/ieee802154/nl802154.c +8
-0} +static int nl802154_set_tx_power (struct sk_buff *skb,struct genl_info *info) +{ +struct cfg802154_registered_device *rdev = info->user_ptr[0 ]; +s32 power; +int i; + +if (rdev->wpan_phy.flags &WPAN_PHY_FLAG_TXPOWER ) +return -EOPNOTSUPP ;if (!(rdev->wpan_phy.flags & WPAN_PHY_FLAG_TXPOWER)) return -EOPNOTSUPP;I did it also wrong in the cca mode setting. I recently send a patch for fixing this.
Quoted 10 lines
net/ieee802154/nl802154.c static int nl802154_set_cca_mode(struct sk_buff *skb, struct genl_info *info) · line 802
Quoted 9 lines
net/ieee802154/nl802154.c +9
-0+ +if (!info->attrs[NL802154_ATTR_TX_POWER ]) +return -EINVAL ; + + power =nla_get_s32 (info->attrs[NL802154_ATTR_TX_POWER ]); + +for (i =0 ; i < rdev->wpan_phy.supported.tx_powers_size; i++) +if (power == rdev->wpan_phy.supported.tx_powers[i]) +return rdev_set_tx_power (rdev, power);please add brackets for the for loop.
Done. Send the updated patch to ML.
Quoted 14 lines
Otherwise it's looking good. Do you want also change the stuff for wpan-tools? I have the following solution currently for a fast testing which works in my first tests:
src/phy.c +1
-1@@ -53,14 +53,14 @@ static int handle_tx_power_set(struct nl802154_state *state, int argc, char **argv, enum id_input id) { - long dbm; + float dbm;
src/phy.c static int handle_tx_power_set(struct nl802154_state *state, · line 65
Quoted 10 lines
src/phy.c +1
-1char *end;if (argc <1 )return 1 ;/* TX_POWER */ - dbm =strtol (argv[0 ], &end,10 ); + dbm =strtof (argv[0 ], &end);if (*end !='\0' )return 1 ;
I also had same patch in my queue.
Will you add this patch to wpan-tools ?
or
Do you want me to send this patch to ML.?
Signature · 1 line
Varka Bhadram
Alexander Aring
maintainerOn Wed, May 27, 2015 at 09:16:25AM +0530, Varka Bhadram wrote:
...
Quoted 7 lines
I also had same patch in my queue.
Will you add this patch to wpan-tools ?
or
Do you want me to send this patch to ML.?
You can do that, I think then it's time for a new release since we have capabilities support and tx power setting.
- Alex