config_file.c 81 KB

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