config.c 67 KB

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