config_file.c 97 KB

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