config.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951
  1. /*
  2. * WPA Supplicant / Configuration parser and common functions
  3. * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #include "includes.h"
  15. #include "common.h"
  16. #include "wpa.h"
  17. #include "sha1.h"
  18. #include "eap_peer/eap.h"
  19. #include "config.h"
  20. #if !defined(CONFIG_CTRL_IFACE) && defined(CONFIG_NO_CONFIG_WRITE)
  21. #define NO_CONFIG_WRITE
  22. #endif
  23. /*
  24. * Structure for network configuration parsing. This data is used to implement
  25. * a generic parser for each network block variable. The table of configuration
  26. * variables is defined below in this file (ssid_fields[]).
  27. */
  28. struct parse_data {
  29. /* Configuration variable name */
  30. char *name;
  31. /* Parser function for this variable */
  32. int (*parser)(const struct parse_data *data, struct wpa_ssid *ssid,
  33. int line, const char *value);
  34. #ifndef NO_CONFIG_WRITE
  35. /* Writer function (i.e., to get the variable in text format from
  36. * internal presentation). */
  37. char * (*writer)(const struct parse_data *data, struct wpa_ssid *ssid);
  38. #endif /* NO_CONFIG_WRITE */
  39. /* Variable specific parameters for the parser. */
  40. void *param1, *param2, *param3, *param4;
  41. /* 0 = this variable can be included in debug output and ctrl_iface
  42. * 1 = this variable contains key/private data and it must not be
  43. * included in debug output unless explicitly requested. In
  44. * addition, this variable will not be readable through the
  45. * ctrl_iface.
  46. */
  47. int key_data;
  48. };
  49. static char * wpa_config_parse_string(const char *value, size_t *len)
  50. {
  51. if (*value == '"') {
  52. char *pos;
  53. value++;
  54. pos = os_strrchr(value, '"');
  55. if (pos == NULL || pos[1] != '\0')
  56. return NULL;
  57. *pos = '\0';
  58. *len = os_strlen(value);
  59. return os_strdup(value);
  60. } else {
  61. u8 *str;
  62. size_t tlen, hlen = os_strlen(value);
  63. if (hlen & 1)
  64. return NULL;
  65. tlen = hlen / 2;
  66. str = os_malloc(tlen + 1);
  67. if (str == NULL)
  68. return NULL;
  69. if (hexstr2bin(value, str, tlen)) {
  70. os_free(str);
  71. return NULL;
  72. }
  73. str[tlen] = '\0';
  74. *len = tlen;
  75. return (char *) str;
  76. }
  77. }
  78. static int wpa_config_parse_str(const struct parse_data *data,
  79. struct wpa_ssid *ssid,
  80. int line, const char *value)
  81. {
  82. size_t res_len, *dst_len;
  83. char **dst, *tmp;
  84. if (os_strcmp(value, "NULL") == 0) {
  85. wpa_printf(MSG_DEBUG, "Unset configuration string '%s'",
  86. data->name);
  87. tmp = NULL;
  88. res_len = 0;
  89. goto set;
  90. }
  91. tmp = wpa_config_parse_string(value, &res_len);
  92. if (tmp == NULL) {
  93. wpa_printf(MSG_ERROR, "Line %d: failed to parse %s '%s'.",
  94. line, data->name,
  95. data->key_data ? "[KEY DATA REMOVED]" : value);
  96. return -1;
  97. }
  98. if (data->key_data) {
  99. wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
  100. (u8 *) tmp, res_len);
  101. } else {
  102. wpa_hexdump_ascii(MSG_MSGDUMP, data->name,
  103. (u8 *) tmp, res_len);
  104. }
  105. if (data->param3 && res_len < (size_t) data->param3) {
  106. wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
  107. "min_len=%ld)", line, data->name,
  108. (unsigned long) res_len, (long) data->param3);
  109. os_free(tmp);
  110. return -1;
  111. }
  112. if (data->param4 && res_len > (size_t) data->param4) {
  113. wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
  114. "max_len=%ld)", line, data->name,
  115. (unsigned long) res_len, (long) data->param4);
  116. os_free(tmp);
  117. return -1;
  118. }
  119. set:
  120. dst = (char **) (((u8 *) ssid) + (long) data->param1);
  121. dst_len = (size_t *) (((u8 *) ssid) + (long) data->param2);
  122. os_free(*dst);
  123. *dst = tmp;
  124. if (data->param2)
  125. *dst_len = res_len;
  126. return 0;
  127. }
  128. #ifndef NO_CONFIG_WRITE
  129. static int is_hex(const u8 *data, size_t len)
  130. {
  131. size_t i;
  132. for (i = 0; i < len; i++) {
  133. if (data[i] < 32 || data[i] >= 127)
  134. return 1;
  135. }
  136. return 0;
  137. }
  138. static char * wpa_config_write_string_ascii(const u8 *value, size_t len)
  139. {
  140. char *buf;
  141. buf = os_malloc(len + 3);
  142. if (buf == NULL)
  143. return NULL;
  144. buf[0] = '"';
  145. os_memcpy(buf + 1, value, len);
  146. buf[len + 1] = '"';
  147. buf[len + 2] = '\0';
  148. return buf;
  149. }
  150. static char * wpa_config_write_string_hex(const u8 *value, size_t len)
  151. {
  152. char *buf;
  153. buf = os_zalloc(2 * len + 1);
  154. if (buf == NULL)
  155. return NULL;
  156. wpa_snprintf_hex(buf, 2 * len + 1, value, len);
  157. return buf;
  158. }
  159. static char * wpa_config_write_string(const u8 *value, size_t len)
  160. {
  161. if (value == NULL)
  162. return NULL;
  163. if (is_hex(value, len))
  164. return wpa_config_write_string_hex(value, len);
  165. else
  166. return wpa_config_write_string_ascii(value, len);
  167. }
  168. static char * wpa_config_write_str(const struct parse_data *data,
  169. struct wpa_ssid *ssid)
  170. {
  171. size_t len;
  172. char **src;
  173. src = (char **) (((u8 *) ssid) + (long) data->param1);
  174. if (*src == NULL)
  175. return NULL;
  176. if (data->param2)
  177. len = *((size_t *) (((u8 *) ssid) + (long) data->param2));
  178. else
  179. len = os_strlen(*src);
  180. return wpa_config_write_string((const u8 *) *src, len);
  181. }
  182. #endif /* NO_CONFIG_WRITE */
  183. static int wpa_config_parse_int(const struct parse_data *data,
  184. struct wpa_ssid *ssid,
  185. int line, const char *value)
  186. {
  187. int *dst;
  188. dst = (int *) (((u8 *) ssid) + (long) data->param1);
  189. *dst = atoi(value);
  190. wpa_printf(MSG_MSGDUMP, "%s=%d (0x%x)", data->name, *dst, *dst);
  191. if (data->param3 && *dst < (long) data->param3) {
  192. wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
  193. "min_value=%ld)", line, data->name, *dst,
  194. (long) data->param3);
  195. *dst = (long) data->param3;
  196. return -1;
  197. }
  198. if (data->param4 && *dst > (long) data->param4) {
  199. wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
  200. "max_value=%ld)", line, data->name, *dst,
  201. (long) data->param4);
  202. *dst = (long) data->param4;
  203. return -1;
  204. }
  205. return 0;
  206. }
  207. #ifndef NO_CONFIG_WRITE
  208. static char * wpa_config_write_int(const struct parse_data *data,
  209. struct wpa_ssid *ssid)
  210. {
  211. int *src, res;
  212. char *value;
  213. src = (int *) (((u8 *) ssid) + (long) data->param1);
  214. value = os_malloc(20);
  215. if (value == NULL)
  216. return NULL;
  217. res = os_snprintf(value, 20, "%d", *src);
  218. if (res < 0 || res >= 20) {
  219. os_free(value);
  220. return NULL;
  221. }
  222. value[20 - 1] = '\0';
  223. return value;
  224. }
  225. #endif /* NO_CONFIG_WRITE */
  226. static int wpa_config_parse_bssid(const struct parse_data *data,
  227. struct wpa_ssid *ssid, int line,
  228. const char *value)
  229. {
  230. if (hwaddr_aton(value, ssid->bssid)) {
  231. wpa_printf(MSG_ERROR, "Line %d: Invalid BSSID '%s'.",
  232. line, value);
  233. return -1;
  234. }
  235. ssid->bssid_set = 1;
  236. wpa_hexdump(MSG_MSGDUMP, "BSSID", ssid->bssid, ETH_ALEN);
  237. return 0;
  238. }
  239. #ifndef NO_CONFIG_WRITE
  240. static char * wpa_config_write_bssid(const struct parse_data *data,
  241. struct wpa_ssid *ssid)
  242. {
  243. char *value;
  244. int res;
  245. if (!ssid->bssid_set)
  246. return NULL;
  247. value = os_malloc(20);
  248. if (value == NULL)
  249. return NULL;
  250. res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->bssid));
  251. if (res < 0 || res >= 20) {
  252. os_free(value);
  253. return NULL;
  254. }
  255. value[20 - 1] = '\0';
  256. return value;
  257. }
  258. #endif /* NO_CONFIG_WRITE */
  259. static int wpa_config_parse_psk(const struct parse_data *data,
  260. struct wpa_ssid *ssid, int line,
  261. const char *value)
  262. {
  263. if (*value == '"') {
  264. #ifndef CONFIG_NO_PBKDF2
  265. const char *pos;
  266. size_t len;
  267. value++;
  268. pos = os_strrchr(value, '"');
  269. if (pos)
  270. len = pos - value;
  271. else
  272. len = os_strlen(value);
  273. if (len < 8 || len > 63) {
  274. wpa_printf(MSG_ERROR, "Line %d: Invalid passphrase "
  275. "length %lu (expected: 8..63) '%s'.",
  276. line, (unsigned long) len, value);
  277. return -1;
  278. }
  279. wpa_hexdump_ascii_key(MSG_MSGDUMP, "PSK (ASCII passphrase)",
  280. (u8 *) value, len);
  281. if (ssid->passphrase && os_strlen(ssid->passphrase) == len &&
  282. os_memcmp(ssid->passphrase, value, len) == 0)
  283. return 0;
  284. ssid->psk_set = 0;
  285. os_free(ssid->passphrase);
  286. ssid->passphrase = os_malloc(len + 1);
  287. if (ssid->passphrase == NULL)
  288. return -1;
  289. os_memcpy(ssid->passphrase, value, len);
  290. ssid->passphrase[len] = '\0';
  291. return 0;
  292. #else /* CONFIG_NO_PBKDF2 */
  293. wpa_printf(MSG_ERROR, "Line %d: ASCII passphrase not "
  294. "supported.", line);
  295. return -1;
  296. #endif /* CONFIG_NO_PBKDF2 */
  297. }
  298. if (hexstr2bin(value, ssid->psk, PMK_LEN) ||
  299. value[PMK_LEN * 2] != '\0') {
  300. wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
  301. line, value);
  302. return -1;
  303. }
  304. os_free(ssid->passphrase);
  305. ssid->passphrase = NULL;
  306. ssid->psk_set = 1;
  307. wpa_hexdump_key(MSG_MSGDUMP, "PSK", ssid->psk, PMK_LEN);
  308. return 0;
  309. }
  310. #ifndef NO_CONFIG_WRITE
  311. static char * wpa_config_write_psk(const struct parse_data *data,
  312. struct wpa_ssid *ssid)
  313. {
  314. if (ssid->passphrase)
  315. return wpa_config_write_string_ascii(
  316. (const u8 *) ssid->passphrase,
  317. os_strlen(ssid->passphrase));
  318. if (ssid->psk_set)
  319. return wpa_config_write_string_hex(ssid->psk, PMK_LEN);
  320. return NULL;
  321. }
  322. #endif /* NO_CONFIG_WRITE */
  323. static int wpa_config_parse_proto(const struct parse_data *data,
  324. struct wpa_ssid *ssid, int line,
  325. const char *value)
  326. {
  327. int val = 0, last, errors = 0;
  328. char *start, *end, *buf;
  329. buf = os_strdup(value);
  330. if (buf == NULL)
  331. return -1;
  332. start = buf;
  333. while (*start != '\0') {
  334. while (*start == ' ' || *start == '\t')
  335. start++;
  336. if (*start == '\0')
  337. break;
  338. end = start;
  339. while (*end != ' ' && *end != '\t' && *end != '\0')
  340. end++;
  341. last = *end == '\0';
  342. *end = '\0';
  343. if (os_strcmp(start, "WPA") == 0)
  344. val |= WPA_PROTO_WPA;
  345. else if (os_strcmp(start, "RSN") == 0 ||
  346. os_strcmp(start, "WPA2") == 0)
  347. val |= WPA_PROTO_RSN;
  348. else {
  349. wpa_printf(MSG_ERROR, "Line %d: invalid proto '%s'",
  350. line, start);
  351. errors++;
  352. }
  353. if (last)
  354. break;
  355. start = end + 1;
  356. }
  357. os_free(buf);
  358. if (val == 0) {
  359. wpa_printf(MSG_ERROR,
  360. "Line %d: no proto values configured.", line);
  361. errors++;
  362. }
  363. wpa_printf(MSG_MSGDUMP, "proto: 0x%x", val);
  364. ssid->proto = val;
  365. return errors ? -1 : 0;
  366. }
  367. #ifndef NO_CONFIG_WRITE
  368. static char * wpa_config_write_proto(const struct parse_data *data,
  369. struct wpa_ssid *ssid)
  370. {
  371. int first = 1, ret;
  372. char *buf, *pos, *end;
  373. pos = buf = os_zalloc(10);
  374. if (buf == NULL)
  375. return NULL;
  376. end = buf + 10;
  377. if (ssid->proto & WPA_PROTO_WPA) {
  378. ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
  379. if (ret < 0 || ret >= end - pos)
  380. return buf;
  381. pos += ret;
  382. first = 0;
  383. }
  384. if (ssid->proto & WPA_PROTO_RSN) {
  385. ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
  386. if (ret < 0 || ret >= end - pos)
  387. return buf;
  388. pos += ret;
  389. first = 0;
  390. }
  391. return buf;
  392. }
  393. #endif /* NO_CONFIG_WRITE */
  394. static int wpa_config_parse_key_mgmt(const struct parse_data *data,
  395. struct wpa_ssid *ssid, int line,
  396. const char *value)
  397. {
  398. int val = 0, last, errors = 0;
  399. char *start, *end, *buf;
  400. buf = os_strdup(value);
  401. if (buf == NULL)
  402. return -1;
  403. start = buf;
  404. while (*start != '\0') {
  405. while (*start == ' ' || *start == '\t')
  406. start++;
  407. if (*start == '\0')
  408. break;
  409. end = start;
  410. while (*end != ' ' && *end != '\t' && *end != '\0')
  411. end++;
  412. last = *end == '\0';
  413. *end = '\0';
  414. if (os_strcmp(start, "WPA-PSK") == 0)
  415. val |= WPA_KEY_MGMT_PSK;
  416. else if (os_strcmp(start, "WPA-EAP") == 0)
  417. val |= WPA_KEY_MGMT_IEEE8021X;
  418. else if (os_strcmp(start, "IEEE8021X") == 0)
  419. val |= WPA_KEY_MGMT_IEEE8021X_NO_WPA;
  420. else if (os_strcmp(start, "NONE") == 0)
  421. val |= WPA_KEY_MGMT_NONE;
  422. else if (os_strcmp(start, "WPA-NONE") == 0)
  423. val |= WPA_KEY_MGMT_WPA_NONE;
  424. #ifdef CONFIG_IEEE80211R
  425. else if (os_strcmp(start, "FT-PSK") == 0)
  426. val |= WPA_KEY_MGMT_FT_PSK;
  427. else if (os_strcmp(start, "FT-EAP") == 0)
  428. val |= WPA_KEY_MGMT_FT_IEEE8021X;
  429. #endif /* CONFIG_IEEE80211R */
  430. #ifdef CONFIG_IEEE80211W
  431. else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
  432. val |= WPA_KEY_MGMT_PSK_SHA256;
  433. else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
  434. val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
  435. #endif /* CONFIG_IEEE80211W */
  436. else {
  437. wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
  438. line, start);
  439. errors++;
  440. }
  441. if (last)
  442. break;
  443. start = end + 1;
  444. }
  445. os_free(buf);
  446. if (val == 0) {
  447. wpa_printf(MSG_ERROR,
  448. "Line %d: no key_mgmt values configured.", line);
  449. errors++;
  450. }
  451. wpa_printf(MSG_MSGDUMP, "key_mgmt: 0x%x", val);
  452. ssid->key_mgmt = val;
  453. return errors ? -1 : 0;
  454. }
  455. #ifndef NO_CONFIG_WRITE
  456. static char * wpa_config_write_key_mgmt(const struct parse_data *data,
  457. struct wpa_ssid *ssid)
  458. {
  459. char *buf, *pos, *end;
  460. int ret;
  461. pos = buf = os_zalloc(50);
  462. if (buf == NULL)
  463. return NULL;
  464. end = buf + 50;
  465. if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
  466. ret = os_snprintf(pos, end - pos, "%sWPA-PSK",
  467. pos == buf ? "" : " ");
  468. if (ret < 0 || ret >= end - pos) {
  469. end[-1] = '\0';
  470. return buf;
  471. }
  472. pos += ret;
  473. }
  474. if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
  475. ret = os_snprintf(pos, end - pos, "%sWPA-EAP",
  476. pos == buf ? "" : " ");
  477. if (ret < 0 || ret >= end - pos) {
  478. end[-1] = '\0';
  479. return buf;
  480. }
  481. pos += ret;
  482. }
  483. if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  484. ret = os_snprintf(pos, end - pos, "%sIEEE8021X",
  485. pos == buf ? "" : " ");
  486. if (ret < 0 || ret >= end - pos) {
  487. end[-1] = '\0';
  488. return buf;
  489. }
  490. pos += ret;
  491. }
  492. if (ssid->key_mgmt & WPA_KEY_MGMT_NONE) {
  493. ret = os_snprintf(pos, end - pos, "%sNONE",
  494. pos == buf ? "" : " ");
  495. if (ret < 0 || ret >= end - pos) {
  496. end[-1] = '\0';
  497. return buf;
  498. }
  499. pos += ret;
  500. }
  501. if (ssid->key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
  502. ret = os_snprintf(pos, end - pos, "%sWPA-NONE",
  503. pos == buf ? "" : " ");
  504. if (ret < 0 || ret >= end - pos) {
  505. end[-1] = '\0';
  506. return buf;
  507. }
  508. pos += ret;
  509. }
  510. #ifdef CONFIG_IEEE80211R
  511. if (ssid->key_mgmt & WPA_KEY_MGMT_FT_PSK)
  512. pos += os_snprintf(pos, end - pos, "%sFT-PSK",
  513. pos == buf ? "" : " ");
  514. if (ssid->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X)
  515. pos += os_snprintf(pos, end - pos, "%sFT-EAP",
  516. pos == buf ? "" : " ");
  517. #endif /* CONFIG_IEEE80211R */
  518. #ifdef CONFIG_IEEE80211W
  519. if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
  520. pos += os_snprintf(pos, end - pos, "%sWPA-PSK-SHA256",
  521. pos == buf ? "" : " ");
  522. if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
  523. pos += os_snprintf(pos, end - pos, "%sWPA-EAP-SHA256",
  524. pos == buf ? "" : " ");
  525. #endif /* CONFIG_IEEE80211W */
  526. return buf;
  527. }
  528. #endif /* NO_CONFIG_WRITE */
  529. static int wpa_config_parse_cipher(int line, const char *value)
  530. {
  531. int val = 0, last;
  532. char *start, *end, *buf;
  533. buf = os_strdup(value);
  534. if (buf == NULL)
  535. return -1;
  536. start = buf;
  537. while (*start != '\0') {
  538. while (*start == ' ' || *start == '\t')
  539. start++;
  540. if (*start == '\0')
  541. break;
  542. end = start;
  543. while (*end != ' ' && *end != '\t' && *end != '\0')
  544. end++;
  545. last = *end == '\0';
  546. *end = '\0';
  547. if (os_strcmp(start, "CCMP") == 0)
  548. val |= WPA_CIPHER_CCMP;
  549. else if (os_strcmp(start, "TKIP") == 0)
  550. val |= WPA_CIPHER_TKIP;
  551. else if (os_strcmp(start, "WEP104") == 0)
  552. val |= WPA_CIPHER_WEP104;
  553. else if (os_strcmp(start, "WEP40") == 0)
  554. val |= WPA_CIPHER_WEP40;
  555. else if (os_strcmp(start, "NONE") == 0)
  556. val |= WPA_CIPHER_NONE;
  557. else {
  558. wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
  559. line, start);
  560. os_free(buf);
  561. return -1;
  562. }
  563. if (last)
  564. break;
  565. start = end + 1;
  566. }
  567. os_free(buf);
  568. if (val == 0) {
  569. wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
  570. line);
  571. return -1;
  572. }
  573. return val;
  574. }
  575. #ifndef NO_CONFIG_WRITE
  576. static char * wpa_config_write_cipher(int cipher)
  577. {
  578. char *buf, *pos, *end;
  579. int ret;
  580. pos = buf = os_zalloc(50);
  581. if (buf == NULL)
  582. return NULL;
  583. end = buf + 50;
  584. if (cipher & WPA_CIPHER_CCMP) {
  585. ret = os_snprintf(pos, end - pos, "%sCCMP",
  586. pos == buf ? "" : " ");
  587. if (ret < 0 || ret >= end - pos) {
  588. end[-1] = '\0';
  589. return buf;
  590. }
  591. pos += ret;
  592. }
  593. if (cipher & WPA_CIPHER_TKIP) {
  594. ret = os_snprintf(pos, end - pos, "%sTKIP",
  595. pos == buf ? "" : " ");
  596. if (ret < 0 || ret >= end - pos) {
  597. end[-1] = '\0';
  598. return buf;
  599. }
  600. pos += ret;
  601. }
  602. if (cipher & WPA_CIPHER_WEP104) {
  603. ret = os_snprintf(pos, end - pos, "%sWEP104",
  604. pos == buf ? "" : " ");
  605. if (ret < 0 || ret >= end - pos) {
  606. end[-1] = '\0';
  607. return buf;
  608. }
  609. pos += ret;
  610. }
  611. if (cipher & WPA_CIPHER_WEP40) {
  612. ret = os_snprintf(pos, end - pos, "%sWEP40",
  613. pos == buf ? "" : " ");
  614. if (ret < 0 || ret >= end - pos) {
  615. end[-1] = '\0';
  616. return buf;
  617. }
  618. pos += ret;
  619. }
  620. if (cipher & WPA_CIPHER_NONE) {
  621. ret = os_snprintf(pos, end - pos, "%sNONE",
  622. pos == buf ? "" : " ");
  623. if (ret < 0 || ret >= end - pos) {
  624. end[-1] = '\0';
  625. return buf;
  626. }
  627. pos += ret;
  628. }
  629. return buf;
  630. }
  631. #endif /* NO_CONFIG_WRITE */
  632. static int wpa_config_parse_pairwise(const struct parse_data *data,
  633. struct wpa_ssid *ssid, int line,
  634. const char *value)
  635. {
  636. int val;
  637. val = wpa_config_parse_cipher(line, value);
  638. if (val == -1)
  639. return -1;
  640. if (val & ~(WPA_CIPHER_CCMP | WPA_CIPHER_TKIP | WPA_CIPHER_NONE)) {
  641. wpa_printf(MSG_ERROR, "Line %d: not allowed pairwise cipher "
  642. "(0x%x).", line, val);
  643. return -1;
  644. }
  645. wpa_printf(MSG_MSGDUMP, "pairwise: 0x%x", val);
  646. ssid->pairwise_cipher = val;
  647. return 0;
  648. }
  649. #ifndef NO_CONFIG_WRITE
  650. static char * wpa_config_write_pairwise(const struct parse_data *data,
  651. struct wpa_ssid *ssid)
  652. {
  653. return wpa_config_write_cipher(ssid->pairwise_cipher);
  654. }
  655. #endif /* NO_CONFIG_WRITE */
  656. static int wpa_config_parse_group(const struct parse_data *data,
  657. struct wpa_ssid *ssid, int line,
  658. const char *value)
  659. {
  660. int val;
  661. val = wpa_config_parse_cipher(line, value);
  662. if (val == -1)
  663. return -1;
  664. if (val & ~(WPA_CIPHER_CCMP | WPA_CIPHER_TKIP | WPA_CIPHER_WEP104 |
  665. WPA_CIPHER_WEP40)) {
  666. wpa_printf(MSG_ERROR, "Line %d: not allowed group cipher "
  667. "(0x%x).", line, val);
  668. return -1;
  669. }
  670. wpa_printf(MSG_MSGDUMP, "group: 0x%x", val);
  671. ssid->group_cipher = val;
  672. return 0;
  673. }
  674. #ifndef NO_CONFIG_WRITE
  675. static char * wpa_config_write_group(const struct parse_data *data,
  676. struct wpa_ssid *ssid)
  677. {
  678. return wpa_config_write_cipher(ssid->group_cipher);
  679. }
  680. #endif /* NO_CONFIG_WRITE */
  681. static int wpa_config_parse_auth_alg(const struct parse_data *data,
  682. struct wpa_ssid *ssid, int line,
  683. const char *value)
  684. {
  685. int val = 0, last, errors = 0;
  686. char *start, *end, *buf;
  687. buf = os_strdup(value);
  688. if (buf == NULL)
  689. return -1;
  690. start = buf;
  691. while (*start != '\0') {
  692. while (*start == ' ' || *start == '\t')
  693. start++;
  694. if (*start == '\0')
  695. break;
  696. end = start;
  697. while (*end != ' ' && *end != '\t' && *end != '\0')
  698. end++;
  699. last = *end == '\0';
  700. *end = '\0';
  701. if (os_strcmp(start, "OPEN") == 0)
  702. val |= WPA_AUTH_ALG_OPEN;
  703. else if (os_strcmp(start, "SHARED") == 0)
  704. val |= WPA_AUTH_ALG_SHARED;
  705. else if (os_strcmp(start, "LEAP") == 0)
  706. val |= WPA_AUTH_ALG_LEAP;
  707. else {
  708. wpa_printf(MSG_ERROR, "Line %d: invalid auth_alg '%s'",
  709. line, start);
  710. errors++;
  711. }
  712. if (last)
  713. break;
  714. start = end + 1;
  715. }
  716. os_free(buf);
  717. if (val == 0) {
  718. wpa_printf(MSG_ERROR,
  719. "Line %d: no auth_alg values configured.", line);
  720. errors++;
  721. }
  722. wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", val);
  723. ssid->auth_alg = val;
  724. return errors ? -1 : 0;
  725. }
  726. #ifndef NO_CONFIG_WRITE
  727. static char * wpa_config_write_auth_alg(const struct parse_data *data,
  728. struct wpa_ssid *ssid)
  729. {
  730. char *buf, *pos, *end;
  731. int ret;
  732. pos = buf = os_zalloc(30);
  733. if (buf == NULL)
  734. return NULL;
  735. end = buf + 30;
  736. if (ssid->auth_alg & WPA_AUTH_ALG_OPEN) {
  737. ret = os_snprintf(pos, end - pos, "%sOPEN",
  738. pos == buf ? "" : " ");
  739. if (ret < 0 || ret >= end - pos) {
  740. end[-1] = '\0';
  741. return buf;
  742. }
  743. pos += ret;
  744. }
  745. if (ssid->auth_alg & WPA_AUTH_ALG_SHARED) {
  746. ret = os_snprintf(pos, end - pos, "%sSHARED",
  747. pos == buf ? "" : " ");
  748. if (ret < 0 || ret >= end - pos) {
  749. end[-1] = '\0';
  750. return buf;
  751. }
  752. pos += ret;
  753. }
  754. if (ssid->auth_alg & WPA_AUTH_ALG_LEAP) {
  755. ret = os_snprintf(pos, end - pos, "%sLEAP",
  756. pos == buf ? "" : " ");
  757. if (ret < 0 || ret >= end - pos) {
  758. end[-1] = '\0';
  759. return buf;
  760. }
  761. pos += ret;
  762. }
  763. return buf;
  764. }
  765. #endif /* NO_CONFIG_WRITE */
  766. #ifdef IEEE8021X_EAPOL
  767. static int wpa_config_parse_eap(const struct parse_data *data,
  768. struct wpa_ssid *ssid, int line,
  769. const char *value)
  770. {
  771. int last, errors = 0;
  772. char *start, *end, *buf;
  773. struct eap_method_type *methods = NULL, *tmp;
  774. size_t num_methods = 0;
  775. buf = os_strdup(value);
  776. if (buf == NULL)
  777. return -1;
  778. start = buf;
  779. while (*start != '\0') {
  780. while (*start == ' ' || *start == '\t')
  781. start++;
  782. if (*start == '\0')
  783. break;
  784. end = start;
  785. while (*end != ' ' && *end != '\t' && *end != '\0')
  786. end++;
  787. last = *end == '\0';
  788. *end = '\0';
  789. tmp = methods;
  790. methods = os_realloc(methods,
  791. (num_methods + 1) * sizeof(*methods));
  792. if (methods == NULL) {
  793. os_free(tmp);
  794. os_free(buf);
  795. return -1;
  796. }
  797. methods[num_methods].method = eap_peer_get_type(
  798. start, &methods[num_methods].vendor);
  799. if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
  800. methods[num_methods].method == EAP_TYPE_NONE) {
  801. wpa_printf(MSG_ERROR, "Line %d: unknown EAP method "
  802. "'%s'", line, start);
  803. wpa_printf(MSG_ERROR, "You may need to add support for"
  804. " this EAP method during wpa_supplicant\n"
  805. "build time configuration.\n"
  806. "See README for more information.");
  807. errors++;
  808. } else if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
  809. methods[num_methods].method == EAP_TYPE_LEAP)
  810. ssid->leap++;
  811. else
  812. ssid->non_leap++;
  813. num_methods++;
  814. if (last)
  815. break;
  816. start = end + 1;
  817. }
  818. os_free(buf);
  819. tmp = methods;
  820. methods = os_realloc(methods, (num_methods + 1) * sizeof(*methods));
  821. if (methods == NULL) {
  822. os_free(tmp);
  823. return -1;
  824. }
  825. methods[num_methods].vendor = EAP_VENDOR_IETF;
  826. methods[num_methods].method = EAP_TYPE_NONE;
  827. num_methods++;
  828. wpa_hexdump(MSG_MSGDUMP, "eap methods",
  829. (u8 *) methods, num_methods * sizeof(*methods));
  830. ssid->eap.eap_methods = methods;
  831. return errors ? -1 : 0;
  832. }
  833. static char * wpa_config_write_eap(const struct parse_data *data,
  834. struct wpa_ssid *ssid)
  835. {
  836. int i, ret;
  837. char *buf, *pos, *end;
  838. const struct eap_method_type *eap_methods = ssid->eap.eap_methods;
  839. const char *name;
  840. if (eap_methods == NULL)
  841. return NULL;
  842. pos = buf = os_zalloc(100);
  843. if (buf == NULL)
  844. return NULL;
  845. end = buf + 100;
  846. for (i = 0; eap_methods[i].vendor != EAP_VENDOR_IETF ||
  847. eap_methods[i].method != EAP_TYPE_NONE; i++) {
  848. name = eap_get_name(eap_methods[i].vendor,
  849. eap_methods[i].method);
  850. if (name) {
  851. ret = os_snprintf(pos, end - pos, "%s%s",
  852. pos == buf ? "" : " ", name);
  853. if (ret < 0 || ret >= end - pos)
  854. break;
  855. pos += ret;
  856. }
  857. }
  858. end[-1] = '\0';
  859. return buf;
  860. }
  861. static int wpa_config_parse_password(const struct parse_data *data,
  862. struct wpa_ssid *ssid, int line,
  863. const char *value)
  864. {
  865. u8 *hash;
  866. if (os_strcmp(value, "NULL") == 0) {
  867. wpa_printf(MSG_DEBUG, "Unset configuration string 'password'");
  868. os_free(ssid->eap.password);
  869. ssid->eap.password = NULL;
  870. ssid->eap.password_len = 0;
  871. return 0;
  872. }
  873. if (os_strncmp(value, "hash:", 5) != 0) {
  874. char *tmp;
  875. size_t res_len;
  876. tmp = wpa_config_parse_string(value, &res_len);
  877. if (tmp == NULL) {
  878. wpa_printf(MSG_ERROR, "Line %d: failed to parse "
  879. "password.", line);
  880. return -1;
  881. }
  882. wpa_hexdump_ascii(MSG_MSGDUMP, data->name,
  883. (u8 *) tmp, res_len);
  884. os_free(ssid->eap.password);
  885. ssid->eap.password = (u8 *) tmp;
  886. ssid->eap.password_len = res_len;
  887. ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
  888. return 0;
  889. }
  890. /* NtPasswordHash: hash:<32 hex digits> */
  891. if (os_strlen(value + 5) != 2 * 16) {
  892. wpa_printf(MSG_ERROR, "Line %d: Invalid password hash length "
  893. "(expected 32 hex digits)", line);
  894. return -1;
  895. }
  896. hash = os_malloc(16);
  897. if (hash == NULL)
  898. return -1;
  899. if (hexstr2bin(value + 5, hash, 16)) {
  900. os_free(hash);
  901. wpa_printf(MSG_ERROR, "Line %d: Invalid password hash", line);
  902. return -1;
  903. }
  904. wpa_hexdump_key(MSG_MSGDUMP, data->name, hash, 16);
  905. os_free(ssid->eap.password);
  906. ssid->eap.password = hash;
  907. ssid->eap.password_len = 16;
  908. ssid->eap.flags |= EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
  909. return 0;
  910. }
  911. static char * wpa_config_write_password(const struct parse_data *data,
  912. struct wpa_ssid *ssid)
  913. {
  914. char *buf;
  915. if (ssid->eap.password == NULL)
  916. return NULL;
  917. if (!(ssid->eap.flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH)) {
  918. return wpa_config_write_string(
  919. ssid->eap.password, ssid->eap.password_len);
  920. }
  921. buf = os_malloc(5 + 32 + 1);
  922. if (buf == NULL)
  923. return NULL;
  924. os_memcpy(buf, "hash:", 5);
  925. wpa_snprintf_hex(buf + 5, 32 + 1, ssid->eap.password, 16);
  926. return buf;
  927. }
  928. #endif /* IEEE8021X_EAPOL */
  929. static int wpa_config_parse_wep_key(u8 *key, size_t *len, int line,
  930. const char *value, int idx)
  931. {
  932. char *buf, title[20];
  933. int res;
  934. buf = wpa_config_parse_string(value, len);
  935. if (buf == NULL) {
  936. wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key %d '%s'.",
  937. line, idx, value);
  938. return -1;
  939. }
  940. if (*len > MAX_WEP_KEY_LEN) {
  941. wpa_printf(MSG_ERROR, "Line %d: Too long WEP key %d '%s'.",
  942. line, idx, value);
  943. os_free(buf);
  944. return -1;
  945. }
  946. os_memcpy(key, buf, *len);
  947. os_free(buf);
  948. res = os_snprintf(title, sizeof(title), "wep_key%d", idx);
  949. if (res >= 0 && (size_t) res < sizeof(title))
  950. wpa_hexdump_key(MSG_MSGDUMP, title, key, *len);
  951. return 0;
  952. }
  953. static int wpa_config_parse_wep_key0(const struct parse_data *data,
  954. struct wpa_ssid *ssid, int line,
  955. const char *value)
  956. {
  957. return wpa_config_parse_wep_key(ssid->wep_key[0],
  958. &ssid->wep_key_len[0], line,
  959. value, 0);
  960. }
  961. static int wpa_config_parse_wep_key1(const struct parse_data *data,
  962. struct wpa_ssid *ssid, int line,
  963. const char *value)
  964. {
  965. return wpa_config_parse_wep_key(ssid->wep_key[1],
  966. &ssid->wep_key_len[1], line,
  967. value, 1);
  968. }
  969. static int wpa_config_parse_wep_key2(const struct parse_data *data,
  970. struct wpa_ssid *ssid, int line,
  971. const char *value)
  972. {
  973. return wpa_config_parse_wep_key(ssid->wep_key[2],
  974. &ssid->wep_key_len[2], line,
  975. value, 2);
  976. }
  977. static int wpa_config_parse_wep_key3(const struct parse_data *data,
  978. struct wpa_ssid *ssid, int line,
  979. const char *value)
  980. {
  981. return wpa_config_parse_wep_key(ssid->wep_key[3],
  982. &ssid->wep_key_len[3], line,
  983. value, 3);
  984. }
  985. #ifndef NO_CONFIG_WRITE
  986. static char * wpa_config_write_wep_key(struct wpa_ssid *ssid, int idx)
  987. {
  988. if (ssid->wep_key_len[idx] == 0)
  989. return NULL;
  990. return wpa_config_write_string(ssid->wep_key[idx],
  991. ssid->wep_key_len[idx]);
  992. }
  993. static char * wpa_config_write_wep_key0(const struct parse_data *data,
  994. struct wpa_ssid *ssid)
  995. {
  996. return wpa_config_write_wep_key(ssid, 0);
  997. }
  998. static char * wpa_config_write_wep_key1(const struct parse_data *data,
  999. struct wpa_ssid *ssid)
  1000. {
  1001. return wpa_config_write_wep_key(ssid, 1);
  1002. }
  1003. static char * wpa_config_write_wep_key2(const struct parse_data *data,
  1004. struct wpa_ssid *ssid)
  1005. {
  1006. return wpa_config_write_wep_key(ssid, 2);
  1007. }
  1008. static char * wpa_config_write_wep_key3(const struct parse_data *data,
  1009. struct wpa_ssid *ssid)
  1010. {
  1011. return wpa_config_write_wep_key(ssid, 3);
  1012. }
  1013. #endif /* NO_CONFIG_WRITE */
  1014. /* Helper macros for network block parser */
  1015. #ifdef OFFSET
  1016. #undef OFFSET
  1017. #endif /* OFFSET */
  1018. /* OFFSET: Get offset of a variable within the wpa_ssid structure */
  1019. #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
  1020. /* STR: Define a string variable for an ASCII string; f = field name */
  1021. #ifdef NO_CONFIG_WRITE
  1022. #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
  1023. #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
  1024. #else /* NO_CONFIG_WRITE */
  1025. #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
  1026. #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
  1027. #endif /* NO_CONFIG_WRITE */
  1028. #define STR(f) _STR(f), NULL, NULL, NULL, 0
  1029. #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
  1030. #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
  1031. #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
  1032. /* STR_LEN: Define a string variable with a separate variable for storing the
  1033. * data length. Unlike STR(), this can be used to store arbitrary binary data
  1034. * (i.e., even nul termination character). */
  1035. #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
  1036. #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
  1037. #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
  1038. #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
  1039. #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
  1040. /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
  1041. * explicitly specified. */
  1042. #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
  1043. #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
  1044. #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
  1045. #ifdef NO_CONFIG_WRITE
  1046. #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
  1047. #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
  1048. #else /* NO_CONFIG_WRITE */
  1049. #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
  1050. OFFSET(f), (void *) 0
  1051. #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
  1052. OFFSET(eap.f), (void *) 0
  1053. #endif /* NO_CONFIG_WRITE */
  1054. /* INT: Define an integer variable */
  1055. #define INT(f) _INT(f), NULL, NULL, 0
  1056. #define INTe(f) _INTe(f), NULL, NULL, 0
  1057. /* INT_RANGE: Define an integer variable with allowed value range */
  1058. #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
  1059. /* FUNC: Define a configuration variable that uses a custom function for
  1060. * parsing and writing the value. */
  1061. #ifdef NO_CONFIG_WRITE
  1062. #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
  1063. #else /* NO_CONFIG_WRITE */
  1064. #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
  1065. NULL, NULL, NULL, NULL
  1066. #endif /* NO_CONFIG_WRITE */
  1067. #define FUNC(f) _FUNC(f), 0
  1068. #define FUNC_KEY(f) _FUNC(f), 1
  1069. /*
  1070. * Table of network configuration variables. This table is used to parse each
  1071. * network configuration variable, e.g., each line in wpa_supplicant.conf file
  1072. * that is inside a network block.
  1073. *
  1074. * This table is generated using the helper macros defined above and with
  1075. * generous help from the C pre-processor. The field name is stored as a string
  1076. * into .name and for STR and INT types, the offset of the target buffer within
  1077. * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
  1078. * offset to the field containing the length of the configuration variable.
  1079. * .param3 and .param4 can be used to mark the allowed range (length for STR
  1080. * and value for INT).
  1081. *
  1082. * For each configuration line in wpa_supplicant.conf, the parser goes through
  1083. * this table and select the entry that matches with the field name. The parser
  1084. * function (.parser) is then called to parse the actual value of the field.
  1085. *
  1086. * This kind of mechanism makes it easy to add new configuration parameters,
  1087. * since only one line needs to be added into this table and into the
  1088. * struct wpa_ssid definition if the new variable is either a string or
  1089. * integer. More complex types will need to use their own parser and writer
  1090. * functions.
  1091. */
  1092. static const struct parse_data ssid_fields[] = {
  1093. { STR_RANGE(ssid, 0, MAX_SSID_LEN) },
  1094. { INT_RANGE(scan_ssid, 0, 1) },
  1095. { FUNC(bssid) },
  1096. { FUNC_KEY(psk) },
  1097. { FUNC(proto) },
  1098. { FUNC(key_mgmt) },
  1099. { FUNC(pairwise) },
  1100. { FUNC(group) },
  1101. { FUNC(auth_alg) },
  1102. #ifdef IEEE8021X_EAPOL
  1103. { FUNC(eap) },
  1104. { STR_LENe(identity) },
  1105. { STR_LENe(anonymous_identity) },
  1106. { FUNC(password) },
  1107. { STRe(ca_cert) },
  1108. { STRe(ca_path) },
  1109. { STRe(client_cert) },
  1110. { STRe(private_key) },
  1111. { STR_KEYe(private_key_passwd) },
  1112. { STRe(dh_file) },
  1113. { STRe(subject_match) },
  1114. { STRe(altsubject_match) },
  1115. { STRe(ca_cert2) },
  1116. { STRe(ca_path2) },
  1117. { STRe(client_cert2) },
  1118. { STRe(private_key2) },
  1119. { STR_KEYe(private_key2_passwd) },
  1120. { STRe(dh_file2) },
  1121. { STRe(subject_match2) },
  1122. { STRe(altsubject_match2) },
  1123. { STRe(phase1) },
  1124. { STRe(phase2) },
  1125. { STRe(pcsc) },
  1126. { STR_KEYe(pin) },
  1127. { STRe(engine_id) },
  1128. { STRe(key_id) },
  1129. { STRe(cert_id) },
  1130. { STRe(ca_cert_id) },
  1131. { STRe(key2_id) },
  1132. { STRe(cert2_id) },
  1133. { STRe(ca_cert2_id) },
  1134. { INTe(engine) },
  1135. { INT(eapol_flags) },
  1136. #endif /* IEEE8021X_EAPOL */
  1137. { FUNC_KEY(wep_key0) },
  1138. { FUNC_KEY(wep_key1) },
  1139. { FUNC_KEY(wep_key2) },
  1140. { FUNC_KEY(wep_key3) },
  1141. { INT(wep_tx_keyidx) },
  1142. { INT(priority) },
  1143. #ifdef IEEE8021X_EAPOL
  1144. { INT(eap_workaround) },
  1145. { STRe(pac_file) },
  1146. { INTe(fragment_size) },
  1147. #endif /* IEEE8021X_EAPOL */
  1148. { INT_RANGE(mode, 0, 1) },
  1149. { INT_RANGE(proactive_key_caching, 0, 1) },
  1150. { INT_RANGE(disabled, 0, 1) },
  1151. { STR(id_str) },
  1152. #ifdef CONFIG_IEEE80211W
  1153. { INT_RANGE(ieee80211w, 0, 2) },
  1154. #endif /* CONFIG_IEEE80211W */
  1155. { INT_RANGE(peerkey, 0, 1) },
  1156. { INT_RANGE(mixed_cell, 0, 1) },
  1157. { INT_RANGE(frequency, 0, 10000) }
  1158. };
  1159. #undef OFFSET
  1160. #undef _STR
  1161. #undef STR
  1162. #undef STR_KEY
  1163. #undef _STR_LEN
  1164. #undef STR_LEN
  1165. #undef STR_LEN_KEY
  1166. #undef _STR_RANGE
  1167. #undef STR_RANGE
  1168. #undef STR_RANGE_KEY
  1169. #undef _INT
  1170. #undef INT
  1171. #undef INT_RANGE
  1172. #undef _FUNC
  1173. #undef FUNC
  1174. #undef FUNC_KEY
  1175. #define NUM_SSID_FIELDS (sizeof(ssid_fields) / sizeof(ssid_fields[0]))
  1176. /**
  1177. * wpa_config_add_prio_network - Add a network to priority lists
  1178. * @config: Configuration data from wpa_config_read()
  1179. * @ssid: Pointer to the network configuration to be added to the list
  1180. * Returns: 0 on success, -1 on failure
  1181. *
  1182. * This function is used to add a network block to the priority list of
  1183. * networks. This must be called for each network when reading in the full
  1184. * configuration. In addition, this can be used indirectly when updating
  1185. * priorities by calling wpa_config_update_prio_list().
  1186. */
  1187. int wpa_config_add_prio_network(struct wpa_config *config,
  1188. struct wpa_ssid *ssid)
  1189. {
  1190. int prio;
  1191. struct wpa_ssid *prev, **nlist;
  1192. /*
  1193. * Add to an existing priority list if one is available for the
  1194. * configured priority level for this network.
  1195. */
  1196. for (prio = 0; prio < config->num_prio; prio++) {
  1197. prev = config->pssid[prio];
  1198. if (prev->priority == ssid->priority) {
  1199. while (prev->pnext)
  1200. prev = prev->pnext;
  1201. prev->pnext = ssid;
  1202. return 0;
  1203. }
  1204. }
  1205. /* First network for this priority - add a new priority list */
  1206. nlist = os_realloc(config->pssid,
  1207. (config->num_prio + 1) * sizeof(struct wpa_ssid *));
  1208. if (nlist == NULL)
  1209. return -1;
  1210. for (prio = 0; prio < config->num_prio; prio++) {
  1211. if (nlist[prio]->priority < ssid->priority)
  1212. break;
  1213. }
  1214. os_memmove(&nlist[prio + 1], &nlist[prio],
  1215. (config->num_prio - prio) * sizeof(struct wpa_ssid *));
  1216. nlist[prio] = ssid;
  1217. config->num_prio++;
  1218. config->pssid = nlist;
  1219. return 0;
  1220. }
  1221. /**
  1222. * wpa_config_update_prio_list - Update network priority list
  1223. * @config: Configuration data from wpa_config_read()
  1224. * Returns: 0 on success, -1 on failure
  1225. *
  1226. * This function is called to update the priority list of networks in the
  1227. * configuration when a network is being added or removed. This is also called
  1228. * if a priority for a network is changed.
  1229. */
  1230. static int wpa_config_update_prio_list(struct wpa_config *config)
  1231. {
  1232. struct wpa_ssid *ssid;
  1233. int ret = 0;
  1234. os_free(config->pssid);
  1235. config->pssid = NULL;
  1236. config->num_prio = 0;
  1237. ssid = config->ssid;
  1238. while (ssid) {
  1239. ssid->pnext = NULL;
  1240. if (wpa_config_add_prio_network(config, ssid) < 0)
  1241. ret = -1;
  1242. ssid = ssid->next;
  1243. }
  1244. return ret;
  1245. }
  1246. #ifdef IEEE8021X_EAPOL
  1247. static void eap_peer_config_free(struct eap_peer_config *eap)
  1248. {
  1249. os_free(eap->eap_methods);
  1250. os_free(eap->identity);
  1251. os_free(eap->anonymous_identity);
  1252. os_free(eap->password);
  1253. os_free(eap->ca_cert);
  1254. os_free(eap->ca_path);
  1255. os_free(eap->client_cert);
  1256. os_free(eap->private_key);
  1257. os_free(eap->private_key_passwd);
  1258. os_free(eap->dh_file);
  1259. os_free(eap->subject_match);
  1260. os_free(eap->altsubject_match);
  1261. os_free(eap->ca_cert2);
  1262. os_free(eap->ca_path2);
  1263. os_free(eap->client_cert2);
  1264. os_free(eap->private_key2);
  1265. os_free(eap->private_key2_passwd);
  1266. os_free(eap->dh_file2);
  1267. os_free(eap->subject_match2);
  1268. os_free(eap->altsubject_match2);
  1269. os_free(eap->phase1);
  1270. os_free(eap->phase2);
  1271. os_free(eap->pcsc);
  1272. os_free(eap->pin);
  1273. os_free(eap->engine_id);
  1274. os_free(eap->key_id);
  1275. os_free(eap->cert_id);
  1276. os_free(eap->ca_cert_id);
  1277. os_free(eap->key2_id);
  1278. os_free(eap->cert2_id);
  1279. os_free(eap->ca_cert2_id);
  1280. os_free(eap->otp);
  1281. os_free(eap->pending_req_otp);
  1282. os_free(eap->pac_file);
  1283. os_free(eap->new_password);
  1284. }
  1285. #endif /* IEEE8021X_EAPOL */
  1286. /**
  1287. * wpa_config_free_ssid - Free network/ssid configuration data
  1288. * @ssid: Configuration data for the network
  1289. *
  1290. * This function frees all resources allocated for the network configuration
  1291. * data.
  1292. */
  1293. void wpa_config_free_ssid(struct wpa_ssid *ssid)
  1294. {
  1295. os_free(ssid->ssid);
  1296. os_free(ssid->passphrase);
  1297. #ifdef IEEE8021X_EAPOL
  1298. eap_peer_config_free(&ssid->eap);
  1299. #endif /* IEEE8021X_EAPOL */
  1300. os_free(ssid->id_str);
  1301. os_free(ssid);
  1302. }
  1303. /**
  1304. * wpa_config_free - Free configuration data
  1305. * @config: Configuration data from wpa_config_read()
  1306. *
  1307. * This function frees all resources allocated for the configuration data by
  1308. * wpa_config_read().
  1309. */
  1310. void wpa_config_free(struct wpa_config *config)
  1311. {
  1312. #ifndef CONFIG_NO_CONFIG_BLOBS
  1313. struct wpa_config_blob *blob, *prevblob;
  1314. #endif /* CONFIG_NO_CONFIG_BLOBS */
  1315. struct wpa_ssid *ssid, *prev = NULL;
  1316. ssid = config->ssid;
  1317. while (ssid) {
  1318. prev = ssid;
  1319. ssid = ssid->next;
  1320. wpa_config_free_ssid(prev);
  1321. }
  1322. #ifndef CONFIG_NO_CONFIG_BLOBS
  1323. blob = config->blobs;
  1324. prevblob = NULL;
  1325. while (blob) {
  1326. prevblob = blob;
  1327. blob = blob->next;
  1328. wpa_config_free_blob(prevblob);
  1329. }
  1330. #endif /* CONFIG_NO_CONFIG_BLOBS */
  1331. os_free(config->ctrl_interface);
  1332. os_free(config->ctrl_interface_group);
  1333. #ifdef EAP_TLS_OPENSSL
  1334. os_free(config->opensc_engine_path);
  1335. os_free(config->pkcs11_engine_path);
  1336. os_free(config->pkcs11_module_path);
  1337. #endif /* EAP_TLS_OPENSSL */
  1338. os_free(config->driver_param);
  1339. os_free(config->pssid);
  1340. os_free(config);
  1341. }
  1342. /**
  1343. * wpa_config_get_network - Get configured network based on id
  1344. * @config: Configuration data from wpa_config_read()
  1345. * @id: Unique network id to search for
  1346. * Returns: Network configuration or %NULL if not found
  1347. */
  1348. struct wpa_ssid * wpa_config_get_network(struct wpa_config *config, int id)
  1349. {
  1350. struct wpa_ssid *ssid;
  1351. ssid = config->ssid;
  1352. while (ssid) {
  1353. if (id == ssid->id)
  1354. break;
  1355. ssid = ssid->next;
  1356. }
  1357. return ssid;
  1358. }
  1359. /**
  1360. * wpa_config_add_network - Add a new network with empty configuration
  1361. * @config: Configuration data from wpa_config_read()
  1362. * Returns: The new network configuration or %NULL if operation failed
  1363. */
  1364. struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)
  1365. {
  1366. int id;
  1367. struct wpa_ssid *ssid, *last = NULL;
  1368. id = -1;
  1369. ssid = config->ssid;
  1370. while (ssid) {
  1371. if (ssid->id > id)
  1372. id = ssid->id;
  1373. last = ssid;
  1374. ssid = ssid->next;
  1375. }
  1376. id++;
  1377. ssid = os_zalloc(sizeof(*ssid));
  1378. if (ssid == NULL)
  1379. return NULL;
  1380. ssid->id = id;
  1381. if (last)
  1382. last->next = ssid;
  1383. else
  1384. config->ssid = ssid;
  1385. wpa_config_update_prio_list(config);
  1386. return ssid;
  1387. }
  1388. /**
  1389. * wpa_config_remove_network - Remove a configured network based on id
  1390. * @config: Configuration data from wpa_config_read()
  1391. * @id: Unique network id to search for
  1392. * Returns: 0 on success, or -1 if the network was not found
  1393. */
  1394. int wpa_config_remove_network(struct wpa_config *config, int id)
  1395. {
  1396. struct wpa_ssid *ssid, *prev = NULL;
  1397. ssid = config->ssid;
  1398. while (ssid) {
  1399. if (id == ssid->id)
  1400. break;
  1401. prev = ssid;
  1402. ssid = ssid->next;
  1403. }
  1404. if (ssid == NULL)
  1405. return -1;
  1406. if (prev)
  1407. prev->next = ssid->next;
  1408. else
  1409. config->ssid = ssid->next;
  1410. wpa_config_update_prio_list(config);
  1411. wpa_config_free_ssid(ssid);
  1412. return 0;
  1413. }
  1414. /**
  1415. * wpa_config_set_network_defaults - Set network default values
  1416. * @ssid: Pointer to network configuration data
  1417. */
  1418. void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
  1419. {
  1420. ssid->proto = DEFAULT_PROTO;
  1421. ssid->pairwise_cipher = DEFAULT_PAIRWISE;
  1422. ssid->group_cipher = DEFAULT_GROUP;
  1423. ssid->key_mgmt = DEFAULT_KEY_MGMT;
  1424. #ifdef IEEE8021X_EAPOL
  1425. ssid->eapol_flags = DEFAULT_EAPOL_FLAGS;
  1426. ssid->eap_workaround = DEFAULT_EAP_WORKAROUND;
  1427. ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE;
  1428. #endif /* IEEE8021X_EAPOL */
  1429. }
  1430. /**
  1431. * wpa_config_set - Set a variable in network configuration
  1432. * @ssid: Pointer to network configuration data
  1433. * @var: Variable name, e.g., "ssid"
  1434. * @value: Variable value
  1435. * @line: Line number in configuration file or 0 if not used
  1436. * Returns: 0 on success, -1 on failure
  1437. *
  1438. * This function can be used to set network configuration variables based on
  1439. * both the configuration file and management interface input. The value
  1440. * parameter must be in the same format as the text-based configuration file is
  1441. * using. For example, strings are using double quotation marks.
  1442. */
  1443. int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
  1444. int line)
  1445. {
  1446. size_t i;
  1447. int ret = 0;
  1448. if (ssid == NULL || var == NULL || value == NULL)
  1449. return -1;
  1450. for (i = 0; i < NUM_SSID_FIELDS; i++) {
  1451. const struct parse_data *field = &ssid_fields[i];
  1452. if (os_strcmp(var, field->name) != 0)
  1453. continue;
  1454. if (field->parser(field, ssid, line, value)) {
  1455. if (line) {
  1456. wpa_printf(MSG_ERROR, "Line %d: failed to "
  1457. "parse %s '%s'.", line, var, value);
  1458. }
  1459. ret = -1;
  1460. }
  1461. break;
  1462. }
  1463. if (i == NUM_SSID_FIELDS) {
  1464. if (line) {
  1465. wpa_printf(MSG_ERROR, "Line %d: unknown network field "
  1466. "'%s'.", line, var);
  1467. }
  1468. ret = -1;
  1469. }
  1470. return ret;
  1471. }
  1472. #ifndef NO_CONFIG_WRITE
  1473. /**
  1474. * wpa_config_get - Get a variable in network configuration
  1475. * @ssid: Pointer to network configuration data
  1476. * @var: Variable name, e.g., "ssid"
  1477. * Returns: Value of the variable or %NULL on failure
  1478. *
  1479. * This function can be used to get network configuration variables. The
  1480. * returned value is a copy of the configuration variable in text format, i.e,.
  1481. * the same format that the text-based configuration file and wpa_config_set()
  1482. * are using for the value. The caller is responsible for freeing the returned
  1483. * value.
  1484. */
  1485. char * wpa_config_get(struct wpa_ssid *ssid, const char *var)
  1486. {
  1487. size_t i;
  1488. if (ssid == NULL || var == NULL)
  1489. return NULL;
  1490. for (i = 0; i < NUM_SSID_FIELDS; i++) {
  1491. const struct parse_data *field = &ssid_fields[i];
  1492. if (os_strcmp(var, field->name) == 0)
  1493. return field->writer(field, ssid);
  1494. }
  1495. return NULL;
  1496. }
  1497. /**
  1498. * wpa_config_get_no_key - Get a variable in network configuration (no keys)
  1499. * @ssid: Pointer to network configuration data
  1500. * @var: Variable name, e.g., "ssid"
  1501. * Returns: Value of the variable or %NULL on failure
  1502. *
  1503. * This function can be used to get network configuration variable like
  1504. * wpa_config_get(). The only difference is that this functions does not expose
  1505. * key/password material from the configuration. In case a key/password field
  1506. * is requested, the returned value is an empty string or %NULL if the variable
  1507. * is not set or "*" if the variable is set (regardless of its value). The
  1508. * returned value is a copy of the configuration variable in text format, i.e,.
  1509. * the same format that the text-based configuration file and wpa_config_set()
  1510. * are using for the value. The caller is responsible for freeing the returned
  1511. * value.
  1512. */
  1513. char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var)
  1514. {
  1515. size_t i;
  1516. if (ssid == NULL || var == NULL)
  1517. return NULL;
  1518. for (i = 0; i < NUM_SSID_FIELDS; i++) {
  1519. const struct parse_data *field = &ssid_fields[i];
  1520. if (os_strcmp(var, field->name) == 0) {
  1521. char *res = field->writer(field, ssid);
  1522. if (field->key_data) {
  1523. if (res && res[0]) {
  1524. wpa_printf(MSG_DEBUG, "Do not allow "
  1525. "key_data field to be "
  1526. "exposed");
  1527. os_free(res);
  1528. return os_strdup("*");
  1529. }
  1530. os_free(res);
  1531. return NULL;
  1532. }
  1533. return res;
  1534. }
  1535. }
  1536. return NULL;
  1537. }
  1538. #endif /* NO_CONFIG_WRITE */
  1539. /**
  1540. * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
  1541. * @ssid: Pointer to network configuration data
  1542. *
  1543. * This function must be called to update WPA PSK when either SSID or the
  1544. * passphrase has changed for the network configuration.
  1545. */
  1546. void wpa_config_update_psk(struct wpa_ssid *ssid)
  1547. {
  1548. #ifndef CONFIG_NO_PBKDF2
  1549. pbkdf2_sha1(ssid->passphrase,
  1550. (char *) ssid->ssid, ssid->ssid_len, 4096,
  1551. ssid->psk, PMK_LEN);
  1552. wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
  1553. ssid->psk, PMK_LEN);
  1554. ssid->psk_set = 1;
  1555. #endif /* CONFIG_NO_PBKDF2 */
  1556. }
  1557. #ifndef CONFIG_NO_CONFIG_BLOBS
  1558. /**
  1559. * wpa_config_get_blob - Get a named configuration blob
  1560. * @config: Configuration data from wpa_config_read()
  1561. * @name: Name of the blob
  1562. * Returns: Pointer to blob data or %NULL if not found
  1563. */
  1564. const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config,
  1565. const char *name)
  1566. {
  1567. struct wpa_config_blob *blob = config->blobs;
  1568. while (blob) {
  1569. if (os_strcmp(blob->name, name) == 0)
  1570. return blob;
  1571. blob = blob->next;
  1572. }
  1573. return NULL;
  1574. }
  1575. /**
  1576. * wpa_config_set_blob - Set or add a named configuration blob
  1577. * @config: Configuration data from wpa_config_read()
  1578. * @blob: New value for the blob
  1579. *
  1580. * Adds a new configuration blob or replaces the current value of an existing
  1581. * blob.
  1582. */
  1583. void wpa_config_set_blob(struct wpa_config *config,
  1584. struct wpa_config_blob *blob)
  1585. {
  1586. wpa_config_remove_blob(config, blob->name);
  1587. blob->next = config->blobs;
  1588. config->blobs = blob;
  1589. }
  1590. /**
  1591. * wpa_config_free_blob - Free blob data
  1592. * @blob: Pointer to blob to be freed
  1593. */
  1594. void wpa_config_free_blob(struct wpa_config_blob *blob)
  1595. {
  1596. if (blob) {
  1597. os_free(blob->name);
  1598. os_free(blob->data);
  1599. os_free(blob);
  1600. }
  1601. }
  1602. /**
  1603. * wpa_config_remove_blob - Remove a named configuration blob
  1604. * @config: Configuration data from wpa_config_read()
  1605. * @name: Name of the blob to remove
  1606. * Returns: 0 if blob was removed or -1 if blob was not found
  1607. */
  1608. int wpa_config_remove_blob(struct wpa_config *config, const char *name)
  1609. {
  1610. struct wpa_config_blob *pos = config->blobs, *prev = NULL;
  1611. while (pos) {
  1612. if (os_strcmp(pos->name, name) == 0) {
  1613. if (prev)
  1614. prev->next = pos->next;
  1615. else
  1616. config->blobs = pos->next;
  1617. wpa_config_free_blob(pos);
  1618. return 0;
  1619. }
  1620. prev = pos;
  1621. pos = pos->next;
  1622. }
  1623. return -1;
  1624. }
  1625. #endif /* CONFIG_NO_CONFIG_BLOBS */
  1626. /**
  1627. * wpa_config_alloc_empty - Allocate an empty configuration
  1628. * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
  1629. * socket
  1630. * @driver_param: Driver parameters
  1631. * Returns: Pointer to allocated configuration data or %NULL on failure
  1632. */
  1633. struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
  1634. const char *driver_param)
  1635. {
  1636. struct wpa_config *config;
  1637. config = os_zalloc(sizeof(*config));
  1638. if (config == NULL)
  1639. return NULL;
  1640. config->eapol_version = DEFAULT_EAPOL_VERSION;
  1641. config->ap_scan = DEFAULT_AP_SCAN;
  1642. config->fast_reauth = DEFAULT_FAST_REAUTH;
  1643. if (ctrl_interface)
  1644. config->ctrl_interface = os_strdup(ctrl_interface);
  1645. if (driver_param)
  1646. config->driver_param = os_strdup(driver_param);
  1647. return config;
  1648. }
  1649. #ifndef CONFIG_NO_STDOUT_DEBUG
  1650. /**
  1651. * wpa_config_debug_dump_networks - Debug dump of configured networks
  1652. * @config: Configuration data from wpa_config_read()
  1653. */
  1654. void wpa_config_debug_dump_networks(struct wpa_config *config)
  1655. {
  1656. int prio;
  1657. struct wpa_ssid *ssid;
  1658. for (prio = 0; prio < config->num_prio; prio++) {
  1659. ssid = config->pssid[prio];
  1660. wpa_printf(MSG_DEBUG, "Priority group %d",
  1661. ssid->priority);
  1662. while (ssid) {
  1663. wpa_printf(MSG_DEBUG, " id=%d ssid='%s'",
  1664. ssid->id,
  1665. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  1666. ssid = ssid->pnext;
  1667. }
  1668. }
  1669. }
  1670. #endif /* CONFIG_NO_STDOUT_DEBUG */