config.c 68 KB

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