config_file.c 98 KB

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