dpp_supplicant.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251
  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. u8 allowed_roles = DPP_CAPAB_CONFIGURATOR;
  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. allowed_roles = DPP_CAPAB_CONFIGURATOR;
  577. else if (os_strncmp(pos, "enrollee", 8) == 0)
  578. allowed_roles = DPP_CAPAB_ENROLLEE;
  579. else if (os_strncmp(pos, "either", 6) == 0)
  580. allowed_roles = DPP_CAPAB_CONFIGURATOR |
  581. DPP_CAPAB_ENROLLEE;
  582. else
  583. goto fail;
  584. }
  585. pos = os_strstr(cmd, " netrole=");
  586. if (pos) {
  587. pos += 9;
  588. wpa_s->dpp_netrole_ap = os_strncmp(pos, "ap", 2) == 0;
  589. }
  590. pos = os_strstr(cmd, " neg_freq=");
  591. if (pos)
  592. neg_freq = atoi(pos + 10);
  593. if (wpa_s->dpp_auth) {
  594. eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
  595. eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
  596. offchannel_send_action_done(wpa_s);
  597. dpp_auth_deinit(wpa_s->dpp_auth);
  598. }
  599. wpa_s->dpp_auth = dpp_auth_init(wpa_s, peer_bi, own_bi, allowed_roles,
  600. neg_freq,
  601. wpa_s->hw.modes, wpa_s->hw.num_modes);
  602. if (!wpa_s->dpp_auth)
  603. goto fail;
  604. wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth);
  605. wpas_dpp_set_configurator(wpa_s, wpa_s->dpp_auth, cmd);
  606. wpa_s->dpp_auth->neg_freq = neg_freq;
  607. if (!is_zero_ether_addr(peer_bi->mac_addr))
  608. os_memcpy(wpa_s->dpp_auth->peer_mac_addr, peer_bi->mac_addr,
  609. ETH_ALEN);
  610. return wpas_dpp_auth_init_next(wpa_s);
  611. fail:
  612. return -1;
  613. }
  614. struct wpas_dpp_listen_work {
  615. unsigned int freq;
  616. unsigned int duration;
  617. struct wpabuf *probe_resp_ie;
  618. };
  619. static void wpas_dpp_listen_work_free(struct wpas_dpp_listen_work *lwork)
  620. {
  621. if (!lwork)
  622. return;
  623. os_free(lwork);
  624. }
  625. static void wpas_dpp_listen_work_done(struct wpa_supplicant *wpa_s)
  626. {
  627. struct wpas_dpp_listen_work *lwork;
  628. if (!wpa_s->dpp_listen_work)
  629. return;
  630. lwork = wpa_s->dpp_listen_work->ctx;
  631. wpas_dpp_listen_work_free(lwork);
  632. radio_work_done(wpa_s->dpp_listen_work);
  633. wpa_s->dpp_listen_work = NULL;
  634. }
  635. static void dpp_start_listen_cb(struct wpa_radio_work *work, int deinit)
  636. {
  637. struct wpa_supplicant *wpa_s = work->wpa_s;
  638. struct wpas_dpp_listen_work *lwork = work->ctx;
  639. if (deinit) {
  640. if (work->started) {
  641. wpa_s->dpp_listen_work = NULL;
  642. wpas_dpp_listen_stop(wpa_s);
  643. }
  644. wpas_dpp_listen_work_free(lwork);
  645. return;
  646. }
  647. wpa_s->dpp_listen_work = work;
  648. wpa_s->dpp_pending_listen_freq = lwork->freq;
  649. if (wpa_drv_remain_on_channel(wpa_s, lwork->freq,
  650. wpa_s->max_remain_on_chan) < 0) {
  651. wpa_printf(MSG_DEBUG,
  652. "DPP: Failed to request the driver to remain on channel (%u MHz) for listen",
  653. lwork->freq);
  654. wpas_dpp_listen_work_done(wpa_s);
  655. wpa_s->dpp_pending_listen_freq = 0;
  656. return;
  657. }
  658. wpa_s->off_channel_freq = 0;
  659. wpa_s->roc_waiting_drv_freq = lwork->freq;
  660. }
  661. static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
  662. unsigned int freq)
  663. {
  664. struct wpas_dpp_listen_work *lwork;
  665. if (wpa_s->dpp_listen_work) {
  666. wpa_printf(MSG_DEBUG,
  667. "DPP: Reject start_listen since dpp_listen_work already exists");
  668. return -1;
  669. }
  670. if (wpa_s->dpp_listen_freq)
  671. wpas_dpp_listen_stop(wpa_s);
  672. wpa_s->dpp_listen_freq = freq;
  673. lwork = os_zalloc(sizeof(*lwork));
  674. if (!lwork)
  675. return -1;
  676. lwork->freq = freq;
  677. if (radio_add_work(wpa_s, freq, "dpp-listen", 0, dpp_start_listen_cb,
  678. lwork) < 0) {
  679. wpas_dpp_listen_work_free(lwork);
  680. return -1;
  681. }
  682. return 0;
  683. }
  684. int wpas_dpp_listen(struct wpa_supplicant *wpa_s, const char *cmd)
  685. {
  686. int freq;
  687. freq = atoi(cmd);
  688. if (freq <= 0)
  689. return -1;
  690. if (os_strstr(cmd, " role=configurator"))
  691. wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR;
  692. else if (os_strstr(cmd, " role=enrollee"))
  693. wpa_s->dpp_allowed_roles = DPP_CAPAB_ENROLLEE;
  694. else
  695. wpa_s->dpp_allowed_roles = DPP_CAPAB_CONFIGURATOR |
  696. DPP_CAPAB_ENROLLEE;
  697. wpa_s->dpp_qr_mutual = os_strstr(cmd, " qr=mutual") != NULL;
  698. wpa_s->dpp_netrole_ap = os_strstr(cmd, " netrole=ap") != NULL;
  699. if (wpa_s->dpp_listen_freq == (unsigned int) freq) {
  700. wpa_printf(MSG_DEBUG, "DPP: Already listening on %u MHz",
  701. freq);
  702. return 0;
  703. }
  704. return wpas_dpp_listen_start(wpa_s, freq);
  705. }
  706. void wpas_dpp_listen_stop(struct wpa_supplicant *wpa_s)
  707. {
  708. if (!wpa_s->dpp_listen_freq)
  709. return;
  710. wpa_printf(MSG_DEBUG, "DPP: Stop listen on %u MHz",
  711. wpa_s->dpp_listen_freq);
  712. wpa_drv_cancel_remain_on_channel(wpa_s);
  713. wpa_s->dpp_listen_freq = 0;
  714. wpas_dpp_listen_work_done(wpa_s);
  715. }
  716. void wpas_dpp_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
  717. unsigned int freq)
  718. {
  719. if (!wpa_s->dpp_listen_freq && !wpa_s->dpp_pending_listen_freq)
  720. return;
  721. wpa_printf(MSG_DEBUG,
  722. "DPP: remain-on-channel callback (off_channel_freq=%u dpp_pending_listen_freq=%d roc_waiting_drv_freq=%d freq=%u)",
  723. wpa_s->off_channel_freq, wpa_s->dpp_pending_listen_freq,
  724. wpa_s->roc_waiting_drv_freq, freq);
  725. if (wpa_s->off_channel_freq &&
  726. wpa_s->off_channel_freq == wpa_s->dpp_pending_listen_freq) {
  727. wpa_printf(MSG_DEBUG, "DPP: Listen on %u MHz started", freq);
  728. wpa_s->dpp_pending_listen_freq = 0;
  729. } else {
  730. wpa_printf(MSG_DEBUG,
  731. "DPP: Ignore remain-on-channel callback (off_channel_freq=%u dpp_pending_listen_freq=%d freq=%u)",
  732. wpa_s->off_channel_freq,
  733. wpa_s->dpp_pending_listen_freq, freq);
  734. }
  735. }
  736. void wpas_dpp_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
  737. unsigned int freq)
  738. {
  739. wpas_dpp_listen_work_done(wpa_s);
  740. if (wpa_s->dpp_auth && !wpa_s->dpp_gas_client) {
  741. /* Continue listen with a new remain-on-channel */
  742. wpa_printf(MSG_DEBUG,
  743. "DPP: Continue wait on %u MHz for the ongoing DPP provisioning session",
  744. wpa_s->dpp_auth->curr_freq);
  745. wpas_dpp_listen_start(wpa_s, wpa_s->dpp_auth->curr_freq);
  746. return;
  747. }
  748. if (wpa_s->dpp_listen_freq) {
  749. /* Continue listen with a new remain-on-channel */
  750. wpas_dpp_listen_start(wpa_s, wpa_s->dpp_listen_freq);
  751. }
  752. }
  753. static void wpas_dpp_rx_auth_req(struct wpa_supplicant *wpa_s, const u8 *src,
  754. const u8 *hdr, const u8 *buf, size_t len,
  755. unsigned int freq)
  756. {
  757. const u8 *r_bootstrap, *i_bootstrap;
  758. u16 r_bootstrap_len, i_bootstrap_len;
  759. struct dpp_bootstrap_info *bi, *own_bi = NULL, *peer_bi = NULL;
  760. wpa_printf(MSG_DEBUG, "DPP: Authentication Request from " MACSTR,
  761. MAC2STR(src));
  762. r_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_R_BOOTSTRAP_KEY_HASH,
  763. &r_bootstrap_len);
  764. if (!r_bootstrap || r_bootstrap_len != SHA256_MAC_LEN) {
  765. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
  766. "Missing or invalid required Responder Bootstrapping Key Hash attribute");
  767. return;
  768. }
  769. wpa_hexdump(MSG_MSGDUMP, "DPP: Responder Bootstrapping Key Hash",
  770. r_bootstrap, r_bootstrap_len);
  771. i_bootstrap = dpp_get_attr(buf, len, DPP_ATTR_I_BOOTSTRAP_KEY_HASH,
  772. &i_bootstrap_len);
  773. if (!i_bootstrap || i_bootstrap_len != SHA256_MAC_LEN) {
  774. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
  775. "Missing or invalid required Initiator Bootstrapping Key Hash attribute");
  776. return;
  777. }
  778. wpa_hexdump(MSG_MSGDUMP, "DPP: Initiator Bootstrapping Key Hash",
  779. i_bootstrap, i_bootstrap_len);
  780. /* Try to find own and peer bootstrapping key matches based on the
  781. * received hash values */
  782. dl_list_for_each(bi, &wpa_s->dpp_bootstrap, struct dpp_bootstrap_info,
  783. list) {
  784. if (!own_bi && bi->own &&
  785. os_memcmp(bi->pubkey_hash, r_bootstrap,
  786. SHA256_MAC_LEN) == 0) {
  787. wpa_printf(MSG_DEBUG,
  788. "DPP: Found matching own bootstrapping information");
  789. own_bi = bi;
  790. }
  791. if (!peer_bi && !bi->own &&
  792. os_memcmp(bi->pubkey_hash, i_bootstrap,
  793. SHA256_MAC_LEN) == 0) {
  794. wpa_printf(MSG_DEBUG,
  795. "DPP: Found matching peer bootstrapping information");
  796. peer_bi = bi;
  797. }
  798. if (own_bi && peer_bi)
  799. break;
  800. }
  801. if (!own_bi) {
  802. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
  803. "No matching own bootstrapping key found - ignore message");
  804. return;
  805. }
  806. if (wpa_s->dpp_auth) {
  807. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_FAIL
  808. "Already in DPP authentication exchange - ignore new one");
  809. return;
  810. }
  811. wpa_s->dpp_gas_client = 0;
  812. wpa_s->dpp_auth_ok_on_ack = 0;
  813. wpa_s->dpp_auth = dpp_auth_req_rx(wpa_s, wpa_s->dpp_allowed_roles,
  814. wpa_s->dpp_qr_mutual,
  815. peer_bi, own_bi, freq, hdr, buf, len);
  816. if (!wpa_s->dpp_auth) {
  817. wpa_printf(MSG_DEBUG, "DPP: No response generated");
  818. return;
  819. }
  820. wpas_dpp_set_testing_options(wpa_s, wpa_s->dpp_auth);
  821. wpas_dpp_set_configurator(wpa_s, wpa_s->dpp_auth,
  822. wpa_s->dpp_configurator_params);
  823. os_memcpy(wpa_s->dpp_auth->peer_mac_addr, src, ETH_ALEN);
  824. if (wpa_s->dpp_listen_freq &&
  825. wpa_s->dpp_listen_freq != wpa_s->dpp_auth->curr_freq) {
  826. wpa_printf(MSG_DEBUG,
  827. "DPP: Stop listen on %u MHz to allow response on the request %u MHz",
  828. wpa_s->dpp_listen_freq, wpa_s->dpp_auth->curr_freq);
  829. wpas_dpp_listen_stop(wpa_s);
  830. }
  831. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
  832. MAC2STR(src), wpa_s->dpp_auth->curr_freq,
  833. DPP_PA_AUTHENTICATION_RESP);
  834. offchannel_send_action(wpa_s, wpa_s->dpp_auth->curr_freq,
  835. src, wpa_s->own_addr, broadcast,
  836. wpabuf_head(wpa_s->dpp_auth->resp_msg),
  837. wpabuf_len(wpa_s->dpp_auth->resp_msg),
  838. 500, wpas_dpp_tx_status, 0);
  839. }
  840. static void wpas_dpp_start_gas_server(struct wpa_supplicant *wpa_s)
  841. {
  842. /* TODO: stop wait and start ROC */
  843. }
  844. static struct wpa_ssid * wpas_dpp_add_network(struct wpa_supplicant *wpa_s,
  845. struct dpp_authentication *auth)
  846. {
  847. struct wpa_ssid *ssid;
  848. ssid = wpa_config_add_network(wpa_s->conf);
  849. if (!ssid)
  850. return NULL;
  851. wpas_notify_network_added(wpa_s, ssid);
  852. wpa_config_set_network_defaults(ssid);
  853. ssid->disabled = 1;
  854. ssid->ssid = os_malloc(auth->ssid_len);
  855. if (!ssid->ssid)
  856. goto fail;
  857. os_memcpy(ssid->ssid, auth->ssid, auth->ssid_len);
  858. ssid->ssid_len = auth->ssid_len;
  859. if (auth->connector) {
  860. ssid->key_mgmt = WPA_KEY_MGMT_DPP;
  861. ssid->ieee80211w = 1;
  862. ssid->dpp_connector = os_strdup(auth->connector);
  863. if (!ssid->dpp_connector)
  864. goto fail;
  865. }
  866. if (auth->c_sign_key) {
  867. ssid->dpp_csign = os_malloc(wpabuf_len(auth->c_sign_key));
  868. if (!ssid->dpp_csign)
  869. goto fail;
  870. os_memcpy(ssid->dpp_csign, wpabuf_head(auth->c_sign_key),
  871. wpabuf_len(auth->c_sign_key));
  872. ssid->dpp_csign_len = wpabuf_len(auth->c_sign_key);
  873. }
  874. if (auth->net_access_key) {
  875. ssid->dpp_netaccesskey =
  876. os_malloc(wpabuf_len(auth->net_access_key));
  877. if (!ssid->dpp_netaccesskey)
  878. goto fail;
  879. os_memcpy(ssid->dpp_netaccesskey,
  880. wpabuf_head(auth->net_access_key),
  881. wpabuf_len(auth->net_access_key));
  882. ssid->dpp_netaccesskey_len = wpabuf_len(auth->net_access_key);
  883. ssid->dpp_netaccesskey_expiry = auth->net_access_key_expiry;
  884. }
  885. if (!auth->connector) {
  886. ssid->key_mgmt = WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_PSK_SHA256;
  887. ssid->ieee80211w = 1;
  888. if (auth->passphrase[0]) {
  889. if (wpa_config_set_quoted(ssid, "psk",
  890. auth->passphrase) < 0)
  891. goto fail;
  892. wpa_config_update_psk(ssid);
  893. ssid->export_keys = 1;
  894. } else {
  895. ssid->psk_set = auth->psk_set;
  896. os_memcpy(ssid->psk, auth->psk, PMK_LEN);
  897. }
  898. }
  899. return ssid;
  900. fail:
  901. wpas_notify_network_removed(wpa_s, ssid);
  902. wpa_config_remove_network(wpa_s->conf, ssid->id);
  903. return NULL;
  904. }
  905. static void wpas_dpp_process_config(struct wpa_supplicant *wpa_s,
  906. struct dpp_authentication *auth)
  907. {
  908. struct wpa_ssid *ssid;
  909. if (wpa_s->conf->dpp_config_processing < 1)
  910. return;
  911. ssid = wpas_dpp_add_network(wpa_s, auth);
  912. if (!ssid)
  913. return;
  914. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_NETWORK_ID "%d", ssid->id);
  915. if (wpa_s->conf->dpp_config_processing < 2)
  916. return;
  917. wpa_printf(MSG_DEBUG, "DPP: Trying to connect to the new network");
  918. ssid->disabled = 0;
  919. wpa_s->disconnected = 0;
  920. wpa_s->reassociate = 1;
  921. wpa_s->scan_runs = 0;
  922. wpa_s->normal_scans = 0;
  923. wpa_supplicant_cancel_sched_scan(wpa_s);
  924. wpa_supplicant_req_scan(wpa_s, 0, 0);
  925. }
  926. static void wpas_dpp_handle_config_obj(struct wpa_supplicant *wpa_s,
  927. struct dpp_authentication *auth)
  928. {
  929. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_RECEIVED);
  930. if (auth->ssid_len)
  931. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONFOBJ_SSID "%s",
  932. wpa_ssid_txt(auth->ssid, auth->ssid_len));
  933. if (auth->connector) {
  934. /* TODO: Save the Connector and consider using a command
  935. * to fetch the value instead of sending an event with
  936. * it. The Connector could end up being larger than what
  937. * most clients are ready to receive as an event
  938. * message. */
  939. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONNECTOR "%s",
  940. auth->connector);
  941. }
  942. if (auth->c_sign_key) {
  943. char *hex;
  944. size_t hexlen;
  945. hexlen = 2 * wpabuf_len(auth->c_sign_key) + 1;
  946. hex = os_malloc(hexlen);
  947. if (hex) {
  948. wpa_snprintf_hex(hex, hexlen,
  949. wpabuf_head(auth->c_sign_key),
  950. wpabuf_len(auth->c_sign_key));
  951. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_C_SIGN_KEY "%s",
  952. hex);
  953. os_free(hex);
  954. }
  955. }
  956. if (auth->net_access_key) {
  957. char *hex;
  958. size_t hexlen;
  959. hexlen = 2 * wpabuf_len(auth->net_access_key) + 1;
  960. hex = os_malloc(hexlen);
  961. if (hex) {
  962. wpa_snprintf_hex(hex, hexlen,
  963. wpabuf_head(auth->net_access_key),
  964. wpabuf_len(auth->net_access_key));
  965. if (auth->net_access_key_expiry)
  966. wpa_msg(wpa_s, MSG_INFO,
  967. DPP_EVENT_NET_ACCESS_KEY "%s %lu", hex,
  968. (long unsigned)
  969. auth->net_access_key_expiry);
  970. else
  971. wpa_msg(wpa_s, MSG_INFO,
  972. DPP_EVENT_NET_ACCESS_KEY "%s", hex);
  973. os_free(hex);
  974. }
  975. }
  976. wpas_dpp_process_config(wpa_s, auth);
  977. }
  978. static void wpas_dpp_gas_resp_cb(void *ctx, const u8 *addr, u8 dialog_token,
  979. enum gas_query_result result,
  980. const struct wpabuf *adv_proto,
  981. const struct wpabuf *resp, u16 status_code)
  982. {
  983. struct wpa_supplicant *wpa_s = ctx;
  984. const u8 *pos;
  985. struct dpp_authentication *auth = wpa_s->dpp_auth;
  986. if (!auth || !auth->auth_success) {
  987. wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
  988. return;
  989. }
  990. if (!resp || status_code != WLAN_STATUS_SUCCESS) {
  991. wpa_printf(MSG_DEBUG, "DPP: GAS query did not succeed");
  992. goto fail;
  993. }
  994. wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response adv_proto",
  995. adv_proto);
  996. wpa_hexdump_buf(MSG_DEBUG, "DPP: Configuration Response (GAS response)",
  997. resp);
  998. if (wpabuf_len(adv_proto) != 10 ||
  999. !(pos = wpabuf_head(adv_proto)) ||
  1000. pos[0] != WLAN_EID_ADV_PROTO ||
  1001. pos[1] != 8 ||
  1002. pos[3] != WLAN_EID_VENDOR_SPECIFIC ||
  1003. pos[4] != 5 ||
  1004. WPA_GET_BE24(&pos[5]) != OUI_WFA ||
  1005. pos[8] != 0x1a ||
  1006. pos[9] != 1) {
  1007. wpa_printf(MSG_DEBUG,
  1008. "DPP: Not a DPP Advertisement Protocol ID");
  1009. goto fail;
  1010. }
  1011. if (dpp_conf_resp_rx(auth, resp) < 0) {
  1012. wpa_printf(MSG_DEBUG, "DPP: Configuration attempt failed");
  1013. goto fail;
  1014. }
  1015. wpas_dpp_handle_config_obj(wpa_s, auth);
  1016. dpp_auth_deinit(wpa_s->dpp_auth);
  1017. wpa_s->dpp_auth = NULL;
  1018. return;
  1019. fail:
  1020. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
  1021. dpp_auth_deinit(wpa_s->dpp_auth);
  1022. wpa_s->dpp_auth = NULL;
  1023. }
  1024. static void wpas_dpp_start_gas_client(struct wpa_supplicant *wpa_s)
  1025. {
  1026. struct dpp_authentication *auth = wpa_s->dpp_auth;
  1027. struct wpabuf *buf, *conf_req;
  1028. char json[100];
  1029. int res;
  1030. wpa_s->dpp_gas_client = 1;
  1031. os_snprintf(json, sizeof(json),
  1032. "{\"name\":\"Test\","
  1033. "\"wi-fi_tech\":\"infra\","
  1034. "\"netRole\":\"%s\"}",
  1035. wpa_s->dpp_netrole_ap ? "ap" : "sta");
  1036. wpa_printf(MSG_DEBUG, "DPP: GAS Config Attributes: %s", json);
  1037. offchannel_send_action_done(wpa_s);
  1038. wpas_dpp_listen_stop(wpa_s);
  1039. conf_req = dpp_build_conf_req(auth, json);
  1040. if (!conf_req) {
  1041. wpa_printf(MSG_DEBUG,
  1042. "DPP: No configuration request data available");
  1043. return;
  1044. }
  1045. buf = gas_build_initial_req(0, 10 + 2 + wpabuf_len(conf_req));
  1046. if (!buf) {
  1047. wpabuf_free(conf_req);
  1048. return;
  1049. }
  1050. /* Advertisement Protocol IE */
  1051. wpabuf_put_u8(buf, WLAN_EID_ADV_PROTO);
  1052. wpabuf_put_u8(buf, 8); /* Length */
  1053. wpabuf_put_u8(buf, 0x7f);
  1054. wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
  1055. wpabuf_put_u8(buf, 5);
  1056. wpabuf_put_be24(buf, OUI_WFA);
  1057. wpabuf_put_u8(buf, DPP_OUI_TYPE);
  1058. wpabuf_put_u8(buf, 0x01);
  1059. /* GAS Query */
  1060. wpabuf_put_le16(buf, wpabuf_len(conf_req));
  1061. wpabuf_put_buf(buf, conf_req);
  1062. wpabuf_free(conf_req);
  1063. wpa_printf(MSG_DEBUG, "DPP: GAS request to " MACSTR " (freq %u MHz)",
  1064. MAC2STR(auth->peer_mac_addr), auth->curr_freq);
  1065. res = gas_query_req(wpa_s->gas, auth->peer_mac_addr, auth->curr_freq,
  1066. buf, wpas_dpp_gas_resp_cb, wpa_s);
  1067. if (res < 0) {
  1068. wpa_msg(wpa_s, MSG_DEBUG, "GAS: Failed to send Query Request");
  1069. wpabuf_free(buf);
  1070. } else {
  1071. wpa_printf(MSG_DEBUG,
  1072. "DPP: GAS query started with dialog token %u", res);
  1073. }
  1074. }
  1075. static void wpas_dpp_auth_success(struct wpa_supplicant *wpa_s, int initiator)
  1076. {
  1077. wpa_printf(MSG_DEBUG, "DPP: Authentication succeeded");
  1078. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_AUTH_SUCCESS "init=%d", initiator);
  1079. if (wpa_s->dpp_auth->configurator)
  1080. wpas_dpp_start_gas_server(wpa_s);
  1081. else
  1082. wpas_dpp_start_gas_client(wpa_s);
  1083. }
  1084. static void wpas_dpp_rx_auth_resp(struct wpa_supplicant *wpa_s, const u8 *src,
  1085. const u8 *hdr, const u8 *buf, size_t len,
  1086. unsigned int freq)
  1087. {
  1088. struct dpp_authentication *auth = wpa_s->dpp_auth;
  1089. struct wpabuf *msg;
  1090. wpa_printf(MSG_DEBUG, "DPP: Authentication Response from " MACSTR
  1091. " (freq %u MHz)", MAC2STR(src), freq);
  1092. if (!auth) {
  1093. wpa_printf(MSG_DEBUG,
  1094. "DPP: No DPP Authentication in progress - drop");
  1095. return;
  1096. }
  1097. if (!is_zero_ether_addr(auth->peer_mac_addr) &&
  1098. os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
  1099. wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
  1100. MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
  1101. return;
  1102. }
  1103. eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
  1104. if (auth->curr_freq != freq && auth->neg_freq == freq) {
  1105. wpa_printf(MSG_DEBUG,
  1106. "DPP: Responder accepted request for different negotiation channel");
  1107. auth->curr_freq = freq;
  1108. }
  1109. eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
  1110. msg = dpp_auth_resp_rx(auth, hdr, buf, len);
  1111. if (!msg) {
  1112. if (auth->auth_resp_status == DPP_STATUS_RESPONSE_PENDING) {
  1113. wpa_printf(MSG_DEBUG,
  1114. "DPP: Start wait for full response");
  1115. offchannel_send_action_done(wpa_s);
  1116. wpas_dpp_listen_start(wpa_s, auth->curr_freq);
  1117. return;
  1118. }
  1119. wpa_printf(MSG_DEBUG, "DPP: No confirm generated");
  1120. return;
  1121. }
  1122. os_memcpy(auth->peer_mac_addr, src, ETH_ALEN);
  1123. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
  1124. MAC2STR(src), auth->curr_freq, DPP_PA_AUTHENTICATION_CONF);
  1125. offchannel_send_action(wpa_s, auth->curr_freq,
  1126. src, wpa_s->own_addr, broadcast,
  1127. wpabuf_head(msg), wpabuf_len(msg),
  1128. 500, wpas_dpp_tx_status, 0);
  1129. wpabuf_free(msg);
  1130. wpa_s->dpp_auth_ok_on_ack = 1;
  1131. }
  1132. static void wpas_dpp_rx_auth_conf(struct wpa_supplicant *wpa_s, const u8 *src,
  1133. const u8 *hdr, const u8 *buf, size_t len)
  1134. {
  1135. struct dpp_authentication *auth = wpa_s->dpp_auth;
  1136. wpa_printf(MSG_DEBUG, "DPP: Authentication Confirmation from " MACSTR,
  1137. MAC2STR(src));
  1138. if (!auth) {
  1139. wpa_printf(MSG_DEBUG,
  1140. "DPP: No DPP Authentication in progress - drop");
  1141. return;
  1142. }
  1143. if (os_memcmp(src, auth->peer_mac_addr, ETH_ALEN) != 0) {
  1144. wpa_printf(MSG_DEBUG, "DPP: MAC address mismatch (expected "
  1145. MACSTR ") - drop", MAC2STR(auth->peer_mac_addr));
  1146. return;
  1147. }
  1148. if (dpp_auth_conf_rx(auth, hdr, buf, len) < 0) {
  1149. wpa_printf(MSG_DEBUG, "DPP: Authentication failed");
  1150. return;
  1151. }
  1152. wpas_dpp_auth_success(wpa_s, 0);
  1153. }
  1154. static void wpas_dpp_rx_peer_disc_resp(struct wpa_supplicant *wpa_s,
  1155. const u8 *src,
  1156. const u8 *buf, size_t len)
  1157. {
  1158. struct wpa_ssid *ssid;
  1159. const u8 *connector, *trans_id, *status;
  1160. u16 connector_len, trans_id_len, status_len;
  1161. struct dpp_introduction intro;
  1162. struct rsn_pmksa_cache_entry *entry;
  1163. struct os_time now;
  1164. struct os_reltime rnow;
  1165. os_time_t expiry;
  1166. unsigned int seconds;
  1167. enum dpp_status_error res;
  1168. wpa_printf(MSG_DEBUG, "DPP: Peer Discovery Response from " MACSTR,
  1169. MAC2STR(src));
  1170. if (is_zero_ether_addr(wpa_s->dpp_intro_bssid) ||
  1171. os_memcmp(src, wpa_s->dpp_intro_bssid, ETH_ALEN) != 0) {
  1172. wpa_printf(MSG_DEBUG, "DPP: Not waiting for response from "
  1173. MACSTR " - drop", MAC2STR(src));
  1174. return;
  1175. }
  1176. offchannel_send_action_done(wpa_s);
  1177. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  1178. if (ssid == wpa_s->dpp_intro_network)
  1179. break;
  1180. }
  1181. if (!ssid || !ssid->dpp_connector || !ssid->dpp_netaccesskey ||
  1182. !ssid->dpp_csign) {
  1183. wpa_printf(MSG_DEBUG,
  1184. "DPP: Profile not found for network introduction");
  1185. return;
  1186. }
  1187. trans_id = dpp_get_attr(buf, len, DPP_ATTR_TRANSACTION_ID,
  1188. &trans_id_len);
  1189. if (!trans_id || trans_id_len != 1) {
  1190. wpa_printf(MSG_DEBUG,
  1191. "DPP: Peer did not include Transaction ID");
  1192. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
  1193. " fail=missing_transaction_id", MAC2STR(src));
  1194. goto fail;
  1195. }
  1196. if (trans_id[0] != TRANSACTION_ID) {
  1197. wpa_printf(MSG_DEBUG,
  1198. "DPP: Ignore frame with unexpected Transaction ID %u",
  1199. trans_id[0]);
  1200. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
  1201. " fail=transaction_id_mismatch", MAC2STR(src));
  1202. goto fail;
  1203. }
  1204. status = dpp_get_attr(buf, len, DPP_ATTR_STATUS, &status_len);
  1205. if (!status || status_len != 1) {
  1206. wpa_printf(MSG_DEBUG, "DPP: Peer did not include Status");
  1207. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
  1208. " fail=missing_status", MAC2STR(src));
  1209. goto fail;
  1210. }
  1211. if (status[0] != DPP_STATUS_OK) {
  1212. wpa_printf(MSG_DEBUG,
  1213. "DPP: Peer rejected network introduction: Status %u",
  1214. status[0]);
  1215. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
  1216. " status=%u", MAC2STR(src), status[0]);
  1217. goto fail;
  1218. }
  1219. connector = dpp_get_attr(buf, len, DPP_ATTR_CONNECTOR, &connector_len);
  1220. if (!connector) {
  1221. wpa_printf(MSG_DEBUG,
  1222. "DPP: Peer did not include its Connector");
  1223. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
  1224. " fail=missing_connector", MAC2STR(src));
  1225. goto fail;
  1226. }
  1227. res = dpp_peer_intro(&intro, ssid->dpp_connector,
  1228. ssid->dpp_netaccesskey,
  1229. ssid->dpp_netaccesskey_len,
  1230. ssid->dpp_csign,
  1231. ssid->dpp_csign_len,
  1232. connector, connector_len, &expiry);
  1233. if (res != DPP_STATUS_OK) {
  1234. wpa_printf(MSG_INFO,
  1235. "DPP: Network Introduction protocol resulted in failure");
  1236. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
  1237. " fail=peer_connector_validation_failed", MAC2STR(src));
  1238. goto fail;
  1239. }
  1240. entry = os_zalloc(sizeof(*entry));
  1241. if (!entry)
  1242. goto fail;
  1243. os_memcpy(entry->aa, src, ETH_ALEN);
  1244. os_memcpy(entry->pmkid, intro.pmkid, PMKID_LEN);
  1245. os_memcpy(entry->pmk, intro.pmk, intro.pmk_len);
  1246. entry->pmk_len = intro.pmk_len;
  1247. entry->akmp = WPA_KEY_MGMT_DPP;
  1248. if (expiry) {
  1249. os_get_time(&now);
  1250. seconds = expiry - now.sec;
  1251. } else {
  1252. seconds = 86400 * 7;
  1253. }
  1254. os_get_reltime(&rnow);
  1255. entry->expiration = rnow.sec + seconds;
  1256. entry->reauth_time = rnow.sec + seconds;
  1257. entry->network_ctx = ssid;
  1258. wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
  1259. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_INTRO "peer=" MACSTR
  1260. " status=%u", MAC2STR(src), status[0]);
  1261. wpa_printf(MSG_DEBUG,
  1262. "DPP: Try connection again after successful network introduction");
  1263. if (wpa_supplicant_fast_associate(wpa_s) != 1) {
  1264. wpa_supplicant_cancel_sched_scan(wpa_s);
  1265. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1266. }
  1267. fail:
  1268. os_memset(&intro, 0, sizeof(intro));
  1269. }
  1270. static void
  1271. wpas_dpp_tx_pkex_status(struct wpa_supplicant *wpa_s,
  1272. unsigned int freq, const u8 *dst,
  1273. const u8 *src, const u8 *bssid,
  1274. const u8 *data, size_t data_len,
  1275. enum offchannel_send_action_result result)
  1276. {
  1277. const char *res_txt;
  1278. res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
  1279. (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
  1280. "FAILED");
  1281. wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
  1282. " result=%s (PKEX)",
  1283. freq, MAC2STR(dst), res_txt);
  1284. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
  1285. " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
  1286. /* TODO: Time out wait for response more quickly in error cases? */
  1287. if (!wpa_s->dpp_pkex) {
  1288. wpa_printf(MSG_DEBUG,
  1289. "DPP: Ignore TX status since there is no ongoing PKEX exchange");
  1290. return;
  1291. }
  1292. if (wpa_s->dpp_pkex->failed) {
  1293. wpa_printf(MSG_DEBUG,
  1294. "DPP: Terminate PKEX exchange due to an earlier error");
  1295. if (wpa_s->dpp_pkex->t > wpa_s->dpp_pkex->own_bi->pkex_t)
  1296. wpa_s->dpp_pkex->own_bi->pkex_t = wpa_s->dpp_pkex->t;
  1297. dpp_pkex_free(wpa_s->dpp_pkex);
  1298. wpa_s->dpp_pkex = NULL;
  1299. }
  1300. }
  1301. static void
  1302. wpas_dpp_rx_pkex_exchange_req(struct wpa_supplicant *wpa_s, const u8 *src,
  1303. const u8 *buf, size_t len, unsigned int freq)
  1304. {
  1305. struct wpabuf *msg;
  1306. unsigned int wait_time;
  1307. wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Request from " MACSTR,
  1308. MAC2STR(src));
  1309. /* TODO: Support multiple PKEX codes by iterating over all the enabled
  1310. * values here */
  1311. if (!wpa_s->dpp_pkex_code || !wpa_s->dpp_pkex_bi) {
  1312. wpa_printf(MSG_DEBUG,
  1313. "DPP: No PKEX code configured - ignore request");
  1314. return;
  1315. }
  1316. if (wpa_s->dpp_pkex) {
  1317. /* TODO: Support parallel operations */
  1318. wpa_printf(MSG_DEBUG,
  1319. "DPP: Already in PKEX session - ignore new request");
  1320. return;
  1321. }
  1322. wpa_s->dpp_pkex = dpp_pkex_rx_exchange_req(wpa_s, wpa_s->dpp_pkex_bi,
  1323. wpa_s->own_addr, src,
  1324. wpa_s->dpp_pkex_identifier,
  1325. wpa_s->dpp_pkex_code,
  1326. buf, len);
  1327. if (!wpa_s->dpp_pkex) {
  1328. wpa_printf(MSG_DEBUG,
  1329. "DPP: Failed to process the request - ignore it");
  1330. return;
  1331. }
  1332. msg = wpa_s->dpp_pkex->exchange_resp;
  1333. wait_time = wpa_s->max_remain_on_chan;
  1334. if (wait_time > 2000)
  1335. wait_time = 2000;
  1336. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
  1337. MAC2STR(src), freq, DPP_PA_PKEX_EXCHANGE_RESP);
  1338. offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
  1339. broadcast,
  1340. wpabuf_head(msg), wpabuf_len(msg),
  1341. wait_time, wpas_dpp_tx_pkex_status, 0);
  1342. }
  1343. static void
  1344. wpas_dpp_rx_pkex_exchange_resp(struct wpa_supplicant *wpa_s, const u8 *src,
  1345. const u8 *buf, size_t len, unsigned int freq)
  1346. {
  1347. struct wpabuf *msg;
  1348. unsigned int wait_time;
  1349. wpa_printf(MSG_DEBUG, "DPP: PKEX Exchange Response from " MACSTR,
  1350. MAC2STR(src));
  1351. /* TODO: Support multiple PKEX codes by iterating over all the enabled
  1352. * values here */
  1353. if (!wpa_s->dpp_pkex || !wpa_s->dpp_pkex->initiator ||
  1354. wpa_s->dpp_pkex->exchange_done) {
  1355. wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
  1356. return;
  1357. }
  1358. os_memcpy(wpa_s->dpp_pkex->peer_mac, src, ETH_ALEN);
  1359. msg = dpp_pkex_rx_exchange_resp(wpa_s->dpp_pkex, buf, len);
  1360. if (!msg) {
  1361. wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
  1362. return;
  1363. }
  1364. wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Request to " MACSTR,
  1365. MAC2STR(src));
  1366. wait_time = wpa_s->max_remain_on_chan;
  1367. if (wait_time > 2000)
  1368. wait_time = 2000;
  1369. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
  1370. MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_REQ);
  1371. offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
  1372. broadcast,
  1373. wpabuf_head(msg), wpabuf_len(msg),
  1374. wait_time, wpas_dpp_tx_pkex_status, 0);
  1375. wpabuf_free(msg);
  1376. }
  1377. static struct dpp_bootstrap_info *
  1378. wpas_dpp_pkex_finish(struct wpa_supplicant *wpa_s, const u8 *peer,
  1379. unsigned int freq)
  1380. {
  1381. struct dpp_pkex *pkex = wpa_s->dpp_pkex;
  1382. struct dpp_bootstrap_info *bi;
  1383. bi = os_zalloc(sizeof(*bi));
  1384. if (!bi)
  1385. return NULL;
  1386. bi->id = wpas_dpp_next_id(wpa_s);
  1387. bi->type = DPP_BOOTSTRAP_PKEX;
  1388. os_memcpy(bi->mac_addr, peer, ETH_ALEN);
  1389. bi->num_freq = 1;
  1390. bi->freq[0] = freq;
  1391. bi->curve = pkex->own_bi->curve;
  1392. bi->pubkey = pkex->peer_bootstrap_key;
  1393. pkex->peer_bootstrap_key = NULL;
  1394. dpp_pkex_free(pkex);
  1395. wpa_s->dpp_pkex = NULL;
  1396. if (dpp_bootstrap_key_hash(bi) < 0) {
  1397. dpp_bootstrap_info_free(bi);
  1398. return NULL;
  1399. }
  1400. dl_list_add(&wpa_s->dpp_bootstrap, &bi->list);
  1401. return bi;
  1402. }
  1403. static void
  1404. wpas_dpp_rx_pkex_commit_reveal_req(struct wpa_supplicant *wpa_s, const u8 *src,
  1405. const u8 *hdr, const u8 *buf, size_t len,
  1406. unsigned int freq)
  1407. {
  1408. struct wpabuf *msg;
  1409. unsigned int wait_time;
  1410. struct dpp_pkex *pkex = wpa_s->dpp_pkex;
  1411. wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Request from " MACSTR,
  1412. MAC2STR(src));
  1413. if (!pkex || pkex->initiator || !pkex->exchange_done) {
  1414. wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
  1415. return;
  1416. }
  1417. msg = dpp_pkex_rx_commit_reveal_req(pkex, hdr, buf, len);
  1418. if (!msg) {
  1419. wpa_printf(MSG_DEBUG, "DPP: Failed to process the request");
  1420. if (pkex->failed) {
  1421. wpa_printf(MSG_DEBUG, "DPP: Terminate PKEX exchange");
  1422. if (pkex->t > pkex->own_bi->pkex_t)
  1423. pkex->own_bi->pkex_t = pkex->t;
  1424. dpp_pkex_free(wpa_s->dpp_pkex);
  1425. wpa_s->dpp_pkex = NULL;
  1426. }
  1427. return;
  1428. }
  1429. wpa_printf(MSG_DEBUG, "DPP: Send PKEX Commit-Reveal Response to "
  1430. MACSTR, MAC2STR(src));
  1431. wait_time = wpa_s->max_remain_on_chan;
  1432. if (wait_time > 2000)
  1433. wait_time = 2000;
  1434. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
  1435. MAC2STR(src), freq, DPP_PA_PKEX_COMMIT_REVEAL_RESP);
  1436. offchannel_send_action(wpa_s, freq, src, wpa_s->own_addr,
  1437. broadcast,
  1438. wpabuf_head(msg), wpabuf_len(msg),
  1439. wait_time, wpas_dpp_tx_pkex_status, 0);
  1440. wpabuf_free(msg);
  1441. wpas_dpp_pkex_finish(wpa_s, src, freq);
  1442. }
  1443. static void
  1444. wpas_dpp_rx_pkex_commit_reveal_resp(struct wpa_supplicant *wpa_s, const u8 *src,
  1445. const u8 *hdr, const u8 *buf, size_t len,
  1446. unsigned int freq)
  1447. {
  1448. int res;
  1449. struct dpp_bootstrap_info *bi;
  1450. struct dpp_pkex *pkex = wpa_s->dpp_pkex;
  1451. char cmd[500];
  1452. wpa_printf(MSG_DEBUG, "DPP: PKEX Commit-Reveal Response from " MACSTR,
  1453. MAC2STR(src));
  1454. if (!pkex || !pkex->initiator || !pkex->exchange_done) {
  1455. wpa_printf(MSG_DEBUG, "DPP: No matching PKEX session");
  1456. return;
  1457. }
  1458. res = dpp_pkex_rx_commit_reveal_resp(pkex, hdr, buf, len);
  1459. if (res < 0) {
  1460. wpa_printf(MSG_DEBUG, "DPP: Failed to process the response");
  1461. return;
  1462. }
  1463. bi = wpas_dpp_pkex_finish(wpa_s, src, freq);
  1464. if (!bi)
  1465. return;
  1466. os_snprintf(cmd, sizeof(cmd), " peer=%u %s",
  1467. bi->id,
  1468. wpa_s->dpp_pkex_auth_cmd ? wpa_s->dpp_pkex_auth_cmd : "");
  1469. wpa_printf(MSG_DEBUG,
  1470. "DPP: Start authentication after PKEX with parameters: %s",
  1471. cmd);
  1472. if (wpas_dpp_auth_init(wpa_s, cmd) < 0) {
  1473. wpa_printf(MSG_DEBUG,
  1474. "DPP: Authentication initialization failed");
  1475. return;
  1476. }
  1477. }
  1478. void wpas_dpp_rx_action(struct wpa_supplicant *wpa_s, const u8 *src,
  1479. const u8 *buf, size_t len, unsigned int freq)
  1480. {
  1481. u8 crypto_suite;
  1482. enum dpp_public_action_frame_type type;
  1483. const u8 *hdr;
  1484. unsigned int pkex_t;
  1485. if (len < DPP_HDR_LEN)
  1486. return;
  1487. if (WPA_GET_BE24(buf) != OUI_WFA || buf[3] != DPP_OUI_TYPE)
  1488. return;
  1489. hdr = buf;
  1490. buf += 4;
  1491. len -= 4;
  1492. crypto_suite = *buf++;
  1493. type = *buf++;
  1494. len -= 2;
  1495. wpa_printf(MSG_DEBUG,
  1496. "DPP: Received DPP Public Action frame crypto suite %u type %d from "
  1497. MACSTR " freq=%u",
  1498. crypto_suite, type, MAC2STR(src), freq);
  1499. if (crypto_suite != 1) {
  1500. wpa_printf(MSG_DEBUG, "DPP: Unsupported crypto suite %u",
  1501. crypto_suite);
  1502. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
  1503. " freq=%u type=%d ignore=unsupported-crypto-suite",
  1504. MAC2STR(src), freq, type);
  1505. return;
  1506. }
  1507. wpa_hexdump(MSG_MSGDUMP, "DPP: Received message attributes", buf, len);
  1508. if (dpp_check_attrs(buf, len) < 0) {
  1509. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
  1510. " freq=%u type=%d ignore=invalid-attributes",
  1511. MAC2STR(src), freq, type);
  1512. return;
  1513. }
  1514. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR " freq=%u type=%d",
  1515. MAC2STR(src), freq, type);
  1516. switch (type) {
  1517. case DPP_PA_AUTHENTICATION_REQ:
  1518. wpas_dpp_rx_auth_req(wpa_s, src, hdr, buf, len, freq);
  1519. break;
  1520. case DPP_PA_AUTHENTICATION_RESP:
  1521. wpas_dpp_rx_auth_resp(wpa_s, src, hdr, buf, len, freq);
  1522. break;
  1523. case DPP_PA_AUTHENTICATION_CONF:
  1524. wpas_dpp_rx_auth_conf(wpa_s, src, hdr, buf, len);
  1525. break;
  1526. case DPP_PA_PEER_DISCOVERY_RESP:
  1527. wpas_dpp_rx_peer_disc_resp(wpa_s, src, buf, len);
  1528. break;
  1529. case DPP_PA_PKEX_EXCHANGE_REQ:
  1530. wpas_dpp_rx_pkex_exchange_req(wpa_s, src, buf, len, freq);
  1531. break;
  1532. case DPP_PA_PKEX_EXCHANGE_RESP:
  1533. wpas_dpp_rx_pkex_exchange_resp(wpa_s, src, buf, len, freq);
  1534. break;
  1535. case DPP_PA_PKEX_COMMIT_REVEAL_REQ:
  1536. wpas_dpp_rx_pkex_commit_reveal_req(wpa_s, src, hdr, buf, len,
  1537. freq);
  1538. break;
  1539. case DPP_PA_PKEX_COMMIT_REVEAL_RESP:
  1540. wpas_dpp_rx_pkex_commit_reveal_resp(wpa_s, src, hdr, buf, len,
  1541. freq);
  1542. break;
  1543. default:
  1544. wpa_printf(MSG_DEBUG,
  1545. "DPP: Ignored unsupported frame subtype %d", type);
  1546. break;
  1547. }
  1548. if (wpa_s->dpp_pkex)
  1549. pkex_t = wpa_s->dpp_pkex->t;
  1550. else if (wpa_s->dpp_pkex_bi)
  1551. pkex_t = wpa_s->dpp_pkex_bi->pkex_t;
  1552. else
  1553. pkex_t = 0;
  1554. if (pkex_t >= PKEX_COUNTER_T_LIMIT) {
  1555. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_PKEX_T_LIMIT "id=0");
  1556. wpas_dpp_pkex_remove(wpa_s, "*");
  1557. }
  1558. }
  1559. static struct wpabuf *
  1560. wpas_dpp_gas_req_handler(void *ctx, const u8 *sa, const u8 *query,
  1561. size_t query_len)
  1562. {
  1563. struct wpa_supplicant *wpa_s = ctx;
  1564. struct dpp_authentication *auth = wpa_s->dpp_auth;
  1565. struct wpabuf *resp;
  1566. wpa_printf(MSG_DEBUG, "DPP: GAS request from " MACSTR,
  1567. MAC2STR(sa));
  1568. if (!auth || !auth->auth_success ||
  1569. os_memcmp(sa, auth->peer_mac_addr, ETH_ALEN) != 0) {
  1570. wpa_printf(MSG_DEBUG, "DPP: No matching exchange in progress");
  1571. return NULL;
  1572. }
  1573. wpa_hexdump(MSG_DEBUG,
  1574. "DPP: Received Configuration Request (GAS Query Request)",
  1575. query, query_len);
  1576. resp = dpp_conf_req_rx(auth, query, query_len);
  1577. if (!resp)
  1578. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
  1579. return resp;
  1580. }
  1581. static void
  1582. wpas_dpp_gas_status_handler(void *ctx, struct wpabuf *resp, int ok)
  1583. {
  1584. struct wpa_supplicant *wpa_s = ctx;
  1585. struct dpp_authentication *auth = wpa_s->dpp_auth;
  1586. if (!auth) {
  1587. wpabuf_free(resp);
  1588. return;
  1589. }
  1590. wpa_printf(MSG_DEBUG, "DPP: Configuration exchange completed (ok=%d)",
  1591. ok);
  1592. eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
  1593. offchannel_send_action_done(wpa_s);
  1594. wpas_dpp_listen_stop(wpa_s);
  1595. if (ok)
  1596. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_SENT);
  1597. else
  1598. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_CONF_FAILED);
  1599. dpp_auth_deinit(wpa_s->dpp_auth);
  1600. wpa_s->dpp_auth = NULL;
  1601. wpabuf_free(resp);
  1602. }
  1603. static unsigned int wpas_dpp_next_configurator_id(struct wpa_supplicant *wpa_s)
  1604. {
  1605. struct dpp_configurator *conf;
  1606. unsigned int max_id = 0;
  1607. dl_list_for_each(conf, &wpa_s->dpp_configurator,
  1608. struct dpp_configurator, list) {
  1609. if (conf->id > max_id)
  1610. max_id = conf->id;
  1611. }
  1612. return max_id + 1;
  1613. }
  1614. int wpas_dpp_configurator_add(struct wpa_supplicant *wpa_s, const char *cmd)
  1615. {
  1616. char *curve = NULL;
  1617. char *key = NULL;
  1618. u8 *privkey = NULL;
  1619. size_t privkey_len = 0;
  1620. int ret = -1;
  1621. struct dpp_configurator *conf = NULL;
  1622. curve = get_param(cmd, " curve=");
  1623. key = get_param(cmd, " key=");
  1624. if (key) {
  1625. privkey_len = os_strlen(key) / 2;
  1626. privkey = os_malloc(privkey_len);
  1627. if (!privkey ||
  1628. hexstr2bin(key, privkey, privkey_len) < 0)
  1629. goto fail;
  1630. }
  1631. conf = dpp_keygen_configurator(curve, privkey, privkey_len);
  1632. if (!conf)
  1633. goto fail;
  1634. conf->id = wpas_dpp_next_configurator_id(wpa_s);
  1635. dl_list_add(&wpa_s->dpp_configurator, &conf->list);
  1636. ret = conf->id;
  1637. conf = NULL;
  1638. fail:
  1639. os_free(curve);
  1640. str_clear_free(key);
  1641. bin_clear_free(privkey, privkey_len);
  1642. dpp_configurator_free(conf);
  1643. return ret;
  1644. }
  1645. static int dpp_configurator_del(struct wpa_supplicant *wpa_s, unsigned int id)
  1646. {
  1647. struct dpp_configurator *conf, *tmp;
  1648. int found = 0;
  1649. dl_list_for_each_safe(conf, tmp, &wpa_s->dpp_configurator,
  1650. struct dpp_configurator, list) {
  1651. if (id && conf->id != id)
  1652. continue;
  1653. found = 1;
  1654. dl_list_del(&conf->list);
  1655. dpp_configurator_free(conf);
  1656. }
  1657. if (id == 0)
  1658. return 0; /* flush succeeds regardless of entries found */
  1659. return found ? 0 : -1;
  1660. }
  1661. int wpas_dpp_configurator_remove(struct wpa_supplicant *wpa_s, const char *id)
  1662. {
  1663. unsigned int id_val;
  1664. if (os_strcmp(id, "*") == 0) {
  1665. id_val = 0;
  1666. } else {
  1667. id_val = atoi(id);
  1668. if (id_val == 0)
  1669. return -1;
  1670. }
  1671. return dpp_configurator_del(wpa_s, id_val);
  1672. }
  1673. int wpas_dpp_configurator_sign(struct wpa_supplicant *wpa_s, const char *cmd)
  1674. {
  1675. struct dpp_authentication *auth;
  1676. int ret = -1;
  1677. char *curve = NULL;
  1678. auth = os_zalloc(sizeof(*auth));
  1679. if (!auth)
  1680. return -1;
  1681. curve = get_param(cmd, " curve=");
  1682. wpas_dpp_set_configurator(wpa_s, auth, cmd);
  1683. if (dpp_configurator_own_config(auth, curve) == 0) {
  1684. wpas_dpp_handle_config_obj(wpa_s, auth);
  1685. ret = 0;
  1686. }
  1687. dpp_auth_deinit(auth);
  1688. os_free(curve);
  1689. return ret;
  1690. }
  1691. static void
  1692. wpas_dpp_tx_introduction_status(struct wpa_supplicant *wpa_s,
  1693. unsigned int freq, const u8 *dst,
  1694. const u8 *src, const u8 *bssid,
  1695. const u8 *data, size_t data_len,
  1696. enum offchannel_send_action_result result)
  1697. {
  1698. const char *res_txt;
  1699. res_txt = result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
  1700. (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
  1701. "FAILED");
  1702. wpa_printf(MSG_DEBUG, "DPP: TX status: freq=%u dst=" MACSTR
  1703. " result=%s (DPP Peer Discovery Request)",
  1704. freq, MAC2STR(dst), res_txt);
  1705. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX_STATUS "dst=" MACSTR
  1706. " freq=%u result=%s", MAC2STR(dst), freq, res_txt);
  1707. /* TODO: Time out wait for response more quickly in error cases? */
  1708. }
  1709. int wpas_dpp_check_connect(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
  1710. struct wpa_bss *bss)
  1711. {
  1712. struct os_time now;
  1713. struct wpabuf *msg;
  1714. unsigned int wait_time;
  1715. if (!(ssid->key_mgmt & WPA_KEY_MGMT_DPP) || !bss)
  1716. return 0; /* Not using DPP AKM - continue */
  1717. if (wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid))
  1718. return 0; /* PMKSA exists for DPP AKM - continue */
  1719. if (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
  1720. !ssid->dpp_csign) {
  1721. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
  1722. "missing %s",
  1723. !ssid->dpp_connector ? "Connector" :
  1724. (!ssid->dpp_netaccesskey ? "netAccessKey" :
  1725. "C-sign-key"));
  1726. return -1;
  1727. }
  1728. os_get_time(&now);
  1729. if (ssid->dpp_netaccesskey_expiry &&
  1730. ssid->dpp_netaccesskey_expiry < now.sec) {
  1731. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_MISSING_CONNECTOR
  1732. "netAccessKey expired");
  1733. return -1;
  1734. }
  1735. wpa_printf(MSG_DEBUG,
  1736. "DPP: Starting network introduction protocol to derive PMKSA for "
  1737. MACSTR, MAC2STR(bss->bssid));
  1738. msg = dpp_alloc_msg(DPP_PA_PEER_DISCOVERY_REQ,
  1739. 5 + 4 + os_strlen(ssid->dpp_connector));
  1740. if (!msg)
  1741. return -1;
  1742. #ifdef CONFIG_TESTING_OPTIONS
  1743. if (dpp_test == DPP_TEST_NO_TRANSACTION_ID_PEER_DISC_REQ) {
  1744. wpa_printf(MSG_INFO, "DPP: TESTING - no Transaction ID");
  1745. goto skip_trans_id;
  1746. }
  1747. #endif /* CONFIG_TESTING_OPTIONS */
  1748. /* Transaction ID */
  1749. wpabuf_put_le16(msg, DPP_ATTR_TRANSACTION_ID);
  1750. wpabuf_put_le16(msg, 1);
  1751. wpabuf_put_u8(msg, TRANSACTION_ID);
  1752. #ifdef CONFIG_TESTING_OPTIONS
  1753. skip_trans_id:
  1754. if (dpp_test == DPP_TEST_NO_CONNECTOR_PEER_DISC_REQ) {
  1755. wpa_printf(MSG_INFO, "DPP: TESTING - no Connector");
  1756. goto skip_connector;
  1757. }
  1758. #endif /* CONFIG_TESTING_OPTIONS */
  1759. /* DPP Connector */
  1760. wpabuf_put_le16(msg, DPP_ATTR_CONNECTOR);
  1761. wpabuf_put_le16(msg, os_strlen(ssid->dpp_connector));
  1762. wpabuf_put_str(msg, ssid->dpp_connector);
  1763. #ifdef CONFIG_TESTING_OPTIONS
  1764. skip_connector:
  1765. #endif /* CONFIG_TESTING_OPTIONS */
  1766. /* TODO: Timeout on AP response */
  1767. wait_time = wpa_s->max_remain_on_chan;
  1768. if (wait_time > 2000)
  1769. wait_time = 2000;
  1770. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR " freq=%u type=%d",
  1771. MAC2STR(bss->bssid), bss->freq, DPP_PA_PEER_DISCOVERY_REQ);
  1772. offchannel_send_action(wpa_s, bss->freq, bss->bssid, wpa_s->own_addr,
  1773. broadcast,
  1774. wpabuf_head(msg), wpabuf_len(msg),
  1775. wait_time, wpas_dpp_tx_introduction_status, 0);
  1776. wpabuf_free(msg);
  1777. /* Request this connection attempt to terminate - new one will be
  1778. * started when network introduction protocol completes */
  1779. os_memcpy(wpa_s->dpp_intro_bssid, bss->bssid, ETH_ALEN);
  1780. wpa_s->dpp_intro_network = ssid;
  1781. return 1;
  1782. }
  1783. int wpas_dpp_pkex_add(struct wpa_supplicant *wpa_s, const char *cmd)
  1784. {
  1785. struct dpp_bootstrap_info *own_bi;
  1786. const char *pos, *end;
  1787. unsigned int wait_time;
  1788. pos = os_strstr(cmd, " own=");
  1789. if (!pos)
  1790. return -1;
  1791. pos += 5;
  1792. own_bi = dpp_bootstrap_get_id(wpa_s, atoi(pos));
  1793. if (!own_bi) {
  1794. wpa_printf(MSG_DEBUG,
  1795. "DPP: Identified bootstrap info not found");
  1796. return -1;
  1797. }
  1798. if (own_bi->type != DPP_BOOTSTRAP_PKEX) {
  1799. wpa_printf(MSG_DEBUG,
  1800. "DPP: Identified bootstrap info not for PKEX");
  1801. return -1;
  1802. }
  1803. wpa_s->dpp_pkex_bi = own_bi;
  1804. own_bi->pkex_t = 0; /* clear pending errors on new code */
  1805. os_free(wpa_s->dpp_pkex_identifier);
  1806. wpa_s->dpp_pkex_identifier = NULL;
  1807. pos = os_strstr(cmd, " identifier=");
  1808. if (pos) {
  1809. pos += 12;
  1810. end = os_strchr(pos, ' ');
  1811. if (!end)
  1812. return -1;
  1813. wpa_s->dpp_pkex_identifier = os_malloc(end - pos + 1);
  1814. if (!wpa_s->dpp_pkex_identifier)
  1815. return -1;
  1816. os_memcpy(wpa_s->dpp_pkex_identifier, pos, end - pos);
  1817. wpa_s->dpp_pkex_identifier[end - pos] = '\0';
  1818. }
  1819. pos = os_strstr(cmd, " code=");
  1820. if (!pos)
  1821. return -1;
  1822. os_free(wpa_s->dpp_pkex_code);
  1823. wpa_s->dpp_pkex_code = os_strdup(pos + 6);
  1824. if (!wpa_s->dpp_pkex_code)
  1825. return -1;
  1826. if (os_strstr(cmd, " init=1")) {
  1827. struct wpabuf *msg;
  1828. wpa_printf(MSG_DEBUG, "DPP: Initiating PKEX");
  1829. dpp_pkex_free(wpa_s->dpp_pkex);
  1830. wpa_s->dpp_pkex = dpp_pkex_init(wpa_s, own_bi, wpa_s->own_addr,
  1831. wpa_s->dpp_pkex_identifier,
  1832. wpa_s->dpp_pkex_code);
  1833. if (!wpa_s->dpp_pkex)
  1834. return -1;
  1835. msg = wpa_s->dpp_pkex->exchange_req;
  1836. wait_time = wpa_s->max_remain_on_chan;
  1837. if (wait_time > 2000)
  1838. wait_time = 2000;
  1839. /* TODO: Which channel to use? */
  1840. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_TX "dst=" MACSTR
  1841. " freq=%u type=%d",
  1842. MAC2STR(broadcast), 2437, DPP_PA_PKEX_EXCHANGE_REQ);
  1843. offchannel_send_action(wpa_s, 2437, broadcast, wpa_s->own_addr,
  1844. broadcast,
  1845. wpabuf_head(msg), wpabuf_len(msg),
  1846. wait_time, wpas_dpp_tx_pkex_status, 0);
  1847. }
  1848. /* TODO: Support multiple PKEX info entries */
  1849. os_free(wpa_s->dpp_pkex_auth_cmd);
  1850. wpa_s->dpp_pkex_auth_cmd = os_strdup(cmd);
  1851. return 1;
  1852. }
  1853. int wpas_dpp_pkex_remove(struct wpa_supplicant *wpa_s, const char *id)
  1854. {
  1855. unsigned int id_val;
  1856. if (os_strcmp(id, "*") == 0) {
  1857. id_val = 0;
  1858. } else {
  1859. id_val = atoi(id);
  1860. if (id_val == 0)
  1861. return -1;
  1862. }
  1863. if ((id_val != 0 && id_val != 1) || !wpa_s->dpp_pkex_code)
  1864. return -1;
  1865. /* TODO: Support multiple PKEX entries */
  1866. os_free(wpa_s->dpp_pkex_code);
  1867. wpa_s->dpp_pkex_code = NULL;
  1868. os_free(wpa_s->dpp_pkex_identifier);
  1869. wpa_s->dpp_pkex_identifier = NULL;
  1870. os_free(wpa_s->dpp_pkex_auth_cmd);
  1871. wpa_s->dpp_pkex_auth_cmd = NULL;
  1872. wpa_s->dpp_pkex_bi = NULL;
  1873. /* TODO: Remove dpp_pkex only if it is for the identified PKEX code */
  1874. dpp_pkex_free(wpa_s->dpp_pkex);
  1875. wpa_s->dpp_pkex = NULL;
  1876. return 0;
  1877. }
  1878. int wpas_dpp_init(struct wpa_supplicant *wpa_s)
  1879. {
  1880. u8 adv_proto_id[7];
  1881. adv_proto_id[0] = WLAN_EID_VENDOR_SPECIFIC;
  1882. adv_proto_id[1] = 5;
  1883. WPA_PUT_BE24(&adv_proto_id[2], OUI_WFA);
  1884. adv_proto_id[5] = DPP_OUI_TYPE;
  1885. adv_proto_id[6] = 0x01;
  1886. if (gas_server_register(wpa_s->gas_server, adv_proto_id,
  1887. sizeof(adv_proto_id), wpas_dpp_gas_req_handler,
  1888. wpas_dpp_gas_status_handler, wpa_s) < 0)
  1889. return -1;
  1890. dl_list_init(&wpa_s->dpp_bootstrap);
  1891. dl_list_init(&wpa_s->dpp_configurator);
  1892. wpa_s->dpp_init_done = 1;
  1893. return 0;
  1894. }
  1895. void wpas_dpp_deinit(struct wpa_supplicant *wpa_s)
  1896. {
  1897. #ifdef CONFIG_TESTING_OPTIONS
  1898. os_free(wpa_s->dpp_config_obj_override);
  1899. wpa_s->dpp_config_obj_override = NULL;
  1900. os_free(wpa_s->dpp_discovery_override);
  1901. wpa_s->dpp_discovery_override = NULL;
  1902. os_free(wpa_s->dpp_groups_override);
  1903. wpa_s->dpp_groups_override = NULL;
  1904. wpa_s->dpp_ignore_netaccesskey_mismatch = 0;
  1905. #endif /* CONFIG_TESTING_OPTIONS */
  1906. if (!wpa_s->dpp_init_done)
  1907. return;
  1908. eloop_cancel_timeout(wpas_dpp_reply_wait_timeout, wpa_s, NULL);
  1909. eloop_cancel_timeout(wpas_dpp_init_timeout, wpa_s, NULL);
  1910. offchannel_send_action_done(wpa_s);
  1911. wpas_dpp_listen_stop(wpa_s);
  1912. dpp_bootstrap_del(wpa_s, 0);
  1913. dpp_configurator_del(wpa_s, 0);
  1914. dpp_auth_deinit(wpa_s->dpp_auth);
  1915. wpa_s->dpp_auth = NULL;
  1916. wpas_dpp_pkex_remove(wpa_s, "*");
  1917. wpa_s->dpp_pkex = NULL;
  1918. os_memset(wpa_s->dpp_intro_bssid, 0, ETH_ALEN);
  1919. os_free(wpa_s->dpp_configurator_params);
  1920. wpa_s->dpp_configurator_params = NULL;
  1921. }