config_file.c 84 KB

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