config_file.c 78 KB

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