Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2016 Quantenna Communications, Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/slab.h> |
| 20 | |
| 21 | #include "cfg80211.h" |
| 22 | #include "core.h" |
| 23 | #include "qlink.h" |
| 24 | #include "bus.h" |
| 25 | #include "trans.h" |
| 26 | #include "util.h" |
| 27 | #include "event.h" |
Igor Mitsyanko | fac7f9b | 2017-09-21 14:34:30 -0700 | [diff] [blame] | 28 | #include "qlink_util.h" |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 29 | |
| 30 | static int |
| 31 | qtnf_event_handle_sta_assoc(struct qtnf_wmac *mac, struct qtnf_vif *vif, |
| 32 | const struct qlink_event_sta_assoc *sta_assoc, |
| 33 | u16 len) |
| 34 | { |
| 35 | const u8 *sta_addr; |
| 36 | u16 frame_control; |
| 37 | struct station_info sinfo = { 0 }; |
| 38 | size_t payload_len; |
| 39 | u16 tlv_type; |
| 40 | u16 tlv_value_len; |
| 41 | size_t tlv_full_len; |
| 42 | const struct qlink_tlv_hdr *tlv; |
| 43 | |
| 44 | if (unlikely(len < sizeof(*sta_assoc))) { |
| 45 | pr_err("VIF%u.%u: payload is too short (%u < %zu)\n", |
| 46 | mac->macid, vif->vifid, len, sizeof(*sta_assoc)); |
| 47 | return -EINVAL; |
| 48 | } |
| 49 | |
| 50 | if (vif->wdev.iftype != NL80211_IFTYPE_AP) { |
| 51 | pr_err("VIF%u.%u: STA_ASSOC event when not in AP mode\n", |
| 52 | mac->macid, vif->vifid); |
| 53 | return -EPROTO; |
| 54 | } |
| 55 | |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 56 | sta_addr = sta_assoc->sta_addr; |
| 57 | frame_control = le16_to_cpu(sta_assoc->frame_control); |
| 58 | |
| 59 | pr_debug("VIF%u.%u: MAC:%pM FC:%x\n", mac->macid, vif->vifid, sta_addr, |
| 60 | frame_control); |
| 61 | |
| 62 | qtnf_sta_list_add(&vif->sta_list, sta_addr); |
| 63 | |
| 64 | sinfo.assoc_req_ies = NULL; |
| 65 | sinfo.assoc_req_ies_len = 0; |
| 66 | |
| 67 | payload_len = len - sizeof(*sta_assoc); |
Igor Mitsyanko | 18b7470 | 2017-10-30 18:04:50 -0700 | [diff] [blame] | 68 | tlv = (const struct qlink_tlv_hdr *)sta_assoc->ies; |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 69 | |
Igor Mitsyanko | 18b7470 | 2017-10-30 18:04:50 -0700 | [diff] [blame] | 70 | while (payload_len >= sizeof(*tlv)) { |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 71 | tlv_type = le16_to_cpu(tlv->type); |
| 72 | tlv_value_len = le16_to_cpu(tlv->len); |
| 73 | tlv_full_len = tlv_value_len + sizeof(struct qlink_tlv_hdr); |
| 74 | |
Igor Mitsyanko | 18b7470 | 2017-10-30 18:04:50 -0700 | [diff] [blame] | 75 | if (tlv_full_len > payload_len) |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 76 | return -EINVAL; |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 77 | |
| 78 | if (tlv_type == QTN_TLV_ID_IE_SET) { |
Igor Mitsyanko | 18b7470 | 2017-10-30 18:04:50 -0700 | [diff] [blame] | 79 | const struct qlink_tlv_ie_set *ie_set; |
| 80 | unsigned int ie_len; |
| 81 | |
| 82 | if (payload_len < sizeof(*ie_set)) |
| 83 | return -EINVAL; |
| 84 | |
| 85 | ie_set = (const struct qlink_tlv_ie_set *)tlv; |
| 86 | ie_len = tlv_value_len - |
| 87 | (sizeof(*ie_set) - sizeof(ie_set->hdr)); |
| 88 | |
| 89 | if (ie_set->type == QLINK_IE_SET_ASSOC_REQ && ie_len) { |
| 90 | sinfo.assoc_req_ies = ie_set->ie_data; |
| 91 | sinfo.assoc_req_ies_len = ie_len; |
| 92 | } |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | payload_len -= tlv_full_len; |
| 96 | tlv = (struct qlink_tlv_hdr *)(tlv->val + tlv_value_len); |
| 97 | } |
| 98 | |
Igor Mitsyanko | 18b7470 | 2017-10-30 18:04:50 -0700 | [diff] [blame] | 99 | if (payload_len) |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 100 | return -EINVAL; |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 101 | |
| 102 | cfg80211_new_sta(vif->netdev, sta_assoc->sta_addr, &sinfo, |
| 103 | GFP_KERNEL); |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static int |
| 109 | qtnf_event_handle_sta_deauth(struct qtnf_wmac *mac, struct qtnf_vif *vif, |
| 110 | const struct qlink_event_sta_deauth *sta_deauth, |
| 111 | u16 len) |
| 112 | { |
| 113 | const u8 *sta_addr; |
| 114 | u16 reason; |
| 115 | |
| 116 | if (unlikely(len < sizeof(*sta_deauth))) { |
| 117 | pr_err("VIF%u.%u: payload is too short (%u < %zu)\n", |
| 118 | mac->macid, vif->vifid, len, |
| 119 | sizeof(struct qlink_event_sta_deauth)); |
| 120 | return -EINVAL; |
| 121 | } |
| 122 | |
| 123 | if (vif->wdev.iftype != NL80211_IFTYPE_AP) { |
| 124 | pr_err("VIF%u.%u: STA_DEAUTH event when not in AP mode\n", |
| 125 | mac->macid, vif->vifid); |
| 126 | return -EPROTO; |
| 127 | } |
| 128 | |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 129 | sta_addr = sta_deauth->sta_addr; |
| 130 | reason = le16_to_cpu(sta_deauth->reason); |
| 131 | |
| 132 | pr_debug("VIF%u.%u: MAC:%pM reason:%x\n", mac->macid, vif->vifid, |
| 133 | sta_addr, reason); |
| 134 | |
| 135 | if (qtnf_sta_list_del(&vif->sta_list, sta_addr)) |
| 136 | cfg80211_del_sta(vif->netdev, sta_deauth->sta_addr, |
| 137 | GFP_KERNEL); |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | static int |
| 143 | qtnf_event_handle_bss_join(struct qtnf_vif *vif, |
| 144 | const struct qlink_event_bss_join *join_info, |
| 145 | u16 len) |
| 146 | { |
| 147 | if (unlikely(len < sizeof(*join_info))) { |
| 148 | pr_err("VIF%u.%u: payload is too short (%u < %zu)\n", |
| 149 | vif->mac->macid, vif->vifid, len, |
| 150 | sizeof(struct qlink_event_bss_join)); |
| 151 | return -EINVAL; |
| 152 | } |
| 153 | |
| 154 | if (vif->wdev.iftype != NL80211_IFTYPE_STATION) { |
| 155 | pr_err("VIF%u.%u: BSS_JOIN event when not in STA mode\n", |
| 156 | vif->mac->macid, vif->vifid); |
| 157 | return -EPROTO; |
| 158 | } |
| 159 | |
| 160 | if (vif->sta_state != QTNF_STA_CONNECTING) { |
| 161 | pr_err("VIF%u.%u: BSS_JOIN event when STA is not connecting\n", |
| 162 | vif->mac->macid, vif->vifid); |
| 163 | return -EPROTO; |
| 164 | } |
| 165 | |
| 166 | pr_debug("VIF%u.%u: BSSID:%pM\n", vif->mac->macid, vif->vifid, |
| 167 | join_info->bssid); |
| 168 | |
| 169 | cfg80211_connect_result(vif->netdev, join_info->bssid, NULL, 0, NULL, |
| 170 | 0, le16_to_cpu(join_info->status), GFP_KERNEL); |
| 171 | |
| 172 | if (le16_to_cpu(join_info->status) == WLAN_STATUS_SUCCESS) { |
| 173 | vif->sta_state = QTNF_STA_CONNECTED; |
| 174 | netif_carrier_on(vif->netdev); |
| 175 | } else { |
| 176 | vif->sta_state = QTNF_STA_DISCONNECTED; |
| 177 | } |
| 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | static int |
| 183 | qtnf_event_handle_bss_leave(struct qtnf_vif *vif, |
| 184 | const struct qlink_event_bss_leave *leave_info, |
| 185 | u16 len) |
| 186 | { |
| 187 | if (unlikely(len < sizeof(*leave_info))) { |
| 188 | pr_err("VIF%u.%u: payload is too short (%u < %zu)\n", |
| 189 | vif->mac->macid, vif->vifid, len, |
| 190 | sizeof(struct qlink_event_bss_leave)); |
| 191 | return -EINVAL; |
| 192 | } |
| 193 | |
| 194 | if (vif->wdev.iftype != NL80211_IFTYPE_STATION) { |
| 195 | pr_err("VIF%u.%u: BSS_LEAVE event when not in STA mode\n", |
| 196 | vif->mac->macid, vif->vifid); |
| 197 | return -EPROTO; |
| 198 | } |
| 199 | |
| 200 | if (vif->sta_state != QTNF_STA_CONNECTED) { |
| 201 | pr_err("VIF%u.%u: BSS_LEAVE event when STA is not connected\n", |
| 202 | vif->mac->macid, vif->vifid); |
| 203 | return -EPROTO; |
| 204 | } |
| 205 | |
| 206 | pr_debug("VIF%u.%u: disconnected\n", vif->mac->macid, vif->vifid); |
| 207 | |
Sergey Matyukevich | fd19ece | 2017-07-28 02:06:48 +0300 | [diff] [blame] | 208 | cfg80211_disconnected(vif->netdev, le16_to_cpu(leave_info->reason), |
| 209 | NULL, 0, 0, GFP_KERNEL); |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 210 | |
| 211 | vif->sta_state = QTNF_STA_DISCONNECTED; |
| 212 | netif_carrier_off(vif->netdev); |
| 213 | |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | static int |
| 218 | qtnf_event_handle_mgmt_received(struct qtnf_vif *vif, |
| 219 | const struct qlink_event_rxmgmt *rxmgmt, |
| 220 | u16 len) |
| 221 | { |
| 222 | const size_t min_len = sizeof(*rxmgmt) + |
| 223 | sizeof(struct ieee80211_hdr_3addr); |
| 224 | const struct ieee80211_hdr_3addr *frame = (void *)rxmgmt->frame_data; |
| 225 | const u16 frame_len = len - sizeof(*rxmgmt); |
| 226 | enum nl80211_rxmgmt_flags flags = 0; |
| 227 | |
| 228 | if (unlikely(len < min_len)) { |
| 229 | pr_err("VIF%u.%u: payload is too short (%u < %zu)\n", |
| 230 | vif->mac->macid, vif->vifid, len, min_len); |
| 231 | return -EINVAL; |
| 232 | } |
| 233 | |
| 234 | if (le32_to_cpu(rxmgmt->flags) & QLINK_RXMGMT_FLAG_ANSWERED) |
| 235 | flags |= NL80211_RXMGMT_FLAG_ANSWERED; |
| 236 | |
| 237 | pr_debug("%s LEN:%u FC:%.4X SA:%pM\n", vif->netdev->name, frame_len, |
| 238 | le16_to_cpu(frame->frame_control), frame->addr2); |
| 239 | |
Sergey Matyukevich | fbad963 | 2017-12-19 14:28:52 +0300 | [diff] [blame] | 240 | cfg80211_rx_mgmt(&vif->wdev, le32_to_cpu(rxmgmt->freq), rxmgmt->sig_dbm, |
| 241 | rxmgmt->frame_data, frame_len, flags); |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 242 | |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | static int |
| 247 | qtnf_event_handle_scan_results(struct qtnf_vif *vif, |
| 248 | const struct qlink_event_scan_result *sr, |
| 249 | u16 len) |
| 250 | { |
| 251 | struct cfg80211_bss *bss; |
| 252 | struct ieee80211_channel *channel; |
| 253 | struct wiphy *wiphy = priv_to_wiphy(vif->mac); |
Igor Mitsyanko | 5face51 | 2017-10-30 18:04:51 -0700 | [diff] [blame] | 254 | enum cfg80211_bss_frame_type frame_type = CFG80211_BSS_FTYPE_UNKNOWN; |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 255 | size_t payload_len; |
| 256 | u16 tlv_type; |
| 257 | u16 tlv_value_len; |
| 258 | size_t tlv_full_len; |
| 259 | const struct qlink_tlv_hdr *tlv; |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 260 | const u8 *ies = NULL; |
| 261 | size_t ies_len = 0; |
| 262 | |
| 263 | if (len < sizeof(*sr)) { |
| 264 | pr_err("VIF%u.%u: payload is too short\n", vif->mac->macid, |
| 265 | vif->vifid); |
| 266 | return -EINVAL; |
| 267 | } |
| 268 | |
| 269 | channel = ieee80211_get_channel(wiphy, le16_to_cpu(sr->freq)); |
| 270 | if (!channel) { |
| 271 | pr_err("VIF%u.%u: channel at %u MHz not found\n", |
| 272 | vif->mac->macid, vif->vifid, le16_to_cpu(sr->freq)); |
| 273 | return -EINVAL; |
| 274 | } |
| 275 | |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 276 | payload_len = len - sizeof(*sr); |
| 277 | tlv = (struct qlink_tlv_hdr *)sr->payload; |
| 278 | |
| 279 | while (payload_len >= sizeof(struct qlink_tlv_hdr)) { |
| 280 | tlv_type = le16_to_cpu(tlv->type); |
| 281 | tlv_value_len = le16_to_cpu(tlv->len); |
| 282 | tlv_full_len = tlv_value_len + sizeof(struct qlink_tlv_hdr); |
| 283 | |
Igor Mitsyanko | 18b7470 | 2017-10-30 18:04:50 -0700 | [diff] [blame] | 284 | if (tlv_full_len > payload_len) |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 285 | return -EINVAL; |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 286 | |
| 287 | if (tlv_type == QTN_TLV_ID_IE_SET) { |
Igor Mitsyanko | 18b7470 | 2017-10-30 18:04:50 -0700 | [diff] [blame] | 288 | const struct qlink_tlv_ie_set *ie_set; |
| 289 | unsigned int ie_len; |
| 290 | |
| 291 | if (payload_len < sizeof(*ie_set)) |
| 292 | return -EINVAL; |
| 293 | |
| 294 | ie_set = (const struct qlink_tlv_ie_set *)tlv; |
| 295 | ie_len = tlv_value_len - |
| 296 | (sizeof(*ie_set) - sizeof(ie_set->hdr)); |
| 297 | |
Igor Mitsyanko | 5face51 | 2017-10-30 18:04:51 -0700 | [diff] [blame] | 298 | switch (ie_set->type) { |
| 299 | case QLINK_IE_SET_BEACON_IES: |
| 300 | frame_type = CFG80211_BSS_FTYPE_BEACON; |
| 301 | break; |
| 302 | case QLINK_IE_SET_PROBE_RESP_IES: |
| 303 | frame_type = CFG80211_BSS_FTYPE_PRESP; |
| 304 | break; |
| 305 | default: |
| 306 | frame_type = CFG80211_BSS_FTYPE_UNKNOWN; |
| 307 | } |
| 308 | |
Igor Mitsyanko | 18b7470 | 2017-10-30 18:04:50 -0700 | [diff] [blame] | 309 | if (ie_len) { |
| 310 | ies = ie_set->ie_data; |
| 311 | ies_len = ie_len; |
| 312 | } |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | payload_len -= tlv_full_len; |
| 316 | tlv = (struct qlink_tlv_hdr *)(tlv->val + tlv_value_len); |
| 317 | } |
| 318 | |
Igor Mitsyanko | 18b7470 | 2017-10-30 18:04:50 -0700 | [diff] [blame] | 319 | if (payload_len) |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 320 | return -EINVAL; |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 321 | |
| 322 | bss = cfg80211_inform_bss(wiphy, channel, frame_type, |
| 323 | sr->bssid, get_unaligned_le64(&sr->tsf), |
| 324 | le16_to_cpu(sr->capab), |
| 325 | le16_to_cpu(sr->bintval), ies, ies_len, |
Sergey Matyukevich | fbad963 | 2017-12-19 14:28:52 +0300 | [diff] [blame] | 326 | DBM_TO_MBM(sr->sig_dbm), GFP_KERNEL); |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 327 | if (!bss) |
| 328 | return -ENOMEM; |
| 329 | |
| 330 | cfg80211_put_bss(wiphy, bss); |
| 331 | |
| 332 | return 0; |
| 333 | } |
| 334 | |
| 335 | static int |
| 336 | qtnf_event_handle_scan_complete(struct qtnf_wmac *mac, |
| 337 | const struct qlink_event_scan_complete *status, |
| 338 | u16 len) |
| 339 | { |
| 340 | if (len < sizeof(*status)) { |
| 341 | pr_err("MAC%u: payload is too short\n", mac->macid); |
| 342 | return -EINVAL; |
| 343 | } |
| 344 | |
| 345 | qtnf_scan_done(mac, le32_to_cpu(status->flags) & QLINK_SCAN_ABORTED); |
| 346 | |
| 347 | return 0; |
| 348 | } |
| 349 | |
Sergey Matyukevich | 97883695 | 2017-07-28 02:06:50 +0300 | [diff] [blame] | 350 | static int |
| 351 | qtnf_event_handle_freq_change(struct qtnf_wmac *mac, |
| 352 | const struct qlink_event_freq_change *data, |
| 353 | u16 len) |
| 354 | { |
| 355 | struct wiphy *wiphy = priv_to_wiphy(mac); |
| 356 | struct cfg80211_chan_def chandef; |
Sergey Matyukevich | 97883695 | 2017-07-28 02:06:50 +0300 | [diff] [blame] | 357 | struct qtnf_vif *vif; |
Sergey Matyukevich | 97883695 | 2017-07-28 02:06:50 +0300 | [diff] [blame] | 358 | int i; |
| 359 | |
| 360 | if (len < sizeof(*data)) { |
Igor Mitsyanko | fac7f9b | 2017-09-21 14:34:30 -0700 | [diff] [blame] | 361 | pr_err("MAC%u: payload is too short\n", mac->macid); |
Sergey Matyukevich | 97883695 | 2017-07-28 02:06:50 +0300 | [diff] [blame] | 362 | return -EINVAL; |
| 363 | } |
| 364 | |
Igor Mitsyanko | 115af85 | 2017-09-21 14:34:37 -0700 | [diff] [blame] | 365 | if (!wiphy->registered) |
| 366 | return 0; |
| 367 | |
Igor Mitsyanko | fac7f9b | 2017-09-21 14:34:30 -0700 | [diff] [blame] | 368 | qlink_chandef_q2cfg(wiphy, &data->chan, &chandef); |
| 369 | |
| 370 | if (!cfg80211_chandef_valid(&chandef)) { |
Sergey Matyukevich | 5bf374a | 2017-12-19 14:28:48 +0300 | [diff] [blame] | 371 | pr_err("MAC%u: bad channel freq=%u cf1=%u cf2=%u bw=%u\n", |
| 372 | mac->macid, chandef.chan->center_freq, |
Igor Mitsyanko | fac7f9b | 2017-09-21 14:34:30 -0700 | [diff] [blame] | 373 | chandef.center_freq1, chandef.center_freq2, |
| 374 | chandef.width); |
Sergey Matyukevich | 97883695 | 2017-07-28 02:06:50 +0300 | [diff] [blame] | 375 | return -EINVAL; |
| 376 | } |
| 377 | |
Igor Mitsyanko | fac7f9b | 2017-09-21 14:34:30 -0700 | [diff] [blame] | 378 | pr_debug("MAC%d: new channel ieee=%u freq1=%u freq2=%u bw=%u\n", |
| 379 | mac->macid, chandef.chan->hw_value, chandef.center_freq1, |
| 380 | chandef.center_freq2, chandef.width); |
Sergey Matyukevich | 97883695 | 2017-07-28 02:06:50 +0300 | [diff] [blame] | 381 | |
Sergey Matyukevich | 97883695 | 2017-07-28 02:06:50 +0300 | [diff] [blame] | 382 | for (i = 0; i < QTNF_MAX_INTF; i++) { |
| 383 | vif = &mac->iflist[i]; |
| 384 | if (vif->wdev.iftype == NL80211_IFTYPE_UNSPECIFIED) |
| 385 | continue; |
| 386 | |
| 387 | if (vif->netdev) { |
| 388 | mutex_lock(&vif->wdev.mtx); |
| 389 | cfg80211_ch_switch_notify(vif->netdev, &chandef); |
| 390 | mutex_unlock(&vif->wdev.mtx); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
Igor Mitsyanko | b05ee45 | 2017-12-19 14:28:49 +0300 | [diff] [blame] | 397 | static int qtnf_event_handle_radar(struct qtnf_vif *vif, |
| 398 | const struct qlink_event_radar *ev, |
| 399 | u16 len) |
| 400 | { |
| 401 | struct wiphy *wiphy = priv_to_wiphy(vif->mac); |
| 402 | struct cfg80211_chan_def chandef; |
| 403 | |
| 404 | if (len < sizeof(*ev)) { |
| 405 | pr_err("MAC%u: payload is too short\n", vif->mac->macid); |
| 406 | return -EINVAL; |
| 407 | } |
| 408 | |
| 409 | if (!wiphy->registered || !vif->netdev) |
| 410 | return 0; |
| 411 | |
| 412 | qlink_chandef_q2cfg(wiphy, &ev->chan, &chandef); |
| 413 | |
| 414 | if (!cfg80211_chandef_valid(&chandef)) { |
| 415 | pr_err("MAC%u: bad channel f1=%u f2=%u bw=%u\n", |
| 416 | vif->mac->macid, |
| 417 | chandef.center_freq1, chandef.center_freq2, |
| 418 | chandef.width); |
| 419 | return -EINVAL; |
| 420 | } |
| 421 | |
| 422 | pr_info("%s: radar event=%u f1=%u f2=%u bw=%u\n", |
| 423 | vif->netdev->name, ev->event, |
| 424 | chandef.center_freq1, chandef.center_freq2, |
| 425 | chandef.width); |
| 426 | |
| 427 | switch (ev->event) { |
| 428 | case QLINK_RADAR_DETECTED: |
| 429 | cfg80211_radar_event(wiphy, &chandef, GFP_KERNEL); |
| 430 | break; |
| 431 | case QLINK_RADAR_CAC_FINISHED: |
| 432 | if (!vif->wdev.cac_started) |
| 433 | break; |
| 434 | |
| 435 | cfg80211_cac_event(vif->netdev, &chandef, |
| 436 | NL80211_RADAR_CAC_FINISHED, GFP_KERNEL); |
| 437 | break; |
| 438 | case QLINK_RADAR_CAC_ABORTED: |
| 439 | if (!vif->wdev.cac_started) |
| 440 | break; |
| 441 | |
| 442 | cfg80211_cac_event(vif->netdev, &chandef, |
| 443 | NL80211_RADAR_CAC_ABORTED, GFP_KERNEL); |
| 444 | break; |
| 445 | default: |
| 446 | pr_warn("%s: unhandled radar event %u\n", |
| 447 | vif->netdev->name, ev->event); |
| 448 | break; |
| 449 | } |
| 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 454 | static int qtnf_event_parse(struct qtnf_wmac *mac, |
| 455 | const struct sk_buff *event_skb) |
| 456 | { |
| 457 | const struct qlink_event *event; |
| 458 | struct qtnf_vif *vif = NULL; |
| 459 | int ret = -1; |
| 460 | u16 event_id; |
| 461 | u16 event_len; |
| 462 | |
| 463 | event = (const struct qlink_event *)event_skb->data; |
| 464 | event_id = le16_to_cpu(event->event_id); |
| 465 | event_len = le16_to_cpu(event->mhdr.len); |
| 466 | |
| 467 | if (likely(event->vifid < QTNF_MAX_INTF)) { |
| 468 | vif = &mac->iflist[event->vifid]; |
| 469 | } else { |
| 470 | pr_err("invalid vif(%u)\n", event->vifid); |
| 471 | return -EINVAL; |
| 472 | } |
| 473 | |
| 474 | switch (event_id) { |
| 475 | case QLINK_EVENT_STA_ASSOCIATED: |
| 476 | ret = qtnf_event_handle_sta_assoc(mac, vif, (const void *)event, |
| 477 | event_len); |
| 478 | break; |
| 479 | case QLINK_EVENT_STA_DEAUTH: |
| 480 | ret = qtnf_event_handle_sta_deauth(mac, vif, |
| 481 | (const void *)event, |
| 482 | event_len); |
| 483 | break; |
| 484 | case QLINK_EVENT_MGMT_RECEIVED: |
| 485 | ret = qtnf_event_handle_mgmt_received(vif, (const void *)event, |
| 486 | event_len); |
| 487 | break; |
| 488 | case QLINK_EVENT_SCAN_RESULTS: |
| 489 | ret = qtnf_event_handle_scan_results(vif, (const void *)event, |
| 490 | event_len); |
| 491 | break; |
| 492 | case QLINK_EVENT_SCAN_COMPLETE: |
| 493 | ret = qtnf_event_handle_scan_complete(mac, (const void *)event, |
| 494 | event_len); |
| 495 | break; |
| 496 | case QLINK_EVENT_BSS_JOIN: |
| 497 | ret = qtnf_event_handle_bss_join(vif, (const void *)event, |
| 498 | event_len); |
| 499 | break; |
| 500 | case QLINK_EVENT_BSS_LEAVE: |
| 501 | ret = qtnf_event_handle_bss_leave(vif, (const void *)event, |
| 502 | event_len); |
| 503 | break; |
Sergey Matyukevich | 97883695 | 2017-07-28 02:06:50 +0300 | [diff] [blame] | 504 | case QLINK_EVENT_FREQ_CHANGE: |
| 505 | ret = qtnf_event_handle_freq_change(mac, (const void *)event, |
| 506 | event_len); |
| 507 | break; |
Igor Mitsyanko | b05ee45 | 2017-12-19 14:28:49 +0300 | [diff] [blame] | 508 | case QLINK_EVENT_RADAR: |
| 509 | ret = qtnf_event_handle_radar(vif, (const void *)event, |
| 510 | event_len); |
| 511 | break; |
Igor Mitsyanko | 98f44cb | 2017-05-11 14:51:01 -0700 | [diff] [blame] | 512 | default: |
| 513 | pr_warn("unknown event type: %x\n", event_id); |
| 514 | break; |
| 515 | } |
| 516 | |
| 517 | return ret; |
| 518 | } |
| 519 | |
| 520 | static int qtnf_event_process_skb(struct qtnf_bus *bus, |
| 521 | const struct sk_buff *skb) |
| 522 | { |
| 523 | const struct qlink_event *event; |
| 524 | struct qtnf_wmac *mac; |
| 525 | int res; |
| 526 | |
| 527 | if (unlikely(!skb || skb->len < sizeof(*event))) { |
| 528 | pr_err("invalid event buffer\n"); |
| 529 | return -EINVAL; |
| 530 | } |
| 531 | |
| 532 | event = (struct qlink_event *)skb->data; |
| 533 | |
| 534 | mac = qtnf_core_get_mac(bus, event->macid); |
| 535 | |
| 536 | pr_debug("new event id:%x len:%u mac:%u vif:%u\n", |
| 537 | le16_to_cpu(event->event_id), le16_to_cpu(event->mhdr.len), |
| 538 | event->macid, event->vifid); |
| 539 | |
| 540 | if (unlikely(!mac)) |
| 541 | return -ENXIO; |
| 542 | |
| 543 | qtnf_bus_lock(bus); |
| 544 | res = qtnf_event_parse(mac, skb); |
| 545 | qtnf_bus_unlock(bus); |
| 546 | |
| 547 | return res; |
| 548 | } |
| 549 | |
| 550 | void qtnf_event_work_handler(struct work_struct *work) |
| 551 | { |
| 552 | struct qtnf_bus *bus = container_of(work, struct qtnf_bus, event_work); |
| 553 | struct sk_buff_head *event_queue = &bus->trans.event_queue; |
| 554 | struct sk_buff *current_event_skb = skb_dequeue(event_queue); |
| 555 | |
| 556 | while (current_event_skb) { |
| 557 | qtnf_event_process_skb(bus, current_event_skb); |
| 558 | dev_kfree_skb_any(current_event_skb); |
| 559 | current_event_skb = skb_dequeue(event_queue); |
| 560 | } |
| 561 | } |