config_file.c 103 KB

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