config.c 68 KB

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