config_file.c 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257
  1. /*
  2. * hostapd / Configuration file parser
  3. * Copyright (c) 2003-2014, 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 "utils/includes.h"
  9. #ifndef CONFIG_NATIVE_WINDOWS
  10. #include <grp.h>
  11. #endif /* CONFIG_NATIVE_WINDOWS */
  12. #include "utils/common.h"
  13. #include "utils/uuid.h"
  14. #include "common/ieee802_11_defs.h"
  15. #include "drivers/driver.h"
  16. #include "eap_server/eap.h"
  17. #include "radius/radius_client.h"
  18. #include "ap/wpa_auth.h"
  19. #include "ap/ap_config.h"
  20. #include "config_file.h"
  21. #ifndef CONFIG_NO_RADIUS
  22. #ifdef EAP_SERVER
  23. static struct hostapd_radius_attr *
  24. hostapd_parse_radius_attr(const char *value);
  25. #endif /* EAP_SERVER */
  26. #endif /* CONFIG_NO_RADIUS */
  27. #ifndef CONFIG_NO_VLAN
  28. static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
  29. const char *fname)
  30. {
  31. FILE *f;
  32. char buf[128], *pos, *pos2;
  33. int line = 0, vlan_id;
  34. struct hostapd_vlan *vlan;
  35. f = fopen(fname, "r");
  36. if (!f) {
  37. wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
  38. return -1;
  39. }
  40. while (fgets(buf, sizeof(buf), f)) {
  41. line++;
  42. if (buf[0] == '#')
  43. continue;
  44. pos = buf;
  45. while (*pos != '\0') {
  46. if (*pos == '\n') {
  47. *pos = '\0';
  48. break;
  49. }
  50. pos++;
  51. }
  52. if (buf[0] == '\0')
  53. continue;
  54. if (buf[0] == '*') {
  55. vlan_id = VLAN_ID_WILDCARD;
  56. pos = buf + 1;
  57. } else {
  58. vlan_id = strtol(buf, &pos, 10);
  59. if (buf == pos || vlan_id < 1 ||
  60. vlan_id > MAX_VLAN_ID) {
  61. wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
  62. "line %d in '%s'", line, fname);
  63. fclose(f);
  64. return -1;
  65. }
  66. }
  67. while (*pos == ' ' || *pos == '\t')
  68. pos++;
  69. pos2 = pos;
  70. while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
  71. pos2++;
  72. *pos2 = '\0';
  73. if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
  74. wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d "
  75. "in '%s'", line, fname);
  76. fclose(f);
  77. return -1;
  78. }
  79. vlan = os_zalloc(sizeof(*vlan));
  80. if (vlan == NULL) {
  81. wpa_printf(MSG_ERROR, "Out of memory while reading "
  82. "VLAN interfaces from '%s'", fname);
  83. fclose(f);
  84. return -1;
  85. }
  86. vlan->vlan_id = vlan_id;
  87. os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
  88. vlan->next = bss->vlan;
  89. bss->vlan = vlan;
  90. }
  91. fclose(f);
  92. return 0;
  93. }
  94. #endif /* CONFIG_NO_VLAN */
  95. static int hostapd_acl_comp(const void *a, const void *b)
  96. {
  97. const struct mac_acl_entry *aa = a;
  98. const struct mac_acl_entry *bb = b;
  99. return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
  100. }
  101. static int hostapd_config_read_maclist(const char *fname,
  102. struct mac_acl_entry **acl, int *num)
  103. {
  104. FILE *f;
  105. char buf[128], *pos;
  106. int line = 0;
  107. u8 addr[ETH_ALEN];
  108. struct mac_acl_entry *newacl;
  109. int vlan_id;
  110. if (!fname)
  111. return 0;
  112. f = fopen(fname, "r");
  113. if (!f) {
  114. wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
  115. return -1;
  116. }
  117. while (fgets(buf, sizeof(buf), f)) {
  118. int i, rem = 0;
  119. line++;
  120. if (buf[0] == '#')
  121. continue;
  122. pos = buf;
  123. while (*pos != '\0') {
  124. if (*pos == '\n') {
  125. *pos = '\0';
  126. break;
  127. }
  128. pos++;
  129. }
  130. if (buf[0] == '\0')
  131. continue;
  132. pos = buf;
  133. if (buf[0] == '-') {
  134. rem = 1;
  135. pos++;
  136. }
  137. if (hwaddr_aton(pos, addr)) {
  138. wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
  139. "line %d in '%s'", pos, line, fname);
  140. fclose(f);
  141. return -1;
  142. }
  143. if (rem) {
  144. i = 0;
  145. while (i < *num) {
  146. if (os_memcmp((*acl)[i].addr, addr, ETH_ALEN) ==
  147. 0) {
  148. os_remove_in_array(*acl, *num,
  149. sizeof(**acl), i);
  150. (*num)--;
  151. } else
  152. i++;
  153. }
  154. continue;
  155. }
  156. vlan_id = 0;
  157. pos = buf;
  158. while (*pos != '\0' && *pos != ' ' && *pos != '\t')
  159. pos++;
  160. while (*pos == ' ' || *pos == '\t')
  161. pos++;
  162. if (*pos != '\0')
  163. vlan_id = atoi(pos);
  164. newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
  165. if (newacl == NULL) {
  166. wpa_printf(MSG_ERROR, "MAC list reallocation failed");
  167. fclose(f);
  168. return -1;
  169. }
  170. *acl = newacl;
  171. os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
  172. (*acl)[*num].vlan_id = vlan_id;
  173. (*num)++;
  174. }
  175. fclose(f);
  176. qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
  177. return 0;
  178. }
  179. #ifdef EAP_SERVER
  180. static int hostapd_config_read_eap_user(const char *fname,
  181. struct hostapd_bss_config *conf)
  182. {
  183. FILE *f;
  184. char buf[512], *pos, *start, *pos2;
  185. int line = 0, ret = 0, num_methods;
  186. struct hostapd_eap_user *user = NULL, *tail = NULL;
  187. if (!fname)
  188. return 0;
  189. if (os_strncmp(fname, "sqlite:", 7) == 0) {
  190. os_free(conf->eap_user_sqlite);
  191. conf->eap_user_sqlite = os_strdup(fname + 7);
  192. return 0;
  193. }
  194. f = fopen(fname, "r");
  195. if (!f) {
  196. wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
  197. return -1;
  198. }
  199. /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
  200. while (fgets(buf, sizeof(buf), f)) {
  201. line++;
  202. if (buf[0] == '#')
  203. continue;
  204. pos = buf;
  205. while (*pos != '\0') {
  206. if (*pos == '\n') {
  207. *pos = '\0';
  208. break;
  209. }
  210. pos++;
  211. }
  212. if (buf[0] == '\0')
  213. continue;
  214. #ifndef CONFIG_NO_RADIUS
  215. if (user && os_strncmp(buf, "radius_accept_attr=", 19) == 0) {
  216. struct hostapd_radius_attr *attr, *a;
  217. attr = hostapd_parse_radius_attr(buf + 19);
  218. if (attr == NULL) {
  219. wpa_printf(MSG_ERROR, "Invalid radius_auth_req_attr: %s",
  220. buf + 19);
  221. user = NULL; /* already in the BSS list */
  222. goto failed;
  223. }
  224. if (user->accept_attr == NULL) {
  225. user->accept_attr = attr;
  226. } else {
  227. a = user->accept_attr;
  228. while (a->next)
  229. a = a->next;
  230. a->next = attr;
  231. }
  232. continue;
  233. }
  234. #endif /* CONFIG_NO_RADIUS */
  235. user = NULL;
  236. if (buf[0] != '"' && buf[0] != '*') {
  237. wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
  238. "start) on line %d in '%s'", line, fname);
  239. goto failed;
  240. }
  241. user = os_zalloc(sizeof(*user));
  242. if (user == NULL) {
  243. wpa_printf(MSG_ERROR, "EAP user allocation failed");
  244. goto failed;
  245. }
  246. user->force_version = -1;
  247. if (buf[0] == '*') {
  248. pos = buf;
  249. } else {
  250. pos = buf + 1;
  251. start = pos;
  252. while (*pos != '"' && *pos != '\0')
  253. pos++;
  254. if (*pos == '\0') {
  255. wpa_printf(MSG_ERROR, "Invalid EAP identity "
  256. "(no \" in end) on line %d in '%s'",
  257. line, fname);
  258. goto failed;
  259. }
  260. user->identity = os_malloc(pos - start);
  261. if (user->identity == NULL) {
  262. wpa_printf(MSG_ERROR, "Failed to allocate "
  263. "memory for EAP identity");
  264. goto failed;
  265. }
  266. os_memcpy(user->identity, start, pos - start);
  267. user->identity_len = pos - start;
  268. if (pos[0] == '"' && pos[1] == '*') {
  269. user->wildcard_prefix = 1;
  270. pos++;
  271. }
  272. }
  273. pos++;
  274. while (*pos == ' ' || *pos == '\t')
  275. pos++;
  276. if (*pos == '\0') {
  277. wpa_printf(MSG_ERROR, "No EAP method on line %d in "
  278. "'%s'", line, fname);
  279. goto failed;
  280. }
  281. start = pos;
  282. while (*pos != ' ' && *pos != '\t' && *pos != '\0')
  283. pos++;
  284. if (*pos == '\0') {
  285. pos = NULL;
  286. } else {
  287. *pos = '\0';
  288. pos++;
  289. }
  290. num_methods = 0;
  291. while (*start) {
  292. char *pos3 = os_strchr(start, ',');
  293. if (pos3) {
  294. *pos3++ = '\0';
  295. }
  296. user->methods[num_methods].method =
  297. eap_server_get_type(
  298. start,
  299. &user->methods[num_methods].vendor);
  300. if (user->methods[num_methods].vendor ==
  301. EAP_VENDOR_IETF &&
  302. user->methods[num_methods].method == EAP_TYPE_NONE)
  303. {
  304. if (os_strcmp(start, "TTLS-PAP") == 0) {
  305. user->ttls_auth |= EAP_TTLS_AUTH_PAP;
  306. goto skip_eap;
  307. }
  308. if (os_strcmp(start, "TTLS-CHAP") == 0) {
  309. user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
  310. goto skip_eap;
  311. }
  312. if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
  313. user->ttls_auth |=
  314. EAP_TTLS_AUTH_MSCHAP;
  315. goto skip_eap;
  316. }
  317. if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
  318. user->ttls_auth |=
  319. EAP_TTLS_AUTH_MSCHAPV2;
  320. goto skip_eap;
  321. }
  322. wpa_printf(MSG_ERROR, "Unsupported EAP type "
  323. "'%s' on line %d in '%s'",
  324. start, line, fname);
  325. goto failed;
  326. }
  327. num_methods++;
  328. if (num_methods >= EAP_MAX_METHODS)
  329. break;
  330. skip_eap:
  331. if (pos3 == NULL)
  332. break;
  333. start = pos3;
  334. }
  335. if (num_methods == 0 && user->ttls_auth == 0) {
  336. wpa_printf(MSG_ERROR, "No EAP types configured on "
  337. "line %d in '%s'", line, fname);
  338. goto failed;
  339. }
  340. if (pos == NULL)
  341. goto done;
  342. while (*pos == ' ' || *pos == '\t')
  343. pos++;
  344. if (*pos == '\0')
  345. goto done;
  346. if (os_strncmp(pos, "[ver=0]", 7) == 0) {
  347. user->force_version = 0;
  348. goto done;
  349. }
  350. if (os_strncmp(pos, "[ver=1]", 7) == 0) {
  351. user->force_version = 1;
  352. goto done;
  353. }
  354. if (os_strncmp(pos, "[2]", 3) == 0) {
  355. user->phase2 = 1;
  356. goto done;
  357. }
  358. if (*pos == '"') {
  359. pos++;
  360. start = pos;
  361. while (*pos != '"' && *pos != '\0')
  362. pos++;
  363. if (*pos == '\0') {
  364. wpa_printf(MSG_ERROR, "Invalid EAP password "
  365. "(no \" in end) on line %d in '%s'",
  366. line, fname);
  367. goto failed;
  368. }
  369. user->password = os_malloc(pos - start);
  370. if (user->password == NULL) {
  371. wpa_printf(MSG_ERROR, "Failed to allocate "
  372. "memory for EAP password");
  373. goto failed;
  374. }
  375. os_memcpy(user->password, start, pos - start);
  376. user->password_len = pos - start;
  377. pos++;
  378. } else if (os_strncmp(pos, "hash:", 5) == 0) {
  379. pos += 5;
  380. pos2 = pos;
  381. while (*pos2 != '\0' && *pos2 != ' ' &&
  382. *pos2 != '\t' && *pos2 != '#')
  383. pos2++;
  384. if (pos2 - pos != 32) {
  385. wpa_printf(MSG_ERROR, "Invalid password hash "
  386. "on line %d in '%s'", line, fname);
  387. goto failed;
  388. }
  389. user->password = os_malloc(16);
  390. if (user->password == NULL) {
  391. wpa_printf(MSG_ERROR, "Failed to allocate "
  392. "memory for EAP password hash");
  393. goto failed;
  394. }
  395. if (hexstr2bin(pos, user->password, 16) < 0) {
  396. wpa_printf(MSG_ERROR, "Invalid hash password "
  397. "on line %d in '%s'", line, fname);
  398. goto failed;
  399. }
  400. user->password_len = 16;
  401. user->password_hash = 1;
  402. pos = pos2;
  403. } else {
  404. pos2 = pos;
  405. while (*pos2 != '\0' && *pos2 != ' ' &&
  406. *pos2 != '\t' && *pos2 != '#')
  407. pos2++;
  408. if ((pos2 - pos) & 1) {
  409. wpa_printf(MSG_ERROR, "Invalid hex password "
  410. "on line %d in '%s'", line, fname);
  411. goto failed;
  412. }
  413. user->password = os_malloc((pos2 - pos) / 2);
  414. if (user->password == NULL) {
  415. wpa_printf(MSG_ERROR, "Failed to allocate "
  416. "memory for EAP password");
  417. goto failed;
  418. }
  419. if (hexstr2bin(pos, user->password,
  420. (pos2 - pos) / 2) < 0) {
  421. wpa_printf(MSG_ERROR, "Invalid hex password "
  422. "on line %d in '%s'", line, fname);
  423. goto failed;
  424. }
  425. user->password_len = (pos2 - pos) / 2;
  426. pos = pos2;
  427. }
  428. while (*pos == ' ' || *pos == '\t')
  429. pos++;
  430. if (os_strncmp(pos, "[2]", 3) == 0) {
  431. user->phase2 = 1;
  432. }
  433. done:
  434. if (tail == NULL) {
  435. tail = conf->eap_user = user;
  436. } else {
  437. tail->next = user;
  438. tail = user;
  439. }
  440. continue;
  441. failed:
  442. if (user)
  443. hostapd_config_free_eap_user(user);
  444. ret = -1;
  445. break;
  446. }
  447. fclose(f);
  448. return ret;
  449. }
  450. #endif /* EAP_SERVER */
  451. #ifndef CONFIG_NO_RADIUS
  452. static int
  453. hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
  454. int *num_server, const char *val, int def_port,
  455. struct hostapd_radius_server **curr_serv)
  456. {
  457. struct hostapd_radius_server *nserv;
  458. int ret;
  459. static int server_index = 1;
  460. nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv));
  461. if (nserv == NULL)
  462. return -1;
  463. *server = nserv;
  464. nserv = &nserv[*num_server];
  465. (*num_server)++;
  466. (*curr_serv) = nserv;
  467. os_memset(nserv, 0, sizeof(*nserv));
  468. nserv->port = def_port;
  469. ret = hostapd_parse_ip_addr(val, &nserv->addr);
  470. nserv->index = server_index++;
  471. return ret;
  472. }
  473. static struct hostapd_radius_attr *
  474. hostapd_parse_radius_attr(const char *value)
  475. {
  476. const char *pos;
  477. char syntax;
  478. struct hostapd_radius_attr *attr;
  479. size_t len;
  480. attr = os_zalloc(sizeof(*attr));
  481. if (attr == NULL)
  482. return NULL;
  483. attr->type = atoi(value);
  484. pos = os_strchr(value, ':');
  485. if (pos == NULL) {
  486. attr->val = wpabuf_alloc(1);
  487. if (attr->val == NULL) {
  488. os_free(attr);
  489. return NULL;
  490. }
  491. wpabuf_put_u8(attr->val, 0);
  492. return attr;
  493. }
  494. pos++;
  495. if (pos[0] == '\0' || pos[1] != ':') {
  496. os_free(attr);
  497. return NULL;
  498. }
  499. syntax = *pos++;
  500. pos++;
  501. switch (syntax) {
  502. case 's':
  503. attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
  504. break;
  505. case 'x':
  506. len = os_strlen(pos);
  507. if (len & 1)
  508. break;
  509. len /= 2;
  510. attr->val = wpabuf_alloc(len);
  511. if (attr->val == NULL)
  512. break;
  513. if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
  514. wpabuf_free(attr->val);
  515. os_free(attr);
  516. return NULL;
  517. }
  518. break;
  519. case 'd':
  520. attr->val = wpabuf_alloc(4);
  521. if (attr->val)
  522. wpabuf_put_be32(attr->val, atoi(pos));
  523. break;
  524. default:
  525. os_free(attr);
  526. return NULL;
  527. }
  528. if (attr->val == NULL) {
  529. os_free(attr);
  530. return NULL;
  531. }
  532. return attr;
  533. }
  534. static int hostapd_parse_das_client(struct hostapd_bss_config *bss,
  535. const char *val)
  536. {
  537. char *secret;
  538. secret = os_strchr(val, ' ');
  539. if (secret == NULL)
  540. return -1;
  541. secret++;
  542. if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr))
  543. return -1;
  544. os_free(bss->radius_das_shared_secret);
  545. bss->radius_das_shared_secret = (u8 *) os_strdup(secret);
  546. if (bss->radius_das_shared_secret == NULL)
  547. return -1;
  548. bss->radius_das_shared_secret_len = os_strlen(secret);
  549. return 0;
  550. }
  551. #endif /* CONFIG_NO_RADIUS */
  552. static int hostapd_config_parse_key_mgmt(int line, const char *value)
  553. {
  554. int val = 0, last;
  555. char *start, *end, *buf;
  556. buf = os_strdup(value);
  557. if (buf == NULL)
  558. return -1;
  559. start = buf;
  560. while (*start != '\0') {
  561. while (*start == ' ' || *start == '\t')
  562. start++;
  563. if (*start == '\0')
  564. break;
  565. end = start;
  566. while (*end != ' ' && *end != '\t' && *end != '\0')
  567. end++;
  568. last = *end == '\0';
  569. *end = '\0';
  570. if (os_strcmp(start, "WPA-PSK") == 0)
  571. val |= WPA_KEY_MGMT_PSK;
  572. else if (os_strcmp(start, "WPA-EAP") == 0)
  573. val |= WPA_KEY_MGMT_IEEE8021X;
  574. #ifdef CONFIG_IEEE80211R
  575. else if (os_strcmp(start, "FT-PSK") == 0)
  576. val |= WPA_KEY_MGMT_FT_PSK;
  577. else if (os_strcmp(start, "FT-EAP") == 0)
  578. val |= WPA_KEY_MGMT_FT_IEEE8021X;
  579. #endif /* CONFIG_IEEE80211R */
  580. #ifdef CONFIG_IEEE80211W
  581. else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
  582. val |= WPA_KEY_MGMT_PSK_SHA256;
  583. else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
  584. val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
  585. #endif /* CONFIG_IEEE80211W */
  586. #ifdef CONFIG_SAE
  587. else if (os_strcmp(start, "SAE") == 0)
  588. val |= WPA_KEY_MGMT_SAE;
  589. else if (os_strcmp(start, "FT-SAE") == 0)
  590. val |= WPA_KEY_MGMT_FT_SAE;
  591. #endif /* CONFIG_SAE */
  592. else {
  593. wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
  594. line, start);
  595. os_free(buf);
  596. return -1;
  597. }
  598. if (last)
  599. break;
  600. start = end + 1;
  601. }
  602. os_free(buf);
  603. if (val == 0) {
  604. wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
  605. "configured.", line);
  606. return -1;
  607. }
  608. return val;
  609. }
  610. static int hostapd_config_parse_cipher(int line, const char *value)
  611. {
  612. int val = wpa_parse_cipher(value);
  613. if (val < 0) {
  614. wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
  615. line, value);
  616. return -1;
  617. }
  618. if (val == 0) {
  619. wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
  620. line);
  621. return -1;
  622. }
  623. return val;
  624. }
  625. static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
  626. char *val)
  627. {
  628. size_t len = os_strlen(val);
  629. if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
  630. return -1;
  631. if (val[0] == '"') {
  632. if (len < 2 || val[len - 1] != '"')
  633. return -1;
  634. len -= 2;
  635. wep->key[keyidx] = os_malloc(len);
  636. if (wep->key[keyidx] == NULL)
  637. return -1;
  638. os_memcpy(wep->key[keyidx], val + 1, len);
  639. wep->len[keyidx] = len;
  640. } else {
  641. if (len & 1)
  642. return -1;
  643. len /= 2;
  644. wep->key[keyidx] = os_malloc(len);
  645. if (wep->key[keyidx] == NULL)
  646. return -1;
  647. wep->len[keyidx] = len;
  648. if (hexstr2bin(val, wep->key[keyidx], len) < 0)
  649. return -1;
  650. }
  651. wep->keys_set++;
  652. return 0;
  653. }
  654. static int hostapd_parse_intlist(int **int_list, char *val)
  655. {
  656. int *list;
  657. int count;
  658. char *pos, *end;
  659. os_free(*int_list);
  660. *int_list = NULL;
  661. pos = val;
  662. count = 0;
  663. while (*pos != '\0') {
  664. if (*pos == ' ')
  665. count++;
  666. pos++;
  667. }
  668. list = os_malloc(sizeof(int) * (count + 2));
  669. if (list == NULL)
  670. return -1;
  671. pos = val;
  672. count = 0;
  673. while (*pos != '\0') {
  674. end = os_strchr(pos, ' ');
  675. if (end)
  676. *end = '\0';
  677. list[count++] = atoi(pos);
  678. if (!end)
  679. break;
  680. pos = end + 1;
  681. }
  682. list[count] = -1;
  683. *int_list = list;
  684. return 0;
  685. }
  686. static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
  687. {
  688. struct hostapd_bss_config **all, *bss;
  689. if (*ifname == '\0')
  690. return -1;
  691. all = os_realloc_array(conf->bss, conf->num_bss + 1,
  692. sizeof(struct hostapd_bss_config *));
  693. if (all == NULL) {
  694. wpa_printf(MSG_ERROR, "Failed to allocate memory for "
  695. "multi-BSS entry");
  696. return -1;
  697. }
  698. conf->bss = all;
  699. bss = os_zalloc(sizeof(*bss));
  700. if (bss == NULL)
  701. return -1;
  702. bss->radius = os_zalloc(sizeof(*bss->radius));
  703. if (bss->radius == NULL) {
  704. wpa_printf(MSG_ERROR, "Failed to allocate memory for "
  705. "multi-BSS RADIUS data");
  706. os_free(bss);
  707. return -1;
  708. }
  709. conf->bss[conf->num_bss++] = bss;
  710. conf->last_bss = bss;
  711. hostapd_config_defaults_bss(bss);
  712. os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
  713. os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
  714. return 0;
  715. }
  716. /* convert floats with one decimal place to value*10 int, i.e.,
  717. * "1.5" will return 15 */
  718. static int hostapd_config_read_int10(const char *value)
  719. {
  720. int i, d;
  721. char *pos;
  722. i = atoi(value);
  723. pos = os_strchr(value, '.');
  724. d = 0;
  725. if (pos) {
  726. pos++;
  727. if (*pos >= '0' && *pos <= '9')
  728. d = *pos - '0';
  729. }
  730. return i * 10 + d;
  731. }
  732. static int valid_cw(int cw)
  733. {
  734. return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
  735. cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
  736. }
  737. enum {
  738. IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
  739. IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
  740. IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
  741. IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */
  742. };
  743. static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
  744. char *val)
  745. {
  746. int num;
  747. char *pos;
  748. struct hostapd_tx_queue_params *queue;
  749. /* skip 'tx_queue_' prefix */
  750. pos = name + 9;
  751. if (os_strncmp(pos, "data", 4) == 0 &&
  752. pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
  753. num = pos[4] - '0';
  754. pos += 6;
  755. } else if (os_strncmp(pos, "after_beacon_", 13) == 0 ||
  756. os_strncmp(pos, "beacon_", 7) == 0) {
  757. wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
  758. return 0;
  759. } else {
  760. wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
  761. return -1;
  762. }
  763. if (num >= NUM_TX_QUEUES) {
  764. /* for backwards compatibility, do not trigger failure */
  765. wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
  766. return 0;
  767. }
  768. queue = &conf->tx_queue[num];
  769. if (os_strcmp(pos, "aifs") == 0) {
  770. queue->aifs = atoi(val);
  771. if (queue->aifs < 0 || queue->aifs > 255) {
  772. wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
  773. queue->aifs);
  774. return -1;
  775. }
  776. } else if (os_strcmp(pos, "cwmin") == 0) {
  777. queue->cwmin = atoi(val);
  778. if (!valid_cw(queue->cwmin)) {
  779. wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
  780. queue->cwmin);
  781. return -1;
  782. }
  783. } else if (os_strcmp(pos, "cwmax") == 0) {
  784. queue->cwmax = atoi(val);
  785. if (!valid_cw(queue->cwmax)) {
  786. wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
  787. queue->cwmax);
  788. return -1;
  789. }
  790. } else if (os_strcmp(pos, "burst") == 0) {
  791. queue->burst = hostapd_config_read_int10(val);
  792. } else {
  793. wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
  794. return -1;
  795. }
  796. return 0;
  797. }
  798. #ifdef CONFIG_IEEE80211R
  799. static int add_r0kh(struct hostapd_bss_config *bss, char *value)
  800. {
  801. struct ft_remote_r0kh *r0kh;
  802. char *pos, *next;
  803. r0kh = os_zalloc(sizeof(*r0kh));
  804. if (r0kh == NULL)
  805. return -1;
  806. /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
  807. pos = value;
  808. next = os_strchr(pos, ' ');
  809. if (next)
  810. *next++ = '\0';
  811. if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
  812. wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
  813. os_free(r0kh);
  814. return -1;
  815. }
  816. pos = next;
  817. next = os_strchr(pos, ' ');
  818. if (next)
  819. *next++ = '\0';
  820. if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
  821. wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
  822. os_free(r0kh);
  823. return -1;
  824. }
  825. r0kh->id_len = next - pos - 1;
  826. os_memcpy(r0kh->id, pos, r0kh->id_len);
  827. pos = next;
  828. if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
  829. wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
  830. os_free(r0kh);
  831. return -1;
  832. }
  833. r0kh->next = bss->r0kh_list;
  834. bss->r0kh_list = r0kh;
  835. return 0;
  836. }
  837. static int add_r1kh(struct hostapd_bss_config *bss, char *value)
  838. {
  839. struct ft_remote_r1kh *r1kh;
  840. char *pos, *next;
  841. r1kh = os_zalloc(sizeof(*r1kh));
  842. if (r1kh == NULL)
  843. return -1;
  844. /* 02:01:02:03:04:05 02:01:02:03:04:05
  845. * 000102030405060708090a0b0c0d0e0f */
  846. pos = value;
  847. next = os_strchr(pos, ' ');
  848. if (next)
  849. *next++ = '\0';
  850. if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
  851. wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
  852. os_free(r1kh);
  853. return -1;
  854. }
  855. pos = next;
  856. next = os_strchr(pos, ' ');
  857. if (next)
  858. *next++ = '\0';
  859. if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
  860. wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
  861. os_free(r1kh);
  862. return -1;
  863. }
  864. pos = next;
  865. if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
  866. wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
  867. os_free(r1kh);
  868. return -1;
  869. }
  870. r1kh->next = bss->r1kh_list;
  871. bss->r1kh_list = r1kh;
  872. return 0;
  873. }
  874. #endif /* CONFIG_IEEE80211R */
  875. #ifdef CONFIG_IEEE80211N
  876. static int hostapd_config_ht_capab(struct hostapd_config *conf,
  877. const char *capab)
  878. {
  879. if (os_strstr(capab, "[LDPC]"))
  880. conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
  881. if (os_strstr(capab, "[HT40-]")) {
  882. conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
  883. conf->secondary_channel = -1;
  884. }
  885. if (os_strstr(capab, "[HT40+]")) {
  886. conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
  887. conf->secondary_channel = 1;
  888. }
  889. if (os_strstr(capab, "[SMPS-STATIC]")) {
  890. conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
  891. conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
  892. }
  893. if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
  894. conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
  895. conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
  896. }
  897. if (os_strstr(capab, "[GF]"))
  898. conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
  899. if (os_strstr(capab, "[SHORT-GI-20]"))
  900. conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
  901. if (os_strstr(capab, "[SHORT-GI-40]"))
  902. conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
  903. if (os_strstr(capab, "[TX-STBC]"))
  904. conf->ht_capab |= HT_CAP_INFO_TX_STBC;
  905. if (os_strstr(capab, "[RX-STBC1]")) {
  906. conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
  907. conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
  908. }
  909. if (os_strstr(capab, "[RX-STBC12]")) {
  910. conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
  911. conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
  912. }
  913. if (os_strstr(capab, "[RX-STBC123]")) {
  914. conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
  915. conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
  916. }
  917. if (os_strstr(capab, "[DELAYED-BA]"))
  918. conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
  919. if (os_strstr(capab, "[MAX-AMSDU-7935]"))
  920. conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
  921. if (os_strstr(capab, "[DSSS_CCK-40]"))
  922. conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
  923. if (os_strstr(capab, "[PSMP]"))
  924. conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP;
  925. if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
  926. conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
  927. return 0;
  928. }
  929. #endif /* CONFIG_IEEE80211N */
  930. #ifdef CONFIG_IEEE80211AC
  931. static int hostapd_config_vht_capab(struct hostapd_config *conf,
  932. const char *capab)
  933. {
  934. if (os_strstr(capab, "[MAX-MPDU-7991]"))
  935. conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
  936. if (os_strstr(capab, "[MAX-MPDU-11454]"))
  937. conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
  938. if (os_strstr(capab, "[VHT160]"))
  939. conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
  940. if (os_strstr(capab, "[VHT160-80PLUS80]"))
  941. conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
  942. if (os_strstr(capab, "[VHT160-80PLUS80]"))
  943. conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
  944. if (os_strstr(capab, "[RXLDPC]"))
  945. conf->vht_capab |= VHT_CAP_RXLDPC;
  946. if (os_strstr(capab, "[SHORT-GI-80]"))
  947. conf->vht_capab |= VHT_CAP_SHORT_GI_80;
  948. if (os_strstr(capab, "[SHORT-GI-160]"))
  949. conf->vht_capab |= VHT_CAP_SHORT_GI_160;
  950. if (os_strstr(capab, "[TX-STBC-2BY1]"))
  951. conf->vht_capab |= VHT_CAP_TXSTBC;
  952. if (os_strstr(capab, "[RX-STBC-1]"))
  953. conf->vht_capab |= VHT_CAP_RXSTBC_1;
  954. if (os_strstr(capab, "[RX-STBC-12]"))
  955. conf->vht_capab |= VHT_CAP_RXSTBC_2;
  956. if (os_strstr(capab, "[RX-STBC-123]"))
  957. conf->vht_capab |= VHT_CAP_RXSTBC_3;
  958. if (os_strstr(capab, "[RX-STBC-1234]"))
  959. conf->vht_capab |= VHT_CAP_RXSTBC_4;
  960. if (os_strstr(capab, "[SU-BEAMFORMER]"))
  961. conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE;
  962. if (os_strstr(capab, "[SU-BEAMFORMEE]"))
  963. conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE;
  964. if (os_strstr(capab, "[BF-ANTENNA-2]") &&
  965. (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
  966. conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
  967. if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
  968. (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
  969. conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
  970. if (os_strstr(capab, "[MU-BEAMFORMER]"))
  971. conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
  972. if (os_strstr(capab, "[MU-BEAMFORMEE]"))
  973. conf->vht_capab |= VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  974. if (os_strstr(capab, "[VHT-TXOP-PS]"))
  975. conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
  976. if (os_strstr(capab, "[HTC-VHT]"))
  977. conf->vht_capab |= VHT_CAP_HTC_VHT;
  978. if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP7]"))
  979. conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX;
  980. else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP6]"))
  981. conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_6;
  982. else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP5]"))
  983. conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_5;
  984. else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP4]"))
  985. conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_4;
  986. else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP3]"))
  987. conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_3;
  988. else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP2]"))
  989. conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_2;
  990. else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP1]"))
  991. conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_1;
  992. if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
  993. (conf->vht_capab & VHT_CAP_HTC_VHT))
  994. conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
  995. if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
  996. (conf->vht_capab & VHT_CAP_HTC_VHT))
  997. conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
  998. if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
  999. conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
  1000. if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
  1001. conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
  1002. return 0;
  1003. }
  1004. #endif /* CONFIG_IEEE80211AC */
  1005. #ifdef CONFIG_INTERWORKING
  1006. static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
  1007. int line)
  1008. {
  1009. size_t len = os_strlen(pos);
  1010. u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
  1011. struct hostapd_roaming_consortium *rc;
  1012. if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
  1013. hexstr2bin(pos, oi, len / 2)) {
  1014. wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
  1015. "'%s'", line, pos);
  1016. return -1;
  1017. }
  1018. len /= 2;
  1019. rc = os_realloc_array(bss->roaming_consortium,
  1020. bss->roaming_consortium_count + 1,
  1021. sizeof(struct hostapd_roaming_consortium));
  1022. if (rc == NULL)
  1023. return -1;
  1024. os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
  1025. rc[bss->roaming_consortium_count].len = len;
  1026. bss->roaming_consortium = rc;
  1027. bss->roaming_consortium_count++;
  1028. return 0;
  1029. }
  1030. static int parse_lang_string(struct hostapd_lang_string **array,
  1031. unsigned int *count, char *pos)
  1032. {
  1033. char *sep, *str = NULL;
  1034. size_t clen, nlen, slen;
  1035. struct hostapd_lang_string *ls;
  1036. int ret = -1;
  1037. if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) {
  1038. str = wpa_config_parse_string(pos, &slen);
  1039. if (!str)
  1040. return -1;
  1041. pos = str;
  1042. }
  1043. sep = os_strchr(pos, ':');
  1044. if (sep == NULL)
  1045. goto fail;
  1046. *sep++ = '\0';
  1047. clen = os_strlen(pos);
  1048. if (clen < 2 || clen > sizeof(ls->lang))
  1049. goto fail;
  1050. nlen = os_strlen(sep);
  1051. if (nlen > 252)
  1052. goto fail;
  1053. ls = os_realloc_array(*array, *count + 1,
  1054. sizeof(struct hostapd_lang_string));
  1055. if (ls == NULL)
  1056. goto fail;
  1057. *array = ls;
  1058. ls = &(*array)[*count];
  1059. (*count)++;
  1060. os_memset(ls->lang, 0, sizeof(ls->lang));
  1061. os_memcpy(ls->lang, pos, clen);
  1062. ls->name_len = nlen;
  1063. os_memcpy(ls->name, sep, nlen);
  1064. ret = 0;
  1065. fail:
  1066. os_free(str);
  1067. return ret;
  1068. }
  1069. static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
  1070. int line)
  1071. {
  1072. if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
  1073. wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
  1074. line, pos);
  1075. return -1;
  1076. }
  1077. return 0;
  1078. }
  1079. static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
  1080. int line)
  1081. {
  1082. size_t count;
  1083. char *pos;
  1084. u8 *info = NULL, *ipos;
  1085. /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
  1086. count = 1;
  1087. for (pos = buf; *pos; pos++) {
  1088. if ((*pos < '0' && *pos > '9') && *pos != ';' && *pos != ',')
  1089. goto fail;
  1090. if (*pos == ';')
  1091. count++;
  1092. }
  1093. if (1 + count * 3 > 0x7f)
  1094. goto fail;
  1095. info = os_zalloc(2 + 3 + count * 3);
  1096. if (info == NULL)
  1097. return -1;
  1098. ipos = info;
  1099. *ipos++ = 0; /* GUD - Version 1 */
  1100. *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
  1101. *ipos++ = 0; /* PLMN List IEI */
  1102. /* ext(b8) | Length of PLMN List value contents(b7..1) */
  1103. *ipos++ = 1 + count * 3;
  1104. *ipos++ = count; /* Number of PLMNs */
  1105. pos = buf;
  1106. while (pos && *pos) {
  1107. char *mcc, *mnc;
  1108. size_t mnc_len;
  1109. mcc = pos;
  1110. mnc = os_strchr(pos, ',');
  1111. if (mnc == NULL)
  1112. goto fail;
  1113. *mnc++ = '\0';
  1114. pos = os_strchr(mnc, ';');
  1115. if (pos)
  1116. *pos++ = '\0';
  1117. mnc_len = os_strlen(mnc);
  1118. if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
  1119. goto fail;
  1120. /* BC coded MCC,MNC */
  1121. /* MCC digit 2 | MCC digit 1 */
  1122. *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
  1123. /* MNC digit 3 | MCC digit 3 */
  1124. *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
  1125. (mcc[2] - '0');
  1126. /* MNC digit 2 | MNC digit 1 */
  1127. *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
  1128. }
  1129. os_free(bss->anqp_3gpp_cell_net);
  1130. bss->anqp_3gpp_cell_net = info;
  1131. bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
  1132. wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
  1133. bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
  1134. return 0;
  1135. fail:
  1136. wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
  1137. line, buf);
  1138. os_free(info);
  1139. return -1;
  1140. }
  1141. static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
  1142. {
  1143. struct hostapd_nai_realm_data *realm;
  1144. size_t i, j, len;
  1145. int *offsets;
  1146. char *pos, *end, *rpos;
  1147. offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
  1148. sizeof(int));
  1149. if (offsets == NULL)
  1150. return -1;
  1151. for (i = 0; i < bss->nai_realm_count; i++) {
  1152. realm = &bss->nai_realm_data[i];
  1153. for (j = 0; j < MAX_NAI_REALMS; j++) {
  1154. offsets[i * MAX_NAI_REALMS + j] =
  1155. realm->realm[j] ?
  1156. realm->realm[j] - realm->realm_buf : -1;
  1157. }
  1158. }
  1159. realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
  1160. sizeof(struct hostapd_nai_realm_data));
  1161. if (realm == NULL) {
  1162. os_free(offsets);
  1163. return -1;
  1164. }
  1165. bss->nai_realm_data = realm;
  1166. /* patch the pointers after realloc */
  1167. for (i = 0; i < bss->nai_realm_count; i++) {
  1168. realm = &bss->nai_realm_data[i];
  1169. for (j = 0; j < MAX_NAI_REALMS; j++) {
  1170. int offs = offsets[i * MAX_NAI_REALMS + j];
  1171. if (offs >= 0)
  1172. realm->realm[j] = realm->realm_buf + offs;
  1173. else
  1174. realm->realm[j] = NULL;
  1175. }
  1176. }
  1177. os_free(offsets);
  1178. realm = &bss->nai_realm_data[bss->nai_realm_count];
  1179. os_memset(realm, 0, sizeof(*realm));
  1180. pos = buf;
  1181. realm->encoding = atoi(pos);
  1182. pos = os_strchr(pos, ',');
  1183. if (pos == NULL)
  1184. goto fail;
  1185. pos++;
  1186. end = os_strchr(pos, ',');
  1187. if (end) {
  1188. len = end - pos;
  1189. *end = '\0';
  1190. } else {
  1191. len = os_strlen(pos);
  1192. }
  1193. if (len > MAX_NAI_REALMLEN) {
  1194. wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
  1195. "characters)", (int) len, MAX_NAI_REALMLEN);
  1196. goto fail;
  1197. }
  1198. os_memcpy(realm->realm_buf, pos, len);
  1199. if (end)
  1200. pos = end + 1;
  1201. else
  1202. pos = NULL;
  1203. while (pos && *pos) {
  1204. struct hostapd_nai_realm_eap *eap;
  1205. if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
  1206. wpa_printf(MSG_ERROR, "Too many EAP methods");
  1207. goto fail;
  1208. }
  1209. eap = &realm->eap_method[realm->eap_method_count];
  1210. realm->eap_method_count++;
  1211. end = os_strchr(pos, ',');
  1212. if (end == NULL)
  1213. end = pos + os_strlen(pos);
  1214. eap->eap_method = atoi(pos);
  1215. for (;;) {
  1216. pos = os_strchr(pos, '[');
  1217. if (pos == NULL || pos > end)
  1218. break;
  1219. pos++;
  1220. if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
  1221. wpa_printf(MSG_ERROR, "Too many auth params");
  1222. goto fail;
  1223. }
  1224. eap->auth_id[eap->num_auths] = atoi(pos);
  1225. pos = os_strchr(pos, ':');
  1226. if (pos == NULL || pos > end)
  1227. goto fail;
  1228. pos++;
  1229. eap->auth_val[eap->num_auths] = atoi(pos);
  1230. pos = os_strchr(pos, ']');
  1231. if (pos == NULL || pos > end)
  1232. goto fail;
  1233. pos++;
  1234. eap->num_auths++;
  1235. }
  1236. if (*end != ',')
  1237. break;
  1238. pos = end + 1;
  1239. }
  1240. /* Split realm list into null terminated realms */
  1241. rpos = realm->realm_buf;
  1242. i = 0;
  1243. while (*rpos) {
  1244. if (i >= MAX_NAI_REALMS) {
  1245. wpa_printf(MSG_ERROR, "Too many realms");
  1246. goto fail;
  1247. }
  1248. realm->realm[i++] = rpos;
  1249. rpos = os_strchr(rpos, ';');
  1250. if (rpos == NULL)
  1251. break;
  1252. *rpos++ = '\0';
  1253. }
  1254. bss->nai_realm_count++;
  1255. return 0;
  1256. fail:
  1257. wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
  1258. return -1;
  1259. }
  1260. static int parse_qos_map_set(struct hostapd_bss_config *bss,
  1261. char *buf, int line)
  1262. {
  1263. u8 qos_map_set[16 + 2 * 21], count = 0;
  1264. char *pos = buf;
  1265. int val;
  1266. for (;;) {
  1267. if (count == sizeof(qos_map_set)) {
  1268. wpa_printf(MSG_ERROR, "Line %d: Too many qos_map_set "
  1269. "parameters '%s'", line, buf);
  1270. return -1;
  1271. }
  1272. val = atoi(pos);
  1273. if (val > 255 || val < 0) {
  1274. wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set "
  1275. "'%s'", line, buf);
  1276. return -1;
  1277. }
  1278. qos_map_set[count++] = val;
  1279. pos = os_strchr(pos, ',');
  1280. if (!pos)
  1281. break;
  1282. pos++;
  1283. }
  1284. if (count < 16 || count & 1) {
  1285. wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'",
  1286. line, buf);
  1287. return -1;
  1288. }
  1289. os_memcpy(bss->qos_map_set, qos_map_set, count);
  1290. bss->qos_map_set_len = count;
  1291. return 0;
  1292. }
  1293. #endif /* CONFIG_INTERWORKING */
  1294. #ifdef CONFIG_HS20
  1295. static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
  1296. int line)
  1297. {
  1298. u8 *conn_cap;
  1299. char *pos;
  1300. if (bss->hs20_connection_capability_len >= 0xfff0)
  1301. return -1;
  1302. conn_cap = os_realloc(bss->hs20_connection_capability,
  1303. bss->hs20_connection_capability_len + 4);
  1304. if (conn_cap == NULL)
  1305. return -1;
  1306. bss->hs20_connection_capability = conn_cap;
  1307. conn_cap += bss->hs20_connection_capability_len;
  1308. pos = buf;
  1309. conn_cap[0] = atoi(pos);
  1310. pos = os_strchr(pos, ':');
  1311. if (pos == NULL)
  1312. return -1;
  1313. pos++;
  1314. WPA_PUT_LE16(conn_cap + 1, atoi(pos));
  1315. pos = os_strchr(pos, ':');
  1316. if (pos == NULL)
  1317. return -1;
  1318. pos++;
  1319. conn_cap[3] = atoi(pos);
  1320. bss->hs20_connection_capability_len += 4;
  1321. return 0;
  1322. }
  1323. static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
  1324. int line)
  1325. {
  1326. u8 *wan_metrics;
  1327. char *pos;
  1328. /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
  1329. wan_metrics = os_zalloc(13);
  1330. if (wan_metrics == NULL)
  1331. return -1;
  1332. pos = buf;
  1333. /* WAN Info */
  1334. if (hexstr2bin(pos, wan_metrics, 1) < 0)
  1335. goto fail;
  1336. pos += 2;
  1337. if (*pos != ':')
  1338. goto fail;
  1339. pos++;
  1340. /* Downlink Speed */
  1341. WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
  1342. pos = os_strchr(pos, ':');
  1343. if (pos == NULL)
  1344. goto fail;
  1345. pos++;
  1346. /* Uplink Speed */
  1347. WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
  1348. pos = os_strchr(pos, ':');
  1349. if (pos == NULL)
  1350. goto fail;
  1351. pos++;
  1352. /* Downlink Load */
  1353. wan_metrics[9] = atoi(pos);
  1354. pos = os_strchr(pos, ':');
  1355. if (pos == NULL)
  1356. goto fail;
  1357. pos++;
  1358. /* Uplink Load */
  1359. wan_metrics[10] = atoi(pos);
  1360. pos = os_strchr(pos, ':');
  1361. if (pos == NULL)
  1362. goto fail;
  1363. pos++;
  1364. /* LMD */
  1365. WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
  1366. os_free(bss->hs20_wan_metrics);
  1367. bss->hs20_wan_metrics = wan_metrics;
  1368. return 0;
  1369. fail:
  1370. wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
  1371. line, pos);
  1372. os_free(wan_metrics);
  1373. return -1;
  1374. }
  1375. static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
  1376. char *pos, int line)
  1377. {
  1378. if (parse_lang_string(&bss->hs20_oper_friendly_name,
  1379. &bss->hs20_oper_friendly_name_count, pos)) {
  1380. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1381. "hs20_oper_friendly_name '%s'", line, pos);
  1382. return -1;
  1383. }
  1384. return 0;
  1385. }
  1386. static int hs20_parse_icon(struct hostapd_bss_config *bss, char *pos)
  1387. {
  1388. struct hs20_icon *icon;
  1389. char *end;
  1390. icon = os_realloc_array(bss->hs20_icons, bss->hs20_icons_count + 1,
  1391. sizeof(struct hs20_icon));
  1392. if (icon == NULL)
  1393. return -1;
  1394. bss->hs20_icons = icon;
  1395. icon = &bss->hs20_icons[bss->hs20_icons_count];
  1396. os_memset(icon, 0, sizeof(*icon));
  1397. icon->width = atoi(pos);
  1398. pos = os_strchr(pos, ':');
  1399. if (pos == NULL)
  1400. return -1;
  1401. pos++;
  1402. icon->height = atoi(pos);
  1403. pos = os_strchr(pos, ':');
  1404. if (pos == NULL)
  1405. return -1;
  1406. pos++;
  1407. end = os_strchr(pos, ':');
  1408. if (end == NULL || end - pos > 3)
  1409. return -1;
  1410. os_memcpy(icon->language, pos, end - pos);
  1411. pos = end + 1;
  1412. end = os_strchr(pos, ':');
  1413. if (end == NULL || end - pos > 255)
  1414. return -1;
  1415. os_memcpy(icon->type, pos, end - pos);
  1416. pos = end + 1;
  1417. end = os_strchr(pos, ':');
  1418. if (end == NULL || end - pos > 255)
  1419. return -1;
  1420. os_memcpy(icon->name, pos, end - pos);
  1421. pos = end + 1;
  1422. if (os_strlen(pos) > 255)
  1423. return -1;
  1424. os_memcpy(icon->file, pos, os_strlen(pos));
  1425. bss->hs20_icons_count++;
  1426. return 0;
  1427. }
  1428. static int hs20_parse_osu_ssid(struct hostapd_bss_config *bss,
  1429. char *pos, int line)
  1430. {
  1431. size_t slen;
  1432. char *str;
  1433. str = wpa_config_parse_string(pos, &slen);
  1434. if (str == NULL || slen < 1 || slen > HOSTAPD_MAX_SSID_LEN) {
  1435. wpa_printf(MSG_ERROR, "Line %d: Invalid SSID '%s'", line, pos);
  1436. os_free(str);
  1437. return -1;
  1438. }
  1439. os_memcpy(bss->osu_ssid, str, slen);
  1440. bss->osu_ssid_len = slen;
  1441. os_free(str);
  1442. return 0;
  1443. }
  1444. static int hs20_parse_osu_server_uri(struct hostapd_bss_config *bss,
  1445. char *pos, int line)
  1446. {
  1447. struct hs20_osu_provider *p;
  1448. p = os_realloc_array(bss->hs20_osu_providers,
  1449. bss->hs20_osu_providers_count + 1, sizeof(*p));
  1450. if (p == NULL)
  1451. return -1;
  1452. bss->hs20_osu_providers = p;
  1453. bss->last_osu = &bss->hs20_osu_providers[bss->hs20_osu_providers_count];
  1454. bss->hs20_osu_providers_count++;
  1455. os_memset(bss->last_osu, 0, sizeof(*p));
  1456. bss->last_osu->server_uri = os_strdup(pos);
  1457. return 0;
  1458. }
  1459. static int hs20_parse_osu_friendly_name(struct hostapd_bss_config *bss,
  1460. char *pos, int line)
  1461. {
  1462. if (bss->last_osu == NULL) {
  1463. wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
  1464. return -1;
  1465. }
  1466. if (parse_lang_string(&bss->last_osu->friendly_name,
  1467. &bss->last_osu->friendly_name_count, pos)) {
  1468. wpa_printf(MSG_ERROR, "Line %d: Invalid osu_friendly_name '%s'",
  1469. line, pos);
  1470. return -1;
  1471. }
  1472. return 0;
  1473. }
  1474. static int hs20_parse_osu_nai(struct hostapd_bss_config *bss,
  1475. char *pos, int line)
  1476. {
  1477. if (bss->last_osu == NULL) {
  1478. wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
  1479. return -1;
  1480. }
  1481. os_free(bss->last_osu->osu_nai);
  1482. bss->last_osu->osu_nai = os_strdup(pos);
  1483. if (bss->last_osu->osu_nai == NULL)
  1484. return -1;
  1485. return 0;
  1486. }
  1487. static int hs20_parse_osu_method_list(struct hostapd_bss_config *bss, char *pos,
  1488. int line)
  1489. {
  1490. if (bss->last_osu == NULL) {
  1491. wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
  1492. return -1;
  1493. }
  1494. if (hostapd_parse_intlist(&bss->last_osu->method_list, pos)) {
  1495. wpa_printf(MSG_ERROR, "Line %d: Invalid osu_method_list", line);
  1496. return -1;
  1497. }
  1498. return 0;
  1499. }
  1500. static int hs20_parse_osu_icon(struct hostapd_bss_config *bss, char *pos,
  1501. int line)
  1502. {
  1503. char **n;
  1504. struct hs20_osu_provider *p = bss->last_osu;
  1505. if (p == NULL) {
  1506. wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
  1507. return -1;
  1508. }
  1509. n = os_realloc_array(p->icons, p->icons_count + 1, sizeof(char *));
  1510. if (n == NULL)
  1511. return -1;
  1512. p->icons = n;
  1513. p->icons[p->icons_count] = os_strdup(pos);
  1514. if (p->icons[p->icons_count] == NULL)
  1515. return -1;
  1516. p->icons_count++;
  1517. return 0;
  1518. }
  1519. static int hs20_parse_osu_service_desc(struct hostapd_bss_config *bss,
  1520. char *pos, int line)
  1521. {
  1522. if (bss->last_osu == NULL) {
  1523. wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
  1524. return -1;
  1525. }
  1526. if (parse_lang_string(&bss->last_osu->service_desc,
  1527. &bss->last_osu->service_desc_count, pos)) {
  1528. wpa_printf(MSG_ERROR, "Line %d: Invalid osu_service_desc '%s'",
  1529. line, pos);
  1530. return -1;
  1531. }
  1532. return 0;
  1533. }
  1534. #endif /* CONFIG_HS20 */
  1535. #ifdef CONFIG_WPS_NFC
  1536. static struct wpabuf * hostapd_parse_bin(const char *buf)
  1537. {
  1538. size_t len;
  1539. struct wpabuf *ret;
  1540. len = os_strlen(buf);
  1541. if (len & 0x01)
  1542. return NULL;
  1543. len /= 2;
  1544. ret = wpabuf_alloc(len);
  1545. if (ret == NULL)
  1546. return NULL;
  1547. if (hexstr2bin(buf, wpabuf_put(ret, len), len)) {
  1548. wpabuf_free(ret);
  1549. return NULL;
  1550. }
  1551. return ret;
  1552. }
  1553. #endif /* CONFIG_WPS_NFC */
  1554. static int hostapd_config_fill(struct hostapd_config *conf,
  1555. struct hostapd_bss_config *bss,
  1556. char *buf, char *pos, int line)
  1557. {
  1558. if (os_strcmp(buf, "interface") == 0) {
  1559. os_strlcpy(conf->bss[0]->iface, pos,
  1560. sizeof(conf->bss[0]->iface));
  1561. } else if (os_strcmp(buf, "bridge") == 0) {
  1562. os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
  1563. } else if (os_strcmp(buf, "vlan_bridge") == 0) {
  1564. os_strlcpy(bss->vlan_bridge, pos, sizeof(bss->vlan_bridge));
  1565. } else if (os_strcmp(buf, "wds_bridge") == 0) {
  1566. os_strlcpy(bss->wds_bridge, pos, sizeof(bss->wds_bridge));
  1567. } else if (os_strcmp(buf, "driver") == 0) {
  1568. int j;
  1569. /* clear to get error below if setting is invalid */
  1570. conf->driver = NULL;
  1571. for (j = 0; wpa_drivers[j]; j++) {
  1572. if (os_strcmp(pos, wpa_drivers[j]->name) == 0) {
  1573. conf->driver = wpa_drivers[j];
  1574. break;
  1575. }
  1576. }
  1577. if (conf->driver == NULL) {
  1578. wpa_printf(MSG_ERROR,
  1579. "Line %d: invalid/unknown driver '%s'",
  1580. line, pos);
  1581. return 1;
  1582. }
  1583. } else if (os_strcmp(buf, "debug") == 0) {
  1584. wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' configuration variable is not used anymore",
  1585. line);
  1586. } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
  1587. bss->logger_syslog_level = atoi(pos);
  1588. } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
  1589. bss->logger_stdout_level = atoi(pos);
  1590. } else if (os_strcmp(buf, "logger_syslog") == 0) {
  1591. bss->logger_syslog = atoi(pos);
  1592. } else if (os_strcmp(buf, "logger_stdout") == 0) {
  1593. bss->logger_stdout = atoi(pos);
  1594. } else if (os_strcmp(buf, "dump_file") == 0) {
  1595. wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore",
  1596. line);
  1597. } else if (os_strcmp(buf, "ssid") == 0) {
  1598. bss->ssid.ssid_len = os_strlen(pos);
  1599. if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
  1600. bss->ssid.ssid_len < 1) {
  1601. wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
  1602. line, pos);
  1603. return 1;
  1604. }
  1605. os_memcpy(bss->ssid.ssid, pos, bss->ssid.ssid_len);
  1606. bss->ssid.ssid_set = 1;
  1607. } else if (os_strcmp(buf, "ssid2") == 0) {
  1608. size_t slen;
  1609. char *str = wpa_config_parse_string(pos, &slen);
  1610. if (str == NULL || slen < 1 || slen > HOSTAPD_MAX_SSID_LEN) {
  1611. wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
  1612. line, pos);
  1613. os_free(str);
  1614. return 1;
  1615. }
  1616. os_memcpy(bss->ssid.ssid, str, slen);
  1617. bss->ssid.ssid_len = slen;
  1618. bss->ssid.ssid_set = 1;
  1619. os_free(str);
  1620. } else if (os_strcmp(buf, "utf8_ssid") == 0) {
  1621. bss->ssid.utf8_ssid = atoi(pos) > 0;
  1622. } else if (os_strcmp(buf, "macaddr_acl") == 0) {
  1623. bss->macaddr_acl = atoi(pos);
  1624. if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
  1625. bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
  1626. bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
  1627. wpa_printf(MSG_ERROR, "Line %d: unknown macaddr_acl %d",
  1628. line, bss->macaddr_acl);
  1629. }
  1630. } else if (os_strcmp(buf, "accept_mac_file") == 0) {
  1631. if (hostapd_config_read_maclist(pos, &bss->accept_mac,
  1632. &bss->num_accept_mac)) {
  1633. wpa_printf(MSG_ERROR, "Line %d: Failed to read accept_mac_file '%s'",
  1634. line, pos);
  1635. return 1;
  1636. }
  1637. } else if (os_strcmp(buf, "deny_mac_file") == 0) {
  1638. if (hostapd_config_read_maclist(pos, &bss->deny_mac,
  1639. &bss->num_deny_mac)) {
  1640. wpa_printf(MSG_ERROR, "Line %d: Failed to read deny_mac_file '%s'",
  1641. line, pos);
  1642. return 1;
  1643. }
  1644. } else if (os_strcmp(buf, "wds_sta") == 0) {
  1645. bss->wds_sta = atoi(pos);
  1646. } else if (os_strcmp(buf, "start_disabled") == 0) {
  1647. bss->start_disabled = atoi(pos);
  1648. } else if (os_strcmp(buf, "ap_isolate") == 0) {
  1649. bss->isolate = atoi(pos);
  1650. } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
  1651. bss->ap_max_inactivity = atoi(pos);
  1652. } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
  1653. bss->skip_inactivity_poll = atoi(pos);
  1654. } else if (os_strcmp(buf, "country_code") == 0) {
  1655. os_memcpy(conf->country, pos, 2);
  1656. /* FIX: make this configurable */
  1657. conf->country[2] = ' ';
  1658. } else if (os_strcmp(buf, "ieee80211d") == 0) {
  1659. conf->ieee80211d = atoi(pos);
  1660. } else if (os_strcmp(buf, "ieee80211h") == 0) {
  1661. conf->ieee80211h = atoi(pos);
  1662. } else if (os_strcmp(buf, "ieee8021x") == 0) {
  1663. bss->ieee802_1x = atoi(pos);
  1664. } else if (os_strcmp(buf, "eapol_version") == 0) {
  1665. bss->eapol_version = atoi(pos);
  1666. if (bss->eapol_version < 1 || bss->eapol_version > 2) {
  1667. wpa_printf(MSG_ERROR,
  1668. "Line %d: invalid EAPOL version (%d): '%s'.",
  1669. line, bss->eapol_version, pos);
  1670. return 1;
  1671. }
  1672. wpa_printf(MSG_DEBUG, "eapol_version=%d", bss->eapol_version);
  1673. #ifdef EAP_SERVER
  1674. } else if (os_strcmp(buf, "eap_authenticator") == 0) {
  1675. bss->eap_server = atoi(pos);
  1676. wpa_printf(MSG_ERROR, "Line %d: obsolete eap_authenticator used; this has been renamed to eap_server", line);
  1677. } else if (os_strcmp(buf, "eap_server") == 0) {
  1678. bss->eap_server = atoi(pos);
  1679. } else if (os_strcmp(buf, "eap_user_file") == 0) {
  1680. if (hostapd_config_read_eap_user(pos, bss))
  1681. return 1;
  1682. } else if (os_strcmp(buf, "ca_cert") == 0) {
  1683. os_free(bss->ca_cert);
  1684. bss->ca_cert = os_strdup(pos);
  1685. } else if (os_strcmp(buf, "server_cert") == 0) {
  1686. os_free(bss->server_cert);
  1687. bss->server_cert = os_strdup(pos);
  1688. } else if (os_strcmp(buf, "private_key") == 0) {
  1689. os_free(bss->private_key);
  1690. bss->private_key = os_strdup(pos);
  1691. } else if (os_strcmp(buf, "private_key_passwd") == 0) {
  1692. os_free(bss->private_key_passwd);
  1693. bss->private_key_passwd = os_strdup(pos);
  1694. } else if (os_strcmp(buf, "check_crl") == 0) {
  1695. bss->check_crl = atoi(pos);
  1696. } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) {
  1697. os_free(bss->ocsp_stapling_response);
  1698. bss->ocsp_stapling_response = os_strdup(pos);
  1699. } else if (os_strcmp(buf, "dh_file") == 0) {
  1700. os_free(bss->dh_file);
  1701. bss->dh_file = os_strdup(pos);
  1702. } else if (os_strcmp(buf, "fragment_size") == 0) {
  1703. bss->fragment_size = atoi(pos);
  1704. #ifdef EAP_SERVER_FAST
  1705. } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
  1706. os_free(bss->pac_opaque_encr_key);
  1707. bss->pac_opaque_encr_key = os_malloc(16);
  1708. if (bss->pac_opaque_encr_key == NULL) {
  1709. wpa_printf(MSG_ERROR,
  1710. "Line %d: No memory for pac_opaque_encr_key",
  1711. line);
  1712. return 1;
  1713. } else if (hexstr2bin(pos, bss->pac_opaque_encr_key, 16)) {
  1714. wpa_printf(MSG_ERROR, "Line %d: Invalid pac_opaque_encr_key",
  1715. line);
  1716. return 1;
  1717. }
  1718. } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
  1719. size_t idlen = os_strlen(pos);
  1720. if (idlen & 1) {
  1721. wpa_printf(MSG_ERROR, "Line %d: Invalid eap_fast_a_id",
  1722. line);
  1723. return 1;
  1724. }
  1725. os_free(bss->eap_fast_a_id);
  1726. bss->eap_fast_a_id = os_malloc(idlen / 2);
  1727. if (bss->eap_fast_a_id == NULL ||
  1728. hexstr2bin(pos, bss->eap_fast_a_id, idlen / 2)) {
  1729. wpa_printf(MSG_ERROR, "Line %d: Failed to parse eap_fast_a_id",
  1730. line);
  1731. os_free(bss->eap_fast_a_id);
  1732. bss->eap_fast_a_id = NULL;
  1733. return 1;
  1734. } else {
  1735. bss->eap_fast_a_id_len = idlen / 2;
  1736. }
  1737. } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
  1738. os_free(bss->eap_fast_a_id_info);
  1739. bss->eap_fast_a_id_info = os_strdup(pos);
  1740. } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
  1741. bss->eap_fast_prov = atoi(pos);
  1742. } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
  1743. bss->pac_key_lifetime = atoi(pos);
  1744. } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
  1745. bss->pac_key_refresh_time = atoi(pos);
  1746. #endif /* EAP_SERVER_FAST */
  1747. #ifdef EAP_SERVER_SIM
  1748. } else if (os_strcmp(buf, "eap_sim_db") == 0) {
  1749. os_free(bss->eap_sim_db);
  1750. bss->eap_sim_db = os_strdup(pos);
  1751. } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
  1752. bss->eap_sim_aka_result_ind = atoi(pos);
  1753. #endif /* EAP_SERVER_SIM */
  1754. #ifdef EAP_SERVER_TNC
  1755. } else if (os_strcmp(buf, "tnc") == 0) {
  1756. bss->tnc = atoi(pos);
  1757. #endif /* EAP_SERVER_TNC */
  1758. #ifdef EAP_SERVER_PWD
  1759. } else if (os_strcmp(buf, "pwd_group") == 0) {
  1760. bss->pwd_group = atoi(pos);
  1761. #endif /* EAP_SERVER_PWD */
  1762. #endif /* EAP_SERVER */
  1763. } else if (os_strcmp(buf, "eap_message") == 0) {
  1764. char *term;
  1765. bss->eap_req_id_text = os_strdup(pos);
  1766. if (bss->eap_req_id_text == NULL) {
  1767. wpa_printf(MSG_ERROR, "Line %d: Failed to allocate memory for eap_req_id_text",
  1768. line);
  1769. return 1;
  1770. }
  1771. bss->eap_req_id_text_len = os_strlen(bss->eap_req_id_text);
  1772. term = os_strstr(bss->eap_req_id_text, "\\0");
  1773. if (term) {
  1774. *term++ = '\0';
  1775. os_memmove(term, term + 1,
  1776. bss->eap_req_id_text_len -
  1777. (term - bss->eap_req_id_text) - 1);
  1778. bss->eap_req_id_text_len--;
  1779. }
  1780. } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
  1781. bss->default_wep_key_len = atoi(pos);
  1782. if (bss->default_wep_key_len > 13) {
  1783. wpa_printf(MSG_ERROR, "Line %d: invalid WEP key len %lu (= %lu bits)",
  1784. line,
  1785. (unsigned long) bss->default_wep_key_len,
  1786. (unsigned long)
  1787. bss->default_wep_key_len * 8);
  1788. return 1;
  1789. }
  1790. } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
  1791. bss->individual_wep_key_len = atoi(pos);
  1792. if (bss->individual_wep_key_len < 0 ||
  1793. bss->individual_wep_key_len > 13) {
  1794. wpa_printf(MSG_ERROR, "Line %d: invalid WEP key len %d (= %d bits)",
  1795. line, bss->individual_wep_key_len,
  1796. bss->individual_wep_key_len * 8);
  1797. return 1;
  1798. }
  1799. } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
  1800. bss->wep_rekeying_period = atoi(pos);
  1801. if (bss->wep_rekeying_period < 0) {
  1802. wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
  1803. line, bss->wep_rekeying_period);
  1804. return 1;
  1805. }
  1806. } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
  1807. bss->eap_reauth_period = atoi(pos);
  1808. if (bss->eap_reauth_period < 0) {
  1809. wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
  1810. line, bss->eap_reauth_period);
  1811. return 1;
  1812. }
  1813. } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
  1814. bss->eapol_key_index_workaround = atoi(pos);
  1815. #ifdef CONFIG_IAPP
  1816. } else if (os_strcmp(buf, "iapp_interface") == 0) {
  1817. bss->ieee802_11f = 1;
  1818. os_strlcpy(bss->iapp_iface, pos, sizeof(bss->iapp_iface));
  1819. #endif /* CONFIG_IAPP */
  1820. } else if (os_strcmp(buf, "own_ip_addr") == 0) {
  1821. if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
  1822. wpa_printf(MSG_ERROR,
  1823. "Line %d: invalid IP address '%s'",
  1824. line, pos);
  1825. return 1;
  1826. }
  1827. } else if (os_strcmp(buf, "nas_identifier") == 0) {
  1828. bss->nas_identifier = os_strdup(pos);
  1829. #ifndef CONFIG_NO_RADIUS
  1830. } else if (os_strcmp(buf, "auth_server_addr") == 0) {
  1831. if (hostapd_config_read_radius_addr(
  1832. &bss->radius->auth_servers,
  1833. &bss->radius->num_auth_servers, pos, 1812,
  1834. &bss->radius->auth_server)) {
  1835. wpa_printf(MSG_ERROR,
  1836. "Line %d: invalid IP address '%s'",
  1837. line, pos);
  1838. return 1;
  1839. }
  1840. } else if (bss->radius->auth_server &&
  1841. os_strcmp(buf, "auth_server_port") == 0) {
  1842. bss->radius->auth_server->port = atoi(pos);
  1843. } else if (bss->radius->auth_server &&
  1844. os_strcmp(buf, "auth_server_shared_secret") == 0) {
  1845. int len = os_strlen(pos);
  1846. if (len == 0) {
  1847. /* RFC 2865, Ch. 3 */
  1848. wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
  1849. line);
  1850. return 1;
  1851. }
  1852. bss->radius->auth_server->shared_secret = (u8 *) os_strdup(pos);
  1853. bss->radius->auth_server->shared_secret_len = len;
  1854. } else if (os_strcmp(buf, "acct_server_addr") == 0) {
  1855. if (hostapd_config_read_radius_addr(
  1856. &bss->radius->acct_servers,
  1857. &bss->radius->num_acct_servers, pos, 1813,
  1858. &bss->radius->acct_server)) {
  1859. wpa_printf(MSG_ERROR,
  1860. "Line %d: invalid IP address '%s'",
  1861. line, pos);
  1862. return 1;
  1863. }
  1864. } else if (bss->radius->acct_server &&
  1865. os_strcmp(buf, "acct_server_port") == 0) {
  1866. bss->radius->acct_server->port = atoi(pos);
  1867. } else if (bss->radius->acct_server &&
  1868. os_strcmp(buf, "acct_server_shared_secret") == 0) {
  1869. int len = os_strlen(pos);
  1870. if (len == 0) {
  1871. /* RFC 2865, Ch. 3 */
  1872. wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
  1873. line);
  1874. return 1;
  1875. }
  1876. bss->radius->acct_server->shared_secret = (u8 *) os_strdup(pos);
  1877. bss->radius->acct_server->shared_secret_len = len;
  1878. } else if (os_strcmp(buf, "radius_retry_primary_interval") == 0) {
  1879. bss->radius->retry_primary_interval = atoi(pos);
  1880. } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0) {
  1881. bss->acct_interim_interval = atoi(pos);
  1882. } else if (os_strcmp(buf, "radius_request_cui") == 0) {
  1883. bss->radius_request_cui = atoi(pos);
  1884. } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
  1885. struct hostapd_radius_attr *attr, *a;
  1886. attr = hostapd_parse_radius_attr(pos);
  1887. if (attr == NULL) {
  1888. wpa_printf(MSG_ERROR,
  1889. "Line %d: invalid radius_auth_req_attr",
  1890. line);
  1891. return 1;
  1892. } else if (bss->radius_auth_req_attr == NULL) {
  1893. bss->radius_auth_req_attr = attr;
  1894. } else {
  1895. a = bss->radius_auth_req_attr;
  1896. while (a->next)
  1897. a = a->next;
  1898. a->next = attr;
  1899. }
  1900. } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
  1901. struct hostapd_radius_attr *attr, *a;
  1902. attr = hostapd_parse_radius_attr(pos);
  1903. if (attr == NULL) {
  1904. wpa_printf(MSG_ERROR,
  1905. "Line %d: invalid radius_acct_req_attr",
  1906. line);
  1907. return 1;
  1908. } else if (bss->radius_acct_req_attr == NULL) {
  1909. bss->radius_acct_req_attr = attr;
  1910. } else {
  1911. a = bss->radius_acct_req_attr;
  1912. while (a->next)
  1913. a = a->next;
  1914. a->next = attr;
  1915. }
  1916. } else if (os_strcmp(buf, "radius_das_port") == 0) {
  1917. bss->radius_das_port = atoi(pos);
  1918. } else if (os_strcmp(buf, "radius_das_client") == 0) {
  1919. if (hostapd_parse_das_client(bss, pos) < 0) {
  1920. wpa_printf(MSG_ERROR, "Line %d: invalid DAS client",
  1921. line);
  1922. return 1;
  1923. }
  1924. } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
  1925. bss->radius_das_time_window = atoi(pos);
  1926. } else if (os_strcmp(buf, "radius_das_require_event_timestamp") == 0) {
  1927. bss->radius_das_require_event_timestamp = atoi(pos);
  1928. #endif /* CONFIG_NO_RADIUS */
  1929. } else if (os_strcmp(buf, "auth_algs") == 0) {
  1930. bss->auth_algs = atoi(pos);
  1931. if (bss->auth_algs == 0) {
  1932. wpa_printf(MSG_ERROR, "Line %d: no authentication algorithms allowed",
  1933. line);
  1934. return 1;
  1935. }
  1936. } else if (os_strcmp(buf, "max_num_sta") == 0) {
  1937. bss->max_num_sta = atoi(pos);
  1938. if (bss->max_num_sta < 0 ||
  1939. bss->max_num_sta > MAX_STA_COUNT) {
  1940. wpa_printf(MSG_ERROR, "Line %d: Invalid max_num_sta=%d; allowed range 0..%d",
  1941. line, bss->max_num_sta, MAX_STA_COUNT);
  1942. return 1;
  1943. }
  1944. } else if (os_strcmp(buf, "wpa") == 0) {
  1945. bss->wpa = atoi(pos);
  1946. } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
  1947. bss->wpa_group_rekey = atoi(pos);
  1948. } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
  1949. bss->wpa_strict_rekey = atoi(pos);
  1950. } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
  1951. bss->wpa_gmk_rekey = atoi(pos);
  1952. } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
  1953. bss->wpa_ptk_rekey = atoi(pos);
  1954. } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
  1955. int len = os_strlen(pos);
  1956. if (len < 8 || len > 63) {
  1957. wpa_printf(MSG_ERROR, "Line %d: invalid WPA passphrase length %d (expected 8..63)",
  1958. line, len);
  1959. return 1;
  1960. }
  1961. os_free(bss->ssid.wpa_passphrase);
  1962. bss->ssid.wpa_passphrase = os_strdup(pos);
  1963. if (bss->ssid.wpa_passphrase) {
  1964. os_free(bss->ssid.wpa_psk);
  1965. bss->ssid.wpa_psk = NULL;
  1966. bss->ssid.wpa_passphrase_set = 1;
  1967. }
  1968. } else if (os_strcmp(buf, "wpa_psk") == 0) {
  1969. os_free(bss->ssid.wpa_psk);
  1970. bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
  1971. if (bss->ssid.wpa_psk == NULL)
  1972. return 1;
  1973. if (hexstr2bin(pos, bss->ssid.wpa_psk->psk, PMK_LEN) ||
  1974. pos[PMK_LEN * 2] != '\0') {
  1975. wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
  1976. line, pos);
  1977. os_free(bss->ssid.wpa_psk);
  1978. bss->ssid.wpa_psk = NULL;
  1979. return 1;
  1980. }
  1981. bss->ssid.wpa_psk->group = 1;
  1982. os_free(bss->ssid.wpa_passphrase);
  1983. bss->ssid.wpa_passphrase = NULL;
  1984. bss->ssid.wpa_psk_set = 1;
  1985. } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
  1986. os_free(bss->ssid.wpa_psk_file);
  1987. bss->ssid.wpa_psk_file = os_strdup(pos);
  1988. if (!bss->ssid.wpa_psk_file) {
  1989. wpa_printf(MSG_ERROR, "Line %d: allocation failed",
  1990. line);
  1991. return 1;
  1992. }
  1993. } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
  1994. bss->wpa_key_mgmt = hostapd_config_parse_key_mgmt(line, pos);
  1995. if (bss->wpa_key_mgmt == -1)
  1996. return 1;
  1997. } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
  1998. bss->wpa_psk_radius = atoi(pos);
  1999. if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
  2000. bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
  2001. bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
  2002. wpa_printf(MSG_ERROR,
  2003. "Line %d: unknown wpa_psk_radius %d",
  2004. line, bss->wpa_psk_radius);
  2005. return 1;
  2006. }
  2007. } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
  2008. bss->wpa_pairwise = hostapd_config_parse_cipher(line, pos);
  2009. if (bss->wpa_pairwise == -1 || bss->wpa_pairwise == 0)
  2010. return 1;
  2011. if (bss->wpa_pairwise &
  2012. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
  2013. wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
  2014. bss->wpa_pairwise, pos);
  2015. return 1;
  2016. }
  2017. } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
  2018. bss->rsn_pairwise = hostapd_config_parse_cipher(line, pos);
  2019. if (bss->rsn_pairwise == -1 || bss->rsn_pairwise == 0)
  2020. return 1;
  2021. if (bss->rsn_pairwise &
  2022. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
  2023. wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
  2024. bss->rsn_pairwise, pos);
  2025. return 1;
  2026. }
  2027. #ifdef CONFIG_RSN_PREAUTH
  2028. } else if (os_strcmp(buf, "rsn_preauth") == 0) {
  2029. bss->rsn_preauth = atoi(pos);
  2030. } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
  2031. bss->rsn_preauth_interfaces = os_strdup(pos);
  2032. #endif /* CONFIG_RSN_PREAUTH */
  2033. #ifdef CONFIG_PEERKEY
  2034. } else if (os_strcmp(buf, "peerkey") == 0) {
  2035. bss->peerkey = atoi(pos);
  2036. #endif /* CONFIG_PEERKEY */
  2037. #ifdef CONFIG_IEEE80211R
  2038. } else if (os_strcmp(buf, "mobility_domain") == 0) {
  2039. if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
  2040. hexstr2bin(pos, bss->mobility_domain,
  2041. MOBILITY_DOMAIN_ID_LEN) != 0) {
  2042. wpa_printf(MSG_ERROR,
  2043. "Line %d: Invalid mobility_domain '%s'",
  2044. line, pos);
  2045. return 1;
  2046. }
  2047. } else if (os_strcmp(buf, "r1_key_holder") == 0) {
  2048. if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
  2049. hexstr2bin(pos, bss->r1_key_holder, FT_R1KH_ID_LEN) != 0) {
  2050. wpa_printf(MSG_ERROR,
  2051. "Line %d: Invalid r1_key_holder '%s'",
  2052. line, pos);
  2053. return 1;
  2054. }
  2055. } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
  2056. bss->r0_key_lifetime = atoi(pos);
  2057. } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
  2058. bss->reassociation_deadline = atoi(pos);
  2059. } else if (os_strcmp(buf, "r0kh") == 0) {
  2060. if (add_r0kh(bss, pos) < 0) {
  2061. wpa_printf(MSG_DEBUG, "Line %d: Invalid r0kh '%s'",
  2062. line, pos);
  2063. return 1;
  2064. }
  2065. } else if (os_strcmp(buf, "r1kh") == 0) {
  2066. if (add_r1kh(bss, pos) < 0) {
  2067. wpa_printf(MSG_DEBUG, "Line %d: Invalid r1kh '%s'",
  2068. line, pos);
  2069. return 1;
  2070. }
  2071. } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
  2072. bss->pmk_r1_push = atoi(pos);
  2073. } else if (os_strcmp(buf, "ft_over_ds") == 0) {
  2074. bss->ft_over_ds = atoi(pos);
  2075. #endif /* CONFIG_IEEE80211R */
  2076. #ifndef CONFIG_NO_CTRL_IFACE
  2077. } else if (os_strcmp(buf, "ctrl_interface") == 0) {
  2078. os_free(bss->ctrl_interface);
  2079. bss->ctrl_interface = os_strdup(pos);
  2080. } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
  2081. #ifndef CONFIG_NATIVE_WINDOWS
  2082. struct group *grp;
  2083. char *endp;
  2084. const char *group = pos;
  2085. grp = getgrnam(group);
  2086. if (grp) {
  2087. bss->ctrl_interface_gid = grp->gr_gid;
  2088. bss->ctrl_interface_gid_set = 1;
  2089. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d (from group name '%s')",
  2090. bss->ctrl_interface_gid, group);
  2091. return 0;
  2092. }
  2093. /* Group name not found - try to parse this as gid */
  2094. bss->ctrl_interface_gid = strtol(group, &endp, 10);
  2095. if (*group == '\0' || *endp != '\0') {
  2096. wpa_printf(MSG_DEBUG, "Line %d: Invalid group '%s'",
  2097. line, group);
  2098. return 1;
  2099. }
  2100. bss->ctrl_interface_gid_set = 1;
  2101. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
  2102. bss->ctrl_interface_gid);
  2103. #endif /* CONFIG_NATIVE_WINDOWS */
  2104. #endif /* CONFIG_NO_CTRL_IFACE */
  2105. #ifdef RADIUS_SERVER
  2106. } else if (os_strcmp(buf, "radius_server_clients") == 0) {
  2107. os_free(bss->radius_server_clients);
  2108. bss->radius_server_clients = os_strdup(pos);
  2109. } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
  2110. bss->radius_server_auth_port = atoi(pos);
  2111. } else if (os_strcmp(buf, "radius_server_acct_port") == 0) {
  2112. bss->radius_server_acct_port = atoi(pos);
  2113. } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
  2114. bss->radius_server_ipv6 = atoi(pos);
  2115. #endif /* RADIUS_SERVER */
  2116. } else if (os_strcmp(buf, "test_socket") == 0) {
  2117. os_free(bss->test_socket);
  2118. bss->test_socket = os_strdup(pos);
  2119. } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
  2120. bss->use_pae_group_addr = atoi(pos);
  2121. } else if (os_strcmp(buf, "hw_mode") == 0) {
  2122. if (os_strcmp(pos, "a") == 0)
  2123. conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
  2124. else if (os_strcmp(pos, "b") == 0)
  2125. conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
  2126. else if (os_strcmp(pos, "g") == 0)
  2127. conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
  2128. else if (os_strcmp(pos, "ad") == 0)
  2129. conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
  2130. else {
  2131. wpa_printf(MSG_ERROR, "Line %d: unknown hw_mode '%s'",
  2132. line, pos);
  2133. return 1;
  2134. }
  2135. } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
  2136. if (os_strcmp(pos, "a") == 0)
  2137. bss->wps_rf_bands = WPS_RF_50GHZ;
  2138. else if (os_strcmp(pos, "g") == 0 ||
  2139. os_strcmp(pos, "b") == 0)
  2140. bss->wps_rf_bands = WPS_RF_24GHZ;
  2141. else if (os_strcmp(pos, "ag") == 0 ||
  2142. os_strcmp(pos, "ga") == 0)
  2143. bss->wps_rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ;
  2144. else {
  2145. wpa_printf(MSG_ERROR,
  2146. "Line %d: unknown wps_rf_band '%s'",
  2147. line, pos);
  2148. return 1;
  2149. }
  2150. } else if (os_strcmp(buf, "channel") == 0) {
  2151. if (os_strcmp(pos, "acs_survey") == 0) {
  2152. #ifndef CONFIG_ACS
  2153. wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled",
  2154. line);
  2155. return 1;
  2156. #endif /* CONFIG_ACS */
  2157. conf->channel = 0;
  2158. } else
  2159. conf->channel = atoi(pos);
  2160. } else if (os_strcmp(buf, "chanlist") == 0) {
  2161. if (hostapd_parse_intlist(&conf->chanlist, pos)) {
  2162. wpa_printf(MSG_ERROR, "Line %d: invalid channel list",
  2163. line);
  2164. return 1;
  2165. }
  2166. } else if (os_strcmp(buf, "beacon_int") == 0) {
  2167. int val = atoi(pos);
  2168. /* MIB defines range as 1..65535, but very small values
  2169. * cause problems with the current implementation.
  2170. * Since it is unlikely that this small numbers are
  2171. * useful in real life scenarios, do not allow beacon
  2172. * period to be set below 15 TU. */
  2173. if (val < 15 || val > 65535) {
  2174. wpa_printf(MSG_ERROR, "Line %d: invalid beacon_int %d (expected 15..65535)",
  2175. line, val);
  2176. return 1;
  2177. }
  2178. conf->beacon_int = val;
  2179. #ifdef CONFIG_ACS
  2180. } else if (os_strcmp(buf, "acs_num_scans") == 0) {
  2181. int val = atoi(pos);
  2182. if (val <= 0 || val > 100) {
  2183. wpa_printf(MSG_ERROR, "Line %d: invalid acs_num_scans %d (expected 1..100)",
  2184. line, val);
  2185. return 1;
  2186. }
  2187. conf->acs_num_scans = val;
  2188. #endif /* CONFIG_ACS */
  2189. } else if (os_strcmp(buf, "dtim_period") == 0) {
  2190. bss->dtim_period = atoi(pos);
  2191. if (bss->dtim_period < 1 || bss->dtim_period > 255) {
  2192. wpa_printf(MSG_ERROR, "Line %d: invalid dtim_period %d",
  2193. line, bss->dtim_period);
  2194. return 1;
  2195. }
  2196. } else if (os_strcmp(buf, "rts_threshold") == 0) {
  2197. conf->rts_threshold = atoi(pos);
  2198. if (conf->rts_threshold < 0 || conf->rts_threshold > 2347) {
  2199. wpa_printf(MSG_ERROR,
  2200. "Line %d: invalid rts_threshold %d",
  2201. line, conf->rts_threshold);
  2202. return 1;
  2203. }
  2204. } else if (os_strcmp(buf, "fragm_threshold") == 0) {
  2205. conf->fragm_threshold = atoi(pos);
  2206. if (conf->fragm_threshold < 256 ||
  2207. conf->fragm_threshold > 2346) {
  2208. wpa_printf(MSG_ERROR,
  2209. "Line %d: invalid fragm_threshold %d",
  2210. line, conf->fragm_threshold);
  2211. return 1;
  2212. }
  2213. } else if (os_strcmp(buf, "send_probe_response") == 0) {
  2214. int val = atoi(pos);
  2215. if (val != 0 && val != 1) {
  2216. wpa_printf(MSG_ERROR, "Line %d: invalid send_probe_response %d (expected 0 or 1)",
  2217. line, val);
  2218. return 1;
  2219. }
  2220. conf->send_probe_response = val;
  2221. } else if (os_strcmp(buf, "supported_rates") == 0) {
  2222. if (hostapd_parse_intlist(&conf->supported_rates, pos)) {
  2223. wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
  2224. line);
  2225. return 1;
  2226. }
  2227. } else if (os_strcmp(buf, "basic_rates") == 0) {
  2228. if (hostapd_parse_intlist(&conf->basic_rates, pos)) {
  2229. wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
  2230. line);
  2231. return 1;
  2232. }
  2233. } else if (os_strcmp(buf, "preamble") == 0) {
  2234. if (atoi(pos))
  2235. conf->preamble = SHORT_PREAMBLE;
  2236. else
  2237. conf->preamble = LONG_PREAMBLE;
  2238. } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
  2239. bss->ignore_broadcast_ssid = atoi(pos);
  2240. } else if (os_strcmp(buf, "wep_default_key") == 0) {
  2241. bss->ssid.wep.idx = atoi(pos);
  2242. if (bss->ssid.wep.idx > 3) {
  2243. wpa_printf(MSG_ERROR,
  2244. "Invalid wep_default_key index %d",
  2245. bss->ssid.wep.idx);
  2246. return 1;
  2247. }
  2248. } else if (os_strcmp(buf, "wep_key0") == 0 ||
  2249. os_strcmp(buf, "wep_key1") == 0 ||
  2250. os_strcmp(buf, "wep_key2") == 0 ||
  2251. os_strcmp(buf, "wep_key3") == 0) {
  2252. if (hostapd_config_read_wep(&bss->ssid.wep,
  2253. buf[7] - '0', pos)) {
  2254. wpa_printf(MSG_ERROR, "Line %d: invalid WEP key '%s'",
  2255. line, buf);
  2256. return 1;
  2257. }
  2258. #ifndef CONFIG_NO_VLAN
  2259. } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
  2260. bss->ssid.dynamic_vlan = atoi(pos);
  2261. } else if (os_strcmp(buf, "vlan_file") == 0) {
  2262. if (hostapd_config_read_vlan_file(bss, pos)) {
  2263. wpa_printf(MSG_ERROR, "Line %d: failed to read VLAN file '%s'",
  2264. line, pos);
  2265. return 1;
  2266. }
  2267. } else if (os_strcmp(buf, "vlan_naming") == 0) {
  2268. bss->ssid.vlan_naming = atoi(pos);
  2269. if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
  2270. bss->ssid.vlan_naming < 0) {
  2271. wpa_printf(MSG_ERROR,
  2272. "Line %d: invalid naming scheme %d",
  2273. line, bss->ssid.vlan_naming);
  2274. return 1;
  2275. }
  2276. #ifdef CONFIG_FULL_DYNAMIC_VLAN
  2277. } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
  2278. bss->ssid.vlan_tagged_interface = os_strdup(pos);
  2279. #endif /* CONFIG_FULL_DYNAMIC_VLAN */
  2280. #endif /* CONFIG_NO_VLAN */
  2281. } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
  2282. conf->ap_table_max_size = atoi(pos);
  2283. } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
  2284. conf->ap_table_expiration_time = atoi(pos);
  2285. } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
  2286. if (hostapd_config_tx_queue(conf, buf, pos)) {
  2287. wpa_printf(MSG_ERROR, "Line %d: invalid TX queue item",
  2288. line);
  2289. return 1;
  2290. }
  2291. } else if (os_strcmp(buf, "wme_enabled") == 0 ||
  2292. os_strcmp(buf, "wmm_enabled") == 0) {
  2293. bss->wmm_enabled = atoi(pos);
  2294. } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
  2295. bss->wmm_uapsd = atoi(pos);
  2296. } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
  2297. os_strncmp(buf, "wmm_ac_", 7) == 0) {
  2298. if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf, pos)) {
  2299. wpa_printf(MSG_ERROR, "Line %d: invalid WMM ac item",
  2300. line);
  2301. return 1;
  2302. }
  2303. } else if (os_strcmp(buf, "bss") == 0) {
  2304. if (hostapd_config_bss(conf, pos)) {
  2305. wpa_printf(MSG_ERROR, "Line %d: invalid bss item",
  2306. line);
  2307. return 1;
  2308. }
  2309. } else if (os_strcmp(buf, "bssid") == 0) {
  2310. if (hwaddr_aton(pos, bss->bssid)) {
  2311. wpa_printf(MSG_ERROR, "Line %d: invalid bssid item",
  2312. line);
  2313. return 1;
  2314. }
  2315. #ifdef CONFIG_IEEE80211W
  2316. } else if (os_strcmp(buf, "ieee80211w") == 0) {
  2317. bss->ieee80211w = atoi(pos);
  2318. } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
  2319. bss->assoc_sa_query_max_timeout = atoi(pos);
  2320. if (bss->assoc_sa_query_max_timeout == 0) {
  2321. wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_max_timeout",
  2322. line);
  2323. return 1;
  2324. }
  2325. } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0) {
  2326. bss->assoc_sa_query_retry_timeout = atoi(pos);
  2327. if (bss->assoc_sa_query_retry_timeout == 0) {
  2328. wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_retry_timeout",
  2329. line);
  2330. return 1;
  2331. }
  2332. #endif /* CONFIG_IEEE80211W */
  2333. #ifdef CONFIG_IEEE80211N
  2334. } else if (os_strcmp(buf, "ieee80211n") == 0) {
  2335. conf->ieee80211n = atoi(pos);
  2336. } else if (os_strcmp(buf, "ht_capab") == 0) {
  2337. if (hostapd_config_ht_capab(conf, pos) < 0) {
  2338. wpa_printf(MSG_ERROR, "Line %d: invalid ht_capab",
  2339. line);
  2340. return 1;
  2341. }
  2342. } else if (os_strcmp(buf, "require_ht") == 0) {
  2343. conf->require_ht = atoi(pos);
  2344. } else if (os_strcmp(buf, "obss_interval") == 0) {
  2345. conf->obss_interval = atoi(pos);
  2346. #endif /* CONFIG_IEEE80211N */
  2347. #ifdef CONFIG_IEEE80211AC
  2348. } else if (os_strcmp(buf, "ieee80211ac") == 0) {
  2349. conf->ieee80211ac = atoi(pos);
  2350. } else if (os_strcmp(buf, "vht_capab") == 0) {
  2351. if (hostapd_config_vht_capab(conf, pos) < 0) {
  2352. wpa_printf(MSG_ERROR, "Line %d: invalid vht_capab",
  2353. line);
  2354. return 1;
  2355. }
  2356. } else if (os_strcmp(buf, "require_vht") == 0) {
  2357. conf->require_vht = atoi(pos);
  2358. } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
  2359. conf->vht_oper_chwidth = atoi(pos);
  2360. } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0) {
  2361. conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
  2362. } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0) {
  2363. conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
  2364. #endif /* CONFIG_IEEE80211AC */
  2365. } else if (os_strcmp(buf, "max_listen_interval") == 0) {
  2366. bss->max_listen_interval = atoi(pos);
  2367. } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
  2368. bss->disable_pmksa_caching = atoi(pos);
  2369. } else if (os_strcmp(buf, "okc") == 0) {
  2370. bss->okc = atoi(pos);
  2371. #ifdef CONFIG_WPS
  2372. } else if (os_strcmp(buf, "wps_state") == 0) {
  2373. bss->wps_state = atoi(pos);
  2374. if (bss->wps_state < 0 || bss->wps_state > 2) {
  2375. wpa_printf(MSG_ERROR, "Line %d: invalid wps_state",
  2376. line);
  2377. return 1;
  2378. }
  2379. } else if (os_strcmp(buf, "wps_independent") == 0) {
  2380. bss->wps_independent = atoi(pos);
  2381. } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
  2382. bss->ap_setup_locked = atoi(pos);
  2383. } else if (os_strcmp(buf, "uuid") == 0) {
  2384. if (uuid_str2bin(pos, bss->uuid)) {
  2385. wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
  2386. return 1;
  2387. }
  2388. } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
  2389. os_free(bss->wps_pin_requests);
  2390. bss->wps_pin_requests = os_strdup(pos);
  2391. } else if (os_strcmp(buf, "device_name") == 0) {
  2392. if (os_strlen(pos) > 32) {
  2393. wpa_printf(MSG_ERROR, "Line %d: Too long "
  2394. "device_name", line);
  2395. return 1;
  2396. }
  2397. os_free(bss->device_name);
  2398. bss->device_name = os_strdup(pos);
  2399. } else if (os_strcmp(buf, "manufacturer") == 0) {
  2400. if (os_strlen(pos) > 64) {
  2401. wpa_printf(MSG_ERROR, "Line %d: Too long manufacturer",
  2402. line);
  2403. return 1;
  2404. }
  2405. os_free(bss->manufacturer);
  2406. bss->manufacturer = os_strdup(pos);
  2407. } else if (os_strcmp(buf, "model_name") == 0) {
  2408. if (os_strlen(pos) > 32) {
  2409. wpa_printf(MSG_ERROR, "Line %d: Too long model_name",
  2410. line);
  2411. return 1;
  2412. }
  2413. os_free(bss->model_name);
  2414. bss->model_name = os_strdup(pos);
  2415. } else if (os_strcmp(buf, "model_number") == 0) {
  2416. if (os_strlen(pos) > 32) {
  2417. wpa_printf(MSG_ERROR, "Line %d: Too long model_number",
  2418. line);
  2419. return 1;
  2420. }
  2421. os_free(bss->model_number);
  2422. bss->model_number = os_strdup(pos);
  2423. } else if (os_strcmp(buf, "serial_number") == 0) {
  2424. if (os_strlen(pos) > 32) {
  2425. wpa_printf(MSG_ERROR, "Line %d: Too long serial_number",
  2426. line);
  2427. return 1;
  2428. }
  2429. os_free(bss->serial_number);
  2430. bss->serial_number = os_strdup(pos);
  2431. } else if (os_strcmp(buf, "device_type") == 0) {
  2432. if (wps_dev_type_str2bin(pos, bss->device_type))
  2433. return 1;
  2434. } else if (os_strcmp(buf, "config_methods") == 0) {
  2435. os_free(bss->config_methods);
  2436. bss->config_methods = os_strdup(pos);
  2437. } else if (os_strcmp(buf, "os_version") == 0) {
  2438. if (hexstr2bin(pos, bss->os_version, 4)) {
  2439. wpa_printf(MSG_ERROR, "Line %d: invalid os_version",
  2440. line);
  2441. return 1;
  2442. }
  2443. } else if (os_strcmp(buf, "ap_pin") == 0) {
  2444. os_free(bss->ap_pin);
  2445. bss->ap_pin = os_strdup(pos);
  2446. } else if (os_strcmp(buf, "skip_cred_build") == 0) {
  2447. bss->skip_cred_build = atoi(pos);
  2448. } else if (os_strcmp(buf, "extra_cred") == 0) {
  2449. os_free(bss->extra_cred);
  2450. bss->extra_cred = (u8 *) os_readfile(pos, &bss->extra_cred_len);
  2451. if (bss->extra_cred == NULL) {
  2452. wpa_printf(MSG_ERROR, "Line %d: could not read Credentials from '%s'",
  2453. line, pos);
  2454. return 1;
  2455. }
  2456. } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
  2457. bss->wps_cred_processing = atoi(pos);
  2458. } else if (os_strcmp(buf, "ap_settings") == 0) {
  2459. os_free(bss->ap_settings);
  2460. bss->ap_settings =
  2461. (u8 *) os_readfile(pos, &bss->ap_settings_len);
  2462. if (bss->ap_settings == NULL) {
  2463. wpa_printf(MSG_ERROR, "Line %d: could not read AP Settings from '%s'",
  2464. line, pos);
  2465. return 1;
  2466. }
  2467. } else if (os_strcmp(buf, "upnp_iface") == 0) {
  2468. bss->upnp_iface = os_strdup(pos);
  2469. } else if (os_strcmp(buf, "friendly_name") == 0) {
  2470. os_free(bss->friendly_name);
  2471. bss->friendly_name = os_strdup(pos);
  2472. } else if (os_strcmp(buf, "manufacturer_url") == 0) {
  2473. os_free(bss->manufacturer_url);
  2474. bss->manufacturer_url = os_strdup(pos);
  2475. } else if (os_strcmp(buf, "model_description") == 0) {
  2476. os_free(bss->model_description);
  2477. bss->model_description = os_strdup(pos);
  2478. } else if (os_strcmp(buf, "model_url") == 0) {
  2479. os_free(bss->model_url);
  2480. bss->model_url = os_strdup(pos);
  2481. } else if (os_strcmp(buf, "upc") == 0) {
  2482. os_free(bss->upc);
  2483. bss->upc = os_strdup(pos);
  2484. } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
  2485. bss->pbc_in_m1 = atoi(pos);
  2486. } else if (os_strcmp(buf, "server_id") == 0) {
  2487. os_free(bss->server_id);
  2488. bss->server_id = os_strdup(pos);
  2489. #ifdef CONFIG_WPS_NFC
  2490. } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
  2491. bss->wps_nfc_dev_pw_id = atoi(pos);
  2492. if (bss->wps_nfc_dev_pw_id < 0x10 ||
  2493. bss->wps_nfc_dev_pw_id > 0xffff) {
  2494. wpa_printf(MSG_ERROR, "Line %d: Invalid wps_nfc_dev_pw_id value",
  2495. line);
  2496. return 1;
  2497. }
  2498. bss->wps_nfc_pw_from_config = 1;
  2499. } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
  2500. wpabuf_free(bss->wps_nfc_dh_pubkey);
  2501. bss->wps_nfc_dh_pubkey = hostapd_parse_bin(pos);
  2502. bss->wps_nfc_pw_from_config = 1;
  2503. } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
  2504. wpabuf_free(bss->wps_nfc_dh_privkey);
  2505. bss->wps_nfc_dh_privkey = hostapd_parse_bin(pos);
  2506. bss->wps_nfc_pw_from_config = 1;
  2507. } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
  2508. wpabuf_free(bss->wps_nfc_dev_pw);
  2509. bss->wps_nfc_dev_pw = hostapd_parse_bin(pos);
  2510. bss->wps_nfc_pw_from_config = 1;
  2511. #endif /* CONFIG_WPS_NFC */
  2512. #endif /* CONFIG_WPS */
  2513. #ifdef CONFIG_P2P_MANAGER
  2514. } else if (os_strcmp(buf, "manage_p2p") == 0) {
  2515. if (atoi(pos))
  2516. bss->p2p |= P2P_MANAGE;
  2517. else
  2518. bss->p2p &= ~P2P_MANAGE;
  2519. } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
  2520. if (atoi(pos))
  2521. bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
  2522. else
  2523. bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
  2524. #endif /* CONFIG_P2P_MANAGER */
  2525. } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
  2526. bss->disassoc_low_ack = atoi(pos);
  2527. } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
  2528. if (atoi(pos))
  2529. bss->tdls |= TDLS_PROHIBIT;
  2530. else
  2531. bss->tdls &= ~TDLS_PROHIBIT;
  2532. } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
  2533. if (atoi(pos))
  2534. bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
  2535. else
  2536. bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
  2537. #ifdef CONFIG_RSN_TESTING
  2538. } else if (os_strcmp(buf, "rsn_testing") == 0) {
  2539. extern int rsn_testing;
  2540. rsn_testing = atoi(pos);
  2541. #endif /* CONFIG_RSN_TESTING */
  2542. } else if (os_strcmp(buf, "time_advertisement") == 0) {
  2543. bss->time_advertisement = atoi(pos);
  2544. } else if (os_strcmp(buf, "time_zone") == 0) {
  2545. size_t tz_len = os_strlen(pos);
  2546. if (tz_len < 4 || tz_len > 255) {
  2547. wpa_printf(MSG_DEBUG, "Line %d: invalid time_zone",
  2548. line);
  2549. return 1;
  2550. }
  2551. os_free(bss->time_zone);
  2552. bss->time_zone = os_strdup(pos);
  2553. if (bss->time_zone == NULL)
  2554. return 1;
  2555. #ifdef CONFIG_WNM
  2556. } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
  2557. bss->wnm_sleep_mode = atoi(pos);
  2558. } else if (os_strcmp(buf, "bss_transition") == 0) {
  2559. bss->bss_transition = atoi(pos);
  2560. #endif /* CONFIG_WNM */
  2561. #ifdef CONFIG_INTERWORKING
  2562. } else if (os_strcmp(buf, "interworking") == 0) {
  2563. bss->interworking = atoi(pos);
  2564. } else if (os_strcmp(buf, "access_network_type") == 0) {
  2565. bss->access_network_type = atoi(pos);
  2566. if (bss->access_network_type < 0 ||
  2567. bss->access_network_type > 15) {
  2568. wpa_printf(MSG_ERROR,
  2569. "Line %d: invalid access_network_type",
  2570. line);
  2571. return 1;
  2572. }
  2573. } else if (os_strcmp(buf, "internet") == 0) {
  2574. bss->internet = atoi(pos);
  2575. } else if (os_strcmp(buf, "asra") == 0) {
  2576. bss->asra = atoi(pos);
  2577. } else if (os_strcmp(buf, "esr") == 0) {
  2578. bss->esr = atoi(pos);
  2579. } else if (os_strcmp(buf, "uesa") == 0) {
  2580. bss->uesa = atoi(pos);
  2581. } else if (os_strcmp(buf, "venue_group") == 0) {
  2582. bss->venue_group = atoi(pos);
  2583. bss->venue_info_set = 1;
  2584. } else if (os_strcmp(buf, "venue_type") == 0) {
  2585. bss->venue_type = atoi(pos);
  2586. bss->venue_info_set = 1;
  2587. } else if (os_strcmp(buf, "hessid") == 0) {
  2588. if (hwaddr_aton(pos, bss->hessid)) {
  2589. wpa_printf(MSG_ERROR, "Line %d: invalid hessid", line);
  2590. return 1;
  2591. }
  2592. } else if (os_strcmp(buf, "roaming_consortium") == 0) {
  2593. if (parse_roaming_consortium(bss, pos, line) < 0)
  2594. return 1;
  2595. } else if (os_strcmp(buf, "venue_name") == 0) {
  2596. if (parse_venue_name(bss, pos, line) < 0)
  2597. return 1;
  2598. } else if (os_strcmp(buf, "network_auth_type") == 0) {
  2599. u8 auth_type;
  2600. u16 redirect_url_len;
  2601. if (hexstr2bin(pos, &auth_type, 1)) {
  2602. wpa_printf(MSG_ERROR,
  2603. "Line %d: Invalid network_auth_type '%s'",
  2604. line, pos);
  2605. return 1;
  2606. }
  2607. if (auth_type == 0 || auth_type == 2)
  2608. redirect_url_len = os_strlen(pos + 2);
  2609. else
  2610. redirect_url_len = 0;
  2611. os_free(bss->network_auth_type);
  2612. bss->network_auth_type = os_malloc(redirect_url_len + 3 + 1);
  2613. if (bss->network_auth_type == NULL)
  2614. return 1;
  2615. *bss->network_auth_type = auth_type;
  2616. WPA_PUT_LE16(bss->network_auth_type + 1, redirect_url_len);
  2617. if (redirect_url_len)
  2618. os_memcpy(bss->network_auth_type + 3, pos + 2,
  2619. redirect_url_len);
  2620. bss->network_auth_type_len = 3 + redirect_url_len;
  2621. } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
  2622. if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1)) {
  2623. wpa_printf(MSG_ERROR, "Line %d: Invalid ipaddr_type_availability '%s'",
  2624. line, pos);
  2625. bss->ipaddr_type_configured = 0;
  2626. return 1;
  2627. }
  2628. bss->ipaddr_type_configured = 1;
  2629. } else if (os_strcmp(buf, "domain_name") == 0) {
  2630. int j, num_domains, domain_len, domain_list_len = 0;
  2631. char *tok_start, *tok_prev;
  2632. u8 *domain_list, *domain_ptr;
  2633. domain_list_len = os_strlen(pos) + 1;
  2634. domain_list = os_malloc(domain_list_len);
  2635. if (domain_list == NULL)
  2636. return 1;
  2637. domain_ptr = domain_list;
  2638. tok_prev = pos;
  2639. num_domains = 1;
  2640. while ((tok_prev = os_strchr(tok_prev, ','))) {
  2641. num_domains++;
  2642. tok_prev++;
  2643. }
  2644. tok_prev = pos;
  2645. for (j = 0; j < num_domains; j++) {
  2646. tok_start = os_strchr(tok_prev, ',');
  2647. if (tok_start) {
  2648. domain_len = tok_start - tok_prev;
  2649. *domain_ptr = domain_len;
  2650. os_memcpy(domain_ptr + 1, tok_prev, domain_len);
  2651. domain_ptr += domain_len + 1;
  2652. tok_prev = ++tok_start;
  2653. } else {
  2654. domain_len = os_strlen(tok_prev);
  2655. *domain_ptr = domain_len;
  2656. os_memcpy(domain_ptr + 1, tok_prev, domain_len);
  2657. domain_ptr += domain_len + 1;
  2658. }
  2659. }
  2660. os_free(bss->domain_name);
  2661. bss->domain_name = domain_list;
  2662. bss->domain_name_len = domain_list_len;
  2663. } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
  2664. if (parse_3gpp_cell_net(bss, pos, line) < 0)
  2665. return 1;
  2666. } else if (os_strcmp(buf, "nai_realm") == 0) {
  2667. if (parse_nai_realm(bss, pos, line) < 0)
  2668. return 1;
  2669. } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
  2670. bss->gas_frag_limit = atoi(pos);
  2671. } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
  2672. bss->gas_comeback_delay = atoi(pos);
  2673. } else if (os_strcmp(buf, "qos_map_set") == 0) {
  2674. if (parse_qos_map_set(bss, pos, line) < 0)
  2675. return 1;
  2676. #endif /* CONFIG_INTERWORKING */
  2677. #ifdef CONFIG_RADIUS_TEST
  2678. } else if (os_strcmp(buf, "dump_msk_file") == 0) {
  2679. os_free(bss->dump_msk_file);
  2680. bss->dump_msk_file = os_strdup(pos);
  2681. #endif /* CONFIG_RADIUS_TEST */
  2682. #ifdef CONFIG_HS20
  2683. } else if (os_strcmp(buf, "hs20") == 0) {
  2684. bss->hs20 = atoi(pos);
  2685. } else if (os_strcmp(buf, "disable_dgaf") == 0) {
  2686. bss->disable_dgaf = atoi(pos);
  2687. } else if (os_strcmp(buf, "osen") == 0) {
  2688. bss->osen = atoi(pos);
  2689. } else if (os_strcmp(buf, "anqp_domain_id") == 0) {
  2690. bss->anqp_domain_id = atoi(pos);
  2691. } else if (os_strcmp(buf, "hs20_deauth_req_timeout") == 0) {
  2692. bss->hs20_deauth_req_timeout = atoi(pos);
  2693. } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
  2694. if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
  2695. return 1;
  2696. } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
  2697. if (hs20_parse_wan_metrics(bss, pos, line) < 0)
  2698. return 1;
  2699. } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
  2700. if (hs20_parse_conn_capab(bss, pos, line) < 0) {
  2701. return 1;
  2702. }
  2703. } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
  2704. u8 *oper_class;
  2705. size_t oper_class_len;
  2706. oper_class_len = os_strlen(pos);
  2707. if (oper_class_len < 2 || (oper_class_len & 0x01)) {
  2708. wpa_printf(MSG_ERROR,
  2709. "Line %d: Invalid hs20_operating_class '%s'",
  2710. line, pos);
  2711. return 1;
  2712. }
  2713. oper_class_len /= 2;
  2714. oper_class = os_malloc(oper_class_len);
  2715. if (oper_class == NULL)
  2716. return 1;
  2717. if (hexstr2bin(pos, oper_class, oper_class_len)) {
  2718. wpa_printf(MSG_ERROR,
  2719. "Line %d: Invalid hs20_operating_class '%s'",
  2720. line, pos);
  2721. os_free(oper_class);
  2722. return 1;
  2723. }
  2724. os_free(bss->hs20_operating_class);
  2725. bss->hs20_operating_class = oper_class;
  2726. bss->hs20_operating_class_len = oper_class_len;
  2727. } else if (os_strcmp(buf, "hs20_icon") == 0) {
  2728. if (hs20_parse_icon(bss, pos) < 0) {
  2729. wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_icon '%s'",
  2730. line, pos);
  2731. return 1;
  2732. }
  2733. } else if (os_strcmp(buf, "osu_ssid") == 0) {
  2734. if (hs20_parse_osu_ssid(bss, pos, line) < 0)
  2735. return 1;
  2736. } else if (os_strcmp(buf, "osu_server_uri") == 0) {
  2737. if (hs20_parse_osu_server_uri(bss, pos, line) < 0)
  2738. return 1;
  2739. } else if (os_strcmp(buf, "osu_friendly_name") == 0) {
  2740. if (hs20_parse_osu_friendly_name(bss, pos, line) < 0)
  2741. return 1;
  2742. } else if (os_strcmp(buf, "osu_nai") == 0) {
  2743. if (hs20_parse_osu_nai(bss, pos, line) < 0)
  2744. return 1;
  2745. } else if (os_strcmp(buf, "osu_method_list") == 0) {
  2746. if (hs20_parse_osu_method_list(bss, pos, line) < 0)
  2747. return 1;
  2748. } else if (os_strcmp(buf, "osu_icon") == 0) {
  2749. if (hs20_parse_osu_icon(bss, pos, line) < 0)
  2750. return 1;
  2751. } else if (os_strcmp(buf, "osu_service_desc") == 0) {
  2752. if (hs20_parse_osu_service_desc(bss, pos, line) < 0)
  2753. return 1;
  2754. } else if (os_strcmp(buf, "subscr_remediation_url") == 0) {
  2755. os_free(bss->subscr_remediation_url);
  2756. bss->subscr_remediation_url = os_strdup(pos);
  2757. } else if (os_strcmp(buf, "subscr_remediation_method") == 0) {
  2758. bss->subscr_remediation_method = atoi(pos);
  2759. #endif /* CONFIG_HS20 */
  2760. #ifdef CONFIG_TESTING_OPTIONS
  2761. #define PARSE_TEST_PROBABILITY(_val) \
  2762. } else if (os_strcmp(buf, #_val) == 0) { \
  2763. char *end; \
  2764. \
  2765. conf->_val = strtod(pos, &end); \
  2766. if (*end || conf->_val < 0.0d || \
  2767. conf->_val > 1.0d) { \
  2768. wpa_printf(MSG_ERROR, \
  2769. "Line %d: Invalid value '%s'", \
  2770. line, pos); \
  2771. return 1; \
  2772. }
  2773. PARSE_TEST_PROBABILITY(ignore_probe_probability)
  2774. PARSE_TEST_PROBABILITY(ignore_auth_probability)
  2775. PARSE_TEST_PROBABILITY(ignore_assoc_probability)
  2776. PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
  2777. PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability)
  2778. } else if (os_strcmp(buf, "bss_load_test") == 0) {
  2779. WPA_PUT_LE16(bss->bss_load_test, atoi(pos));
  2780. pos = os_strchr(pos, ':');
  2781. if (pos == NULL) {
  2782. wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
  2783. line);
  2784. return 1;
  2785. }
  2786. pos++;
  2787. bss->bss_load_test[2] = atoi(pos);
  2788. pos = os_strchr(pos, ':');
  2789. if (pos == NULL) {
  2790. wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
  2791. line);
  2792. return 1;
  2793. }
  2794. pos++;
  2795. WPA_PUT_LE16(&bss->bss_load_test[3], atoi(pos));
  2796. bss->bss_load_test_set = 1;
  2797. #endif /* CONFIG_TESTING_OPTIONS */
  2798. } else if (os_strcmp(buf, "vendor_elements") == 0) {
  2799. struct wpabuf *elems;
  2800. size_t len = os_strlen(pos);
  2801. if (len & 0x01) {
  2802. wpa_printf(MSG_ERROR,
  2803. "Line %d: Invalid vendor_elements '%s'",
  2804. line, pos);
  2805. return 1;
  2806. }
  2807. len /= 2;
  2808. if (len == 0) {
  2809. wpabuf_free(bss->vendor_elements);
  2810. bss->vendor_elements = NULL;
  2811. return 0;
  2812. }
  2813. elems = wpabuf_alloc(len);
  2814. if (elems == NULL)
  2815. return 1;
  2816. if (hexstr2bin(pos, wpabuf_put(elems, len), len)) {
  2817. wpabuf_free(elems);
  2818. wpa_printf(MSG_ERROR,
  2819. "Line %d: Invalid vendor_elements '%s'",
  2820. line, pos);
  2821. return 1;
  2822. }
  2823. wpabuf_free(bss->vendor_elements);
  2824. bss->vendor_elements = elems;
  2825. } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0) {
  2826. bss->sae_anti_clogging_threshold = atoi(pos);
  2827. } else if (os_strcmp(buf, "sae_groups") == 0) {
  2828. if (hostapd_parse_intlist(&bss->sae_groups, pos)) {
  2829. wpa_printf(MSG_ERROR,
  2830. "Line %d: Invalid sae_groups value '%s'",
  2831. line, pos);
  2832. return 1;
  2833. }
  2834. } else if (os_strcmp(buf, "local_pwr_constraint") == 0) {
  2835. int val = atoi(pos);
  2836. if (val < 0 || val > 255) {
  2837. wpa_printf(MSG_ERROR, "Line %d: Invalid local_pwr_constraint %d (expected 0..255)",
  2838. line, val);
  2839. return 1;
  2840. }
  2841. conf->local_pwr_constraint = val;
  2842. } else if (os_strcmp(buf, "spectrum_mgmt_required") == 0) {
  2843. conf->spectrum_mgmt_required = atoi(pos);
  2844. } else {
  2845. wpa_printf(MSG_ERROR,
  2846. "Line %d: unknown configuration item '%s'",
  2847. line, buf);
  2848. return 1;
  2849. }
  2850. return 0;
  2851. }
  2852. /**
  2853. * hostapd_config_read - Read and parse a configuration file
  2854. * @fname: Configuration file name (including path, if needed)
  2855. * Returns: Allocated configuration data structure
  2856. */
  2857. struct hostapd_config * hostapd_config_read(const char *fname)
  2858. {
  2859. struct hostapd_config *conf;
  2860. struct hostapd_bss_config *bss;
  2861. FILE *f;
  2862. char buf[512], *pos;
  2863. int line = 0;
  2864. int errors = 0;
  2865. size_t i;
  2866. f = fopen(fname, "r");
  2867. if (f == NULL) {
  2868. wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
  2869. "for reading.", fname);
  2870. return NULL;
  2871. }
  2872. conf = hostapd_config_defaults();
  2873. if (conf == NULL) {
  2874. fclose(f);
  2875. return NULL;
  2876. }
  2877. /* set default driver based on configuration */
  2878. conf->driver = wpa_drivers[0];
  2879. if (conf->driver == NULL) {
  2880. wpa_printf(MSG_ERROR, "No driver wrappers registered!");
  2881. hostapd_config_free(conf);
  2882. fclose(f);
  2883. return NULL;
  2884. }
  2885. bss = conf->last_bss = conf->bss[0];
  2886. while (fgets(buf, sizeof(buf), f)) {
  2887. bss = conf->last_bss;
  2888. line++;
  2889. if (buf[0] == '#')
  2890. continue;
  2891. pos = buf;
  2892. while (*pos != '\0') {
  2893. if (*pos == '\n') {
  2894. *pos = '\0';
  2895. break;
  2896. }
  2897. pos++;
  2898. }
  2899. if (buf[0] == '\0')
  2900. continue;
  2901. pos = os_strchr(buf, '=');
  2902. if (pos == NULL) {
  2903. wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
  2904. line, buf);
  2905. errors++;
  2906. continue;
  2907. }
  2908. *pos = '\0';
  2909. pos++;
  2910. errors += hostapd_config_fill(conf, bss, buf, pos, line);
  2911. }
  2912. fclose(f);
  2913. for (i = 0; i < conf->num_bss; i++)
  2914. hostapd_set_security_params(conf->bss[i]);
  2915. if (hostapd_config_check(conf, 1))
  2916. errors++;
  2917. #ifndef WPA_IGNORE_CONFIG_ERRORS
  2918. if (errors) {
  2919. wpa_printf(MSG_ERROR, "%d errors found in configuration file "
  2920. "'%s'", errors, fname);
  2921. hostapd_config_free(conf);
  2922. conf = NULL;
  2923. }
  2924. #endif /* WPA_IGNORE_CONFIG_ERRORS */
  2925. return conf;
  2926. }
  2927. int hostapd_set_iface(struct hostapd_config *conf,
  2928. struct hostapd_bss_config *bss, char *field, char *value)
  2929. {
  2930. int errors;
  2931. size_t i;
  2932. errors = hostapd_config_fill(conf, bss, field, value, 0);
  2933. if (errors) {
  2934. wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
  2935. "to value '%s'", field, value);
  2936. return -1;
  2937. }
  2938. for (i = 0; i < conf->num_bss; i++)
  2939. hostapd_set_security_params(conf->bss[i]);
  2940. if (hostapd_config_check(conf, 0)) {
  2941. wpa_printf(MSG_ERROR, "Configuration check failed");
  2942. return -1;
  2943. }
  2944. return 0;
  2945. }