dpp_supplicant.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248
  1. /*
  2. * wpa_supplicant - DPP
  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/gas_server.h"
  14. #include "rsn_supp/wpa.h"
  15. #include "rsn_supp/pmksa_cache.h"
  16. #include "wpa_supplicant_i.h"
  17. #include "config.h"
  18. #include "driver_i.h"
  19. #include "offchannel.h"
  20. #include "gas_query.h"
  21. #include "bss.h"
  22. #include "scan.h"
  23. #include "notify.h"
  24. #include "dpp_supplicant.h"
  25. static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
  26. unsigned int freq);
  27. static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx);
  28. static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator);
  29. static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s,
  30. unsigned int freq, const u8 *dst,
  31. const u8 *src, const u8 *bssid,
  32. const u8 *data, size_t data_len,
  33. enum offchannel_send_action_result result);
  34. static void wpas_dpp_init_timeout(void *eloop_ctx, void *timeout_ctx);
  35. static int wpas_dpp_auth_init_next(struct wpa_supplicant *wpa_s);
  36. static const u8 broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  37. /* Use a hardcoded Transaction ID 1 in Peer Discovery frames since there is only
  38. * a single transaction in progress at any point in time. */
  39. static const u8 TRANSACTION_ID = 1;
  40. static struct dpp_configurator *
  41. dpp_configurator_get_id(struct wpa_supplicant *wpa_s, unsigned int id)
  42. {
  43. struct dpp_configurator *conf;
  44. dl_list_for_each(conf, &wpa_s->dpp_configurator,
  45. struct dpp_configurator, list) {
  46. if (conf->id == id)
  47. return conf;
  48. }
  49. return NULL;
  50. }
  51. static unsigned int wpas_dpp_next_id(struct wpa_supplicant *wpa_s)
  52. {
  53. struct dpp_bootstrap_info *bi;
  54. unsigned int max_id = 0;
  55. dl_list_for_each(bi, &wpa_s->dpp_bootstrap, struct dpp_bootstrap_info,
  56. list) {
  57. if (bi->id > max_id)
  58. max_id = bi->id;
  59. }
  60. return max_id + 1;
  61. }
  62. /**
  63. * wpas_dpp_qr_code - Parse and add DPP bootstrapping info from a QR Code
  64. * @wpa_s: Pointer to wpa_supplicant data
  65. * @cmd: DPP URI read from a QR Code
  66. * Returns: Identifier of the stored info or -1 on failure
  67. */
  68. int wpas_dpp_qr_code(struct wpa_supplicant *wpa_s, const char *cmd)
  69. {
  70. struct dpp_bootstrap_info *bi;
  71. struct dpp_authentication *auth = wpa_s->dpp_auth;
  72. bi = dpp_parse_qr_code(cmd);
  73. if (!bi)
  74. return -1;
  75. bi->id = wpas_dpp_next_id(wpa_s);
  76. dl_list_add(&wpa_s->dpp_bootstrap, &bi->list);
  77. if (auth && auth->response_pending &&
  78. dpp_notify_new_qr_code(auth, bi) == 1) {
  79. wpa_printf(MSG_DEBUG,
  80. "DPP: Sending out pending authentication response");
  81. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
  82. " freq=%u type=%d",
  83. MAC2STR(auth->peer_mac_addr), auth->curr_freq,
  84. DPP_PA_AUTHENTICATION_RESP);
  85. offchannel_send_action(wpa_s, auth->curr_freq,
  86. auth->peer_mac_addr, wpa_s->own_addr,
  87. broadcast,
  88. wpabuf_head(auth->resp_msg),
  89. wpabuf_len(auth->resp_msg),
  90. 500, wpas_dpp_tx_status, 0);
  91. }
  92. return bi->id;
  93. }
  94. static char * get_param(const char *cmd, const char *param)
  95. {
  96. const char *pos, *end;
  97. char *val;
  98. size_t len;
  99. pos = os_strstr(cmd, param);
  100. if (!pos)
  101. return NULL;
  102. pos += os_strlen(param);
  103. end = os_strchr(pos, ' ');
  104. if (end)
  105. len = end - pos;
  106. else
  107. len = os_strlen(pos);
  108. val = os_malloc(len + 1);
  109. if (!val)
  110. return NULL;
  111. os_memcpy(val, pos, len);
  112. val[len] = '\0';
  113. return val;
  114. }
  115. int wpas_dpp_bootstrap_gen(struct wpa_supplicant *wpa_s, const char *cmd)
  116. {
  117. char *chan = NULL, *mac = NULL, *info = NULL, *pk = NULL, *curve = NULL;
  118. char *key = NULL;
  119. u8 *privkey = NULL;
  120. size_t privkey_len = 0;
  121. size_t len;
  122. int ret = -1;
  123. struct dpp_bootstrap_info *bi;
  124. bi = os_zalloc(sizeof(*bi));
  125. if (!bi)
  126. goto fail;
  127. if (os_strstr(cmd, "type=qrcode"))
  128. bi->type = DPP_BOOTSTRAP_QR_CODE;
  129. else if (os_strstr(cmd, "type=pkex"))
  130. bi->type = DPP_BOOTSTRAP_PKEX;
  131. else
  132. goto fail;
  133. chan = get_param(cmd, " chan=");
  134. mac = get_param(cmd, " mac=");
  135. info = get_param(cmd, " info=");
  136. curve = get_param(cmd, " curve=");
  137. key = get_param(cmd, " key=");
  138. if (key) {
  139. privkey_len = os_strlen(key) / 2;
  140. privkey = os_malloc(privkey_len);
  141. if (!privkey ||
  142. hexstr2bin(key, privkey, privkey_len) < 0)
  143. goto fail;
  144. }
  145. pk = dpp_keygen(bi, curve, privkey, privkey_len);
  146. if (!pk)
  147. goto fail;
  148. len = 4; /* "DPP:" */
  149. if (chan) {
  150. if (dpp_parse_uri_chan_list(bi, chan) < 0)
  151. goto fail;
  152. len += 3 + os_strlen(chan); /* C:...; */
  153. }
  154. if (mac) {
  155. if (dpp_parse_uri_mac(bi, mac) < 0)
  156. goto fail;
  157. len += 3 + os_strlen(mac); /* M:...; */
  158. }
  159. if (info) {
  160. if (dpp_parse_uri_info(bi, info) < 0)
  161. goto fail;
  162. len += 3 + os_strlen(info); /* I:...; */
  163. }
  164. len += 4 + os_strlen(pk);
  165. bi->uri = os_malloc(len + 1);
  166. if (!bi->uri)
  167. goto fail;
  168. os_snprintf(bi->uri, len + 1, "DPP:%s%s%s%s%s%s%s%s%sK:%s;;",
  169. chan ? "C:" : "", chan ? chan : "", chan ? ";" : "",
  170. mac ? "M:" : "", mac ? mac : "", mac ? ";" : "",
  171. info ? "I:" : "", info ? info : "", info ? ";" : "",
  172. pk);
  173. bi->id = wpas_dpp_next_id(wpa_s);
  174. dl_list_add(&wpa_s->dpp_bootstrap, &bi->list);
  175. ret = bi->id;
  176. bi = NULL;
  177. fail:
  178. os_free(curve);
  179. os_free(pk);
  180. os_free(chan);
  181. os_free(mac);
  182. os_free(info);
  183. str_clear_free(key);
  184. bin_clear_free(privkey, privkey_len);
  185. dpp_bootstrap_info_free(bi);
  186. return ret;
  187. }
  188. static struct dpp_bootstrap_info *
  189. dpp_bootstrap_get_id(struct wpa_supplicant *wpa_s, unsigned int id)
  190. {
  191. struct dpp_bootstrap_info *bi;
  192. dl_list_for_each(bi, &wpa_s->dpp_bootstrap, struct dpp_bootstrap_info,
  193. list) {
  194. if (bi->id == id)
  195. return bi;
  196. }
  197. return NULL;
  198. }
  199. static int dpp_bootstrap_del(struct wpa_supplicant *wpa_s, unsigned int id)
  200. {
  201. struct dpp_bootstrap_info *bi, *tmp;
  202. int found = 0;
  203. dl_list_for_each_safe(bi, tmp, &wpa_s->dpp_bootstrap,
  204. struct dpp_bootstrap_info, list) {
  205. if (id && bi->id != id)
  206. continue;
  207. found = 1;
  208. dl_list_del(&bi->list);
  209. dpp_bootstrap_info_free(bi);
  210. }
  211. if (id == 0)
  212. return 0; /* flush succeeds regardless of entries found */
  213. return found ? 0 : -1;
  214. }
  215. int wpas_dpp_bootstrap_remove(struct wpa_supplicant *wpa_s, const char *id)
  216. {
  217. unsigned int id_val;
  218. if (os_strcmp(id, "*") == 0) {
  219. id_val = 0;
  220. } else {
  221. id_val = atoi(id);
  222. if (id_val == 0)
  223. return -1;
  224. }
  225. return dpp_bootstrap_del(wpa_s, id_val);
  226. }
  227. const char * wpas_dpp_bootstrap_get_uri(struct wpa_supplicant *wpa_s,
  228. unsigned int id)
  229. {
  230. struct dpp_bootstrap_info *bi;
  231. bi = dpp_bootstrap_get_id(wpa_s, id);
  232. if (!bi)
  233. return NULL;
  234. return bi->uri;
  235. }
  236. int wpas_dpp_bootstrap_info(struct wpa_supplicant *wpa_s, int id,
  237. char *reply, int reply_size)
  238. {
  239. struct dpp_bootstrap_info *bi;
  240. bi = dpp_bootstrap_get_id(wpa_s, id);
  241. if (!bi)
  242. return -1;
  243. return os_snprintf(reply, reply_size, "type=%s\n"
  244. "mac_addr=" MACSTR "\n"
  245. "info=%s\n"
  246. "num_freq=%u\n"
  247. "curve=%s\n",
  248. dpp_bootstrap_type_txt(bi->type),
  249. MAC2STR(bi->mac_addr),
  250. bi->info ? bi->info : "",
  251. bi->num_freq,
  252. bi->curve->name);
  253. }
  254. static void wpas_dpp_tx_status(struct wpa_supplicant *wpa_s,
  255. unsigned int freq, const u8 *dst,
  256. const u8 *src, const u8 *bssid,
  257. const u8 *data, size_t data_len,
  258. enum offchannel_send_action_result result)
  259. {
  260. const char *res_txt;
  261. struct dpp_authentication *auth = wpa_s->dpp_auth;
  262. res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
  263. (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
  264. "FAILED");
  265. wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
  266. " result=%s", freq, MAC2STR(dst), res_txt);
  267. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
  268. " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
  269. if (!wpa_s->dpp_auth) {
  270. wpa_printf(MSG_DEBUG,
  271. "DPP: Ignore TX status since there is no ongoing authentication exchange");
  272. return;
  273. }
  274. if (wpa_s->dpp_auth->remove_on_tx_status) {
  275. wpa_printf(MSG_DEBUG,
  276. "DPP: Terminate authentication exchange due to an earlier error");
  277. eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
  278. eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
  279. offchannel_send_action_done(wpa_s);
  280. dpp_auth_deinit(wpa_s->dpp_auth);
  281. wpa_s->dpp_auth = NULL;
  282. return;
  283. }
  284. if (wpa_s->dpp_auth_ok_on_ack)
  285. wpas_dpp_auth_success(wpa_s, 1);
  286. if (!is_broadcast_ether_addr(dst) &&
  287. result != OFFCHANNEL_SEND_ACTION_SUCCESS) {
  288. wpa_printf(MSG_DEBUG,
  289. "DPP: Unicast DPP Action frame was not ACKed");
  290. if (auth->waiting_auth_resp) {
  291. /* In case of DPP Authentication Request frame, move to
  292. * the next channel immediately. */
  293. offchannel_send_action_done(wpa_s);
  294. wpas_dpp_auth_init_next(wpa_s);
  295. return;
  296. }
  297. }
  298. if (!wpa_s->dpp_auth_ok_on_ack && wpa_s->dpp_auth->neg_freq > 0 &&
  299. wpa_s->dpp_auth->curr_freq != wpa_s->dpp_auth->neg_freq) {
  300. wpa_printf(MSG_DEBUG,
  301. "DPP: Move from curr_freq %u MHz to neg_freq %u MHz for response",
  302. wpa_s->dpp_auth->curr_freq,
  303. wpa_s->dpp_auth->neg_freq);
  304. offchannel_send_action_done(wpa_s);
  305. wpas_dpp_listen_start(wpa_s, wpa_s->dpp_auth->neg_freq);
  306. }
  307. }
  308. static void wpas_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx)
  309. {
  310. struct wpa_supplicant *wpa_s = eloop_ctx;
  311. unsigned int freq;
  312. struct os_reltime now;
  313. if (!wpa_s->dpp_auth)
  314. return;
  315. if (wpa_s->dpp_auth->waiting_auth_resp) {
  316. unsigned int wait_time;
  317. wait_time = wpa_s->dpp_resp_wait_time ?
  318. wpa_s->dpp_resp_wait_time : 2;
  319. os_get_reltime(&now);
  320. if (os_reltime_expired(&now, &wpa_s->dpp_last_init,
  321. wait_time)) {
  322. offchannel_send_action_done(wpa_s);
  323. wpas_dpp_auth_init_next(wpa_s);
  324. return;
  325. }
  326. }
  327. freq = wpa_s->dpp_auth->curr_freq;
  328. if (wpa_s->dpp_auth->neg_freq > 0)
  329. freq = wpa_s->dpp_auth->neg_freq;
  330. wpa_printf(MSG_DEBUG, "DPP: Continue reply wait on channel %u MHz",
  331. freq);
  332. wpas_dpp_listen_start(wpa_s, freq);
  333. }
  334. static void wpas_dpp_set_testing_options(struct wpa_supplicant *wpa_s,
  335. struct dpp_authentication *auth)
  336. {
  337. #ifdef CONFIG_TESTING_OPTIONS
  338. if (wpa_s->dpp_config_obj_override)
  339. auth->config_obj_override =
  340. os_strdup(wpa_s->dpp_config_obj_override);
  341. if (wpa_s->dpp_discovery_override)
  342. auth->discovery_override =
  343. os_strdup(wpa_s->dpp_discovery_override);
  344. if (wpa_s->dpp_groups_override)
  345. auth->groups_override =
  346. os_strdup(wpa_s->dpp_groups_override);
  347. auth->ignore_netaccesskey_mismatch =
  348. wpa_s->dpp_ignore_netaccesskey_mismatch;
  349. #endif /* CONFIG_TESTING_OPTIONS */
  350. }
  351. static void wpas_dpp_set_configurator(struct wpa_supplicant *wpa_s,
  352. struct dpp_authentication *auth,
  353. const char *cmd)
  354. {
  355. const char *pos, *end;
  356. struct dpp_configuration *conf_sta = NULL, *conf_ap = NULL;
  357. struct dpp_configurator *conf = NULL;
  358. u8 ssid[32] = { "test" };
  359. size_t ssid_len = 4;
  360. char pass[64] = { };
  361. size_t pass_len = 0;
  362. u8 psk[PMK_LEN];
  363. int psk_set = 0;
  364. if (!cmd)
  365. return;
  366. wpa_printf(MSG_DEBUG, "DPP: Set configurator parameters: %s", cmd);
  367. pos = os_strstr(cmd, " ssid=");
  368. if (pos) {
  369. pos += 6;
  370. end = os_strchr(pos, ' ');
  371. ssid_len = end ? (size_t) (end - pos) : os_strlen(pos);
  372. ssid_len /= 2;
  373. if (ssid_len > sizeof(ssid) ||
  374. hexstr2bin(pos, ssid, ssid_len) < 0)
  375. goto fail;
  376. }
  377. pos = os_strstr(cmd, " pass=");
  378. if (pos) {
  379. pos += 6;
  380. end = os_strchr(pos, ' ');
  381. pass_len = end ? (size_t) (end - pos) : os_strlen(pos);
  382. pass_len /= 2;
  383. if (pass_len > sizeof(pass) - 1 || pass_len < 8 ||
  384. hexstr2bin(pos, (u8 *) pass, pass_len) < 0)
  385. goto fail;
  386. }
  387. pos = os_strstr(cmd, " psk=");
  388. if (pos) {
  389. pos += 5;
  390. if (hexstr2bin(pos, psk, PMK_LEN) < 0)
  391. goto fail;
  392. psk_set = 1;
  393. }
  394. if (os_strstr(cmd, " conf=sta-")) {
  395. conf_sta = os_zalloc(sizeof(struct dpp_configuration));
  396. if (!conf_sta)
  397. goto fail;
  398. os_memcpy(conf_sta->ssid, ssid, ssid_len);
  399. conf_sta->ssid_len = ssid_len;
  400. if (os_strstr(cmd, " conf=sta-psk")) {
  401. conf_sta->dpp = 0;
  402. if (psk_set) {
  403. os_memcpy(conf_sta->psk, psk, PMK_LEN);
  404. } else {
  405. conf_sta->passphrase = os_strdup(pass);
  406. if (!conf_sta->passphrase)
  407. goto fail;
  408. }
  409. } else if (os_strstr(cmd, " conf=sta-dpp")) {
  410. conf_sta->dpp = 1;
  411. } else {
  412. goto fail;
  413. }
  414. }
  415. if (os_strstr(cmd, " conf=ap-")) {
  416. conf_ap = os_zalloc(sizeof(struct dpp_configuration));
  417. if (!conf_ap)
  418. goto fail;
  419. os_memcpy(conf_ap->ssid, ssid, ssid_len);
  420. conf_ap->ssid_len = ssid_len;
  421. if (os_strstr(cmd, " conf=ap-psk")) {
  422. conf_ap->dpp = 0;
  423. if (psk_set) {
  424. os_memcpy(conf_ap->psk, psk, PMK_LEN);
  425. } else {
  426. conf_ap->passphrase = os_strdup(pass);
  427. if (!conf_ap->passphrase)
  428. goto fail;
  429. }
  430. } else if (os_strstr(cmd, " conf=ap-dpp")) {
  431. conf_ap->dpp = 1;
  432. } else {
  433. goto fail;
  434. }
  435. }
  436. pos = os_strstr(cmd, " expiry=");
  437. if (pos) {
  438. long int val;
  439. pos += 8;
  440. val = strtol(pos, NULL, 0);
  441. if (val <= 0)
  442. goto fail;
  443. if (conf_sta)
  444. conf_sta->netaccesskey_expiry = val;
  445. if (conf_ap)
  446. conf_ap->netaccesskey_expiry = val;
  447. }
  448. pos = os_strstr(cmd, " configurator=");
  449. if (pos) {
  450. pos += 14;
  451. conf = dpp_configurator_get_id(wpa_s, atoi(pos));
  452. if (!conf) {
  453. wpa_printf(MSG_INFO,
  454. "DPP: Could not find the specified configurator");
  455. goto fail;
  456. }
  457. }
  458. auth->conf_sta = conf_sta;
  459. auth->conf_ap = conf_ap;
  460. auth->conf = conf;
  461. return;
  462. fail:
  463. wpa_printf(MSG_DEBUG, "DPP: Failed to set configurator parameters");
  464. dpp_configuration_free(conf_sta);
  465. dpp_configuration_free(conf_ap);
  466. }
  467. static void wpas_dpp_init_timeout(void *eloop_ctx, void *timeout_ctx)
  468. {
  469. struct wpa_supplicant *wpa_s = eloop_ctx;
  470. if (!wpa_s->dpp_auth)
  471. return;
  472. wpa_printf(MSG_DEBUG, "DPP: Retry initiation after timeout");
  473. wpas_dpp_auth_init_next(wpa_s);
  474. }
  475. static int wpas_dpp_auth_init_next(struct wpa_supplicant *wpa_s)
  476. {
  477. struct dpp_authentication *auth = wpa_s->dpp_auth;
  478. const u8 *dst;
  479. unsigned int wait_time, freq, max_tries;
  480. if (!auth)
  481. return -1;
  482. if (auth->freq_idx >= auth->num_freq) {
  483. auth->num_freq_iters++;
  484. if (wpa_s->dpp_init_max_tries)
  485. max_tries = wpa_s->dpp_init_max_tries;
  486. else
  487. max_tries = 5;
  488. if (auth->num_freq_iters >= max_tries) {
  489. wpa_printf(MSG_INFO,
  490. "DPP: No response received from responder - stopping initiation attempt");
  491. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_INIT_FAILED);
  492. eloop_cancel_timeout(wpas_dpp_reply_wait_timeout,
  493. wpa_s, NULL);
  494. offchannel_send_action_done(wpa_s);
  495. dpp_auth_deinit(wpa_s->dpp_auth);
  496. wpa_s->dpp_auth = NULL;
  497. return -1;
  498. }
  499. auth->freq_idx = 0;
  500. eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
  501. if (wpa_s->dpp_init_retry_time)
  502. wait_time = wpa_s->dpp_init_retry_time;
  503. else
  504. wait_time = 10000;
  505. eloop_register_timeout(wait_time / 1000,
  506. (wait_time % 1000) * 1000,
  507. wpas_dpp_init_timeout, wpa_s,
  508. NULL);
  509. return 0;
  510. }
  511. freq = auth->freq[auth->freq_idx++];
  512. auth->curr_freq = freq;
  513. if (is_zero_ether_addr(auth->peer_bi->mac_addr))
  514. dst = broadcast;
  515. else
  516. dst = auth->peer_bi->mac_addr;
  517. wpa_s->dpp_auth_ok_on_ack = 0;
  518. eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
  519. wait_time = wpa_s->max_remain_on_chan;
  520. if (wait_time > 2000)
  521. wait_time = 2000;
  522. eloop_register_timeout(wait_time / 1000, (wait_time % 1000) * 1000,
  523. wpas_dpp_reply_wait_timeout,
  524. wpa_s, NULL);
  525. if (auth->neg_freq > 0 && freq != auth->neg_freq) {
  526. wpa_printf(MSG_DEBUG,
  527. "DPP: Initiate on %u MHz and move to neg_freq %u MHz for response",
  528. freq, auth->neg_freq);
  529. }
  530. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
  531. MAC2STR(dst), freq, DPP_PA_AUTHENTICATION_REQ);
  532. os_get_reltime(&wpa_s->dpp_last_init);
  533. return offchannel_send_action(wpa_s, freq, dst,
  534. wpa_s->own_addr, broadcast,
  535. wpabuf_head(auth->req_msg),
  536. wpabuf_len(auth->req_msg),
  537. wait_time, wpas_dpp_tx_status, 0);
  538. }
  539. int wpas_dpp_auth_init(struct wpa_supplicant *wpa_s, const char *cmd)
  540. {
  541. const char *pos;
  542. struct dpp_bootstrap_info *peer_bi, *own_bi = NULL;
  543. int configurator = 1;
  544. unsigned int neg_freq = 0;
  545. wpa_s->dpp_gas_client = 0;
  546. pos = os_strstr(cmd, " peer=");
  547. if (!pos)
  548. return -1;
  549. pos += 6;
  550. peer_bi = dpp_bootstrap_get_id(wpa_s, atoi(pos));
  551. if (!peer_bi) {
  552. wpa_printf(MSG_INFO,
  553. "DPP: Could not find bootstrapping info for the identified peer");
  554. return -1;
  555. }
  556. pos = os_strstr(cmd, " own=");
  557. if (pos) {
  558. pos += 5;
  559. own_bi = dpp_bootstrap_get_id(wpa_s, atoi(pos));
  560. if (!own_bi) {
  561. wpa_printf(MSG_INFO,
  562. "DPP: Could not find bootstrapping info for the identified local entry");
  563. return -1;
  564. }
  565. if (peer_bi->curve != own_bi->curve) {
  566. wpa_printf(MSG_INFO,
  567. "DPP: Mismatching curves in bootstrapping info (peer=%s own=%s)",
  568. peer_bi->curve->name, own_bi->curve->name);
  569. return -1;
  570. }
  571. }
  572. pos = os_strstr(cmd, " role=");
  573. if (pos) {
  574. pos += 6;
  575. if (os_strncmp(pos, "configurator", 12) == 0)
  576. configurator = 1;
  577. else if (os_strncmp(pos, "enrollee", 8) == 0)
  578. configurator = 0;
  579. else
  580. goto fail;
  581. }
  582. pos = os_strstr(cmd, " netrole=");
  583. if (pos) {
  584. pos += 9;
  585. wpa_s->dpp_netrole_ap = os_strncmp(pos, "ap", 2) == 0;
  586. }
  587. pos = os_strstr(cmd, " neg_freq=");
  588. if (pos)
  589. neg_freq = atoi(pos + 10);
  590. if (wpa_s->dpp_auth) {
  591. eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
  592. eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
  593. offchannel_send_action_done(wpa_s);
  594. dpp_auth_deinit(wpa_s->dpp_auth);
  595. }
  596. wpa_s->dpp_auth = dpp_auth_init(wpa_s, peer_bi, own_bi, configurator,
  597. neg_freq,
  598. wpa_s->hw.modes, wpa_s->hw.num_modes);
  599. if (!wpa_s->dpp_auth)
  600. goto fail;
  601. wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth);
  602. wpas_dpp_set_configurator(wpa_s, wpa_s->dpp_auth, cmd);
  603. wpa_s->dpp_auth->neg_freq = neg_freq;
  604. if (!is_zero_ether_addr(peer_bi->mac_addr))
  605. os_memcpy(wpa_s->dpp_auth->peer_mac_addr, peer_bi->mac_addr,
  606. ETH_ALEN);
  607. return wpas_dpp_auth_init_next(wpa_s);
  608. fail:
  609. return -1;
  610. }
  611. struct wpas_dpp_listen_work {
  612. unsigned int freq;
  613. unsigned int duration;
  614. struct wpabuf *probe_resp_ie;
  615. };
  616. static void wpas_dpp_listen_work_free(struct wpas_dpp_listen_work *lwork)
  617. {
  618. if (!lwork)
  619. return;
  620. os_free(lwork);
  621. }
  622. static void wpas_dpp_listen_work_done(struct wpa_supplicant *wpa_s)
  623. {
  624. struct wpas_dpp_listen_work *lwork;
  625. if (!wpa_s->dpp_listen_work)
  626. return;
  627. lwork = wpa_s->dpp_listen_work->ctx;
  628. wpas_dpp_listen_work_free(lwork);
  629. radio_work_done(wpa_s->dpp_listen_work);
  630. wpa_s->dpp_listen_work = NULL;
  631. }
  632. static void dpp_start_listen_cb(struct wpa_radio_work *work, int deinit)
  633. {
  634. struct wpa_supplicant *wpa_s = work->wpa_s;
  635. struct wpas_dpp_listen_work *lwork = work->ctx;
  636. if (deinit) {
  637. if (work->started) {
  638. wpa_s->dpp_listen_work = NULL;
  639. wpas_dpp_listen_stop(wpa_s);
  640. }
  641. wpas_dpp_listen_work_free(lwork);
  642. return;
  643. }
  644. wpa_s->dpp_listen_work = work;
  645. wpa_s->dpp_pending_listen_freq = lwork->freq;
  646. if (wpa_drv_remain_on_channel(wpa_s, lwork->freq,
  647. wpa_s->max_remain_on_chan) < 0) {
  648. wpa_printf(MSG_DEBUG,
  649. "DPP: Failed to request the driver to remain on channel (%u MHz) for listen",
  650. lwork->freq);
  651. wpas_dpp_listen_work_done(wpa_s);
  652. wpa_s->dpp_pending_listen_freq = 0;
  653. return;
  654. }
  655. wpa_s->off_channel_freq = 0;
  656. wpa_s->roc_waiting_drv_freq = lwork->freq;
  657. }
  658. static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
  659. unsigned int freq)
  660. {
  661. struct wpas_dpp_listen_work *lwork;
  662. if (wpa_s->dpp_listen_work) {
  663. wpa_printf(MSG_DEBUG,
  664. "DPP: Reject start_listen since dpp_listen_work already exists");
  665. return -1;
  666. }
  667. if (wpa_s->dpp_listen_freq)
  668. wpas_dpp_listen_stop(wpa_s);
  669. wpa_s->dpp_listen_freq = freq;
  670. lwork = os_zalloc(sizeof(*lwork));
  671. if (!lwork)
  672. return -1;
  673. lwork->freq = freq;
  674. if (radio_add_work(wpa_s, freq, "dpp-listen", 0, dpp_start_listen_cb,
  675. lwork) < 0) {
  676. wpas_dpp_listen_work_free(lwork);
  677. return -1;
  678. }
  679. return 0;
  680. }
  681. int wpas_dpp_listen(struct wpa_supplicant *wpa_s, const char *cmd)
  682. {
  683. int freq;
  684. freq = atoi(cmd);
  685. if (freq <= 0)
  686. return -1;
  687. if (os_strstr(cmd, " role=configurator"))
  688. wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR;
  689. else if (os_strstr(cmd, " role=enrollee"))
  690. wpa_s->dpp_allowed_roles = DPP_CAPAB_ENROLLEE;
  691. else
  692. wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR |
  693. DPP_CAPAB_ENROLLEE;
  694. wpa_s->dpp_qr_mutual = os_strstr(cmd, " qr=mutual") != NULL;
  695. wpa_s->dpp_netrole_ap = os_strstr(cmd, " netrole=ap") != NULL;
  696. if (wpa_s->dpp_listen_freq == (unsigned int) freq) {
  697. wpa_printf(MSG_DEBUG, "DPP: Already listening on %u MHz",
  698. freq);
  699. return 0;
  700. }
  701. return wpas_dpp_listen_start(wpa_s, freq);
  702. }
  703. void wpas_dpp_listen_stop(struct wpa_supplicant *wpa_s)
  704. {
  705. if (!wpa_s->dpp_listen_freq)
  706. return;
  707. wpa_printf(MSG_DEBUG, "DPP: Stop listen on %u MHz",
  708. wpa_s->dpp_listen_freq);
  709. wpa_drv_cancel_remain_on_channel(wpa_s);
  710. wpa_s->dpp_listen_freq = 0;
  711. wpas_dpp_listen_work_done(wpa_s);
  712. }
  713. void wpas_dpp_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
  714. unsigned int freq)
  715. {
  716. if (!wpa_s->dpp_listen_freq && !wpa_s->dpp_pending_listen_freq)
  717. return;
  718. wpa_printf(MSG_DEBUG,
  719. "DPP: remain-on-channel callback (off_channel_freq=%u dpp_pending_listen_freq=%d roc_waiting_drv_freq=%d freq=%u)",
  720. wpa_s->off_channel_freq, wpa_s->dpp_pending_listen_freq,
  721. wpa_s->roc_waiting_drv_freq, freq);
  722. if (wpa_s->off_channel_freq &&
  723. wpa_s->off_channel_freq == wpa_s->dpp_pending_listen_freq) {
  724. wpa_printf(MSG_DEBUG, "DPP: Listen on %u MHz started", freq);
  725. wpa_s->dpp_pending_listen_freq = 0;
  726. } else {
  727. wpa_printf(MSG_DEBUG,
  728. "DPP: Ignore remain-on-channel callback (off_channel_freq=%u dpp_pending_listen_freq=%d freq=%u)",
  729. wpa_s->off_channel_freq,
  730. wpa_s->dpp_pending_listen_freq, freq);
  731. }
  732. }
  733. void wpas_dpp_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
  734. unsigned int freq)
  735. {
  736. wpas_dpp_listen_work_done(wpa_s);
  737. if (wpa_s->dpp_auth && !wpa_s->dpp_gas_client) {
  738. /* Continue listen with a new remain-on-channel */
  739. wpa_printf(MSG_DEBUG,
  740. "DPP: Continue wait on %u MHz for the ongoing DPP provisioning session",
  741. wpa_s->dpp_auth->curr_freq);
  742. wpas_dpp_listen_start(wpa_s, wpa_s->dpp_auth->curr_freq);
  743. return;
  744. }
  745. if (wpa_s->dpp_listen_freq) {
  746. /* Continue listen with a new remain-on-channel */
  747. wpas_dpp_listen_start(wpa_s, wpa_s->dpp_listen_freq);
  748. }
  749. }
  750. static void wpas_dpp_rx_auth_req(struct wpa_supplicant *wpa_s, const u8 *src,
  751. const u8 *hdr, const u8 *buf, size_t len,
  752. unsigned int freq)
  753. {
  754. const u8 *r_bootstrap, *i_bootstrap;
  755. u16 r_bootstrap_len, i_bootstrap_len;
  756. struct dpp_bootstrap_info *bi, *own_bi = NULL, *peer_bi = NULL;
  757. wpa_printf(MSG_DEBUG, "DPP: Authentication Request from " MACSTR,
  758. MAC2STR(src));
  759. r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH,
  760. &r_bootstrap_len);
  761. if (!r_bootstrap || r_bootstrap_len != SHA256_MAC_LEN) {
  762. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
  763. "Missing or invalid required Responder Bootstrapping Key Hash attribute");
  764. return;
  765. }
  766. wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash",
  767. r_bootstrap, r_bootstrap_len);
  768. i_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_I_BOOTSTRAP_KEY_HASH,
  769. &i_bootstrap_len);
  770. if (!i_bootstrap || i_bootstrap_len != SHA256_MAC_LEN) {
  771. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
  772. "Missing or invalid required Initiator Bootstrapping Key Hash attribute");
  773. return;
  774. }
  775. wpa_hexdump(MSG_MSGDUMP, "DPP: Initiator Bootstrapping Key Hash",
  776. i_bootstrap, i_bootstrap_len);
  777. /* Try to find own and peer bootstrapping key matches based on the
  778. * received hash values */
  779. dl_list_for_each(bi, &wpa_s->dpp_bootstrap, struct dpp_bootstrap_info,
  780. list) {
  781. if (!own_bi && bi->own &&
  782. os_memcmp(bi->pubkey_hash, r_bootstrap,
  783. SHA256_MAC_LEN) == 0) {
  784. wpa_printf(MSG_DEBUG,
  785. "DPP: Found matching own bootstrapping information");
  786. own_bi = bi;
  787. }
  788. if (!peer_bi && !bi->own &&
  789. os_memcmp(bi->pubkey_hash, i_bootstrap,
  790. SHA256_MAC_LEN) == 0) {
  791. wpa_printf(MSG_DEBUG,
  792. "DPP: Found matching peer bootstrapping information");
  793. peer_bi = bi;
  794. }
  795. if (own_bi && peer_bi)
  796. break;
  797. }
  798. if (!own_bi) {
  799. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
  800. "No matching own bootstrapping key found - ignore message");
  801. return;
  802. }
  803. if (wpa_s->dpp_auth) {
  804. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
  805. "Already in DPP authentication exchange - ignore new one");
  806. return;
  807. }
  808. wpa_s->dpp_gas_client = 0;
  809. wpa_s->dpp_auth_ok_on_ack = 0;
  810. wpa_s->dpp_auth = dpp_auth_req_rx(wpa_s, wpa_s->dpp_allowed_roles,
  811. wpa_s->dpp_qr_mutual,
  812. peer_bi, own_bi, freq, hdr, buf, len);
  813. if (!wpa_s->dpp_auth) {
  814. wpa_printf(MSG_DEBUG, "DPP: No response generated");
  815. return;
  816. }
  817. wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth);
  818. wpas_dpp_set_configurator(wpa_s, wpa_s->dpp_auth,
  819. wpa_s->dpp_configurator_params);
  820. os_memcpy(wpa_s->dpp_auth->peer_mac_addr, src, ETH_ALEN);
  821. if (wpa_s->dpp_listen_freq &&
  822. wpa_s->dpp_listen_freq != wpa_s->dpp_auth->curr_freq) {
  823. wpa_printf(MSG_DEBUG,
  824. "DPP: Stop listen on %u MHz to allow response on the request %u MHz",
  825. wpa_s->dpp_listen_freq, wpa_s->dpp_auth->curr_freq);
  826. wpas_dpp_listen_stop(wpa_s);
  827. }
  828. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
  829. MAC2STR(src), wpa_s->dpp_auth->curr_freq,
  830. DPP_PA_AUTHENTICATION_RESP);
  831. offchannel_send_action(wpa_s, wpa_s->dpp_auth->curr_freq,
  832. src, wpa_s->own_addr, broadcast,
  833. wpabuf_head(wpa_s->dpp_auth->resp_msg),
  834. wpabuf_len(wpa_s->dpp_auth->resp_msg),
  835. 500, wpas_dpp_tx_status, 0);
  836. }
  837. static void wpas_dpp_start_gas_server(struct wpa_supplicant *wpa_s)
  838. {
  839. /* TODO: stop wait and start ROC */
  840. }
  841. static struct wpa_ssid * wpas_dpp_add_network(struct wpa_supplicant *wpa_s,
  842. struct dpp_authentication *auth)
  843. {
  844. struct wpa_ssid *ssid;
  845. ssid = wpa_config_add_network(wpa_s->conf);
  846. if (!ssid)
  847. return NULL;
  848. wpas_notify_network_added(wpa_s, ssid);
  849. wpa_config_set_network_defaults(ssid);
  850. ssid->disabled = 1;
  851. ssid->ssid = os_malloc(auth->ssid_len);
  852. if (!ssid->ssid)
  853. goto fail;
  854. os_memcpy(ssid->ssid, auth->ssid, auth->ssid_len);
  855. ssid->ssid_len = auth->ssid_len;
  856. if (auth->connector) {
  857. ssid->key_mgmt = WPA_KEY_MGMT_DPP;
  858. ssid->ieee80211w = 1;
  859. ssid->dpp_connector = os_strdup(auth->connector);
  860. if (!ssid->dpp_connector)
  861. goto fail;
  862. }
  863. if (auth->c_sign_key) {
  864. ssid->dpp_csign = os_malloc(wpabuf_len(auth->c_sign_key));
  865. if (!ssid->dpp_csign)
  866. goto fail;
  867. os_memcpy(ssid->dpp_csign, wpabuf_head(auth->c_sign_key),
  868. wpabuf_len(auth->c_sign_key));
  869. ssid->dpp_csign_len = wpabuf_len(auth->c_sign_key);
  870. }
  871. if (auth->net_access_key) {
  872. ssid->dpp_netaccesskey =
  873. os_malloc(wpabuf_len(auth->net_access_key));
  874. if (!ssid->dpp_netaccesskey)
  875. goto fail;
  876. os_memcpy(ssid->dpp_netaccesskey,
  877. wpabuf_head(auth->net_access_key),
  878. wpabuf_len(auth->net_access_key));
  879. ssid->dpp_netaccesskey_len = wpabuf_len(auth->net_access_key);
  880. ssid->dpp_netaccesskey_expiry = auth->net_access_key_expiry;
  881. }
  882. if (!auth->connector) {
  883. ssid->key_mgmt = WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_PSK_SHA256;
  884. ssid->ieee80211w = 1;
  885. if (auth->passphrase[0]) {
  886. if (wpa_config_set_quoted(ssid, "psk",
  887. auth->passphrase) < 0)
  888. goto fail;
  889. wpa_config_update_psk(ssid);
  890. ssid->export_keys = 1;
  891. } else {
  892. ssid->psk_set = auth->psk_set;
  893. os_memcpy(ssid->psk, auth->psk, PMK_LEN);
  894. }
  895. }
  896. return ssid;
  897. fail:
  898. wpas_notify_network_removed(wpa_s, ssid);
  899. wpa_config_remove_network(wpa_s->conf, ssid->id);
  900. return NULL;
  901. }
  902. static void wpas_dpp_process_config(struct wpa_supplicant *wpa_s,
  903. struct dpp_authentication *auth)
  904. {
  905. struct wpa_ssid *ssid;
  906. if (wpa_s->conf->dpp_config_processing < 1)
  907. return;
  908. ssid = wpas_dpp_add_network(wpa_s, auth);
  909. if (!ssid)
  910. return;
  911. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_NETWORK_ID "%d", ssid->id);
  912. if (wpa_s->conf->dpp_config_processing < 2)
  913. return;
  914. wpa_printf(MSG_DEBUG, "DPP: Trying to connect to the new network");
  915. ssid->disabled = 0;
  916. wpa_s->disconnected = 0;
  917. wpa_s->reassociate = 1;
  918. wpa_s->scan_runs = 0;
  919. wpa_s->normal_scans = 0;
  920. wpa_supplicant_cancel_sched_scan(wpa_s);
  921. wpa_supplicant_req_scan(wpa_s, 0, 0);
  922. }
  923. static void wpas_dpp_handle_config_obj(struct wpa_supplicant *wpa_s,
  924. struct dpp_authentication *auth)
  925. {
  926. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_RECEIVED);
  927. if (auth->ssid_len)
  928. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFOBJ_SSID "%s",
  929. wpa_ssid_txt(auth->ssid, auth->ssid_len));
  930. if (auth->connector) {
  931. /* TODO: Save the Connector and consider using a command
  932. * to fetch the value instead of sending an event with
  933. * it. The Connector could end up being larger than what
  934. * most clients are ready to receive as an event
  935. * message. */
  936. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONNECTOR "%s",
  937. auth->connector);
  938. }
  939. if (auth->c_sign_key) {
  940. char *hex;
  941. size_t hexlen;
  942. hexlen = 2 * wpabuf_len(auth->c_sign_key) + 1;
  943. hex = os_malloc(hexlen);
  944. if (hex) {
  945. wpa_snprintf_hex(hex, hexlen,
  946. wpabuf_head(auth->c_sign_key),
  947. wpabuf_len(auth->c_sign_key));
  948. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_C_SIGN_KEY "%s",
  949. hex);
  950. os_free(hex);
  951. }
  952. }
  953. if (auth->net_access_key) {
  954. char *hex;
  955. size_t hexlen;
  956. hexlen = 2 * wpabuf_len(auth->net_access_key) + 1;
  957. hex = os_malloc(hexlen);
  958. if (hex) {
  959. wpa_snprintf_hex(hex, hexlen,
  960. wpabuf_head(auth->net_access_key),
  961. wpabuf_len(auth->net_access_key));
  962. if (auth->net_access_key_expiry)
  963. wpa_msg(wpa_s, MSG_INFO,
  964. DPP_EVENT_NET_ACCESS_KEY "%s %lu", hex,
  965. (long unsigned)
  966. auth->net_access_key_expiry);
  967. else
  968. wpa_msg(wpa_s, MSG_INFO,
  969. DPP_EVENT_NET_ACCESS_KEY "%s", hex);
  970. os_free(hex);
  971. }
  972. }
  973. wpas_dpp_process_config(wpa_s, auth);
  974. }
  975. static void wpas_dpp_gas_resp_cb(void *ctx, const u8 *addr, u8 dialog_token,
  976. enum gas_query_result result,
  977. const struct wpabuf *adv_proto,
  978. const struct wpabuf *resp, u16 status_code)
  979. {
  980. struct wpa_supplicant *wpa_s = ctx;
  981. const u8 *pos;
  982. struct dpp_authentication *auth = wpa_s->dpp_auth;
  983. if (!auth || !auth->auth_success) {
  984. wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
  985. return;
  986. }
  987. if (!resp || status_code != WLAN_STATUS_SUCCESS) {
  988. wpa_printf(MSG_DEBUG, "DPP: GAS query did not succeed");
  989. goto fail;
  990. }
  991. wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response adv_proto",
  992. adv_proto);
  993. wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response (GAS response)",
  994. resp);
  995. if (wpabuf_len(adv_proto) != 10 ||
  996. !(pos = wpabuf_head(adv_proto)) ||
  997. pos[0] != WLAN_EID_ADV_PROTO ||
  998. pos[1] != 8 ||
  999. pos[3] != WLAN_EID_VENDOR_SPECIFIC ||
  1000. pos[4] != 5 ||
  1001. WPA_GET_BE24(&pos[5]) != OUI_WFA ||
  1002. pos[8] != 0x1a ||
  1003. pos[9] != 1) {
  1004. wpa_printf(MSG_DEBUG,
  1005. "DPP: Not a DPP Advertisement Protocol ID");
  1006. goto fail;
  1007. }
  1008. if (dpp_conf_resp_rx(auth, resp) < 0) {
  1009. wpa_printf(MSG_DEBUG, "DPP: Configuration attempt failed");
  1010. goto fail;
  1011. }
  1012. wpas_dpp_handle_config_obj(wpa_s, auth);
  1013. dpp_auth_deinit(wpa_s->dpp_auth);
  1014. wpa_s->dpp_auth = NULL;
  1015. return;
  1016. fail:
  1017. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
  1018. dpp_auth_deinit(wpa_s->dpp_auth);
  1019. wpa_s->dpp_auth = NULL;
  1020. }
  1021. static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s)
  1022. {
  1023. struct dpp_authentication *auth = wpa_s->dpp_auth;
  1024. struct wpabuf *buf, *conf_req;
  1025. char json[100];
  1026. int res;
  1027. wpa_s->dpp_gas_client = 1;
  1028. os_snprintf(json, sizeof(json),
  1029. "{\"name\":\"Test\","
  1030. "\"wi-fi_tech\":\"infra\","
  1031. "\"netRole\":\"%s\"}",
  1032. wpa_s->dpp_netrole_ap ? "ap" : "sta");
  1033. wpa_printf(MSG_DEBUG, "DPP: GAS Config Attributes: %s", json);
  1034. offchannel_send_action_done(wpa_s);
  1035. wpas_dpp_listen_stop(wpa_s);
  1036. conf_req = dpp_build_conf_req(auth, json);
  1037. if (!conf_req) {
  1038. wpa_printf(MSG_DEBUG,
  1039. "DPP: No configuration request data available");
  1040. return;
  1041. }
  1042. buf = gas_build_initial_req(0, 10 + 2 + wpabuf_len(conf_req));
  1043. if (!buf) {
  1044. wpabuf_free(conf_req);
  1045. return;
  1046. }
  1047. /* Advertisement Protocol IE */
  1048. wpabuf_put_u8(buf, WLAN_EID_ADV_PROTO);
  1049. wpabuf_put_u8(buf, 8); /* Length */
  1050. wpabuf_put_u8(buf, 0x7f);
  1051. wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
  1052. wpabuf_put_u8(buf, 5);
  1053. wpabuf_put_be24(buf, OUI_WFA);
  1054. wpabuf_put_u8(buf, DPP_OUI_TYPE);
  1055. wpabuf_put_u8(buf, 0x01);
  1056. /* GAS Query */
  1057. wpabuf_put_le16(buf, wpabuf_len(conf_req));
  1058. wpabuf_put_buf(buf, conf_req);
  1059. wpabuf_free(conf_req);
  1060. wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)",
  1061. MAC2STR(auth->peer_mac_addr), auth->curr_freq);
  1062. res = gas_query_req(wpa_s->gas, auth->peer_mac_addr, auth->curr_freq,
  1063. buf, wpas_dpp_gas_resp_cb, wpa_s);
  1064. if (res < 0) {
  1065. wpa_msg(wpa_s, MSG_DEBUG, "GAS: Failed to send Query Request");
  1066. wpabuf_free(buf);
  1067. } else {
  1068. wpa_printf(MSG_DEBUG,
  1069. "DPP: GAS query started with dialog token %u", res);
  1070. }
  1071. }
  1072. static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator)
  1073. {
  1074. wpa_printf(MSG_DEBUG, "DPP: Authentication succeeded");
  1075. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=%d", initiator);
  1076. if (wpa_s->dpp_auth->configurator)
  1077. wpas_dpp_start_gas_server(wpa_s);
  1078. else
  1079. wpas_dpp_start_gas_client(wpa_s);
  1080. }
  1081. static void wpas_dpp_rx_auth_resp(struct wpa_supplicant *wpa_s, const u8 *src,
  1082. const u8 *hdr, const u8 *buf, size_t len,
  1083. unsigned int freq)
  1084. {
  1085. struct dpp_authentication *auth = wpa_s->dpp_auth;
  1086. struct wpabuf *msg;
  1087. wpa_printf(MSG_DEBUG, "DPP: Authentication Response from " MACSTR
  1088. " (freq %u MHz)", MAC2STR(src), freq);
  1089. if (!auth) {
  1090. wpa_printf(MSG_DEBUG,
  1091. "DPP: No DPP Authentication in progress - drop");
  1092. return;
  1093. }
  1094. if (!is_zero_ether_addr(auth->peer_mac_addr) &&
  1095. os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
  1096. wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
  1097. MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
  1098. return;
  1099. }
  1100. eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
  1101. if (auth->curr_freq != freq && auth->neg_freq == freq) {
  1102. wpa_printf(MSG_DEBUG,
  1103. "DPP: Responder accepted request for different negotiation channel");
  1104. auth->curr_freq = freq;
  1105. }
  1106. eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
  1107. msg = dpp_auth_resp_rx(auth, hdr, buf, len);
  1108. if (!msg) {
  1109. if (auth->auth_resp_status == DPP_STATUS_RESPONSE_PENDING) {
  1110. wpa_printf(MSG_DEBUG,
  1111. "DPP: Start wait for full response");
  1112. offchannel_send_action_done(wpa_s);
  1113. wpas_dpp_listen_start(wpa_s, auth->curr_freq);
  1114. return;
  1115. }
  1116. wpa_printf(MSG_DEBUG, "DPP: No confirm generated");
  1117. return;
  1118. }
  1119. os_memcpy(auth->peer_mac_addr, src, ETH_ALEN);
  1120. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
  1121. MAC2STR(src), auth->curr_freq, DPP_PA_AUTHENTICATION_CONF);
  1122. offchannel_send_action(wpa_s, auth->curr_freq,
  1123. src, wpa_s->own_addr, broadcast,
  1124. wpabuf_head(msg), wpabuf_len(msg),
  1125. 500, wpas_dpp_tx_status, 0);
  1126. wpabuf_free(msg);
  1127. wpa_s->dpp_auth_ok_on_ack = 1;
  1128. }
  1129. static void wpas_dpp_rx_auth_conf(struct wpa_supplicant *wpa_s, const u8 *src,
  1130. const u8 *hdr, const u8 *buf, size_t len)
  1131. {
  1132. struct dpp_authentication *auth = wpa_s->dpp_auth;
  1133. wpa_printf(MSG_DEBUG, "DPP: Authentication Confirmation from " MACSTR,
  1134. MAC2STR(src));
  1135. if (!auth) {
  1136. wpa_printf(MSG_DEBUG,
  1137. "DPP: No DPP Authentication in progress - drop");
  1138. return;
  1139. }
  1140. if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
  1141. wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
  1142. MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
  1143. return;
  1144. }
  1145. if (dpp_auth_conf_rx(auth, hdr, buf, len) < 0) {
  1146. wpa_printf(MSG_DEBUG, "DPP: Authentication failed");
  1147. return;
  1148. }
  1149. wpas_dpp_auth_success(wpa_s, 0);
  1150. }
  1151. static void wpas_dpp_rx_peer_disc_resp(struct wpa_supplicant *wpa_s,
  1152. const u8 *src,
  1153. const u8 *buf, size_t len)
  1154. {
  1155. struct wpa_ssid *ssid;
  1156. const u8 *connector, *trans_id, *status;
  1157. u16 connector_len, trans_id_len, status_len;
  1158. struct dpp_introduction intro;
  1159. struct rsn_pmksa_cache_entry *entry;
  1160. struct os_time now;
  1161. struct os_reltime rnow;
  1162. os_time_t expiry;
  1163. unsigned int seconds;
  1164. enum dpp_status_error res;
  1165. wpa_printf(MSG_DEBUG, "DPP: Peer Discovery Response from " MACSTR,
  1166. MAC2STR(src));
  1167. if (is_zero_ether_addr(wpa_s->dpp_intro_bssid) ||
  1168. os_memcmp(src, wpa_s->dpp_intro_bssid, ETH_ALEN) != 0) {
  1169. wpa_printf(MSG_DEBUG, "DPP: Not waiting for response from "
  1170. MACSTR " - drop", MAC2STR(src));
  1171. return;
  1172. }
  1173. offchannel_send_action_done(wpa_s);
  1174. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  1175. if (ssid == wpa_s->dpp_intro_network)
  1176. break;
  1177. }
  1178. if (!ssid || !ssid->dpp_connector || !ssid->dpp_netaccesskey ||
  1179. !ssid->dpp_csign) {
  1180. wpa_printf(MSG_DEBUG,
  1181. "DPP: Profile not found for network introduction");
  1182. return;
  1183. }
  1184. trans_id = dpp_get_attr(buf, len, DPP_ATTR_TRANSACTION_ID,
  1185. &trans_id_len);
  1186. if (!trans_id || trans_id_len != 1) {
  1187. wpa_printf(MSG_DEBUG,
  1188. "DPP: Peer did not include Transaction ID");
  1189. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
  1190. " fail=missing_transaction_id", MAC2STR(src));
  1191. goto fail;
  1192. }
  1193. if (trans_id[0] != TRANSACTION_ID) {
  1194. wpa_printf(MSG_DEBUG,
  1195. "DPP: Ignore frame with unexpected Transaction ID %u",
  1196. trans_id[0]);
  1197. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
  1198. " fail=transaction_id_mismatch", MAC2STR(src));
  1199. goto fail;
  1200. }
  1201. status = dpp_get_attr(buf, len, DPP_ATTR_STATUS, &status_len);
  1202. if (!status || status_len != 1) {
  1203. wpa_printf(MSG_DEBUG, "DPP: Peer did not include Status");
  1204. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
  1205. " fail=missing_status", MAC2STR(src));
  1206. goto fail;
  1207. }
  1208. if (status[0] != DPP_STATUS_OK) {
  1209. wpa_printf(MSG_DEBUG,
  1210. "DPP: Peer rejected network introduction: Status %u",
  1211. status[0]);
  1212. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
  1213. " status=%u", MAC2STR(src), status[0]);
  1214. goto fail;
  1215. }
  1216. connector = dpp_get_attr(buf, len, DPP_ATTR_CONNECTOR, &connector_len);
  1217. if (!connector) {
  1218. wpa_printf(MSG_DEBUG,
  1219. "DPP: Peer did not include its Connector");
  1220. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
  1221. " fail=missing_connector", MAC2STR(src));
  1222. goto fail;
  1223. }
  1224. res = dpp_peer_intro(&intro, ssid->dpp_connector,
  1225. ssid->dpp_netaccesskey,
  1226. ssid->dpp_netaccesskey_len,
  1227. ssid->dpp_csign,
  1228. ssid->dpp_csign_len,
  1229. connector, connector_len, &expiry);
  1230. if (res != DPP_STATUS_OK) {
  1231. wpa_printf(MSG_INFO,
  1232. "DPP: Network Introduction protocol resulted in failure");
  1233. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
  1234. " fail=peer_connector_validation_failed", MAC2STR(src));
  1235. goto fail;
  1236. }
  1237. entry = os_zalloc(sizeof(*entry));
  1238. if (!entry)
  1239. goto fail;
  1240. os_memcpy(entry->aa, src, ETH_ALEN);
  1241. os_memcpy(entry->pmkid, intro.pmkid, PMKID_LEN);
  1242. os_memcpy(entry->pmk, intro.pmk, intro.pmk_len);
  1243. entry->pmk_len = intro.pmk_len;
  1244. entry->akmp = WPA_KEY_MGMT_DPP;
  1245. if (expiry) {
  1246. os_get_time(&now);
  1247. seconds = expiry - now.sec;
  1248. } else {
  1249. seconds = 86400 * 7;
  1250. }
  1251. os_get_reltime(&rnow);
  1252. entry->expiration = rnow.sec + seconds;
  1253. entry->reauth_time = rnow.sec + seconds;
  1254. entry->network_ctx = ssid;
  1255. wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
  1256. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
  1257. " status=%u", MAC2STR(src), status[0]);
  1258. wpa_printf(MSG_DEBUG,
  1259. "DPP: Try connection again after successful network introduction");
  1260. if (wpa_supplicant_fast_associate(wpa_s) != 1) {
  1261. wpa_supplicant_cancel_sched_scan(wpa_s);
  1262. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1263. }
  1264. fail:
  1265. os_memset(&intro, 0, sizeof(intro));
  1266. }
  1267. static void
  1268. wpas_dpp_tx_pkex_status(struct wpa_supplicant *wpa_s,
  1269. unsigned int freq, const u8 *dst,
  1270. const u8 *src, const u8 *bssid,
  1271. const u8 *data, size_t data_len,
  1272. enum offchannel_send_action_result result)
  1273. {
  1274. const char *res_txt;
  1275. res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
  1276. (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
  1277. "FAILED");
  1278. wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
  1279. " result=%s (PKEX)",
  1280. freq, MAC2STR(dst), res_txt);
  1281. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
  1282. " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
  1283. /* TODO: Time out wait for response more quickly in error cases? */
  1284. if (!wpa_s->dpp_pkex) {
  1285. wpa_printf(MSG_DEBUG,
  1286. "DPP: Ignore TX status since there is no ongoing PKEX exchange");
  1287. return;
  1288. }
  1289. if (wpa_s->dpp_pkex->failed) {
  1290. wpa_printf(MSG_DEBUG,
  1291. "DPP: Terminate PKEX exchange due to an earlier error");
  1292. if (wpa_s->dpp_pkex->t > wpa_s->dpp_pkex->own_bi->pkex_t)
  1293. wpa_s->dpp_pkex->own_bi->pkex_t = wpa_s->dpp_pkex->t;
  1294. dpp_pkex_free(wpa_s->dpp_pkex);
  1295. wpa_s->dpp_pkex = NULL;
  1296. }
  1297. }
  1298. static void
  1299. wpas_dpp_rx_pkex_exchange_req(struct wpa_supplicant *wpa_s, const u8 *src,
  1300. const u8 *buf, size_t len, unsigned int freq)
  1301. {
  1302. struct wpabuf *msg;
  1303. unsigned int wait_time;
  1304. wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Request from " MACSTR,
  1305. MAC2STR(src));
  1306. /* TODO: Support multiple PKEX codes by iterating over all the enabled
  1307. * values here */
  1308. if (!wpa_s->dpp_pkex_code || !wpa_s->dpp_pkex_bi) {
  1309. wpa_printf(MSG_DEBUG,
  1310. "DPP: No PKEX code configured - ignore request");
  1311. return;
  1312. }
  1313. if (wpa_s->dpp_pkex) {
  1314. /* TODO: Support parallel operations */
  1315. wpa_printf(MSG_DEBUG,
  1316. "DPP: Already in PKEX session - ignore new request");
  1317. return;
  1318. }
  1319. wpa_s->dpp_pkex = dpp_pkex_rx_exchange_req(wpa_s, wpa_s->dpp_pkex_bi,
  1320. wpa_s->own_addr, src,
  1321. wpa_s->dpp_pkex_identifier,
  1322. wpa_s->dpp_pkex_code,
  1323. buf, len);
  1324. if (!wpa_s->dpp_pkex) {
  1325. wpa_printf(MSG_DEBUG,
  1326. "DPP: Failed to process the request - ignore it");
  1327. return;
  1328. }
  1329. msg = wpa_s->dpp_pkex->exchange_resp;
  1330. wait_time = wpa_s->max_remain_on_chan;
  1331. if (wait_time > 2000)
  1332. wait_time = 2000;
  1333. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
  1334. MAC2STR(src), freq, DPP_PA_PKEX_EXCHANGE_RESP);
  1335. offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
  1336. broadcast,
  1337. wpabuf_head(msg), wpabuf_len(msg),
  1338. wait_time, wpas_dpp_tx_pkex_status, 0);
  1339. }
  1340. static void
  1341. wpas_dpp_rx_pkex_exchange_resp(struct wpa_supplicant *wpa_s, const u8 *src,
  1342. const u8 *buf, size_t len, unsigned int freq)
  1343. {
  1344. struct wpabuf *msg;
  1345. unsigned int wait_time;
  1346. wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Response from " MACSTR,
  1347. MAC2STR(src));
  1348. /* TODO: Support multiple PKEX codes by iterating over all the enabled
  1349. * values here */
  1350. if (!wpa_s->dpp_pkex || !wpa_s->dpp_pkex->initiator ||
  1351. wpa_s->dpp_pkex->exchange_done) {
  1352. wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
  1353. return;
  1354. }
  1355. os_memcpy(wpa_s->dpp_pkex->peer_mac, src, ETH_ALEN);
  1356. msg = dpp_pkex_rx_exchange_resp(wpa_s->dpp_pkex, buf, len);
  1357. if (!msg) {
  1358. wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
  1359. return;
  1360. }
  1361. wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Request to " MACSTR,
  1362. MAC2STR(src));
  1363. wait_time = wpa_s->max_remain_on_chan;
  1364. if (wait_time > 2000)
  1365. wait_time = 2000;
  1366. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
  1367. MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_REQ);
  1368. offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
  1369. broadcast,
  1370. wpabuf_head(msg), wpabuf_len(msg),
  1371. wait_time, wpas_dpp_tx_pkex_status, 0);
  1372. wpabuf_free(msg);
  1373. }
  1374. static struct dpp_bootstrap_info *
  1375. wpas_dpp_pkex_finish(struct wpa_supplicant *wpa_s, const u8 *peer,
  1376. unsigned int freq)
  1377. {
  1378. struct dpp_pkex *pkex = wpa_s->dpp_pkex;
  1379. struct dpp_bootstrap_info *bi;
  1380. bi = os_zalloc(sizeof(*bi));
  1381. if (!bi)
  1382. return NULL;
  1383. bi->id = wpas_dpp_next_id(wpa_s);
  1384. bi->type = DPP_BOOTSTRAP_PKEX;
  1385. os_memcpy(bi->mac_addr, peer, ETH_ALEN);
  1386. bi->num_freq = 1;
  1387. bi->freq[0] = freq;
  1388. bi->curve = pkex->own_bi->curve;
  1389. bi->pubkey = pkex->peer_bootstrap_key;
  1390. pkex->peer_bootstrap_key = NULL;
  1391. dpp_pkex_free(pkex);
  1392. wpa_s->dpp_pkex = NULL;
  1393. if (dpp_bootstrap_key_hash(bi) < 0) {
  1394. dpp_bootstrap_info_free(bi);
  1395. return NULL;
  1396. }
  1397. dl_list_add(&wpa_s->dpp_bootstrap, &bi->list);
  1398. return bi;
  1399. }
  1400. static void
  1401. wpas_dpp_rx_pkex_commit_reveal_req(struct wpa_supplicant *wpa_s, const u8 *src,
  1402. const u8 *hdr, const u8 *buf, size_t len,
  1403. unsigned int freq)
  1404. {
  1405. struct wpabuf *msg;
  1406. unsigned int wait_time;
  1407. struct dpp_pkex *pkex = wpa_s->dpp_pkex;
  1408. wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Request from " MACSTR,
  1409. MAC2STR(src));
  1410. if (!pkex || pkex->initiator || !pkex->exchange_done) {
  1411. wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
  1412. return;
  1413. }
  1414. msg = dpp_pkex_rx_commit_reveal_req(pkex, hdr, buf, len);
  1415. if (!msg) {
  1416. wpa_printf(MSG_DEBUG, "DPP: Failed to process the request");
  1417. if (pkex->failed) {
  1418. wpa_printf(MSG_DEBUG, "DPP: Terminate PKEX exchange");
  1419. if (pkex->t > pkex->own_bi->pkex_t)
  1420. pkex->own_bi->pkex_t = pkex->t;
  1421. dpp_pkex_free(wpa_s->dpp_pkex);
  1422. wpa_s->dpp_pkex = NULL;
  1423. }
  1424. return;
  1425. }
  1426. wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Response to "
  1427. MACSTR, MAC2STR(src));
  1428. wait_time = wpa_s->max_remain_on_chan;
  1429. if (wait_time > 2000)
  1430. wait_time = 2000;
  1431. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
  1432. MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_RESP);
  1433. offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
  1434. broadcast,
  1435. wpabuf_head(msg), wpabuf_len(msg),
  1436. wait_time, wpas_dpp_tx_pkex_status, 0);
  1437. wpabuf_free(msg);
  1438. wpas_dpp_pkex_finish(wpa_s, src, freq);
  1439. }
  1440. static void
  1441. wpas_dpp_rx_pkex_commit_reveal_resp(struct wpa_supplicant *wpa_s, const u8 *src,
  1442. const u8 *hdr, const u8 *buf, size_t len,
  1443. unsigned int freq)
  1444. {
  1445. int res;
  1446. struct dpp_bootstrap_info *bi;
  1447. struct dpp_pkex *pkex = wpa_s->dpp_pkex;
  1448. char cmd[500];
  1449. wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Response from " MACSTR,
  1450. MAC2STR(src));
  1451. if (!pkex || !pkex->initiator || !pkex->exchange_done) {
  1452. wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
  1453. return;
  1454. }
  1455. res = dpp_pkex_rx_commit_reveal_resp(pkex, hdr, buf, len);
  1456. if (res < 0) {
  1457. wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
  1458. return;
  1459. }
  1460. bi = wpas_dpp_pkex_finish(wpa_s, src, freq);
  1461. if (!bi)
  1462. return;
  1463. os_snprintf(cmd, sizeof(cmd), " peer=%u %s",
  1464. bi->id,
  1465. wpa_s->dpp_pkex_auth_cmd ? wpa_s->dpp_pkex_auth_cmd : "");
  1466. wpa_printf(MSG_DEBUG,
  1467. "DPP: Start authentication after PKEX with parameters: %s",
  1468. cmd);
  1469. if (wpas_dpp_auth_init(wpa_s, cmd) < 0) {
  1470. wpa_printf(MSG_DEBUG,
  1471. "DPP: Authentication initialization failed");
  1472. return;
  1473. }
  1474. }
  1475. void wpas_dpp_rx_action(struct wpa_supplicant *wpa_s, const u8 *src,
  1476. const u8 *buf, size_t len, unsigned int freq)
  1477. {
  1478. u8 crypto_suite;
  1479. enum dpp_public_action_frame_type type;
  1480. const u8 *hdr;
  1481. unsigned int pkex_t;
  1482. if (len < DPP_HDR_LEN)
  1483. return;
  1484. if (WPA_GET_BE24(buf) != OUI_WFA || buf[3] != DPP_OUI_TYPE)
  1485. return;
  1486. hdr = buf;
  1487. buf += 4;
  1488. len -= 4;
  1489. crypto_suite = *buf++;
  1490. type = *buf++;
  1491. len -= 2;
  1492. wpa_printf(MSG_DEBUG,
  1493. "DPP: Received DPP Public Action frame crypto suite %u type %d from "
  1494. MACSTR " freq=%u",
  1495. crypto_suite, type, MAC2STR(src), freq);
  1496. if (crypto_suite != 1) {
  1497. wpa_printf(MSG_DEBUG, "DPP: Unsupported crypto suite %u",
  1498. crypto_suite);
  1499. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
  1500. " freq=%u type=%d ignore=unsupported-crypto-suite",
  1501. MAC2STR(src), freq, type);
  1502. return;
  1503. }
  1504. wpa_hexdump(MSG_MSGDUMP, "DPP: Received message attributes", buf, len);
  1505. if (dpp_check_attrs(buf, len) < 0) {
  1506. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
  1507. " freq=%u type=%d ignore=invalid-attributes",
  1508. MAC2STR(src), freq, type);
  1509. return;
  1510. }
  1511. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR " freq=%u type=%d",
  1512. MAC2STR(src), freq, type);
  1513. switch (type) {
  1514. case DPP_PA_AUTHENTICATION_REQ:
  1515. wpas_dpp_rx_auth_req(wpa_s, src, hdr, buf, len, freq);
  1516. break;
  1517. case DPP_PA_AUTHENTICATION_RESP:
  1518. wpas_dpp_rx_auth_resp(wpa_s, src, hdr, buf, len, freq);
  1519. break;
  1520. case DPP_PA_AUTHENTICATION_CONF:
  1521. wpas_dpp_rx_auth_conf(wpa_s, src, hdr, buf, len);
  1522. break;
  1523. case DPP_PA_PEER_DISCOVERY_RESP:
  1524. wpas_dpp_rx_peer_disc_resp(wpa_s, src, buf, len);
  1525. break;
  1526. case DPP_PA_PKEX_EXCHANGE_REQ:
  1527. wpas_dpp_rx_pkex_exchange_req(wpa_s, src, buf, len, freq);
  1528. break;
  1529. case DPP_PA_PKEX_EXCHANGE_RESP:
  1530. wpas_dpp_rx_pkex_exchange_resp(wpa_s, src, buf, len, freq);
  1531. break;
  1532. case DPP_PA_PKEX_COMMIT_REVEAL_REQ:
  1533. wpas_dpp_rx_pkex_commit_reveal_req(wpa_s, src, hdr, buf, len,
  1534. freq);
  1535. break;
  1536. case DPP_PA_PKEX_COMMIT_REVEAL_RESP:
  1537. wpas_dpp_rx_pkex_commit_reveal_resp(wpa_s, src, hdr, buf, len,
  1538. freq);
  1539. break;
  1540. default:
  1541. wpa_printf(MSG_DEBUG,
  1542. "DPP: Ignored unsupported frame subtype %d", type);
  1543. break;
  1544. }
  1545. if (wpa_s->dpp_pkex)
  1546. pkex_t = wpa_s->dpp_pkex->t;
  1547. else if (wpa_s->dpp_pkex_bi)
  1548. pkex_t = wpa_s->dpp_pkex_bi->pkex_t;
  1549. else
  1550. pkex_t = 0;
  1551. if (pkex_t >= PKEX_COUNTER_T_LIMIT) {
  1552. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_PKEX_T_LIMIT "id=0");
  1553. wpas_dpp_pkex_remove(wpa_s, "*");
  1554. }
  1555. }
  1556. static struct wpabuf *
  1557. wpas_dpp_gas_req_handler(void *ctx, const u8 *sa, const u8 *query,
  1558. size_t query_len)
  1559. {
  1560. struct wpa_supplicant *wpa_s = ctx;
  1561. struct dpp_authentication *auth = wpa_s->dpp_auth;
  1562. struct wpabuf *resp;
  1563. wpa_printf(MSG_DEBUG, "DPP: GAS request from " MACSTR,
  1564. MAC2STR(sa));
  1565. if (!auth || !auth->auth_success ||
  1566. os_memcmp(sa, auth->peer_mac_addr, ETH_ALEN) != 0) {
  1567. wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
  1568. return NULL;
  1569. }
  1570. wpa_hexdump(MSG_DEBUG,
  1571. "DPP: Received Configuration Request (GAS Query Request)",
  1572. query, query_len);
  1573. resp = dpp_conf_req_rx(auth, query, query_len);
  1574. if (!resp)
  1575. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
  1576. return resp;
  1577. }
  1578. static void
  1579. wpas_dpp_gas_status_handler(void *ctx, struct wpabuf *resp, int ok)
  1580. {
  1581. struct wpa_supplicant *wpa_s = ctx;
  1582. struct dpp_authentication *auth = wpa_s->dpp_auth;
  1583. if (!auth) {
  1584. wpabuf_free(resp);
  1585. return;
  1586. }
  1587. wpa_printf(MSG_DEBUG, "DPP: Configuration exchange completed (ok=%d)",
  1588. ok);
  1589. eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
  1590. offchannel_send_action_done(wpa_s);
  1591. wpas_dpp_listen_stop(wpa_s);
  1592. if (ok)
  1593. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT);
  1594. else
  1595. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
  1596. dpp_auth_deinit(wpa_s->dpp_auth);
  1597. wpa_s->dpp_auth = NULL;
  1598. wpabuf_free(resp);
  1599. }
  1600. static unsigned int wpas_dpp_next_configurator_id(struct wpa_supplicant *wpa_s)
  1601. {
  1602. struct dpp_configurator *conf;
  1603. unsigned int max_id = 0;
  1604. dl_list_for_each(conf, &wpa_s->dpp_configurator,
  1605. struct dpp_configurator, list) {
  1606. if (conf->id > max_id)
  1607. max_id = conf->id;
  1608. }
  1609. return max_id + 1;
  1610. }
  1611. int wpas_dpp_configurator_add(struct wpa_supplicant *wpa_s, const char *cmd)
  1612. {
  1613. char *curve = NULL;
  1614. char *key = NULL;
  1615. u8 *privkey = NULL;
  1616. size_t privkey_len = 0;
  1617. int ret = -1;
  1618. struct dpp_configurator *conf = NULL;
  1619. curve = get_param(cmd, " curve=");
  1620. key = get_param(cmd, " key=");
  1621. if (key) {
  1622. privkey_len = os_strlen(key) / 2;
  1623. privkey = os_malloc(privkey_len);
  1624. if (!privkey ||
  1625. hexstr2bin(key, privkey, privkey_len) < 0)
  1626. goto fail;
  1627. }
  1628. conf = dpp_keygen_configurator(curve, privkey, privkey_len);
  1629. if (!conf)
  1630. goto fail;
  1631. conf->id = wpas_dpp_next_configurator_id(wpa_s);
  1632. dl_list_add(&wpa_s->dpp_configurator, &conf->list);
  1633. ret = conf->id;
  1634. conf = NULL;
  1635. fail:
  1636. os_free(curve);
  1637. str_clear_free(key);
  1638. bin_clear_free(privkey, privkey_len);
  1639. dpp_configurator_free(conf);
  1640. return ret;
  1641. }
  1642. static int dpp_configurator_del(struct wpa_supplicant *wpa_s, unsigned int id)
  1643. {
  1644. struct dpp_configurator *conf, *tmp;
  1645. int found = 0;
  1646. dl_list_for_each_safe(conf, tmp, &wpa_s->dpp_configurator,
  1647. struct dpp_configurator, list) {
  1648. if (id && conf->id != id)
  1649. continue;
  1650. found = 1;
  1651. dl_list_del(&conf->list);
  1652. dpp_configurator_free(conf);
  1653. }
  1654. if (id == 0)
  1655. return 0; /* flush succeeds regardless of entries found */
  1656. return found ? 0 : -1;
  1657. }
  1658. int wpas_dpp_configurator_remove(struct wpa_supplicant *wpa_s, const char *id)
  1659. {
  1660. unsigned int id_val;
  1661. if (os_strcmp(id, "*") == 0) {
  1662. id_val = 0;
  1663. } else {
  1664. id_val = atoi(id);
  1665. if (id_val == 0)
  1666. return -1;
  1667. }
  1668. return dpp_configurator_del(wpa_s, id_val);
  1669. }
  1670. int wpas_dpp_configurator_sign(struct wpa_supplicant *wpa_s, const char *cmd)
  1671. {
  1672. struct dpp_authentication *auth;
  1673. int ret = -1;
  1674. char *curve = NULL;
  1675. auth = os_zalloc(sizeof(*auth));
  1676. if (!auth)
  1677. return -1;
  1678. curve = get_param(cmd, " curve=");
  1679. wpas_dpp_set_configurator(wpa_s, auth, cmd);
  1680. if (dpp_configurator_own_config(auth, curve) == 0) {
  1681. wpas_dpp_handle_config_obj(wpa_s, auth);
  1682. ret = 0;
  1683. }
  1684. dpp_auth_deinit(auth);
  1685. os_free(curve);
  1686. return ret;
  1687. }
  1688. static void
  1689. wpas_dpp_tx_introduction_status(struct wpa_supplicant *wpa_s,
  1690. unsigned int freq, const u8 *dst,
  1691. const u8 *src, const u8 *bssid,
  1692. const u8 *data, size_t data_len,
  1693. enum offchannel_send_action_result result)
  1694. {
  1695. const char *res_txt;
  1696. res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
  1697. (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
  1698. "FAILED");
  1699. wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
  1700. " result=%s (DPP Peer Discovery Request)",
  1701. freq, MAC2STR(dst), res_txt);
  1702. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
  1703. " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
  1704. /* TODO: Time out wait for response more quickly in error cases? */
  1705. }
  1706. int wpas_dpp_check_connect(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
  1707. struct wpa_bss *bss)
  1708. {
  1709. struct os_time now;
  1710. struct wpabuf *msg;
  1711. unsigned int wait_time;
  1712. if (!(ssid->key_mgmt & WPA_KEY_MGMT_DPP) || !bss)
  1713. return 0; /* Not using DPP AKM - continue */
  1714. if (wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid))
  1715. return 0; /* PMKSA exists for DPP AKM - continue */
  1716. if (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
  1717. !ssid->dpp_csign) {
  1718. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
  1719. "missing %s",
  1720. !ssid->dpp_connector ? "Connector" :
  1721. (!ssid->dpp_netaccesskey ? "netAccessKey" :
  1722. "C-sign-key"));
  1723. return -1;
  1724. }
  1725. os_get_time(&now);
  1726. if (ssid->dpp_netaccesskey_expiry &&
  1727. ssid->dpp_netaccesskey_expiry < now.sec) {
  1728. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
  1729. "netAccessKey expired");
  1730. return -1;
  1731. }
  1732. wpa_printf(MSG_DEBUG,
  1733. "DPP: Starting network introduction protocol to derive PMKSA for "
  1734. MACSTR, MAC2STR(bss->bssid));
  1735. msg = dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_REQ,
  1736. 5 + 4 + os_strlen(ssid->dpp_connector));
  1737. if (!msg)
  1738. return -1;
  1739. #ifdef CONFIG_TESTING_OPTIONS
  1740. if (dpp_test == DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ) {
  1741. wpa_printf(MSG_INFO, "DPP: TESTING - no Transaction ID");
  1742. goto skip_trans_id;
  1743. }
  1744. #endif /* CONFIG_TESTING_OPTIONS */
  1745. /* Transaction ID */
  1746. wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
  1747. wpabuf_put_le16(msg, 1);
  1748. wpabuf_put_u8(msg, TRANSACTION_ID);
  1749. #ifdef CONFIG_TESTING_OPTIONS
  1750. skip_trans_id:
  1751. if (dpp_test == DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ) {
  1752. wpa_printf(MSG_INFO, "DPP: TESTING - no Connector");
  1753. goto skip_connector;
  1754. }
  1755. #endif /* CONFIG_TESTING_OPTIONS */
  1756. /* DPP Connector */
  1757. wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
  1758. wpabuf_put_le16(msg, os_strlen(ssid->dpp_connector));
  1759. wpabuf_put_str(msg, ssid->dpp_connector);
  1760. #ifdef CONFIG_TESTING_OPTIONS
  1761. skip_connector:
  1762. #endif /* CONFIG_TESTING_OPTIONS */
  1763. /* TODO: Timeout on AP response */
  1764. wait_time = wpa_s->max_remain_on_chan;
  1765. if (wait_time > 2000)
  1766. wait_time = 2000;
  1767. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
  1768. MAC2STR(bss->bssid), bss->freq, DPP_PA_PEER_DISCOVERY_REQ);
  1769. offchannel_send_action(wpa_s, bss->freq, bss->bssid, wpa_s->own_addr,
  1770. broadcast,
  1771. wpabuf_head(msg), wpabuf_len(msg),
  1772. wait_time, wpas_dpp_tx_introduction_status, 0);
  1773. wpabuf_free(msg);
  1774. /* Request this connection attempt to terminate - new one will be
  1775. * started when network introduction protocol completes */
  1776. os_memcpy(wpa_s->dpp_intro_bssid, bss->bssid, ETH_ALEN);
  1777. wpa_s->dpp_intro_network = ssid;
  1778. return 1;
  1779. }
  1780. int wpas_dpp_pkex_add(struct wpa_supplicant *wpa_s, const char *cmd)
  1781. {
  1782. struct dpp_bootstrap_info *own_bi;
  1783. const char *pos, *end;
  1784. unsigned int wait_time;
  1785. pos = os_strstr(cmd, " own=");
  1786. if (!pos)
  1787. return -1;
  1788. pos += 5;
  1789. own_bi = dpp_bootstrap_get_id(wpa_s, atoi(pos));
  1790. if (!own_bi) {
  1791. wpa_printf(MSG_DEBUG,
  1792. "DPP: Identified bootstrap info not found");
  1793. return -1;
  1794. }
  1795. if (own_bi->type != DPP_BOOTSTRAP_PKEX) {
  1796. wpa_printf(MSG_DEBUG,
  1797. "DPP: Identified bootstrap info not for PKEX");
  1798. return -1;
  1799. }
  1800. wpa_s->dpp_pkex_bi = own_bi;
  1801. own_bi->pkex_t = 0; /* clear pending errors on new code */
  1802. os_free(wpa_s->dpp_pkex_identifier);
  1803. wpa_s->dpp_pkex_identifier = NULL;
  1804. pos = os_strstr(cmd, " identifier=");
  1805. if (pos) {
  1806. pos += 12;
  1807. end = os_strchr(pos, ' ');
  1808. if (!end)
  1809. return -1;
  1810. wpa_s->dpp_pkex_identifier = os_malloc(end - pos + 1);
  1811. if (!wpa_s->dpp_pkex_identifier)
  1812. return -1;
  1813. os_memcpy(wpa_s->dpp_pkex_identifier, pos, end - pos);
  1814. wpa_s->dpp_pkex_identifier[end - pos] = '\0';
  1815. }
  1816. pos = os_strstr(cmd, " code=");
  1817. if (!pos)
  1818. return -1;
  1819. os_free(wpa_s->dpp_pkex_code);
  1820. wpa_s->dpp_pkex_code = os_strdup(pos + 6);
  1821. if (!wpa_s->dpp_pkex_code)
  1822. return -1;
  1823. if (os_strstr(cmd, " init=1")) {
  1824. struct wpabuf *msg;
  1825. wpa_printf(MSG_DEBUG, "DPP: Initiating PKEX");
  1826. dpp_pkex_free(wpa_s->dpp_pkex);
  1827. wpa_s->dpp_pkex = dpp_pkex_init(wpa_s, own_bi, wpa_s->own_addr,
  1828. wpa_s->dpp_pkex_identifier,
  1829. wpa_s->dpp_pkex_code);
  1830. if (!wpa_s->dpp_pkex)
  1831. return -1;
  1832. msg = wpa_s->dpp_pkex->exchange_req;
  1833. wait_time = wpa_s->max_remain_on_chan;
  1834. if (wait_time > 2000)
  1835. wait_time = 2000;
  1836. /* TODO: Which channel to use? */
  1837. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
  1838. " freq=%u type=%d",
  1839. MAC2STR(broadcast), 2437, DPP_PA_PKEX_EXCHANGE_REQ);
  1840. offchannel_send_action(wpa_s, 2437, broadcast, wpa_s->own_addr,
  1841. broadcast,
  1842. wpabuf_head(msg), wpabuf_len(msg),
  1843. wait_time, wpas_dpp_tx_pkex_status, 0);
  1844. }
  1845. /* TODO: Support multiple PKEX info entries */
  1846. os_free(wpa_s->dpp_pkex_auth_cmd);
  1847. wpa_s->dpp_pkex_auth_cmd = os_strdup(cmd);
  1848. return 1;
  1849. }
  1850. int wpas_dpp_pkex_remove(struct wpa_supplicant *wpa_s, const char *id)
  1851. {
  1852. unsigned int id_val;
  1853. if (os_strcmp(id, "*") == 0) {
  1854. id_val = 0;
  1855. } else {
  1856. id_val = atoi(id);
  1857. if (id_val == 0)
  1858. return -1;
  1859. }
  1860. if ((id_val != 0 && id_val != 1) || !wpa_s->dpp_pkex_code)
  1861. return -1;
  1862. /* TODO: Support multiple PKEX entries */
  1863. os_free(wpa_s->dpp_pkex_code);
  1864. wpa_s->dpp_pkex_code = NULL;
  1865. os_free(wpa_s->dpp_pkex_identifier);
  1866. wpa_s->dpp_pkex_identifier = NULL;
  1867. os_free(wpa_s->dpp_pkex_auth_cmd);
  1868. wpa_s->dpp_pkex_auth_cmd = NULL;
  1869. wpa_s->dpp_pkex_bi = NULL;
  1870. /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */
  1871. dpp_pkex_free(wpa_s->dpp_pkex);
  1872. wpa_s->dpp_pkex = NULL;
  1873. return 0;
  1874. }
  1875. int wpas_dpp_init(struct wpa_supplicant *wpa_s)
  1876. {
  1877. u8 adv_proto_id[7];
  1878. adv_proto_id[0] = WLAN_EID_VENDOR_SPECIFIC;
  1879. adv_proto_id[1] = 5;
  1880. WPA_PUT_BE24(&adv_proto_id[2], OUI_WFA);
  1881. adv_proto_id[5] = DPP_OUI_TYPE;
  1882. adv_proto_id[6] = 0x01;
  1883. if (gas_server_register(wpa_s->gas_server, adv_proto_id,
  1884. sizeof(adv_proto_id), wpas_dpp_gas_req_handler,
  1885. wpas_dpp_gas_status_handler, wpa_s) < 0)
  1886. return -1;
  1887. dl_list_init(&wpa_s->dpp_bootstrap);
  1888. dl_list_init(&wpa_s->dpp_configurator);
  1889. wpa_s->dpp_init_done = 1;
  1890. return 0;
  1891. }
  1892. void wpas_dpp_deinit(struct wpa_supplicant *wpa_s)
  1893. {
  1894. #ifdef CONFIG_TESTING_OPTIONS
  1895. os_free(wpa_s->dpp_config_obj_override);
  1896. wpa_s->dpp_config_obj_override = NULL;
  1897. os_free(wpa_s->dpp_discovery_override);
  1898. wpa_s->dpp_discovery_override = NULL;
  1899. os_free(wpa_s->dpp_groups_override);
  1900. wpa_s->dpp_groups_override = NULL;
  1901. wpa_s->dpp_ignore_netaccesskey_mismatch = 0;
  1902. #endif /* CONFIG_TESTING_OPTIONS */
  1903. if (!wpa_s->dpp_init_done)
  1904. return;
  1905. eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
  1906. eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
  1907. offchannel_send_action_done(wpa_s);
  1908. wpas_dpp_listen_stop(wpa_s);
  1909. dpp_bootstrap_del(wpa_s, 0);
  1910. dpp_configurator_del(wpa_s, 0);
  1911. dpp_auth_deinit(wpa_s->dpp_auth);
  1912. wpa_s->dpp_auth = NULL;
  1913. wpas_dpp_pkex_remove(wpa_s, "*");
  1914. wpa_s->dpp_pkex = NULL;
  1915. os_memset(wpa_s->dpp_intro_bssid, 0, ETH_ALEN);
  1916. os_free(wpa_s->dpp_configurator_params);
  1917. wpa_s->dpp_configurator_params = NULL;
  1918. }