config_file.c 108 KB

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