config_file.c 82 KB

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