Skip to content

Commit e5b900d

Browse files
jmberg-intellinvjw
authored andcommitted
mac80211: allow drivers to request DTIM period
Some features require knowing the DTIM period before associating. This implements the ability to wait for a beacon in mac80211 before assoc to provide this value. It is optional since most likely not all drivers will need this. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent d28232b commit e5b900d

5 files changed

Lines changed: 84 additions & 5 deletions

File tree

‎include/net/mac80211.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ enum ieee80211_bss_change {
194194
* if the hardware cannot handle this it must set the
195195
* IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE hardware flag
196196
* @dtim_period: num of beacons before the next DTIM, for beaconing,
197-
* not valid in station mode (cf. hw conf ps_dtim_period)
197+
* valid in station mode only while @assoc is true and if also
198+
* requested by %IEEE80211_HW_NEED_DTIM_PERIOD (cf. also hw conf
199+
* @ps_dtim_period)
198200
* @timestamp: beacon timestamp
199201
* @beacon_int: beacon interval
200202
* @assoc_capability: capabilities taken from assoc resp
@@ -1027,6 +1029,9 @@ enum ieee80211_tkip_key_type {
10271029
* connection quality related parameters, such as the RSSI level and
10281030
* provide notifications if configured trigger levels are reached.
10291031
*
1032+
* @IEEE80211_HW_NEED_DTIM_PERIOD:
1033+
* This device needs to know the DTIM period for the BSS before
1034+
* associating.
10301035
*/
10311036
enum ieee80211_hw_flags {
10321037
IEEE80211_HW_HAS_RATE_CONTROL = 1<<0,
@@ -1036,7 +1041,7 @@ enum ieee80211_hw_flags {
10361041
IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE = 1<<4,
10371042
IEEE80211_HW_SIGNAL_UNSPEC = 1<<5,
10381043
IEEE80211_HW_SIGNAL_DBM = 1<<6,
1039-
/* use this hole */
1044+
IEEE80211_HW_NEED_DTIM_PERIOD = 1<<7,
10401045
IEEE80211_HW_SPECTRUM_MGMT = 1<<8,
10411046
IEEE80211_HW_AMPDU_AGGREGATION = 1<<9,
10421047
IEEE80211_HW_SUPPORTS_PS = 1<<10,

‎net/mac80211/ieee80211_i.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ enum ieee80211_work_type {
238238
IEEE80211_WORK_ABORT,
239239
IEEE80211_WORK_DIRECT_PROBE,
240240
IEEE80211_WORK_AUTH,
241+
IEEE80211_WORK_ASSOC_BEACON_WAIT,
241242
IEEE80211_WORK_ASSOC,
242243
IEEE80211_WORK_REMAIN_ON_CHANNEL,
243244
};

‎net/mac80211/mlme.c‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,11 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
870870

871871
ieee80211_led_assoc(local, 1);
872872

873+
if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
874+
bss_conf->dtim_period = bss->dtim_period;
875+
else
876+
bss_conf->dtim_period = 0;
877+
873878
bss_conf->assoc = 1;
874879
/*
875880
* For now just always ask the driver to update the basic rateset
@@ -1751,7 +1756,8 @@ void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
17511756
if (wk->sdata != sdata)
17521757
continue;
17531758

1754-
if (wk->type != IEEE80211_WORK_ASSOC)
1759+
if (wk->type != IEEE80211_WORK_ASSOC &&
1760+
wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
17551761
continue;
17561762

17571763
if (memcmp(mgmt->bssid, wk->filter_ta, ETH_ALEN))
@@ -2086,13 +2092,28 @@ static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk,
20862092
struct sk_buff *skb)
20872093
{
20882094
struct ieee80211_mgmt *mgmt;
2095+
struct ieee80211_rx_status *rx_status;
2096+
struct ieee802_11_elems elems;
20892097
u16 status;
20902098

20912099
if (!skb) {
20922100
cfg80211_send_assoc_timeout(wk->sdata->dev, wk->filter_ta);
20932101
return WORK_DONE_DESTROY;
20942102
}
20952103

2104+
if (wk->type == IEEE80211_WORK_ASSOC_BEACON_WAIT) {
2105+
mutex_lock(&wk->sdata->u.mgd.mtx);
2106+
rx_status = (void *) skb->cb;
2107+
ieee802_11_parse_elems(skb->data + 24 + 12, skb->len - 24 - 12, &elems);
2108+
ieee80211_rx_bss_info(wk->sdata, (void *)skb->data, skb->len, rx_status,
2109+
&elems, true);
2110+
mutex_unlock(&wk->sdata->u.mgd.mtx);
2111+
2112+
wk->type = IEEE80211_WORK_ASSOC;
2113+
/* not really done yet */
2114+
return WORK_DONE_REQUEUE;
2115+
}
2116+
20962117
mgmt = (void *)skb->data;
20972118
status = le16_to_cpu(mgmt->u.assoc_resp.status_code);
20982119

@@ -2206,10 +2227,14 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
22062227
if (req->prev_bssid)
22072228
memcpy(wk->assoc.prev_bssid, req->prev_bssid, ETH_ALEN);
22082229

2209-
wk->type = IEEE80211_WORK_ASSOC;
22102230
wk->chan = req->bss->channel;
22112231
wk->sdata = sdata;
22122232
wk->done = ieee80211_assoc_done;
2233+
if (!bss->dtim_period &&
2234+
sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
2235+
wk->type = IEEE80211_WORK_ASSOC_BEACON_WAIT;
2236+
else
2237+
wk->type = IEEE80211_WORK_ASSOC;
22132238

22142239
if (req->use_mfp) {
22152240
ifmgd->mfp = IEEE80211_MFP_REQUIRED;
@@ -2257,7 +2282,8 @@ int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
22572282

22582283
if (wk->type != IEEE80211_WORK_DIRECT_PROBE &&
22592284
wk->type != IEEE80211_WORK_AUTH &&
2260-
wk->type != IEEE80211_WORK_ASSOC)
2285+
wk->type != IEEE80211_WORK_ASSOC &&
2286+
wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
22612287
continue;
22622288

22632289
if (memcmp(req->bss->bssid, wk->filter_ta, ETH_ALEN))

‎net/mac80211/scan.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ ieee80211_bss_info_update(struct ieee80211_local *local,
114114
bss->dtim_period = tim_ie->dtim_period;
115115
}
116116

117+
/* If the beacon had no TIM IE, or it was invalid, use 1 */
118+
if (beacon && !bss->dtim_period)
119+
bss->dtim_period = 1;
120+
117121
/* replace old supported rates if we get new values */
118122
srlen = 0;
119123
if (elems->supp_rates) {

‎net/mac80211/work.c‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,22 @@ ieee80211_remain_on_channel_timeout(struct ieee80211_work *wk)
560560
return WORK_ACT_TIMEOUT;
561561
}
562562

563+
static enum work_action __must_check
564+
ieee80211_assoc_beacon_wait(struct ieee80211_work *wk)
565+
{
566+
if (wk->started)
567+
return WORK_ACT_TIMEOUT;
568+
569+
/*
570+
* Wait up to one beacon interval ...
571+
* should this be more if we miss one?
572+
*/
573+
printk(KERN_DEBUG "%s: waiting for beacon from %pM\n",
574+
wk->sdata->name, wk->filter_ta);
575+
wk->timeout = TU_TO_EXP_TIME(wk->assoc.bss->beacon_interval);
576+
return WORK_ACT_NONE;
577+
}
578+
563579
static void ieee80211_auth_challenge(struct ieee80211_work *wk,
564580
struct ieee80211_mgmt *mgmt,
565581
size_t len)
@@ -709,6 +725,25 @@ ieee80211_rx_mgmt_probe_resp(struct ieee80211_work *wk,
709725
return WORK_ACT_DONE;
710726
}
711727

728+
static enum work_action __must_check
729+
ieee80211_rx_mgmt_beacon(struct ieee80211_work *wk,
730+
struct ieee80211_mgmt *mgmt, size_t len)
731+
{
732+
struct ieee80211_sub_if_data *sdata = wk->sdata;
733+
struct ieee80211_local *local = sdata->local;
734+
735+
ASSERT_WORK_MTX(local);
736+
737+
if (wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
738+
return WORK_ACT_MISMATCH;
739+
740+
if (len < 24 + 12)
741+
return WORK_ACT_NONE;
742+
743+
printk(KERN_DEBUG "%s: beacon received\n", sdata->name);
744+
return WORK_ACT_DONE;
745+
}
746+
712747
static void ieee80211_work_rx_queued_mgmt(struct ieee80211_local *local,
713748
struct sk_buff *skb)
714749
{
@@ -731,6 +766,7 @@ static void ieee80211_work_rx_queued_mgmt(struct ieee80211_local *local,
731766
case IEEE80211_WORK_DIRECT_PROBE:
732767
case IEEE80211_WORK_AUTH:
733768
case IEEE80211_WORK_ASSOC:
769+
case IEEE80211_WORK_ASSOC_BEACON_WAIT:
734770
bssid = wk->filter_ta;
735771
break;
736772
default:
@@ -745,6 +781,9 @@ static void ieee80211_work_rx_queued_mgmt(struct ieee80211_local *local,
745781
continue;
746782

747783
switch (fc & IEEE80211_FCTL_STYPE) {
784+
case IEEE80211_STYPE_BEACON:
785+
rma = ieee80211_rx_mgmt_beacon(wk, mgmt, skb->len);
786+
break;
748787
case IEEE80211_STYPE_PROBE_RESP:
749788
rma = ieee80211_rx_mgmt_probe_resp(wk, mgmt, skb->len,
750789
rx_status);
@@ -916,6 +955,9 @@ static void ieee80211_work_work(struct work_struct *work)
916955
case IEEE80211_WORK_REMAIN_ON_CHANNEL:
917956
rma = ieee80211_remain_on_channel_timeout(wk);
918957
break;
958+
case IEEE80211_WORK_ASSOC_BEACON_WAIT:
959+
rma = ieee80211_assoc_beacon_wait(wk);
960+
break;
919961
}
920962

921963
wk->started = started;
@@ -1065,6 +1107,7 @@ ieee80211_rx_result ieee80211_work_rx_mgmt(struct ieee80211_sub_if_data *sdata,
10651107
case IEEE80211_STYPE_PROBE_RESP:
10661108
case IEEE80211_STYPE_ASSOC_RESP:
10671109
case IEEE80211_STYPE_REASSOC_RESP:
1110+
case IEEE80211_STYPE_BEACON:
10681111
skb_queue_tail(&local->work_skb_queue, skb);
10691112
ieee80211_queue_work(&local->hw, &local->work_work);
10701113
return RX_QUEUED;

0 commit comments

Comments
 (0)