config_file.c 100 KB

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