mac80211: fix monitor-only injection
[openwrt.git] / package / mac80211 / patches / 300-pending_work.patch
1 --- a/drivers/net/wireless/ath/ath9k/common.h
2 +++ b/drivers/net/wireless/ath/ath9k/common.h
3 @@ -27,7 +27,7 @@
4  #define WME_MAX_BA              WME_BA_BMP_SIZE
5  #define ATH_TID_MAX_BUFS        (2 * WME_MAX_BA)
6  
7 -#define ATH_RSSI_DUMMY_MARKER   0x127
8 +#define ATH_RSSI_DUMMY_MARKER   127
9  #define ATH_RSSI_LPF_LEN               10
10  #define RSSI_LPF_THRESHOLD             -20
11  #define ATH_RSSI_EP_MULTIPLIER     (1<<7)
12 --- a/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c
13 +++ b/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c
14 @@ -1067,15 +1067,19 @@ static bool ath9k_rx_prepare(struct ath9
15  
16         last_rssi = priv->rx.last_rssi;
17  
18 -       if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
19 -               rxbuf->rxstatus.rs_rssi = ATH_EP_RND(last_rssi,
20 -                                                    ATH_RSSI_EP_MULTIPLIER);
21 +       if (ieee80211_is_beacon(hdr->frame_control) &&
22 +           !is_zero_ether_addr(common->curbssid) &&
23 +           ether_addr_equal(hdr->addr3, common->curbssid)) {
24 +               s8 rssi = rxbuf->rxstatus.rs_rssi;
25  
26 -       if (rxbuf->rxstatus.rs_rssi < 0)
27 -               rxbuf->rxstatus.rs_rssi = 0;
28 +               if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
29 +                       rssi = ATH_EP_RND(last_rssi, ATH_RSSI_EP_MULTIPLIER);
30  
31 -       if (ieee80211_is_beacon(fc))
32 -               priv->ah->stats.avgbrssi = rxbuf->rxstatus.rs_rssi;
33 +               if (rssi < 0)
34 +                       rssi = 0;
35 +
36 +               priv->ah->stats.avgbrssi = rssi;
37 +       }
38  
39         rx_status->mactime = be64_to_cpu(rxbuf->rxstatus.rs_tstamp);
40         rx_status->band = hw->conf.channel->band;
41 --- a/include/linux/ieee80211.h
42 +++ b/include/linux/ieee80211.h
43 @@ -185,7 +185,7 @@ struct ieee80211_hdr {
44         u8 addr3[6];
45         __le16 seq_ctrl;
46         u8 addr4[6];
47 -} __packed;
48 +} __packed __aligned(2);
49  
50  struct ieee80211_hdr_3addr {
51         __le16 frame_control;
52 @@ -194,7 +194,7 @@ struct ieee80211_hdr_3addr {
53         u8 addr2[6];
54         u8 addr3[6];
55         __le16 seq_ctrl;
56 -} __packed;
57 +} __packed __aligned(2);
58  
59  struct ieee80211_qos_hdr {
60         __le16 frame_control;
61 @@ -204,7 +204,7 @@ struct ieee80211_qos_hdr {
62         u8 addr3[6];
63         __le16 seq_ctrl;
64         __le16 qos_ctrl;
65 -} __packed;
66 +} __packed __aligned(2);
67  
68  /**
69   * ieee80211_has_tods - check if IEEE80211_FCTL_TODS is set
70 @@ -581,7 +581,7 @@ struct ieee80211s_hdr {
71         __le32 seqnum;
72         u8 eaddr1[6];
73         u8 eaddr2[6];
74 -} __packed;
75 +} __packed __aligned(2);
76  
77  /* Mesh flags */
78  #define MESH_FLAGS_AE_A4       0x1
79 @@ -875,7 +875,7 @@ struct ieee80211_mgmt {
80                         } u;
81                 } __packed action;
82         } u;
83 -} __packed;
84 +} __packed __aligned(2);
85  
86  /* Supported Rates value encodings in 802.11n-2009 7.3.2.2 */
87  #define BSS_MEMBERSHIP_SELECTOR_HT_PHY 127
88 @@ -906,20 +906,20 @@ struct ieee80211_rts {
89         __le16 duration;
90         u8 ra[6];
91         u8 ta[6];
92 -} __packed;
93 +} __packed __aligned(2);
94  
95  struct ieee80211_cts {
96         __le16 frame_control;
97         __le16 duration;
98         u8 ra[6];
99 -} __packed;
100 +} __packed __aligned(2);
101  
102  struct ieee80211_pspoll {
103         __le16 frame_control;
104         __le16 aid;
105         u8 bssid[6];
106         u8 ta[6];
107 -} __packed;
108 +} __packed __aligned(2);
109  
110  /* TDLS */
111  
112 --- a/net/mac80211/agg-rx.c
113 +++ b/net/mac80211/agg-rx.c
114 @@ -204,6 +204,8 @@ static void ieee80211_send_addba_resp(st
115                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
116         else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
117                 memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
118 +       else if (sdata->vif.type == NL80211_IFTYPE_WDS)
119 +               memcpy(mgmt->bssid, da, ETH_ALEN);
120  
121         mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
122                                           IEEE80211_STYPE_ACTION);
123 --- a/net/mac80211/agg-tx.c
124 +++ b/net/mac80211/agg-tx.c
125 @@ -81,7 +81,8 @@ static void ieee80211_send_addba_request
126         memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
127         if (sdata->vif.type == NL80211_IFTYPE_AP ||
128             sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
129 -           sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
130 +           sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
131 +           sdata->vif.type == NL80211_IFTYPE_WDS)
132                 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
133         else if (sdata->vif.type == NL80211_IFTYPE_STATION)
134                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
135 @@ -527,6 +528,7 @@ int ieee80211_start_tx_ba_session(struct
136             sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
137             sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
138             sdata->vif.type != NL80211_IFTYPE_AP &&
139 +           sdata->vif.type != NL80211_IFTYPE_WDS &&
140             sdata->vif.type != NL80211_IFTYPE_ADHOC)
141                 return -EINVAL;
142  
143 --- a/net/mac80211/debugfs_sta.c
144 +++ b/net/mac80211/debugfs_sta.c
145 @@ -65,11 +65,11 @@ static ssize_t sta_flags_read(struct fil
146         test_sta_flag(sta, WLAN_STA_##flg) ? #flg "\n" : ""
147  
148         int res = scnprintf(buf, sizeof(buf),
149 -                           "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
150 +                           "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
151                             TEST(AUTH), TEST(ASSOC), TEST(PS_STA),
152                             TEST(PS_DRIVER), TEST(AUTHORIZED),
153                             TEST(SHORT_PREAMBLE),
154 -                           TEST(WME), TEST(WDS), TEST(CLEAR_PS_FILT),
155 +                           TEST(WME), TEST(CLEAR_PS_FILT),
156                             TEST(MFP), TEST(BLOCK_BA), TEST(PSPOLL),
157                             TEST(UAPSD), TEST(SP), TEST(TDLS_PEER),
158                             TEST(TDLS_PEER_AUTH), TEST(4ADDR_EVENT),
159 --- a/net/mac80211/iface.c
160 +++ b/net/mac80211/iface.c
161 @@ -107,7 +107,7 @@ void ieee80211_recalc_idle(struct ieee80
162  
163         lockdep_assert_held(&local->mtx);
164  
165 -       active = !list_empty(&local->chanctx_list);
166 +       active = !list_empty(&local->chanctx_list) || local->monitors;
167  
168         if (!local->ops->remain_on_channel) {
169                 list_for_each_entry(roc, &local->roc_list, list) {
170 @@ -436,7 +436,6 @@ int ieee80211_do_open(struct wireless_de
171         struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
172         struct net_device *dev = wdev->netdev;
173         struct ieee80211_local *local = sdata->local;
174 -       struct sta_info *sta;
175         u32 changed = 0;
176         int res;
177         u32 hw_reconf_flags = 0;
178 @@ -595,30 +594,8 @@ int ieee80211_do_open(struct wireless_de
179  
180         set_bit(SDATA_STATE_RUNNING, &sdata->state);
181  
182 -       if (sdata->vif.type == NL80211_IFTYPE_WDS) {
183 -               /* Create STA entry for the WDS peer */
184 -               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
185 -                                    GFP_KERNEL);
186 -               if (!sta) {
187 -                       res = -ENOMEM;
188 -                       goto err_del_interface;
189 -               }
190 -
191 -               sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
192 -               sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
193 -               sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
194 -
195 -               res = sta_info_insert(sta);
196 -               if (res) {
197 -                       /* STA has been freed */
198 -                       goto err_del_interface;
199 -               }
200 -
201 -               rate_control_rate_init(sta);
202 -               netif_carrier_on(dev);
203 -       } else if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
204 +       if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE)
205                 rcu_assign_pointer(local->p2p_sdata, sdata);
206 -       }
207  
208         /*
209          * set_multicast_list will be invoked by the networking core
210 @@ -1022,6 +999,72 @@ static void ieee80211_if_setup(struct ne
211         dev->destructor = free_netdev;
212  }
213  
214 +static void ieee80211_wds_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
215 +                                        struct sk_buff *skb)
216 +{
217 +       struct ieee80211_local *local = sdata->local;
218 +       struct ieee80211_rx_status *rx_status;
219 +       struct ieee802_11_elems elems;
220 +       struct ieee80211_mgmt *mgmt;
221 +       struct sta_info *sta;
222 +       size_t baselen;
223 +       u32 rates = 0;
224 +       u16 stype;
225 +       bool new = false;
226 +       enum ieee80211_band band = local->hw.conf.channel->band;
227 +       struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
228 +
229 +       rx_status = IEEE80211_SKB_RXCB(skb);
230 +       mgmt = (struct ieee80211_mgmt *) skb->data;
231 +       stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
232 +
233 +       if (stype != IEEE80211_STYPE_BEACON)
234 +               return;
235 +
236 +       baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
237 +       if (baselen > skb->len)
238 +               return;
239 +
240 +       ieee802_11_parse_elems(mgmt->u.probe_resp.variable,
241 +                              skb->len - baselen, &elems);
242 +
243 +       rates = ieee80211_sta_get_rates(local, &elems, band, NULL);
244 +
245 +       rcu_read_lock();
246 +
247 +       sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
248 +
249 +       if (!sta) {
250 +               rcu_read_unlock();
251 +               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
252 +                                    GFP_KERNEL);
253 +               if (!sta)
254 +                       return;
255 +
256 +               new = true;
257 +       }
258 +
259 +       sta->last_rx = jiffies;
260 +       sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
261 +
262 +       if (elems.ht_cap_elem)
263 +               ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
264 +                               elems.ht_cap_elem, sta);
265 +
266 +       if (elems.wmm_param)
267 +               set_sta_flag(sta, WLAN_STA_WME);
268 +
269 +       if (new) {
270 +               sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
271 +               sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
272 +               sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
273 +               rate_control_rate_init(sta);
274 +               sta_info_insert_rcu(sta);
275 +       }
276 +
277 +       rcu_read_unlock();
278 +}
279 +
280  static void ieee80211_iface_work(struct work_struct *work)
281  {
282         struct ieee80211_sub_if_data *sdata =
283 @@ -1126,6 +1169,9 @@ static void ieee80211_iface_work(struct 
284                                 break;
285                         ieee80211_mesh_rx_queued_mgmt(sdata, skb);
286                         break;
287 +               case NL80211_IFTYPE_WDS:
288 +                       ieee80211_wds_rx_queued_mgmt(sdata, skb);
289 +                       break;
290                 default:
291                         WARN(1, "frame for unexpected interface type");
292                         break;
293 --- a/net/mac80211/rx.c
294 +++ b/net/mac80211/rx.c
295 @@ -2365,6 +2365,7 @@ ieee80211_rx_h_action(struct ieee80211_r
296                     sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
297                     sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
298                     sdata->vif.type != NL80211_IFTYPE_AP &&
299 +                   sdata->vif.type != NL80211_IFTYPE_WDS &&
300                     sdata->vif.type != NL80211_IFTYPE_ADHOC)
301                         break;
302  
303 @@ -2692,14 +2693,15 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_
304  
305         if (!ieee80211_vif_is_mesh(&sdata->vif) &&
306             sdata->vif.type != NL80211_IFTYPE_ADHOC &&
307 -           sdata->vif.type != NL80211_IFTYPE_STATION)
308 +           sdata->vif.type != NL80211_IFTYPE_STATION &&
309 +           sdata->vif.type != NL80211_IFTYPE_WDS)
310                 return RX_DROP_MONITOR;
311  
312         switch (stype) {
313         case cpu_to_le16(IEEE80211_STYPE_AUTH):
314         case cpu_to_le16(IEEE80211_STYPE_BEACON):
315         case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
316 -               /* process for all: mesh, mlme, ibss */
317 +               /* process for all: mesh, mlme, ibss, wds */
318                 break;
319         case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
320         case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
321 @@ -3028,10 +3030,16 @@ static int prepare_for_handlers(struct i
322                 }
323                 break;
324         case NL80211_IFTYPE_WDS:
325 -               if (bssid || !ieee80211_is_data(hdr->frame_control))
326 -                       return 0;
327                 if (!ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2))
328                         return 0;
329 +
330 +               if (ieee80211_is_data(hdr->frame_control) ||
331 +                   ieee80211_is_action(hdr->frame_control)) {
332 +                       if (compare_ether_addr(sdata->vif.addr, hdr->addr1))
333 +                               return 0;
334 +               } else if (!ieee80211_is_beacon(hdr->frame_control))
335 +                       return 0;
336 +
337                 break;
338         case NL80211_IFTYPE_P2P_DEVICE:
339                 if (!ieee80211_is_public_action(hdr, skb->len) &&
340 --- a/net/mac80211/sta_info.h
341 +++ b/net/mac80211/sta_info.h
342 @@ -32,7 +32,6 @@
343   * @WLAN_STA_SHORT_PREAMBLE: Station is capable of receiving short-preamble
344   *     frames.
345   * @WLAN_STA_WME: Station is a QoS-STA.
346 - * @WLAN_STA_WDS: Station is one of our WDS peers.
347   * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
348   *     IEEE80211_TX_CTL_CLEAR_PS_FILT control flag) when the next
349   *     frame to this station is transmitted.
350 @@ -66,7 +65,6 @@ enum ieee80211_sta_info_flags {
351         WLAN_STA_AUTHORIZED,
352         WLAN_STA_SHORT_PREAMBLE,
353         WLAN_STA_WME,
354 -       WLAN_STA_WDS,
355         WLAN_STA_CLEAR_PS_FILT,
356         WLAN_STA_MFP,
357         WLAN_STA_BLOCK_BA,
358 --- a/net/mac80211/tx.c
359 +++ b/net/mac80211/tx.c
360 @@ -1848,9 +1848,24 @@ netdev_tx_t ieee80211_subif_start_xmit(s
361                 }
362  
363                 if (!is_multicast_ether_addr(skb->data)) {
364 +                       struct sta_info *next_hop;
365 +                       bool mpp_lookup = true;
366 +
367                         mpath = mesh_path_lookup(sdata, skb->data);
368 -                       if (!mpath)
369 +                       if (mpath) {
370 +                               mpp_lookup = false;
371 +                               next_hop = rcu_dereference(mpath->next_hop);
372 +                               if (!next_hop ||
373 +                                   !(mpath->flags & (MESH_PATH_ACTIVE |
374 +                                                     MESH_PATH_RESOLVING)))
375 +                                       mpp_lookup = true;
376 +                       }
377 +
378 +                       if (mpp_lookup)
379                                 mppath = mpp_path_lookup(sdata, skb->data);
380 +
381 +                       if (mppath && mpath)
382 +                               mesh_path_del(mpath->sdata, mpath->dst);
383                 }
384  
385                 /*
386 --- a/net/wireless/nl80211.c
387 +++ b/net/wireless/nl80211.c
388 @@ -554,16 +554,9 @@ static int nl80211_msg_put_channel(struc
389         if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
390             nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
391                 goto nla_put_failure;
392 -       if (chan->flags & IEEE80211_CHAN_RADAR) {
393 -               u32 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
394 -               if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
395 -                       goto nla_put_failure;
396 -               if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
397 -                               chan->dfs_state))
398 -                       goto nla_put_failure;
399 -               if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, time))
400 -                       goto nla_put_failure;
401 -       }
402 +       if ((chan->flags & IEEE80211_CHAN_RADAR) &&
403 +           nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
404 +               goto nla_put_failure;
405         if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
406             nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
407                 goto nla_put_failure;
408 @@ -900,9 +893,6 @@ static int nl80211_put_iface_combination
409                     nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
410                                 c->max_interfaces))
411                         goto nla_put_failure;
412 -               if (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
413 -                               c->radar_detect_widths))
414 -                       goto nla_put_failure;
415  
416                 nla_nest_end(msg, nl_combi);
417         }
418 @@ -914,48 +904,6 @@ nla_put_failure:
419         return -ENOBUFS;
420  }
421  
422 -#ifdef CONFIG_PM
423 -static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
424 -                                       struct sk_buff *msg)
425 -{
426 -       const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp;
427 -       struct nlattr *nl_tcp;
428 -
429 -       if (!tcp)
430 -               return 0;
431 -
432 -       nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
433 -       if (!nl_tcp)
434 -               return -ENOBUFS;
435 -
436 -       if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
437 -                       tcp->data_payload_max))
438 -               return -ENOBUFS;
439 -
440 -       if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
441 -                       tcp->data_payload_max))
442 -               return -ENOBUFS;
443 -
444 -       if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
445 -               return -ENOBUFS;
446 -
447 -       if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
448 -                               sizeof(*tcp->tok), tcp->tok))
449 -               return -ENOBUFS;
450 -
451 -       if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
452 -                       tcp->data_interval_max))
453 -               return -ENOBUFS;
454 -
455 -       if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
456 -                       tcp->wake_payload_max))
457 -               return -ENOBUFS;
458 -
459 -       nla_nest_end(msg, nl_tcp);
460 -       return 0;
461 -}
462 -#endif
463 -
464  static int nl80211_send_wiphy(struct sk_buff *msg, u32 portid, u32 seq, int flags,
465                               struct cfg80211_registered_device *dev)
466  {
467 @@ -1330,9 +1278,6 @@ static int nl80211_send_wiphy(struct sk_
468                                 goto nla_put_failure;
469                 }
470  
471 -               if (nl80211_send_wowlan_tcp_caps(dev, msg))
472 -                       goto nla_put_failure;
473 -
474                 nla_nest_end(msg, nl_wowlan);
475         }
476  #endif