config_file.c 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337
  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. return -1;
  1437. }
  1438. os_memcpy(bss->osu_ssid, str, slen);
  1439. bss->osu_ssid_len = slen;
  1440. os_free(str);
  1441. return 0;
  1442. }
  1443. static int hs20_parse_osu_server_uri(struct hostapd_bss_config *bss,
  1444. char *pos, int line)
  1445. {
  1446. struct hs20_osu_provider *p;
  1447. p = os_realloc_array(bss->hs20_osu_providers,
  1448. bss->hs20_osu_providers_count + 1, sizeof(*p));
  1449. if (p == NULL)
  1450. return -1;
  1451. bss->hs20_osu_providers = p;
  1452. bss->last_osu = &bss->hs20_osu_providers[bss->hs20_osu_providers_count];
  1453. bss->hs20_osu_providers_count++;
  1454. os_memset(bss->last_osu, 0, sizeof(*p));
  1455. bss->last_osu->server_uri = os_strdup(pos);
  1456. return 0;
  1457. }
  1458. static int hs20_parse_osu_friendly_name(struct hostapd_bss_config *bss,
  1459. char *pos, int line)
  1460. {
  1461. if (bss->last_osu == NULL) {
  1462. wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
  1463. return -1;
  1464. }
  1465. if (parse_lang_string(&bss->last_osu->friendly_name,
  1466. &bss->last_osu->friendly_name_count, pos)) {
  1467. wpa_printf(MSG_ERROR, "Line %d: Invalid osu_friendly_name '%s'",
  1468. line, pos);
  1469. return -1;
  1470. }
  1471. return 0;
  1472. }
  1473. static int hs20_parse_osu_nai(struct hostapd_bss_config *bss,
  1474. char *pos, int line)
  1475. {
  1476. if (bss->last_osu == NULL) {
  1477. wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
  1478. return -1;
  1479. }
  1480. os_free(bss->last_osu->osu_nai);
  1481. bss->last_osu->osu_nai = os_strdup(pos);
  1482. if (bss->last_osu->osu_nai == NULL)
  1483. return -1;
  1484. return 0;
  1485. }
  1486. static int hs20_parse_osu_method_list(struct hostapd_bss_config *bss, char *pos,
  1487. int line)
  1488. {
  1489. if (bss->last_osu == NULL) {
  1490. wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
  1491. return -1;
  1492. }
  1493. if (hostapd_parse_intlist(&bss->last_osu->method_list, pos)) {
  1494. wpa_printf(MSG_ERROR, "Line %d: Invalid osu_method_list", line);
  1495. return -1;
  1496. }
  1497. return 0;
  1498. }
  1499. static int hs20_parse_osu_icon(struct hostapd_bss_config *bss, char *pos,
  1500. int line)
  1501. {
  1502. char **n;
  1503. struct hs20_osu_provider *p = bss->last_osu;
  1504. if (p == NULL) {
  1505. wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
  1506. return -1;
  1507. }
  1508. n = os_realloc_array(p->icons, p->icons_count + 1, sizeof(char *));
  1509. if (n == NULL)
  1510. return -1;
  1511. p->icons = n;
  1512. p->icons[p->icons_count] = os_strdup(pos);
  1513. if (p->icons[p->icons_count] == NULL)
  1514. return -1;
  1515. p->icons_count++;
  1516. return 0;
  1517. }
  1518. static int hs20_parse_osu_service_desc(struct hostapd_bss_config *bss,
  1519. char *pos, int line)
  1520. {
  1521. if (bss->last_osu == NULL) {
  1522. wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line);
  1523. return -1;
  1524. }
  1525. if (parse_lang_string(&bss->last_osu->service_desc,
  1526. &bss->last_osu->service_desc_count, pos)) {
  1527. wpa_printf(MSG_ERROR, "Line %d: Invalid osu_service_desc '%s'",
  1528. line, pos);
  1529. return -1;
  1530. }
  1531. return 0;
  1532. }
  1533. #endif /* CONFIG_HS20 */
  1534. #ifdef CONFIG_WPS_NFC
  1535. static struct wpabuf * hostapd_parse_bin(const char *buf)
  1536. {
  1537. size_t len;
  1538. struct wpabuf *ret;
  1539. len = os_strlen(buf);
  1540. if (len & 0x01)
  1541. return NULL;
  1542. len /= 2;
  1543. ret = wpabuf_alloc(len);
  1544. if (ret == NULL)
  1545. return NULL;
  1546. if (hexstr2bin(buf, wpabuf_put(ret, len), len)) {
  1547. wpabuf_free(ret);
  1548. return NULL;
  1549. }
  1550. return ret;
  1551. }
  1552. #endif /* CONFIG_WPS_NFC */
  1553. static int hostapd_config_fill(struct hostapd_config *conf,
  1554. struct hostapd_bss_config *bss,
  1555. char *buf, char *pos, int line)
  1556. {
  1557. int errors = 0;
  1558. {
  1559. if (os_strcmp(buf, "interface") == 0) {
  1560. os_strlcpy(conf->bss[0]->iface, pos,
  1561. sizeof(conf->bss[0]->iface));
  1562. } else if (os_strcmp(buf, "bridge") == 0) {
  1563. os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
  1564. } else if (os_strcmp(buf, "vlan_bridge") == 0) {
  1565. os_strlcpy(bss->vlan_bridge, pos,
  1566. sizeof(bss->vlan_bridge));
  1567. } else if (os_strcmp(buf, "wds_bridge") == 0) {
  1568. os_strlcpy(bss->wds_bridge, pos,
  1569. sizeof(bss->wds_bridge));
  1570. } else if (os_strcmp(buf, "driver") == 0) {
  1571. int j;
  1572. /* clear to get error below if setting is invalid */
  1573. conf->driver = NULL;
  1574. for (j = 0; wpa_drivers[j]; j++) {
  1575. if (os_strcmp(pos, wpa_drivers[j]->name) == 0)
  1576. {
  1577. conf->driver = wpa_drivers[j];
  1578. break;
  1579. }
  1580. }
  1581. if (conf->driver == NULL) {
  1582. wpa_printf(MSG_ERROR, "Line %d: invalid/"
  1583. "unknown driver '%s'", line, pos);
  1584. errors++;
  1585. }
  1586. } else if (os_strcmp(buf, "debug") == 0) {
  1587. wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
  1588. "configuration variable is not used "
  1589. "anymore", line);
  1590. } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
  1591. bss->logger_syslog_level = atoi(pos);
  1592. } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
  1593. bss->logger_stdout_level = atoi(pos);
  1594. } else if (os_strcmp(buf, "logger_syslog") == 0) {
  1595. bss->logger_syslog = atoi(pos);
  1596. } else if (os_strcmp(buf, "logger_stdout") == 0) {
  1597. bss->logger_stdout = atoi(pos);
  1598. } else if (os_strcmp(buf, "dump_file") == 0) {
  1599. wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore",
  1600. line);
  1601. } else if (os_strcmp(buf, "ssid") == 0) {
  1602. bss->ssid.ssid_len = os_strlen(pos);
  1603. if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
  1604. bss->ssid.ssid_len < 1) {
  1605. wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
  1606. "'%s'", line, pos);
  1607. errors++;
  1608. } else {
  1609. os_memcpy(bss->ssid.ssid, pos,
  1610. bss->ssid.ssid_len);
  1611. bss->ssid.ssid_set = 1;
  1612. }
  1613. } else if (os_strcmp(buf, "ssid2") == 0) {
  1614. size_t slen;
  1615. char *str = wpa_config_parse_string(pos, &slen);
  1616. if (str == NULL || slen < 1 ||
  1617. slen > HOSTAPD_MAX_SSID_LEN) {
  1618. wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
  1619. "'%s'", line, pos);
  1620. errors++;
  1621. } else {
  1622. os_memcpy(bss->ssid.ssid, str, slen);
  1623. bss->ssid.ssid_len = slen;
  1624. bss->ssid.ssid_set = 1;
  1625. }
  1626. os_free(str);
  1627. } else if (os_strcmp(buf, "utf8_ssid") == 0) {
  1628. bss->ssid.utf8_ssid = atoi(pos) > 0;
  1629. } else if (os_strcmp(buf, "macaddr_acl") == 0) {
  1630. bss->macaddr_acl = atoi(pos);
  1631. if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
  1632. bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
  1633. bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
  1634. wpa_printf(MSG_ERROR, "Line %d: unknown "
  1635. "macaddr_acl %d",
  1636. line, bss->macaddr_acl);
  1637. }
  1638. } else if (os_strcmp(buf, "accept_mac_file") == 0) {
  1639. if (hostapd_config_read_maclist(pos, &bss->accept_mac,
  1640. &bss->num_accept_mac))
  1641. {
  1642. wpa_printf(MSG_ERROR, "Line %d: Failed to "
  1643. "read accept_mac_file '%s'",
  1644. line, pos);
  1645. errors++;
  1646. }
  1647. } else if (os_strcmp(buf, "deny_mac_file") == 0) {
  1648. if (hostapd_config_read_maclist(pos, &bss->deny_mac,
  1649. &bss->num_deny_mac)) {
  1650. wpa_printf(MSG_ERROR, "Line %d: Failed to "
  1651. "read deny_mac_file '%s'",
  1652. line, pos);
  1653. errors++;
  1654. }
  1655. } else if (os_strcmp(buf, "wds_sta") == 0) {
  1656. bss->wds_sta = atoi(pos);
  1657. } else if (os_strcmp(buf, "start_disabled") == 0) {
  1658. bss->start_disabled = atoi(pos);
  1659. } else if (os_strcmp(buf, "ap_isolate") == 0) {
  1660. bss->isolate = atoi(pos);
  1661. } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
  1662. bss->ap_max_inactivity = atoi(pos);
  1663. } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
  1664. bss->skip_inactivity_poll = atoi(pos);
  1665. } else if (os_strcmp(buf, "country_code") == 0) {
  1666. os_memcpy(conf->country, pos, 2);
  1667. /* FIX: make this configurable */
  1668. conf->country[2] = ' ';
  1669. } else if (os_strcmp(buf, "ieee80211d") == 0) {
  1670. conf->ieee80211d = atoi(pos);
  1671. } else if (os_strcmp(buf, "ieee80211h") == 0) {
  1672. conf->ieee80211h = atoi(pos);
  1673. } else if (os_strcmp(buf, "ieee8021x") == 0) {
  1674. bss->ieee802_1x = atoi(pos);
  1675. } else if (os_strcmp(buf, "eapol_version") == 0) {
  1676. bss->eapol_version = atoi(pos);
  1677. if (bss->eapol_version < 1 ||
  1678. bss->eapol_version > 2) {
  1679. wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL "
  1680. "version (%d): '%s'.",
  1681. line, bss->eapol_version, pos);
  1682. errors++;
  1683. } else
  1684. wpa_printf(MSG_DEBUG, "eapol_version=%d",
  1685. bss->eapol_version);
  1686. #ifdef EAP_SERVER
  1687. } else if (os_strcmp(buf, "eap_authenticator") == 0) {
  1688. bss->eap_server = atoi(pos);
  1689. wpa_printf(MSG_ERROR, "Line %d: obsolete "
  1690. "eap_authenticator used; this has been "
  1691. "renamed to eap_server", line);
  1692. } else if (os_strcmp(buf, "eap_server") == 0) {
  1693. bss->eap_server = atoi(pos);
  1694. } else if (os_strcmp(buf, "eap_user_file") == 0) {
  1695. if (hostapd_config_read_eap_user(pos, bss))
  1696. errors++;
  1697. } else if (os_strcmp(buf, "ca_cert") == 0) {
  1698. os_free(bss->ca_cert);
  1699. bss->ca_cert = os_strdup(pos);
  1700. } else if (os_strcmp(buf, "server_cert") == 0) {
  1701. os_free(bss->server_cert);
  1702. bss->server_cert = os_strdup(pos);
  1703. } else if (os_strcmp(buf, "private_key") == 0) {
  1704. os_free(bss->private_key);
  1705. bss->private_key = os_strdup(pos);
  1706. } else if (os_strcmp(buf, "private_key_passwd") == 0) {
  1707. os_free(bss->private_key_passwd);
  1708. bss->private_key_passwd = os_strdup(pos);
  1709. } else if (os_strcmp(buf, "check_crl") == 0) {
  1710. bss->check_crl = atoi(pos);
  1711. } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) {
  1712. os_free(bss->ocsp_stapling_response);
  1713. bss->ocsp_stapling_response = os_strdup(pos);
  1714. } else if (os_strcmp(buf, "dh_file") == 0) {
  1715. os_free(bss->dh_file);
  1716. bss->dh_file = os_strdup(pos);
  1717. } else if (os_strcmp(buf, "fragment_size") == 0) {
  1718. bss->fragment_size = atoi(pos);
  1719. #ifdef EAP_SERVER_FAST
  1720. } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
  1721. os_free(bss->pac_opaque_encr_key);
  1722. bss->pac_opaque_encr_key = os_malloc(16);
  1723. if (bss->pac_opaque_encr_key == NULL) {
  1724. wpa_printf(MSG_ERROR, "Line %d: No memory for "
  1725. "pac_opaque_encr_key", line);
  1726. errors++;
  1727. } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
  1728. 16)) {
  1729. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1730. "pac_opaque_encr_key", line);
  1731. errors++;
  1732. }
  1733. } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
  1734. size_t idlen = os_strlen(pos);
  1735. if (idlen & 1) {
  1736. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1737. "eap_fast_a_id", line);
  1738. errors++;
  1739. } else {
  1740. os_free(bss->eap_fast_a_id);
  1741. bss->eap_fast_a_id = os_malloc(idlen / 2);
  1742. if (bss->eap_fast_a_id == NULL ||
  1743. hexstr2bin(pos, bss->eap_fast_a_id,
  1744. idlen / 2)) {
  1745. wpa_printf(MSG_ERROR, "Line %d: "
  1746. "Failed to parse "
  1747. "eap_fast_a_id", line);
  1748. errors++;
  1749. } else
  1750. bss->eap_fast_a_id_len = idlen / 2;
  1751. }
  1752. } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
  1753. os_free(bss->eap_fast_a_id_info);
  1754. bss->eap_fast_a_id_info = os_strdup(pos);
  1755. } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
  1756. bss->eap_fast_prov = atoi(pos);
  1757. } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
  1758. bss->pac_key_lifetime = atoi(pos);
  1759. } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
  1760. bss->pac_key_refresh_time = atoi(pos);
  1761. #endif /* EAP_SERVER_FAST */
  1762. #ifdef EAP_SERVER_SIM
  1763. } else if (os_strcmp(buf, "eap_sim_db") == 0) {
  1764. os_free(bss->eap_sim_db);
  1765. bss->eap_sim_db = os_strdup(pos);
  1766. } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
  1767. bss->eap_sim_aka_result_ind = atoi(pos);
  1768. #endif /* EAP_SERVER_SIM */
  1769. #ifdef EAP_SERVER_TNC
  1770. } else if (os_strcmp(buf, "tnc") == 0) {
  1771. bss->tnc = atoi(pos);
  1772. #endif /* EAP_SERVER_TNC */
  1773. #ifdef EAP_SERVER_PWD
  1774. } else if (os_strcmp(buf, "pwd_group") == 0) {
  1775. bss->pwd_group = atoi(pos);
  1776. #endif /* EAP_SERVER_PWD */
  1777. #endif /* EAP_SERVER */
  1778. } else if (os_strcmp(buf, "eap_message") == 0) {
  1779. char *term;
  1780. bss->eap_req_id_text = os_strdup(pos);
  1781. if (bss->eap_req_id_text == NULL) {
  1782. wpa_printf(MSG_ERROR, "Line %d: Failed to "
  1783. "allocate memory for "
  1784. "eap_req_id_text", line);
  1785. errors++;
  1786. return errors;
  1787. }
  1788. bss->eap_req_id_text_len =
  1789. os_strlen(bss->eap_req_id_text);
  1790. term = os_strstr(bss->eap_req_id_text, "\\0");
  1791. if (term) {
  1792. *term++ = '\0';
  1793. os_memmove(term, term + 1,
  1794. bss->eap_req_id_text_len -
  1795. (term - bss->eap_req_id_text) - 1);
  1796. bss->eap_req_id_text_len--;
  1797. }
  1798. } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
  1799. bss->default_wep_key_len = atoi(pos);
  1800. if (bss->default_wep_key_len > 13) {
  1801. wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
  1802. "key len %lu (= %lu bits)", line,
  1803. (unsigned long)
  1804. bss->default_wep_key_len,
  1805. (unsigned long)
  1806. bss->default_wep_key_len * 8);
  1807. errors++;
  1808. }
  1809. } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
  1810. bss->individual_wep_key_len = atoi(pos);
  1811. if (bss->individual_wep_key_len < 0 ||
  1812. bss->individual_wep_key_len > 13) {
  1813. wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
  1814. "key len %d (= %d bits)", line,
  1815. bss->individual_wep_key_len,
  1816. bss->individual_wep_key_len * 8);
  1817. errors++;
  1818. }
  1819. } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
  1820. bss->wep_rekeying_period = atoi(pos);
  1821. if (bss->wep_rekeying_period < 0) {
  1822. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1823. "period %d",
  1824. line, bss->wep_rekeying_period);
  1825. errors++;
  1826. }
  1827. } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
  1828. bss->eap_reauth_period = atoi(pos);
  1829. if (bss->eap_reauth_period < 0) {
  1830. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1831. "period %d",
  1832. line, bss->eap_reauth_period);
  1833. errors++;
  1834. }
  1835. } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
  1836. bss->eapol_key_index_workaround = atoi(pos);
  1837. #ifdef CONFIG_IAPP
  1838. } else if (os_strcmp(buf, "iapp_interface") == 0) {
  1839. bss->ieee802_11f = 1;
  1840. os_strlcpy(bss->iapp_iface, pos,
  1841. sizeof(bss->iapp_iface));
  1842. #endif /* CONFIG_IAPP */
  1843. } else if (os_strcmp(buf, "own_ip_addr") == 0) {
  1844. if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
  1845. wpa_printf(MSG_ERROR, "Line %d: invalid IP "
  1846. "address '%s'", line, pos);
  1847. errors++;
  1848. }
  1849. } else if (os_strcmp(buf, "nas_identifier") == 0) {
  1850. bss->nas_identifier = os_strdup(pos);
  1851. #ifndef CONFIG_NO_RADIUS
  1852. } else if (os_strcmp(buf, "auth_server_addr") == 0) {
  1853. if (hostapd_config_read_radius_addr(
  1854. &bss->radius->auth_servers,
  1855. &bss->radius->num_auth_servers, pos, 1812,
  1856. &bss->radius->auth_server)) {
  1857. wpa_printf(MSG_ERROR, "Line %d: invalid IP "
  1858. "address '%s'", line, pos);
  1859. errors++;
  1860. }
  1861. } else if (bss->radius->auth_server &&
  1862. os_strcmp(buf, "auth_server_port") == 0) {
  1863. bss->radius->auth_server->port = atoi(pos);
  1864. } else if (bss->radius->auth_server &&
  1865. os_strcmp(buf, "auth_server_shared_secret") == 0) {
  1866. int len = os_strlen(pos);
  1867. if (len == 0) {
  1868. /* RFC 2865, Ch. 3 */
  1869. wpa_printf(MSG_ERROR, "Line %d: empty shared "
  1870. "secret is not allowed.", line);
  1871. errors++;
  1872. }
  1873. bss->radius->auth_server->shared_secret =
  1874. (u8 *) os_strdup(pos);
  1875. bss->radius->auth_server->shared_secret_len = len;
  1876. } else if (os_strcmp(buf, "acct_server_addr") == 0) {
  1877. if (hostapd_config_read_radius_addr(
  1878. &bss->radius->acct_servers,
  1879. &bss->radius->num_acct_servers, pos, 1813,
  1880. &bss->radius->acct_server)) {
  1881. wpa_printf(MSG_ERROR, "Line %d: invalid IP "
  1882. "address '%s'", line, pos);
  1883. errors++;
  1884. }
  1885. } else if (bss->radius->acct_server &&
  1886. os_strcmp(buf, "acct_server_port") == 0) {
  1887. bss->radius->acct_server->port = atoi(pos);
  1888. } else if (bss->radius->acct_server &&
  1889. os_strcmp(buf, "acct_server_shared_secret") == 0) {
  1890. int len = os_strlen(pos);
  1891. if (len == 0) {
  1892. /* RFC 2865, Ch. 3 */
  1893. wpa_printf(MSG_ERROR, "Line %d: empty shared "
  1894. "secret is not allowed.", line);
  1895. errors++;
  1896. }
  1897. bss->radius->acct_server->shared_secret =
  1898. (u8 *) os_strdup(pos);
  1899. bss->radius->acct_server->shared_secret_len = len;
  1900. } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
  1901. 0) {
  1902. bss->radius->retry_primary_interval = atoi(pos);
  1903. } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
  1904. {
  1905. bss->acct_interim_interval = atoi(pos);
  1906. } else if (os_strcmp(buf, "radius_request_cui") == 0) {
  1907. bss->radius_request_cui = atoi(pos);
  1908. } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
  1909. struct hostapd_radius_attr *attr, *a;
  1910. attr = hostapd_parse_radius_attr(pos);
  1911. if (attr == NULL) {
  1912. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1913. "radius_auth_req_attr", line);
  1914. errors++;
  1915. } else if (bss->radius_auth_req_attr == NULL) {
  1916. bss->radius_auth_req_attr = attr;
  1917. } else {
  1918. a = bss->radius_auth_req_attr;
  1919. while (a->next)
  1920. a = a->next;
  1921. a->next = attr;
  1922. }
  1923. } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
  1924. struct hostapd_radius_attr *attr, *a;
  1925. attr = hostapd_parse_radius_attr(pos);
  1926. if (attr == NULL) {
  1927. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1928. "radius_acct_req_attr", line);
  1929. errors++;
  1930. } else if (bss->radius_acct_req_attr == NULL) {
  1931. bss->radius_acct_req_attr = attr;
  1932. } else {
  1933. a = bss->radius_acct_req_attr;
  1934. while (a->next)
  1935. a = a->next;
  1936. a->next = attr;
  1937. }
  1938. } else if (os_strcmp(buf, "radius_das_port") == 0) {
  1939. bss->radius_das_port = atoi(pos);
  1940. } else if (os_strcmp(buf, "radius_das_client") == 0) {
  1941. if (hostapd_parse_das_client(bss, pos) < 0) {
  1942. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1943. "DAS client", line);
  1944. errors++;
  1945. }
  1946. } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
  1947. bss->radius_das_time_window = atoi(pos);
  1948. } else if (os_strcmp(buf, "radius_das_require_event_timestamp")
  1949. == 0) {
  1950. bss->radius_das_require_event_timestamp = atoi(pos);
  1951. #endif /* CONFIG_NO_RADIUS */
  1952. } else if (os_strcmp(buf, "auth_algs") == 0) {
  1953. bss->auth_algs = atoi(pos);
  1954. if (bss->auth_algs == 0) {
  1955. wpa_printf(MSG_ERROR, "Line %d: no "
  1956. "authentication algorithms allowed",
  1957. line);
  1958. errors++;
  1959. }
  1960. } else if (os_strcmp(buf, "max_num_sta") == 0) {
  1961. bss->max_num_sta = atoi(pos);
  1962. if (bss->max_num_sta < 0 ||
  1963. bss->max_num_sta > MAX_STA_COUNT) {
  1964. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1965. "max_num_sta=%d; allowed range "
  1966. "0..%d", line, bss->max_num_sta,
  1967. MAX_STA_COUNT);
  1968. errors++;
  1969. }
  1970. } else if (os_strcmp(buf, "wpa") == 0) {
  1971. bss->wpa = atoi(pos);
  1972. } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
  1973. bss->wpa_group_rekey = atoi(pos);
  1974. } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
  1975. bss->wpa_strict_rekey = atoi(pos);
  1976. } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
  1977. bss->wpa_gmk_rekey = atoi(pos);
  1978. } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
  1979. bss->wpa_ptk_rekey = atoi(pos);
  1980. } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
  1981. int len = os_strlen(pos);
  1982. if (len < 8 || len > 63) {
  1983. wpa_printf(MSG_ERROR, "Line %d: invalid WPA "
  1984. "passphrase length %d (expected "
  1985. "8..63)", line, len);
  1986. errors++;
  1987. } else {
  1988. os_free(bss->ssid.wpa_passphrase);
  1989. bss->ssid.wpa_passphrase = os_strdup(pos);
  1990. if (bss->ssid.wpa_passphrase) {
  1991. os_free(bss->ssid.wpa_psk);
  1992. bss->ssid.wpa_psk = NULL;
  1993. bss->ssid.wpa_passphrase_set = 1;
  1994. }
  1995. }
  1996. } else if (os_strcmp(buf, "wpa_psk") == 0) {
  1997. os_free(bss->ssid.wpa_psk);
  1998. bss->ssid.wpa_psk =
  1999. os_zalloc(sizeof(struct hostapd_wpa_psk));
  2000. if (bss->ssid.wpa_psk == NULL)
  2001. errors++;
  2002. else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
  2003. PMK_LEN) ||
  2004. pos[PMK_LEN * 2] != '\0') {
  2005. wpa_printf(MSG_ERROR, "Line %d: Invalid PSK "
  2006. "'%s'.", line, pos);
  2007. errors++;
  2008. } else {
  2009. bss->ssid.wpa_psk->group = 1;
  2010. os_free(bss->ssid.wpa_passphrase);
  2011. bss->ssid.wpa_passphrase = NULL;
  2012. bss->ssid.wpa_psk_set = 1;
  2013. }
  2014. } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
  2015. os_free(bss->ssid.wpa_psk_file);
  2016. bss->ssid.wpa_psk_file = os_strdup(pos);
  2017. if (!bss->ssid.wpa_psk_file) {
  2018. wpa_printf(MSG_ERROR, "Line %d: allocation "
  2019. "failed", line);
  2020. errors++;
  2021. }
  2022. } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
  2023. bss->wpa_key_mgmt =
  2024. hostapd_config_parse_key_mgmt(line, pos);
  2025. if (bss->wpa_key_mgmt == -1)
  2026. errors++;
  2027. } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
  2028. bss->wpa_psk_radius = atoi(pos);
  2029. if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
  2030. bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
  2031. bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
  2032. wpa_printf(MSG_ERROR, "Line %d: unknown "
  2033. "wpa_psk_radius %d",
  2034. line, bss->wpa_psk_radius);
  2035. errors++;
  2036. }
  2037. } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
  2038. bss->wpa_pairwise =
  2039. hostapd_config_parse_cipher(line, pos);
  2040. if (bss->wpa_pairwise == -1 ||
  2041. bss->wpa_pairwise == 0)
  2042. errors++;
  2043. else if (bss->wpa_pairwise &
  2044. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
  2045. WPA_CIPHER_WEP104)) {
  2046. wpa_printf(MSG_ERROR, "Line %d: unsupported "
  2047. "pairwise cipher suite '%s'",
  2048. bss->wpa_pairwise, pos);
  2049. errors++;
  2050. }
  2051. } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
  2052. bss->rsn_pairwise =
  2053. hostapd_config_parse_cipher(line, pos);
  2054. if (bss->rsn_pairwise == -1 ||
  2055. bss->rsn_pairwise == 0)
  2056. errors++;
  2057. else if (bss->rsn_pairwise &
  2058. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
  2059. WPA_CIPHER_WEP104)) {
  2060. wpa_printf(MSG_ERROR, "Line %d: unsupported "
  2061. "pairwise cipher suite '%s'",
  2062. bss->rsn_pairwise, pos);
  2063. errors++;
  2064. }
  2065. #ifdef CONFIG_RSN_PREAUTH
  2066. } else if (os_strcmp(buf, "rsn_preauth") == 0) {
  2067. bss->rsn_preauth = atoi(pos);
  2068. } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
  2069. bss->rsn_preauth_interfaces = os_strdup(pos);
  2070. #endif /* CONFIG_RSN_PREAUTH */
  2071. #ifdef CONFIG_PEERKEY
  2072. } else if (os_strcmp(buf, "peerkey") == 0) {
  2073. bss->peerkey = atoi(pos);
  2074. #endif /* CONFIG_PEERKEY */
  2075. #ifdef CONFIG_IEEE80211R
  2076. } else if (os_strcmp(buf, "mobility_domain") == 0) {
  2077. if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
  2078. hexstr2bin(pos, bss->mobility_domain,
  2079. MOBILITY_DOMAIN_ID_LEN) != 0) {
  2080. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  2081. "mobility_domain '%s'", line, pos);
  2082. errors++;
  2083. return errors;
  2084. }
  2085. } else if (os_strcmp(buf, "r1_key_holder") == 0) {
  2086. if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
  2087. hexstr2bin(pos, bss->r1_key_holder,
  2088. FT_R1KH_ID_LEN) != 0) {
  2089. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  2090. "r1_key_holder '%s'", line, pos);
  2091. errors++;
  2092. return errors;
  2093. }
  2094. } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
  2095. bss->r0_key_lifetime = atoi(pos);
  2096. } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
  2097. bss->reassociation_deadline = atoi(pos);
  2098. } else if (os_strcmp(buf, "r0kh") == 0) {
  2099. if (add_r0kh(bss, pos) < 0) {
  2100. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  2101. "r0kh '%s'", line, pos);
  2102. errors++;
  2103. return errors;
  2104. }
  2105. } else if (os_strcmp(buf, "r1kh") == 0) {
  2106. if (add_r1kh(bss, pos) < 0) {
  2107. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  2108. "r1kh '%s'", line, pos);
  2109. errors++;
  2110. return errors;
  2111. }
  2112. } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
  2113. bss->pmk_r1_push = atoi(pos);
  2114. } else if (os_strcmp(buf, "ft_over_ds") == 0) {
  2115. bss->ft_over_ds = atoi(pos);
  2116. #endif /* CONFIG_IEEE80211R */
  2117. #ifndef CONFIG_NO_CTRL_IFACE
  2118. } else if (os_strcmp(buf, "ctrl_interface") == 0) {
  2119. os_free(bss->ctrl_interface);
  2120. bss->ctrl_interface = os_strdup(pos);
  2121. } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
  2122. #ifndef CONFIG_NATIVE_WINDOWS
  2123. struct group *grp;
  2124. char *endp;
  2125. const char *group = pos;
  2126. grp = getgrnam(group);
  2127. if (grp) {
  2128. bss->ctrl_interface_gid = grp->gr_gid;
  2129. bss->ctrl_interface_gid_set = 1;
  2130. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
  2131. " (from group name '%s')",
  2132. bss->ctrl_interface_gid, group);
  2133. return errors;
  2134. }
  2135. /* Group name not found - try to parse this as gid */
  2136. bss->ctrl_interface_gid = strtol(group, &endp, 10);
  2137. if (*group == '\0' || *endp != '\0') {
  2138. wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
  2139. "'%s'", line, group);
  2140. errors++;
  2141. return errors;
  2142. }
  2143. bss->ctrl_interface_gid_set = 1;
  2144. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
  2145. bss->ctrl_interface_gid);
  2146. #endif /* CONFIG_NATIVE_WINDOWS */
  2147. #endif /* CONFIG_NO_CTRL_IFACE */
  2148. #ifdef RADIUS_SERVER
  2149. } else if (os_strcmp(buf, "radius_server_clients") == 0) {
  2150. os_free(bss->radius_server_clients);
  2151. bss->radius_server_clients = os_strdup(pos);
  2152. } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
  2153. bss->radius_server_auth_port = atoi(pos);
  2154. } else if (os_strcmp(buf, "radius_server_acct_port") == 0) {
  2155. bss->radius_server_acct_port = atoi(pos);
  2156. } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
  2157. bss->radius_server_ipv6 = atoi(pos);
  2158. #endif /* RADIUS_SERVER */
  2159. } else if (os_strcmp(buf, "test_socket") == 0) {
  2160. os_free(bss->test_socket);
  2161. bss->test_socket = os_strdup(pos);
  2162. } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
  2163. bss->use_pae_group_addr = atoi(pos);
  2164. } else if (os_strcmp(buf, "hw_mode") == 0) {
  2165. if (os_strcmp(pos, "a") == 0)
  2166. conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
  2167. else if (os_strcmp(pos, "b") == 0)
  2168. conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
  2169. else if (os_strcmp(pos, "g") == 0)
  2170. conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
  2171. else if (os_strcmp(pos, "ad") == 0)
  2172. conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
  2173. else {
  2174. wpa_printf(MSG_ERROR, "Line %d: unknown "
  2175. "hw_mode '%s'", line, pos);
  2176. errors++;
  2177. }
  2178. } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
  2179. if (os_strcmp(pos, "a") == 0)
  2180. bss->wps_rf_bands = WPS_RF_50GHZ;
  2181. else if (os_strcmp(pos, "g") == 0 ||
  2182. os_strcmp(pos, "b") == 0)
  2183. bss->wps_rf_bands = WPS_RF_24GHZ;
  2184. else if (os_strcmp(pos, "ag") == 0 ||
  2185. os_strcmp(pos, "ga") == 0)
  2186. bss->wps_rf_bands =
  2187. WPS_RF_24GHZ | WPS_RF_50GHZ;
  2188. else {
  2189. wpa_printf(MSG_ERROR, "Line %d: unknown "
  2190. "wps_rf_band '%s'", line, pos);
  2191. errors++;
  2192. }
  2193. } else if (os_strcmp(buf, "channel") == 0) {
  2194. if (os_strcmp(pos, "acs_survey") == 0) {
  2195. #ifndef CONFIG_ACS
  2196. wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled",
  2197. line);
  2198. errors++;
  2199. #endif /* CONFIG_ACS */
  2200. conf->channel = 0;
  2201. } else
  2202. conf->channel = atoi(pos);
  2203. } else if (os_strcmp(buf, "chanlist") == 0) {
  2204. if (hostapd_parse_intlist(&conf->chanlist, pos)) {
  2205. wpa_printf(MSG_ERROR,
  2206. "Line %d: invalid channel list",
  2207. line);
  2208. errors++;
  2209. }
  2210. } else if (os_strcmp(buf, "beacon_int") == 0) {
  2211. int val = atoi(pos);
  2212. /* MIB defines range as 1..65535, but very small values
  2213. * cause problems with the current implementation.
  2214. * Since it is unlikely that this small numbers are
  2215. * useful in real life scenarios, do not allow beacon
  2216. * period to be set below 15 TU. */
  2217. if (val < 15 || val > 65535) {
  2218. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2219. "beacon_int %d (expected "
  2220. "15..65535)", line, val);
  2221. errors++;
  2222. } else
  2223. conf->beacon_int = val;
  2224. #ifdef CONFIG_ACS
  2225. } else if (os_strcmp(buf, "acs_num_scans") == 0) {
  2226. int val = atoi(pos);
  2227. if (val <= 0 || val > 100) {
  2228. wpa_printf(MSG_ERROR, "Line %d: invalid acs_num_scans %d (expected 1..100)",
  2229. line, val);
  2230. errors++;
  2231. } else
  2232. conf->acs_num_scans = val;
  2233. #endif /* CONFIG_ACS */
  2234. } else if (os_strcmp(buf, "dtim_period") == 0) {
  2235. bss->dtim_period = atoi(pos);
  2236. if (bss->dtim_period < 1 || bss->dtim_period > 255) {
  2237. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2238. "dtim_period %d",
  2239. line, bss->dtim_period);
  2240. errors++;
  2241. }
  2242. } else if (os_strcmp(buf, "rts_threshold") == 0) {
  2243. conf->rts_threshold = atoi(pos);
  2244. if (conf->rts_threshold < 0 ||
  2245. conf->rts_threshold > 2347) {
  2246. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2247. "rts_threshold %d",
  2248. line, conf->rts_threshold);
  2249. errors++;
  2250. }
  2251. } else if (os_strcmp(buf, "fragm_threshold") == 0) {
  2252. conf->fragm_threshold = atoi(pos);
  2253. if (conf->fragm_threshold < 256 ||
  2254. conf->fragm_threshold > 2346) {
  2255. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2256. "fragm_threshold %d",
  2257. line, conf->fragm_threshold);
  2258. errors++;
  2259. }
  2260. } else if (os_strcmp(buf, "send_probe_response") == 0) {
  2261. int val = atoi(pos);
  2262. if (val != 0 && val != 1) {
  2263. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2264. "send_probe_response %d (expected "
  2265. "0 or 1)", line, val);
  2266. } else
  2267. conf->send_probe_response = val;
  2268. } else if (os_strcmp(buf, "supported_rates") == 0) {
  2269. if (hostapd_parse_intlist(&conf->supported_rates, pos))
  2270. {
  2271. wpa_printf(MSG_ERROR, "Line %d: invalid rate "
  2272. "list", line);
  2273. errors++;
  2274. }
  2275. } else if (os_strcmp(buf, "basic_rates") == 0) {
  2276. if (hostapd_parse_intlist(&conf->basic_rates, pos)) {
  2277. wpa_printf(MSG_ERROR, "Line %d: invalid rate "
  2278. "list", line);
  2279. errors++;
  2280. }
  2281. } else if (os_strcmp(buf, "preamble") == 0) {
  2282. if (atoi(pos))
  2283. conf->preamble = SHORT_PREAMBLE;
  2284. else
  2285. conf->preamble = LONG_PREAMBLE;
  2286. } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
  2287. bss->ignore_broadcast_ssid = atoi(pos);
  2288. } else if (os_strcmp(buf, "wep_default_key") == 0) {
  2289. bss->ssid.wep.idx = atoi(pos);
  2290. if (bss->ssid.wep.idx > 3) {
  2291. wpa_printf(MSG_ERROR, "Invalid "
  2292. "wep_default_key index %d",
  2293. bss->ssid.wep.idx);
  2294. errors++;
  2295. }
  2296. } else if (os_strcmp(buf, "wep_key0") == 0 ||
  2297. os_strcmp(buf, "wep_key1") == 0 ||
  2298. os_strcmp(buf, "wep_key2") == 0 ||
  2299. os_strcmp(buf, "wep_key3") == 0) {
  2300. if (hostapd_config_read_wep(&bss->ssid.wep,
  2301. buf[7] - '0', pos)) {
  2302. wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
  2303. "key '%s'", line, buf);
  2304. errors++;
  2305. }
  2306. #ifndef CONFIG_NO_VLAN
  2307. } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
  2308. bss->ssid.dynamic_vlan = atoi(pos);
  2309. } else if (os_strcmp(buf, "vlan_file") == 0) {
  2310. if (hostapd_config_read_vlan_file(bss, pos)) {
  2311. wpa_printf(MSG_ERROR, "Line %d: failed to "
  2312. "read VLAN file '%s'", line, pos);
  2313. errors++;
  2314. }
  2315. } else if (os_strcmp(buf, "vlan_naming") == 0) {
  2316. bss->ssid.vlan_naming = atoi(pos);
  2317. if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
  2318. bss->ssid.vlan_naming < 0) {
  2319. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2320. "naming scheme %d", line,
  2321. bss->ssid.vlan_naming);
  2322. errors++;
  2323. }
  2324. #ifdef CONFIG_FULL_DYNAMIC_VLAN
  2325. } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
  2326. bss->ssid.vlan_tagged_interface = os_strdup(pos);
  2327. #endif /* CONFIG_FULL_DYNAMIC_VLAN */
  2328. #endif /* CONFIG_NO_VLAN */
  2329. } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
  2330. conf->ap_table_max_size = atoi(pos);
  2331. } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
  2332. conf->ap_table_expiration_time = atoi(pos);
  2333. } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
  2334. if (hostapd_config_tx_queue(conf, buf, pos)) {
  2335. wpa_printf(MSG_ERROR, "Line %d: invalid TX "
  2336. "queue item", line);
  2337. errors++;
  2338. }
  2339. } else if (os_strcmp(buf, "wme_enabled") == 0 ||
  2340. os_strcmp(buf, "wmm_enabled") == 0) {
  2341. bss->wmm_enabled = atoi(pos);
  2342. } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
  2343. bss->wmm_uapsd = atoi(pos);
  2344. } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
  2345. os_strncmp(buf, "wmm_ac_", 7) == 0) {
  2346. if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf,
  2347. pos)) {
  2348. wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
  2349. "ac item", line);
  2350. errors++;
  2351. }
  2352. } else if (os_strcmp(buf, "bss") == 0) {
  2353. if (hostapd_config_bss(conf, pos)) {
  2354. wpa_printf(MSG_ERROR, "Line %d: invalid bss "
  2355. "item", line);
  2356. errors++;
  2357. }
  2358. } else if (os_strcmp(buf, "bssid") == 0) {
  2359. if (hwaddr_aton(pos, bss->bssid)) {
  2360. wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
  2361. "item", line);
  2362. errors++;
  2363. }
  2364. #ifdef CONFIG_IEEE80211W
  2365. } else if (os_strcmp(buf, "ieee80211w") == 0) {
  2366. bss->ieee80211w = atoi(pos);
  2367. } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
  2368. bss->assoc_sa_query_max_timeout = atoi(pos);
  2369. if (bss->assoc_sa_query_max_timeout == 0) {
  2370. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2371. "assoc_sa_query_max_timeout", line);
  2372. errors++;
  2373. }
  2374. } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0)
  2375. {
  2376. bss->assoc_sa_query_retry_timeout = atoi(pos);
  2377. if (bss->assoc_sa_query_retry_timeout == 0) {
  2378. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2379. "assoc_sa_query_retry_timeout",
  2380. line);
  2381. errors++;
  2382. }
  2383. #endif /* CONFIG_IEEE80211W */
  2384. #ifdef CONFIG_IEEE80211N
  2385. } else if (os_strcmp(buf, "ieee80211n") == 0) {
  2386. conf->ieee80211n = atoi(pos);
  2387. } else if (os_strcmp(buf, "ht_capab") == 0) {
  2388. if (hostapd_config_ht_capab(conf, pos) < 0) {
  2389. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2390. "ht_capab", line);
  2391. errors++;
  2392. }
  2393. } else if (os_strcmp(buf, "require_ht") == 0) {
  2394. conf->require_ht = atoi(pos);
  2395. } else if (os_strcmp(buf, "obss_interval") == 0) {
  2396. conf->obss_interval = atoi(pos);
  2397. #endif /* CONFIG_IEEE80211N */
  2398. #ifdef CONFIG_IEEE80211AC
  2399. } else if (os_strcmp(buf, "ieee80211ac") == 0) {
  2400. conf->ieee80211ac = atoi(pos);
  2401. } else if (os_strcmp(buf, "vht_capab") == 0) {
  2402. if (hostapd_config_vht_capab(conf, pos) < 0) {
  2403. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2404. "vht_capab", line);
  2405. errors++;
  2406. }
  2407. } else if (os_strcmp(buf, "require_vht") == 0) {
  2408. conf->require_vht = atoi(pos);
  2409. } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
  2410. conf->vht_oper_chwidth = atoi(pos);
  2411. } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0)
  2412. {
  2413. conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
  2414. } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0)
  2415. {
  2416. conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
  2417. #endif /* CONFIG_IEEE80211AC */
  2418. } else if (os_strcmp(buf, "max_listen_interval") == 0) {
  2419. bss->max_listen_interval = atoi(pos);
  2420. } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
  2421. bss->disable_pmksa_caching = atoi(pos);
  2422. } else if (os_strcmp(buf, "okc") == 0) {
  2423. bss->okc = atoi(pos);
  2424. #ifdef CONFIG_WPS
  2425. } else if (os_strcmp(buf, "wps_state") == 0) {
  2426. bss->wps_state = atoi(pos);
  2427. if (bss->wps_state < 0 || bss->wps_state > 2) {
  2428. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2429. "wps_state", line);
  2430. errors++;
  2431. }
  2432. } else if (os_strcmp(buf, "wps_independent") == 0) {
  2433. bss->wps_independent = atoi(pos);
  2434. } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
  2435. bss->ap_setup_locked = atoi(pos);
  2436. } else if (os_strcmp(buf, "uuid") == 0) {
  2437. if (uuid_str2bin(pos, bss->uuid)) {
  2438. wpa_printf(MSG_ERROR, "Line %d: invalid UUID",
  2439. line);
  2440. errors++;
  2441. }
  2442. } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
  2443. os_free(bss->wps_pin_requests);
  2444. bss->wps_pin_requests = os_strdup(pos);
  2445. } else if (os_strcmp(buf, "device_name") == 0) {
  2446. if (os_strlen(pos) > 32) {
  2447. wpa_printf(MSG_ERROR, "Line %d: Too long "
  2448. "device_name", line);
  2449. errors++;
  2450. }
  2451. os_free(bss->device_name);
  2452. bss->device_name = os_strdup(pos);
  2453. } else if (os_strcmp(buf, "manufacturer") == 0) {
  2454. if (os_strlen(pos) > 64) {
  2455. wpa_printf(MSG_ERROR, "Line %d: Too long "
  2456. "manufacturer", line);
  2457. errors++;
  2458. }
  2459. os_free(bss->manufacturer);
  2460. bss->manufacturer = os_strdup(pos);
  2461. } else if (os_strcmp(buf, "model_name") == 0) {
  2462. if (os_strlen(pos) > 32) {
  2463. wpa_printf(MSG_ERROR, "Line %d: Too long "
  2464. "model_name", line);
  2465. errors++;
  2466. }
  2467. os_free(bss->model_name);
  2468. bss->model_name = os_strdup(pos);
  2469. } else if (os_strcmp(buf, "model_number") == 0) {
  2470. if (os_strlen(pos) > 32) {
  2471. wpa_printf(MSG_ERROR, "Line %d: Too long "
  2472. "model_number", line);
  2473. errors++;
  2474. }
  2475. os_free(bss->model_number);
  2476. bss->model_number = os_strdup(pos);
  2477. } else if (os_strcmp(buf, "serial_number") == 0) {
  2478. if (os_strlen(pos) > 32) {
  2479. wpa_printf(MSG_ERROR, "Line %d: Too long "
  2480. "serial_number", line);
  2481. errors++;
  2482. }
  2483. os_free(bss->serial_number);
  2484. bss->serial_number = os_strdup(pos);
  2485. } else if (os_strcmp(buf, "device_type") == 0) {
  2486. if (wps_dev_type_str2bin(pos, bss->device_type))
  2487. errors++;
  2488. } else if (os_strcmp(buf, "config_methods") == 0) {
  2489. os_free(bss->config_methods);
  2490. bss->config_methods = os_strdup(pos);
  2491. } else if (os_strcmp(buf, "os_version") == 0) {
  2492. if (hexstr2bin(pos, bss->os_version, 4)) {
  2493. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2494. "os_version", line);
  2495. errors++;
  2496. }
  2497. } else if (os_strcmp(buf, "ap_pin") == 0) {
  2498. os_free(bss->ap_pin);
  2499. bss->ap_pin = os_strdup(pos);
  2500. } else if (os_strcmp(buf, "skip_cred_build") == 0) {
  2501. bss->skip_cred_build = atoi(pos);
  2502. } else if (os_strcmp(buf, "extra_cred") == 0) {
  2503. os_free(bss->extra_cred);
  2504. bss->extra_cred =
  2505. (u8 *) os_readfile(pos, &bss->extra_cred_len);
  2506. if (bss->extra_cred == NULL) {
  2507. wpa_printf(MSG_ERROR, "Line %d: could not "
  2508. "read Credentials from '%s'",
  2509. line, pos);
  2510. errors++;
  2511. }
  2512. } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
  2513. bss->wps_cred_processing = atoi(pos);
  2514. } else if (os_strcmp(buf, "ap_settings") == 0) {
  2515. os_free(bss->ap_settings);
  2516. bss->ap_settings =
  2517. (u8 *) os_readfile(pos, &bss->ap_settings_len);
  2518. if (bss->ap_settings == NULL) {
  2519. wpa_printf(MSG_ERROR, "Line %d: could not "
  2520. "read AP Settings from '%s'",
  2521. line, pos);
  2522. errors++;
  2523. }
  2524. } else if (os_strcmp(buf, "upnp_iface") == 0) {
  2525. bss->upnp_iface = os_strdup(pos);
  2526. } else if (os_strcmp(buf, "friendly_name") == 0) {
  2527. os_free(bss->friendly_name);
  2528. bss->friendly_name = os_strdup(pos);
  2529. } else if (os_strcmp(buf, "manufacturer_url") == 0) {
  2530. os_free(bss->manufacturer_url);
  2531. bss->manufacturer_url = os_strdup(pos);
  2532. } else if (os_strcmp(buf, "model_description") == 0) {
  2533. os_free(bss->model_description);
  2534. bss->model_description = os_strdup(pos);
  2535. } else if (os_strcmp(buf, "model_url") == 0) {
  2536. os_free(bss->model_url);
  2537. bss->model_url = os_strdup(pos);
  2538. } else if (os_strcmp(buf, "upc") == 0) {
  2539. os_free(bss->upc);
  2540. bss->upc = os_strdup(pos);
  2541. } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
  2542. bss->pbc_in_m1 = atoi(pos);
  2543. } else if (os_strcmp(buf, "server_id") == 0) {
  2544. os_free(bss->server_id);
  2545. bss->server_id = os_strdup(pos);
  2546. #ifdef CONFIG_WPS_NFC
  2547. } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
  2548. bss->wps_nfc_dev_pw_id = atoi(pos);
  2549. if (bss->wps_nfc_dev_pw_id < 0x10 ||
  2550. bss->wps_nfc_dev_pw_id > 0xffff) {
  2551. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2552. "wps_nfc_dev_pw_id value", line);
  2553. errors++;
  2554. }
  2555. bss->wps_nfc_pw_from_config = 1;
  2556. } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
  2557. wpabuf_free(bss->wps_nfc_dh_pubkey);
  2558. bss->wps_nfc_dh_pubkey = hostapd_parse_bin(pos);
  2559. bss->wps_nfc_pw_from_config = 1;
  2560. } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
  2561. wpabuf_free(bss->wps_nfc_dh_privkey);
  2562. bss->wps_nfc_dh_privkey = hostapd_parse_bin(pos);
  2563. bss->wps_nfc_pw_from_config = 1;
  2564. } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
  2565. wpabuf_free(bss->wps_nfc_dev_pw);
  2566. bss->wps_nfc_dev_pw = hostapd_parse_bin(pos);
  2567. bss->wps_nfc_pw_from_config = 1;
  2568. #endif /* CONFIG_WPS_NFC */
  2569. #endif /* CONFIG_WPS */
  2570. #ifdef CONFIG_P2P_MANAGER
  2571. } else if (os_strcmp(buf, "manage_p2p") == 0) {
  2572. int manage = atoi(pos);
  2573. if (manage)
  2574. bss->p2p |= P2P_MANAGE;
  2575. else
  2576. bss->p2p &= ~P2P_MANAGE;
  2577. } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
  2578. if (atoi(pos))
  2579. bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
  2580. else
  2581. bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
  2582. #endif /* CONFIG_P2P_MANAGER */
  2583. } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
  2584. bss->disassoc_low_ack = atoi(pos);
  2585. } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
  2586. int val = atoi(pos);
  2587. if (val)
  2588. bss->tdls |= TDLS_PROHIBIT;
  2589. else
  2590. bss->tdls &= ~TDLS_PROHIBIT;
  2591. } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
  2592. int val = atoi(pos);
  2593. if (val)
  2594. bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
  2595. else
  2596. bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
  2597. #ifdef CONFIG_RSN_TESTING
  2598. } else if (os_strcmp(buf, "rsn_testing") == 0) {
  2599. extern int rsn_testing;
  2600. rsn_testing = atoi(pos);
  2601. #endif /* CONFIG_RSN_TESTING */
  2602. } else if (os_strcmp(buf, "time_advertisement") == 0) {
  2603. bss->time_advertisement = atoi(pos);
  2604. } else if (os_strcmp(buf, "time_zone") == 0) {
  2605. size_t tz_len = os_strlen(pos);
  2606. if (tz_len < 4 || tz_len > 255) {
  2607. wpa_printf(MSG_DEBUG, "Line %d: invalid "
  2608. "time_zone", line);
  2609. errors++;
  2610. return errors;
  2611. }
  2612. os_free(bss->time_zone);
  2613. bss->time_zone = os_strdup(pos);
  2614. if (bss->time_zone == NULL)
  2615. errors++;
  2616. #ifdef CONFIG_WNM
  2617. } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
  2618. bss->wnm_sleep_mode = atoi(pos);
  2619. } else if (os_strcmp(buf, "bss_transition") == 0) {
  2620. bss->bss_transition = atoi(pos);
  2621. #endif /* CONFIG_WNM */
  2622. #ifdef CONFIG_INTERWORKING
  2623. } else if (os_strcmp(buf, "interworking") == 0) {
  2624. bss->interworking = atoi(pos);
  2625. } else if (os_strcmp(buf, "access_network_type") == 0) {
  2626. bss->access_network_type = atoi(pos);
  2627. if (bss->access_network_type < 0 ||
  2628. bss->access_network_type > 15) {
  2629. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2630. "access_network_type", line);
  2631. errors++;
  2632. }
  2633. } else if (os_strcmp(buf, "internet") == 0) {
  2634. bss->internet = atoi(pos);
  2635. } else if (os_strcmp(buf, "asra") == 0) {
  2636. bss->asra = atoi(pos);
  2637. } else if (os_strcmp(buf, "esr") == 0) {
  2638. bss->esr = atoi(pos);
  2639. } else if (os_strcmp(buf, "uesa") == 0) {
  2640. bss->uesa = atoi(pos);
  2641. } else if (os_strcmp(buf, "venue_group") == 0) {
  2642. bss->venue_group = atoi(pos);
  2643. bss->venue_info_set = 1;
  2644. } else if (os_strcmp(buf, "venue_type") == 0) {
  2645. bss->venue_type = atoi(pos);
  2646. bss->venue_info_set = 1;
  2647. } else if (os_strcmp(buf, "hessid") == 0) {
  2648. if (hwaddr_aton(pos, bss->hessid)) {
  2649. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2650. "hessid", line);
  2651. errors++;
  2652. }
  2653. } else if (os_strcmp(buf, "roaming_consortium") == 0) {
  2654. if (parse_roaming_consortium(bss, pos, line) < 0)
  2655. errors++;
  2656. } else if (os_strcmp(buf, "venue_name") == 0) {
  2657. if (parse_venue_name(bss, pos, line) < 0)
  2658. errors++;
  2659. } else if (os_strcmp(buf, "network_auth_type") == 0) {
  2660. u8 auth_type;
  2661. u16 redirect_url_len;
  2662. if (hexstr2bin(pos, &auth_type, 1)) {
  2663. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2664. "network_auth_type '%s'",
  2665. line, pos);
  2666. errors++;
  2667. return errors;
  2668. }
  2669. if (auth_type == 0 || auth_type == 2)
  2670. redirect_url_len = os_strlen(pos + 2);
  2671. else
  2672. redirect_url_len = 0;
  2673. os_free(bss->network_auth_type);
  2674. bss->network_auth_type =
  2675. os_malloc(redirect_url_len + 3 + 1);
  2676. if (bss->network_auth_type == NULL) {
  2677. errors++;
  2678. return errors;
  2679. }
  2680. *bss->network_auth_type = auth_type;
  2681. WPA_PUT_LE16(bss->network_auth_type + 1,
  2682. redirect_url_len);
  2683. if (redirect_url_len)
  2684. os_memcpy(bss->network_auth_type + 3,
  2685. pos + 2, redirect_url_len);
  2686. bss->network_auth_type_len = 3 + redirect_url_len;
  2687. } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
  2688. if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1))
  2689. {
  2690. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2691. "ipaddr_type_availability '%s'",
  2692. line, pos);
  2693. bss->ipaddr_type_configured = 0;
  2694. errors++;
  2695. return errors;
  2696. }
  2697. bss->ipaddr_type_configured = 1;
  2698. } else if (os_strcmp(buf, "domain_name") == 0) {
  2699. int j, num_domains, domain_len, domain_list_len = 0;
  2700. char *tok_start, *tok_prev;
  2701. u8 *domain_list, *domain_ptr;
  2702. domain_list_len = os_strlen(pos) + 1;
  2703. domain_list = os_malloc(domain_list_len);
  2704. if (domain_list == NULL) {
  2705. errors++;
  2706. return errors;
  2707. }
  2708. domain_ptr = domain_list;
  2709. tok_prev = pos;
  2710. num_domains = 1;
  2711. while ((tok_prev = os_strchr(tok_prev, ','))) {
  2712. num_domains++;
  2713. tok_prev++;
  2714. }
  2715. tok_prev = pos;
  2716. for (j = 0; j < num_domains; j++) {
  2717. tok_start = os_strchr(tok_prev, ',');
  2718. if (tok_start) {
  2719. domain_len = tok_start - tok_prev;
  2720. *domain_ptr = domain_len;
  2721. os_memcpy(domain_ptr + 1, tok_prev,
  2722. domain_len);
  2723. domain_ptr += domain_len + 1;
  2724. tok_prev = ++tok_start;
  2725. } else {
  2726. domain_len = os_strlen(tok_prev);
  2727. *domain_ptr = domain_len;
  2728. os_memcpy(domain_ptr + 1, tok_prev,
  2729. domain_len);
  2730. domain_ptr += domain_len + 1;
  2731. }
  2732. }
  2733. os_free(bss->domain_name);
  2734. bss->domain_name = domain_list;
  2735. bss->domain_name_len = domain_list_len;
  2736. } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
  2737. if (parse_3gpp_cell_net(bss, pos, line) < 0)
  2738. errors++;
  2739. } else if (os_strcmp(buf, "nai_realm") == 0) {
  2740. if (parse_nai_realm(bss, pos, line) < 0)
  2741. errors++;
  2742. } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
  2743. bss->gas_frag_limit = atoi(pos);
  2744. } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
  2745. bss->gas_comeback_delay = atoi(pos);
  2746. } else if (os_strcmp(buf, "qos_map_set") == 0) {
  2747. if (parse_qos_map_set(bss, pos, line) < 0)
  2748. errors++;
  2749. #endif /* CONFIG_INTERWORKING */
  2750. #ifdef CONFIG_RADIUS_TEST
  2751. } else if (os_strcmp(buf, "dump_msk_file") == 0) {
  2752. os_free(bss->dump_msk_file);
  2753. bss->dump_msk_file = os_strdup(pos);
  2754. #endif /* CONFIG_RADIUS_TEST */
  2755. #ifdef CONFIG_HS20
  2756. } else if (os_strcmp(buf, "hs20") == 0) {
  2757. bss->hs20 = atoi(pos);
  2758. } else if (os_strcmp(buf, "disable_dgaf") == 0) {
  2759. bss->disable_dgaf = atoi(pos);
  2760. } else if (os_strcmp(buf, "osen") == 0) {
  2761. bss->osen = atoi(pos);
  2762. } else if (os_strcmp(buf, "anqp_domain_id") == 0) {
  2763. bss->anqp_domain_id = atoi(pos);
  2764. } else if (os_strcmp(buf, "hs20_deauth_req_timeout") == 0) {
  2765. bss->hs20_deauth_req_timeout = atoi(pos);
  2766. } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
  2767. if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
  2768. errors++;
  2769. } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
  2770. if (hs20_parse_wan_metrics(bss, pos, line) < 0) {
  2771. errors++;
  2772. return errors;
  2773. }
  2774. } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
  2775. if (hs20_parse_conn_capab(bss, pos, line) < 0) {
  2776. errors++;
  2777. return errors;
  2778. }
  2779. } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
  2780. u8 *oper_class;
  2781. size_t oper_class_len;
  2782. oper_class_len = os_strlen(pos);
  2783. if (oper_class_len < 2 || (oper_class_len & 0x01)) {
  2784. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2785. "hs20_operating_class '%s'",
  2786. line, pos);
  2787. errors++;
  2788. return errors;
  2789. }
  2790. oper_class_len /= 2;
  2791. oper_class = os_malloc(oper_class_len);
  2792. if (oper_class == NULL) {
  2793. errors++;
  2794. return errors;
  2795. }
  2796. if (hexstr2bin(pos, oper_class, oper_class_len)) {
  2797. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2798. "hs20_operating_class '%s'",
  2799. line, pos);
  2800. os_free(oper_class);
  2801. errors++;
  2802. return errors;
  2803. }
  2804. os_free(bss->hs20_operating_class);
  2805. bss->hs20_operating_class = oper_class;
  2806. bss->hs20_operating_class_len = oper_class_len;
  2807. } else if (os_strcmp(buf, "hs20_icon") == 0) {
  2808. if (hs20_parse_icon(bss, pos) < 0) {
  2809. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2810. "hs20_icon '%s'", line, pos);
  2811. errors++;
  2812. return errors;
  2813. }
  2814. } else if (os_strcmp(buf, "osu_ssid") == 0) {
  2815. if (hs20_parse_osu_ssid(bss, pos, line) < 0)
  2816. errors++;
  2817. } else if (os_strcmp(buf, "osu_server_uri") == 0) {
  2818. if (hs20_parse_osu_server_uri(bss, pos, line) < 0)
  2819. errors++;
  2820. } else if (os_strcmp(buf, "osu_friendly_name") == 0) {
  2821. if (hs20_parse_osu_friendly_name(bss, pos, line) < 0)
  2822. errors++;
  2823. } else if (os_strcmp(buf, "osu_nai") == 0) {
  2824. if (hs20_parse_osu_nai(bss, pos, line) < 0)
  2825. errors++;
  2826. } else if (os_strcmp(buf, "osu_method_list") == 0) {
  2827. if (hs20_parse_osu_method_list(bss, pos, line) < 0)
  2828. errors++;
  2829. } else if (os_strcmp(buf, "osu_icon") == 0) {
  2830. if (hs20_parse_osu_icon(bss, pos, line) < 0)
  2831. errors++;
  2832. } else if (os_strcmp(buf, "osu_service_desc") == 0) {
  2833. if (hs20_parse_osu_service_desc(bss, pos, line) < 0)
  2834. errors++;
  2835. } else if (os_strcmp(buf, "subscr_remediation_url") == 0) {
  2836. os_free(bss->subscr_remediation_url);
  2837. bss->subscr_remediation_url = os_strdup(pos);
  2838. } else if (os_strcmp(buf, "subscr_remediation_method") == 0) {
  2839. bss->subscr_remediation_method = atoi(pos);
  2840. #endif /* CONFIG_HS20 */
  2841. #ifdef CONFIG_TESTING_OPTIONS
  2842. #define PARSE_TEST_PROBABILITY(_val) \
  2843. } else if (os_strcmp(buf, #_val) == 0) { \
  2844. char *end; \
  2845. \
  2846. conf->_val = strtod(pos, &end); \
  2847. if (*end || conf->_val < 0.0d || \
  2848. conf->_val > 1.0d) { \
  2849. wpa_printf(MSG_ERROR, \
  2850. "Line %d: Invalid value '%s'", \
  2851. line, pos); \
  2852. errors++; \
  2853. return errors; \
  2854. }
  2855. PARSE_TEST_PROBABILITY(ignore_probe_probability)
  2856. PARSE_TEST_PROBABILITY(ignore_auth_probability)
  2857. PARSE_TEST_PROBABILITY(ignore_assoc_probability)
  2858. PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
  2859. PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability)
  2860. } else if (os_strcmp(buf, "bss_load_test") == 0) {
  2861. WPA_PUT_LE16(bss->bss_load_test, atoi(pos));
  2862. pos = os_strchr(pos, ':');
  2863. if (pos == NULL) {
  2864. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2865. "bss_load_test", line);
  2866. return 1;
  2867. }
  2868. pos++;
  2869. bss->bss_load_test[2] = atoi(pos);
  2870. pos = os_strchr(pos, ':');
  2871. if (pos == NULL) {
  2872. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2873. "bss_load_test", line);
  2874. return 1;
  2875. }
  2876. pos++;
  2877. WPA_PUT_LE16(&bss->bss_load_test[3], atoi(pos));
  2878. bss->bss_load_test_set = 1;
  2879. #endif /* CONFIG_TESTING_OPTIONS */
  2880. } else if (os_strcmp(buf, "vendor_elements") == 0) {
  2881. struct wpabuf *elems;
  2882. size_t len = os_strlen(pos);
  2883. if (len & 0x01) {
  2884. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2885. "vendor_elements '%s'", line, pos);
  2886. return 1;
  2887. }
  2888. len /= 2;
  2889. if (len == 0) {
  2890. wpabuf_free(bss->vendor_elements);
  2891. bss->vendor_elements = NULL;
  2892. return 0;
  2893. }
  2894. elems = wpabuf_alloc(len);
  2895. if (elems == NULL)
  2896. return 1;
  2897. if (hexstr2bin(pos, wpabuf_put(elems, len), len)) {
  2898. wpabuf_free(elems);
  2899. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2900. "vendor_elements '%s'", line, pos);
  2901. return 1;
  2902. }
  2903. wpabuf_free(bss->vendor_elements);
  2904. bss->vendor_elements = elems;
  2905. } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0) {
  2906. bss->sae_anti_clogging_threshold = atoi(pos);
  2907. } else if (os_strcmp(buf, "sae_groups") == 0) {
  2908. if (hostapd_parse_intlist(&bss->sae_groups, pos)) {
  2909. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2910. "sae_groups value '%s'", line, pos);
  2911. return 1;
  2912. }
  2913. } else if (os_strcmp(buf, "local_pwr_constraint") == 0) {
  2914. int val = atoi(pos);
  2915. if (val < 0 || val > 255) {
  2916. wpa_printf(MSG_ERROR, "Line %d: Invalid local_pwr_constraint %d (expected 0..255)",
  2917. line, val);
  2918. return 1;
  2919. }
  2920. conf->local_pwr_constraint = val;
  2921. } else if (os_strcmp(buf, "spectrum_mgmt_required") == 0) {
  2922. conf->spectrum_mgmt_required = atoi(pos);
  2923. } else {
  2924. wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
  2925. "item '%s'", line, buf);
  2926. errors++;
  2927. }
  2928. }
  2929. return errors;
  2930. }
  2931. /**
  2932. * hostapd_config_read - Read and parse a configuration file
  2933. * @fname: Configuration file name (including path, if needed)
  2934. * Returns: Allocated configuration data structure
  2935. */
  2936. struct hostapd_config * hostapd_config_read(const char *fname)
  2937. {
  2938. struct hostapd_config *conf;
  2939. struct hostapd_bss_config *bss;
  2940. FILE *f;
  2941. char buf[512], *pos;
  2942. int line = 0;
  2943. int errors = 0;
  2944. size_t i;
  2945. f = fopen(fname, "r");
  2946. if (f == NULL) {
  2947. wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
  2948. "for reading.", fname);
  2949. return NULL;
  2950. }
  2951. conf = hostapd_config_defaults();
  2952. if (conf == NULL) {
  2953. fclose(f);
  2954. return NULL;
  2955. }
  2956. /* set default driver based on configuration */
  2957. conf->driver = wpa_drivers[0];
  2958. if (conf->driver == NULL) {
  2959. wpa_printf(MSG_ERROR, "No driver wrappers registered!");
  2960. hostapd_config_free(conf);
  2961. fclose(f);
  2962. return NULL;
  2963. }
  2964. bss = conf->last_bss = conf->bss[0];
  2965. while (fgets(buf, sizeof(buf), f)) {
  2966. bss = conf->last_bss;
  2967. line++;
  2968. if (buf[0] == '#')
  2969. continue;
  2970. pos = buf;
  2971. while (*pos != '\0') {
  2972. if (*pos == '\n') {
  2973. *pos = '\0';
  2974. break;
  2975. }
  2976. pos++;
  2977. }
  2978. if (buf[0] == '\0')
  2979. continue;
  2980. pos = os_strchr(buf, '=');
  2981. if (pos == NULL) {
  2982. wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
  2983. line, buf);
  2984. errors++;
  2985. continue;
  2986. }
  2987. *pos = '\0';
  2988. pos++;
  2989. errors += hostapd_config_fill(conf, bss, buf, pos, line);
  2990. }
  2991. fclose(f);
  2992. for (i = 0; i < conf->num_bss; i++)
  2993. hostapd_set_security_params(conf->bss[i]);
  2994. if (hostapd_config_check(conf, 1))
  2995. errors++;
  2996. #ifndef WPA_IGNORE_CONFIG_ERRORS
  2997. if (errors) {
  2998. wpa_printf(MSG_ERROR, "%d errors found in configuration file "
  2999. "'%s'", errors, fname);
  3000. hostapd_config_free(conf);
  3001. conf = NULL;
  3002. }
  3003. #endif /* WPA_IGNORE_CONFIG_ERRORS */
  3004. return conf;
  3005. }
  3006. int hostapd_set_iface(struct hostapd_config *conf,
  3007. struct hostapd_bss_config *bss, char *field, char *value)
  3008. {
  3009. int errors;
  3010. size_t i;
  3011. errors = hostapd_config_fill(conf, bss, field, value, 0);
  3012. if (errors) {
  3013. wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
  3014. "to value '%s'", field, value);
  3015. return -1;
  3016. }
  3017. for (i = 0; i < conf->num_bss; i++)
  3018. hostapd_set_security_params(conf->bss[i]);
  3019. if (hostapd_config_check(conf, 0)) {
  3020. wpa_printf(MSG_ERROR, "Configuration check failed");
  3021. return -1;
  3022. }
  3023. return 0;
  3024. }