config.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961
  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. #ifdef CONFIG_WPS
  437. else if (os_strcmp(start, "WPS") == 0)
  438. val |= WPA_KEY_MGMT_WPS;
  439. #endif /* CONFIG_WPS */
  440. else {
  441. wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
  442. line, start);
  443. errors++;
  444. }
  445. if (last)
  446. break;
  447. start = end + 1;
  448. }
  449. os_free(buf);
  450. if (val == 0) {
  451. wpa_printf(MSG_ERROR,
  452. "Line %d: no key_mgmt values configured.", line);
  453. errors++;
  454. }
  455. wpa_printf(MSG_MSGDUMP, "key_mgmt: 0x%x", val);
  456. ssid->key_mgmt = val;
  457. return errors ? -1 : 0;
  458. }
  459. #ifndef NO_CONFIG_WRITE
  460. static char * wpa_config_write_key_mgmt(const struct parse_data *data,
  461. struct wpa_ssid *ssid)
  462. {
  463. char *buf, *pos, *end;
  464. int ret;
  465. pos = buf = os_zalloc(50);
  466. if (buf == NULL)
  467. return NULL;
  468. end = buf + 50;
  469. if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
  470. ret = os_snprintf(pos, end - pos, "%sWPA-PSK",
  471. pos == buf ? "" : " ");
  472. if (ret < 0 || ret >= end - pos) {
  473. end[-1] = '\0';
  474. return buf;
  475. }
  476. pos += ret;
  477. }
  478. if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
  479. ret = os_snprintf(pos, end - pos, "%sWPA-EAP",
  480. pos == buf ? "" : " ");
  481. if (ret < 0 || ret >= end - pos) {
  482. end[-1] = '\0';
  483. return buf;
  484. }
  485. pos += ret;
  486. }
  487. if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  488. ret = os_snprintf(pos, end - pos, "%sIEEE8021X",
  489. pos == buf ? "" : " ");
  490. if (ret < 0 || ret >= end - pos) {
  491. end[-1] = '\0';
  492. return buf;
  493. }
  494. pos += ret;
  495. }
  496. if (ssid->key_mgmt & WPA_KEY_MGMT_NONE) {
  497. ret = os_snprintf(pos, end - pos, "%sNONE",
  498. pos == buf ? "" : " ");
  499. if (ret < 0 || ret >= end - pos) {
  500. end[-1] = '\0';
  501. return buf;
  502. }
  503. pos += ret;
  504. }
  505. if (ssid->key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
  506. ret = os_snprintf(pos, end - pos, "%sWPA-NONE",
  507. pos == buf ? "" : " ");
  508. if (ret < 0 || ret >= end - pos) {
  509. end[-1] = '\0';
  510. return buf;
  511. }
  512. pos += ret;
  513. }
  514. #ifdef CONFIG_IEEE80211R
  515. if (ssid->key_mgmt & WPA_KEY_MGMT_FT_PSK)
  516. pos += os_snprintf(pos, end - pos, "%sFT-PSK",
  517. pos == buf ? "" : " ");
  518. if (ssid->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X)
  519. pos += os_snprintf(pos, end - pos, "%sFT-EAP",
  520. pos == buf ? "" : " ");
  521. #endif /* CONFIG_IEEE80211R */
  522. #ifdef CONFIG_IEEE80211W
  523. if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
  524. pos += os_snprintf(pos, end - pos, "%sWPA-PSK-SHA256",
  525. pos == buf ? "" : " ");
  526. if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
  527. pos += os_snprintf(pos, end - pos, "%sWPA-EAP-SHA256",
  528. pos == buf ? "" : " ");
  529. #endif /* CONFIG_IEEE80211W */
  530. return buf;
  531. }
  532. #endif /* NO_CONFIG_WRITE */
  533. static int wpa_config_parse_cipher(int line, const char *value)
  534. {
  535. int val = 0, last;
  536. char *start, *end, *buf;
  537. buf = os_strdup(value);
  538. if (buf == NULL)
  539. return -1;
  540. start = buf;
  541. while (*start != '\0') {
  542. while (*start == ' ' || *start == '\t')
  543. start++;
  544. if (*start == '\0')
  545. break;
  546. end = start;
  547. while (*end != ' ' && *end != '\t' && *end != '\0')
  548. end++;
  549. last = *end == '\0';
  550. *end = '\0';
  551. if (os_strcmp(start, "CCMP") == 0)
  552. val |= WPA_CIPHER_CCMP;
  553. else if (os_strcmp(start, "TKIP") == 0)
  554. val |= WPA_CIPHER_TKIP;
  555. else if (os_strcmp(start, "WEP104") == 0)
  556. val |= WPA_CIPHER_WEP104;
  557. else if (os_strcmp(start, "WEP40") == 0)
  558. val |= WPA_CIPHER_WEP40;
  559. else if (os_strcmp(start, "NONE") == 0)
  560. val |= WPA_CIPHER_NONE;
  561. else {
  562. wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
  563. line, start);
  564. os_free(buf);
  565. return -1;
  566. }
  567. if (last)
  568. break;
  569. start = end + 1;
  570. }
  571. os_free(buf);
  572. if (val == 0) {
  573. wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
  574. line);
  575. return -1;
  576. }
  577. return val;
  578. }
  579. #ifndef NO_CONFIG_WRITE
  580. static char * wpa_config_write_cipher(int cipher)
  581. {
  582. char *buf, *pos, *end;
  583. int ret;
  584. pos = buf = os_zalloc(50);
  585. if (buf == NULL)
  586. return NULL;
  587. end = buf + 50;
  588. if (cipher & WPA_CIPHER_CCMP) {
  589. ret = os_snprintf(pos, end - pos, "%sCCMP",
  590. pos == buf ? "" : " ");
  591. if (ret < 0 || ret >= end - pos) {
  592. end[-1] = '\0';
  593. return buf;
  594. }
  595. pos += ret;
  596. }
  597. if (cipher & WPA_CIPHER_TKIP) {
  598. ret = os_snprintf(pos, end - pos, "%sTKIP",
  599. pos == buf ? "" : " ");
  600. if (ret < 0 || ret >= end - pos) {
  601. end[-1] = '\0';
  602. return buf;
  603. }
  604. pos += ret;
  605. }
  606. if (cipher & WPA_CIPHER_WEP104) {
  607. ret = os_snprintf(pos, end - pos, "%sWEP104",
  608. pos == buf ? "" : " ");
  609. if (ret < 0 || ret >= end - pos) {
  610. end[-1] = '\0';
  611. return buf;
  612. }
  613. pos += ret;
  614. }
  615. if (cipher & WPA_CIPHER_WEP40) {
  616. ret = os_snprintf(pos, end - pos, "%sWEP40",
  617. pos == buf ? "" : " ");
  618. if (ret < 0 || ret >= end - pos) {
  619. end[-1] = '\0';
  620. return buf;
  621. }
  622. pos += ret;
  623. }
  624. if (cipher & WPA_CIPHER_NONE) {
  625. ret = os_snprintf(pos, end - pos, "%sNONE",
  626. pos == buf ? "" : " ");
  627. if (ret < 0 || ret >= end - pos) {
  628. end[-1] = '\0';
  629. return buf;
  630. }
  631. pos += ret;
  632. }
  633. return buf;
  634. }
  635. #endif /* NO_CONFIG_WRITE */
  636. static int wpa_config_parse_pairwise(const struct parse_data *data,
  637. struct wpa_ssid *ssid, int line,
  638. const char *value)
  639. {
  640. int val;
  641. val = wpa_config_parse_cipher(line, value);
  642. if (val == -1)
  643. return -1;
  644. if (val & ~(WPA_CIPHER_CCMP | WPA_CIPHER_TKIP | WPA_CIPHER_NONE)) {
  645. wpa_printf(MSG_ERROR, "Line %d: not allowed pairwise cipher "
  646. "(0x%x).", line, val);
  647. return -1;
  648. }
  649. wpa_printf(MSG_MSGDUMP, "pairwise: 0x%x", val);
  650. ssid->pairwise_cipher = val;
  651. return 0;
  652. }
  653. #ifndef NO_CONFIG_WRITE
  654. static char * wpa_config_write_pairwise(const struct parse_data *data,
  655. struct wpa_ssid *ssid)
  656. {
  657. return wpa_config_write_cipher(ssid->pairwise_cipher);
  658. }
  659. #endif /* NO_CONFIG_WRITE */
  660. static int wpa_config_parse_group(const struct parse_data *data,
  661. struct wpa_ssid *ssid, int line,
  662. const char *value)
  663. {
  664. int val;
  665. val = wpa_config_parse_cipher(line, value);
  666. if (val == -1)
  667. return -1;
  668. if (val & ~(WPA_CIPHER_CCMP | WPA_CIPHER_TKIP | WPA_CIPHER_WEP104 |
  669. WPA_CIPHER_WEP40)) {
  670. wpa_printf(MSG_ERROR, "Line %d: not allowed group cipher "
  671. "(0x%x).", line, val);
  672. return -1;
  673. }
  674. wpa_printf(MSG_MSGDUMP, "group: 0x%x", val);
  675. ssid->group_cipher = val;
  676. return 0;
  677. }
  678. #ifndef NO_CONFIG_WRITE
  679. static char * wpa_config_write_group(const struct parse_data *data,
  680. struct wpa_ssid *ssid)
  681. {
  682. return wpa_config_write_cipher(ssid->group_cipher);
  683. }
  684. #endif /* NO_CONFIG_WRITE */
  685. static int wpa_config_parse_auth_alg(const struct parse_data *data,
  686. struct wpa_ssid *ssid, int line,
  687. const char *value)
  688. {
  689. int val = 0, last, errors = 0;
  690. char *start, *end, *buf;
  691. buf = os_strdup(value);
  692. if (buf == NULL)
  693. return -1;
  694. start = buf;
  695. while (*start != '\0') {
  696. while (*start == ' ' || *start == '\t')
  697. start++;
  698. if (*start == '\0')
  699. break;
  700. end = start;
  701. while (*end != ' ' && *end != '\t' && *end != '\0')
  702. end++;
  703. last = *end == '\0';
  704. *end = '\0';
  705. if (os_strcmp(start, "OPEN") == 0)
  706. val |= WPA_AUTH_ALG_OPEN;
  707. else if (os_strcmp(start, "SHARED") == 0)
  708. val |= WPA_AUTH_ALG_SHARED;
  709. else if (os_strcmp(start, "LEAP") == 0)
  710. val |= WPA_AUTH_ALG_LEAP;
  711. else {
  712. wpa_printf(MSG_ERROR, "Line %d: invalid auth_alg '%s'",
  713. line, start);
  714. errors++;
  715. }
  716. if (last)
  717. break;
  718. start = end + 1;
  719. }
  720. os_free(buf);
  721. if (val == 0) {
  722. wpa_printf(MSG_ERROR,
  723. "Line %d: no auth_alg values configured.", line);
  724. errors++;
  725. }
  726. wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", val);
  727. ssid->auth_alg = val;
  728. return errors ? -1 : 0;
  729. }
  730. #ifndef NO_CONFIG_WRITE
  731. static char * wpa_config_write_auth_alg(const struct parse_data *data,
  732. struct wpa_ssid *ssid)
  733. {
  734. char *buf, *pos, *end;
  735. int ret;
  736. pos = buf = os_zalloc(30);
  737. if (buf == NULL)
  738. return NULL;
  739. end = buf + 30;
  740. if (ssid->auth_alg & WPA_AUTH_ALG_OPEN) {
  741. ret = os_snprintf(pos, end - pos, "%sOPEN",
  742. pos == buf ? "" : " ");
  743. if (ret < 0 || ret >= end - pos) {
  744. end[-1] = '\0';
  745. return buf;
  746. }
  747. pos += ret;
  748. }
  749. if (ssid->auth_alg & WPA_AUTH_ALG_SHARED) {
  750. ret = os_snprintf(pos, end - pos, "%sSHARED",
  751. pos == buf ? "" : " ");
  752. if (ret < 0 || ret >= end - pos) {
  753. end[-1] = '\0';
  754. return buf;
  755. }
  756. pos += ret;
  757. }
  758. if (ssid->auth_alg & WPA_AUTH_ALG_LEAP) {
  759. ret = os_snprintf(pos, end - pos, "%sLEAP",
  760. pos == buf ? "" : " ");
  761. if (ret < 0 || ret >= end - pos) {
  762. end[-1] = '\0';
  763. return buf;
  764. }
  765. pos += ret;
  766. }
  767. return buf;
  768. }
  769. #endif /* NO_CONFIG_WRITE */
  770. #ifdef IEEE8021X_EAPOL
  771. static int wpa_config_parse_eap(const struct parse_data *data,
  772. struct wpa_ssid *ssid, int line,
  773. const char *value)
  774. {
  775. int last, errors = 0;
  776. char *start, *end, *buf;
  777. struct eap_method_type *methods = NULL, *tmp;
  778. size_t num_methods = 0;
  779. buf = os_strdup(value);
  780. if (buf == NULL)
  781. return -1;
  782. start = buf;
  783. while (*start != '\0') {
  784. while (*start == ' ' || *start == '\t')
  785. start++;
  786. if (*start == '\0')
  787. break;
  788. end = start;
  789. while (*end != ' ' && *end != '\t' && *end != '\0')
  790. end++;
  791. last = *end == '\0';
  792. *end = '\0';
  793. tmp = methods;
  794. methods = os_realloc(methods,
  795. (num_methods + 1) * sizeof(*methods));
  796. if (methods == NULL) {
  797. os_free(tmp);
  798. os_free(buf);
  799. return -1;
  800. }
  801. methods[num_methods].method = eap_peer_get_type(
  802. start, &methods[num_methods].vendor);
  803. if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
  804. methods[num_methods].method == EAP_TYPE_NONE) {
  805. wpa_printf(MSG_ERROR, "Line %d: unknown EAP method "
  806. "'%s'", line, start);
  807. wpa_printf(MSG_ERROR, "You may need to add support for"
  808. " this EAP method during wpa_supplicant\n"
  809. "build time configuration.\n"
  810. "See README for more information.");
  811. errors++;
  812. } else if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
  813. methods[num_methods].method == EAP_TYPE_LEAP)
  814. ssid->leap++;
  815. else
  816. ssid->non_leap++;
  817. num_methods++;
  818. if (last)
  819. break;
  820. start = end + 1;
  821. }
  822. os_free(buf);
  823. tmp = methods;
  824. methods = os_realloc(methods, (num_methods + 1) * sizeof(*methods));
  825. if (methods == NULL) {
  826. os_free(tmp);
  827. return -1;
  828. }
  829. methods[num_methods].vendor = EAP_VENDOR_IETF;
  830. methods[num_methods].method = EAP_TYPE_NONE;
  831. num_methods++;
  832. wpa_hexdump(MSG_MSGDUMP, "eap methods",
  833. (u8 *) methods, num_methods * sizeof(*methods));
  834. ssid->eap.eap_methods = methods;
  835. return errors ? -1 : 0;
  836. }
  837. static char * wpa_config_write_eap(const struct parse_data *data,
  838. struct wpa_ssid *ssid)
  839. {
  840. int i, ret;
  841. char *buf, *pos, *end;
  842. const struct eap_method_type *eap_methods = ssid->eap.eap_methods;
  843. const char *name;
  844. if (eap_methods == NULL)
  845. return NULL;
  846. pos = buf = os_zalloc(100);
  847. if (buf == NULL)
  848. return NULL;
  849. end = buf + 100;
  850. for (i = 0; eap_methods[i].vendor != EAP_VENDOR_IETF ||
  851. eap_methods[i].method != EAP_TYPE_NONE; i++) {
  852. name = eap_get_name(eap_methods[i].vendor,
  853. eap_methods[i].method);
  854. if (name) {
  855. ret = os_snprintf(pos, end - pos, "%s%s",
  856. pos == buf ? "" : " ", name);
  857. if (ret < 0 || ret >= end - pos)
  858. break;
  859. pos += ret;
  860. }
  861. }
  862. end[-1] = '\0';
  863. return buf;
  864. }
  865. static int wpa_config_parse_password(const struct parse_data *data,
  866. struct wpa_ssid *ssid, int line,
  867. const char *value)
  868. {
  869. u8 *hash;
  870. if (os_strcmp(value, "NULL") == 0) {
  871. wpa_printf(MSG_DEBUG, "Unset configuration string 'password'");
  872. os_free(ssid->eap.password);
  873. ssid->eap.password = NULL;
  874. ssid->eap.password_len = 0;
  875. return 0;
  876. }
  877. if (os_strncmp(value, "hash:", 5) != 0) {
  878. char *tmp;
  879. size_t res_len;
  880. tmp = wpa_config_parse_string(value, &res_len);
  881. if (tmp == NULL) {
  882. wpa_printf(MSG_ERROR, "Line %d: failed to parse "
  883. "password.", line);
  884. return -1;
  885. }
  886. wpa_hexdump_ascii(MSG_MSGDUMP, data->name,
  887. (u8 *) tmp, res_len);
  888. os_free(ssid->eap.password);
  889. ssid->eap.password = (u8 *) tmp;
  890. ssid->eap.password_len = res_len;
  891. ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
  892. return 0;
  893. }
  894. /* NtPasswordHash: hash:<32 hex digits> */
  895. if (os_strlen(value + 5) != 2 * 16) {
  896. wpa_printf(MSG_ERROR, "Line %d: Invalid password hash length "
  897. "(expected 32 hex digits)", line);
  898. return -1;
  899. }
  900. hash = os_malloc(16);
  901. if (hash == NULL)
  902. return -1;
  903. if (hexstr2bin(value + 5, hash, 16)) {
  904. os_free(hash);
  905. wpa_printf(MSG_ERROR, "Line %d: Invalid password hash", line);
  906. return -1;
  907. }
  908. wpa_hexdump_key(MSG_MSGDUMP, data->name, hash, 16);
  909. os_free(ssid->eap.password);
  910. ssid->eap.password = hash;
  911. ssid->eap.password_len = 16;
  912. ssid->eap.flags |= EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
  913. return 0;
  914. }
  915. static char * wpa_config_write_password(const struct parse_data *data,
  916. struct wpa_ssid *ssid)
  917. {
  918. char *buf;
  919. if (ssid->eap.password == NULL)
  920. return NULL;
  921. if (!(ssid->eap.flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH)) {
  922. return wpa_config_write_string(
  923. ssid->eap.password, ssid->eap.password_len);
  924. }
  925. buf = os_malloc(5 + 32 + 1);
  926. if (buf == NULL)
  927. return NULL;
  928. os_memcpy(buf, "hash:", 5);
  929. wpa_snprintf_hex(buf + 5, 32 + 1, ssid->eap.password, 16);
  930. return buf;
  931. }
  932. #endif /* IEEE8021X_EAPOL */
  933. static int wpa_config_parse_wep_key(u8 *key, size_t *len, int line,
  934. const char *value, int idx)
  935. {
  936. char *buf, title[20];
  937. int res;
  938. buf = wpa_config_parse_string(value, len);
  939. if (buf == NULL) {
  940. wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key %d '%s'.",
  941. line, idx, value);
  942. return -1;
  943. }
  944. if (*len > MAX_WEP_KEY_LEN) {
  945. wpa_printf(MSG_ERROR, "Line %d: Too long WEP key %d '%s'.",
  946. line, idx, value);
  947. os_free(buf);
  948. return -1;
  949. }
  950. os_memcpy(key, buf, *len);
  951. os_free(buf);
  952. res = os_snprintf(title, sizeof(title), "wep_key%d", idx);
  953. if (res >= 0 && (size_t) res < sizeof(title))
  954. wpa_hexdump_key(MSG_MSGDUMP, title, key, *len);
  955. return 0;
  956. }
  957. static int wpa_config_parse_wep_key0(const struct parse_data *data,
  958. struct wpa_ssid *ssid, int line,
  959. const char *value)
  960. {
  961. return wpa_config_parse_wep_key(ssid->wep_key[0],
  962. &ssid->wep_key_len[0], line,
  963. value, 0);
  964. }
  965. static int wpa_config_parse_wep_key1(const struct parse_data *data,
  966. struct wpa_ssid *ssid, int line,
  967. const char *value)
  968. {
  969. return wpa_config_parse_wep_key(ssid->wep_key[1],
  970. &ssid->wep_key_len[1], line,
  971. value, 1);
  972. }
  973. static int wpa_config_parse_wep_key2(const struct parse_data *data,
  974. struct wpa_ssid *ssid, int line,
  975. const char *value)
  976. {
  977. return wpa_config_parse_wep_key(ssid->wep_key[2],
  978. &ssid->wep_key_len[2], line,
  979. value, 2);
  980. }
  981. static int wpa_config_parse_wep_key3(const struct parse_data *data,
  982. struct wpa_ssid *ssid, int line,
  983. const char *value)
  984. {
  985. return wpa_config_parse_wep_key(ssid->wep_key[3],
  986. &ssid->wep_key_len[3], line,
  987. value, 3);
  988. }
  989. #ifndef NO_CONFIG_WRITE
  990. static char * wpa_config_write_wep_key(struct wpa_ssid *ssid, int idx)
  991. {
  992. if (ssid->wep_key_len[idx] == 0)
  993. return NULL;
  994. return wpa_config_write_string(ssid->wep_key[idx],
  995. ssid->wep_key_len[idx]);
  996. }
  997. static char * wpa_config_write_wep_key0(const struct parse_data *data,
  998. struct wpa_ssid *ssid)
  999. {
  1000. return wpa_config_write_wep_key(ssid, 0);
  1001. }
  1002. static char * wpa_config_write_wep_key1(const struct parse_data *data,
  1003. struct wpa_ssid *ssid)
  1004. {
  1005. return wpa_config_write_wep_key(ssid, 1);
  1006. }
  1007. static char * wpa_config_write_wep_key2(const struct parse_data *data,
  1008. struct wpa_ssid *ssid)
  1009. {
  1010. return wpa_config_write_wep_key(ssid, 2);
  1011. }
  1012. static char * wpa_config_write_wep_key3(const struct parse_data *data,
  1013. struct wpa_ssid *ssid)
  1014. {
  1015. return wpa_config_write_wep_key(ssid, 3);
  1016. }
  1017. #endif /* NO_CONFIG_WRITE */
  1018. /* Helper macros for network block parser */
  1019. #ifdef OFFSET
  1020. #undef OFFSET
  1021. #endif /* OFFSET */
  1022. /* OFFSET: Get offset of a variable within the wpa_ssid structure */
  1023. #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
  1024. /* STR: Define a string variable for an ASCII string; f = field name */
  1025. #ifdef NO_CONFIG_WRITE
  1026. #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
  1027. #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
  1028. #else /* NO_CONFIG_WRITE */
  1029. #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
  1030. #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
  1031. #endif /* NO_CONFIG_WRITE */
  1032. #define STR(f) _STR(f), NULL, NULL, NULL, 0
  1033. #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
  1034. #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
  1035. #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
  1036. /* STR_LEN: Define a string variable with a separate variable for storing the
  1037. * data length. Unlike STR(), this can be used to store arbitrary binary data
  1038. * (i.e., even nul termination character). */
  1039. #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
  1040. #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
  1041. #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
  1042. #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
  1043. #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
  1044. /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
  1045. * explicitly specified. */
  1046. #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
  1047. #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
  1048. #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
  1049. #ifdef NO_CONFIG_WRITE
  1050. #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
  1051. #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
  1052. #else /* NO_CONFIG_WRITE */
  1053. #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
  1054. OFFSET(f), (void *) 0
  1055. #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
  1056. OFFSET(eap.f), (void *) 0
  1057. #endif /* NO_CONFIG_WRITE */
  1058. /* INT: Define an integer variable */
  1059. #define INT(f) _INT(f), NULL, NULL, 0
  1060. #define INTe(f) _INTe(f), NULL, NULL, 0
  1061. /* INT_RANGE: Define an integer variable with allowed value range */
  1062. #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
  1063. /* FUNC: Define a configuration variable that uses a custom function for
  1064. * parsing and writing the value. */
  1065. #ifdef NO_CONFIG_WRITE
  1066. #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
  1067. #else /* NO_CONFIG_WRITE */
  1068. #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
  1069. NULL, NULL, NULL, NULL
  1070. #endif /* NO_CONFIG_WRITE */
  1071. #define FUNC(f) _FUNC(f), 0
  1072. #define FUNC_KEY(f) _FUNC(f), 1
  1073. /*
  1074. * Table of network configuration variables. This table is used to parse each
  1075. * network configuration variable, e.g., each line in wpa_supplicant.conf file
  1076. * that is inside a network block.
  1077. *
  1078. * This table is generated using the helper macros defined above and with
  1079. * generous help from the C pre-processor. The field name is stored as a string
  1080. * into .name and for STR and INT types, the offset of the target buffer within
  1081. * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
  1082. * offset to the field containing the length of the configuration variable.
  1083. * .param3 and .param4 can be used to mark the allowed range (length for STR
  1084. * and value for INT).
  1085. *
  1086. * For each configuration line in wpa_supplicant.conf, the parser goes through
  1087. * this table and select the entry that matches with the field name. The parser
  1088. * function (.parser) is then called to parse the actual value of the field.
  1089. *
  1090. * This kind of mechanism makes it easy to add new configuration parameters,
  1091. * since only one line needs to be added into this table and into the
  1092. * struct wpa_ssid definition if the new variable is either a string or
  1093. * integer. More complex types will need to use their own parser and writer
  1094. * functions.
  1095. */
  1096. static const struct parse_data ssid_fields[] = {
  1097. { STR_RANGE(ssid, 0, MAX_SSID_LEN) },
  1098. { INT_RANGE(scan_ssid, 0, 1) },
  1099. { FUNC(bssid) },
  1100. { FUNC_KEY(psk) },
  1101. { FUNC(proto) },
  1102. { FUNC(key_mgmt) },
  1103. { FUNC(pairwise) },
  1104. { FUNC(group) },
  1105. { FUNC(auth_alg) },
  1106. #ifdef IEEE8021X_EAPOL
  1107. { FUNC(eap) },
  1108. { STR_LENe(identity) },
  1109. { STR_LENe(anonymous_identity) },
  1110. { FUNC(password) },
  1111. { STRe(ca_cert) },
  1112. { STRe(ca_path) },
  1113. { STRe(client_cert) },
  1114. { STRe(private_key) },
  1115. { STR_KEYe(private_key_passwd) },
  1116. { STRe(dh_file) },
  1117. { STRe(subject_match) },
  1118. { STRe(altsubject_match) },
  1119. { STRe(ca_cert2) },
  1120. { STRe(ca_path2) },
  1121. { STRe(client_cert2) },
  1122. { STRe(private_key2) },
  1123. { STR_KEYe(private_key2_passwd) },
  1124. { STRe(dh_file2) },
  1125. { STRe(subject_match2) },
  1126. { STRe(altsubject_match2) },
  1127. { STRe(phase1) },
  1128. { STRe(phase2) },
  1129. { STRe(pcsc) },
  1130. { STR_KEYe(pin) },
  1131. { STRe(engine_id) },
  1132. { STRe(key_id) },
  1133. { STRe(cert_id) },
  1134. { STRe(ca_cert_id) },
  1135. { STR_KEYe(pin2) },
  1136. { STRe(engine2_id) },
  1137. { STRe(key2_id) },
  1138. { STRe(cert2_id) },
  1139. { STRe(ca_cert2_id) },
  1140. { INTe(engine) },
  1141. { INTe(engine2) },
  1142. { INT(eapol_flags) },
  1143. #endif /* IEEE8021X_EAPOL */
  1144. { FUNC_KEY(wep_key0) },
  1145. { FUNC_KEY(wep_key1) },
  1146. { FUNC_KEY(wep_key2) },
  1147. { FUNC_KEY(wep_key3) },
  1148. { INT(wep_tx_keyidx) },
  1149. { INT(priority) },
  1150. #ifdef IEEE8021X_EAPOL
  1151. { INT(eap_workaround) },
  1152. { STRe(pac_file) },
  1153. { INTe(fragment_size) },
  1154. #endif /* IEEE8021X_EAPOL */
  1155. { INT_RANGE(mode, 0, 1) },
  1156. { INT_RANGE(proactive_key_caching, 0, 1) },
  1157. { INT_RANGE(disabled, 0, 1) },
  1158. { STR(id_str) },
  1159. #ifdef CONFIG_IEEE80211W
  1160. { INT_RANGE(ieee80211w, 0, 2) },
  1161. #endif /* CONFIG_IEEE80211W */
  1162. { INT_RANGE(peerkey, 0, 1) },
  1163. { INT_RANGE(mixed_cell, 0, 1) },
  1164. { INT_RANGE(frequency, 0, 10000) },
  1165. { INT(wpa_ptk_rekey) }
  1166. };
  1167. #undef OFFSET
  1168. #undef _STR
  1169. #undef STR
  1170. #undef STR_KEY
  1171. #undef _STR_LEN
  1172. #undef STR_LEN
  1173. #undef STR_LEN_KEY
  1174. #undef _STR_RANGE
  1175. #undef STR_RANGE
  1176. #undef STR_RANGE_KEY
  1177. #undef _INT
  1178. #undef INT
  1179. #undef INT_RANGE
  1180. #undef _FUNC
  1181. #undef FUNC
  1182. #undef FUNC_KEY
  1183. #define NUM_SSID_FIELDS (sizeof(ssid_fields) / sizeof(ssid_fields[0]))
  1184. /**
  1185. * wpa_config_add_prio_network - Add a network to priority lists
  1186. * @config: Configuration data from wpa_config_read()
  1187. * @ssid: Pointer to the network configuration to be added to the list
  1188. * Returns: 0 on success, -1 on failure
  1189. *
  1190. * This function is used to add a network block to the priority list of
  1191. * networks. This must be called for each network when reading in the full
  1192. * configuration. In addition, this can be used indirectly when updating
  1193. * priorities by calling wpa_config_update_prio_list().
  1194. */
  1195. int wpa_config_add_prio_network(struct wpa_config *config,
  1196. struct wpa_ssid *ssid)
  1197. {
  1198. int prio;
  1199. struct wpa_ssid *prev, **nlist;
  1200. /*
  1201. * Add to an existing priority list if one is available for the
  1202. * configured priority level for this network.
  1203. */
  1204. for (prio = 0; prio < config->num_prio; prio++) {
  1205. prev = config->pssid[prio];
  1206. if (prev->priority == ssid->priority) {
  1207. while (prev->pnext)
  1208. prev = prev->pnext;
  1209. prev->pnext = ssid;
  1210. return 0;
  1211. }
  1212. }
  1213. /* First network for this priority - add a new priority list */
  1214. nlist = os_realloc(config->pssid,
  1215. (config->num_prio + 1) * sizeof(struct wpa_ssid *));
  1216. if (nlist == NULL)
  1217. return -1;
  1218. for (prio = 0; prio < config->num_prio; prio++) {
  1219. if (nlist[prio]->priority < ssid->priority)
  1220. break;
  1221. }
  1222. os_memmove(&nlist[prio + 1], &nlist[prio],
  1223. (config->num_prio - prio) * sizeof(struct wpa_ssid *));
  1224. nlist[prio] = ssid;
  1225. config->num_prio++;
  1226. config->pssid = nlist;
  1227. return 0;
  1228. }
  1229. /**
  1230. * wpa_config_update_prio_list - Update network priority list
  1231. * @config: Configuration data from wpa_config_read()
  1232. * Returns: 0 on success, -1 on failure
  1233. *
  1234. * This function is called to update the priority list of networks in the
  1235. * configuration when a network is being added or removed. This is also called
  1236. * if a priority for a network is changed.
  1237. */
  1238. static int wpa_config_update_prio_list(struct wpa_config *config)
  1239. {
  1240. struct wpa_ssid *ssid;
  1241. int ret = 0;
  1242. os_free(config->pssid);
  1243. config->pssid = NULL;
  1244. config->num_prio = 0;
  1245. ssid = config->ssid;
  1246. while (ssid) {
  1247. ssid->pnext = NULL;
  1248. if (wpa_config_add_prio_network(config, ssid) < 0)
  1249. ret = -1;
  1250. ssid = ssid->next;
  1251. }
  1252. return ret;
  1253. }
  1254. #ifdef IEEE8021X_EAPOL
  1255. static void eap_peer_config_free(struct eap_peer_config *eap)
  1256. {
  1257. os_free(eap->eap_methods);
  1258. os_free(eap->identity);
  1259. os_free(eap->anonymous_identity);
  1260. os_free(eap->password);
  1261. os_free(eap->ca_cert);
  1262. os_free(eap->ca_path);
  1263. os_free(eap->client_cert);
  1264. os_free(eap->private_key);
  1265. os_free(eap->private_key_passwd);
  1266. os_free(eap->dh_file);
  1267. os_free(eap->subject_match);
  1268. os_free(eap->altsubject_match);
  1269. os_free(eap->ca_cert2);
  1270. os_free(eap->ca_path2);
  1271. os_free(eap->client_cert2);
  1272. os_free(eap->private_key2);
  1273. os_free(eap->private_key2_passwd);
  1274. os_free(eap->dh_file2);
  1275. os_free(eap->subject_match2);
  1276. os_free(eap->altsubject_match2);
  1277. os_free(eap->phase1);
  1278. os_free(eap->phase2);
  1279. os_free(eap->pcsc);
  1280. os_free(eap->pin);
  1281. os_free(eap->engine_id);
  1282. os_free(eap->key_id);
  1283. os_free(eap->cert_id);
  1284. os_free(eap->ca_cert_id);
  1285. os_free(eap->key2_id);
  1286. os_free(eap->cert2_id);
  1287. os_free(eap->ca_cert2_id);
  1288. os_free(eap->pin2);
  1289. os_free(eap->engine2_id);
  1290. os_free(eap->otp);
  1291. os_free(eap->pending_req_otp);
  1292. os_free(eap->pac_file);
  1293. os_free(eap->new_password);
  1294. }
  1295. #endif /* IEEE8021X_EAPOL */
  1296. /**
  1297. * wpa_config_free_ssid - Free network/ssid configuration data
  1298. * @ssid: Configuration data for the network
  1299. *
  1300. * This function frees all resources allocated for the network configuration
  1301. * data.
  1302. */
  1303. void wpa_config_free_ssid(struct wpa_ssid *ssid)
  1304. {
  1305. os_free(ssid->ssid);
  1306. os_free(ssid->passphrase);
  1307. #ifdef IEEE8021X_EAPOL
  1308. eap_peer_config_free(&ssid->eap);
  1309. #endif /* IEEE8021X_EAPOL */
  1310. os_free(ssid->id_str);
  1311. os_free(ssid);
  1312. }
  1313. /**
  1314. * wpa_config_free - Free configuration data
  1315. * @config: Configuration data from wpa_config_read()
  1316. *
  1317. * This function frees all resources allocated for the configuration data by
  1318. * wpa_config_read().
  1319. */
  1320. void wpa_config_free(struct wpa_config *config)
  1321. {
  1322. #ifndef CONFIG_NO_CONFIG_BLOBS
  1323. struct wpa_config_blob *blob, *prevblob;
  1324. #endif /* CONFIG_NO_CONFIG_BLOBS */
  1325. struct wpa_ssid *ssid, *prev = NULL;
  1326. ssid = config->ssid;
  1327. while (ssid) {
  1328. prev = ssid;
  1329. ssid = ssid->next;
  1330. wpa_config_free_ssid(prev);
  1331. }
  1332. #ifndef CONFIG_NO_CONFIG_BLOBS
  1333. blob = config->blobs;
  1334. prevblob = NULL;
  1335. while (blob) {
  1336. prevblob = blob;
  1337. blob = blob->next;
  1338. wpa_config_free_blob(prevblob);
  1339. }
  1340. #endif /* CONFIG_NO_CONFIG_BLOBS */
  1341. os_free(config->ctrl_interface);
  1342. os_free(config->ctrl_interface_group);
  1343. #ifdef EAP_TLS_OPENSSL
  1344. os_free(config->opensc_engine_path);
  1345. os_free(config->pkcs11_engine_path);
  1346. os_free(config->pkcs11_module_path);
  1347. #endif /* EAP_TLS_OPENSSL */
  1348. os_free(config->driver_param);
  1349. os_free(config->pssid);
  1350. os_free(config);
  1351. }
  1352. /**
  1353. * wpa_config_get_network - Get configured network based on id
  1354. * @config: Configuration data from wpa_config_read()
  1355. * @id: Unique network id to search for
  1356. * Returns: Network configuration or %NULL if not found
  1357. */
  1358. struct wpa_ssid * wpa_config_get_network(struct wpa_config *config, int id)
  1359. {
  1360. struct wpa_ssid *ssid;
  1361. ssid = config->ssid;
  1362. while (ssid) {
  1363. if (id == ssid->id)
  1364. break;
  1365. ssid = ssid->next;
  1366. }
  1367. return ssid;
  1368. }
  1369. /**
  1370. * wpa_config_add_network - Add a new network with empty configuration
  1371. * @config: Configuration data from wpa_config_read()
  1372. * Returns: The new network configuration or %NULL if operation failed
  1373. */
  1374. struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)
  1375. {
  1376. int id;
  1377. struct wpa_ssid *ssid, *last = NULL;
  1378. id = -1;
  1379. ssid = config->ssid;
  1380. while (ssid) {
  1381. if (ssid->id > id)
  1382. id = ssid->id;
  1383. last = ssid;
  1384. ssid = ssid->next;
  1385. }
  1386. id++;
  1387. ssid = os_zalloc(sizeof(*ssid));
  1388. if (ssid == NULL)
  1389. return NULL;
  1390. ssid->id = id;
  1391. if (last)
  1392. last->next = ssid;
  1393. else
  1394. config->ssid = ssid;
  1395. wpa_config_update_prio_list(config);
  1396. return ssid;
  1397. }
  1398. /**
  1399. * wpa_config_remove_network - Remove a configured network based on id
  1400. * @config: Configuration data from wpa_config_read()
  1401. * @id: Unique network id to search for
  1402. * Returns: 0 on success, or -1 if the network was not found
  1403. */
  1404. int wpa_config_remove_network(struct wpa_config *config, int id)
  1405. {
  1406. struct wpa_ssid *ssid, *prev = NULL;
  1407. ssid = config->ssid;
  1408. while (ssid) {
  1409. if (id == ssid->id)
  1410. break;
  1411. prev = ssid;
  1412. ssid = ssid->next;
  1413. }
  1414. if (ssid == NULL)
  1415. return -1;
  1416. if (prev)
  1417. prev->next = ssid->next;
  1418. else
  1419. config->ssid = ssid->next;
  1420. wpa_config_update_prio_list(config);
  1421. wpa_config_free_ssid(ssid);
  1422. return 0;
  1423. }
  1424. /**
  1425. * wpa_config_set_network_defaults - Set network default values
  1426. * @ssid: Pointer to network configuration data
  1427. */
  1428. void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
  1429. {
  1430. ssid->proto = DEFAULT_PROTO;
  1431. ssid->pairwise_cipher = DEFAULT_PAIRWISE;
  1432. ssid->group_cipher = DEFAULT_GROUP;
  1433. ssid->key_mgmt = DEFAULT_KEY_MGMT;
  1434. #ifdef IEEE8021X_EAPOL
  1435. ssid->eapol_flags = DEFAULT_EAPOL_FLAGS;
  1436. ssid->eap_workaround = DEFAULT_EAP_WORKAROUND;
  1437. ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE;
  1438. #endif /* IEEE8021X_EAPOL */
  1439. }
  1440. /**
  1441. * wpa_config_set - Set a variable in network configuration
  1442. * @ssid: Pointer to network configuration data
  1443. * @var: Variable name, e.g., "ssid"
  1444. * @value: Variable value
  1445. * @line: Line number in configuration file or 0 if not used
  1446. * Returns: 0 on success, -1 on failure
  1447. *
  1448. * This function can be used to set network configuration variables based on
  1449. * both the configuration file and management interface input. The value
  1450. * parameter must be in the same format as the text-based configuration file is
  1451. * using. For example, strings are using double quotation marks.
  1452. */
  1453. int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
  1454. int line)
  1455. {
  1456. size_t i;
  1457. int ret = 0;
  1458. if (ssid == NULL || var == NULL || value == NULL)
  1459. return -1;
  1460. for (i = 0; i < NUM_SSID_FIELDS; i++) {
  1461. const struct parse_data *field = &ssid_fields[i];
  1462. if (os_strcmp(var, field->name) != 0)
  1463. continue;
  1464. if (field->parser(field, ssid, line, value)) {
  1465. if (line) {
  1466. wpa_printf(MSG_ERROR, "Line %d: failed to "
  1467. "parse %s '%s'.", line, var, value);
  1468. }
  1469. ret = -1;
  1470. }
  1471. break;
  1472. }
  1473. if (i == NUM_SSID_FIELDS) {
  1474. if (line) {
  1475. wpa_printf(MSG_ERROR, "Line %d: unknown network field "
  1476. "'%s'.", line, var);
  1477. }
  1478. ret = -1;
  1479. }
  1480. return ret;
  1481. }
  1482. #ifndef NO_CONFIG_WRITE
  1483. /**
  1484. * wpa_config_get - Get a variable in network configuration
  1485. * @ssid: Pointer to network configuration data
  1486. * @var: Variable name, e.g., "ssid"
  1487. * Returns: Value of the variable or %NULL on failure
  1488. *
  1489. * This function can be used to get network configuration variables. The
  1490. * returned value is a copy of the configuration variable in text format, i.e,.
  1491. * the same format that the text-based configuration file and wpa_config_set()
  1492. * are using for the value. The caller is responsible for freeing the returned
  1493. * value.
  1494. */
  1495. char * wpa_config_get(struct wpa_ssid *ssid, const char *var)
  1496. {
  1497. size_t i;
  1498. if (ssid == NULL || var == NULL)
  1499. return NULL;
  1500. for (i = 0; i < NUM_SSID_FIELDS; i++) {
  1501. const struct parse_data *field = &ssid_fields[i];
  1502. if (os_strcmp(var, field->name) == 0)
  1503. return field->writer(field, ssid);
  1504. }
  1505. return NULL;
  1506. }
  1507. /**
  1508. * wpa_config_get_no_key - Get a variable in network configuration (no keys)
  1509. * @ssid: Pointer to network configuration data
  1510. * @var: Variable name, e.g., "ssid"
  1511. * Returns: Value of the variable or %NULL on failure
  1512. *
  1513. * This function can be used to get network configuration variable like
  1514. * wpa_config_get(). The only difference is that this functions does not expose
  1515. * key/password material from the configuration. In case a key/password field
  1516. * is requested, the returned value is an empty string or %NULL if the variable
  1517. * is not set or "*" if the variable is set (regardless of its value). The
  1518. * returned value is a copy of the configuration variable in text format, i.e,.
  1519. * the same format that the text-based configuration file and wpa_config_set()
  1520. * are using for the value. The caller is responsible for freeing the returned
  1521. * value.
  1522. */
  1523. char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var)
  1524. {
  1525. size_t i;
  1526. if (ssid == NULL || var == NULL)
  1527. return NULL;
  1528. for (i = 0; i < NUM_SSID_FIELDS; i++) {
  1529. const struct parse_data *field = &ssid_fields[i];
  1530. if (os_strcmp(var, field->name) == 0) {
  1531. char *res = field->writer(field, ssid);
  1532. if (field->key_data) {
  1533. if (res && res[0]) {
  1534. wpa_printf(MSG_DEBUG, "Do not allow "
  1535. "key_data field to be "
  1536. "exposed");
  1537. os_free(res);
  1538. return os_strdup("*");
  1539. }
  1540. os_free(res);
  1541. return NULL;
  1542. }
  1543. return res;
  1544. }
  1545. }
  1546. return NULL;
  1547. }
  1548. #endif /* NO_CONFIG_WRITE */
  1549. /**
  1550. * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
  1551. * @ssid: Pointer to network configuration data
  1552. *
  1553. * This function must be called to update WPA PSK when either SSID or the
  1554. * passphrase has changed for the network configuration.
  1555. */
  1556. void wpa_config_update_psk(struct wpa_ssid *ssid)
  1557. {
  1558. #ifndef CONFIG_NO_PBKDF2
  1559. pbkdf2_sha1(ssid->passphrase,
  1560. (char *) ssid->ssid, ssid->ssid_len, 4096,
  1561. ssid->psk, PMK_LEN);
  1562. wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
  1563. ssid->psk, PMK_LEN);
  1564. ssid->psk_set = 1;
  1565. #endif /* CONFIG_NO_PBKDF2 */
  1566. }
  1567. #ifndef CONFIG_NO_CONFIG_BLOBS
  1568. /**
  1569. * wpa_config_get_blob - Get a named configuration blob
  1570. * @config: Configuration data from wpa_config_read()
  1571. * @name: Name of the blob
  1572. * Returns: Pointer to blob data or %NULL if not found
  1573. */
  1574. const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config,
  1575. const char *name)
  1576. {
  1577. struct wpa_config_blob *blob = config->blobs;
  1578. while (blob) {
  1579. if (os_strcmp(blob->name, name) == 0)
  1580. return blob;
  1581. blob = blob->next;
  1582. }
  1583. return NULL;
  1584. }
  1585. /**
  1586. * wpa_config_set_blob - Set or add a named configuration blob
  1587. * @config: Configuration data from wpa_config_read()
  1588. * @blob: New value for the blob
  1589. *
  1590. * Adds a new configuration blob or replaces the current value of an existing
  1591. * blob.
  1592. */
  1593. void wpa_config_set_blob(struct wpa_config *config,
  1594. struct wpa_config_blob *blob)
  1595. {
  1596. wpa_config_remove_blob(config, blob->name);
  1597. blob->next = config->blobs;
  1598. config->blobs = blob;
  1599. }
  1600. /**
  1601. * wpa_config_free_blob - Free blob data
  1602. * @blob: Pointer to blob to be freed
  1603. */
  1604. void wpa_config_free_blob(struct wpa_config_blob *blob)
  1605. {
  1606. if (blob) {
  1607. os_free(blob->name);
  1608. os_free(blob->data);
  1609. os_free(blob);
  1610. }
  1611. }
  1612. /**
  1613. * wpa_config_remove_blob - Remove a named configuration blob
  1614. * @config: Configuration data from wpa_config_read()
  1615. * @name: Name of the blob to remove
  1616. * Returns: 0 if blob was removed or -1 if blob was not found
  1617. */
  1618. int wpa_config_remove_blob(struct wpa_config *config, const char *name)
  1619. {
  1620. struct wpa_config_blob *pos = config->blobs, *prev = NULL;
  1621. while (pos) {
  1622. if (os_strcmp(pos->name, name) == 0) {
  1623. if (prev)
  1624. prev->next = pos->next;
  1625. else
  1626. config->blobs = pos->next;
  1627. wpa_config_free_blob(pos);
  1628. return 0;
  1629. }
  1630. prev = pos;
  1631. pos = pos->next;
  1632. }
  1633. return -1;
  1634. }
  1635. #endif /* CONFIG_NO_CONFIG_BLOBS */
  1636. /**
  1637. * wpa_config_alloc_empty - Allocate an empty configuration
  1638. * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
  1639. * socket
  1640. * @driver_param: Driver parameters
  1641. * Returns: Pointer to allocated configuration data or %NULL on failure
  1642. */
  1643. struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
  1644. const char *driver_param)
  1645. {
  1646. struct wpa_config *config;
  1647. config = os_zalloc(sizeof(*config));
  1648. if (config == NULL)
  1649. return NULL;
  1650. config->eapol_version = DEFAULT_EAPOL_VERSION;
  1651. config->ap_scan = DEFAULT_AP_SCAN;
  1652. config->fast_reauth = DEFAULT_FAST_REAUTH;
  1653. if (ctrl_interface)
  1654. config->ctrl_interface = os_strdup(ctrl_interface);
  1655. if (driver_param)
  1656. config->driver_param = os_strdup(driver_param);
  1657. return config;
  1658. }
  1659. #ifndef CONFIG_NO_STDOUT_DEBUG
  1660. /**
  1661. * wpa_config_debug_dump_networks - Debug dump of configured networks
  1662. * @config: Configuration data from wpa_config_read()
  1663. */
  1664. void wpa_config_debug_dump_networks(struct wpa_config *config)
  1665. {
  1666. int prio;
  1667. struct wpa_ssid *ssid;
  1668. for (prio = 0; prio < config->num_prio; prio++) {
  1669. ssid = config->pssid[prio];
  1670. wpa_printf(MSG_DEBUG, "Priority group %d",
  1671. ssid->priority);
  1672. while (ssid) {
  1673. wpa_printf(MSG_DEBUG, " id=%d ssid='%s'",
  1674. ssid->id,
  1675. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  1676. ssid = ssid->pnext;
  1677. }
  1678. }
  1679. }
  1680. #endif /* CONFIG_NO_STDOUT_DEBUG */