config_file.c 101 KB

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