config.c 66 KB

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