config_file.c 83 KB

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