提交 b2023ddc 编写于 作者: C Christian Lamparter 提交者: John W. Linville

p54: refactoring

Thanks to the introduction of "changed" flags, we no longer
have to do the bookkeeping of p54's firmware state for everything.
Thus we can cut down redundancy code.
Signed-off-by: NChristian Lamparter <chunkeey@web.de>
Signed-off-by: NJohn W. Linville <linville@tuxdriver.com>
上级 64c354dd
...@@ -85,7 +85,6 @@ struct p54_common { ...@@ -85,7 +85,6 @@ struct p54_common {
struct mutex conf_mutex; struct mutex conf_mutex;
u8 mac_addr[ETH_ALEN]; u8 mac_addr[ETH_ALEN];
u8 bssid[ETH_ALEN]; u8 bssid[ETH_ALEN];
u16 mac_mode;
struct pda_iq_autocal_entry *iq_autocal; struct pda_iq_autocal_entry *iq_autocal;
unsigned int iq_autocal_len; unsigned int iq_autocal_len;
struct pda_channel_output_limit *output_limit; struct pda_channel_output_limit *output_limit;
...@@ -95,7 +94,6 @@ struct p54_common { ...@@ -95,7 +94,6 @@ struct p54_common {
bool use_short_slot; bool use_short_slot;
u16 rxhw; u16 rxhw;
u8 version; u8 version;
u8 rx_antenna;
unsigned int tx_hdr_len; unsigned int tx_hdr_len;
unsigned int fw_var; unsigned int fw_var;
unsigned int fw_interface; unsigned int fw_interface;
......
...@@ -1334,11 +1334,12 @@ static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb) ...@@ -1334,11 +1334,12 @@ static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
return NETDEV_TX_BUSY; return NETDEV_TX_BUSY;
} }
static int p54_setup_mac(struct ieee80211_hw *dev, u16 mode, const u8 *bssid) static int p54_setup_mac(struct ieee80211_hw *dev)
{ {
struct p54_common *priv = dev->priv; struct p54_common *priv = dev->priv;
struct sk_buff *skb; struct sk_buff *skb;
struct p54_setup_mac *setup; struct p54_setup_mac *setup;
u16 mode;
skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*setup) + skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*setup) +
sizeof(struct p54_hdr), P54_CONTROL_TYPE_SETUP, sizeof(struct p54_hdr), P54_CONTROL_TYPE_SETUP,
...@@ -1347,14 +1348,31 @@ static int p54_setup_mac(struct ieee80211_hw *dev, u16 mode, const u8 *bssid) ...@@ -1347,14 +1348,31 @@ static int p54_setup_mac(struct ieee80211_hw *dev, u16 mode, const u8 *bssid)
return -ENOMEM; return -ENOMEM;
setup = (struct p54_setup_mac *) skb_put(skb, sizeof(*setup)); setup = (struct p54_setup_mac *) skb_put(skb, sizeof(*setup));
priv->mac_mode = mode; if (dev->conf.radio_enabled) {
switch (priv->mode) {
case NL80211_IFTYPE_STATION:
mode = P54_FILTER_TYPE_STATION;
break;
case NL80211_IFTYPE_AP:
mode = P54_FILTER_TYPE_AP;
break;
case NL80211_IFTYPE_ADHOC:
case NL80211_IFTYPE_MESH_POINT:
mode = P54_FILTER_TYPE_IBSS;
break;
default:
mode = P54_FILTER_TYPE_NONE;
break;
}
if (priv->filter_flags & FIF_PROMISC_IN_BSS)
mode |= P54_FILTER_TYPE_TRANSPARENT;
} else
mode = P54_FILTER_TYPE_RX_DISABLED;
setup->mac_mode = cpu_to_le16(mode); setup->mac_mode = cpu_to_le16(mode);
memcpy(setup->mac_addr, priv->mac_addr, ETH_ALEN); memcpy(setup->mac_addr, priv->mac_addr, ETH_ALEN);
if (!bssid) memcpy(setup->bssid, priv->bssid, ETH_ALEN);
memset(setup->bssid, ~0, ETH_ALEN); setup->rx_antenna = 2; /* automatic */
else
memcpy(setup->bssid, bssid, ETH_ALEN);
setup->rx_antenna = priv->rx_antenna;
setup->rx_align = 0; setup->rx_align = 0;
if (priv->fw_var < 0x500) { if (priv->fw_var < 0x500) {
setup->v1.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask); setup->v1.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
...@@ -1383,7 +1401,8 @@ static int p54_setup_mac(struct ieee80211_hw *dev, u16 mode, const u8 *bssid) ...@@ -1383,7 +1401,8 @@ static int p54_setup_mac(struct ieee80211_hw *dev, u16 mode, const u8 *bssid)
return 0; return 0;
} }
static int p54_set_freq(struct ieee80211_hw *dev, u16 frequency) static int p54_scan(struct ieee80211_hw *dev, u16 mode, u16 dwell,
u16 frequency)
{ {
struct p54_common *priv = dev->priv; struct p54_common *priv = dev->priv;
struct sk_buff *skb; struct sk_buff *skb;
...@@ -1400,8 +1419,8 @@ static int p54_set_freq(struct ieee80211_hw *dev, u16 frequency) ...@@ -1400,8 +1419,8 @@ static int p54_set_freq(struct ieee80211_hw *dev, u16 frequency)
chan = (struct p54_scan *) skb_put(skb, sizeof(*chan)); chan = (struct p54_scan *) skb_put(skb, sizeof(*chan));
memset(chan->padding1, 0, sizeof(chan->padding1)); memset(chan->padding1, 0, sizeof(chan->padding1));
chan->mode = cpu_to_le16(P54_SCAN_EXIT); chan->mode = cpu_to_le16(mode);
chan->dwell = cpu_to_le16(0x0); chan->dwell = cpu_to_le16(dwell);
for (i = 0; i < priv->iq_autocal_len; i++) { for (i = 0; i < priv->iq_autocal_len; i++) {
if (priv->iq_autocal[i].freq != freq) if (priv->iq_autocal[i].freq != freq)
...@@ -1644,10 +1663,14 @@ static int p54_start(struct ieee80211_hw *dev) ...@@ -1644,10 +1663,14 @@ static int p54_start(struct ieee80211_hw *dev)
err = p54_init_stats(dev); err = p54_init_stats(dev);
if (err) if (err)
goto out; goto out;
err = p54_setup_mac(dev, P54_FILTER_TYPE_NONE, NULL);
if (err) memset(priv->bssid, ~0, ETH_ALEN);
goto out;
priv->mode = NL80211_IFTYPE_MONITOR; priv->mode = NL80211_IFTYPE_MONITOR;
err = p54_setup_mac(dev);
if (err) {
priv->mode = NL80211_IFTYPE_UNSPECIFIED;
goto out;
}
out: out:
mutex_unlock(&priv->conf_mutex); mutex_unlock(&priv->conf_mutex);
...@@ -1700,27 +1723,8 @@ static int p54_add_interface(struct ieee80211_hw *dev, ...@@ -1700,27 +1723,8 @@ static int p54_add_interface(struct ieee80211_hw *dev,
} }
memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
p54_setup_mac(dev);
p54_setup_mac(dev, P54_FILTER_TYPE_NONE, NULL);
switch (conf->type) {
case NL80211_IFTYPE_STATION:
p54_setup_mac(dev, P54_FILTER_TYPE_STATION, NULL);
break;
case NL80211_IFTYPE_AP:
p54_setup_mac(dev, P54_FILTER_TYPE_AP, priv->mac_addr);
break;
case NL80211_IFTYPE_ADHOC:
case NL80211_IFTYPE_MESH_POINT:
p54_setup_mac(dev, P54_FILTER_TYPE_IBSS, NULL);
break;
default:
BUG(); /* impossible */
break;
}
p54_set_leds(dev, 1, 0, 0); p54_set_leds(dev, 1, 0, 0);
mutex_unlock(&priv->conf_mutex); mutex_unlock(&priv->conf_mutex);
return 0; return 0;
} }
...@@ -1733,9 +1737,10 @@ static void p54_remove_interface(struct ieee80211_hw *dev, ...@@ -1733,9 +1737,10 @@ static void p54_remove_interface(struct ieee80211_hw *dev,
mutex_lock(&priv->conf_mutex); mutex_lock(&priv->conf_mutex);
if (priv->cached_beacon) if (priv->cached_beacon)
p54_tx_cancel(dev, priv->cached_beacon); p54_tx_cancel(dev, priv->cached_beacon);
p54_setup_mac(dev, P54_FILTER_TYPE_NONE, NULL);
priv->mode = NL80211_IFTYPE_MONITOR; priv->mode = NL80211_IFTYPE_MONITOR;
memset(priv->mac_addr, 0, ETH_ALEN); memset(priv->mac_addr, 0, ETH_ALEN);
memset(priv->bssid, 0, ETH_ALEN);
p54_setup_mac(dev);
mutex_unlock(&priv->conf_mutex); mutex_unlock(&priv->conf_mutex);
} }
...@@ -1746,11 +1751,21 @@ static int p54_config(struct ieee80211_hw *dev, u32 changed) ...@@ -1746,11 +1751,21 @@ static int p54_config(struct ieee80211_hw *dev, u32 changed)
struct ieee80211_conf *conf = &dev->conf; struct ieee80211_conf *conf = &dev->conf;
mutex_lock(&priv->conf_mutex); mutex_lock(&priv->conf_mutex);
priv->rx_antenna = 2; /* automatic */ if (changed & IEEE80211_CONF_CHANGE_POWER)
priv->output_power = conf->power_level << 2; priv->output_power = conf->power_level << 2;
ret = p54_set_freq(dev, conf->channel->center_freq); if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) {
if (!ret) ret = p54_setup_mac(dev);
ret = p54_set_edcf(dev); if (ret)
goto out;
}
if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
ret = p54_scan(dev, P54_SCAN_EXIT, 0,
conf->channel->center_freq);
if (ret)
goto out;
}
out:
mutex_unlock(&priv->conf_mutex); mutex_unlock(&priv->conf_mutex);
return ret; return ret;
} }
...@@ -1763,36 +1778,31 @@ static int p54_config_interface(struct ieee80211_hw *dev, ...@@ -1763,36 +1778,31 @@ static int p54_config_interface(struct ieee80211_hw *dev,
int ret = 0; int ret = 0;
mutex_lock(&priv->conf_mutex); mutex_lock(&priv->conf_mutex);
switch (priv->mode) { if (conf->changed & IEEE80211_IFCC_BSSID) {
case NL80211_IFTYPE_STATION: memcpy(priv->bssid, conf->bssid, ETH_ALEN);
ret = p54_setup_mac(dev, P54_FILTER_TYPE_STATION, conf->bssid); ret = p54_setup_mac(dev);
if (ret) if (ret)
goto out; goto out;
ret = p54_set_leds(dev, 1, }
!is_multicast_ether_addr(conf->bssid), 0);
if (conf->changed & IEEE80211_IFCC_BEACON) {
ret = p54_scan(dev, P54_SCAN_EXIT, 0,
dev->conf.channel->center_freq);
if (ret) if (ret)
goto out; goto out;
memcpy(priv->bssid, conf->bssid, ETH_ALEN); ret = p54_setup_mac(dev);
break;
case NL80211_IFTYPE_AP:
case NL80211_IFTYPE_ADHOC:
case NL80211_IFTYPE_MESH_POINT:
memcpy(priv->bssid, conf->bssid, ETH_ALEN);
ret = p54_set_freq(dev, dev->conf.channel->center_freq);
if (ret) if (ret)
goto out; goto out;
ret = p54_setup_mac(dev, priv->mac_mode, priv->bssid); ret = p54_beacon_update(dev, vif);
if (ret)
goto out;
ret = p54_set_edcf(dev);
if (ret) if (ret)
goto out; goto out;
if (conf->changed & IEEE80211_IFCC_BEACON) {
ret = p54_beacon_update(dev, vif);
if (ret)
goto out;
ret = p54_set_edcf(dev);
if (ret)
goto out;
}
} }
ret = p54_set_leds(dev, 1, !is_multicast_ether_addr(priv->bssid), 0);
out: out:
mutex_unlock(&priv->conf_mutex); mutex_unlock(&priv->conf_mutex);
return ret; return ret;
...@@ -1805,25 +1815,14 @@ static void p54_configure_filter(struct ieee80211_hw *dev, ...@@ -1805,25 +1815,14 @@ static void p54_configure_filter(struct ieee80211_hw *dev,
{ {
struct p54_common *priv = dev->priv; struct p54_common *priv = dev->priv;
*total_flags &= FIF_BCN_PRBRESP_PROMISC | *total_flags &= FIF_PROMISC_IN_BSS |
FIF_PROMISC_IN_BSS | (*total_flags & FIF_PROMISC_IN_BSS) ?
FIF_FCSFAIL; FIF_FCSFAIL : 0;
priv->filter_flags = *total_flags; priv->filter_flags = *total_flags;
if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { if (changed_flags & FIF_PROMISC_IN_BSS)
if (*total_flags & FIF_BCN_PRBRESP_PROMISC) p54_setup_mac(dev);
p54_setup_mac(dev, priv->mac_mode, NULL);
else
p54_setup_mac(dev, priv->mac_mode, priv->bssid);
}
if (changed_flags & FIF_PROMISC_IN_BSS) {
if (*total_flags & FIF_PROMISC_IN_BSS)
p54_setup_mac(dev, priv->mac_mode | 0x8, NULL);
else
p54_setup_mac(dev, priv->mac_mode & ~0x8, priv->bssid);
}
} }
static int p54_conf_tx(struct ieee80211_hw *dev, u16 queue, static int p54_conf_tx(struct ieee80211_hw *dev, u16 queue,
...@@ -1920,16 +1919,17 @@ static void p54_bss_info_changed(struct ieee80211_hw *dev, ...@@ -1920,16 +1919,17 @@ static void p54_bss_info_changed(struct ieee80211_hw *dev,
priv->basic_rate_mask = (info->basic_rates << 4); priv->basic_rate_mask = (info->basic_rates << 4);
else else
priv->basic_rate_mask = info->basic_rates; priv->basic_rate_mask = info->basic_rates;
p54_setup_mac(dev, priv->mac_mode, priv->bssid); p54_setup_mac(dev);
if (priv->fw_var >= 0x500) if (priv->fw_var >= 0x500)
p54_set_freq(dev, dev->conf.channel->center_freq); p54_scan(dev, P54_SCAN_EXIT, 0,
dev->conf.channel->center_freq);
} }
if (changed & BSS_CHANGED_ASSOC) { if (changed & BSS_CHANGED_ASSOC) {
if (info->assoc) { if (info->assoc) {
priv->aid = info->aid; priv->aid = info->aid;
priv->wakeup_timer = info->beacon_int * priv->wakeup_timer = info->beacon_int *
info->dtim_period * 5; info->dtim_period * 5;
p54_setup_mac(dev, priv->mac_mode, priv->bssid); p54_setup_mac(dev);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册