config.c 63 KB

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