config_file.c 104 KB

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