config_file.c 103 KB

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