config.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152
  1. /*
  2. * WPA Supplicant / Configuration parser and common functions
  3. * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "includes.h"
  9. #include "common.h"
  10. #include "utils/uuid.h"
  11. #include "crypto/sha1.h"
  12. #include "rsn_supp/wpa.h"
  13. #include "eap_peer/eap.h"
  14. #include "p2p/p2p.h"
  15. #include "config.h"
  16. #if !defined(CONFIG_CTRL_IFACE) && defined(CONFIG_NO_CONFIG_WRITE)
  17. #define NO_CONFIG_WRITE
  18. #endif
  19. /*
  20. * Structure for network configuration parsing. This data is used to implement
  21. * a generic parser for each network block variable. The table of configuration
  22. * variables is defined below in this file (ssid_fields[]).
  23. */
  24. struct parse_data {
  25. /* Configuration variable name */
  26. char *name;
  27. /* Parser function for this variable */
  28. int (*parser)(const struct parse_data *data, struct wpa_ssid *ssid,
  29. int line, const char *value);
  30. #ifndef NO_CONFIG_WRITE
  31. /* Writer function (i.e., to get the variable in text format from
  32. * internal presentation). */
  33. char * (*writer)(const struct parse_data *data, struct wpa_ssid *ssid);
  34. #endif /* NO_CONFIG_WRITE */
  35. /* Variable specific parameters for the parser. */
  36. void *param1, *param2, *param3, *param4;
  37. /* 0 = this variable can be included in debug output and ctrl_iface
  38. * 1 = this variable contains key/private data and it must not be
  39. * included in debug output unless explicitly requested. In
  40. * addition, this variable will not be readable through the
  41. * ctrl_iface.
  42. */
  43. int key_data;
  44. };
  45. static int wpa_config_parse_str(const struct parse_data *data,
  46. struct wpa_ssid *ssid,
  47. int line, const char *value)
  48. {
  49. size_t res_len, *dst_len;
  50. char **dst, *tmp;
  51. if (os_strcmp(value, "NULL") == 0) {
  52. wpa_printf(MSG_DEBUG, "Unset configuration string '%s'",
  53. data->name);
  54. tmp = NULL;
  55. res_len = 0;
  56. goto set;
  57. }
  58. tmp = wpa_config_parse_string(value, &res_len);
  59. if (tmp == NULL) {
  60. wpa_printf(MSG_ERROR, "Line %d: failed to parse %s '%s'.",
  61. line, data->name,
  62. data->key_data ? "[KEY DATA REMOVED]" : value);
  63. return -1;
  64. }
  65. if (data->key_data) {
  66. wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
  67. (u8 *) tmp, res_len);
  68. } else {
  69. wpa_hexdump_ascii(MSG_MSGDUMP, data->name,
  70. (u8 *) tmp, res_len);
  71. }
  72. if (data->param3 && res_len < (size_t) data->param3) {
  73. wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
  74. "min_len=%ld)", line, data->name,
  75. (unsigned long) res_len, (long) data->param3);
  76. os_free(tmp);
  77. return -1;
  78. }
  79. if (data->param4 && res_len > (size_t) data->param4) {
  80. wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
  81. "max_len=%ld)", line, data->name,
  82. (unsigned long) res_len, (long) data->param4);
  83. os_free(tmp);
  84. return -1;
  85. }
  86. set:
  87. dst = (char **) (((u8 *) ssid) + (long) data->param1);
  88. dst_len = (size_t *) (((u8 *) ssid) + (long) data->param2);
  89. os_free(*dst);
  90. *dst = tmp;
  91. if (data->param2)
  92. *dst_len = res_len;
  93. return 0;
  94. }
  95. #ifndef NO_CONFIG_WRITE
  96. static char * wpa_config_write_string_ascii(const u8 *value, size_t len)
  97. {
  98. char *buf;
  99. buf = os_malloc(len + 3);
  100. if (buf == NULL)
  101. return NULL;
  102. buf[0] = '"';
  103. os_memcpy(buf + 1, value, len);
  104. buf[len + 1] = '"';
  105. buf[len + 2] = '\0';
  106. return buf;
  107. }
  108. static char * wpa_config_write_string_hex(const u8 *value, size_t len)
  109. {
  110. char *buf;
  111. buf = os_zalloc(2 * len + 1);
  112. if (buf == NULL)
  113. return NULL;
  114. wpa_snprintf_hex(buf, 2 * len + 1, value, len);
  115. return buf;
  116. }
  117. static char * wpa_config_write_string(const u8 *value, size_t len)
  118. {
  119. if (value == NULL)
  120. return NULL;
  121. if (is_hex(value, len))
  122. return wpa_config_write_string_hex(value, len);
  123. else
  124. return wpa_config_write_string_ascii(value, len);
  125. }
  126. static char * wpa_config_write_str(const struct parse_data *data,
  127. struct wpa_ssid *ssid)
  128. {
  129. size_t len;
  130. char **src;
  131. src = (char **) (((u8 *) ssid) + (long) data->param1);
  132. if (*src == NULL)
  133. return NULL;
  134. if (data->param2)
  135. len = *((size_t *) (((u8 *) ssid) + (long) data->param2));
  136. else
  137. len = os_strlen(*src);
  138. return wpa_config_write_string((const u8 *) *src, len);
  139. }
  140. #endif /* NO_CONFIG_WRITE */
  141. static int wpa_config_parse_int(const struct parse_data *data,
  142. struct wpa_ssid *ssid,
  143. int line, const char *value)
  144. {
  145. int *dst;
  146. dst = (int *) (((u8 *) ssid) + (long) data->param1);
  147. *dst = atoi(value);
  148. wpa_printf(MSG_MSGDUMP, "%s=%d (0x%x)", data->name, *dst, *dst);
  149. if (data->param3 && *dst < (long) data->param3) {
  150. wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
  151. "min_value=%ld)", line, data->name, *dst,
  152. (long) data->param3);
  153. *dst = (long) data->param3;
  154. return -1;
  155. }
  156. if (data->param4 && *dst > (long) data->param4) {
  157. wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
  158. "max_value=%ld)", line, data->name, *dst,
  159. (long) data->param4);
  160. *dst = (long) data->param4;
  161. return -1;
  162. }
  163. return 0;
  164. }
  165. #ifndef NO_CONFIG_WRITE
  166. static char * wpa_config_write_int(const struct parse_data *data,
  167. struct wpa_ssid *ssid)
  168. {
  169. int *src, res;
  170. char *value;
  171. src = (int *) (((u8 *) ssid) + (long) data->param1);
  172. value = os_malloc(20);
  173. if (value == NULL)
  174. return NULL;
  175. res = os_snprintf(value, 20, "%d", *src);
  176. if (res < 0 || res >= 20) {
  177. os_free(value);
  178. return NULL;
  179. }
  180. value[20 - 1] = '\0';
  181. return value;
  182. }
  183. #endif /* NO_CONFIG_WRITE */
  184. static int wpa_config_parse_bssid(const struct parse_data *data,
  185. struct wpa_ssid *ssid, int line,
  186. const char *value)
  187. {
  188. if (value[0] == '\0' || os_strcmp(value, "\"\"") == 0 ||
  189. os_strcmp(value, "any") == 0) {
  190. ssid->bssid_set = 0;
  191. wpa_printf(MSG_MSGDUMP, "BSSID any");
  192. return 0;
  193. }
  194. if (hwaddr_aton(value, ssid->bssid)) {
  195. wpa_printf(MSG_ERROR, "Line %d: Invalid BSSID '%s'.",
  196. line, value);
  197. return -1;
  198. }
  199. ssid->bssid_set = 1;
  200. wpa_hexdump(MSG_MSGDUMP, "BSSID", ssid->bssid, ETH_ALEN);
  201. return 0;
  202. }
  203. #ifndef NO_CONFIG_WRITE
  204. static char * wpa_config_write_bssid(const struct parse_data *data,
  205. struct wpa_ssid *ssid)
  206. {
  207. char *value;
  208. int res;
  209. if (!ssid->bssid_set)
  210. return NULL;
  211. value = os_malloc(20);
  212. if (value == NULL)
  213. return NULL;
  214. res = os_snprintf(value, 20, MACSTR, MAC2STR(ssid->bssid));
  215. if (res < 0 || res >= 20) {
  216. os_free(value);
  217. return NULL;
  218. }
  219. value[20 - 1] = '\0';
  220. return value;
  221. }
  222. #endif /* NO_CONFIG_WRITE */
  223. static int wpa_config_parse_psk(const struct parse_data *data,
  224. struct wpa_ssid *ssid, int line,
  225. const char *value)
  226. {
  227. #ifdef CONFIG_EXT_PASSWORD
  228. if (os_strncmp(value, "ext:", 4) == 0) {
  229. os_free(ssid->passphrase);
  230. ssid->passphrase = NULL;
  231. ssid->psk_set = 0;
  232. os_free(ssid->ext_psk);
  233. ssid->ext_psk = os_strdup(value + 4);
  234. if (ssid->ext_psk == NULL)
  235. return -1;
  236. wpa_printf(MSG_DEBUG, "PSK: External password '%s'",
  237. ssid->ext_psk);
  238. return 0;
  239. }
  240. #endif /* CONFIG_EXT_PASSWORD */
  241. if (*value == '"') {
  242. #ifndef CONFIG_NO_PBKDF2
  243. const char *pos;
  244. size_t len;
  245. value++;
  246. pos = os_strrchr(value, '"');
  247. if (pos)
  248. len = pos - value;
  249. else
  250. len = os_strlen(value);
  251. if (len < 8 || len > 63) {
  252. wpa_printf(MSG_ERROR, "Line %d: Invalid passphrase "
  253. "length %lu (expected: 8..63) '%s'.",
  254. line, (unsigned long) len, value);
  255. return -1;
  256. }
  257. wpa_hexdump_ascii_key(MSG_MSGDUMP, "PSK (ASCII passphrase)",
  258. (u8 *) value, len);
  259. if (ssid->passphrase && os_strlen(ssid->passphrase) == len &&
  260. os_memcmp(ssid->passphrase, value, len) == 0)
  261. return 0;
  262. ssid->psk_set = 0;
  263. os_free(ssid->passphrase);
  264. ssid->passphrase = os_malloc(len + 1);
  265. if (ssid->passphrase == NULL)
  266. return -1;
  267. os_memcpy(ssid->passphrase, value, len);
  268. ssid->passphrase[len] = '\0';
  269. return 0;
  270. #else /* CONFIG_NO_PBKDF2 */
  271. wpa_printf(MSG_ERROR, "Line %d: ASCII passphrase not "
  272. "supported.", line);
  273. return -1;
  274. #endif /* CONFIG_NO_PBKDF2 */
  275. }
  276. if (hexstr2bin(value, ssid->psk, PMK_LEN) ||
  277. value[PMK_LEN * 2] != '\0') {
  278. wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
  279. line, value);
  280. return -1;
  281. }
  282. os_free(ssid->passphrase);
  283. ssid->passphrase = NULL;
  284. ssid->psk_set = 1;
  285. wpa_hexdump_key(MSG_MSGDUMP, "PSK", ssid->psk, PMK_LEN);
  286. return 0;
  287. }
  288. #ifndef NO_CONFIG_WRITE
  289. static char * wpa_config_write_psk(const struct parse_data *data,
  290. struct wpa_ssid *ssid)
  291. {
  292. #ifdef CONFIG_EXT_PASSWORD
  293. if (ssid->ext_psk) {
  294. size_t len = 4 + os_strlen(ssid->ext_psk) + 1;
  295. char *buf = os_malloc(len);
  296. if (buf == NULL)
  297. return NULL;
  298. os_snprintf(buf, len, "ext:%s", ssid->ext_psk);
  299. return buf;
  300. }
  301. #endif /* CONFIG_EXT_PASSWORD */
  302. if (ssid->passphrase)
  303. return wpa_config_write_string_ascii(
  304. (const u8 *) ssid->passphrase,
  305. os_strlen(ssid->passphrase));
  306. if (ssid->psk_set)
  307. return wpa_config_write_string_hex(ssid->psk, PMK_LEN);
  308. return NULL;
  309. }
  310. #endif /* NO_CONFIG_WRITE */
  311. static int wpa_config_parse_proto(const struct parse_data *data,
  312. struct wpa_ssid *ssid, int line,
  313. const char *value)
  314. {
  315. int val = 0, last, errors = 0;
  316. char *start, *end, *buf;
  317. buf = os_strdup(value);
  318. if (buf == NULL)
  319. return -1;
  320. start = buf;
  321. while (*start != '\0') {
  322. while (*start == ' ' || *start == '\t')
  323. start++;
  324. if (*start == '\0')
  325. break;
  326. end = start;
  327. while (*end != ' ' && *end != '\t' && *end != '\0')
  328. end++;
  329. last = *end == '\0';
  330. *end = '\0';
  331. if (os_strcmp(start, "WPA") == 0)
  332. val |= WPA_PROTO_WPA;
  333. else if (os_strcmp(start, "RSN") == 0 ||
  334. os_strcmp(start, "WPA2") == 0)
  335. val |= WPA_PROTO_RSN;
  336. else {
  337. wpa_printf(MSG_ERROR, "Line %d: invalid proto '%s'",
  338. line, start);
  339. errors++;
  340. }
  341. if (last)
  342. break;
  343. start = end + 1;
  344. }
  345. os_free(buf);
  346. if (val == 0) {
  347. wpa_printf(MSG_ERROR,
  348. "Line %d: no proto values configured.", line);
  349. errors++;
  350. }
  351. wpa_printf(MSG_MSGDUMP, "proto: 0x%x", val);
  352. ssid->proto = val;
  353. return errors ? -1 : 0;
  354. }
  355. #ifndef NO_CONFIG_WRITE
  356. static char * wpa_config_write_proto(const struct parse_data *data,
  357. struct wpa_ssid *ssid)
  358. {
  359. int first = 1, ret;
  360. char *buf, *pos, *end;
  361. pos = buf = os_zalloc(10);
  362. if (buf == NULL)
  363. return NULL;
  364. end = buf + 10;
  365. if (ssid->proto & WPA_PROTO_WPA) {
  366. ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
  367. if (ret < 0 || ret >= end - pos)
  368. return buf;
  369. pos += ret;
  370. first = 0;
  371. }
  372. if (ssid->proto & WPA_PROTO_RSN) {
  373. ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
  374. if (ret < 0 || ret >= end - pos)
  375. return buf;
  376. pos += ret;
  377. first = 0;
  378. }
  379. return buf;
  380. }
  381. #endif /* NO_CONFIG_WRITE */
  382. static int wpa_config_parse_key_mgmt(const struct parse_data *data,
  383. struct wpa_ssid *ssid, int line,
  384. const char *value)
  385. {
  386. int val = 0, last, errors = 0;
  387. char *start, *end, *buf;
  388. buf = os_strdup(value);
  389. if (buf == NULL)
  390. return -1;
  391. start = buf;
  392. while (*start != '\0') {
  393. while (*start == ' ' || *start == '\t')
  394. start++;
  395. if (*start == '\0')
  396. break;
  397. end = start;
  398. while (*end != ' ' && *end != '\t' && *end != '\0')
  399. end++;
  400. last = *end == '\0';
  401. *end = '\0';
  402. if (os_strcmp(start, "WPA-PSK") == 0)
  403. val |= WPA_KEY_MGMT_PSK;
  404. else if (os_strcmp(start, "WPA-EAP") == 0)
  405. val |= WPA_KEY_MGMT_IEEE8021X;
  406. else if (os_strcmp(start, "IEEE8021X") == 0)
  407. val |= WPA_KEY_MGMT_IEEE8021X_NO_WPA;
  408. else if (os_strcmp(start, "NONE") == 0)
  409. val |= WPA_KEY_MGMT_NONE;
  410. else if (os_strcmp(start, "WPA-NONE") == 0)
  411. val |= WPA_KEY_MGMT_WPA_NONE;
  412. #ifdef CONFIG_IEEE80211R
  413. else if (os_strcmp(start, "FT-PSK") == 0)
  414. val |= WPA_KEY_MGMT_FT_PSK;
  415. else if (os_strcmp(start, "FT-EAP") == 0)
  416. val |= WPA_KEY_MGMT_FT_IEEE8021X;
  417. #endif /* CONFIG_IEEE80211R */
  418. #ifdef CONFIG_IEEE80211W
  419. else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
  420. val |= WPA_KEY_MGMT_PSK_SHA256;
  421. else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
  422. val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
  423. #endif /* CONFIG_IEEE80211W */
  424. #ifdef CONFIG_WPS
  425. else if (os_strcmp(start, "WPS") == 0)
  426. val |= WPA_KEY_MGMT_WPS;
  427. #endif /* CONFIG_WPS */
  428. #ifdef CONFIG_SAE
  429. else if (os_strcmp(start, "SAE") == 0)
  430. val |= WPA_KEY_MGMT_SAE;
  431. else if (os_strcmp(start, "FT-SAE") == 0)
  432. val |= WPA_KEY_MGMT_FT_SAE;
  433. #endif /* CONFIG_SAE */
  434. else {
  435. wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
  436. line, start);
  437. errors++;
  438. }
  439. if (last)
  440. break;
  441. start = end + 1;
  442. }
  443. os_free(buf);
  444. if (val == 0) {
  445. wpa_printf(MSG_ERROR,
  446. "Line %d: no key_mgmt values configured.", line);
  447. errors++;
  448. }
  449. wpa_printf(MSG_MSGDUMP, "key_mgmt: 0x%x", val);
  450. ssid->key_mgmt = val;
  451. return errors ? -1 : 0;
  452. }
  453. #ifndef NO_CONFIG_WRITE
  454. static char * wpa_config_write_key_mgmt(const struct parse_data *data,
  455. struct wpa_ssid *ssid)
  456. {
  457. char *buf, *pos, *end;
  458. int ret;
  459. pos = buf = os_zalloc(50);
  460. if (buf == NULL)
  461. return NULL;
  462. end = buf + 50;
  463. if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
  464. ret = os_snprintf(pos, end - pos, "%sWPA-PSK",
  465. pos == buf ? "" : " ");
  466. if (ret < 0 || ret >= end - pos) {
  467. end[-1] = '\0';
  468. return buf;
  469. }
  470. pos += ret;
  471. }
  472. if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
  473. ret = os_snprintf(pos, end - pos, "%sWPA-EAP",
  474. pos == buf ? "" : " ");
  475. if (ret < 0 || ret >= end - pos) {
  476. end[-1] = '\0';
  477. return buf;
  478. }
  479. pos += ret;
  480. }
  481. if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  482. ret = os_snprintf(pos, end - pos, "%sIEEE8021X",
  483. pos == buf ? "" : " ");
  484. if (ret < 0 || ret >= end - pos) {
  485. end[-1] = '\0';
  486. return buf;
  487. }
  488. pos += ret;
  489. }
  490. if (ssid->key_mgmt & WPA_KEY_MGMT_NONE) {
  491. ret = os_snprintf(pos, end - pos, "%sNONE",
  492. pos == buf ? "" : " ");
  493. if (ret < 0 || ret >= end - pos) {
  494. end[-1] = '\0';
  495. return buf;
  496. }
  497. pos += ret;
  498. }
  499. if (ssid->key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
  500. ret = os_snprintf(pos, end - pos, "%sWPA-NONE",
  501. pos == buf ? "" : " ");
  502. if (ret < 0 || ret >= end - pos) {
  503. end[-1] = '\0';
  504. return buf;
  505. }
  506. pos += ret;
  507. }
  508. #ifdef CONFIG_IEEE80211R
  509. if (ssid->key_mgmt & WPA_KEY_MGMT_FT_PSK)
  510. pos += os_snprintf(pos, end - pos, "%sFT-PSK",
  511. pos == buf ? "" : " ");
  512. if (ssid->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X)
  513. pos += os_snprintf(pos, end - pos, "%sFT-EAP",
  514. pos == buf ? "" : " ");
  515. #endif /* CONFIG_IEEE80211R */
  516. #ifdef CONFIG_IEEE80211W
  517. if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
  518. pos += os_snprintf(pos, end - pos, "%sWPA-PSK-SHA256",
  519. pos == buf ? "" : " ");
  520. if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
  521. pos += os_snprintf(pos, end - pos, "%sWPA-EAP-SHA256",
  522. pos == buf ? "" : " ");
  523. #endif /* CONFIG_IEEE80211W */
  524. #ifdef CONFIG_WPS
  525. if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
  526. pos += os_snprintf(pos, end - pos, "%sWPS",
  527. pos == buf ? "" : " ");
  528. #endif /* CONFIG_WPS */
  529. return buf;
  530. }
  531. #endif /* NO_CONFIG_WRITE */
  532. static int wpa_config_parse_cipher(int line, const char *value)
  533. {
  534. int val = 0, last;
  535. char *start, *end, *buf;
  536. buf = os_strdup(value);
  537. if (buf == NULL)
  538. return -1;
  539. start = buf;
  540. while (*start != '\0') {
  541. while (*start == ' ' || *start == '\t')
  542. start++;
  543. if (*start == '\0')
  544. break;
  545. end = start;
  546. while (*end != ' ' && *end != '\t' && *end != '\0')
  547. end++;
  548. last = *end == '\0';
  549. *end = '\0';
  550. if (os_strcmp(start, "CCMP") == 0)
  551. val |= WPA_CIPHER_CCMP;
  552. else if (os_strcmp(start, "GCMP") == 0)
  553. val |= WPA_CIPHER_GCMP;
  554. else if (os_strcmp(start, "TKIP") == 0)
  555. val |= WPA_CIPHER_TKIP;
  556. else if (os_strcmp(start, "WEP104") == 0)
  557. val |= WPA_CIPHER_WEP104;
  558. else if (os_strcmp(start, "WEP40") == 0)
  559. val |= WPA_CIPHER_WEP40;
  560. else if (os_strcmp(start, "NONE") == 0)
  561. val |= WPA_CIPHER_NONE;
  562. else {
  563. wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
  564. line, start);
  565. os_free(buf);
  566. return -1;
  567. }
  568. if (last)
  569. break;
  570. start = end + 1;
  571. }
  572. os_free(buf);
  573. if (val == 0) {
  574. wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
  575. line);
  576. return -1;
  577. }
  578. return val;
  579. }
  580. #ifndef NO_CONFIG_WRITE
  581. static char * wpa_config_write_cipher(int cipher)
  582. {
  583. char *buf, *pos, *end;
  584. int ret;
  585. pos = buf = os_zalloc(50);
  586. if (buf == NULL)
  587. return NULL;
  588. end = buf + 50;
  589. if (cipher & WPA_CIPHER_CCMP) {
  590. ret = os_snprintf(pos, end - pos, "%sCCMP",
  591. pos == buf ? "" : " ");
  592. if (ret < 0 || ret >= end - pos) {
  593. end[-1] = '\0';
  594. return buf;
  595. }
  596. pos += ret;
  597. }
  598. if (cipher & WPA_CIPHER_GCMP) {
  599. ret = os_snprintf(pos, end - pos, "%sGCMP",
  600. pos == buf ? "" : " ");
  601. if (ret < 0 || ret >= end - pos) {
  602. end[-1] = '\0';
  603. return buf;
  604. }
  605. pos += ret;
  606. }
  607. if (cipher & WPA_CIPHER_TKIP) {
  608. ret = os_snprintf(pos, end - pos, "%sTKIP",
  609. pos == buf ? "" : " ");
  610. if (ret < 0 || ret >= end - pos) {
  611. end[-1] = '\0';
  612. return buf;
  613. }
  614. pos += ret;
  615. }
  616. if (cipher & WPA_CIPHER_WEP104) {
  617. ret = os_snprintf(pos, end - pos, "%sWEP104",
  618. pos == buf ? "" : " ");
  619. if (ret < 0 || ret >= end - pos) {
  620. end[-1] = '\0';
  621. return buf;
  622. }
  623. pos += ret;
  624. }
  625. if (cipher & WPA_CIPHER_WEP40) {
  626. ret = os_snprintf(pos, end - pos, "%sWEP40",
  627. pos == buf ? "" : " ");
  628. if (ret < 0 || ret >= end - pos) {
  629. end[-1] = '\0';
  630. return buf;
  631. }
  632. pos += ret;
  633. }
  634. if (cipher & WPA_CIPHER_NONE) {
  635. ret = os_snprintf(pos, end - pos, "%sNONE",
  636. pos == buf ? "" : " ");
  637. if (ret < 0 || ret >= end - pos) {
  638. end[-1] = '\0';
  639. return buf;
  640. }
  641. pos += ret;
  642. }
  643. return buf;
  644. }
  645. #endif /* NO_CONFIG_WRITE */
  646. static int wpa_config_parse_pairwise(const struct parse_data *data,
  647. struct wpa_ssid *ssid, int line,
  648. const char *value)
  649. {
  650. int val;
  651. val = wpa_config_parse_cipher(line, value);
  652. if (val == -1)
  653. return -1;
  654. if (val & ~(WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | WPA_CIPHER_TKIP |
  655. WPA_CIPHER_NONE)) {
  656. wpa_printf(MSG_ERROR, "Line %d: not allowed pairwise cipher "
  657. "(0x%x).", line, val);
  658. return -1;
  659. }
  660. wpa_printf(MSG_MSGDUMP, "pairwise: 0x%x", val);
  661. ssid->pairwise_cipher = val;
  662. return 0;
  663. }
  664. #ifndef NO_CONFIG_WRITE
  665. static char * wpa_config_write_pairwise(const struct parse_data *data,
  666. struct wpa_ssid *ssid)
  667. {
  668. return wpa_config_write_cipher(ssid->pairwise_cipher);
  669. }
  670. #endif /* NO_CONFIG_WRITE */
  671. static int wpa_config_parse_group(const struct parse_data *data,
  672. struct wpa_ssid *ssid, int line,
  673. const char *value)
  674. {
  675. int val;
  676. val = wpa_config_parse_cipher(line, value);
  677. if (val == -1)
  678. return -1;
  679. if (val & ~(WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | WPA_CIPHER_TKIP |
  680. WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) {
  681. wpa_printf(MSG_ERROR, "Line %d: not allowed group cipher "
  682. "(0x%x).", line, val);
  683. return -1;
  684. }
  685. wpa_printf(MSG_MSGDUMP, "group: 0x%x", val);
  686. ssid->group_cipher = val;
  687. return 0;
  688. }
  689. #ifndef NO_CONFIG_WRITE
  690. static char * wpa_config_write_group(const struct parse_data *data,
  691. struct wpa_ssid *ssid)
  692. {
  693. return wpa_config_write_cipher(ssid->group_cipher);
  694. }
  695. #endif /* NO_CONFIG_WRITE */
  696. static int wpa_config_parse_auth_alg(const struct parse_data *data,
  697. struct wpa_ssid *ssid, int line,
  698. const char *value)
  699. {
  700. int val = 0, last, errors = 0;
  701. char *start, *end, *buf;
  702. buf = os_strdup(value);
  703. if (buf == NULL)
  704. return -1;
  705. start = buf;
  706. while (*start != '\0') {
  707. while (*start == ' ' || *start == '\t')
  708. start++;
  709. if (*start == '\0')
  710. break;
  711. end = start;
  712. while (*end != ' ' && *end != '\t' && *end != '\0')
  713. end++;
  714. last = *end == '\0';
  715. *end = '\0';
  716. if (os_strcmp(start, "OPEN") == 0)
  717. val |= WPA_AUTH_ALG_OPEN;
  718. else if (os_strcmp(start, "SHARED") == 0)
  719. val |= WPA_AUTH_ALG_SHARED;
  720. else if (os_strcmp(start, "LEAP") == 0)
  721. val |= WPA_AUTH_ALG_LEAP;
  722. else {
  723. wpa_printf(MSG_ERROR, "Line %d: invalid auth_alg '%s'",
  724. line, start);
  725. errors++;
  726. }
  727. if (last)
  728. break;
  729. start = end + 1;
  730. }
  731. os_free(buf);
  732. if (val == 0) {
  733. wpa_printf(MSG_ERROR,
  734. "Line %d: no auth_alg values configured.", line);
  735. errors++;
  736. }
  737. wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", val);
  738. ssid->auth_alg = val;
  739. return errors ? -1 : 0;
  740. }
  741. #ifndef NO_CONFIG_WRITE
  742. static char * wpa_config_write_auth_alg(const struct parse_data *data,
  743. struct wpa_ssid *ssid)
  744. {
  745. char *buf, *pos, *end;
  746. int ret;
  747. pos = buf = os_zalloc(30);
  748. if (buf == NULL)
  749. return NULL;
  750. end = buf + 30;
  751. if (ssid->auth_alg & WPA_AUTH_ALG_OPEN) {
  752. ret = os_snprintf(pos, end - pos, "%sOPEN",
  753. pos == buf ? "" : " ");
  754. if (ret < 0 || ret >= end - pos) {
  755. end[-1] = '\0';
  756. return buf;
  757. }
  758. pos += ret;
  759. }
  760. if (ssid->auth_alg & WPA_AUTH_ALG_SHARED) {
  761. ret = os_snprintf(pos, end - pos, "%sSHARED",
  762. pos == buf ? "" : " ");
  763. if (ret < 0 || ret >= end - pos) {
  764. end[-1] = '\0';
  765. return buf;
  766. }
  767. pos += ret;
  768. }
  769. if (ssid->auth_alg & WPA_AUTH_ALG_LEAP) {
  770. ret = os_snprintf(pos, end - pos, "%sLEAP",
  771. pos == buf ? "" : " ");
  772. if (ret < 0 || ret >= end - pos) {
  773. end[-1] = '\0';
  774. return buf;
  775. }
  776. pos += ret;
  777. }
  778. return buf;
  779. }
  780. #endif /* NO_CONFIG_WRITE */
  781. static int * wpa_config_parse_int_array(const char *value)
  782. {
  783. int *freqs;
  784. size_t used, len;
  785. const char *pos;
  786. used = 0;
  787. len = 10;
  788. freqs = os_calloc(len + 1, sizeof(int));
  789. if (freqs == NULL)
  790. return NULL;
  791. pos = value;
  792. while (pos) {
  793. while (*pos == ' ')
  794. pos++;
  795. if (used == len) {
  796. int *n;
  797. size_t i;
  798. n = os_realloc_array(freqs, len * 2 + 1, sizeof(int));
  799. if (n == NULL) {
  800. os_free(freqs);
  801. return NULL;
  802. }
  803. for (i = len; i <= len * 2; i++)
  804. n[i] = 0;
  805. freqs = n;
  806. len *= 2;
  807. }
  808. freqs[used] = atoi(pos);
  809. if (freqs[used] == 0)
  810. break;
  811. used++;
  812. pos = os_strchr(pos + 1, ' ');
  813. }
  814. return freqs;
  815. }
  816. static int wpa_config_parse_scan_freq(const struct parse_data *data,
  817. struct wpa_ssid *ssid, int line,
  818. const char *value)
  819. {
  820. int *freqs;
  821. freqs = wpa_config_parse_int_array(value);
  822. if (freqs == NULL)
  823. return -1;
  824. os_free(ssid->scan_freq);
  825. ssid->scan_freq = freqs;
  826. return 0;
  827. }
  828. static int wpa_config_parse_freq_list(const struct parse_data *data,
  829. struct wpa_ssid *ssid, int line,
  830. const char *value)
  831. {
  832. int *freqs;
  833. freqs = wpa_config_parse_int_array(value);
  834. if (freqs == NULL)
  835. return -1;
  836. os_free(ssid->freq_list);
  837. ssid->freq_list = freqs;
  838. return 0;
  839. }
  840. #ifndef NO_CONFIG_WRITE
  841. static char * wpa_config_write_freqs(const struct parse_data *data,
  842. const int *freqs)
  843. {
  844. char *buf, *pos, *end;
  845. int i, ret;
  846. size_t count;
  847. if (freqs == NULL)
  848. return NULL;
  849. count = 0;
  850. for (i = 0; freqs[i]; i++)
  851. count++;
  852. pos = buf = os_zalloc(10 * count + 1);
  853. if (buf == NULL)
  854. return NULL;
  855. end = buf + 10 * count + 1;
  856. for (i = 0; freqs[i]; i++) {
  857. ret = os_snprintf(pos, end - pos, "%s%u",
  858. i == 0 ? "" : " ", freqs[i]);
  859. if (ret < 0 || ret >= end - pos) {
  860. end[-1] = '\0';
  861. return buf;
  862. }
  863. pos += ret;
  864. }
  865. return buf;
  866. }
  867. static char * wpa_config_write_scan_freq(const struct parse_data *data,
  868. struct wpa_ssid *ssid)
  869. {
  870. return wpa_config_write_freqs(data, ssid->scan_freq);
  871. }
  872. static char * wpa_config_write_freq_list(const struct parse_data *data,
  873. struct wpa_ssid *ssid)
  874. {
  875. return wpa_config_write_freqs(data, ssid->freq_list);
  876. }
  877. #endif /* NO_CONFIG_WRITE */
  878. #ifdef IEEE8021X_EAPOL
  879. static int wpa_config_parse_eap(const struct parse_data *data,
  880. struct wpa_ssid *ssid, int line,
  881. const char *value)
  882. {
  883. int last, errors = 0;
  884. char *start, *end, *buf;
  885. struct eap_method_type *methods = NULL, *tmp;
  886. size_t num_methods = 0;
  887. buf = os_strdup(value);
  888. if (buf == NULL)
  889. return -1;
  890. start = buf;
  891. while (*start != '\0') {
  892. while (*start == ' ' || *start == '\t')
  893. start++;
  894. if (*start == '\0')
  895. break;
  896. end = start;
  897. while (*end != ' ' && *end != '\t' && *end != '\0')
  898. end++;
  899. last = *end == '\0';
  900. *end = '\0';
  901. tmp = methods;
  902. methods = os_realloc_array(methods, num_methods + 1,
  903. sizeof(*methods));
  904. if (methods == NULL) {
  905. os_free(tmp);
  906. os_free(buf);
  907. return -1;
  908. }
  909. methods[num_methods].method = eap_peer_get_type(
  910. start, &methods[num_methods].vendor);
  911. if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
  912. methods[num_methods].method == EAP_TYPE_NONE) {
  913. wpa_printf(MSG_ERROR, "Line %d: unknown EAP method "
  914. "'%s'", line, start);
  915. wpa_printf(MSG_ERROR, "You may need to add support for"
  916. " this EAP method during wpa_supplicant\n"
  917. "build time configuration.\n"
  918. "See README for more information.");
  919. errors++;
  920. } else if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
  921. methods[num_methods].method == EAP_TYPE_LEAP)
  922. ssid->leap++;
  923. else
  924. ssid->non_leap++;
  925. num_methods++;
  926. if (last)
  927. break;
  928. start = end + 1;
  929. }
  930. os_free(buf);
  931. tmp = methods;
  932. methods = os_realloc_array(methods, num_methods + 1, sizeof(*methods));
  933. if (methods == NULL) {
  934. os_free(tmp);
  935. return -1;
  936. }
  937. methods[num_methods].vendor = EAP_VENDOR_IETF;
  938. methods[num_methods].method = EAP_TYPE_NONE;
  939. num_methods++;
  940. wpa_hexdump(MSG_MSGDUMP, "eap methods",
  941. (u8 *) methods, num_methods * sizeof(*methods));
  942. os_free(ssid->eap.eap_methods);
  943. ssid->eap.eap_methods = methods;
  944. return errors ? -1 : 0;
  945. }
  946. static char * wpa_config_write_eap(const struct parse_data *data,
  947. struct wpa_ssid *ssid)
  948. {
  949. int i, ret;
  950. char *buf, *pos, *end;
  951. const struct eap_method_type *eap_methods = ssid->eap.eap_methods;
  952. const char *name;
  953. if (eap_methods == NULL)
  954. return NULL;
  955. pos = buf = os_zalloc(100);
  956. if (buf == NULL)
  957. return NULL;
  958. end = buf + 100;
  959. for (i = 0; eap_methods[i].vendor != EAP_VENDOR_IETF ||
  960. eap_methods[i].method != EAP_TYPE_NONE; i++) {
  961. name = eap_get_name(eap_methods[i].vendor,
  962. eap_methods[i].method);
  963. if (name) {
  964. ret = os_snprintf(pos, end - pos, "%s%s",
  965. pos == buf ? "" : " ", name);
  966. if (ret < 0 || ret >= end - pos)
  967. break;
  968. pos += ret;
  969. }
  970. }
  971. end[-1] = '\0';
  972. return buf;
  973. }
  974. static int wpa_config_parse_password(const struct parse_data *data,
  975. struct wpa_ssid *ssid, int line,
  976. const char *value)
  977. {
  978. u8 *hash;
  979. if (os_strcmp(value, "NULL") == 0) {
  980. wpa_printf(MSG_DEBUG, "Unset configuration string 'password'");
  981. os_free(ssid->eap.password);
  982. ssid->eap.password = NULL;
  983. ssid->eap.password_len = 0;
  984. return 0;
  985. }
  986. #ifdef CONFIG_EXT_PASSWORD
  987. if (os_strncmp(value, "ext:", 4) == 0) {
  988. char *name = os_strdup(value + 4);
  989. if (name == NULL)
  990. return -1;
  991. os_free(ssid->eap.password);
  992. ssid->eap.password = (u8 *) name;
  993. ssid->eap.password_len = os_strlen(name);
  994. ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
  995. ssid->eap.flags |= EAP_CONFIG_FLAGS_EXT_PASSWORD;
  996. return 0;
  997. }
  998. #endif /* CONFIG_EXT_PASSWORD */
  999. if (os_strncmp(value, "hash:", 5) != 0) {
  1000. char *tmp;
  1001. size_t res_len;
  1002. tmp = wpa_config_parse_string(value, &res_len);
  1003. if (tmp == NULL) {
  1004. wpa_printf(MSG_ERROR, "Line %d: failed to parse "
  1005. "password.", line);
  1006. return -1;
  1007. }
  1008. wpa_hexdump_ascii_key(MSG_MSGDUMP, data->name,
  1009. (u8 *) tmp, res_len);
  1010. os_free(ssid->eap.password);
  1011. ssid->eap.password = (u8 *) tmp;
  1012. ssid->eap.password_len = res_len;
  1013. ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
  1014. ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
  1015. return 0;
  1016. }
  1017. /* NtPasswordHash: hash:<32 hex digits> */
  1018. if (os_strlen(value + 5) != 2 * 16) {
  1019. wpa_printf(MSG_ERROR, "Line %d: Invalid password hash length "
  1020. "(expected 32 hex digits)", line);
  1021. return -1;
  1022. }
  1023. hash = os_malloc(16);
  1024. if (hash == NULL)
  1025. return -1;
  1026. if (hexstr2bin(value + 5, hash, 16)) {
  1027. os_free(hash);
  1028. wpa_printf(MSG_ERROR, "Line %d: Invalid password hash", line);
  1029. return -1;
  1030. }
  1031. wpa_hexdump_key(MSG_MSGDUMP, data->name, hash, 16);
  1032. os_free(ssid->eap.password);
  1033. ssid->eap.password = hash;
  1034. ssid->eap.password_len = 16;
  1035. ssid->eap.flags |= EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
  1036. ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
  1037. return 0;
  1038. }
  1039. static char * wpa_config_write_password(const struct parse_data *data,
  1040. struct wpa_ssid *ssid)
  1041. {
  1042. char *buf;
  1043. if (ssid->eap.password == NULL)
  1044. return NULL;
  1045. #ifdef CONFIG_EXT_PASSWORD
  1046. if (ssid->eap.flags & EAP_CONFIG_FLAGS_EXT_PASSWORD) {
  1047. buf = os_zalloc(4 + ssid->eap.password_len + 1);
  1048. if (buf == NULL)
  1049. return NULL;
  1050. os_memcpy(buf, "ext:", 4);
  1051. os_memcpy(buf + 4, ssid->eap.password, ssid->eap.password_len);
  1052. return buf;
  1053. }
  1054. #endif /* CONFIG_EXT_PASSWORD */
  1055. if (!(ssid->eap.flags & EAP_CONFIG_FLAGS_PASSWORD_NTHASH)) {
  1056. return wpa_config_write_string(
  1057. ssid->eap.password, ssid->eap.password_len);
  1058. }
  1059. buf = os_malloc(5 + 32 + 1);
  1060. if (buf == NULL)
  1061. return NULL;
  1062. os_memcpy(buf, "hash:", 5);
  1063. wpa_snprintf_hex(buf + 5, 32 + 1, ssid->eap.password, 16);
  1064. return buf;
  1065. }
  1066. #endif /* IEEE8021X_EAPOL */
  1067. static int wpa_config_parse_wep_key(u8 *key, size_t *len, int line,
  1068. const char *value, int idx)
  1069. {
  1070. char *buf, title[20];
  1071. int res;
  1072. buf = wpa_config_parse_string(value, len);
  1073. if (buf == NULL) {
  1074. wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key %d '%s'.",
  1075. line, idx, value);
  1076. return -1;
  1077. }
  1078. if (*len > MAX_WEP_KEY_LEN) {
  1079. wpa_printf(MSG_ERROR, "Line %d: Too long WEP key %d '%s'.",
  1080. line, idx, value);
  1081. os_free(buf);
  1082. return -1;
  1083. }
  1084. if (*len && *len != 5 && *len != 13 && *len != 16) {
  1085. wpa_printf(MSG_ERROR, "Line %d: Invalid WEP key length %u - "
  1086. "this network block will be ignored",
  1087. line, (unsigned int) *len);
  1088. }
  1089. os_memcpy(key, buf, *len);
  1090. os_free(buf);
  1091. res = os_snprintf(title, sizeof(title), "wep_key%d", idx);
  1092. if (res >= 0 && (size_t) res < sizeof(title))
  1093. wpa_hexdump_key(MSG_MSGDUMP, title, key, *len);
  1094. return 0;
  1095. }
  1096. static int wpa_config_parse_wep_key0(const struct parse_data *data,
  1097. struct wpa_ssid *ssid, int line,
  1098. const char *value)
  1099. {
  1100. return wpa_config_parse_wep_key(ssid->wep_key[0],
  1101. &ssid->wep_key_len[0], line,
  1102. value, 0);
  1103. }
  1104. static int wpa_config_parse_wep_key1(const struct parse_data *data,
  1105. struct wpa_ssid *ssid, int line,
  1106. const char *value)
  1107. {
  1108. return wpa_config_parse_wep_key(ssid->wep_key[1],
  1109. &ssid->wep_key_len[1], line,
  1110. value, 1);
  1111. }
  1112. static int wpa_config_parse_wep_key2(const struct parse_data *data,
  1113. struct wpa_ssid *ssid, int line,
  1114. const char *value)
  1115. {
  1116. return wpa_config_parse_wep_key(ssid->wep_key[2],
  1117. &ssid->wep_key_len[2], line,
  1118. value, 2);
  1119. }
  1120. static int wpa_config_parse_wep_key3(const struct parse_data *data,
  1121. struct wpa_ssid *ssid, int line,
  1122. const char *value)
  1123. {
  1124. return wpa_config_parse_wep_key(ssid->wep_key[3],
  1125. &ssid->wep_key_len[3], line,
  1126. value, 3);
  1127. }
  1128. #ifndef NO_CONFIG_WRITE
  1129. static char * wpa_config_write_wep_key(struct wpa_ssid *ssid, int idx)
  1130. {
  1131. if (ssid->wep_key_len[idx] == 0)
  1132. return NULL;
  1133. return wpa_config_write_string(ssid->wep_key[idx],
  1134. ssid->wep_key_len[idx]);
  1135. }
  1136. static char * wpa_config_write_wep_key0(const struct parse_data *data,
  1137. struct wpa_ssid *ssid)
  1138. {
  1139. return wpa_config_write_wep_key(ssid, 0);
  1140. }
  1141. static char * wpa_config_write_wep_key1(const struct parse_data *data,
  1142. struct wpa_ssid *ssid)
  1143. {
  1144. return wpa_config_write_wep_key(ssid, 1);
  1145. }
  1146. static char * wpa_config_write_wep_key2(const struct parse_data *data,
  1147. struct wpa_ssid *ssid)
  1148. {
  1149. return wpa_config_write_wep_key(ssid, 2);
  1150. }
  1151. static char * wpa_config_write_wep_key3(const struct parse_data *data,
  1152. struct wpa_ssid *ssid)
  1153. {
  1154. return wpa_config_write_wep_key(ssid, 3);
  1155. }
  1156. #endif /* NO_CONFIG_WRITE */
  1157. #ifdef CONFIG_P2P
  1158. static int wpa_config_parse_p2p_client_list(const struct parse_data *data,
  1159. struct wpa_ssid *ssid, int line,
  1160. const char *value)
  1161. {
  1162. const char *pos;
  1163. u8 *buf, *n, addr[ETH_ALEN];
  1164. size_t count;
  1165. buf = NULL;
  1166. count = 0;
  1167. pos = value;
  1168. while (pos && *pos) {
  1169. while (*pos == ' ')
  1170. pos++;
  1171. if (hwaddr_aton(pos, addr)) {
  1172. if (count == 0) {
  1173. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1174. "p2p_client_list address '%s'.",
  1175. line, value);
  1176. os_free(buf);
  1177. return -1;
  1178. }
  1179. /* continue anyway since this could have been from a
  1180. * truncated configuration file line */
  1181. wpa_printf(MSG_INFO, "Line %d: Ignore likely "
  1182. "truncated p2p_client_list address '%s'",
  1183. line, pos);
  1184. } else {
  1185. n = os_realloc_array(buf, count + 1, ETH_ALEN);
  1186. if (n == NULL) {
  1187. os_free(buf);
  1188. return -1;
  1189. }
  1190. buf = n;
  1191. os_memmove(buf + ETH_ALEN, buf, count * ETH_ALEN);
  1192. os_memcpy(buf, addr, ETH_ALEN);
  1193. count++;
  1194. wpa_hexdump(MSG_MSGDUMP, "p2p_client_list",
  1195. addr, ETH_ALEN);
  1196. }
  1197. pos = os_strchr(pos, ' ');
  1198. }
  1199. os_free(ssid->p2p_client_list);
  1200. ssid->p2p_client_list = buf;
  1201. ssid->num_p2p_clients = count;
  1202. return 0;
  1203. }
  1204. #ifndef NO_CONFIG_WRITE
  1205. static char * wpa_config_write_p2p_client_list(const struct parse_data *data,
  1206. struct wpa_ssid *ssid)
  1207. {
  1208. char *value, *end, *pos;
  1209. int res;
  1210. size_t i;
  1211. if (ssid->p2p_client_list == NULL || ssid->num_p2p_clients == 0)
  1212. return NULL;
  1213. value = os_malloc(20 * ssid->num_p2p_clients);
  1214. if (value == NULL)
  1215. return NULL;
  1216. pos = value;
  1217. end = value + 20 * ssid->num_p2p_clients;
  1218. for (i = ssid->num_p2p_clients; i > 0; i--) {
  1219. res = os_snprintf(pos, end - pos, MACSTR " ",
  1220. MAC2STR(ssid->p2p_client_list +
  1221. (i - 1) * ETH_ALEN));
  1222. if (res < 0 || res >= end - pos) {
  1223. os_free(value);
  1224. return NULL;
  1225. }
  1226. pos += res;
  1227. }
  1228. if (pos > value)
  1229. pos[-1] = '\0';
  1230. return value;
  1231. }
  1232. #endif /* NO_CONFIG_WRITE */
  1233. #endif /* CONFIG_P2P */
  1234. /* Helper macros for network block parser */
  1235. #ifdef OFFSET
  1236. #undef OFFSET
  1237. #endif /* OFFSET */
  1238. /* OFFSET: Get offset of a variable within the wpa_ssid structure */
  1239. #define OFFSET(v) ((void *) &((struct wpa_ssid *) 0)->v)
  1240. /* STR: Define a string variable for an ASCII string; f = field name */
  1241. #ifdef NO_CONFIG_WRITE
  1242. #define _STR(f) #f, wpa_config_parse_str, OFFSET(f)
  1243. #define _STRe(f) #f, wpa_config_parse_str, OFFSET(eap.f)
  1244. #else /* NO_CONFIG_WRITE */
  1245. #define _STR(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(f)
  1246. #define _STRe(f) #f, wpa_config_parse_str, wpa_config_write_str, OFFSET(eap.f)
  1247. #endif /* NO_CONFIG_WRITE */
  1248. #define STR(f) _STR(f), NULL, NULL, NULL, 0
  1249. #define STRe(f) _STRe(f), NULL, NULL, NULL, 0
  1250. #define STR_KEY(f) _STR(f), NULL, NULL, NULL, 1
  1251. #define STR_KEYe(f) _STRe(f), NULL, NULL, NULL, 1
  1252. /* STR_LEN: Define a string variable with a separate variable for storing the
  1253. * data length. Unlike STR(), this can be used to store arbitrary binary data
  1254. * (i.e., even nul termination character). */
  1255. #define _STR_LEN(f) _STR(f), OFFSET(f ## _len)
  1256. #define _STR_LENe(f) _STRe(f), OFFSET(eap.f ## _len)
  1257. #define STR_LEN(f) _STR_LEN(f), NULL, NULL, 0
  1258. #define STR_LENe(f) _STR_LENe(f), NULL, NULL, 0
  1259. #define STR_LEN_KEY(f) _STR_LEN(f), NULL, NULL, 1
  1260. /* STR_RANGE: Like STR_LEN(), but with minimum and maximum allowed length
  1261. * explicitly specified. */
  1262. #define _STR_RANGE(f, min, max) _STR_LEN(f), (void *) (min), (void *) (max)
  1263. #define STR_RANGE(f, min, max) _STR_RANGE(f, min, max), 0
  1264. #define STR_RANGE_KEY(f, min, max) _STR_RANGE(f, min, max), 1
  1265. #ifdef NO_CONFIG_WRITE
  1266. #define _INT(f) #f, wpa_config_parse_int, OFFSET(f), (void *) 0
  1267. #define _INTe(f) #f, wpa_config_parse_int, OFFSET(eap.f), (void *) 0
  1268. #else /* NO_CONFIG_WRITE */
  1269. #define _INT(f) #f, wpa_config_parse_int, wpa_config_write_int, \
  1270. OFFSET(f), (void *) 0
  1271. #define _INTe(f) #f, wpa_config_parse_int, wpa_config_write_int, \
  1272. OFFSET(eap.f), (void *) 0
  1273. #endif /* NO_CONFIG_WRITE */
  1274. /* INT: Define an integer variable */
  1275. #define INT(f) _INT(f), NULL, NULL, 0
  1276. #define INTe(f) _INTe(f), NULL, NULL, 0
  1277. /* INT_RANGE: Define an integer variable with allowed value range */
  1278. #define INT_RANGE(f, min, max) _INT(f), (void *) (min), (void *) (max), 0
  1279. /* FUNC: Define a configuration variable that uses a custom function for
  1280. * parsing and writing the value. */
  1281. #ifdef NO_CONFIG_WRITE
  1282. #define _FUNC(f) #f, wpa_config_parse_ ## f, NULL, NULL, NULL, NULL
  1283. #else /* NO_CONFIG_WRITE */
  1284. #define _FUNC(f) #f, wpa_config_parse_ ## f, wpa_config_write_ ## f, \
  1285. NULL, NULL, NULL, NULL
  1286. #endif /* NO_CONFIG_WRITE */
  1287. #define FUNC(f) _FUNC(f), 0
  1288. #define FUNC_KEY(f) _FUNC(f), 1
  1289. /*
  1290. * Table of network configuration variables. This table is used to parse each
  1291. * network configuration variable, e.g., each line in wpa_supplicant.conf file
  1292. * that is inside a network block.
  1293. *
  1294. * This table is generated using the helper macros defined above and with
  1295. * generous help from the C pre-processor. The field name is stored as a string
  1296. * into .name and for STR and INT types, the offset of the target buffer within
  1297. * struct wpa_ssid is stored in .param1. .param2 (if not NULL) is similar
  1298. * offset to the field containing the length of the configuration variable.
  1299. * .param3 and .param4 can be used to mark the allowed range (length for STR
  1300. * and value for INT).
  1301. *
  1302. * For each configuration line in wpa_supplicant.conf, the parser goes through
  1303. * this table and select the entry that matches with the field name. The parser
  1304. * function (.parser) is then called to parse the actual value of the field.
  1305. *
  1306. * This kind of mechanism makes it easy to add new configuration parameters,
  1307. * since only one line needs to be added into this table and into the
  1308. * struct wpa_ssid definition if the new variable is either a string or
  1309. * integer. More complex types will need to use their own parser and writer
  1310. * functions.
  1311. */
  1312. static const struct parse_data ssid_fields[] = {
  1313. { STR_RANGE(ssid, 0, MAX_SSID_LEN) },
  1314. { INT_RANGE(scan_ssid, 0, 1) },
  1315. { FUNC(bssid) },
  1316. { FUNC_KEY(psk) },
  1317. { FUNC(proto) },
  1318. { FUNC(key_mgmt) },
  1319. { INT(bg_scan_period) },
  1320. { FUNC(pairwise) },
  1321. { FUNC(group) },
  1322. { FUNC(auth_alg) },
  1323. { FUNC(scan_freq) },
  1324. { FUNC(freq_list) },
  1325. #ifdef IEEE8021X_EAPOL
  1326. { FUNC(eap) },
  1327. { STR_LENe(identity) },
  1328. { STR_LENe(anonymous_identity) },
  1329. { FUNC_KEY(password) },
  1330. { STRe(ca_cert) },
  1331. { STRe(ca_path) },
  1332. { STRe(client_cert) },
  1333. { STRe(private_key) },
  1334. { STR_KEYe(private_key_passwd) },
  1335. { STRe(dh_file) },
  1336. { STRe(subject_match) },
  1337. { STRe(altsubject_match) },
  1338. { STRe(ca_cert2) },
  1339. { STRe(ca_path2) },
  1340. { STRe(client_cert2) },
  1341. { STRe(private_key2) },
  1342. { STR_KEYe(private_key2_passwd) },
  1343. { STRe(dh_file2) },
  1344. { STRe(subject_match2) },
  1345. { STRe(altsubject_match2) },
  1346. { STRe(phase1) },
  1347. { STRe(phase2) },
  1348. { STRe(pcsc) },
  1349. { STR_KEYe(pin) },
  1350. { STRe(engine_id) },
  1351. { STRe(key_id) },
  1352. { STRe(cert_id) },
  1353. { STRe(ca_cert_id) },
  1354. { STR_KEYe(pin2) },
  1355. { STRe(engine2_id) },
  1356. { STRe(key2_id) },
  1357. { STRe(cert2_id) },
  1358. { STRe(ca_cert2_id) },
  1359. { INTe(engine) },
  1360. { INTe(engine2) },
  1361. { INT(eapol_flags) },
  1362. #endif /* IEEE8021X_EAPOL */
  1363. { FUNC_KEY(wep_key0) },
  1364. { FUNC_KEY(wep_key1) },
  1365. { FUNC_KEY(wep_key2) },
  1366. { FUNC_KEY(wep_key3) },
  1367. { INT(wep_tx_keyidx) },
  1368. { INT(priority) },
  1369. #ifdef IEEE8021X_EAPOL
  1370. { INT(eap_workaround) },
  1371. { STRe(pac_file) },
  1372. { INTe(fragment_size) },
  1373. #endif /* IEEE8021X_EAPOL */
  1374. { INT_RANGE(mode, 0, 4) },
  1375. { INT_RANGE(proactive_key_caching, 0, 1) },
  1376. { INT_RANGE(disabled, 0, 2) },
  1377. { STR(id_str) },
  1378. #ifdef CONFIG_IEEE80211W
  1379. { INT_RANGE(ieee80211w, 0, 2) },
  1380. #endif /* CONFIG_IEEE80211W */
  1381. { INT_RANGE(peerkey, 0, 1) },
  1382. { INT_RANGE(mixed_cell, 0, 1) },
  1383. { INT_RANGE(frequency, 0, 65000) },
  1384. { INT(wpa_ptk_rekey) },
  1385. { STR(bgscan) },
  1386. { INT_RANGE(ignore_broadcast_ssid, 0, 2) },
  1387. #ifdef CONFIG_P2P
  1388. { FUNC(p2p_client_list) },
  1389. #endif /* CONFIG_P2P */
  1390. #ifdef CONFIG_HT_OVERRIDES
  1391. { INT_RANGE(disable_ht, 0, 1) },
  1392. { INT_RANGE(disable_ht40, -1, 1) },
  1393. { INT_RANGE(disable_sgi, 0, 1) },
  1394. { INT_RANGE(disable_max_amsdu, -1, 1) },
  1395. { INT_RANGE(ampdu_factor, -1, 3) },
  1396. { INT_RANGE(ampdu_density, -1, 7) },
  1397. { STR(ht_mcs) },
  1398. #endif /* CONFIG_HT_OVERRIDES */
  1399. { INT(ap_max_inactivity) },
  1400. { INT(dtim_period) },
  1401. };
  1402. #undef OFFSET
  1403. #undef _STR
  1404. #undef STR
  1405. #undef STR_KEY
  1406. #undef _STR_LEN
  1407. #undef STR_LEN
  1408. #undef STR_LEN_KEY
  1409. #undef _STR_RANGE
  1410. #undef STR_RANGE
  1411. #undef STR_RANGE_KEY
  1412. #undef _INT
  1413. #undef INT
  1414. #undef INT_RANGE
  1415. #undef _FUNC
  1416. #undef FUNC
  1417. #undef FUNC_KEY
  1418. #define NUM_SSID_FIELDS (sizeof(ssid_fields) / sizeof(ssid_fields[0]))
  1419. /**
  1420. * wpa_config_add_prio_network - Add a network to priority lists
  1421. * @config: Configuration data from wpa_config_read()
  1422. * @ssid: Pointer to the network configuration to be added to the list
  1423. * Returns: 0 on success, -1 on failure
  1424. *
  1425. * This function is used to add a network block to the priority list of
  1426. * networks. This must be called for each network when reading in the full
  1427. * configuration. In addition, this can be used indirectly when updating
  1428. * priorities by calling wpa_config_update_prio_list().
  1429. */
  1430. int wpa_config_add_prio_network(struct wpa_config *config,
  1431. struct wpa_ssid *ssid)
  1432. {
  1433. int prio;
  1434. struct wpa_ssid *prev, **nlist;
  1435. /*
  1436. * Add to an existing priority list if one is available for the
  1437. * configured priority level for this network.
  1438. */
  1439. for (prio = 0; prio < config->num_prio; prio++) {
  1440. prev = config->pssid[prio];
  1441. if (prev->priority == ssid->priority) {
  1442. while (prev->pnext)
  1443. prev = prev->pnext;
  1444. prev->pnext = ssid;
  1445. return 0;
  1446. }
  1447. }
  1448. /* First network for this priority - add a new priority list */
  1449. nlist = os_realloc_array(config->pssid, config->num_prio + 1,
  1450. sizeof(struct wpa_ssid *));
  1451. if (nlist == NULL)
  1452. return -1;
  1453. for (prio = 0; prio < config->num_prio; prio++) {
  1454. if (nlist[prio]->priority < ssid->priority) {
  1455. os_memmove(&nlist[prio + 1], &nlist[prio],
  1456. (config->num_prio - prio) *
  1457. sizeof(struct wpa_ssid *));
  1458. break;
  1459. }
  1460. }
  1461. nlist[prio] = ssid;
  1462. config->num_prio++;
  1463. config->pssid = nlist;
  1464. return 0;
  1465. }
  1466. /**
  1467. * wpa_config_update_prio_list - Update network priority list
  1468. * @config: Configuration data from wpa_config_read()
  1469. * Returns: 0 on success, -1 on failure
  1470. *
  1471. * This function is called to update the priority list of networks in the
  1472. * configuration when a network is being added or removed. This is also called
  1473. * if a priority for a network is changed.
  1474. */
  1475. int wpa_config_update_prio_list(struct wpa_config *config)
  1476. {
  1477. struct wpa_ssid *ssid;
  1478. int ret = 0;
  1479. os_free(config->pssid);
  1480. config->pssid = NULL;
  1481. config->num_prio = 0;
  1482. ssid = config->ssid;
  1483. while (ssid) {
  1484. ssid->pnext = NULL;
  1485. if (wpa_config_add_prio_network(config, ssid) < 0)
  1486. ret = -1;
  1487. ssid = ssid->next;
  1488. }
  1489. return ret;
  1490. }
  1491. #ifdef IEEE8021X_EAPOL
  1492. static void eap_peer_config_free(struct eap_peer_config *eap)
  1493. {
  1494. os_free(eap->eap_methods);
  1495. os_free(eap->identity);
  1496. os_free(eap->anonymous_identity);
  1497. os_free(eap->password);
  1498. os_free(eap->ca_cert);
  1499. os_free(eap->ca_path);
  1500. os_free(eap->client_cert);
  1501. os_free(eap->private_key);
  1502. os_free(eap->private_key_passwd);
  1503. os_free(eap->dh_file);
  1504. os_free(eap->subject_match);
  1505. os_free(eap->altsubject_match);
  1506. os_free(eap->ca_cert2);
  1507. os_free(eap->ca_path2);
  1508. os_free(eap->client_cert2);
  1509. os_free(eap->private_key2);
  1510. os_free(eap->private_key2_passwd);
  1511. os_free(eap->dh_file2);
  1512. os_free(eap->subject_match2);
  1513. os_free(eap->altsubject_match2);
  1514. os_free(eap->phase1);
  1515. os_free(eap->phase2);
  1516. os_free(eap->pcsc);
  1517. os_free(eap->pin);
  1518. os_free(eap->engine_id);
  1519. os_free(eap->key_id);
  1520. os_free(eap->cert_id);
  1521. os_free(eap->ca_cert_id);
  1522. os_free(eap->key2_id);
  1523. os_free(eap->cert2_id);
  1524. os_free(eap->ca_cert2_id);
  1525. os_free(eap->pin2);
  1526. os_free(eap->engine2_id);
  1527. os_free(eap->otp);
  1528. os_free(eap->pending_req_otp);
  1529. os_free(eap->pac_file);
  1530. os_free(eap->new_password);
  1531. }
  1532. #endif /* IEEE8021X_EAPOL */
  1533. /**
  1534. * wpa_config_free_ssid - Free network/ssid configuration data
  1535. * @ssid: Configuration data for the network
  1536. *
  1537. * This function frees all resources allocated for the network configuration
  1538. * data.
  1539. */
  1540. void wpa_config_free_ssid(struct wpa_ssid *ssid)
  1541. {
  1542. os_free(ssid->ssid);
  1543. os_free(ssid->passphrase);
  1544. os_free(ssid->ext_psk);
  1545. #ifdef IEEE8021X_EAPOL
  1546. eap_peer_config_free(&ssid->eap);
  1547. #endif /* IEEE8021X_EAPOL */
  1548. os_free(ssid->id_str);
  1549. os_free(ssid->scan_freq);
  1550. os_free(ssid->freq_list);
  1551. os_free(ssid->bgscan);
  1552. os_free(ssid->p2p_client_list);
  1553. #ifdef CONFIG_HT_OVERRIDES
  1554. os_free(ssid->ht_mcs);
  1555. #endif /* CONFIG_HT_OVERRIDES */
  1556. os_free(ssid);
  1557. }
  1558. void wpa_config_free_cred(struct wpa_cred *cred)
  1559. {
  1560. os_free(cred->realm);
  1561. os_free(cred->username);
  1562. os_free(cred->password);
  1563. os_free(cred->ca_cert);
  1564. os_free(cred->client_cert);
  1565. os_free(cred->private_key);
  1566. os_free(cred->private_key_passwd);
  1567. os_free(cred->imsi);
  1568. os_free(cred->milenage);
  1569. os_free(cred->domain);
  1570. os_free(cred->eap_method);
  1571. os_free(cred->phase1);
  1572. os_free(cred->phase2);
  1573. os_free(cred->excluded_ssid);
  1574. os_free(cred);
  1575. }
  1576. /**
  1577. * wpa_config_free - Free configuration data
  1578. * @config: Configuration data from wpa_config_read()
  1579. *
  1580. * This function frees all resources allocated for the configuration data by
  1581. * wpa_config_read().
  1582. */
  1583. void wpa_config_free(struct wpa_config *config)
  1584. {
  1585. #ifndef CONFIG_NO_CONFIG_BLOBS
  1586. struct wpa_config_blob *blob, *prevblob;
  1587. #endif /* CONFIG_NO_CONFIG_BLOBS */
  1588. struct wpa_ssid *ssid, *prev = NULL;
  1589. struct wpa_cred *cred, *cprev;
  1590. ssid = config->ssid;
  1591. while (ssid) {
  1592. prev = ssid;
  1593. ssid = ssid->next;
  1594. wpa_config_free_ssid(prev);
  1595. }
  1596. cred = config->cred;
  1597. while (cred) {
  1598. cprev = cred;
  1599. cred = cred->next;
  1600. wpa_config_free_cred(cprev);
  1601. }
  1602. #ifndef CONFIG_NO_CONFIG_BLOBS
  1603. blob = config->blobs;
  1604. prevblob = NULL;
  1605. while (blob) {
  1606. prevblob = blob;
  1607. blob = blob->next;
  1608. wpa_config_free_blob(prevblob);
  1609. }
  1610. #endif /* CONFIG_NO_CONFIG_BLOBS */
  1611. wpabuf_free(config->wps_vendor_ext_m1);
  1612. os_free(config->ctrl_interface);
  1613. os_free(config->ctrl_interface_group);
  1614. os_free(config->opensc_engine_path);
  1615. os_free(config->pkcs11_engine_path);
  1616. os_free(config->pkcs11_module_path);
  1617. os_free(config->pcsc_reader);
  1618. os_free(config->pcsc_pin);
  1619. os_free(config->driver_param);
  1620. os_free(config->device_name);
  1621. os_free(config->manufacturer);
  1622. os_free(config->model_name);
  1623. os_free(config->model_number);
  1624. os_free(config->serial_number);
  1625. os_free(config->config_methods);
  1626. os_free(config->p2p_ssid_postfix);
  1627. os_free(config->pssid);
  1628. os_free(config->p2p_pref_chan);
  1629. os_free(config->autoscan);
  1630. wpabuf_free(config->wps_nfc_dh_pubkey);
  1631. wpabuf_free(config->wps_nfc_dh_privkey);
  1632. wpabuf_free(config->wps_nfc_dev_pw);
  1633. os_free(config->ext_password_backend);
  1634. os_free(config->sae_groups);
  1635. os_free(config);
  1636. }
  1637. /**
  1638. * wpa_config_foreach_network - Iterate over each configured network
  1639. * @config: Configuration data from wpa_config_read()
  1640. * @func: Callback function to process each network
  1641. * @arg: Opaque argument to pass to callback function
  1642. *
  1643. * Iterate over the set of configured networks calling the specified
  1644. * function for each item. We guard against callbacks removing the
  1645. * supplied network.
  1646. */
  1647. void wpa_config_foreach_network(struct wpa_config *config,
  1648. void (*func)(void *, struct wpa_ssid *),
  1649. void *arg)
  1650. {
  1651. struct wpa_ssid *ssid, *next;
  1652. ssid = config->ssid;
  1653. while (ssid) {
  1654. next = ssid->next;
  1655. func(arg, ssid);
  1656. ssid = next;
  1657. }
  1658. }
  1659. /**
  1660. * wpa_config_get_network - Get configured network based on id
  1661. * @config: Configuration data from wpa_config_read()
  1662. * @id: Unique network id to search for
  1663. * Returns: Network configuration or %NULL if not found
  1664. */
  1665. struct wpa_ssid * wpa_config_get_network(struct wpa_config *config, int id)
  1666. {
  1667. struct wpa_ssid *ssid;
  1668. ssid = config->ssid;
  1669. while (ssid) {
  1670. if (id == ssid->id)
  1671. break;
  1672. ssid = ssid->next;
  1673. }
  1674. return ssid;
  1675. }
  1676. /**
  1677. * wpa_config_add_network - Add a new network with empty configuration
  1678. * @config: Configuration data from wpa_config_read()
  1679. * Returns: The new network configuration or %NULL if operation failed
  1680. */
  1681. struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)
  1682. {
  1683. int id;
  1684. struct wpa_ssid *ssid, *last = NULL;
  1685. id = -1;
  1686. ssid = config->ssid;
  1687. while (ssid) {
  1688. if (ssid->id > id)
  1689. id = ssid->id;
  1690. last = ssid;
  1691. ssid = ssid->next;
  1692. }
  1693. id++;
  1694. ssid = os_zalloc(sizeof(*ssid));
  1695. if (ssid == NULL)
  1696. return NULL;
  1697. ssid->id = id;
  1698. if (last)
  1699. last->next = ssid;
  1700. else
  1701. config->ssid = ssid;
  1702. wpa_config_update_prio_list(config);
  1703. return ssid;
  1704. }
  1705. /**
  1706. * wpa_config_remove_network - Remove a configured network based on id
  1707. * @config: Configuration data from wpa_config_read()
  1708. * @id: Unique network id to search for
  1709. * Returns: 0 on success, or -1 if the network was not found
  1710. */
  1711. int wpa_config_remove_network(struct wpa_config *config, int id)
  1712. {
  1713. struct wpa_ssid *ssid, *prev = NULL;
  1714. ssid = config->ssid;
  1715. while (ssid) {
  1716. if (id == ssid->id)
  1717. break;
  1718. prev = ssid;
  1719. ssid = ssid->next;
  1720. }
  1721. if (ssid == NULL)
  1722. return -1;
  1723. if (prev)
  1724. prev->next = ssid->next;
  1725. else
  1726. config->ssid = ssid->next;
  1727. wpa_config_update_prio_list(config);
  1728. wpa_config_free_ssid(ssid);
  1729. return 0;
  1730. }
  1731. /**
  1732. * wpa_config_set_network_defaults - Set network default values
  1733. * @ssid: Pointer to network configuration data
  1734. */
  1735. void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
  1736. {
  1737. ssid->proto = DEFAULT_PROTO;
  1738. ssid->pairwise_cipher = DEFAULT_PAIRWISE;
  1739. ssid->group_cipher = DEFAULT_GROUP;
  1740. ssid->key_mgmt = DEFAULT_KEY_MGMT;
  1741. ssid->bg_scan_period = DEFAULT_BG_SCAN_PERIOD;
  1742. #ifdef IEEE8021X_EAPOL
  1743. ssid->eapol_flags = DEFAULT_EAPOL_FLAGS;
  1744. ssid->eap_workaround = DEFAULT_EAP_WORKAROUND;
  1745. ssid->eap.fragment_size = DEFAULT_FRAGMENT_SIZE;
  1746. #endif /* IEEE8021X_EAPOL */
  1747. #ifdef CONFIG_HT_OVERRIDES
  1748. ssid->disable_ht = DEFAULT_DISABLE_HT;
  1749. ssid->disable_ht40 = DEFAULT_DISABLE_HT40;
  1750. ssid->disable_sgi = DEFAULT_DISABLE_SGI;
  1751. ssid->disable_max_amsdu = DEFAULT_DISABLE_MAX_AMSDU;
  1752. ssid->ampdu_factor = DEFAULT_AMPDU_FACTOR;
  1753. ssid->ampdu_density = DEFAULT_AMPDU_DENSITY;
  1754. #endif /* CONFIG_HT_OVERRIDES */
  1755. ssid->proactive_key_caching = -1;
  1756. #ifdef CONFIG_IEEE80211W
  1757. ssid->ieee80211w = MGMT_FRAME_PROTECTION_DEFAULT;
  1758. #endif /* CONFIG_IEEE80211W */
  1759. }
  1760. /**
  1761. * wpa_config_set - Set a variable in network configuration
  1762. * @ssid: Pointer to network configuration data
  1763. * @var: Variable name, e.g., "ssid"
  1764. * @value: Variable value
  1765. * @line: Line number in configuration file or 0 if not used
  1766. * Returns: 0 on success, -1 on failure
  1767. *
  1768. * This function can be used to set network configuration variables based on
  1769. * both the configuration file and management interface input. The value
  1770. * parameter must be in the same format as the text-based configuration file is
  1771. * using. For example, strings are using double quotation marks.
  1772. */
  1773. int wpa_config_set(struct wpa_ssid *ssid, const char *var, const char *value,
  1774. int line)
  1775. {
  1776. size_t i;
  1777. int ret = 0;
  1778. if (ssid == NULL || var == NULL || value == NULL)
  1779. return -1;
  1780. for (i = 0; i < NUM_SSID_FIELDS; i++) {
  1781. const struct parse_data *field = &ssid_fields[i];
  1782. if (os_strcmp(var, field->name) != 0)
  1783. continue;
  1784. if (field->parser(field, ssid, line, value)) {
  1785. if (line) {
  1786. wpa_printf(MSG_ERROR, "Line %d: failed to "
  1787. "parse %s '%s'.", line, var, value);
  1788. }
  1789. ret = -1;
  1790. }
  1791. break;
  1792. }
  1793. if (i == NUM_SSID_FIELDS) {
  1794. if (line) {
  1795. wpa_printf(MSG_ERROR, "Line %d: unknown network field "
  1796. "'%s'.", line, var);
  1797. }
  1798. ret = -1;
  1799. }
  1800. return ret;
  1801. }
  1802. int wpa_config_set_quoted(struct wpa_ssid *ssid, const char *var,
  1803. const char *value)
  1804. {
  1805. size_t len;
  1806. char *buf;
  1807. int ret;
  1808. len = os_strlen(value);
  1809. buf = os_malloc(len + 3);
  1810. if (buf == NULL)
  1811. return -1;
  1812. buf[0] = '"';
  1813. os_memcpy(buf + 1, value, len);
  1814. buf[len + 1] = '"';
  1815. buf[len + 2] = '\0';
  1816. ret = wpa_config_set(ssid, var, buf, 0);
  1817. os_free(buf);
  1818. return ret;
  1819. }
  1820. /**
  1821. * wpa_config_get_all - Get all options from network configuration
  1822. * @ssid: Pointer to network configuration data
  1823. * @get_keys: Determines if keys/passwords will be included in returned list
  1824. * (if they may be exported)
  1825. * Returns: %NULL terminated list of all set keys and their values in the form
  1826. * of [key1, val1, key2, val2, ... , NULL]
  1827. *
  1828. * This function can be used to get list of all configured network properties.
  1829. * The caller is responsible for freeing the returned list and all its
  1830. * elements.
  1831. */
  1832. char ** wpa_config_get_all(struct wpa_ssid *ssid, int get_keys)
  1833. {
  1834. const struct parse_data *field;
  1835. char *key, *value;
  1836. size_t i;
  1837. char **props;
  1838. int fields_num;
  1839. get_keys = get_keys && ssid->export_keys;
  1840. props = os_calloc(2 * NUM_SSID_FIELDS + 1, sizeof(char *));
  1841. if (!props)
  1842. return NULL;
  1843. fields_num = 0;
  1844. for (i = 0; i < NUM_SSID_FIELDS; i++) {
  1845. field = &ssid_fields[i];
  1846. if (field->key_data && !get_keys)
  1847. continue;
  1848. value = field->writer(field, ssid);
  1849. if (value == NULL)
  1850. continue;
  1851. if (os_strlen(value) == 0) {
  1852. os_free(value);
  1853. continue;
  1854. }
  1855. key = os_strdup(field->name);
  1856. if (key == NULL) {
  1857. os_free(value);
  1858. goto err;
  1859. }
  1860. props[fields_num * 2] = key;
  1861. props[fields_num * 2 + 1] = value;
  1862. fields_num++;
  1863. }
  1864. return props;
  1865. err:
  1866. value = *props;
  1867. while (value)
  1868. os_free(value++);
  1869. os_free(props);
  1870. return NULL;
  1871. }
  1872. #ifndef NO_CONFIG_WRITE
  1873. /**
  1874. * wpa_config_get - Get a variable in network configuration
  1875. * @ssid: Pointer to network configuration data
  1876. * @var: Variable name, e.g., "ssid"
  1877. * Returns: Value of the variable or %NULL on failure
  1878. *
  1879. * This function can be used to get network configuration variables. The
  1880. * returned value is a copy of the configuration variable in text format, i.e,.
  1881. * the same format that the text-based configuration file and wpa_config_set()
  1882. * are using for the value. The caller is responsible for freeing the returned
  1883. * value.
  1884. */
  1885. char * wpa_config_get(struct wpa_ssid *ssid, const char *var)
  1886. {
  1887. size_t i;
  1888. if (ssid == NULL || var == NULL)
  1889. return NULL;
  1890. for (i = 0; i < NUM_SSID_FIELDS; i++) {
  1891. const struct parse_data *field = &ssid_fields[i];
  1892. if (os_strcmp(var, field->name) == 0)
  1893. return field->writer(field, ssid);
  1894. }
  1895. return NULL;
  1896. }
  1897. /**
  1898. * wpa_config_get_no_key - Get a variable in network configuration (no keys)
  1899. * @ssid: Pointer to network configuration data
  1900. * @var: Variable name, e.g., "ssid"
  1901. * Returns: Value of the variable or %NULL on failure
  1902. *
  1903. * This function can be used to get network configuration variable like
  1904. * wpa_config_get(). The only difference is that this functions does not expose
  1905. * key/password material from the configuration. In case a key/password field
  1906. * is requested, the returned value is an empty string or %NULL if the variable
  1907. * is not set or "*" if the variable is set (regardless of its value). The
  1908. * returned value is a copy of the configuration variable in text format, i.e,.
  1909. * the same format that the text-based configuration file and wpa_config_set()
  1910. * are using for the value. The caller is responsible for freeing the returned
  1911. * value.
  1912. */
  1913. char * wpa_config_get_no_key(struct wpa_ssid *ssid, const char *var)
  1914. {
  1915. size_t i;
  1916. if (ssid == NULL || var == NULL)
  1917. return NULL;
  1918. for (i = 0; i < NUM_SSID_FIELDS; i++) {
  1919. const struct parse_data *field = &ssid_fields[i];
  1920. if (os_strcmp(var, field->name) == 0) {
  1921. char *res = field->writer(field, ssid);
  1922. if (field->key_data) {
  1923. if (res && res[0]) {
  1924. wpa_printf(MSG_DEBUG, "Do not allow "
  1925. "key_data field to be "
  1926. "exposed");
  1927. os_free(res);
  1928. return os_strdup("*");
  1929. }
  1930. os_free(res);
  1931. return NULL;
  1932. }
  1933. return res;
  1934. }
  1935. }
  1936. return NULL;
  1937. }
  1938. #endif /* NO_CONFIG_WRITE */
  1939. /**
  1940. * wpa_config_update_psk - Update WPA PSK based on passphrase and SSID
  1941. * @ssid: Pointer to network configuration data
  1942. *
  1943. * This function must be called to update WPA PSK when either SSID or the
  1944. * passphrase has changed for the network configuration.
  1945. */
  1946. void wpa_config_update_psk(struct wpa_ssid *ssid)
  1947. {
  1948. #ifndef CONFIG_NO_PBKDF2
  1949. pbkdf2_sha1(ssid->passphrase, ssid->ssid, ssid->ssid_len, 4096,
  1950. ssid->psk, PMK_LEN);
  1951. wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
  1952. ssid->psk, PMK_LEN);
  1953. ssid->psk_set = 1;
  1954. #endif /* CONFIG_NO_PBKDF2 */
  1955. }
  1956. int wpa_config_set_cred(struct wpa_cred *cred, const char *var,
  1957. const char *value, int line)
  1958. {
  1959. char *val;
  1960. size_t len;
  1961. if (os_strcmp(var, "priority") == 0) {
  1962. cred->priority = atoi(value);
  1963. return 0;
  1964. }
  1965. if (os_strcmp(var, "pcsc") == 0) {
  1966. cred->pcsc = atoi(value);
  1967. return 0;
  1968. }
  1969. if (os_strcmp(var, "eap") == 0) {
  1970. struct eap_method_type method;
  1971. method.method = eap_peer_get_type(value, &method.vendor);
  1972. if (method.vendor == EAP_VENDOR_IETF &&
  1973. method.method == EAP_TYPE_NONE) {
  1974. wpa_printf(MSG_ERROR, "Line %d: unknown EAP type '%s' "
  1975. "for a credential", line, value);
  1976. return -1;
  1977. }
  1978. os_free(cred->eap_method);
  1979. cred->eap_method = os_malloc(sizeof(*cred->eap_method));
  1980. if (cred->eap_method == NULL)
  1981. return -1;
  1982. os_memcpy(cred->eap_method, &method, sizeof(method));
  1983. return 0;
  1984. }
  1985. if (os_strcmp(var, "password") == 0 &&
  1986. os_strncmp(value, "ext:", 4) == 0) {
  1987. os_free(cred->password);
  1988. cred->password = os_strdup(value);
  1989. cred->ext_password = 1;
  1990. return 0;
  1991. }
  1992. val = wpa_config_parse_string(value, &len);
  1993. if (val == NULL) {
  1994. wpa_printf(MSG_ERROR, "Line %d: invalid field '%s' string "
  1995. "value '%s'.", line, var, value);
  1996. return -1;
  1997. }
  1998. if (os_strcmp(var, "realm") == 0) {
  1999. os_free(cred->realm);
  2000. cred->realm = val;
  2001. return 0;
  2002. }
  2003. if (os_strcmp(var, "username") == 0) {
  2004. os_free(cred->username);
  2005. cred->username = val;
  2006. return 0;
  2007. }
  2008. if (os_strcmp(var, "password") == 0) {
  2009. os_free(cred->password);
  2010. cred->password = val;
  2011. cred->ext_password = 0;
  2012. return 0;
  2013. }
  2014. if (os_strcmp(var, "ca_cert") == 0) {
  2015. os_free(cred->ca_cert);
  2016. cred->ca_cert = val;
  2017. return 0;
  2018. }
  2019. if (os_strcmp(var, "client_cert") == 0) {
  2020. os_free(cred->client_cert);
  2021. cred->client_cert = val;
  2022. return 0;
  2023. }
  2024. if (os_strcmp(var, "private_key") == 0) {
  2025. os_free(cred->private_key);
  2026. cred->private_key = val;
  2027. return 0;
  2028. }
  2029. if (os_strcmp(var, "private_key_passwd") == 0) {
  2030. os_free(cred->private_key_passwd);
  2031. cred->private_key_passwd = val;
  2032. return 0;
  2033. }
  2034. if (os_strcmp(var, "imsi") == 0) {
  2035. os_free(cred->imsi);
  2036. cred->imsi = val;
  2037. return 0;
  2038. }
  2039. if (os_strcmp(var, "milenage") == 0) {
  2040. os_free(cred->milenage);
  2041. cred->milenage = val;
  2042. return 0;
  2043. }
  2044. if (os_strcmp(var, "domain") == 0) {
  2045. os_free(cred->domain);
  2046. cred->domain = val;
  2047. return 0;
  2048. }
  2049. if (os_strcmp(var, "phase1") == 0) {
  2050. os_free(cred->phase1);
  2051. cred->phase1 = val;
  2052. return 0;
  2053. }
  2054. if (os_strcmp(var, "phase2") == 0) {
  2055. os_free(cred->phase2);
  2056. cred->phase2 = val;
  2057. return 0;
  2058. }
  2059. if (os_strcmp(var, "roaming_consortium") == 0) {
  2060. if (len < 3 || len > sizeof(cred->roaming_consortium)) {
  2061. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2062. "roaming_consortium length %d (3..15 "
  2063. "expected)", line, (int) len);
  2064. os_free(val);
  2065. return -1;
  2066. }
  2067. os_memcpy(cred->roaming_consortium, val, len);
  2068. cred->roaming_consortium_len = len;
  2069. os_free(val);
  2070. return 0;
  2071. }
  2072. if (os_strcmp(var, "excluded_ssid") == 0) {
  2073. struct excluded_ssid *e;
  2074. if (len > MAX_SSID_LEN) {
  2075. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2076. "excluded_ssid length %d", line, (int) len);
  2077. os_free(val);
  2078. return -1;
  2079. }
  2080. e = os_realloc_array(cred->excluded_ssid,
  2081. cred->num_excluded_ssid + 1,
  2082. sizeof(struct excluded_ssid));
  2083. if (e == NULL) {
  2084. os_free(val);
  2085. return -1;
  2086. }
  2087. cred->excluded_ssid = e;
  2088. e = &cred->excluded_ssid[cred->num_excluded_ssid++];
  2089. os_memcpy(e->ssid, val, len);
  2090. e->ssid_len = len;
  2091. os_free(val);
  2092. return 0;
  2093. }
  2094. if (line) {
  2095. wpa_printf(MSG_ERROR, "Line %d: unknown cred field '%s'.",
  2096. line, var);
  2097. }
  2098. os_free(val);
  2099. return -1;
  2100. }
  2101. struct wpa_cred * wpa_config_get_cred(struct wpa_config *config, int id)
  2102. {
  2103. struct wpa_cred *cred;
  2104. cred = config->cred;
  2105. while (cred) {
  2106. if (id == cred->id)
  2107. break;
  2108. cred = cred->next;
  2109. }
  2110. return cred;
  2111. }
  2112. struct wpa_cred * wpa_config_add_cred(struct wpa_config *config)
  2113. {
  2114. int id;
  2115. struct wpa_cred *cred, *last = NULL;
  2116. id = -1;
  2117. cred = config->cred;
  2118. while (cred) {
  2119. if (cred->id > id)
  2120. id = cred->id;
  2121. last = cred;
  2122. cred = cred->next;
  2123. }
  2124. id++;
  2125. cred = os_zalloc(sizeof(*cred));
  2126. if (cred == NULL)
  2127. return NULL;
  2128. cred->id = id;
  2129. if (last)
  2130. last->next = cred;
  2131. else
  2132. config->cred = cred;
  2133. return cred;
  2134. }
  2135. int wpa_config_remove_cred(struct wpa_config *config, int id)
  2136. {
  2137. struct wpa_cred *cred, *prev = NULL;
  2138. cred = config->cred;
  2139. while (cred) {
  2140. if (id == cred->id)
  2141. break;
  2142. prev = cred;
  2143. cred = cred->next;
  2144. }
  2145. if (cred == NULL)
  2146. return -1;
  2147. if (prev)
  2148. prev->next = cred->next;
  2149. else
  2150. config->cred = cred->next;
  2151. wpa_config_free_cred(cred);
  2152. return 0;
  2153. }
  2154. #ifndef CONFIG_NO_CONFIG_BLOBS
  2155. /**
  2156. * wpa_config_get_blob - Get a named configuration blob
  2157. * @config: Configuration data from wpa_config_read()
  2158. * @name: Name of the blob
  2159. * Returns: Pointer to blob data or %NULL if not found
  2160. */
  2161. const struct wpa_config_blob * wpa_config_get_blob(struct wpa_config *config,
  2162. const char *name)
  2163. {
  2164. struct wpa_config_blob *blob = config->blobs;
  2165. while (blob) {
  2166. if (os_strcmp(blob->name, name) == 0)
  2167. return blob;
  2168. blob = blob->next;
  2169. }
  2170. return NULL;
  2171. }
  2172. /**
  2173. * wpa_config_set_blob - Set or add a named configuration blob
  2174. * @config: Configuration data from wpa_config_read()
  2175. * @blob: New value for the blob
  2176. *
  2177. * Adds a new configuration blob or replaces the current value of an existing
  2178. * blob.
  2179. */
  2180. void wpa_config_set_blob(struct wpa_config *config,
  2181. struct wpa_config_blob *blob)
  2182. {
  2183. wpa_config_remove_blob(config, blob->name);
  2184. blob->next = config->blobs;
  2185. config->blobs = blob;
  2186. }
  2187. /**
  2188. * wpa_config_free_blob - Free blob data
  2189. * @blob: Pointer to blob to be freed
  2190. */
  2191. void wpa_config_free_blob(struct wpa_config_blob *blob)
  2192. {
  2193. if (blob) {
  2194. os_free(blob->name);
  2195. os_free(blob->data);
  2196. os_free(blob);
  2197. }
  2198. }
  2199. /**
  2200. * wpa_config_remove_blob - Remove a named configuration blob
  2201. * @config: Configuration data from wpa_config_read()
  2202. * @name: Name of the blob to remove
  2203. * Returns: 0 if blob was removed or -1 if blob was not found
  2204. */
  2205. int wpa_config_remove_blob(struct wpa_config *config, const char *name)
  2206. {
  2207. struct wpa_config_blob *pos = config->blobs, *prev = NULL;
  2208. while (pos) {
  2209. if (os_strcmp(pos->name, name) == 0) {
  2210. if (prev)
  2211. prev->next = pos->next;
  2212. else
  2213. config->blobs = pos->next;
  2214. wpa_config_free_blob(pos);
  2215. return 0;
  2216. }
  2217. prev = pos;
  2218. pos = pos->next;
  2219. }
  2220. return -1;
  2221. }
  2222. #endif /* CONFIG_NO_CONFIG_BLOBS */
  2223. /**
  2224. * wpa_config_alloc_empty - Allocate an empty configuration
  2225. * @ctrl_interface: Control interface parameters, e.g., path to UNIX domain
  2226. * socket
  2227. * @driver_param: Driver parameters
  2228. * Returns: Pointer to allocated configuration data or %NULL on failure
  2229. */
  2230. struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
  2231. const char *driver_param)
  2232. {
  2233. struct wpa_config *config;
  2234. const int aCWmin = 4, aCWmax = 10;
  2235. const struct hostapd_wmm_ac_params ac_bk =
  2236. { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
  2237. const struct hostapd_wmm_ac_params ac_be =
  2238. { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
  2239. const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
  2240. { aCWmin - 1, aCWmin, 2, 3000 / 32, 0 };
  2241. const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
  2242. { aCWmin - 2, aCWmin - 1, 2, 1500 / 32, 0 };
  2243. config = os_zalloc(sizeof(*config));
  2244. if (config == NULL)
  2245. return NULL;
  2246. config->eapol_version = DEFAULT_EAPOL_VERSION;
  2247. config->ap_scan = DEFAULT_AP_SCAN;
  2248. config->fast_reauth = DEFAULT_FAST_REAUTH;
  2249. config->p2p_go_intent = DEFAULT_P2P_GO_INTENT;
  2250. config->p2p_intra_bss = DEFAULT_P2P_INTRA_BSS;
  2251. config->p2p_go_max_inactivity = DEFAULT_P2P_GO_MAX_INACTIVITY;
  2252. config->bss_max_count = DEFAULT_BSS_MAX_COUNT;
  2253. config->bss_expiration_age = DEFAULT_BSS_EXPIRATION_AGE;
  2254. config->bss_expiration_scan_count = DEFAULT_BSS_EXPIRATION_SCAN_COUNT;
  2255. config->max_num_sta = DEFAULT_MAX_NUM_STA;
  2256. config->access_network_type = DEFAULT_ACCESS_NETWORK_TYPE;
  2257. config->wmm_ac_params[0] = ac_be;
  2258. config->wmm_ac_params[1] = ac_bk;
  2259. config->wmm_ac_params[2] = ac_vi;
  2260. config->wmm_ac_params[3] = ac_vo;
  2261. if (ctrl_interface)
  2262. config->ctrl_interface = os_strdup(ctrl_interface);
  2263. if (driver_param)
  2264. config->driver_param = os_strdup(driver_param);
  2265. return config;
  2266. }
  2267. #ifndef CONFIG_NO_STDOUT_DEBUG
  2268. /**
  2269. * wpa_config_debug_dump_networks - Debug dump of configured networks
  2270. * @config: Configuration data from wpa_config_read()
  2271. */
  2272. void wpa_config_debug_dump_networks(struct wpa_config *config)
  2273. {
  2274. int prio;
  2275. struct wpa_ssid *ssid;
  2276. for (prio = 0; prio < config->num_prio; prio++) {
  2277. ssid = config->pssid[prio];
  2278. wpa_printf(MSG_DEBUG, "Priority group %d",
  2279. ssid->priority);
  2280. while (ssid) {
  2281. wpa_printf(MSG_DEBUG, " id=%d ssid='%s'",
  2282. ssid->id,
  2283. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  2284. ssid = ssid->pnext;
  2285. }
  2286. }
  2287. }
  2288. #endif /* CONFIG_NO_STDOUT_DEBUG */
  2289. struct global_parse_data {
  2290. char *name;
  2291. int (*parser)(const struct global_parse_data *data,
  2292. struct wpa_config *config, int line, const char *value);
  2293. void *param1, *param2, *param3;
  2294. unsigned int changed_flag;
  2295. };
  2296. static int wpa_global_config_parse_int(const struct global_parse_data *data,
  2297. struct wpa_config *config, int line,
  2298. const char *pos)
  2299. {
  2300. int *dst;
  2301. dst = (int *) (((u8 *) config) + (long) data->param1);
  2302. *dst = atoi(pos);
  2303. wpa_printf(MSG_DEBUG, "%s=%d", data->name, *dst);
  2304. if (data->param2 && *dst < (long) data->param2) {
  2305. wpa_printf(MSG_ERROR, "Line %d: too small %s (value=%d "
  2306. "min_value=%ld)", line, data->name, *dst,
  2307. (long) data->param2);
  2308. *dst = (long) data->param2;
  2309. return -1;
  2310. }
  2311. if (data->param3 && *dst > (long) data->param3) {
  2312. wpa_printf(MSG_ERROR, "Line %d: too large %s (value=%d "
  2313. "max_value=%ld)", line, data->name, *dst,
  2314. (long) data->param3);
  2315. *dst = (long) data->param3;
  2316. return -1;
  2317. }
  2318. return 0;
  2319. }
  2320. static int wpa_global_config_parse_str(const struct global_parse_data *data,
  2321. struct wpa_config *config, int line,
  2322. const char *pos)
  2323. {
  2324. size_t len;
  2325. char **dst, *tmp;
  2326. len = os_strlen(pos);
  2327. if (data->param2 && len < (size_t) data->param2) {
  2328. wpa_printf(MSG_ERROR, "Line %d: too short %s (len=%lu "
  2329. "min_len=%ld)", line, data->name,
  2330. (unsigned long) len, (long) data->param2);
  2331. return -1;
  2332. }
  2333. if (data->param3 && len > (size_t) data->param3) {
  2334. wpa_printf(MSG_ERROR, "Line %d: too long %s (len=%lu "
  2335. "max_len=%ld)", line, data->name,
  2336. (unsigned long) len, (long) data->param3);
  2337. return -1;
  2338. }
  2339. tmp = os_strdup(pos);
  2340. if (tmp == NULL)
  2341. return -1;
  2342. dst = (char **) (((u8 *) config) + (long) data->param1);
  2343. os_free(*dst);
  2344. *dst = tmp;
  2345. wpa_printf(MSG_DEBUG, "%s='%s'", data->name, *dst);
  2346. return 0;
  2347. }
  2348. static int wpa_global_config_parse_bin(const struct global_parse_data *data,
  2349. struct wpa_config *config, int line,
  2350. const char *pos)
  2351. {
  2352. size_t len;
  2353. struct wpabuf **dst, *tmp;
  2354. len = os_strlen(pos);
  2355. if (len & 0x01)
  2356. return -1;
  2357. tmp = wpabuf_alloc(len / 2);
  2358. if (tmp == NULL)
  2359. return -1;
  2360. if (hexstr2bin(pos, wpabuf_put(tmp, len / 2), len / 2)) {
  2361. wpabuf_free(tmp);
  2362. return -1;
  2363. }
  2364. dst = (struct wpabuf **) (((u8 *) config) + (long) data->param1);
  2365. wpabuf_free(*dst);
  2366. *dst = tmp;
  2367. wpa_printf(MSG_DEBUG, "%s", data->name);
  2368. return 0;
  2369. }
  2370. static int wpa_config_process_country(const struct global_parse_data *data,
  2371. struct wpa_config *config, int line,
  2372. const char *pos)
  2373. {
  2374. if (!pos[0] || !pos[1]) {
  2375. wpa_printf(MSG_DEBUG, "Invalid country set");
  2376. return -1;
  2377. }
  2378. config->country[0] = pos[0];
  2379. config->country[1] = pos[1];
  2380. wpa_printf(MSG_DEBUG, "country='%c%c'",
  2381. config->country[0], config->country[1]);
  2382. return 0;
  2383. }
  2384. static int wpa_config_process_load_dynamic_eap(
  2385. const struct global_parse_data *data, struct wpa_config *config,
  2386. int line, const char *so)
  2387. {
  2388. int ret;
  2389. wpa_printf(MSG_DEBUG, "load_dynamic_eap=%s", so);
  2390. ret = eap_peer_method_load(so);
  2391. if (ret == -2) {
  2392. wpa_printf(MSG_DEBUG, "This EAP type was already loaded - not "
  2393. "reloading.");
  2394. } else if (ret) {
  2395. wpa_printf(MSG_ERROR, "Line %d: Failed to load dynamic EAP "
  2396. "method '%s'.", line, so);
  2397. return -1;
  2398. }
  2399. return 0;
  2400. }
  2401. #ifdef CONFIG_WPS
  2402. static int wpa_config_process_uuid(const struct global_parse_data *data,
  2403. struct wpa_config *config, int line,
  2404. const char *pos)
  2405. {
  2406. char buf[40];
  2407. if (uuid_str2bin(pos, config->uuid)) {
  2408. wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
  2409. return -1;
  2410. }
  2411. uuid_bin2str(config->uuid, buf, sizeof(buf));
  2412. wpa_printf(MSG_DEBUG, "uuid=%s", buf);
  2413. return 0;
  2414. }
  2415. static int wpa_config_process_device_type(
  2416. const struct global_parse_data *data,
  2417. struct wpa_config *config, int line, const char *pos)
  2418. {
  2419. return wps_dev_type_str2bin(pos, config->device_type);
  2420. }
  2421. static int wpa_config_process_os_version(const struct global_parse_data *data,
  2422. struct wpa_config *config, int line,
  2423. const char *pos)
  2424. {
  2425. if (hexstr2bin(pos, config->os_version, 4)) {
  2426. wpa_printf(MSG_ERROR, "Line %d: invalid os_version", line);
  2427. return -1;
  2428. }
  2429. wpa_printf(MSG_DEBUG, "os_version=%08x",
  2430. WPA_GET_BE32(config->os_version));
  2431. return 0;
  2432. }
  2433. static int wpa_config_process_wps_vendor_ext_m1(
  2434. const struct global_parse_data *data,
  2435. struct wpa_config *config, int line, const char *pos)
  2436. {
  2437. struct wpabuf *tmp;
  2438. int len = os_strlen(pos) / 2;
  2439. u8 *p;
  2440. if (!len) {
  2441. wpa_printf(MSG_ERROR, "Line %d: "
  2442. "invalid wps_vendor_ext_m1", line);
  2443. return -1;
  2444. }
  2445. tmp = wpabuf_alloc(len);
  2446. if (tmp) {
  2447. p = wpabuf_put(tmp, len);
  2448. if (hexstr2bin(pos, p, len)) {
  2449. wpa_printf(MSG_ERROR, "Line %d: "
  2450. "invalid wps_vendor_ext_m1", line);
  2451. wpabuf_free(tmp);
  2452. return -1;
  2453. }
  2454. wpabuf_free(config->wps_vendor_ext_m1);
  2455. config->wps_vendor_ext_m1 = tmp;
  2456. } else {
  2457. wpa_printf(MSG_ERROR, "Can not allocate "
  2458. "memory for wps_vendor_ext_m1");
  2459. return -1;
  2460. }
  2461. return 0;
  2462. }
  2463. #endif /* CONFIG_WPS */
  2464. #ifdef CONFIG_P2P
  2465. static int wpa_config_process_sec_device_type(
  2466. const struct global_parse_data *data,
  2467. struct wpa_config *config, int line, const char *pos)
  2468. {
  2469. int idx;
  2470. if (config->num_sec_device_types >= MAX_SEC_DEVICE_TYPES) {
  2471. wpa_printf(MSG_ERROR, "Line %d: too many sec_device_type "
  2472. "items", line);
  2473. return -1;
  2474. }
  2475. idx = config->num_sec_device_types;
  2476. if (wps_dev_type_str2bin(pos, config->sec_device_type[idx]))
  2477. return -1;
  2478. config->num_sec_device_types++;
  2479. return 0;
  2480. }
  2481. static int wpa_config_process_p2p_pref_chan(
  2482. const struct global_parse_data *data,
  2483. struct wpa_config *config, int line, const char *pos)
  2484. {
  2485. struct p2p_channel *pref = NULL, *n;
  2486. unsigned int num = 0;
  2487. const char *pos2;
  2488. u8 op_class, chan;
  2489. /* format: class:chan,class:chan,... */
  2490. while (*pos) {
  2491. op_class = atoi(pos);
  2492. pos2 = os_strchr(pos, ':');
  2493. if (pos2 == NULL)
  2494. goto fail;
  2495. pos2++;
  2496. chan = atoi(pos2);
  2497. n = os_realloc_array(pref, num + 1,
  2498. sizeof(struct p2p_channel));
  2499. if (n == NULL)
  2500. goto fail;
  2501. pref = n;
  2502. pref[num].op_class = op_class;
  2503. pref[num].chan = chan;
  2504. num++;
  2505. pos = os_strchr(pos2, ',');
  2506. if (pos == NULL)
  2507. break;
  2508. pos++;
  2509. }
  2510. os_free(config->p2p_pref_chan);
  2511. config->p2p_pref_chan = pref;
  2512. config->num_p2p_pref_chan = num;
  2513. wpa_hexdump(MSG_DEBUG, "P2P: Preferred class/channel pairs",
  2514. (u8 *) config->p2p_pref_chan,
  2515. config->num_p2p_pref_chan * sizeof(struct p2p_channel));
  2516. return 0;
  2517. fail:
  2518. os_free(pref);
  2519. wpa_printf(MSG_ERROR, "Line %d: Invalid p2p_pref_chan list", line);
  2520. return -1;
  2521. }
  2522. #endif /* CONFIG_P2P */
  2523. static int wpa_config_process_hessid(
  2524. const struct global_parse_data *data,
  2525. struct wpa_config *config, int line, const char *pos)
  2526. {
  2527. if (hwaddr_aton2(pos, config->hessid) < 0) {
  2528. wpa_printf(MSG_ERROR, "Line %d: Invalid hessid '%s'",
  2529. line, pos);
  2530. return -1;
  2531. }
  2532. return 0;
  2533. }
  2534. static int wpa_config_process_sae_groups(
  2535. const struct global_parse_data *data,
  2536. struct wpa_config *config, int line, const char *pos)
  2537. {
  2538. int *groups = wpa_config_parse_int_array(pos);
  2539. if (groups == NULL) {
  2540. wpa_printf(MSG_ERROR, "Line %d: Invalid sae_groups '%s'",
  2541. line, pos);
  2542. return -1;
  2543. }
  2544. os_free(config->sae_groups);
  2545. config->sae_groups = groups;
  2546. return 0;
  2547. }
  2548. #ifdef OFFSET
  2549. #undef OFFSET
  2550. #endif /* OFFSET */
  2551. /* OFFSET: Get offset of a variable within the wpa_config structure */
  2552. #define OFFSET(v) ((void *) &((struct wpa_config *) 0)->v)
  2553. #define FUNC(f) #f, wpa_config_process_ ## f, OFFSET(f), NULL, NULL
  2554. #define FUNC_NO_VAR(f) #f, wpa_config_process_ ## f, NULL, NULL, NULL
  2555. #define _INT(f) #f, wpa_global_config_parse_int, OFFSET(f)
  2556. #define INT(f) _INT(f), NULL, NULL
  2557. #define INT_RANGE(f, min, max) _INT(f), (void *) min, (void *) max
  2558. #define _STR(f) #f, wpa_global_config_parse_str, OFFSET(f)
  2559. #define STR(f) _STR(f), NULL, NULL
  2560. #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
  2561. #define BIN(f) #f, wpa_global_config_parse_bin, OFFSET(f), NULL, NULL
  2562. static const struct global_parse_data global_fields[] = {
  2563. #ifdef CONFIG_CTRL_IFACE
  2564. { STR(ctrl_interface), 0 },
  2565. { STR(ctrl_interface_group), 0 } /* deprecated */,
  2566. #endif /* CONFIG_CTRL_IFACE */
  2567. { INT_RANGE(eapol_version, 1, 2), 0 },
  2568. { INT(ap_scan), 0 },
  2569. { INT(disable_scan_offload), 0 },
  2570. { INT(fast_reauth), 0 },
  2571. { STR(opensc_engine_path), 0 },
  2572. { STR(pkcs11_engine_path), 0 },
  2573. { STR(pkcs11_module_path), 0 },
  2574. { STR(pcsc_reader), 0 },
  2575. { STR(pcsc_pin), 0 },
  2576. { STR(driver_param), 0 },
  2577. { INT(dot11RSNAConfigPMKLifetime), 0 },
  2578. { INT(dot11RSNAConfigPMKReauthThreshold), 0 },
  2579. { INT(dot11RSNAConfigSATimeout), 0 },
  2580. #ifndef CONFIG_NO_CONFIG_WRITE
  2581. { INT(update_config), 0 },
  2582. #endif /* CONFIG_NO_CONFIG_WRITE */
  2583. { FUNC_NO_VAR(load_dynamic_eap), 0 },
  2584. #ifdef CONFIG_WPS
  2585. { FUNC(uuid), CFG_CHANGED_UUID },
  2586. { STR_RANGE(device_name, 0, 32), CFG_CHANGED_DEVICE_NAME },
  2587. { STR_RANGE(manufacturer, 0, 64), CFG_CHANGED_WPS_STRING },
  2588. { STR_RANGE(model_name, 0, 32), CFG_CHANGED_WPS_STRING },
  2589. { STR_RANGE(model_number, 0, 32), CFG_CHANGED_WPS_STRING },
  2590. { STR_RANGE(serial_number, 0, 32), CFG_CHANGED_WPS_STRING },
  2591. { FUNC(device_type), CFG_CHANGED_DEVICE_TYPE },
  2592. { FUNC(os_version), CFG_CHANGED_OS_VERSION },
  2593. { STR(config_methods), CFG_CHANGED_CONFIG_METHODS },
  2594. { INT_RANGE(wps_cred_processing, 0, 2), 0 },
  2595. { FUNC(wps_vendor_ext_m1), CFG_CHANGED_VENDOR_EXTENSION },
  2596. #endif /* CONFIG_WPS */
  2597. #ifdef CONFIG_P2P
  2598. { FUNC(sec_device_type), CFG_CHANGED_SEC_DEVICE_TYPE },
  2599. { INT(p2p_listen_reg_class), 0 },
  2600. { INT(p2p_listen_channel), 0 },
  2601. { INT(p2p_oper_reg_class), 0 },
  2602. { INT(p2p_oper_channel), 0 },
  2603. { INT_RANGE(p2p_go_intent, 0, 15), 0 },
  2604. { STR(p2p_ssid_postfix), CFG_CHANGED_P2P_SSID_POSTFIX },
  2605. { INT_RANGE(persistent_reconnect, 0, 1), 0 },
  2606. { INT_RANGE(p2p_intra_bss, 0, 1), CFG_CHANGED_P2P_INTRA_BSS },
  2607. { INT(p2p_group_idle), 0 },
  2608. { FUNC(p2p_pref_chan), CFG_CHANGED_P2P_PREF_CHAN },
  2609. { INT(p2p_go_ht40), 0 },
  2610. { INT(p2p_disabled), 0 },
  2611. { INT(p2p_no_group_iface), 0 },
  2612. #endif /* CONFIG_P2P */
  2613. { FUNC(country), CFG_CHANGED_COUNTRY },
  2614. { INT(bss_max_count), 0 },
  2615. { INT(bss_expiration_age), 0 },
  2616. { INT(bss_expiration_scan_count), 0 },
  2617. { INT_RANGE(filter_ssids, 0, 1), 0 },
  2618. { INT_RANGE(filter_rssi, -100, 0), 0 },
  2619. { INT(max_num_sta), 0 },
  2620. { INT_RANGE(disassoc_low_ack, 0, 1), 0 },
  2621. #ifdef CONFIG_HS20
  2622. { INT_RANGE(hs20, 0, 1), 0 },
  2623. #endif /* CONFIG_HS20 */
  2624. { INT_RANGE(interworking, 0, 1), 0 },
  2625. { FUNC(hessid), 0 },
  2626. { INT_RANGE(access_network_type, 0, 15), 0 },
  2627. { INT_RANGE(pbc_in_m1, 0, 1), 0 },
  2628. { STR(autoscan), 0 },
  2629. { INT_RANGE(wps_nfc_dev_pw_id, 0x10, 0xffff), 0 },
  2630. { BIN(wps_nfc_dh_pubkey), 0 },
  2631. { BIN(wps_nfc_dh_privkey), 0 },
  2632. { BIN(wps_nfc_dev_pw), 0 },
  2633. { STR(ext_password_backend), CFG_CHANGED_EXT_PW_BACKEND },
  2634. { INT(p2p_go_max_inactivity), 0 },
  2635. { INT_RANGE(auto_interworking, 0, 1), 0 },
  2636. { INT(okc), 0 },
  2637. { INT(pmf), 0 },
  2638. { FUNC(sae_groups), 0 },
  2639. };
  2640. #undef FUNC
  2641. #undef _INT
  2642. #undef INT
  2643. #undef INT_RANGE
  2644. #undef _STR
  2645. #undef STR
  2646. #undef STR_RANGE
  2647. #undef BIN
  2648. #define NUM_GLOBAL_FIELDS (sizeof(global_fields) / sizeof(global_fields[0]))
  2649. int wpa_config_process_global(struct wpa_config *config, char *pos, int line)
  2650. {
  2651. size_t i;
  2652. int ret = 0;
  2653. for (i = 0; i < NUM_GLOBAL_FIELDS; i++) {
  2654. const struct global_parse_data *field = &global_fields[i];
  2655. size_t flen = os_strlen(field->name);
  2656. if (os_strncmp(pos, field->name, flen) != 0 ||
  2657. pos[flen] != '=')
  2658. continue;
  2659. if (field->parser(field, config, line, pos + flen + 1)) {
  2660. wpa_printf(MSG_ERROR, "Line %d: failed to "
  2661. "parse '%s'.", line, pos);
  2662. ret = -1;
  2663. }
  2664. config->changed_parameters |= field->changed_flag;
  2665. break;
  2666. }
  2667. if (i == NUM_GLOBAL_FIELDS) {
  2668. #ifdef CONFIG_AP
  2669. if (os_strncmp(pos, "wmm_ac_", 7) == 0) {
  2670. char *tmp = os_strchr(pos, '=');
  2671. if (tmp == NULL) {
  2672. if (line < 0)
  2673. return -1;
  2674. wpa_printf(MSG_ERROR, "Line %d: invalid line "
  2675. "'%s'", line, pos);
  2676. return -1;
  2677. }
  2678. *tmp++ = '\0';
  2679. if (hostapd_config_wmm_ac(config->wmm_ac_params, pos,
  2680. tmp)) {
  2681. wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
  2682. "AC item", line);
  2683. return -1;
  2684. }
  2685. }
  2686. #endif /* CONFIG_AP */
  2687. if (line < 0)
  2688. return -1;
  2689. wpa_printf(MSG_ERROR, "Line %d: unknown global field '%s'.",
  2690. line, pos);
  2691. ret = -1;
  2692. }
  2693. return ret;
  2694. }