config.c 62 KB

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