blob: b9d61762503ffafb2bc31e502af3e3daa2cec8d4 [file] [log] [blame]
Dmitry Shmidt04949592012-07-19 12:16:46 -07001/*
2 * Generic advertisement service (GAS) server
Dmitry Shmidt18463232014-01-24 12:29:41 -08003 * Copyright (c) 2011-2014, Qualcomm Atheros, Inc.
Dmitry Shmidt04949592012-07-19 12:16:46 -07004 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "common/ieee802_11_defs.h"
13#include "common/gas.h"
14#include "utils/eloop.h"
15#include "hostapd.h"
16#include "ap_config.h"
17#include "ap_drv_ops.h"
18#include "sta_info.h"
19#include "gas_serv.h"
20
21
Dmitry Shmidt18463232014-01-24 12:29:41 -080022static void convert_to_protected_dual(struct wpabuf *msg)
23{
24 u8 *categ = wpabuf_mhead_u8(msg);
25 *categ = WLAN_ACTION_PROTECTED_DUAL;
26}
27
28
Dmitry Shmidt04949592012-07-19 12:16:46 -070029static struct gas_dialog_info *
30gas_dialog_create(struct hostapd_data *hapd, const u8 *addr, u8 dialog_token)
31{
32 struct sta_info *sta;
33 struct gas_dialog_info *dia = NULL;
34 int i, j;
35
36 sta = ap_get_sta(hapd, addr);
37 if (!sta) {
38 /*
39 * We need a STA entry to be able to maintain state for
40 * the GAS query.
41 */
42 wpa_printf(MSG_DEBUG, "ANQP: Add a temporary STA entry for "
43 "GAS query");
44 sta = ap_sta_add(hapd, addr);
45 if (!sta) {
46 wpa_printf(MSG_DEBUG, "Failed to add STA " MACSTR
47 " for GAS query", MAC2STR(addr));
48 return NULL;
49 }
50 sta->flags |= WLAN_STA_GAS;
51 /*
52 * The default inactivity is 300 seconds. We don't need
53 * it to be that long.
54 */
55 ap_sta_session_timeout(hapd, sta, 5);
Dmitry Shmidt54605472013-11-08 11:10:19 -080056 } else {
57 ap_sta_replenish_timeout(hapd, sta, 5);
Dmitry Shmidt04949592012-07-19 12:16:46 -070058 }
59
60 if (sta->gas_dialog == NULL) {
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -080061 sta->gas_dialog = os_calloc(GAS_DIALOG_MAX,
Dmitry Shmidt04949592012-07-19 12:16:46 -070062 sizeof(struct gas_dialog_info));
63 if (sta->gas_dialog == NULL)
64 return NULL;
65 }
66
67 for (i = sta->gas_dialog_next, j = 0; j < GAS_DIALOG_MAX; i++, j++) {
68 if (i == GAS_DIALOG_MAX)
69 i = 0;
70 if (sta->gas_dialog[i].valid)
71 continue;
72 dia = &sta->gas_dialog[i];
73 dia->valid = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070074 dia->dialog_token = dialog_token;
75 sta->gas_dialog_next = (++i == GAS_DIALOG_MAX) ? 0 : i;
76 return dia;
77 }
78
79 wpa_msg(hapd->msg_ctx, MSG_ERROR, "ANQP: Could not create dialog for "
80 MACSTR " dialog_token %u. Consider increasing "
81 "GAS_DIALOG_MAX.", MAC2STR(addr), dialog_token);
82
83 return NULL;
84}
85
86
87struct gas_dialog_info *
88gas_serv_dialog_find(struct hostapd_data *hapd, const u8 *addr,
89 u8 dialog_token)
90{
91 struct sta_info *sta;
92 int i;
93
94 sta = ap_get_sta(hapd, addr);
95 if (!sta) {
96 wpa_printf(MSG_DEBUG, "ANQP: could not find STA " MACSTR,
97 MAC2STR(addr));
98 return NULL;
99 }
100 for (i = 0; sta->gas_dialog && i < GAS_DIALOG_MAX; i++) {
101 if (sta->gas_dialog[i].dialog_token != dialog_token ||
102 !sta->gas_dialog[i].valid)
103 continue;
Dmitry Shmidt7d56b752015-12-22 10:59:44 -0800104 ap_sta_replenish_timeout(hapd, sta, 5);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700105 return &sta->gas_dialog[i];
106 }
107 wpa_printf(MSG_DEBUG, "ANQP: Could not find dialog for "
108 MACSTR " dialog_token %u", MAC2STR(addr), dialog_token);
109 return NULL;
110}
111
112
113void gas_serv_dialog_clear(struct gas_dialog_info *dia)
114{
115 wpabuf_free(dia->sd_resp);
116 os_memset(dia, 0, sizeof(*dia));
117}
118
119
120static void gas_serv_free_dialogs(struct hostapd_data *hapd,
121 const u8 *sta_addr)
122{
123 struct sta_info *sta;
124 int i;
125
126 sta = ap_get_sta(hapd, sta_addr);
127 if (sta == NULL || sta->gas_dialog == NULL)
128 return;
129
130 for (i = 0; i < GAS_DIALOG_MAX; i++) {
131 if (sta->gas_dialog[i].valid)
132 return;
133 }
134
135 os_free(sta->gas_dialog);
136 sta->gas_dialog = NULL;
137}
138
139
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700140#ifdef CONFIG_HS20
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700141static void anqp_add_hs_capab_list(struct hostapd_data *hapd,
142 struct wpabuf *buf)
143{
144 u8 *len;
145
146 len = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
147 wpabuf_put_be24(buf, OUI_WFA);
148 wpabuf_put_u8(buf, HS20_ANQP_OUI_TYPE);
149 wpabuf_put_u8(buf, HS20_STYPE_CAPABILITY_LIST);
150 wpabuf_put_u8(buf, 0); /* Reserved */
151 wpabuf_put_u8(buf, HS20_STYPE_CAPABILITY_LIST);
152 if (hapd->conf->hs20_oper_friendly_name)
153 wpabuf_put_u8(buf, HS20_STYPE_OPERATOR_FRIENDLY_NAME);
154 if (hapd->conf->hs20_wan_metrics)
155 wpabuf_put_u8(buf, HS20_STYPE_WAN_METRICS);
156 if (hapd->conf->hs20_connection_capability)
157 wpabuf_put_u8(buf, HS20_STYPE_CONNECTION_CAPABILITY);
158 if (hapd->conf->nai_realm_data)
159 wpabuf_put_u8(buf, HS20_STYPE_NAI_HOME_REALM_QUERY);
160 if (hapd->conf->hs20_operating_class)
161 wpabuf_put_u8(buf, HS20_STYPE_OPERATING_CLASS);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800162 if (hapd->conf->hs20_osu_providers_count)
163 wpabuf_put_u8(buf, HS20_STYPE_OSU_PROVIDERS_LIST);
164 if (hapd->conf->hs20_icons_count)
165 wpabuf_put_u8(buf, HS20_STYPE_ICON_REQUEST);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700166 gas_anqp_set_element_len(buf, len);
167}
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700168#endif /* CONFIG_HS20 */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700169
170
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800171static struct anqp_element * get_anqp_elem(struct hostapd_data *hapd,
172 u16 infoid)
173{
174 struct anqp_element *elem;
175
176 dl_list_for_each(elem, &hapd->conf->anqp_elem, struct anqp_element,
177 list) {
178 if (elem->infoid == infoid)
179 return elem;
180 }
181
182 return NULL;
183}
184
185
186static void anqp_add_elem(struct hostapd_data *hapd, struct wpabuf *buf,
187 u16 infoid)
188{
189 struct anqp_element *elem;
190
191 elem = get_anqp_elem(hapd, infoid);
192 if (!elem)
193 return;
194 if (wpabuf_tailroom(buf) < 2 + 2 + wpabuf_len(elem->payload)) {
195 wpa_printf(MSG_DEBUG, "ANQP: No room for InfoID %u payload",
196 infoid);
197 return;
198 }
199
200 wpabuf_put_le16(buf, infoid);
201 wpabuf_put_le16(buf, wpabuf_len(elem->payload));
202 wpabuf_put_buf(buf, elem->payload);
203}
204
205
206static int anqp_add_override(struct hostapd_data *hapd, struct wpabuf *buf,
207 u16 infoid)
208{
209 if (get_anqp_elem(hapd, infoid)) {
210 anqp_add_elem(hapd, buf, infoid);
211 return 1;
212 }
213
214 return 0;
215}
216
217
Dmitry Shmidt04949592012-07-19 12:16:46 -0700218static void anqp_add_capab_list(struct hostapd_data *hapd,
219 struct wpabuf *buf)
220{
221 u8 *len;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800222 u16 id;
223
224 if (anqp_add_override(hapd, buf, ANQP_CAPABILITY_LIST))
225 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700226
227 len = gas_anqp_add_element(buf, ANQP_CAPABILITY_LIST);
228 wpabuf_put_le16(buf, ANQP_CAPABILITY_LIST);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800229 if (hapd->conf->venue_name || get_anqp_elem(hapd, ANQP_VENUE_NAME))
Dmitry Shmidt04949592012-07-19 12:16:46 -0700230 wpabuf_put_le16(buf, ANQP_VENUE_NAME);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800231 if (get_anqp_elem(hapd, ANQP_EMERGENCY_CALL_NUMBER))
232 wpabuf_put_le16(buf, ANQP_EMERGENCY_CALL_NUMBER);
233 if (hapd->conf->network_auth_type ||
234 get_anqp_elem(hapd, ANQP_NETWORK_AUTH_TYPE))
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700235 wpabuf_put_le16(buf, ANQP_NETWORK_AUTH_TYPE);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800236 if (hapd->conf->roaming_consortium ||
237 get_anqp_elem(hapd, ANQP_ROAMING_CONSORTIUM))
Dmitry Shmidt04949592012-07-19 12:16:46 -0700238 wpabuf_put_le16(buf, ANQP_ROAMING_CONSORTIUM);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800239 if (hapd->conf->ipaddr_type_configured ||
240 get_anqp_elem(hapd, ANQP_IP_ADDR_TYPE_AVAILABILITY))
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700241 wpabuf_put_le16(buf, ANQP_IP_ADDR_TYPE_AVAILABILITY);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800242 if (hapd->conf->nai_realm_data ||
243 get_anqp_elem(hapd, ANQP_NAI_REALM))
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700244 wpabuf_put_le16(buf, ANQP_NAI_REALM);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800245 if (hapd->conf->anqp_3gpp_cell_net ||
246 get_anqp_elem(hapd, ANQP_3GPP_CELLULAR_NETWORK))
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700247 wpabuf_put_le16(buf, ANQP_3GPP_CELLULAR_NETWORK);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800248 if (get_anqp_elem(hapd, ANQP_AP_GEOSPATIAL_LOCATION))
249 wpabuf_put_le16(buf, ANQP_AP_GEOSPATIAL_LOCATION);
250 if (get_anqp_elem(hapd, ANQP_AP_CIVIC_LOCATION))
251 wpabuf_put_le16(buf, ANQP_AP_CIVIC_LOCATION);
252 if (get_anqp_elem(hapd, ANQP_AP_LOCATION_PUBLIC_URI))
253 wpabuf_put_le16(buf, ANQP_AP_LOCATION_PUBLIC_URI);
254 if (hapd->conf->domain_name || get_anqp_elem(hapd, ANQP_DOMAIN_NAME))
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700255 wpabuf_put_le16(buf, ANQP_DOMAIN_NAME);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800256 if (get_anqp_elem(hapd, ANQP_EMERGENCY_ALERT_URI))
257 wpabuf_put_le16(buf, ANQP_EMERGENCY_ALERT_URI);
258 if (get_anqp_elem(hapd, ANQP_EMERGENCY_NAI))
259 wpabuf_put_le16(buf, ANQP_EMERGENCY_NAI);
260 if (get_anqp_elem(hapd, ANQP_NEIGHBOR_REPORT))
261 wpabuf_put_le16(buf, ANQP_NEIGHBOR_REPORT);
262 for (id = 273; id < 277; id++) {
263 if (get_anqp_elem(hapd, id))
264 wpabuf_put_le16(buf, id);
265 }
266 if (get_anqp_elem(hapd, ANQP_VENUE_URL))
267 wpabuf_put_le16(buf, ANQP_VENUE_URL);
268 if (get_anqp_elem(hapd, ANQP_ADVICE_OF_CHARGE))
269 wpabuf_put_le16(buf, ANQP_ADVICE_OF_CHARGE);
270 if (get_anqp_elem(hapd, ANQP_LOCAL_CONTENT))
271 wpabuf_put_le16(buf, ANQP_LOCAL_CONTENT);
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700272#ifdef CONFIG_HS20
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700273 anqp_add_hs_capab_list(hapd, buf);
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700274#endif /* CONFIG_HS20 */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700275 gas_anqp_set_element_len(buf, len);
276}
277
278
279static void anqp_add_venue_name(struct hostapd_data *hapd, struct wpabuf *buf)
280{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800281 if (anqp_add_override(hapd, buf, ANQP_VENUE_NAME))
282 return;
283
Dmitry Shmidt04949592012-07-19 12:16:46 -0700284 if (hapd->conf->venue_name) {
285 u8 *len;
286 unsigned int i;
287 len = gas_anqp_add_element(buf, ANQP_VENUE_NAME);
288 wpabuf_put_u8(buf, hapd->conf->venue_group);
289 wpabuf_put_u8(buf, hapd->conf->venue_type);
290 for (i = 0; i < hapd->conf->venue_name_count; i++) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700291 struct hostapd_lang_string *vn;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700292 vn = &hapd->conf->venue_name[i];
293 wpabuf_put_u8(buf, 3 + vn->name_len);
294 wpabuf_put_data(buf, vn->lang, 3);
295 wpabuf_put_data(buf, vn->name, vn->name_len);
296 }
297 gas_anqp_set_element_len(buf, len);
298 }
299}
300
301
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700302static void anqp_add_network_auth_type(struct hostapd_data *hapd,
303 struct wpabuf *buf)
304{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800305 if (anqp_add_override(hapd, buf, ANQP_NETWORK_AUTH_TYPE))
306 return;
307
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700308 if (hapd->conf->network_auth_type) {
309 wpabuf_put_le16(buf, ANQP_NETWORK_AUTH_TYPE);
310 wpabuf_put_le16(buf, hapd->conf->network_auth_type_len);
311 wpabuf_put_data(buf, hapd->conf->network_auth_type,
312 hapd->conf->network_auth_type_len);
313 }
314}
315
316
Dmitry Shmidt04949592012-07-19 12:16:46 -0700317static void anqp_add_roaming_consortium(struct hostapd_data *hapd,
318 struct wpabuf *buf)
319{
320 unsigned int i;
321 u8 *len;
322
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800323 if (anqp_add_override(hapd, buf, ANQP_ROAMING_CONSORTIUM))
324 return;
325
Dmitry Shmidt04949592012-07-19 12:16:46 -0700326 len = gas_anqp_add_element(buf, ANQP_ROAMING_CONSORTIUM);
327 for (i = 0; i < hapd->conf->roaming_consortium_count; i++) {
328 struct hostapd_roaming_consortium *rc;
329 rc = &hapd->conf->roaming_consortium[i];
330 wpabuf_put_u8(buf, rc->len);
331 wpabuf_put_data(buf, rc->oi, rc->len);
332 }
333 gas_anqp_set_element_len(buf, len);
334}
335
336
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700337static void anqp_add_ip_addr_type_availability(struct hostapd_data *hapd,
338 struct wpabuf *buf)
339{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800340 if (anqp_add_override(hapd, buf, ANQP_IP_ADDR_TYPE_AVAILABILITY))
341 return;
342
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700343 if (hapd->conf->ipaddr_type_configured) {
344 wpabuf_put_le16(buf, ANQP_IP_ADDR_TYPE_AVAILABILITY);
345 wpabuf_put_le16(buf, 1);
346 wpabuf_put_u8(buf, hapd->conf->ipaddr_type_availability);
347 }
348}
349
350
351static void anqp_add_nai_realm_eap(struct wpabuf *buf,
352 struct hostapd_nai_realm_data *realm)
353{
354 unsigned int i, j;
355
356 wpabuf_put_u8(buf, realm->eap_method_count);
357
358 for (i = 0; i < realm->eap_method_count; i++) {
359 struct hostapd_nai_realm_eap *eap = &realm->eap_method[i];
360 wpabuf_put_u8(buf, 2 + (3 * eap->num_auths));
361 wpabuf_put_u8(buf, eap->eap_method);
362 wpabuf_put_u8(buf, eap->num_auths);
363 for (j = 0; j < eap->num_auths; j++) {
364 wpabuf_put_u8(buf, eap->auth_id[j]);
365 wpabuf_put_u8(buf, 1);
366 wpabuf_put_u8(buf, eap->auth_val[j]);
367 }
368 }
369}
370
371
372static void anqp_add_nai_realm_data(struct wpabuf *buf,
373 struct hostapd_nai_realm_data *realm,
374 unsigned int realm_idx)
375{
376 u8 *realm_data_len;
377
378 wpa_printf(MSG_DEBUG, "realm=%s, len=%d", realm->realm[realm_idx],
379 (int) os_strlen(realm->realm[realm_idx]));
380 realm_data_len = wpabuf_put(buf, 2);
381 wpabuf_put_u8(buf, realm->encoding);
382 wpabuf_put_u8(buf, os_strlen(realm->realm[realm_idx]));
383 wpabuf_put_str(buf, realm->realm[realm_idx]);
384 anqp_add_nai_realm_eap(buf, realm);
385 gas_anqp_set_element_len(buf, realm_data_len);
386}
387
388
389static int hs20_add_nai_home_realm_matches(struct hostapd_data *hapd,
390 struct wpabuf *buf,
391 const u8 *home_realm,
392 size_t home_realm_len)
393{
394 unsigned int i, j, k;
395 u8 num_realms, num_matching = 0, encoding, realm_len, *realm_list_len;
396 struct hostapd_nai_realm_data *realm;
397 const u8 *pos, *realm_name, *end;
398 struct {
399 unsigned int realm_data_idx;
400 unsigned int realm_idx;
401 } matches[10];
402
403 pos = home_realm;
404 end = pos + home_realm_len;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800405 if (end - pos < 1) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700406 wpa_hexdump(MSG_DEBUG, "Too short NAI Home Realm Query",
407 home_realm, home_realm_len);
408 return -1;
409 }
410 num_realms = *pos++;
411
412 for (i = 0; i < num_realms && num_matching < 10; i++) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800413 if (end - pos < 2) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700414 wpa_hexdump(MSG_DEBUG,
415 "Truncated NAI Home Realm Query",
416 home_realm, home_realm_len);
417 return -1;
418 }
419 encoding = *pos++;
420 realm_len = *pos++;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800421 if (realm_len > end - pos) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700422 wpa_hexdump(MSG_DEBUG,
423 "Truncated NAI Home Realm Query",
424 home_realm, home_realm_len);
425 return -1;
426 }
427 realm_name = pos;
428 for (j = 0; j < hapd->conf->nai_realm_count &&
429 num_matching < 10; j++) {
430 const u8 *rpos, *rend;
431 realm = &hapd->conf->nai_realm_data[j];
432 if (encoding != realm->encoding)
433 continue;
434
435 rpos = realm_name;
436 while (rpos < realm_name + realm_len &&
437 num_matching < 10) {
438 for (rend = rpos;
439 rend < realm_name + realm_len; rend++) {
440 if (*rend == ';')
441 break;
442 }
443 for (k = 0; k < MAX_NAI_REALMS &&
444 realm->realm[k] &&
445 num_matching < 10; k++) {
446 if ((int) os_strlen(realm->realm[k]) !=
447 rend - rpos ||
448 os_strncmp((char *) rpos,
449 realm->realm[k],
450 rend - rpos) != 0)
451 continue;
452 matches[num_matching].realm_data_idx =
453 j;
454 matches[num_matching].realm_idx = k;
455 num_matching++;
456 }
457 rpos = rend + 1;
458 }
459 }
460 pos += realm_len;
461 }
462
463 realm_list_len = gas_anqp_add_element(buf, ANQP_NAI_REALM);
464 wpabuf_put_le16(buf, num_matching);
465
466 /*
467 * There are two ways to format. 1. each realm in a NAI Realm Data unit
468 * 2. all realms that share the same EAP methods in a NAI Realm Data
469 * unit. The first format is likely to be bigger in size than the
470 * second, but may be easier to parse and process by the receiver.
471 */
472 for (i = 0; i < num_matching; i++) {
473 wpa_printf(MSG_DEBUG, "realm_idx %d, realm_data_idx %d",
474 matches[i].realm_data_idx, matches[i].realm_idx);
475 realm = &hapd->conf->nai_realm_data[matches[i].realm_data_idx];
476 anqp_add_nai_realm_data(buf, realm, matches[i].realm_idx);
477 }
478 gas_anqp_set_element_len(buf, realm_list_len);
479 return 0;
480}
481
482
483static void anqp_add_nai_realm(struct hostapd_data *hapd, struct wpabuf *buf,
484 const u8 *home_realm, size_t home_realm_len,
485 int nai_realm, int nai_home_realm)
486{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800487 if (nai_realm && !nai_home_realm &&
488 anqp_add_override(hapd, buf, ANQP_NAI_REALM))
489 return;
490
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700491 if (nai_realm && hapd->conf->nai_realm_data) {
492 u8 *len;
493 unsigned int i, j;
494 len = gas_anqp_add_element(buf, ANQP_NAI_REALM);
495 wpabuf_put_le16(buf, hapd->conf->nai_realm_count);
496 for (i = 0; i < hapd->conf->nai_realm_count; i++) {
497 u8 *realm_data_len, *realm_len;
498 struct hostapd_nai_realm_data *realm;
499
500 realm = &hapd->conf->nai_realm_data[i];
501 realm_data_len = wpabuf_put(buf, 2);
502 wpabuf_put_u8(buf, realm->encoding);
503 realm_len = wpabuf_put(buf, 1);
504 for (j = 0; realm->realm[j]; j++) {
505 if (j > 0)
506 wpabuf_put_u8(buf, ';');
507 wpabuf_put_str(buf, realm->realm[j]);
508 }
509 *realm_len = (u8 *) wpabuf_put(buf, 0) - realm_len - 1;
510 anqp_add_nai_realm_eap(buf, realm);
511 gas_anqp_set_element_len(buf, realm_data_len);
512 }
513 gas_anqp_set_element_len(buf, len);
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -0700514 } else if (nai_home_realm && hapd->conf->nai_realm_data && home_realm) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700515 hs20_add_nai_home_realm_matches(hapd, buf, home_realm,
516 home_realm_len);
517 }
518}
519
520
521static void anqp_add_3gpp_cellular_network(struct hostapd_data *hapd,
522 struct wpabuf *buf)
523{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800524 if (anqp_add_override(hapd, buf, ANQP_3GPP_CELLULAR_NETWORK))
525 return;
526
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700527 if (hapd->conf->anqp_3gpp_cell_net) {
528 wpabuf_put_le16(buf, ANQP_3GPP_CELLULAR_NETWORK);
529 wpabuf_put_le16(buf,
530 hapd->conf->anqp_3gpp_cell_net_len);
531 wpabuf_put_data(buf, hapd->conf->anqp_3gpp_cell_net,
532 hapd->conf->anqp_3gpp_cell_net_len);
533 }
534}
535
536
537static void anqp_add_domain_name(struct hostapd_data *hapd, struct wpabuf *buf)
538{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800539 if (anqp_add_override(hapd, buf, ANQP_DOMAIN_NAME))
540 return;
541
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700542 if (hapd->conf->domain_name) {
543 wpabuf_put_le16(buf, ANQP_DOMAIN_NAME);
544 wpabuf_put_le16(buf, hapd->conf->domain_name_len);
545 wpabuf_put_data(buf, hapd->conf->domain_name,
546 hapd->conf->domain_name_len);
547 }
548}
549
550
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700551#ifdef CONFIG_HS20
552
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700553static void anqp_add_operator_friendly_name(struct hostapd_data *hapd,
554 struct wpabuf *buf)
555{
556 if (hapd->conf->hs20_oper_friendly_name) {
557 u8 *len;
558 unsigned int i;
559 len = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
560 wpabuf_put_be24(buf, OUI_WFA);
561 wpabuf_put_u8(buf, HS20_ANQP_OUI_TYPE);
562 wpabuf_put_u8(buf, HS20_STYPE_OPERATOR_FRIENDLY_NAME);
563 wpabuf_put_u8(buf, 0); /* Reserved */
564 for (i = 0; i < hapd->conf->hs20_oper_friendly_name_count; i++)
565 {
566 struct hostapd_lang_string *vn;
567 vn = &hapd->conf->hs20_oper_friendly_name[i];
568 wpabuf_put_u8(buf, 3 + vn->name_len);
569 wpabuf_put_data(buf, vn->lang, 3);
570 wpabuf_put_data(buf, vn->name, vn->name_len);
571 }
572 gas_anqp_set_element_len(buf, len);
573 }
574}
575
576
577static void anqp_add_wan_metrics(struct hostapd_data *hapd,
578 struct wpabuf *buf)
579{
580 if (hapd->conf->hs20_wan_metrics) {
581 u8 *len = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
582 wpabuf_put_be24(buf, OUI_WFA);
583 wpabuf_put_u8(buf, HS20_ANQP_OUI_TYPE);
584 wpabuf_put_u8(buf, HS20_STYPE_WAN_METRICS);
585 wpabuf_put_u8(buf, 0); /* Reserved */
586 wpabuf_put_data(buf, hapd->conf->hs20_wan_metrics, 13);
587 gas_anqp_set_element_len(buf, len);
588 }
589}
590
591
592static void anqp_add_connection_capability(struct hostapd_data *hapd,
593 struct wpabuf *buf)
594{
595 if (hapd->conf->hs20_connection_capability) {
596 u8 *len = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
597 wpabuf_put_be24(buf, OUI_WFA);
598 wpabuf_put_u8(buf, HS20_ANQP_OUI_TYPE);
599 wpabuf_put_u8(buf, HS20_STYPE_CONNECTION_CAPABILITY);
600 wpabuf_put_u8(buf, 0); /* Reserved */
601 wpabuf_put_data(buf, hapd->conf->hs20_connection_capability,
602 hapd->conf->hs20_connection_capability_len);
603 gas_anqp_set_element_len(buf, len);
604 }
605}
606
607
608static void anqp_add_operating_class(struct hostapd_data *hapd,
609 struct wpabuf *buf)
610{
611 if (hapd->conf->hs20_operating_class) {
612 u8 *len = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
613 wpabuf_put_be24(buf, OUI_WFA);
614 wpabuf_put_u8(buf, HS20_ANQP_OUI_TYPE);
615 wpabuf_put_u8(buf, HS20_STYPE_OPERATING_CLASS);
616 wpabuf_put_u8(buf, 0); /* Reserved */
617 wpabuf_put_data(buf, hapd->conf->hs20_operating_class,
618 hapd->conf->hs20_operating_class_len);
619 gas_anqp_set_element_len(buf, len);
620 }
621}
622
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800623
624static void anqp_add_osu_provider(struct wpabuf *buf,
625 struct hostapd_bss_config *bss,
626 struct hs20_osu_provider *p)
627{
628 u8 *len, *len2, *count;
629 unsigned int i;
630
631 len = wpabuf_put(buf, 2); /* OSU Provider Length to be filled */
632
633 /* OSU Friendly Name Duples */
634 len2 = wpabuf_put(buf, 2);
635 for (i = 0; i < p->friendly_name_count; i++) {
636 struct hostapd_lang_string *s = &p->friendly_name[i];
637 wpabuf_put_u8(buf, 3 + s->name_len);
638 wpabuf_put_data(buf, s->lang, 3);
639 wpabuf_put_data(buf, s->name, s->name_len);
640 }
641 WPA_PUT_LE16(len2, (u8 *) wpabuf_put(buf, 0) - len2 - 2);
642
643 /* OSU Server URI */
644 if (p->server_uri) {
645 wpabuf_put_u8(buf, os_strlen(p->server_uri));
646 wpabuf_put_str(buf, p->server_uri);
647 } else
648 wpabuf_put_u8(buf, 0);
649
650 /* OSU Method List */
651 count = wpabuf_put(buf, 1);
652 for (i = 0; p->method_list[i] >= 0; i++)
653 wpabuf_put_u8(buf, p->method_list[i]);
654 *count = i;
655
656 /* Icons Available */
657 len2 = wpabuf_put(buf, 2);
658 for (i = 0; i < p->icons_count; i++) {
659 size_t j;
660 struct hs20_icon *icon = NULL;
661
662 for (j = 0; j < bss->hs20_icons_count && !icon; j++) {
663 if (os_strcmp(p->icons[i], bss->hs20_icons[j].name) ==
664 0)
665 icon = &bss->hs20_icons[j];
666 }
667 if (!icon)
668 continue; /* icon info not found */
669
670 wpabuf_put_le16(buf, icon->width);
671 wpabuf_put_le16(buf, icon->height);
672 wpabuf_put_data(buf, icon->language, 3);
673 wpabuf_put_u8(buf, os_strlen(icon->type));
674 wpabuf_put_str(buf, icon->type);
675 wpabuf_put_u8(buf, os_strlen(icon->name));
676 wpabuf_put_str(buf, icon->name);
677 }
678 WPA_PUT_LE16(len2, (u8 *) wpabuf_put(buf, 0) - len2 - 2);
679
680 /* OSU_NAI */
681 if (p->osu_nai) {
682 wpabuf_put_u8(buf, os_strlen(p->osu_nai));
683 wpabuf_put_str(buf, p->osu_nai);
684 } else
685 wpabuf_put_u8(buf, 0);
686
687 /* OSU Service Description Duples */
688 len2 = wpabuf_put(buf, 2);
689 for (i = 0; i < p->service_desc_count; i++) {
690 struct hostapd_lang_string *s = &p->service_desc[i];
691 wpabuf_put_u8(buf, 3 + s->name_len);
692 wpabuf_put_data(buf, s->lang, 3);
693 wpabuf_put_data(buf, s->name, s->name_len);
694 }
695 WPA_PUT_LE16(len2, (u8 *) wpabuf_put(buf, 0) - len2 - 2);
696
697 WPA_PUT_LE16(len, (u8 *) wpabuf_put(buf, 0) - len - 2);
698}
699
700
701static void anqp_add_osu_providers_list(struct hostapd_data *hapd,
702 struct wpabuf *buf)
703{
704 if (hapd->conf->hs20_osu_providers_count) {
705 size_t i;
706 u8 *len = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
707 wpabuf_put_be24(buf, OUI_WFA);
708 wpabuf_put_u8(buf, HS20_ANQP_OUI_TYPE);
709 wpabuf_put_u8(buf, HS20_STYPE_OSU_PROVIDERS_LIST);
710 wpabuf_put_u8(buf, 0); /* Reserved */
711
712 /* OSU SSID */
713 wpabuf_put_u8(buf, hapd->conf->osu_ssid_len);
714 wpabuf_put_data(buf, hapd->conf->osu_ssid,
715 hapd->conf->osu_ssid_len);
716
717 /* Number of OSU Providers */
718 wpabuf_put_u8(buf, hapd->conf->hs20_osu_providers_count);
719
720 for (i = 0; i < hapd->conf->hs20_osu_providers_count; i++) {
721 anqp_add_osu_provider(
722 buf, hapd->conf,
723 &hapd->conf->hs20_osu_providers[i]);
724 }
725
726 gas_anqp_set_element_len(buf, len);
727 }
728}
729
730
731static void anqp_add_icon_binary_file(struct hostapd_data *hapd,
732 struct wpabuf *buf,
733 const u8 *name, size_t name_len)
734{
735 struct hs20_icon *icon;
736 size_t i;
737 u8 *len;
738
739 wpa_hexdump_ascii(MSG_DEBUG, "HS 2.0: Requested Icon Filename",
740 name, name_len);
741 for (i = 0; i < hapd->conf->hs20_icons_count; i++) {
742 icon = &hapd->conf->hs20_icons[i];
743 if (name_len == os_strlen(icon->name) &&
744 os_memcmp(name, icon->name, name_len) == 0)
745 break;
746 }
747
748 if (i < hapd->conf->hs20_icons_count)
749 icon = &hapd->conf->hs20_icons[i];
750 else
751 icon = NULL;
752
753 len = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
754 wpabuf_put_be24(buf, OUI_WFA);
755 wpabuf_put_u8(buf, HS20_ANQP_OUI_TYPE);
756 wpabuf_put_u8(buf, HS20_STYPE_ICON_BINARY_FILE);
757 wpabuf_put_u8(buf, 0); /* Reserved */
758
759 if (icon) {
760 char *data;
761 size_t data_len;
762
763 data = os_readfile(icon->file, &data_len);
764 if (data == NULL || data_len > 65535) {
765 wpabuf_put_u8(buf, 2); /* Download Status:
766 * Unspecified file error */
767 wpabuf_put_u8(buf, 0);
768 wpabuf_put_le16(buf, 0);
769 } else {
770 wpabuf_put_u8(buf, 0); /* Download Status: Success */
771 wpabuf_put_u8(buf, os_strlen(icon->type));
772 wpabuf_put_str(buf, icon->type);
773 wpabuf_put_le16(buf, data_len);
774 wpabuf_put_data(buf, data, data_len);
775 }
776 os_free(data);
777 } else {
778 wpabuf_put_u8(buf, 1); /* Download Status: File not found */
779 wpabuf_put_u8(buf, 0);
780 wpabuf_put_le16(buf, 0);
781 }
782
783 gas_anqp_set_element_len(buf, len);
784}
785
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700786#endif /* CONFIG_HS20 */
787
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700788
Dmitry Shmidt04949592012-07-19 12:16:46 -0700789static struct wpabuf *
790gas_serv_build_gas_resp_payload(struct hostapd_data *hapd,
791 unsigned int request,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800792 const u8 *home_realm, size_t home_realm_len,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800793 const u8 *icon_name, size_t icon_name_len,
794 const u16 *extra_req,
795 unsigned int num_extra_req)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700796{
797 struct wpabuf *buf;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800798 size_t len;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800799 unsigned int i;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700800
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800801 len = 1400;
802 if (request & (ANQP_REQ_NAI_REALM | ANQP_REQ_NAI_HOME_REALM))
803 len += 1000;
804 if (request & ANQP_REQ_ICON_REQUEST)
805 len += 65536;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800806 len += num_extra_req * 1000;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800807
808 buf = wpabuf_alloc(len);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700809 if (buf == NULL)
810 return NULL;
811
812 if (request & ANQP_REQ_CAPABILITY_LIST)
813 anqp_add_capab_list(hapd, buf);
814 if (request & ANQP_REQ_VENUE_NAME)
815 anqp_add_venue_name(hapd, buf);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800816 if (request & ANQP_REQ_EMERGENCY_CALL_NUMBER)
817 anqp_add_elem(hapd, buf, ANQP_EMERGENCY_CALL_NUMBER);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700818 if (request & ANQP_REQ_NETWORK_AUTH_TYPE)
819 anqp_add_network_auth_type(hapd, buf);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700820 if (request & ANQP_REQ_ROAMING_CONSORTIUM)
821 anqp_add_roaming_consortium(hapd, buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700822 if (request & ANQP_REQ_IP_ADDR_TYPE_AVAILABILITY)
823 anqp_add_ip_addr_type_availability(hapd, buf);
824 if (request & (ANQP_REQ_NAI_REALM | ANQP_REQ_NAI_HOME_REALM))
825 anqp_add_nai_realm(hapd, buf, home_realm, home_realm_len,
826 request & ANQP_REQ_NAI_REALM,
827 request & ANQP_REQ_NAI_HOME_REALM);
828 if (request & ANQP_REQ_3GPP_CELLULAR_NETWORK)
829 anqp_add_3gpp_cellular_network(hapd, buf);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800830 if (request & ANQP_REQ_AP_GEOSPATIAL_LOCATION)
831 anqp_add_elem(hapd, buf, ANQP_AP_GEOSPATIAL_LOCATION);
832 if (request & ANQP_REQ_AP_CIVIC_LOCATION)
833 anqp_add_elem(hapd, buf, ANQP_AP_CIVIC_LOCATION);
834 if (request & ANQP_REQ_AP_LOCATION_PUBLIC_URI)
835 anqp_add_elem(hapd, buf, ANQP_AP_LOCATION_PUBLIC_URI);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700836 if (request & ANQP_REQ_DOMAIN_NAME)
837 anqp_add_domain_name(hapd, buf);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800838 if (request & ANQP_REQ_EMERGENCY_ALERT_URI)
839 anqp_add_elem(hapd, buf, ANQP_EMERGENCY_ALERT_URI);
840 if (request & ANQP_REQ_TDLS_CAPABILITY)
841 anqp_add_elem(hapd, buf, ANQP_TDLS_CAPABILITY);
842 if (request & ANQP_REQ_EMERGENCY_NAI)
843 anqp_add_elem(hapd, buf, ANQP_EMERGENCY_NAI);
844
845 for (i = 0; i < num_extra_req; i++)
846 anqp_add_elem(hapd, buf, extra_req[i]);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700847
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700848#ifdef CONFIG_HS20
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700849 if (request & ANQP_REQ_HS_CAPABILITY_LIST)
850 anqp_add_hs_capab_list(hapd, buf);
851 if (request & ANQP_REQ_OPERATOR_FRIENDLY_NAME)
852 anqp_add_operator_friendly_name(hapd, buf);
853 if (request & ANQP_REQ_WAN_METRICS)
854 anqp_add_wan_metrics(hapd, buf);
855 if (request & ANQP_REQ_CONNECTION_CAPABILITY)
856 anqp_add_connection_capability(hapd, buf);
857 if (request & ANQP_REQ_OPERATING_CLASS)
858 anqp_add_operating_class(hapd, buf);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800859 if (request & ANQP_REQ_OSU_PROVIDERS_LIST)
860 anqp_add_osu_providers_list(hapd, buf);
861 if (request & ANQP_REQ_ICON_REQUEST)
862 anqp_add_icon_binary_file(hapd, buf, icon_name, icon_name_len);
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700863#endif /* CONFIG_HS20 */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700864
865 return buf;
866}
867
868
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800869#define ANQP_MAX_EXTRA_REQ 20
870
Dmitry Shmidt04949592012-07-19 12:16:46 -0700871struct anqp_query_info {
872 unsigned int request;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700873 const u8 *home_realm_query;
874 size_t home_realm_query_len;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800875 const u8 *icon_name;
876 size_t icon_name_len;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800877 int p2p_sd;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800878 u16 extra_req[ANQP_MAX_EXTRA_REQ];
879 unsigned int num_extra_req;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700880};
881
882
883static void set_anqp_req(unsigned int bit, const char *name, int local,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700884 struct anqp_query_info *qi)
885{
886 qi->request |= bit;
887 if (local) {
888 wpa_printf(MSG_DEBUG, "ANQP: %s (local)", name);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700889 } else {
890 wpa_printf(MSG_DEBUG, "ANQP: %s not available", name);
891 }
892}
893
894
895static void rx_anqp_query_list_id(struct hostapd_data *hapd, u16 info_id,
896 struct anqp_query_info *qi)
897{
898 switch (info_id) {
899 case ANQP_CAPABILITY_LIST:
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700900 set_anqp_req(ANQP_REQ_CAPABILITY_LIST, "Capability List", 1,
901 qi);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700902 break;
903 case ANQP_VENUE_NAME:
904 set_anqp_req(ANQP_REQ_VENUE_NAME, "Venue Name",
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700905 hapd->conf->venue_name != NULL, qi);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700906 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800907 case ANQP_EMERGENCY_CALL_NUMBER:
908 set_anqp_req(ANQP_REQ_EMERGENCY_CALL_NUMBER,
909 "Emergency Call Number",
910 get_anqp_elem(hapd, info_id) != NULL, qi);
911 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700912 case ANQP_NETWORK_AUTH_TYPE:
913 set_anqp_req(ANQP_REQ_NETWORK_AUTH_TYPE, "Network Auth Type",
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700914 hapd->conf->network_auth_type != NULL, qi);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700915 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700916 case ANQP_ROAMING_CONSORTIUM:
917 set_anqp_req(ANQP_REQ_ROAMING_CONSORTIUM, "Roaming Consortium",
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700918 hapd->conf->roaming_consortium != NULL, qi);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700919 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700920 case ANQP_IP_ADDR_TYPE_AVAILABILITY:
921 set_anqp_req(ANQP_REQ_IP_ADDR_TYPE_AVAILABILITY,
922 "IP Addr Type Availability",
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700923 hapd->conf->ipaddr_type_configured, qi);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700924 break;
925 case ANQP_NAI_REALM:
926 set_anqp_req(ANQP_REQ_NAI_REALM, "NAI Realm",
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700927 hapd->conf->nai_realm_data != NULL, qi);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700928 break;
929 case ANQP_3GPP_CELLULAR_NETWORK:
930 set_anqp_req(ANQP_REQ_3GPP_CELLULAR_NETWORK,
931 "3GPP Cellular Network",
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700932 hapd->conf->anqp_3gpp_cell_net != NULL, qi);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700933 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800934 case ANQP_AP_GEOSPATIAL_LOCATION:
935 set_anqp_req(ANQP_REQ_AP_GEOSPATIAL_LOCATION,
936 "AP Geospatial Location",
937 get_anqp_elem(hapd, info_id) != NULL, qi);
938 break;
939 case ANQP_AP_CIVIC_LOCATION:
940 set_anqp_req(ANQP_REQ_AP_CIVIC_LOCATION,
941 "AP Civic Location",
942 get_anqp_elem(hapd, info_id) != NULL, qi);
943 break;
944 case ANQP_AP_LOCATION_PUBLIC_URI:
945 set_anqp_req(ANQP_REQ_AP_LOCATION_PUBLIC_URI,
946 "AP Location Public URI",
947 get_anqp_elem(hapd, info_id) != NULL, qi);
948 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700949 case ANQP_DOMAIN_NAME:
950 set_anqp_req(ANQP_REQ_DOMAIN_NAME, "Domain Name",
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700951 hapd->conf->domain_name != NULL, qi);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700952 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800953 case ANQP_EMERGENCY_ALERT_URI:
954 set_anqp_req(ANQP_REQ_EMERGENCY_ALERT_URI,
955 "Emergency Alert URI",
956 get_anqp_elem(hapd, info_id) != NULL, qi);
957 break;
958 case ANQP_TDLS_CAPABILITY:
959 set_anqp_req(ANQP_REQ_TDLS_CAPABILITY,
960 "TDLS Capability",
961 get_anqp_elem(hapd, info_id) != NULL, qi);
962 break;
963 case ANQP_EMERGENCY_NAI:
964 set_anqp_req(ANQP_REQ_EMERGENCY_NAI,
965 "Emergency NAI",
966 get_anqp_elem(hapd, info_id) != NULL, qi);
967 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700968 default:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800969 if (!get_anqp_elem(hapd, info_id)) {
970 wpa_printf(MSG_DEBUG, "ANQP: Unsupported Info Id %u",
971 info_id);
972 break;
973 }
974 if (qi->num_extra_req == ANQP_MAX_EXTRA_REQ) {
975 wpa_printf(MSG_DEBUG,
976 "ANQP: No more room for extra requests - ignore Info Id %u",
977 info_id);
978 break;
979 }
980 wpa_printf(MSG_DEBUG, "ANQP: Info Id %u (local)", info_id);
981 qi->extra_req[qi->num_extra_req] = info_id;
982 qi->num_extra_req++;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700983 break;
984 }
985}
986
987
988static void rx_anqp_query_list(struct hostapd_data *hapd,
989 const u8 *pos, const u8 *end,
990 struct anqp_query_info *qi)
991{
992 wpa_printf(MSG_DEBUG, "ANQP: %u Info IDs requested in Query list",
993 (unsigned int) (end - pos) / 2);
994
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800995 while (end - pos >= 2) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700996 rx_anqp_query_list_id(hapd, WPA_GET_LE16(pos), qi);
997 pos += 2;
998 }
999}
1000
1001
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001002#ifdef CONFIG_HS20
1003
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001004static void rx_anqp_hs_query_list(struct hostapd_data *hapd, u8 subtype,
1005 struct anqp_query_info *qi)
1006{
1007 switch (subtype) {
1008 case HS20_STYPE_CAPABILITY_LIST:
1009 set_anqp_req(ANQP_REQ_HS_CAPABILITY_LIST, "HS Capability List",
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001010 1, qi);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001011 break;
1012 case HS20_STYPE_OPERATOR_FRIENDLY_NAME:
1013 set_anqp_req(ANQP_REQ_OPERATOR_FRIENDLY_NAME,
1014 "Operator Friendly Name",
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001015 hapd->conf->hs20_oper_friendly_name != NULL, qi);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001016 break;
1017 case HS20_STYPE_WAN_METRICS:
1018 set_anqp_req(ANQP_REQ_WAN_METRICS, "WAN Metrics",
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001019 hapd->conf->hs20_wan_metrics != NULL, qi);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001020 break;
1021 case HS20_STYPE_CONNECTION_CAPABILITY:
1022 set_anqp_req(ANQP_REQ_CONNECTION_CAPABILITY,
1023 "Connection Capability",
1024 hapd->conf->hs20_connection_capability != NULL,
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001025 qi);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001026 break;
1027 case HS20_STYPE_OPERATING_CLASS:
1028 set_anqp_req(ANQP_REQ_OPERATING_CLASS, "Operating Class",
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001029 hapd->conf->hs20_operating_class != NULL, qi);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001030 break;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001031 case HS20_STYPE_OSU_PROVIDERS_LIST:
1032 set_anqp_req(ANQP_REQ_OSU_PROVIDERS_LIST, "OSU Providers list",
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001033 hapd->conf->hs20_osu_providers_count, qi);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001034 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001035 default:
1036 wpa_printf(MSG_DEBUG, "ANQP: Unsupported HS 2.0 subtype %u",
1037 subtype);
1038 break;
1039 }
1040}
1041
1042
1043static void rx_anqp_hs_nai_home_realm(struct hostapd_data *hapd,
1044 const u8 *pos, const u8 *end,
1045 struct anqp_query_info *qi)
1046{
1047 qi->request |= ANQP_REQ_NAI_HOME_REALM;
1048 qi->home_realm_query = pos;
1049 qi->home_realm_query_len = end - pos;
1050 if (hapd->conf->nai_realm_data != NULL) {
1051 wpa_printf(MSG_DEBUG, "ANQP: HS 2.0 NAI Home Realm Query "
1052 "(local)");
1053 } else {
1054 wpa_printf(MSG_DEBUG, "ANQP: HS 2.0 NAI Home Realm Query not "
1055 "available");
1056 }
1057}
1058
1059
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001060static void rx_anqp_hs_icon_request(struct hostapd_data *hapd,
1061 const u8 *pos, const u8 *end,
1062 struct anqp_query_info *qi)
1063{
1064 qi->request |= ANQP_REQ_ICON_REQUEST;
1065 qi->icon_name = pos;
1066 qi->icon_name_len = end - pos;
1067 if (hapd->conf->hs20_icons_count) {
1068 wpa_printf(MSG_DEBUG, "ANQP: HS 2.0 Icon Request Query "
1069 "(local)");
1070 } else {
1071 wpa_printf(MSG_DEBUG, "ANQP: HS 2.0 Icon Request Query not "
1072 "available");
1073 }
1074}
1075
1076
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001077static void rx_anqp_vendor_specific(struct hostapd_data *hapd,
1078 const u8 *pos, const u8 *end,
1079 struct anqp_query_info *qi)
1080{
1081 u32 oui;
1082 u8 subtype;
1083
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001084 if (end - pos < 4) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001085 wpa_printf(MSG_DEBUG, "ANQP: Too short vendor specific ANQP "
1086 "Query element");
1087 return;
1088 }
1089
1090 oui = WPA_GET_BE24(pos);
1091 pos += 3;
1092 if (oui != OUI_WFA) {
1093 wpa_printf(MSG_DEBUG, "ANQP: Unsupported vendor OUI %06x",
1094 oui);
1095 return;
1096 }
1097
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001098#ifdef CONFIG_P2P
1099 if (*pos == P2P_OUI_TYPE) {
1100 /*
1101 * This is for P2P SD and will be taken care of by the P2P
1102 * implementation. This query needs to be ignored in the generic
1103 * GAS server to avoid duplicated response.
1104 */
1105 wpa_printf(MSG_DEBUG,
1106 "ANQP: Ignore WFA vendor type %u (P2P SD) in generic GAS server",
1107 *pos);
1108 qi->p2p_sd = 1;
1109 return;
1110 }
1111#endif /* CONFIG_P2P */
1112
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001113 if (*pos != HS20_ANQP_OUI_TYPE) {
1114 wpa_printf(MSG_DEBUG, "ANQP: Unsupported WFA vendor type %u",
1115 *pos);
1116 return;
1117 }
1118 pos++;
1119
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001120 if (end - pos <= 1)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001121 return;
1122
1123 subtype = *pos++;
1124 pos++; /* Reserved */
1125 switch (subtype) {
1126 case HS20_STYPE_QUERY_LIST:
1127 wpa_printf(MSG_DEBUG, "ANQP: HS 2.0 Query List");
1128 while (pos < end) {
1129 rx_anqp_hs_query_list(hapd, *pos, qi);
1130 pos++;
1131 }
1132 break;
1133 case HS20_STYPE_NAI_HOME_REALM_QUERY:
1134 rx_anqp_hs_nai_home_realm(hapd, pos, end, qi);
1135 break;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001136 case HS20_STYPE_ICON_REQUEST:
1137 rx_anqp_hs_icon_request(hapd, pos, end, qi);
1138 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001139 default:
1140 wpa_printf(MSG_DEBUG, "ANQP: Unsupported HS 2.0 query subtype "
1141 "%u", subtype);
1142 break;
1143 }
1144}
1145
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001146#endif /* CONFIG_HS20 */
1147
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001148
Dmitry Shmidt04949592012-07-19 12:16:46 -07001149static void gas_serv_req_local_processing(struct hostapd_data *hapd,
1150 const u8 *sa, u8 dialog_token,
Dmitry Shmidt18463232014-01-24 12:29:41 -08001151 struct anqp_query_info *qi, int prot)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001152{
1153 struct wpabuf *buf, *tx_buf;
1154
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07001155 buf = gas_serv_build_gas_resp_payload(hapd, qi->request,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001156 qi->home_realm_query,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001157 qi->home_realm_query_len,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001158 qi->icon_name, qi->icon_name_len,
1159 qi->extra_req, qi->num_extra_req);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001160 wpa_hexdump_buf(MSG_MSGDUMP, "ANQP: Locally generated ANQP responses",
1161 buf);
1162 if (!buf)
1163 return;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08001164#ifdef CONFIG_P2P
1165 if (wpabuf_len(buf) == 0 && qi->p2p_sd) {
1166 wpa_printf(MSG_DEBUG,
1167 "ANQP: Do not send response to P2P SD from generic GAS service (P2P SD implementation will process this)");
1168 wpabuf_free(buf);
1169 return;
1170 }
1171#endif /* CONFIG_P2P */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001172
1173 if (wpabuf_len(buf) > hapd->gas_frag_limit ||
1174 hapd->conf->gas_comeback_delay) {
1175 struct gas_dialog_info *di;
1176 u16 comeback_delay = 1;
1177
1178 if (hapd->conf->gas_comeback_delay) {
1179 /* Testing - allow overriding of the delay value */
1180 comeback_delay = hapd->conf->gas_comeback_delay;
1181 }
1182
1183 wpa_printf(MSG_DEBUG, "ANQP: Too long response to fit in "
1184 "initial response - use GAS comeback");
1185 di = gas_dialog_create(hapd, sa, dialog_token);
1186 if (!di) {
1187 wpa_printf(MSG_INFO, "ANQP: Could not create dialog "
1188 "for " MACSTR " (dialog token %u)",
1189 MAC2STR(sa), dialog_token);
1190 wpabuf_free(buf);
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07001191 tx_buf = gas_anqp_build_initial_resp_buf(
1192 dialog_token, WLAN_STATUS_UNSPECIFIED_FAILURE,
1193 0, NULL);
1194 } else {
1195 di->prot = prot;
1196 di->sd_resp = buf;
1197 di->sd_resp_pos = 0;
1198 tx_buf = gas_anqp_build_initial_resp_buf(
1199 dialog_token, WLAN_STATUS_SUCCESS,
1200 comeback_delay, NULL);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001201 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001202 } else {
1203 wpa_printf(MSG_DEBUG, "ANQP: Initial response (no comeback)");
1204 tx_buf = gas_anqp_build_initial_resp_buf(
1205 dialog_token, WLAN_STATUS_SUCCESS, 0, buf);
1206 wpabuf_free(buf);
1207 }
1208 if (!tx_buf)
1209 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -08001210 if (prot)
1211 convert_to_protected_dual(tx_buf);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001212 hostapd_drv_send_action(hapd, hapd->iface->freq, 0, sa,
1213 wpabuf_head(tx_buf), wpabuf_len(tx_buf));
1214 wpabuf_free(tx_buf);
1215}
1216
1217
1218static void gas_serv_rx_gas_initial_req(struct hostapd_data *hapd,
1219 const u8 *sa,
Dmitry Shmidt18463232014-01-24 12:29:41 -08001220 const u8 *data, size_t len, int prot)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001221{
1222 const u8 *pos = data;
1223 const u8 *end = data + len;
1224 const u8 *next;
1225 u8 dialog_token;
1226 u16 slen;
1227 struct anqp_query_info qi;
1228 const u8 *adv_proto;
1229
1230 if (len < 1 + 2)
1231 return;
1232
1233 os_memset(&qi, 0, sizeof(qi));
1234
1235 dialog_token = *pos++;
1236 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
1237 "GAS: GAS Initial Request from " MACSTR " (dialog token %u) ",
1238 MAC2STR(sa), dialog_token);
1239
1240 if (*pos != WLAN_EID_ADV_PROTO) {
1241 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
1242 "GAS: Unexpected IE in GAS Initial Request: %u", *pos);
1243 return;
1244 }
1245 adv_proto = pos++;
1246
1247 slen = *pos++;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001248 if (slen > end - pos || slen < 2) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001249 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
1250 "GAS: Invalid IE in GAS Initial Request");
1251 return;
1252 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001253 next = pos + slen;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001254 pos++; /* skip QueryRespLenLimit and PAME-BI */
1255
1256 if (*pos != ACCESS_NETWORK_QUERY_PROTOCOL) {
1257 struct wpabuf *buf;
1258 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
1259 "GAS: Unsupported GAS advertisement protocol id %u",
1260 *pos);
1261 if (sa[0] & 0x01)
1262 return; /* Invalid source address - drop silently */
1263 buf = gas_build_initial_resp(
1264 dialog_token, WLAN_STATUS_GAS_ADV_PROTO_NOT_SUPPORTED,
1265 0, 2 + slen + 2);
1266 if (buf == NULL)
1267 return;
1268 wpabuf_put_data(buf, adv_proto, 2 + slen);
1269 wpabuf_put_le16(buf, 0); /* Query Response Length */
Dmitry Shmidt18463232014-01-24 12:29:41 -08001270 if (prot)
1271 convert_to_protected_dual(buf);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001272 hostapd_drv_send_action(hapd, hapd->iface->freq, 0, sa,
1273 wpabuf_head(buf), wpabuf_len(buf));
1274 wpabuf_free(buf);
1275 return;
1276 }
1277
1278 pos = next;
1279 /* Query Request */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001280 if (end - pos < 2)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001281 return;
1282 slen = WPA_GET_LE16(pos);
1283 pos += 2;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001284 if (slen > end - pos)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001285 return;
1286 end = pos + slen;
1287
1288 /* ANQP Query Request */
1289 while (pos < end) {
1290 u16 info_id, elen;
1291
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001292 if (end - pos < 4)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001293 return;
1294
1295 info_id = WPA_GET_LE16(pos);
1296 pos += 2;
1297 elen = WPA_GET_LE16(pos);
1298 pos += 2;
1299
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001300 if (elen > end - pos) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001301 wpa_printf(MSG_DEBUG, "ANQP: Invalid Query Request");
1302 return;
1303 }
1304
1305 switch (info_id) {
1306 case ANQP_QUERY_LIST:
1307 rx_anqp_query_list(hapd, pos, pos + elen, &qi);
1308 break;
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001309#ifdef CONFIG_HS20
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001310 case ANQP_VENDOR_SPECIFIC:
1311 rx_anqp_vendor_specific(hapd, pos, pos + elen, &qi);
1312 break;
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001313#endif /* CONFIG_HS20 */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001314 default:
1315 wpa_printf(MSG_DEBUG, "ANQP: Unsupported Query "
1316 "Request element %u", info_id);
1317 break;
1318 }
1319
1320 pos += elen;
1321 }
1322
Dmitry Shmidt18463232014-01-24 12:29:41 -08001323 gas_serv_req_local_processing(hapd, sa, dialog_token, &qi, prot);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001324}
1325
1326
Dmitry Shmidt04949592012-07-19 12:16:46 -07001327static void gas_serv_rx_gas_comeback_req(struct hostapd_data *hapd,
1328 const u8 *sa,
Dmitry Shmidt18463232014-01-24 12:29:41 -08001329 const u8 *data, size_t len, int prot)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001330{
1331 struct gas_dialog_info *dialog;
1332 struct wpabuf *buf, *tx_buf;
1333 u8 dialog_token;
1334 size_t frag_len;
1335 int more = 0;
1336
1337 wpa_hexdump(MSG_DEBUG, "GAS: RX GAS Comeback Request", data, len);
1338 if (len < 1)
1339 return;
1340 dialog_token = *data;
1341 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: Dialog Token: %u",
1342 dialog_token);
1343
1344 dialog = gas_serv_dialog_find(hapd, sa, dialog_token);
1345 if (!dialog) {
1346 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: No pending SD "
1347 "response fragment for " MACSTR " dialog token %u",
1348 MAC2STR(sa), dialog_token);
1349
1350 if (sa[0] & 0x01)
1351 return; /* Invalid source address - drop silently */
1352 tx_buf = gas_anqp_build_comeback_resp_buf(
1353 dialog_token, WLAN_STATUS_NO_OUTSTANDING_GAS_REQ, 0, 0,
1354 0, NULL);
1355 if (tx_buf == NULL)
1356 return;
1357 goto send_resp;
1358 }
1359
Dmitry Shmidt04949592012-07-19 12:16:46 -07001360 frag_len = wpabuf_len(dialog->sd_resp) - dialog->sd_resp_pos;
1361 if (frag_len > hapd->gas_frag_limit) {
1362 frag_len = hapd->gas_frag_limit;
1363 more = 1;
1364 }
1365 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: resp frag_len %u",
1366 (unsigned int) frag_len);
1367 buf = wpabuf_alloc_copy(wpabuf_head_u8(dialog->sd_resp) +
1368 dialog->sd_resp_pos, frag_len);
1369 if (buf == NULL) {
1370 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: Failed to allocate "
1371 "buffer");
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001372 gas_serv_dialog_clear(dialog);
1373 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001374 }
1375 tx_buf = gas_anqp_build_comeback_resp_buf(dialog_token,
1376 WLAN_STATUS_SUCCESS,
1377 dialog->sd_frag_id,
1378 more, 0, buf);
1379 wpabuf_free(buf);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001380 if (tx_buf == NULL) {
1381 gas_serv_dialog_clear(dialog);
1382 return;
1383 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001384 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: Tx GAS Comeback Response "
1385 "(frag_id %d more=%d frag_len=%d)",
1386 dialog->sd_frag_id, more, (int) frag_len);
1387 dialog->sd_frag_id++;
1388 dialog->sd_resp_pos += frag_len;
1389
1390 if (more) {
1391 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: %d more bytes remain "
1392 "to be sent",
1393 (int) (wpabuf_len(dialog->sd_resp) -
1394 dialog->sd_resp_pos));
1395 } else {
1396 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: All fragments of "
1397 "SD response sent");
1398 gas_serv_dialog_clear(dialog);
1399 gas_serv_free_dialogs(hapd, sa);
1400 }
1401
1402send_resp:
Dmitry Shmidt18463232014-01-24 12:29:41 -08001403 if (prot)
1404 convert_to_protected_dual(tx_buf);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001405 hostapd_drv_send_action(hapd, hapd->iface->freq, 0, sa,
1406 wpabuf_head(tx_buf), wpabuf_len(tx_buf));
1407 wpabuf_free(tx_buf);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001408}
1409
1410
1411static void gas_serv_rx_public_action(void *ctx, const u8 *buf, size_t len,
1412 int freq)
1413{
1414 struct hostapd_data *hapd = ctx;
1415 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001416 const u8 *sa, *data;
Dmitry Shmidt18463232014-01-24 12:29:41 -08001417 int prot;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001418
1419 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07001420 if (len < IEEE80211_HDRLEN + 2)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001421 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -08001422 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
1423 mgmt->u.action.category != WLAN_ACTION_PROTECTED_DUAL)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001424 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -08001425 /*
1426 * Note: Public Action and Protected Dual of Public Action frames share
1427 * the same payload structure, so it is fine to use definitions of
1428 * Public Action frames to process both.
1429 */
1430 prot = mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001431 sa = mgmt->sa;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07001432 len -= IEEE80211_HDRLEN + 1;
1433 data = buf + IEEE80211_HDRLEN + 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001434 switch (data[0]) {
1435 case WLAN_PA_GAS_INITIAL_REQ:
Dmitry Shmidt18463232014-01-24 12:29:41 -08001436 gas_serv_rx_gas_initial_req(hapd, sa, data + 1, len - 1, prot);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001437 break;
1438 case WLAN_PA_GAS_COMEBACK_REQ:
Dmitry Shmidt18463232014-01-24 12:29:41 -08001439 gas_serv_rx_gas_comeback_req(hapd, sa, data + 1, len - 1, prot);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001440 break;
1441 }
1442}
1443
1444
1445int gas_serv_init(struct hostapd_data *hapd)
1446{
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001447 hapd->public_action_cb2 = gas_serv_rx_public_action;
1448 hapd->public_action_cb2_ctx = hapd;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001449 hapd->gas_frag_limit = 1400;
1450 if (hapd->conf->gas_frag_limit > 0)
1451 hapd->gas_frag_limit = hapd->conf->gas_frag_limit;
1452 return 0;
1453}
1454
1455
1456void gas_serv_deinit(struct hostapd_data *hapd)
1457{
1458}