config_file.c 108 KB

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