config_file.c 89 KB

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