2 * hostapd / IEEE 802.11 Management
3 * Copyright (c) 2002-2012, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "common/ieee802_11_defs.h"
15 #include "ap_config.h"
16 #include "ap_drv_ops.h"
17 #include "ieee802_11.h"
20 #ifdef CONFIG_IEEE80211W
22 u8
* hostapd_eid_assoc_comeback_time(struct hostapd_data
*hapd
,
23 struct sta_info
*sta
, u8
*eid
)
27 struct os_time now
, passed
;
29 *pos
++ = WLAN_EID_TIMEOUT_INTERVAL
;
31 *pos
++ = WLAN_TIMEOUT_ASSOC_COMEBACK
;
33 os_time_sub(&now
, &sta
->sa_query_start
, &passed
);
34 tu
= (passed
.sec
* 1000000 + passed
.usec
) / 1024;
35 if (hapd
->conf
->assoc_sa_query_max_timeout
> tu
)
36 timeout
= hapd
->conf
->assoc_sa_query_max_timeout
- tu
;
39 if (timeout
< hapd
->conf
->assoc_sa_query_max_timeout
)
40 timeout
++; /* add some extra time for local timers */
41 WPA_PUT_LE32(pos
, timeout
);
48 /* MLME-SAQuery.request */
49 void ieee802_11_send_sa_query_req(struct hostapd_data
*hapd
,
50 const u8
*addr
, const u8
*trans_id
)
52 struct ieee80211_mgmt mgmt
;
55 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Sending SA Query Request to "
56 MACSTR
, MAC2STR(addr
));
57 wpa_hexdump(MSG_DEBUG
, "IEEE 802.11: SA Query Transaction ID",
58 trans_id
, WLAN_SA_QUERY_TR_ID_LEN
);
60 os_memset(&mgmt
, 0, sizeof(mgmt
));
61 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
62 WLAN_FC_STYPE_ACTION
);
63 os_memcpy(mgmt
.da
, addr
, ETH_ALEN
);
64 os_memcpy(mgmt
.sa
, hapd
->own_addr
, ETH_ALEN
);
65 os_memcpy(mgmt
.bssid
, hapd
->own_addr
, ETH_ALEN
);
66 mgmt
.u
.action
.category
= WLAN_ACTION_SA_QUERY
;
67 mgmt
.u
.action
.u
.sa_query_req
.action
= WLAN_SA_QUERY_REQUEST
;
68 os_memcpy(mgmt
.u
.action
.u
.sa_query_req
.trans_id
, trans_id
,
69 WLAN_SA_QUERY_TR_ID_LEN
);
70 end
= mgmt
.u
.action
.u
.sa_query_req
.trans_id
+ WLAN_SA_QUERY_TR_ID_LEN
;
71 if (hostapd_drv_send_mlme(hapd
, &mgmt
, end
- (u8
*) &mgmt
, 0) < 0)
72 perror("ieee802_11_send_sa_query_req: send");
76 static void ieee802_11_send_sa_query_resp(struct hostapd_data
*hapd
,
77 const u8
*sa
, const u8
*trans_id
)
80 struct ieee80211_mgmt resp
;
83 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Received SA Query Request from "
85 wpa_hexdump(MSG_DEBUG
, "IEEE 802.11: SA Query Transaction ID",
86 trans_id
, WLAN_SA_QUERY_TR_ID_LEN
);
88 sta
= ap_get_sta(hapd
, sa
);
89 if (sta
== NULL
|| !(sta
->flags
& WLAN_STA_ASSOC
)) {
90 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Ignore SA Query Request "
91 "from unassociated STA " MACSTR
, MAC2STR(sa
));
95 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Sending SA Query Response to "
98 os_memset(&resp
, 0, sizeof(resp
));
99 resp
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
100 WLAN_FC_STYPE_ACTION
);
101 os_memcpy(resp
.da
, sa
, ETH_ALEN
);
102 os_memcpy(resp
.sa
, hapd
->own_addr
, ETH_ALEN
);
103 os_memcpy(resp
.bssid
, hapd
->own_addr
, ETH_ALEN
);
104 resp
.u
.action
.category
= WLAN_ACTION_SA_QUERY
;
105 resp
.u
.action
.u
.sa_query_req
.action
= WLAN_SA_QUERY_RESPONSE
;
106 os_memcpy(resp
.u
.action
.u
.sa_query_req
.trans_id
, trans_id
,
107 WLAN_SA_QUERY_TR_ID_LEN
);
108 end
= resp
.u
.action
.u
.sa_query_req
.trans_id
+ WLAN_SA_QUERY_TR_ID_LEN
;
109 if (hostapd_drv_send_mlme(hapd
, &resp
, end
- (u8
*) &resp
, 0) < 0)
110 perror("ieee80211_mgmt_sa_query_request: send");
114 void ieee802_11_sa_query_action(struct hostapd_data
*hapd
, const u8
*sa
,
115 const u8 action_type
, const u8
*trans_id
)
117 struct sta_info
*sta
;
120 if (action_type
== WLAN_SA_QUERY_REQUEST
) {
121 ieee802_11_send_sa_query_resp(hapd
, sa
, trans_id
);
125 if (action_type
!= WLAN_SA_QUERY_RESPONSE
) {
126 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Unexpected SA Query "
127 "Action %d", action_type
);
131 wpa_printf(MSG_DEBUG
, "IEEE 802.11: Received SA Query Response from "
132 MACSTR
, MAC2STR(sa
));
133 wpa_hexdump(MSG_DEBUG
, "IEEE 802.11: SA Query Transaction ID",
134 trans_id
, WLAN_SA_QUERY_TR_ID_LEN
);
136 /* MLME-SAQuery.confirm */
138 sta
= ap_get_sta(hapd
, sa
);
139 if (sta
== NULL
|| sta
->sa_query_trans_id
== NULL
) {
140 wpa_printf(MSG_DEBUG
, "IEEE 802.11: No matching STA with "
141 "pending SA Query request found");
145 for (i
= 0; i
< sta
->sa_query_count
; i
++) {
146 if (os_memcmp(sta
->sa_query_trans_id
+
147 i
* WLAN_SA_QUERY_TR_ID_LEN
,
148 trans_id
, WLAN_SA_QUERY_TR_ID_LEN
) == 0)
152 if (i
>= sta
->sa_query_count
) {
153 wpa_printf(MSG_DEBUG
, "IEEE 802.11: No matching SA Query "
154 "transaction identifier found");
158 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
160 "Reply to pending SA Query received");
161 ap_sta_stop_sa_query(hapd
, sta
);
164 #endif /* CONFIG_IEEE80211W */
167 u8
* hostapd_eid_ext_capab(struct hostapd_data
*hapd
, u8
*eid
)
172 if (hapd
->conf
->tdls
& (TDLS_PROHIBIT
| TDLS_PROHIBIT_CHAN_SWITCH
))
174 if (len
< 4 && hapd
->conf
->interworking
)
176 if (len
< 3 && hapd
->conf
->wnm_sleep_mode
)
178 if (len
< 7 && hapd
->conf
->ssid
.utf8_ssid
)
183 #endif /* CONFIG_WNM */
187 *pos
++ = WLAN_EID_EXT_CAPAB
;
193 if (hapd
->conf
->wnm_sleep_mode
)
194 *pos
|= 0x02; /* Bit 17 - WNM-Sleep Mode */
195 if (hapd
->conf
->bss_transition
)
196 *pos
|= 0x08; /* Bit 19 - BSS Transition */
203 *pos
|= 0x02; /* Bit 25 - SSID List */
204 #endif /* CONFIG_WNM */
205 if (hapd
->conf
->time_advertisement
== 2)
206 *pos
|= 0x08; /* Bit 27 - UTC TSF Offset */
207 if (hapd
->conf
->interworking
)
208 *pos
|= 0x80; /* Bit 31 - Interworking */
214 if (hapd
->conf
->tdls
& TDLS_PROHIBIT
)
215 *pos
|= 0x40; /* Bit 38 - TDLS Prohibited */
216 if (hapd
->conf
->tdls
& TDLS_PROHIBIT_CHAN_SWITCH
)
217 *pos
|= 0x80; /* Bit 39 - TDLS Channel Switching Prohibited */
228 if (hapd
->conf
->ssid
.utf8_ssid
)
229 *pos
|= 0x01; /* Bit 48 - UTF-8 SSID */
236 u8
* hostapd_eid_interworking(struct hostapd_data
*hapd
, u8
*eid
)
239 #ifdef CONFIG_INTERWORKING
242 if (!hapd
->conf
->interworking
)
245 *pos
++ = WLAN_EID_INTERWORKING
;
248 *pos
= hapd
->conf
->access_network_type
;
249 if (hapd
->conf
->internet
)
250 *pos
|= INTERWORKING_ANO_INTERNET
;
251 if (hapd
->conf
->asra
)
252 *pos
|= INTERWORKING_ANO_ASRA
;
254 *pos
|= INTERWORKING_ANO_ESR
;
255 if (hapd
->conf
->uesa
)
256 *pos
|= INTERWORKING_ANO_UESA
;
259 if (hapd
->conf
->venue_info_set
) {
260 *pos
++ = hapd
->conf
->venue_group
;
261 *pos
++ = hapd
->conf
->venue_type
;
264 if (!is_zero_ether_addr(hapd
->conf
->hessid
)) {
265 os_memcpy(pos
, hapd
->conf
->hessid
, ETH_ALEN
);
269 *len
= pos
- len
- 1;
270 #endif /* CONFIG_INTERWORKING */
276 u8
* hostapd_eid_adv_proto(struct hostapd_data
*hapd
, u8
*eid
)
279 #ifdef CONFIG_INTERWORKING
281 /* TODO: Separate configuration for ANQP? */
282 if (!hapd
->conf
->interworking
)
285 *pos
++ = WLAN_EID_ADV_PROTO
;
287 *pos
++ = 0x7F; /* Query Response Length Limit | PAME-BI */
288 *pos
++ = ACCESS_NETWORK_QUERY_PROTOCOL
;
289 #endif /* CONFIG_INTERWORKING */
295 u8
* hostapd_eid_roaming_consortium(struct hostapd_data
*hapd
, u8
*eid
)
298 #ifdef CONFIG_INTERWORKING
300 unsigned int i
, count
;
302 if (!hapd
->conf
->interworking
||
303 hapd
->conf
->roaming_consortium
== NULL
||
304 hapd
->conf
->roaming_consortium_count
== 0)
307 *pos
++ = WLAN_EID_ROAMING_CONSORTIUM
;
310 /* Number of ANQP OIs (in addition to the max 3 listed here) */
311 if (hapd
->conf
->roaming_consortium_count
> 3 + 255)
313 else if (hapd
->conf
->roaming_consortium_count
> 3)
314 *pos
++ = hapd
->conf
->roaming_consortium_count
- 3;
318 /* OU #1 and #2 Lengths */
319 *pos
= hapd
->conf
->roaming_consortium
[0].len
;
320 if (hapd
->conf
->roaming_consortium_count
> 1)
321 *pos
|= hapd
->conf
->roaming_consortium
[1].len
<< 4;
324 if (hapd
->conf
->roaming_consortium_count
> 3)
327 count
= hapd
->conf
->roaming_consortium_count
;
329 for (i
= 0; i
< count
; i
++) {
330 os_memcpy(pos
, hapd
->conf
->roaming_consortium
[i
].oi
,
331 hapd
->conf
->roaming_consortium
[i
].len
);
332 pos
+= hapd
->conf
->roaming_consortium
[i
].len
;
335 *len
= pos
- len
- 1;
336 #endif /* CONFIG_INTERWORKING */
342 u8
* hostapd_eid_time_adv(struct hostapd_data
*hapd
, u8
*eid
)
344 if (hapd
->conf
->time_advertisement
!= 2)
347 if (hapd
->time_adv
== NULL
&&
348 hostapd_update_time_adv(hapd
) < 0)
351 if (hapd
->time_adv
== NULL
)
354 os_memcpy(eid
, wpabuf_head(hapd
->time_adv
),
355 wpabuf_len(hapd
->time_adv
));
356 eid
+= wpabuf_len(hapd
->time_adv
);
362 u8
* hostapd_eid_time_zone(struct hostapd_data
*hapd
, u8
*eid
)
366 if (hapd
->conf
->time_advertisement
!= 2)
369 len
= os_strlen(hapd
->conf
->time_zone
);
371 *eid
++ = WLAN_EID_TIME_ZONE
;
373 os_memcpy(eid
, hapd
->conf
->time_zone
, len
);
380 int hostapd_update_time_adv(struct hostapd_data
*hapd
)
382 const int elen
= 2 + 1 + 10 + 5 + 1;
387 if (hapd
->conf
->time_advertisement
!= 2)
390 if (os_get_time(&t
) < 0 || os_gmtime(t
.sec
, &tm
) < 0)
393 if (!hapd
->time_adv
) {
394 hapd
->time_adv
= wpabuf_alloc(elen
);
395 if (hapd
->time_adv
== NULL
)
397 pos
= wpabuf_put(hapd
->time_adv
, elen
);
399 pos
= wpabuf_mhead_u8(hapd
->time_adv
);
401 *pos
++ = WLAN_EID_TIME_ADVERTISEMENT
;
402 *pos
++ = 1 + 10 + 5 + 1;
404 *pos
++ = 2; /* UTC time at which the TSF timer is 0 */
406 /* Time Value at TSF 0 */
407 /* FIX: need to calculate this based on the current TSF value */
408 WPA_PUT_LE16(pos
, tm
.year
); /* Year */
410 *pos
++ = tm
.month
; /* Month */
411 *pos
++ = tm
.day
; /* Day of month */
412 *pos
++ = tm
.hour
; /* Hours */
413 *pos
++ = tm
.min
; /* Minutes */
414 *pos
++ = tm
.sec
; /* Seconds */
415 WPA_PUT_LE16(pos
, 0); /* Milliseconds (not used) */
417 *pos
++ = 0; /* Reserved */
420 /* TODO: fill in an estimate on the error */
427 *pos
++ = hapd
->time_update_counter
++;
433 u8
* hostapd_eid_bss_max_idle_period(struct hostapd_data
*hapd
, u8
*eid
)
438 if (hapd
->conf
->ap_max_inactivity
> 0) {
440 *pos
++ = WLAN_EID_BSS_MAX_IDLE_PERIOD
;
442 val
= hapd
->conf
->ap_max_inactivity
;
451 WPA_PUT_LE16(pos
, val
);
453 *pos
++ = 0x00; /* TODO: Protected Keep-Alive Required */
455 #endif /* CONFIG_WNM */