gas_serv.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655
  1. /*
  2. * Generic advertisement service (GAS) server
  3. * Copyright (c) 2011-2014, Qualcomm Atheros, Inc.
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "includes.h"
  9. #include "common.h"
  10. #include "common/ieee802_11_defs.h"
  11. #include "common/gas.h"
  12. #include "utils/eloop.h"
  13. #include "hostapd.h"
  14. #include "ap_config.h"
  15. #include "ap_drv_ops.h"
  16. #include "sta_info.h"
  17. #include "gas_serv.h"
  18. static void convert_to_protected_dual(struct wpabuf *msg)
  19. {
  20. u8 *categ = wpabuf_mhead_u8(msg);
  21. *categ = WLAN_ACTION_PROTECTED_DUAL;
  22. }
  23. static struct gas_dialog_info *
  24. gas_dialog_create(struct hostapd_data *hapd, const u8 *addr, u8 dialog_token)
  25. {
  26. struct sta_info *sta;
  27. struct gas_dialog_info *dia = NULL;
  28. int i, j;
  29. sta = ap_get_sta(hapd, addr);
  30. if (!sta) {
  31. /*
  32. * We need a STA entry to be able to maintain state for
  33. * the GAS query.
  34. */
  35. wpa_printf(MSG_DEBUG, "ANQP: Add a temporary STA entry for "
  36. "GAS query");
  37. sta = ap_sta_add(hapd, addr);
  38. if (!sta) {
  39. wpa_printf(MSG_DEBUG, "Failed to add STA " MACSTR
  40. " for GAS query", MAC2STR(addr));
  41. return NULL;
  42. }
  43. sta->flags |= WLAN_STA_GAS;
  44. /*
  45. * The default inactivity is 300 seconds. We don't need
  46. * it to be that long. Use five second timeout and increase this
  47. * with the comeback_delay for testing cases.
  48. */
  49. ap_sta_session_timeout(hapd, sta,
  50. hapd->conf->gas_comeback_delay / 1024 +
  51. 5);
  52. } else {
  53. ap_sta_replenish_timeout(hapd, sta, 5);
  54. }
  55. if (sta->gas_dialog == NULL) {
  56. sta->gas_dialog = os_calloc(GAS_DIALOG_MAX,
  57. sizeof(struct gas_dialog_info));
  58. if (sta->gas_dialog == NULL)
  59. return NULL;
  60. }
  61. for (i = sta->gas_dialog_next, j = 0; j < GAS_DIALOG_MAX; i++, j++) {
  62. if (i == GAS_DIALOG_MAX)
  63. i = 0;
  64. if (sta->gas_dialog[i].valid)
  65. continue;
  66. dia = &sta->gas_dialog[i];
  67. dia->valid = 1;
  68. dia->dialog_token = dialog_token;
  69. sta->gas_dialog_next = (++i == GAS_DIALOG_MAX) ? 0 : i;
  70. return dia;
  71. }
  72. wpa_msg(hapd->msg_ctx, MSG_ERROR, "ANQP: Could not create dialog for "
  73. MACSTR " dialog_token %u. Consider increasing "
  74. "GAS_DIALOG_MAX.", MAC2STR(addr), dialog_token);
  75. return NULL;
  76. }
  77. struct gas_dialog_info *
  78. gas_serv_dialog_find(struct hostapd_data *hapd, const u8 *addr,
  79. u8 dialog_token)
  80. {
  81. struct sta_info *sta;
  82. int i;
  83. sta = ap_get_sta(hapd, addr);
  84. if (!sta) {
  85. wpa_printf(MSG_DEBUG, "ANQP: could not find STA " MACSTR,
  86. MAC2STR(addr));
  87. return NULL;
  88. }
  89. for (i = 0; sta->gas_dialog && i < GAS_DIALOG_MAX; i++) {
  90. if (sta->gas_dialog[i].dialog_token != dialog_token ||
  91. !sta->gas_dialog[i].valid)
  92. continue;
  93. ap_sta_replenish_timeout(hapd, sta, 5);
  94. return &sta->gas_dialog[i];
  95. }
  96. wpa_printf(MSG_DEBUG, "ANQP: Could not find dialog for "
  97. MACSTR " dialog_token %u", MAC2STR(addr), dialog_token);
  98. return NULL;
  99. }
  100. void gas_serv_dialog_clear(struct gas_dialog_info *dia)
  101. {
  102. wpabuf_free(dia->sd_resp);
  103. os_memset(dia, 0, sizeof(*dia));
  104. }
  105. static void gas_serv_free_dialogs(struct hostapd_data *hapd,
  106. const u8 *sta_addr)
  107. {
  108. struct sta_info *sta;
  109. int i;
  110. sta = ap_get_sta(hapd, sta_addr);
  111. if (sta == NULL || sta->gas_dialog == NULL)
  112. return;
  113. for (i = 0; i < GAS_DIALOG_MAX; i++) {
  114. if (sta->gas_dialog[i].valid)
  115. return;
  116. }
  117. os_free(sta->gas_dialog);
  118. sta->gas_dialog = NULL;
  119. }
  120. #ifdef CONFIG_HS20
  121. static void anqp_add_hs_capab_list(struct hostapd_data *hapd,
  122. struct wpabuf *buf)
  123. {
  124. u8 *len;
  125. len = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
  126. wpabuf_put_be24(buf, OUI_WFA);
  127. wpabuf_put_u8(buf, HS20_ANQP_OUI_TYPE);
  128. wpabuf_put_u8(buf, HS20_STYPE_CAPABILITY_LIST);
  129. wpabuf_put_u8(buf, 0); /* Reserved */
  130. wpabuf_put_u8(buf, HS20_STYPE_CAPABILITY_LIST);
  131. if (hapd->conf->hs20_oper_friendly_name)
  132. wpabuf_put_u8(buf, HS20_STYPE_OPERATOR_FRIENDLY_NAME);
  133. if (hapd->conf->hs20_wan_metrics)
  134. wpabuf_put_u8(buf, HS20_STYPE_WAN_METRICS);
  135. if (hapd->conf->hs20_connection_capability)
  136. wpabuf_put_u8(buf, HS20_STYPE_CONNECTION_CAPABILITY);
  137. if (hapd->conf->nai_realm_data)
  138. wpabuf_put_u8(buf, HS20_STYPE_NAI_HOME_REALM_QUERY);
  139. if (hapd->conf->hs20_operating_class)
  140. wpabuf_put_u8(buf, HS20_STYPE_OPERATING_CLASS);
  141. if (hapd->conf->hs20_osu_providers_count)
  142. wpabuf_put_u8(buf, HS20_STYPE_OSU_PROVIDERS_LIST);
  143. if (hapd->conf->hs20_icons_count)
  144. wpabuf_put_u8(buf, HS20_STYPE_ICON_REQUEST);
  145. gas_anqp_set_element_len(buf, len);
  146. }
  147. #endif /* CONFIG_HS20 */
  148. static struct anqp_element * get_anqp_elem(struct hostapd_data *hapd,
  149. u16 infoid)
  150. {
  151. struct anqp_element *elem;
  152. dl_list_for_each(elem, &hapd->conf->anqp_elem, struct anqp_element,
  153. list) {
  154. if (elem->infoid == infoid)
  155. return elem;
  156. }
  157. return NULL;
  158. }
  159. static void anqp_add_elem(struct hostapd_data *hapd, struct wpabuf *buf,
  160. u16 infoid)
  161. {
  162. struct anqp_element *elem;
  163. elem = get_anqp_elem(hapd, infoid);
  164. if (!elem)
  165. return;
  166. if (wpabuf_tailroom(buf) < 2 + 2 + wpabuf_len(elem->payload)) {
  167. wpa_printf(MSG_DEBUG, "ANQP: No room for InfoID %u payload",
  168. infoid);
  169. return;
  170. }
  171. wpabuf_put_le16(buf, infoid);
  172. wpabuf_put_le16(buf, wpabuf_len(elem->payload));
  173. wpabuf_put_buf(buf, elem->payload);
  174. }
  175. static int anqp_add_override(struct hostapd_data *hapd, struct wpabuf *buf,
  176. u16 infoid)
  177. {
  178. if (get_anqp_elem(hapd, infoid)) {
  179. anqp_add_elem(hapd, buf, infoid);
  180. return 1;
  181. }
  182. return 0;
  183. }
  184. static void anqp_add_capab_list(struct hostapd_data *hapd,
  185. struct wpabuf *buf)
  186. {
  187. u8 *len;
  188. u16 id;
  189. if (anqp_add_override(hapd, buf, ANQP_CAPABILITY_LIST))
  190. return;
  191. len = gas_anqp_add_element(buf, ANQP_CAPABILITY_LIST);
  192. wpabuf_put_le16(buf, ANQP_CAPABILITY_LIST);
  193. if (hapd->conf->venue_name || get_anqp_elem(hapd, ANQP_VENUE_NAME))
  194. wpabuf_put_le16(buf, ANQP_VENUE_NAME);
  195. if (get_anqp_elem(hapd, ANQP_EMERGENCY_CALL_NUMBER))
  196. wpabuf_put_le16(buf, ANQP_EMERGENCY_CALL_NUMBER);
  197. if (hapd->conf->network_auth_type ||
  198. get_anqp_elem(hapd, ANQP_NETWORK_AUTH_TYPE))
  199. wpabuf_put_le16(buf, ANQP_NETWORK_AUTH_TYPE);
  200. if (hapd->conf->roaming_consortium ||
  201. get_anqp_elem(hapd, ANQP_ROAMING_CONSORTIUM))
  202. wpabuf_put_le16(buf, ANQP_ROAMING_CONSORTIUM);
  203. if (hapd->conf->ipaddr_type_configured ||
  204. get_anqp_elem(hapd, ANQP_IP_ADDR_TYPE_AVAILABILITY))
  205. wpabuf_put_le16(buf, ANQP_IP_ADDR_TYPE_AVAILABILITY);
  206. if (hapd->conf->nai_realm_data ||
  207. get_anqp_elem(hapd, ANQP_NAI_REALM))
  208. wpabuf_put_le16(buf, ANQP_NAI_REALM);
  209. if (hapd->conf->anqp_3gpp_cell_net ||
  210. get_anqp_elem(hapd, ANQP_3GPP_CELLULAR_NETWORK))
  211. wpabuf_put_le16(buf, ANQP_3GPP_CELLULAR_NETWORK);
  212. if (get_anqp_elem(hapd, ANQP_AP_GEOSPATIAL_LOCATION))
  213. wpabuf_put_le16(buf, ANQP_AP_GEOSPATIAL_LOCATION);
  214. if (get_anqp_elem(hapd, ANQP_AP_CIVIC_LOCATION))
  215. wpabuf_put_le16(buf, ANQP_AP_CIVIC_LOCATION);
  216. if (get_anqp_elem(hapd, ANQP_AP_LOCATION_PUBLIC_URI))
  217. wpabuf_put_le16(buf, ANQP_AP_LOCATION_PUBLIC_URI);
  218. if (hapd->conf->domain_name || get_anqp_elem(hapd, ANQP_DOMAIN_NAME))
  219. wpabuf_put_le16(buf, ANQP_DOMAIN_NAME);
  220. if (get_anqp_elem(hapd, ANQP_EMERGENCY_ALERT_URI))
  221. wpabuf_put_le16(buf, ANQP_EMERGENCY_ALERT_URI);
  222. if (get_anqp_elem(hapd, ANQP_TDLS_CAPABILITY))
  223. wpabuf_put_le16(buf, ANQP_TDLS_CAPABILITY);
  224. if (get_anqp_elem(hapd, ANQP_EMERGENCY_NAI))
  225. wpabuf_put_le16(buf, ANQP_EMERGENCY_NAI);
  226. if (get_anqp_elem(hapd, ANQP_NEIGHBOR_REPORT))
  227. wpabuf_put_le16(buf, ANQP_NEIGHBOR_REPORT);
  228. #ifdef CONFIG_FILS
  229. if (!dl_list_empty(&hapd->conf->fils_realms) ||
  230. get_anqp_elem(hapd, ANQP_FILS_REALM_INFO))
  231. wpabuf_put_le16(buf, ANQP_FILS_REALM_INFO);
  232. #endif /* CONFIG_FILS */
  233. if (get_anqp_elem(hapd, ANQP_CAG))
  234. wpabuf_put_le16(buf, ANQP_CAG);
  235. if (get_anqp_elem(hapd, ANQP_VENUE_URL))
  236. wpabuf_put_le16(buf, ANQP_VENUE_URL);
  237. if (get_anqp_elem(hapd, ANQP_ADVICE_OF_CHARGE))
  238. wpabuf_put_le16(buf, ANQP_ADVICE_OF_CHARGE);
  239. if (get_anqp_elem(hapd, ANQP_LOCAL_CONTENT))
  240. wpabuf_put_le16(buf, ANQP_LOCAL_CONTENT);
  241. for (id = 280; id < 300; id++) {
  242. if (get_anqp_elem(hapd, id))
  243. wpabuf_put_le16(buf, id);
  244. }
  245. #ifdef CONFIG_HS20
  246. anqp_add_hs_capab_list(hapd, buf);
  247. #endif /* CONFIG_HS20 */
  248. gas_anqp_set_element_len(buf, len);
  249. }
  250. static void anqp_add_venue_name(struct hostapd_data *hapd, struct wpabuf *buf)
  251. {
  252. if (anqp_add_override(hapd, buf, ANQP_VENUE_NAME))
  253. return;
  254. if (hapd->conf->venue_name) {
  255. u8 *len;
  256. unsigned int i;
  257. len = gas_anqp_add_element(buf, ANQP_VENUE_NAME);
  258. wpabuf_put_u8(buf, hapd->conf->venue_group);
  259. wpabuf_put_u8(buf, hapd->conf->venue_type);
  260. for (i = 0; i < hapd->conf->venue_name_count; i++) {
  261. struct hostapd_lang_string *vn;
  262. vn = &hapd->conf->venue_name[i];
  263. wpabuf_put_u8(buf, 3 + vn->name_len);
  264. wpabuf_put_data(buf, vn->lang, 3);
  265. wpabuf_put_data(buf, vn->name, vn->name_len);
  266. }
  267. gas_anqp_set_element_len(buf, len);
  268. }
  269. }
  270. static void anqp_add_network_auth_type(struct hostapd_data *hapd,
  271. struct wpabuf *buf)
  272. {
  273. if (anqp_add_override(hapd, buf, ANQP_NETWORK_AUTH_TYPE))
  274. return;
  275. if (hapd->conf->network_auth_type) {
  276. wpabuf_put_le16(buf, ANQP_NETWORK_AUTH_TYPE);
  277. wpabuf_put_le16(buf, hapd->conf->network_auth_type_len);
  278. wpabuf_put_data(buf, hapd->conf->network_auth_type,
  279. hapd->conf->network_auth_type_len);
  280. }
  281. }
  282. static void anqp_add_roaming_consortium(struct hostapd_data *hapd,
  283. struct wpabuf *buf)
  284. {
  285. unsigned int i;
  286. u8 *len;
  287. if (anqp_add_override(hapd, buf, ANQP_ROAMING_CONSORTIUM))
  288. return;
  289. len = gas_anqp_add_element(buf, ANQP_ROAMING_CONSORTIUM);
  290. for (i = 0; i < hapd->conf->roaming_consortium_count; i++) {
  291. struct hostapd_roaming_consortium *rc;
  292. rc = &hapd->conf->roaming_consortium[i];
  293. wpabuf_put_u8(buf, rc->len);
  294. wpabuf_put_data(buf, rc->oi, rc->len);
  295. }
  296. gas_anqp_set_element_len(buf, len);
  297. }
  298. static void anqp_add_ip_addr_type_availability(struct hostapd_data *hapd,
  299. struct wpabuf *buf)
  300. {
  301. if (anqp_add_override(hapd, buf, ANQP_IP_ADDR_TYPE_AVAILABILITY))
  302. return;
  303. if (hapd->conf->ipaddr_type_configured) {
  304. wpabuf_put_le16(buf, ANQP_IP_ADDR_TYPE_AVAILABILITY);
  305. wpabuf_put_le16(buf, 1);
  306. wpabuf_put_u8(buf, hapd->conf->ipaddr_type_availability);
  307. }
  308. }
  309. static void anqp_add_nai_realm_eap(struct wpabuf *buf,
  310. struct hostapd_nai_realm_data *realm)
  311. {
  312. unsigned int i, j;
  313. wpabuf_put_u8(buf, realm->eap_method_count);
  314. for (i = 0; i < realm->eap_method_count; i++) {
  315. struct hostapd_nai_realm_eap *eap = &realm->eap_method[i];
  316. wpabuf_put_u8(buf, 2 + (3 * eap->num_auths));
  317. wpabuf_put_u8(buf, eap->eap_method);
  318. wpabuf_put_u8(buf, eap->num_auths);
  319. for (j = 0; j < eap->num_auths; j++) {
  320. wpabuf_put_u8(buf, eap->auth_id[j]);
  321. wpabuf_put_u8(buf, 1);
  322. wpabuf_put_u8(buf, eap->auth_val[j]);
  323. }
  324. }
  325. }
  326. static void anqp_add_nai_realm_data(struct wpabuf *buf,
  327. struct hostapd_nai_realm_data *realm,
  328. unsigned int realm_idx)
  329. {
  330. u8 *realm_data_len;
  331. wpa_printf(MSG_DEBUG, "realm=%s, len=%d", realm->realm[realm_idx],
  332. (int) os_strlen(realm->realm[realm_idx]));
  333. realm_data_len = wpabuf_put(buf, 2);
  334. wpabuf_put_u8(buf, realm->encoding);
  335. wpabuf_put_u8(buf, os_strlen(realm->realm[realm_idx]));
  336. wpabuf_put_str(buf, realm->realm[realm_idx]);
  337. anqp_add_nai_realm_eap(buf, realm);
  338. gas_anqp_set_element_len(buf, realm_data_len);
  339. }
  340. static int hs20_add_nai_home_realm_matches(struct hostapd_data *hapd,
  341. struct wpabuf *buf,
  342. const u8 *home_realm,
  343. size_t home_realm_len)
  344. {
  345. unsigned int i, j, k;
  346. u8 num_realms, num_matching = 0, encoding, realm_len, *realm_list_len;
  347. struct hostapd_nai_realm_data *realm;
  348. const u8 *pos, *realm_name, *end;
  349. struct {
  350. unsigned int realm_data_idx;
  351. unsigned int realm_idx;
  352. } matches[10];
  353. pos = home_realm;
  354. end = pos + home_realm_len;
  355. if (end - pos < 1) {
  356. wpa_hexdump(MSG_DEBUG, "Too short NAI Home Realm Query",
  357. home_realm, home_realm_len);
  358. return -1;
  359. }
  360. num_realms = *pos++;
  361. for (i = 0; i < num_realms && num_matching < 10; i++) {
  362. if (end - pos < 2) {
  363. wpa_hexdump(MSG_DEBUG,
  364. "Truncated NAI Home Realm Query",
  365. home_realm, home_realm_len);
  366. return -1;
  367. }
  368. encoding = *pos++;
  369. realm_len = *pos++;
  370. if (realm_len > end - pos) {
  371. wpa_hexdump(MSG_DEBUG,
  372. "Truncated NAI Home Realm Query",
  373. home_realm, home_realm_len);
  374. return -1;
  375. }
  376. realm_name = pos;
  377. for (j = 0; j < hapd->conf->nai_realm_count &&
  378. num_matching < 10; j++) {
  379. const u8 *rpos, *rend;
  380. realm = &hapd->conf->nai_realm_data[j];
  381. if (encoding != realm->encoding)
  382. continue;
  383. rpos = realm_name;
  384. while (rpos < realm_name + realm_len &&
  385. num_matching < 10) {
  386. for (rend = rpos;
  387. rend < realm_name + realm_len; rend++) {
  388. if (*rend == ';')
  389. break;
  390. }
  391. for (k = 0; k < MAX_NAI_REALMS &&
  392. realm->realm[k] &&
  393. num_matching < 10; k++) {
  394. if ((int) os_strlen(realm->realm[k]) !=
  395. rend - rpos ||
  396. os_strncmp((char *) rpos,
  397. realm->realm[k],
  398. rend - rpos) != 0)
  399. continue;
  400. matches[num_matching].realm_data_idx =
  401. j;
  402. matches[num_matching].realm_idx = k;
  403. num_matching++;
  404. }
  405. rpos = rend + 1;
  406. }
  407. }
  408. pos += realm_len;
  409. }
  410. realm_list_len = gas_anqp_add_element(buf, ANQP_NAI_REALM);
  411. wpabuf_put_le16(buf, num_matching);
  412. /*
  413. * There are two ways to format. 1. each realm in a NAI Realm Data unit
  414. * 2. all realms that share the same EAP methods in a NAI Realm Data
  415. * unit. The first format is likely to be bigger in size than the
  416. * second, but may be easier to parse and process by the receiver.
  417. */
  418. for (i = 0; i < num_matching; i++) {
  419. wpa_printf(MSG_DEBUG, "realm_idx %d, realm_data_idx %d",
  420. matches[i].realm_data_idx, matches[i].realm_idx);
  421. realm = &hapd->conf->nai_realm_data[matches[i].realm_data_idx];
  422. anqp_add_nai_realm_data(buf, realm, matches[i].realm_idx);
  423. }
  424. gas_anqp_set_element_len(buf, realm_list_len);
  425. return 0;
  426. }
  427. static void anqp_add_nai_realm(struct hostapd_data *hapd, struct wpabuf *buf,
  428. const u8 *home_realm, size_t home_realm_len,
  429. int nai_realm, int nai_home_realm)
  430. {
  431. if (nai_realm && !nai_home_realm &&
  432. anqp_add_override(hapd, buf, ANQP_NAI_REALM))
  433. return;
  434. if (nai_realm && hapd->conf->nai_realm_data) {
  435. u8 *len;
  436. unsigned int i, j;
  437. len = gas_anqp_add_element(buf, ANQP_NAI_REALM);
  438. wpabuf_put_le16(buf, hapd->conf->nai_realm_count);
  439. for (i = 0; i < hapd->conf->nai_realm_count; i++) {
  440. u8 *realm_data_len, *realm_len;
  441. struct hostapd_nai_realm_data *realm;
  442. realm = &hapd->conf->nai_realm_data[i];
  443. realm_data_len = wpabuf_put(buf, 2);
  444. wpabuf_put_u8(buf, realm->encoding);
  445. realm_len = wpabuf_put(buf, 1);
  446. for (j = 0; realm->realm[j]; j++) {
  447. if (j > 0)
  448. wpabuf_put_u8(buf, ';');
  449. wpabuf_put_str(buf, realm->realm[j]);
  450. }
  451. *realm_len = (u8 *) wpabuf_put(buf, 0) - realm_len - 1;
  452. anqp_add_nai_realm_eap(buf, realm);
  453. gas_anqp_set_element_len(buf, realm_data_len);
  454. }
  455. gas_anqp_set_element_len(buf, len);
  456. } else if (nai_home_realm && hapd->conf->nai_realm_data && home_realm) {
  457. hs20_add_nai_home_realm_matches(hapd, buf, home_realm,
  458. home_realm_len);
  459. }
  460. }
  461. static void anqp_add_3gpp_cellular_network(struct hostapd_data *hapd,
  462. struct wpabuf *buf)
  463. {
  464. if (anqp_add_override(hapd, buf, ANQP_3GPP_CELLULAR_NETWORK))
  465. return;
  466. if (hapd->conf->anqp_3gpp_cell_net) {
  467. wpabuf_put_le16(buf, ANQP_3GPP_CELLULAR_NETWORK);
  468. wpabuf_put_le16(buf,
  469. hapd->conf->anqp_3gpp_cell_net_len);
  470. wpabuf_put_data(buf, hapd->conf->anqp_3gpp_cell_net,
  471. hapd->conf->anqp_3gpp_cell_net_len);
  472. }
  473. }
  474. static void anqp_add_domain_name(struct hostapd_data *hapd, struct wpabuf *buf)
  475. {
  476. if (anqp_add_override(hapd, buf, ANQP_DOMAIN_NAME))
  477. return;
  478. if (hapd->conf->domain_name) {
  479. wpabuf_put_le16(buf, ANQP_DOMAIN_NAME);
  480. wpabuf_put_le16(buf, hapd->conf->domain_name_len);
  481. wpabuf_put_data(buf, hapd->conf->domain_name,
  482. hapd->conf->domain_name_len);
  483. }
  484. }
  485. #ifdef CONFIG_FILS
  486. static void anqp_add_fils_realm_info(struct hostapd_data *hapd,
  487. struct wpabuf *buf)
  488. {
  489. size_t count;
  490. if (anqp_add_override(hapd, buf, ANQP_FILS_REALM_INFO))
  491. return;
  492. count = dl_list_len(&hapd->conf->fils_realms);
  493. if (count > 10000)
  494. count = 10000;
  495. if (count) {
  496. struct fils_realm *realm;
  497. wpabuf_put_le16(buf, ANQP_FILS_REALM_INFO);
  498. wpabuf_put_le16(buf, 2 * count);
  499. dl_list_for_each(realm, &hapd->conf->fils_realms,
  500. struct fils_realm, list) {
  501. if (count == 0)
  502. break;
  503. wpabuf_put_data(buf, realm->hash, 2);
  504. count--;
  505. }
  506. }
  507. }
  508. #endif /* CONFIG_FILS */
  509. #ifdef CONFIG_HS20
  510. static void anqp_add_operator_friendly_name(struct hostapd_data *hapd,
  511. struct wpabuf *buf)
  512. {
  513. if (hapd->conf->hs20_oper_friendly_name) {
  514. u8 *len;
  515. unsigned int i;
  516. len = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
  517. wpabuf_put_be24(buf, OUI_WFA);
  518. wpabuf_put_u8(buf, HS20_ANQP_OUI_TYPE);
  519. wpabuf_put_u8(buf, HS20_STYPE_OPERATOR_FRIENDLY_NAME);
  520. wpabuf_put_u8(buf, 0); /* Reserved */
  521. for (i = 0; i < hapd->conf->hs20_oper_friendly_name_count; i++)
  522. {
  523. struct hostapd_lang_string *vn;
  524. vn = &hapd->conf->hs20_oper_friendly_name[i];
  525. wpabuf_put_u8(buf, 3 + vn->name_len);
  526. wpabuf_put_data(buf, vn->lang, 3);
  527. wpabuf_put_data(buf, vn->name, vn->name_len);
  528. }
  529. gas_anqp_set_element_len(buf, len);
  530. }
  531. }
  532. static void anqp_add_wan_metrics(struct hostapd_data *hapd,
  533. struct wpabuf *buf)
  534. {
  535. if (hapd->conf->hs20_wan_metrics) {
  536. u8 *len = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
  537. wpabuf_put_be24(buf, OUI_WFA);
  538. wpabuf_put_u8(buf, HS20_ANQP_OUI_TYPE);
  539. wpabuf_put_u8(buf, HS20_STYPE_WAN_METRICS);
  540. wpabuf_put_u8(buf, 0); /* Reserved */
  541. wpabuf_put_data(buf, hapd->conf->hs20_wan_metrics, 13);
  542. gas_anqp_set_element_len(buf, len);
  543. }
  544. }
  545. static void anqp_add_connection_capability(struct hostapd_data *hapd,
  546. struct wpabuf *buf)
  547. {
  548. if (hapd->conf->hs20_connection_capability) {
  549. u8 *len = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
  550. wpabuf_put_be24(buf, OUI_WFA);
  551. wpabuf_put_u8(buf, HS20_ANQP_OUI_TYPE);
  552. wpabuf_put_u8(buf, HS20_STYPE_CONNECTION_CAPABILITY);
  553. wpabuf_put_u8(buf, 0); /* Reserved */
  554. wpabuf_put_data(buf, hapd->conf->hs20_connection_capability,
  555. hapd->conf->hs20_connection_capability_len);
  556. gas_anqp_set_element_len(buf, len);
  557. }
  558. }
  559. static void anqp_add_operating_class(struct hostapd_data *hapd,
  560. struct wpabuf *buf)
  561. {
  562. if (hapd->conf->hs20_operating_class) {
  563. u8 *len = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
  564. wpabuf_put_be24(buf, OUI_WFA);
  565. wpabuf_put_u8(buf, HS20_ANQP_OUI_TYPE);
  566. wpabuf_put_u8(buf, HS20_STYPE_OPERATING_CLASS);
  567. wpabuf_put_u8(buf, 0); /* Reserved */
  568. wpabuf_put_data(buf, hapd->conf->hs20_operating_class,
  569. hapd->conf->hs20_operating_class_len);
  570. gas_anqp_set_element_len(buf, len);
  571. }
  572. }
  573. static void anqp_add_osu_provider(struct wpabuf *buf,
  574. struct hostapd_bss_config *bss,
  575. struct hs20_osu_provider *p)
  576. {
  577. u8 *len, *len2, *count;
  578. unsigned int i;
  579. len = wpabuf_put(buf, 2); /* OSU Provider Length to be filled */
  580. /* OSU Friendly Name Duples */
  581. len2 = wpabuf_put(buf, 2);
  582. for (i = 0; i < p->friendly_name_count; i++) {
  583. struct hostapd_lang_string *s = &p->friendly_name[i];
  584. wpabuf_put_u8(buf, 3 + s->name_len);
  585. wpabuf_put_data(buf, s->lang, 3);
  586. wpabuf_put_data(buf, s->name, s->name_len);
  587. }
  588. WPA_PUT_LE16(len2, (u8 *) wpabuf_put(buf, 0) - len2 - 2);
  589. /* OSU Server URI */
  590. if (p->server_uri) {
  591. wpabuf_put_u8(buf, os_strlen(p->server_uri));
  592. wpabuf_put_str(buf, p->server_uri);
  593. } else
  594. wpabuf_put_u8(buf, 0);
  595. /* OSU Method List */
  596. count = wpabuf_put(buf, 1);
  597. for (i = 0; p->method_list && p->method_list[i] >= 0; i++)
  598. wpabuf_put_u8(buf, p->method_list[i]);
  599. *count = i;
  600. /* Icons Available */
  601. len2 = wpabuf_put(buf, 2);
  602. for (i = 0; i < p->icons_count; i++) {
  603. size_t j;
  604. struct hs20_icon *icon = NULL;
  605. for (j = 0; j < bss->hs20_icons_count && !icon; j++) {
  606. if (os_strcmp(p->icons[i], bss->hs20_icons[j].name) ==
  607. 0)
  608. icon = &bss->hs20_icons[j];
  609. }
  610. if (!icon)
  611. continue; /* icon info not found */
  612. wpabuf_put_le16(buf, icon->width);
  613. wpabuf_put_le16(buf, icon->height);
  614. wpabuf_put_data(buf, icon->language, 3);
  615. wpabuf_put_u8(buf, os_strlen(icon->type));
  616. wpabuf_put_str(buf, icon->type);
  617. wpabuf_put_u8(buf, os_strlen(icon->name));
  618. wpabuf_put_str(buf, icon->name);
  619. }
  620. WPA_PUT_LE16(len2, (u8 *) wpabuf_put(buf, 0) - len2 - 2);
  621. /* OSU_NAI */
  622. if (p->osu_nai) {
  623. wpabuf_put_u8(buf, os_strlen(p->osu_nai));
  624. wpabuf_put_str(buf, p->osu_nai);
  625. } else
  626. wpabuf_put_u8(buf, 0);
  627. /* OSU Service Description Duples */
  628. len2 = wpabuf_put(buf, 2);
  629. for (i = 0; i < p->service_desc_count; i++) {
  630. struct hostapd_lang_string *s = &p->service_desc[i];
  631. wpabuf_put_u8(buf, 3 + s->name_len);
  632. wpabuf_put_data(buf, s->lang, 3);
  633. wpabuf_put_data(buf, s->name, s->name_len);
  634. }
  635. WPA_PUT_LE16(len2, (u8 *) wpabuf_put(buf, 0) - len2 - 2);
  636. WPA_PUT_LE16(len, (u8 *) wpabuf_put(buf, 0) - len - 2);
  637. }
  638. static void anqp_add_osu_providers_list(struct hostapd_data *hapd,
  639. struct wpabuf *buf)
  640. {
  641. if (hapd->conf->hs20_osu_providers_count) {
  642. size_t i;
  643. u8 *len = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
  644. wpabuf_put_be24(buf, OUI_WFA);
  645. wpabuf_put_u8(buf, HS20_ANQP_OUI_TYPE);
  646. wpabuf_put_u8(buf, HS20_STYPE_OSU_PROVIDERS_LIST);
  647. wpabuf_put_u8(buf, 0); /* Reserved */
  648. /* OSU SSID */
  649. wpabuf_put_u8(buf, hapd->conf->osu_ssid_len);
  650. wpabuf_put_data(buf, hapd->conf->osu_ssid,
  651. hapd->conf->osu_ssid_len);
  652. /* Number of OSU Providers */
  653. wpabuf_put_u8(buf, hapd->conf->hs20_osu_providers_count);
  654. for (i = 0; i < hapd->conf->hs20_osu_providers_count; i++) {
  655. anqp_add_osu_provider(
  656. buf, hapd->conf,
  657. &hapd->conf->hs20_osu_providers[i]);
  658. }
  659. gas_anqp_set_element_len(buf, len);
  660. }
  661. }
  662. static void anqp_add_icon_binary_file(struct hostapd_data *hapd,
  663. struct wpabuf *buf,
  664. const u8 *name, size_t name_len)
  665. {
  666. struct hs20_icon *icon;
  667. size_t i;
  668. u8 *len;
  669. wpa_hexdump_ascii(MSG_DEBUG, "HS 2.0: Requested Icon Filename",
  670. name, name_len);
  671. for (i = 0; i < hapd->conf->hs20_icons_count; i++) {
  672. icon = &hapd->conf->hs20_icons[i];
  673. if (name_len == os_strlen(icon->name) &&
  674. os_memcmp(name, icon->name, name_len) == 0)
  675. break;
  676. }
  677. if (i < hapd->conf->hs20_icons_count)
  678. icon = &hapd->conf->hs20_icons[i];
  679. else
  680. icon = NULL;
  681. len = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
  682. wpabuf_put_be24(buf, OUI_WFA);
  683. wpabuf_put_u8(buf, HS20_ANQP_OUI_TYPE);
  684. wpabuf_put_u8(buf, HS20_STYPE_ICON_BINARY_FILE);
  685. wpabuf_put_u8(buf, 0); /* Reserved */
  686. if (icon) {
  687. char *data;
  688. size_t data_len;
  689. data = os_readfile(icon->file, &data_len);
  690. if (data == NULL || data_len > 65535) {
  691. wpabuf_put_u8(buf, 2); /* Download Status:
  692. * Unspecified file error */
  693. wpabuf_put_u8(buf, 0);
  694. wpabuf_put_le16(buf, 0);
  695. } else {
  696. wpabuf_put_u8(buf, 0); /* Download Status: Success */
  697. wpabuf_put_u8(buf, os_strlen(icon->type));
  698. wpabuf_put_str(buf, icon->type);
  699. wpabuf_put_le16(buf, data_len);
  700. wpabuf_put_data(buf, data, data_len);
  701. }
  702. os_free(data);
  703. } else {
  704. wpabuf_put_u8(buf, 1); /* Download Status: File not found */
  705. wpabuf_put_u8(buf, 0);
  706. wpabuf_put_le16(buf, 0);
  707. }
  708. gas_anqp_set_element_len(buf, len);
  709. }
  710. #endif /* CONFIG_HS20 */
  711. #ifdef CONFIG_MBO
  712. static void anqp_add_mbo_cell_data_conn_pref(struct hostapd_data *hapd,
  713. struct wpabuf *buf)
  714. {
  715. if (hapd->conf->mbo_cell_data_conn_pref >= 0) {
  716. u8 *len = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
  717. wpabuf_put_be24(buf, OUI_WFA);
  718. wpabuf_put_u8(buf, MBO_ANQP_OUI_TYPE);
  719. wpabuf_put_u8(buf, MBO_ANQP_SUBTYPE_CELL_CONN_PREF);
  720. wpabuf_put_u8(buf, hapd->conf->mbo_cell_data_conn_pref);
  721. gas_anqp_set_element_len(buf, len);
  722. }
  723. }
  724. #endif /* CONFIG_MBO */
  725. static size_t anqp_get_required_len(struct hostapd_data *hapd,
  726. const u16 *infoid,
  727. unsigned int num_infoid)
  728. {
  729. size_t len = 0;
  730. unsigned int i;
  731. for (i = 0; i < num_infoid; i++) {
  732. struct anqp_element *elem = get_anqp_elem(hapd, infoid[i]);
  733. if (elem)
  734. len += 2 + 2 + wpabuf_len(elem->payload);
  735. }
  736. return len;
  737. }
  738. static struct wpabuf *
  739. gas_serv_build_gas_resp_payload(struct hostapd_data *hapd,
  740. unsigned int request,
  741. const u8 *home_realm, size_t home_realm_len,
  742. const u8 *icon_name, size_t icon_name_len,
  743. const u16 *extra_req,
  744. unsigned int num_extra_req)
  745. {
  746. struct wpabuf *buf;
  747. size_t len;
  748. unsigned int i;
  749. len = 1400;
  750. if (request & (ANQP_REQ_NAI_REALM | ANQP_REQ_NAI_HOME_REALM))
  751. len += 1000;
  752. if (request & ANQP_REQ_ICON_REQUEST)
  753. len += 65536;
  754. #ifdef CONFIG_FILS
  755. if (request & ANQP_FILS_REALM_INFO)
  756. len += 2 * dl_list_len(&hapd->conf->fils_realms);
  757. #endif /* CONFIG_FILS */
  758. len += anqp_get_required_len(hapd, extra_req, num_extra_req);
  759. buf = wpabuf_alloc(len);
  760. if (buf == NULL)
  761. return NULL;
  762. if (request & ANQP_REQ_CAPABILITY_LIST)
  763. anqp_add_capab_list(hapd, buf);
  764. if (request & ANQP_REQ_VENUE_NAME)
  765. anqp_add_venue_name(hapd, buf);
  766. if (request & ANQP_REQ_EMERGENCY_CALL_NUMBER)
  767. anqp_add_elem(hapd, buf, ANQP_EMERGENCY_CALL_NUMBER);
  768. if (request & ANQP_REQ_NETWORK_AUTH_TYPE)
  769. anqp_add_network_auth_type(hapd, buf);
  770. if (request & ANQP_REQ_ROAMING_CONSORTIUM)
  771. anqp_add_roaming_consortium(hapd, buf);
  772. if (request & ANQP_REQ_IP_ADDR_TYPE_AVAILABILITY)
  773. anqp_add_ip_addr_type_availability(hapd, buf);
  774. if (request & (ANQP_REQ_NAI_REALM | ANQP_REQ_NAI_HOME_REALM))
  775. anqp_add_nai_realm(hapd, buf, home_realm, home_realm_len,
  776. request & ANQP_REQ_NAI_REALM,
  777. request & ANQP_REQ_NAI_HOME_REALM);
  778. if (request & ANQP_REQ_3GPP_CELLULAR_NETWORK)
  779. anqp_add_3gpp_cellular_network(hapd, buf);
  780. if (request & ANQP_REQ_AP_GEOSPATIAL_LOCATION)
  781. anqp_add_elem(hapd, buf, ANQP_AP_GEOSPATIAL_LOCATION);
  782. if (request & ANQP_REQ_AP_CIVIC_LOCATION)
  783. anqp_add_elem(hapd, buf, ANQP_AP_CIVIC_LOCATION);
  784. if (request & ANQP_REQ_AP_LOCATION_PUBLIC_URI)
  785. anqp_add_elem(hapd, buf, ANQP_AP_LOCATION_PUBLIC_URI);
  786. if (request & ANQP_REQ_DOMAIN_NAME)
  787. anqp_add_domain_name(hapd, buf);
  788. if (request & ANQP_REQ_EMERGENCY_ALERT_URI)
  789. anqp_add_elem(hapd, buf, ANQP_EMERGENCY_ALERT_URI);
  790. if (request & ANQP_REQ_TDLS_CAPABILITY)
  791. anqp_add_elem(hapd, buf, ANQP_TDLS_CAPABILITY);
  792. if (request & ANQP_REQ_EMERGENCY_NAI)
  793. anqp_add_elem(hapd, buf, ANQP_EMERGENCY_NAI);
  794. for (i = 0; i < num_extra_req; i++) {
  795. #ifdef CONFIG_FILS
  796. if (extra_req[i] == ANQP_FILS_REALM_INFO) {
  797. anqp_add_fils_realm_info(hapd, buf);
  798. continue;
  799. }
  800. #endif /* CONFIG_FILS */
  801. anqp_add_elem(hapd, buf, extra_req[i]);
  802. }
  803. #ifdef CONFIG_HS20
  804. if (request & ANQP_REQ_HS_CAPABILITY_LIST)
  805. anqp_add_hs_capab_list(hapd, buf);
  806. if (request & ANQP_REQ_OPERATOR_FRIENDLY_NAME)
  807. anqp_add_operator_friendly_name(hapd, buf);
  808. if (request & ANQP_REQ_WAN_METRICS)
  809. anqp_add_wan_metrics(hapd, buf);
  810. if (request & ANQP_REQ_CONNECTION_CAPABILITY)
  811. anqp_add_connection_capability(hapd, buf);
  812. if (request & ANQP_REQ_OPERATING_CLASS)
  813. anqp_add_operating_class(hapd, buf);
  814. if (request & ANQP_REQ_OSU_PROVIDERS_LIST)
  815. anqp_add_osu_providers_list(hapd, buf);
  816. if (request & ANQP_REQ_ICON_REQUEST)
  817. anqp_add_icon_binary_file(hapd, buf, icon_name, icon_name_len);
  818. #endif /* CONFIG_HS20 */
  819. #ifdef CONFIG_MBO
  820. if (request & ANQP_REQ_MBO_CELL_DATA_CONN_PREF)
  821. anqp_add_mbo_cell_data_conn_pref(hapd, buf);
  822. #endif /* CONFIG_MBO */
  823. return buf;
  824. }
  825. #define ANQP_MAX_EXTRA_REQ 20
  826. struct anqp_query_info {
  827. unsigned int request;
  828. const u8 *home_realm_query;
  829. size_t home_realm_query_len;
  830. const u8 *icon_name;
  831. size_t icon_name_len;
  832. int p2p_sd;
  833. u16 extra_req[ANQP_MAX_EXTRA_REQ];
  834. unsigned int num_extra_req;
  835. };
  836. static void set_anqp_req(unsigned int bit, const char *name, int local,
  837. struct anqp_query_info *qi)
  838. {
  839. qi->request |= bit;
  840. if (local) {
  841. wpa_printf(MSG_DEBUG, "ANQP: %s (local)", name);
  842. } else {
  843. wpa_printf(MSG_DEBUG, "ANQP: %s not available", name);
  844. }
  845. }
  846. static void rx_anqp_query_list_id(struct hostapd_data *hapd, u16 info_id,
  847. struct anqp_query_info *qi)
  848. {
  849. switch (info_id) {
  850. case ANQP_CAPABILITY_LIST:
  851. set_anqp_req(ANQP_REQ_CAPABILITY_LIST, "Capability List", 1,
  852. qi);
  853. break;
  854. case ANQP_VENUE_NAME:
  855. set_anqp_req(ANQP_REQ_VENUE_NAME, "Venue Name",
  856. hapd->conf->venue_name != NULL, qi);
  857. break;
  858. case ANQP_EMERGENCY_CALL_NUMBER:
  859. set_anqp_req(ANQP_REQ_EMERGENCY_CALL_NUMBER,
  860. "Emergency Call Number",
  861. get_anqp_elem(hapd, info_id) != NULL, qi);
  862. break;
  863. case ANQP_NETWORK_AUTH_TYPE:
  864. set_anqp_req(ANQP_REQ_NETWORK_AUTH_TYPE, "Network Auth Type",
  865. hapd->conf->network_auth_type != NULL, qi);
  866. break;
  867. case ANQP_ROAMING_CONSORTIUM:
  868. set_anqp_req(ANQP_REQ_ROAMING_CONSORTIUM, "Roaming Consortium",
  869. hapd->conf->roaming_consortium != NULL, qi);
  870. break;
  871. case ANQP_IP_ADDR_TYPE_AVAILABILITY:
  872. set_anqp_req(ANQP_REQ_IP_ADDR_TYPE_AVAILABILITY,
  873. "IP Addr Type Availability",
  874. hapd->conf->ipaddr_type_configured, qi);
  875. break;
  876. case ANQP_NAI_REALM:
  877. set_anqp_req(ANQP_REQ_NAI_REALM, "NAI Realm",
  878. hapd->conf->nai_realm_data != NULL, qi);
  879. break;
  880. case ANQP_3GPP_CELLULAR_NETWORK:
  881. set_anqp_req(ANQP_REQ_3GPP_CELLULAR_NETWORK,
  882. "3GPP Cellular Network",
  883. hapd->conf->anqp_3gpp_cell_net != NULL, qi);
  884. break;
  885. case ANQP_AP_GEOSPATIAL_LOCATION:
  886. set_anqp_req(ANQP_REQ_AP_GEOSPATIAL_LOCATION,
  887. "AP Geospatial Location",
  888. get_anqp_elem(hapd, info_id) != NULL, qi);
  889. break;
  890. case ANQP_AP_CIVIC_LOCATION:
  891. set_anqp_req(ANQP_REQ_AP_CIVIC_LOCATION,
  892. "AP Civic Location",
  893. get_anqp_elem(hapd, info_id) != NULL, qi);
  894. break;
  895. case ANQP_AP_LOCATION_PUBLIC_URI:
  896. set_anqp_req(ANQP_REQ_AP_LOCATION_PUBLIC_URI,
  897. "AP Location Public URI",
  898. get_anqp_elem(hapd, info_id) != NULL, qi);
  899. break;
  900. case ANQP_DOMAIN_NAME:
  901. set_anqp_req(ANQP_REQ_DOMAIN_NAME, "Domain Name",
  902. hapd->conf->domain_name != NULL, qi);
  903. break;
  904. case ANQP_EMERGENCY_ALERT_URI:
  905. set_anqp_req(ANQP_REQ_EMERGENCY_ALERT_URI,
  906. "Emergency Alert URI",
  907. get_anqp_elem(hapd, info_id) != NULL, qi);
  908. break;
  909. case ANQP_TDLS_CAPABILITY:
  910. set_anqp_req(ANQP_REQ_TDLS_CAPABILITY,
  911. "TDLS Capability",
  912. get_anqp_elem(hapd, info_id) != NULL, qi);
  913. break;
  914. case ANQP_EMERGENCY_NAI:
  915. set_anqp_req(ANQP_REQ_EMERGENCY_NAI,
  916. "Emergency NAI",
  917. get_anqp_elem(hapd, info_id) != NULL, qi);
  918. break;
  919. default:
  920. #ifdef CONFIG_FILS
  921. if (info_id == ANQP_FILS_REALM_INFO &&
  922. !dl_list_empty(&hapd->conf->fils_realms)) {
  923. wpa_printf(MSG_DEBUG,
  924. "ANQP: FILS Realm Information (local)");
  925. } else
  926. #endif /* CONFIG_FILS */
  927. if (!get_anqp_elem(hapd, info_id)) {
  928. wpa_printf(MSG_DEBUG, "ANQP: Unsupported Info Id %u",
  929. info_id);
  930. break;
  931. }
  932. if (qi->num_extra_req == ANQP_MAX_EXTRA_REQ) {
  933. wpa_printf(MSG_DEBUG,
  934. "ANQP: No more room for extra requests - ignore Info Id %u",
  935. info_id);
  936. break;
  937. }
  938. wpa_printf(MSG_DEBUG, "ANQP: Info Id %u (local)", info_id);
  939. qi->extra_req[qi->num_extra_req] = info_id;
  940. qi->num_extra_req++;
  941. break;
  942. }
  943. }
  944. static void rx_anqp_query_list(struct hostapd_data *hapd,
  945. const u8 *pos, const u8 *end,
  946. struct anqp_query_info *qi)
  947. {
  948. wpa_printf(MSG_DEBUG, "ANQP: %u Info IDs requested in Query list",
  949. (unsigned int) (end - pos) / 2);
  950. while (end - pos >= 2) {
  951. rx_anqp_query_list_id(hapd, WPA_GET_LE16(pos), qi);
  952. pos += 2;
  953. }
  954. }
  955. #ifdef CONFIG_HS20
  956. static void rx_anqp_hs_query_list(struct hostapd_data *hapd, u8 subtype,
  957. struct anqp_query_info *qi)
  958. {
  959. switch (subtype) {
  960. case HS20_STYPE_CAPABILITY_LIST:
  961. set_anqp_req(ANQP_REQ_HS_CAPABILITY_LIST, "HS Capability List",
  962. 1, qi);
  963. break;
  964. case HS20_STYPE_OPERATOR_FRIENDLY_NAME:
  965. set_anqp_req(ANQP_REQ_OPERATOR_FRIENDLY_NAME,
  966. "Operator Friendly Name",
  967. hapd->conf->hs20_oper_friendly_name != NULL, qi);
  968. break;
  969. case HS20_STYPE_WAN_METRICS:
  970. set_anqp_req(ANQP_REQ_WAN_METRICS, "WAN Metrics",
  971. hapd->conf->hs20_wan_metrics != NULL, qi);
  972. break;
  973. case HS20_STYPE_CONNECTION_CAPABILITY:
  974. set_anqp_req(ANQP_REQ_CONNECTION_CAPABILITY,
  975. "Connection Capability",
  976. hapd->conf->hs20_connection_capability != NULL,
  977. qi);
  978. break;
  979. case HS20_STYPE_OPERATING_CLASS:
  980. set_anqp_req(ANQP_REQ_OPERATING_CLASS, "Operating Class",
  981. hapd->conf->hs20_operating_class != NULL, qi);
  982. break;
  983. case HS20_STYPE_OSU_PROVIDERS_LIST:
  984. set_anqp_req(ANQP_REQ_OSU_PROVIDERS_LIST, "OSU Providers list",
  985. hapd->conf->hs20_osu_providers_count, qi);
  986. break;
  987. default:
  988. wpa_printf(MSG_DEBUG, "ANQP: Unsupported HS 2.0 subtype %u",
  989. subtype);
  990. break;
  991. }
  992. }
  993. static void rx_anqp_hs_nai_home_realm(struct hostapd_data *hapd,
  994. const u8 *pos, const u8 *end,
  995. struct anqp_query_info *qi)
  996. {
  997. qi->request |= ANQP_REQ_NAI_HOME_REALM;
  998. qi->home_realm_query = pos;
  999. qi->home_realm_query_len = end - pos;
  1000. if (hapd->conf->nai_realm_data != NULL) {
  1001. wpa_printf(MSG_DEBUG, "ANQP: HS 2.0 NAI Home Realm Query "
  1002. "(local)");
  1003. } else {
  1004. wpa_printf(MSG_DEBUG, "ANQP: HS 2.0 NAI Home Realm Query not "
  1005. "available");
  1006. }
  1007. }
  1008. static void rx_anqp_hs_icon_request(struct hostapd_data *hapd,
  1009. const u8 *pos, const u8 *end,
  1010. struct anqp_query_info *qi)
  1011. {
  1012. qi->request |= ANQP_REQ_ICON_REQUEST;
  1013. qi->icon_name = pos;
  1014. qi->icon_name_len = end - pos;
  1015. if (hapd->conf->hs20_icons_count) {
  1016. wpa_printf(MSG_DEBUG, "ANQP: HS 2.0 Icon Request Query "
  1017. "(local)");
  1018. } else {
  1019. wpa_printf(MSG_DEBUG, "ANQP: HS 2.0 Icon Request Query not "
  1020. "available");
  1021. }
  1022. }
  1023. static void rx_anqp_vendor_specific_hs20(struct hostapd_data *hapd,
  1024. const u8 *pos, const u8 *end,
  1025. struct anqp_query_info *qi)
  1026. {
  1027. u8 subtype;
  1028. if (end - pos <= 1)
  1029. return;
  1030. subtype = *pos++;
  1031. pos++; /* Reserved */
  1032. switch (subtype) {
  1033. case HS20_STYPE_QUERY_LIST:
  1034. wpa_printf(MSG_DEBUG, "ANQP: HS 2.0 Query List");
  1035. while (pos < end) {
  1036. rx_anqp_hs_query_list(hapd, *pos, qi);
  1037. pos++;
  1038. }
  1039. break;
  1040. case HS20_STYPE_NAI_HOME_REALM_QUERY:
  1041. rx_anqp_hs_nai_home_realm(hapd, pos, end, qi);
  1042. break;
  1043. case HS20_STYPE_ICON_REQUEST:
  1044. rx_anqp_hs_icon_request(hapd, pos, end, qi);
  1045. break;
  1046. default:
  1047. wpa_printf(MSG_DEBUG, "ANQP: Unsupported HS 2.0 query subtype "
  1048. "%u", subtype);
  1049. break;
  1050. }
  1051. }
  1052. #endif /* CONFIG_HS20 */
  1053. #ifdef CONFIG_P2P
  1054. static void rx_anqp_vendor_specific_p2p(struct hostapd_data *hapd,
  1055. struct anqp_query_info *qi)
  1056. {
  1057. /*
  1058. * This is for P2P SD and will be taken care of by the P2P
  1059. * implementation. This query needs to be ignored in the generic
  1060. * GAS server to avoid duplicated response.
  1061. */
  1062. wpa_printf(MSG_DEBUG,
  1063. "ANQP: Ignore WFA vendor type %u (P2P SD) in generic GAS server",
  1064. P2P_OUI_TYPE);
  1065. qi->p2p_sd = 1;
  1066. return;
  1067. }
  1068. #endif /* CONFIG_P2P */
  1069. #ifdef CONFIG_MBO
  1070. static void rx_anqp_mbo_query_list(struct hostapd_data *hapd, u8 subtype,
  1071. struct anqp_query_info *qi)
  1072. {
  1073. switch (subtype) {
  1074. case MBO_ANQP_SUBTYPE_CELL_CONN_PREF:
  1075. set_anqp_req(ANQP_REQ_MBO_CELL_DATA_CONN_PREF,
  1076. "Cellular Data Connection Preference",
  1077. hapd->conf->mbo_cell_data_conn_pref >= 0, qi);
  1078. break;
  1079. default:
  1080. wpa_printf(MSG_DEBUG, "ANQP: Unsupported MBO subtype %u",
  1081. subtype);
  1082. break;
  1083. }
  1084. }
  1085. static void rx_anqp_vendor_specific_mbo(struct hostapd_data *hapd,
  1086. const u8 *pos, const u8 *end,
  1087. struct anqp_query_info *qi)
  1088. {
  1089. u8 subtype;
  1090. if (end - pos < 1)
  1091. return;
  1092. subtype = *pos++;
  1093. switch (subtype) {
  1094. case MBO_ANQP_SUBTYPE_QUERY_LIST:
  1095. wpa_printf(MSG_DEBUG, "ANQP: MBO Query List");
  1096. while (pos < end) {
  1097. rx_anqp_mbo_query_list(hapd, *pos, qi);
  1098. pos++;
  1099. }
  1100. break;
  1101. default:
  1102. wpa_printf(MSG_DEBUG, "ANQP: Unsupported MBO query subtype %u",
  1103. subtype);
  1104. break;
  1105. }
  1106. }
  1107. #endif /* CONFIG_MBO */
  1108. static void rx_anqp_vendor_specific(struct hostapd_data *hapd,
  1109. const u8 *pos, const u8 *end,
  1110. struct anqp_query_info *qi)
  1111. {
  1112. u32 oui;
  1113. if (end - pos < 4) {
  1114. wpa_printf(MSG_DEBUG, "ANQP: Too short vendor specific ANQP "
  1115. "Query element");
  1116. return;
  1117. }
  1118. oui = WPA_GET_BE24(pos);
  1119. pos += 3;
  1120. if (oui != OUI_WFA) {
  1121. wpa_printf(MSG_DEBUG, "ANQP: Unsupported vendor OUI %06x",
  1122. oui);
  1123. return;
  1124. }
  1125. switch (*pos) {
  1126. #ifdef CONFIG_P2P
  1127. case P2P_OUI_TYPE:
  1128. rx_anqp_vendor_specific_p2p(hapd, qi);
  1129. break;
  1130. #endif /* CONFIG_P2P */
  1131. #ifdef CONFIG_HS20
  1132. case HS20_ANQP_OUI_TYPE:
  1133. rx_anqp_vendor_specific_hs20(hapd, pos + 1, end, qi);
  1134. break;
  1135. #endif /* CONFIG_HS20 */
  1136. #ifdef CONFIG_MBO
  1137. case MBO_ANQP_OUI_TYPE:
  1138. rx_anqp_vendor_specific_mbo(hapd, pos + 1, end, qi);
  1139. break;
  1140. #endif /* CONFIG_MBO */
  1141. default:
  1142. wpa_printf(MSG_DEBUG, "ANQP: Unsupported WFA vendor type %u",
  1143. *pos);
  1144. break;
  1145. }
  1146. }
  1147. static void gas_serv_req_local_processing(struct hostapd_data *hapd,
  1148. const u8 *sa, u8 dialog_token,
  1149. struct anqp_query_info *qi, int prot,
  1150. int std_addr3)
  1151. {
  1152. struct wpabuf *buf, *tx_buf;
  1153. buf = gas_serv_build_gas_resp_payload(hapd, qi->request,
  1154. qi->home_realm_query,
  1155. qi->home_realm_query_len,
  1156. qi->icon_name, qi->icon_name_len,
  1157. qi->extra_req, qi->num_extra_req);
  1158. wpa_hexdump_buf(MSG_MSGDUMP, "ANQP: Locally generated ANQP responses",
  1159. buf);
  1160. if (!buf)
  1161. return;
  1162. #ifdef CONFIG_P2P
  1163. if (wpabuf_len(buf) == 0 && qi->p2p_sd) {
  1164. wpa_printf(MSG_DEBUG,
  1165. "ANQP: Do not send response to P2P SD from generic GAS service (P2P SD implementation will process this)");
  1166. wpabuf_free(buf);
  1167. return;
  1168. }
  1169. #endif /* CONFIG_P2P */
  1170. if (wpabuf_len(buf) > hapd->conf->gas_frag_limit ||
  1171. hapd->conf->gas_comeback_delay) {
  1172. struct gas_dialog_info *di;
  1173. u16 comeback_delay = 1;
  1174. if (hapd->conf->gas_comeback_delay) {
  1175. /* Testing - allow overriding of the delay value */
  1176. comeback_delay = hapd->conf->gas_comeback_delay;
  1177. }
  1178. wpa_printf(MSG_DEBUG, "ANQP: Too long response to fit in "
  1179. "initial response - use GAS comeback");
  1180. di = gas_dialog_create(hapd, sa, dialog_token);
  1181. if (!di) {
  1182. wpa_printf(MSG_INFO, "ANQP: Could not create dialog "
  1183. "for " MACSTR " (dialog token %u)",
  1184. MAC2STR(sa), dialog_token);
  1185. wpabuf_free(buf);
  1186. tx_buf = gas_anqp_build_initial_resp_buf(
  1187. dialog_token, WLAN_STATUS_UNSPECIFIED_FAILURE,
  1188. 0, NULL);
  1189. } else {
  1190. di->prot = prot;
  1191. di->sd_resp = buf;
  1192. di->sd_resp_pos = 0;
  1193. tx_buf = gas_anqp_build_initial_resp_buf(
  1194. dialog_token, WLAN_STATUS_SUCCESS,
  1195. comeback_delay, NULL);
  1196. }
  1197. } else {
  1198. wpa_printf(MSG_DEBUG, "ANQP: Initial response (no comeback)");
  1199. tx_buf = gas_anqp_build_initial_resp_buf(
  1200. dialog_token, WLAN_STATUS_SUCCESS, 0, buf);
  1201. wpabuf_free(buf);
  1202. }
  1203. if (!tx_buf)
  1204. return;
  1205. if (prot)
  1206. convert_to_protected_dual(tx_buf);
  1207. if (std_addr3)
  1208. hostapd_drv_send_action(hapd, hapd->iface->freq, 0, sa,
  1209. wpabuf_head(tx_buf),
  1210. wpabuf_len(tx_buf));
  1211. else
  1212. hostapd_drv_send_action_addr3_ap(hapd, hapd->iface->freq, 0, sa,
  1213. wpabuf_head(tx_buf),
  1214. wpabuf_len(tx_buf));
  1215. wpabuf_free(tx_buf);
  1216. }
  1217. static void gas_serv_rx_gas_initial_req(struct hostapd_data *hapd,
  1218. const u8 *sa,
  1219. const u8 *data, size_t len, int prot,
  1220. int std_addr3)
  1221. {
  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. if (len < 1 + 2)
  1230. return;
  1231. os_memset(&qi, 0, sizeof(qi));
  1232. dialog_token = *pos++;
  1233. wpa_msg(hapd->msg_ctx, MSG_DEBUG,
  1234. "GAS: GAS Initial Request from " MACSTR " (dialog token %u) ",
  1235. MAC2STR(sa), dialog_token);
  1236. if (*pos != WLAN_EID_ADV_PROTO) {
  1237. wpa_msg(hapd->msg_ctx, MSG_DEBUG,
  1238. "GAS: Unexpected IE in GAS Initial Request: %u", *pos);
  1239. return;
  1240. }
  1241. adv_proto = pos++;
  1242. slen = *pos++;
  1243. if (slen > end - pos || slen < 2) {
  1244. wpa_msg(hapd->msg_ctx, MSG_DEBUG,
  1245. "GAS: Invalid IE in GAS Initial Request");
  1246. return;
  1247. }
  1248. next = pos + slen;
  1249. pos++; /* skip QueryRespLenLimit and PAME-BI */
  1250. if (*pos != ACCESS_NETWORK_QUERY_PROTOCOL) {
  1251. struct wpabuf *buf;
  1252. wpa_msg(hapd->msg_ctx, MSG_DEBUG,
  1253. "GAS: Unsupported GAS advertisement protocol id %u",
  1254. *pos);
  1255. if (sa[0] & 0x01)
  1256. return; /* Invalid source address - drop silently */
  1257. buf = gas_build_initial_resp(
  1258. dialog_token, WLAN_STATUS_GAS_ADV_PROTO_NOT_SUPPORTED,
  1259. 0, 2 + slen + 2);
  1260. if (buf == NULL)
  1261. return;
  1262. wpabuf_put_data(buf, adv_proto, 2 + slen);
  1263. wpabuf_put_le16(buf, 0); /* Query Response Length */
  1264. if (prot)
  1265. convert_to_protected_dual(buf);
  1266. if (std_addr3)
  1267. hostapd_drv_send_action(hapd, hapd->iface->freq, 0, sa,
  1268. wpabuf_head(buf),
  1269. wpabuf_len(buf));
  1270. else
  1271. hostapd_drv_send_action_addr3_ap(hapd,
  1272. hapd->iface->freq, 0,
  1273. sa, wpabuf_head(buf),
  1274. wpabuf_len(buf));
  1275. wpabuf_free(buf);
  1276. return;
  1277. }
  1278. pos = next;
  1279. /* Query Request */
  1280. if (end - pos < 2)
  1281. return;
  1282. slen = WPA_GET_LE16(pos);
  1283. pos += 2;
  1284. if (slen > end - pos)
  1285. return;
  1286. end = pos + slen;
  1287. /* ANQP Query Request */
  1288. while (pos < end) {
  1289. u16 info_id, elen;
  1290. if (end - pos < 4)
  1291. return;
  1292. info_id = WPA_GET_LE16(pos);
  1293. pos += 2;
  1294. elen = WPA_GET_LE16(pos);
  1295. pos += 2;
  1296. if (elen > end - pos) {
  1297. wpa_printf(MSG_DEBUG, "ANQP: Invalid Query Request");
  1298. return;
  1299. }
  1300. switch (info_id) {
  1301. case ANQP_QUERY_LIST:
  1302. rx_anqp_query_list(hapd, pos, pos + elen, &qi);
  1303. break;
  1304. case ANQP_VENDOR_SPECIFIC:
  1305. rx_anqp_vendor_specific(hapd, pos, pos + elen, &qi);
  1306. break;
  1307. default:
  1308. wpa_printf(MSG_DEBUG, "ANQP: Unsupported Query "
  1309. "Request element %u", info_id);
  1310. break;
  1311. }
  1312. pos += elen;
  1313. }
  1314. gas_serv_req_local_processing(hapd, sa, dialog_token, &qi, prot,
  1315. std_addr3);
  1316. }
  1317. static void gas_serv_rx_gas_comeback_req(struct hostapd_data *hapd,
  1318. const u8 *sa,
  1319. const u8 *data, size_t len, int prot,
  1320. int std_addr3)
  1321. {
  1322. struct gas_dialog_info *dialog;
  1323. struct wpabuf *buf, *tx_buf;
  1324. u8 dialog_token;
  1325. size_t frag_len;
  1326. int more = 0;
  1327. wpa_hexdump(MSG_DEBUG, "GAS: RX GAS Comeback Request", data, len);
  1328. if (len < 1)
  1329. return;
  1330. dialog_token = *data;
  1331. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: Dialog Token: %u",
  1332. dialog_token);
  1333. dialog = gas_serv_dialog_find(hapd, sa, dialog_token);
  1334. if (!dialog) {
  1335. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: No pending SD "
  1336. "response fragment for " MACSTR " dialog token %u",
  1337. MAC2STR(sa), dialog_token);
  1338. if (sa[0] & 0x01)
  1339. return; /* Invalid source address - drop silently */
  1340. tx_buf = gas_anqp_build_comeback_resp_buf(
  1341. dialog_token, WLAN_STATUS_NO_OUTSTANDING_GAS_REQ, 0, 0,
  1342. 0, NULL);
  1343. if (tx_buf == NULL)
  1344. return;
  1345. goto send_resp;
  1346. }
  1347. frag_len = wpabuf_len(dialog->sd_resp) - dialog->sd_resp_pos;
  1348. if (frag_len > hapd->conf->gas_frag_limit) {
  1349. frag_len = hapd->conf->gas_frag_limit;
  1350. more = 1;
  1351. }
  1352. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: resp frag_len %u",
  1353. (unsigned int) frag_len);
  1354. buf = wpabuf_alloc_copy(wpabuf_head_u8(dialog->sd_resp) +
  1355. dialog->sd_resp_pos, frag_len);
  1356. if (buf == NULL) {
  1357. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: Failed to allocate "
  1358. "buffer");
  1359. gas_serv_dialog_clear(dialog);
  1360. return;
  1361. }
  1362. tx_buf = gas_anqp_build_comeback_resp_buf(dialog_token,
  1363. WLAN_STATUS_SUCCESS,
  1364. dialog->sd_frag_id,
  1365. more, 0, buf);
  1366. wpabuf_free(buf);
  1367. if (tx_buf == NULL) {
  1368. gas_serv_dialog_clear(dialog);
  1369. return;
  1370. }
  1371. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: Tx GAS Comeback Response "
  1372. "(frag_id %d more=%d frag_len=%d)",
  1373. dialog->sd_frag_id, more, (int) frag_len);
  1374. dialog->sd_frag_id++;
  1375. dialog->sd_resp_pos += frag_len;
  1376. if (more) {
  1377. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: %d more bytes remain "
  1378. "to be sent",
  1379. (int) (wpabuf_len(dialog->sd_resp) -
  1380. dialog->sd_resp_pos));
  1381. } else {
  1382. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "GAS: All fragments of "
  1383. "SD response sent");
  1384. gas_serv_dialog_clear(dialog);
  1385. gas_serv_free_dialogs(hapd, sa);
  1386. }
  1387. send_resp:
  1388. if (prot)
  1389. convert_to_protected_dual(tx_buf);
  1390. if (std_addr3)
  1391. hostapd_drv_send_action(hapd, hapd->iface->freq, 0, sa,
  1392. wpabuf_head(tx_buf),
  1393. wpabuf_len(tx_buf));
  1394. else
  1395. hostapd_drv_send_action_addr3_ap(hapd, hapd->iface->freq, 0, sa,
  1396. wpabuf_head(tx_buf),
  1397. wpabuf_len(tx_buf));
  1398. wpabuf_free(tx_buf);
  1399. }
  1400. static void gas_serv_rx_public_action(void *ctx, const u8 *buf, size_t len,
  1401. int freq)
  1402. {
  1403. struct hostapd_data *hapd = ctx;
  1404. const struct ieee80211_mgmt *mgmt;
  1405. const u8 *sa, *data;
  1406. int prot, std_addr3;
  1407. mgmt = (const struct ieee80211_mgmt *) buf;
  1408. if (len < IEEE80211_HDRLEN + 2)
  1409. return;
  1410. if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
  1411. mgmt->u.action.category != WLAN_ACTION_PROTECTED_DUAL)
  1412. return;
  1413. /*
  1414. * Note: Public Action and Protected Dual of Public Action frames share
  1415. * the same payload structure, so it is fine to use definitions of
  1416. * Public Action frames to process both.
  1417. */
  1418. prot = mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL;
  1419. sa = mgmt->sa;
  1420. if (hapd->conf->gas_address3 == 1)
  1421. std_addr3 = 1;
  1422. else if (hapd->conf->gas_address3 == 2)
  1423. std_addr3 = 0;
  1424. else
  1425. std_addr3 = is_broadcast_ether_addr(mgmt->bssid);
  1426. len -= IEEE80211_HDRLEN + 1;
  1427. data = buf + IEEE80211_HDRLEN + 1;
  1428. switch (data[0]) {
  1429. case WLAN_PA_GAS_INITIAL_REQ:
  1430. gas_serv_rx_gas_initial_req(hapd, sa, data + 1, len - 1, prot,
  1431. std_addr3);
  1432. break;
  1433. case WLAN_PA_GAS_COMEBACK_REQ:
  1434. gas_serv_rx_gas_comeback_req(hapd, sa, data + 1, len - 1, prot,
  1435. std_addr3);
  1436. break;
  1437. }
  1438. }
  1439. int gas_serv_init(struct hostapd_data *hapd)
  1440. {
  1441. hapd->public_action_cb2 = gas_serv_rx_public_action;
  1442. hapd->public_action_cb2_ctx = hapd;
  1443. return 0;
  1444. }
  1445. void gas_serv_deinit(struct hostapd_data *hapd)
  1446. {
  1447. }