config_file.c 99 KB

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