config.c 67 KB

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