move mac address validation to core

Signed-off-by: Felix Fietkau <[email protected]>
This commit is contained in:
Felix Fietkau
2016-01-01 19:38:59 +01:00
parent 7f8b9944c9
commit 6ca2852f65
9 changed files with 26 additions and 35 deletions
+11 -2
View File
@@ -13,6 +13,7 @@
#include <linux/of.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/etherdevice.h>
#include "mt76.h"
static int
@@ -70,10 +71,10 @@ mt76_get_of_eeprom(struct mt76_dev *dev, int len)
#endif
}
#ifdef CONFIG_OF
void
mt76_eeprom_override(struct mt76_dev *dev)
{
#ifdef CONFIG_OF
struct device_node *np = dev->dev->of_node;
const __be32 *val;
int size;
@@ -88,9 +89,17 @@ mt76_eeprom_override(struct mt76_dev *dev)
val = of_get_property(np, "mediatek,5ghz", &size);
if (val)
dev->cap.has_5ghz = be32_to_cpup(val);
#endif
if (!is_valid_ether_addr(dev->macaddr)) {
eth_random_addr(dev->macaddr);
dev_printk(KERN_INFO, dev->dev,
"Invalid MAC address, using random address %pM\n",
dev->macaddr);
}
}
EXPORT_SYMBOL_GPL(mt76_eeprom_override);
#endif
int
mt76_eeprom_init(struct mt76_dev *dev, int len)
+1
View File
@@ -170,6 +170,7 @@ int mt76_register_device(struct mt76_dev *dev, bool vht,
INIT_LIST_HEAD(&dev->txwi_cache);
SET_IEEE80211_DEV(hw, dev->dev);
SET_IEEE80211_PERM_ADDR(hw, dev->macaddr);
wiphy->interface_modes =
BIT(NL80211_IFTYPE_STATION) |
+2 -9
View File
@@ -162,6 +162,7 @@ struct mt76_dev {
struct mt76_queue q_tx[__MT_TXQ_MAX];
const struct mt76_queue_ops *queue_ops;
u8 macaddr[ETH_ALEN];
u32 rev;
unsigned long state;
@@ -229,16 +230,8 @@ void mt76_unregister_device(struct mt76_dev *dev);
struct dentry *mt76_register_debugfs(struct mt76_dev *dev);
#ifdef CONFIG_OF
void mt76_eeprom_override(struct mt76_dev *dev);
#else
static inline void mt76_eeprom_override(struct mt76_dev *dev)
{
}
#endif
int mt76_eeprom_init(struct mt76_dev *dev, int len);
void mt76_eeprom_override(struct mt76_dev *dev);
static inline struct ieee80211_txq *
mtxq_to_txq(struct mt76_txq *mtxq)
-1
View File
@@ -77,7 +77,6 @@ struct mt7603_dev {
u8 tx_chains;
u8 rssi_offset[3];
u8 macaddr[ETH_ALEN];
struct mt7603_mcu mcu;
struct mt76_queue q_rx;
+3 -3
View File
@@ -229,7 +229,9 @@ mt7603_init_hardware(struct mt7603_dev *dev)
return ret;
dev->mt76.cap.has_2ghz = true;
memcpy(dev->macaddr, dev->mt76.eeprom.data + MT_EE_MAC_ADDR, ETH_ALEN);
memcpy(dev->mt76.macaddr, dev->mt76.eeprom.data + MT_EE_MAC_ADDR,
ETH_ALEN);
mt76_eeprom_override(&dev->mt76);
ret = mt7603_dma_init(dev);
if (ret)
@@ -331,8 +333,6 @@ int mt7603_register_device(struct mt7603_dev *dev)
hw->sta_data_size = sizeof(struct mt7603_sta);
hw->vif_data_size = sizeof(struct mt7603_vif);
SET_IEEE80211_PERM_ADDR(hw, dev->macaddr);
wiphy->iface_combinations = if_comb;
wiphy->n_iface_combinations = ARRAY_SIZE(if_comb);
-1
View File
@@ -89,7 +89,6 @@ struct mt76x2_rate_power {
struct mt76x2_dev {
struct mt76_dev mt76; /* must be first */
u8 macaddr[ETH_ALEN];
struct mac_address macaddr_list[8];
struct mutex mutex;
+2 -10
View File
@@ -11,7 +11,6 @@
* GNU General Public License for more details.
*/
#include <linux/etherdevice.h>
#include <asm/unaligned.h>
#include "mt76x2.h"
#include "mt76x2_eeprom.h"
@@ -34,7 +33,7 @@ mt76x2_eeprom_get_macaddr(struct mt76x2_dev *dev)
{
void *src = dev->mt76.eeprom.data + MT_EE_MAC_ADDR;
memcpy(dev->macaddr, src, ETH_ALEN);
memcpy(dev->mt76.macaddr, src, ETH_ALEN);
return 0;
}
@@ -617,15 +616,8 @@ int mt76x2_eeprom_init(struct mt76x2_dev *dev)
return ret;
mt76x2_eeprom_parse_hw_cap(dev);
mt76_eeprom_override(&dev->mt76);
mt76x2_eeprom_get_macaddr(dev);
if (!is_valid_ether_addr(dev->macaddr)) {
eth_random_addr(dev->macaddr);
dev_printk(KERN_INFO, dev->mt76.dev,
"Invalid MAC address, using random address %pM\n",
dev->macaddr);
}
mt76_eeprom_override(&dev->mt76);
return 0;
}
+6 -8
View File
@@ -185,6 +185,7 @@ mt76x2_init_beacon_offsets(struct mt76x2_dev *dev)
int mt76x2_mac_reset(struct mt76x2_dev *dev, bool hard)
{
static const u8 null_addr[ETH_ALEN] = {};
const u8 *macaddr = dev->mt76.macaddr;
u32 val;
int i, k;
@@ -224,11 +225,11 @@ int mt76x2_mac_reset(struct mt76x2_dev *dev, bool hard)
mt76_wr(dev, MT_MCU_CLOCK_CTL, 0x1401);
mt76_clear(dev, MT_FCE_L2_STUFF, MT_FCE_L2_STUFF_WR_MPDU_LEN_EN);
mt76_wr(dev, MT_MAC_ADDR_DW0, get_unaligned_le32(dev->macaddr));
mt76_wr(dev, MT_MAC_ADDR_DW1, get_unaligned_le16(dev->macaddr + 4));
mt76_wr(dev, MT_MAC_ADDR_DW0, get_unaligned_le32(macaddr));
mt76_wr(dev, MT_MAC_ADDR_DW1, get_unaligned_le16(macaddr + 4));
mt76_wr(dev, MT_MAC_BSSID_DW0, get_unaligned_le32(dev->macaddr));
mt76_wr(dev, MT_MAC_BSSID_DW1, get_unaligned_le16(dev->macaddr + 4) |
mt76_wr(dev, MT_MAC_BSSID_DW0, get_unaligned_le32(macaddr));
mt76_wr(dev, MT_MAC_BSSID_DW1, get_unaligned_le16(macaddr + 4) |
MT76_SET(MT_MAC_BSSID_DW1_MBSS_MODE, 3) | /* 8 beacons */
MT_MAC_BSSID_DW1_MBSS_LOCAL_BIT);
@@ -662,12 +663,9 @@ int mt76x2_register_device(struct mt76x2_dev *dev)
hw->sta_data_size = sizeof(struct mt76x2_sta);
hw->vif_data_size = sizeof(struct mt76x2_vif);
dev->macaddr[0] &= ~BIT(1);
SET_IEEE80211_PERM_ADDR(hw, dev->macaddr);
for (i = 0; i < ARRAY_SIZE(dev->macaddr_list); i++) {
u8 *addr = dev->macaddr_list[i].addr;
memcpy(addr, dev->macaddr, ETH_ALEN);
memcpy(addr, dev->mt76.macaddr, ETH_ALEN);
if (!i)
continue;
+1 -1
View File
@@ -61,7 +61,7 @@ mt76x2_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
int ret = 0;
if (vif->addr[0] & BIT(1))
idx = 1 + (((dev->macaddr[0] ^ vif->addr[0]) >> 2) & 7);
idx = 1 + (((dev->mt76.macaddr[0] ^ vif->addr[0]) >> 2) & 7);
/*
* Client mode typically only has one configurable BSSID register,