config.c 57 KB

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