config_file.c 96 KB

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