2 * Generic advertisement service (GAS) server
3 * Copyright (c) 2011-2014, Qualcomm Atheros, Inc.
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "common/ieee802_11_defs.h"
13 #include "common/gas.h"
14 #include "utils/eloop.h"
16 #include "ap_config.h"
17 #include "ap_drv_ops.h"
22 static void convert_to_protected_dual(struct wpabuf *msg)
24 u8 *categ = wpabuf_mhead_u8(msg);
25 *categ = WLAN_ACTION_PROTECTED_DUAL;
29 static struct gas_dialog_info *
30 gas_dialog_create(struct hostapd_data *hapd, const u8 *addr, u8 dialog_token)
33 struct gas_dialog_info *dia = NULL;
36 sta = ap_get_sta(hapd, addr);
39 * We need a STA entry to be able to maintain state for
42 wpa_printf(MSG_DEBUG, "ANQP: Add a temporary STA entry for "
44 sta = ap_sta_add(hapd, addr);
46 wpa_printf(MSG_DEBUG, "Failed to add STA " MACSTR
47 " for GAS query", MAC2STR(addr));
50 sta->flags |= WLAN_STA_GAS;
52 * The default inactivity is 300 seconds. We don't need
55 ap_sta_session_timeout(hapd, sta, 5);
57 ap_sta_replenish_timeout(hapd, sta, 5);
60 if (sta->gas_dialog == NULL) {
61 sta->gas_dialog = os_calloc(GAS_DIALOG_MAX,
62 sizeof(struct gas_dialog_info));
63 if (sta->gas_dialog == NULL)
67 for (i = sta->gas_dialog_next, j = 0; j < GAS_DIALOG_MAX; i++, j++) {
68 if (i == GAS_DIALOG_MAX)
70 if (sta->gas_dialog[i].valid)
72 dia = &sta->gas_dialog[i];
74 dia->dialog_token = dialog_token;
75 sta->gas_dialog_next = (++i == GAS_DIALOG_MAX) ? 0 : i;
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);
87 struct gas_dialog_info *
88 gas_serv_dialog_find(struct hostapd_data *hapd, const u8 *addr,
94 sta = ap_get_sta(hapd, addr);
96 wpa_printf(MSG_DEBUG, "ANQP: could not find STA " MACSTR,
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)
104 ap_sta_replenish_timeout(hapd, sta, 5);
105 return &sta->gas_dialog[i];
107 wpa_printf(MSG_DEBUG, "ANQP: Could not find dialog for "
108 MACSTR " dialog_token %u", MAC2STR(addr), dialog_token);
113 void gas_serv_dialog_clear(struct gas_dialog_info *dia)
115 wpabuf_free(dia->sd_resp);
116 os_memset(dia, 0, sizeof(*dia));
120 static void gas_serv_free_dialogs(struct hostapd_data *hapd,
123 struct sta_info *sta;
126 sta = ap_get_sta(hapd, sta_addr);
127 if (sta == NULL || sta->gas_dialog == NULL)
130 for (i = 0; i < GAS_DIALOG_MAX; i++) {
131 if (sta->gas_dialog[i].valid)
135 os_free(sta->gas_dialog);
136 sta->gas_dialog = NULL;
141 static void anqp_add_hs_capab_list(struct hostapd_data *hapd,
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);
162 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);
166 gas_anqp_set_element_len(buf, len);
168 #endif /* CONFIG_HS20 */
171 static struct anqp_element * get_anqp_elem(struct hostapd_data *hapd,
174 struct anqp_element *elem;
176 dl_list_for_each(elem, &hapd->conf->anqp_elem, struct anqp_element,
178 if (elem->infoid == infoid)
186 static void anqp_add_elem(struct hostapd_data *hapd, struct wpabuf *buf,
189 struct anqp_element *elem;
191 elem = get_anqp_elem(hapd, infoid);
194 if (wpabuf_tailroom(buf) < 2 + 2 + wpabuf_len(elem->payload)) {
195 wpa_printf(MSG_DEBUG, "ANQP: No room for InfoID %u payload",
200 wpabuf_put_le16(buf, infoid);
201 wpabuf_put_le16(buf, wpabuf_len(elem->payload));
202 wpabuf_put_buf(buf, elem->payload);
206 static int anqp_add_override(struct hostapd_data *hapd, struct wpabuf *buf,
209 if (get_anqp_elem(hapd, infoid)) {
210 anqp_add_elem(hapd, buf, infoid);
218 static void anqp_add_capab_list(struct hostapd_data *hapd,
224 if (anqp_add_override(hapd, buf, ANQP_CAPABILITY_LIST))
227 len = gas_anqp_add_element(buf, ANQP_CAPABILITY_LIST);
228 wpabuf_put_le16(buf, ANQP_CAPABILITY_LIST);
229 if (hapd->conf->venue_name || get_anqp_elem(hapd, ANQP_VENUE_NAME))
230 wpabuf_put_le16(buf, ANQP_VENUE_NAME);
231 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))
235 wpabuf_put_le16(buf, ANQP_NETWORK_AUTH_TYPE);
236 if (hapd->conf->roaming_consortium ||
237 get_anqp_elem(hapd, ANQP_ROAMING_CONSORTIUM))
238 wpabuf_put_le16(buf, ANQP_ROAMING_CONSORTIUM);
239 if (hapd->conf->ipaddr_type_configured ||
240 get_anqp_elem(hapd, ANQP_IP_ADDR_TYPE_AVAILABILITY))
241 wpabuf_put_le16(buf, ANQP_IP_ADDR_TYPE_AVAILABILITY);
242 if (hapd->conf->nai_realm_data ||
243 get_anqp_elem(hapd, ANQP_NAI_REALM))
244 wpabuf_put_le16(buf, ANQP_NAI_REALM);
245 if (hapd->conf->anqp_3gpp_cell_net ||
246 get_anqp_elem(hapd, ANQP_3GPP_CELLULAR_NETWORK))
247 wpabuf_put_le16(buf, ANQP_3GPP_CELLULAR_NETWORK);
248 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))
255 wpabuf_put_le16(buf, ANQP_DOMAIN_NAME);
256 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);
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);
273 anqp_add_hs_capab_list(hapd, buf);
274 #endif /* CONFIG_HS20 */
275 gas_anqp_set_element_len(buf, len);
279 static void anqp_add_venue_name(struct hostapd_data *hapd, struct wpabuf *buf)
281 if (anqp_add_override(hapd, buf, ANQP_VENUE_NAME))
284 if (hapd->conf->venue_name) {
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++) {
291 struct hostapd_lang_string *vn;
292 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);
297 gas_anqp_set_element_len(buf, len);
302 static void anqp_add_network_auth_type(struct hostapd_data *hapd,
305 if (anqp_add_override(hapd, buf, ANQP_NETWORK_AUTH_TYPE))
308 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);
317 static void anqp_add_roaming_consortium(struct hostapd_data *hapd,
323 if (anqp_add_override(hapd, buf, ANQP_ROAMING_CONSORTIUM))
326 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);
333 gas_anqp_set_element_len(buf, len);
337 static void anqp_add_ip_addr_type_availability(struct hostapd_data *hapd,
340 if (anqp_add_override(hapd, buf, ANQP_IP_ADDR_TYPE_AVAILABILITY))
343 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);
351 static void anqp_add_nai_realm_eap(struct wpabuf *buf,
352 struct hostapd_nai_realm_data *realm)
356 wpabuf_put_u8(buf, realm->eap_method_count);
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]);
372 static void anqp_add_nai_realm_data(struct wpabuf *buf,
373 struct hostapd_nai_realm_data *realm,
374 unsigned int realm_idx)
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);
389 static int hs20_add_nai_home_realm_matches(struct hostapd_data *hapd,
391 const u8 *home_realm,
392 size_t home_realm_len)
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;
399 unsigned int realm_data_idx;
400 unsigned int realm_idx;
404 end = pos + home_realm_len;
406 wpa_hexdump(MSG_DEBUG, "Too short NAI Home Realm Query",
407 home_realm, home_realm_len);
412 for (i = 0; i < num_realms && num_matching < 10; i++) {
414 wpa_hexdump(MSG_DEBUG,
415 "Truncated NAI Home Realm Query",
416 home_realm, home_realm_len);
421 if (realm_len > end - pos) {
422 wpa_hexdump(MSG_DEBUG,
423 "Truncated NAI Home Realm Query",
424 home_realm, home_realm_len);
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)
436 while (rpos < realm_name + realm_len &&
439 rend < realm_name + realm_len; rend++) {
443 for (k = 0; k < MAX_NAI_REALMS &&
445 num_matching < 10; k++) {
446 if ((int) os_strlen(realm->realm[k]) !=
448 os_strncmp((char *) rpos,
452 matches[num_matching].realm_data_idx =
454 matches[num_matching].realm_idx = k;
463 realm_list_len = gas_anqp_add_element(buf, ANQP_NAI_REALM);
464 wpabuf_put_le16(buf, num_matching);
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.
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);
478 gas_anqp_set_element_len(buf, realm_list_len);
483 static 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)
487 if (nai_realm && !nai_home_realm &&
488 anqp_add_override(hapd, buf, ANQP_NAI_REALM))
491 if (nai_realm && hapd->conf->nai_realm_data) {
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;
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++) {
506 wpabuf_put_u8(buf, ';');
507 wpabuf_put_str(buf, realm->realm[j]);
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);
513 gas_anqp_set_element_len(buf, len);
514 } else if (nai_home_realm && hapd->conf->nai_realm_data && home_realm) {
515 hs20_add_nai_home_realm_matches(hapd, buf, home_realm,
521 static void anqp_add_3gpp_cellular_network(struct hostapd_data *hapd,
524 if (anqp_add_override(hapd, buf, ANQP_3GPP_CELLULAR_NETWORK))
527 if (hapd->conf->anqp_3gpp_cell_net) {
528 wpabuf_put_le16(buf, ANQP_3GPP_CELLULAR_NETWORK);
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);
537 static void anqp_add_domain_name(struct hostapd_data *hapd, struct wpabuf *buf)
539 if (anqp_add_override(hapd, buf, ANQP_DOMAIN_NAME))
542 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);
553 static void anqp_add_operator_friendly_name(struct hostapd_data *hapd,
556 if (hapd->conf->hs20_oper_friendly_name) {
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++)
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);
572 gas_anqp_set_element_len(buf, len);
577 static void anqp_add_wan_metrics(struct hostapd_data *hapd,
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);
592 static void anqp_add_connection_capability(struct hostapd_data *hapd,
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);
608 static void anqp_add_operating_class(struct hostapd_data *hapd,
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);
624 static void anqp_add_osu_provider(struct wpabuf *buf,
625 struct hostapd_bss_config *bss,
626 struct hs20_osu_provider *p)
628 u8 *len, *len2, *count;
631 len = wpabuf_put(buf, 2); /* OSU Provider Length to be filled */
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);
641 WPA_PUT_LE16(len2, (u8 *) wpabuf_put(buf, 0) - len2 - 2);
645 wpabuf_put_u8(buf, os_strlen(p->server_uri));
646 wpabuf_put_str(buf, p->server_uri);
648 wpabuf_put_u8(buf, 0);
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]);
656 /* Icons Available */
657 len2 = wpabuf_put(buf, 2);
658 for (i = 0; i < p->icons_count; i++) {
660 struct hs20_icon *icon = NULL;
662 for (j = 0; j < bss->hs20_icons_count && !icon; j++) {
663 if (os_strcmp(p->icons[i], bss->hs20_icons[j].name) ==
665 icon = &bss->hs20_icons[j];
668 continue; /* icon info not found */
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);
678 WPA_PUT_LE16(len2, (u8 *) wpabuf_put(buf, 0) - len2 - 2);
682 wpabuf_put_u8(buf, os_strlen(p->osu_nai));
683 wpabuf_put_str(buf, p->osu_nai);
685 wpabuf_put_u8(buf, 0);
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);
695 WPA_PUT_LE16(len2, (u8 *) wpabuf_put(buf, 0) - len2 - 2);
697 WPA_PUT_LE16(len, (u8 *) wpabuf_put(buf, 0) - len - 2);
701 static void anqp_add_osu_providers_list(struct hostapd_data *hapd,
704 if (hapd->conf->hs20_osu_providers_count) {
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 */
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);
717 /* Number of OSU Providers */
718 wpabuf_put_u8(buf, hapd->conf->hs20_osu_providers_count);
720 for (i = 0; i < hapd->conf->hs20_osu_providers_count; i++) {
721 anqp_add_osu_provider(
723 &hapd->conf->hs20_osu_providers[i]);
726 gas_anqp_set_element_len(buf, len);
731 static void anqp_add_icon_binary_file(struct hostapd_data *hapd,
733 const u8 *name, size_t name_len)
735 struct hs20_icon *icon;
739 wpa_hexdump_ascii(MSG_DEBUG, "HS 2.0: Requested Icon Filename",
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)
748 if (i < hapd->conf->hs20_icons_count)
749 icon = &hapd->conf->hs20_icons[i];
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 */
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);
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);
778 wpabuf_put_u8(buf, 1); /* Download Status: File not found */
779 wpabuf_put_u8(buf, 0);
780 wpabuf_put_le16(buf, 0);
783 gas_anqp_set_element_len(buf, len);
786 #endif /* CONFIG_HS20 */
789 static size_t anqp_get_required_len(struct hostapd_data *hapd,
791 unsigned int num_infoid)
796 for (i = 0; i < num_infoid; i++) {
797 struct anqp_element *elem = get_anqp_elem(hapd, infoid[i]);
800 len += 2 + 2 + wpabuf_len(elem->payload);
807 static struct wpabuf *
808 gas_serv_build_gas_resp_payload(struct hostapd_data *hapd,
809 unsigned int request,
810 const u8 *home_realm, size_t home_realm_len,
811 const u8 *icon_name, size_t icon_name_len,
812 const u16 *extra_req,
813 unsigned int num_extra_req)
820 if (request & (ANQP_REQ_NAI_REALM | ANQP_REQ_NAI_HOME_REALM))
822 if (request & ANQP_REQ_ICON_REQUEST)
824 len += anqp_get_required_len(hapd, extra_req, num_extra_req);
826 buf = wpabuf_alloc(len);
830 if (request & ANQP_REQ_CAPABILITY_LIST)
831 anqp_add_capab_list(hapd, buf);
832 if (request & ANQP_REQ_VENUE_NAME)
833 anqp_add_venue_name(hapd, buf);
834 if (request & ANQP_REQ_EMERGENCY_CALL_NUMBER)
835 anqp_add_elem(hapd, buf, ANQP_EMERGENCY_CALL_NUMBER);
836 if (request & ANQP_REQ_NETWORK_AUTH_TYPE)
837 anqp_add_network_auth_type(hapd, buf);
838 if (request & ANQP_REQ_ROAMING_CONSORTIUM)
839 anqp_add_roaming_consortium(hapd, buf);
840 if (request & ANQP_REQ_IP_ADDR_TYPE_AVAILABILITY)
841 anqp_add_ip_addr_type_availability(hapd, buf);
842 if (request & (ANQP_REQ_NAI_REALM | ANQP_REQ_NAI_HOME_REALM))
843 anqp_add_nai_realm(hapd, buf, home_realm, home_realm_len,
844 request & ANQP_REQ_NAI_REALM,
845 request & ANQP_REQ_NAI_HOME_REALM);
846 if (request & ANQP_REQ_3GPP_CELLULAR_NETWORK)
847 anqp_add_3gpp_cellular_network(hapd, buf);
848 if (request & ANQP_REQ_AP_GEOSPATIAL_LOCATION)
849 anqp_add_elem(hapd, buf, ANQP_AP_GEOSPATIAL_LOCATION);
850 if (request & ANQP_REQ_AP_CIVIC_LOCATION)
851 anqp_add_elem(hapd, buf, ANQP_AP_CIVIC_LOCATION);
852 if (request & ANQP_REQ_AP_LOCATION_PUBLIC_URI)
853 anqp_add_elem(hapd, buf, ANQP_AP_LOCATION_PUBLIC_URI);
854 if (request & ANQP_REQ_DOMAIN_NAME)
855 anqp_add_domain_name(hapd, buf);
856 if (request & ANQP_REQ_EMERGENCY_ALERT_URI)
857 anqp_add_elem(hapd, buf, ANQP_EMERGENCY_ALERT_URI);
858 if (request & ANQP_REQ_TDLS_CAPABILITY)
859 anqp_add_elem(hapd, buf, ANQP_TDLS_CAPABILITY);
860 if (request & ANQP_REQ_EMERGENCY_NAI)
861 anqp_add_elem(hapd, buf, ANQP_EMERGENCY_NAI);
863 for (i = 0; i < num_extra_req; i++)
864 anqp_add_elem(hapd, buf, extra_req[i]);
867 if (request & ANQP_REQ_HS_CAPABILITY_LIST)
868 anqp_add_hs_capab_list(hapd, buf);
869 if (request & ANQP_REQ_OPERATOR_FRIENDLY_NAME)
870 anqp_add_operator_friendly_name(hapd, buf);
871 if (request & ANQP_REQ_WAN_METRICS)
872 anqp_add_wan_metrics(hapd, buf);
873 if (request & ANQP_REQ_CONNECTION_CAPABILITY)
874 anqp_add_connection_capability(hapd, buf);
875 if (request & ANQP_REQ_OPERATING_CLASS)
876 anqp_add_operating_class(hapd, buf);
877 if (request & ANQP_REQ_OSU_PROVIDERS_LIST)
878 anqp_add_osu_providers_list(hapd, buf);
879 if (request & ANQP_REQ_ICON_REQUEST)
880 anqp_add_icon_binary_file(hapd, buf, icon_name, icon_name_len);
881 #endif /* CONFIG_HS20 */
887 #define ANQP_MAX_EXTRA_REQ 20
889 struct anqp_query_info {
890 unsigned int request;
891 const u8 *home_realm_query;
892 size_t home_realm_query_len;
894 size_t icon_name_len;
896 u16 extra_req[ANQP_MAX_EXTRA_REQ];
897 unsigned int num_extra_req;
901 static void set_anqp_req(unsigned int bit, const char *name, int local,
902 struct anqp_query_info *qi)
906 wpa_printf(MSG_DEBUG, "ANQP: %s (local)", name);
908 wpa_printf(MSG_DEBUG, "ANQP: %s not available", name);
913 static void rx_anqp_query_list_id(struct hostapd_data *hapd, u16 info_id,
914 struct anqp_query_info *qi)
917 case ANQP_CAPABILITY_LIST:
918 set_anqp_req(ANQP_REQ_CAPABILITY_LIST, "Capability List", 1,
921 case ANQP_VENUE_NAME:
922 set_anqp_req(ANQP_REQ_VENUE_NAME, "Venue Name",
923 hapd->conf->venue_name != NULL, qi);
925 case ANQP_EMERGENCY_CALL_NUMBER:
926 set_anqp_req(ANQP_REQ_EMERGENCY_CALL_NUMBER,
927 "Emergency Call Number",
928 get_anqp_elem(hapd, info_id) != NULL, qi);
930 case ANQP_NETWORK_AUTH_TYPE:
931 set_anqp_req(ANQP_REQ_NETWORK_AUTH_TYPE, "Network Auth Type",
932 hapd->conf->network_auth_type != NULL, qi);
934 case ANQP_ROAMING_CONSORTIUM:
935 set_anqp_req(ANQP_REQ_ROAMING_CONSORTIUM, "Roaming Consortium",
936 hapd->conf->roaming_consortium != NULL, qi);
938 case ANQP_IP_ADDR_TYPE_AVAILABILITY:
939 set_anqp_req(ANQP_REQ_IP_ADDR_TYPE_AVAILABILITY,
940 "IP Addr Type Availability",
941 hapd->conf->ipaddr_type_configured, qi);
944 set_anqp_req(ANQP_REQ_NAI_REALM, "NAI Realm",
945 hapd->conf->nai_realm_data != NULL, qi);
947 case ANQP_3GPP_CELLULAR_NETWORK:
948 set_anqp_req(ANQP_REQ_3GPP_CELLULAR_NETWORK,
949 "3GPP Cellular Network",
950 hapd->conf->anqp_3gpp_cell_net != NULL, qi);
952 case ANQP_AP_GEOSPATIAL_LOCATION:
953 set_anqp_req(ANQP_REQ_AP_GEOSPATIAL_LOCATION,
954 "AP Geospatial Location",
955 get_anqp_elem(hapd, info_id) != NULL, qi);
957 case ANQP_AP_CIVIC_LOCATION:
958 set_anqp_req(ANQP_REQ_AP_CIVIC_LOCATION,
960 get_anqp_elem(hapd, info_id) != NULL, qi);
962 case ANQP_AP_LOCATION_PUBLIC_URI:
963 set_anqp_req(ANQP_REQ_AP_LOCATION_PUBLIC_URI,
964 "AP Location Public URI",
965 get_anqp_elem(hapd, info_id) != NULL, qi);
967 case ANQP_DOMAIN_NAME:
968 set_anqp_req(ANQP_REQ_DOMAIN_NAME, "Domain Name",
969 hapd->conf->domain_name != NULL, qi);
971 case ANQP_EMERGENCY_ALERT_URI:
972 set_anqp_req(ANQP_REQ_EMERGENCY_ALERT_URI,
973 "Emergency Alert URI",
974 get_anqp_elem(hapd, info_id) != NULL, qi);
976 case ANQP_TDLS_CAPABILITY:
977 set_anqp_req(ANQP_REQ_TDLS_CAPABILITY,
979 get_anqp_elem(hapd, info_id) != NULL, qi);
981 case ANQP_EMERGENCY_NAI:
982 set_anqp_req(ANQP_REQ_EMERGENCY_NAI,
984 get_anqp_elem(hapd, info_id) != NULL, qi);
987 if (!get_anqp_elem(hapd, info_id)) {
988 wpa_printf(MSG_DEBUG, "ANQP: Unsupported Info Id %u",
992 if (qi->num_extra_req == ANQP_MAX_EXTRA_REQ) {
993 wpa_printf(MSG_DEBUG,
994 "ANQP: No more room for extra requests - ignore Info Id %u",
998 wpa_printf(MSG_DEBUG, "ANQP: Info Id %u (local)", info_id);
999 qi->extra_req[qi->num_extra_req] = info_id;
1000 qi->num_extra_req++;
1006 static void rx_anqp_query_list(struct hostapd_data *hapd,
1007 const u8 *pos, const u8 *end,
1008 struct anqp_query_info *qi)
1010 wpa_printf(MSG_DEBUG, "ANQP: %u Info IDs requested in Query list",
1011 (unsigned int) (end - pos) / 2);
1013 while (end - pos >= 2) {
1014 rx_anqp_query_list_id(hapd, WPA_GET_LE16(pos), qi);
1022 static void rx_anqp_hs_query_list(struct hostapd_data *hapd, u8 subtype,
1023 struct anqp_query_info *qi)
1026 case HS20_STYPE_CAPABILITY_LIST:
1027 set_anqp_req(ANQP_REQ_HS_CAPABILITY_LIST, "HS Capability List",
1030 case HS20_STYPE_OPERATOR_FRIENDLY_NAME:
1031 set_anqp_req(ANQP_REQ_OPERATOR_FRIENDLY_NAME,
1032 "Operator Friendly Name",
1033 hapd->conf->hs20_oper_friendly_name != NULL, qi);
1035 case HS20_STYPE_WAN_METRICS:
1036 set_anqp_req(ANQP_REQ_WAN_METRICS, "WAN Metrics",
1037 hapd->conf->hs20_wan_metrics != NULL, qi);
1039 case HS20_STYPE_CONNECTION_CAPABILITY:
1040 set_anqp_req(ANQP_REQ_CONNECTION_CAPABILITY,
1041 "Connection Capability",
1042 hapd->conf->hs20_connection_capability != NULL,
1045 case HS20_STYPE_OPERATING_CLASS:
1046 set_anqp_req(ANQP_REQ_OPERATING_CLASS, "Operating Class",
1047 hapd->conf->hs20_operating_class != NULL, qi);
1049 case HS20_STYPE_OSU_PROVIDERS_LIST:
1050 set_anqp_req(ANQP_REQ_OSU_PROVIDERS_LIST, "OSU Providers list",
1051 hapd->conf->hs20_osu_providers_count, qi);
1054 wpa_printf(MSG_DEBUG, "ANQP: Unsupported HS 2.0 subtype %u",
1061 static void rx_anqp_hs_nai_home_realm(struct hostapd_data *hapd,
1062 const u8 *pos, const u8 *end,
1063 struct anqp_query_info *qi)
1065 qi->request |= ANQP_REQ_NAI_HOME_REALM;
1066 qi->home_realm_query = pos;
1067 qi->home_realm_query_len = end - pos;
1068 if (hapd->conf->nai_realm_data != NULL) {
1069 wpa_printf(MSG_DEBUG, "ANQP: HS 2.0 NAI Home Realm Query "
1072 wpa_printf(MSG_DEBUG, "ANQP: HS 2.0 NAI Home Realm Query not "
1078 static void rx_anqp_hs_icon_request(struct hostapd_data *hapd,
1079 const u8 *pos, const u8 *end,
1080 struct anqp_query_info *qi)
1082 qi->request |= ANQP_REQ_ICON_REQUEST;
1083 qi->icon_name = pos;
1084 qi->icon_name_len = end - pos;
1085 if (hapd->conf->hs20_icons_count) {
1086 wpa_printf(MSG_DEBUG, "ANQP: HS 2.0 Icon Request Query "
1089 wpa_printf(MSG_DEBUG, "ANQP: HS 2.0 Icon Request Query not "
1095 static void rx_anqp_vendor_specific(struct hostapd_data *hapd,
1096 const u8 *pos, const u8 *end,
1097 struct anqp_query_info *qi)
1102 if (end - pos < 4) {
1103 wpa_printf(MSG_DEBUG, "ANQP: Too short vendor specific ANQP "
1108 oui = WPA_GET_BE24(pos);
1110 if (oui != OUI_WFA) {
1111 wpa_printf(MSG_DEBUG, "ANQP: Unsupported vendor OUI %06x",
1117 if (*pos == P2P_OUI_TYPE) {
1119 * This is for P2P SD and will be taken care of by the P2P
1120 * implementation. This query needs to be ignored in the generic
1121 * GAS server to avoid duplicated response.
1123 wpa_printf(MSG_DEBUG,
1124 "ANQP: Ignore WFA vendor type %u (P2P SD) in generic GAS server",
1129 #endif /* CONFIG_P2P */
1131 if (*pos != HS20_ANQP_OUI_TYPE) {
1132 wpa_printf(MSG_DEBUG, "ANQP: Unsupported WFA vendor type %u",
1142 pos++; /* Reserved */
1144 case HS20_STYPE_QUERY_LIST:
1145 wpa_printf(MSG_DEBUG, "ANQP: HS 2.0 Query List");
1147 rx_anqp_hs_query_list(hapd, *pos, qi);
1151 case HS20_STYPE_NAI_HOME_REALM_QUERY:
1152 rx_anqp_hs_nai_home_realm(hapd, pos, end, qi);
1154 case HS20_STYPE_ICON_REQUEST:
1155 rx_anqp_hs_icon_request(hapd, pos, end, qi);
1158 wpa_printf(MSG_DEBUG, "ANQP: Unsupported HS 2.0 query subtype "
1164 #endif /* CONFIG_HS20 */
1167 static void gas_serv_req_local_processing(struct hostapd_data *hapd,
1168 const u8 *sa, u8 dialog_token,
1169 struct anqp_query_info *qi, int prot,
1172 struct wpabuf *buf, *tx_buf;
1174 buf = gas_serv_build_gas_resp_payload(hapd, qi->request,
1175 qi->home_realm_query,
1176 qi->home_realm_query_len,
1177 qi->icon_name, qi->icon_name_len,
1178 qi->extra_req, qi->num_extra_req);
1179 wpa_hexdump_buf(MSG_MSGDUMP, "ANQP: Locally generated ANQP responses",
1184 if (wpabuf_len(buf) == 0 && qi->p2p_sd) {
1185 wpa_printf(MSG_DEBUG,
1186 "ANQP: Do not send response to P2P SD from generic GAS service (P2P SD implementation will process this)");
1190 #endif /* CONFIG_P2P */
1192 if (wpabuf_len(buf) > hapd->gas_frag_limit ||
1193 hapd->conf->gas_comeback_delay) {
1194 struct gas_dialog_info *di;
1195 u16 comeback_delay = 1;
1197 if (hapd->conf->gas_comeback_delay) {
1198 /* Testing - allow overriding of the delay value */
1199 comeback_delay = hapd->conf->gas_comeback_delay;
1202 wpa_printf(MSG_DEBUG, "ANQP: Too long response to fit in "
1203 "initial response - use GAS comeback");
1204 di = gas_dialog_create(hapd, sa, dialog_token);
1206 wpa_printf(MSG_INFO, "ANQP: Could not create dialog "
1207 "for " MACSTR " (dialog token %u)",
1208 MAC2STR(sa), dialog_token);
1210 tx_buf = gas_anqp_build_initial_resp_buf(
1211 dialog_token, WLAN_STATUS_UNSPECIFIED_FAILURE,
1216 di->sd_resp_pos = 0;
1217 tx_buf = gas_anqp_build_initial_resp_buf(
1218 dialog_token, WLAN_STATUS_SUCCESS,
1219 comeback_delay, NULL);
1222 wpa_printf(MSG_DEBUG, "ANQP: Initial response (no comeback)");
1223 tx_buf = gas_anqp_build_initial_resp_buf(
1224 dialog_token, WLAN_STATUS_SUCCESS, 0, buf);
1230 convert_to_protected_dual(tx_buf);
1232 hostapd_drv_send_action(hapd, hapd->iface->freq, 0, sa,
1233 wpabuf_head(tx_buf),
1234 wpabuf_len(tx_buf));
1236 hostapd_drv_send_action_addr3_ap(hapd, hapd->iface->freq, 0, sa,
1237 wpabuf_head(tx_buf),
1238 wpabuf_len(tx_buf));
1239 wpabuf_free(tx_buf);
1243 static void gas_serv_rx_gas_initial_req(struct hostapd_data *hapd,
1245 const u8 *data, size_t len, int prot,
1248 const u8 *pos = data;
1249 const u8 *end = data + len;
1253 struct anqp_query_info qi;
1254 const u8 *adv_proto;
1259 os_memset(&qi, 0, sizeof(qi));
1261 dialog_token = *pos++;
1262 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
1263 "GAS: GAS Initial Request from " MACSTR " (dialog token %u) ",
1264 MAC2STR(sa), dialog_token);
1266 if (*pos != WLAN_EID_ADV_PROTO) {
1267 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
1268 "GAS: Unexpected IE in GAS Initial Request: %u", *pos);
1274 if (slen > end - pos || slen < 2) {
1275 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
1276 "GAS: Invalid IE in GAS Initial Request");
1280 pos++; /* skip QueryRespLenLimit and PAME-BI */
1282 if (*pos != ACCESS_NETWORK_QUERY_PROTOCOL) {
1284 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
1285 "GAS: Unsupported GAS advertisement protocol id %u",
1288 return; /* Invalid source address - drop silently */
1289 buf = gas_build_initial_resp(
1290 dialog_token, WLAN_STATUS_GAS_ADV_PROTO_NOT_SUPPORTED,
1294 wpabuf_put_data(buf, adv_proto, 2 + slen);
1295 wpabuf_put_le16(buf, 0); /* Query Response Length */
1297 convert_to_protected_dual(buf);
1299 hostapd_drv_send_action(hapd, hapd->iface->freq, 0, sa,
1303 hostapd_drv_send_action_addr3_ap(hapd,
1304 hapd->iface->freq, 0,
1305 sa, wpabuf_head(buf),
1315 slen = WPA_GET_LE16(pos);
1317 if (slen > end - pos)
1321 /* ANQP Query Request */
1328 info_id = WPA_GET_LE16(pos);
1330 elen = WPA_GET_LE16(pos);
1333 if (elen > end - pos) {
1334 wpa_printf(MSG_DEBUG, "ANQP: Invalid Query Request");
1339 case ANQP_QUERY_LIST:
1340 rx_anqp_query_list(hapd, pos, pos + elen, &qi);
1343 case ANQP_VENDOR_SPECIFIC:
1344 rx_anqp_vendor_specific(hapd, pos, pos + elen, &qi);
1346 #endif /* CONFIG_HS20 */
1348 wpa_printf(MSG_DEBUG, "ANQP: Unsupported Query "
1349 "Request element %u", info_id);
1356 gas_serv_req_local_processing(hapd, sa, dialog_token, &qi, prot,
1361 static void gas_serv_rx_gas_comeback_req(struct hostapd_data *hapd,
1363 const u8 *data, size_t len, int prot,
1366 struct gas_dialog_info *dialog;
1367 struct wpabuf *buf, *tx_buf;
1372 wpa_hexdump(MSG_DEBUG, "GAS: RX GAS Comeback Request", data, len);
1375 dialog_token = *data;
1376 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: Dialog Token: %u",
1379 dialog = gas_serv_dialog_find(hapd, sa, dialog_token);
1381 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: No pending SD "
1382 "response fragment for " MACSTR " dialog token %u",
1383 MAC2STR(sa), dialog_token);
1386 return; /* Invalid source address - drop silently */
1387 tx_buf = gas_anqp_build_comeback_resp_buf(
1388 dialog_token, WLAN_STATUS_NO_OUTSTANDING_GAS_REQ, 0, 0,
1395 frag_len = wpabuf_len(dialog->sd_resp) - dialog->sd_resp_pos;
1396 if (frag_len > hapd->gas_frag_limit) {
1397 frag_len = hapd->gas_frag_limit;
1400 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: resp frag_len %u",
1401 (unsigned int) frag_len);
1402 buf = wpabuf_alloc_copy(wpabuf_head_u8(dialog->sd_resp) +
1403 dialog->sd_resp_pos, frag_len);
1405 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: Failed to allocate "
1407 gas_serv_dialog_clear(dialog);
1410 tx_buf = gas_anqp_build_comeback_resp_buf(dialog_token,
1411 WLAN_STATUS_SUCCESS,
1415 if (tx_buf == NULL) {
1416 gas_serv_dialog_clear(dialog);
1419 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: Tx GAS Comeback Response "
1420 "(frag_id %d more=%d frag_len=%d)",
1421 dialog->sd_frag_id, more, (int) frag_len);
1422 dialog->sd_frag_id++;
1423 dialog->sd_resp_pos += frag_len;
1426 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: %d more bytes remain "
1428 (int) (wpabuf_len(dialog->sd_resp) -
1429 dialog->sd_resp_pos));
1431 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: All fragments of "
1432 "SD response sent");
1433 gas_serv_dialog_clear(dialog);
1434 gas_serv_free_dialogs(hapd, sa);
1439 convert_to_protected_dual(tx_buf);
1441 hostapd_drv_send_action(hapd, hapd->iface->freq, 0, sa,
1442 wpabuf_head(tx_buf),
1443 wpabuf_len(tx_buf));
1445 hostapd_drv_send_action_addr3_ap(hapd, hapd->iface->freq, 0, sa,
1446 wpabuf_head(tx_buf),
1447 wpabuf_len(tx_buf));
1448 wpabuf_free(tx_buf);
1452 static void gas_serv_rx_public_action(void *ctx, const u8 *buf, size_t len,
1455 struct hostapd_data *hapd = ctx;
1456 const struct ieee80211_mgmt *mgmt;
1457 const u8 *sa, *data;
1458 int prot, std_addr3;
1460 mgmt = (const struct ieee80211_mgmt *) buf;
1461 if (len < IEEE80211_HDRLEN + 2)
1463 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
1464 mgmt->u.action.category != WLAN_ACTION_PROTECTED_DUAL)
1467 * Note: Public Action and Protected Dual of Public Action frames share
1468 * the same payload structure, so it is fine to use definitions of
1469 * Public Action frames to process both.
1471 prot = mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL;
1473 if (hapd->conf->gas_address3 == 1)
1475 else if (hapd->conf->gas_address3 == 2)
1478 std_addr3 = is_broadcast_ether_addr(mgmt->bssid);
1479 len -= IEEE80211_HDRLEN + 1;
1480 data = buf + IEEE80211_HDRLEN + 1;
1482 case WLAN_PA_GAS_INITIAL_REQ:
1483 gas_serv_rx_gas_initial_req(hapd, sa, data + 1, len - 1, prot,
1486 case WLAN_PA_GAS_COMEBACK_REQ:
1487 gas_serv_rx_gas_comeback_req(hapd, sa, data + 1, len - 1, prot,
1494 int gas_serv_init(struct hostapd_data *hapd)
1496 hapd->public_action_cb2 = gas_serv_rx_public_action;
1497 hapd->public_action_cb2_ctx = hapd;
1498 hapd->gas_frag_limit = 1400;
1499 if (hapd->conf->gas_frag_limit > 0)
1500 hapd->gas_frag_limit = hapd->conf->gas_frag_limit;
1505 void gas_serv_deinit(struct hostapd_data *hapd)