All of lore.kernel.org
 help / color / mirror / Atom feed
From: Varka Bhadram <varkabhadram@gmail.com>
To: linux-wpan@vger.kernel.org
Cc: alex.aring@gmail.com, Varka Bhadram <varkab@cdac.in>
Subject: [PATCH bluetooth-next 1/3] ieee802154: add set transmit power support
Date: Fri, 20 Mar 2015 12:52:18 +0530	[thread overview]
Message-ID: <1426836141-21528-1-git-send-email-varkab@cdac.in> (raw)

This patch adds transmission power setting support to nl802154.

Signed-off-by: Varka Bhadram <varkab@cdac.in>
---
 include/net/cfg802154.h   |    1 +
 net/ieee802154/nl802154.c |   20 ++++++++++++++++++++
 net/ieee802154/rdev-ops.h |    7 +++++++
 net/mac802154/cfg.c       |   19 +++++++++++++++++++
 4 files changed, 47 insertions(+)

diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index eeda676..b163d4e 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -57,6 +57,7 @@ struct cfg802154_ops {
 					 s8 max_frame_retries);
 	int	(*set_lbt_mode)(struct wpan_phy *wpan_phy,
 				struct wpan_dev *wpan_dev, bool mode);
+	int	(*set_tx_power)(struct wpan_phy *wpan_phy, s8 power);
 };
 
 struct wpan_phy_cca {
diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index a4daf91..8288fcb 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -794,6 +794,18 @@ static int nl802154_set_lbt_mode(struct sk_buff *skb, struct genl_info *info)
 	return rdev_set_lbt_mode(rdev, wpan_dev, mode);
 }
 
+static int nl802154_set_tx_power(struct sk_buff *skb, struct genl_info *info)
+{
+	struct cfg802154_registered_device *rdev = info->user_ptr[0];
+	s8 power;
+
+	if (!info->attrs[NL802154_ATTR_TX_POWER])
+		return -EINVAL;
+
+	power = nla_get_s8(info->attrs[NL802154_ATTR_TX_POWER]);
+	return rdev_set_tx_power(rdev, power);
+}
+
 #define NL802154_FLAG_NEED_WPAN_PHY	0x01
 #define NL802154_FLAG_NEED_NETDEV	0x02
 #define NL802154_FLAG_NEED_RTNL		0x04
@@ -984,6 +996,14 @@ static const struct genl_ops nl802154_ops[] = {
 		.internal_flags = NL802154_FLAG_NEED_NETDEV |
 				  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,
+	},
 };
 
 /* initialisation/exit functions */
diff --git a/net/ieee802154/rdev-ops.h b/net/ieee802154/rdev-ops.h
index 7c46732..3de05a8 100644
--- a/net/ieee802154/rdev-ops.h
+++ b/net/ieee802154/rdev-ops.h
@@ -91,6 +91,13 @@ rdev_set_lbt_mode(struct cfg802154_registered_device *rdev,
 		  struct wpan_dev *wpan_dev, bool mode)
 {
 	return rdev->ops->set_lbt_mode(&rdev->wpan_phy, wpan_dev, mode);
+
 }
 
+static inline int
+rdev_set_tx_power(struct cfg802154_registered_device *rdev,
+		  u8 power)
+{
+	return rdev->ops->set_tx_power(&rdev->wpan_phy, power);
+}
 #endif /* __CFG802154_RDEV_OPS */
diff --git a/net/mac802154/cfg.c b/net/mac802154/cfg.c
index 5d9f68c..dde26f1 100644
--- a/net/mac802154/cfg.c
+++ b/net/mac802154/cfg.c
@@ -212,6 +212,24 @@ ieee802154_set_lbt_mode(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev,
 	return 0;
 }
 
+static int
+ieee802154_set_tx_power(struct wpan_phy *wpan_phy, s8 power)
+{
+	struct ieee802154_local *local = wpan_phy_priv(wpan_phy);
+	int ret;
+
+	ASSERT_RTNL();
+
+	if (!(local->hw.flags & IEEE802154_HW_TXPOWER))
+		return -EOPNOTSUPP;
+
+	ret = drv_set_tx_power(local, power);
+	if (!ret)
+		wpan_phy->transmit_power = power;
+
+	return ret;
+}
+
 const struct cfg802154_ops mac802154_config_ops = {
 	.add_virtual_intf_deprecated = ieee802154_add_iface_deprecated,
 	.del_virtual_intf_deprecated = ieee802154_del_iface_deprecated,
@@ -225,4 +243,5 @@ const struct cfg802154_ops mac802154_config_ops = {
 	.set_max_csma_backoffs = ieee802154_set_max_csma_backoffs,
 	.set_max_frame_retries = ieee802154_set_max_frame_retries,
 	.set_lbt_mode = ieee802154_set_lbt_mode,
+	.set_tx_power = ieee802154_set_tx_power,
 };
-- 
1.7.9.5


             reply	other threads:[~2015-03-20  7:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-20  7:22 Varka Bhadram [this message]
2015-03-20  7:22 ` [PATCH bluetooth-next 2/3] cc2520: add set transmit power support Varka Bhadram
2015-03-20  9:19   ` Stefan Schmidt
2015-03-20 16:03     ` Alexander Aring
2015-03-20 15:30   ` Alexander Aring
2015-03-23  3:34     ` Varka Bhadram
2015-03-20  7:22 ` [PATCH bluetooth-next 3/3] cc2520: fix in updated register settings Varka Bhadram
2015-03-20 15:38   ` Alexander Aring
2015-03-20 15:28 ` [PATCH bluetooth-next 1/3] ieee802154: add set transmit power support Alexander Aring
2015-03-23  3:33   ` Varka Bhadram

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1426836141-21528-1-git-send-email-varkab@cdac.in \
    --to=varkabhadram@gmail.com \
    --cc=alex.aring@gmail.com \
    --cc=linux-wpan@vger.kernel.org \
    --cc=varkab@cdac.in \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.