config_file.c 84 KB

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