]> git.karo-electronics.de Git - linux-beck.git/commitdiff
ieee802154: rework cca setting
authorAlexander Aring <alex.aring@gmail.com>
Wed, 10 Dec 2014 14:33:12 +0000 (15:33 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 18 Dec 2014 23:19:23 +0000 (00:19 +0100)
The current cca setting handle is a driver specific call. We need to
introduce some 802.15.4 specific layer and mapping 802.15.4 cca modes to
driver specific ones inside the 802.15.4 driver. This patch will add
such 802.15.4 layer and mapping the cca settings to driver specific ones.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
drivers/net/ieee802154/at86rf230.c
include/net/cfg802154.h
include/net/ieee802154_netdev.h
include/net/mac802154.h
net/ieee802154/nl-mac.c
net/ieee802154/nl802154.c
net/ieee802154/sysfs.c
net/mac802154/driver-ops.h
net/mac802154/mac_cmd.c

index 1c0135620c62261dca42b32c3958d43c3dca3ded..1ac46ba41fd8a85c09a7094f9fbd704e73f8a286 100644 (file)
@@ -1146,11 +1146,37 @@ at86rf230_set_lbt(struct ieee802154_hw *hw, bool on)
 }
 
 static int
-at86rf230_set_cca_mode(struct ieee802154_hw *hw, u8 mode)
+at86rf230_set_cca_mode(struct ieee802154_hw *hw,
+                      const struct wpan_phy_cca *cca)
 {
        struct at86rf230_local *lp = hw->priv;
+       u8 val;
 
-       return at86rf230_write_subreg(lp, SR_CCA_MODE, mode);
+       /* mapping 802.15.4 to driver spec */
+       switch (cca->mode) {
+       case NL802154_CCA_ENERGY:
+               val = 1;
+               break;
+       case NL802154_CCA_CARRIER:
+               val = 2;
+               break;
+       case NL802154_CCA_ENERGY_CARRIER:
+               switch (cca->opt) {
+               case NL802154_CCA_OPT_ENERGY_CARRIER_AND:
+                       val = 3;
+                       break;
+               case NL802154_CCA_OPT_ENERGY_CARRIER_OR:
+                       val = 0;
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return at86rf230_write_subreg(lp, SR_CCA_MODE, val);
 }
 
 static int
index 7f713acfa106c9bd564b4c748a1d9b7b8978d8ae..6ee2618ac78a66913367771603a422146fa798b7 100644 (file)
@@ -56,6 +56,11 @@ struct cfg802154_ops {
                                struct wpan_dev *wpan_dev, bool mode);
 };
 
+struct wpan_phy_cca {
+       enum nl802154_cca_modes mode;
+       enum nl802154_cca_opts opt;
+};
+
 struct wpan_phy {
        struct mutex pib_lock;
 
@@ -76,7 +81,7 @@ struct wpan_phy {
        u8 current_page;
        u32 channels_supported[IEEE802154_MAX_PAGE + 1];
        s8 transmit_power;
-       u8 cca_mode;
+       struct wpan_phy_cca cca;
 
        __le64 perm_extended_addr;
 
index 83bb8a73d23c0f056b10a8c9061997a7b98e02a9..94a297052442600acff26e86404fec2afbb27d5a 100644 (file)
@@ -28,6 +28,8 @@
 #include <linux/skbuff.h>
 #include <linux/ieee802154.h>
 
+#include <net/cfg802154.h>
+
 struct ieee802154_sechdr {
 #if defined(__LITTLE_ENDIAN_BITFIELD)
        u8 level:3,
@@ -337,7 +339,7 @@ struct ieee802154_mac_params {
        s8 frame_retries;
 
        bool lbt;
-       u8 cca_mode;
+       struct wpan_phy_cca cca;
        s32 cca_ed_level;
 };
 
index c823d910b46ca7da89866226ba5e1be7c7c93529..8506478117496c971f19ec07eb00625b4b847498 100644 (file)
@@ -20,6 +20,8 @@
 #include <linux/ieee802154.h>
 #include <linux/skbuff.h>
 
+#include <net/cfg802154.h>
+
 /* General MAC frame format:
  *  2 bytes: Frame Control
  *  1 byte:  Sequence Number
@@ -212,7 +214,8 @@ struct ieee802154_ops {
                                            unsigned long changed);
        int             (*set_txpower)(struct ieee802154_hw *hw, int db);
        int             (*set_lbt)(struct ieee802154_hw *hw, bool on);
-       int             (*set_cca_mode)(struct ieee802154_hw *hw, u8 mode);
+       int             (*set_cca_mode)(struct ieee802154_hw *hw,
+                                       const struct wpan_phy_cca *cca);
        int             (*set_cca_ed_level)(struct ieee802154_hw *hw,
                                            s32 level);
        int             (*set_csma_params)(struct ieee802154_hw *hw,
index cd919493c976000e6b5cd206014110500e68886e..3c902e9516fb69dc94508ac1f77cda79d4095d16 100644 (file)
@@ -121,7 +121,7 @@ static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,
                               params.transmit_power) ||
                    nla_put_u8(msg, IEEE802154_ATTR_LBT_ENABLED, params.lbt) ||
                    nla_put_u8(msg, IEEE802154_ATTR_CCA_MODE,
-                              params.cca_mode) ||
+                              params.cca.mode) ||
                    nla_put_s32(msg, IEEE802154_ATTR_CCA_ED_LEVEL,
                                params.cca_ed_level) ||
                    nla_put_u8(msg, IEEE802154_ATTR_CSMA_RETRIES,
@@ -516,7 +516,7 @@ int ieee802154_set_macparams(struct sk_buff *skb, struct genl_info *info)
                params.lbt = nla_get_u8(info->attrs[IEEE802154_ATTR_LBT_ENABLED]);
 
        if (info->attrs[IEEE802154_ATTR_CCA_MODE])
-               params.cca_mode = nla_get_u8(info->attrs[IEEE802154_ATTR_CCA_MODE]);
+               params.cca.mode = nla_get_u8(info->attrs[IEEE802154_ATTR_CCA_MODE]);
 
        if (info->attrs[IEEE802154_ATTR_CCA_ED_LEVEL])
                params.cca_ed_level = nla_get_s32(info->attrs[IEEE802154_ATTR_CCA_ED_LEVEL]);
index 8896477446977a7b4fdab732aec1308c60a46d8b..1efbe42500248c885607cbd420be85760220d834 100644 (file)
@@ -291,7 +291,7 @@ static int nl802154_send_wpan_phy(struct cfg802154_registered_device *rdev,
 
        /* cca mode */
        if (nla_put_u8(msg, NL802154_ATTR_CCA_MODE,
-                      rdev->wpan_phy.cca_mode))
+                      rdev->wpan_phy.cca.mode))
                goto nla_put_failure;
 
        if (nla_put_s8(msg, NL802154_ATTR_TX_POWER,
index 1613b9c65dfa15aafd154042e60abc44517bc9d6..dff55c2d87f34fb8304f7b19d321bc3a08813ee7 100644 (file)
@@ -68,7 +68,7 @@ static DEVICE_ATTR_RO(name)
 MASTER_SHOW(current_channel, "%d");
 MASTER_SHOW(current_page, "%d");
 MASTER_SHOW(transmit_power, "%d +- 1 dB");
-MASTER_SHOW(cca_mode, "%d");
+MASTER_SHOW_COMPLEX(cca_mode, "%d", phy->cca.mode);
 
 static ssize_t channels_supported_show(struct device *dev,
                                       struct device_attribute *attr,
index f21e864613d09b6d02c4ffe8f2b7e72e78b75e16..98180a9fff4adc565f7ac9fe7fe711ef549396da 100644 (file)
@@ -70,7 +70,8 @@ static inline int drv_set_tx_power(struct ieee802154_local *local, s8 dbm)
        return local->ops->set_txpower(&local->hw, dbm);
 }
 
-static inline int drv_set_cca_mode(struct ieee802154_local *local, u8 cca_mode)
+static inline int drv_set_cca_mode(struct ieee802154_local *local,
+                                  const struct wpan_phy_cca *cca)
 {
        might_sleep();
 
@@ -79,7 +80,7 @@ static inline int drv_set_cca_mode(struct ieee802154_local *local, u8 cca_mode)
                return -EOPNOTSUPP;
        }
 
-       return local->ops->set_cca_mode(&local->hw, cca_mode);
+       return local->ops->set_cca_mode(&local->hw, cca);
 }
 
 static inline int drv_set_lbt_mode(struct ieee802154_local *local, bool mode)
index 6aacb181688961178bab9849c23425a7a3e25478..bdccb4ecd30fed81fec03a00c1a3b6452024fcbb 100644 (file)
@@ -81,7 +81,7 @@ static int mac802154_set_mac_params(struct net_device *dev,
 
        /* PHY */
        wpan_dev->wpan_phy->transmit_power = params->transmit_power;
-       wpan_dev->wpan_phy->cca_mode = params->cca_mode;
+       wpan_dev->wpan_phy->cca = params->cca;
        wpan_dev->wpan_phy->cca_ed_level = params->cca_ed_level;
 
        /* MAC */
@@ -98,7 +98,7 @@ static int mac802154_set_mac_params(struct net_device *dev,
        }
 
        if (local->hw.flags & IEEE802154_HW_CCA_MODE) {
-               ret = drv_set_cca_mode(local, params->cca_mode);
+               ret = drv_set_cca_mode(local, &params->cca);
                if (ret < 0)
                        return ret;
        }
@@ -122,7 +122,7 @@ static void mac802154_get_mac_params(struct net_device *dev,
 
        /* PHY */
        params->transmit_power = wpan_dev->wpan_phy->transmit_power;
-       params->cca_mode = wpan_dev->wpan_phy->cca_mode;
+       params->cca = wpan_dev->wpan_phy->cca;
        params->cca_ed_level = wpan_dev->wpan_phy->cca_ed_level;
 
        /* MAC */