config.c 68 KB

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