config_file.c 108 KB

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