This source file includes following definitions.
- mps_qos_null_get
- mps_qos_null_tx
- ieee80211_mps_local_status_update
- ieee80211_mps_set_sta_local_pm
- ieee80211_mps_set_frame_flags
- ieee80211_mps_sta_status_update
- mps_set_sta_peer_pm
- mps_set_sta_nonpeer_pm
- ieee80211_mps_rx_h_sta_process
- mpsp_trigger_send
- mpsp_qos_null_append
- mps_frame_deliver
- ieee80211_mpsp_trigger_process
- ieee80211_mps_frame_release
1
2
3
4
5
6
7 #include "mesh.h"
8 #include "wme.h"
9
10
11
12
13
14
15
16 static struct sk_buff *mps_qos_null_get(struct sta_info *sta)
17 {
18 struct ieee80211_sub_if_data *sdata = sta->sdata;
19 struct ieee80211_local *local = sdata->local;
20 struct ieee80211_hdr *nullfunc;
21 struct sk_buff *skb;
22 int size = sizeof(*nullfunc);
23 __le16 fc;
24
25 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size + 2);
26 if (!skb)
27 return NULL;
28 skb_reserve(skb, local->hw.extra_tx_headroom);
29
30 nullfunc = skb_put(skb, size);
31 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_NULLFUNC);
32 ieee80211_fill_mesh_addresses(nullfunc, &fc, sta->sta.addr,
33 sdata->vif.addr);
34 nullfunc->frame_control = fc;
35 nullfunc->duration_id = 0;
36 nullfunc->seq_ctrl = 0;
37
38 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
39 skb_put_zero(skb, 2);
40 ieee80211_mps_set_frame_flags(sdata, sta, nullfunc);
41
42 return skb;
43 }
44
45
46
47
48 static void mps_qos_null_tx(struct sta_info *sta)
49 {
50 struct sk_buff *skb;
51
52 skb = mps_qos_null_get(sta);
53 if (!skb)
54 return;
55
56 mps_dbg(sta->sdata, "announcing peer-specific power mode to %pM\n",
57 sta->sta.addr);
58
59
60 if (!test_sta_flag(sta, WLAN_STA_PS_STA)) {
61 u8 *qc = ieee80211_get_qos_ctl((void *) skb->data);
62
63 qc[0] |= IEEE80211_QOS_CTL_EOSP;
64 }
65
66 ieee80211_tx_skb(sta->sdata, skb);
67 }
68
69
70
71
72
73
74
75
76
77 u32 ieee80211_mps_local_status_update(struct ieee80211_sub_if_data *sdata)
78 {
79 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
80 struct sta_info *sta;
81 bool peering = false;
82 int light_sleep_cnt = 0;
83 int deep_sleep_cnt = 0;
84 u32 changed = 0;
85 enum nl80211_mesh_power_mode nonpeer_pm;
86
87 rcu_read_lock();
88 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
89 if (sdata != sta->sdata)
90 continue;
91
92 switch (sta->mesh->plink_state) {
93 case NL80211_PLINK_OPN_SNT:
94 case NL80211_PLINK_OPN_RCVD:
95 case NL80211_PLINK_CNF_RCVD:
96 peering = true;
97 break;
98 case NL80211_PLINK_ESTAB:
99 if (sta->mesh->local_pm == NL80211_MESH_POWER_LIGHT_SLEEP)
100 light_sleep_cnt++;
101 else if (sta->mesh->local_pm == NL80211_MESH_POWER_DEEP_SLEEP)
102 deep_sleep_cnt++;
103 break;
104 default:
105 break;
106 }
107 }
108 rcu_read_unlock();
109
110
111
112
113
114
115
116
117 if (peering) {
118 mps_dbg(sdata, "setting non-peer PM to active for peering\n");
119 nonpeer_pm = NL80211_MESH_POWER_ACTIVE;
120 } else if (light_sleep_cnt || deep_sleep_cnt) {
121 mps_dbg(sdata, "setting non-peer PM to deep sleep\n");
122 nonpeer_pm = NL80211_MESH_POWER_DEEP_SLEEP;
123 } else {
124 mps_dbg(sdata, "setting non-peer PM to user value\n");
125 nonpeer_pm = ifmsh->mshcfg.power_mode;
126 }
127
128
129 if (ifmsh->nonpeer_pm != nonpeer_pm ||
130 !ifmsh->ps_peers_light_sleep != !light_sleep_cnt ||
131 !ifmsh->ps_peers_deep_sleep != !deep_sleep_cnt)
132 changed = BSS_CHANGED_BEACON;
133
134 ifmsh->nonpeer_pm = nonpeer_pm;
135 ifmsh->ps_peers_light_sleep = light_sleep_cnt;
136 ifmsh->ps_peers_deep_sleep = deep_sleep_cnt;
137
138 return changed;
139 }
140
141
142
143
144
145
146
147
148 u32 ieee80211_mps_set_sta_local_pm(struct sta_info *sta,
149 enum nl80211_mesh_power_mode pm)
150 {
151 struct ieee80211_sub_if_data *sdata = sta->sdata;
152
153 if (sta->mesh->local_pm == pm)
154 return 0;
155
156 mps_dbg(sdata, "local STA operates in mode %d with %pM\n",
157 pm, sta->sta.addr);
158
159 sta->mesh->local_pm = pm;
160
161
162
163
164
165 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
166 mps_qos_null_tx(sta);
167
168 return ieee80211_mps_local_status_update(sdata);
169 }
170
171
172
173
174
175
176
177
178
179
180
181
182
183 void ieee80211_mps_set_frame_flags(struct ieee80211_sub_if_data *sdata,
184 struct sta_info *sta,
185 struct ieee80211_hdr *hdr)
186 {
187 enum nl80211_mesh_power_mode pm;
188 u8 *qc;
189
190 if (WARN_ON(is_unicast_ether_addr(hdr->addr1) &&
191 ieee80211_is_data_qos(hdr->frame_control) &&
192 !sta))
193 return;
194
195 if (is_unicast_ether_addr(hdr->addr1) &&
196 ieee80211_is_data_qos(hdr->frame_control) &&
197 sta->mesh->plink_state == NL80211_PLINK_ESTAB)
198 pm = sta->mesh->local_pm;
199 else
200 pm = sdata->u.mesh.nonpeer_pm;
201
202 if (pm == NL80211_MESH_POWER_ACTIVE)
203 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_PM);
204 else
205 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
206
207 if (!ieee80211_is_data_qos(hdr->frame_control))
208 return;
209
210 qc = ieee80211_get_qos_ctl(hdr);
211
212 if ((is_unicast_ether_addr(hdr->addr1) &&
213 pm == NL80211_MESH_POWER_DEEP_SLEEP) ||
214 (is_multicast_ether_addr(hdr->addr1) &&
215 sdata->u.mesh.ps_peers_deep_sleep > 0))
216 qc[1] |= (IEEE80211_QOS_CTL_MESH_PS_LEVEL >> 8);
217 else
218 qc[1] &= ~(IEEE80211_QOS_CTL_MESH_PS_LEVEL >> 8);
219 }
220
221
222
223
224
225
226
227
228 void ieee80211_mps_sta_status_update(struct sta_info *sta)
229 {
230 enum nl80211_mesh_power_mode pm;
231 bool do_buffer;
232
233
234 if (sta->sta_state < IEEE80211_STA_ASSOC)
235 return;
236
237
238
239
240
241 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB &&
242 sta->mesh->peer_pm != NL80211_MESH_POWER_UNKNOWN)
243 pm = sta->mesh->peer_pm;
244 else
245 pm = sta->mesh->nonpeer_pm;
246
247 do_buffer = (pm != NL80211_MESH_POWER_ACTIVE);
248
249
250 if (sta->mesh->plink_state != NL80211_PLINK_ESTAB) {
251 clear_sta_flag(sta, WLAN_STA_MPSP_OWNER);
252 clear_sta_flag(sta, WLAN_STA_MPSP_RECIPIENT);
253 } else if (!do_buffer) {
254 clear_sta_flag(sta, WLAN_STA_MPSP_OWNER);
255 }
256
257
258 if (test_sta_flag(sta, WLAN_STA_PS_STA) == do_buffer)
259 return;
260
261 if (do_buffer) {
262 set_sta_flag(sta, WLAN_STA_PS_STA);
263 atomic_inc(&sta->sdata->u.mesh.ps.num_sta_ps);
264 mps_dbg(sta->sdata, "start PS buffering frames towards %pM\n",
265 sta->sta.addr);
266 } else {
267 ieee80211_sta_ps_deliver_wakeup(sta);
268 }
269 }
270
271 static void mps_set_sta_peer_pm(struct sta_info *sta,
272 struct ieee80211_hdr *hdr)
273 {
274 enum nl80211_mesh_power_mode pm;
275 u8 *qc = ieee80211_get_qos_ctl(hdr);
276
277
278
279
280
281
282
283
284
285
286
287 if (ieee80211_has_pm(hdr->frame_control)) {
288 if (qc[1] & (IEEE80211_QOS_CTL_MESH_PS_LEVEL >> 8))
289 pm = NL80211_MESH_POWER_DEEP_SLEEP;
290 else
291 pm = NL80211_MESH_POWER_LIGHT_SLEEP;
292 } else {
293 pm = NL80211_MESH_POWER_ACTIVE;
294 }
295
296 if (sta->mesh->peer_pm == pm)
297 return;
298
299 mps_dbg(sta->sdata, "STA %pM enters mode %d\n",
300 sta->sta.addr, pm);
301
302 sta->mesh->peer_pm = pm;
303
304 ieee80211_mps_sta_status_update(sta);
305 }
306
307 static void mps_set_sta_nonpeer_pm(struct sta_info *sta,
308 struct ieee80211_hdr *hdr)
309 {
310 enum nl80211_mesh_power_mode pm;
311
312 if (ieee80211_has_pm(hdr->frame_control))
313 pm = NL80211_MESH_POWER_DEEP_SLEEP;
314 else
315 pm = NL80211_MESH_POWER_ACTIVE;
316
317 if (sta->mesh->nonpeer_pm == pm)
318 return;
319
320 mps_dbg(sta->sdata, "STA %pM sets non-peer mode to %d\n",
321 sta->sta.addr, pm);
322
323 sta->mesh->nonpeer_pm = pm;
324
325 ieee80211_mps_sta_status_update(sta);
326 }
327
328
329
330
331
332
333
334 void ieee80211_mps_rx_h_sta_process(struct sta_info *sta,
335 struct ieee80211_hdr *hdr)
336 {
337 if (is_unicast_ether_addr(hdr->addr1) &&
338 ieee80211_is_data_qos(hdr->frame_control)) {
339
340
341
342
343 mps_set_sta_peer_pm(sta, hdr);
344
345
346 ieee80211_mpsp_trigger_process(ieee80211_get_qos_ctl(hdr),
347 sta, false, false);
348 } else {
349
350
351
352
353 mps_set_sta_nonpeer_pm(sta, hdr);
354 }
355 }
356
357
358
359
360 static void mpsp_trigger_send(struct sta_info *sta, bool rspi, bool eosp)
361 {
362 struct ieee80211_sub_if_data *sdata = sta->sdata;
363 struct sk_buff *skb;
364 struct ieee80211_hdr *nullfunc;
365 struct ieee80211_tx_info *info;
366 u8 *qc;
367
368 skb = mps_qos_null_get(sta);
369 if (!skb)
370 return;
371
372 nullfunc = (struct ieee80211_hdr *) skb->data;
373 if (!eosp)
374 nullfunc->frame_control |=
375 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
376
377
378
379
380
381
382
383
384 qc = ieee80211_get_qos_ctl(nullfunc);
385 if (rspi)
386 qc[1] |= (IEEE80211_QOS_CTL_RSPI >> 8);
387 if (eosp)
388 qc[0] |= IEEE80211_QOS_CTL_EOSP;
389
390 info = IEEE80211_SKB_CB(skb);
391
392 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER |
393 IEEE80211_TX_CTL_REQ_TX_STATUS;
394
395 mps_dbg(sdata, "sending MPSP trigger%s%s to %pM\n",
396 rspi ? " RSPI" : "", eosp ? " EOSP" : "", sta->sta.addr);
397
398 ieee80211_tx_skb(sdata, skb);
399 }
400
401
402
403
404
405
406
407
408 static void mpsp_qos_null_append(struct sta_info *sta,
409 struct sk_buff_head *frames)
410 {
411 struct ieee80211_sub_if_data *sdata = sta->sdata;
412 struct sk_buff *new_skb, *skb = skb_peek_tail(frames);
413 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
414 struct ieee80211_tx_info *info;
415
416 if (ieee80211_is_data_qos(hdr->frame_control))
417 return;
418
419 new_skb = mps_qos_null_get(sta);
420 if (!new_skb)
421 return;
422
423 mps_dbg(sdata, "appending QoS Null in MPSP towards %pM\n",
424 sta->sta.addr);
425
426
427
428
429 new_skb->priority = 1;
430 skb_set_queue_mapping(new_skb, IEEE80211_AC_BK);
431 ieee80211_set_qos_hdr(sdata, new_skb);
432
433 info = IEEE80211_SKB_CB(new_skb);
434 info->control.vif = &sdata->vif;
435 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
436
437 __skb_queue_tail(frames, new_skb);
438 }
439
440
441
442
443
444
445
446 static void mps_frame_deliver(struct sta_info *sta, int n_frames)
447 {
448 struct ieee80211_local *local = sta->sdata->local;
449 int ac;
450 struct sk_buff_head frames;
451 struct sk_buff *skb;
452 bool more_data = false;
453
454 skb_queue_head_init(&frames);
455
456
457 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
458 while (n_frames != 0) {
459 skb = skb_dequeue(&sta->tx_filtered[ac]);
460 if (!skb) {
461 skb = skb_dequeue(
462 &sta->ps_tx_buf[ac]);
463 if (skb)
464 local->total_ps_buffered--;
465 }
466 if (!skb)
467 break;
468 n_frames--;
469 __skb_queue_tail(&frames, skb);
470 }
471
472 if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
473 !skb_queue_empty(&sta->ps_tx_buf[ac]))
474 more_data = true;
475 }
476
477
478 if (skb_queue_empty(&frames)) {
479 mpsp_trigger_send(sta, false, true);
480 return;
481 }
482
483
484 if (test_sta_flag(sta, WLAN_STA_MPSP_OWNER))
485 mpsp_qos_null_append(sta, &frames);
486
487 mps_dbg(sta->sdata, "sending %d frames to PS STA %pM\n",
488 skb_queue_len(&frames), sta->sta.addr);
489
490
491 skb_queue_walk(&frames, skb) {
492 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
493 struct ieee80211_hdr *hdr = (void *) skb->data;
494
495
496
497
498
499
500 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
501
502 if (more_data || !skb_queue_is_last(&frames, skb))
503 hdr->frame_control |=
504 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
505 else
506 hdr->frame_control &=
507 cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
508
509 if (skb_queue_is_last(&frames, skb) &&
510 ieee80211_is_data_qos(hdr->frame_control)) {
511 u8 *qoshdr = ieee80211_get_qos_ctl(hdr);
512
513
514 *qoshdr |= IEEE80211_QOS_CTL_EOSP;
515 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
516 }
517 }
518
519 ieee80211_add_pending_skbs(local, &frames);
520 sta_info_recalc_tim(sta);
521 }
522
523
524
525
526
527
528
529
530
531
532
533 void ieee80211_mpsp_trigger_process(u8 *qc, struct sta_info *sta,
534 bool tx, bool acked)
535 {
536 u8 rspi = qc[1] & (IEEE80211_QOS_CTL_RSPI >> 8);
537 u8 eosp = qc[0] & IEEE80211_QOS_CTL_EOSP;
538
539 if (tx) {
540 if (rspi && acked)
541 set_sta_flag(sta, WLAN_STA_MPSP_RECIPIENT);
542
543 if (eosp)
544 clear_sta_flag(sta, WLAN_STA_MPSP_OWNER);
545 else if (acked &&
546 test_sta_flag(sta, WLAN_STA_PS_STA) &&
547 !test_and_set_sta_flag(sta, WLAN_STA_MPSP_OWNER))
548 mps_frame_deliver(sta, -1);
549 } else {
550 if (eosp)
551 clear_sta_flag(sta, WLAN_STA_MPSP_RECIPIENT);
552 else if (sta->mesh->local_pm != NL80211_MESH_POWER_ACTIVE)
553 set_sta_flag(sta, WLAN_STA_MPSP_RECIPIENT);
554
555 if (rspi && !test_and_set_sta_flag(sta, WLAN_STA_MPSP_OWNER))
556 mps_frame_deliver(sta, -1);
557 }
558 }
559
560
561
562
563
564
565
566
567
568
569
570
571 void ieee80211_mps_frame_release(struct sta_info *sta,
572 struct ieee802_11_elems *elems)
573 {
574 int ac, buffer_local = 0;
575 bool has_buffered = false;
576
577 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
578 has_buffered = ieee80211_check_tim(elems->tim, elems->tim_len,
579 sta->mesh->aid);
580
581 if (has_buffered)
582 mps_dbg(sta->sdata, "%pM indicates buffered frames\n",
583 sta->sta.addr);
584
585
586 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
587 (!elems->awake_window || !le16_to_cpu(*elems->awake_window)))
588 return;
589
590 if (!test_sta_flag(sta, WLAN_STA_MPSP_OWNER))
591 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
592 buffer_local += skb_queue_len(&sta->ps_tx_buf[ac]) +
593 skb_queue_len(&sta->tx_filtered[ac]);
594
595 if (!has_buffered && !buffer_local)
596 return;
597
598 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
599 mpsp_trigger_send(sta, has_buffered, !buffer_local);
600 else
601 mps_frame_deliver(sta, 1);
602 }