config_file.c 73 KB

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