config_file.c 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167
  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 *bss;
  647. if (*ifname == '\0')
  648. return -1;
  649. bss = os_realloc_array(conf->bss, conf->num_bss + 1,
  650. sizeof(struct hostapd_bss_config));
  651. if (bss == NULL) {
  652. wpa_printf(MSG_ERROR, "Failed to allocate memory for "
  653. "multi-BSS entry");
  654. return -1;
  655. }
  656. conf->bss = bss;
  657. bss = &(conf->bss[conf->num_bss]);
  658. os_memset(bss, 0, sizeof(*bss));
  659. bss->radius = os_zalloc(sizeof(*bss->radius));
  660. if (bss->radius == NULL) {
  661. wpa_printf(MSG_ERROR, "Failed to allocate memory for "
  662. "multi-BSS RADIUS data");
  663. return -1;
  664. }
  665. conf->num_bss++;
  666. conf->last_bss = bss;
  667. hostapd_config_defaults_bss(bss);
  668. os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
  669. os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
  670. return 0;
  671. }
  672. /* convert floats with one decimal place to value*10 int, i.e.,
  673. * "1.5" will return 15 */
  674. static int hostapd_config_read_int10(const char *value)
  675. {
  676. int i, d;
  677. char *pos;
  678. i = atoi(value);
  679. pos = os_strchr(value, '.');
  680. d = 0;
  681. if (pos) {
  682. pos++;
  683. if (*pos >= '0' && *pos <= '9')
  684. d = *pos - '0';
  685. }
  686. return i * 10 + d;
  687. }
  688. static int valid_cw(int cw)
  689. {
  690. return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
  691. cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
  692. }
  693. enum {
  694. IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
  695. IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
  696. IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
  697. IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */
  698. };
  699. static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
  700. char *val)
  701. {
  702. int num;
  703. char *pos;
  704. struct hostapd_tx_queue_params *queue;
  705. /* skip 'tx_queue_' prefix */
  706. pos = name + 9;
  707. if (os_strncmp(pos, "data", 4) == 0 &&
  708. pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
  709. num = pos[4] - '0';
  710. pos += 6;
  711. } else if (os_strncmp(pos, "after_beacon_", 13) == 0 ||
  712. os_strncmp(pos, "beacon_", 7) == 0) {
  713. wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
  714. return 0;
  715. } else {
  716. wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
  717. return -1;
  718. }
  719. if (num >= NUM_TX_QUEUES) {
  720. /* for backwards compatibility, do not trigger failure */
  721. wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
  722. return 0;
  723. }
  724. queue = &conf->tx_queue[num];
  725. if (os_strcmp(pos, "aifs") == 0) {
  726. queue->aifs = atoi(val);
  727. if (queue->aifs < 0 || queue->aifs > 255) {
  728. wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
  729. queue->aifs);
  730. return -1;
  731. }
  732. } else if (os_strcmp(pos, "cwmin") == 0) {
  733. queue->cwmin = atoi(val);
  734. if (!valid_cw(queue->cwmin)) {
  735. wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
  736. queue->cwmin);
  737. return -1;
  738. }
  739. } else if (os_strcmp(pos, "cwmax") == 0) {
  740. queue->cwmax = atoi(val);
  741. if (!valid_cw(queue->cwmax)) {
  742. wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
  743. queue->cwmax);
  744. return -1;
  745. }
  746. } else if (os_strcmp(pos, "burst") == 0) {
  747. queue->burst = hostapd_config_read_int10(val);
  748. } else {
  749. wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
  750. return -1;
  751. }
  752. return 0;
  753. }
  754. #ifdef CONFIG_IEEE80211R
  755. static int add_r0kh(struct hostapd_bss_config *bss, char *value)
  756. {
  757. struct ft_remote_r0kh *r0kh;
  758. char *pos, *next;
  759. r0kh = os_zalloc(sizeof(*r0kh));
  760. if (r0kh == NULL)
  761. return -1;
  762. /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
  763. pos = value;
  764. next = os_strchr(pos, ' ');
  765. if (next)
  766. *next++ = '\0';
  767. if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
  768. wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
  769. os_free(r0kh);
  770. return -1;
  771. }
  772. pos = next;
  773. next = os_strchr(pos, ' ');
  774. if (next)
  775. *next++ = '\0';
  776. if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
  777. wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
  778. os_free(r0kh);
  779. return -1;
  780. }
  781. r0kh->id_len = next - pos - 1;
  782. os_memcpy(r0kh->id, pos, r0kh->id_len);
  783. pos = next;
  784. if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
  785. wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
  786. os_free(r0kh);
  787. return -1;
  788. }
  789. r0kh->next = bss->r0kh_list;
  790. bss->r0kh_list = r0kh;
  791. return 0;
  792. }
  793. static int add_r1kh(struct hostapd_bss_config *bss, char *value)
  794. {
  795. struct ft_remote_r1kh *r1kh;
  796. char *pos, *next;
  797. r1kh = os_zalloc(sizeof(*r1kh));
  798. if (r1kh == NULL)
  799. return -1;
  800. /* 02:01:02:03:04:05 02:01:02:03:04:05
  801. * 000102030405060708090a0b0c0d0e0f */
  802. pos = value;
  803. next = os_strchr(pos, ' ');
  804. if (next)
  805. *next++ = '\0';
  806. if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
  807. wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
  808. os_free(r1kh);
  809. return -1;
  810. }
  811. pos = next;
  812. next = os_strchr(pos, ' ');
  813. if (next)
  814. *next++ = '\0';
  815. if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
  816. wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
  817. os_free(r1kh);
  818. return -1;
  819. }
  820. pos = next;
  821. if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
  822. wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
  823. os_free(r1kh);
  824. return -1;
  825. }
  826. r1kh->next = bss->r1kh_list;
  827. bss->r1kh_list = r1kh;
  828. return 0;
  829. }
  830. #endif /* CONFIG_IEEE80211R */
  831. #ifdef CONFIG_IEEE80211N
  832. static int hostapd_config_ht_capab(struct hostapd_config *conf,
  833. const char *capab)
  834. {
  835. if (os_strstr(capab, "[LDPC]"))
  836. conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
  837. if (os_strstr(capab, "[HT40-]")) {
  838. conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
  839. conf->secondary_channel = -1;
  840. }
  841. if (os_strstr(capab, "[HT40+]")) {
  842. conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
  843. conf->secondary_channel = 1;
  844. }
  845. if (os_strstr(capab, "[SMPS-STATIC]")) {
  846. conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
  847. conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
  848. }
  849. if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
  850. conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
  851. conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
  852. }
  853. if (os_strstr(capab, "[GF]"))
  854. conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
  855. if (os_strstr(capab, "[SHORT-GI-20]"))
  856. conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
  857. if (os_strstr(capab, "[SHORT-GI-40]"))
  858. conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
  859. if (os_strstr(capab, "[TX-STBC]"))
  860. conf->ht_capab |= HT_CAP_INFO_TX_STBC;
  861. if (os_strstr(capab, "[RX-STBC1]")) {
  862. conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
  863. conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
  864. }
  865. if (os_strstr(capab, "[RX-STBC12]")) {
  866. conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
  867. conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
  868. }
  869. if (os_strstr(capab, "[RX-STBC123]")) {
  870. conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
  871. conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
  872. }
  873. if (os_strstr(capab, "[DELAYED-BA]"))
  874. conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
  875. if (os_strstr(capab, "[MAX-AMSDU-7935]"))
  876. conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
  877. if (os_strstr(capab, "[DSSS_CCK-40]"))
  878. conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
  879. if (os_strstr(capab, "[PSMP]"))
  880. conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP;
  881. if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
  882. conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
  883. return 0;
  884. }
  885. #endif /* CONFIG_IEEE80211N */
  886. #ifdef CONFIG_IEEE80211AC
  887. static int hostapd_config_vht_capab(struct hostapd_config *conf,
  888. const char *capab)
  889. {
  890. if (os_strstr(capab, "[MAX-MPDU-7991]"))
  891. conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
  892. if (os_strstr(capab, "[MAX-MPDU-11454]"))
  893. conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
  894. if (os_strstr(capab, "[VHT160]"))
  895. conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
  896. if (os_strstr(capab, "[VHT160-80PLUS80]"))
  897. conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
  898. if (os_strstr(capab, "[VHT160-80PLUS80]"))
  899. conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
  900. if (os_strstr(capab, "[RXLDPC]"))
  901. conf->vht_capab |= VHT_CAP_RXLDPC;
  902. if (os_strstr(capab, "[SHORT-GI-80]"))
  903. conf->vht_capab |= VHT_CAP_SHORT_GI_80;
  904. if (os_strstr(capab, "[SHORT-GI-160]"))
  905. conf->vht_capab |= VHT_CAP_SHORT_GI_160;
  906. if (os_strstr(capab, "[TX-STBC-2BY1]"))
  907. conf->vht_capab |= VHT_CAP_TXSTBC;
  908. if (os_strstr(capab, "[RX-STBC-1]"))
  909. conf->vht_capab |= VHT_CAP_RXSTBC_1;
  910. if (os_strstr(capab, "[RX-STBC-12]"))
  911. conf->vht_capab |= VHT_CAP_RXSTBC_2;
  912. if (os_strstr(capab, "[RX-STBC-123]"))
  913. conf->vht_capab |= VHT_CAP_RXSTBC_3;
  914. if (os_strstr(capab, "[RX-STBC-1234]"))
  915. conf->vht_capab |= VHT_CAP_RXSTBC_4;
  916. if (os_strstr(capab, "[SU-BEAMFORMER]"))
  917. conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
  918. if (os_strstr(capab, "[SU-BEAMFORMEE]"))
  919. conf->vht_capab |= VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  920. if (os_strstr(capab, "[BF-ANTENNA-2]") &&
  921. (conf->vht_capab & VHT_CAP_MU_BEAMFORMER_CAPABLE))
  922. conf->vht_capab |= VHT_CAP_BEAMFORMER_ANTENNAS_MAX;
  923. if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
  924. (conf->vht_capab & VHT_CAP_MU_BEAMFORMER_CAPABLE))
  925. conf->vht_capab |= VHT_CAP_SOUNDING_DIMENTION_MAX;
  926. if (os_strstr(capab, "[MU-BEAMFORMER]"))
  927. conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
  928. if (os_strstr(capab, "[MU-BEAMFORMEE]"))
  929. conf->vht_capab |= VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  930. if (os_strstr(capab, "[VHT-TXOP-PS]"))
  931. conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
  932. if (os_strstr(capab, "[HTC-VHT]"))
  933. conf->vht_capab |= VHT_CAP_HTC_VHT;
  934. if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP0]"))
  935. conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT;
  936. if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
  937. (conf->vht_capab & VHT_CAP_HTC_VHT))
  938. conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
  939. if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
  940. (conf->vht_capab & VHT_CAP_HTC_VHT))
  941. conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
  942. if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
  943. conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
  944. if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
  945. conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
  946. return 0;
  947. }
  948. #endif /* CONFIG_IEEE80211AC */
  949. static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
  950. struct hostapd_config *conf)
  951. {
  952. if (bss->ieee802_1x && !bss->eap_server &&
  953. !bss->radius->auth_servers) {
  954. wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
  955. "EAP authenticator configured).");
  956. return -1;
  957. }
  958. if (bss->wpa) {
  959. int wep, i;
  960. wep = bss->default_wep_key_len > 0 ||
  961. bss->individual_wep_key_len > 0;
  962. for (i = 0; i < NUM_WEP_KEYS; i++) {
  963. if (bss->ssid.wep.keys_set) {
  964. wep = 1;
  965. break;
  966. }
  967. }
  968. if (wep) {
  969. wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
  970. return -1;
  971. }
  972. }
  973. if (bss->wpa && bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
  974. bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
  975. wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
  976. "RADIUS checking (macaddr_acl=2) enabled.");
  977. return -1;
  978. }
  979. if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
  980. bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
  981. bss->ssid.wpa_psk_file == NULL &&
  982. (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
  983. bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
  984. wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
  985. "is not configured.");
  986. return -1;
  987. }
  988. if (hostapd_mac_comp_empty(bss->bssid) != 0) {
  989. size_t i;
  990. for (i = 0; i < conf->num_bss; i++) {
  991. if ((&conf->bss[i] != bss) &&
  992. (hostapd_mac_comp(conf->bss[i].bssid,
  993. bss->bssid) == 0)) {
  994. wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
  995. " on interface '%s' and '%s'.",
  996. MAC2STR(bss->bssid),
  997. conf->bss[i].iface, bss->iface);
  998. return -1;
  999. }
  1000. }
  1001. }
  1002. #ifdef CONFIG_IEEE80211R
  1003. if (wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
  1004. (bss->nas_identifier == NULL ||
  1005. os_strlen(bss->nas_identifier) < 1 ||
  1006. os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
  1007. wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
  1008. "nas_identifier to be configured as a 1..48 octet "
  1009. "string");
  1010. return -1;
  1011. }
  1012. #endif /* CONFIG_IEEE80211R */
  1013. #ifdef CONFIG_IEEE80211N
  1014. if (conf->ieee80211n && conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
  1015. bss->disable_11n = 1;
  1016. wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
  1017. "allowed, disabling HT capabilites");
  1018. }
  1019. if (conf->ieee80211n &&
  1020. bss->ssid.security_policy == SECURITY_STATIC_WEP) {
  1021. bss->disable_11n = 1;
  1022. wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
  1023. "allowed, disabling HT capabilities");
  1024. }
  1025. if (conf->ieee80211n && bss->wpa &&
  1026. !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
  1027. !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP))) {
  1028. bss->disable_11n = 1;
  1029. wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
  1030. "requires CCMP/GCMP to be enabled, disabling HT "
  1031. "capabilities");
  1032. }
  1033. #endif /* CONFIG_IEEE80211N */
  1034. #ifdef CONFIG_WPS2
  1035. if (bss->wps_state && bss->ignore_broadcast_ssid) {
  1036. wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
  1037. "configuration forced WPS to be disabled");
  1038. bss->wps_state = 0;
  1039. }
  1040. if (bss->wps_state && bss->ssid.wep.keys_set && bss->wpa == 0) {
  1041. wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
  1042. "disabled");
  1043. bss->wps_state = 0;
  1044. }
  1045. if (bss->wps_state && bss->wpa &&
  1046. (!(bss->wpa & 2) ||
  1047. !(bss->rsn_pairwise & WPA_CIPHER_CCMP))) {
  1048. wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
  1049. "WPA2/CCMP forced WPS to be disabled");
  1050. bss->wps_state = 0;
  1051. }
  1052. #endif /* CONFIG_WPS2 */
  1053. #ifdef CONFIG_HS20
  1054. if (bss->hs20 &&
  1055. (!(bss->wpa & 2) ||
  1056. !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)))) {
  1057. wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
  1058. "configuration is required for Hotspot 2.0 "
  1059. "functionality");
  1060. return -1;
  1061. }
  1062. #endif /* CONFIG_HS20 */
  1063. return 0;
  1064. }
  1065. static int hostapd_config_check(struct hostapd_config *conf)
  1066. {
  1067. size_t i;
  1068. if (conf->ieee80211d && (!conf->country[0] || !conf->country[1])) {
  1069. wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
  1070. "setting the country_code");
  1071. return -1;
  1072. }
  1073. if (conf->ieee80211h && !conf->ieee80211d) {
  1074. wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
  1075. "IEEE 802.11d enabled");
  1076. return -1;
  1077. }
  1078. for (i = 0; i < conf->num_bss; i++) {
  1079. if (hostapd_config_check_bss(&conf->bss[i], conf))
  1080. return -1;
  1081. }
  1082. return 0;
  1083. }
  1084. #ifdef CONFIG_INTERWORKING
  1085. static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
  1086. int line)
  1087. {
  1088. size_t len = os_strlen(pos);
  1089. u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
  1090. struct hostapd_roaming_consortium *rc;
  1091. if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
  1092. hexstr2bin(pos, oi, len / 2)) {
  1093. wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
  1094. "'%s'", line, pos);
  1095. return -1;
  1096. }
  1097. len /= 2;
  1098. rc = os_realloc_array(bss->roaming_consortium,
  1099. bss->roaming_consortium_count + 1,
  1100. sizeof(struct hostapd_roaming_consortium));
  1101. if (rc == NULL)
  1102. return -1;
  1103. os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
  1104. rc[bss->roaming_consortium_count].len = len;
  1105. bss->roaming_consortium = rc;
  1106. bss->roaming_consortium_count++;
  1107. return 0;
  1108. }
  1109. static int parse_lang_string(struct hostapd_lang_string **array,
  1110. unsigned int *count, char *pos)
  1111. {
  1112. char *sep, *str = NULL;
  1113. size_t clen, nlen, slen;
  1114. struct hostapd_lang_string *ls;
  1115. int ret = -1;
  1116. if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) {
  1117. str = wpa_config_parse_string(pos, &slen);
  1118. if (!str)
  1119. return -1;
  1120. pos = str;
  1121. }
  1122. sep = os_strchr(pos, ':');
  1123. if (sep == NULL)
  1124. goto fail;
  1125. *sep++ = '\0';
  1126. clen = os_strlen(pos);
  1127. if (clen < 2 || clen > sizeof(ls->lang))
  1128. goto fail;
  1129. nlen = os_strlen(sep);
  1130. if (nlen > 252)
  1131. goto fail;
  1132. ls = os_realloc_array(*array, *count + 1,
  1133. sizeof(struct hostapd_lang_string));
  1134. if (ls == NULL)
  1135. goto fail;
  1136. *array = ls;
  1137. ls = &(*array)[*count];
  1138. (*count)++;
  1139. os_memset(ls->lang, 0, sizeof(ls->lang));
  1140. os_memcpy(ls->lang, pos, clen);
  1141. ls->name_len = nlen;
  1142. os_memcpy(ls->name, sep, nlen);
  1143. ret = 0;
  1144. fail:
  1145. os_free(str);
  1146. return ret;
  1147. }
  1148. static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
  1149. int line)
  1150. {
  1151. if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
  1152. wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
  1153. line, pos);
  1154. return -1;
  1155. }
  1156. return 0;
  1157. }
  1158. static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
  1159. int line)
  1160. {
  1161. size_t count;
  1162. char *pos;
  1163. u8 *info = NULL, *ipos;
  1164. /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
  1165. count = 1;
  1166. for (pos = buf; *pos; pos++) {
  1167. if ((*pos < '0' && *pos > '9') && *pos != ';' && *pos != ',')
  1168. goto fail;
  1169. if (*pos == ';')
  1170. count++;
  1171. }
  1172. if (1 + count * 3 > 0x7f)
  1173. goto fail;
  1174. info = os_zalloc(2 + 3 + count * 3);
  1175. if (info == NULL)
  1176. return -1;
  1177. ipos = info;
  1178. *ipos++ = 0; /* GUD - Version 1 */
  1179. *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
  1180. *ipos++ = 0; /* PLMN List IEI */
  1181. /* ext(b8) | Length of PLMN List value contents(b7..1) */
  1182. *ipos++ = 1 + count * 3;
  1183. *ipos++ = count; /* Number of PLMNs */
  1184. pos = buf;
  1185. while (pos && *pos) {
  1186. char *mcc, *mnc;
  1187. size_t mnc_len;
  1188. mcc = pos;
  1189. mnc = os_strchr(pos, ',');
  1190. if (mnc == NULL)
  1191. goto fail;
  1192. *mnc++ = '\0';
  1193. pos = os_strchr(mnc, ';');
  1194. if (pos)
  1195. *pos++ = '\0';
  1196. mnc_len = os_strlen(mnc);
  1197. if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
  1198. goto fail;
  1199. /* BC coded MCC,MNC */
  1200. /* MCC digit 2 | MCC digit 1 */
  1201. *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
  1202. /* MNC digit 3 | MCC digit 3 */
  1203. *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
  1204. (mcc[2] - '0');
  1205. /* MNC digit 2 | MNC digit 1 */
  1206. *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
  1207. }
  1208. os_free(bss->anqp_3gpp_cell_net);
  1209. bss->anqp_3gpp_cell_net = info;
  1210. bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
  1211. wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
  1212. bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
  1213. return 0;
  1214. fail:
  1215. wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
  1216. line, buf);
  1217. os_free(info);
  1218. return -1;
  1219. }
  1220. static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
  1221. {
  1222. struct hostapd_nai_realm_data *realm;
  1223. size_t i, j, len;
  1224. int *offsets;
  1225. char *pos, *end, *rpos;
  1226. offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
  1227. sizeof(int));
  1228. if (offsets == NULL)
  1229. return -1;
  1230. for (i = 0; i < bss->nai_realm_count; i++) {
  1231. realm = &bss->nai_realm_data[i];
  1232. for (j = 0; j < MAX_NAI_REALMS; j++) {
  1233. offsets[i * MAX_NAI_REALMS + j] =
  1234. realm->realm[j] ?
  1235. realm->realm[j] - realm->realm_buf : -1;
  1236. }
  1237. }
  1238. realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
  1239. sizeof(struct hostapd_nai_realm_data));
  1240. if (realm == NULL) {
  1241. os_free(offsets);
  1242. return -1;
  1243. }
  1244. bss->nai_realm_data = realm;
  1245. /* patch the pointers after realloc */
  1246. for (i = 0; i < bss->nai_realm_count; i++) {
  1247. realm = &bss->nai_realm_data[i];
  1248. for (j = 0; j < MAX_NAI_REALMS; j++) {
  1249. int offs = offsets[i * MAX_NAI_REALMS + j];
  1250. if (offs >= 0)
  1251. realm->realm[j] = realm->realm_buf + offs;
  1252. else
  1253. realm->realm[j] = NULL;
  1254. }
  1255. }
  1256. os_free(offsets);
  1257. realm = &bss->nai_realm_data[bss->nai_realm_count];
  1258. os_memset(realm, 0, sizeof(*realm));
  1259. pos = buf;
  1260. realm->encoding = atoi(pos);
  1261. pos = os_strchr(pos, ',');
  1262. if (pos == NULL)
  1263. goto fail;
  1264. pos++;
  1265. end = os_strchr(pos, ',');
  1266. if (end) {
  1267. len = end - pos;
  1268. *end = '\0';
  1269. } else {
  1270. len = os_strlen(pos);
  1271. }
  1272. if (len > MAX_NAI_REALMLEN) {
  1273. wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
  1274. "characters)", (int) len, MAX_NAI_REALMLEN);
  1275. goto fail;
  1276. }
  1277. os_memcpy(realm->realm_buf, pos, len);
  1278. if (end)
  1279. pos = end + 1;
  1280. else
  1281. pos = NULL;
  1282. while (pos && *pos) {
  1283. struct hostapd_nai_realm_eap *eap;
  1284. if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
  1285. wpa_printf(MSG_ERROR, "Too many EAP methods");
  1286. goto fail;
  1287. }
  1288. eap = &realm->eap_method[realm->eap_method_count];
  1289. realm->eap_method_count++;
  1290. end = os_strchr(pos, ',');
  1291. if (end == NULL)
  1292. end = pos + os_strlen(pos);
  1293. eap->eap_method = atoi(pos);
  1294. for (;;) {
  1295. pos = os_strchr(pos, '[');
  1296. if (pos == NULL || pos > end)
  1297. break;
  1298. pos++;
  1299. if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
  1300. wpa_printf(MSG_ERROR, "Too many auth params");
  1301. goto fail;
  1302. }
  1303. eap->auth_id[eap->num_auths] = atoi(pos);
  1304. pos = os_strchr(pos, ':');
  1305. if (pos == NULL || pos > end)
  1306. goto fail;
  1307. pos++;
  1308. eap->auth_val[eap->num_auths] = atoi(pos);
  1309. pos = os_strchr(pos, ']');
  1310. if (pos == NULL || pos > end)
  1311. goto fail;
  1312. pos++;
  1313. eap->num_auths++;
  1314. }
  1315. if (*end != ',')
  1316. break;
  1317. pos = end + 1;
  1318. }
  1319. /* Split realm list into null terminated realms */
  1320. rpos = realm->realm_buf;
  1321. i = 0;
  1322. while (*rpos) {
  1323. if (i >= MAX_NAI_REALMS) {
  1324. wpa_printf(MSG_ERROR, "Too many realms");
  1325. goto fail;
  1326. }
  1327. realm->realm[i++] = rpos;
  1328. rpos = os_strchr(rpos, ';');
  1329. if (rpos == NULL)
  1330. break;
  1331. *rpos++ = '\0';
  1332. }
  1333. bss->nai_realm_count++;
  1334. return 0;
  1335. fail:
  1336. wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
  1337. return -1;
  1338. }
  1339. #endif /* CONFIG_INTERWORKING */
  1340. #ifdef CONFIG_HS20
  1341. static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
  1342. int line)
  1343. {
  1344. u8 *conn_cap;
  1345. char *pos;
  1346. if (bss->hs20_connection_capability_len >= 0xfff0)
  1347. return -1;
  1348. conn_cap = os_realloc(bss->hs20_connection_capability,
  1349. bss->hs20_connection_capability_len + 4);
  1350. if (conn_cap == NULL)
  1351. return -1;
  1352. bss->hs20_connection_capability = conn_cap;
  1353. conn_cap += bss->hs20_connection_capability_len;
  1354. pos = buf;
  1355. conn_cap[0] = atoi(pos);
  1356. pos = os_strchr(pos, ':');
  1357. if (pos == NULL)
  1358. return -1;
  1359. pos++;
  1360. WPA_PUT_LE16(conn_cap + 1, atoi(pos));
  1361. pos = os_strchr(pos, ':');
  1362. if (pos == NULL)
  1363. return -1;
  1364. pos++;
  1365. conn_cap[3] = atoi(pos);
  1366. bss->hs20_connection_capability_len += 4;
  1367. return 0;
  1368. }
  1369. static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
  1370. int line)
  1371. {
  1372. u8 *wan_metrics;
  1373. char *pos;
  1374. /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
  1375. wan_metrics = os_zalloc(13);
  1376. if (wan_metrics == NULL)
  1377. return -1;
  1378. pos = buf;
  1379. /* WAN Info */
  1380. if (hexstr2bin(pos, wan_metrics, 1) < 0)
  1381. goto fail;
  1382. pos += 2;
  1383. if (*pos != ':')
  1384. goto fail;
  1385. pos++;
  1386. /* Downlink Speed */
  1387. WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
  1388. pos = os_strchr(pos, ':');
  1389. if (pos == NULL)
  1390. goto fail;
  1391. pos++;
  1392. /* Uplink Speed */
  1393. WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
  1394. pos = os_strchr(pos, ':');
  1395. if (pos == NULL)
  1396. goto fail;
  1397. pos++;
  1398. /* Downlink Load */
  1399. wan_metrics[9] = atoi(pos);
  1400. pos = os_strchr(pos, ':');
  1401. if (pos == NULL)
  1402. goto fail;
  1403. pos++;
  1404. /* Uplink Load */
  1405. wan_metrics[10] = atoi(pos);
  1406. pos = os_strchr(pos, ':');
  1407. if (pos == NULL)
  1408. goto fail;
  1409. pos++;
  1410. /* LMD */
  1411. WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
  1412. os_free(bss->hs20_wan_metrics);
  1413. bss->hs20_wan_metrics = wan_metrics;
  1414. return 0;
  1415. fail:
  1416. wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
  1417. line, pos);
  1418. os_free(wan_metrics);
  1419. return -1;
  1420. }
  1421. static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
  1422. char *pos, int line)
  1423. {
  1424. if (parse_lang_string(&bss->hs20_oper_friendly_name,
  1425. &bss->hs20_oper_friendly_name_count, pos)) {
  1426. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1427. "hs20_oper_friendly_name '%s'", line, pos);
  1428. return -1;
  1429. }
  1430. return 0;
  1431. }
  1432. #endif /* CONFIG_HS20 */
  1433. #ifdef CONFIG_WPS_NFC
  1434. static struct wpabuf * hostapd_parse_bin(const char *buf)
  1435. {
  1436. size_t len;
  1437. struct wpabuf *ret;
  1438. len = os_strlen(buf);
  1439. if (len & 0x01)
  1440. return NULL;
  1441. len /= 2;
  1442. ret = wpabuf_alloc(len);
  1443. if (ret == NULL)
  1444. return NULL;
  1445. if (hexstr2bin(buf, wpabuf_put(ret, len), len)) {
  1446. wpabuf_free(ret);
  1447. return NULL;
  1448. }
  1449. return ret;
  1450. }
  1451. #endif /* CONFIG_WPS_NFC */
  1452. static int hostapd_config_fill(struct hostapd_config *conf,
  1453. struct hostapd_bss_config *bss,
  1454. char *buf, char *pos, int line)
  1455. {
  1456. int errors = 0;
  1457. {
  1458. if (os_strcmp(buf, "interface") == 0) {
  1459. os_strlcpy(conf->bss[0].iface, pos,
  1460. sizeof(conf->bss[0].iface));
  1461. } else if (os_strcmp(buf, "bridge") == 0) {
  1462. os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
  1463. } else if (os_strcmp(buf, "vlan_bridge") == 0) {
  1464. os_strlcpy(bss->vlan_bridge, pos,
  1465. sizeof(bss->vlan_bridge));
  1466. } else if (os_strcmp(buf, "wds_bridge") == 0) {
  1467. os_strlcpy(bss->wds_bridge, pos,
  1468. sizeof(bss->wds_bridge));
  1469. } else if (os_strcmp(buf, "driver") == 0) {
  1470. int j;
  1471. /* clear to get error below if setting is invalid */
  1472. conf->driver = NULL;
  1473. for (j = 0; wpa_drivers[j]; j++) {
  1474. if (os_strcmp(pos, wpa_drivers[j]->name) == 0)
  1475. {
  1476. conf->driver = wpa_drivers[j];
  1477. break;
  1478. }
  1479. }
  1480. if (conf->driver == NULL) {
  1481. wpa_printf(MSG_ERROR, "Line %d: invalid/"
  1482. "unknown driver '%s'", line, pos);
  1483. errors++;
  1484. }
  1485. } else if (os_strcmp(buf, "debug") == 0) {
  1486. wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
  1487. "configuration variable is not used "
  1488. "anymore", line);
  1489. } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
  1490. bss->logger_syslog_level = atoi(pos);
  1491. } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
  1492. bss->logger_stdout_level = atoi(pos);
  1493. } else if (os_strcmp(buf, "logger_syslog") == 0) {
  1494. bss->logger_syslog = atoi(pos);
  1495. } else if (os_strcmp(buf, "logger_stdout") == 0) {
  1496. bss->logger_stdout = atoi(pos);
  1497. } else if (os_strcmp(buf, "dump_file") == 0) {
  1498. bss->dump_log_name = os_strdup(pos);
  1499. } else if (os_strcmp(buf, "ssid") == 0) {
  1500. bss->ssid.ssid_len = os_strlen(pos);
  1501. if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
  1502. bss->ssid.ssid_len < 1) {
  1503. wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
  1504. "'%s'", line, pos);
  1505. errors++;
  1506. } else {
  1507. os_memcpy(bss->ssid.ssid, pos,
  1508. bss->ssid.ssid_len);
  1509. bss->ssid.ssid_set = 1;
  1510. }
  1511. } else if (os_strcmp(buf, "ssid2") == 0) {
  1512. size_t slen;
  1513. char *str = wpa_config_parse_string(pos, &slen);
  1514. if (str == NULL || slen < 1 ||
  1515. slen > HOSTAPD_MAX_SSID_LEN) {
  1516. wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
  1517. "'%s'", line, pos);
  1518. errors++;
  1519. } else {
  1520. os_memcpy(bss->ssid.ssid, str, slen);
  1521. bss->ssid.ssid_len = slen;
  1522. bss->ssid.ssid_set = 1;
  1523. }
  1524. os_free(str);
  1525. } else if (os_strcmp(buf, "utf8_ssid") == 0) {
  1526. bss->ssid.utf8_ssid = atoi(pos) > 0;
  1527. } else if (os_strcmp(buf, "macaddr_acl") == 0) {
  1528. bss->macaddr_acl = atoi(pos);
  1529. if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
  1530. bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
  1531. bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
  1532. wpa_printf(MSG_ERROR, "Line %d: unknown "
  1533. "macaddr_acl %d",
  1534. line, bss->macaddr_acl);
  1535. }
  1536. } else if (os_strcmp(buf, "accept_mac_file") == 0) {
  1537. if (hostapd_config_read_maclist(pos, &bss->accept_mac,
  1538. &bss->num_accept_mac))
  1539. {
  1540. wpa_printf(MSG_ERROR, "Line %d: Failed to "
  1541. "read accept_mac_file '%s'",
  1542. line, pos);
  1543. errors++;
  1544. }
  1545. } else if (os_strcmp(buf, "deny_mac_file") == 0) {
  1546. if (hostapd_config_read_maclist(pos, &bss->deny_mac,
  1547. &bss->num_deny_mac)) {
  1548. wpa_printf(MSG_ERROR, "Line %d: Failed to "
  1549. "read deny_mac_file '%s'",
  1550. line, pos);
  1551. errors++;
  1552. }
  1553. } else if (os_strcmp(buf, "wds_sta") == 0) {
  1554. bss->wds_sta = atoi(pos);
  1555. } else if (os_strcmp(buf, "start_disabled") == 0) {
  1556. bss->start_disabled = atoi(pos);
  1557. } else if (os_strcmp(buf, "ap_isolate") == 0) {
  1558. bss->isolate = atoi(pos);
  1559. } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
  1560. bss->ap_max_inactivity = atoi(pos);
  1561. } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
  1562. bss->skip_inactivity_poll = atoi(pos);
  1563. } else if (os_strcmp(buf, "country_code") == 0) {
  1564. os_memcpy(conf->country, pos, 2);
  1565. /* FIX: make this configurable */
  1566. conf->country[2] = ' ';
  1567. } else if (os_strcmp(buf, "ieee80211d") == 0) {
  1568. conf->ieee80211d = atoi(pos);
  1569. } else if (os_strcmp(buf, "ieee80211h") == 0) {
  1570. conf->ieee80211h = atoi(pos);
  1571. } else if (os_strcmp(buf, "ieee8021x") == 0) {
  1572. bss->ieee802_1x = atoi(pos);
  1573. } else if (os_strcmp(buf, "eapol_version") == 0) {
  1574. bss->eapol_version = atoi(pos);
  1575. if (bss->eapol_version < 1 ||
  1576. bss->eapol_version > 2) {
  1577. wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL "
  1578. "version (%d): '%s'.",
  1579. line, bss->eapol_version, pos);
  1580. errors++;
  1581. } else
  1582. wpa_printf(MSG_DEBUG, "eapol_version=%d",
  1583. bss->eapol_version);
  1584. #ifdef EAP_SERVER
  1585. } else if (os_strcmp(buf, "eap_authenticator") == 0) {
  1586. bss->eap_server = atoi(pos);
  1587. wpa_printf(MSG_ERROR, "Line %d: obsolete "
  1588. "eap_authenticator used; this has been "
  1589. "renamed to eap_server", line);
  1590. } else if (os_strcmp(buf, "eap_server") == 0) {
  1591. bss->eap_server = atoi(pos);
  1592. } else if (os_strcmp(buf, "eap_user_file") == 0) {
  1593. if (hostapd_config_read_eap_user(pos, bss))
  1594. errors++;
  1595. } else if (os_strcmp(buf, "ca_cert") == 0) {
  1596. os_free(bss->ca_cert);
  1597. bss->ca_cert = os_strdup(pos);
  1598. } else if (os_strcmp(buf, "server_cert") == 0) {
  1599. os_free(bss->server_cert);
  1600. bss->server_cert = os_strdup(pos);
  1601. } else if (os_strcmp(buf, "private_key") == 0) {
  1602. os_free(bss->private_key);
  1603. bss->private_key = os_strdup(pos);
  1604. } else if (os_strcmp(buf, "private_key_passwd") == 0) {
  1605. os_free(bss->private_key_passwd);
  1606. bss->private_key_passwd = os_strdup(pos);
  1607. } else if (os_strcmp(buf, "check_crl") == 0) {
  1608. bss->check_crl = atoi(pos);
  1609. } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) {
  1610. os_free(bss->ocsp_stapling_response);
  1611. bss->ocsp_stapling_response = os_strdup(pos);
  1612. } else if (os_strcmp(buf, "dh_file") == 0) {
  1613. os_free(bss->dh_file);
  1614. bss->dh_file = os_strdup(pos);
  1615. } else if (os_strcmp(buf, "fragment_size") == 0) {
  1616. bss->fragment_size = atoi(pos);
  1617. #ifdef EAP_SERVER_FAST
  1618. } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
  1619. os_free(bss->pac_opaque_encr_key);
  1620. bss->pac_opaque_encr_key = os_malloc(16);
  1621. if (bss->pac_opaque_encr_key == NULL) {
  1622. wpa_printf(MSG_ERROR, "Line %d: No memory for "
  1623. "pac_opaque_encr_key", line);
  1624. errors++;
  1625. } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
  1626. 16)) {
  1627. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1628. "pac_opaque_encr_key", line);
  1629. errors++;
  1630. }
  1631. } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
  1632. size_t idlen = os_strlen(pos);
  1633. if (idlen & 1) {
  1634. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1635. "eap_fast_a_id", line);
  1636. errors++;
  1637. } else {
  1638. os_free(bss->eap_fast_a_id);
  1639. bss->eap_fast_a_id = os_malloc(idlen / 2);
  1640. if (bss->eap_fast_a_id == NULL ||
  1641. hexstr2bin(pos, bss->eap_fast_a_id,
  1642. idlen / 2)) {
  1643. wpa_printf(MSG_ERROR, "Line %d: "
  1644. "Failed to parse "
  1645. "eap_fast_a_id", line);
  1646. errors++;
  1647. } else
  1648. bss->eap_fast_a_id_len = idlen / 2;
  1649. }
  1650. } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
  1651. os_free(bss->eap_fast_a_id_info);
  1652. bss->eap_fast_a_id_info = os_strdup(pos);
  1653. } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
  1654. bss->eap_fast_prov = atoi(pos);
  1655. } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
  1656. bss->pac_key_lifetime = atoi(pos);
  1657. } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
  1658. bss->pac_key_refresh_time = atoi(pos);
  1659. #endif /* EAP_SERVER_FAST */
  1660. #ifdef EAP_SERVER_SIM
  1661. } else if (os_strcmp(buf, "eap_sim_db") == 0) {
  1662. os_free(bss->eap_sim_db);
  1663. bss->eap_sim_db = os_strdup(pos);
  1664. } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
  1665. bss->eap_sim_aka_result_ind = atoi(pos);
  1666. #endif /* EAP_SERVER_SIM */
  1667. #ifdef EAP_SERVER_TNC
  1668. } else if (os_strcmp(buf, "tnc") == 0) {
  1669. bss->tnc = atoi(pos);
  1670. #endif /* EAP_SERVER_TNC */
  1671. #ifdef EAP_SERVER_PWD
  1672. } else if (os_strcmp(buf, "pwd_group") == 0) {
  1673. bss->pwd_group = atoi(pos);
  1674. #endif /* EAP_SERVER_PWD */
  1675. #endif /* EAP_SERVER */
  1676. } else if (os_strcmp(buf, "eap_message") == 0) {
  1677. char *term;
  1678. bss->eap_req_id_text = os_strdup(pos);
  1679. if (bss->eap_req_id_text == NULL) {
  1680. wpa_printf(MSG_ERROR, "Line %d: Failed to "
  1681. "allocate memory for "
  1682. "eap_req_id_text", line);
  1683. errors++;
  1684. return errors;
  1685. }
  1686. bss->eap_req_id_text_len =
  1687. os_strlen(bss->eap_req_id_text);
  1688. term = os_strstr(bss->eap_req_id_text, "\\0");
  1689. if (term) {
  1690. *term++ = '\0';
  1691. os_memmove(term, term + 1,
  1692. bss->eap_req_id_text_len -
  1693. (term - bss->eap_req_id_text) - 1);
  1694. bss->eap_req_id_text_len--;
  1695. }
  1696. } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
  1697. bss->default_wep_key_len = atoi(pos);
  1698. if (bss->default_wep_key_len > 13) {
  1699. wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
  1700. "key len %lu (= %lu bits)", line,
  1701. (unsigned long)
  1702. bss->default_wep_key_len,
  1703. (unsigned long)
  1704. bss->default_wep_key_len * 8);
  1705. errors++;
  1706. }
  1707. } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
  1708. bss->individual_wep_key_len = atoi(pos);
  1709. if (bss->individual_wep_key_len < 0 ||
  1710. bss->individual_wep_key_len > 13) {
  1711. wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
  1712. "key len %d (= %d bits)", line,
  1713. bss->individual_wep_key_len,
  1714. bss->individual_wep_key_len * 8);
  1715. errors++;
  1716. }
  1717. } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
  1718. bss->wep_rekeying_period = atoi(pos);
  1719. if (bss->wep_rekeying_period < 0) {
  1720. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1721. "period %d",
  1722. line, bss->wep_rekeying_period);
  1723. errors++;
  1724. }
  1725. } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
  1726. bss->eap_reauth_period = atoi(pos);
  1727. if (bss->eap_reauth_period < 0) {
  1728. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1729. "period %d",
  1730. line, bss->eap_reauth_period);
  1731. errors++;
  1732. }
  1733. } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
  1734. bss->eapol_key_index_workaround = atoi(pos);
  1735. #ifdef CONFIG_IAPP
  1736. } else if (os_strcmp(buf, "iapp_interface") == 0) {
  1737. bss->ieee802_11f = 1;
  1738. os_strlcpy(bss->iapp_iface, pos,
  1739. sizeof(bss->iapp_iface));
  1740. #endif /* CONFIG_IAPP */
  1741. } else if (os_strcmp(buf, "own_ip_addr") == 0) {
  1742. if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
  1743. wpa_printf(MSG_ERROR, "Line %d: invalid IP "
  1744. "address '%s'", line, pos);
  1745. errors++;
  1746. }
  1747. } else if (os_strcmp(buf, "nas_identifier") == 0) {
  1748. bss->nas_identifier = os_strdup(pos);
  1749. #ifndef CONFIG_NO_RADIUS
  1750. } else if (os_strcmp(buf, "auth_server_addr") == 0) {
  1751. if (hostapd_config_read_radius_addr(
  1752. &bss->radius->auth_servers,
  1753. &bss->radius->num_auth_servers, pos, 1812,
  1754. &bss->radius->auth_server)) {
  1755. wpa_printf(MSG_ERROR, "Line %d: invalid IP "
  1756. "address '%s'", line, pos);
  1757. errors++;
  1758. }
  1759. } else if (bss->radius->auth_server &&
  1760. os_strcmp(buf, "auth_server_port") == 0) {
  1761. bss->radius->auth_server->port = atoi(pos);
  1762. } else if (bss->radius->auth_server &&
  1763. os_strcmp(buf, "auth_server_shared_secret") == 0) {
  1764. int len = os_strlen(pos);
  1765. if (len == 0) {
  1766. /* RFC 2865, Ch. 3 */
  1767. wpa_printf(MSG_ERROR, "Line %d: empty shared "
  1768. "secret is not allowed.", line);
  1769. errors++;
  1770. }
  1771. bss->radius->auth_server->shared_secret =
  1772. (u8 *) os_strdup(pos);
  1773. bss->radius->auth_server->shared_secret_len = len;
  1774. } else if (os_strcmp(buf, "acct_server_addr") == 0) {
  1775. if (hostapd_config_read_radius_addr(
  1776. &bss->radius->acct_servers,
  1777. &bss->radius->num_acct_servers, pos, 1813,
  1778. &bss->radius->acct_server)) {
  1779. wpa_printf(MSG_ERROR, "Line %d: invalid IP "
  1780. "address '%s'", line, pos);
  1781. errors++;
  1782. }
  1783. } else if (bss->radius->acct_server &&
  1784. os_strcmp(buf, "acct_server_port") == 0) {
  1785. bss->radius->acct_server->port = atoi(pos);
  1786. } else if (bss->radius->acct_server &&
  1787. os_strcmp(buf, "acct_server_shared_secret") == 0) {
  1788. int len = os_strlen(pos);
  1789. if (len == 0) {
  1790. /* RFC 2865, Ch. 3 */
  1791. wpa_printf(MSG_ERROR, "Line %d: empty shared "
  1792. "secret is not allowed.", line);
  1793. errors++;
  1794. }
  1795. bss->radius->acct_server->shared_secret =
  1796. (u8 *) os_strdup(pos);
  1797. bss->radius->acct_server->shared_secret_len = len;
  1798. } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
  1799. 0) {
  1800. bss->radius->retry_primary_interval = atoi(pos);
  1801. } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
  1802. {
  1803. bss->acct_interim_interval = atoi(pos);
  1804. } else if (os_strcmp(buf, "radius_request_cui") == 0) {
  1805. bss->radius_request_cui = atoi(pos);
  1806. } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
  1807. struct hostapd_radius_attr *attr, *a;
  1808. attr = hostapd_parse_radius_attr(pos);
  1809. if (attr == NULL) {
  1810. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1811. "radius_auth_req_attr", line);
  1812. errors++;
  1813. } else if (bss->radius_auth_req_attr == NULL) {
  1814. bss->radius_auth_req_attr = attr;
  1815. } else {
  1816. a = bss->radius_auth_req_attr;
  1817. while (a->next)
  1818. a = a->next;
  1819. a->next = attr;
  1820. }
  1821. } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
  1822. struct hostapd_radius_attr *attr, *a;
  1823. attr = hostapd_parse_radius_attr(pos);
  1824. if (attr == NULL) {
  1825. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1826. "radius_acct_req_attr", line);
  1827. errors++;
  1828. } else if (bss->radius_acct_req_attr == NULL) {
  1829. bss->radius_acct_req_attr = attr;
  1830. } else {
  1831. a = bss->radius_acct_req_attr;
  1832. while (a->next)
  1833. a = a->next;
  1834. a->next = attr;
  1835. }
  1836. } else if (os_strcmp(buf, "radius_das_port") == 0) {
  1837. bss->radius_das_port = atoi(pos);
  1838. } else if (os_strcmp(buf, "radius_das_client") == 0) {
  1839. if (hostapd_parse_das_client(bss, pos) < 0) {
  1840. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1841. "DAS client", line);
  1842. errors++;
  1843. }
  1844. } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
  1845. bss->radius_das_time_window = atoi(pos);
  1846. } else if (os_strcmp(buf, "radius_das_require_event_timestamp")
  1847. == 0) {
  1848. bss->radius_das_require_event_timestamp = atoi(pos);
  1849. #endif /* CONFIG_NO_RADIUS */
  1850. } else if (os_strcmp(buf, "auth_algs") == 0) {
  1851. bss->auth_algs = atoi(pos);
  1852. if (bss->auth_algs == 0) {
  1853. wpa_printf(MSG_ERROR, "Line %d: no "
  1854. "authentication algorithms allowed",
  1855. line);
  1856. errors++;
  1857. }
  1858. } else if (os_strcmp(buf, "max_num_sta") == 0) {
  1859. bss->max_num_sta = atoi(pos);
  1860. if (bss->max_num_sta < 0 ||
  1861. bss->max_num_sta > MAX_STA_COUNT) {
  1862. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1863. "max_num_sta=%d; allowed range "
  1864. "0..%d", line, bss->max_num_sta,
  1865. MAX_STA_COUNT);
  1866. errors++;
  1867. }
  1868. } else if (os_strcmp(buf, "wpa") == 0) {
  1869. bss->wpa = atoi(pos);
  1870. } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
  1871. bss->wpa_group_rekey = atoi(pos);
  1872. } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
  1873. bss->wpa_strict_rekey = atoi(pos);
  1874. } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
  1875. bss->wpa_gmk_rekey = atoi(pos);
  1876. } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
  1877. bss->wpa_ptk_rekey = atoi(pos);
  1878. } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
  1879. int len = os_strlen(pos);
  1880. if (len < 8 || len > 63) {
  1881. wpa_printf(MSG_ERROR, "Line %d: invalid WPA "
  1882. "passphrase length %d (expected "
  1883. "8..63)", line, len);
  1884. errors++;
  1885. } else {
  1886. os_free(bss->ssid.wpa_passphrase);
  1887. bss->ssid.wpa_passphrase = os_strdup(pos);
  1888. os_free(bss->ssid.wpa_psk);
  1889. bss->ssid.wpa_psk = NULL;
  1890. }
  1891. } else if (os_strcmp(buf, "wpa_psk") == 0) {
  1892. os_free(bss->ssid.wpa_psk);
  1893. bss->ssid.wpa_psk =
  1894. os_zalloc(sizeof(struct hostapd_wpa_psk));
  1895. if (bss->ssid.wpa_psk == NULL)
  1896. errors++;
  1897. else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
  1898. PMK_LEN) ||
  1899. pos[PMK_LEN * 2] != '\0') {
  1900. wpa_printf(MSG_ERROR, "Line %d: Invalid PSK "
  1901. "'%s'.", line, pos);
  1902. errors++;
  1903. } else {
  1904. bss->ssid.wpa_psk->group = 1;
  1905. os_free(bss->ssid.wpa_passphrase);
  1906. bss->ssid.wpa_passphrase = NULL;
  1907. }
  1908. } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
  1909. os_free(bss->ssid.wpa_psk_file);
  1910. bss->ssid.wpa_psk_file = os_strdup(pos);
  1911. if (!bss->ssid.wpa_psk_file) {
  1912. wpa_printf(MSG_ERROR, "Line %d: allocation "
  1913. "failed", line);
  1914. errors++;
  1915. }
  1916. } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
  1917. bss->wpa_key_mgmt =
  1918. hostapd_config_parse_key_mgmt(line, pos);
  1919. if (bss->wpa_key_mgmt == -1)
  1920. errors++;
  1921. } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
  1922. bss->wpa_psk_radius = atoi(pos);
  1923. if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
  1924. bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
  1925. bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
  1926. wpa_printf(MSG_ERROR, "Line %d: unknown "
  1927. "wpa_psk_radius %d",
  1928. line, bss->wpa_psk_radius);
  1929. errors++;
  1930. }
  1931. } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
  1932. bss->wpa_pairwise =
  1933. hostapd_config_parse_cipher(line, pos);
  1934. if (bss->wpa_pairwise == -1 ||
  1935. bss->wpa_pairwise == 0)
  1936. errors++;
  1937. else if (bss->wpa_pairwise &
  1938. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
  1939. WPA_CIPHER_WEP104)) {
  1940. wpa_printf(MSG_ERROR, "Line %d: unsupported "
  1941. "pairwise cipher suite '%s'",
  1942. bss->wpa_pairwise, pos);
  1943. errors++;
  1944. }
  1945. } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
  1946. bss->rsn_pairwise =
  1947. hostapd_config_parse_cipher(line, pos);
  1948. if (bss->rsn_pairwise == -1 ||
  1949. bss->rsn_pairwise == 0)
  1950. errors++;
  1951. else if (bss->rsn_pairwise &
  1952. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
  1953. WPA_CIPHER_WEP104)) {
  1954. wpa_printf(MSG_ERROR, "Line %d: unsupported "
  1955. "pairwise cipher suite '%s'",
  1956. bss->rsn_pairwise, pos);
  1957. errors++;
  1958. }
  1959. #ifdef CONFIG_RSN_PREAUTH
  1960. } else if (os_strcmp(buf, "rsn_preauth") == 0) {
  1961. bss->rsn_preauth = atoi(pos);
  1962. } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
  1963. bss->rsn_preauth_interfaces = os_strdup(pos);
  1964. #endif /* CONFIG_RSN_PREAUTH */
  1965. #ifdef CONFIG_PEERKEY
  1966. } else if (os_strcmp(buf, "peerkey") == 0) {
  1967. bss->peerkey = atoi(pos);
  1968. #endif /* CONFIG_PEERKEY */
  1969. #ifdef CONFIG_IEEE80211R
  1970. } else if (os_strcmp(buf, "mobility_domain") == 0) {
  1971. if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
  1972. hexstr2bin(pos, bss->mobility_domain,
  1973. MOBILITY_DOMAIN_ID_LEN) != 0) {
  1974. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1975. "mobility_domain '%s'", line, pos);
  1976. errors++;
  1977. return errors;
  1978. }
  1979. } else if (os_strcmp(buf, "r1_key_holder") == 0) {
  1980. if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
  1981. hexstr2bin(pos, bss->r1_key_holder,
  1982. FT_R1KH_ID_LEN) != 0) {
  1983. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1984. "r1_key_holder '%s'", line, pos);
  1985. errors++;
  1986. return errors;
  1987. }
  1988. } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
  1989. bss->r0_key_lifetime = atoi(pos);
  1990. } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
  1991. bss->reassociation_deadline = atoi(pos);
  1992. } else if (os_strcmp(buf, "r0kh") == 0) {
  1993. if (add_r0kh(bss, pos) < 0) {
  1994. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1995. "r0kh '%s'", line, pos);
  1996. errors++;
  1997. return errors;
  1998. }
  1999. } else if (os_strcmp(buf, "r1kh") == 0) {
  2000. if (add_r1kh(bss, pos) < 0) {
  2001. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  2002. "r1kh '%s'", line, pos);
  2003. errors++;
  2004. return errors;
  2005. }
  2006. } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
  2007. bss->pmk_r1_push = atoi(pos);
  2008. } else if (os_strcmp(buf, "ft_over_ds") == 0) {
  2009. bss->ft_over_ds = atoi(pos);
  2010. #endif /* CONFIG_IEEE80211R */
  2011. #ifndef CONFIG_NO_CTRL_IFACE
  2012. } else if (os_strcmp(buf, "ctrl_interface") == 0) {
  2013. os_free(bss->ctrl_interface);
  2014. bss->ctrl_interface = os_strdup(pos);
  2015. } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
  2016. #ifndef CONFIG_NATIVE_WINDOWS
  2017. struct group *grp;
  2018. char *endp;
  2019. const char *group = pos;
  2020. grp = getgrnam(group);
  2021. if (grp) {
  2022. bss->ctrl_interface_gid = grp->gr_gid;
  2023. bss->ctrl_interface_gid_set = 1;
  2024. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
  2025. " (from group name '%s')",
  2026. bss->ctrl_interface_gid, group);
  2027. return errors;
  2028. }
  2029. /* Group name not found - try to parse this as gid */
  2030. bss->ctrl_interface_gid = strtol(group, &endp, 10);
  2031. if (*group == '\0' || *endp != '\0') {
  2032. wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
  2033. "'%s'", line, group);
  2034. errors++;
  2035. return errors;
  2036. }
  2037. bss->ctrl_interface_gid_set = 1;
  2038. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
  2039. bss->ctrl_interface_gid);
  2040. #endif /* CONFIG_NATIVE_WINDOWS */
  2041. #endif /* CONFIG_NO_CTRL_IFACE */
  2042. #ifdef RADIUS_SERVER
  2043. } else if (os_strcmp(buf, "radius_server_clients") == 0) {
  2044. os_free(bss->radius_server_clients);
  2045. bss->radius_server_clients = os_strdup(pos);
  2046. } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
  2047. bss->radius_server_auth_port = atoi(pos);
  2048. } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
  2049. bss->radius_server_ipv6 = atoi(pos);
  2050. #endif /* RADIUS_SERVER */
  2051. } else if (os_strcmp(buf, "test_socket") == 0) {
  2052. os_free(bss->test_socket);
  2053. bss->test_socket = os_strdup(pos);
  2054. } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
  2055. bss->use_pae_group_addr = atoi(pos);
  2056. } else if (os_strcmp(buf, "hw_mode") == 0) {
  2057. if (os_strcmp(pos, "a") == 0)
  2058. conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
  2059. else if (os_strcmp(pos, "b") == 0)
  2060. conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
  2061. else if (os_strcmp(pos, "g") == 0)
  2062. conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
  2063. else if (os_strcmp(pos, "ad") == 0)
  2064. conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
  2065. else {
  2066. wpa_printf(MSG_ERROR, "Line %d: unknown "
  2067. "hw_mode '%s'", line, pos);
  2068. errors++;
  2069. }
  2070. } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
  2071. if (os_strcmp(pos, "a") == 0)
  2072. bss->wps_rf_bands = WPS_RF_50GHZ;
  2073. else if (os_strcmp(pos, "g") == 0 ||
  2074. os_strcmp(pos, "b") == 0)
  2075. bss->wps_rf_bands = WPS_RF_24GHZ;
  2076. else if (os_strcmp(pos, "ag") == 0 ||
  2077. os_strcmp(pos, "ga") == 0)
  2078. bss->wps_rf_bands =
  2079. WPS_RF_24GHZ | WPS_RF_50GHZ;
  2080. else {
  2081. wpa_printf(MSG_ERROR, "Line %d: unknown "
  2082. "wps_rf_band '%s'", line, pos);
  2083. errors++;
  2084. }
  2085. } else if (os_strcmp(buf, "channel") == 0) {
  2086. if (os_strcmp(pos, "acs_survey") == 0) {
  2087. #ifndef CONFIG_ACS
  2088. wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled",
  2089. line);
  2090. errors++;
  2091. #endif /* CONFIG_ACS */
  2092. conf->channel = 0;
  2093. } else
  2094. conf->channel = atoi(pos);
  2095. } else if (os_strcmp(buf, "beacon_int") == 0) {
  2096. int val = atoi(pos);
  2097. /* MIB defines range as 1..65535, but very small values
  2098. * cause problems with the current implementation.
  2099. * Since it is unlikely that this small numbers are
  2100. * useful in real life scenarios, do not allow beacon
  2101. * period to be set below 15 TU. */
  2102. if (val < 15 || val > 65535) {
  2103. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2104. "beacon_int %d (expected "
  2105. "15..65535)", line, val);
  2106. errors++;
  2107. } else
  2108. conf->beacon_int = val;
  2109. #ifdef CONFIG_ACS
  2110. } else if (os_strcmp(buf, "acs_num_scans") == 0) {
  2111. int val = atoi(pos);
  2112. if (val <= 0 || val > 100) {
  2113. wpa_printf(MSG_ERROR, "Line %d: invalid acs_num_scans %d (expected 1..100)",
  2114. line, val);
  2115. errors++;
  2116. } else
  2117. conf->acs_num_scans = val;
  2118. #endif /* CONFIG_ACS */
  2119. } else if (os_strcmp(buf, "dtim_period") == 0) {
  2120. bss->dtim_period = atoi(pos);
  2121. if (bss->dtim_period < 1 || bss->dtim_period > 255) {
  2122. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2123. "dtim_period %d",
  2124. line, bss->dtim_period);
  2125. errors++;
  2126. }
  2127. } else if (os_strcmp(buf, "rts_threshold") == 0) {
  2128. conf->rts_threshold = atoi(pos);
  2129. if (conf->rts_threshold < 0 ||
  2130. conf->rts_threshold > 2347) {
  2131. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2132. "rts_threshold %d",
  2133. line, conf->rts_threshold);
  2134. errors++;
  2135. }
  2136. } else if (os_strcmp(buf, "fragm_threshold") == 0) {
  2137. conf->fragm_threshold = atoi(pos);
  2138. if (conf->fragm_threshold < 256 ||
  2139. conf->fragm_threshold > 2346) {
  2140. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2141. "fragm_threshold %d",
  2142. line, conf->fragm_threshold);
  2143. errors++;
  2144. }
  2145. } else if (os_strcmp(buf, "send_probe_response") == 0) {
  2146. int val = atoi(pos);
  2147. if (val != 0 && val != 1) {
  2148. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2149. "send_probe_response %d (expected "
  2150. "0 or 1)", line, val);
  2151. } else
  2152. conf->send_probe_response = val;
  2153. } else if (os_strcmp(buf, "supported_rates") == 0) {
  2154. if (hostapd_parse_intlist(&conf->supported_rates, pos))
  2155. {
  2156. wpa_printf(MSG_ERROR, "Line %d: invalid rate "
  2157. "list", line);
  2158. errors++;
  2159. }
  2160. } else if (os_strcmp(buf, "basic_rates") == 0) {
  2161. if (hostapd_parse_intlist(&conf->basic_rates, pos)) {
  2162. wpa_printf(MSG_ERROR, "Line %d: invalid rate "
  2163. "list", line);
  2164. errors++;
  2165. }
  2166. } else if (os_strcmp(buf, "preamble") == 0) {
  2167. if (atoi(pos))
  2168. conf->preamble = SHORT_PREAMBLE;
  2169. else
  2170. conf->preamble = LONG_PREAMBLE;
  2171. } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
  2172. bss->ignore_broadcast_ssid = atoi(pos);
  2173. } else if (os_strcmp(buf, "wep_default_key") == 0) {
  2174. bss->ssid.wep.idx = atoi(pos);
  2175. if (bss->ssid.wep.idx > 3) {
  2176. wpa_printf(MSG_ERROR, "Invalid "
  2177. "wep_default_key index %d",
  2178. bss->ssid.wep.idx);
  2179. errors++;
  2180. }
  2181. } else if (os_strcmp(buf, "wep_key0") == 0 ||
  2182. os_strcmp(buf, "wep_key1") == 0 ||
  2183. os_strcmp(buf, "wep_key2") == 0 ||
  2184. os_strcmp(buf, "wep_key3") == 0) {
  2185. if (hostapd_config_read_wep(&bss->ssid.wep,
  2186. buf[7] - '0', pos)) {
  2187. wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
  2188. "key '%s'", line, buf);
  2189. errors++;
  2190. }
  2191. #ifndef CONFIG_NO_VLAN
  2192. } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
  2193. bss->ssid.dynamic_vlan = atoi(pos);
  2194. } else if (os_strcmp(buf, "vlan_file") == 0) {
  2195. if (hostapd_config_read_vlan_file(bss, pos)) {
  2196. wpa_printf(MSG_ERROR, "Line %d: failed to "
  2197. "read VLAN file '%s'", line, pos);
  2198. errors++;
  2199. }
  2200. } else if (os_strcmp(buf, "vlan_naming") == 0) {
  2201. bss->ssid.vlan_naming = atoi(pos);
  2202. if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
  2203. bss->ssid.vlan_naming < 0) {
  2204. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2205. "naming scheme %d", line,
  2206. bss->ssid.vlan_naming);
  2207. errors++;
  2208. }
  2209. #ifdef CONFIG_FULL_DYNAMIC_VLAN
  2210. } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
  2211. bss->ssid.vlan_tagged_interface = os_strdup(pos);
  2212. #endif /* CONFIG_FULL_DYNAMIC_VLAN */
  2213. #endif /* CONFIG_NO_VLAN */
  2214. } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
  2215. conf->ap_table_max_size = atoi(pos);
  2216. } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
  2217. conf->ap_table_expiration_time = atoi(pos);
  2218. } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
  2219. if (hostapd_config_tx_queue(conf, buf, pos)) {
  2220. wpa_printf(MSG_ERROR, "Line %d: invalid TX "
  2221. "queue item", line);
  2222. errors++;
  2223. }
  2224. } else if (os_strcmp(buf, "wme_enabled") == 0 ||
  2225. os_strcmp(buf, "wmm_enabled") == 0) {
  2226. bss->wmm_enabled = atoi(pos);
  2227. } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
  2228. bss->wmm_uapsd = atoi(pos);
  2229. } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
  2230. os_strncmp(buf, "wmm_ac_", 7) == 0) {
  2231. if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf,
  2232. pos)) {
  2233. wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
  2234. "ac item", line);
  2235. errors++;
  2236. }
  2237. } else if (os_strcmp(buf, "bss") == 0) {
  2238. if (hostapd_config_bss(conf, pos)) {
  2239. wpa_printf(MSG_ERROR, "Line %d: invalid bss "
  2240. "item", line);
  2241. errors++;
  2242. }
  2243. } else if (os_strcmp(buf, "bssid") == 0) {
  2244. if (hwaddr_aton(pos, bss->bssid)) {
  2245. wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
  2246. "item", line);
  2247. errors++;
  2248. }
  2249. #ifdef CONFIG_IEEE80211W
  2250. } else if (os_strcmp(buf, "ieee80211w") == 0) {
  2251. bss->ieee80211w = atoi(pos);
  2252. } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
  2253. bss->assoc_sa_query_max_timeout = atoi(pos);
  2254. if (bss->assoc_sa_query_max_timeout == 0) {
  2255. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2256. "assoc_sa_query_max_timeout", line);
  2257. errors++;
  2258. }
  2259. } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0)
  2260. {
  2261. bss->assoc_sa_query_retry_timeout = atoi(pos);
  2262. if (bss->assoc_sa_query_retry_timeout == 0) {
  2263. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2264. "assoc_sa_query_retry_timeout",
  2265. line);
  2266. errors++;
  2267. }
  2268. #endif /* CONFIG_IEEE80211W */
  2269. #ifdef CONFIG_IEEE80211N
  2270. } else if (os_strcmp(buf, "ieee80211n") == 0) {
  2271. conf->ieee80211n = atoi(pos);
  2272. } else if (os_strcmp(buf, "ht_capab") == 0) {
  2273. if (hostapd_config_ht_capab(conf, pos) < 0) {
  2274. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2275. "ht_capab", line);
  2276. errors++;
  2277. }
  2278. } else if (os_strcmp(buf, "require_ht") == 0) {
  2279. conf->require_ht = atoi(pos);
  2280. #endif /* CONFIG_IEEE80211N */
  2281. #ifdef CONFIG_IEEE80211AC
  2282. } else if (os_strcmp(buf, "ieee80211ac") == 0) {
  2283. conf->ieee80211ac = atoi(pos);
  2284. } else if (os_strcmp(buf, "vht_capab") == 0) {
  2285. if (hostapd_config_vht_capab(conf, pos) < 0) {
  2286. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2287. "vht_capab", line);
  2288. errors++;
  2289. }
  2290. } else if (os_strcmp(buf, "require_vht") == 0) {
  2291. conf->require_vht = atoi(pos);
  2292. } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
  2293. conf->vht_oper_chwidth = atoi(pos);
  2294. } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0)
  2295. {
  2296. conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
  2297. } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0)
  2298. {
  2299. conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
  2300. #endif /* CONFIG_IEEE80211AC */
  2301. } else if (os_strcmp(buf, "max_listen_interval") == 0) {
  2302. bss->max_listen_interval = atoi(pos);
  2303. } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
  2304. bss->disable_pmksa_caching = atoi(pos);
  2305. } else if (os_strcmp(buf, "okc") == 0) {
  2306. bss->okc = atoi(pos);
  2307. #ifdef CONFIG_WPS
  2308. } else if (os_strcmp(buf, "wps_state") == 0) {
  2309. bss->wps_state = atoi(pos);
  2310. if (bss->wps_state < 0 || bss->wps_state > 2) {
  2311. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2312. "wps_state", line);
  2313. errors++;
  2314. }
  2315. } else if (os_strcmp(buf, "wps_independent") == 0) {
  2316. bss->wps_independent = atoi(pos);
  2317. } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
  2318. bss->ap_setup_locked = atoi(pos);
  2319. } else if (os_strcmp(buf, "uuid") == 0) {
  2320. if (uuid_str2bin(pos, bss->uuid)) {
  2321. wpa_printf(MSG_ERROR, "Line %d: invalid UUID",
  2322. line);
  2323. errors++;
  2324. }
  2325. } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
  2326. os_free(bss->wps_pin_requests);
  2327. bss->wps_pin_requests = os_strdup(pos);
  2328. } else if (os_strcmp(buf, "device_name") == 0) {
  2329. if (os_strlen(pos) > 32) {
  2330. wpa_printf(MSG_ERROR, "Line %d: Too long "
  2331. "device_name", line);
  2332. errors++;
  2333. }
  2334. os_free(bss->device_name);
  2335. bss->device_name = os_strdup(pos);
  2336. } else if (os_strcmp(buf, "manufacturer") == 0) {
  2337. if (os_strlen(pos) > 64) {
  2338. wpa_printf(MSG_ERROR, "Line %d: Too long "
  2339. "manufacturer", line);
  2340. errors++;
  2341. }
  2342. os_free(bss->manufacturer);
  2343. bss->manufacturer = os_strdup(pos);
  2344. } else if (os_strcmp(buf, "model_name") == 0) {
  2345. if (os_strlen(pos) > 32) {
  2346. wpa_printf(MSG_ERROR, "Line %d: Too long "
  2347. "model_name", line);
  2348. errors++;
  2349. }
  2350. os_free(bss->model_name);
  2351. bss->model_name = os_strdup(pos);
  2352. } else if (os_strcmp(buf, "model_number") == 0) {
  2353. if (os_strlen(pos) > 32) {
  2354. wpa_printf(MSG_ERROR, "Line %d: Too long "
  2355. "model_number", line);
  2356. errors++;
  2357. }
  2358. os_free(bss->model_number);
  2359. bss->model_number = os_strdup(pos);
  2360. } else if (os_strcmp(buf, "serial_number") == 0) {
  2361. if (os_strlen(pos) > 32) {
  2362. wpa_printf(MSG_ERROR, "Line %d: Too long "
  2363. "serial_number", line);
  2364. errors++;
  2365. }
  2366. os_free(bss->serial_number);
  2367. bss->serial_number = os_strdup(pos);
  2368. } else if (os_strcmp(buf, "device_type") == 0) {
  2369. if (wps_dev_type_str2bin(pos, bss->device_type))
  2370. errors++;
  2371. } else if (os_strcmp(buf, "config_methods") == 0) {
  2372. os_free(bss->config_methods);
  2373. bss->config_methods = os_strdup(pos);
  2374. } else if (os_strcmp(buf, "os_version") == 0) {
  2375. if (hexstr2bin(pos, bss->os_version, 4)) {
  2376. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2377. "os_version", line);
  2378. errors++;
  2379. }
  2380. } else if (os_strcmp(buf, "ap_pin") == 0) {
  2381. os_free(bss->ap_pin);
  2382. bss->ap_pin = os_strdup(pos);
  2383. } else if (os_strcmp(buf, "skip_cred_build") == 0) {
  2384. bss->skip_cred_build = atoi(pos);
  2385. } else if (os_strcmp(buf, "extra_cred") == 0) {
  2386. os_free(bss->extra_cred);
  2387. bss->extra_cred =
  2388. (u8 *) os_readfile(pos, &bss->extra_cred_len);
  2389. if (bss->extra_cred == NULL) {
  2390. wpa_printf(MSG_ERROR, "Line %d: could not "
  2391. "read Credentials from '%s'",
  2392. line, pos);
  2393. errors++;
  2394. }
  2395. } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
  2396. bss->wps_cred_processing = atoi(pos);
  2397. } else if (os_strcmp(buf, "ap_settings") == 0) {
  2398. os_free(bss->ap_settings);
  2399. bss->ap_settings =
  2400. (u8 *) os_readfile(pos, &bss->ap_settings_len);
  2401. if (bss->ap_settings == NULL) {
  2402. wpa_printf(MSG_ERROR, "Line %d: could not "
  2403. "read AP Settings from '%s'",
  2404. line, pos);
  2405. errors++;
  2406. }
  2407. } else if (os_strcmp(buf, "upnp_iface") == 0) {
  2408. bss->upnp_iface = os_strdup(pos);
  2409. } else if (os_strcmp(buf, "friendly_name") == 0) {
  2410. os_free(bss->friendly_name);
  2411. bss->friendly_name = os_strdup(pos);
  2412. } else if (os_strcmp(buf, "manufacturer_url") == 0) {
  2413. os_free(bss->manufacturer_url);
  2414. bss->manufacturer_url = os_strdup(pos);
  2415. } else if (os_strcmp(buf, "model_description") == 0) {
  2416. os_free(bss->model_description);
  2417. bss->model_description = os_strdup(pos);
  2418. } else if (os_strcmp(buf, "model_url") == 0) {
  2419. os_free(bss->model_url);
  2420. bss->model_url = os_strdup(pos);
  2421. } else if (os_strcmp(buf, "upc") == 0) {
  2422. os_free(bss->upc);
  2423. bss->upc = os_strdup(pos);
  2424. } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
  2425. bss->pbc_in_m1 = atoi(pos);
  2426. } else if (os_strcmp(buf, "server_id") == 0) {
  2427. os_free(bss->server_id);
  2428. bss->server_id = os_strdup(pos);
  2429. #ifdef CONFIG_WPS_NFC
  2430. } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
  2431. bss->wps_nfc_dev_pw_id = atoi(pos);
  2432. if (bss->wps_nfc_dev_pw_id < 0x10 ||
  2433. bss->wps_nfc_dev_pw_id > 0xffff) {
  2434. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2435. "wps_nfc_dev_pw_id value", line);
  2436. errors++;
  2437. }
  2438. bss->wps_nfc_pw_from_config = 1;
  2439. } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
  2440. wpabuf_free(bss->wps_nfc_dh_pubkey);
  2441. bss->wps_nfc_dh_pubkey = hostapd_parse_bin(pos);
  2442. bss->wps_nfc_pw_from_config = 1;
  2443. } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
  2444. wpabuf_free(bss->wps_nfc_dh_privkey);
  2445. bss->wps_nfc_dh_privkey = hostapd_parse_bin(pos);
  2446. bss->wps_nfc_pw_from_config = 1;
  2447. } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
  2448. wpabuf_free(bss->wps_nfc_dev_pw);
  2449. bss->wps_nfc_dev_pw = hostapd_parse_bin(pos);
  2450. bss->wps_nfc_pw_from_config = 1;
  2451. #endif /* CONFIG_WPS_NFC */
  2452. #endif /* CONFIG_WPS */
  2453. #ifdef CONFIG_P2P_MANAGER
  2454. } else if (os_strcmp(buf, "manage_p2p") == 0) {
  2455. int manage = atoi(pos);
  2456. if (manage)
  2457. bss->p2p |= P2P_MANAGE;
  2458. else
  2459. bss->p2p &= ~P2P_MANAGE;
  2460. } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
  2461. if (atoi(pos))
  2462. bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
  2463. else
  2464. bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
  2465. #endif /* CONFIG_P2P_MANAGER */
  2466. } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
  2467. bss->disassoc_low_ack = atoi(pos);
  2468. } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
  2469. int val = atoi(pos);
  2470. if (val)
  2471. bss->tdls |= TDLS_PROHIBIT;
  2472. else
  2473. bss->tdls &= ~TDLS_PROHIBIT;
  2474. } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
  2475. int val = atoi(pos);
  2476. if (val)
  2477. bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
  2478. else
  2479. bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
  2480. #ifdef CONFIG_RSN_TESTING
  2481. } else if (os_strcmp(buf, "rsn_testing") == 0) {
  2482. extern int rsn_testing;
  2483. rsn_testing = atoi(pos);
  2484. #endif /* CONFIG_RSN_TESTING */
  2485. } else if (os_strcmp(buf, "time_advertisement") == 0) {
  2486. bss->time_advertisement = atoi(pos);
  2487. } else if (os_strcmp(buf, "time_zone") == 0) {
  2488. size_t tz_len = os_strlen(pos);
  2489. if (tz_len < 4 || tz_len > 255) {
  2490. wpa_printf(MSG_DEBUG, "Line %d: invalid "
  2491. "time_zone", line);
  2492. errors++;
  2493. return errors;
  2494. }
  2495. os_free(bss->time_zone);
  2496. bss->time_zone = os_strdup(pos);
  2497. if (bss->time_zone == NULL)
  2498. errors++;
  2499. #ifdef CONFIG_WNM
  2500. } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
  2501. bss->wnm_sleep_mode = atoi(pos);
  2502. } else if (os_strcmp(buf, "bss_transition") == 0) {
  2503. bss->bss_transition = atoi(pos);
  2504. #endif /* CONFIG_WNM */
  2505. #ifdef CONFIG_INTERWORKING
  2506. } else if (os_strcmp(buf, "interworking") == 0) {
  2507. bss->interworking = atoi(pos);
  2508. } else if (os_strcmp(buf, "access_network_type") == 0) {
  2509. bss->access_network_type = atoi(pos);
  2510. if (bss->access_network_type < 0 ||
  2511. bss->access_network_type > 15) {
  2512. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2513. "access_network_type", line);
  2514. errors++;
  2515. }
  2516. } else if (os_strcmp(buf, "internet") == 0) {
  2517. bss->internet = atoi(pos);
  2518. } else if (os_strcmp(buf, "asra") == 0) {
  2519. bss->asra = atoi(pos);
  2520. } else if (os_strcmp(buf, "esr") == 0) {
  2521. bss->esr = atoi(pos);
  2522. } else if (os_strcmp(buf, "uesa") == 0) {
  2523. bss->uesa = atoi(pos);
  2524. } else if (os_strcmp(buf, "venue_group") == 0) {
  2525. bss->venue_group = atoi(pos);
  2526. bss->venue_info_set = 1;
  2527. } else if (os_strcmp(buf, "venue_type") == 0) {
  2528. bss->venue_type = atoi(pos);
  2529. bss->venue_info_set = 1;
  2530. } else if (os_strcmp(buf, "hessid") == 0) {
  2531. if (hwaddr_aton(pos, bss->hessid)) {
  2532. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2533. "hessid", line);
  2534. errors++;
  2535. }
  2536. } else if (os_strcmp(buf, "roaming_consortium") == 0) {
  2537. if (parse_roaming_consortium(bss, pos, line) < 0)
  2538. errors++;
  2539. } else if (os_strcmp(buf, "venue_name") == 0) {
  2540. if (parse_venue_name(bss, pos, line) < 0)
  2541. errors++;
  2542. } else if (os_strcmp(buf, "network_auth_type") == 0) {
  2543. u8 auth_type;
  2544. u16 redirect_url_len;
  2545. if (hexstr2bin(pos, &auth_type, 1)) {
  2546. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2547. "network_auth_type '%s'",
  2548. line, pos);
  2549. errors++;
  2550. return errors;
  2551. }
  2552. if (auth_type == 0 || auth_type == 2)
  2553. redirect_url_len = os_strlen(pos + 2);
  2554. else
  2555. redirect_url_len = 0;
  2556. os_free(bss->network_auth_type);
  2557. bss->network_auth_type =
  2558. os_malloc(redirect_url_len + 3 + 1);
  2559. if (bss->network_auth_type == NULL) {
  2560. errors++;
  2561. return errors;
  2562. }
  2563. *bss->network_auth_type = auth_type;
  2564. WPA_PUT_LE16(bss->network_auth_type + 1,
  2565. redirect_url_len);
  2566. if (redirect_url_len)
  2567. os_memcpy(bss->network_auth_type + 3,
  2568. pos + 2, redirect_url_len);
  2569. bss->network_auth_type_len = 3 + redirect_url_len;
  2570. } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
  2571. if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1))
  2572. {
  2573. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2574. "ipaddr_type_availability '%s'",
  2575. line, pos);
  2576. bss->ipaddr_type_configured = 0;
  2577. errors++;
  2578. return errors;
  2579. }
  2580. bss->ipaddr_type_configured = 1;
  2581. } else if (os_strcmp(buf, "domain_name") == 0) {
  2582. int j, num_domains, domain_len, domain_list_len = 0;
  2583. char *tok_start, *tok_prev;
  2584. u8 *domain_list, *domain_ptr;
  2585. domain_list_len = os_strlen(pos) + 1;
  2586. domain_list = os_malloc(domain_list_len);
  2587. if (domain_list == NULL) {
  2588. errors++;
  2589. return errors;
  2590. }
  2591. domain_ptr = domain_list;
  2592. tok_prev = pos;
  2593. num_domains = 1;
  2594. while ((tok_prev = os_strchr(tok_prev, ','))) {
  2595. num_domains++;
  2596. tok_prev++;
  2597. }
  2598. tok_prev = pos;
  2599. for (j = 0; j < num_domains; j++) {
  2600. tok_start = os_strchr(tok_prev, ',');
  2601. if (tok_start) {
  2602. domain_len = tok_start - tok_prev;
  2603. *domain_ptr = domain_len;
  2604. os_memcpy(domain_ptr + 1, tok_prev,
  2605. domain_len);
  2606. domain_ptr += domain_len + 1;
  2607. tok_prev = ++tok_start;
  2608. } else {
  2609. domain_len = os_strlen(tok_prev);
  2610. *domain_ptr = domain_len;
  2611. os_memcpy(domain_ptr + 1, tok_prev,
  2612. domain_len);
  2613. domain_ptr += domain_len + 1;
  2614. }
  2615. }
  2616. os_free(bss->domain_name);
  2617. bss->domain_name = domain_list;
  2618. bss->domain_name_len = domain_list_len;
  2619. } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
  2620. if (parse_3gpp_cell_net(bss, pos, line) < 0)
  2621. errors++;
  2622. } else if (os_strcmp(buf, "nai_realm") == 0) {
  2623. if (parse_nai_realm(bss, pos, line) < 0)
  2624. errors++;
  2625. } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
  2626. bss->gas_frag_limit = atoi(pos);
  2627. } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
  2628. bss->gas_comeback_delay = atoi(pos);
  2629. #endif /* CONFIG_INTERWORKING */
  2630. #ifdef CONFIG_RADIUS_TEST
  2631. } else if (os_strcmp(buf, "dump_msk_file") == 0) {
  2632. os_free(bss->dump_msk_file);
  2633. bss->dump_msk_file = os_strdup(pos);
  2634. #endif /* CONFIG_RADIUS_TEST */
  2635. #ifdef CONFIG_HS20
  2636. } else if (os_strcmp(buf, "hs20") == 0) {
  2637. bss->hs20 = atoi(pos);
  2638. } else if (os_strcmp(buf, "disable_dgaf") == 0) {
  2639. bss->disable_dgaf = atoi(pos);
  2640. } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
  2641. if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
  2642. errors++;
  2643. } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
  2644. if (hs20_parse_wan_metrics(bss, pos, line) < 0) {
  2645. errors++;
  2646. return errors;
  2647. }
  2648. } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
  2649. if (hs20_parse_conn_capab(bss, pos, line) < 0) {
  2650. errors++;
  2651. return errors;
  2652. }
  2653. } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
  2654. u8 *oper_class;
  2655. size_t oper_class_len;
  2656. oper_class_len = os_strlen(pos);
  2657. if (oper_class_len < 2 || (oper_class_len & 0x01)) {
  2658. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2659. "hs20_operating_class '%s'",
  2660. line, pos);
  2661. errors++;
  2662. return errors;
  2663. }
  2664. oper_class_len /= 2;
  2665. oper_class = os_malloc(oper_class_len);
  2666. if (oper_class == NULL) {
  2667. errors++;
  2668. return errors;
  2669. }
  2670. if (hexstr2bin(pos, oper_class, oper_class_len)) {
  2671. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2672. "hs20_operating_class '%s'",
  2673. line, pos);
  2674. os_free(oper_class);
  2675. errors++;
  2676. return errors;
  2677. }
  2678. os_free(bss->hs20_operating_class);
  2679. bss->hs20_operating_class = oper_class;
  2680. bss->hs20_operating_class_len = oper_class_len;
  2681. #endif /* CONFIG_HS20 */
  2682. #ifdef CONFIG_TESTING_OPTIONS
  2683. #define PARSE_TEST_PROBABILITY(_val) \
  2684. } else if (os_strcmp(buf, #_val) == 0) { \
  2685. char *end; \
  2686. \
  2687. conf->_val = strtod(pos, &end); \
  2688. if (*end || conf->_val < 0.0d || \
  2689. conf->_val > 1.0d) { \
  2690. wpa_printf(MSG_ERROR, \
  2691. "Line %d: Invalid value '%s'", \
  2692. line, pos); \
  2693. errors++; \
  2694. return errors; \
  2695. }
  2696. PARSE_TEST_PROBABILITY(ignore_probe_probability)
  2697. PARSE_TEST_PROBABILITY(ignore_auth_probability)
  2698. PARSE_TEST_PROBABILITY(ignore_assoc_probability)
  2699. PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
  2700. PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability)
  2701. #endif /* CONFIG_TESTING_OPTIONS */
  2702. } else if (os_strcmp(buf, "vendor_elements") == 0) {
  2703. struct wpabuf *elems;
  2704. size_t len = os_strlen(pos);
  2705. if (len & 0x01) {
  2706. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2707. "vendor_elements '%s'", line, pos);
  2708. return 1;
  2709. }
  2710. len /= 2;
  2711. if (len == 0) {
  2712. wpabuf_free(bss->vendor_elements);
  2713. bss->vendor_elements = NULL;
  2714. return 0;
  2715. }
  2716. elems = wpabuf_alloc(len);
  2717. if (elems == NULL)
  2718. return 1;
  2719. if (hexstr2bin(pos, wpabuf_put(elems, len), len)) {
  2720. wpabuf_free(elems);
  2721. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2722. "vendor_elements '%s'", line, pos);
  2723. return 1;
  2724. }
  2725. wpabuf_free(bss->vendor_elements);
  2726. bss->vendor_elements = elems;
  2727. } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0) {
  2728. bss->sae_anti_clogging_threshold = atoi(pos);
  2729. } else if (os_strcmp(buf, "sae_groups") == 0) {
  2730. if (hostapd_parse_intlist(&bss->sae_groups, pos)) {
  2731. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2732. "sae_groups value '%s'", line, pos);
  2733. return 1;
  2734. }
  2735. } else {
  2736. wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
  2737. "item '%s'", line, buf);
  2738. errors++;
  2739. }
  2740. }
  2741. return errors;
  2742. }
  2743. static void hostapd_set_security_params(struct hostapd_bss_config *bss)
  2744. {
  2745. if (bss->individual_wep_key_len == 0) {
  2746. /* individual keys are not use; can use key idx0 for
  2747. * broadcast keys */
  2748. bss->broadcast_key_idx_min = 0;
  2749. }
  2750. if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
  2751. bss->rsn_pairwise = bss->wpa_pairwise;
  2752. bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
  2753. bss->rsn_pairwise);
  2754. bss->radius->auth_server = bss->radius->auth_servers;
  2755. bss->radius->acct_server = bss->radius->acct_servers;
  2756. if (bss->wpa && bss->ieee802_1x) {
  2757. bss->ssid.security_policy = SECURITY_WPA;
  2758. } else if (bss->wpa) {
  2759. bss->ssid.security_policy = SECURITY_WPA_PSK;
  2760. } else if (bss->ieee802_1x) {
  2761. int cipher = WPA_CIPHER_NONE;
  2762. bss->ssid.security_policy = SECURITY_IEEE_802_1X;
  2763. bss->ssid.wep.default_len = bss->default_wep_key_len;
  2764. if (bss->default_wep_key_len)
  2765. cipher = bss->default_wep_key_len >= 13 ?
  2766. WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
  2767. bss->wpa_group = cipher;
  2768. bss->wpa_pairwise = cipher;
  2769. bss->rsn_pairwise = cipher;
  2770. } else if (bss->ssid.wep.keys_set) {
  2771. int cipher = WPA_CIPHER_WEP40;
  2772. if (bss->ssid.wep.len[0] >= 13)
  2773. cipher = WPA_CIPHER_WEP104;
  2774. bss->ssid.security_policy = SECURITY_STATIC_WEP;
  2775. bss->wpa_group = cipher;
  2776. bss->wpa_pairwise = cipher;
  2777. bss->rsn_pairwise = cipher;
  2778. } else {
  2779. bss->ssid.security_policy = SECURITY_PLAINTEXT;
  2780. bss->wpa_group = WPA_CIPHER_NONE;
  2781. bss->wpa_pairwise = WPA_CIPHER_NONE;
  2782. bss->rsn_pairwise = WPA_CIPHER_NONE;
  2783. }
  2784. }
  2785. /**
  2786. * hostapd_config_read - Read and parse a configuration file
  2787. * @fname: Configuration file name (including path, if needed)
  2788. * Returns: Allocated configuration data structure
  2789. */
  2790. struct hostapd_config * hostapd_config_read(const char *fname)
  2791. {
  2792. struct hostapd_config *conf;
  2793. struct hostapd_bss_config *bss;
  2794. FILE *f;
  2795. char buf[512], *pos;
  2796. int line = 0;
  2797. int errors = 0;
  2798. size_t i;
  2799. f = fopen(fname, "r");
  2800. if (f == NULL) {
  2801. wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
  2802. "for reading.", fname);
  2803. return NULL;
  2804. }
  2805. conf = hostapd_config_defaults();
  2806. if (conf == NULL) {
  2807. fclose(f);
  2808. return NULL;
  2809. }
  2810. /* set default driver based on configuration */
  2811. conf->driver = wpa_drivers[0];
  2812. if (conf->driver == NULL) {
  2813. wpa_printf(MSG_ERROR, "No driver wrappers registered!");
  2814. hostapd_config_free(conf);
  2815. fclose(f);
  2816. return NULL;
  2817. }
  2818. bss = conf->last_bss = conf->bss;
  2819. while (fgets(buf, sizeof(buf), f)) {
  2820. bss = conf->last_bss;
  2821. line++;
  2822. if (buf[0] == '#')
  2823. continue;
  2824. pos = buf;
  2825. while (*pos != '\0') {
  2826. if (*pos == '\n') {
  2827. *pos = '\0';
  2828. break;
  2829. }
  2830. pos++;
  2831. }
  2832. if (buf[0] == '\0')
  2833. continue;
  2834. pos = os_strchr(buf, '=');
  2835. if (pos == NULL) {
  2836. wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
  2837. line, buf);
  2838. errors++;
  2839. continue;
  2840. }
  2841. *pos = '\0';
  2842. pos++;
  2843. errors += hostapd_config_fill(conf, bss, buf, pos, line);
  2844. }
  2845. fclose(f);
  2846. for (i = 0; i < conf->num_bss; i++)
  2847. hostapd_set_security_params(&conf->bss[i]);
  2848. if (hostapd_config_check(conf))
  2849. errors++;
  2850. #ifndef WPA_IGNORE_CONFIG_ERRORS
  2851. if (errors) {
  2852. wpa_printf(MSG_ERROR, "%d errors found in configuration file "
  2853. "'%s'", errors, fname);
  2854. hostapd_config_free(conf);
  2855. conf = NULL;
  2856. }
  2857. #endif /* WPA_IGNORE_CONFIG_ERRORS */
  2858. return conf;
  2859. }
  2860. int hostapd_set_iface(struct hostapd_config *conf,
  2861. struct hostapd_bss_config *bss, char *field, char *value)
  2862. {
  2863. int errors;
  2864. size_t i;
  2865. errors = hostapd_config_fill(conf, bss, field, value, 0);
  2866. if (errors) {
  2867. wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
  2868. "to value '%s'", field, value);
  2869. return -1;
  2870. }
  2871. for (i = 0; i < conf->num_bss; i++)
  2872. hostapd_set_security_params(&conf->bss[i]);
  2873. if (hostapd_config_check(conf)) {
  2874. wpa_printf(MSG_ERROR, "Configuration check failed");
  2875. return -1;
  2876. }
  2877. return 0;
  2878. }