config_file.c 81 KB

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