config_file.c 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546
  1. /*
  2. * hostapd / Configuration file parser
  3. * Copyright (c) 2003-2012, 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_malloc(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. os_memset(vlan, 0, sizeof(*vlan));
  82. vlan->vlan_id = vlan_id;
  83. os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
  84. if (bss->vlan_tail)
  85. bss->vlan_tail->next = vlan;
  86. else
  87. bss->vlan = vlan;
  88. bss->vlan_tail = vlan;
  89. }
  90. fclose(f);
  91. return 0;
  92. }
  93. #endif /* CONFIG_NO_VLAN */
  94. static int hostapd_acl_comp(const void *a, const void *b)
  95. {
  96. const struct mac_acl_entry *aa = a;
  97. const struct mac_acl_entry *bb = b;
  98. return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
  99. }
  100. static int hostapd_config_read_maclist(const char *fname,
  101. struct mac_acl_entry **acl, int *num)
  102. {
  103. FILE *f;
  104. char buf[128], *pos;
  105. int line = 0;
  106. u8 addr[ETH_ALEN];
  107. struct mac_acl_entry *newacl;
  108. int vlan_id;
  109. if (!fname)
  110. return 0;
  111. f = fopen(fname, "r");
  112. if (!f) {
  113. wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
  114. return -1;
  115. }
  116. while (fgets(buf, sizeof(buf), f)) {
  117. line++;
  118. if (buf[0] == '#')
  119. continue;
  120. pos = buf;
  121. while (*pos != '\0') {
  122. if (*pos == '\n') {
  123. *pos = '\0';
  124. break;
  125. }
  126. pos++;
  127. }
  128. if (buf[0] == '\0')
  129. continue;
  130. if (hwaddr_aton(buf, addr)) {
  131. wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
  132. "line %d in '%s'", buf, line, fname);
  133. fclose(f);
  134. return -1;
  135. }
  136. vlan_id = 0;
  137. pos = buf;
  138. while (*pos != '\0' && *pos != ' ' && *pos != '\t')
  139. pos++;
  140. while (*pos == ' ' || *pos == '\t')
  141. pos++;
  142. if (*pos != '\0')
  143. vlan_id = atoi(pos);
  144. newacl = os_realloc(*acl, (*num + 1) * sizeof(**acl));
  145. if (newacl == NULL) {
  146. wpa_printf(MSG_ERROR, "MAC list reallocation failed");
  147. fclose(f);
  148. return -1;
  149. }
  150. *acl = newacl;
  151. os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
  152. (*acl)[*num].vlan_id = vlan_id;
  153. (*num)++;
  154. }
  155. fclose(f);
  156. qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
  157. return 0;
  158. }
  159. #ifdef EAP_SERVER
  160. static int hostapd_config_read_eap_user(const char *fname,
  161. struct hostapd_bss_config *conf)
  162. {
  163. FILE *f;
  164. char buf[512], *pos, *start, *pos2;
  165. int line = 0, ret = 0, num_methods;
  166. struct hostapd_eap_user *user, *tail = NULL;
  167. if (!fname)
  168. return 0;
  169. f = fopen(fname, "r");
  170. if (!f) {
  171. wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
  172. return -1;
  173. }
  174. /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
  175. while (fgets(buf, sizeof(buf), f)) {
  176. line++;
  177. if (buf[0] == '#')
  178. continue;
  179. pos = buf;
  180. while (*pos != '\0') {
  181. if (*pos == '\n') {
  182. *pos = '\0';
  183. break;
  184. }
  185. pos++;
  186. }
  187. if (buf[0] == '\0')
  188. continue;
  189. user = NULL;
  190. if (buf[0] != '"' && buf[0] != '*') {
  191. wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
  192. "start) on line %d in '%s'", line, fname);
  193. goto failed;
  194. }
  195. user = os_zalloc(sizeof(*user));
  196. if (user == NULL) {
  197. wpa_printf(MSG_ERROR, "EAP user allocation failed");
  198. goto failed;
  199. }
  200. user->force_version = -1;
  201. if (buf[0] == '*') {
  202. pos = buf;
  203. } else {
  204. pos = buf + 1;
  205. start = pos;
  206. while (*pos != '"' && *pos != '\0')
  207. pos++;
  208. if (*pos == '\0') {
  209. wpa_printf(MSG_ERROR, "Invalid EAP identity "
  210. "(no \" in end) on line %d in '%s'",
  211. line, fname);
  212. goto failed;
  213. }
  214. user->identity = os_malloc(pos - start);
  215. if (user->identity == NULL) {
  216. wpa_printf(MSG_ERROR, "Failed to allocate "
  217. "memory for EAP identity");
  218. goto failed;
  219. }
  220. os_memcpy(user->identity, start, pos - start);
  221. user->identity_len = pos - start;
  222. if (pos[0] == '"' && pos[1] == '*') {
  223. user->wildcard_prefix = 1;
  224. pos++;
  225. }
  226. }
  227. pos++;
  228. while (*pos == ' ' || *pos == '\t')
  229. pos++;
  230. if (*pos == '\0') {
  231. wpa_printf(MSG_ERROR, "No EAP method on line %d in "
  232. "'%s'", line, fname);
  233. goto failed;
  234. }
  235. start = pos;
  236. while (*pos != ' ' && *pos != '\t' && *pos != '\0')
  237. pos++;
  238. if (*pos == '\0') {
  239. pos = NULL;
  240. } else {
  241. *pos = '\0';
  242. pos++;
  243. }
  244. num_methods = 0;
  245. while (*start) {
  246. char *pos3 = os_strchr(start, ',');
  247. if (pos3) {
  248. *pos3++ = '\0';
  249. }
  250. user->methods[num_methods].method =
  251. eap_server_get_type(
  252. start,
  253. &user->methods[num_methods].vendor);
  254. if (user->methods[num_methods].vendor ==
  255. EAP_VENDOR_IETF &&
  256. user->methods[num_methods].method == EAP_TYPE_NONE)
  257. {
  258. if (os_strcmp(start, "TTLS-PAP") == 0) {
  259. user->ttls_auth |= EAP_TTLS_AUTH_PAP;
  260. goto skip_eap;
  261. }
  262. if (os_strcmp(start, "TTLS-CHAP") == 0) {
  263. user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
  264. goto skip_eap;
  265. }
  266. if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
  267. user->ttls_auth |=
  268. EAP_TTLS_AUTH_MSCHAP;
  269. goto skip_eap;
  270. }
  271. if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
  272. user->ttls_auth |=
  273. EAP_TTLS_AUTH_MSCHAPV2;
  274. goto skip_eap;
  275. }
  276. wpa_printf(MSG_ERROR, "Unsupported EAP type "
  277. "'%s' on line %d in '%s'",
  278. start, line, fname);
  279. goto failed;
  280. }
  281. num_methods++;
  282. if (num_methods >= EAP_MAX_METHODS)
  283. break;
  284. skip_eap:
  285. if (pos3 == NULL)
  286. break;
  287. start = pos3;
  288. }
  289. if (num_methods == 0 && user->ttls_auth == 0) {
  290. wpa_printf(MSG_ERROR, "No EAP types configured on "
  291. "line %d in '%s'", line, fname);
  292. goto failed;
  293. }
  294. if (pos == NULL)
  295. goto done;
  296. while (*pos == ' ' || *pos == '\t')
  297. pos++;
  298. if (*pos == '\0')
  299. goto done;
  300. if (os_strncmp(pos, "[ver=0]", 7) == 0) {
  301. user->force_version = 0;
  302. goto done;
  303. }
  304. if (os_strncmp(pos, "[ver=1]", 7) == 0) {
  305. user->force_version = 1;
  306. goto done;
  307. }
  308. if (os_strncmp(pos, "[2]", 3) == 0) {
  309. user->phase2 = 1;
  310. goto done;
  311. }
  312. if (*pos == '"') {
  313. pos++;
  314. start = pos;
  315. while (*pos != '"' && *pos != '\0')
  316. pos++;
  317. if (*pos == '\0') {
  318. wpa_printf(MSG_ERROR, "Invalid EAP password "
  319. "(no \" in end) on line %d in '%s'",
  320. line, fname);
  321. goto failed;
  322. }
  323. user->password = os_malloc(pos - start);
  324. if (user->password == NULL) {
  325. wpa_printf(MSG_ERROR, "Failed to allocate "
  326. "memory for EAP password");
  327. goto failed;
  328. }
  329. os_memcpy(user->password, start, pos - start);
  330. user->password_len = pos - start;
  331. pos++;
  332. } else if (os_strncmp(pos, "hash:", 5) == 0) {
  333. pos += 5;
  334. pos2 = pos;
  335. while (*pos2 != '\0' && *pos2 != ' ' &&
  336. *pos2 != '\t' && *pos2 != '#')
  337. pos2++;
  338. if (pos2 - pos != 32) {
  339. wpa_printf(MSG_ERROR, "Invalid password hash "
  340. "on line %d in '%s'", line, fname);
  341. goto failed;
  342. }
  343. user->password = os_malloc(16);
  344. if (user->password == NULL) {
  345. wpa_printf(MSG_ERROR, "Failed to allocate "
  346. "memory for EAP password hash");
  347. goto failed;
  348. }
  349. if (hexstr2bin(pos, user->password, 16) < 0) {
  350. wpa_printf(MSG_ERROR, "Invalid hash password "
  351. "on line %d in '%s'", line, fname);
  352. goto failed;
  353. }
  354. user->password_len = 16;
  355. user->password_hash = 1;
  356. pos = pos2;
  357. } else {
  358. pos2 = pos;
  359. while (*pos2 != '\0' && *pos2 != ' ' &&
  360. *pos2 != '\t' && *pos2 != '#')
  361. pos2++;
  362. if ((pos2 - pos) & 1) {
  363. wpa_printf(MSG_ERROR, "Invalid hex password "
  364. "on line %d in '%s'", line, fname);
  365. goto failed;
  366. }
  367. user->password = os_malloc((pos2 - pos) / 2);
  368. if (user->password == NULL) {
  369. wpa_printf(MSG_ERROR, "Failed to allocate "
  370. "memory for EAP password");
  371. goto failed;
  372. }
  373. if (hexstr2bin(pos, user->password,
  374. (pos2 - pos) / 2) < 0) {
  375. wpa_printf(MSG_ERROR, "Invalid hex password "
  376. "on line %d in '%s'", line, fname);
  377. goto failed;
  378. }
  379. user->password_len = (pos2 - pos) / 2;
  380. pos = pos2;
  381. }
  382. while (*pos == ' ' || *pos == '\t')
  383. pos++;
  384. if (os_strncmp(pos, "[2]", 3) == 0) {
  385. user->phase2 = 1;
  386. }
  387. done:
  388. if (tail == NULL) {
  389. tail = conf->eap_user = user;
  390. } else {
  391. tail->next = user;
  392. tail = user;
  393. }
  394. continue;
  395. failed:
  396. if (user) {
  397. os_free(user->password);
  398. os_free(user->identity);
  399. os_free(user);
  400. }
  401. ret = -1;
  402. break;
  403. }
  404. fclose(f);
  405. return ret;
  406. }
  407. #endif /* EAP_SERVER */
  408. #ifndef CONFIG_NO_RADIUS
  409. static int
  410. hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
  411. int *num_server, const char *val, int def_port,
  412. struct hostapd_radius_server **curr_serv)
  413. {
  414. struct hostapd_radius_server *nserv;
  415. int ret;
  416. static int server_index = 1;
  417. nserv = os_realloc(*server, (*num_server + 1) * sizeof(*nserv));
  418. if (nserv == NULL)
  419. return -1;
  420. *server = nserv;
  421. nserv = &nserv[*num_server];
  422. (*num_server)++;
  423. (*curr_serv) = nserv;
  424. os_memset(nserv, 0, sizeof(*nserv));
  425. nserv->port = def_port;
  426. ret = hostapd_parse_ip_addr(val, &nserv->addr);
  427. nserv->index = server_index++;
  428. return ret;
  429. }
  430. static struct hostapd_radius_attr *
  431. hostapd_parse_radius_attr(const char *value)
  432. {
  433. const char *pos;
  434. char syntax;
  435. struct hostapd_radius_attr *attr;
  436. size_t len;
  437. attr = os_zalloc(sizeof(*attr));
  438. if (attr == NULL)
  439. return NULL;
  440. attr->type = atoi(value);
  441. pos = os_strchr(value, ':');
  442. if (pos == NULL) {
  443. attr->val = wpabuf_alloc(1);
  444. if (attr->val == NULL) {
  445. os_free(attr);
  446. return NULL;
  447. }
  448. wpabuf_put_u8(attr->val, 0);
  449. return attr;
  450. }
  451. pos++;
  452. if (pos[0] == '\0' || pos[1] != ':') {
  453. os_free(attr);
  454. return NULL;
  455. }
  456. syntax = *pos++;
  457. pos++;
  458. switch (syntax) {
  459. case 's':
  460. attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
  461. break;
  462. case 'x':
  463. len = os_strlen(pos);
  464. if (len & 1)
  465. break;
  466. len /= 2;
  467. attr->val = wpabuf_alloc(len);
  468. if (attr->val == NULL)
  469. break;
  470. if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
  471. wpabuf_free(attr->val);
  472. os_free(attr);
  473. return NULL;
  474. }
  475. break;
  476. case 'd':
  477. attr->val = wpabuf_alloc(4);
  478. if (attr->val)
  479. wpabuf_put_be32(attr->val, atoi(pos));
  480. break;
  481. default:
  482. os_free(attr);
  483. return NULL;
  484. }
  485. if (attr->val == NULL) {
  486. os_free(attr);
  487. return NULL;
  488. }
  489. return attr;
  490. }
  491. static int hostapd_parse_das_client(struct hostapd_bss_config *bss,
  492. const char *val)
  493. {
  494. char *secret;
  495. size_t len;
  496. secret = os_strchr(val, ' ');
  497. if (secret == NULL)
  498. return -1;
  499. secret++;
  500. len = os_strlen(secret);
  501. if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr))
  502. return -1;
  503. os_free(bss->radius_das_shared_secret);
  504. bss->radius_das_shared_secret = os_malloc(len);
  505. if (bss->radius_das_shared_secret == NULL)
  506. return -1;
  507. os_memcpy(bss->radius_das_shared_secret, secret, len);
  508. bss->radius_das_shared_secret_len = len;
  509. return 0;
  510. }
  511. #endif /* CONFIG_NO_RADIUS */
  512. static int hostapd_config_parse_key_mgmt(int line, const char *value)
  513. {
  514. int val = 0, last;
  515. char *start, *end, *buf;
  516. buf = os_strdup(value);
  517. if (buf == NULL)
  518. return -1;
  519. start = buf;
  520. while (*start != '\0') {
  521. while (*start == ' ' || *start == '\t')
  522. start++;
  523. if (*start == '\0')
  524. break;
  525. end = start;
  526. while (*end != ' ' && *end != '\t' && *end != '\0')
  527. end++;
  528. last = *end == '\0';
  529. *end = '\0';
  530. if (os_strcmp(start, "WPA-PSK") == 0)
  531. val |= WPA_KEY_MGMT_PSK;
  532. else if (os_strcmp(start, "WPA-EAP") == 0)
  533. val |= WPA_KEY_MGMT_IEEE8021X;
  534. #ifdef CONFIG_IEEE80211R
  535. else if (os_strcmp(start, "FT-PSK") == 0)
  536. val |= WPA_KEY_MGMT_FT_PSK;
  537. else if (os_strcmp(start, "FT-EAP") == 0)
  538. val |= WPA_KEY_MGMT_FT_IEEE8021X;
  539. #endif /* CONFIG_IEEE80211R */
  540. #ifdef CONFIG_IEEE80211W
  541. else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
  542. val |= WPA_KEY_MGMT_PSK_SHA256;
  543. else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
  544. val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
  545. #endif /* CONFIG_IEEE80211W */
  546. else {
  547. wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
  548. line, start);
  549. os_free(buf);
  550. return -1;
  551. }
  552. if (last)
  553. break;
  554. start = end + 1;
  555. }
  556. os_free(buf);
  557. if (val == 0) {
  558. wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
  559. "configured.", line);
  560. return -1;
  561. }
  562. return val;
  563. }
  564. static int hostapd_config_parse_cipher(int line, const char *value)
  565. {
  566. int val = 0, last;
  567. char *start, *end, *buf;
  568. buf = os_strdup(value);
  569. if (buf == NULL)
  570. return -1;
  571. start = buf;
  572. while (*start != '\0') {
  573. while (*start == ' ' || *start == '\t')
  574. start++;
  575. if (*start == '\0')
  576. break;
  577. end = start;
  578. while (*end != ' ' && *end != '\t' && *end != '\0')
  579. end++;
  580. last = *end == '\0';
  581. *end = '\0';
  582. if (os_strcmp(start, "CCMP") == 0)
  583. val |= WPA_CIPHER_CCMP;
  584. else if (os_strcmp(start, "TKIP") == 0)
  585. val |= WPA_CIPHER_TKIP;
  586. else if (os_strcmp(start, "WEP104") == 0)
  587. val |= WPA_CIPHER_WEP104;
  588. else if (os_strcmp(start, "WEP40") == 0)
  589. val |= WPA_CIPHER_WEP40;
  590. else if (os_strcmp(start, "NONE") == 0)
  591. val |= WPA_CIPHER_NONE;
  592. else {
  593. wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
  594. line, start);
  595. os_free(buf);
  596. return -1;
  597. }
  598. if (last)
  599. break;
  600. start = end + 1;
  601. }
  602. os_free(buf);
  603. if (val == 0) {
  604. wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
  605. line);
  606. return -1;
  607. }
  608. return val;
  609. }
  610. static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
  611. char *val)
  612. {
  613. size_t len = os_strlen(val);
  614. if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
  615. return -1;
  616. if (val[0] == '"') {
  617. if (len < 2 || val[len - 1] != '"')
  618. return -1;
  619. len -= 2;
  620. wep->key[keyidx] = os_malloc(len);
  621. if (wep->key[keyidx] == NULL)
  622. return -1;
  623. os_memcpy(wep->key[keyidx], val + 1, len);
  624. wep->len[keyidx] = len;
  625. } else {
  626. if (len & 1)
  627. return -1;
  628. len /= 2;
  629. wep->key[keyidx] = os_malloc(len);
  630. if (wep->key[keyidx] == NULL)
  631. return -1;
  632. wep->len[keyidx] = len;
  633. if (hexstr2bin(val, wep->key[keyidx], len) < 0)
  634. return -1;
  635. }
  636. wep->keys_set++;
  637. return 0;
  638. }
  639. static int hostapd_parse_rates(int **rate_list, char *val)
  640. {
  641. int *list;
  642. int count;
  643. char *pos, *end;
  644. os_free(*rate_list);
  645. *rate_list = NULL;
  646. pos = val;
  647. count = 0;
  648. while (*pos != '\0') {
  649. if (*pos == ' ')
  650. count++;
  651. pos++;
  652. }
  653. list = os_malloc(sizeof(int) * (count + 2));
  654. if (list == NULL)
  655. return -1;
  656. pos = val;
  657. count = 0;
  658. while (*pos != '\0') {
  659. end = os_strchr(pos, ' ');
  660. if (end)
  661. *end = '\0';
  662. list[count++] = atoi(pos);
  663. if (!end)
  664. break;
  665. pos = end + 1;
  666. }
  667. list[count] = -1;
  668. *rate_list = list;
  669. return 0;
  670. }
  671. static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
  672. {
  673. struct hostapd_bss_config *bss;
  674. if (*ifname == '\0')
  675. return -1;
  676. bss = os_realloc(conf->bss, (conf->num_bss + 1) *
  677. sizeof(struct hostapd_bss_config));
  678. if (bss == NULL) {
  679. wpa_printf(MSG_ERROR, "Failed to allocate memory for "
  680. "multi-BSS entry");
  681. return -1;
  682. }
  683. conf->bss = bss;
  684. bss = &(conf->bss[conf->num_bss]);
  685. os_memset(bss, 0, sizeof(*bss));
  686. bss->radius = os_zalloc(sizeof(*bss->radius));
  687. if (bss->radius == NULL) {
  688. wpa_printf(MSG_ERROR, "Failed to allocate memory for "
  689. "multi-BSS RADIUS data");
  690. return -1;
  691. }
  692. conf->num_bss++;
  693. conf->last_bss = bss;
  694. hostapd_config_defaults_bss(bss);
  695. os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
  696. os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
  697. return 0;
  698. }
  699. /* convert floats with one decimal place to value*10 int, i.e.,
  700. * "1.5" will return 15 */
  701. static int hostapd_config_read_int10(const char *value)
  702. {
  703. int i, d;
  704. char *pos;
  705. i = atoi(value);
  706. pos = os_strchr(value, '.');
  707. d = 0;
  708. if (pos) {
  709. pos++;
  710. if (*pos >= '0' && *pos <= '9')
  711. d = *pos - '0';
  712. }
  713. return i * 10 + d;
  714. }
  715. static int valid_cw(int cw)
  716. {
  717. return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
  718. cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
  719. }
  720. enum {
  721. IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
  722. IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
  723. IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
  724. IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */
  725. };
  726. static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
  727. char *val)
  728. {
  729. int num;
  730. char *pos;
  731. struct hostapd_tx_queue_params *queue;
  732. /* skip 'tx_queue_' prefix */
  733. pos = name + 9;
  734. if (os_strncmp(pos, "data", 4) == 0 &&
  735. pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
  736. num = pos[4] - '0';
  737. pos += 6;
  738. } else if (os_strncmp(pos, "after_beacon_", 13) == 0 ||
  739. os_strncmp(pos, "beacon_", 7) == 0) {
  740. wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
  741. return 0;
  742. } else {
  743. wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
  744. return -1;
  745. }
  746. if (num >= NUM_TX_QUEUES) {
  747. /* for backwards compatibility, do not trigger failure */
  748. wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
  749. return 0;
  750. }
  751. queue = &conf->tx_queue[num];
  752. if (os_strcmp(pos, "aifs") == 0) {
  753. queue->aifs = atoi(val);
  754. if (queue->aifs < 0 || queue->aifs > 255) {
  755. wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
  756. queue->aifs);
  757. return -1;
  758. }
  759. } else if (os_strcmp(pos, "cwmin") == 0) {
  760. queue->cwmin = atoi(val);
  761. if (!valid_cw(queue->cwmin)) {
  762. wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
  763. queue->cwmin);
  764. return -1;
  765. }
  766. } else if (os_strcmp(pos, "cwmax") == 0) {
  767. queue->cwmax = atoi(val);
  768. if (!valid_cw(queue->cwmax)) {
  769. wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
  770. queue->cwmax);
  771. return -1;
  772. }
  773. } else if (os_strcmp(pos, "burst") == 0) {
  774. queue->burst = hostapd_config_read_int10(val);
  775. } else {
  776. wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
  777. return -1;
  778. }
  779. return 0;
  780. }
  781. static int hostapd_config_wmm_ac(struct hostapd_config *conf, char *name,
  782. char *val)
  783. {
  784. int num, v;
  785. char *pos;
  786. struct hostapd_wmm_ac_params *ac;
  787. /* skip 'wme_ac_' or 'wmm_ac_' prefix */
  788. pos = name + 7;
  789. if (os_strncmp(pos, "be_", 3) == 0) {
  790. num = 0;
  791. pos += 3;
  792. } else if (os_strncmp(pos, "bk_", 3) == 0) {
  793. num = 1;
  794. pos += 3;
  795. } else if (os_strncmp(pos, "vi_", 3) == 0) {
  796. num = 2;
  797. pos += 3;
  798. } else if (os_strncmp(pos, "vo_", 3) == 0) {
  799. num = 3;
  800. pos += 3;
  801. } else {
  802. wpa_printf(MSG_ERROR, "Unknown WMM name '%s'", pos);
  803. return -1;
  804. }
  805. ac = &conf->wmm_ac_params[num];
  806. if (os_strcmp(pos, "aifs") == 0) {
  807. v = atoi(val);
  808. if (v < 1 || v > 255) {
  809. wpa_printf(MSG_ERROR, "Invalid AIFS value %d", v);
  810. return -1;
  811. }
  812. ac->aifs = v;
  813. } else if (os_strcmp(pos, "cwmin") == 0) {
  814. v = atoi(val);
  815. if (v < 0 || v > 12) {
  816. wpa_printf(MSG_ERROR, "Invalid cwMin value %d", v);
  817. return -1;
  818. }
  819. ac->cwmin = v;
  820. } else if (os_strcmp(pos, "cwmax") == 0) {
  821. v = atoi(val);
  822. if (v < 0 || v > 12) {
  823. wpa_printf(MSG_ERROR, "Invalid cwMax value %d", v);
  824. return -1;
  825. }
  826. ac->cwmax = v;
  827. } else if (os_strcmp(pos, "txop_limit") == 0) {
  828. v = atoi(val);
  829. if (v < 0 || v > 0xffff) {
  830. wpa_printf(MSG_ERROR, "Invalid txop value %d", v);
  831. return -1;
  832. }
  833. ac->txop_limit = v;
  834. } else if (os_strcmp(pos, "acm") == 0) {
  835. v = atoi(val);
  836. if (v < 0 || v > 1) {
  837. wpa_printf(MSG_ERROR, "Invalid acm value %d", v);
  838. return -1;
  839. }
  840. ac->admission_control_mandatory = v;
  841. } else {
  842. wpa_printf(MSG_ERROR, "Unknown wmm_ac_ field '%s'", pos);
  843. return -1;
  844. }
  845. return 0;
  846. }
  847. #ifdef CONFIG_IEEE80211R
  848. static int add_r0kh(struct hostapd_bss_config *bss, char *value)
  849. {
  850. struct ft_remote_r0kh *r0kh;
  851. char *pos, *next;
  852. r0kh = os_zalloc(sizeof(*r0kh));
  853. if (r0kh == NULL)
  854. return -1;
  855. /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
  856. pos = value;
  857. next = os_strchr(pos, ' ');
  858. if (next)
  859. *next++ = '\0';
  860. if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
  861. wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
  862. os_free(r0kh);
  863. return -1;
  864. }
  865. pos = next;
  866. next = os_strchr(pos, ' ');
  867. if (next)
  868. *next++ = '\0';
  869. if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
  870. wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
  871. os_free(r0kh);
  872. return -1;
  873. }
  874. r0kh->id_len = next - pos - 1;
  875. os_memcpy(r0kh->id, pos, r0kh->id_len);
  876. pos = next;
  877. if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
  878. wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
  879. os_free(r0kh);
  880. return -1;
  881. }
  882. r0kh->next = bss->r0kh_list;
  883. bss->r0kh_list = r0kh;
  884. return 0;
  885. }
  886. static int add_r1kh(struct hostapd_bss_config *bss, char *value)
  887. {
  888. struct ft_remote_r1kh *r1kh;
  889. char *pos, *next;
  890. r1kh = os_zalloc(sizeof(*r1kh));
  891. if (r1kh == NULL)
  892. return -1;
  893. /* 02:01:02:03:04:05 02:01:02:03:04:05
  894. * 000102030405060708090a0b0c0d0e0f */
  895. pos = value;
  896. next = os_strchr(pos, ' ');
  897. if (next)
  898. *next++ = '\0';
  899. if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
  900. wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
  901. os_free(r1kh);
  902. return -1;
  903. }
  904. pos = next;
  905. next = os_strchr(pos, ' ');
  906. if (next)
  907. *next++ = '\0';
  908. if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
  909. wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
  910. os_free(r1kh);
  911. return -1;
  912. }
  913. pos = next;
  914. if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
  915. wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
  916. os_free(r1kh);
  917. return -1;
  918. }
  919. r1kh->next = bss->r1kh_list;
  920. bss->r1kh_list = r1kh;
  921. return 0;
  922. }
  923. #endif /* CONFIG_IEEE80211R */
  924. #ifdef CONFIG_IEEE80211N
  925. static int hostapd_config_ht_capab(struct hostapd_config *conf,
  926. const char *capab)
  927. {
  928. if (os_strstr(capab, "[LDPC]"))
  929. conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
  930. if (os_strstr(capab, "[HT40-]")) {
  931. conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
  932. conf->secondary_channel = -1;
  933. }
  934. if (os_strstr(capab, "[HT40+]")) {
  935. conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
  936. conf->secondary_channel = 1;
  937. }
  938. if (os_strstr(capab, "[SMPS-STATIC]")) {
  939. conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
  940. conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
  941. }
  942. if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
  943. conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
  944. conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
  945. }
  946. if (os_strstr(capab, "[GF]"))
  947. conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
  948. if (os_strstr(capab, "[SHORT-GI-20]"))
  949. conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
  950. if (os_strstr(capab, "[SHORT-GI-40]"))
  951. conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
  952. if (os_strstr(capab, "[TX-STBC]"))
  953. conf->ht_capab |= HT_CAP_INFO_TX_STBC;
  954. if (os_strstr(capab, "[RX-STBC1]")) {
  955. conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
  956. conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
  957. }
  958. if (os_strstr(capab, "[RX-STBC12]")) {
  959. conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
  960. conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
  961. }
  962. if (os_strstr(capab, "[RX-STBC123]")) {
  963. conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
  964. conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
  965. }
  966. if (os_strstr(capab, "[DELAYED-BA]"))
  967. conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
  968. if (os_strstr(capab, "[MAX-AMSDU-7935]"))
  969. conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
  970. if (os_strstr(capab, "[DSSS_CCK-40]"))
  971. conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
  972. if (os_strstr(capab, "[PSMP]"))
  973. conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP;
  974. if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
  975. conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
  976. return 0;
  977. }
  978. #endif /* CONFIG_IEEE80211N */
  979. static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
  980. struct hostapd_config *conf)
  981. {
  982. if (bss->ieee802_1x && !bss->eap_server &&
  983. !bss->radius->auth_servers) {
  984. wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
  985. "EAP authenticator configured).");
  986. return -1;
  987. }
  988. if (bss->wpa && bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
  989. bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
  990. wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
  991. "RADIUS checking (macaddr_acl=2) enabled.");
  992. return -1;
  993. }
  994. if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
  995. bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
  996. bss->ssid.wpa_psk_file == NULL &&
  997. (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
  998. bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
  999. wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
  1000. "is not configured.");
  1001. return -1;
  1002. }
  1003. if (hostapd_mac_comp_empty(bss->bssid) != 0) {
  1004. size_t i;
  1005. for (i = 0; i < conf->num_bss; i++) {
  1006. if ((&conf->bss[i] != bss) &&
  1007. (hostapd_mac_comp(conf->bss[i].bssid,
  1008. bss->bssid) == 0)) {
  1009. wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
  1010. " on interface '%s' and '%s'.",
  1011. MAC2STR(bss->bssid),
  1012. conf->bss[i].iface, bss->iface);
  1013. return -1;
  1014. }
  1015. }
  1016. }
  1017. #ifdef CONFIG_IEEE80211R
  1018. if (wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
  1019. (bss->nas_identifier == NULL ||
  1020. os_strlen(bss->nas_identifier) < 1 ||
  1021. os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
  1022. wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
  1023. "nas_identifier to be configured as a 1..48 octet "
  1024. "string");
  1025. return -1;
  1026. }
  1027. #endif /* CONFIG_IEEE80211R */
  1028. #ifdef CONFIG_IEEE80211N
  1029. if (conf->ieee80211n && conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
  1030. bss->disable_11n = 1;
  1031. wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
  1032. "allowed, disabling HT capabilites");
  1033. }
  1034. if (conf->ieee80211n &&
  1035. bss->ssid.security_policy == SECURITY_STATIC_WEP) {
  1036. bss->disable_11n = 1;
  1037. wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
  1038. "allowed, disabling HT capabilities");
  1039. }
  1040. if (conf->ieee80211n && bss->wpa &&
  1041. !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
  1042. !(bss->rsn_pairwise & WPA_CIPHER_CCMP)) {
  1043. bss->disable_11n = 1;
  1044. wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
  1045. "requires CCMP to be enabled, disabling HT "
  1046. "capabilities");
  1047. }
  1048. #endif /* CONFIG_IEEE80211N */
  1049. #ifdef CONFIG_WPS2
  1050. if (bss->wps_state && bss->ignore_broadcast_ssid) {
  1051. wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
  1052. "configuration forced WPS to be disabled");
  1053. bss->wps_state = 0;
  1054. }
  1055. if (bss->wps_state && bss->ssid.wep.keys_set && bss->wpa == 0) {
  1056. wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
  1057. "disabled");
  1058. bss->wps_state = 0;
  1059. }
  1060. #endif /* CONFIG_WPS2 */
  1061. return 0;
  1062. }
  1063. static int hostapd_config_check(struct hostapd_config *conf)
  1064. {
  1065. size_t i;
  1066. if (conf->ieee80211d && (!conf->country[0] || !conf->country[1])) {
  1067. wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
  1068. "setting the country_code");
  1069. return -1;
  1070. }
  1071. for (i = 0; i < conf->num_bss; i++) {
  1072. if (hostapd_config_check_bss(&conf->bss[i], conf))
  1073. return -1;
  1074. }
  1075. return 0;
  1076. }
  1077. #ifdef CONFIG_INTERWORKING
  1078. static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
  1079. int line)
  1080. {
  1081. size_t len = os_strlen(pos);
  1082. u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
  1083. struct hostapd_roaming_consortium *rc;
  1084. if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
  1085. hexstr2bin(pos, oi, len / 2)) {
  1086. wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
  1087. "'%s'", line, pos);
  1088. return -1;
  1089. }
  1090. len /= 2;
  1091. rc = os_realloc(bss->roaming_consortium,
  1092. sizeof(struct hostapd_roaming_consortium) *
  1093. (bss->roaming_consortium_count + 1));
  1094. if (rc == NULL)
  1095. return -1;
  1096. os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
  1097. rc[bss->roaming_consortium_count].len = len;
  1098. bss->roaming_consortium = rc;
  1099. bss->roaming_consortium_count++;
  1100. return 0;
  1101. }
  1102. static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
  1103. int line)
  1104. {
  1105. char *sep;
  1106. size_t clen, nlen;
  1107. struct hostapd_venue_name *vn;
  1108. sep = os_strchr(pos, ':');
  1109. if (sep == NULL)
  1110. goto fail;
  1111. *sep++ = '\0';
  1112. clen = os_strlen(pos);
  1113. if (clen < 2)
  1114. goto fail;
  1115. nlen = os_strlen(sep);
  1116. if (nlen > 252)
  1117. goto fail;
  1118. vn = os_realloc(bss->venue_name,
  1119. sizeof(struct hostapd_venue_name) *
  1120. (bss->venue_name_count + 1));
  1121. if (vn == NULL)
  1122. return -1;
  1123. bss->venue_name = vn;
  1124. vn = &bss->venue_name[bss->venue_name_count];
  1125. bss->venue_name_count++;
  1126. os_memset(vn->lang, 0, sizeof(vn->lang));
  1127. os_memcpy(vn->lang, pos, clen);
  1128. vn->name_len = nlen;
  1129. os_memcpy(vn->name, sep, nlen);
  1130. return 0;
  1131. fail:
  1132. wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
  1133. line, pos);
  1134. return -1;
  1135. }
  1136. #endif /* CONFIG_INTERWORKING */
  1137. #ifdef CONFIG_WPS_NFC
  1138. static struct wpabuf * hostapd_parse_bin(const char *buf)
  1139. {
  1140. size_t len;
  1141. struct wpabuf *ret;
  1142. len = os_strlen(buf);
  1143. if (len & 0x01)
  1144. return NULL;
  1145. len /= 2;
  1146. ret = wpabuf_alloc(len);
  1147. if (ret == NULL)
  1148. return NULL;
  1149. if (hexstr2bin(buf, wpabuf_put(ret, len), len)) {
  1150. wpabuf_free(ret);
  1151. return NULL;
  1152. }
  1153. return ret;
  1154. }
  1155. #endif /* CONFIG_WPS_NFC */
  1156. static int hostapd_config_fill(struct hostapd_config *conf,
  1157. struct hostapd_bss_config *bss,
  1158. char *buf, char *pos, int line)
  1159. {
  1160. int errors = 0;
  1161. {
  1162. if (os_strcmp(buf, "interface") == 0) {
  1163. os_strlcpy(conf->bss[0].iface, pos,
  1164. sizeof(conf->bss[0].iface));
  1165. } else if (os_strcmp(buf, "bridge") == 0) {
  1166. os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
  1167. } else if (os_strcmp(buf, "wds_bridge") == 0) {
  1168. os_strlcpy(bss->wds_bridge, pos,
  1169. sizeof(bss->wds_bridge));
  1170. } else if (os_strcmp(buf, "driver") == 0) {
  1171. int j;
  1172. /* clear to get error below if setting is invalid */
  1173. conf->driver = NULL;
  1174. for (j = 0; wpa_drivers[j]; j++) {
  1175. if (os_strcmp(pos, wpa_drivers[j]->name) == 0)
  1176. {
  1177. conf->driver = wpa_drivers[j];
  1178. break;
  1179. }
  1180. }
  1181. if (conf->driver == NULL) {
  1182. wpa_printf(MSG_ERROR, "Line %d: invalid/"
  1183. "unknown driver '%s'", line, pos);
  1184. errors++;
  1185. }
  1186. } else if (os_strcmp(buf, "debug") == 0) {
  1187. wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
  1188. "configuration variable is not used "
  1189. "anymore", line);
  1190. } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
  1191. bss->logger_syslog_level = atoi(pos);
  1192. } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
  1193. bss->logger_stdout_level = atoi(pos);
  1194. } else if (os_strcmp(buf, "logger_syslog") == 0) {
  1195. bss->logger_syslog = atoi(pos);
  1196. } else if (os_strcmp(buf, "logger_stdout") == 0) {
  1197. bss->logger_stdout = atoi(pos);
  1198. } else if (os_strcmp(buf, "dump_file") == 0) {
  1199. bss->dump_log_name = os_strdup(pos);
  1200. } else if (os_strcmp(buf, "ssid") == 0) {
  1201. bss->ssid.ssid_len = os_strlen(pos);
  1202. if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
  1203. bss->ssid.ssid_len < 1) {
  1204. wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
  1205. "'%s'", line, pos);
  1206. errors++;
  1207. } else {
  1208. os_memcpy(bss->ssid.ssid, pos,
  1209. bss->ssid.ssid_len);
  1210. bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
  1211. bss->ssid.ssid_set = 1;
  1212. }
  1213. } else if (os_strcmp(buf, "macaddr_acl") == 0) {
  1214. bss->macaddr_acl = atoi(pos);
  1215. if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
  1216. bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
  1217. bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
  1218. wpa_printf(MSG_ERROR, "Line %d: unknown "
  1219. "macaddr_acl %d",
  1220. line, bss->macaddr_acl);
  1221. }
  1222. } else if (os_strcmp(buf, "accept_mac_file") == 0) {
  1223. if (hostapd_config_read_maclist(pos, &bss->accept_mac,
  1224. &bss->num_accept_mac))
  1225. {
  1226. wpa_printf(MSG_ERROR, "Line %d: Failed to "
  1227. "read accept_mac_file '%s'",
  1228. line, pos);
  1229. errors++;
  1230. }
  1231. } else if (os_strcmp(buf, "deny_mac_file") == 0) {
  1232. if (hostapd_config_read_maclist(pos, &bss->deny_mac,
  1233. &bss->num_deny_mac)) {
  1234. wpa_printf(MSG_ERROR, "Line %d: Failed to "
  1235. "read deny_mac_file '%s'",
  1236. line, pos);
  1237. errors++;
  1238. }
  1239. } else if (os_strcmp(buf, "wds_sta") == 0) {
  1240. bss->wds_sta = atoi(pos);
  1241. } else if (os_strcmp(buf, "ap_isolate") == 0) {
  1242. bss->isolate = atoi(pos);
  1243. } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
  1244. bss->ap_max_inactivity = atoi(pos);
  1245. } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
  1246. bss->skip_inactivity_poll = atoi(pos);
  1247. } else if (os_strcmp(buf, "country_code") == 0) {
  1248. os_memcpy(conf->country, pos, 2);
  1249. /* FIX: make this configurable */
  1250. conf->country[2] = ' ';
  1251. } else if (os_strcmp(buf, "ieee80211d") == 0) {
  1252. conf->ieee80211d = atoi(pos);
  1253. } else if (os_strcmp(buf, "ieee8021x") == 0) {
  1254. bss->ieee802_1x = atoi(pos);
  1255. } else if (os_strcmp(buf, "eapol_version") == 0) {
  1256. bss->eapol_version = atoi(pos);
  1257. if (bss->eapol_version < 1 ||
  1258. bss->eapol_version > 2) {
  1259. wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL "
  1260. "version (%d): '%s'.",
  1261. line, bss->eapol_version, pos);
  1262. errors++;
  1263. } else
  1264. wpa_printf(MSG_DEBUG, "eapol_version=%d",
  1265. bss->eapol_version);
  1266. #ifdef EAP_SERVER
  1267. } else if (os_strcmp(buf, "eap_authenticator") == 0) {
  1268. bss->eap_server = atoi(pos);
  1269. wpa_printf(MSG_ERROR, "Line %d: obsolete "
  1270. "eap_authenticator used; this has been "
  1271. "renamed to eap_server", line);
  1272. } else if (os_strcmp(buf, "eap_server") == 0) {
  1273. bss->eap_server = atoi(pos);
  1274. } else if (os_strcmp(buf, "eap_user_file") == 0) {
  1275. if (hostapd_config_read_eap_user(pos, bss))
  1276. errors++;
  1277. } else if (os_strcmp(buf, "ca_cert") == 0) {
  1278. os_free(bss->ca_cert);
  1279. bss->ca_cert = os_strdup(pos);
  1280. } else if (os_strcmp(buf, "server_cert") == 0) {
  1281. os_free(bss->server_cert);
  1282. bss->server_cert = os_strdup(pos);
  1283. } else if (os_strcmp(buf, "private_key") == 0) {
  1284. os_free(bss->private_key);
  1285. bss->private_key = os_strdup(pos);
  1286. } else if (os_strcmp(buf, "private_key_passwd") == 0) {
  1287. os_free(bss->private_key_passwd);
  1288. bss->private_key_passwd = os_strdup(pos);
  1289. } else if (os_strcmp(buf, "check_crl") == 0) {
  1290. bss->check_crl = atoi(pos);
  1291. } else if (os_strcmp(buf, "dh_file") == 0) {
  1292. os_free(bss->dh_file);
  1293. bss->dh_file = os_strdup(pos);
  1294. } else if (os_strcmp(buf, "fragment_size") == 0) {
  1295. bss->fragment_size = atoi(pos);
  1296. #ifdef EAP_SERVER_FAST
  1297. } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
  1298. os_free(bss->pac_opaque_encr_key);
  1299. bss->pac_opaque_encr_key = os_malloc(16);
  1300. if (bss->pac_opaque_encr_key == NULL) {
  1301. wpa_printf(MSG_ERROR, "Line %d: No memory for "
  1302. "pac_opaque_encr_key", line);
  1303. errors++;
  1304. } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
  1305. 16)) {
  1306. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1307. "pac_opaque_encr_key", line);
  1308. errors++;
  1309. }
  1310. } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
  1311. size_t idlen = os_strlen(pos);
  1312. if (idlen & 1) {
  1313. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1314. "eap_fast_a_id", line);
  1315. errors++;
  1316. } else {
  1317. os_free(bss->eap_fast_a_id);
  1318. bss->eap_fast_a_id = os_malloc(idlen / 2);
  1319. if (bss->eap_fast_a_id == NULL ||
  1320. hexstr2bin(pos, bss->eap_fast_a_id,
  1321. idlen / 2)) {
  1322. wpa_printf(MSG_ERROR, "Line %d: "
  1323. "Failed to parse "
  1324. "eap_fast_a_id", line);
  1325. errors++;
  1326. } else
  1327. bss->eap_fast_a_id_len = idlen / 2;
  1328. }
  1329. } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
  1330. os_free(bss->eap_fast_a_id_info);
  1331. bss->eap_fast_a_id_info = os_strdup(pos);
  1332. } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
  1333. bss->eap_fast_prov = atoi(pos);
  1334. } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
  1335. bss->pac_key_lifetime = atoi(pos);
  1336. } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
  1337. bss->pac_key_refresh_time = atoi(pos);
  1338. #endif /* EAP_SERVER_FAST */
  1339. #ifdef EAP_SERVER_SIM
  1340. } else if (os_strcmp(buf, "eap_sim_db") == 0) {
  1341. os_free(bss->eap_sim_db);
  1342. bss->eap_sim_db = os_strdup(pos);
  1343. } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
  1344. bss->eap_sim_aka_result_ind = atoi(pos);
  1345. #endif /* EAP_SERVER_SIM */
  1346. #ifdef EAP_SERVER_TNC
  1347. } else if (os_strcmp(buf, "tnc") == 0) {
  1348. bss->tnc = atoi(pos);
  1349. #endif /* EAP_SERVER_TNC */
  1350. #ifdef EAP_SERVER_PWD
  1351. } else if (os_strcmp(buf, "pwd_group") == 0) {
  1352. bss->pwd_group = atoi(pos);
  1353. #endif /* EAP_SERVER_PWD */
  1354. #endif /* EAP_SERVER */
  1355. } else if (os_strcmp(buf, "eap_message") == 0) {
  1356. char *term;
  1357. bss->eap_req_id_text = os_strdup(pos);
  1358. if (bss->eap_req_id_text == NULL) {
  1359. wpa_printf(MSG_ERROR, "Line %d: Failed to "
  1360. "allocate memory for "
  1361. "eap_req_id_text", line);
  1362. errors++;
  1363. return errors;
  1364. }
  1365. bss->eap_req_id_text_len =
  1366. os_strlen(bss->eap_req_id_text);
  1367. term = os_strstr(bss->eap_req_id_text, "\\0");
  1368. if (term) {
  1369. *term++ = '\0';
  1370. os_memmove(term, term + 1,
  1371. bss->eap_req_id_text_len -
  1372. (term - bss->eap_req_id_text) - 1);
  1373. bss->eap_req_id_text_len--;
  1374. }
  1375. } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
  1376. bss->default_wep_key_len = atoi(pos);
  1377. if (bss->default_wep_key_len > 13) {
  1378. wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
  1379. "key len %lu (= %lu bits)", line,
  1380. (unsigned long)
  1381. bss->default_wep_key_len,
  1382. (unsigned long)
  1383. bss->default_wep_key_len * 8);
  1384. errors++;
  1385. }
  1386. } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
  1387. bss->individual_wep_key_len = atoi(pos);
  1388. if (bss->individual_wep_key_len < 0 ||
  1389. bss->individual_wep_key_len > 13) {
  1390. wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
  1391. "key len %d (= %d bits)", line,
  1392. bss->individual_wep_key_len,
  1393. bss->individual_wep_key_len * 8);
  1394. errors++;
  1395. }
  1396. } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
  1397. bss->wep_rekeying_period = atoi(pos);
  1398. if (bss->wep_rekeying_period < 0) {
  1399. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1400. "period %d",
  1401. line, bss->wep_rekeying_period);
  1402. errors++;
  1403. }
  1404. } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
  1405. bss->eap_reauth_period = atoi(pos);
  1406. if (bss->eap_reauth_period < 0) {
  1407. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1408. "period %d",
  1409. line, bss->eap_reauth_period);
  1410. errors++;
  1411. }
  1412. } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
  1413. bss->eapol_key_index_workaround = atoi(pos);
  1414. #ifdef CONFIG_IAPP
  1415. } else if (os_strcmp(buf, "iapp_interface") == 0) {
  1416. bss->ieee802_11f = 1;
  1417. os_strlcpy(bss->iapp_iface, pos,
  1418. sizeof(bss->iapp_iface));
  1419. #endif /* CONFIG_IAPP */
  1420. } else if (os_strcmp(buf, "own_ip_addr") == 0) {
  1421. if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
  1422. wpa_printf(MSG_ERROR, "Line %d: invalid IP "
  1423. "address '%s'", line, pos);
  1424. errors++;
  1425. }
  1426. } else if (os_strcmp(buf, "nas_identifier") == 0) {
  1427. bss->nas_identifier = os_strdup(pos);
  1428. #ifndef CONFIG_NO_RADIUS
  1429. } else if (os_strcmp(buf, "auth_server_addr") == 0) {
  1430. if (hostapd_config_read_radius_addr(
  1431. &bss->radius->auth_servers,
  1432. &bss->radius->num_auth_servers, pos, 1812,
  1433. &bss->radius->auth_server)) {
  1434. wpa_printf(MSG_ERROR, "Line %d: invalid IP "
  1435. "address '%s'", line, pos);
  1436. errors++;
  1437. }
  1438. } else if (bss->radius->auth_server &&
  1439. os_strcmp(buf, "auth_server_port") == 0) {
  1440. bss->radius->auth_server->port = atoi(pos);
  1441. } else if (bss->radius->auth_server &&
  1442. os_strcmp(buf, "auth_server_shared_secret") == 0) {
  1443. int len = os_strlen(pos);
  1444. if (len == 0) {
  1445. /* RFC 2865, Ch. 3 */
  1446. wpa_printf(MSG_ERROR, "Line %d: empty shared "
  1447. "secret is not allowed.", line);
  1448. errors++;
  1449. }
  1450. bss->radius->auth_server->shared_secret =
  1451. (u8 *) os_strdup(pos);
  1452. bss->radius->auth_server->shared_secret_len = len;
  1453. } else if (os_strcmp(buf, "acct_server_addr") == 0) {
  1454. if (hostapd_config_read_radius_addr(
  1455. &bss->radius->acct_servers,
  1456. &bss->radius->num_acct_servers, pos, 1813,
  1457. &bss->radius->acct_server)) {
  1458. wpa_printf(MSG_ERROR, "Line %d: invalid IP "
  1459. "address '%s'", line, pos);
  1460. errors++;
  1461. }
  1462. } else if (bss->radius->acct_server &&
  1463. os_strcmp(buf, "acct_server_port") == 0) {
  1464. bss->radius->acct_server->port = atoi(pos);
  1465. } else if (bss->radius->acct_server &&
  1466. os_strcmp(buf, "acct_server_shared_secret") == 0) {
  1467. int len = os_strlen(pos);
  1468. if (len == 0) {
  1469. /* RFC 2865, Ch. 3 */
  1470. wpa_printf(MSG_ERROR, "Line %d: empty shared "
  1471. "secret is not allowed.", line);
  1472. errors++;
  1473. }
  1474. bss->radius->acct_server->shared_secret =
  1475. (u8 *) os_strdup(pos);
  1476. bss->radius->acct_server->shared_secret_len = len;
  1477. } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
  1478. 0) {
  1479. bss->radius->retry_primary_interval = atoi(pos);
  1480. } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
  1481. {
  1482. bss->acct_interim_interval = atoi(pos);
  1483. } else if (os_strcmp(buf, "radius_request_cui") == 0) {
  1484. bss->radius_request_cui = atoi(pos);
  1485. } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
  1486. struct hostapd_radius_attr *attr, *a;
  1487. attr = hostapd_parse_radius_attr(pos);
  1488. if (attr == NULL) {
  1489. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1490. "radius_auth_req_attr", line);
  1491. errors++;
  1492. } else if (bss->radius_auth_req_attr == NULL) {
  1493. bss->radius_auth_req_attr = attr;
  1494. } else {
  1495. a = bss->radius_auth_req_attr;
  1496. while (a->next)
  1497. a = a->next;
  1498. a->next = attr;
  1499. }
  1500. } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
  1501. struct hostapd_radius_attr *attr, *a;
  1502. attr = hostapd_parse_radius_attr(pos);
  1503. if (attr == NULL) {
  1504. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1505. "radius_acct_req_attr", line);
  1506. errors++;
  1507. } else if (bss->radius_acct_req_attr == NULL) {
  1508. bss->radius_acct_req_attr = attr;
  1509. } else {
  1510. a = bss->radius_acct_req_attr;
  1511. while (a->next)
  1512. a = a->next;
  1513. a->next = attr;
  1514. }
  1515. } else if (os_strcmp(buf, "radius_das_port") == 0) {
  1516. bss->radius_das_port = atoi(pos);
  1517. } else if (os_strcmp(buf, "radius_das_client") == 0) {
  1518. if (hostapd_parse_das_client(bss, pos) < 0) {
  1519. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1520. "DAS client", line);
  1521. errors++;
  1522. }
  1523. } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
  1524. bss->radius_das_time_window = atoi(pos);
  1525. } else if (os_strcmp(buf, "radius_das_require_event_timestamp")
  1526. == 0) {
  1527. bss->radius_das_require_event_timestamp = atoi(pos);
  1528. #endif /* CONFIG_NO_RADIUS */
  1529. } else if (os_strcmp(buf, "auth_algs") == 0) {
  1530. bss->auth_algs = atoi(pos);
  1531. if (bss->auth_algs == 0) {
  1532. wpa_printf(MSG_ERROR, "Line %d: no "
  1533. "authentication algorithms allowed",
  1534. line);
  1535. errors++;
  1536. }
  1537. } else if (os_strcmp(buf, "max_num_sta") == 0) {
  1538. bss->max_num_sta = atoi(pos);
  1539. if (bss->max_num_sta < 0 ||
  1540. bss->max_num_sta > MAX_STA_COUNT) {
  1541. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1542. "max_num_sta=%d; allowed range "
  1543. "0..%d", line, bss->max_num_sta,
  1544. MAX_STA_COUNT);
  1545. errors++;
  1546. }
  1547. } else if (os_strcmp(buf, "wpa") == 0) {
  1548. bss->wpa = atoi(pos);
  1549. } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
  1550. bss->wpa_group_rekey = atoi(pos);
  1551. } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
  1552. bss->wpa_strict_rekey = atoi(pos);
  1553. } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
  1554. bss->wpa_gmk_rekey = atoi(pos);
  1555. } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
  1556. bss->wpa_ptk_rekey = atoi(pos);
  1557. } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
  1558. int len = os_strlen(pos);
  1559. if (len < 8 || len > 63) {
  1560. wpa_printf(MSG_ERROR, "Line %d: invalid WPA "
  1561. "passphrase length %d (expected "
  1562. "8..63)", line, len);
  1563. errors++;
  1564. } else {
  1565. os_free(bss->ssid.wpa_passphrase);
  1566. bss->ssid.wpa_passphrase = os_strdup(pos);
  1567. os_free(bss->ssid.wpa_psk);
  1568. bss->ssid.wpa_psk = NULL;
  1569. }
  1570. } else if (os_strcmp(buf, "wpa_psk") == 0) {
  1571. os_free(bss->ssid.wpa_psk);
  1572. bss->ssid.wpa_psk =
  1573. os_zalloc(sizeof(struct hostapd_wpa_psk));
  1574. if (bss->ssid.wpa_psk == NULL)
  1575. errors++;
  1576. else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
  1577. PMK_LEN) ||
  1578. pos[PMK_LEN * 2] != '\0') {
  1579. wpa_printf(MSG_ERROR, "Line %d: Invalid PSK "
  1580. "'%s'.", line, pos);
  1581. errors++;
  1582. } else {
  1583. bss->ssid.wpa_psk->group = 1;
  1584. os_free(bss->ssid.wpa_passphrase);
  1585. bss->ssid.wpa_passphrase = NULL;
  1586. }
  1587. } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
  1588. os_free(bss->ssid.wpa_psk_file);
  1589. bss->ssid.wpa_psk_file = os_strdup(pos);
  1590. if (!bss->ssid.wpa_psk_file) {
  1591. wpa_printf(MSG_ERROR, "Line %d: allocation "
  1592. "failed", line);
  1593. errors++;
  1594. }
  1595. } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
  1596. bss->wpa_key_mgmt =
  1597. hostapd_config_parse_key_mgmt(line, pos);
  1598. if (bss->wpa_key_mgmt == -1)
  1599. errors++;
  1600. } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
  1601. bss->wpa_psk_radius = atoi(pos);
  1602. if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
  1603. bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
  1604. bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
  1605. wpa_printf(MSG_ERROR, "Line %d: unknown "
  1606. "wpa_psk_radius %d",
  1607. line, bss->wpa_psk_radius);
  1608. errors++;
  1609. }
  1610. } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
  1611. bss->wpa_pairwise =
  1612. hostapd_config_parse_cipher(line, pos);
  1613. if (bss->wpa_pairwise == -1 ||
  1614. bss->wpa_pairwise == 0)
  1615. errors++;
  1616. else if (bss->wpa_pairwise &
  1617. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
  1618. WPA_CIPHER_WEP104)) {
  1619. wpa_printf(MSG_ERROR, "Line %d: unsupported "
  1620. "pairwise cipher suite '%s'",
  1621. bss->wpa_pairwise, pos);
  1622. errors++;
  1623. }
  1624. } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
  1625. bss->rsn_pairwise =
  1626. hostapd_config_parse_cipher(line, pos);
  1627. if (bss->rsn_pairwise == -1 ||
  1628. bss->rsn_pairwise == 0)
  1629. errors++;
  1630. else if (bss->rsn_pairwise &
  1631. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
  1632. WPA_CIPHER_WEP104)) {
  1633. wpa_printf(MSG_ERROR, "Line %d: unsupported "
  1634. "pairwise cipher suite '%s'",
  1635. bss->rsn_pairwise, pos);
  1636. errors++;
  1637. }
  1638. #ifdef CONFIG_RSN_PREAUTH
  1639. } else if (os_strcmp(buf, "rsn_preauth") == 0) {
  1640. bss->rsn_preauth = atoi(pos);
  1641. } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
  1642. bss->rsn_preauth_interfaces = os_strdup(pos);
  1643. #endif /* CONFIG_RSN_PREAUTH */
  1644. #ifdef CONFIG_PEERKEY
  1645. } else if (os_strcmp(buf, "peerkey") == 0) {
  1646. bss->peerkey = atoi(pos);
  1647. #endif /* CONFIG_PEERKEY */
  1648. #ifdef CONFIG_IEEE80211R
  1649. } else if (os_strcmp(buf, "mobility_domain") == 0) {
  1650. if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
  1651. hexstr2bin(pos, bss->mobility_domain,
  1652. MOBILITY_DOMAIN_ID_LEN) != 0) {
  1653. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1654. "mobility_domain '%s'", line, pos);
  1655. errors++;
  1656. return errors;
  1657. }
  1658. } else if (os_strcmp(buf, "r1_key_holder") == 0) {
  1659. if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
  1660. hexstr2bin(pos, bss->r1_key_holder,
  1661. FT_R1KH_ID_LEN) != 0) {
  1662. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1663. "r1_key_holder '%s'", line, pos);
  1664. errors++;
  1665. return errors;
  1666. }
  1667. } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
  1668. bss->r0_key_lifetime = atoi(pos);
  1669. } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
  1670. bss->reassociation_deadline = atoi(pos);
  1671. } else if (os_strcmp(buf, "r0kh") == 0) {
  1672. if (add_r0kh(bss, pos) < 0) {
  1673. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1674. "r0kh '%s'", line, pos);
  1675. errors++;
  1676. return errors;
  1677. }
  1678. } else if (os_strcmp(buf, "r1kh") == 0) {
  1679. if (add_r1kh(bss, pos) < 0) {
  1680. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1681. "r1kh '%s'", line, pos);
  1682. errors++;
  1683. return errors;
  1684. }
  1685. } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
  1686. bss->pmk_r1_push = atoi(pos);
  1687. } else if (os_strcmp(buf, "ft_over_ds") == 0) {
  1688. bss->ft_over_ds = atoi(pos);
  1689. #endif /* CONFIG_IEEE80211R */
  1690. #ifndef CONFIG_NO_CTRL_IFACE
  1691. } else if (os_strcmp(buf, "ctrl_interface") == 0) {
  1692. os_free(bss->ctrl_interface);
  1693. bss->ctrl_interface = os_strdup(pos);
  1694. } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
  1695. #ifndef CONFIG_NATIVE_WINDOWS
  1696. struct group *grp;
  1697. char *endp;
  1698. const char *group = pos;
  1699. grp = getgrnam(group);
  1700. if (grp) {
  1701. bss->ctrl_interface_gid = grp->gr_gid;
  1702. bss->ctrl_interface_gid_set = 1;
  1703. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
  1704. " (from group name '%s')",
  1705. bss->ctrl_interface_gid, group);
  1706. return errors;
  1707. }
  1708. /* Group name not found - try to parse this as gid */
  1709. bss->ctrl_interface_gid = strtol(group, &endp, 10);
  1710. if (*group == '\0' || *endp != '\0') {
  1711. wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
  1712. "'%s'", line, group);
  1713. errors++;
  1714. return errors;
  1715. }
  1716. bss->ctrl_interface_gid_set = 1;
  1717. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
  1718. bss->ctrl_interface_gid);
  1719. #endif /* CONFIG_NATIVE_WINDOWS */
  1720. #endif /* CONFIG_NO_CTRL_IFACE */
  1721. #ifdef RADIUS_SERVER
  1722. } else if (os_strcmp(buf, "radius_server_clients") == 0) {
  1723. os_free(bss->radius_server_clients);
  1724. bss->radius_server_clients = os_strdup(pos);
  1725. } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
  1726. bss->radius_server_auth_port = atoi(pos);
  1727. } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
  1728. bss->radius_server_ipv6 = atoi(pos);
  1729. #endif /* RADIUS_SERVER */
  1730. } else if (os_strcmp(buf, "test_socket") == 0) {
  1731. os_free(bss->test_socket);
  1732. bss->test_socket = os_strdup(pos);
  1733. } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
  1734. bss->use_pae_group_addr = atoi(pos);
  1735. } else if (os_strcmp(buf, "hw_mode") == 0) {
  1736. if (os_strcmp(pos, "a") == 0)
  1737. conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
  1738. else if (os_strcmp(pos, "b") == 0)
  1739. conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
  1740. else if (os_strcmp(pos, "g") == 0)
  1741. conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
  1742. else {
  1743. wpa_printf(MSG_ERROR, "Line %d: unknown "
  1744. "hw_mode '%s'", line, pos);
  1745. errors++;
  1746. }
  1747. } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
  1748. if (os_strcmp(pos, "a") == 0)
  1749. bss->wps_rf_bands = WPS_RF_50GHZ;
  1750. else if (os_strcmp(pos, "g") == 0 ||
  1751. os_strcmp(pos, "b") == 0)
  1752. bss->wps_rf_bands = WPS_RF_24GHZ;
  1753. else if (os_strcmp(pos, "ag") == 0 ||
  1754. os_strcmp(pos, "ga") == 0)
  1755. bss->wps_rf_bands =
  1756. WPS_RF_24GHZ | WPS_RF_50GHZ;
  1757. else {
  1758. wpa_printf(MSG_ERROR, "Line %d: unknown "
  1759. "wps_rf_band '%s'", line, pos);
  1760. errors++;
  1761. }
  1762. } else if (os_strcmp(buf, "channel") == 0) {
  1763. conf->channel = atoi(pos);
  1764. } else if (os_strcmp(buf, "beacon_int") == 0) {
  1765. int val = atoi(pos);
  1766. /* MIB defines range as 1..65535, but very small values
  1767. * cause problems with the current implementation.
  1768. * Since it is unlikely that this small numbers are
  1769. * useful in real life scenarios, do not allow beacon
  1770. * period to be set below 15 TU. */
  1771. if (val < 15 || val > 65535) {
  1772. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1773. "beacon_int %d (expected "
  1774. "15..65535)", line, val);
  1775. errors++;
  1776. } else
  1777. conf->beacon_int = val;
  1778. } else if (os_strcmp(buf, "dtim_period") == 0) {
  1779. bss->dtim_period = atoi(pos);
  1780. if (bss->dtim_period < 1 || bss->dtim_period > 255) {
  1781. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1782. "dtim_period %d",
  1783. line, bss->dtim_period);
  1784. errors++;
  1785. }
  1786. } else if (os_strcmp(buf, "rts_threshold") == 0) {
  1787. conf->rts_threshold = atoi(pos);
  1788. if (conf->rts_threshold < 0 ||
  1789. conf->rts_threshold > 2347) {
  1790. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1791. "rts_threshold %d",
  1792. line, conf->rts_threshold);
  1793. errors++;
  1794. }
  1795. } else if (os_strcmp(buf, "fragm_threshold") == 0) {
  1796. conf->fragm_threshold = atoi(pos);
  1797. if (conf->fragm_threshold < 256 ||
  1798. conf->fragm_threshold > 2346) {
  1799. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1800. "fragm_threshold %d",
  1801. line, conf->fragm_threshold);
  1802. errors++;
  1803. }
  1804. } else if (os_strcmp(buf, "send_probe_response") == 0) {
  1805. int val = atoi(pos);
  1806. if (val != 0 && val != 1) {
  1807. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1808. "send_probe_response %d (expected "
  1809. "0 or 1)", line, val);
  1810. } else
  1811. conf->send_probe_response = val;
  1812. } else if (os_strcmp(buf, "supported_rates") == 0) {
  1813. if (hostapd_parse_rates(&conf->supported_rates, pos)) {
  1814. wpa_printf(MSG_ERROR, "Line %d: invalid rate "
  1815. "list", line);
  1816. errors++;
  1817. }
  1818. } else if (os_strcmp(buf, "basic_rates") == 0) {
  1819. if (hostapd_parse_rates(&conf->basic_rates, pos)) {
  1820. wpa_printf(MSG_ERROR, "Line %d: invalid rate "
  1821. "list", line);
  1822. errors++;
  1823. }
  1824. } else if (os_strcmp(buf, "preamble") == 0) {
  1825. if (atoi(pos))
  1826. conf->preamble = SHORT_PREAMBLE;
  1827. else
  1828. conf->preamble = LONG_PREAMBLE;
  1829. } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
  1830. bss->ignore_broadcast_ssid = atoi(pos);
  1831. } else if (os_strcmp(buf, "wep_default_key") == 0) {
  1832. bss->ssid.wep.idx = atoi(pos);
  1833. if (bss->ssid.wep.idx > 3) {
  1834. wpa_printf(MSG_ERROR, "Invalid "
  1835. "wep_default_key index %d",
  1836. bss->ssid.wep.idx);
  1837. errors++;
  1838. }
  1839. } else if (os_strcmp(buf, "wep_key0") == 0 ||
  1840. os_strcmp(buf, "wep_key1") == 0 ||
  1841. os_strcmp(buf, "wep_key2") == 0 ||
  1842. os_strcmp(buf, "wep_key3") == 0) {
  1843. if (hostapd_config_read_wep(&bss->ssid.wep,
  1844. buf[7] - '0', pos)) {
  1845. wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
  1846. "key '%s'", line, buf);
  1847. errors++;
  1848. }
  1849. #ifndef CONFIG_NO_VLAN
  1850. } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
  1851. bss->ssid.dynamic_vlan = atoi(pos);
  1852. } else if (os_strcmp(buf, "vlan_file") == 0) {
  1853. if (hostapd_config_read_vlan_file(bss, pos)) {
  1854. wpa_printf(MSG_ERROR, "Line %d: failed to "
  1855. "read VLAN file '%s'", line, pos);
  1856. errors++;
  1857. }
  1858. #ifdef CONFIG_FULL_DYNAMIC_VLAN
  1859. } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
  1860. bss->ssid.vlan_tagged_interface = os_strdup(pos);
  1861. #endif /* CONFIG_FULL_DYNAMIC_VLAN */
  1862. #endif /* CONFIG_NO_VLAN */
  1863. } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
  1864. conf->ap_table_max_size = atoi(pos);
  1865. } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
  1866. conf->ap_table_expiration_time = atoi(pos);
  1867. } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
  1868. if (hostapd_config_tx_queue(conf, buf, pos)) {
  1869. wpa_printf(MSG_ERROR, "Line %d: invalid TX "
  1870. "queue item", line);
  1871. errors++;
  1872. }
  1873. } else if (os_strcmp(buf, "wme_enabled") == 0 ||
  1874. os_strcmp(buf, "wmm_enabled") == 0) {
  1875. bss->wmm_enabled = atoi(pos);
  1876. } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
  1877. bss->wmm_uapsd = atoi(pos);
  1878. } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
  1879. os_strncmp(buf, "wmm_ac_", 7) == 0) {
  1880. if (hostapd_config_wmm_ac(conf, buf, pos)) {
  1881. wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
  1882. "ac item", line);
  1883. errors++;
  1884. }
  1885. } else if (os_strcmp(buf, "bss") == 0) {
  1886. if (hostapd_config_bss(conf, pos)) {
  1887. wpa_printf(MSG_ERROR, "Line %d: invalid bss "
  1888. "item", line);
  1889. errors++;
  1890. }
  1891. } else if (os_strcmp(buf, "bssid") == 0) {
  1892. if (hwaddr_aton(pos, bss->bssid)) {
  1893. wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
  1894. "item", line);
  1895. errors++;
  1896. }
  1897. #ifdef CONFIG_IEEE80211W
  1898. } else if (os_strcmp(buf, "ieee80211w") == 0) {
  1899. bss->ieee80211w = atoi(pos);
  1900. } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
  1901. bss->assoc_sa_query_max_timeout = atoi(pos);
  1902. if (bss->assoc_sa_query_max_timeout == 0) {
  1903. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1904. "assoc_sa_query_max_timeout", line);
  1905. errors++;
  1906. }
  1907. } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0)
  1908. {
  1909. bss->assoc_sa_query_retry_timeout = atoi(pos);
  1910. if (bss->assoc_sa_query_retry_timeout == 0) {
  1911. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1912. "assoc_sa_query_retry_timeout",
  1913. line);
  1914. errors++;
  1915. }
  1916. #endif /* CONFIG_IEEE80211W */
  1917. #ifdef CONFIG_IEEE80211N
  1918. } else if (os_strcmp(buf, "ieee80211n") == 0) {
  1919. conf->ieee80211n = atoi(pos);
  1920. } else if (os_strcmp(buf, "ht_capab") == 0) {
  1921. if (hostapd_config_ht_capab(conf, pos) < 0) {
  1922. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1923. "ht_capab", line);
  1924. errors++;
  1925. }
  1926. } else if (os_strcmp(buf, "require_ht") == 0) {
  1927. conf->require_ht = atoi(pos);
  1928. #endif /* CONFIG_IEEE80211N */
  1929. } else if (os_strcmp(buf, "max_listen_interval") == 0) {
  1930. bss->max_listen_interval = atoi(pos);
  1931. } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
  1932. bss->disable_pmksa_caching = atoi(pos);
  1933. } else if (os_strcmp(buf, "okc") == 0) {
  1934. bss->okc = atoi(pos);
  1935. #ifdef CONFIG_WPS
  1936. } else if (os_strcmp(buf, "wps_state") == 0) {
  1937. bss->wps_state = atoi(pos);
  1938. if (bss->wps_state < 0 || bss->wps_state > 2) {
  1939. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1940. "wps_state", line);
  1941. errors++;
  1942. }
  1943. } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
  1944. bss->ap_setup_locked = atoi(pos);
  1945. } else if (os_strcmp(buf, "uuid") == 0) {
  1946. if (uuid_str2bin(pos, bss->uuid)) {
  1947. wpa_printf(MSG_ERROR, "Line %d: invalid UUID",
  1948. line);
  1949. errors++;
  1950. }
  1951. } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
  1952. os_free(bss->wps_pin_requests);
  1953. bss->wps_pin_requests = os_strdup(pos);
  1954. } else if (os_strcmp(buf, "device_name") == 0) {
  1955. if (os_strlen(pos) > 32) {
  1956. wpa_printf(MSG_ERROR, "Line %d: Too long "
  1957. "device_name", line);
  1958. errors++;
  1959. }
  1960. os_free(bss->device_name);
  1961. bss->device_name = os_strdup(pos);
  1962. } else if (os_strcmp(buf, "manufacturer") == 0) {
  1963. if (os_strlen(pos) > 64) {
  1964. wpa_printf(MSG_ERROR, "Line %d: Too long "
  1965. "manufacturer", line);
  1966. errors++;
  1967. }
  1968. os_free(bss->manufacturer);
  1969. bss->manufacturer = os_strdup(pos);
  1970. } else if (os_strcmp(buf, "model_name") == 0) {
  1971. if (os_strlen(pos) > 32) {
  1972. wpa_printf(MSG_ERROR, "Line %d: Too long "
  1973. "model_name", line);
  1974. errors++;
  1975. }
  1976. os_free(bss->model_name);
  1977. bss->model_name = os_strdup(pos);
  1978. } else if (os_strcmp(buf, "model_number") == 0) {
  1979. if (os_strlen(pos) > 32) {
  1980. wpa_printf(MSG_ERROR, "Line %d: Too long "
  1981. "model_number", line);
  1982. errors++;
  1983. }
  1984. os_free(bss->model_number);
  1985. bss->model_number = os_strdup(pos);
  1986. } else if (os_strcmp(buf, "serial_number") == 0) {
  1987. if (os_strlen(pos) > 32) {
  1988. wpa_printf(MSG_ERROR, "Line %d: Too long "
  1989. "serial_number", line);
  1990. errors++;
  1991. }
  1992. os_free(bss->serial_number);
  1993. bss->serial_number = os_strdup(pos);
  1994. } else if (os_strcmp(buf, "device_type") == 0) {
  1995. if (wps_dev_type_str2bin(pos, bss->device_type))
  1996. errors++;
  1997. } else if (os_strcmp(buf, "config_methods") == 0) {
  1998. os_free(bss->config_methods);
  1999. bss->config_methods = os_strdup(pos);
  2000. } else if (os_strcmp(buf, "os_version") == 0) {
  2001. if (hexstr2bin(pos, bss->os_version, 4)) {
  2002. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2003. "os_version", line);
  2004. errors++;
  2005. }
  2006. } else if (os_strcmp(buf, "ap_pin") == 0) {
  2007. os_free(bss->ap_pin);
  2008. bss->ap_pin = os_strdup(pos);
  2009. } else if (os_strcmp(buf, "skip_cred_build") == 0) {
  2010. bss->skip_cred_build = atoi(pos);
  2011. } else if (os_strcmp(buf, "extra_cred") == 0) {
  2012. os_free(bss->extra_cred);
  2013. bss->extra_cred =
  2014. (u8 *) os_readfile(pos, &bss->extra_cred_len);
  2015. if (bss->extra_cred == NULL) {
  2016. wpa_printf(MSG_ERROR, "Line %d: could not "
  2017. "read Credentials from '%s'",
  2018. line, pos);
  2019. errors++;
  2020. }
  2021. } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
  2022. bss->wps_cred_processing = atoi(pos);
  2023. } else if (os_strcmp(buf, "ap_settings") == 0) {
  2024. os_free(bss->ap_settings);
  2025. bss->ap_settings =
  2026. (u8 *) os_readfile(pos, &bss->ap_settings_len);
  2027. if (bss->ap_settings == NULL) {
  2028. wpa_printf(MSG_ERROR, "Line %d: could not "
  2029. "read AP Settings from '%s'",
  2030. line, pos);
  2031. errors++;
  2032. }
  2033. } else if (os_strcmp(buf, "upnp_iface") == 0) {
  2034. bss->upnp_iface = os_strdup(pos);
  2035. } else if (os_strcmp(buf, "friendly_name") == 0) {
  2036. os_free(bss->friendly_name);
  2037. bss->friendly_name = os_strdup(pos);
  2038. } else if (os_strcmp(buf, "manufacturer_url") == 0) {
  2039. os_free(bss->manufacturer_url);
  2040. bss->manufacturer_url = os_strdup(pos);
  2041. } else if (os_strcmp(buf, "model_description") == 0) {
  2042. os_free(bss->model_description);
  2043. bss->model_description = os_strdup(pos);
  2044. } else if (os_strcmp(buf, "model_url") == 0) {
  2045. os_free(bss->model_url);
  2046. bss->model_url = os_strdup(pos);
  2047. } else if (os_strcmp(buf, "upc") == 0) {
  2048. os_free(bss->upc);
  2049. bss->upc = os_strdup(pos);
  2050. } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
  2051. bss->pbc_in_m1 = atoi(pos);
  2052. #ifdef CONFIG_WPS_NFC
  2053. } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
  2054. bss->wps_nfc_dev_pw_id = atoi(pos);
  2055. if (bss->wps_nfc_dev_pw_id < 0x10 ||
  2056. bss->wps_nfc_dev_pw_id > 0xffff) {
  2057. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2058. "wps_nfc_dev_pw_id value", line);
  2059. errors++;
  2060. }
  2061. } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
  2062. wpabuf_free(bss->wps_nfc_dh_pubkey);
  2063. bss->wps_nfc_dh_pubkey = hostapd_parse_bin(pos);
  2064. } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
  2065. wpabuf_free(bss->wps_nfc_dh_privkey);
  2066. bss->wps_nfc_dh_privkey = hostapd_parse_bin(pos);
  2067. } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
  2068. wpabuf_free(bss->wps_nfc_dev_pw);
  2069. bss->wps_nfc_dev_pw = hostapd_parse_bin(pos);
  2070. #endif /* CONFIG_WPS_NFC */
  2071. #endif /* CONFIG_WPS */
  2072. #ifdef CONFIG_P2P_MANAGER
  2073. } else if (os_strcmp(buf, "manage_p2p") == 0) {
  2074. int manage = atoi(pos);
  2075. if (manage)
  2076. bss->p2p |= P2P_MANAGE;
  2077. else
  2078. bss->p2p &= ~P2P_MANAGE;
  2079. } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
  2080. if (atoi(pos))
  2081. bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
  2082. else
  2083. bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
  2084. #endif /* CONFIG_P2P_MANAGER */
  2085. } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
  2086. bss->disassoc_low_ack = atoi(pos);
  2087. } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
  2088. int val = atoi(pos);
  2089. if (val)
  2090. bss->tdls |= TDLS_PROHIBIT;
  2091. else
  2092. bss->tdls &= ~TDLS_PROHIBIT;
  2093. } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
  2094. int val = atoi(pos);
  2095. if (val)
  2096. bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
  2097. else
  2098. bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
  2099. #ifdef CONFIG_RSN_TESTING
  2100. } else if (os_strcmp(buf, "rsn_testing") == 0) {
  2101. extern int rsn_testing;
  2102. rsn_testing = atoi(pos);
  2103. #endif /* CONFIG_RSN_TESTING */
  2104. } else if (os_strcmp(buf, "time_advertisement") == 0) {
  2105. bss->time_advertisement = atoi(pos);
  2106. } else if (os_strcmp(buf, "time_zone") == 0) {
  2107. size_t tz_len = os_strlen(pos);
  2108. if (tz_len < 4 || tz_len > 255) {
  2109. wpa_printf(MSG_DEBUG, "Line %d: invalid "
  2110. "time_zone", line);
  2111. errors++;
  2112. return errors;
  2113. }
  2114. os_free(bss->time_zone);
  2115. bss->time_zone = os_strdup(pos);
  2116. if (bss->time_zone == NULL)
  2117. errors++;
  2118. #ifdef CONFIG_INTERWORKING
  2119. } else if (os_strcmp(buf, "interworking") == 0) {
  2120. bss->interworking = atoi(pos);
  2121. } else if (os_strcmp(buf, "access_network_type") == 0) {
  2122. bss->access_network_type = atoi(pos);
  2123. if (bss->access_network_type < 0 ||
  2124. bss->access_network_type > 15) {
  2125. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2126. "access_network_type", line);
  2127. errors++;
  2128. }
  2129. } else if (os_strcmp(buf, "internet") == 0) {
  2130. bss->internet = atoi(pos);
  2131. } else if (os_strcmp(buf, "asra") == 0) {
  2132. bss->asra = atoi(pos);
  2133. } else if (os_strcmp(buf, "esr") == 0) {
  2134. bss->esr = atoi(pos);
  2135. } else if (os_strcmp(buf, "uesa") == 0) {
  2136. bss->uesa = atoi(pos);
  2137. } else if (os_strcmp(buf, "venue_group") == 0) {
  2138. bss->venue_group = atoi(pos);
  2139. bss->venue_info_set = 1;
  2140. } else if (os_strcmp(buf, "venue_type") == 0) {
  2141. bss->venue_type = atoi(pos);
  2142. bss->venue_info_set = 1;
  2143. } else if (os_strcmp(buf, "hessid") == 0) {
  2144. if (hwaddr_aton(pos, bss->hessid)) {
  2145. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2146. "hessid", line);
  2147. errors++;
  2148. }
  2149. } else if (os_strcmp(buf, "roaming_consortium") == 0) {
  2150. if (parse_roaming_consortium(bss, pos, line) < 0)
  2151. errors++;
  2152. } else if (os_strcmp(buf, "venue_name") == 0) {
  2153. if (parse_venue_name(bss, pos, line) < 0)
  2154. errors++;
  2155. } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
  2156. bss->gas_frag_limit = atoi(pos);
  2157. } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
  2158. bss->gas_comeback_delay = atoi(pos);
  2159. #endif /* CONFIG_INTERWORKING */
  2160. #ifdef CONFIG_RADIUS_TEST
  2161. } else if (os_strcmp(buf, "dump_msk_file") == 0) {
  2162. os_free(bss->dump_msk_file);
  2163. bss->dump_msk_file = os_strdup(pos);
  2164. #endif /* CONFIG_RADIUS_TEST */
  2165. } else {
  2166. wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
  2167. "item '%s'", line, buf);
  2168. errors++;
  2169. }
  2170. }
  2171. return errors;
  2172. }
  2173. static void hostapd_set_security_params(struct hostapd_bss_config *bss)
  2174. {
  2175. int pairwise;
  2176. if (bss->individual_wep_key_len == 0) {
  2177. /* individual keys are not use; can use key idx0 for
  2178. * broadcast keys */
  2179. bss->broadcast_key_idx_min = 0;
  2180. }
  2181. /* Select group cipher based on the enabled pairwise cipher
  2182. * suites */
  2183. pairwise = 0;
  2184. if (bss->wpa & 1)
  2185. pairwise |= bss->wpa_pairwise;
  2186. if (bss->wpa & 2) {
  2187. if (bss->rsn_pairwise == 0)
  2188. bss->rsn_pairwise = bss->wpa_pairwise;
  2189. pairwise |= bss->rsn_pairwise;
  2190. }
  2191. if (pairwise & WPA_CIPHER_TKIP)
  2192. bss->wpa_group = WPA_CIPHER_TKIP;
  2193. else
  2194. bss->wpa_group = WPA_CIPHER_CCMP;
  2195. bss->radius->auth_server = bss->radius->auth_servers;
  2196. bss->radius->acct_server = bss->radius->acct_servers;
  2197. if (bss->wpa && bss->ieee802_1x) {
  2198. bss->ssid.security_policy = SECURITY_WPA;
  2199. } else if (bss->wpa) {
  2200. bss->ssid.security_policy = SECURITY_WPA_PSK;
  2201. } else if (bss->ieee802_1x) {
  2202. int cipher = WPA_CIPHER_NONE;
  2203. bss->ssid.security_policy = SECURITY_IEEE_802_1X;
  2204. bss->ssid.wep.default_len = bss->default_wep_key_len;
  2205. if (bss->default_wep_key_len)
  2206. cipher = bss->default_wep_key_len >= 13 ?
  2207. WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
  2208. bss->wpa_group = cipher;
  2209. bss->wpa_pairwise = cipher;
  2210. bss->rsn_pairwise = cipher;
  2211. } else if (bss->ssid.wep.keys_set) {
  2212. int cipher = WPA_CIPHER_WEP40;
  2213. if (bss->ssid.wep.len[0] >= 13)
  2214. cipher = WPA_CIPHER_WEP104;
  2215. bss->ssid.security_policy = SECURITY_STATIC_WEP;
  2216. bss->wpa_group = cipher;
  2217. bss->wpa_pairwise = cipher;
  2218. bss->rsn_pairwise = cipher;
  2219. } else {
  2220. bss->ssid.security_policy = SECURITY_PLAINTEXT;
  2221. bss->wpa_group = WPA_CIPHER_NONE;
  2222. bss->wpa_pairwise = WPA_CIPHER_NONE;
  2223. bss->rsn_pairwise = WPA_CIPHER_NONE;
  2224. }
  2225. }
  2226. /**
  2227. * hostapd_config_read - Read and parse a configuration file
  2228. * @fname: Configuration file name (including path, if needed)
  2229. * Returns: Allocated configuration data structure
  2230. */
  2231. struct hostapd_config * hostapd_config_read(const char *fname)
  2232. {
  2233. struct hostapd_config *conf;
  2234. struct hostapd_bss_config *bss;
  2235. FILE *f;
  2236. char buf[512], *pos;
  2237. int line = 0;
  2238. int errors = 0;
  2239. size_t i;
  2240. f = fopen(fname, "r");
  2241. if (f == NULL) {
  2242. wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
  2243. "for reading.", fname);
  2244. return NULL;
  2245. }
  2246. conf = hostapd_config_defaults();
  2247. if (conf == NULL) {
  2248. fclose(f);
  2249. return NULL;
  2250. }
  2251. /* set default driver based on configuration */
  2252. conf->driver = wpa_drivers[0];
  2253. if (conf->driver == NULL) {
  2254. wpa_printf(MSG_ERROR, "No driver wrappers registered!");
  2255. hostapd_config_free(conf);
  2256. fclose(f);
  2257. return NULL;
  2258. }
  2259. bss = conf->last_bss = conf->bss;
  2260. while (fgets(buf, sizeof(buf), f)) {
  2261. bss = conf->last_bss;
  2262. line++;
  2263. if (buf[0] == '#')
  2264. continue;
  2265. pos = buf;
  2266. while (*pos != '\0') {
  2267. if (*pos == '\n') {
  2268. *pos = '\0';
  2269. break;
  2270. }
  2271. pos++;
  2272. }
  2273. if (buf[0] == '\0')
  2274. continue;
  2275. pos = os_strchr(buf, '=');
  2276. if (pos == NULL) {
  2277. wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
  2278. line, buf);
  2279. errors++;
  2280. continue;
  2281. }
  2282. *pos = '\0';
  2283. pos++;
  2284. errors += hostapd_config_fill(conf, bss, buf, pos, line);
  2285. }
  2286. fclose(f);
  2287. for (i = 0; i < conf->num_bss; i++)
  2288. hostapd_set_security_params(&conf->bss[i]);
  2289. if (hostapd_config_check(conf))
  2290. errors++;
  2291. #ifndef WPA_IGNORE_CONFIG_ERRORS
  2292. if (errors) {
  2293. wpa_printf(MSG_ERROR, "%d errors found in configuration file "
  2294. "'%s'", errors, fname);
  2295. hostapd_config_free(conf);
  2296. conf = NULL;
  2297. }
  2298. #endif /* WPA_IGNORE_CONFIG_ERRORS */
  2299. return conf;
  2300. }
  2301. int hostapd_set_iface(struct hostapd_config *conf,
  2302. struct hostapd_bss_config *bss, char *field, char *value)
  2303. {
  2304. int errors;
  2305. size_t i;
  2306. errors = hostapd_config_fill(conf, bss, field, value, 0);
  2307. if (errors) {
  2308. wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
  2309. "to value '%s'", field, value);
  2310. return -1;
  2311. }
  2312. for (i = 0; i < conf->num_bss; i++)
  2313. hostapd_set_security_params(&conf->bss[i]);
  2314. if (hostapd_config_check(conf)) {
  2315. wpa_printf(MSG_ERROR, "Configuration check failed");
  2316. return -1;
  2317. }
  2318. return 0;
  2319. }