dpp_hostapd.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682
  1. /*
  2. * hostapd / DPP integration
  3. * Copyright (c) 2017, 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 "utils/includes.h"
  9. #include "utils/common.h"
  10. #include "utils/eloop.h"
  11. #include "common/dpp.h"
  12. #include "common/gas.h"
  13. #include "common/wpa_ctrl.h"
  14. #include "hostapd.h"
  15. #include "ap_drv_ops.h"
  16. #include "gas_query_ap.h"
  17. #include "wpa_auth.h"
  18. #include "dpp_hostapd.h"
  19. static void hostapd_dpp_auth_success(struct hostapd_data *hapd, int initiator);
  20. static const u8 broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  21. static struct dpp_configurator *
  22. hostapd_dpp_configurator_get_id(struct hostapd_data *hapd, unsigned int id)
  23. {
  24. struct dpp_configurator *conf;
  25. dl_list_for_each(conf, &hapd->dpp_configurator,
  26. struct dpp_configurator, list) {
  27. if (conf->id == id)
  28. return conf;
  29. }
  30. return NULL;
  31. }
  32. static unsigned int hapd_dpp_next_id(struct hostapd_data *hapd)
  33. {
  34. struct dpp_bootstrap_info *bi;
  35. unsigned int max_id = 0;
  36. dl_list_for_each(bi, &hapd->dpp_bootstrap, struct dpp_bootstrap_info,
  37. list) {
  38. if (bi->id > max_id)
  39. max_id = bi->id;
  40. }
  41. return max_id + 1;
  42. }
  43. /**
  44. * hostapd_dpp_qr_code - Parse and add DPP bootstrapping info from a QR Code
  45. * @hapd: Pointer to hostapd_data
  46. * @cmd: DPP URI read from a QR Code
  47. * Returns: Identifier of the stored info or -1 on failure
  48. */
  49. int hostapd_dpp_qr_code(struct hostapd_data *hapd, const char *cmd)
  50. {
  51. struct dpp_bootstrap_info *bi;
  52. struct dpp_authentication *auth = hapd->dpp_auth;
  53. bi = dpp_parse_qr_code(cmd);
  54. if (!bi)
  55. return -1;
  56. bi->id = hapd_dpp_next_id(hapd);
  57. dl_list_add(&hapd->dpp_bootstrap, &bi->list);
  58. if (auth && auth->response_pending &&
  59. dpp_notify_new_qr_code(auth, bi) == 1) {
  60. wpa_printf(MSG_DEBUG,
  61. "DPP: Sending out pending authentication response");
  62. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
  63. " freq=%u type=%d",
  64. MAC2STR(auth->peer_mac_addr), auth->curr_freq,
  65. DPP_PA_AUTHENTICATION_RESP);
  66. hostapd_drv_send_action(hapd, auth->curr_freq, 0,
  67. auth->peer_mac_addr,
  68. wpabuf_head(hapd->dpp_auth->resp_msg),
  69. wpabuf_len(hapd->dpp_auth->resp_msg));
  70. }
  71. return bi->id;
  72. }
  73. static char * get_param(const char *cmd, const char *param)
  74. {
  75. const char *pos, *end;
  76. char *val;
  77. size_t len;
  78. pos = os_strstr(cmd, param);
  79. if (!pos)
  80. return NULL;
  81. pos += os_strlen(param);
  82. end = os_strchr(pos, ' ');
  83. if (end)
  84. len = end - pos;
  85. else
  86. len = os_strlen(pos);
  87. val = os_malloc(len + 1);
  88. if (!val)
  89. return NULL;
  90. os_memcpy(val, pos, len);
  91. val[len] = '\0';
  92. return val;
  93. }
  94. int hostapd_dpp_bootstrap_gen(struct hostapd_data *hapd, const char *cmd)
  95. {
  96. char *chan = NULL, *mac = NULL, *info = NULL, *pk = NULL, *curve = NULL;
  97. char *key = NULL;
  98. u8 *privkey = NULL;
  99. size_t privkey_len = 0;
  100. size_t len;
  101. int ret = -1;
  102. struct dpp_bootstrap_info *bi;
  103. bi = os_zalloc(sizeof(*bi));
  104. if (!bi)
  105. goto fail;
  106. if (os_strstr(cmd, "type=qrcode"))
  107. bi->type = DPP_BOOTSTRAP_QR_CODE;
  108. else if (os_strstr(cmd, "type=pkex"))
  109. bi->type = DPP_BOOTSTRAP_PKEX;
  110. else
  111. goto fail;
  112. chan = get_param(cmd, " chan=");
  113. mac = get_param(cmd, " mac=");
  114. info = get_param(cmd, " info=");
  115. curve = get_param(cmd, " curve=");
  116. key = get_param(cmd, " key=");
  117. if (key) {
  118. privkey_len = os_strlen(key) / 2;
  119. privkey = os_malloc(privkey_len);
  120. if (!privkey ||
  121. hexstr2bin(key, privkey, privkey_len) < 0)
  122. goto fail;
  123. }
  124. pk = dpp_keygen(bi, curve, privkey, privkey_len);
  125. if (!pk)
  126. goto fail;
  127. len = 4; /* "DPP:" */
  128. if (chan) {
  129. if (dpp_parse_uri_chan_list(bi, chan) < 0)
  130. goto fail;
  131. len += 3 + os_strlen(chan); /* C:...; */
  132. }
  133. if (mac) {
  134. if (dpp_parse_uri_mac(bi, mac) < 0)
  135. goto fail;
  136. len += 3 + os_strlen(mac); /* M:...; */
  137. }
  138. if (info) {
  139. if (dpp_parse_uri_info(bi, info) < 0)
  140. goto fail;
  141. len += 3 + os_strlen(info); /* I:...; */
  142. }
  143. len += 4 + os_strlen(pk);
  144. bi->uri = os_malloc(len + 1);
  145. if (!bi->uri)
  146. goto fail;
  147. os_snprintf(bi->uri, len + 1, "DPP:%s%s%s%s%s%s%s%s%sK:%s;;",
  148. chan ? "C:" : "", chan ? chan : "", chan ? ";" : "",
  149. mac ? "M:" : "", mac ? mac : "", mac ? ";" : "",
  150. info ? "I:" : "", info ? info : "", info ? ";" : "",
  151. pk);
  152. bi->id = hapd_dpp_next_id(hapd);
  153. dl_list_add(&hapd->dpp_bootstrap, &bi->list);
  154. ret = bi->id;
  155. bi = NULL;
  156. fail:
  157. os_free(curve);
  158. os_free(pk);
  159. os_free(chan);
  160. os_free(mac);
  161. os_free(info);
  162. str_clear_free(key);
  163. bin_clear_free(privkey, privkey_len);
  164. dpp_bootstrap_info_free(bi);
  165. return ret;
  166. }
  167. static struct dpp_bootstrap_info *
  168. dpp_bootstrap_get_id(struct hostapd_data *hapd, unsigned int id)
  169. {
  170. struct dpp_bootstrap_info *bi;
  171. dl_list_for_each(bi, &hapd->dpp_bootstrap, struct dpp_bootstrap_info,
  172. list) {
  173. if (bi->id == id)
  174. return bi;
  175. }
  176. return NULL;
  177. }
  178. static int dpp_bootstrap_del(struct hostapd_data *hapd, unsigned int id)
  179. {
  180. struct dpp_bootstrap_info *bi, *tmp;
  181. int found = 0;
  182. dl_list_for_each_safe(bi, tmp, &hapd->dpp_bootstrap,
  183. struct dpp_bootstrap_info, list) {
  184. if (id && bi->id != id)
  185. continue;
  186. found = 1;
  187. dl_list_del(&bi->list);
  188. dpp_bootstrap_info_free(bi);
  189. }
  190. if (id == 0)
  191. return 0; /* flush succeeds regardless of entries found */
  192. return found ? 0 : -1;
  193. }
  194. int hostapd_dpp_bootstrap_remove(struct hostapd_data *hapd, const char *id)
  195. {
  196. unsigned int id_val;
  197. if (os_strcmp(id, "*") == 0) {
  198. id_val = 0;
  199. } else {
  200. id_val = atoi(id);
  201. if (id_val == 0)
  202. return -1;
  203. }
  204. return dpp_bootstrap_del(hapd, id_val);
  205. }
  206. const char * hostapd_dpp_bootstrap_get_uri(struct hostapd_data *hapd,
  207. unsigned int id)
  208. {
  209. struct dpp_bootstrap_info *bi;
  210. bi = dpp_bootstrap_get_id(hapd, id);
  211. if (!bi)
  212. return NULL;
  213. return bi->uri;
  214. }
  215. int hostapd_dpp_bootstrap_info(struct hostapd_data *hapd, int id,
  216. char *reply, int reply_size)
  217. {
  218. struct dpp_bootstrap_info *bi;
  219. bi = dpp_bootstrap_get_id(hapd, id);
  220. if (!bi)
  221. return -1;
  222. return os_snprintf(reply, reply_size, "type=%s\n"
  223. "mac_addr=" MACSTR "\n"
  224. "info=%s\n"
  225. "num_freq=%u\n"
  226. "curve=%s\n",
  227. dpp_bootstrap_type_txt(bi->type),
  228. MAC2STR(bi->mac_addr),
  229. bi->info ? bi->info : "",
  230. bi->num_freq,
  231. bi->curve->name);
  232. }
  233. void hostapd_dpp_tx_status(struct hostapd_data *hapd, const u8 *dst,
  234. const u8 *data, size_t data_len, int ok)
  235. {
  236. wpa_printf(MSG_DEBUG, "DPP: TX status: dst=" MACSTR " ok=%d",
  237. MAC2STR(dst), ok);
  238. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
  239. " result=%s", MAC2STR(dst), ok ? "SUCCESS" : "FAILED");
  240. if (!hapd->dpp_auth) {
  241. wpa_printf(MSG_DEBUG,
  242. "DPP: Ignore TX status since there is no ongoing authentication exchange");
  243. return;
  244. }
  245. if (hapd->dpp_auth->remove_on_tx_status) {
  246. wpa_printf(MSG_DEBUG,
  247. "DPP: Terminate authentication exchange due to an earlier error");
  248. dpp_auth_deinit(hapd->dpp_auth);
  249. hapd->dpp_auth = NULL;
  250. return;
  251. }
  252. if (hapd->dpp_auth_ok_on_ack)
  253. hostapd_dpp_auth_success(hapd, 1);
  254. }
  255. static void hostapd_dpp_set_testing_options(struct hostapd_data *hapd,
  256. struct dpp_authentication *auth)
  257. {
  258. #ifdef CONFIG_TESTING_OPTIONS
  259. if (hapd->dpp_config_obj_override)
  260. auth->config_obj_override =
  261. os_strdup(hapd->dpp_config_obj_override);
  262. if (hapd->dpp_discovery_override)
  263. auth->discovery_override =
  264. os_strdup(hapd->dpp_discovery_override);
  265. if (hapd->dpp_groups_override)
  266. auth->groups_override = os_strdup(hapd->dpp_groups_override);
  267. auth->ignore_netaccesskey_mismatch =
  268. hapd->dpp_ignore_netaccesskey_mismatch;
  269. #endif /* CONFIG_TESTING_OPTIONS */
  270. }
  271. static void hostapd_dpp_set_configurator(struct hostapd_data *hapd,
  272. struct dpp_authentication *auth,
  273. const char *cmd)
  274. {
  275. const char *pos, *end;
  276. struct dpp_configuration *conf_sta = NULL, *conf_ap = NULL;
  277. struct dpp_configurator *conf = NULL;
  278. u8 ssid[32] = { "test" };
  279. size_t ssid_len = 4;
  280. char pass[64] = { };
  281. size_t pass_len = 0;
  282. u8 psk[PMK_LEN];
  283. int psk_set = 0;
  284. if (!cmd)
  285. return;
  286. wpa_printf(MSG_DEBUG, "DPP: Set configurator parameters: %s", cmd);
  287. pos = os_strstr(cmd, " ssid=");
  288. if (pos) {
  289. pos += 6;
  290. end = os_strchr(pos, ' ');
  291. ssid_len = end ? (size_t) (end - pos) : os_strlen(pos);
  292. ssid_len /= 2;
  293. if (ssid_len > sizeof(ssid) ||
  294. hexstr2bin(pos, ssid, ssid_len) < 0)
  295. goto fail;
  296. }
  297. pos = os_strstr(cmd, " pass=");
  298. if (pos) {
  299. pos += 6;
  300. end = os_strchr(pos, ' ');
  301. pass_len = end ? (size_t) (end - pos) : os_strlen(pos);
  302. pass_len /= 2;
  303. if (pass_len > sizeof(pass) - 1 || pass_len < 8 ||
  304. hexstr2bin(pos, (u8 *) pass, pass_len) < 0)
  305. goto fail;
  306. }
  307. pos = os_strstr(cmd, " psk=");
  308. if (pos) {
  309. pos += 5;
  310. if (hexstr2bin(pos, psk, PMK_LEN) < 0)
  311. goto fail;
  312. psk_set = 1;
  313. }
  314. if (os_strstr(cmd, " conf=sta-")) {
  315. conf_sta = os_zalloc(sizeof(struct dpp_configuration));
  316. if (!conf_sta)
  317. goto fail;
  318. os_memcpy(conf_sta->ssid, ssid, ssid_len);
  319. conf_sta->ssid_len = ssid_len;
  320. if (os_strstr(cmd, " conf=sta-psk") ||
  321. os_strstr(cmd, " conf=sta-sae") ||
  322. os_strstr(cmd, " conf=sta-psk-sae")) {
  323. if (os_strstr(cmd, " conf=sta-psk-sae"))
  324. conf_sta->akm = DPP_AKM_PSK_SAE;
  325. else if (os_strstr(cmd, " conf=sta-sae"))
  326. conf_sta->akm = DPP_AKM_SAE;
  327. else
  328. conf_sta->akm = DPP_AKM_PSK;
  329. if (psk_set) {
  330. os_memcpy(conf_sta->psk, psk, PMK_LEN);
  331. } else {
  332. conf_sta->passphrase = os_strdup(pass);
  333. if (!conf_sta->passphrase)
  334. goto fail;
  335. }
  336. } else if (os_strstr(cmd, " conf=sta-dpp")) {
  337. conf_sta->akm = DPP_AKM_DPP;
  338. } else {
  339. goto fail;
  340. }
  341. }
  342. if (os_strstr(cmd, " conf=ap-")) {
  343. conf_ap = os_zalloc(sizeof(struct dpp_configuration));
  344. if (!conf_ap)
  345. goto fail;
  346. os_memcpy(conf_ap->ssid, ssid, ssid_len);
  347. conf_ap->ssid_len = ssid_len;
  348. if (os_strstr(cmd, " conf=ap-psk") ||
  349. os_strstr(cmd, " conf=ap-sae") ||
  350. os_strstr(cmd, " conf=ap-psk-sae")) {
  351. if (os_strstr(cmd, " conf=ap-psk-sae"))
  352. conf_ap->akm = DPP_AKM_PSK_SAE;
  353. else if (os_strstr(cmd, " conf=ap-sae"))
  354. conf_ap->akm = DPP_AKM_SAE;
  355. else
  356. conf_ap->akm = DPP_AKM_PSK;
  357. if (psk_set) {
  358. os_memcpy(conf_ap->psk, psk, PMK_LEN);
  359. } else {
  360. conf_ap->passphrase = os_strdup(pass);
  361. if (!conf_ap->passphrase)
  362. goto fail;
  363. }
  364. } else if (os_strstr(cmd, " conf=ap-dpp")) {
  365. conf_ap->akm = DPP_AKM_DPP;
  366. } else {
  367. goto fail;
  368. }
  369. }
  370. pos = os_strstr(cmd, " expiry=");
  371. if (pos) {
  372. long int val;
  373. pos += 8;
  374. val = strtol(pos, NULL, 0);
  375. if (val <= 0)
  376. goto fail;
  377. if (conf_sta)
  378. conf_sta->netaccesskey_expiry = val;
  379. if (conf_ap)
  380. conf_ap->netaccesskey_expiry = val;
  381. }
  382. pos = os_strstr(cmd, " configurator=");
  383. if (pos) {
  384. auth->configurator = 1;
  385. pos += 14;
  386. conf = hostapd_dpp_configurator_get_id(hapd, atoi(pos));
  387. if (!conf) {
  388. wpa_printf(MSG_INFO,
  389. "DPP: Could not find the specified configurator");
  390. goto fail;
  391. }
  392. }
  393. auth->conf_sta = conf_sta;
  394. auth->conf_ap = conf_ap;
  395. auth->conf = conf;
  396. return;
  397. fail:
  398. wpa_printf(MSG_DEBUG, "DPP: Failed to set configurator parameters");
  399. dpp_configuration_free(conf_sta);
  400. dpp_configuration_free(conf_ap);
  401. }
  402. int hostapd_dpp_auth_init(struct hostapd_data *hapd, const char *cmd)
  403. {
  404. const char *pos;
  405. struct dpp_bootstrap_info *peer_bi, *own_bi = NULL;
  406. const u8 *dst;
  407. int res;
  408. u8 allowed_roles = DPP_CAPAB_CONFIGURATOR;
  409. struct dpp_configuration *conf_sta = NULL, *conf_ap = NULL;
  410. pos = os_strstr(cmd, " peer=");
  411. if (!pos)
  412. return -1;
  413. pos += 6;
  414. peer_bi = dpp_bootstrap_get_id(hapd, atoi(pos));
  415. if (!peer_bi) {
  416. wpa_printf(MSG_INFO,
  417. "DPP: Could not find bootstrapping info for the identified peer");
  418. return -1;
  419. }
  420. pos = os_strstr(cmd, " own=");
  421. if (pos) {
  422. pos += 5;
  423. own_bi = dpp_bootstrap_get_id(hapd, atoi(pos));
  424. if (!own_bi) {
  425. wpa_printf(MSG_INFO,
  426. "DPP: Could not find bootstrapping info for the identified local entry");
  427. return -1;
  428. }
  429. if (peer_bi->curve != own_bi->curve) {
  430. wpa_printf(MSG_INFO,
  431. "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
  432. peer_bi->curve->name, own_bi->curve->name);
  433. return -1;
  434. }
  435. }
  436. pos = os_strstr(cmd, " role=");
  437. if (pos) {
  438. pos += 6;
  439. if (os_strncmp(pos, "configurator", 12) == 0)
  440. allowed_roles = DPP_CAPAB_CONFIGURATOR;
  441. else if (os_strncmp(pos, "enrollee", 8) == 0)
  442. allowed_roles = DPP_CAPAB_ENROLLEE;
  443. else if (os_strncmp(pos, "either", 6) == 0)
  444. allowed_roles = DPP_CAPAB_CONFIGURATOR |
  445. DPP_CAPAB_ENROLLEE;
  446. else
  447. goto fail;
  448. }
  449. if (hapd->dpp_auth)
  450. dpp_auth_deinit(hapd->dpp_auth);
  451. /* TODO: hw_modes */
  452. hapd->dpp_auth = dpp_auth_init(hapd->msg_ctx, peer_bi, own_bi,
  453. allowed_roles, 0, NULL, 0);
  454. if (!hapd->dpp_auth)
  455. goto fail;
  456. hostapd_dpp_set_testing_options(hapd, hapd->dpp_auth);
  457. hostapd_dpp_set_configurator(hapd, hapd->dpp_auth, cmd);
  458. /* TODO: Support iteration over all frequencies and filtering of
  459. * frequencies based on locally enabled channels that allow initiation
  460. * of transmission. */
  461. if (is_zero_ether_addr(peer_bi->mac_addr)) {
  462. dst = broadcast;
  463. } else {
  464. dst = peer_bi->mac_addr;
  465. os_memcpy(hapd->dpp_auth->peer_mac_addr, peer_bi->mac_addr,
  466. ETH_ALEN);
  467. }
  468. hapd->dpp_auth_ok_on_ack = 0;
  469. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
  470. " freq=%u type=%d",
  471. MAC2STR(dst), hapd->dpp_auth->curr_freq,
  472. DPP_PA_AUTHENTICATION_REQ);
  473. res = hostapd_drv_send_action(hapd, hapd->dpp_auth->curr_freq, 0,
  474. dst, wpabuf_head(hapd->dpp_auth->req_msg),
  475. wpabuf_len(hapd->dpp_auth->req_msg));
  476. return res;
  477. fail:
  478. dpp_configuration_free(conf_sta);
  479. dpp_configuration_free(conf_ap);
  480. return -1;
  481. }
  482. int hostapd_dpp_listen(struct hostapd_data *hapd, const char *cmd)
  483. {
  484. int freq;
  485. freq = atoi(cmd);
  486. if (freq <= 0)
  487. return -1;
  488. if (os_strstr(cmd, " role=configurator"))
  489. hapd->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR;
  490. else if (os_strstr(cmd, " role=enrollee"))
  491. hapd->dpp_allowed_roles = DPP_CAPAB_ENROLLEE;
  492. else
  493. hapd->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR |
  494. DPP_CAPAB_ENROLLEE;
  495. hapd->dpp_qr_mutual = os_strstr(cmd, " qr=mutual") != NULL;
  496. if (freq != hapd->iface->freq && hapd->iface->freq > 0) {
  497. /* TODO: Listen operation on non-operating channel */
  498. wpa_printf(MSG_INFO,
  499. "DPP: Listen operation on non-operating channel (%d MHz) is not yet supported (operating channel: %d MHz)",
  500. freq, hapd->iface->freq);
  501. return -1;
  502. }
  503. return 0;
  504. }
  505. void hostapd_dpp_listen_stop(struct hostapd_data *hapd)
  506. {
  507. /* TODO: Stop listen operation on non-operating channel */
  508. }
  509. static void hostapd_dpp_rx_auth_req(struct hostapd_data *hapd, const u8 *src,
  510. const u8 *hdr, const u8 *buf, size_t len,
  511. unsigned int freq)
  512. {
  513. const u8 *r_bootstrap, *i_bootstrap;
  514. u16 r_bootstrap_len, i_bootstrap_len;
  515. struct dpp_bootstrap_info *bi, *own_bi = NULL, *peer_bi = NULL;
  516. wpa_printf(MSG_DEBUG, "DPP: Authentication Request from " MACSTR,
  517. MAC2STR(src));
  518. r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH,
  519. &r_bootstrap_len);
  520. if (!r_bootstrap || r_bootstrap_len != SHA256_MAC_LEN) {
  521. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_FAIL
  522. "Missing or invalid required Responder Bootstrapping Key Hash attribute");
  523. return;
  524. }
  525. wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash",
  526. r_bootstrap, r_bootstrap_len);
  527. i_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_I_BOOTSTRAP_KEY_HASH,
  528. &i_bootstrap_len);
  529. if (!i_bootstrap || i_bootstrap_len != SHA256_MAC_LEN) {
  530. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_FAIL
  531. "Missing or invalid required Initiator Bootstrapping Key Hash attribute");
  532. return;
  533. }
  534. wpa_hexdump(MSG_MSGDUMP, "DPP: Initiator Bootstrapping Key Hash",
  535. i_bootstrap, i_bootstrap_len);
  536. /* Try to find own and peer bootstrapping key matches based on the
  537. * received hash values */
  538. dl_list_for_each(bi, &hapd->dpp_bootstrap, struct dpp_bootstrap_info,
  539. list) {
  540. if (!own_bi && bi->own &&
  541. os_memcmp(bi->pubkey_hash, r_bootstrap,
  542. SHA256_MAC_LEN) == 0) {
  543. wpa_printf(MSG_DEBUG,
  544. "DPP: Found matching own bootstrapping information");
  545. own_bi = bi;
  546. }
  547. if (!peer_bi && !bi->own &&
  548. os_memcmp(bi->pubkey_hash, i_bootstrap,
  549. SHA256_MAC_LEN) == 0) {
  550. wpa_printf(MSG_DEBUG,
  551. "DPP: Found matching peer bootstrapping information");
  552. peer_bi = bi;
  553. }
  554. if (own_bi && peer_bi)
  555. break;
  556. }
  557. if (!own_bi) {
  558. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_FAIL
  559. "No matching own bootstrapping key found - ignore message");
  560. return;
  561. }
  562. if (hapd->dpp_auth) {
  563. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_FAIL
  564. "Already in DPP authentication exchange - ignore new one");
  565. return;
  566. }
  567. hapd->dpp_auth_ok_on_ack = 0;
  568. hapd->dpp_auth = dpp_auth_req_rx(hapd->msg_ctx, hapd->dpp_allowed_roles,
  569. hapd->dpp_qr_mutual,
  570. peer_bi, own_bi, freq, hdr, buf, len);
  571. if (!hapd->dpp_auth) {
  572. wpa_printf(MSG_DEBUG, "DPP: No response generated");
  573. return;
  574. }
  575. hostapd_dpp_set_testing_options(hapd, hapd->dpp_auth);
  576. hostapd_dpp_set_configurator(hapd, hapd->dpp_auth,
  577. hapd->dpp_configurator_params);
  578. os_memcpy(hapd->dpp_auth->peer_mac_addr, src, ETH_ALEN);
  579. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
  580. " freq=%u type=%d",
  581. MAC2STR(src), hapd->dpp_auth->curr_freq,
  582. DPP_PA_AUTHENTICATION_RESP);
  583. hostapd_drv_send_action(hapd, hapd->dpp_auth->curr_freq, 0,
  584. src, wpabuf_head(hapd->dpp_auth->resp_msg),
  585. wpabuf_len(hapd->dpp_auth->resp_msg));
  586. }
  587. static void hostapd_dpp_gas_resp_cb(void *ctx, const u8 *addr, u8 dialog_token,
  588. enum gas_query_ap_result result,
  589. const struct wpabuf *adv_proto,
  590. const struct wpabuf *resp, u16 status_code)
  591. {
  592. struct hostapd_data *hapd = ctx;
  593. const u8 *pos;
  594. struct dpp_authentication *auth = hapd->dpp_auth;
  595. if (!auth || !auth->auth_success) {
  596. wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
  597. return;
  598. }
  599. if (!resp || status_code != WLAN_STATUS_SUCCESS) {
  600. wpa_printf(MSG_DEBUG, "DPP: GAS query did not succeed");
  601. goto fail;
  602. }
  603. wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response adv_proto",
  604. adv_proto);
  605. wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response (GAS response)",
  606. resp);
  607. if (wpabuf_len(adv_proto) != 10 ||
  608. !(pos = wpabuf_head(adv_proto)) ||
  609. pos[0] != WLAN_EID_ADV_PROTO ||
  610. pos[1] != 8 ||
  611. pos[3] != WLAN_EID_VENDOR_SPECIFIC ||
  612. pos[4] != 5 ||
  613. WPA_GET_BE24(&pos[5]) != OUI_WFA ||
  614. pos[8] != 0x1a ||
  615. pos[9] != 1) {
  616. wpa_printf(MSG_DEBUG,
  617. "DPP: Not a DPP Advertisement Protocol ID");
  618. goto fail;
  619. }
  620. if (dpp_conf_resp_rx(auth, resp) < 0) {
  621. wpa_printf(MSG_DEBUG, "DPP: Configuration attempt failed");
  622. goto fail;
  623. }
  624. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONF_RECEIVED);
  625. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONFOBJ_AKM "%s",
  626. dpp_akm_str(auth->akm));
  627. if (auth->ssid_len)
  628. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONFOBJ_SSID "%s",
  629. wpa_ssid_txt(auth->ssid, auth->ssid_len));
  630. if (auth->connector) {
  631. /* TODO: Save the Connector and consider using a command
  632. * to fetch the value instead of sending an event with
  633. * it. The Connector could end up being larger than what
  634. * most clients are ready to receive as an event
  635. * message. */
  636. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONNECTOR "%s",
  637. auth->connector);
  638. } else if (auth->passphrase[0]) {
  639. char hex[64 * 2 + 1];
  640. wpa_snprintf_hex(hex, sizeof(hex),
  641. (const u8 *) auth->passphrase,
  642. os_strlen(auth->passphrase));
  643. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONFOBJ_PASS "%s",
  644. hex);
  645. } else if (auth->psk_set) {
  646. char hex[PMK_LEN * 2 + 1];
  647. wpa_snprintf_hex(hex, sizeof(hex), auth->psk, PMK_LEN);
  648. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONFOBJ_PSK "%s",
  649. hex);
  650. }
  651. if (auth->c_sign_key) {
  652. char *hex;
  653. size_t hexlen;
  654. hexlen = 2 * wpabuf_len(auth->c_sign_key) + 1;
  655. hex = os_malloc(hexlen);
  656. if (hex) {
  657. wpa_snprintf_hex(hex, hexlen,
  658. wpabuf_head(auth->c_sign_key),
  659. wpabuf_len(auth->c_sign_key));
  660. wpa_msg(hapd->msg_ctx, MSG_INFO,
  661. DPP_EVENT_C_SIGN_KEY "%s", hex);
  662. os_free(hex);
  663. }
  664. }
  665. if (auth->net_access_key) {
  666. char *hex;
  667. size_t hexlen;
  668. hexlen = 2 * wpabuf_len(auth->net_access_key) + 1;
  669. hex = os_malloc(hexlen);
  670. if (hex) {
  671. wpa_snprintf_hex(hex, hexlen,
  672. wpabuf_head(auth->net_access_key),
  673. wpabuf_len(auth->net_access_key));
  674. if (auth->net_access_key_expiry)
  675. wpa_msg(hapd->msg_ctx, MSG_INFO,
  676. DPP_EVENT_NET_ACCESS_KEY "%s %lu", hex,
  677. (unsigned long)
  678. auth->net_access_key_expiry);
  679. else
  680. wpa_msg(hapd->msg_ctx, MSG_INFO,
  681. DPP_EVENT_NET_ACCESS_KEY "%s", hex);
  682. os_free(hex);
  683. }
  684. }
  685. dpp_auth_deinit(hapd->dpp_auth);
  686. hapd->dpp_auth = NULL;
  687. return;
  688. fail:
  689. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONF_FAILED);
  690. dpp_auth_deinit(hapd->dpp_auth);
  691. hapd->dpp_auth = NULL;
  692. }
  693. static void hostapd_dpp_start_gas_client(struct hostapd_data *hapd)
  694. {
  695. struct dpp_authentication *auth = hapd->dpp_auth;
  696. struct wpabuf *buf, *conf_req;
  697. char json[100];
  698. int res;
  699. int netrole_ap = 1;
  700. os_snprintf(json, sizeof(json),
  701. "{\"name\":\"Test\","
  702. "\"wi-fi_tech\":\"infra\","
  703. "\"netRole\":\"%s\"}",
  704. netrole_ap ? "ap" : "sta");
  705. wpa_printf(MSG_DEBUG, "DPP: GAS Config Attributes: %s", json);
  706. conf_req = dpp_build_conf_req(auth, json);
  707. if (!conf_req) {
  708. wpa_printf(MSG_DEBUG,
  709. "DPP: No configuration request data available");
  710. return;
  711. }
  712. buf = gas_build_initial_req(0, 10 + 2 + wpabuf_len(conf_req));
  713. if (!buf) {
  714. wpabuf_free(conf_req);
  715. return;
  716. }
  717. /* Advertisement Protocol IE */
  718. wpabuf_put_u8(buf, WLAN_EID_ADV_PROTO);
  719. wpabuf_put_u8(buf, 8); /* Length */
  720. wpabuf_put_u8(buf, 0x7f);
  721. wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
  722. wpabuf_put_u8(buf, 5);
  723. wpabuf_put_be24(buf, OUI_WFA);
  724. wpabuf_put_u8(buf, DPP_OUI_TYPE);
  725. wpabuf_put_u8(buf, 0x01);
  726. /* GAS Query */
  727. wpabuf_put_le16(buf, wpabuf_len(conf_req));
  728. wpabuf_put_buf(buf, conf_req);
  729. wpabuf_free(conf_req);
  730. wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)",
  731. MAC2STR(auth->peer_mac_addr), auth->curr_freq);
  732. res = gas_query_ap_req(hapd->gas, auth->peer_mac_addr, auth->curr_freq,
  733. buf, hostapd_dpp_gas_resp_cb, hapd);
  734. if (res < 0) {
  735. wpa_msg(hapd->msg_ctx, MSG_DEBUG,
  736. "GAS: Failed to send Query Request");
  737. wpabuf_free(buf);
  738. } else {
  739. wpa_printf(MSG_DEBUG,
  740. "DPP: GAS query started with dialog token %u", res);
  741. }
  742. }
  743. static void hostapd_dpp_auth_success(struct hostapd_data *hapd, int initiator)
  744. {
  745. wpa_printf(MSG_DEBUG, "DPP: Authentication succeeded");
  746. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=%d",
  747. initiator);
  748. if (!hapd->dpp_auth->configurator)
  749. hostapd_dpp_start_gas_client(hapd);
  750. }
  751. static void hostapd_dpp_rx_auth_resp(struct hostapd_data *hapd, const u8 *src,
  752. const u8 *hdr, const u8 *buf, size_t len)
  753. {
  754. struct dpp_authentication *auth = hapd->dpp_auth;
  755. struct wpabuf *msg;
  756. wpa_printf(MSG_DEBUG, "DPP: Authentication Response from " MACSTR,
  757. MAC2STR(src));
  758. if (!auth) {
  759. wpa_printf(MSG_DEBUG,
  760. "DPP: No DPP Authentication in progress - drop");
  761. return;
  762. }
  763. if (!is_zero_ether_addr(auth->peer_mac_addr) &&
  764. os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
  765. wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
  766. MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
  767. return;
  768. }
  769. msg = dpp_auth_resp_rx(auth, hdr, buf, len);
  770. if (!msg) {
  771. if (auth->auth_resp_status == DPP_STATUS_RESPONSE_PENDING) {
  772. wpa_printf(MSG_DEBUG, "DPP: Wait for full response");
  773. return;
  774. }
  775. wpa_printf(MSG_DEBUG, "DPP: No confirm generated");
  776. return;
  777. }
  778. os_memcpy(auth->peer_mac_addr, src, ETH_ALEN);
  779. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
  780. " freq=%u type=%d", MAC2STR(src), auth->curr_freq,
  781. DPP_PA_AUTHENTICATION_CONF);
  782. hostapd_drv_send_action(hapd, auth->curr_freq, 0, src,
  783. wpabuf_head(msg), wpabuf_len(msg));
  784. wpabuf_free(msg);
  785. hapd->dpp_auth_ok_on_ack = 1;
  786. }
  787. static void hostapd_dpp_rx_auth_conf(struct hostapd_data *hapd, const u8 *src,
  788. const u8 *hdr, const u8 *buf, size_t len)
  789. {
  790. struct dpp_authentication *auth = hapd->dpp_auth;
  791. wpa_printf(MSG_DEBUG, "DPP: Authentication Confirmation from " MACSTR,
  792. MAC2STR(src));
  793. if (!auth) {
  794. wpa_printf(MSG_DEBUG,
  795. "DPP: No DPP Authentication in progress - drop");
  796. return;
  797. }
  798. if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
  799. wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
  800. MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
  801. return;
  802. }
  803. if (dpp_auth_conf_rx(auth, hdr, buf, len) < 0) {
  804. wpa_printf(MSG_DEBUG, "DPP: Authentication failed");
  805. return;
  806. }
  807. hostapd_dpp_auth_success(hapd, 0);
  808. }
  809. static void hostapd_dpp_send_peer_disc_resp(struct hostapd_data *hapd,
  810. const u8 *src, unsigned int freq,
  811. u8 trans_id,
  812. enum dpp_status_error status)
  813. {
  814. struct wpabuf *msg;
  815. msg = dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_RESP,
  816. 5 + 5 + 4 + os_strlen(hapd->conf->dpp_connector));
  817. if (!msg)
  818. return;
  819. #ifdef CONFIG_TESTING_OPTIONS
  820. if (dpp_test == DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_RESP) {
  821. wpa_printf(MSG_INFO, "DPP: TESTING - no Transaction ID");
  822. goto skip_trans_id;
  823. }
  824. if (dpp_test == DPP_TEST_INVALID_TRANSACTION_ID_PEER_DISC_RESP) {
  825. wpa_printf(MSG_INFO, "DPP: TESTING - invalid Transaction ID");
  826. trans_id ^= 0x01;
  827. }
  828. #endif /* CONFIG_TESTING_OPTIONS */
  829. /* Transaction ID */
  830. wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
  831. wpabuf_put_le16(msg, 1);
  832. wpabuf_put_u8(msg, trans_id);
  833. #ifdef CONFIG_TESTING_OPTIONS
  834. skip_trans_id:
  835. if (dpp_test == DPP_TEST_NO_STATUS_PEER_DISC_RESP) {
  836. wpa_printf(MSG_INFO, "DPP: TESTING - no Status");
  837. goto skip_status;
  838. }
  839. if (dpp_test == DPP_TEST_INVALID_STATUS_PEER_DISC_RESP) {
  840. wpa_printf(MSG_INFO, "DPP: TESTING - invalid Status");
  841. status = 254;
  842. }
  843. #endif /* CONFIG_TESTING_OPTIONS */
  844. /* DPP Status */
  845. wpabuf_put_le16(msg, DPP_ATTR_STATUS);
  846. wpabuf_put_le16(msg, 1);
  847. wpabuf_put_u8(msg, status);
  848. #ifdef CONFIG_TESTING_OPTIONS
  849. skip_status:
  850. if (dpp_test == DPP_TEST_NO_CONNECTOR_PEER_DISC_RESP) {
  851. wpa_printf(MSG_INFO, "DPP: TESTING - no Connector");
  852. goto skip_connector;
  853. }
  854. if (status == DPP_STATUS_OK &&
  855. dpp_test == DPP_TEST_INVALID_CONNECTOR_PEER_DISC_RESP) {
  856. char *connector;
  857. wpa_printf(MSG_INFO, "DPP: TESTING - invalid Connector");
  858. connector = dpp_corrupt_connector_signature(
  859. hapd->conf->dpp_connector);
  860. if (!connector) {
  861. wpabuf_free(msg);
  862. return;
  863. }
  864. wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
  865. wpabuf_put_le16(msg, os_strlen(connector));
  866. wpabuf_put_str(msg, connector);
  867. os_free(connector);
  868. goto skip_connector;
  869. }
  870. #endif /* CONFIG_TESTING_OPTIONS */
  871. /* DPP Connector */
  872. if (status == DPP_STATUS_OK) {
  873. wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
  874. wpabuf_put_le16(msg, os_strlen(hapd->conf->dpp_connector));
  875. wpabuf_put_str(msg, hapd->conf->dpp_connector);
  876. }
  877. #ifdef CONFIG_TESTING_OPTIONS
  878. skip_connector:
  879. #endif /* CONFIG_TESTING_OPTIONS */
  880. wpa_printf(MSG_DEBUG, "DPP: Send Peer Discovery Response to " MACSTR
  881. " status=%d", MAC2STR(src), status);
  882. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
  883. " freq=%u type=%d status=%d", MAC2STR(src), freq,
  884. DPP_PA_PEER_DISCOVERY_RESP, status);
  885. hostapd_drv_send_action(hapd, freq, 0, src,
  886. wpabuf_head(msg), wpabuf_len(msg));
  887. wpabuf_free(msg);
  888. }
  889. static void hostapd_dpp_rx_peer_disc_req(struct hostapd_data *hapd,
  890. const u8 *src,
  891. const u8 *buf, size_t len,
  892. unsigned int freq)
  893. {
  894. const u8 *connector, *trans_id;
  895. u16 connector_len, trans_id_len;
  896. struct os_time now;
  897. struct dpp_introduction intro;
  898. os_time_t expire;
  899. int expiration;
  900. enum dpp_status_error res;
  901. wpa_printf(MSG_DEBUG, "DPP: Peer Discovery Request from " MACSTR,
  902. MAC2STR(src));
  903. if (!hapd->wpa_auth ||
  904. !(hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) ||
  905. !(hapd->conf->wpa & WPA_PROTO_RSN)) {
  906. wpa_printf(MSG_DEBUG, "DPP: DPP AKM not in use");
  907. return;
  908. }
  909. if (!hapd->conf->dpp_connector || !hapd->conf->dpp_netaccesskey ||
  910. !hapd->conf->dpp_csign) {
  911. wpa_printf(MSG_DEBUG, "DPP: No own Connector/keys set");
  912. return;
  913. }
  914. os_get_time(&now);
  915. if (hapd->conf->dpp_netaccesskey_expiry &&
  916. (os_time_t) hapd->conf->dpp_netaccesskey_expiry < now.sec) {
  917. wpa_printf(MSG_INFO, "DPP: Own netAccessKey expired");
  918. return;
  919. }
  920. trans_id = dpp_get_attr(buf, len, DPP_ATTR_TRANSACTION_ID,
  921. &trans_id_len);
  922. if (!trans_id || trans_id_len != 1) {
  923. wpa_printf(MSG_DEBUG,
  924. "DPP: Peer did not include Transaction ID");
  925. return;
  926. }
  927. connector = dpp_get_attr(buf, len, DPP_ATTR_CONNECTOR, &connector_len);
  928. if (!connector) {
  929. wpa_printf(MSG_DEBUG,
  930. "DPP: Peer did not include its Connector");
  931. return;
  932. }
  933. res = dpp_peer_intro(&intro, hapd->conf->dpp_connector,
  934. wpabuf_head(hapd->conf->dpp_netaccesskey),
  935. wpabuf_len(hapd->conf->dpp_netaccesskey),
  936. wpabuf_head(hapd->conf->dpp_csign),
  937. wpabuf_len(hapd->conf->dpp_csign),
  938. connector, connector_len, &expire);
  939. if (res == 255) {
  940. wpa_printf(MSG_INFO,
  941. "DPP: Network Introduction protocol resulted in internal failure (peer "
  942. MACSTR ")", MAC2STR(src));
  943. return;
  944. }
  945. if (res != DPP_STATUS_OK) {
  946. wpa_printf(MSG_INFO,
  947. "DPP: Network Introduction protocol resulted in failure (peer "
  948. MACSTR " status %d)", MAC2STR(src), res);
  949. hostapd_dpp_send_peer_disc_resp(hapd, src, freq, trans_id[0],
  950. res);
  951. return;
  952. }
  953. if (!expire || (os_time_t) hapd->conf->dpp_netaccesskey_expiry < expire)
  954. expire = hapd->conf->dpp_netaccesskey_expiry;
  955. if (expire)
  956. expiration = expire - now.sec;
  957. else
  958. expiration = 0;
  959. if (wpa_auth_pmksa_add2(hapd->wpa_auth, src, intro.pmk, intro.pmk_len,
  960. intro.pmkid, expiration,
  961. WPA_KEY_MGMT_DPP) < 0) {
  962. wpa_printf(MSG_ERROR, "DPP: Failed to add PMKSA cache entry");
  963. return;
  964. }
  965. hostapd_dpp_send_peer_disc_resp(hapd, src, freq, trans_id[0],
  966. DPP_STATUS_OK);
  967. }
  968. static void
  969. hostapd_dpp_rx_pkex_exchange_req(struct hostapd_data *hapd, const u8 *src,
  970. const u8 *buf, size_t len,
  971. unsigned int freq)
  972. {
  973. struct wpabuf *msg;
  974. wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Request from " MACSTR,
  975. MAC2STR(src));
  976. /* TODO: Support multiple PKEX codes by iterating over all the enabled
  977. * values here */
  978. if (!hapd->dpp_pkex_code || !hapd->dpp_pkex_bi) {
  979. wpa_printf(MSG_DEBUG,
  980. "DPP: No PKEX code configured - ignore request");
  981. return;
  982. }
  983. if (hapd->dpp_pkex) {
  984. /* TODO: Support parallel operations */
  985. wpa_printf(MSG_DEBUG,
  986. "DPP: Already in PKEX session - ignore new request");
  987. return;
  988. }
  989. hapd->dpp_pkex = dpp_pkex_rx_exchange_req(hapd->msg_ctx,
  990. hapd->dpp_pkex_bi,
  991. hapd->own_addr, src,
  992. hapd->dpp_pkex_identifier,
  993. hapd->dpp_pkex_code,
  994. buf, len);
  995. if (!hapd->dpp_pkex) {
  996. wpa_printf(MSG_DEBUG,
  997. "DPP: Failed to process the request - ignore it");
  998. return;
  999. }
  1000. msg = hapd->dpp_pkex->exchange_resp;
  1001. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
  1002. " freq=%u type=%d", MAC2STR(src), freq,
  1003. DPP_PA_PKEX_EXCHANGE_RESP);
  1004. hostapd_drv_send_action(hapd, freq, 0, src,
  1005. wpabuf_head(msg), wpabuf_len(msg));
  1006. if (hapd->dpp_pkex->failed) {
  1007. wpa_printf(MSG_DEBUG,
  1008. "DPP: Terminate PKEX exchange due to an earlier error");
  1009. if (hapd->dpp_pkex->t > hapd->dpp_pkex->own_bi->pkex_t)
  1010. hapd->dpp_pkex->own_bi->pkex_t = hapd->dpp_pkex->t;
  1011. dpp_pkex_free(hapd->dpp_pkex);
  1012. hapd->dpp_pkex = NULL;
  1013. }
  1014. }
  1015. static void
  1016. hostapd_dpp_rx_pkex_exchange_resp(struct hostapd_data *hapd, const u8 *src,
  1017. const u8 *buf, size_t len, unsigned int freq)
  1018. {
  1019. struct wpabuf *msg;
  1020. wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Response from " MACSTR,
  1021. MAC2STR(src));
  1022. /* TODO: Support multiple PKEX codes by iterating over all the enabled
  1023. * values here */
  1024. if (!hapd->dpp_pkex || !hapd->dpp_pkex->initiator ||
  1025. hapd->dpp_pkex->exchange_done) {
  1026. wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
  1027. return;
  1028. }
  1029. os_memcpy(hapd->dpp_pkex->peer_mac, src, ETH_ALEN);
  1030. msg = dpp_pkex_rx_exchange_resp(hapd->dpp_pkex, buf, len);
  1031. if (!msg) {
  1032. wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
  1033. return;
  1034. }
  1035. wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Request to " MACSTR,
  1036. MAC2STR(src));
  1037. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
  1038. " freq=%u type=%d", MAC2STR(src), freq,
  1039. DPP_PA_PKEX_COMMIT_REVEAL_REQ);
  1040. hostapd_drv_send_action(hapd, freq, 0, src,
  1041. wpabuf_head(msg), wpabuf_len(msg));
  1042. wpabuf_free(msg);
  1043. }
  1044. static void
  1045. hostapd_dpp_rx_pkex_commit_reveal_req(struct hostapd_data *hapd, const u8 *src,
  1046. const u8 *hdr, const u8 *buf, size_t len,
  1047. unsigned int freq)
  1048. {
  1049. struct wpabuf *msg;
  1050. struct dpp_pkex *pkex = hapd->dpp_pkex;
  1051. struct dpp_bootstrap_info *bi;
  1052. wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Request from " MACSTR,
  1053. MAC2STR(src));
  1054. if (!pkex || pkex->initiator || !pkex->exchange_done) {
  1055. wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
  1056. return;
  1057. }
  1058. msg = dpp_pkex_rx_commit_reveal_req(pkex, hdr, buf, len);
  1059. if (!msg) {
  1060. wpa_printf(MSG_DEBUG, "DPP: Failed to process the request");
  1061. if (hapd->dpp_pkex->failed) {
  1062. wpa_printf(MSG_DEBUG, "DPP: Terminate PKEX exchange");
  1063. if (hapd->dpp_pkex->t > hapd->dpp_pkex->own_bi->pkex_t)
  1064. hapd->dpp_pkex->own_bi->pkex_t =
  1065. hapd->dpp_pkex->t;
  1066. dpp_pkex_free(hapd->dpp_pkex);
  1067. hapd->dpp_pkex = NULL;
  1068. }
  1069. return;
  1070. }
  1071. wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Response to "
  1072. MACSTR, MAC2STR(src));
  1073. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
  1074. " freq=%u type=%d", MAC2STR(src), freq,
  1075. DPP_PA_PKEX_COMMIT_REVEAL_RESP);
  1076. hostapd_drv_send_action(hapd, freq, 0, src,
  1077. wpabuf_head(msg), wpabuf_len(msg));
  1078. wpabuf_free(msg);
  1079. bi = os_zalloc(sizeof(*bi));
  1080. if (!bi)
  1081. return;
  1082. bi->id = hapd_dpp_next_id(hapd);
  1083. bi->type = DPP_BOOTSTRAP_PKEX;
  1084. os_memcpy(bi->mac_addr, src, ETH_ALEN);
  1085. bi->num_freq = 1;
  1086. bi->freq[0] = freq;
  1087. bi->curve = pkex->own_bi->curve;
  1088. bi->pubkey = pkex->peer_bootstrap_key;
  1089. pkex->peer_bootstrap_key = NULL;
  1090. dpp_pkex_free(pkex);
  1091. hapd->dpp_pkex = NULL;
  1092. if (dpp_bootstrap_key_hash(bi) < 0) {
  1093. dpp_bootstrap_info_free(bi);
  1094. return;
  1095. }
  1096. dl_list_add(&hapd->dpp_bootstrap, &bi->list);
  1097. }
  1098. static void
  1099. hostapd_dpp_rx_pkex_commit_reveal_resp(struct hostapd_data *hapd, const u8 *src,
  1100. const u8 *hdr, const u8 *buf, size_t len,
  1101. unsigned int freq)
  1102. {
  1103. int res;
  1104. struct dpp_bootstrap_info *bi, *own_bi;
  1105. struct dpp_pkex *pkex = hapd->dpp_pkex;
  1106. char cmd[500];
  1107. wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Response from " MACSTR,
  1108. MAC2STR(src));
  1109. if (!pkex || !pkex->initiator || !pkex->exchange_done) {
  1110. wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
  1111. return;
  1112. }
  1113. res = dpp_pkex_rx_commit_reveal_resp(pkex, hdr, buf, len);
  1114. if (res < 0) {
  1115. wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
  1116. return;
  1117. }
  1118. own_bi = pkex->own_bi;
  1119. bi = os_zalloc(sizeof(*bi));
  1120. if (!bi)
  1121. return;
  1122. bi->id = hapd_dpp_next_id(hapd);
  1123. bi->type = DPP_BOOTSTRAP_PKEX;
  1124. os_memcpy(bi->mac_addr, src, ETH_ALEN);
  1125. bi->num_freq = 1;
  1126. bi->freq[0] = freq;
  1127. bi->curve = own_bi->curve;
  1128. bi->pubkey = pkex->peer_bootstrap_key;
  1129. pkex->peer_bootstrap_key = NULL;
  1130. dpp_pkex_free(pkex);
  1131. hapd->dpp_pkex = NULL;
  1132. if (dpp_bootstrap_key_hash(bi) < 0) {
  1133. dpp_bootstrap_info_free(bi);
  1134. return;
  1135. }
  1136. dl_list_add(&hapd->dpp_bootstrap, &bi->list);
  1137. os_snprintf(cmd, sizeof(cmd), " peer=%u %s",
  1138. bi->id,
  1139. hapd->dpp_pkex_auth_cmd ? hapd->dpp_pkex_auth_cmd : "");
  1140. wpa_printf(MSG_DEBUG,
  1141. "DPP: Start authentication after PKEX with parameters: %s",
  1142. cmd);
  1143. if (hostapd_dpp_auth_init(hapd, cmd) < 0) {
  1144. wpa_printf(MSG_DEBUG,
  1145. "DPP: Authentication initialization failed");
  1146. return;
  1147. }
  1148. }
  1149. void hostapd_dpp_rx_action(struct hostapd_data *hapd, const u8 *src,
  1150. const u8 *buf, size_t len, unsigned int freq)
  1151. {
  1152. u8 crypto_suite;
  1153. enum dpp_public_action_frame_type type;
  1154. const u8 *hdr;
  1155. unsigned int pkex_t;
  1156. if (len < DPP_HDR_LEN)
  1157. return;
  1158. if (WPA_GET_BE24(buf) != OUI_WFA || buf[3] != DPP_OUI_TYPE)
  1159. return;
  1160. hdr = buf;
  1161. buf += 4;
  1162. len -= 4;
  1163. crypto_suite = *buf++;
  1164. type = *buf++;
  1165. len -= 2;
  1166. wpa_printf(MSG_DEBUG,
  1167. "DPP: Received DPP Public Action frame crypto suite %u type %d from "
  1168. MACSTR " freq=%u",
  1169. crypto_suite, type, MAC2STR(src), freq);
  1170. if (crypto_suite != 1) {
  1171. wpa_printf(MSG_DEBUG, "DPP: Unsupported crypto suite %u",
  1172. crypto_suite);
  1173. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
  1174. " freq=%u type=%d ignore=unsupported-crypto-suite",
  1175. MAC2STR(src), freq, type);
  1176. return;
  1177. }
  1178. wpa_hexdump(MSG_MSGDUMP, "DPP: Received message attributes", buf, len);
  1179. if (dpp_check_attrs(buf, len) < 0) {
  1180. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
  1181. " freq=%u type=%d ignore=invalid-attributes",
  1182. MAC2STR(src), freq, type);
  1183. return;
  1184. }
  1185. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
  1186. " freq=%u type=%d", MAC2STR(src), freq, type);
  1187. switch (type) {
  1188. case DPP_PA_AUTHENTICATION_REQ:
  1189. hostapd_dpp_rx_auth_req(hapd, src, hdr, buf, len, freq);
  1190. break;
  1191. case DPP_PA_AUTHENTICATION_RESP:
  1192. hostapd_dpp_rx_auth_resp(hapd, src, hdr, buf, len);
  1193. break;
  1194. case DPP_PA_AUTHENTICATION_CONF:
  1195. hostapd_dpp_rx_auth_conf(hapd, src, hdr, buf, len);
  1196. break;
  1197. case DPP_PA_PEER_DISCOVERY_REQ:
  1198. hostapd_dpp_rx_peer_disc_req(hapd, src, buf, len, freq);
  1199. break;
  1200. case DPP_PA_PKEX_EXCHANGE_REQ:
  1201. hostapd_dpp_rx_pkex_exchange_req(hapd, src, buf, len, freq);
  1202. break;
  1203. case DPP_PA_PKEX_EXCHANGE_RESP:
  1204. hostapd_dpp_rx_pkex_exchange_resp(hapd, src, buf, len, freq);
  1205. break;
  1206. case DPP_PA_PKEX_COMMIT_REVEAL_REQ:
  1207. hostapd_dpp_rx_pkex_commit_reveal_req(hapd, src, hdr, buf, len,
  1208. freq);
  1209. break;
  1210. case DPP_PA_PKEX_COMMIT_REVEAL_RESP:
  1211. hostapd_dpp_rx_pkex_commit_reveal_resp(hapd, src, hdr, buf, len,
  1212. freq);
  1213. break;
  1214. default:
  1215. wpa_printf(MSG_DEBUG,
  1216. "DPP: Ignored unsupported frame subtype %d", type);
  1217. break;
  1218. }
  1219. if (hapd->dpp_pkex)
  1220. pkex_t = hapd->dpp_pkex->t;
  1221. else if (hapd->dpp_pkex_bi)
  1222. pkex_t = hapd->dpp_pkex_bi->pkex_t;
  1223. else
  1224. pkex_t = 0;
  1225. if (pkex_t >= PKEX_COUNTER_T_LIMIT) {
  1226. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_PKEX_T_LIMIT "id=0");
  1227. hostapd_dpp_pkex_remove(hapd, "*");
  1228. }
  1229. }
  1230. struct wpabuf *
  1231. hostapd_dpp_gas_req_handler(struct hostapd_data *hapd, const u8 *sa,
  1232. const u8 *query, size_t query_len)
  1233. {
  1234. struct dpp_authentication *auth = hapd->dpp_auth;
  1235. struct wpabuf *resp;
  1236. wpa_printf(MSG_DEBUG, "DPP: GAS request from " MACSTR, MAC2STR(sa));
  1237. if (!auth || !auth->auth_success ||
  1238. os_memcmp(sa, auth->peer_mac_addr, ETH_ALEN) != 0) {
  1239. wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
  1240. return NULL;
  1241. }
  1242. wpa_hexdump(MSG_DEBUG,
  1243. "DPP: Received Configuration Request (GAS Query Request)",
  1244. query, query_len);
  1245. resp = dpp_conf_req_rx(auth, query, query_len);
  1246. if (!resp)
  1247. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_CONF_FAILED);
  1248. return resp;
  1249. }
  1250. static unsigned int hostapd_dpp_next_configurator_id(struct hostapd_data *hapd)
  1251. {
  1252. struct dpp_configurator *conf;
  1253. unsigned int max_id = 0;
  1254. dl_list_for_each(conf, &hapd->dpp_configurator,
  1255. struct dpp_configurator, list) {
  1256. if (conf->id > max_id)
  1257. max_id = conf->id;
  1258. }
  1259. return max_id + 1;
  1260. }
  1261. int hostapd_dpp_configurator_add(struct hostapd_data *hapd, const char *cmd)
  1262. {
  1263. char *curve = NULL;
  1264. char *key = NULL;
  1265. u8 *privkey = NULL;
  1266. size_t privkey_len = 0;
  1267. int ret = -1;
  1268. struct dpp_configurator *conf = NULL;
  1269. curve = get_param(cmd, " curve=");
  1270. key = get_param(cmd, " key=");
  1271. if (key) {
  1272. privkey_len = os_strlen(key) / 2;
  1273. privkey = os_malloc(privkey_len);
  1274. if (!privkey ||
  1275. hexstr2bin(key, privkey, privkey_len) < 0)
  1276. goto fail;
  1277. }
  1278. conf = dpp_keygen_configurator(curve, privkey, privkey_len);
  1279. if (!conf)
  1280. goto fail;
  1281. conf->id = hostapd_dpp_next_configurator_id(hapd);
  1282. dl_list_add(&hapd->dpp_configurator, &conf->list);
  1283. ret = conf->id;
  1284. conf = NULL;
  1285. fail:
  1286. os_free(curve);
  1287. str_clear_free(key);
  1288. bin_clear_free(privkey, privkey_len);
  1289. dpp_configurator_free(conf);
  1290. return ret;
  1291. }
  1292. static int dpp_configurator_del(struct hostapd_data *hapd, unsigned int id)
  1293. {
  1294. struct dpp_configurator *conf, *tmp;
  1295. int found = 0;
  1296. dl_list_for_each_safe(conf, tmp, &hapd->dpp_configurator,
  1297. struct dpp_configurator, list) {
  1298. if (id && conf->id != id)
  1299. continue;
  1300. found = 1;
  1301. dl_list_del(&conf->list);
  1302. dpp_configurator_free(conf);
  1303. }
  1304. if (id == 0)
  1305. return 0; /* flush succeeds regardless of entries found */
  1306. return found ? 0 : -1;
  1307. }
  1308. int hostapd_dpp_configurator_remove(struct hostapd_data *hapd, const char *id)
  1309. {
  1310. unsigned int id_val;
  1311. if (os_strcmp(id, "*") == 0) {
  1312. id_val = 0;
  1313. } else {
  1314. id_val = atoi(id);
  1315. if (id_val == 0)
  1316. return -1;
  1317. }
  1318. return dpp_configurator_del(hapd, id_val);
  1319. }
  1320. int hostapd_dpp_pkex_add(struct hostapd_data *hapd, const char *cmd)
  1321. {
  1322. struct dpp_bootstrap_info *own_bi;
  1323. const char *pos, *end;
  1324. pos = os_strstr(cmd, " own=");
  1325. if (!pos)
  1326. return -1;
  1327. pos += 5;
  1328. own_bi = dpp_bootstrap_get_id(hapd, atoi(pos));
  1329. if (!own_bi) {
  1330. wpa_printf(MSG_DEBUG,
  1331. "DPP: Identified bootstrap info not found");
  1332. return -1;
  1333. }
  1334. if (own_bi->type != DPP_BOOTSTRAP_PKEX) {
  1335. wpa_printf(MSG_DEBUG,
  1336. "DPP: Identified bootstrap info not for PKEX");
  1337. return -1;
  1338. }
  1339. hapd->dpp_pkex_bi = own_bi;
  1340. own_bi->pkex_t = 0; /* clear pending errors on new code */
  1341. os_free(hapd->dpp_pkex_identifier);
  1342. hapd->dpp_pkex_identifier = NULL;
  1343. pos = os_strstr(cmd, " identifier=");
  1344. if (pos) {
  1345. pos += 12;
  1346. end = os_strchr(pos, ' ');
  1347. if (!end)
  1348. return -1;
  1349. hapd->dpp_pkex_identifier = os_malloc(end - pos + 1);
  1350. if (!hapd->dpp_pkex_identifier)
  1351. return -1;
  1352. os_memcpy(hapd->dpp_pkex_identifier, pos, end - pos);
  1353. hapd->dpp_pkex_identifier[end - pos] = '\0';
  1354. }
  1355. pos = os_strstr(cmd, " code=");
  1356. if (!pos)
  1357. return -1;
  1358. os_free(hapd->dpp_pkex_code);
  1359. hapd->dpp_pkex_code = os_strdup(pos + 6);
  1360. if (!hapd->dpp_pkex_code)
  1361. return -1;
  1362. if (os_strstr(cmd, " init=1")) {
  1363. struct wpabuf *msg;
  1364. wpa_printf(MSG_DEBUG, "DPP: Initiating PKEX");
  1365. dpp_pkex_free(hapd->dpp_pkex);
  1366. hapd->dpp_pkex = dpp_pkex_init(hapd->msg_ctx, own_bi,
  1367. hapd->own_addr,
  1368. hapd->dpp_pkex_identifier,
  1369. hapd->dpp_pkex_code);
  1370. if (!hapd->dpp_pkex)
  1371. return -1;
  1372. msg = hapd->dpp_pkex->exchange_req;
  1373. /* TODO: Which channel to use? */
  1374. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
  1375. " freq=%u type=%d", MAC2STR(broadcast), 2437,
  1376. DPP_PA_PKEX_EXCHANGE_REQ);
  1377. hostapd_drv_send_action(hapd, 2437, 0, broadcast,
  1378. wpabuf_head(msg), wpabuf_len(msg));
  1379. }
  1380. /* TODO: Support multiple PKEX info entries */
  1381. os_free(hapd->dpp_pkex_auth_cmd);
  1382. hapd->dpp_pkex_auth_cmd = os_strdup(cmd);
  1383. return 1;
  1384. }
  1385. int hostapd_dpp_pkex_remove(struct hostapd_data *hapd, const char *id)
  1386. {
  1387. unsigned int id_val;
  1388. if (os_strcmp(id, "*") == 0) {
  1389. id_val = 0;
  1390. } else {
  1391. id_val = atoi(id);
  1392. if (id_val == 0)
  1393. return -1;
  1394. }
  1395. if ((id_val != 0 && id_val != 1) || !hapd->dpp_pkex_code)
  1396. return -1;
  1397. /* TODO: Support multiple PKEX entries */
  1398. os_free(hapd->dpp_pkex_code);
  1399. hapd->dpp_pkex_code = NULL;
  1400. os_free(hapd->dpp_pkex_identifier);
  1401. hapd->dpp_pkex_identifier = NULL;
  1402. os_free(hapd->dpp_pkex_auth_cmd);
  1403. hapd->dpp_pkex_auth_cmd = NULL;
  1404. hapd->dpp_pkex_bi = NULL;
  1405. /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */
  1406. dpp_pkex_free(hapd->dpp_pkex);
  1407. hapd->dpp_pkex = NULL;
  1408. return 0;
  1409. }
  1410. void hostapd_dpp_stop(struct hostapd_data *hapd)
  1411. {
  1412. dpp_auth_deinit(hapd->dpp_auth);
  1413. hapd->dpp_auth = NULL;
  1414. }
  1415. int hostapd_dpp_init(struct hostapd_data *hapd)
  1416. {
  1417. dl_list_init(&hapd->dpp_bootstrap);
  1418. dl_list_init(&hapd->dpp_configurator);
  1419. hapd->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR | DPP_CAPAB_ENROLLEE;
  1420. hapd->dpp_init_done = 1;
  1421. return 0;
  1422. }
  1423. void hostapd_dpp_deinit(struct hostapd_data *hapd)
  1424. {
  1425. #ifdef CONFIG_TESTING_OPTIONS
  1426. os_free(hapd->dpp_config_obj_override);
  1427. hapd->dpp_config_obj_override = NULL;
  1428. os_free(hapd->dpp_discovery_override);
  1429. hapd->dpp_discovery_override = NULL;
  1430. os_free(hapd->dpp_groups_override);
  1431. hapd->dpp_groups_override = NULL;
  1432. hapd->dpp_ignore_netaccesskey_mismatch = 0;
  1433. #endif /* CONFIG_TESTING_OPTIONS */
  1434. if (!hapd->dpp_init_done)
  1435. return;
  1436. dpp_bootstrap_del(hapd, 0);
  1437. dpp_configurator_del(hapd, 0);
  1438. dpp_auth_deinit(hapd->dpp_auth);
  1439. hapd->dpp_auth = NULL;
  1440. hostapd_dpp_pkex_remove(hapd, "*");
  1441. hapd->dpp_pkex = NULL;
  1442. os_free(hapd->dpp_configurator_params);
  1443. hapd->dpp_configurator_params = NULL;
  1444. }