config_file.c 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275
  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, "[PSMP]"))
  928. conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP;
  929. if (os_strstr(capab, "[40-INTOLERANT]"))
  930. conf->ht_capab |= HT_CAP_INFO_40MHZ_INTOLERANT;
  931. if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
  932. conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
  933. return 0;
  934. }
  935. #endif /* CONFIG_IEEE80211N */
  936. #ifdef CONFIG_IEEE80211AC
  937. static int hostapd_config_vht_capab(struct hostapd_config *conf,
  938. const char *capab)
  939. {
  940. if (os_strstr(capab, "[MAX-MPDU-7991]"))
  941. conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
  942. if (os_strstr(capab, "[MAX-MPDU-11454]"))
  943. conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
  944. if (os_strstr(capab, "[VHT160]"))
  945. conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
  946. if (os_strstr(capab, "[VHT160-80PLUS80]"))
  947. conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
  948. if (os_strstr(capab, "[RXLDPC]"))
  949. conf->vht_capab |= VHT_CAP_RXLDPC;
  950. if (os_strstr(capab, "[SHORT-GI-80]"))
  951. conf->vht_capab |= VHT_CAP_SHORT_GI_80;
  952. if (os_strstr(capab, "[SHORT-GI-160]"))
  953. conf->vht_capab |= VHT_CAP_SHORT_GI_160;
  954. if (os_strstr(capab, "[TX-STBC-2BY1]"))
  955. conf->vht_capab |= VHT_CAP_TXSTBC;
  956. if (os_strstr(capab, "[RX-STBC-1]"))
  957. conf->vht_capab |= VHT_CAP_RXSTBC_1;
  958. if (os_strstr(capab, "[RX-STBC-12]"))
  959. conf->vht_capab |= VHT_CAP_RXSTBC_2;
  960. if (os_strstr(capab, "[RX-STBC-123]"))
  961. conf->vht_capab |= VHT_CAP_RXSTBC_3;
  962. if (os_strstr(capab, "[RX-STBC-1234]"))
  963. conf->vht_capab |= VHT_CAP_RXSTBC_4;
  964. if (os_strstr(capab, "[SU-BEAMFORMER]"))
  965. conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE;
  966. if (os_strstr(capab, "[SU-BEAMFORMEE]"))
  967. conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE;
  968. if (os_strstr(capab, "[BF-ANTENNA-2]") &&
  969. (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
  970. conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
  971. if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
  972. (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
  973. conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
  974. if (os_strstr(capab, "[MU-BEAMFORMER]"))
  975. conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
  976. if (os_strstr(capab, "[MU-BEAMFORMEE]"))
  977. conf->vht_capab |= VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  978. if (os_strstr(capab, "[VHT-TXOP-PS]"))
  979. conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
  980. if (os_strstr(capab, "[HTC-VHT]"))
  981. conf->vht_capab |= VHT_CAP_HTC_VHT;
  982. if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP7]"))
  983. conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX;
  984. else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP6]"))
  985. conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_6;
  986. else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP5]"))
  987. conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_5;
  988. else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP4]"))
  989. conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_4;
  990. else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP3]"))
  991. conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_3;
  992. else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP2]"))
  993. conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_2;
  994. else if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP1]"))
  995. conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_1;
  996. if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
  997. (conf->vht_capab & VHT_CAP_HTC_VHT))
  998. conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
  999. if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
  1000. (conf->vht_capab & VHT_CAP_HTC_VHT))
  1001. conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
  1002. if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
  1003. conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
  1004. if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
  1005. conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
  1006. return 0;
  1007. }
  1008. #endif /* CONFIG_IEEE80211AC */
  1009. #ifdef CONFIG_INTERWORKING
  1010. static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
  1011. int line)
  1012. {
  1013. size_t len = os_strlen(pos);
  1014. u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
  1015. struct hostapd_roaming_consortium *rc;
  1016. if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
  1017. hexstr2bin(pos, oi, len / 2)) {
  1018. wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
  1019. "'%s'", line, pos);
  1020. return -1;
  1021. }
  1022. len /= 2;
  1023. rc = os_realloc_array(bss->roaming_consortium,
  1024. bss->roaming_consortium_count + 1,
  1025. sizeof(struct hostapd_roaming_consortium));
  1026. if (rc == NULL)
  1027. return -1;
  1028. os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
  1029. rc[bss->roaming_consortium_count].len = len;
  1030. bss->roaming_consortium = rc;
  1031. bss->roaming_consortium_count++;
  1032. return 0;
  1033. }
  1034. static int parse_lang_string(struct hostapd_lang_string **array,
  1035. unsigned int *count, char *pos)
  1036. {
  1037. char *sep, *str = NULL;
  1038. size_t clen, nlen, slen;
  1039. struct hostapd_lang_string *ls;
  1040. int ret = -1;
  1041. if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) {
  1042. str = wpa_config_parse_string(pos, &slen);
  1043. if (!str)
  1044. return -1;
  1045. pos = str;
  1046. }
  1047. sep = os_strchr(pos, ':');
  1048. if (sep == NULL)
  1049. goto fail;
  1050. *sep++ = '\0';
  1051. clen = os_strlen(pos);
  1052. if (clen < 2 || clen > sizeof(ls->lang))
  1053. goto fail;
  1054. nlen = os_strlen(sep);
  1055. if (nlen > 252)
  1056. goto fail;
  1057. ls = os_realloc_array(*array, *count + 1,
  1058. sizeof(struct hostapd_lang_string));
  1059. if (ls == NULL)
  1060. goto fail;
  1061. *array = ls;
  1062. ls = &(*array)[*count];
  1063. (*count)++;
  1064. os_memset(ls->lang, 0, sizeof(ls->lang));
  1065. os_memcpy(ls->lang, pos, clen);
  1066. ls->name_len = nlen;
  1067. os_memcpy(ls->name, sep, nlen);
  1068. ret = 0;
  1069. fail:
  1070. os_free(str);
  1071. return ret;
  1072. }
  1073. static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
  1074. int line)
  1075. {
  1076. if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
  1077. wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
  1078. line, pos);
  1079. return -1;
  1080. }
  1081. return 0;
  1082. }
  1083. static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
  1084. int line)
  1085. {
  1086. size_t count;
  1087. char *pos;
  1088. u8 *info = NULL, *ipos;
  1089. /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
  1090. count = 1;
  1091. for (pos = buf; *pos; pos++) {
  1092. if ((*pos < '0' || *pos > '9') && *pos != ';' && *pos != ',')
  1093. goto fail;
  1094. if (*pos == ';')
  1095. count++;
  1096. }
  1097. if (1 + count * 3 > 0x7f)
  1098. goto fail;
  1099. info = os_zalloc(2 + 3 + count * 3);
  1100. if (info == NULL)
  1101. return -1;
  1102. ipos = info;
  1103. *ipos++ = 0; /* GUD - Version 1 */
  1104. *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
  1105. *ipos++ = 0; /* PLMN List IEI */
  1106. /* ext(b8) | Length of PLMN List value contents(b7..1) */
  1107. *ipos++ = 1 + count * 3;
  1108. *ipos++ = count; /* Number of PLMNs */
  1109. pos = buf;
  1110. while (pos && *pos) {
  1111. char *mcc, *mnc;
  1112. size_t mnc_len;
  1113. mcc = pos;
  1114. mnc = os_strchr(pos, ',');
  1115. if (mnc == NULL)
  1116. goto fail;
  1117. *mnc++ = '\0';
  1118. pos = os_strchr(mnc, ';');
  1119. if (pos)
  1120. *pos++ = '\0';
  1121. mnc_len = os_strlen(mnc);
  1122. if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
  1123. goto fail;
  1124. /* BC coded MCC,MNC */
  1125. /* MCC digit 2 | MCC digit 1 */
  1126. *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
  1127. /* MNC digit 3 | MCC digit 3 */
  1128. *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
  1129. (mcc[2] - '0');
  1130. /* MNC digit 2 | MNC digit 1 */
  1131. *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
  1132. }
  1133. os_free(bss->anqp_3gpp_cell_net);
  1134. bss->anqp_3gpp_cell_net = info;
  1135. bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
  1136. wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
  1137. bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
  1138. return 0;
  1139. fail:
  1140. wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
  1141. line, buf);
  1142. os_free(info);
  1143. return -1;
  1144. }
  1145. static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
  1146. {
  1147. struct hostapd_nai_realm_data *realm;
  1148. size_t i, j, len;
  1149. int *offsets;
  1150. char *pos, *end, *rpos;
  1151. offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
  1152. sizeof(int));
  1153. if (offsets == NULL)
  1154. return -1;
  1155. for (i = 0; i < bss->nai_realm_count; i++) {
  1156. realm = &bss->nai_realm_data[i];
  1157. for (j = 0; j < MAX_NAI_REALMS; j++) {
  1158. offsets[i * MAX_NAI_REALMS + j] =
  1159. realm->realm[j] ?
  1160. realm->realm[j] - realm->realm_buf : -1;
  1161. }
  1162. }
  1163. realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
  1164. sizeof(struct hostapd_nai_realm_data));
  1165. if (realm == NULL) {
  1166. os_free(offsets);
  1167. return -1;
  1168. }
  1169. bss->nai_realm_data = realm;
  1170. /* patch the pointers after realloc */
  1171. for (i = 0; i < bss->nai_realm_count; i++) {
  1172. realm = &bss->nai_realm_data[i];
  1173. for (j = 0; j < MAX_NAI_REALMS; j++) {
  1174. int offs = offsets[i * MAX_NAI_REALMS + j];
  1175. if (offs >= 0)
  1176. realm->realm[j] = realm->realm_buf + offs;
  1177. else
  1178. realm->realm[j] = NULL;
  1179. }
  1180. }
  1181. os_free(offsets);
  1182. realm = &bss->nai_realm_data[bss->nai_realm_count];
  1183. os_memset(realm, 0, sizeof(*realm));
  1184. pos = buf;
  1185. realm->encoding = atoi(pos);
  1186. pos = os_strchr(pos, ',');
  1187. if (pos == NULL)
  1188. goto fail;
  1189. pos++;
  1190. end = os_strchr(pos, ',');
  1191. if (end) {
  1192. len = end - pos;
  1193. *end = '\0';
  1194. } else {
  1195. len = os_strlen(pos);
  1196. }
  1197. if (len > MAX_NAI_REALMLEN) {
  1198. wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
  1199. "characters)", (int) len, MAX_NAI_REALMLEN);
  1200. goto fail;
  1201. }
  1202. os_memcpy(realm->realm_buf, pos, len);
  1203. if (end)
  1204. pos = end + 1;
  1205. else
  1206. pos = NULL;
  1207. while (pos && *pos) {
  1208. struct hostapd_nai_realm_eap *eap;
  1209. if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
  1210. wpa_printf(MSG_ERROR, "Too many EAP methods");
  1211. goto fail;
  1212. }
  1213. eap = &realm->eap_method[realm->eap_method_count];
  1214. realm->eap_method_count++;
  1215. end = os_strchr(pos, ',');
  1216. if (end == NULL)
  1217. end = pos + os_strlen(pos);
  1218. eap->eap_method = atoi(pos);
  1219. for (;;) {
  1220. pos = os_strchr(pos, '[');
  1221. if (pos == NULL || pos > end)
  1222. break;
  1223. pos++;
  1224. if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
  1225. wpa_printf(MSG_ERROR, "Too many auth params");
  1226. goto fail;
  1227. }
  1228. eap->auth_id[eap->num_auths] = atoi(pos);
  1229. pos = os_strchr(pos, ':');
  1230. if (pos == NULL || pos > end)
  1231. goto fail;
  1232. pos++;
  1233. eap->auth_val[eap->num_auths] = atoi(pos);
  1234. pos = os_strchr(pos, ']');
  1235. if (pos == NULL || pos > end)
  1236. goto fail;
  1237. pos++;
  1238. eap->num_auths++;
  1239. }
  1240. if (*end != ',')
  1241. break;
  1242. pos = end + 1;
  1243. }
  1244. /* Split realm list into null terminated realms */
  1245. rpos = realm->realm_buf;
  1246. i = 0;
  1247. while (*rpos) {
  1248. if (i >= MAX_NAI_REALMS) {
  1249. wpa_printf(MSG_ERROR, "Too many realms");
  1250. goto fail;
  1251. }
  1252. realm->realm[i++] = rpos;
  1253. rpos = os_strchr(rpos, ';');
  1254. if (rpos == NULL)
  1255. break;
  1256. *rpos++ = '\0';
  1257. }
  1258. bss->nai_realm_count++;
  1259. return 0;
  1260. fail:
  1261. wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
  1262. return -1;
  1263. }
  1264. static int parse_qos_map_set(struct hostapd_bss_config *bss,
  1265. char *buf, int line)
  1266. {
  1267. u8 qos_map_set[16 + 2 * 21], count = 0;
  1268. char *pos = buf;
  1269. int val;
  1270. for (;;) {
  1271. if (count == sizeof(qos_map_set)) {
  1272. wpa_printf(MSG_ERROR, "Line %d: Too many qos_map_set "
  1273. "parameters '%s'", line, buf);
  1274. return -1;
  1275. }
  1276. val = atoi(pos);
  1277. if (val > 255 || val < 0) {
  1278. wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set "
  1279. "'%s'", line, buf);
  1280. return -1;
  1281. }
  1282. qos_map_set[count++] = val;
  1283. pos = os_strchr(pos, ',');
  1284. if (!pos)
  1285. break;
  1286. pos++;
  1287. }
  1288. if (count < 16 || count & 1) {
  1289. wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'",
  1290. line, buf);
  1291. return -1;
  1292. }
  1293. os_memcpy(bss->qos_map_set, qos_map_set, count);
  1294. bss->qos_map_set_len = count;
  1295. return 0;
  1296. }
  1297. #endif /* CONFIG_INTERWORKING */
  1298. #ifdef CONFIG_HS20
  1299. static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
  1300. int line)
  1301. {
  1302. u8 *conn_cap;
  1303. char *pos;
  1304. if (bss->hs20_connection_capability_len >= 0xfff0)
  1305. return -1;
  1306. conn_cap = os_realloc(bss->hs20_connection_capability,
  1307. bss->hs20_connection_capability_len + 4);
  1308. if (conn_cap == NULL)
  1309. return -1;
  1310. bss->hs20_connection_capability = conn_cap;
  1311. conn_cap += bss->hs20_connection_capability_len;
  1312. pos = buf;
  1313. conn_cap[0] = atoi(pos);
  1314. pos = os_strchr(pos, ':');
  1315. if (pos == NULL)
  1316. return -1;
  1317. pos++;
  1318. WPA_PUT_LE16(conn_cap + 1, atoi(pos));
  1319. pos = os_strchr(pos, ':');
  1320. if (pos == NULL)
  1321. return -1;
  1322. pos++;
  1323. conn_cap[3] = atoi(pos);
  1324. bss->hs20_connection_capability_len += 4;
  1325. return 0;
  1326. }
  1327. static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
  1328. int line)
  1329. {
  1330. u8 *wan_metrics;
  1331. char *pos;
  1332. /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
  1333. wan_metrics = os_zalloc(13);
  1334. if (wan_metrics == NULL)
  1335. return -1;
  1336. pos = buf;
  1337. /* WAN Info */
  1338. if (hexstr2bin(pos, wan_metrics, 1) < 0)
  1339. goto fail;
  1340. pos += 2;
  1341. if (*pos != ':')
  1342. goto fail;
  1343. pos++;
  1344. /* Downlink Speed */
  1345. WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
  1346. pos = os_strchr(pos, ':');
  1347. if (pos == NULL)
  1348. goto fail;
  1349. pos++;
  1350. /* Uplink Speed */
  1351. WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
  1352. pos = os_strchr(pos, ':');
  1353. if (pos == NULL)
  1354. goto fail;
  1355. pos++;
  1356. /* Downlink Load */
  1357. wan_metrics[9] = atoi(pos);
  1358. pos = os_strchr(pos, ':');
  1359. if (pos == NULL)
  1360. goto fail;
  1361. pos++;
  1362. /* Uplink Load */
  1363. wan_metrics[10] = atoi(pos);
  1364. pos = os_strchr(pos, ':');
  1365. if (pos == NULL)
  1366. goto fail;
  1367. pos++;
  1368. /* LMD */
  1369. WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
  1370. os_free(bss->hs20_wan_metrics);
  1371. bss->hs20_wan_metrics = wan_metrics;
  1372. return 0;
  1373. fail:
  1374. wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
  1375. line, buf);
  1376. os_free(wan_metrics);
  1377. return -1;
  1378. }
  1379. static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
  1380. char *pos, int line)
  1381. {
  1382. if (parse_lang_string(&bss->hs20_oper_friendly_name,
  1383. &bss->hs20_oper_friendly_name_count, pos)) {
  1384. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1385. "hs20_oper_friendly_name '%s'", line, pos);
  1386. return -1;
  1387. }
  1388. return 0;
  1389. }
  1390. static int hs20_parse_icon(struct hostapd_bss_config *bss, char *pos)
  1391. {
  1392. struct hs20_icon *icon;
  1393. char *end;
  1394. icon = os_realloc_array(bss->hs20_icons, bss->hs20_icons_count + 1,
  1395. sizeof(struct hs20_icon));
  1396. if (icon == NULL)
  1397. return -1;
  1398. bss->hs20_icons = icon;
  1399. icon = &bss->hs20_icons[bss->hs20_icons_count];
  1400. os_memset(icon, 0, sizeof(*icon));
  1401. icon->width = atoi(pos);
  1402. pos = os_strchr(pos, ':');
  1403. if (pos == NULL)
  1404. return -1;
  1405. pos++;
  1406. icon->height = atoi(pos);
  1407. pos = os_strchr(pos, ':');
  1408. if (pos == NULL)
  1409. return -1;
  1410. pos++;
  1411. end = os_strchr(pos, ':');
  1412. if (end == NULL || end - pos > 3)
  1413. return -1;
  1414. os_memcpy(icon->language, pos, end - pos);
  1415. pos = end + 1;
  1416. end = os_strchr(pos, ':');
  1417. if (end == NULL || end - pos > 255)
  1418. return -1;
  1419. os_memcpy(icon->type, pos, end - pos);
  1420. pos = end + 1;
  1421. end = os_strchr(pos, ':');
  1422. if (end == NULL || end - pos > 255)
  1423. return -1;
  1424. os_memcpy(icon->name, pos, end - pos);
  1425. pos = end + 1;
  1426. if (os_strlen(pos) > 255)
  1427. return -1;
  1428. os_memcpy(icon->file, pos, os_strlen(pos));
  1429. bss->hs20_icons_count++;
  1430. return 0;
  1431. }
  1432. static int hs20_parse_osu_ssid(struct hostapd_bss_config *bss,
  1433. char *pos, int line)
  1434. {
  1435. size_t slen;
  1436. char *str;
  1437. str = wpa_config_parse_string(pos, &slen);
  1438. if (str == NULL || slen < 1 || slen > HOSTAPD_MAX_SSID_LEN) {
  1439. wpa_printf(MSG_ERROR, "Line %d: Invalid SSID '%s'", line, pos);
  1440. os_free(str);
  1441. return -1;
  1442. }
  1443. os_memcpy(bss->osu_ssid, str, slen);
  1444. bss->osu_ssid_len = slen;
  1445. os_free(str);
  1446. return 0;
  1447. }
  1448. static int hs20_parse_osu_server_uri(struct hostapd_bss_config *bss,
  1449. char *pos, int line)
  1450. {
  1451. struct hs20_osu_provider *p;
  1452. p = os_realloc_array(bss->hs20_osu_providers,
  1453. bss->hs20_osu_providers_count + 1, sizeof(*p));
  1454. if (p == NULL)
  1455. return -1;
  1456. bss->hs20_osu_providers = p;
  1457. bss->last_osu = &bss->hs20_osu_providers[bss->hs20_osu_providers_count];
  1458. bss->hs20_osu_providers_count++;
  1459. os_memset(bss->last_osu, 0, sizeof(*p));
  1460. bss->last_osu->server_uri = os_strdup(pos);
  1461. return 0;
  1462. }
  1463. static int hs20_parse_osu_friendly_name(struct hostapd_bss_config *bss,
  1464. char *pos, int line)
  1465. {
  1466. if (bss->last_osu == NULL) {
  1467. wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
  1468. return -1;
  1469. }
  1470. if (parse_lang_string(&bss->last_osu->friendly_name,
  1471. &bss->last_osu->friendly_name_count, pos)) {
  1472. wpa_printf(MSG_ERROR, "Line %d: Invalid osu_friendly_name '%s'",
  1473. line, pos);
  1474. return -1;
  1475. }
  1476. return 0;
  1477. }
  1478. static int hs20_parse_osu_nai(struct hostapd_bss_config *bss,
  1479. char *pos, int line)
  1480. {
  1481. if (bss->last_osu == NULL) {
  1482. wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
  1483. return -1;
  1484. }
  1485. os_free(bss->last_osu->osu_nai);
  1486. bss->last_osu->osu_nai = os_strdup(pos);
  1487. if (bss->last_osu->osu_nai == NULL)
  1488. return -1;
  1489. return 0;
  1490. }
  1491. static int hs20_parse_osu_method_list(struct hostapd_bss_config *bss, char *pos,
  1492. int line)
  1493. {
  1494. if (bss->last_osu == NULL) {
  1495. wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
  1496. return -1;
  1497. }
  1498. if (hostapd_parse_intlist(&bss->last_osu->method_list, pos)) {
  1499. wpa_printf(MSG_ERROR, "Line %d: Invalid osu_method_list", line);
  1500. return -1;
  1501. }
  1502. return 0;
  1503. }
  1504. static int hs20_parse_osu_icon(struct hostapd_bss_config *bss, char *pos,
  1505. int line)
  1506. {
  1507. char **n;
  1508. struct hs20_osu_provider *p = bss->last_osu;
  1509. if (p == NULL) {
  1510. wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
  1511. return -1;
  1512. }
  1513. n = os_realloc_array(p->icons, p->icons_count + 1, sizeof(char *));
  1514. if (n == NULL)
  1515. return -1;
  1516. p->icons = n;
  1517. p->icons[p->icons_count] = os_strdup(pos);
  1518. if (p->icons[p->icons_count] == NULL)
  1519. return -1;
  1520. p->icons_count++;
  1521. return 0;
  1522. }
  1523. static int hs20_parse_osu_service_desc(struct hostapd_bss_config *bss,
  1524. char *pos, int line)
  1525. {
  1526. if (bss->last_osu == NULL) {
  1527. wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
  1528. return -1;
  1529. }
  1530. if (parse_lang_string(&bss->last_osu->service_desc,
  1531. &bss->last_osu->service_desc_count, pos)) {
  1532. wpa_printf(MSG_ERROR, "Line %d: Invalid osu_service_desc '%s'",
  1533. line, pos);
  1534. return -1;
  1535. }
  1536. return 0;
  1537. }
  1538. #endif /* CONFIG_HS20 */
  1539. #ifdef CONFIG_WPS_NFC
  1540. static struct wpabuf * hostapd_parse_bin(const char *buf)
  1541. {
  1542. size_t len;
  1543. struct wpabuf *ret;
  1544. len = os_strlen(buf);
  1545. if (len & 0x01)
  1546. return NULL;
  1547. len /= 2;
  1548. ret = wpabuf_alloc(len);
  1549. if (ret == NULL)
  1550. return NULL;
  1551. if (hexstr2bin(buf, wpabuf_put(ret, len), len)) {
  1552. wpabuf_free(ret);
  1553. return NULL;
  1554. }
  1555. return ret;
  1556. }
  1557. #endif /* CONFIG_WPS_NFC */
  1558. static int hostapd_config_fill(struct hostapd_config *conf,
  1559. struct hostapd_bss_config *bss,
  1560. char *buf, char *pos, int line)
  1561. {
  1562. if (os_strcmp(buf, "interface") == 0) {
  1563. os_strlcpy(conf->bss[0]->iface, pos,
  1564. sizeof(conf->bss[0]->iface));
  1565. } else if (os_strcmp(buf, "bridge") == 0) {
  1566. os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
  1567. } else if (os_strcmp(buf, "vlan_bridge") == 0) {
  1568. os_strlcpy(bss->vlan_bridge, pos, sizeof(bss->vlan_bridge));
  1569. } else if (os_strcmp(buf, "wds_bridge") == 0) {
  1570. os_strlcpy(bss->wds_bridge, pos, sizeof(bss->wds_bridge));
  1571. } else if (os_strcmp(buf, "driver") == 0) {
  1572. int j;
  1573. /* clear to get error below if setting is invalid */
  1574. conf->driver = NULL;
  1575. for (j = 0; wpa_drivers[j]; j++) {
  1576. if (os_strcmp(pos, wpa_drivers[j]->name) == 0) {
  1577. conf->driver = wpa_drivers[j];
  1578. break;
  1579. }
  1580. }
  1581. if (conf->driver == NULL) {
  1582. wpa_printf(MSG_ERROR,
  1583. "Line %d: invalid/unknown driver '%s'",
  1584. line, pos);
  1585. return 1;
  1586. }
  1587. } else if (os_strcmp(buf, "debug") == 0) {
  1588. wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' configuration variable is not used anymore",
  1589. line);
  1590. } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
  1591. bss->logger_syslog_level = atoi(pos);
  1592. } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
  1593. bss->logger_stdout_level = atoi(pos);
  1594. } else if (os_strcmp(buf, "logger_syslog") == 0) {
  1595. bss->logger_syslog = atoi(pos);
  1596. } else if (os_strcmp(buf, "logger_stdout") == 0) {
  1597. bss->logger_stdout = atoi(pos);
  1598. } else if (os_strcmp(buf, "dump_file") == 0) {
  1599. wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore",
  1600. line);
  1601. } else if (os_strcmp(buf, "ssid") == 0) {
  1602. bss->ssid.ssid_len = os_strlen(pos);
  1603. if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
  1604. bss->ssid.ssid_len < 1) {
  1605. wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
  1606. line, pos);
  1607. return 1;
  1608. }
  1609. os_memcpy(bss->ssid.ssid, pos, bss->ssid.ssid_len);
  1610. bss->ssid.ssid_set = 1;
  1611. } else if (os_strcmp(buf, "ssid2") == 0) {
  1612. size_t slen;
  1613. char *str = wpa_config_parse_string(pos, &slen);
  1614. if (str == NULL || slen < 1 || slen > HOSTAPD_MAX_SSID_LEN) {
  1615. wpa_printf(MSG_ERROR, "Line %d: invalid SSID '%s'",
  1616. line, pos);
  1617. os_free(str);
  1618. return 1;
  1619. }
  1620. os_memcpy(bss->ssid.ssid, str, slen);
  1621. bss->ssid.ssid_len = slen;
  1622. bss->ssid.ssid_set = 1;
  1623. os_free(str);
  1624. } else if (os_strcmp(buf, "utf8_ssid") == 0) {
  1625. bss->ssid.utf8_ssid = atoi(pos) > 0;
  1626. } else if (os_strcmp(buf, "macaddr_acl") == 0) {
  1627. bss->macaddr_acl = atoi(pos);
  1628. if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
  1629. bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
  1630. bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
  1631. wpa_printf(MSG_ERROR, "Line %d: unknown macaddr_acl %d",
  1632. line, bss->macaddr_acl);
  1633. }
  1634. } else if (os_strcmp(buf, "accept_mac_file") == 0) {
  1635. if (hostapd_config_read_maclist(pos, &bss->accept_mac,
  1636. &bss->num_accept_mac)) {
  1637. wpa_printf(MSG_ERROR, "Line %d: Failed to read accept_mac_file '%s'",
  1638. line, pos);
  1639. return 1;
  1640. }
  1641. } else if (os_strcmp(buf, "deny_mac_file") == 0) {
  1642. if (hostapd_config_read_maclist(pos, &bss->deny_mac,
  1643. &bss->num_deny_mac)) {
  1644. wpa_printf(MSG_ERROR, "Line %d: Failed to read deny_mac_file '%s'",
  1645. line, pos);
  1646. return 1;
  1647. }
  1648. } else if (os_strcmp(buf, "wds_sta") == 0) {
  1649. bss->wds_sta = atoi(pos);
  1650. } else if (os_strcmp(buf, "start_disabled") == 0) {
  1651. bss->start_disabled = atoi(pos);
  1652. } else if (os_strcmp(buf, "ap_isolate") == 0) {
  1653. bss->isolate = atoi(pos);
  1654. } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
  1655. bss->ap_max_inactivity = atoi(pos);
  1656. } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
  1657. bss->skip_inactivity_poll = atoi(pos);
  1658. } else if (os_strcmp(buf, "country_code") == 0) {
  1659. os_memcpy(conf->country, pos, 2);
  1660. /* FIX: make this configurable */
  1661. conf->country[2] = ' ';
  1662. } else if (os_strcmp(buf, "ieee80211d") == 0) {
  1663. conf->ieee80211d = atoi(pos);
  1664. } else if (os_strcmp(buf, "ieee80211h") == 0) {
  1665. conf->ieee80211h = atoi(pos);
  1666. } else if (os_strcmp(buf, "ieee8021x") == 0) {
  1667. bss->ieee802_1x = atoi(pos);
  1668. } else if (os_strcmp(buf, "eapol_version") == 0) {
  1669. bss->eapol_version = atoi(pos);
  1670. if (bss->eapol_version < 1 || bss->eapol_version > 2) {
  1671. wpa_printf(MSG_ERROR,
  1672. "Line %d: invalid EAPOL version (%d): '%s'.",
  1673. line, bss->eapol_version, pos);
  1674. return 1;
  1675. }
  1676. wpa_printf(MSG_DEBUG, "eapol_version=%d", bss->eapol_version);
  1677. #ifdef EAP_SERVER
  1678. } else if (os_strcmp(buf, "eap_authenticator") == 0) {
  1679. bss->eap_server = atoi(pos);
  1680. wpa_printf(MSG_ERROR, "Line %d: obsolete eap_authenticator used; this has been renamed to eap_server", line);
  1681. } else if (os_strcmp(buf, "eap_server") == 0) {
  1682. bss->eap_server = atoi(pos);
  1683. } else if (os_strcmp(buf, "eap_user_file") == 0) {
  1684. if (hostapd_config_read_eap_user(pos, bss))
  1685. return 1;
  1686. } else if (os_strcmp(buf, "ca_cert") == 0) {
  1687. os_free(bss->ca_cert);
  1688. bss->ca_cert = os_strdup(pos);
  1689. } else if (os_strcmp(buf, "server_cert") == 0) {
  1690. os_free(bss->server_cert);
  1691. bss->server_cert = os_strdup(pos);
  1692. } else if (os_strcmp(buf, "private_key") == 0) {
  1693. os_free(bss->private_key);
  1694. bss->private_key = os_strdup(pos);
  1695. } else if (os_strcmp(buf, "private_key_passwd") == 0) {
  1696. os_free(bss->private_key_passwd);
  1697. bss->private_key_passwd = os_strdup(pos);
  1698. } else if (os_strcmp(buf, "check_crl") == 0) {
  1699. bss->check_crl = atoi(pos);
  1700. } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) {
  1701. os_free(bss->ocsp_stapling_response);
  1702. bss->ocsp_stapling_response = os_strdup(pos);
  1703. } else if (os_strcmp(buf, "dh_file") == 0) {
  1704. os_free(bss->dh_file);
  1705. bss->dh_file = os_strdup(pos);
  1706. } else if (os_strcmp(buf, "fragment_size") == 0) {
  1707. bss->fragment_size = atoi(pos);
  1708. #ifdef EAP_SERVER_FAST
  1709. } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
  1710. os_free(bss->pac_opaque_encr_key);
  1711. bss->pac_opaque_encr_key = os_malloc(16);
  1712. if (bss->pac_opaque_encr_key == NULL) {
  1713. wpa_printf(MSG_ERROR,
  1714. "Line %d: No memory for pac_opaque_encr_key",
  1715. line);
  1716. return 1;
  1717. } else if (hexstr2bin(pos, bss->pac_opaque_encr_key, 16)) {
  1718. wpa_printf(MSG_ERROR, "Line %d: Invalid pac_opaque_encr_key",
  1719. line);
  1720. return 1;
  1721. }
  1722. } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
  1723. size_t idlen = os_strlen(pos);
  1724. if (idlen & 1) {
  1725. wpa_printf(MSG_ERROR, "Line %d: Invalid eap_fast_a_id",
  1726. line);
  1727. return 1;
  1728. }
  1729. os_free(bss->eap_fast_a_id);
  1730. bss->eap_fast_a_id = os_malloc(idlen / 2);
  1731. if (bss->eap_fast_a_id == NULL ||
  1732. hexstr2bin(pos, bss->eap_fast_a_id, idlen / 2)) {
  1733. wpa_printf(MSG_ERROR, "Line %d: Failed to parse eap_fast_a_id",
  1734. line);
  1735. os_free(bss->eap_fast_a_id);
  1736. bss->eap_fast_a_id = NULL;
  1737. return 1;
  1738. } else {
  1739. bss->eap_fast_a_id_len = idlen / 2;
  1740. }
  1741. } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
  1742. os_free(bss->eap_fast_a_id_info);
  1743. bss->eap_fast_a_id_info = os_strdup(pos);
  1744. } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
  1745. bss->eap_fast_prov = atoi(pos);
  1746. } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
  1747. bss->pac_key_lifetime = atoi(pos);
  1748. } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
  1749. bss->pac_key_refresh_time = atoi(pos);
  1750. #endif /* EAP_SERVER_FAST */
  1751. #ifdef EAP_SERVER_SIM
  1752. } else if (os_strcmp(buf, "eap_sim_db") == 0) {
  1753. os_free(bss->eap_sim_db);
  1754. bss->eap_sim_db = os_strdup(pos);
  1755. } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
  1756. bss->eap_sim_aka_result_ind = atoi(pos);
  1757. #endif /* EAP_SERVER_SIM */
  1758. #ifdef EAP_SERVER_TNC
  1759. } else if (os_strcmp(buf, "tnc") == 0) {
  1760. bss->tnc = atoi(pos);
  1761. #endif /* EAP_SERVER_TNC */
  1762. #ifdef EAP_SERVER_PWD
  1763. } else if (os_strcmp(buf, "pwd_group") == 0) {
  1764. bss->pwd_group = atoi(pos);
  1765. #endif /* EAP_SERVER_PWD */
  1766. #endif /* EAP_SERVER */
  1767. } else if (os_strcmp(buf, "eap_message") == 0) {
  1768. char *term;
  1769. bss->eap_req_id_text = os_strdup(pos);
  1770. if (bss->eap_req_id_text == NULL) {
  1771. wpa_printf(MSG_ERROR, "Line %d: Failed to allocate memory for eap_req_id_text",
  1772. line);
  1773. return 1;
  1774. }
  1775. bss->eap_req_id_text_len = os_strlen(bss->eap_req_id_text);
  1776. term = os_strstr(bss->eap_req_id_text, "\\0");
  1777. if (term) {
  1778. *term++ = '\0';
  1779. os_memmove(term, term + 1,
  1780. bss->eap_req_id_text_len -
  1781. (term - bss->eap_req_id_text) - 1);
  1782. bss->eap_req_id_text_len--;
  1783. }
  1784. } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
  1785. bss->default_wep_key_len = atoi(pos);
  1786. if (bss->default_wep_key_len > 13) {
  1787. wpa_printf(MSG_ERROR, "Line %d: invalid WEP key len %lu (= %lu bits)",
  1788. line,
  1789. (unsigned long) bss->default_wep_key_len,
  1790. (unsigned long)
  1791. bss->default_wep_key_len * 8);
  1792. return 1;
  1793. }
  1794. } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
  1795. bss->individual_wep_key_len = atoi(pos);
  1796. if (bss->individual_wep_key_len < 0 ||
  1797. bss->individual_wep_key_len > 13) {
  1798. wpa_printf(MSG_ERROR, "Line %d: invalid WEP key len %d (= %d bits)",
  1799. line, bss->individual_wep_key_len,
  1800. bss->individual_wep_key_len * 8);
  1801. return 1;
  1802. }
  1803. } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
  1804. bss->wep_rekeying_period = atoi(pos);
  1805. if (bss->wep_rekeying_period < 0) {
  1806. wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
  1807. line, bss->wep_rekeying_period);
  1808. return 1;
  1809. }
  1810. } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
  1811. bss->eap_reauth_period = atoi(pos);
  1812. if (bss->eap_reauth_period < 0) {
  1813. wpa_printf(MSG_ERROR, "Line %d: invalid period %d",
  1814. line, bss->eap_reauth_period);
  1815. return 1;
  1816. }
  1817. } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
  1818. bss->eapol_key_index_workaround = atoi(pos);
  1819. #ifdef CONFIG_IAPP
  1820. } else if (os_strcmp(buf, "iapp_interface") == 0) {
  1821. bss->ieee802_11f = 1;
  1822. os_strlcpy(bss->iapp_iface, pos, sizeof(bss->iapp_iface));
  1823. #endif /* CONFIG_IAPP */
  1824. } else if (os_strcmp(buf, "own_ip_addr") == 0) {
  1825. if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
  1826. wpa_printf(MSG_ERROR,
  1827. "Line %d: invalid IP address '%s'",
  1828. line, pos);
  1829. return 1;
  1830. }
  1831. } else if (os_strcmp(buf, "nas_identifier") == 0) {
  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. bss->radius->auth_server->shared_secret = (u8 *) os_strdup(pos);
  1857. bss->radius->auth_server->shared_secret_len = len;
  1858. } else if (os_strcmp(buf, "acct_server_addr") == 0) {
  1859. if (hostapd_config_read_radius_addr(
  1860. &bss->radius->acct_servers,
  1861. &bss->radius->num_acct_servers, pos, 1813,
  1862. &bss->radius->acct_server)) {
  1863. wpa_printf(MSG_ERROR,
  1864. "Line %d: invalid IP address '%s'",
  1865. line, pos);
  1866. return 1;
  1867. }
  1868. } else if (bss->radius->acct_server &&
  1869. os_strcmp(buf, "acct_server_port") == 0) {
  1870. bss->radius->acct_server->port = atoi(pos);
  1871. } else if (bss->radius->acct_server &&
  1872. os_strcmp(buf, "acct_server_shared_secret") == 0) {
  1873. int len = os_strlen(pos);
  1874. if (len == 0) {
  1875. /* RFC 2865, Ch. 3 */
  1876. wpa_printf(MSG_ERROR, "Line %d: empty shared secret is not allowed",
  1877. line);
  1878. return 1;
  1879. }
  1880. bss->radius->acct_server->shared_secret = (u8 *) os_strdup(pos);
  1881. bss->radius->acct_server->shared_secret_len = len;
  1882. } else if (os_strcmp(buf, "radius_retry_primary_interval") == 0) {
  1883. bss->radius->retry_primary_interval = atoi(pos);
  1884. } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0) {
  1885. bss->acct_interim_interval = atoi(pos);
  1886. } else if (os_strcmp(buf, "radius_request_cui") == 0) {
  1887. bss->radius_request_cui = atoi(pos);
  1888. } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
  1889. struct hostapd_radius_attr *attr, *a;
  1890. attr = hostapd_parse_radius_attr(pos);
  1891. if (attr == NULL) {
  1892. wpa_printf(MSG_ERROR,
  1893. "Line %d: invalid radius_auth_req_attr",
  1894. line);
  1895. return 1;
  1896. } else if (bss->radius_auth_req_attr == NULL) {
  1897. bss->radius_auth_req_attr = attr;
  1898. } else {
  1899. a = bss->radius_auth_req_attr;
  1900. while (a->next)
  1901. a = a->next;
  1902. a->next = attr;
  1903. }
  1904. } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
  1905. struct hostapd_radius_attr *attr, *a;
  1906. attr = hostapd_parse_radius_attr(pos);
  1907. if (attr == NULL) {
  1908. wpa_printf(MSG_ERROR,
  1909. "Line %d: invalid radius_acct_req_attr",
  1910. line);
  1911. return 1;
  1912. } else if (bss->radius_acct_req_attr == NULL) {
  1913. bss->radius_acct_req_attr = attr;
  1914. } else {
  1915. a = bss->radius_acct_req_attr;
  1916. while (a->next)
  1917. a = a->next;
  1918. a->next = attr;
  1919. }
  1920. } else if (os_strcmp(buf, "radius_das_port") == 0) {
  1921. bss->radius_das_port = atoi(pos);
  1922. } else if (os_strcmp(buf, "radius_das_client") == 0) {
  1923. if (hostapd_parse_das_client(bss, pos) < 0) {
  1924. wpa_printf(MSG_ERROR, "Line %d: invalid DAS client",
  1925. line);
  1926. return 1;
  1927. }
  1928. } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
  1929. bss->radius_das_time_window = atoi(pos);
  1930. } else if (os_strcmp(buf, "radius_das_require_event_timestamp") == 0) {
  1931. bss->radius_das_require_event_timestamp = atoi(pos);
  1932. #endif /* CONFIG_NO_RADIUS */
  1933. } else if (os_strcmp(buf, "auth_algs") == 0) {
  1934. bss->auth_algs = atoi(pos);
  1935. if (bss->auth_algs == 0) {
  1936. wpa_printf(MSG_ERROR, "Line %d: no authentication algorithms allowed",
  1937. line);
  1938. return 1;
  1939. }
  1940. } else if (os_strcmp(buf, "max_num_sta") == 0) {
  1941. bss->max_num_sta = atoi(pos);
  1942. if (bss->max_num_sta < 0 ||
  1943. bss->max_num_sta > MAX_STA_COUNT) {
  1944. wpa_printf(MSG_ERROR, "Line %d: Invalid max_num_sta=%d; allowed range 0..%d",
  1945. line, bss->max_num_sta, MAX_STA_COUNT);
  1946. return 1;
  1947. }
  1948. } else if (os_strcmp(buf, "wpa") == 0) {
  1949. bss->wpa = atoi(pos);
  1950. } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
  1951. bss->wpa_group_rekey = atoi(pos);
  1952. } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
  1953. bss->wpa_strict_rekey = atoi(pos);
  1954. } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
  1955. bss->wpa_gmk_rekey = atoi(pos);
  1956. } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
  1957. bss->wpa_ptk_rekey = atoi(pos);
  1958. } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
  1959. int len = os_strlen(pos);
  1960. if (len < 8 || len > 63) {
  1961. wpa_printf(MSG_ERROR, "Line %d: invalid WPA passphrase length %d (expected 8..63)",
  1962. line, len);
  1963. return 1;
  1964. }
  1965. os_free(bss->ssid.wpa_passphrase);
  1966. bss->ssid.wpa_passphrase = os_strdup(pos);
  1967. if (bss->ssid.wpa_passphrase) {
  1968. os_free(bss->ssid.wpa_psk);
  1969. bss->ssid.wpa_psk = NULL;
  1970. bss->ssid.wpa_passphrase_set = 1;
  1971. }
  1972. } else if (os_strcmp(buf, "wpa_psk") == 0) {
  1973. os_free(bss->ssid.wpa_psk);
  1974. bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
  1975. if (bss->ssid.wpa_psk == NULL)
  1976. return 1;
  1977. if (hexstr2bin(pos, bss->ssid.wpa_psk->psk, PMK_LEN) ||
  1978. pos[PMK_LEN * 2] != '\0') {
  1979. wpa_printf(MSG_ERROR, "Line %d: Invalid PSK '%s'.",
  1980. line, pos);
  1981. os_free(bss->ssid.wpa_psk);
  1982. bss->ssid.wpa_psk = NULL;
  1983. return 1;
  1984. }
  1985. bss->ssid.wpa_psk->group = 1;
  1986. os_free(bss->ssid.wpa_passphrase);
  1987. bss->ssid.wpa_passphrase = NULL;
  1988. bss->ssid.wpa_psk_set = 1;
  1989. } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
  1990. os_free(bss->ssid.wpa_psk_file);
  1991. bss->ssid.wpa_psk_file = os_strdup(pos);
  1992. if (!bss->ssid.wpa_psk_file) {
  1993. wpa_printf(MSG_ERROR, "Line %d: allocation failed",
  1994. line);
  1995. return 1;
  1996. }
  1997. } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
  1998. bss->wpa_key_mgmt = hostapd_config_parse_key_mgmt(line, pos);
  1999. if (bss->wpa_key_mgmt == -1)
  2000. return 1;
  2001. } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
  2002. bss->wpa_psk_radius = atoi(pos);
  2003. if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
  2004. bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
  2005. bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
  2006. wpa_printf(MSG_ERROR,
  2007. "Line %d: unknown wpa_psk_radius %d",
  2008. line, bss->wpa_psk_radius);
  2009. return 1;
  2010. }
  2011. } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
  2012. bss->wpa_pairwise = hostapd_config_parse_cipher(line, pos);
  2013. if (bss->wpa_pairwise == -1 || bss->wpa_pairwise == 0)
  2014. return 1;
  2015. if (bss->wpa_pairwise &
  2016. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
  2017. wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
  2018. bss->wpa_pairwise, pos);
  2019. return 1;
  2020. }
  2021. } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
  2022. bss->rsn_pairwise = hostapd_config_parse_cipher(line, pos);
  2023. if (bss->rsn_pairwise == -1 || bss->rsn_pairwise == 0)
  2024. return 1;
  2025. if (bss->rsn_pairwise &
  2026. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)) {
  2027. wpa_printf(MSG_ERROR, "Line %d: unsupported pairwise cipher suite '%s'",
  2028. bss->rsn_pairwise, pos);
  2029. return 1;
  2030. }
  2031. #ifdef CONFIG_RSN_PREAUTH
  2032. } else if (os_strcmp(buf, "rsn_preauth") == 0) {
  2033. bss->rsn_preauth = atoi(pos);
  2034. } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
  2035. bss->rsn_preauth_interfaces = os_strdup(pos);
  2036. #endif /* CONFIG_RSN_PREAUTH */
  2037. #ifdef CONFIG_PEERKEY
  2038. } else if (os_strcmp(buf, "peerkey") == 0) {
  2039. bss->peerkey = atoi(pos);
  2040. #endif /* CONFIG_PEERKEY */
  2041. #ifdef CONFIG_IEEE80211R
  2042. } else if (os_strcmp(buf, "mobility_domain") == 0) {
  2043. if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
  2044. hexstr2bin(pos, bss->mobility_domain,
  2045. MOBILITY_DOMAIN_ID_LEN) != 0) {
  2046. wpa_printf(MSG_ERROR,
  2047. "Line %d: Invalid mobility_domain '%s'",
  2048. line, pos);
  2049. return 1;
  2050. }
  2051. } else if (os_strcmp(buf, "r1_key_holder") == 0) {
  2052. if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
  2053. hexstr2bin(pos, bss->r1_key_holder, FT_R1KH_ID_LEN) != 0) {
  2054. wpa_printf(MSG_ERROR,
  2055. "Line %d: Invalid r1_key_holder '%s'",
  2056. line, pos);
  2057. return 1;
  2058. }
  2059. } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
  2060. bss->r0_key_lifetime = atoi(pos);
  2061. } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
  2062. bss->reassociation_deadline = atoi(pos);
  2063. } else if (os_strcmp(buf, "r0kh") == 0) {
  2064. if (add_r0kh(bss, pos) < 0) {
  2065. wpa_printf(MSG_DEBUG, "Line %d: Invalid r0kh '%s'",
  2066. line, pos);
  2067. return 1;
  2068. }
  2069. } else if (os_strcmp(buf, "r1kh") == 0) {
  2070. if (add_r1kh(bss, pos) < 0) {
  2071. wpa_printf(MSG_DEBUG, "Line %d: Invalid r1kh '%s'",
  2072. line, pos);
  2073. return 1;
  2074. }
  2075. } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
  2076. bss->pmk_r1_push = atoi(pos);
  2077. } else if (os_strcmp(buf, "ft_over_ds") == 0) {
  2078. bss->ft_over_ds = atoi(pos);
  2079. #endif /* CONFIG_IEEE80211R */
  2080. #ifndef CONFIG_NO_CTRL_IFACE
  2081. } else if (os_strcmp(buf, "ctrl_interface") == 0) {
  2082. os_free(bss->ctrl_interface);
  2083. bss->ctrl_interface = os_strdup(pos);
  2084. } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
  2085. #ifndef CONFIG_NATIVE_WINDOWS
  2086. struct group *grp;
  2087. char *endp;
  2088. const char *group = pos;
  2089. grp = getgrnam(group);
  2090. if (grp) {
  2091. bss->ctrl_interface_gid = grp->gr_gid;
  2092. bss->ctrl_interface_gid_set = 1;
  2093. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d (from group name '%s')",
  2094. bss->ctrl_interface_gid, group);
  2095. return 0;
  2096. }
  2097. /* Group name not found - try to parse this as gid */
  2098. bss->ctrl_interface_gid = strtol(group, &endp, 10);
  2099. if (*group == '\0' || *endp != '\0') {
  2100. wpa_printf(MSG_DEBUG, "Line %d: Invalid group '%s'",
  2101. line, group);
  2102. return 1;
  2103. }
  2104. bss->ctrl_interface_gid_set = 1;
  2105. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
  2106. bss->ctrl_interface_gid);
  2107. #endif /* CONFIG_NATIVE_WINDOWS */
  2108. #endif /* CONFIG_NO_CTRL_IFACE */
  2109. #ifdef RADIUS_SERVER
  2110. } else if (os_strcmp(buf, "radius_server_clients") == 0) {
  2111. os_free(bss->radius_server_clients);
  2112. bss->radius_server_clients = os_strdup(pos);
  2113. } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
  2114. bss->radius_server_auth_port = atoi(pos);
  2115. } else if (os_strcmp(buf, "radius_server_acct_port") == 0) {
  2116. bss->radius_server_acct_port = atoi(pos);
  2117. } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
  2118. bss->radius_server_ipv6 = atoi(pos);
  2119. #endif /* RADIUS_SERVER */
  2120. } else if (os_strcmp(buf, "test_socket") == 0) {
  2121. os_free(bss->test_socket);
  2122. bss->test_socket = os_strdup(pos);
  2123. } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
  2124. bss->use_pae_group_addr = atoi(pos);
  2125. } else if (os_strcmp(buf, "hw_mode") == 0) {
  2126. if (os_strcmp(pos, "a") == 0)
  2127. conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
  2128. else if (os_strcmp(pos, "b") == 0)
  2129. conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
  2130. else if (os_strcmp(pos, "g") == 0)
  2131. conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
  2132. else if (os_strcmp(pos, "ad") == 0)
  2133. conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
  2134. else {
  2135. wpa_printf(MSG_ERROR, "Line %d: unknown hw_mode '%s'",
  2136. line, pos);
  2137. return 1;
  2138. }
  2139. } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
  2140. if (os_strcmp(pos, "a") == 0)
  2141. bss->wps_rf_bands = WPS_RF_50GHZ;
  2142. else if (os_strcmp(pos, "g") == 0 ||
  2143. os_strcmp(pos, "b") == 0)
  2144. bss->wps_rf_bands = WPS_RF_24GHZ;
  2145. else if (os_strcmp(pos, "ag") == 0 ||
  2146. os_strcmp(pos, "ga") == 0)
  2147. bss->wps_rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ;
  2148. else {
  2149. wpa_printf(MSG_ERROR,
  2150. "Line %d: unknown wps_rf_band '%s'",
  2151. line, pos);
  2152. return 1;
  2153. }
  2154. } else if (os_strcmp(buf, "channel") == 0) {
  2155. if (os_strcmp(pos, "acs_survey") == 0) {
  2156. #ifndef CONFIG_ACS
  2157. wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled",
  2158. line);
  2159. return 1;
  2160. #endif /* CONFIG_ACS */
  2161. conf->channel = 0;
  2162. } else
  2163. conf->channel = atoi(pos);
  2164. } else if (os_strcmp(buf, "chanlist") == 0) {
  2165. if (hostapd_parse_intlist(&conf->chanlist, pos)) {
  2166. wpa_printf(MSG_ERROR, "Line %d: invalid channel list",
  2167. line);
  2168. return 1;
  2169. }
  2170. } else if (os_strcmp(buf, "beacon_int") == 0) {
  2171. int val = atoi(pos);
  2172. /* MIB defines range as 1..65535, but very small values
  2173. * cause problems with the current implementation.
  2174. * Since it is unlikely that this small numbers are
  2175. * useful in real life scenarios, do not allow beacon
  2176. * period to be set below 15 TU. */
  2177. if (val < 15 || val > 65535) {
  2178. wpa_printf(MSG_ERROR, "Line %d: invalid beacon_int %d (expected 15..65535)",
  2179. line, val);
  2180. return 1;
  2181. }
  2182. conf->beacon_int = val;
  2183. #ifdef CONFIG_ACS
  2184. } else if (os_strcmp(buf, "acs_num_scans") == 0) {
  2185. int val = atoi(pos);
  2186. if (val <= 0 || val > 100) {
  2187. wpa_printf(MSG_ERROR, "Line %d: invalid acs_num_scans %d (expected 1..100)",
  2188. line, val);
  2189. return 1;
  2190. }
  2191. conf->acs_num_scans = val;
  2192. #endif /* CONFIG_ACS */
  2193. } else if (os_strcmp(buf, "dtim_period") == 0) {
  2194. bss->dtim_period = atoi(pos);
  2195. if (bss->dtim_period < 1 || bss->dtim_period > 255) {
  2196. wpa_printf(MSG_ERROR, "Line %d: invalid dtim_period %d",
  2197. line, bss->dtim_period);
  2198. return 1;
  2199. }
  2200. } else if (os_strcmp(buf, "rts_threshold") == 0) {
  2201. conf->rts_threshold = atoi(pos);
  2202. if (conf->rts_threshold < 0 || conf->rts_threshold > 2347) {
  2203. wpa_printf(MSG_ERROR,
  2204. "Line %d: invalid rts_threshold %d",
  2205. line, conf->rts_threshold);
  2206. return 1;
  2207. }
  2208. } else if (os_strcmp(buf, "fragm_threshold") == 0) {
  2209. conf->fragm_threshold = atoi(pos);
  2210. if (conf->fragm_threshold < 256 ||
  2211. conf->fragm_threshold > 2346) {
  2212. wpa_printf(MSG_ERROR,
  2213. "Line %d: invalid fragm_threshold %d",
  2214. line, conf->fragm_threshold);
  2215. return 1;
  2216. }
  2217. } else if (os_strcmp(buf, "send_probe_response") == 0) {
  2218. int val = atoi(pos);
  2219. if (val != 0 && val != 1) {
  2220. wpa_printf(MSG_ERROR, "Line %d: invalid send_probe_response %d (expected 0 or 1)",
  2221. line, val);
  2222. return 1;
  2223. }
  2224. conf->send_probe_response = val;
  2225. } else if (os_strcmp(buf, "supported_rates") == 0) {
  2226. if (hostapd_parse_intlist(&conf->supported_rates, pos)) {
  2227. wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
  2228. line);
  2229. return 1;
  2230. }
  2231. } else if (os_strcmp(buf, "basic_rates") == 0) {
  2232. if (hostapd_parse_intlist(&conf->basic_rates, pos)) {
  2233. wpa_printf(MSG_ERROR, "Line %d: invalid rate list",
  2234. line);
  2235. return 1;
  2236. }
  2237. } else if (os_strcmp(buf, "preamble") == 0) {
  2238. if (atoi(pos))
  2239. conf->preamble = SHORT_PREAMBLE;
  2240. else
  2241. conf->preamble = LONG_PREAMBLE;
  2242. } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
  2243. bss->ignore_broadcast_ssid = atoi(pos);
  2244. } else if (os_strcmp(buf, "wep_default_key") == 0) {
  2245. bss->ssid.wep.idx = atoi(pos);
  2246. if (bss->ssid.wep.idx > 3) {
  2247. wpa_printf(MSG_ERROR,
  2248. "Invalid wep_default_key index %d",
  2249. bss->ssid.wep.idx);
  2250. return 1;
  2251. }
  2252. } else if (os_strcmp(buf, "wep_key0") == 0 ||
  2253. os_strcmp(buf, "wep_key1") == 0 ||
  2254. os_strcmp(buf, "wep_key2") == 0 ||
  2255. os_strcmp(buf, "wep_key3") == 0) {
  2256. if (hostapd_config_read_wep(&bss->ssid.wep,
  2257. buf[7] - '0', pos)) {
  2258. wpa_printf(MSG_ERROR, "Line %d: invalid WEP key '%s'",
  2259. line, buf);
  2260. return 1;
  2261. }
  2262. #ifndef CONFIG_NO_VLAN
  2263. } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
  2264. bss->ssid.dynamic_vlan = atoi(pos);
  2265. } else if (os_strcmp(buf, "vlan_file") == 0) {
  2266. if (hostapd_config_read_vlan_file(bss, pos)) {
  2267. wpa_printf(MSG_ERROR, "Line %d: failed to read VLAN file '%s'",
  2268. line, pos);
  2269. return 1;
  2270. }
  2271. } else if (os_strcmp(buf, "vlan_naming") == 0) {
  2272. bss->ssid.vlan_naming = atoi(pos);
  2273. if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
  2274. bss->ssid.vlan_naming < 0) {
  2275. wpa_printf(MSG_ERROR,
  2276. "Line %d: invalid naming scheme %d",
  2277. line, bss->ssid.vlan_naming);
  2278. return 1;
  2279. }
  2280. #ifdef CONFIG_FULL_DYNAMIC_VLAN
  2281. } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
  2282. bss->ssid.vlan_tagged_interface = os_strdup(pos);
  2283. #endif /* CONFIG_FULL_DYNAMIC_VLAN */
  2284. #endif /* CONFIG_NO_VLAN */
  2285. } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
  2286. conf->ap_table_max_size = atoi(pos);
  2287. } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
  2288. conf->ap_table_expiration_time = atoi(pos);
  2289. } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
  2290. if (hostapd_config_tx_queue(conf, buf, pos)) {
  2291. wpa_printf(MSG_ERROR, "Line %d: invalid TX queue item",
  2292. line);
  2293. return 1;
  2294. }
  2295. } else if (os_strcmp(buf, "wme_enabled") == 0 ||
  2296. os_strcmp(buf, "wmm_enabled") == 0) {
  2297. bss->wmm_enabled = atoi(pos);
  2298. } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
  2299. bss->wmm_uapsd = atoi(pos);
  2300. } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
  2301. os_strncmp(buf, "wmm_ac_", 7) == 0) {
  2302. if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf, pos)) {
  2303. wpa_printf(MSG_ERROR, "Line %d: invalid WMM ac item",
  2304. line);
  2305. return 1;
  2306. }
  2307. } else if (os_strcmp(buf, "bss") == 0) {
  2308. if (hostapd_config_bss(conf, pos)) {
  2309. wpa_printf(MSG_ERROR, "Line %d: invalid bss item",
  2310. line);
  2311. return 1;
  2312. }
  2313. } else if (os_strcmp(buf, "bssid") == 0) {
  2314. if (hwaddr_aton(pos, bss->bssid)) {
  2315. wpa_printf(MSG_ERROR, "Line %d: invalid bssid item",
  2316. line);
  2317. return 1;
  2318. }
  2319. #ifdef CONFIG_IEEE80211W
  2320. } else if (os_strcmp(buf, "ieee80211w") == 0) {
  2321. bss->ieee80211w = atoi(pos);
  2322. } else if (os_strcmp(buf, "group_mgmt_cipher") == 0) {
  2323. if (os_strcmp(pos, "AES-128-CMAC") == 0) {
  2324. bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
  2325. } else if (os_strcmp(pos, "BIP-GMAC-128") == 0) {
  2326. bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_128;
  2327. } else if (os_strcmp(pos, "BIP-GMAC-256") == 0) {
  2328. bss->group_mgmt_cipher = WPA_CIPHER_BIP_GMAC_256;
  2329. } else if (os_strcmp(pos, "BIP-CMAC-256") == 0) {
  2330. bss->group_mgmt_cipher = WPA_CIPHER_BIP_CMAC_256;
  2331. } else {
  2332. wpa_printf(MSG_ERROR, "Line %d: invalid group_mgmt_cipher: %s",
  2333. line, pos);
  2334. return 1;
  2335. }
  2336. } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
  2337. bss->assoc_sa_query_max_timeout = atoi(pos);
  2338. if (bss->assoc_sa_query_max_timeout == 0) {
  2339. wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_max_timeout",
  2340. line);
  2341. return 1;
  2342. }
  2343. } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0) {
  2344. bss->assoc_sa_query_retry_timeout = atoi(pos);
  2345. if (bss->assoc_sa_query_retry_timeout == 0) {
  2346. wpa_printf(MSG_ERROR, "Line %d: invalid assoc_sa_query_retry_timeout",
  2347. line);
  2348. return 1;
  2349. }
  2350. #endif /* CONFIG_IEEE80211W */
  2351. #ifdef CONFIG_IEEE80211N
  2352. } else if (os_strcmp(buf, "ieee80211n") == 0) {
  2353. conf->ieee80211n = atoi(pos);
  2354. } else if (os_strcmp(buf, "ht_capab") == 0) {
  2355. if (hostapd_config_ht_capab(conf, pos) < 0) {
  2356. wpa_printf(MSG_ERROR, "Line %d: invalid ht_capab",
  2357. line);
  2358. return 1;
  2359. }
  2360. } else if (os_strcmp(buf, "require_ht") == 0) {
  2361. conf->require_ht = atoi(pos);
  2362. } else if (os_strcmp(buf, "obss_interval") == 0) {
  2363. conf->obss_interval = atoi(pos);
  2364. #endif /* CONFIG_IEEE80211N */
  2365. #ifdef CONFIG_IEEE80211AC
  2366. } else if (os_strcmp(buf, "ieee80211ac") == 0) {
  2367. conf->ieee80211ac = atoi(pos);
  2368. } else if (os_strcmp(buf, "vht_capab") == 0) {
  2369. if (hostapd_config_vht_capab(conf, pos) < 0) {
  2370. wpa_printf(MSG_ERROR, "Line %d: invalid vht_capab",
  2371. line);
  2372. return 1;
  2373. }
  2374. } else if (os_strcmp(buf, "require_vht") == 0) {
  2375. conf->require_vht = atoi(pos);
  2376. } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
  2377. conf->vht_oper_chwidth = atoi(pos);
  2378. } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0) {
  2379. conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
  2380. } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0) {
  2381. conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
  2382. #endif /* CONFIG_IEEE80211AC */
  2383. } else if (os_strcmp(buf, "max_listen_interval") == 0) {
  2384. bss->max_listen_interval = atoi(pos);
  2385. } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
  2386. bss->disable_pmksa_caching = atoi(pos);
  2387. } else if (os_strcmp(buf, "okc") == 0) {
  2388. bss->okc = atoi(pos);
  2389. #ifdef CONFIG_WPS
  2390. } else if (os_strcmp(buf, "wps_state") == 0) {
  2391. bss->wps_state = atoi(pos);
  2392. if (bss->wps_state < 0 || bss->wps_state > 2) {
  2393. wpa_printf(MSG_ERROR, "Line %d: invalid wps_state",
  2394. line);
  2395. return 1;
  2396. }
  2397. } else if (os_strcmp(buf, "wps_independent") == 0) {
  2398. bss->wps_independent = atoi(pos);
  2399. } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
  2400. bss->ap_setup_locked = atoi(pos);
  2401. } else if (os_strcmp(buf, "uuid") == 0) {
  2402. if (uuid_str2bin(pos, bss->uuid)) {
  2403. wpa_printf(MSG_ERROR, "Line %d: invalid UUID", line);
  2404. return 1;
  2405. }
  2406. } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
  2407. os_free(bss->wps_pin_requests);
  2408. bss->wps_pin_requests = os_strdup(pos);
  2409. } else if (os_strcmp(buf, "device_name") == 0) {
  2410. if (os_strlen(pos) > 32) {
  2411. wpa_printf(MSG_ERROR, "Line %d: Too long "
  2412. "device_name", line);
  2413. return 1;
  2414. }
  2415. os_free(bss->device_name);
  2416. bss->device_name = os_strdup(pos);
  2417. } else if (os_strcmp(buf, "manufacturer") == 0) {
  2418. if (os_strlen(pos) > 64) {
  2419. wpa_printf(MSG_ERROR, "Line %d: Too long manufacturer",
  2420. line);
  2421. return 1;
  2422. }
  2423. os_free(bss->manufacturer);
  2424. bss->manufacturer = os_strdup(pos);
  2425. } else if (os_strcmp(buf, "model_name") == 0) {
  2426. if (os_strlen(pos) > 32) {
  2427. wpa_printf(MSG_ERROR, "Line %d: Too long model_name",
  2428. line);
  2429. return 1;
  2430. }
  2431. os_free(bss->model_name);
  2432. bss->model_name = os_strdup(pos);
  2433. } else if (os_strcmp(buf, "model_number") == 0) {
  2434. if (os_strlen(pos) > 32) {
  2435. wpa_printf(MSG_ERROR, "Line %d: Too long model_number",
  2436. line);
  2437. return 1;
  2438. }
  2439. os_free(bss->model_number);
  2440. bss->model_number = os_strdup(pos);
  2441. } else if (os_strcmp(buf, "serial_number") == 0) {
  2442. if (os_strlen(pos) > 32) {
  2443. wpa_printf(MSG_ERROR, "Line %d: Too long serial_number",
  2444. line);
  2445. return 1;
  2446. }
  2447. os_free(bss->serial_number);
  2448. bss->serial_number = os_strdup(pos);
  2449. } else if (os_strcmp(buf, "device_type") == 0) {
  2450. if (wps_dev_type_str2bin(pos, bss->device_type))
  2451. return 1;
  2452. } else if (os_strcmp(buf, "config_methods") == 0) {
  2453. os_free(bss->config_methods);
  2454. bss->config_methods = os_strdup(pos);
  2455. } else if (os_strcmp(buf, "os_version") == 0) {
  2456. if (hexstr2bin(pos, bss->os_version, 4)) {
  2457. wpa_printf(MSG_ERROR, "Line %d: invalid os_version",
  2458. line);
  2459. return 1;
  2460. }
  2461. } else if (os_strcmp(buf, "ap_pin") == 0) {
  2462. os_free(bss->ap_pin);
  2463. bss->ap_pin = os_strdup(pos);
  2464. } else if (os_strcmp(buf, "skip_cred_build") == 0) {
  2465. bss->skip_cred_build = atoi(pos);
  2466. } else if (os_strcmp(buf, "extra_cred") == 0) {
  2467. os_free(bss->extra_cred);
  2468. bss->extra_cred = (u8 *) os_readfile(pos, &bss->extra_cred_len);
  2469. if (bss->extra_cred == NULL) {
  2470. wpa_printf(MSG_ERROR, "Line %d: could not read Credentials from '%s'",
  2471. line, pos);
  2472. return 1;
  2473. }
  2474. } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
  2475. bss->wps_cred_processing = atoi(pos);
  2476. } else if (os_strcmp(buf, "ap_settings") == 0) {
  2477. os_free(bss->ap_settings);
  2478. bss->ap_settings =
  2479. (u8 *) os_readfile(pos, &bss->ap_settings_len);
  2480. if (bss->ap_settings == NULL) {
  2481. wpa_printf(MSG_ERROR, "Line %d: could not read AP Settings from '%s'",
  2482. line, pos);
  2483. return 1;
  2484. }
  2485. } else if (os_strcmp(buf, "upnp_iface") == 0) {
  2486. bss->upnp_iface = os_strdup(pos);
  2487. } else if (os_strcmp(buf, "friendly_name") == 0) {
  2488. os_free(bss->friendly_name);
  2489. bss->friendly_name = os_strdup(pos);
  2490. } else if (os_strcmp(buf, "manufacturer_url") == 0) {
  2491. os_free(bss->manufacturer_url);
  2492. bss->manufacturer_url = os_strdup(pos);
  2493. } else if (os_strcmp(buf, "model_description") == 0) {
  2494. os_free(bss->model_description);
  2495. bss->model_description = os_strdup(pos);
  2496. } else if (os_strcmp(buf, "model_url") == 0) {
  2497. os_free(bss->model_url);
  2498. bss->model_url = os_strdup(pos);
  2499. } else if (os_strcmp(buf, "upc") == 0) {
  2500. os_free(bss->upc);
  2501. bss->upc = os_strdup(pos);
  2502. } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
  2503. bss->pbc_in_m1 = atoi(pos);
  2504. } else if (os_strcmp(buf, "server_id") == 0) {
  2505. os_free(bss->server_id);
  2506. bss->server_id = os_strdup(pos);
  2507. #ifdef CONFIG_WPS_NFC
  2508. } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
  2509. bss->wps_nfc_dev_pw_id = atoi(pos);
  2510. if (bss->wps_nfc_dev_pw_id < 0x10 ||
  2511. bss->wps_nfc_dev_pw_id > 0xffff) {
  2512. wpa_printf(MSG_ERROR, "Line %d: Invalid wps_nfc_dev_pw_id value",
  2513. line);
  2514. return 1;
  2515. }
  2516. bss->wps_nfc_pw_from_config = 1;
  2517. } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
  2518. wpabuf_free(bss->wps_nfc_dh_pubkey);
  2519. bss->wps_nfc_dh_pubkey = hostapd_parse_bin(pos);
  2520. bss->wps_nfc_pw_from_config = 1;
  2521. } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
  2522. wpabuf_free(bss->wps_nfc_dh_privkey);
  2523. bss->wps_nfc_dh_privkey = hostapd_parse_bin(pos);
  2524. bss->wps_nfc_pw_from_config = 1;
  2525. } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
  2526. wpabuf_free(bss->wps_nfc_dev_pw);
  2527. bss->wps_nfc_dev_pw = hostapd_parse_bin(pos);
  2528. bss->wps_nfc_pw_from_config = 1;
  2529. #endif /* CONFIG_WPS_NFC */
  2530. #endif /* CONFIG_WPS */
  2531. #ifdef CONFIG_P2P_MANAGER
  2532. } else if (os_strcmp(buf, "manage_p2p") == 0) {
  2533. if (atoi(pos))
  2534. bss->p2p |= P2P_MANAGE;
  2535. else
  2536. bss->p2p &= ~P2P_MANAGE;
  2537. } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
  2538. if (atoi(pos))
  2539. bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
  2540. else
  2541. bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
  2542. #endif /* CONFIG_P2P_MANAGER */
  2543. } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
  2544. bss->disassoc_low_ack = atoi(pos);
  2545. } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
  2546. if (atoi(pos))
  2547. bss->tdls |= TDLS_PROHIBIT;
  2548. else
  2549. bss->tdls &= ~TDLS_PROHIBIT;
  2550. } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
  2551. if (atoi(pos))
  2552. bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
  2553. else
  2554. bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
  2555. #ifdef CONFIG_RSN_TESTING
  2556. } else if (os_strcmp(buf, "rsn_testing") == 0) {
  2557. extern int rsn_testing;
  2558. rsn_testing = atoi(pos);
  2559. #endif /* CONFIG_RSN_TESTING */
  2560. } else if (os_strcmp(buf, "time_advertisement") == 0) {
  2561. bss->time_advertisement = atoi(pos);
  2562. } else if (os_strcmp(buf, "time_zone") == 0) {
  2563. size_t tz_len = os_strlen(pos);
  2564. if (tz_len < 4 || tz_len > 255) {
  2565. wpa_printf(MSG_DEBUG, "Line %d: invalid time_zone",
  2566. line);
  2567. return 1;
  2568. }
  2569. os_free(bss->time_zone);
  2570. bss->time_zone = os_strdup(pos);
  2571. if (bss->time_zone == NULL)
  2572. return 1;
  2573. #ifdef CONFIG_WNM
  2574. } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
  2575. bss->wnm_sleep_mode = atoi(pos);
  2576. } else if (os_strcmp(buf, "bss_transition") == 0) {
  2577. bss->bss_transition = atoi(pos);
  2578. #endif /* CONFIG_WNM */
  2579. #ifdef CONFIG_INTERWORKING
  2580. } else if (os_strcmp(buf, "interworking") == 0) {
  2581. bss->interworking = atoi(pos);
  2582. } else if (os_strcmp(buf, "access_network_type") == 0) {
  2583. bss->access_network_type = atoi(pos);
  2584. if (bss->access_network_type < 0 ||
  2585. bss->access_network_type > 15) {
  2586. wpa_printf(MSG_ERROR,
  2587. "Line %d: invalid access_network_type",
  2588. line);
  2589. return 1;
  2590. }
  2591. } else if (os_strcmp(buf, "internet") == 0) {
  2592. bss->internet = atoi(pos);
  2593. } else if (os_strcmp(buf, "asra") == 0) {
  2594. bss->asra = atoi(pos);
  2595. } else if (os_strcmp(buf, "esr") == 0) {
  2596. bss->esr = atoi(pos);
  2597. } else if (os_strcmp(buf, "uesa") == 0) {
  2598. bss->uesa = atoi(pos);
  2599. } else if (os_strcmp(buf, "venue_group") == 0) {
  2600. bss->venue_group = atoi(pos);
  2601. bss->venue_info_set = 1;
  2602. } else if (os_strcmp(buf, "venue_type") == 0) {
  2603. bss->venue_type = atoi(pos);
  2604. bss->venue_info_set = 1;
  2605. } else if (os_strcmp(buf, "hessid") == 0) {
  2606. if (hwaddr_aton(pos, bss->hessid)) {
  2607. wpa_printf(MSG_ERROR, "Line %d: invalid hessid", line);
  2608. return 1;
  2609. }
  2610. } else if (os_strcmp(buf, "roaming_consortium") == 0) {
  2611. if (parse_roaming_consortium(bss, pos, line) < 0)
  2612. return 1;
  2613. } else if (os_strcmp(buf, "venue_name") == 0) {
  2614. if (parse_venue_name(bss, pos, line) < 0)
  2615. return 1;
  2616. } else if (os_strcmp(buf, "network_auth_type") == 0) {
  2617. u8 auth_type;
  2618. u16 redirect_url_len;
  2619. if (hexstr2bin(pos, &auth_type, 1)) {
  2620. wpa_printf(MSG_ERROR,
  2621. "Line %d: Invalid network_auth_type '%s'",
  2622. line, pos);
  2623. return 1;
  2624. }
  2625. if (auth_type == 0 || auth_type == 2)
  2626. redirect_url_len = os_strlen(pos + 2);
  2627. else
  2628. redirect_url_len = 0;
  2629. os_free(bss->network_auth_type);
  2630. bss->network_auth_type = os_malloc(redirect_url_len + 3 + 1);
  2631. if (bss->network_auth_type == NULL)
  2632. return 1;
  2633. *bss->network_auth_type = auth_type;
  2634. WPA_PUT_LE16(bss->network_auth_type + 1, redirect_url_len);
  2635. if (redirect_url_len)
  2636. os_memcpy(bss->network_auth_type + 3, pos + 2,
  2637. redirect_url_len);
  2638. bss->network_auth_type_len = 3 + redirect_url_len;
  2639. } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
  2640. if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1)) {
  2641. wpa_printf(MSG_ERROR, "Line %d: Invalid ipaddr_type_availability '%s'",
  2642. line, pos);
  2643. bss->ipaddr_type_configured = 0;
  2644. return 1;
  2645. }
  2646. bss->ipaddr_type_configured = 1;
  2647. } else if (os_strcmp(buf, "domain_name") == 0) {
  2648. int j, num_domains, domain_len, domain_list_len = 0;
  2649. char *tok_start, *tok_prev;
  2650. u8 *domain_list, *domain_ptr;
  2651. domain_list_len = os_strlen(pos) + 1;
  2652. domain_list = os_malloc(domain_list_len);
  2653. if (domain_list == NULL)
  2654. return 1;
  2655. domain_ptr = domain_list;
  2656. tok_prev = pos;
  2657. num_domains = 1;
  2658. while ((tok_prev = os_strchr(tok_prev, ','))) {
  2659. num_domains++;
  2660. tok_prev++;
  2661. }
  2662. tok_prev = pos;
  2663. for (j = 0; j < num_domains; j++) {
  2664. tok_start = os_strchr(tok_prev, ',');
  2665. if (tok_start) {
  2666. domain_len = tok_start - tok_prev;
  2667. *domain_ptr = domain_len;
  2668. os_memcpy(domain_ptr + 1, tok_prev, domain_len);
  2669. domain_ptr += domain_len + 1;
  2670. tok_prev = ++tok_start;
  2671. } else {
  2672. domain_len = os_strlen(tok_prev);
  2673. *domain_ptr = domain_len;
  2674. os_memcpy(domain_ptr + 1, tok_prev, domain_len);
  2675. domain_ptr += domain_len + 1;
  2676. }
  2677. }
  2678. os_free(bss->domain_name);
  2679. bss->domain_name = domain_list;
  2680. bss->domain_name_len = domain_list_len;
  2681. } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
  2682. if (parse_3gpp_cell_net(bss, pos, line) < 0)
  2683. return 1;
  2684. } else if (os_strcmp(buf, "nai_realm") == 0) {
  2685. if (parse_nai_realm(bss, pos, line) < 0)
  2686. return 1;
  2687. } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
  2688. bss->gas_frag_limit = atoi(pos);
  2689. } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
  2690. bss->gas_comeback_delay = atoi(pos);
  2691. } else if (os_strcmp(buf, "qos_map_set") == 0) {
  2692. if (parse_qos_map_set(bss, pos, line) < 0)
  2693. return 1;
  2694. #endif /* CONFIG_INTERWORKING */
  2695. #ifdef CONFIG_RADIUS_TEST
  2696. } else if (os_strcmp(buf, "dump_msk_file") == 0) {
  2697. os_free(bss->dump_msk_file);
  2698. bss->dump_msk_file = os_strdup(pos);
  2699. #endif /* CONFIG_RADIUS_TEST */
  2700. #ifdef CONFIG_HS20
  2701. } else if (os_strcmp(buf, "hs20") == 0) {
  2702. bss->hs20 = atoi(pos);
  2703. } else if (os_strcmp(buf, "disable_dgaf") == 0) {
  2704. bss->disable_dgaf = atoi(pos);
  2705. } else if (os_strcmp(buf, "osen") == 0) {
  2706. bss->osen = atoi(pos);
  2707. } else if (os_strcmp(buf, "anqp_domain_id") == 0) {
  2708. bss->anqp_domain_id = atoi(pos);
  2709. } else if (os_strcmp(buf, "hs20_deauth_req_timeout") == 0) {
  2710. bss->hs20_deauth_req_timeout = atoi(pos);
  2711. } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
  2712. if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
  2713. return 1;
  2714. } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
  2715. if (hs20_parse_wan_metrics(bss, pos, line) < 0)
  2716. return 1;
  2717. } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
  2718. if (hs20_parse_conn_capab(bss, pos, line) < 0) {
  2719. return 1;
  2720. }
  2721. } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
  2722. u8 *oper_class;
  2723. size_t oper_class_len;
  2724. oper_class_len = os_strlen(pos);
  2725. if (oper_class_len < 2 || (oper_class_len & 0x01)) {
  2726. wpa_printf(MSG_ERROR,
  2727. "Line %d: Invalid hs20_operating_class '%s'",
  2728. line, pos);
  2729. return 1;
  2730. }
  2731. oper_class_len /= 2;
  2732. oper_class = os_malloc(oper_class_len);
  2733. if (oper_class == NULL)
  2734. return 1;
  2735. if (hexstr2bin(pos, oper_class, oper_class_len)) {
  2736. wpa_printf(MSG_ERROR,
  2737. "Line %d: Invalid hs20_operating_class '%s'",
  2738. line, pos);
  2739. os_free(oper_class);
  2740. return 1;
  2741. }
  2742. os_free(bss->hs20_operating_class);
  2743. bss->hs20_operating_class = oper_class;
  2744. bss->hs20_operating_class_len = oper_class_len;
  2745. } else if (os_strcmp(buf, "hs20_icon") == 0) {
  2746. if (hs20_parse_icon(bss, pos) < 0) {
  2747. wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_icon '%s'",
  2748. line, pos);
  2749. return 1;
  2750. }
  2751. } else if (os_strcmp(buf, "osu_ssid") == 0) {
  2752. if (hs20_parse_osu_ssid(bss, pos, line) < 0)
  2753. return 1;
  2754. } else if (os_strcmp(buf, "osu_server_uri") == 0) {
  2755. if (hs20_parse_osu_server_uri(bss, pos, line) < 0)
  2756. return 1;
  2757. } else if (os_strcmp(buf, "osu_friendly_name") == 0) {
  2758. if (hs20_parse_osu_friendly_name(bss, pos, line) < 0)
  2759. return 1;
  2760. } else if (os_strcmp(buf, "osu_nai") == 0) {
  2761. if (hs20_parse_osu_nai(bss, pos, line) < 0)
  2762. return 1;
  2763. } else if (os_strcmp(buf, "osu_method_list") == 0) {
  2764. if (hs20_parse_osu_method_list(bss, pos, line) < 0)
  2765. return 1;
  2766. } else if (os_strcmp(buf, "osu_icon") == 0) {
  2767. if (hs20_parse_osu_icon(bss, pos, line) < 0)
  2768. return 1;
  2769. } else if (os_strcmp(buf, "osu_service_desc") == 0) {
  2770. if (hs20_parse_osu_service_desc(bss, pos, line) < 0)
  2771. return 1;
  2772. } else if (os_strcmp(buf, "subscr_remediation_url") == 0) {
  2773. os_free(bss->subscr_remediation_url);
  2774. bss->subscr_remediation_url = os_strdup(pos);
  2775. } else if (os_strcmp(buf, "subscr_remediation_method") == 0) {
  2776. bss->subscr_remediation_method = atoi(pos);
  2777. #endif /* CONFIG_HS20 */
  2778. #ifdef CONFIG_TESTING_OPTIONS
  2779. #define PARSE_TEST_PROBABILITY(_val) \
  2780. } else if (os_strcmp(buf, #_val) == 0) { \
  2781. char *end; \
  2782. \
  2783. conf->_val = strtod(pos, &end); \
  2784. if (*end || conf->_val < 0.0d || \
  2785. conf->_val > 1.0d) { \
  2786. wpa_printf(MSG_ERROR, \
  2787. "Line %d: Invalid value '%s'", \
  2788. line, pos); \
  2789. return 1; \
  2790. }
  2791. PARSE_TEST_PROBABILITY(ignore_probe_probability)
  2792. PARSE_TEST_PROBABILITY(ignore_auth_probability)
  2793. PARSE_TEST_PROBABILITY(ignore_assoc_probability)
  2794. PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
  2795. PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability)
  2796. } else if (os_strcmp(buf, "bss_load_test") == 0) {
  2797. WPA_PUT_LE16(bss->bss_load_test, atoi(pos));
  2798. pos = os_strchr(pos, ':');
  2799. if (pos == NULL) {
  2800. wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
  2801. line);
  2802. return 1;
  2803. }
  2804. pos++;
  2805. bss->bss_load_test[2] = atoi(pos);
  2806. pos = os_strchr(pos, ':');
  2807. if (pos == NULL) {
  2808. wpa_printf(MSG_ERROR, "Line %d: Invalid bss_load_test",
  2809. line);
  2810. return 1;
  2811. }
  2812. pos++;
  2813. WPA_PUT_LE16(&bss->bss_load_test[3], atoi(pos));
  2814. bss->bss_load_test_set = 1;
  2815. #endif /* CONFIG_TESTING_OPTIONS */
  2816. } else if (os_strcmp(buf, "vendor_elements") == 0) {
  2817. struct wpabuf *elems;
  2818. size_t len = os_strlen(pos);
  2819. if (len & 0x01) {
  2820. wpa_printf(MSG_ERROR,
  2821. "Line %d: Invalid vendor_elements '%s'",
  2822. line, pos);
  2823. return 1;
  2824. }
  2825. len /= 2;
  2826. if (len == 0) {
  2827. wpabuf_free(bss->vendor_elements);
  2828. bss->vendor_elements = NULL;
  2829. return 0;
  2830. }
  2831. elems = wpabuf_alloc(len);
  2832. if (elems == NULL)
  2833. return 1;
  2834. if (hexstr2bin(pos, wpabuf_put(elems, len), len)) {
  2835. wpabuf_free(elems);
  2836. wpa_printf(MSG_ERROR,
  2837. "Line %d: Invalid vendor_elements '%s'",
  2838. line, pos);
  2839. return 1;
  2840. }
  2841. wpabuf_free(bss->vendor_elements);
  2842. bss->vendor_elements = elems;
  2843. } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0) {
  2844. bss->sae_anti_clogging_threshold = atoi(pos);
  2845. } else if (os_strcmp(buf, "sae_groups") == 0) {
  2846. if (hostapd_parse_intlist(&bss->sae_groups, pos)) {
  2847. wpa_printf(MSG_ERROR,
  2848. "Line %d: Invalid sae_groups value '%s'",
  2849. line, pos);
  2850. return 1;
  2851. }
  2852. } else if (os_strcmp(buf, "local_pwr_constraint") == 0) {
  2853. int val = atoi(pos);
  2854. if (val < 0 || val > 255) {
  2855. wpa_printf(MSG_ERROR, "Line %d: Invalid local_pwr_constraint %d (expected 0..255)",
  2856. line, val);
  2857. return 1;
  2858. }
  2859. conf->local_pwr_constraint = val;
  2860. } else if (os_strcmp(buf, "spectrum_mgmt_required") == 0) {
  2861. conf->spectrum_mgmt_required = atoi(pos);
  2862. } else {
  2863. wpa_printf(MSG_ERROR,
  2864. "Line %d: unknown configuration item '%s'",
  2865. line, buf);
  2866. return 1;
  2867. }
  2868. return 0;
  2869. }
  2870. /**
  2871. * hostapd_config_read - Read and parse a configuration file
  2872. * @fname: Configuration file name (including path, if needed)
  2873. * Returns: Allocated configuration data structure
  2874. */
  2875. struct hostapd_config * hostapd_config_read(const char *fname)
  2876. {
  2877. struct hostapd_config *conf;
  2878. struct hostapd_bss_config *bss;
  2879. FILE *f;
  2880. char buf[512], *pos;
  2881. int line = 0;
  2882. int errors = 0;
  2883. size_t i;
  2884. f = fopen(fname, "r");
  2885. if (f == NULL) {
  2886. wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
  2887. "for reading.", fname);
  2888. return NULL;
  2889. }
  2890. conf = hostapd_config_defaults();
  2891. if (conf == NULL) {
  2892. fclose(f);
  2893. return NULL;
  2894. }
  2895. /* set default driver based on configuration */
  2896. conf->driver = wpa_drivers[0];
  2897. if (conf->driver == NULL) {
  2898. wpa_printf(MSG_ERROR, "No driver wrappers registered!");
  2899. hostapd_config_free(conf);
  2900. fclose(f);
  2901. return NULL;
  2902. }
  2903. bss = conf->last_bss = conf->bss[0];
  2904. while (fgets(buf, sizeof(buf), f)) {
  2905. bss = conf->last_bss;
  2906. line++;
  2907. if (buf[0] == '#')
  2908. continue;
  2909. pos = buf;
  2910. while (*pos != '\0') {
  2911. if (*pos == '\n') {
  2912. *pos = '\0';
  2913. break;
  2914. }
  2915. pos++;
  2916. }
  2917. if (buf[0] == '\0')
  2918. continue;
  2919. pos = os_strchr(buf, '=');
  2920. if (pos == NULL) {
  2921. wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
  2922. line, buf);
  2923. errors++;
  2924. continue;
  2925. }
  2926. *pos = '\0';
  2927. pos++;
  2928. errors += hostapd_config_fill(conf, bss, buf, pos, line);
  2929. }
  2930. fclose(f);
  2931. for (i = 0; i < conf->num_bss; i++)
  2932. hostapd_set_security_params(conf->bss[i]);
  2933. if (hostapd_config_check(conf, 1))
  2934. errors++;
  2935. #ifndef WPA_IGNORE_CONFIG_ERRORS
  2936. if (errors) {
  2937. wpa_printf(MSG_ERROR, "%d errors found in configuration file "
  2938. "'%s'", errors, fname);
  2939. hostapd_config_free(conf);
  2940. conf = NULL;
  2941. }
  2942. #endif /* WPA_IGNORE_CONFIG_ERRORS */
  2943. return conf;
  2944. }
  2945. int hostapd_set_iface(struct hostapd_config *conf,
  2946. struct hostapd_bss_config *bss, char *field, char *value)
  2947. {
  2948. int errors;
  2949. size_t i;
  2950. errors = hostapd_config_fill(conf, bss, field, value, 0);
  2951. if (errors) {
  2952. wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
  2953. "to value '%s'", field, value);
  2954. return -1;
  2955. }
  2956. for (i = 0; i < conf->num_bss; i++)
  2957. hostapd_set_security_params(conf->bss[i]);
  2958. if (hostapd_config_check(conf, 0)) {
  2959. wpa_printf(MSG_ERROR, "Configuration check failed");
  2960. return -1;
  2961. }
  2962. return 0;
  2963. }