config.c 68 KB

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