config_file.c 88 KB

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