config.c 66 KB

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