config_file.c 86 KB

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