config_file.c 87 KB

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