1 // SPDX-License-Identifier: GPL-2.0-only
3 * Datapath implementation.
5 * Copyright (c) 2017-2019, Silicon Laboratories, Inc.
6 * Copyright (c) 2010, ST-Ericsson
8 #include <linux/etherdevice.h>
9 #include <net/mac80211.h>
16 static int wfx_drop_encrypt_data(struct wfx_dev *wdev,
17 const struct hif_ind_rx *arg,
20 struct ieee80211_hdr *frame = (struct ieee80211_hdr *) skb->data;
21 size_t hdrlen = ieee80211_hdrlen(frame->frame_control);
22 size_t iv_len, icv_len;
24 /* Oops... There is no fast way to ask mac80211 about
25 * IV/ICV lengths. Even defineas are not exposed.
27 switch (arg->rx_flags.encryp) {
28 case HIF_RI_FLAGS_WEP_ENCRYPTED:
29 iv_len = 4 /* WEP_IV_LEN */;
30 icv_len = 4 /* WEP_ICV_LEN */;
32 case HIF_RI_FLAGS_TKIP_ENCRYPTED:
33 iv_len = 8 /* TKIP_IV_LEN */;
34 icv_len = 4 /* TKIP_ICV_LEN */
35 + 8 /*MICHAEL_MIC_LEN*/;
37 case HIF_RI_FLAGS_AES_ENCRYPTED:
38 iv_len = 8 /* CCMP_HDR_LEN */;
39 icv_len = 8 /* CCMP_MIC_LEN */;
41 case HIF_RI_FLAGS_WAPI_ENCRYPTED:
42 iv_len = 18 /* WAPI_HDR_LEN */;
43 icv_len = 16 /* WAPI_MIC_LEN */;
46 dev_err(wdev->dev, "unknown encryption type %d\n",
47 arg->rx_flags.encryp);
51 /* Firmware strips ICV in case of MIC failure. */
52 if (arg->status == HIF_STATUS_MICFAILURE)
55 if (skb->len < hdrlen + iv_len + icv_len) {
56 dev_warn(wdev->dev, "malformed SDU received\n");
60 /* Remove IV, ICV and MIC */
61 skb_trim(skb, skb->len - icv_len);
62 memmove(skb->data + iv_len, skb->data, hdrlen);
63 skb_pull(skb, iv_len);
68 void wfx_rx_cb(struct wfx_vif *wvif,
69 const struct hif_ind_rx *arg, struct sk_buff *skb)
71 struct ieee80211_rx_status *hdr = IEEE80211_SKB_RXCB(skb);
72 struct ieee80211_hdr *frame = (struct ieee80211_hdr *)skb->data;
73 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
75 memset(hdr, 0, sizeof(*hdr));
77 // FIXME: Why do we drop these frames?
78 if (!arg->rcpi_rssi &&
79 (ieee80211_is_probe_resp(frame->frame_control) ||
80 ieee80211_is_beacon(frame->frame_control)))
83 if (arg->status == HIF_STATUS_MICFAILURE)
84 hdr->flag |= RX_FLAG_MMIC_ERROR;
88 if (skb->len < sizeof(struct ieee80211_pspoll)) {
89 dev_warn(wvif->wdev->dev, "malformed SDU received\n");
93 hdr->band = NL80211_BAND_2GHZ;
94 hdr->freq = ieee80211_channel_to_frequency(arg->channel_number,
97 if (arg->rxed_rate >= 14) {
98 hdr->encoding = RX_ENC_HT;
99 hdr->rate_idx = arg->rxed_rate - 14;
100 } else if (arg->rxed_rate >= 4) {
101 hdr->rate_idx = arg->rxed_rate - 2;
103 hdr->rate_idx = arg->rxed_rate;
106 hdr->signal = arg->rcpi_rssi / 2 - 110;
109 if (arg->rx_flags.encryp) {
110 if (wfx_drop_encrypt_data(wvif->wdev, arg, skb))
112 hdr->flag |= RX_FLAG_DECRYPTED | RX_FLAG_IV_STRIPPED;
113 if (arg->rx_flags.encryp == HIF_RI_FLAGS_TKIP_ENCRYPTED)
114 hdr->flag |= RX_FLAG_MMIC_STRIPPED;
117 /* Filter block ACK negotiation: fully controlled by firmware */
118 if (ieee80211_is_action(frame->frame_control) &&
119 arg->rx_flags.match_uc_addr &&
120 mgmt->u.action.category == WLAN_CATEGORY_BACK)
122 if (ieee80211_is_beacon(frame->frame_control) &&
123 !arg->status && wvif->vif &&
124 ether_addr_equal(ieee80211_get_SA(frame),
125 wvif->vif->bss_conf.bssid)) {
126 /* Disable beacon filter once we're associated... */
127 if (wvif->disable_beacon_filter &&
128 (wvif->vif->bss_conf.assoc ||
129 wvif->vif->bss_conf.ibss_joined)) {
130 wvif->disable_beacon_filter = false;
131 schedule_work(&wvif->update_filtering_work);
134 ieee80211_rx_irqsafe(wvif->wdev->hw, skb);