config_file.c 95 KB

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