config_file.c 103 KB

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