config.c 66 KB

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