0001
0002
0003
0004 #include <linux/kernel.h>
0005 #include <linux/etherdevice.h>
0006 #include <linux/vmalloc.h>
0007 #include <linux/ieee80211.h>
0008 #include <net/cfg80211.h>
0009 #include <net/netlink.h>
0010
0011 #include "cfg80211.h"
0012 #include "commands.h"
0013 #include "core.h"
0014 #include "util.h"
0015 #include "bus.h"
0016
0017
0018 static struct ieee80211_rate qtnf_rates_2g[] = {
0019 {.bitrate = 10, .hw_value = 2, },
0020 {.bitrate = 20, .hw_value = 4, },
0021 {.bitrate = 55, .hw_value = 11, },
0022 {.bitrate = 110, .hw_value = 22, },
0023 {.bitrate = 60, .hw_value = 12, },
0024 {.bitrate = 90, .hw_value = 18, },
0025 {.bitrate = 120, .hw_value = 24, },
0026 {.bitrate = 180, .hw_value = 36, },
0027 {.bitrate = 240, .hw_value = 48, },
0028 {.bitrate = 360, .hw_value = 72, },
0029 {.bitrate = 480, .hw_value = 96, },
0030 {.bitrate = 540, .hw_value = 108, },
0031 };
0032
0033
0034 static struct ieee80211_rate qtnf_rates_5g[] = {
0035 {.bitrate = 60, .hw_value = 12, },
0036 {.bitrate = 90, .hw_value = 18, },
0037 {.bitrate = 120, .hw_value = 24, },
0038 {.bitrate = 180, .hw_value = 36, },
0039 {.bitrate = 240, .hw_value = 48, },
0040 {.bitrate = 360, .hw_value = 72, },
0041 {.bitrate = 480, .hw_value = 96, },
0042 {.bitrate = 540, .hw_value = 108, },
0043 };
0044
0045
0046 static const u32 qtnf_cipher_suites[] = {
0047 WLAN_CIPHER_SUITE_TKIP,
0048 WLAN_CIPHER_SUITE_CCMP,
0049 WLAN_CIPHER_SUITE_AES_CMAC,
0050 };
0051
0052
0053 static const struct ieee80211_txrx_stypes
0054 qtnf_mgmt_stypes[NUM_NL80211_IFTYPES] = {
0055 [NL80211_IFTYPE_STATION] = {
0056 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
0057 BIT(IEEE80211_STYPE_AUTH >> 4),
0058 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
0059 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
0060 BIT(IEEE80211_STYPE_AUTH >> 4),
0061 },
0062 [NL80211_IFTYPE_AP] = {
0063 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
0064 BIT(IEEE80211_STYPE_AUTH >> 4),
0065 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
0066 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
0067 BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
0068 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
0069 BIT(IEEE80211_STYPE_AUTH >> 4),
0070 },
0071 };
0072
0073 static int
0074 qtnf_validate_iface_combinations(struct wiphy *wiphy,
0075 struct qtnf_vif *change_vif,
0076 enum nl80211_iftype new_type)
0077 {
0078 struct qtnf_wmac *mac;
0079 struct qtnf_vif *vif;
0080 int i;
0081 int ret = 0;
0082 struct iface_combination_params params = {
0083 .num_different_channels = 1,
0084 };
0085
0086 mac = wiphy_priv(wiphy);
0087 if (!mac)
0088 return -EFAULT;
0089
0090 for (i = 0; i < QTNF_MAX_INTF; i++) {
0091 vif = &mac->iflist[i];
0092 if (vif->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED)
0093 params.iftype_num[vif->wdev.iftype]++;
0094 }
0095
0096 if (change_vif) {
0097 params.iftype_num[new_type]++;
0098 params.iftype_num[change_vif->wdev.iftype]--;
0099 } else {
0100 params.iftype_num[new_type]++;
0101 }
0102
0103 ret = cfg80211_check_combinations(wiphy, ¶ms);
0104
0105 if (ret)
0106 return ret;
0107
0108
0109
0110
0111
0112 vif = qtnf_mac_get_base_vif(mac);
0113 if (vif && vif->wdev.iftype == NL80211_IFTYPE_AP &&
0114 vif != change_vif && new_type == NL80211_IFTYPE_STATION) {
0115 ret = -EINVAL;
0116 pr_err("MAC%u invalid combination: AP as primary repeater interface is not supported\n",
0117 mac->macid);
0118 }
0119
0120 return ret;
0121 }
0122
0123 static int
0124 qtnf_change_virtual_intf(struct wiphy *wiphy,
0125 struct net_device *dev,
0126 enum nl80211_iftype type,
0127 struct vif_params *params)
0128 {
0129 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
0130 u8 *mac_addr = NULL;
0131 int use4addr = 0;
0132 int ret;
0133
0134 ret = qtnf_validate_iface_combinations(wiphy, vif, type);
0135 if (ret) {
0136 pr_err("VIF%u.%u combination check: failed to set type %d\n",
0137 vif->mac->macid, vif->vifid, type);
0138 return ret;
0139 }
0140
0141 if (params) {
0142 mac_addr = params->macaddr;
0143 use4addr = params->use_4addr;
0144 }
0145
0146 qtnf_scan_done(vif->mac, true);
0147
0148 ret = qtnf_cmd_send_change_intf_type(vif, type, use4addr, mac_addr);
0149 if (ret) {
0150 pr_err("VIF%u.%u: failed to change type to %d\n",
0151 vif->mac->macid, vif->vifid, type);
0152 return ret;
0153 }
0154
0155 vif->wdev.iftype = type;
0156 return 0;
0157 }
0158
0159 int qtnf_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
0160 {
0161 struct net_device *netdev = wdev->netdev;
0162 struct qtnf_vif *vif;
0163 struct sk_buff *skb;
0164
0165 if (WARN_ON(!netdev))
0166 return -EFAULT;
0167
0168 vif = qtnf_netdev_get_priv(wdev->netdev);
0169
0170 qtnf_scan_done(vif->mac, true);
0171
0172
0173 netif_tx_stop_all_queues(netdev);
0174 if (netif_carrier_ok(netdev))
0175 netif_carrier_off(netdev);
0176
0177 while ((skb = skb_dequeue(&vif->high_pri_tx_queue)))
0178 dev_kfree_skb_any(skb);
0179
0180 cancel_work_sync(&vif->high_pri_tx_work);
0181
0182 if (netdev->reg_state == NETREG_REGISTERED)
0183 cfg80211_unregister_netdevice(netdev);
0184
0185 if (qtnf_cmd_send_del_intf(vif))
0186 pr_err("VIF%u.%u: failed to delete VIF\n", vif->mac->macid,
0187 vif->vifid);
0188
0189 vif->netdev->ieee80211_ptr = NULL;
0190 vif->netdev = NULL;
0191 vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
0192
0193 return 0;
0194 }
0195
0196 static struct wireless_dev *qtnf_add_virtual_intf(struct wiphy *wiphy,
0197 const char *name,
0198 unsigned char name_assign_t,
0199 enum nl80211_iftype type,
0200 struct vif_params *params)
0201 {
0202 struct qtnf_wmac *mac;
0203 struct qtnf_vif *vif;
0204 u8 *mac_addr = NULL;
0205 int use4addr = 0;
0206 int ret;
0207
0208 mac = wiphy_priv(wiphy);
0209
0210 if (!mac)
0211 return ERR_PTR(-EFAULT);
0212
0213 ret = qtnf_validate_iface_combinations(wiphy, NULL, type);
0214 if (ret) {
0215 pr_err("MAC%u invalid combination: failed to add type %d\n",
0216 mac->macid, type);
0217 return ERR_PTR(ret);
0218 }
0219
0220 switch (type) {
0221 case NL80211_IFTYPE_STATION:
0222 case NL80211_IFTYPE_AP:
0223 vif = qtnf_mac_get_free_vif(mac);
0224 if (!vif) {
0225 pr_err("MAC%u: no free VIF available\n", mac->macid);
0226 return ERR_PTR(-EFAULT);
0227 }
0228
0229 eth_zero_addr(vif->mac_addr);
0230 eth_zero_addr(vif->bssid);
0231 vif->bss_priority = QTNF_DEF_BSS_PRIORITY;
0232 memset(&vif->wdev, 0, sizeof(vif->wdev));
0233 vif->wdev.wiphy = wiphy;
0234 vif->wdev.iftype = type;
0235 break;
0236 default:
0237 pr_err("MAC%u: unsupported IF type %d\n", mac->macid, type);
0238 return ERR_PTR(-ENOTSUPP);
0239 }
0240
0241 if (params) {
0242 mac_addr = params->macaddr;
0243 use4addr = params->use_4addr;
0244 }
0245
0246 ret = qtnf_cmd_send_add_intf(vif, type, use4addr, mac_addr);
0247 if (ret) {
0248 pr_err("VIF%u.%u: failed to add VIF %pM\n",
0249 mac->macid, vif->vifid, mac_addr);
0250 goto err_cmd;
0251 }
0252
0253 if (!is_valid_ether_addr(vif->mac_addr)) {
0254 pr_err("VIF%u.%u: FW reported bad MAC: %pM\n",
0255 mac->macid, vif->vifid, vif->mac_addr);
0256 ret = -EINVAL;
0257 goto error_del_vif;
0258 }
0259
0260 ret = qtnf_core_net_attach(mac, vif, name, name_assign_t);
0261 if (ret) {
0262 pr_err("VIF%u.%u: failed to attach netdev\n", mac->macid,
0263 vif->vifid);
0264 goto error_del_vif;
0265 }
0266
0267 if (qtnf_hwcap_is_set(&mac->bus->hw_info, QLINK_HW_CAPAB_HW_BRIDGE)) {
0268 ret = qtnf_cmd_netdev_changeupper(vif, vif->netdev->ifindex);
0269 if (ret) {
0270 cfg80211_unregister_netdevice(vif->netdev);
0271 vif->netdev = NULL;
0272 goto error_del_vif;
0273 }
0274 }
0275
0276 vif->wdev.netdev = vif->netdev;
0277 return &vif->wdev;
0278
0279 error_del_vif:
0280 qtnf_cmd_send_del_intf(vif);
0281 err_cmd:
0282 vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
0283
0284 return ERR_PTR(ret);
0285 }
0286
0287 static int qtnf_mgmt_set_appie(struct qtnf_vif *vif,
0288 const struct cfg80211_beacon_data *info)
0289 {
0290 int ret = 0;
0291
0292 if (!info->beacon_ies || !info->beacon_ies_len) {
0293 ret = qtnf_cmd_send_mgmt_set_appie(vif, QLINK_IE_SET_BEACON_IES,
0294 NULL, 0);
0295 } else {
0296 ret = qtnf_cmd_send_mgmt_set_appie(vif, QLINK_IE_SET_BEACON_IES,
0297 info->beacon_ies,
0298 info->beacon_ies_len);
0299 }
0300
0301 if (ret)
0302 goto out;
0303
0304 if (!info->proberesp_ies || !info->proberesp_ies_len) {
0305 ret = qtnf_cmd_send_mgmt_set_appie(vif,
0306 QLINK_IE_SET_PROBE_RESP_IES,
0307 NULL, 0);
0308 } else {
0309 ret = qtnf_cmd_send_mgmt_set_appie(vif,
0310 QLINK_IE_SET_PROBE_RESP_IES,
0311 info->proberesp_ies,
0312 info->proberesp_ies_len);
0313 }
0314
0315 if (ret)
0316 goto out;
0317
0318 if (!info->assocresp_ies || !info->assocresp_ies_len) {
0319 ret = qtnf_cmd_send_mgmt_set_appie(vif,
0320 QLINK_IE_SET_ASSOC_RESP,
0321 NULL, 0);
0322 } else {
0323 ret = qtnf_cmd_send_mgmt_set_appie(vif,
0324 QLINK_IE_SET_ASSOC_RESP,
0325 info->assocresp_ies,
0326 info->assocresp_ies_len);
0327 }
0328
0329 out:
0330 return ret;
0331 }
0332
0333 static int qtnf_change_beacon(struct wiphy *wiphy, struct net_device *dev,
0334 struct cfg80211_beacon_data *info)
0335 {
0336 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
0337
0338 return qtnf_mgmt_set_appie(vif, info);
0339 }
0340
0341 static int qtnf_start_ap(struct wiphy *wiphy, struct net_device *dev,
0342 struct cfg80211_ap_settings *settings)
0343 {
0344 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
0345 int ret;
0346
0347 ret = qtnf_cmd_send_start_ap(vif, settings);
0348 if (ret)
0349 pr_err("VIF%u.%u: failed to start AP\n", vif->mac->macid,
0350 vif->vifid);
0351
0352 return ret;
0353 }
0354
0355 static int qtnf_stop_ap(struct wiphy *wiphy, struct net_device *dev,
0356 unsigned int link_id)
0357 {
0358 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
0359 int ret;
0360
0361 qtnf_scan_done(vif->mac, true);
0362
0363 ret = qtnf_cmd_send_stop_ap(vif);
0364 if (ret)
0365 pr_err("VIF%u.%u: failed to stop AP operation in FW\n",
0366 vif->mac->macid, vif->vifid);
0367
0368 netif_carrier_off(vif->netdev);
0369
0370 return ret;
0371 }
0372
0373 static int qtnf_set_wiphy_params(struct wiphy *wiphy, u32 changed)
0374 {
0375 struct qtnf_wmac *mac = wiphy_priv(wiphy);
0376 struct qtnf_vif *vif;
0377 int ret;
0378
0379 vif = qtnf_mac_get_base_vif(mac);
0380 if (!vif) {
0381 pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
0382 return -EFAULT;
0383 }
0384
0385 ret = qtnf_cmd_send_update_phy_params(mac, changed);
0386 if (ret)
0387 pr_err("MAC%u: failed to update PHY params\n", mac->macid);
0388
0389 return ret;
0390 }
0391
0392 static void
0393 qtnf_update_mgmt_frame_registrations(struct wiphy *wiphy,
0394 struct wireless_dev *wdev,
0395 struct mgmt_frame_regs *upd)
0396 {
0397 struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev);
0398 u16 new_mask = upd->interface_stypes;
0399 u16 old_mask = vif->mgmt_frames_bitmask;
0400 static const struct {
0401 u16 mask, qlink_type;
0402 } updates[] = {
0403 {
0404 .mask = BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
0405 BIT(IEEE80211_STYPE_ASSOC_REQ >> 4),
0406 .qlink_type = QLINK_MGMT_FRAME_ASSOC_REQ,
0407 },
0408 {
0409 .mask = BIT(IEEE80211_STYPE_AUTH >> 4),
0410 .qlink_type = QLINK_MGMT_FRAME_AUTH,
0411 },
0412 {
0413 .mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
0414 .qlink_type = QLINK_MGMT_FRAME_PROBE_REQ,
0415 },
0416 {
0417 .mask = BIT(IEEE80211_STYPE_ACTION >> 4),
0418 .qlink_type = QLINK_MGMT_FRAME_ACTION,
0419 },
0420 };
0421 unsigned int i;
0422
0423 if (new_mask == old_mask)
0424 return;
0425
0426 for (i = 0; i < ARRAY_SIZE(updates); i++) {
0427 u16 mask = updates[i].mask;
0428 u16 qlink_frame_type = updates[i].qlink_type;
0429 bool reg;
0430
0431
0432 if (!(new_mask & mask) == !(old_mask & mask))
0433 continue;
0434
0435 reg = new_mask & mask;
0436
0437 if (qtnf_cmd_send_register_mgmt(vif, qlink_frame_type, reg))
0438 pr_warn("VIF%u.%u: failed to %sregister qlink frame type 0x%x\n",
0439 vif->mac->macid, vif->vifid, reg ? "" : "un",
0440 qlink_frame_type);
0441 }
0442
0443 vif->mgmt_frames_bitmask = new_mask;
0444 }
0445
0446 static int
0447 qtnf_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
0448 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
0449 {
0450 struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev);
0451 const struct ieee80211_mgmt *mgmt_frame = (void *)params->buf;
0452 u32 short_cookie = prandom_u32();
0453 u16 flags = 0;
0454 u16 freq;
0455
0456 *cookie = short_cookie;
0457
0458 if (params->offchan)
0459 flags |= QLINK_FRAME_TX_FLAG_OFFCHAN;
0460
0461 if (params->no_cck)
0462 flags |= QLINK_FRAME_TX_FLAG_NO_CCK;
0463
0464 if (params->dont_wait_for_ack)
0465 flags |= QLINK_FRAME_TX_FLAG_ACK_NOWAIT;
0466
0467
0468
0469
0470 if (params->chan)
0471 freq = params->chan->center_freq;
0472 else
0473 freq = 0;
0474
0475 pr_debug("%s freq:%u; FC:%.4X; DA:%pM; len:%zu; C:%.8X; FL:%.4X\n",
0476 wdev->netdev->name, freq,
0477 le16_to_cpu(mgmt_frame->frame_control), mgmt_frame->da,
0478 params->len, short_cookie, flags);
0479
0480 return qtnf_cmd_send_frame(vif, short_cookie, flags,
0481 freq, params->buf, params->len);
0482 }
0483
0484 static int
0485 qtnf_get_station(struct wiphy *wiphy, struct net_device *dev,
0486 const u8 *mac, struct station_info *sinfo)
0487 {
0488 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
0489
0490 sinfo->generation = vif->generation;
0491 return qtnf_cmd_get_sta_info(vif, mac, sinfo);
0492 }
0493
0494 static int
0495 qtnf_dump_station(struct wiphy *wiphy, struct net_device *dev,
0496 int idx, u8 *mac, struct station_info *sinfo)
0497 {
0498 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
0499 const struct qtnf_sta_node *sta_node;
0500 int ret;
0501
0502 switch (vif->wdev.iftype) {
0503 case NL80211_IFTYPE_STATION:
0504 if (idx != 0 || !vif->wdev.connected)
0505 return -ENOENT;
0506
0507 ether_addr_copy(mac, vif->bssid);
0508 break;
0509 case NL80211_IFTYPE_AP:
0510 sta_node = qtnf_sta_list_lookup_index(&vif->sta_list, idx);
0511 if (unlikely(!sta_node))
0512 return -ENOENT;
0513
0514 ether_addr_copy(mac, sta_node->mac_addr);
0515 break;
0516 default:
0517 return -ENOTSUPP;
0518 }
0519
0520 ret = qtnf_cmd_get_sta_info(vif, mac, sinfo);
0521
0522 if (vif->wdev.iftype == NL80211_IFTYPE_AP) {
0523 if (ret == -ENOENT) {
0524 cfg80211_del_sta(vif->netdev, mac, GFP_KERNEL);
0525 sinfo->filled = 0;
0526 }
0527 }
0528
0529 sinfo->generation = vif->generation;
0530
0531 return ret;
0532 }
0533
0534 static int qtnf_add_key(struct wiphy *wiphy, struct net_device *dev,
0535 u8 key_index, bool pairwise, const u8 *mac_addr,
0536 struct key_params *params)
0537 {
0538 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
0539 int ret;
0540
0541 ret = qtnf_cmd_send_add_key(vif, key_index, pairwise, mac_addr, params);
0542 if (ret)
0543 pr_err("VIF%u.%u: failed to add key: cipher=%x idx=%u pw=%u\n",
0544 vif->mac->macid, vif->vifid, params->cipher, key_index,
0545 pairwise);
0546
0547 return ret;
0548 }
0549
0550 static int qtnf_del_key(struct wiphy *wiphy, struct net_device *dev,
0551 u8 key_index, bool pairwise, const u8 *mac_addr)
0552 {
0553 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
0554 int ret;
0555
0556 ret = qtnf_cmd_send_del_key(vif, key_index, pairwise, mac_addr);
0557 if (ret) {
0558 if (ret == -ENOENT) {
0559 pr_debug("VIF%u.%u: key index %d out of bounds\n",
0560 vif->mac->macid, vif->vifid, key_index);
0561 } else {
0562 pr_err("VIF%u.%u: failed to delete key: idx=%u pw=%u\n",
0563 vif->mac->macid, vif->vifid,
0564 key_index, pairwise);
0565 }
0566 }
0567
0568 return ret;
0569 }
0570
0571 static int qtnf_set_default_key(struct wiphy *wiphy, struct net_device *dev,
0572 u8 key_index, bool unicast, bool multicast)
0573 {
0574 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
0575 int ret;
0576
0577 ret = qtnf_cmd_send_set_default_key(vif, key_index, unicast, multicast);
0578 if (ret)
0579 pr_err("VIF%u.%u: failed to set dflt key: idx=%u uc=%u mc=%u\n",
0580 vif->mac->macid, vif->vifid, key_index, unicast,
0581 multicast);
0582
0583 return ret;
0584 }
0585
0586 static int
0587 qtnf_set_default_mgmt_key(struct wiphy *wiphy, struct net_device *dev,
0588 u8 key_index)
0589 {
0590 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
0591 int ret;
0592
0593 ret = qtnf_cmd_send_set_default_mgmt_key(vif, key_index);
0594 if (ret)
0595 pr_err("VIF%u.%u: failed to set default MGMT key: idx=%u\n",
0596 vif->mac->macid, vif->vifid, key_index);
0597
0598 return ret;
0599 }
0600
0601 static int
0602 qtnf_change_station(struct wiphy *wiphy, struct net_device *dev,
0603 const u8 *mac, struct station_parameters *params)
0604 {
0605 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
0606 int ret;
0607
0608 ret = qtnf_cmd_send_change_sta(vif, mac, params);
0609 if (ret)
0610 pr_err("VIF%u.%u: failed to change STA %pM\n",
0611 vif->mac->macid, vif->vifid, mac);
0612
0613 return ret;
0614 }
0615
0616 static int
0617 qtnf_del_station(struct wiphy *wiphy, struct net_device *dev,
0618 struct station_del_parameters *params)
0619 {
0620 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
0621 int ret;
0622
0623 if (params->mac &&
0624 (vif->wdev.iftype == NL80211_IFTYPE_AP) &&
0625 !is_broadcast_ether_addr(params->mac) &&
0626 !qtnf_sta_list_lookup(&vif->sta_list, params->mac))
0627 return 0;
0628
0629 ret = qtnf_cmd_send_del_sta(vif, params);
0630 if (ret)
0631 pr_err("VIF%u.%u: failed to delete STA %pM\n",
0632 vif->mac->macid, vif->vifid, params->mac);
0633
0634 return ret;
0635 }
0636
0637 static int
0638 qtnf_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
0639 {
0640 struct qtnf_wmac *mac = wiphy_priv(wiphy);
0641 int ret;
0642
0643 cancel_delayed_work_sync(&mac->scan_timeout);
0644
0645 mac->scan_req = request;
0646
0647 ret = qtnf_cmd_send_scan(mac);
0648 if (ret) {
0649 pr_err("MAC%u: failed to start scan\n", mac->macid);
0650 mac->scan_req = NULL;
0651 goto out;
0652 }
0653
0654 pr_debug("MAC%u: scan started\n", mac->macid);
0655 queue_delayed_work(mac->bus->workqueue, &mac->scan_timeout,
0656 QTNF_SCAN_TIMEOUT_SEC * HZ);
0657
0658 out:
0659 return ret;
0660 }
0661
0662 static int
0663 qtnf_connect(struct wiphy *wiphy, struct net_device *dev,
0664 struct cfg80211_connect_params *sme)
0665 {
0666 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
0667 int ret;
0668
0669 if (vif->wdev.iftype != NL80211_IFTYPE_STATION)
0670 return -EOPNOTSUPP;
0671
0672 if (sme->auth_type == NL80211_AUTHTYPE_SAE &&
0673 !(sme->flags & CONNECT_REQ_EXTERNAL_AUTH_SUPPORT)) {
0674 pr_err("can not offload authentication to userspace\n");
0675 return -EOPNOTSUPP;
0676 }
0677
0678 if (sme->bssid)
0679 ether_addr_copy(vif->bssid, sme->bssid);
0680 else
0681 eth_zero_addr(vif->bssid);
0682
0683 ret = qtnf_cmd_send_connect(vif, sme);
0684 if (ret)
0685 pr_err("VIF%u.%u: failed to connect\n",
0686 vif->mac->macid, vif->vifid);
0687
0688 return ret;
0689 }
0690
0691 static int
0692 qtnf_external_auth(struct wiphy *wiphy, struct net_device *dev,
0693 struct cfg80211_external_auth_params *auth)
0694 {
0695 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
0696 int ret;
0697
0698 if (vif->wdev.iftype == NL80211_IFTYPE_STATION &&
0699 !ether_addr_equal(vif->bssid, auth->bssid))
0700 pr_warn("unexpected bssid: %pM", auth->bssid);
0701
0702 ret = qtnf_cmd_send_external_auth(vif, auth);
0703 if (ret)
0704 pr_err("VIF%u.%u: failed to report external auth\n",
0705 vif->mac->macid, vif->vifid);
0706
0707 return ret;
0708 }
0709
0710 static int
0711 qtnf_disconnect(struct wiphy *wiphy, struct net_device *dev,
0712 u16 reason_code)
0713 {
0714 struct qtnf_wmac *mac = wiphy_priv(wiphy);
0715 struct qtnf_vif *vif;
0716 int ret = 0;
0717
0718 vif = qtnf_mac_get_base_vif(mac);
0719 if (!vif) {
0720 pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
0721 return -EFAULT;
0722 }
0723
0724 if (vif->wdev.iftype != NL80211_IFTYPE_STATION) {
0725 return -EOPNOTSUPP;
0726 }
0727
0728 ret = qtnf_cmd_send_disconnect(vif, reason_code);
0729 if (ret)
0730 pr_err("VIF%u.%u: failed to disconnect\n",
0731 mac->macid, vif->vifid);
0732
0733 if (vif->wdev.connected) {
0734 netif_carrier_off(vif->netdev);
0735 cfg80211_disconnected(vif->netdev, reason_code,
0736 NULL, 0, true, GFP_KERNEL);
0737 }
0738
0739 return ret;
0740 }
0741
0742 static int
0743 qtnf_dump_survey(struct wiphy *wiphy, struct net_device *dev,
0744 int idx, struct survey_info *survey)
0745 {
0746 struct qtnf_wmac *mac = wiphy_priv(wiphy);
0747 struct wireless_dev *wdev = dev->ieee80211_ptr;
0748 struct ieee80211_supported_band *sband;
0749 const struct cfg80211_chan_def *chandef = wdev_chandef(wdev, 0);
0750 struct ieee80211_channel *chan;
0751 int ret;
0752
0753
0754 sband = wiphy->bands[NL80211_BAND_2GHZ];
0755 if (sband && idx >= sband->n_channels) {
0756 idx -= sband->n_channels;
0757 sband = NULL;
0758 }
0759
0760 if (!sband)
0761 sband = wiphy->bands[NL80211_BAND_5GHZ];
0762
0763 if (!sband || idx >= sband->n_channels)
0764 return -ENOENT;
0765
0766 chan = &sband->channels[idx];
0767 survey->channel = chan;
0768 survey->filled = 0x0;
0769
0770 if (chandef && chan == chandef->chan)
0771 survey->filled = SURVEY_INFO_IN_USE;
0772
0773 ret = qtnf_cmd_get_chan_stats(mac, chan->center_freq, survey);
0774 if (ret)
0775 pr_debug("failed to get chan(%d) stats from card\n",
0776 chan->hw_value);
0777
0778 return ret;
0779 }
0780
0781 static int
0782 qtnf_get_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
0783 unsigned int link_id, struct cfg80211_chan_def *chandef)
0784 {
0785 struct net_device *ndev = wdev->netdev;
0786 struct qtnf_vif *vif;
0787 int ret;
0788
0789 if (!ndev)
0790 return -ENODEV;
0791
0792 vif = qtnf_netdev_get_priv(wdev->netdev);
0793
0794 ret = qtnf_cmd_get_channel(vif, chandef);
0795 if (ret) {
0796 pr_err("%s: failed to get channel: %d\n", ndev->name, ret);
0797 ret = -ENODATA;
0798 goto out;
0799 }
0800
0801 if (!cfg80211_chandef_valid(chandef)) {
0802 pr_err("%s: bad channel freq=%u cf1=%u cf2=%u bw=%u\n",
0803 ndev->name, chandef->chan->center_freq,
0804 chandef->center_freq1, chandef->center_freq2,
0805 chandef->width);
0806 ret = -ENODATA;
0807 goto out;
0808 }
0809
0810 out:
0811 return ret;
0812 }
0813
0814 static int qtnf_channel_switch(struct wiphy *wiphy, struct net_device *dev,
0815 struct cfg80211_csa_settings *params)
0816 {
0817 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
0818 int ret;
0819
0820 pr_debug("%s: chan(%u) count(%u) radar(%u) block_tx(%u)\n", dev->name,
0821 params->chandef.chan->hw_value, params->count,
0822 params->radar_required, params->block_tx);
0823
0824 if (!cfg80211_chandef_valid(¶ms->chandef)) {
0825 pr_err("%s: invalid channel\n", dev->name);
0826 return -EINVAL;
0827 }
0828
0829 ret = qtnf_cmd_send_chan_switch(vif, params);
0830 if (ret)
0831 pr_warn("%s: failed to switch to channel (%u)\n",
0832 dev->name, params->chandef.chan->hw_value);
0833
0834 return ret;
0835 }
0836
0837 static int qtnf_start_radar_detection(struct wiphy *wiphy,
0838 struct net_device *ndev,
0839 struct cfg80211_chan_def *chandef,
0840 u32 cac_time_ms)
0841 {
0842 struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
0843 int ret;
0844
0845 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
0846 return -ENOTSUPP;
0847
0848 ret = qtnf_cmd_start_cac(vif, chandef, cac_time_ms);
0849 if (ret)
0850 pr_err("%s: failed to start CAC ret=%d\n", ndev->name, ret);
0851
0852 return ret;
0853 }
0854
0855 static int qtnf_set_mac_acl(struct wiphy *wiphy,
0856 struct net_device *dev,
0857 const struct cfg80211_acl_data *params)
0858 {
0859 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
0860 int ret;
0861
0862 ret = qtnf_cmd_set_mac_acl(vif, params);
0863 if (ret)
0864 pr_err("%s: failed to set mac ACL ret=%d\n", dev->name, ret);
0865
0866 return ret;
0867 }
0868
0869 static int qtnf_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
0870 bool enabled, int timeout)
0871 {
0872 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
0873 int ret;
0874
0875 ret = qtnf_cmd_send_pm_set(vif, enabled ? QLINK_PM_AUTO_STANDBY :
0876 QLINK_PM_OFF, timeout);
0877 if (ret)
0878 pr_err("%s: failed to set PM mode ret=%d\n", dev->name, ret);
0879
0880 return ret;
0881 }
0882
0883 static int qtnf_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
0884 int *dbm)
0885 {
0886 struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev);
0887 int ret;
0888
0889 ret = qtnf_cmd_get_tx_power(vif, dbm);
0890 if (ret)
0891 pr_err("MAC%u: failed to get Tx power\n", vif->mac->macid);
0892
0893 return ret;
0894 }
0895
0896 static int qtnf_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
0897 enum nl80211_tx_power_setting type, int mbm)
0898 {
0899 struct qtnf_vif *vif;
0900 int ret;
0901
0902 if (wdev) {
0903 vif = qtnf_netdev_get_priv(wdev->netdev);
0904 } else {
0905 struct qtnf_wmac *mac = wiphy_priv(wiphy);
0906
0907 vif = qtnf_mac_get_base_vif(mac);
0908 if (!vif) {
0909 pr_err("MAC%u: primary VIF is not configured\n",
0910 mac->macid);
0911 return -EFAULT;
0912 }
0913 }
0914
0915 ret = qtnf_cmd_set_tx_power(vif, type, mbm);
0916 if (ret)
0917 pr_err("MAC%u: failed to set Tx power\n", vif->mac->macid);
0918
0919 return ret;
0920 }
0921
0922 static int qtnf_update_owe_info(struct wiphy *wiphy, struct net_device *dev,
0923 struct cfg80211_update_owe_info *owe_info)
0924 {
0925 struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
0926 int ret;
0927
0928 if (vif->wdev.iftype != NL80211_IFTYPE_AP)
0929 return -EOPNOTSUPP;
0930
0931 ret = qtnf_cmd_send_update_owe(vif, owe_info);
0932 if (ret)
0933 pr_err("VIF%u.%u: failed to update owe info\n",
0934 vif->mac->macid, vif->vifid);
0935
0936 return ret;
0937 }
0938
0939 #ifdef CONFIG_PM
0940 static int qtnf_suspend(struct wiphy *wiphy, struct cfg80211_wowlan *wowlan)
0941 {
0942 struct qtnf_wmac *mac = wiphy_priv(wiphy);
0943 struct qtnf_vif *vif;
0944 int ret = 0;
0945
0946 vif = qtnf_mac_get_base_vif(mac);
0947 if (!vif) {
0948 pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
0949 ret = -EFAULT;
0950 goto exit;
0951 }
0952
0953 if (!wowlan) {
0954 pr_debug("WoWLAN triggers are not enabled\n");
0955 qtnf_virtual_intf_cleanup(vif->netdev);
0956 goto exit;
0957 }
0958
0959 qtnf_scan_done(vif->mac, true);
0960
0961 ret = qtnf_cmd_send_wowlan_set(vif, wowlan);
0962 if (ret) {
0963 pr_err("MAC%u: failed to set WoWLAN triggers\n",
0964 mac->macid);
0965 goto exit;
0966 }
0967
0968 exit:
0969 return ret;
0970 }
0971
0972 static int qtnf_resume(struct wiphy *wiphy)
0973 {
0974 struct qtnf_wmac *mac = wiphy_priv(wiphy);
0975 struct qtnf_vif *vif;
0976 int ret = 0;
0977
0978 vif = qtnf_mac_get_base_vif(mac);
0979 if (!vif) {
0980 pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
0981 return -EFAULT;
0982 }
0983
0984 ret = qtnf_cmd_send_wowlan_set(vif, NULL);
0985 if (ret)
0986 pr_err("MAC%u: failed to reset WoWLAN triggers\n",
0987 mac->macid);
0988
0989 return ret;
0990 }
0991
0992 static void qtnf_set_wakeup(struct wiphy *wiphy, bool enabled)
0993 {
0994 struct qtnf_wmac *mac = wiphy_priv(wiphy);
0995 struct qtnf_bus *bus = mac->bus;
0996
0997 device_set_wakeup_enable(bus->dev, enabled);
0998 }
0999 #endif
1000
1001 static struct cfg80211_ops qtn_cfg80211_ops = {
1002 .add_virtual_intf = qtnf_add_virtual_intf,
1003 .change_virtual_intf = qtnf_change_virtual_intf,
1004 .del_virtual_intf = qtnf_del_virtual_intf,
1005 .start_ap = qtnf_start_ap,
1006 .change_beacon = qtnf_change_beacon,
1007 .stop_ap = qtnf_stop_ap,
1008 .set_wiphy_params = qtnf_set_wiphy_params,
1009 .update_mgmt_frame_registrations =
1010 qtnf_update_mgmt_frame_registrations,
1011 .mgmt_tx = qtnf_mgmt_tx,
1012 .change_station = qtnf_change_station,
1013 .del_station = qtnf_del_station,
1014 .get_station = qtnf_get_station,
1015 .dump_station = qtnf_dump_station,
1016 .add_key = qtnf_add_key,
1017 .del_key = qtnf_del_key,
1018 .set_default_key = qtnf_set_default_key,
1019 .set_default_mgmt_key = qtnf_set_default_mgmt_key,
1020 .scan = qtnf_scan,
1021 .connect = qtnf_connect,
1022 .external_auth = qtnf_external_auth,
1023 .disconnect = qtnf_disconnect,
1024 .dump_survey = qtnf_dump_survey,
1025 .get_channel = qtnf_get_channel,
1026 .channel_switch = qtnf_channel_switch,
1027 .start_radar_detection = qtnf_start_radar_detection,
1028 .set_mac_acl = qtnf_set_mac_acl,
1029 .set_power_mgmt = qtnf_set_power_mgmt,
1030 .get_tx_power = qtnf_get_tx_power,
1031 .set_tx_power = qtnf_set_tx_power,
1032 .update_owe_info = qtnf_update_owe_info,
1033 #ifdef CONFIG_PM
1034 .suspend = qtnf_suspend,
1035 .resume = qtnf_resume,
1036 .set_wakeup = qtnf_set_wakeup,
1037 #endif
1038 };
1039
1040 static void qtnf_cfg80211_reg_notifier(struct wiphy *wiphy,
1041 struct regulatory_request *req)
1042 {
1043 struct qtnf_wmac *mac = wiphy_priv(wiphy);
1044 enum nl80211_band band;
1045 int ret;
1046
1047 pr_debug("MAC%u: initiator=%d alpha=%c%c\n", mac->macid, req->initiator,
1048 req->alpha2[0], req->alpha2[1]);
1049
1050 ret = qtnf_cmd_reg_notify(mac, req, qtnf_slave_radar_get(),
1051 qtnf_dfs_offload_get());
1052 if (ret) {
1053 pr_err("MAC%u: failed to update region to %c%c: %d\n",
1054 mac->macid, req->alpha2[0], req->alpha2[1], ret);
1055 return;
1056 }
1057
1058 for (band = 0; band < NUM_NL80211_BANDS; ++band) {
1059 if (!wiphy->bands[band])
1060 continue;
1061
1062 ret = qtnf_cmd_band_info_get(mac, wiphy->bands[band]);
1063 if (ret)
1064 pr_err("MAC%u: failed to update band %u\n",
1065 mac->macid, band);
1066 }
1067 }
1068
1069 struct wiphy *qtnf_wiphy_allocate(struct qtnf_bus *bus,
1070 struct platform_device *pdev)
1071 {
1072 struct wiphy *wiphy;
1073
1074 if (qtnf_dfs_offload_get() &&
1075 qtnf_hwcap_is_set(&bus->hw_info, QLINK_HW_CAPAB_DFS_OFFLOAD))
1076 qtn_cfg80211_ops.start_radar_detection = NULL;
1077
1078 if (!qtnf_hwcap_is_set(&bus->hw_info, QLINK_HW_CAPAB_PWR_MGMT))
1079 qtn_cfg80211_ops.set_power_mgmt = NULL;
1080
1081 wiphy = wiphy_new(&qtn_cfg80211_ops, sizeof(struct qtnf_wmac));
1082 if (!wiphy)
1083 return NULL;
1084
1085 if (pdev)
1086 set_wiphy_dev(wiphy, &pdev->dev);
1087 else
1088 set_wiphy_dev(wiphy, bus->dev);
1089
1090 return wiphy;
1091 }
1092
1093 static int
1094 qtnf_wiphy_setup_if_comb(struct wiphy *wiphy, struct qtnf_mac_info *mac_info)
1095 {
1096 struct ieee80211_iface_combination *if_comb;
1097 size_t n_if_comb;
1098 u16 interface_modes = 0;
1099 size_t i, j;
1100
1101 if_comb = mac_info->if_comb;
1102 n_if_comb = mac_info->n_if_comb;
1103
1104 if (!if_comb || !n_if_comb)
1105 return -ENOENT;
1106
1107 for (i = 0; i < n_if_comb; i++) {
1108 if_comb[i].radar_detect_widths = mac_info->radar_detect_widths;
1109
1110 for (j = 0; j < if_comb[i].n_limits; j++)
1111 interface_modes |= if_comb[i].limits[j].types;
1112 }
1113
1114 wiphy->iface_combinations = if_comb;
1115 wiphy->n_iface_combinations = n_if_comb;
1116 wiphy->interface_modes = interface_modes;
1117
1118 return 0;
1119 }
1120
1121 int qtnf_wiphy_register(struct qtnf_hw_info *hw_info, struct qtnf_wmac *mac)
1122 {
1123 struct wiphy *wiphy = priv_to_wiphy(mac);
1124 struct qtnf_mac_info *macinfo = &mac->macinfo;
1125 int ret;
1126 bool regdomain_is_known;
1127
1128 if (!wiphy) {
1129 pr_err("invalid wiphy pointer\n");
1130 return -EFAULT;
1131 }
1132
1133 wiphy->frag_threshold = macinfo->frag_thr;
1134 wiphy->rts_threshold = macinfo->rts_thr;
1135 wiphy->retry_short = macinfo->sretry_limit;
1136 wiphy->retry_long = macinfo->lretry_limit;
1137 wiphy->coverage_class = macinfo->coverage_class;
1138
1139 wiphy->max_scan_ssids =
1140 (macinfo->max_scan_ssids) ? macinfo->max_scan_ssids : 1;
1141 wiphy->max_scan_ie_len = QTNF_MAX_VSIE_LEN;
1142 wiphy->mgmt_stypes = qtnf_mgmt_stypes;
1143 wiphy->max_remain_on_channel_duration = 5000;
1144 wiphy->max_acl_mac_addrs = macinfo->max_acl_mac_addrs;
1145 wiphy->max_num_csa_counters = 2;
1146
1147 ret = qtnf_wiphy_setup_if_comb(wiphy, macinfo);
1148 if (ret)
1149 goto out;
1150
1151
1152 wiphy->cipher_suites = qtnf_cipher_suites;
1153 wiphy->n_cipher_suites = ARRAY_SIZE(qtnf_cipher_suites);
1154 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1155 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
1156 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
1157 WIPHY_FLAG_AP_UAPSD |
1158 WIPHY_FLAG_HAS_CHANNEL_SWITCH |
1159 WIPHY_FLAG_4ADDR_STATION |
1160 WIPHY_FLAG_NETNS_OK;
1161 wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
1162
1163 if (qtnf_dfs_offload_get() &&
1164 qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_DFS_OFFLOAD))
1165 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD);
1166
1167 if (qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_SCAN_DWELL))
1168 wiphy_ext_feature_set(wiphy,
1169 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
1170
1171 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
1172 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2;
1173
1174 wiphy->available_antennas_tx = macinfo->num_tx_chain;
1175 wiphy->available_antennas_rx = macinfo->num_rx_chain;
1176
1177 wiphy->max_ap_assoc_sta = macinfo->max_ap_assoc_sta;
1178 wiphy->ht_capa_mod_mask = &macinfo->ht_cap_mod_mask;
1179 wiphy->vht_capa_mod_mask = &macinfo->vht_cap_mod_mask;
1180
1181 ether_addr_copy(wiphy->perm_addr, mac->macaddr);
1182
1183 if (qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_STA_INACT_TIMEOUT))
1184 wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER;
1185
1186 if (qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_SCAN_RANDOM_MAC_ADDR))
1187 wiphy->features |= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
1188
1189 if (!qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_OBSS_SCAN))
1190 wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
1191
1192 if (qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_SAE))
1193 wiphy->features |= NL80211_FEATURE_SAE;
1194
1195 #ifdef CONFIG_PM
1196 if (macinfo->wowlan)
1197 wiphy->wowlan = macinfo->wowlan;
1198 #endif
1199
1200 regdomain_is_known = isalpha(mac->rd->alpha2[0]) &&
1201 isalpha(mac->rd->alpha2[1]);
1202
1203 if (qtnf_hwcap_is_set(hw_info, QLINK_HW_CAPAB_REG_UPDATE)) {
1204 wiphy->reg_notifier = qtnf_cfg80211_reg_notifier;
1205
1206 if (mac->rd->alpha2[0] == '9' && mac->rd->alpha2[1] == '9') {
1207 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
1208 REGULATORY_STRICT_REG;
1209 wiphy_apply_custom_regulatory(wiphy, mac->rd);
1210 } else if (regdomain_is_known) {
1211 wiphy->regulatory_flags |= REGULATORY_STRICT_REG;
1212 }
1213 } else {
1214 wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
1215 }
1216
1217 if (mac->macinfo.extended_capabilities_len) {
1218 wiphy->extended_capabilities =
1219 mac->macinfo.extended_capabilities;
1220 wiphy->extended_capabilities_mask =
1221 mac->macinfo.extended_capabilities_mask;
1222 wiphy->extended_capabilities_len =
1223 mac->macinfo.extended_capabilities_len;
1224 }
1225
1226 strlcpy(wiphy->fw_version, hw_info->fw_version,
1227 sizeof(wiphy->fw_version));
1228 wiphy->hw_version = hw_info->hw_version;
1229
1230 ret = wiphy_register(wiphy);
1231 if (ret < 0)
1232 goto out;
1233
1234 if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED)
1235 ret = regulatory_set_wiphy_regd(wiphy, mac->rd);
1236 else if (regdomain_is_known)
1237 ret = regulatory_hint(wiphy, mac->rd->alpha2);
1238
1239 out:
1240 return ret;
1241 }
1242
1243 void qtnf_netdev_updown(struct net_device *ndev, bool up)
1244 {
1245 struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
1246
1247 if (qtnf_cmd_send_updown_intf(vif, up))
1248 pr_err("failed to send %s command to VIF%u.%u\n",
1249 up ? "UP" : "DOWN", vif->mac->macid, vif->vifid);
1250 }
1251
1252 void qtnf_virtual_intf_cleanup(struct net_device *ndev)
1253 {
1254 struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
1255 struct qtnf_wmac *mac = wiphy_priv(vif->wdev.wiphy);
1256
1257 if (vif->wdev.iftype == NL80211_IFTYPE_STATION)
1258 qtnf_disconnect(vif->wdev.wiphy, ndev,
1259 WLAN_REASON_DEAUTH_LEAVING);
1260
1261 qtnf_scan_done(mac, true);
1262 }
1263
1264 void qtnf_cfg80211_vif_reset(struct qtnf_vif *vif)
1265 {
1266 if (vif->wdev.iftype == NL80211_IFTYPE_STATION)
1267 cfg80211_disconnected(vif->netdev, WLAN_REASON_DEAUTH_LEAVING,
1268 NULL, 0, 1, GFP_KERNEL);
1269
1270 cfg80211_shutdown_all_interfaces(vif->wdev.wiphy);
1271 }
1272
1273 void qtnf_band_init_rates(struct ieee80211_supported_band *band)
1274 {
1275 switch (band->band) {
1276 case NL80211_BAND_2GHZ:
1277 band->bitrates = qtnf_rates_2g;
1278 band->n_bitrates = ARRAY_SIZE(qtnf_rates_2g);
1279 break;
1280 case NL80211_BAND_5GHZ:
1281 band->bitrates = qtnf_rates_5g;
1282 band->n_bitrates = ARRAY_SIZE(qtnf_rates_5g);
1283 break;
1284 default:
1285 band->bitrates = NULL;
1286 band->n_bitrates = 0;
1287 break;
1288 }
1289 }