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);
67 void wfx_rx_cb(struct wfx_vif *wvif,
68 const struct hif_ind_rx *arg, struct sk_buff *skb)
70 struct ieee80211_rx_status *hdr = IEEE80211_SKB_RXCB(skb);
71 struct ieee80211_hdr *frame = (struct ieee80211_hdr *)skb->data;
72 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
74 memset(hdr, 0, sizeof(*hdr));
76 // FIXME: Why do we drop these frames?
77 if (!arg->rcpi_rssi &&
78 (ieee80211_is_probe_resp(frame->frame_control) ||
79 ieee80211_is_beacon(frame->frame_control)))
82 if (arg->status == HIF_STATUS_MICFAILURE)
83 hdr->flag |= RX_FLAG_MMIC_ERROR;
87 if (skb->len < sizeof(struct ieee80211_pspoll)) {
88 dev_warn(wvif->wdev->dev, "malformed SDU received\n");
92 hdr->band = NL80211_BAND_2GHZ;
93 hdr->freq = ieee80211_channel_to_frequency(arg->channel_number,
96 if (arg->rxed_rate >= 14) {
97 hdr->encoding = RX_ENC_HT;
98 hdr->rate_idx = arg->rxed_rate - 14;
99 } else if (arg->rxed_rate >= 4) {
100 hdr->rate_idx = arg->rxed_rate - 2;
102 hdr->rate_idx = arg->rxed_rate;
105 hdr->signal = arg->rcpi_rssi / 2 - 110;
108 if (arg->rx_flags.encryp) {
109 if (wfx_drop_encrypt_data(wvif->wdev, arg, skb))
111 hdr->flag |= RX_FLAG_DECRYPTED | RX_FLAG_IV_STRIPPED;
112 if (arg->rx_flags.encryp == HIF_RI_FLAGS_TKIP_ENCRYPTED)
113 hdr->flag |= RX_FLAG_MMIC_STRIPPED;
116 /* Filter block ACK negotiation: fully controlled by firmware */
117 if (ieee80211_is_action(frame->frame_control) &&
118 arg->rx_flags.match_uc_addr &&
119 mgmt->u.action.category == WLAN_CATEGORY_BACK)
121 if (ieee80211_is_beacon(frame->frame_control) &&
122 !arg->status && wvif->vif &&
123 ether_addr_equal(ieee80211_get_SA(frame),
124 wvif->vif->bss_conf.bssid)) {
125 /* Disable beacon filter once we're associated... */
126 if (wvif->disable_beacon_filter &&
127 (wvif->vif->bss_conf.assoc ||
128 wvif->vif->bss_conf.ibss_joined)) {
129 wvif->disable_beacon_filter = false;
130 schedule_work(&wvif->update_filtering_work);
133 ieee80211_rx_irqsafe(wvif->wdev->hw, skb);