config.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952
  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. { INT(wpa_ptk_rekey) }
  1159. };
  1160. #undef OFFSET
  1161. #undef _STR
  1162. #undef STR
  1163. #undef STR_KEY
  1164. #undef _STR_LEN
  1165. #undef STR_LEN
  1166. #undef STR_LEN_KEY
  1167. #undef _STR_RANGE
  1168. #undef STR_RANGE
  1169. #undef STR_RANGE_KEY
  1170. #undef _INT
  1171. #undef INT
  1172. #undef INT_RANGE
  1173. #undef _FUNC
  1174. #undef FUNC
  1175. #undef FUNC_KEY
  1176. #define NUM_SSID_FIELDS (sizeof(ssid_fields) / sizeof(ssid_fields[0]))
  1177. /**
  1178. * wpa_config_add_prio_network - Add a network to priority lists
  1179. * @config: Configuration data from wpa_config_read()
  1180. * @ssid: Pointer to the network configuration to be added to the list
  1181. * Returns: 0 on success, -1 on failure
  1182. *
  1183. * This function is used to add a network block to the priority list of
  1184. * networks. This must be called for each network when reading in the full
  1185. * configuration. In addition, this can be used indirectly when updating
  1186. * priorities by calling wpa_config_update_prio_list().
  1187. */
  1188. int wpa_config_add_prio_network(struct wpa_config *config,
  1189. struct wpa_ssid *ssid)
  1190. {
  1191. int prio;
  1192. struct wpa_ssid *prev, **nlist;
  1193. /*
  1194. * Add to an existing priority list if one is available for the
  1195. * configured priority level for this network.
  1196. */
  1197. for (prio = 0; prio < config->num_prio; prio++) {
  1198. prev = config->pssid[prio];
  1199. if (prev->priority == ssid->priority) {
  1200. while (prev->pnext)
  1201. prev = prev->pnext;
  1202. prev->pnext = ssid;
  1203. return 0;
  1204. }
  1205. }
  1206. /* First network for this priority - add a new priority list */
  1207. nlist = os_realloc(config->pssid,
  1208. (config->num_prio + 1) * sizeof(struct wpa_ssid *));
  1209. if (nlist == NULL)
  1210. return -1;
  1211. for (prio = 0; prio < config->num_prio; prio++) {
  1212. if (nlist[prio]->priority < ssid->priority)
  1213. break;
  1214. }
  1215. os_memmove(&nlist[prio + 1], &nlist[prio],
  1216. (config->num_prio - prio) * sizeof(struct wpa_ssid *));
  1217. nlist[prio] = ssid;
  1218. config->num_prio++;
  1219. config->pssid = nlist;
  1220. return 0;
  1221. }
  1222. /**
  1223. * wpa_config_update_prio_list - Update network priority list
  1224. * @config: Configuration data from wpa_config_read()
  1225. * Returns: 0 on success, -1 on failure
  1226. *
  1227. * This function is called to update the priority list of networks in the
  1228. * configuration when a network is being added or removed. This is also called
  1229. * if a priority for a network is changed.
  1230. */
  1231. static int wpa_config_update_prio_list(struct wpa_config *config)
  1232. {
  1233. struct wpa_ssid *ssid;
  1234. int ret = 0;
  1235. os_free(config->pssid);
  1236. config->pssid = NULL;
  1237. config->num_prio = 0;
  1238. ssid = config->ssid;
  1239. while (ssid) {
  1240. ssid->pnext = NULL;
  1241. if (wpa_config_add_prio_network(config, ssid) < 0)
  1242. ret = -1;
  1243. ssid = ssid->next;
  1244. }
  1245. return ret;
  1246. }
  1247. #ifdef IEEE8021X_EAPOL
  1248. static void eap_peer_config_free(struct eap_peer_config *eap)
  1249. {
  1250. os_free(eap->eap_methods);
  1251. os_free(eap->identity);
  1252. os_free(eap->anonymous_identity);
  1253. os_free(eap->password);
  1254. os_free(eap->ca_cert);
  1255. os_free(eap->ca_path);
  1256. os_free(eap->client_cert);
  1257. os_free(eap->private_key);
  1258. os_free(eap->private_key_passwd);
  1259. os_free(eap->dh_file);
  1260. os_free(eap->subject_match);
  1261. os_free(eap->altsubject_match);
  1262. os_free(eap->ca_cert2);
  1263. os_free(eap->ca_path2);
  1264. os_free(eap->client_cert2);
  1265. os_free(eap->private_key2);
  1266. os_free(eap->private_key2_passwd);
  1267. os_free(eap->dh_file2);
  1268. os_free(eap->subject_match2);
  1269. os_free(eap->altsubject_match2);
  1270. os_free(eap->phase1);
  1271. os_free(eap->phase2);
  1272. os_free(eap->pcsc);
  1273. os_free(eap->pin);
  1274. os_free(eap->engine_id);
  1275. os_free(eap->key_id);
  1276. os_free(eap->cert_id);
  1277. os_free(eap->ca_cert_id);
  1278. os_free(eap->key2_id);
  1279. os_free(eap->cert2_id);
  1280. os_free(eap->ca_cert2_id);
  1281. os_free(eap->otp);
  1282. os_free(eap->pending_req_otp);
  1283. os_free(eap->pac_file);
  1284. os_free(eap->new_password);
  1285. }
  1286. #endif /* IEEE8021X_EAPOL */
  1287. /**
  1288. * wpa_config_free_ssid - Free network/ssid configuration data
  1289. * @ssid: Configuration data for the network
  1290. *
  1291. * This function frees all resources allocated for the network configuration
  1292. * data.
  1293. */
  1294. void wpa_config_free_ssid(struct wpa_ssid *ssid)
  1295. {
  1296. os_free(ssid->ssid);
  1297. os_free(ssid->passphrase);
  1298. #ifdef IEEE8021X_EAPOL
  1299. eap_peer_config_free(&ssid->eap);
  1300. #endif /* IEEE8021X_EAPOL */
  1301. os_free(ssid->id_str);
  1302. os_free(ssid);
  1303. }
  1304. /**
  1305. * wpa_config_free - Free configuration data
  1306. * @config: Configuration data from wpa_config_read()
  1307. *
  1308. * This function frees all resources allocated for the configuration data by
  1309. * wpa_config_read().
  1310. */
  1311. void wpa_config_free(struct wpa_config *config)
  1312. {
  1313. #ifndef CONFIG_NO_CONFIG_BLOBS
  1314. struct wpa_config_blob *blob, *prevblob;
  1315. #endif /* CONFIG_NO_CONFIG_BLOBS */
  1316. struct wpa_ssid *ssid, *prev = NULL;
  1317. ssid = config->ssid;
  1318. while (ssid) {
  1319. prev = ssid;
  1320. ssid = ssid->next;
  1321. wpa_config_free_ssid(prev);
  1322. }
  1323. #ifndef CONFIG_NO_CONFIG_BLOBS
  1324. blob = config->blobs;
  1325. prevblob = NULL;
  1326. while (blob) {
  1327. prevblob = blob;
  1328. blob = blob->next;
  1329. wpa_config_free_blob(prevblob);
  1330. }
  1331. #endif /* CONFIG_NO_CONFIG_BLOBS */
  1332. os_free(config->ctrl_interface);
  1333. os_free(config->ctrl_interface_group);
  1334. #ifdef EAP_TLS_OPENSSL
  1335. os_free(config->opensc_engine_path);
  1336. os_free(config->pkcs11_engine_path);
  1337. os_free(config->pkcs11_module_path);
  1338. #endif /* EAP_TLS_OPENSSL */
  1339. os_free(config->driver_param);
  1340. os_free(config->pssid);
  1341. os_free(config);
  1342. }
  1343. /**
  1344. * wpa_config_get_network - Get configured network based on id
  1345. * @config: Configuration data from wpa_config_read()
  1346. * @id: Unique network id to search for
  1347. * Returns: Network configuration or %NULL if not found
  1348. */
  1349. struct wpa_ssid * wpa_config_get_network(struct wpa_config *config, int id)
  1350. {
  1351. struct wpa_ssid *ssid;
  1352. ssid = config->ssid;
  1353. while (ssid) {
  1354. if (id == ssid->id)
  1355. break;
  1356. ssid = ssid->next;
  1357. }
  1358. return ssid;
  1359. }
  1360. /**
  1361. * wpa_config_add_network - Add a new network with empty configuration
  1362. * @config: Configuration data from wpa_config_read()
  1363. * Returns: The new network configuration or %NULL if operation failed
  1364. */
  1365. struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)
  1366. {
  1367. int id;
  1368. struct wpa_ssid *ssid, *last = NULL;
  1369. id = -1;
  1370. ssid = config->ssid;
  1371. while (ssid) {
  1372. if (ssid->id > id)
  1373. id = ssid->id;
  1374. last = ssid;
  1375. ssid = ssid->next;
  1376. }
  1377. id++;
  1378. ssid = os_zalloc(sizeof(*ssid));
  1379. if (ssid == NULL)
  1380. return NULL;
  1381. ssid->id = id;
  1382. if (last)
  1383. last->next = ssid;
  1384. else
  1385. config->ssid = ssid;
  1386. wpa_config_update_prio_list(config);
  1387. return ssid;
  1388. }
  1389. /**
  1390. * wpa_config_remove_network - Remove a configured network based on id
  1391. * @config: Configuration data from wpa_config_read()
  1392. * @id: Unique network id to search for
  1393. * Returns: 0 on success, or -1 if the network was not found
  1394. */
  1395. int wpa_config_remove_network(struct wpa_config *config, int id)
  1396. {
  1397. struct wpa_ssid *ssid, *prev = NULL;
  1398. ssid = config->ssid;
  1399. while (ssid) {
  1400. if (id == ssid->id)
  1401. break;
  1402. prev = ssid;
  1403. ssid = ssid->next;
  1404. }
  1405. if (ssid == NULL)
  1406. return -1;
  1407. if (prev)
  1408. prev->next = ssid->next;
  1409. else
  1410. config->ssid = ssid->next;
  1411. wpa_config_update_prio_list(config);
  1412. wpa_config_free_ssid(ssid);
  1413. return 0;
  1414. }
  1415. /**
  1416. * wpa_config_set_network_defaults - Set network default values
  1417. * @ssid: Pointer to network configuration data
  1418. */
  1419. void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
  1420. {
  1421. ssid->proto = DEFAULT_PROTO;
  1422. ssid->pairwise_cipher = DEFAULT_PAIRWISE;
  1423. ssid->group_cipher = DEFAULT_GROUP;
  1424. ssid->key_mgmt = DEFAULT_KEY_MGMT;
  1425. #ifdef IEEE8021X_EAPOL
  1426. ssid->eapol_flags = DEFAULT_EAPOL_FLAGS;
  1427. ssid->eap_workaround = DEFAULT_EAP_WORKAROUND;
  1428. ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE;
  1429. #endif /* IEEE8021X_EAPOL */
  1430. }
  1431. /**
  1432. * wpa_config_set - Set a variable in network configuration
  1433. * @ssid: Pointer to network configuration data
  1434. * @var: Variable name, e.g., "ssid"
  1435. * @value: Variable value
  1436. * @line: Line number in configuration file or 0 if not used
  1437. * Returns: 0 on success, -1 on failure
  1438. *
  1439. * This function can be used to set network configuration variables based on
  1440. * both the configuration file and management interface input. The value
  1441. * parameter must be in the same format as the text-based configuration file is
  1442. * using. For example, strings are using double quotation marks.
  1443. */
  1444. int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
  1445. int line)
  1446. {
  1447. size_t i;
  1448. int ret = 0;
  1449. if (ssid == NULL || var == NULL || value == NULL)
  1450. return -1;
  1451. for (i = 0; i < NUM_SSID_FIELDS; i++) {
  1452. const struct parse_data *field = &ssid_fields[i];
  1453. if (os_strcmp(var, field->name) != 0)
  1454. continue;
  1455. if (field->parser(field, ssid, line, value)) {
  1456. if (line) {
  1457. wpa_printf(MSG_ERROR, "Line %d: failed to "
  1458. "parse %s '%s'.", line, var, value);
  1459. }
  1460. ret = -1;
  1461. }
  1462. break;
  1463. }
  1464. if (i == NUM_SSID_FIELDS) {
  1465. if (line) {
  1466. wpa_printf(MSG_ERROR, "Line %d: unknown network field "
  1467. "'%s'.", line, var);
  1468. }
  1469. ret = -1;
  1470. }
  1471. return ret;
  1472. }
  1473. #ifndef NO_CONFIG_WRITE
  1474. /**
  1475. * wpa_config_get - Get a variable in network configuration
  1476. * @ssid: Pointer to network configuration data
  1477. * @var: Variable name, e.g., "ssid"
  1478. * Returns: Value of the variable or %NULL on failure
  1479. *
  1480. * This function can be used to get network configuration variables. The
  1481. * returned value is a copy of the configuration variable in text format, i.e,.
  1482. * the same format that the text-based configuration file and wpa_config_set()
  1483. * are using for the value. The caller is responsible for freeing the returned
  1484. * value.
  1485. */
  1486. char * wpa_config_get(struct wpa_ssid *ssid, const char *var)
  1487. {
  1488. size_t i;
  1489. if (ssid == NULL || var == NULL)
  1490. return NULL;
  1491. for (i = 0; i < NUM_SSID_FIELDS; i++) {
  1492. const struct parse_data *field = &ssid_fields[i];
  1493. if (os_strcmp(var, field->name) == 0)
  1494. return field->writer(field, ssid);
  1495. }
  1496. return NULL;
  1497. }
  1498. /**
  1499. * wpa_config_get_no_key - Get a variable in network configuration (no keys)
  1500. * @ssid: Pointer to network configuration data
  1501. * @var: Variable name, e.g., "ssid"
  1502. * Returns: Value of the variable or %NULL on failure
  1503. *
  1504. * This function can be used to get network configuration variable like
  1505. * wpa_config_get(). The only difference is that this functions does not expose
  1506. * key/password material from the configuration. In case a key/password field
  1507. * is requested, the returned value is an empty string or %NULL if the variable
  1508. * is not set or "*" if the variable is set (regardless of its value). The
  1509. * returned value is a copy of the configuration variable in text format, i.e,.
  1510. * the same format that the text-based configuration file and wpa_config_set()
  1511. * are using for the value. The caller is responsible for freeing the returned
  1512. * value.
  1513. */
  1514. char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var)
  1515. {
  1516. size_t i;
  1517. if (ssid == NULL || var == NULL)
  1518. return NULL;
  1519. for (i = 0; i < NUM_SSID_FIELDS; i++) {
  1520. const struct parse_data *field = &ssid_fields[i];
  1521. if (os_strcmp(var, field->name) == 0) {
  1522. char *res = field->writer(field, ssid);
  1523. if (field->key_data) {
  1524. if (res && res[0]) {
  1525. wpa_printf(MSG_DEBUG, "Do not allow "
  1526. "key_data field to be "
  1527. "exposed");
  1528. os_free(res);
  1529. return os_strdup("*");
  1530. }
  1531. os_free(res);
  1532. return NULL;
  1533. }
  1534. return res;
  1535. }
  1536. }
  1537. return NULL;
  1538. }
  1539. #endif /* NO_CONFIG_WRITE */
  1540. /**
  1541. * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
  1542. * @ssid: Pointer to network configuration data
  1543. *
  1544. * This function must be called to update WPA PSK when either SSID or the
  1545. * passphrase has changed for the network configuration.
  1546. */
  1547. void wpa_config_update_psk(struct wpa_ssid *ssid)
  1548. {
  1549. #ifndef CONFIG_NO_PBKDF2
  1550. pbkdf2_sha1(ssid->passphrase,
  1551. (char *) ssid->ssid, ssid->ssid_len, 4096,
  1552. ssid->psk, PMK_LEN);
  1553. wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
  1554. ssid->psk, PMK_LEN);
  1555. ssid->psk_set = 1;
  1556. #endif /* CONFIG_NO_PBKDF2 */
  1557. }
  1558. #ifndef CONFIG_NO_CONFIG_BLOBS
  1559. /**
  1560. * wpa_config_get_blob - Get a named configuration blob
  1561. * @config: Configuration data from wpa_config_read()
  1562. * @name: Name of the blob
  1563. * Returns: Pointer to blob data or %NULL if not found
  1564. */
  1565. const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config,
  1566. const char *name)
  1567. {
  1568. struct wpa_config_blob *blob = config->blobs;
  1569. while (blob) {
  1570. if (os_strcmp(blob->name, name) == 0)
  1571. return blob;
  1572. blob = blob->next;
  1573. }
  1574. return NULL;
  1575. }
  1576. /**
  1577. * wpa_config_set_blob - Set or add a named configuration blob
  1578. * @config: Configuration data from wpa_config_read()
  1579. * @blob: New value for the blob
  1580. *
  1581. * Adds a new configuration blob or replaces the current value of an existing
  1582. * blob.
  1583. */
  1584. void wpa_config_set_blob(struct wpa_config *config,
  1585. struct wpa_config_blob *blob)
  1586. {
  1587. wpa_config_remove_blob(config, blob->name);
  1588. blob->next = config->blobs;
  1589. config->blobs = blob;
  1590. }
  1591. /**
  1592. * wpa_config_free_blob - Free blob data
  1593. * @blob: Pointer to blob to be freed
  1594. */
  1595. void wpa_config_free_blob(struct wpa_config_blob *blob)
  1596. {
  1597. if (blob) {
  1598. os_free(blob->name);
  1599. os_free(blob->data);
  1600. os_free(blob);
  1601. }
  1602. }
  1603. /**
  1604. * wpa_config_remove_blob - Remove a named configuration blob
  1605. * @config: Configuration data from wpa_config_read()
  1606. * @name: Name of the blob to remove
  1607. * Returns: 0 if blob was removed or -1 if blob was not found
  1608. */
  1609. int wpa_config_remove_blob(struct wpa_config *config, const char *name)
  1610. {
  1611. struct wpa_config_blob *pos = config->blobs, *prev = NULL;
  1612. while (pos) {
  1613. if (os_strcmp(pos->name, name) == 0) {
  1614. if (prev)
  1615. prev->next = pos->next;
  1616. else
  1617. config->blobs = pos->next;
  1618. wpa_config_free_blob(pos);
  1619. return 0;
  1620. }
  1621. prev = pos;
  1622. pos = pos->next;
  1623. }
  1624. return -1;
  1625. }
  1626. #endif /* CONFIG_NO_CONFIG_BLOBS */
  1627. /**
  1628. * wpa_config_alloc_empty - Allocate an empty configuration
  1629. * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
  1630. * socket
  1631. * @driver_param: Driver parameters
  1632. * Returns: Pointer to allocated configuration data or %NULL on failure
  1633. */
  1634. struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
  1635. const char *driver_param)
  1636. {
  1637. struct wpa_config *config;
  1638. config = os_zalloc(sizeof(*config));
  1639. if (config == NULL)
  1640. return NULL;
  1641. config->eapol_version = DEFAULT_EAPOL_VERSION;
  1642. config->ap_scan = DEFAULT_AP_SCAN;
  1643. config->fast_reauth = DEFAULT_FAST_REAUTH;
  1644. if (ctrl_interface)
  1645. config->ctrl_interface = os_strdup(ctrl_interface);
  1646. if (driver_param)
  1647. config->driver_param = os_strdup(driver_param);
  1648. return config;
  1649. }
  1650. #ifndef CONFIG_NO_STDOUT_DEBUG
  1651. /**
  1652. * wpa_config_debug_dump_networks - Debug dump of configured networks
  1653. * @config: Configuration data from wpa_config_read()
  1654. */
  1655. void wpa_config_debug_dump_networks(struct wpa_config *config)
  1656. {
  1657. int prio;
  1658. struct wpa_ssid *ssid;
  1659. for (prio = 0; prio < config->num_prio; prio++) {
  1660. ssid = config->pssid[prio];
  1661. wpa_printf(MSG_DEBUG, "Priority group %d",
  1662. ssid->priority);
  1663. while (ssid) {
  1664. wpa_printf(MSG_DEBUG, " id=%d ssid='%s'",
  1665. ssid->id,
  1666. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  1667. ssid = ssid->pnext;
  1668. }
  1669. }
  1670. }
  1671. #endif /* CONFIG_NO_STDOUT_DEBUG */