config_file.c 96 KB

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