1 // SPDX-License-Identifier: GPL-2.0-only 1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 2 /* 3 * MAC commands interface 3 * MAC commands interface 4 * 4 * 5 * Copyright 2007-2012 Siemens AG 5 * Copyright 2007-2012 Siemens AG 6 * 6 * 7 * Written by: 7 * Written by: 8 * Sergey Lapin <slapin@ossfans.org> 8 * Sergey Lapin <slapin@ossfans.org> 9 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.c 9 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 10 * Alexander Smirnov <alex.bluesman.smirnov@gm 10 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com> 11 */ 11 */ 12 12 13 #include <linux/skbuff.h> 13 #include <linux/skbuff.h> 14 #include <linux/if_arp.h> 14 #include <linux/if_arp.h> 15 #include <linux/ieee802154.h> 15 #include <linux/ieee802154.h> 16 16 17 #include <net/ieee802154_netdev.h> 17 #include <net/ieee802154_netdev.h> 18 #include <net/cfg802154.h> 18 #include <net/cfg802154.h> 19 #include <net/mac802154.h> 19 #include <net/mac802154.h> 20 20 21 #include "ieee802154_i.h" 21 #include "ieee802154_i.h" 22 #include "driver-ops.h" 22 #include "driver-ops.h" 23 23 24 static int mac802154_mlme_start_req(struct net 24 static int mac802154_mlme_start_req(struct net_device *dev, 25 struct iee 25 struct ieee802154_addr *addr, 26 u8 channel 26 u8 channel, u8 page, 27 u8 bcn_ord 27 u8 bcn_ord, u8 sf_ord, 28 u8 pan_coo 28 u8 pan_coord, u8 blx, 29 u8 coord_r 29 u8 coord_realign) 30 { 30 { 31 struct ieee802154_llsec_params params; 31 struct ieee802154_llsec_params params; 32 int changed = 0; 32 int changed = 0; 33 33 34 ASSERT_RTNL(); 34 ASSERT_RTNL(); 35 35 36 BUG_ON(addr->mode != IEEE802154_ADDR_S 36 BUG_ON(addr->mode != IEEE802154_ADDR_SHORT); 37 37 38 dev->ieee802154_ptr->pan_id = addr->pa 38 dev->ieee802154_ptr->pan_id = addr->pan_id; 39 dev->ieee802154_ptr->short_addr = addr 39 dev->ieee802154_ptr->short_addr = addr->short_addr; 40 mac802154_dev_set_page_channel(dev, pa 40 mac802154_dev_set_page_channel(dev, page, channel); 41 41 42 params.pan_id = addr->pan_id; 42 params.pan_id = addr->pan_id; 43 changed |= IEEE802154_LLSEC_PARAM_PAN_ 43 changed |= IEEE802154_LLSEC_PARAM_PAN_ID; 44 44 45 params.hwaddr = ieee802154_devaddr_fro 45 params.hwaddr = ieee802154_devaddr_from_raw(dev->dev_addr); 46 changed |= IEEE802154_LLSEC_PARAM_HWAD 46 changed |= IEEE802154_LLSEC_PARAM_HWADDR; 47 47 48 params.coord_hwaddr = params.hwaddr; 48 params.coord_hwaddr = params.hwaddr; 49 changed |= IEEE802154_LLSEC_PARAM_COOR 49 changed |= IEEE802154_LLSEC_PARAM_COORD_HWADDR; 50 50 51 params.coord_shortaddr = addr->short_a 51 params.coord_shortaddr = addr->short_addr; 52 changed |= IEEE802154_LLSEC_PARAM_COOR 52 changed |= IEEE802154_LLSEC_PARAM_COORD_SHORTADDR; 53 53 54 return mac802154_set_params(dev, ¶ 54 return mac802154_set_params(dev, ¶ms, changed); 55 } 55 } 56 56 57 static int mac802154_set_mac_params(struct net 57 static int mac802154_set_mac_params(struct net_device *dev, 58 const stru 58 const struct ieee802154_mac_params *params) 59 { 59 { 60 struct ieee802154_sub_if_data *sdata = 60 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); 61 struct ieee802154_local *local = sdata 61 struct ieee802154_local *local = sdata->local; 62 struct wpan_dev *wpan_dev = &sdata->wp 62 struct wpan_dev *wpan_dev = &sdata->wpan_dev; 63 int ret; 63 int ret; 64 64 65 ASSERT_RTNL(); 65 ASSERT_RTNL(); 66 66 67 /* PHY */ 67 /* PHY */ 68 wpan_dev->wpan_phy->transmit_power = p 68 wpan_dev->wpan_phy->transmit_power = params->transmit_power; 69 wpan_dev->wpan_phy->cca = params->cca; 69 wpan_dev->wpan_phy->cca = params->cca; 70 wpan_dev->wpan_phy->cca_ed_level = par 70 wpan_dev->wpan_phy->cca_ed_level = params->cca_ed_level; 71 71 72 /* MAC */ 72 /* MAC */ 73 wpan_dev->min_be = params->min_be; 73 wpan_dev->min_be = params->min_be; 74 wpan_dev->max_be = params->max_be; 74 wpan_dev->max_be = params->max_be; 75 wpan_dev->csma_retries = params->csma_ 75 wpan_dev->csma_retries = params->csma_retries; 76 wpan_dev->frame_retries = params->fram 76 wpan_dev->frame_retries = params->frame_retries; 77 wpan_dev->lbt = params->lbt; 77 wpan_dev->lbt = params->lbt; 78 78 79 if (local->hw.phy->flags & WPAN_PHY_FL 79 if (local->hw.phy->flags & WPAN_PHY_FLAG_TXPOWER) { 80 ret = drv_set_tx_power(local, 80 ret = drv_set_tx_power(local, params->transmit_power); 81 if (ret < 0) 81 if (ret < 0) 82 return ret; 82 return ret; 83 } 83 } 84 84 85 if (local->hw.phy->flags & WPAN_PHY_FL 85 if (local->hw.phy->flags & WPAN_PHY_FLAG_CCA_MODE) { 86 ret = drv_set_cca_mode(local, 86 ret = drv_set_cca_mode(local, ¶ms->cca); 87 if (ret < 0) 87 if (ret < 0) 88 return ret; 88 return ret; 89 } 89 } 90 90 91 if (local->hw.phy->flags & WPAN_PHY_FL 91 if (local->hw.phy->flags & WPAN_PHY_FLAG_CCA_ED_LEVEL) { 92 ret = drv_set_cca_ed_level(loc 92 ret = drv_set_cca_ed_level(local, params->cca_ed_level); 93 if (ret < 0) 93 if (ret < 0) 94 return ret; 94 return ret; 95 } 95 } 96 96 97 return 0; 97 return 0; 98 } 98 } 99 99 100 static void mac802154_get_mac_params(struct ne 100 static void mac802154_get_mac_params(struct net_device *dev, 101 struct ie 101 struct ieee802154_mac_params *params) 102 { 102 { 103 struct ieee802154_sub_if_data *sdata = 103 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); 104 struct wpan_dev *wpan_dev = &sdata->wp 104 struct wpan_dev *wpan_dev = &sdata->wpan_dev; 105 105 106 ASSERT_RTNL(); 106 ASSERT_RTNL(); 107 107 108 /* PHY */ 108 /* PHY */ 109 params->transmit_power = wpan_dev->wpa 109 params->transmit_power = wpan_dev->wpan_phy->transmit_power; 110 params->cca = wpan_dev->wpan_phy->cca; 110 params->cca = wpan_dev->wpan_phy->cca; 111 params->cca_ed_level = wpan_dev->wpan_ 111 params->cca_ed_level = wpan_dev->wpan_phy->cca_ed_level; 112 112 113 /* MAC */ 113 /* MAC */ 114 params->min_be = wpan_dev->min_be; 114 params->min_be = wpan_dev->min_be; 115 params->max_be = wpan_dev->max_be; 115 params->max_be = wpan_dev->max_be; 116 params->csma_retries = wpan_dev->csma_ 116 params->csma_retries = wpan_dev->csma_retries; 117 params->frame_retries = wpan_dev->fram 117 params->frame_retries = wpan_dev->frame_retries; 118 params->lbt = wpan_dev->lbt; 118 params->lbt = wpan_dev->lbt; 119 } 119 } 120 120 121 static const struct ieee802154_llsec_ops mac80 121 static const struct ieee802154_llsec_ops mac802154_llsec_ops = { 122 .get_params = mac802154_get_params, 122 .get_params = mac802154_get_params, 123 .set_params = mac802154_set_params, 123 .set_params = mac802154_set_params, 124 .add_key = mac802154_add_key, 124 .add_key = mac802154_add_key, 125 .del_key = mac802154_del_key, 125 .del_key = mac802154_del_key, 126 .add_dev = mac802154_add_dev, 126 .add_dev = mac802154_add_dev, 127 .del_dev = mac802154_del_dev, 127 .del_dev = mac802154_del_dev, 128 .add_devkey = mac802154_add_devkey, 128 .add_devkey = mac802154_add_devkey, 129 .del_devkey = mac802154_del_devkey, 129 .del_devkey = mac802154_del_devkey, 130 .add_seclevel = mac802154_add_seclevel 130 .add_seclevel = mac802154_add_seclevel, 131 .del_seclevel = mac802154_del_seclevel 131 .del_seclevel = mac802154_del_seclevel, 132 .lock_table = mac802154_lock_table, 132 .lock_table = mac802154_lock_table, 133 .get_table = mac802154_get_table, 133 .get_table = mac802154_get_table, 134 .unlock_table = mac802154_unlock_table 134 .unlock_table = mac802154_unlock_table, 135 }; 135 }; 136 136 137 struct ieee802154_mlme_ops mac802154_mlme_wpan 137 struct ieee802154_mlme_ops mac802154_mlme_wpan = { 138 .start_req = mac802154_mlme_start_req, 138 .start_req = mac802154_mlme_start_req, 139 139 140 .llsec = &mac802154_llsec_ops, 140 .llsec = &mac802154_llsec_ops, 141 141 142 .set_mac_params = mac802154_set_mac_pa 142 .set_mac_params = mac802154_set_mac_params, 143 .get_mac_params = mac802154_get_mac_pa 143 .get_mac_params = mac802154_get_mac_params, 144 }; 144 }; 145 145
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.