config.c 56 KB

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