config_file.c 82 KB

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