13 #include <linux/slab.h>
14 #include <linux/kernel.h>
15 #include <linux/if_arp.h>
16 #include <linux/netdevice.h>
17 #include <linux/rtnetlink.h>
61 drv_flush(local,
false);
71 bool working =
false, scanning =
false;
72 unsigned int led_trig_start = 0, led_trig_stop = 0;
75 #ifdef CONFIG_PROVE_LOCKING
82 if (!ieee80211_sdata_running(sdata)) {
83 sdata->
vif.bss_conf.idle =
true;
91 !sdata->
u.
mgd.associated &&
92 !sdata->
u.
mgd.auth_data &&
93 !sdata->
u.
mgd.assoc_data) {
94 sdata->
vif.bss_conf.idle =
true;
99 !sdata->
u.
ibss.ssid_len) {
100 sdata->
vif.bss_conf.idle =
true;
108 sdata->
vif.bss_conf.idle =
false;
112 if (!local->
ops->remain_on_channel) {
115 roc->
sdata->vif.bss_conf.idle =
false;
120 lockdep_is_held(&local->
mtx));
123 sdata->
vif.bss_conf.idle =
false;
133 if (!ieee80211_sdata_running(sdata))
138 if (working || scanning)
151 return ieee80211_idle_off(local,
"working");
153 return ieee80211_idle_off(local,
"scanning");
155 return ieee80211_idle_on(local);
157 return ieee80211_idle_off(local,
"in use");
167 chg = __ieee80211_recalc_idle(local);
173 static int ieee80211_change_mtu(
struct net_device *
dev,
int new_mtu)
191 static int ieee80211_change_mac(
struct net_device *dev,
void *
addr)
197 if (ieee80211_sdata_running(sdata))
208 static inline int identical_mac_addr_allowed(
int type1,
int type2)
234 if (nsdata != sdata && ieee80211_sdata_running(nsdata)) {
253 if (!ether_addr_equal(sdata->
vif.addr,
260 if (!identical_mac_addr_allowed(iftype,
269 sdata->
bss = &nsdata->
u.
ap;
278 int n_queues = sdata->
local->hw.queues;
313 #define ADJUST(_f, _s) do { \
314 if (flags & MONITOR_FLAG_##_f) \
315 local->fif_##_s += offset; \
319 ADJUST(PLCPFAIL, plcpfail);
322 ADJUST(OTHER_BSS, other_bss);
335 else if (local->
hw.queues >= IEEE80211_NUM_ACS)
336 sdata->
vif.hw_queue[
i] =
i;
338 sdata->
vif.hw_queue[
i] = 0;
343 static int ieee80211_add_virtual_monitor(
struct ieee80211_local *local)
356 sdata = kzalloc(
sizeof(*sdata) + local->
hw.vif_data_size,
GFP_KERNEL);
366 wiphy_name(local->
hw.wiphy));
368 ieee80211_set_default_queues(sdata);
370 ret = drv_add_interface(local, sdata);
377 ret = ieee80211_check_queues(sdata);
389 static void ieee80211_del_virtual_monitor(
struct ieee80211_local *local)
406 drv_remove_interface(local, sdata);
426 u32 hw_reconf_flags = 0;
428 switch (sdata->
vif.type) {
430 if (!is_valid_ether_addr(sdata->
u.
wds.remote_addr))
439 list_add(&sdata->
u.
vlan.list, &sdata->
bss->vlans);
450 sdata->
bss = &sdata->
u.
ap;
469 res = drv_start(local);
472 if (local->
ops->napi_poll)
473 napi_enable(&local->
napi);
475 hw_reconf_flags = ~0;
485 if (dev && is_zero_ether_addr(dev->
dev_addr)) {
487 local->
hw.wiphy->perm_addr,
491 if (!is_valid_ether_addr(dev->
dev_addr)) {
497 switch (sdata->
vif.type) {
512 res = ieee80211_add_virtual_monitor(local);
531 ieee80211_del_virtual_monitor(local);
533 res = drv_add_interface(local, sdata);
536 res = ieee80211_check_queues(sdata);
538 goto err_del_interface;
554 switch (sdata->
vif.type) {
584 goto err_del_interface;
594 goto err_del_interface;
597 rate_control_rate_init(sta);
615 hw_reconf_flags |= __ieee80211_recalc_idle(local);
627 netif_tx_start_all_queues(dev);
631 drv_remove_interface(local, sdata);
644 static int ieee80211_open(
struct net_device *dev)
650 if (!is_valid_ether_addr(dev->
dev_addr))
653 err = ieee80211_check_concurrent_iface(sdata, sdata->
vif.type);
666 u32 hw_reconf_flags = 0;
679 netif_tx_stop_all_queues(sdata->
dev);
719 netif_addr_lock_bh(sdata->
dev);
722 sdata->
dev->addr_len);
724 netif_addr_unlock_bh(sdata->
dev);
749 kfree(old_probe_resp);
754 dev_close(vlan->dev);
755 WARN_ON(!list_empty(&sdata->
u.ap.vlans));
758 local->total_ps_buffered -= skb_queue_len(&sdata->
u.ap.ps_bc_buf);
767 switch (sdata->
vif.type) {
782 ieee80211_del_virtual_monitor(local);
819 drv_remove_interface(local, sdata);
825 hw_reconf_flags |= __ieee80211_recalc_idle(local);
831 if (local->
ops->napi_poll)
832 napi_disable(&local->
napi);
852 skb_queue_walk_safe(&local->
pending[i], skb, tmp) {
855 __skb_unlink(skb, &local->
pending[i]);
863 ieee80211_add_virtual_monitor(local);
866 static int ieee80211_stop(
struct net_device *dev)
870 ieee80211_do_stop(sdata,
true);
875 static void ieee80211_set_multicast_list(
struct net_device *dev)
879 int allmulti, promisc, sdata_allmulti, sdata_promisc;
886 if (allmulti != sdata_allmulti) {
894 if (promisc != sdata_promisc) {
923 __skb_queue_purge(&sdata->
fragments[i].skb_list);
926 if (ieee80211_vif_is_mesh(&sdata->
vif))
933 static void ieee80211_uninit(
struct net_device *dev)
935 ieee80211_teardown_sdata(IEEE80211_DEV_TO_SUB_IF(dev));
938 static u16 ieee80211_netdev_select_queue(
struct net_device *dev,
945 .ndo_open = ieee80211_open,
946 .ndo_stop = ieee80211_stop,
947 .ndo_uninit = ieee80211_uninit,
949 .ndo_set_rx_mode = ieee80211_set_multicast_list,
950 .ndo_change_mtu = ieee80211_change_mtu,
951 .ndo_set_mac_address = ieee80211_change_mac,
952 .ndo_select_queue = ieee80211_netdev_select_queue,
955 static u16 ieee80211_monitor_select_queue(
struct net_device *dev,
963 if (local->
hw.queues < IEEE80211_NUM_ACS)
976 .ndo_open = ieee80211_open,
977 .ndo_stop = ieee80211_stop,
978 .ndo_uninit = ieee80211_uninit,
980 .ndo_set_rx_mode = ieee80211_set_multicast_list,
981 .ndo_change_mtu = ieee80211_change_mtu,
983 .ndo_select_queue = ieee80211_monitor_select_queue,
986 static void ieee80211_if_setup(
struct net_device *dev)
1003 if (!ieee80211_sdata_running(sdata))
1014 "interface work scheduled while going to suspend\n"))
1022 ra_tid = (
void *)&skb->cb;
1026 ra_tid = (
void *)&skb->cb;
1036 switch (mgmt->
u.action.u.addba_req.action_code) {
1039 local, sta, mgmt, len);
1077 u16 tid = *ieee80211_get_qos_ctl(hdr) &
1086 }
else switch (sdata->
vif.type) {
1094 if (!ieee80211_vif_is_mesh(&sdata->
vif))
1099 WARN(1,
"frame for unexpected interface type");
1107 switch (sdata->
vif.type) {
1115 if (!ieee80211_vif_is_mesh(&sdata->
vif))
1132 memset(&sdata->
u, 0,
sizeof(sdata->
u));
1136 sdata->
vif.p2p =
false;
1146 sdata->
dev->netdev_ops = &ieee80211_dataif_ops;
1157 sdata->
vif.p2p =
true;
1160 skb_queue_head_init(&sdata->
u.
ap.ps_bc_buf);
1161 INIT_LIST_HEAD(&sdata->
u.
ap.vlans);
1166 sdata->
vif.p2p =
true;
1175 if (ieee80211_vif_is_mesh(&sdata->
vif))
1180 sdata->
dev->netdev_ops = &ieee80211_monitorif_ops;
1207 if (!local->
ops->change_interface)
1210 switch (sdata->
vif.type) {
1248 ret = ieee80211_check_concurrent_iface(sdata, internal_type);
1252 ieee80211_do_stop(sdata,
false);
1254 ieee80211_teardown_sdata(sdata);
1256 ret = drv_change_interface(local, sdata, internal_type, p2p);
1258 type = sdata->
vif.type;
1265 ieee80211_check_queues(sdata);
1267 ieee80211_setup_sdata(sdata, type);
1270 WARN(err,
"type change: do_open returned %d", err);
1282 if (type == ieee80211_vif_type_p2p(&sdata->
vif))
1290 if (ieee80211_sdata_running(sdata)) {
1291 ret = ieee80211_runtime_change_iftype(sdata, type);
1296 ieee80211_teardown_sdata(sdata);
1297 ieee80211_setup_sdata(sdata, type);
1301 sdata->
vif.bss_conf.basic_rates =
1303 sdata->
local->oper_channel->band);
1306 sdata->
u.
mgd.use_4addr =
false;
1323 if (is_zero_ether_addr(local->
hw.wiphy->addr_mask) &&
1324 local->
hw.wiphy->n_addresses <= 1)
1350 if (!ieee80211_sdata_running(sdata))
1359 for (i = 0; i < local->
hw.wiphy->n_addresses; i++) {
1363 if (
memcmp(local->
hw.wiphy->addresses[i].addr,
1372 local->
hw.wiphy->addresses[i].addr,
1379 if (is_zero_ether_addr(local->
hw.wiphy->addr_mask))
1382 m = local->
hw.wiphy->addr_mask;
1383 mask = ((
u64)m[0] << 5*8) | ((
u64)m[1] << 4*8) |
1384 ((
u64)m[2] << 3*8) | ((
u64)m[3] << 2*8) |
1385 ((
u64)m[4] << 1*8) | ((
u64)m[5] << 0*8);
1387 if (__ffs64(mask) +
hweight64(mask) != fls64(mask)) {
1393 m = local->
hw.wiphy->perm_addr;
1394 start = ((
u64)m[0] << 5*8) | ((
u64)m[1] << 4*8) |
1395 ((
u64)m[2] << 3*8) | ((
u64)m[3] << 2*8) |
1396 ((
u64)m[4] << 1*8) | ((
u64)m[5] << 0*8);
1398 inc = 1ULL<<__ffs64(mask);
1399 val = (start &
mask);
1400 addr = (start & ~mask) | (val & mask);
1404 tmp_addr[5] = addr >> 0*8;
1405 tmp_addr[4] = addr >> 1*8;
1406 tmp_addr[3] = addr >> 2*8;
1407 tmp_addr[2] = addr >> 3*8;
1408 tmp_addr[1] = addr >> 4*8;
1409 tmp_addr[0] = addr >> 5*8;
1425 addr = (start & ~mask) | (val & mask);
1426 }
while (addr != start);
1449 sdata = kzalloc(
sizeof(*sdata) + local->
hw.vif_data_size,
1453 wdev = &sdata->
wdev;
1457 ieee80211_assign_perm_addr(local, wdev->address, type);
1460 if (local->
hw.queues >= IEEE80211_NUM_ACS)
1464 local->
hw.vif_data_size,
1465 name, ieee80211_if_setup, txqs, 1);
1468 dev_net_set(ndev, wiphy_net(local->
hw.wiphy));
1485 ieee80211_assign_perm_addr(local, ndev->
perm_addr, type);
1490 sdata = netdev_priv(ndev);
1499 sdata->
wdev.wiphy = local->
hw.wiphy;
1500 sdata->
local = local;
1506 skb_queue_head_init(&sdata->
fragments[i].skb_list);
1512 sband = local->
hw.wiphy->bands[
i];
1517 sband->
ht_cap.mcs.rx_mask,
1524 ieee80211_set_default_queues(sdata);
1527 ieee80211_setup_sdata(sdata, type);
1550 *new_wdev = &sdata->
wdev;
1560 list_del_rcu(&sdata->
list);
1566 unregister_netdevice(sdata->
dev);
1577 ieee80211_do_stop(sdata,
true);
1578 ieee80211_teardown_sdata(sdata);
1600 list_add(&sdata->
list, &wdev_list);
1614 unsigned long state,
1629 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1638 .notifier_call = netdev_notify,