config.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315
  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. #ifdef CONFIG_IEEE80211W
  697. else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
  698. val |= WPA_KEY_MGMT_PSK_SHA256;
  699. else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
  700. val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
  701. #endif /* CONFIG_IEEE80211W */
  702. else {
  703. printf("Line %d: invalid key_mgmt '%s'\n",
  704. line, start);
  705. os_free(buf);
  706. return -1;
  707. }
  708. if (last)
  709. break;
  710. start = end + 1;
  711. }
  712. os_free(buf);
  713. if (val == 0) {
  714. printf("Line %d: no key_mgmt values configured.\n", line);
  715. return -1;
  716. }
  717. return val;
  718. }
  719. static int hostapd_config_parse_cipher(int line, const char *value)
  720. {
  721. int val = 0, last;
  722. char *start, *end, *buf;
  723. buf = os_strdup(value);
  724. if (buf == NULL)
  725. return -1;
  726. start = buf;
  727. while (start != '\0') {
  728. while (*start == ' ' || *start == '\t')
  729. start++;
  730. if (*start == '\0')
  731. break;
  732. end = start;
  733. while (*end != ' ' && *end != '\t' && *end != '\0')
  734. end++;
  735. last = *end == '\0';
  736. *end = '\0';
  737. if (os_strcmp(start, "CCMP") == 0)
  738. val |= WPA_CIPHER_CCMP;
  739. else if (os_strcmp(start, "TKIP") == 0)
  740. val |= WPA_CIPHER_TKIP;
  741. else if (os_strcmp(start, "WEP104") == 0)
  742. val |= WPA_CIPHER_WEP104;
  743. else if (os_strcmp(start, "WEP40") == 0)
  744. val |= WPA_CIPHER_WEP40;
  745. else if (os_strcmp(start, "NONE") == 0)
  746. val |= WPA_CIPHER_NONE;
  747. else {
  748. printf("Line %d: invalid cipher '%s'.", line, start);
  749. os_free(buf);
  750. return -1;
  751. }
  752. if (last)
  753. break;
  754. start = end + 1;
  755. }
  756. os_free(buf);
  757. if (val == 0) {
  758. printf("Line %d: no cipher values configured.", line);
  759. return -1;
  760. }
  761. return val;
  762. }
  763. static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
  764. struct hostapd_config *conf)
  765. {
  766. if (bss->ieee802_1x && !bss->eap_server &&
  767. !bss->radius->auth_servers) {
  768. printf("Invalid IEEE 802.1X configuration (no EAP "
  769. "authenticator configured).\n");
  770. return -1;
  771. }
  772. if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
  773. bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
  774. bss->ssid.wpa_psk_file == NULL) {
  775. printf("WPA-PSK enabled, but PSK or passphrase is not "
  776. "configured.\n");
  777. return -1;
  778. }
  779. if (hostapd_mac_comp_empty(bss->bssid) != 0) {
  780. size_t i;
  781. for (i = 0; i < conf->num_bss; i++) {
  782. if ((&conf->bss[i] != bss) &&
  783. (hostapd_mac_comp(conf->bss[i].bssid,
  784. bss->bssid) == 0)) {
  785. printf("Duplicate BSSID " MACSTR
  786. " on interface '%s' and '%s'.\n",
  787. MAC2STR(bss->bssid),
  788. conf->bss[i].iface, bss->iface);
  789. return -1;
  790. }
  791. }
  792. }
  793. #ifdef CONFIG_IEEE80211R
  794. if ((bss->wpa_key_mgmt &
  795. (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
  796. (bss->nas_identifier == NULL ||
  797. os_strlen(bss->nas_identifier) < 1 ||
  798. os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
  799. printf("FT (IEEE 802.11r) requires nas_identifier to be "
  800. "configured as a 1..48 octet string\n");
  801. return -1;
  802. }
  803. #endif /* CONFIG_IEEE80211R */
  804. return 0;
  805. }
  806. static int hostapd_config_check(struct hostapd_config *conf)
  807. {
  808. size_t i;
  809. for (i = 0; i < conf->num_bss; i++) {
  810. if (hostapd_config_check_bss(&conf->bss[i], conf))
  811. return -1;
  812. }
  813. return 0;
  814. }
  815. static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
  816. char *val)
  817. {
  818. size_t len = os_strlen(val);
  819. if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
  820. return -1;
  821. if (val[0] == '"') {
  822. if (len < 2 || val[len - 1] != '"')
  823. return -1;
  824. len -= 2;
  825. wep->key[keyidx] = os_malloc(len);
  826. if (wep->key[keyidx] == NULL)
  827. return -1;
  828. os_memcpy(wep->key[keyidx], val + 1, len);
  829. wep->len[keyidx] = len;
  830. } else {
  831. if (len & 1)
  832. return -1;
  833. len /= 2;
  834. wep->key[keyidx] = os_malloc(len);
  835. if (wep->key[keyidx] == NULL)
  836. return -1;
  837. wep->len[keyidx] = len;
  838. if (hexstr2bin(val, wep->key[keyidx], len) < 0)
  839. return -1;
  840. }
  841. wep->keys_set++;
  842. return 0;
  843. }
  844. static int hostapd_parse_rates(int **rate_list, char *val)
  845. {
  846. int *list;
  847. int count;
  848. char *pos, *end;
  849. os_free(*rate_list);
  850. *rate_list = NULL;
  851. pos = val;
  852. count = 0;
  853. while (*pos != '\0') {
  854. if (*pos == ' ')
  855. count++;
  856. pos++;
  857. }
  858. list = os_malloc(sizeof(int) * (count + 2));
  859. if (list == NULL)
  860. return -1;
  861. pos = val;
  862. count = 0;
  863. while (*pos != '\0') {
  864. end = os_strchr(pos, ' ');
  865. if (end)
  866. *end = '\0';
  867. list[count++] = atoi(pos);
  868. if (!end)
  869. break;
  870. pos = end + 1;
  871. }
  872. list[count] = -1;
  873. *rate_list = list;
  874. return 0;
  875. }
  876. static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
  877. {
  878. struct hostapd_bss_config *bss;
  879. if (*ifname == '\0')
  880. return -1;
  881. bss = os_realloc(conf->bss, (conf->num_bss + 1) *
  882. sizeof(struct hostapd_bss_config));
  883. if (bss == NULL) {
  884. printf("Failed to allocate memory for multi-BSS entry\n");
  885. return -1;
  886. }
  887. conf->bss = bss;
  888. bss = &(conf->bss[conf->num_bss]);
  889. os_memset(bss, 0, sizeof(*bss));
  890. bss->radius = os_zalloc(sizeof(*bss->radius));
  891. if (bss->radius == NULL) {
  892. printf("Failed to allocate memory for multi-BSS RADIUS "
  893. "data\n");
  894. return -1;
  895. }
  896. conf->num_bss++;
  897. conf->last_bss = bss;
  898. hostapd_config_defaults_bss(bss);
  899. os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
  900. os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
  901. return 0;
  902. }
  903. static int valid_cw(int cw)
  904. {
  905. return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
  906. cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
  907. }
  908. enum {
  909. IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
  910. IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
  911. IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
  912. IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */
  913. IEEE80211_TX_QUEUE_DATA4 = 4,
  914. IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
  915. IEEE80211_TX_QUEUE_BEACON = 7
  916. };
  917. static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
  918. char *val)
  919. {
  920. int num;
  921. char *pos;
  922. struct hostapd_tx_queue_params *queue;
  923. /* skip 'tx_queue_' prefix */
  924. pos = name + 9;
  925. if (os_strncmp(pos, "data", 4) == 0 &&
  926. pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
  927. num = pos[4] - '0';
  928. pos += 6;
  929. } else if (os_strncmp(pos, "after_beacon_", 13) == 0) {
  930. num = IEEE80211_TX_QUEUE_AFTER_BEACON;
  931. pos += 13;
  932. } else if (os_strncmp(pos, "beacon_", 7) == 0) {
  933. num = IEEE80211_TX_QUEUE_BEACON;
  934. pos += 7;
  935. } else {
  936. printf("Unknown tx_queue name '%s'\n", pos);
  937. return -1;
  938. }
  939. queue = &conf->tx_queue[num];
  940. if (os_strcmp(pos, "aifs") == 0) {
  941. queue->aifs = atoi(val);
  942. if (queue->aifs < 0 || queue->aifs > 255) {
  943. printf("Invalid AIFS value %d\n", queue->aifs);
  944. return -1;
  945. }
  946. } else if (os_strcmp(pos, "cwmin") == 0) {
  947. queue->cwmin = atoi(val);
  948. if (!valid_cw(queue->cwmin)) {
  949. printf("Invalid cwMin value %d\n", queue->cwmin);
  950. return -1;
  951. }
  952. } else if (os_strcmp(pos, "cwmax") == 0) {
  953. queue->cwmax = atoi(val);
  954. if (!valid_cw(queue->cwmax)) {
  955. printf("Invalid cwMax value %d\n", queue->cwmax);
  956. return -1;
  957. }
  958. } else if (os_strcmp(pos, "burst") == 0) {
  959. queue->burst = hostapd_config_read_int10(val);
  960. } else {
  961. printf("Unknown tx_queue field '%s'\n", pos);
  962. return -1;
  963. }
  964. queue->configured = 1;
  965. return 0;
  966. }
  967. static int hostapd_config_wme_ac(struct hostapd_config *conf, char *name,
  968. char *val)
  969. {
  970. int num, v;
  971. char *pos;
  972. struct hostapd_wme_ac_params *ac;
  973. /* skip 'wme_ac_' prefix */
  974. pos = name + 7;
  975. if (os_strncmp(pos, "be_", 3) == 0) {
  976. num = 0;
  977. pos += 3;
  978. } else if (os_strncmp(pos, "bk_", 3) == 0) {
  979. num = 1;
  980. pos += 3;
  981. } else if (os_strncmp(pos, "vi_", 3) == 0) {
  982. num = 2;
  983. pos += 3;
  984. } else if (os_strncmp(pos, "vo_", 3) == 0) {
  985. num = 3;
  986. pos += 3;
  987. } else {
  988. printf("Unknown wme name '%s'\n", pos);
  989. return -1;
  990. }
  991. ac = &conf->wme_ac_params[num];
  992. if (os_strcmp(pos, "aifs") == 0) {
  993. v = atoi(val);
  994. if (v < 1 || v > 255) {
  995. printf("Invalid AIFS value %d\n", v);
  996. return -1;
  997. }
  998. ac->aifs = v;
  999. } else if (os_strcmp(pos, "cwmin") == 0) {
  1000. v = atoi(val);
  1001. if (v < 0 || v > 12) {
  1002. printf("Invalid cwMin value %d\n", v);
  1003. return -1;
  1004. }
  1005. ac->cwmin = v;
  1006. } else if (os_strcmp(pos, "cwmax") == 0) {
  1007. v = atoi(val);
  1008. if (v < 0 || v > 12) {
  1009. printf("Invalid cwMax value %d\n", v);
  1010. return -1;
  1011. }
  1012. ac->cwmax = v;
  1013. } else if (os_strcmp(pos, "txop_limit") == 0) {
  1014. v = atoi(val);
  1015. if (v < 0 || v > 0xffff) {
  1016. printf("Invalid txop value %d\n", v);
  1017. return -1;
  1018. }
  1019. ac->txopLimit = v;
  1020. } else if (os_strcmp(pos, "acm") == 0) {
  1021. v = atoi(val);
  1022. if (v < 0 || v > 1) {
  1023. printf("Invalid acm value %d\n", v);
  1024. return -1;
  1025. }
  1026. ac->admission_control_mandatory = v;
  1027. } else {
  1028. printf("Unknown wme_ac_ field '%s'\n", pos);
  1029. return -1;
  1030. }
  1031. return 0;
  1032. }
  1033. #ifdef CONFIG_IEEE80211R
  1034. static int add_r0kh(struct hostapd_bss_config *bss, char *value)
  1035. {
  1036. struct ft_remote_r0kh *r0kh;
  1037. char *pos, *next;
  1038. r0kh = os_zalloc(sizeof(*r0kh));
  1039. if (r0kh == NULL)
  1040. return -1;
  1041. /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
  1042. pos = value;
  1043. next = os_strchr(pos, ' ');
  1044. if (next)
  1045. *next++ = '\0';
  1046. if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
  1047. printf("Invalid R0KH MAC address: '%s'\n", pos);
  1048. os_free(r0kh);
  1049. return -1;
  1050. }
  1051. pos = next;
  1052. next = os_strchr(pos, ' ');
  1053. if (next)
  1054. *next++ = '\0';
  1055. if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
  1056. printf("Invalid R0KH-ID: '%s'\n", pos);
  1057. os_free(r0kh);
  1058. return -1;
  1059. }
  1060. r0kh->id_len = next - pos - 1;
  1061. os_memcpy(r0kh->id, pos, r0kh->id_len);
  1062. pos = next;
  1063. if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
  1064. printf("Invalid R0KH key: '%s'\n", pos);
  1065. os_free(r0kh);
  1066. return -1;
  1067. }
  1068. r0kh->next = bss->r0kh_list;
  1069. bss->r0kh_list = r0kh;
  1070. return 0;
  1071. }
  1072. static int add_r1kh(struct hostapd_bss_config *bss, char *value)
  1073. {
  1074. struct ft_remote_r1kh *r1kh;
  1075. char *pos, *next;
  1076. r1kh = os_zalloc(sizeof(*r1kh));
  1077. if (r1kh == NULL)
  1078. return -1;
  1079. /* 02:01:02:03:04:05 02:01:02:03:04:05
  1080. * 000102030405060708090a0b0c0d0e0f */
  1081. pos = value;
  1082. next = os_strchr(pos, ' ');
  1083. if (next)
  1084. *next++ = '\0';
  1085. if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
  1086. printf("Invalid R1KH MAC address: '%s'\n", pos);
  1087. os_free(r1kh);
  1088. return -1;
  1089. }
  1090. pos = next;
  1091. next = os_strchr(pos, ' ');
  1092. if (next)
  1093. *next++ = '\0';
  1094. if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
  1095. printf("Invalid R1KH-ID: '%s'\n", pos);
  1096. os_free(r1kh);
  1097. return -1;
  1098. }
  1099. pos = next;
  1100. if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
  1101. printf("Invalid R1KH key: '%s'\n", pos);
  1102. os_free(r1kh);
  1103. return -1;
  1104. }
  1105. r1kh->next = bss->r1kh_list;
  1106. bss->r1kh_list = r1kh;
  1107. return 0;
  1108. }
  1109. #endif /* CONFIG_IEEE80211R */
  1110. struct hostapd_config * hostapd_config_read(const char *fname)
  1111. {
  1112. struct hostapd_config *conf;
  1113. struct hostapd_bss_config *bss;
  1114. FILE *f;
  1115. char buf[256], *pos;
  1116. int line = 0;
  1117. int errors = 0;
  1118. int pairwise;
  1119. size_t i;
  1120. f = fopen(fname, "r");
  1121. if (f == NULL) {
  1122. printf("Could not open configuration file '%s' for reading.\n",
  1123. fname);
  1124. return NULL;
  1125. }
  1126. conf = hostapd_config_defaults();
  1127. if (conf == NULL) {
  1128. fclose(f);
  1129. return NULL;
  1130. }
  1131. bss = conf->last_bss = conf->bss;
  1132. while (fgets(buf, sizeof(buf), f)) {
  1133. bss = conf->last_bss;
  1134. line++;
  1135. if (buf[0] == '#')
  1136. continue;
  1137. pos = buf;
  1138. while (*pos != '\0') {
  1139. if (*pos == '\n') {
  1140. *pos = '\0';
  1141. break;
  1142. }
  1143. pos++;
  1144. }
  1145. if (buf[0] == '\0')
  1146. continue;
  1147. pos = os_strchr(buf, '=');
  1148. if (pos == NULL) {
  1149. printf("Line %d: invalid line '%s'\n", line, buf);
  1150. errors++;
  1151. continue;
  1152. }
  1153. *pos = '\0';
  1154. pos++;
  1155. if (os_strcmp(buf, "interface") == 0) {
  1156. os_strlcpy(conf->bss[0].iface, pos,
  1157. sizeof(conf->bss[0].iface));
  1158. } else if (os_strcmp(buf, "bridge") == 0) {
  1159. os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
  1160. } else if (os_strcmp(buf, "driver") == 0) {
  1161. int i;
  1162. /* clear to get error below if setting is invalid */
  1163. conf->driver = NULL;
  1164. for (i = 0; hostapd_drivers[i]; i++) {
  1165. if (os_strcmp(pos, hostapd_drivers[i]->name) ==
  1166. 0) {
  1167. conf->driver = hostapd_drivers[i];
  1168. break;
  1169. }
  1170. }
  1171. if (conf->driver == NULL) {
  1172. printf("Line %d: invalid/unknown driver "
  1173. "'%s'\n", line, pos);
  1174. errors++;
  1175. }
  1176. } else if (os_strcmp(buf, "debug") == 0) {
  1177. wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
  1178. "configuration variable is not used "
  1179. "anymore", line);
  1180. } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
  1181. bss->logger_syslog_level = atoi(pos);
  1182. } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
  1183. bss->logger_stdout_level = atoi(pos);
  1184. } else if (os_strcmp(buf, "logger_syslog") == 0) {
  1185. bss->logger_syslog = atoi(pos);
  1186. } else if (os_strcmp(buf, "logger_stdout") == 0) {
  1187. bss->logger_stdout = atoi(pos);
  1188. } else if (os_strcmp(buf, "dump_file") == 0) {
  1189. bss->dump_log_name = os_strdup(pos);
  1190. } else if (os_strcmp(buf, "ssid") == 0) {
  1191. bss->ssid.ssid_len = os_strlen(pos);
  1192. if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
  1193. bss->ssid.ssid_len < 1) {
  1194. printf("Line %d: invalid SSID '%s'\n", line,
  1195. pos);
  1196. errors++;
  1197. } else {
  1198. os_memcpy(bss->ssid.ssid, pos,
  1199. bss->ssid.ssid_len);
  1200. bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
  1201. bss->ssid.ssid_set = 1;
  1202. }
  1203. } else if (os_strcmp(buf, "macaddr_acl") == 0) {
  1204. bss->macaddr_acl = atoi(pos);
  1205. if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
  1206. bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
  1207. bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
  1208. printf("Line %d: unknown macaddr_acl %d\n",
  1209. line, bss->macaddr_acl);
  1210. }
  1211. } else if (os_strcmp(buf, "accept_mac_file") == 0) {
  1212. if (hostapd_config_read_maclist(pos, &bss->accept_mac,
  1213. &bss->num_accept_mac))
  1214. {
  1215. printf("Line %d: Failed to read "
  1216. "accept_mac_file '%s'\n",
  1217. line, pos);
  1218. errors++;
  1219. }
  1220. } else if (os_strcmp(buf, "deny_mac_file") == 0) {
  1221. if (hostapd_config_read_maclist(pos, &bss->deny_mac,
  1222. &bss->num_deny_mac))
  1223. {
  1224. printf("Line %d: Failed to read "
  1225. "deny_mac_file '%s'\n",
  1226. line, pos);
  1227. errors++;
  1228. }
  1229. } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
  1230. bss->ap_max_inactivity = atoi(pos);
  1231. } else if (os_strcmp(buf, "country_code") == 0) {
  1232. os_memcpy(conf->country, pos, 2);
  1233. /* FIX: make this configurable */
  1234. conf->country[2] = ' ';
  1235. } else if (os_strcmp(buf, "ieee80211d") == 0) {
  1236. conf->ieee80211d = atoi(pos);
  1237. } else if (os_strcmp(buf, "ieee80211h") == 0) {
  1238. conf->ieee80211h = atoi(pos);
  1239. } else if (os_strcmp(buf, "assoc_ap_addr") == 0) {
  1240. if (hwaddr_aton(pos, bss->assoc_ap_addr)) {
  1241. printf("Line %d: invalid MAC address '%s'\n",
  1242. line, pos);
  1243. errors++;
  1244. }
  1245. bss->assoc_ap = 1;
  1246. } else if (os_strcmp(buf, "ieee8021x") == 0) {
  1247. bss->ieee802_1x = atoi(pos);
  1248. } else if (os_strcmp(buf, "eapol_version") == 0) {
  1249. bss->eapol_version = atoi(pos);
  1250. if (bss->eapol_version < 1 ||
  1251. bss->eapol_version > 2) {
  1252. printf("Line %d: invalid EAPOL "
  1253. "version (%d): '%s'.\n",
  1254. line, bss->eapol_version, pos);
  1255. errors++;
  1256. } else
  1257. wpa_printf(MSG_DEBUG, "eapol_version=%d",
  1258. bss->eapol_version);
  1259. #ifdef EAP_SERVER
  1260. } else if (os_strcmp(buf, "eap_authenticator") == 0) {
  1261. bss->eap_server = atoi(pos);
  1262. printf("Line %d: obsolete eap_authenticator used; "
  1263. "this has been renamed to eap_server\n", line);
  1264. } else if (os_strcmp(buf, "eap_server") == 0) {
  1265. bss->eap_server = atoi(pos);
  1266. } else if (os_strcmp(buf, "eap_user_file") == 0) {
  1267. if (hostapd_config_read_eap_user(pos, bss))
  1268. errors++;
  1269. } else if (os_strcmp(buf, "ca_cert") == 0) {
  1270. os_free(bss->ca_cert);
  1271. bss->ca_cert = os_strdup(pos);
  1272. } else if (os_strcmp(buf, "server_cert") == 0) {
  1273. os_free(bss->server_cert);
  1274. bss->server_cert = os_strdup(pos);
  1275. } else if (os_strcmp(buf, "private_key") == 0) {
  1276. os_free(bss->private_key);
  1277. bss->private_key = os_strdup(pos);
  1278. } else if (os_strcmp(buf, "private_key_passwd") == 0) {
  1279. os_free(bss->private_key_passwd);
  1280. bss->private_key_passwd = os_strdup(pos);
  1281. } else if (os_strcmp(buf, "check_crl") == 0) {
  1282. bss->check_crl = atoi(pos);
  1283. } else if (os_strcmp(buf, "dh_file") == 0) {
  1284. os_free(bss->dh_file);
  1285. bss->dh_file = os_strdup(pos);
  1286. #ifdef EAP_FAST
  1287. } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
  1288. os_free(bss->pac_opaque_encr_key);
  1289. bss->pac_opaque_encr_key = os_malloc(16);
  1290. if (bss->pac_opaque_encr_key == NULL) {
  1291. printf("Line %d: No memory for "
  1292. "pac_opque_encr_key\n", line);
  1293. errors++;
  1294. } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
  1295. 16)) {
  1296. printf("Line %d: Invalid pac_opque_encr_key\n",
  1297. line);
  1298. errors++;
  1299. }
  1300. } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
  1301. os_free(bss->eap_fast_a_id);
  1302. bss->eap_fast_a_id = os_strdup(pos);
  1303. #endif /* EAP_FAST */
  1304. #ifdef EAP_SIM
  1305. } else if (os_strcmp(buf, "eap_sim_db") == 0) {
  1306. os_free(bss->eap_sim_db);
  1307. bss->eap_sim_db = os_strdup(pos);
  1308. } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
  1309. bss->eap_sim_aka_result_ind = atoi(pos);
  1310. #endif /* EAP_SIM */
  1311. #ifdef EAP_TNC
  1312. } else if (os_strcmp(buf, "tnc") == 0) {
  1313. bss->tnc = atoi(pos);
  1314. #endif /* EAP_TNC */
  1315. #endif /* EAP_SERVER */
  1316. } else if (os_strcmp(buf, "eap_message") == 0) {
  1317. char *term;
  1318. bss->eap_req_id_text = os_strdup(pos);
  1319. if (bss->eap_req_id_text == NULL) {
  1320. printf("Line %d: Failed to allocate memory "
  1321. "for eap_req_id_text\n", line);
  1322. errors++;
  1323. continue;
  1324. }
  1325. bss->eap_req_id_text_len =
  1326. os_strlen(bss->eap_req_id_text);
  1327. term = os_strstr(bss->eap_req_id_text, "\\0");
  1328. if (term) {
  1329. *term++ = '\0';
  1330. os_memmove(term, term + 1,
  1331. bss->eap_req_id_text_len -
  1332. (term - bss->eap_req_id_text) - 1);
  1333. bss->eap_req_id_text_len--;
  1334. }
  1335. } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
  1336. bss->default_wep_key_len = atoi(pos);
  1337. if (bss->default_wep_key_len > 13) {
  1338. printf("Line %d: invalid WEP key len %lu "
  1339. "(= %lu bits)\n", line,
  1340. (unsigned long)
  1341. bss->default_wep_key_len,
  1342. (unsigned long)
  1343. bss->default_wep_key_len * 8);
  1344. errors++;
  1345. }
  1346. } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
  1347. bss->individual_wep_key_len = atoi(pos);
  1348. if (bss->individual_wep_key_len < 0 ||
  1349. bss->individual_wep_key_len > 13) {
  1350. printf("Line %d: invalid WEP key len %d "
  1351. "(= %d bits)\n", line,
  1352. bss->individual_wep_key_len,
  1353. bss->individual_wep_key_len * 8);
  1354. errors++;
  1355. }
  1356. } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
  1357. bss->wep_rekeying_period = atoi(pos);
  1358. if (bss->wep_rekeying_period < 0) {
  1359. printf("Line %d: invalid period %d\n",
  1360. line, bss->wep_rekeying_period);
  1361. errors++;
  1362. }
  1363. } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
  1364. bss->eap_reauth_period = atoi(pos);
  1365. if (bss->eap_reauth_period < 0) {
  1366. printf("Line %d: invalid period %d\n",
  1367. line, bss->eap_reauth_period);
  1368. errors++;
  1369. }
  1370. } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
  1371. bss->eapol_key_index_workaround = atoi(pos);
  1372. #ifdef CONFIG_IAPP
  1373. } else if (os_strcmp(buf, "iapp_interface") == 0) {
  1374. bss->ieee802_11f = 1;
  1375. os_strlcpy(bss->iapp_iface, pos,
  1376. sizeof(bss->iapp_iface));
  1377. #endif /* CONFIG_IAPP */
  1378. } else if (os_strcmp(buf, "own_ip_addr") == 0) {
  1379. if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
  1380. printf("Line %d: invalid IP address '%s'\n",
  1381. line, pos);
  1382. errors++;
  1383. }
  1384. } else if (os_strcmp(buf, "nas_identifier") == 0) {
  1385. bss->nas_identifier = os_strdup(pos);
  1386. } else if (os_strcmp(buf, "auth_server_addr") == 0) {
  1387. if (hostapd_config_read_radius_addr(
  1388. &bss->radius->auth_servers,
  1389. &bss->radius->num_auth_servers, pos, 1812,
  1390. &bss->radius->auth_server)) {
  1391. printf("Line %d: invalid IP address '%s'\n",
  1392. line, pos);
  1393. errors++;
  1394. }
  1395. } else if (bss->radius->auth_server &&
  1396. os_strcmp(buf, "auth_server_port") == 0) {
  1397. bss->radius->auth_server->port = atoi(pos);
  1398. } else if (bss->radius->auth_server &&
  1399. os_strcmp(buf, "auth_server_shared_secret") == 0) {
  1400. int len = os_strlen(pos);
  1401. if (len == 0) {
  1402. /* RFC 2865, Ch. 3 */
  1403. printf("Line %d: empty shared secret is not "
  1404. "allowed.\n", line);
  1405. errors++;
  1406. }
  1407. bss->radius->auth_server->shared_secret =
  1408. (u8 *) os_strdup(pos);
  1409. bss->radius->auth_server->shared_secret_len = len;
  1410. } else if (os_strcmp(buf, "acct_server_addr") == 0) {
  1411. if (hostapd_config_read_radius_addr(
  1412. &bss->radius->acct_servers,
  1413. &bss->radius->num_acct_servers, pos, 1813,
  1414. &bss->radius->acct_server)) {
  1415. printf("Line %d: invalid IP address '%s'\n",
  1416. line, pos);
  1417. errors++;
  1418. }
  1419. } else if (bss->radius->acct_server &&
  1420. os_strcmp(buf, "acct_server_port") == 0) {
  1421. bss->radius->acct_server->port = atoi(pos);
  1422. } else if (bss->radius->acct_server &&
  1423. os_strcmp(buf, "acct_server_shared_secret") == 0) {
  1424. int len = os_strlen(pos);
  1425. if (len == 0) {
  1426. /* RFC 2865, Ch. 3 */
  1427. printf("Line %d: empty shared secret is not "
  1428. "allowed.\n", line);
  1429. errors++;
  1430. }
  1431. bss->radius->acct_server->shared_secret =
  1432. (u8 *) os_strdup(pos);
  1433. bss->radius->acct_server->shared_secret_len = len;
  1434. } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
  1435. 0) {
  1436. bss->radius->retry_primary_interval = atoi(pos);
  1437. } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
  1438. {
  1439. bss->radius->acct_interim_interval = atoi(pos);
  1440. } else if (os_strcmp(buf, "auth_algs") == 0) {
  1441. bss->auth_algs = atoi(pos);
  1442. if (bss->auth_algs == 0) {
  1443. printf("Line %d: no authentication algorithms "
  1444. "allowed\n",
  1445. line);
  1446. errors++;
  1447. }
  1448. } else if (os_strcmp(buf, "max_num_sta") == 0) {
  1449. bss->max_num_sta = atoi(pos);
  1450. if (bss->max_num_sta < 0 ||
  1451. bss->max_num_sta > MAX_STA_COUNT) {
  1452. printf("Line %d: Invalid max_num_sta=%d; "
  1453. "allowed range 0..%d\n", line,
  1454. bss->max_num_sta, MAX_STA_COUNT);
  1455. errors++;
  1456. }
  1457. } else if (os_strcmp(buf, "wpa") == 0) {
  1458. bss->wpa = atoi(pos);
  1459. } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
  1460. bss->wpa_group_rekey = atoi(pos);
  1461. } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
  1462. bss->wpa_strict_rekey = atoi(pos);
  1463. } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
  1464. bss->wpa_gmk_rekey = atoi(pos);
  1465. } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
  1466. int len = os_strlen(pos);
  1467. if (len < 8 || len > 63) {
  1468. printf("Line %d: invalid WPA passphrase length"
  1469. " %d (expected 8..63)\n", line, len);
  1470. errors++;
  1471. } else {
  1472. os_free(bss->ssid.wpa_passphrase);
  1473. bss->ssid.wpa_passphrase = os_strdup(pos);
  1474. }
  1475. } else if (os_strcmp(buf, "wpa_psk") == 0) {
  1476. os_free(bss->ssid.wpa_psk);
  1477. bss->ssid.wpa_psk =
  1478. os_zalloc(sizeof(struct hostapd_wpa_psk));
  1479. if (bss->ssid.wpa_psk == NULL)
  1480. errors++;
  1481. else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
  1482. PMK_LEN) ||
  1483. pos[PMK_LEN * 2] != '\0') {
  1484. printf("Line %d: Invalid PSK '%s'.\n", line,
  1485. pos);
  1486. errors++;
  1487. } else {
  1488. bss->ssid.wpa_psk->group = 1;
  1489. }
  1490. } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
  1491. os_free(bss->ssid.wpa_psk_file);
  1492. bss->ssid.wpa_psk_file = os_strdup(pos);
  1493. if (!bss->ssid.wpa_psk_file) {
  1494. printf("Line %d: allocation failed\n", line);
  1495. errors++;
  1496. }
  1497. } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
  1498. bss->wpa_key_mgmt =
  1499. hostapd_config_parse_key_mgmt(line, pos);
  1500. if (bss->wpa_key_mgmt == -1)
  1501. errors++;
  1502. } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
  1503. bss->wpa_pairwise =
  1504. hostapd_config_parse_cipher(line, pos);
  1505. if (bss->wpa_pairwise == -1 ||
  1506. bss->wpa_pairwise == 0)
  1507. errors++;
  1508. else if (bss->wpa_pairwise &
  1509. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
  1510. WPA_CIPHER_WEP104)) {
  1511. printf("Line %d: unsupported pairwise "
  1512. "cipher suite '%s'\n",
  1513. bss->wpa_pairwise, pos);
  1514. errors++;
  1515. }
  1516. } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
  1517. bss->rsn_pairwise =
  1518. hostapd_config_parse_cipher(line, pos);
  1519. if (bss->rsn_pairwise == -1 ||
  1520. bss->rsn_pairwise == 0)
  1521. errors++;
  1522. else if (bss->rsn_pairwise &
  1523. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
  1524. WPA_CIPHER_WEP104)) {
  1525. printf("Line %d: unsupported pairwise "
  1526. "cipher suite '%s'\n",
  1527. bss->rsn_pairwise, pos);
  1528. errors++;
  1529. }
  1530. #ifdef CONFIG_RSN_PREAUTH
  1531. } else if (os_strcmp(buf, "rsn_preauth") == 0) {
  1532. bss->rsn_preauth = atoi(pos);
  1533. } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
  1534. bss->rsn_preauth_interfaces = os_strdup(pos);
  1535. #endif /* CONFIG_RSN_PREAUTH */
  1536. #ifdef CONFIG_PEERKEY
  1537. } else if (os_strcmp(buf, "peerkey") == 0) {
  1538. bss->peerkey = atoi(pos);
  1539. #endif /* CONFIG_PEERKEY */
  1540. #ifdef CONFIG_IEEE80211R
  1541. } else if (os_strcmp(buf, "mobility_domain") == 0) {
  1542. if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
  1543. hexstr2bin(pos, bss->mobility_domain,
  1544. MOBILITY_DOMAIN_ID_LEN) != 0) {
  1545. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1546. "mobility_domain '%s'", line, pos);
  1547. errors++;
  1548. continue;
  1549. }
  1550. } else if (os_strcmp(buf, "r1_key_holder") == 0) {
  1551. if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
  1552. hexstr2bin(pos, bss->r1_key_holder,
  1553. FT_R1KH_ID_LEN) != 0) {
  1554. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1555. "r1_key_holder '%s'", line, pos);
  1556. errors++;
  1557. continue;
  1558. }
  1559. } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
  1560. bss->r0_key_lifetime = atoi(pos);
  1561. } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
  1562. bss->reassociation_deadline = atoi(pos);
  1563. } else if (os_strcmp(buf, "r0kh") == 0) {
  1564. if (add_r0kh(bss, pos) < 0) {
  1565. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1566. "r0kh '%s'", line, pos);
  1567. errors++;
  1568. continue;
  1569. }
  1570. } else if (os_strcmp(buf, "r1kh") == 0) {
  1571. if (add_r1kh(bss, pos) < 0) {
  1572. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1573. "r1kh '%s'", line, pos);
  1574. errors++;
  1575. continue;
  1576. }
  1577. } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
  1578. bss->pmk_r1_push = atoi(pos);
  1579. #endif /* CONFIG_IEEE80211R */
  1580. } else if (os_strcmp(buf, "ctrl_interface") == 0) {
  1581. os_free(bss->ctrl_interface);
  1582. bss->ctrl_interface = os_strdup(pos);
  1583. } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
  1584. #ifndef CONFIG_NATIVE_WINDOWS
  1585. struct group *grp;
  1586. char *endp;
  1587. const char *group = pos;
  1588. grp = getgrnam(group);
  1589. if (grp) {
  1590. bss->ctrl_interface_gid = grp->gr_gid;
  1591. bss->ctrl_interface_gid_set = 1;
  1592. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
  1593. " (from group name '%s')",
  1594. bss->ctrl_interface_gid, group);
  1595. continue;
  1596. }
  1597. /* Group name not found - try to parse this as gid */
  1598. bss->ctrl_interface_gid = strtol(group, &endp, 10);
  1599. if (*group == '\0' || *endp != '\0') {
  1600. wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
  1601. "'%s'", line, group);
  1602. errors++;
  1603. continue;
  1604. }
  1605. bss->ctrl_interface_gid_set = 1;
  1606. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
  1607. bss->ctrl_interface_gid);
  1608. #endif /* CONFIG_NATIVE_WINDOWS */
  1609. #ifdef RADIUS_SERVER
  1610. } else if (os_strcmp(buf, "radius_server_clients") == 0) {
  1611. os_free(bss->radius_server_clients);
  1612. bss->radius_server_clients = os_strdup(pos);
  1613. } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
  1614. bss->radius_server_auth_port = atoi(pos);
  1615. } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
  1616. bss->radius_server_ipv6 = atoi(pos);
  1617. #endif /* RADIUS_SERVER */
  1618. } else if (os_strcmp(buf, "test_socket") == 0) {
  1619. os_free(bss->test_socket);
  1620. bss->test_socket = os_strdup(pos);
  1621. } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
  1622. bss->use_pae_group_addr = atoi(pos);
  1623. } else if (os_strcmp(buf, "hw_mode") == 0) {
  1624. if (os_strcmp(pos, "a") == 0)
  1625. conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
  1626. else if (os_strcmp(pos, "b") == 0)
  1627. conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
  1628. else if (os_strcmp(pos, "g") == 0)
  1629. conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
  1630. else {
  1631. printf("Line %d: unknown hw_mode '%s'\n",
  1632. line, pos);
  1633. errors++;
  1634. }
  1635. } else if (os_strcmp(buf, "channel") == 0) {
  1636. conf->channel = atoi(pos);
  1637. } else if (os_strcmp(buf, "beacon_int") == 0) {
  1638. int val = atoi(pos);
  1639. /* MIB defines range as 1..65535, but very small values
  1640. * cause problems with the current implementation.
  1641. * Since it is unlikely that this small numbers are
  1642. * useful in real life scenarios, do not allow beacon
  1643. * period to be set below 15 TU. */
  1644. if (val < 15 || val > 65535) {
  1645. printf("Line %d: invalid beacon_int %d "
  1646. "(expected 15..65535)\n",
  1647. line, val);
  1648. errors++;
  1649. } else
  1650. conf->beacon_int = val;
  1651. } else if (os_strcmp(buf, "dtim_period") == 0) {
  1652. bss->dtim_period = atoi(pos);
  1653. if (bss->dtim_period < 1 || bss->dtim_period > 255) {
  1654. printf("Line %d: invalid dtim_period %d\n",
  1655. line, bss->dtim_period);
  1656. errors++;
  1657. }
  1658. } else if (os_strcmp(buf, "rts_threshold") == 0) {
  1659. conf->rts_threshold = atoi(pos);
  1660. if (conf->rts_threshold < 0 ||
  1661. conf->rts_threshold > 2347) {
  1662. printf("Line %d: invalid rts_threshold %d\n",
  1663. line, conf->rts_threshold);
  1664. errors++;
  1665. }
  1666. } else if (os_strcmp(buf, "fragm_threshold") == 0) {
  1667. conf->fragm_threshold = atoi(pos);
  1668. if (conf->fragm_threshold < 256 ||
  1669. conf->fragm_threshold > 2346) {
  1670. printf("Line %d: invalid fragm_threshold %d\n",
  1671. line, conf->fragm_threshold);
  1672. errors++;
  1673. }
  1674. } else if (os_strcmp(buf, "send_probe_response") == 0) {
  1675. int val = atoi(pos);
  1676. if (val != 0 && val != 1) {
  1677. printf("Line %d: invalid send_probe_response "
  1678. "%d (expected 0 or 1)\n", line, val);
  1679. } else
  1680. conf->send_probe_response = val;
  1681. } else if (os_strcmp(buf, "supported_rates") == 0) {
  1682. if (hostapd_parse_rates(&conf->supported_rates, pos)) {
  1683. printf("Line %d: invalid rate list\n", line);
  1684. errors++;
  1685. }
  1686. } else if (os_strcmp(buf, "basic_rates") == 0) {
  1687. if (hostapd_parse_rates(&conf->basic_rates, pos)) {
  1688. printf("Line %d: invalid rate list\n", line);
  1689. errors++;
  1690. }
  1691. } else if (os_strcmp(buf, "preamble") == 0) {
  1692. if (atoi(pos))
  1693. conf->preamble = SHORT_PREAMBLE;
  1694. else
  1695. conf->preamble = LONG_PREAMBLE;
  1696. } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
  1697. bss->ignore_broadcast_ssid = atoi(pos);
  1698. } else if (os_strcmp(buf, "bridge_packets") == 0) {
  1699. conf->bridge_packets = atoi(pos);
  1700. } else if (os_strcmp(buf, "wep_default_key") == 0) {
  1701. bss->ssid.wep.idx = atoi(pos);
  1702. if (bss->ssid.wep.idx > 3) {
  1703. printf("Invalid wep_default_key index %d\n",
  1704. bss->ssid.wep.idx);
  1705. errors++;
  1706. }
  1707. } else if (os_strcmp(buf, "wep_key0") == 0 ||
  1708. os_strcmp(buf, "wep_key1") == 0 ||
  1709. os_strcmp(buf, "wep_key2") == 0 ||
  1710. os_strcmp(buf, "wep_key3") == 0) {
  1711. if (hostapd_config_read_wep(&bss->ssid.wep,
  1712. buf[7] - '0', pos)) {
  1713. printf("Line %d: invalid WEP key '%s'\n",
  1714. line, buf);
  1715. errors++;
  1716. }
  1717. } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
  1718. bss->ssid.dynamic_vlan = atoi(pos);
  1719. } else if (os_strcmp(buf, "vlan_file") == 0) {
  1720. if (hostapd_config_read_vlan_file(bss, pos)) {
  1721. printf("Line %d: failed to read VLAN file "
  1722. "'%s'\n", line, pos);
  1723. errors++;
  1724. }
  1725. #ifdef CONFIG_FULL_DYNAMIC_VLAN
  1726. } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
  1727. bss->ssid.vlan_tagged_interface = os_strdup(pos);
  1728. #endif /* CONFIG_FULL_DYNAMIC_VLAN */
  1729. } else if (os_strcmp(buf, "passive_scan_interval") == 0) {
  1730. conf->passive_scan_interval = atoi(pos);
  1731. } else if (os_strcmp(buf, "passive_scan_listen") == 0) {
  1732. conf->passive_scan_listen = atoi(pos);
  1733. } else if (os_strcmp(buf, "passive_scan_mode") == 0) {
  1734. conf->passive_scan_mode = atoi(pos);
  1735. } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
  1736. conf->ap_table_max_size = atoi(pos);
  1737. } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
  1738. conf->ap_table_expiration_time = atoi(pos);
  1739. } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
  1740. if (hostapd_config_tx_queue(conf, buf, pos)) {
  1741. printf("Line %d: invalid TX queue item\n",
  1742. line);
  1743. errors++;
  1744. }
  1745. } else if (os_strcmp(buf, "wme_enabled") == 0) {
  1746. bss->wme_enabled = atoi(pos);
  1747. } else if (os_strncmp(buf, "wme_ac_", 7) == 0) {
  1748. if (hostapd_config_wme_ac(conf, buf, pos)) {
  1749. printf("Line %d: invalid wme ac item\n",
  1750. line);
  1751. errors++;
  1752. }
  1753. } else if (os_strcmp(buf, "bss") == 0) {
  1754. if (hostapd_config_bss(conf, pos)) {
  1755. printf("Line %d: invalid bss item\n", line);
  1756. errors++;
  1757. }
  1758. } else if (os_strcmp(buf, "bssid") == 0) {
  1759. if (bss == conf->bss &&
  1760. (!conf->driver || !conf->driver->init_bssid)) {
  1761. printf("Line %d: bssid item not allowed "
  1762. "for the default interface and this "
  1763. "driver\n", line);
  1764. errors++;
  1765. } else if (hwaddr_aton(pos, bss->bssid)) {
  1766. printf("Line %d: invalid bssid item\n", line);
  1767. errors++;
  1768. }
  1769. #ifdef CONFIG_IEEE80211W
  1770. } else if (os_strcmp(buf, "ieee80211w") == 0) {
  1771. bss->ieee80211w = atoi(pos);
  1772. } else if (os_strcmp(buf, "assoc_ping_timeout") == 0) {
  1773. bss->assoc_ping_timeout = atoi(pos);
  1774. if (bss->assoc_ping_timeout == 0) {
  1775. printf("Line %d: invalid assoc_ping_timeout\n",
  1776. line);
  1777. errors++;
  1778. }
  1779. } else if (os_strcmp(buf, "assoc_ping_attempts") == 0) {
  1780. bss->assoc_ping_timeout = atoi(pos);
  1781. if (bss->assoc_ping_timeout == 0) {
  1782. printf("Line %d: invalid assoc_ping_attempts "
  1783. "(valid range: 1..255)\n",
  1784. line);
  1785. errors++;
  1786. }
  1787. #endif /* CONFIG_IEEE80211W */
  1788. #ifdef CONFIG_IEEE80211N
  1789. } else if (os_strcmp(buf, "ieee80211n") == 0) {
  1790. conf->ieee80211n = atoi(pos);
  1791. #endif /* CONFIG_IEEE80211N */
  1792. } else if (os_strcmp(buf, "max_listen_interval") == 0) {
  1793. bss->max_listen_interval = atoi(pos);
  1794. } else if (os_strcmp(buf, "okc") == 0) {
  1795. bss->okc = atoi(pos);
  1796. } else {
  1797. printf("Line %d: unknown configuration item '%s'\n",
  1798. line, buf);
  1799. errors++;
  1800. }
  1801. }
  1802. fclose(f);
  1803. if (bss->individual_wep_key_len == 0) {
  1804. /* individual keys are not use; can use key idx0 for broadcast
  1805. * keys */
  1806. bss->broadcast_key_idx_min = 0;
  1807. }
  1808. /* Select group cipher based on the enabled pairwise cipher suites */
  1809. pairwise = 0;
  1810. if (bss->wpa & 1)
  1811. pairwise |= bss->wpa_pairwise;
  1812. if (bss->wpa & 2) {
  1813. if (bss->rsn_pairwise == 0)
  1814. bss->rsn_pairwise = bss->wpa_pairwise;
  1815. pairwise |= bss->rsn_pairwise;
  1816. }
  1817. if (pairwise & WPA_CIPHER_TKIP)
  1818. bss->wpa_group = WPA_CIPHER_TKIP;
  1819. else
  1820. bss->wpa_group = WPA_CIPHER_CCMP;
  1821. for (i = 0; i < conf->num_bss; i++) {
  1822. bss = &conf->bss[i];
  1823. bss->radius->auth_server = bss->radius->auth_servers;
  1824. bss->radius->acct_server = bss->radius->acct_servers;
  1825. if (bss->wpa && bss->ieee802_1x) {
  1826. bss->ssid.security_policy = SECURITY_WPA;
  1827. } else if (bss->wpa) {
  1828. bss->ssid.security_policy = SECURITY_WPA_PSK;
  1829. } else if (bss->ieee802_1x) {
  1830. bss->ssid.security_policy = SECURITY_IEEE_802_1X;
  1831. bss->ssid.wep.default_len = bss->default_wep_key_len;
  1832. } else if (bss->ssid.wep.keys_set)
  1833. bss->ssid.security_policy = SECURITY_STATIC_WEP;
  1834. else
  1835. bss->ssid.security_policy = SECURITY_PLAINTEXT;
  1836. }
  1837. if (hostapd_config_check(conf))
  1838. errors++;
  1839. if (errors) {
  1840. printf("%d errors found in configuration file '%s'\n",
  1841. errors, fname);
  1842. hostapd_config_free(conf);
  1843. conf = NULL;
  1844. }
  1845. return conf;
  1846. }
  1847. int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
  1848. {
  1849. int i;
  1850. if (a->idx != b->idx || a->default_len != b->default_len)
  1851. return 1;
  1852. for (i = 0; i < NUM_WEP_KEYS; i++)
  1853. if (a->len[i] != b->len[i] ||
  1854. os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
  1855. return 1;
  1856. return 0;
  1857. }
  1858. static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
  1859. int num_servers)
  1860. {
  1861. int i;
  1862. for (i = 0; i < num_servers; i++) {
  1863. os_free(servers[i].shared_secret);
  1864. }
  1865. os_free(servers);
  1866. }
  1867. static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
  1868. {
  1869. os_free(user->identity);
  1870. os_free(user->password);
  1871. os_free(user);
  1872. }
  1873. static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
  1874. {
  1875. int i;
  1876. for (i = 0; i < NUM_WEP_KEYS; i++) {
  1877. os_free(keys->key[i]);
  1878. keys->key[i] = NULL;
  1879. }
  1880. }
  1881. static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
  1882. {
  1883. struct hostapd_wpa_psk *psk, *prev;
  1884. struct hostapd_eap_user *user, *prev_user;
  1885. if (conf == NULL)
  1886. return;
  1887. psk = conf->ssid.wpa_psk;
  1888. while (psk) {
  1889. prev = psk;
  1890. psk = psk->next;
  1891. os_free(prev);
  1892. }
  1893. os_free(conf->ssid.wpa_passphrase);
  1894. os_free(conf->ssid.wpa_psk_file);
  1895. #ifdef CONFIG_FULL_DYNAMIC_VLAN
  1896. os_free(conf->ssid.vlan_tagged_interface);
  1897. #endif /* CONFIG_FULL_DYNAMIC_VLAN */
  1898. user = conf->eap_user;
  1899. while (user) {
  1900. prev_user = user;
  1901. user = user->next;
  1902. hostapd_config_free_eap_user(prev_user);
  1903. }
  1904. os_free(conf->dump_log_name);
  1905. os_free(conf->eap_req_id_text);
  1906. os_free(conf->accept_mac);
  1907. os_free(conf->deny_mac);
  1908. os_free(conf->nas_identifier);
  1909. hostapd_config_free_radius(conf->radius->auth_servers,
  1910. conf->radius->num_auth_servers);
  1911. hostapd_config_free_radius(conf->radius->acct_servers,
  1912. conf->radius->num_acct_servers);
  1913. os_free(conf->rsn_preauth_interfaces);
  1914. os_free(conf->ctrl_interface);
  1915. os_free(conf->ca_cert);
  1916. os_free(conf->server_cert);
  1917. os_free(conf->private_key);
  1918. os_free(conf->private_key_passwd);
  1919. os_free(conf->dh_file);
  1920. os_free(conf->pac_opaque_encr_key);
  1921. os_free(conf->eap_fast_a_id);
  1922. os_free(conf->eap_sim_db);
  1923. os_free(conf->radius_server_clients);
  1924. os_free(conf->test_socket);
  1925. os_free(conf->radius);
  1926. hostapd_config_free_vlan(conf);
  1927. if (conf->ssid.dyn_vlan_keys) {
  1928. struct hostapd_ssid *ssid = &conf->ssid;
  1929. size_t i;
  1930. for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
  1931. if (ssid->dyn_vlan_keys[i] == NULL)
  1932. continue;
  1933. hostapd_config_free_wep(ssid->dyn_vlan_keys[i]);
  1934. os_free(ssid->dyn_vlan_keys[i]);
  1935. }
  1936. os_free(ssid->dyn_vlan_keys);
  1937. ssid->dyn_vlan_keys = NULL;
  1938. }
  1939. #ifdef CONFIG_IEEE80211R
  1940. {
  1941. struct ft_remote_r0kh *r0kh, *r0kh_prev;
  1942. struct ft_remote_r1kh *r1kh, *r1kh_prev;
  1943. r0kh = conf->r0kh_list;
  1944. conf->r0kh_list = NULL;
  1945. while (r0kh) {
  1946. r0kh_prev = r0kh;
  1947. r0kh = r0kh->next;
  1948. os_free(r0kh_prev);
  1949. }
  1950. r1kh = conf->r1kh_list;
  1951. conf->r1kh_list = NULL;
  1952. while (r1kh) {
  1953. r1kh_prev = r1kh;
  1954. r1kh = r1kh->next;
  1955. os_free(r1kh_prev);
  1956. }
  1957. }
  1958. #endif /* CONFIG_IEEE80211R */
  1959. }
  1960. void hostapd_config_free(struct hostapd_config *conf)
  1961. {
  1962. size_t i;
  1963. if (conf == NULL)
  1964. return;
  1965. for (i = 0; i < conf->num_bss; i++)
  1966. hostapd_config_free_bss(&conf->bss[i]);
  1967. os_free(conf->bss);
  1968. os_free(conf);
  1969. }
  1970. /* Perform a binary search for given MAC address from a pre-sorted list.
  1971. * Returns 1 if address is in the list or 0 if not. */
  1972. int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
  1973. const u8 *addr, int *vlan_id)
  1974. {
  1975. int start, end, middle, res;
  1976. start = 0;
  1977. end = num_entries - 1;
  1978. while (start <= end) {
  1979. middle = (start + end) / 2;
  1980. res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
  1981. if (res == 0) {
  1982. if (vlan_id)
  1983. *vlan_id = list[middle].vlan_id;
  1984. return 1;
  1985. }
  1986. if (res < 0)
  1987. start = middle + 1;
  1988. else
  1989. end = middle - 1;
  1990. }
  1991. return 0;
  1992. }
  1993. int hostapd_rate_found(int *list, int rate)
  1994. {
  1995. int i;
  1996. if (list == NULL)
  1997. return 0;
  1998. for (i = 0; list[i] >= 0; i++)
  1999. if (list[i] == rate)
  2000. return 1;
  2001. return 0;
  2002. }
  2003. const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
  2004. {
  2005. struct hostapd_vlan *v = vlan;
  2006. while (v) {
  2007. if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
  2008. return v->ifname;
  2009. v = v->next;
  2010. }
  2011. return NULL;
  2012. }
  2013. const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
  2014. const u8 *addr, const u8 *prev_psk)
  2015. {
  2016. struct hostapd_wpa_psk *psk;
  2017. int next_ok = prev_psk == NULL;
  2018. for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
  2019. if (next_ok &&
  2020. (psk->group || os_memcmp(psk->addr, addr, ETH_ALEN) == 0))
  2021. return psk->psk;
  2022. if (psk->psk == prev_psk)
  2023. next_ok = 1;
  2024. }
  2025. return NULL;
  2026. }
  2027. const struct hostapd_eap_user *
  2028. hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
  2029. size_t identity_len, int phase2)
  2030. {
  2031. struct hostapd_eap_user *user = conf->eap_user;
  2032. while (user) {
  2033. if (!phase2 && user->identity == NULL) {
  2034. /* Wildcard match */
  2035. break;
  2036. }
  2037. if (user->phase2 == !!phase2 && user->wildcard_prefix &&
  2038. identity_len >= user->identity_len &&
  2039. os_memcmp(user->identity, identity, user->identity_len) ==
  2040. 0) {
  2041. /* Wildcard prefix match */
  2042. break;
  2043. }
  2044. if (user->phase2 == !!phase2 &&
  2045. user->identity_len == identity_len &&
  2046. os_memcmp(user->identity, identity, identity_len) == 0)
  2047. break;
  2048. user = user->next;
  2049. }
  2050. return user;
  2051. }