config_file.c 85 KB

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