config_file.c 92 KB

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