From: Alexander Aring <alex.aring@gmail.com>
To: linux-wpan@vger.kernel.org
Cc: kernel@pengutronix.de, Alexander Aring <alex.aring@gmail.com>
Subject: [PATCHv2 wpan-next 15/16] ieee802154: check transmit power before driver layer
Date: Wed, 6 May 2015 13:40:27 +0200 [thread overview]
Message-ID: <1430912428-17284-16-git-send-email-alex.aring@gmail.com> (raw)
In-Reply-To: <1430912428-17284-1-git-send-email-alex.aring@gmail.com>
This patch moves the validation check of transmit power mbm values to
the netlink layer by using the callback to get all transmit power levels
mbm values.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
drivers/net/ieee802154/at86rf230.c | 22 +++-----------------
net/mac802154/mac_cmd.c | 41 ++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 19 deletions(-)
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index 165c4cd..2484f16 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -1225,17 +1225,7 @@ at86rf23x_set_txpower(struct at86rf230_local *lp, s32 mbm)
static int
at86rf212_set_txpower(struct at86rf230_local *lp, s32 mbm)
{
- s8 db = mbm / 100;
- /* typical maximum output is 5dBm with RG_PHY_TX_PWR 0x60, lower five
- * bits decrease power in 1dB steps. 0x60 represents extra PA gain of
- * 0dB.
- * thus, supported values for db range from -26 to 5, for 31dB of
- * reduction to 0dB of reduction.
- */
- if (db > 5 || db < -26)
- return -EINVAL;
-
- return at86rf230_write_subreg(lp, SR_TX_PWR_212, -(db - 5));
+ return at86rf230_write_subreg(lp, SR_TX_PWR_212, -((mbm / 100) - 5));
}
static int
@@ -1321,15 +1311,9 @@ static int
at86rf230_set_cca_ed_level(struct ieee802154_hw *hw, s32 mbm)
{
struct at86rf230_local *lp = hw->priv;
- s32 level = mbm / 100;
-
- /* backwards compatible for old interface, should be removed */
- if (level < lp->data->rssi_base_val ||
- level > lp->data->rssi_base_val + 2 * 0xF)
- return -EINVAL;
+ s32 val = ((mbm / 100) - lp->data->rssi_base_val) / 2;
- return at86rf230_write_subreg(lp, SR_CCA_ED_THRES,
- (level - lp->data->rssi_base_val) / 2);
+ return at86rf230_write_subreg(lp, SR_CCA_ED_THRES, val);
}
#define AT86RF230_MAX_ED_LEVELS_IDX 0xF
diff --git a/net/mac802154/mac_cmd.c b/net/mac802154/mac_cmd.c
index bdccb4e..f09d8fb 100644
--- a/net/mac802154/mac_cmd.c
+++ b/net/mac802154/mac_cmd.c
@@ -76,6 +76,7 @@ static int mac802154_set_mac_params(struct net_device *dev,
struct ieee802154_local *local = sdata->local;
struct wpan_dev *wpan_dev = &sdata->wpan_dev;
int ret;
+ s32 idx;
ASSERT_RTNL();
@@ -92,6 +93,26 @@ static int mac802154_set_mac_params(struct net_device *dev,
wpan_dev->lbt = params->lbt;
if (local->hw.flags & IEEE802154_HW_TXPOWER) {
+ bool found = false;
+ s32 pwr;
+
+ idx = 0;
+ while (1) {
+ ret = drv_get_tx_powers(local, &pwr, idx++);
+ if (ret < 0)
+ return ret;
+ else if (ret == 1)
+ break;
+
+ if (pwr == params->transmit_power) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ return -EINVAL;
+
ret = drv_set_tx_power(local, params->transmit_power);
if (ret < 0)
return ret;
@@ -104,6 +125,26 @@ static int mac802154_set_mac_params(struct net_device *dev,
}
if (local->hw.flags & IEEE802154_HW_CCA_ED_LEVEL) {
+ bool found = false;
+ s32 ed;
+
+ idx = 0;
+ while (1) {
+ ret = drv_get_cca_ed_levels(local, &ed, idx++);
+ if (ret < 0)
+ return ret;
+ else if (ret == 1)
+ break;
+
+ if (ed == params->cca_ed_level) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ return -EINVAL;
+
ret = drv_set_cca_ed_level(local, params->cca_ed_level);
if (ret < 0)
return ret;
--
2.3.7
next prev parent reply other threads:[~2015-05-06 11:41 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-06 11:40 [PATCHv2 wpan-next 00/16] ieee802154: add support for phy capabilities Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 01/16] ieee802154: change transmit power to s32 Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 02/16] ieee802154: change transmit power to mbm Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 03/16] ieee802154: change cca ed level " Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 04/16] ieee802154: introduce wpan_phy_supported Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 05/16] ieee802154: add several phy supported handling Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 06/16] mac802154: check for really changes Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 07/16] mac802154: remove check if operation is supported Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 08/16] ieee802154: add iftypes capability Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 09/16] ieee802154: add support for get tx powers Alexander Aring
2015-05-06 12:02 ` Phoebe Buckheister
2015-05-06 13:19 ` Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 10/16] ieee802154: add support for get cca ed levels Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 11/16] at86rf230: set cca_modes supported flags Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 12/16] at86rf230: add reset states of tx power level Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 13/16] at86rf230: rework tx power support Alexander Aring
2015-05-06 11:40 ` [PATCHv2 wpan-next 14/16] at86rf230: rework tx cca energy detection level Alexander Aring
2015-05-06 11:40 ` Alexander Aring [this message]
2015-05-06 11:40 ` [PATCHv2 wpan-next 16/16] nl802154: add support for dump phy capabilities Alexander Aring
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=1430912428-17284-16-git-send-email-alex.aring@gmail.com \
--to=alex.aring@gmail.com \
--cc=kernel@pengutronix.de \
--cc=linux-wpan@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox