config.c 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246
  1. /*
  2. * hostapd / Configuration file
  3. * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #include "includes.h"
  15. #ifndef CONFIG_NATIVE_WINDOWS
  16. #include <grp.h>
  17. #endif /* CONFIG_NATIVE_WINDOWS */
  18. #include "hostapd.h"
  19. #include "driver.h"
  20. #include "sha1.h"
  21. #include "eap_server/eap.h"
  22. #include "radius/radius_client.h"
  23. #include "wpa_common.h"
  24. #include "wpa.h"
  25. #include "uuid.h"
  26. #define MAX_STA_COUNT 2007
  27. extern struct wpa_driver_ops *hostapd_drivers[];
  28. static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
  29. const char *fname)
  30. {
  31. FILE *f;
  32. char buf[128], *pos, *pos2;
  33. int line = 0, vlan_id;
  34. struct hostapd_vlan *vlan;
  35. f = fopen(fname, "r");
  36. if (!f) {
  37. printf("VLAN file '%s' not readable.\n", fname);
  38. return -1;
  39. }
  40. while (fgets(buf, sizeof(buf), f)) {
  41. line++;
  42. if (buf[0] == '#')
  43. continue;
  44. pos = buf;
  45. while (*pos != '\0') {
  46. if (*pos == '\n') {
  47. *pos = '\0';
  48. break;
  49. }
  50. pos++;
  51. }
  52. if (buf[0] == '\0')
  53. continue;
  54. if (buf[0] == '*') {
  55. vlan_id = VLAN_ID_WILDCARD;
  56. pos = buf + 1;
  57. } else {
  58. vlan_id = strtol(buf, &pos, 10);
  59. if (buf == pos || vlan_id < 1 ||
  60. vlan_id > MAX_VLAN_ID) {
  61. printf("Invalid VLAN ID at line %d in '%s'\n",
  62. line, fname);
  63. fclose(f);
  64. return -1;
  65. }
  66. }
  67. while (*pos == ' ' || *pos == '\t')
  68. pos++;
  69. pos2 = pos;
  70. while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
  71. pos2++;
  72. *pos2 = '\0';
  73. if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
  74. printf("Invalid VLAN ifname at line %d in '%s'\n",
  75. line, fname);
  76. fclose(f);
  77. return -1;
  78. }
  79. vlan = os_malloc(sizeof(*vlan));
  80. if (vlan == NULL) {
  81. printf("Out of memory while reading VLAN interfaces "
  82. "from '%s'\n", fname);
  83. fclose(f);
  84. return -1;
  85. }
  86. os_memset(vlan, 0, sizeof(*vlan));
  87. vlan->vlan_id = vlan_id;
  88. os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
  89. if (bss->vlan_tail)
  90. bss->vlan_tail->next = vlan;
  91. else
  92. bss->vlan = vlan;
  93. bss->vlan_tail = vlan;
  94. }
  95. fclose(f);
  96. return 0;
  97. }
  98. static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
  99. {
  100. struct hostapd_vlan *vlan, *prev;
  101. vlan = bss->vlan;
  102. prev = NULL;
  103. while (vlan) {
  104. prev = vlan;
  105. vlan = vlan->next;
  106. os_free(prev);
  107. }
  108. bss->vlan = NULL;
  109. }
  110. /* convert floats with one decimal place to value*10 int, i.e.,
  111. * "1.5" will return 15 */
  112. static int hostapd_config_read_int10(const char *value)
  113. {
  114. int i, d;
  115. char *pos;
  116. i = atoi(value);
  117. pos = os_strchr(value, '.');
  118. d = 0;
  119. if (pos) {
  120. pos++;
  121. if (*pos >= '0' && *pos <= '9')
  122. d = *pos - '0';
  123. }
  124. return i * 10 + d;
  125. }
  126. static void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
  127. {
  128. bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
  129. bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
  130. bss->logger_syslog = (unsigned int) -1;
  131. bss->logger_stdout = (unsigned int) -1;
  132. bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
  133. bss->wep_rekeying_period = 300;
  134. /* use key0 in individual key and key1 in broadcast key */
  135. bss->broadcast_key_idx_min = 1;
  136. bss->broadcast_key_idx_max = 2;
  137. bss->eap_reauth_period = 3600;
  138. bss->wpa_group_rekey = 600;
  139. bss->wpa_gmk_rekey = 86400;
  140. bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
  141. bss->wpa_pairwise = WPA_CIPHER_TKIP;
  142. bss->wpa_group = WPA_CIPHER_TKIP;
  143. bss->rsn_pairwise = 0;
  144. bss->max_num_sta = MAX_STA_COUNT;
  145. bss->dtim_period = 2;
  146. bss->radius_server_auth_port = 1812;
  147. bss->ap_max_inactivity = AP_MAX_INACTIVITY;
  148. bss->eapol_version = EAPOL_VERSION;
  149. bss->max_listen_interval = 65535;
  150. }
  151. static struct hostapd_config * hostapd_config_defaults(void)
  152. {
  153. struct hostapd_config *conf;
  154. struct hostapd_bss_config *bss;
  155. int i;
  156. const int aCWmin = 15, aCWmax = 1024;
  157. const struct hostapd_wme_ac_params ac_bk =
  158. { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
  159. const struct hostapd_wme_ac_params ac_be =
  160. { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
  161. const struct hostapd_wme_ac_params ac_vi = /* video traffic */
  162. { aCWmin >> 1, aCWmin, 2, 3000 / 32, 1 };
  163. const struct hostapd_wme_ac_params ac_vo = /* voice traffic */
  164. { aCWmin >> 2, aCWmin >> 1, 2, 1500 / 32, 1 };
  165. conf = os_zalloc(sizeof(*conf));
  166. bss = os_zalloc(sizeof(*bss));
  167. if (conf == NULL || bss == NULL) {
  168. printf("Failed to allocate memory for configuration data.\n");
  169. os_free(conf);
  170. os_free(bss);
  171. return NULL;
  172. }
  173. /* set default driver based on configuration */
  174. conf->driver = hostapd_drivers[0];
  175. if (conf->driver == NULL) {
  176. printf("No driver wrappers registered!\n");
  177. os_free(conf);
  178. os_free(bss);
  179. return NULL;
  180. }
  181. bss->radius = os_zalloc(sizeof(*bss->radius));
  182. if (bss->radius == NULL) {
  183. os_free(conf);
  184. os_free(bss);
  185. return NULL;
  186. }
  187. hostapd_config_defaults_bss(bss);
  188. conf->num_bss = 1;
  189. conf->bss = bss;
  190. conf->beacon_int = 100;
  191. conf->rts_threshold = -1; /* use driver default: 2347 */
  192. conf->fragm_threshold = -1; /* user driver default: 2346 */
  193. conf->send_probe_response = 1;
  194. conf->bridge_packets = INTERNAL_BRIDGE_DO_NOT_CONTROL;
  195. os_memcpy(conf->country, "US ", 3);
  196. for (i = 0; i < NUM_TX_QUEUES; i++)
  197. conf->tx_queue[i].aifs = -1; /* use hw default */
  198. conf->wme_ac_params[0] = ac_be;
  199. conf->wme_ac_params[1] = ac_bk;
  200. conf->wme_ac_params[2] = ac_vi;
  201. conf->wme_ac_params[3] = ac_vo;
  202. return conf;
  203. }
  204. int hostapd_mac_comp(const void *a, const void *b)
  205. {
  206. return os_memcmp(a, b, sizeof(macaddr));
  207. }
  208. int hostapd_mac_comp_empty(const void *a)
  209. {
  210. macaddr empty = { 0 };
  211. return os_memcmp(a, empty, sizeof(macaddr));
  212. }
  213. static int hostapd_config_read_maclist(const char *fname, macaddr **acl,
  214. int *num)
  215. {
  216. FILE *f;
  217. char buf[128], *pos;
  218. int line = 0;
  219. u8 addr[ETH_ALEN];
  220. macaddr *newacl;
  221. if (!fname)
  222. return 0;
  223. f = fopen(fname, "r");
  224. if (!f) {
  225. printf("MAC list file '%s' not found.\n", fname);
  226. return -1;
  227. }
  228. while (fgets(buf, sizeof(buf), f)) {
  229. line++;
  230. if (buf[0] == '#')
  231. continue;
  232. pos = buf;
  233. while (*pos != '\0') {
  234. if (*pos == '\n') {
  235. *pos = '\0';
  236. break;
  237. }
  238. pos++;
  239. }
  240. if (buf[0] == '\0')
  241. continue;
  242. if (hwaddr_aton(buf, addr)) {
  243. printf("Invalid MAC address '%s' at line %d in '%s'\n",
  244. buf, line, fname);
  245. fclose(f);
  246. return -1;
  247. }
  248. newacl = os_realloc(*acl, (*num + 1) * ETH_ALEN);
  249. if (newacl == NULL) {
  250. printf("MAC list reallocation failed\n");
  251. fclose(f);
  252. return -1;
  253. }
  254. *acl = newacl;
  255. os_memcpy((*acl)[*num], addr, ETH_ALEN);
  256. (*num)++;
  257. }
  258. fclose(f);
  259. qsort(*acl, *num, sizeof(macaddr), hostapd_mac_comp);
  260. return 0;
  261. }
  262. static int hostapd_config_read_wpa_psk(const char *fname,
  263. struct hostapd_ssid *ssid)
  264. {
  265. FILE *f;
  266. char buf[128], *pos;
  267. int line = 0, ret = 0, len, ok;
  268. u8 addr[ETH_ALEN];
  269. struct hostapd_wpa_psk *psk;
  270. if (!fname)
  271. return 0;
  272. f = fopen(fname, "r");
  273. if (!f) {
  274. printf("WPA PSK file '%s' not found.\n", fname);
  275. return -1;
  276. }
  277. while (fgets(buf, sizeof(buf), f)) {
  278. line++;
  279. if (buf[0] == '#')
  280. continue;
  281. pos = buf;
  282. while (*pos != '\0') {
  283. if (*pos == '\n') {
  284. *pos = '\0';
  285. break;
  286. }
  287. pos++;
  288. }
  289. if (buf[0] == '\0')
  290. continue;
  291. if (hwaddr_aton(buf, addr)) {
  292. printf("Invalid MAC address '%s' on line %d in '%s'\n",
  293. buf, line, fname);
  294. ret = -1;
  295. break;
  296. }
  297. psk = os_zalloc(sizeof(*psk));
  298. if (psk == NULL) {
  299. printf("WPA PSK allocation failed\n");
  300. ret = -1;
  301. break;
  302. }
  303. if (os_memcmp(addr, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0)
  304. psk->group = 1;
  305. else
  306. os_memcpy(psk->addr, addr, ETH_ALEN);
  307. pos = buf + 17;
  308. if (pos == '\0') {
  309. printf("No PSK on line %d in '%s'\n", line, fname);
  310. os_free(psk);
  311. ret = -1;
  312. break;
  313. }
  314. pos++;
  315. ok = 0;
  316. len = os_strlen(pos);
  317. if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
  318. ok = 1;
  319. else if (len >= 8 && len < 64) {
  320. pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
  321. 4096, psk->psk, PMK_LEN);
  322. ok = 1;
  323. }
  324. if (!ok) {
  325. printf("Invalid PSK '%s' on line %d in '%s'\n",
  326. pos, line, fname);
  327. os_free(psk);
  328. ret = -1;
  329. break;
  330. }
  331. psk->next = ssid->wpa_psk;
  332. ssid->wpa_psk = psk;
  333. }
  334. fclose(f);
  335. return ret;
  336. }
  337. int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
  338. {
  339. struct hostapd_ssid *ssid = &conf->ssid;
  340. if (ssid->wpa_passphrase != NULL) {
  341. if (ssid->wpa_psk != NULL) {
  342. printf("Warning: both WPA PSK and passphrase set. "
  343. "Using passphrase.\n");
  344. os_free(ssid->wpa_psk);
  345. }
  346. ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
  347. if (ssid->wpa_psk == NULL) {
  348. printf("Unable to alloc space for PSK\n");
  349. return -1;
  350. }
  351. wpa_hexdump_ascii(MSG_DEBUG, "SSID",
  352. (u8 *) ssid->ssid, ssid->ssid_len);
  353. wpa_hexdump_ascii(MSG_DEBUG, "PSK (ASCII passphrase)",
  354. (u8 *) ssid->wpa_passphrase,
  355. os_strlen(ssid->wpa_passphrase));
  356. pbkdf2_sha1(ssid->wpa_passphrase,
  357. ssid->ssid, ssid->ssid_len,
  358. 4096, ssid->wpa_psk->psk, PMK_LEN);
  359. wpa_hexdump(MSG_DEBUG, "PSK (from passphrase)",
  360. ssid->wpa_psk->psk, PMK_LEN);
  361. ssid->wpa_psk->group = 1;
  362. os_memset(ssid->wpa_passphrase, 0,
  363. os_strlen(ssid->wpa_passphrase));
  364. os_free(ssid->wpa_passphrase);
  365. ssid->wpa_passphrase = NULL;
  366. }
  367. if (ssid->wpa_psk_file) {
  368. if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
  369. &conf->ssid))
  370. return -1;
  371. }
  372. return 0;
  373. }
  374. #ifdef EAP_SERVER
  375. static int hostapd_config_read_eap_user(const char *fname,
  376. struct hostapd_bss_config *conf)
  377. {
  378. FILE *f;
  379. char buf[512], *pos, *start, *pos2;
  380. int line = 0, ret = 0, num_methods;
  381. struct hostapd_eap_user *user, *tail = NULL;
  382. if (!fname)
  383. return 0;
  384. f = fopen(fname, "r");
  385. if (!f) {
  386. printf("EAP user file '%s' not found.\n", fname);
  387. return -1;
  388. }
  389. /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
  390. while (fgets(buf, sizeof(buf), f)) {
  391. line++;
  392. if (buf[0] == '#')
  393. continue;
  394. pos = buf;
  395. while (*pos != '\0') {
  396. if (*pos == '\n') {
  397. *pos = '\0';
  398. break;
  399. }
  400. pos++;
  401. }
  402. if (buf[0] == '\0')
  403. continue;
  404. user = NULL;
  405. if (buf[0] != '"' && buf[0] != '*') {
  406. printf("Invalid EAP identity (no \" in start) on "
  407. "line %d in '%s'\n", line, fname);
  408. goto failed;
  409. }
  410. user = os_zalloc(sizeof(*user));
  411. if (user == NULL) {
  412. printf("EAP user allocation failed\n");
  413. goto failed;
  414. }
  415. user->force_version = -1;
  416. if (buf[0] == '*') {
  417. pos = buf;
  418. } else {
  419. pos = buf + 1;
  420. start = pos;
  421. while (*pos != '"' && *pos != '\0')
  422. pos++;
  423. if (*pos == '\0') {
  424. printf("Invalid EAP identity (no \" in end) on"
  425. " line %d in '%s'\n", line, fname);
  426. goto failed;
  427. }
  428. user->identity = os_malloc(pos - start);
  429. if (user->identity == NULL) {
  430. printf("Failed to allocate memory for EAP "
  431. "identity\n");
  432. goto failed;
  433. }
  434. os_memcpy(user->identity, start, pos - start);
  435. user->identity_len = pos - start;
  436. if (pos[0] == '"' && pos[1] == '*') {
  437. user->wildcard_prefix = 1;
  438. pos++;
  439. }
  440. }
  441. pos++;
  442. while (*pos == ' ' || *pos == '\t')
  443. pos++;
  444. if (*pos == '\0') {
  445. printf("No EAP method on line %d in '%s'\n",
  446. line, fname);
  447. goto failed;
  448. }
  449. start = pos;
  450. while (*pos != ' ' && *pos != '\t' && *pos != '\0')
  451. pos++;
  452. if (*pos == '\0') {
  453. pos = NULL;
  454. } else {
  455. *pos = '\0';
  456. pos++;
  457. }
  458. num_methods = 0;
  459. while (*start) {
  460. char *pos3 = os_strchr(start, ',');
  461. if (pos3) {
  462. *pos3++ = '\0';
  463. }
  464. user->methods[num_methods].method =
  465. eap_server_get_type(
  466. start,
  467. &user->methods[num_methods].vendor);
  468. if (user->methods[num_methods].vendor ==
  469. EAP_VENDOR_IETF &&
  470. user->methods[num_methods].method == EAP_TYPE_NONE)
  471. {
  472. if (os_strcmp(start, "TTLS-PAP") == 0) {
  473. user->ttls_auth |= EAP_TTLS_AUTH_PAP;
  474. goto skip_eap;
  475. }
  476. if (os_strcmp(start, "TTLS-CHAP") == 0) {
  477. user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
  478. goto skip_eap;
  479. }
  480. if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
  481. user->ttls_auth |=
  482. EAP_TTLS_AUTH_MSCHAP;
  483. goto skip_eap;
  484. }
  485. if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
  486. user->ttls_auth |=
  487. EAP_TTLS_AUTH_MSCHAPV2;
  488. goto skip_eap;
  489. }
  490. printf("Unsupported EAP type '%s' on line %d "
  491. "in '%s'\n", start, line, fname);
  492. goto failed;
  493. }
  494. num_methods++;
  495. if (num_methods >= EAP_USER_MAX_METHODS)
  496. break;
  497. skip_eap:
  498. if (pos3 == NULL)
  499. break;
  500. start = pos3;
  501. }
  502. if (num_methods == 0 && user->ttls_auth == 0) {
  503. printf("No EAP types configured on line %d in '%s'\n",
  504. line, fname);
  505. goto failed;
  506. }
  507. if (pos == NULL)
  508. goto done;
  509. while (*pos == ' ' || *pos == '\t')
  510. pos++;
  511. if (*pos == '\0')
  512. goto done;
  513. if (os_strncmp(pos, "[ver=0]", 7) == 0) {
  514. user->force_version = 0;
  515. goto done;
  516. }
  517. if (os_strncmp(pos, "[ver=1]", 7) == 0) {
  518. user->force_version = 1;
  519. goto done;
  520. }
  521. if (os_strncmp(pos, "[2]", 3) == 0) {
  522. user->phase2 = 1;
  523. goto done;
  524. }
  525. if (*pos == '"') {
  526. pos++;
  527. start = pos;
  528. while (*pos != '"' && *pos != '\0')
  529. pos++;
  530. if (*pos == '\0') {
  531. printf("Invalid EAP password (no \" in end) "
  532. "on line %d in '%s'\n", line, fname);
  533. goto failed;
  534. }
  535. user->password = os_malloc(pos - start);
  536. if (user->password == NULL) {
  537. printf("Failed to allocate memory for EAP "
  538. "password\n");
  539. goto failed;
  540. }
  541. os_memcpy(user->password, start, pos - start);
  542. user->password_len = pos - start;
  543. pos++;
  544. } else if (os_strncmp(pos, "hash:", 5) == 0) {
  545. pos += 5;
  546. pos2 = pos;
  547. while (*pos2 != '\0' && *pos2 != ' ' &&
  548. *pos2 != '\t' && *pos2 != '#')
  549. pos2++;
  550. if (pos2 - pos != 32) {
  551. printf("Invalid password hash on line %d in "
  552. "'%s'\n", line, fname);
  553. goto failed;
  554. }
  555. user->password = os_malloc(16);
  556. if (user->password == NULL) {
  557. printf("Failed to allocate memory for EAP "
  558. "password hash\n");
  559. goto failed;
  560. }
  561. if (hexstr2bin(pos, user->password, 16) < 0) {
  562. printf("Invalid hash password on line %d in "
  563. "'%s'\n", line, fname);
  564. goto failed;
  565. }
  566. user->password_len = 16;
  567. user->password_hash = 1;
  568. pos = pos2;
  569. } else {
  570. pos2 = pos;
  571. while (*pos2 != '\0' && *pos2 != ' ' &&
  572. *pos2 != '\t' && *pos2 != '#')
  573. pos2++;
  574. if ((pos2 - pos) & 1) {
  575. printf("Invalid hex password on line %d in "
  576. "'%s'\n", line, fname);
  577. goto failed;
  578. }
  579. user->password = os_malloc((pos2 - pos) / 2);
  580. if (user->password == NULL) {
  581. printf("Failed to allocate memory for EAP "
  582. "password\n");
  583. goto failed;
  584. }
  585. if (hexstr2bin(pos, user->password,
  586. (pos2 - pos) / 2) < 0) {
  587. printf("Invalid hex password on line %d in "
  588. "'%s'\n", line, fname);
  589. goto failed;
  590. }
  591. user->password_len = (pos2 - pos) / 2;
  592. pos = pos2;
  593. }
  594. while (*pos == ' ' || *pos == '\t')
  595. pos++;
  596. if (os_strncmp(pos, "[2]", 3) == 0) {
  597. user->phase2 = 1;
  598. }
  599. done:
  600. if (tail == NULL) {
  601. tail = conf->eap_user = user;
  602. } else {
  603. tail->next = user;
  604. tail = user;
  605. }
  606. continue;
  607. failed:
  608. if (user) {
  609. os_free(user->password);
  610. os_free(user->identity);
  611. os_free(user);
  612. }
  613. ret = -1;
  614. break;
  615. }
  616. fclose(f);
  617. return ret;
  618. }
  619. #endif /* EAP_SERVER */
  620. static int
  621. hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
  622. int *num_server, const char *val, int def_port,
  623. struct hostapd_radius_server **curr_serv)
  624. {
  625. struct hostapd_radius_server *nserv;
  626. int ret;
  627. static int server_index = 1;
  628. nserv = os_realloc(*server, (*num_server + 1) * sizeof(*nserv));
  629. if (nserv == NULL)
  630. return -1;
  631. *server = nserv;
  632. nserv = &nserv[*num_server];
  633. (*num_server)++;
  634. (*curr_serv) = nserv;
  635. os_memset(nserv, 0, sizeof(*nserv));
  636. nserv->port = def_port;
  637. ret = hostapd_parse_ip_addr(val, &nserv->addr);
  638. nserv->index = server_index++;
  639. return ret;
  640. }
  641. static int hostapd_config_parse_key_mgmt(int line, const char *value)
  642. {
  643. int val = 0, last;
  644. char *start, *end, *buf;
  645. buf = os_strdup(value);
  646. if (buf == NULL)
  647. return -1;
  648. start = buf;
  649. while (start != '\0') {
  650. while (*start == ' ' || *start == '\t')
  651. start++;
  652. if (*start == '\0')
  653. break;
  654. end = start;
  655. while (*end != ' ' && *end != '\t' && *end != '\0')
  656. end++;
  657. last = *end == '\0';
  658. *end = '\0';
  659. if (os_strcmp(start, "WPA-PSK") == 0)
  660. val |= WPA_KEY_MGMT_PSK;
  661. else if (os_strcmp(start, "WPA-EAP") == 0)
  662. val |= WPA_KEY_MGMT_IEEE8021X;
  663. #ifdef CONFIG_IEEE80211R
  664. else if (os_strcmp(start, "FT-PSK") == 0)
  665. val |= WPA_KEY_MGMT_FT_PSK;
  666. else if (os_strcmp(start, "FT-EAP") == 0)
  667. val |= WPA_KEY_MGMT_FT_IEEE8021X;
  668. #endif /* CONFIG_IEEE80211R */
  669. else {
  670. printf("Line %d: invalid key_mgmt '%s'\n",
  671. line, start);
  672. os_free(buf);
  673. return -1;
  674. }
  675. if (last)
  676. break;
  677. start = end + 1;
  678. }
  679. os_free(buf);
  680. if (val == 0) {
  681. printf("Line %d: no key_mgmt values configured.\n", line);
  682. return -1;
  683. }
  684. return val;
  685. }
  686. static int hostapd_config_parse_cipher(int line, const char *value)
  687. {
  688. int val = 0, last;
  689. char *start, *end, *buf;
  690. buf = os_strdup(value);
  691. if (buf == NULL)
  692. return -1;
  693. start = buf;
  694. while (start != '\0') {
  695. while (*start == ' ' || *start == '\t')
  696. start++;
  697. if (*start == '\0')
  698. break;
  699. end = start;
  700. while (*end != ' ' && *end != '\t' && *end != '\0')
  701. end++;
  702. last = *end == '\0';
  703. *end = '\0';
  704. if (os_strcmp(start, "CCMP") == 0)
  705. val |= WPA_CIPHER_CCMP;
  706. else if (os_strcmp(start, "TKIP") == 0)
  707. val |= WPA_CIPHER_TKIP;
  708. else if (os_strcmp(start, "WEP104") == 0)
  709. val |= WPA_CIPHER_WEP104;
  710. else if (os_strcmp(start, "WEP40") == 0)
  711. val |= WPA_CIPHER_WEP40;
  712. else if (os_strcmp(start, "NONE") == 0)
  713. val |= WPA_CIPHER_NONE;
  714. else {
  715. printf("Line %d: invalid cipher '%s'.", line, start);
  716. os_free(buf);
  717. return -1;
  718. }
  719. if (last)
  720. break;
  721. start = end + 1;
  722. }
  723. os_free(buf);
  724. if (val == 0) {
  725. printf("Line %d: no cipher values configured.", line);
  726. return -1;
  727. }
  728. return val;
  729. }
  730. static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
  731. struct hostapd_config *conf)
  732. {
  733. if (bss->ieee802_1x && !bss->eap_server &&
  734. !bss->radius->auth_servers) {
  735. printf("Invalid IEEE 802.1X configuration (no EAP "
  736. "authenticator configured).\n");
  737. return -1;
  738. }
  739. if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
  740. bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
  741. bss->ssid.wpa_psk_file == NULL) {
  742. printf("WPA-PSK enabled, but PSK or passphrase is not "
  743. "configured.\n");
  744. return -1;
  745. }
  746. if (hostapd_mac_comp_empty(bss->bssid) != 0) {
  747. size_t i;
  748. for (i = 0; i < conf->num_bss; i++) {
  749. if ((&conf->bss[i] != bss) &&
  750. (hostapd_mac_comp(conf->bss[i].bssid,
  751. bss->bssid) == 0)) {
  752. printf("Duplicate BSSID " MACSTR
  753. " on interface '%s' and '%s'.\n",
  754. MAC2STR(bss->bssid),
  755. conf->bss[i].iface, bss->iface);
  756. return -1;
  757. }
  758. }
  759. }
  760. #ifdef CONFIG_IEEE80211R
  761. if ((bss->wpa_key_mgmt &
  762. (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
  763. (bss->nas_identifier == NULL ||
  764. os_strlen(bss->nas_identifier) < 1 ||
  765. os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
  766. printf("FT (IEEE 802.11r) requires nas_identifier to be "
  767. "configured as a 1..48 octet string\n");
  768. return -1;
  769. }
  770. #endif /* CONFIG_IEEE80211R */
  771. return 0;
  772. }
  773. static int hostapd_config_check(struct hostapd_config *conf)
  774. {
  775. size_t i;
  776. for (i = 0; i < conf->num_bss; i++) {
  777. if (hostapd_config_check_bss(&conf->bss[i], conf))
  778. return -1;
  779. }
  780. return 0;
  781. }
  782. static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
  783. char *val)
  784. {
  785. size_t len = os_strlen(val);
  786. if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
  787. return -1;
  788. if (val[0] == '"') {
  789. if (len < 2 || val[len - 1] != '"')
  790. return -1;
  791. len -= 2;
  792. wep->key[keyidx] = os_malloc(len);
  793. if (wep->key[keyidx] == NULL)
  794. return -1;
  795. os_memcpy(wep->key[keyidx], val + 1, len);
  796. wep->len[keyidx] = len;
  797. } else {
  798. if (len & 1)
  799. return -1;
  800. len /= 2;
  801. wep->key[keyidx] = os_malloc(len);
  802. if (wep->key[keyidx] == NULL)
  803. return -1;
  804. wep->len[keyidx] = len;
  805. if (hexstr2bin(val, wep->key[keyidx], len) < 0)
  806. return -1;
  807. }
  808. wep->keys_set++;
  809. return 0;
  810. }
  811. static int hostapd_parse_rates(int **rate_list, char *val)
  812. {
  813. int *list;
  814. int count;
  815. char *pos, *end;
  816. os_free(*rate_list);
  817. *rate_list = NULL;
  818. pos = val;
  819. count = 0;
  820. while (*pos != '\0') {
  821. if (*pos == ' ')
  822. count++;
  823. pos++;
  824. }
  825. list = os_malloc(sizeof(int) * (count + 2));
  826. if (list == NULL)
  827. return -1;
  828. pos = val;
  829. count = 0;
  830. while (*pos != '\0') {
  831. end = os_strchr(pos, ' ');
  832. if (end)
  833. *end = '\0';
  834. list[count++] = atoi(pos);
  835. if (!end)
  836. break;
  837. pos = end + 1;
  838. }
  839. list[count] = -1;
  840. *rate_list = list;
  841. return 0;
  842. }
  843. static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
  844. {
  845. struct hostapd_bss_config *bss;
  846. if (*ifname == '\0')
  847. return -1;
  848. bss = os_realloc(conf->bss, (conf->num_bss + 1) *
  849. sizeof(struct hostapd_bss_config));
  850. if (bss == NULL) {
  851. printf("Failed to allocate memory for multi-BSS entry\n");
  852. return -1;
  853. }
  854. conf->bss = bss;
  855. bss = &(conf->bss[conf->num_bss]);
  856. os_memset(bss, 0, sizeof(*bss));
  857. bss->radius = os_zalloc(sizeof(*bss->radius));
  858. if (bss->radius == NULL) {
  859. printf("Failed to allocate memory for multi-BSS RADIUS "
  860. "data\n");
  861. return -1;
  862. }
  863. conf->num_bss++;
  864. conf->last_bss = bss;
  865. hostapd_config_defaults_bss(bss);
  866. os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
  867. os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
  868. return 0;
  869. }
  870. static int valid_cw(int cw)
  871. {
  872. return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
  873. cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
  874. }
  875. enum {
  876. IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
  877. IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
  878. IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
  879. IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */
  880. IEEE80211_TX_QUEUE_DATA4 = 4,
  881. IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
  882. IEEE80211_TX_QUEUE_BEACON = 7
  883. };
  884. static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
  885. char *val)
  886. {
  887. int num;
  888. char *pos;
  889. struct hostapd_tx_queue_params *queue;
  890. /* skip 'tx_queue_' prefix */
  891. pos = name + 9;
  892. if (os_strncmp(pos, "data", 4) == 0 &&
  893. pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
  894. num = pos[4] - '0';
  895. pos += 6;
  896. } else if (os_strncmp(pos, "after_beacon_", 13) == 0) {
  897. num = IEEE80211_TX_QUEUE_AFTER_BEACON;
  898. pos += 13;
  899. } else if (os_strncmp(pos, "beacon_", 7) == 0) {
  900. num = IEEE80211_TX_QUEUE_BEACON;
  901. pos += 7;
  902. } else {
  903. printf("Unknown tx_queue name '%s'\n", pos);
  904. return -1;
  905. }
  906. queue = &conf->tx_queue[num];
  907. if (os_strcmp(pos, "aifs") == 0) {
  908. queue->aifs = atoi(val);
  909. if (queue->aifs < 0 || queue->aifs > 255) {
  910. printf("Invalid AIFS value %d\n", queue->aifs);
  911. return -1;
  912. }
  913. } else if (os_strcmp(pos, "cwmin") == 0) {
  914. queue->cwmin = atoi(val);
  915. if (!valid_cw(queue->cwmin)) {
  916. printf("Invalid cwMin value %d\n", queue->cwmin);
  917. return -1;
  918. }
  919. } else if (os_strcmp(pos, "cwmax") == 0) {
  920. queue->cwmax = atoi(val);
  921. if (!valid_cw(queue->cwmax)) {
  922. printf("Invalid cwMax value %d\n", queue->cwmax);
  923. return -1;
  924. }
  925. } else if (os_strcmp(pos, "burst") == 0) {
  926. queue->burst = hostapd_config_read_int10(val);
  927. } else {
  928. printf("Unknown tx_queue field '%s'\n", pos);
  929. return -1;
  930. }
  931. queue->configured = 1;
  932. return 0;
  933. }
  934. static int hostapd_config_wme_ac(struct hostapd_config *conf, char *name,
  935. char *val)
  936. {
  937. int num, v;
  938. char *pos;
  939. struct hostapd_wme_ac_params *ac;
  940. /* skip 'wme_ac_' prefix */
  941. pos = name + 7;
  942. if (os_strncmp(pos, "be_", 3) == 0) {
  943. num = 0;
  944. pos += 3;
  945. } else if (os_strncmp(pos, "bk_", 3) == 0) {
  946. num = 1;
  947. pos += 3;
  948. } else if (os_strncmp(pos, "vi_", 3) == 0) {
  949. num = 2;
  950. pos += 3;
  951. } else if (os_strncmp(pos, "vo_", 3) == 0) {
  952. num = 3;
  953. pos += 3;
  954. } else {
  955. printf("Unknown wme name '%s'\n", pos);
  956. return -1;
  957. }
  958. ac = &conf->wme_ac_params[num];
  959. if (os_strcmp(pos, "aifs") == 0) {
  960. v = atoi(val);
  961. if (v < 1 || v > 255) {
  962. printf("Invalid AIFS value %d\n", v);
  963. return -1;
  964. }
  965. ac->aifs = v;
  966. } else if (os_strcmp(pos, "cwmin") == 0) {
  967. v = atoi(val);
  968. if (v < 0 || v > 12) {
  969. printf("Invalid cwMin value %d\n", v);
  970. return -1;
  971. }
  972. ac->cwmin = v;
  973. } else if (os_strcmp(pos, "cwmax") == 0) {
  974. v = atoi(val);
  975. if (v < 0 || v > 12) {
  976. printf("Invalid cwMax value %d\n", v);
  977. return -1;
  978. }
  979. ac->cwmax = v;
  980. } else if (os_strcmp(pos, "txop_limit") == 0) {
  981. v = atoi(val);
  982. if (v < 0 || v > 0xffff) {
  983. printf("Invalid txop value %d\n", v);
  984. return -1;
  985. }
  986. ac->txopLimit = v;
  987. } else if (os_strcmp(pos, "acm") == 0) {
  988. v = atoi(val);
  989. if (v < 0 || v > 1) {
  990. printf("Invalid acm value %d\n", v);
  991. return -1;
  992. }
  993. ac->admission_control_mandatory = v;
  994. } else {
  995. printf("Unknown wme_ac_ field '%s'\n", pos);
  996. return -1;
  997. }
  998. return 0;
  999. }
  1000. #ifdef CONFIG_IEEE80211R
  1001. static int add_r0kh(struct hostapd_bss_config *bss, char *value)
  1002. {
  1003. struct ft_remote_r0kh *r0kh;
  1004. char *pos, *next;
  1005. r0kh = os_zalloc(sizeof(*r0kh));
  1006. if (r0kh == NULL)
  1007. return -1;
  1008. /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
  1009. pos = value;
  1010. next = os_strchr(pos, ' ');
  1011. if (next)
  1012. *next++ = '\0';
  1013. if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
  1014. printf("Invalid R0KH MAC address: '%s'\n", pos);
  1015. os_free(r0kh);
  1016. return -1;
  1017. }
  1018. pos = next;
  1019. next = os_strchr(pos, ' ');
  1020. if (next)
  1021. *next++ = '\0';
  1022. if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
  1023. printf("Invalid R0KH-ID: '%s'\n", pos);
  1024. os_free(r0kh);
  1025. return -1;
  1026. }
  1027. r0kh->id_len = next - pos - 1;
  1028. os_memcpy(r0kh->id, pos, r0kh->id_len);
  1029. pos = next;
  1030. if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
  1031. printf("Invalid R0KH key: '%s'\n", pos);
  1032. os_free(r0kh);
  1033. return -1;
  1034. }
  1035. r0kh->next = bss->r0kh_list;
  1036. bss->r0kh_list = r0kh;
  1037. return 0;
  1038. }
  1039. static int add_r1kh(struct hostapd_bss_config *bss, char *value)
  1040. {
  1041. struct ft_remote_r1kh *r1kh;
  1042. char *pos, *next;
  1043. r1kh = os_zalloc(sizeof(*r1kh));
  1044. if (r1kh == NULL)
  1045. return -1;
  1046. /* 02:01:02:03:04:05 02:01:02:03:04:05
  1047. * 000102030405060708090a0b0c0d0e0f */
  1048. pos = value;
  1049. next = os_strchr(pos, ' ');
  1050. if (next)
  1051. *next++ = '\0';
  1052. if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
  1053. printf("Invalid R1KH MAC address: '%s'\n", pos);
  1054. os_free(r1kh);
  1055. return -1;
  1056. }
  1057. pos = next;
  1058. next = os_strchr(pos, ' ');
  1059. if (next)
  1060. *next++ = '\0';
  1061. if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
  1062. printf("Invalid R1KH-ID: '%s'\n", pos);
  1063. os_free(r1kh);
  1064. return -1;
  1065. }
  1066. pos = next;
  1067. if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
  1068. printf("Invalid R1KH key: '%s'\n", pos);
  1069. os_free(r1kh);
  1070. return -1;
  1071. }
  1072. r1kh->next = bss->r1kh_list;
  1073. bss->r1kh_list = r1kh;
  1074. return 0;
  1075. }
  1076. #endif /* CONFIG_IEEE80211R */
  1077. struct hostapd_config * hostapd_config_read(const char *fname)
  1078. {
  1079. struct hostapd_config *conf;
  1080. struct hostapd_bss_config *bss;
  1081. FILE *f;
  1082. char buf[256], *pos;
  1083. int line = 0;
  1084. int errors = 0;
  1085. int pairwise;
  1086. size_t i;
  1087. f = fopen(fname, "r");
  1088. if (f == NULL) {
  1089. printf("Could not open configuration file '%s' for reading.\n",
  1090. fname);
  1091. return NULL;
  1092. }
  1093. conf = hostapd_config_defaults();
  1094. if (conf == NULL) {
  1095. fclose(f);
  1096. return NULL;
  1097. }
  1098. bss = conf->last_bss = conf->bss;
  1099. while (fgets(buf, sizeof(buf), f)) {
  1100. bss = conf->last_bss;
  1101. line++;
  1102. if (buf[0] == '#')
  1103. continue;
  1104. pos = buf;
  1105. while (*pos != '\0') {
  1106. if (*pos == '\n') {
  1107. *pos = '\0';
  1108. break;
  1109. }
  1110. pos++;
  1111. }
  1112. if (buf[0] == '\0')
  1113. continue;
  1114. pos = os_strchr(buf, '=');
  1115. if (pos == NULL) {
  1116. printf("Line %d: invalid line '%s'\n", line, buf);
  1117. errors++;
  1118. continue;
  1119. }
  1120. *pos = '\0';
  1121. pos++;
  1122. if (os_strcmp(buf, "interface") == 0) {
  1123. os_strlcpy(conf->bss[0].iface, pos,
  1124. sizeof(conf->bss[0].iface));
  1125. } else if (os_strcmp(buf, "bridge") == 0) {
  1126. os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
  1127. } else if (os_strcmp(buf, "driver") == 0) {
  1128. int i;
  1129. /* clear to get error below if setting is invalid */
  1130. conf->driver = NULL;
  1131. for (i = 0; hostapd_drivers[i]; i++) {
  1132. if (os_strcmp(pos, hostapd_drivers[i]->name) ==
  1133. 0) {
  1134. conf->driver = hostapd_drivers[i];
  1135. break;
  1136. }
  1137. }
  1138. if (conf->driver == NULL) {
  1139. printf("Line %d: invalid/unknown driver "
  1140. "'%s'\n", line, pos);
  1141. errors++;
  1142. }
  1143. } else if (os_strcmp(buf, "debug") == 0) {
  1144. wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
  1145. "configuration variable is not used "
  1146. "anymore", line);
  1147. } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
  1148. bss->logger_syslog_level = atoi(pos);
  1149. } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
  1150. bss->logger_stdout_level = atoi(pos);
  1151. } else if (os_strcmp(buf, "logger_syslog") == 0) {
  1152. bss->logger_syslog = atoi(pos);
  1153. } else if (os_strcmp(buf, "logger_stdout") == 0) {
  1154. bss->logger_stdout = atoi(pos);
  1155. } else if (os_strcmp(buf, "dump_file") == 0) {
  1156. bss->dump_log_name = os_strdup(pos);
  1157. } else if (os_strcmp(buf, "ssid") == 0) {
  1158. bss->ssid.ssid_len = os_strlen(pos);
  1159. if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
  1160. bss->ssid.ssid_len < 1) {
  1161. printf("Line %d: invalid SSID '%s'\n", line,
  1162. pos);
  1163. errors++;
  1164. } else {
  1165. os_memcpy(bss->ssid.ssid, pos,
  1166. bss->ssid.ssid_len);
  1167. bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
  1168. bss->ssid.ssid_set = 1;
  1169. }
  1170. } else if (os_strcmp(buf, "macaddr_acl") == 0) {
  1171. bss->macaddr_acl = atoi(pos);
  1172. if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
  1173. bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
  1174. bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
  1175. printf("Line %d: unknown macaddr_acl %d\n",
  1176. line, bss->macaddr_acl);
  1177. }
  1178. } else if (os_strcmp(buf, "accept_mac_file") == 0) {
  1179. if (hostapd_config_read_maclist(pos, &bss->accept_mac,
  1180. &bss->num_accept_mac))
  1181. {
  1182. printf("Line %d: Failed to read "
  1183. "accept_mac_file '%s'\n",
  1184. line, pos);
  1185. errors++;
  1186. }
  1187. } else if (os_strcmp(buf, "deny_mac_file") == 0) {
  1188. if (hostapd_config_read_maclist(pos, &bss->deny_mac,
  1189. &bss->num_deny_mac))
  1190. {
  1191. printf("Line %d: Failed to read "
  1192. "deny_mac_file '%s'\n",
  1193. line, pos);
  1194. errors++;
  1195. }
  1196. } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
  1197. bss->ap_max_inactivity = atoi(pos);
  1198. } else if (os_strcmp(buf, "country_code") == 0) {
  1199. os_memcpy(conf->country, pos, 2);
  1200. /* FIX: make this configurable */
  1201. conf->country[2] = ' ';
  1202. } else if (os_strcmp(buf, "ieee80211d") == 0) {
  1203. conf->ieee80211d = atoi(pos);
  1204. } else if (os_strcmp(buf, "ieee80211h") == 0) {
  1205. conf->ieee80211h = atoi(pos);
  1206. } else if (os_strcmp(buf, "assoc_ap_addr") == 0) {
  1207. if (hwaddr_aton(pos, bss->assoc_ap_addr)) {
  1208. printf("Line %d: invalid MAC address '%s'\n",
  1209. line, pos);
  1210. errors++;
  1211. }
  1212. bss->assoc_ap = 1;
  1213. } else if (os_strcmp(buf, "ieee8021x") == 0) {
  1214. bss->ieee802_1x = atoi(pos);
  1215. } else if (os_strcmp(buf, "eapol_version") == 0) {
  1216. bss->eapol_version = atoi(pos);
  1217. if (bss->eapol_version < 1 ||
  1218. bss->eapol_version > 2) {
  1219. printf("Line %d: invalid EAPOL "
  1220. "version (%d): '%s'.\n",
  1221. line, bss->eapol_version, pos);
  1222. errors++;
  1223. } else
  1224. wpa_printf(MSG_DEBUG, "eapol_version=%d",
  1225. bss->eapol_version);
  1226. #ifdef EAP_SERVER
  1227. } else if (os_strcmp(buf, "eap_authenticator") == 0) {
  1228. bss->eap_server = atoi(pos);
  1229. printf("Line %d: obsolete eap_authenticator used; "
  1230. "this has been renamed to eap_server\n", line);
  1231. } else if (os_strcmp(buf, "eap_server") == 0) {
  1232. bss->eap_server = atoi(pos);
  1233. } else if (os_strcmp(buf, "eap_user_file") == 0) {
  1234. if (hostapd_config_read_eap_user(pos, bss))
  1235. errors++;
  1236. } else if (os_strcmp(buf, "ca_cert") == 0) {
  1237. os_free(bss->ca_cert);
  1238. bss->ca_cert = os_strdup(pos);
  1239. } else if (os_strcmp(buf, "server_cert") == 0) {
  1240. os_free(bss->server_cert);
  1241. bss->server_cert = os_strdup(pos);
  1242. } else if (os_strcmp(buf, "private_key") == 0) {
  1243. os_free(bss->private_key);
  1244. bss->private_key = os_strdup(pos);
  1245. } else if (os_strcmp(buf, "private_key_passwd") == 0) {
  1246. os_free(bss->private_key_passwd);
  1247. bss->private_key_passwd = os_strdup(pos);
  1248. } else if (os_strcmp(buf, "check_crl") == 0) {
  1249. bss->check_crl = atoi(pos);
  1250. } else if (os_strcmp(buf, "dh_file") == 0) {
  1251. os_free(bss->dh_file);
  1252. bss->dh_file = os_strdup(pos);
  1253. #ifdef EAP_FAST
  1254. } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
  1255. os_free(bss->pac_opaque_encr_key);
  1256. bss->pac_opaque_encr_key = os_malloc(16);
  1257. if (bss->pac_opaque_encr_key == NULL) {
  1258. printf("Line %d: No memory for "
  1259. "pac_opque_encr_key\n", line);
  1260. errors++;
  1261. } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
  1262. 16)) {
  1263. printf("Line %d: Invalid pac_opque_encr_key\n",
  1264. line);
  1265. errors++;
  1266. }
  1267. } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
  1268. os_free(bss->eap_fast_a_id);
  1269. bss->eap_fast_a_id = os_strdup(pos);
  1270. #endif /* EAP_FAST */
  1271. #ifdef EAP_SIM
  1272. } else if (os_strcmp(buf, "eap_sim_db") == 0) {
  1273. os_free(bss->eap_sim_db);
  1274. bss->eap_sim_db = os_strdup(pos);
  1275. } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
  1276. bss->eap_sim_aka_result_ind = atoi(pos);
  1277. #endif /* EAP_SIM */
  1278. #ifdef EAP_TNC
  1279. } else if (os_strcmp(buf, "tnc") == 0) {
  1280. bss->tnc = atoi(pos);
  1281. #endif /* EAP_TNC */
  1282. #endif /* EAP_SERVER */
  1283. } else if (os_strcmp(buf, "eap_message") == 0) {
  1284. char *term;
  1285. bss->eap_req_id_text = os_strdup(pos);
  1286. if (bss->eap_req_id_text == NULL) {
  1287. printf("Line %d: Failed to allocate memory "
  1288. "for eap_req_id_text\n", line);
  1289. errors++;
  1290. continue;
  1291. }
  1292. bss->eap_req_id_text_len =
  1293. os_strlen(bss->eap_req_id_text);
  1294. term = os_strstr(bss->eap_req_id_text, "\\0");
  1295. if (term) {
  1296. *term++ = '\0';
  1297. os_memmove(term, term + 1,
  1298. bss->eap_req_id_text_len -
  1299. (term - bss->eap_req_id_text) - 1);
  1300. bss->eap_req_id_text_len--;
  1301. }
  1302. } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
  1303. bss->default_wep_key_len = atoi(pos);
  1304. if (bss->default_wep_key_len > 13) {
  1305. printf("Line %d: invalid WEP key len %lu "
  1306. "(= %lu bits)\n", line,
  1307. (unsigned long)
  1308. bss->default_wep_key_len,
  1309. (unsigned long)
  1310. bss->default_wep_key_len * 8);
  1311. errors++;
  1312. }
  1313. } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
  1314. bss->individual_wep_key_len = atoi(pos);
  1315. if (bss->individual_wep_key_len < 0 ||
  1316. bss->individual_wep_key_len > 13) {
  1317. printf("Line %d: invalid WEP key len %d "
  1318. "(= %d bits)\n", line,
  1319. bss->individual_wep_key_len,
  1320. bss->individual_wep_key_len * 8);
  1321. errors++;
  1322. }
  1323. } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
  1324. bss->wep_rekeying_period = atoi(pos);
  1325. if (bss->wep_rekeying_period < 0) {
  1326. printf("Line %d: invalid period %d\n",
  1327. line, bss->wep_rekeying_period);
  1328. errors++;
  1329. }
  1330. } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
  1331. bss->eap_reauth_period = atoi(pos);
  1332. if (bss->eap_reauth_period < 0) {
  1333. printf("Line %d: invalid period %d\n",
  1334. line, bss->eap_reauth_period);
  1335. errors++;
  1336. }
  1337. } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
  1338. bss->eapol_key_index_workaround = atoi(pos);
  1339. #ifdef CONFIG_IAPP
  1340. } else if (os_strcmp(buf, "iapp_interface") == 0) {
  1341. bss->ieee802_11f = 1;
  1342. os_strlcpy(bss->iapp_iface, pos,
  1343. sizeof(bss->iapp_iface));
  1344. #endif /* CONFIG_IAPP */
  1345. } else if (os_strcmp(buf, "own_ip_addr") == 0) {
  1346. if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
  1347. printf("Line %d: invalid IP address '%s'\n",
  1348. line, pos);
  1349. errors++;
  1350. }
  1351. } else if (os_strcmp(buf, "nas_identifier") == 0) {
  1352. bss->nas_identifier = os_strdup(pos);
  1353. } else if (os_strcmp(buf, "auth_server_addr") == 0) {
  1354. if (hostapd_config_read_radius_addr(
  1355. &bss->radius->auth_servers,
  1356. &bss->radius->num_auth_servers, pos, 1812,
  1357. &bss->radius->auth_server)) {
  1358. printf("Line %d: invalid IP address '%s'\n",
  1359. line, pos);
  1360. errors++;
  1361. }
  1362. } else if (bss->radius->auth_server &&
  1363. os_strcmp(buf, "auth_server_port") == 0) {
  1364. bss->radius->auth_server->port = atoi(pos);
  1365. } else if (bss->radius->auth_server &&
  1366. os_strcmp(buf, "auth_server_shared_secret") == 0) {
  1367. int len = os_strlen(pos);
  1368. if (len == 0) {
  1369. /* RFC 2865, Ch. 3 */
  1370. printf("Line %d: empty shared secret is not "
  1371. "allowed.\n", line);
  1372. errors++;
  1373. }
  1374. bss->radius->auth_server->shared_secret =
  1375. (u8 *) os_strdup(pos);
  1376. bss->radius->auth_server->shared_secret_len = len;
  1377. } else if (os_strcmp(buf, "acct_server_addr") == 0) {
  1378. if (hostapd_config_read_radius_addr(
  1379. &bss->radius->acct_servers,
  1380. &bss->radius->num_acct_servers, pos, 1813,
  1381. &bss->radius->acct_server)) {
  1382. printf("Line %d: invalid IP address '%s'\n",
  1383. line, pos);
  1384. errors++;
  1385. }
  1386. } else if (bss->radius->acct_server &&
  1387. os_strcmp(buf, "acct_server_port") == 0) {
  1388. bss->radius->acct_server->port = atoi(pos);
  1389. } else if (bss->radius->acct_server &&
  1390. os_strcmp(buf, "acct_server_shared_secret") == 0) {
  1391. int len = os_strlen(pos);
  1392. if (len == 0) {
  1393. /* RFC 2865, Ch. 3 */
  1394. printf("Line %d: empty shared secret is not "
  1395. "allowed.\n", line);
  1396. errors++;
  1397. }
  1398. bss->radius->acct_server->shared_secret =
  1399. (u8 *) os_strdup(pos);
  1400. bss->radius->acct_server->shared_secret_len = len;
  1401. } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
  1402. 0) {
  1403. bss->radius->retry_primary_interval = atoi(pos);
  1404. } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
  1405. {
  1406. bss->radius->acct_interim_interval = atoi(pos);
  1407. } else if (os_strcmp(buf, "auth_algs") == 0) {
  1408. bss->auth_algs = atoi(pos);
  1409. if (bss->auth_algs == 0) {
  1410. printf("Line %d: no authentication algorithms "
  1411. "allowed\n",
  1412. line);
  1413. errors++;
  1414. }
  1415. } else if (os_strcmp(buf, "max_num_sta") == 0) {
  1416. bss->max_num_sta = atoi(pos);
  1417. if (bss->max_num_sta < 0 ||
  1418. bss->max_num_sta > MAX_STA_COUNT) {
  1419. printf("Line %d: Invalid max_num_sta=%d; "
  1420. "allowed range 0..%d\n", line,
  1421. bss->max_num_sta, MAX_STA_COUNT);
  1422. errors++;
  1423. }
  1424. } else if (os_strcmp(buf, "wpa") == 0) {
  1425. bss->wpa = atoi(pos);
  1426. } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
  1427. bss->wpa_group_rekey = atoi(pos);
  1428. } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
  1429. bss->wpa_strict_rekey = atoi(pos);
  1430. } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
  1431. bss->wpa_gmk_rekey = atoi(pos);
  1432. } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
  1433. int len = os_strlen(pos);
  1434. if (len < 8 || len > 63) {
  1435. printf("Line %d: invalid WPA passphrase length"
  1436. " %d (expected 8..63)\n", line, len);
  1437. errors++;
  1438. } else {
  1439. os_free(bss->ssid.wpa_passphrase);
  1440. bss->ssid.wpa_passphrase = os_strdup(pos);
  1441. }
  1442. } else if (os_strcmp(buf, "wpa_psk") == 0) {
  1443. os_free(bss->ssid.wpa_psk);
  1444. bss->ssid.wpa_psk =
  1445. os_zalloc(sizeof(struct hostapd_wpa_psk));
  1446. if (bss->ssid.wpa_psk == NULL)
  1447. errors++;
  1448. else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
  1449. PMK_LEN) ||
  1450. pos[PMK_LEN * 2] != '\0') {
  1451. printf("Line %d: Invalid PSK '%s'.\n", line,
  1452. pos);
  1453. errors++;
  1454. } else {
  1455. bss->ssid.wpa_psk->group = 1;
  1456. }
  1457. } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
  1458. os_free(bss->ssid.wpa_psk_file);
  1459. bss->ssid.wpa_psk_file = os_strdup(pos);
  1460. if (!bss->ssid.wpa_psk_file) {
  1461. printf("Line %d: allocation failed\n", line);
  1462. errors++;
  1463. }
  1464. } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
  1465. bss->wpa_key_mgmt =
  1466. hostapd_config_parse_key_mgmt(line, pos);
  1467. if (bss->wpa_key_mgmt == -1)
  1468. errors++;
  1469. } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
  1470. bss->wpa_pairwise =
  1471. hostapd_config_parse_cipher(line, pos);
  1472. if (bss->wpa_pairwise == -1 ||
  1473. bss->wpa_pairwise == 0)
  1474. errors++;
  1475. else if (bss->wpa_pairwise &
  1476. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
  1477. WPA_CIPHER_WEP104)) {
  1478. printf("Line %d: unsupported pairwise "
  1479. "cipher suite '%s'\n",
  1480. bss->wpa_pairwise, pos);
  1481. errors++;
  1482. }
  1483. } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
  1484. bss->rsn_pairwise =
  1485. hostapd_config_parse_cipher(line, pos);
  1486. if (bss->rsn_pairwise == -1 ||
  1487. bss->rsn_pairwise == 0)
  1488. errors++;
  1489. else if (bss->rsn_pairwise &
  1490. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
  1491. WPA_CIPHER_WEP104)) {
  1492. printf("Line %d: unsupported pairwise "
  1493. "cipher suite '%s'\n",
  1494. bss->rsn_pairwise, pos);
  1495. errors++;
  1496. }
  1497. #ifdef CONFIG_RSN_PREAUTH
  1498. } else if (os_strcmp(buf, "rsn_preauth") == 0) {
  1499. bss->rsn_preauth = atoi(pos);
  1500. } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
  1501. bss->rsn_preauth_interfaces = os_strdup(pos);
  1502. #endif /* CONFIG_RSN_PREAUTH */
  1503. #ifdef CONFIG_PEERKEY
  1504. } else if (os_strcmp(buf, "peerkey") == 0) {
  1505. bss->peerkey = atoi(pos);
  1506. #endif /* CONFIG_PEERKEY */
  1507. #ifdef CONFIG_IEEE80211R
  1508. } else if (os_strcmp(buf, "mobility_domain") == 0) {
  1509. if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
  1510. hexstr2bin(pos, bss->mobility_domain,
  1511. MOBILITY_DOMAIN_ID_LEN) != 0) {
  1512. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1513. "mobility_domain '%s'", line, pos);
  1514. errors++;
  1515. continue;
  1516. }
  1517. } else if (os_strcmp(buf, "r1_key_holder") == 0) {
  1518. if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
  1519. hexstr2bin(pos, bss->r1_key_holder,
  1520. FT_R1KH_ID_LEN) != 0) {
  1521. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1522. "r1_key_holder '%s'", line, pos);
  1523. errors++;
  1524. continue;
  1525. }
  1526. } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
  1527. bss->r0_key_lifetime = atoi(pos);
  1528. } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
  1529. bss->reassociation_deadline = atoi(pos);
  1530. } else if (os_strcmp(buf, "r0kh") == 0) {
  1531. if (add_r0kh(bss, pos) < 0) {
  1532. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1533. "r0kh '%s'", line, pos);
  1534. errors++;
  1535. continue;
  1536. }
  1537. } else if (os_strcmp(buf, "r1kh") == 0) {
  1538. if (add_r1kh(bss, pos) < 0) {
  1539. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1540. "r1kh '%s'", line, pos);
  1541. errors++;
  1542. continue;
  1543. }
  1544. } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
  1545. bss->pmk_r1_push = atoi(pos);
  1546. #endif /* CONFIG_IEEE80211R */
  1547. } else if (os_strcmp(buf, "ctrl_interface") == 0) {
  1548. os_free(bss->ctrl_interface);
  1549. bss->ctrl_interface = os_strdup(pos);
  1550. } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
  1551. #ifndef CONFIG_NATIVE_WINDOWS
  1552. struct group *grp;
  1553. char *endp;
  1554. const char *group = pos;
  1555. grp = getgrnam(group);
  1556. if (grp) {
  1557. bss->ctrl_interface_gid = grp->gr_gid;
  1558. bss->ctrl_interface_gid_set = 1;
  1559. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
  1560. " (from group name '%s')",
  1561. bss->ctrl_interface_gid, group);
  1562. continue;
  1563. }
  1564. /* Group name not found - try to parse this as gid */
  1565. bss->ctrl_interface_gid = strtol(group, &endp, 10);
  1566. if (*group == '\0' || *endp != '\0') {
  1567. wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
  1568. "'%s'", line, group);
  1569. errors++;
  1570. continue;
  1571. }
  1572. bss->ctrl_interface_gid_set = 1;
  1573. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
  1574. bss->ctrl_interface_gid);
  1575. #endif /* CONFIG_NATIVE_WINDOWS */
  1576. #ifdef RADIUS_SERVER
  1577. } else if (os_strcmp(buf, "radius_server_clients") == 0) {
  1578. os_free(bss->radius_server_clients);
  1579. bss->radius_server_clients = os_strdup(pos);
  1580. } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
  1581. bss->radius_server_auth_port = atoi(pos);
  1582. } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
  1583. bss->radius_server_ipv6 = atoi(pos);
  1584. #endif /* RADIUS_SERVER */
  1585. } else if (os_strcmp(buf, "test_socket") == 0) {
  1586. os_free(bss->test_socket);
  1587. bss->test_socket = os_strdup(pos);
  1588. } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
  1589. bss->use_pae_group_addr = atoi(pos);
  1590. } else if (os_strcmp(buf, "hw_mode") == 0) {
  1591. if (os_strcmp(pos, "a") == 0)
  1592. conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
  1593. else if (os_strcmp(pos, "b") == 0)
  1594. conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
  1595. else if (os_strcmp(pos, "g") == 0)
  1596. conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
  1597. else {
  1598. printf("Line %d: unknown hw_mode '%s'\n",
  1599. line, pos);
  1600. errors++;
  1601. }
  1602. } else if (os_strcmp(buf, "channel") == 0) {
  1603. conf->channel = atoi(pos);
  1604. } else if (os_strcmp(buf, "beacon_int") == 0) {
  1605. int val = atoi(pos);
  1606. /* MIB defines range as 1..65535, but very small values
  1607. * cause problems with the current implementation.
  1608. * Since it is unlikely that this small numbers are
  1609. * useful in real life scenarios, do not allow beacon
  1610. * period to be set below 15 TU. */
  1611. if (val < 15 || val > 65535) {
  1612. printf("Line %d: invalid beacon_int %d "
  1613. "(expected 15..65535)\n",
  1614. line, val);
  1615. errors++;
  1616. } else
  1617. conf->beacon_int = val;
  1618. } else if (os_strcmp(buf, "dtim_period") == 0) {
  1619. bss->dtim_period = atoi(pos);
  1620. if (bss->dtim_period < 1 || bss->dtim_period > 255) {
  1621. printf("Line %d: invalid dtim_period %d\n",
  1622. line, bss->dtim_period);
  1623. errors++;
  1624. }
  1625. } else if (os_strcmp(buf, "rts_threshold") == 0) {
  1626. conf->rts_threshold = atoi(pos);
  1627. if (conf->rts_threshold < 0 ||
  1628. conf->rts_threshold > 2347) {
  1629. printf("Line %d: invalid rts_threshold %d\n",
  1630. line, conf->rts_threshold);
  1631. errors++;
  1632. }
  1633. } else if (os_strcmp(buf, "fragm_threshold") == 0) {
  1634. conf->fragm_threshold = atoi(pos);
  1635. if (conf->fragm_threshold < 256 ||
  1636. conf->fragm_threshold > 2346) {
  1637. printf("Line %d: invalid fragm_threshold %d\n",
  1638. line, conf->fragm_threshold);
  1639. errors++;
  1640. }
  1641. } else if (os_strcmp(buf, "send_probe_response") == 0) {
  1642. int val = atoi(pos);
  1643. if (val != 0 && val != 1) {
  1644. printf("Line %d: invalid send_probe_response "
  1645. "%d (expected 0 or 1)\n", line, val);
  1646. } else
  1647. conf->send_probe_response = val;
  1648. } else if (os_strcmp(buf, "supported_rates") == 0) {
  1649. if (hostapd_parse_rates(&conf->supported_rates, pos)) {
  1650. printf("Line %d: invalid rate list\n", line);
  1651. errors++;
  1652. }
  1653. } else if (os_strcmp(buf, "basic_rates") == 0) {
  1654. if (hostapd_parse_rates(&conf->basic_rates, pos)) {
  1655. printf("Line %d: invalid rate list\n", line);
  1656. errors++;
  1657. }
  1658. } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
  1659. bss->ignore_broadcast_ssid = atoi(pos);
  1660. } else if (os_strcmp(buf, "bridge_packets") == 0) {
  1661. conf->bridge_packets = atoi(pos);
  1662. } else if (os_strcmp(buf, "wep_default_key") == 0) {
  1663. bss->ssid.wep.idx = atoi(pos);
  1664. if (bss->ssid.wep.idx > 3) {
  1665. printf("Invalid wep_default_key index %d\n",
  1666. bss->ssid.wep.idx);
  1667. errors++;
  1668. }
  1669. } else if (os_strcmp(buf, "wep_key0") == 0 ||
  1670. os_strcmp(buf, "wep_key1") == 0 ||
  1671. os_strcmp(buf, "wep_key2") == 0 ||
  1672. os_strcmp(buf, "wep_key3") == 0) {
  1673. if (hostapd_config_read_wep(&bss->ssid.wep,
  1674. buf[7] - '0', pos)) {
  1675. printf("Line %d: invalid WEP key '%s'\n",
  1676. line, buf);
  1677. errors++;
  1678. }
  1679. } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
  1680. bss->ssid.dynamic_vlan = atoi(pos);
  1681. } else if (os_strcmp(buf, "vlan_file") == 0) {
  1682. if (hostapd_config_read_vlan_file(bss, pos)) {
  1683. printf("Line %d: failed to read VLAN file "
  1684. "'%s'\n", line, pos);
  1685. errors++;
  1686. }
  1687. #ifdef CONFIG_FULL_DYNAMIC_VLAN
  1688. } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
  1689. bss->ssid.vlan_tagged_interface = os_strdup(pos);
  1690. #endif /* CONFIG_FULL_DYNAMIC_VLAN */
  1691. } else if (os_strcmp(buf, "passive_scan_interval") == 0) {
  1692. conf->passive_scan_interval = atoi(pos);
  1693. } else if (os_strcmp(buf, "passive_scan_listen") == 0) {
  1694. conf->passive_scan_listen = atoi(pos);
  1695. } else if (os_strcmp(buf, "passive_scan_mode") == 0) {
  1696. conf->passive_scan_mode = atoi(pos);
  1697. } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
  1698. conf->ap_table_max_size = atoi(pos);
  1699. } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
  1700. conf->ap_table_expiration_time = atoi(pos);
  1701. } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
  1702. if (hostapd_config_tx_queue(conf, buf, pos)) {
  1703. printf("Line %d: invalid TX queue item\n",
  1704. line);
  1705. errors++;
  1706. }
  1707. } else if (os_strcmp(buf, "wme_enabled") == 0) {
  1708. bss->wme_enabled = atoi(pos);
  1709. } else if (os_strncmp(buf, "wme_ac_", 7) == 0) {
  1710. if (hostapd_config_wme_ac(conf, buf, pos)) {
  1711. printf("Line %d: invalid wme ac item\n",
  1712. line);
  1713. errors++;
  1714. }
  1715. } else if (os_strcmp(buf, "bss") == 0) {
  1716. if (hostapd_config_bss(conf, pos)) {
  1717. printf("Line %d: invalid bss item\n", line);
  1718. errors++;
  1719. }
  1720. } else if (os_strcmp(buf, "bssid") == 0) {
  1721. if (bss == conf->bss &&
  1722. (!conf->driver || !conf->driver->init_bssid)) {
  1723. printf("Line %d: bssid item not allowed "
  1724. "for the default interface and this "
  1725. "driver\n", line);
  1726. errors++;
  1727. } else if (hwaddr_aton(pos, bss->bssid)) {
  1728. printf("Line %d: invalid bssid item\n", line);
  1729. errors++;
  1730. }
  1731. #ifdef CONFIG_IEEE80211W
  1732. } else if (os_strcmp(buf, "ieee80211w") == 0) {
  1733. bss->ieee80211w = atoi(pos);
  1734. #endif /* CONFIG_IEEE80211W */
  1735. } else if (os_strcmp(buf, "max_listen_interval") == 0) {
  1736. bss->max_listen_interval = atoi(pos);
  1737. } else {
  1738. printf("Line %d: unknown configuration item '%s'\n",
  1739. line, buf);
  1740. errors++;
  1741. }
  1742. }
  1743. fclose(f);
  1744. if (bss->individual_wep_key_len == 0) {
  1745. /* individual keys are not use; can use key idx0 for broadcast
  1746. * keys */
  1747. bss->broadcast_key_idx_min = 0;
  1748. }
  1749. /* Select group cipher based on the enabled pairwise cipher suites */
  1750. pairwise = 0;
  1751. if (bss->wpa & 1)
  1752. pairwise |= bss->wpa_pairwise;
  1753. if (bss->wpa & 2) {
  1754. if (bss->rsn_pairwise == 0)
  1755. bss->rsn_pairwise = bss->wpa_pairwise;
  1756. pairwise |= bss->rsn_pairwise;
  1757. }
  1758. if (pairwise & WPA_CIPHER_TKIP)
  1759. bss->wpa_group = WPA_CIPHER_TKIP;
  1760. else
  1761. bss->wpa_group = WPA_CIPHER_CCMP;
  1762. for (i = 0; i < conf->num_bss; i++) {
  1763. bss = &conf->bss[i];
  1764. bss->radius->auth_server = bss->radius->auth_servers;
  1765. bss->radius->acct_server = bss->radius->acct_servers;
  1766. if (bss->wpa && bss->ieee802_1x) {
  1767. bss->ssid.security_policy = SECURITY_WPA;
  1768. } else if (bss->wpa) {
  1769. bss->ssid.security_policy = SECURITY_WPA_PSK;
  1770. } else if (bss->ieee802_1x) {
  1771. bss->ssid.security_policy = SECURITY_IEEE_802_1X;
  1772. bss->ssid.wep.default_len = bss->default_wep_key_len;
  1773. } else if (bss->ssid.wep.keys_set)
  1774. bss->ssid.security_policy = SECURITY_STATIC_WEP;
  1775. else
  1776. bss->ssid.security_policy = SECURITY_PLAINTEXT;
  1777. }
  1778. if (hostapd_config_check(conf))
  1779. errors++;
  1780. if (errors) {
  1781. printf("%d errors found in configuration file '%s'\n",
  1782. errors, fname);
  1783. hostapd_config_free(conf);
  1784. conf = NULL;
  1785. }
  1786. return conf;
  1787. }
  1788. int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
  1789. {
  1790. int i;
  1791. if (a->idx != b->idx || a->default_len != b->default_len)
  1792. return 1;
  1793. for (i = 0; i < NUM_WEP_KEYS; i++)
  1794. if (a->len[i] != b->len[i] ||
  1795. os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
  1796. return 1;
  1797. return 0;
  1798. }
  1799. static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
  1800. int num_servers)
  1801. {
  1802. int i;
  1803. for (i = 0; i < num_servers; i++) {
  1804. os_free(servers[i].shared_secret);
  1805. }
  1806. os_free(servers);
  1807. }
  1808. static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
  1809. {
  1810. os_free(user->identity);
  1811. os_free(user->password);
  1812. os_free(user);
  1813. }
  1814. static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
  1815. {
  1816. int i;
  1817. for (i = 0; i < NUM_WEP_KEYS; i++) {
  1818. os_free(keys->key[i]);
  1819. keys->key[i] = NULL;
  1820. }
  1821. }
  1822. static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
  1823. {
  1824. struct hostapd_wpa_psk *psk, *prev;
  1825. struct hostapd_eap_user *user, *prev_user;
  1826. if (conf == NULL)
  1827. return;
  1828. psk = conf->ssid.wpa_psk;
  1829. while (psk) {
  1830. prev = psk;
  1831. psk = psk->next;
  1832. os_free(prev);
  1833. }
  1834. os_free(conf->ssid.wpa_passphrase);
  1835. os_free(conf->ssid.wpa_psk_file);
  1836. #ifdef CONFIG_FULL_DYNAMIC_VLAN
  1837. os_free(conf->ssid.vlan_tagged_interface);
  1838. #endif /* CONFIG_FULL_DYNAMIC_VLAN */
  1839. user = conf->eap_user;
  1840. while (user) {
  1841. prev_user = user;
  1842. user = user->next;
  1843. hostapd_config_free_eap_user(prev_user);
  1844. }
  1845. os_free(conf->dump_log_name);
  1846. os_free(conf->eap_req_id_text);
  1847. os_free(conf->accept_mac);
  1848. os_free(conf->deny_mac);
  1849. os_free(conf->nas_identifier);
  1850. hostapd_config_free_radius(conf->radius->auth_servers,
  1851. conf->radius->num_auth_servers);
  1852. hostapd_config_free_radius(conf->radius->acct_servers,
  1853. conf->radius->num_acct_servers);
  1854. os_free(conf->rsn_preauth_interfaces);
  1855. os_free(conf->ctrl_interface);
  1856. os_free(conf->ca_cert);
  1857. os_free(conf->server_cert);
  1858. os_free(conf->private_key);
  1859. os_free(conf->private_key_passwd);
  1860. os_free(conf->dh_file);
  1861. os_free(conf->pac_opaque_encr_key);
  1862. os_free(conf->eap_fast_a_id);
  1863. os_free(conf->eap_sim_db);
  1864. os_free(conf->radius_server_clients);
  1865. os_free(conf->test_socket);
  1866. os_free(conf->radius);
  1867. hostapd_config_free_vlan(conf);
  1868. if (conf->ssid.dyn_vlan_keys) {
  1869. struct hostapd_ssid *ssid = &conf->ssid;
  1870. size_t i;
  1871. for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
  1872. if (ssid->dyn_vlan_keys[i] == NULL)
  1873. continue;
  1874. hostapd_config_free_wep(ssid->dyn_vlan_keys[i]);
  1875. os_free(ssid->dyn_vlan_keys[i]);
  1876. }
  1877. os_free(ssid->dyn_vlan_keys);
  1878. ssid->dyn_vlan_keys = NULL;
  1879. }
  1880. #ifdef CONFIG_IEEE80211R
  1881. {
  1882. struct ft_remote_r0kh *r0kh, *r0kh_prev;
  1883. struct ft_remote_r1kh *r1kh, *r1kh_prev;
  1884. r0kh = conf->r0kh_list;
  1885. conf->r0kh_list = NULL;
  1886. while (r0kh) {
  1887. r0kh_prev = r0kh;
  1888. r0kh = r0kh->next;
  1889. os_free(r0kh_prev);
  1890. }
  1891. r1kh = conf->r1kh_list;
  1892. conf->r1kh_list = NULL;
  1893. while (r1kh) {
  1894. r1kh_prev = r1kh;
  1895. r1kh = r1kh->next;
  1896. os_free(r1kh_prev);
  1897. }
  1898. }
  1899. #endif /* CONFIG_IEEE80211R */
  1900. }
  1901. void hostapd_config_free(struct hostapd_config *conf)
  1902. {
  1903. size_t i;
  1904. if (conf == NULL)
  1905. return;
  1906. for (i = 0; i < conf->num_bss; i++)
  1907. hostapd_config_free_bss(&conf->bss[i]);
  1908. os_free(conf->bss);
  1909. os_free(conf);
  1910. }
  1911. /* Perform a binary search for given MAC address from a pre-sorted list.
  1912. * Returns 1 if address is in the list or 0 if not. */
  1913. int hostapd_maclist_found(macaddr *list, int num_entries, const u8 *addr)
  1914. {
  1915. int start, end, middle, res;
  1916. start = 0;
  1917. end = num_entries - 1;
  1918. while (start <= end) {
  1919. middle = (start + end) / 2;
  1920. res = os_memcmp(list[middle], addr, ETH_ALEN);
  1921. if (res == 0)
  1922. return 1;
  1923. if (res < 0)
  1924. start = middle + 1;
  1925. else
  1926. end = middle - 1;
  1927. }
  1928. return 0;
  1929. }
  1930. int hostapd_rate_found(int *list, int rate)
  1931. {
  1932. int i;
  1933. if (list == NULL)
  1934. return 0;
  1935. for (i = 0; list[i] >= 0; i++)
  1936. if (list[i] == rate)
  1937. return 1;
  1938. return 0;
  1939. }
  1940. const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
  1941. {
  1942. struct hostapd_vlan *v = vlan;
  1943. while (v) {
  1944. if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
  1945. return v->ifname;
  1946. v = v->next;
  1947. }
  1948. return NULL;
  1949. }
  1950. const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
  1951. const u8 *addr, const u8 *prev_psk)
  1952. {
  1953. struct hostapd_wpa_psk *psk;
  1954. int next_ok = prev_psk == NULL;
  1955. for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
  1956. if (next_ok &&
  1957. (psk->group || os_memcmp(psk->addr, addr, ETH_ALEN) == 0))
  1958. return psk->psk;
  1959. if (psk->psk == prev_psk)
  1960. next_ok = 1;
  1961. }
  1962. return NULL;
  1963. }
  1964. const struct hostapd_eap_user *
  1965. hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
  1966. size_t identity_len, int phase2)
  1967. {
  1968. struct hostapd_eap_user *user = conf->eap_user;
  1969. while (user) {
  1970. if (!phase2 && user->identity == NULL) {
  1971. /* Wildcard match */
  1972. break;
  1973. }
  1974. if (user->phase2 == !!phase2 && user->wildcard_prefix &&
  1975. identity_len >= user->identity_len &&
  1976. os_memcmp(user->identity, identity, user->identity_len) ==
  1977. 0) {
  1978. /* Wildcard prefix match */
  1979. break;
  1980. }
  1981. if (user->phase2 == !!phase2 &&
  1982. user->identity_len == identity_len &&
  1983. os_memcmp(user->identity, identity, identity_len) == 0)
  1984. break;
  1985. user = user->next;
  1986. }
  1987. return user;
  1988. }