config_file.c 88 KB

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