config_file.c 87 KB

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