Commit 58871300 authored by Ajay Singh's avatar Ajay Singh Committed by Greg Kroah-Hartman

staging: wilc1000: avoid the use of 'wilc_wfi_mon' static variable

Avoid use of static variable for monitor net_device and move it inside
wilc structure.
Signed-off-by: default avatarAjay Singh <ajay.kathat@microchip.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 5ae89078
......@@ -18,8 +18,6 @@ struct wilc_wfi_radiotap_cb_hdr {
u16 tx_flags;
} __packed;
static struct net_device *wilc_wfi_mon; /* global monitor netdev */
static u8 srcadd[6];
static u8 bssid[6];
......@@ -29,17 +27,17 @@ static u8 bssid[6];
#define TX_RADIOTAP_PRESENT ((1 << IEEE80211_RADIOTAP_RATE) | \
(1 << IEEE80211_RADIOTAP_TX_FLAGS))
void wilc_wfi_monitor_rx(u8 *buff, u32 size)
void wilc_wfi_monitor_rx(struct net_device *mon_dev, u8 *buff, u32 size)
{
u32 header, pkt_offset;
struct sk_buff *skb = NULL;
struct wilc_wfi_radiotap_hdr *hdr;
struct wilc_wfi_radiotap_cb_hdr *cb_hdr;
if (!wilc_wfi_mon)
if (!mon_dev)
return;
if (!netif_running(wilc_wfi_mon))
if (!netif_running(mon_dev))
return;
/* Get WILC header */
......@@ -94,7 +92,7 @@ void wilc_wfi_monitor_rx(u8 *buff, u32 size)
hdr->rate = 5;
}
skb->dev = wilc_wfi_mon;
skb->dev = mon_dev;
skb_reset_mac_header(skb);
skb->ip_summed = CHECKSUM_UNNECESSARY;
skb->pkt_type = PACKET_OTHERHOST;
......@@ -156,12 +154,10 @@ static netdev_tx_t wilc_wfi_mon_xmit(struct sk_buff *skb,
struct sk_buff *skb2;
struct wilc_wfi_radiotap_cb_hdr *cb_hdr;
if (!wilc_wfi_mon)
return -EFAULT;
mon_priv = netdev_priv(wilc_wfi_mon);
mon_priv = netdev_priv(dev);
if (!mon_priv)
return -EFAULT;
rtap_len = ieee80211_get_radiotap_len(skb->data);
if (skb->len < rtap_len)
return -1;
......@@ -187,7 +183,7 @@ static netdev_tx_t wilc_wfi_mon_xmit(struct sk_buff *skb,
cb_hdr->rate = 5;
cb_hdr->tx_flags = 0x0004;
skb2->dev = wilc_wfi_mon;
skb2->dev = dev;
skb_reset_mac_header(skb2);
skb2->ip_summed = CHECKSUM_UNNECESSARY;
skb2->pkt_type = PACKET_OTHERHOST;
......@@ -223,51 +219,53 @@ static const struct net_device_ops wilc_wfi_netdev_ops = {
};
struct net_device *wilc_wfi_init_mon_interface(const char *name,
struct net_device *wilc_wfi_init_mon_interface(struct wilc *wl,
const char *name,
struct net_device *real_dev)
{
struct wilc_wfi_mon_priv *priv;
/*If monitor interface is already initialized, return it*/
if (wilc_wfi_mon)
return wilc_wfi_mon;
if (wl->monitor_dev)
return wl->monitor_dev;
wilc_wfi_mon = alloc_etherdev(sizeof(struct wilc_wfi_mon_priv));
if (!wilc_wfi_mon)
wl->monitor_dev = alloc_etherdev(sizeof(struct wilc_wfi_mon_priv));
if (!wl->monitor_dev)
return NULL;
wilc_wfi_mon->type = ARPHRD_IEEE80211_RADIOTAP;
strncpy(wilc_wfi_mon->name, name, IFNAMSIZ);
wilc_wfi_mon->name[IFNAMSIZ - 1] = 0;
wilc_wfi_mon->netdev_ops = &wilc_wfi_netdev_ops;
if (register_netdevice(wilc_wfi_mon)) {
wl->monitor_dev->type = ARPHRD_IEEE80211_RADIOTAP;
strncpy(wl->monitor_dev->name, name, IFNAMSIZ);
wl->monitor_dev->name[IFNAMSIZ - 1] = 0;
wl->monitor_dev->netdev_ops = &wilc_wfi_netdev_ops;
if (register_netdevice(wl->monitor_dev)) {
netdev_err(real_dev, "register_netdevice failed\n");
return NULL;
}
priv = netdev_priv(wilc_wfi_mon);
priv = netdev_priv(wl->monitor_dev);
if (!priv)
return NULL;
priv->real_ndev = real_dev;
return wilc_wfi_mon;
return wl->monitor_dev;
}
void wilc_wfi_deinit_mon_interface(void)
void wilc_wfi_deinit_mon_interface(struct wilc *wl)
{
bool rollback_lock = false;
if (wilc_wfi_mon) {
if (wl->monitor_dev) {
if (rtnl_is_locked()) {
rtnl_unlock();
rollback_lock = true;
}
unregister_netdev(wilc_wfi_mon);
unregister_netdev(wl->monitor_dev);
if (rollback_lock) {
rtnl_lock();
rollback_lock = false;
}
wilc_wfi_mon = NULL;
wl->monitor_dev = NULL;
}
}
......@@ -920,7 +920,7 @@ static int wilc_mac_close(struct net_device *ndev)
netdev_dbg(ndev, "Deinitializing wilc1000\n");
wl->close = 1;
wilc_wlan_deinitialize(ndev);
wilc_wfi_deinit_mon_interface();
wilc_wfi_deinit_mon_interface(wl);
}
vif->mac_opened = 0;
......@@ -976,7 +976,7 @@ void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size)
for (i = 0; i < wilc->vif_num; i++) {
vif = netdev_priv(wilc->vif[i]->ndev);
if (vif->monitor_flag) {
wilc_wfi_monitor_rx(buff, size);
wilc_wfi_monitor_rx(wilc->monitor_dev, buff, size);
return;
}
}
......
......@@ -1617,7 +1617,8 @@ static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,
struct net_device *new_ifc;
if (type == NL80211_IFTYPE_MONITOR) {
new_ifc = wilc_wfi_init_mon_interface(name, vif->ndev);
new_ifc = wilc_wfi_init_mon_interface(vif->wilc, name,
vif->ndev);
if (new_ifc) {
vif = netdev_priv(priv->wdev->netdev);
vif->monitor_flag = 1;
......
......@@ -13,9 +13,10 @@ struct wireless_dev *wilc_create_wiphy(struct net_device *net,
void wilc_free_wiphy(struct net_device *net);
void wilc_deinit_host_int(struct net_device *net);
int wilc_init_host_int(struct net_device *net);
void wilc_wfi_monitor_rx(u8 *buff, u32 size);
void wilc_wfi_deinit_mon_interface(void);
struct net_device *wilc_wfi_init_mon_interface(const char *name,
void wilc_wfi_monitor_rx(struct net_device *mon_dev, u8 *buff, u32 size);
void wilc_wfi_deinit_mon_interface(struct wilc *wl);
struct net_device *wilc_wfi_init_mon_interface(struct wilc *wl,
const char *name,
struct net_device *real_dev);
void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
u16 frame_type, bool reg);
......
......@@ -270,6 +270,7 @@ struct wilc {
enum chip_ps_states chip_ps_state;
struct wilc_cfg cfg;
void *bus_data;
struct net_device *monitor_dev;
};
struct wilc_wfi_mon_priv {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment