sta_info.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /*
  2. * hostapd / Station table
  3. * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #include "includes.h"
  15. #include "hostapd.h"
  16. #include "sta_info.h"
  17. #include "eloop.h"
  18. #include "accounting.h"
  19. #include "ieee802_1x.h"
  20. #include "ieee802_11.h"
  21. #include "radius/radius.h"
  22. #include "wpa.h"
  23. #include "preauth.h"
  24. #include "radius/radius_client.h"
  25. #include "driver.h"
  26. #include "beacon.h"
  27. #include "hw_features.h"
  28. #include "mlme.h"
  29. #include "vlan_init.h"
  30. static int ap_sta_in_other_bss(struct hostapd_data *hapd,
  31. struct sta_info *sta, u32 flags);
  32. static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx);
  33. int ap_for_each_sta(struct hostapd_data *hapd,
  34. int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
  35. void *ctx),
  36. void *ctx)
  37. {
  38. struct sta_info *sta;
  39. for (sta = hapd->sta_list; sta; sta = sta->next) {
  40. if (cb(hapd, sta, ctx))
  41. return 1;
  42. }
  43. return 0;
  44. }
  45. struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta)
  46. {
  47. struct sta_info *s;
  48. s = hapd->sta_hash[STA_HASH(sta)];
  49. while (s != NULL && os_memcmp(s->addr, sta, 6) != 0)
  50. s = s->hnext;
  51. return s;
  52. }
  53. static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta)
  54. {
  55. struct sta_info *tmp;
  56. if (hapd->sta_list == sta) {
  57. hapd->sta_list = sta->next;
  58. return;
  59. }
  60. tmp = hapd->sta_list;
  61. while (tmp != NULL && tmp->next != sta)
  62. tmp = tmp->next;
  63. if (tmp == NULL) {
  64. wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from "
  65. "list.", MAC2STR(sta->addr));
  66. } else
  67. tmp->next = sta->next;
  68. }
  69. void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta)
  70. {
  71. sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)];
  72. hapd->sta_hash[STA_HASH(sta->addr)] = sta;
  73. }
  74. static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta)
  75. {
  76. struct sta_info *s;
  77. s = hapd->sta_hash[STA_HASH(sta->addr)];
  78. if (s == NULL) return;
  79. if (os_memcmp(s->addr, sta->addr, 6) == 0) {
  80. hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext;
  81. return;
  82. }
  83. while (s->hnext != NULL &&
  84. os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
  85. s = s->hnext;
  86. if (s->hnext != NULL)
  87. s->hnext = s->hnext->hnext;
  88. else
  89. wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR
  90. " from hash table", MAC2STR(sta->addr));
  91. }
  92. void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
  93. {
  94. int set_beacon = 0;
  95. accounting_sta_stop(hapd, sta);
  96. if (!ap_sta_in_other_bss(hapd, sta, WLAN_STA_ASSOC) &&
  97. !(sta->flags & WLAN_STA_PREAUTH))
  98. hostapd_sta_remove(hapd, sta->addr);
  99. ap_sta_hash_del(hapd, sta);
  100. ap_sta_list_del(hapd, sta);
  101. if (sta->aid > 0)
  102. hapd->sta_aid[sta->aid - 1] = NULL;
  103. hapd->num_sta--;
  104. if (sta->nonerp_set) {
  105. sta->nonerp_set = 0;
  106. hapd->iface->num_sta_non_erp--;
  107. if (hapd->iface->num_sta_non_erp == 0)
  108. set_beacon++;
  109. }
  110. if (sta->no_short_slot_time_set) {
  111. sta->no_short_slot_time_set = 0;
  112. hapd->iface->num_sta_no_short_slot_time--;
  113. if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
  114. && hapd->iface->num_sta_no_short_slot_time == 0)
  115. set_beacon++;
  116. }
  117. if (sta->no_short_preamble_set) {
  118. sta->no_short_preamble_set = 0;
  119. hapd->iface->num_sta_no_short_preamble--;
  120. if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
  121. && hapd->iface->num_sta_no_short_preamble == 0)
  122. set_beacon++;
  123. }
  124. #ifdef CONFIG_IEEE80211N
  125. if (sta->flags & WLAN_STA_HT) {
  126. if ((sta->ht_capabilities.data.capabilities_info &
  127. HT_CAP_INFO_GREEN_FIELD) == 0)
  128. hapd->iface->num_sta_ht_no_gf--;
  129. if ((sta->ht_capabilities.data.capabilities_info &
  130. HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0)
  131. hapd->iface->num_sta_ht_20mhz--;
  132. } else
  133. hapd->iface->num_sta_no_ht--;
  134. if (hostapd_ht_operation_update(hapd->iface) > 0)
  135. set_beacon++;
  136. #endif /* CONFIG_IEEE80211N */
  137. if (set_beacon)
  138. ieee802_11_set_beacons(hapd->iface);
  139. eloop_cancel_timeout(ap_handle_timer, hapd, sta);
  140. eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
  141. ieee802_1x_free_station(sta);
  142. wpa_auth_sta_deinit(sta->wpa_sm);
  143. rsn_preauth_free_station(hapd, sta);
  144. radius_client_flush_auth(hapd->radius, sta->addr);
  145. os_free(sta->last_assoc_req);
  146. os_free(sta->challenge);
  147. os_free(sta);
  148. }
  149. void hostapd_free_stas(struct hostapd_data *hapd)
  150. {
  151. struct sta_info *sta, *prev;
  152. sta = hapd->sta_list;
  153. while (sta) {
  154. prev = sta;
  155. if (sta->flags & WLAN_STA_AUTH) {
  156. mlme_deauthenticate_indication(
  157. hapd, sta, WLAN_REASON_UNSPECIFIED);
  158. }
  159. sta = sta->next;
  160. wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
  161. MAC2STR(prev->addr));
  162. ap_free_sta(hapd, prev);
  163. }
  164. }
  165. void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
  166. {
  167. struct hostapd_data *hapd = eloop_ctx;
  168. struct sta_info *sta = timeout_ctx;
  169. unsigned long next_time = 0;
  170. if (sta->timeout_next == STA_REMOVE) {
  171. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  172. HOSTAPD_LEVEL_INFO, "deauthenticated due to "
  173. "local deauth request");
  174. ap_free_sta(hapd, sta);
  175. return;
  176. }
  177. if ((sta->flags & WLAN_STA_ASSOC) &&
  178. (sta->timeout_next == STA_NULLFUNC ||
  179. sta->timeout_next == STA_DISASSOC)) {
  180. int inactive_sec;
  181. wpa_printf(MSG_DEBUG, "Checking STA " MACSTR " inactivity:",
  182. MAC2STR(sta->addr));
  183. inactive_sec = hostapd_get_inact_sec(hapd, sta->addr);
  184. if (inactive_sec == -1) {
  185. wpa_printf(MSG_DEBUG, "Could not get station info "
  186. "from kernel driver for " MACSTR ".",
  187. MAC2STR(sta->addr));
  188. } else if (inactive_sec < hapd->conf->ap_max_inactivity &&
  189. sta->flags & WLAN_STA_ASSOC) {
  190. /* station activity detected; reset timeout state */
  191. wpa_printf(MSG_DEBUG, " Station has been active");
  192. sta->timeout_next = STA_NULLFUNC;
  193. next_time = hapd->conf->ap_max_inactivity -
  194. inactive_sec;
  195. }
  196. }
  197. if ((sta->flags & WLAN_STA_ASSOC) &&
  198. sta->timeout_next == STA_DISASSOC &&
  199. !(sta->flags & WLAN_STA_PENDING_POLL)) {
  200. wpa_printf(MSG_DEBUG, " Station has ACKed data poll");
  201. /* data nullfunc frame poll did not produce TX errors; assume
  202. * station ACKed it */
  203. sta->timeout_next = STA_NULLFUNC;
  204. next_time = hapd->conf->ap_max_inactivity;
  205. }
  206. if (next_time) {
  207. eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
  208. sta);
  209. return;
  210. }
  211. if (sta->timeout_next == STA_NULLFUNC &&
  212. (sta->flags & WLAN_STA_ASSOC)) {
  213. /* send data frame to poll STA and check whether this frame
  214. * is ACKed */
  215. struct ieee80211_hdr hdr;
  216. wpa_printf(MSG_DEBUG, " Polling STA with data frame");
  217. sta->flags |= WLAN_STA_PENDING_POLL;
  218. #ifndef CONFIG_NATIVE_WINDOWS
  219. /* FIX: WLAN_FC_STYPE_NULLFUNC would be more appropriate, but
  220. * it is apparently not retried so TX Exc events are not
  221. * received for it */
  222. os_memset(&hdr, 0, sizeof(hdr));
  223. hdr.frame_control =
  224. IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
  225. hdr.frame_control |= host_to_le16(BIT(1));
  226. hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS);
  227. os_memcpy(hdr.IEEE80211_DA_FROMDS, sta->addr, ETH_ALEN);
  228. os_memcpy(hdr.IEEE80211_BSSID_FROMDS, hapd->own_addr,
  229. ETH_ALEN);
  230. os_memcpy(hdr.IEEE80211_SA_FROMDS, hapd->own_addr, ETH_ALEN);
  231. if (hostapd_send_mgmt_frame(hapd, &hdr, sizeof(hdr), 0) < 0)
  232. perror("ap_handle_timer: send");
  233. #endif /* CONFIG_NATIVE_WINDOWS */
  234. } else if (sta->timeout_next != STA_REMOVE) {
  235. int deauth = sta->timeout_next == STA_DEAUTH;
  236. wpa_printf(MSG_DEBUG, "Sending %s info to STA " MACSTR,
  237. deauth ? "deauthentication" : "disassociation",
  238. MAC2STR(sta->addr));
  239. if (deauth) {
  240. hostapd_sta_deauth(hapd, sta->addr,
  241. WLAN_REASON_PREV_AUTH_NOT_VALID);
  242. } else {
  243. hostapd_sta_disassoc(
  244. hapd, sta->addr,
  245. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
  246. }
  247. }
  248. switch (sta->timeout_next) {
  249. case STA_NULLFUNC:
  250. sta->timeout_next = STA_DISASSOC;
  251. eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
  252. hapd, sta);
  253. break;
  254. case STA_DISASSOC:
  255. sta->flags &= ~WLAN_STA_ASSOC;
  256. ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
  257. if (!sta->acct_terminate_cause)
  258. sta->acct_terminate_cause =
  259. RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
  260. accounting_sta_stop(hapd, sta);
  261. ieee802_1x_free_station(sta);
  262. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  263. HOSTAPD_LEVEL_INFO, "disassociated due to "
  264. "inactivity");
  265. sta->timeout_next = STA_DEAUTH;
  266. eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
  267. hapd, sta);
  268. mlme_disassociate_indication(
  269. hapd, sta, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
  270. break;
  271. case STA_DEAUTH:
  272. case STA_REMOVE:
  273. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  274. HOSTAPD_LEVEL_INFO, "deauthenticated due to "
  275. "inactivity");
  276. if (!sta->acct_terminate_cause)
  277. sta->acct_terminate_cause =
  278. RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
  279. mlme_deauthenticate_indication(
  280. hapd, sta,
  281. WLAN_REASON_PREV_AUTH_NOT_VALID);
  282. ap_free_sta(hapd, sta);
  283. break;
  284. }
  285. }
  286. static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
  287. {
  288. struct hostapd_data *hapd = eloop_ctx;
  289. struct sta_info *sta = timeout_ctx;
  290. u8 addr[ETH_ALEN];
  291. if (!(sta->flags & WLAN_STA_AUTH))
  292. return;
  293. mlme_deauthenticate_indication(hapd, sta,
  294. WLAN_REASON_PREV_AUTH_NOT_VALID);
  295. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  296. HOSTAPD_LEVEL_INFO, "deauthenticated due to "
  297. "session timeout");
  298. sta->acct_terminate_cause =
  299. RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
  300. os_memcpy(addr, sta->addr, ETH_ALEN);
  301. ap_free_sta(hapd, sta);
  302. hostapd_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
  303. }
  304. void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
  305. u32 session_timeout)
  306. {
  307. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  308. HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
  309. "seconds", session_timeout);
  310. eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
  311. eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
  312. hapd, sta);
  313. }
  314. void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
  315. {
  316. eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
  317. }
  318. struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
  319. {
  320. struct sta_info *sta;
  321. sta = ap_get_sta(hapd, addr);
  322. if (sta)
  323. return sta;
  324. wpa_printf(MSG_DEBUG, " New STA");
  325. if (hapd->num_sta >= hapd->conf->max_num_sta) {
  326. /* FIX: might try to remove some old STAs first? */
  327. wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
  328. hapd->num_sta, hapd->conf->max_num_sta);
  329. return NULL;
  330. }
  331. sta = os_zalloc(sizeof(struct sta_info));
  332. if (sta == NULL) {
  333. wpa_printf(MSG_ERROR, "malloc failed");
  334. return NULL;
  335. }
  336. sta->acct_interim_interval = hapd->conf->radius->acct_interim_interval;
  337. /* initialize STA info data */
  338. eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
  339. ap_handle_timer, hapd, sta);
  340. os_memcpy(sta->addr, addr, ETH_ALEN);
  341. sta->next = hapd->sta_list;
  342. hapd->sta_list = sta;
  343. hapd->num_sta++;
  344. ap_sta_hash_add(hapd, sta);
  345. sta->ssid = &hapd->conf->ssid;
  346. return sta;
  347. }
  348. static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
  349. {
  350. ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
  351. wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",
  352. MAC2STR(sta->addr));
  353. if (hostapd_sta_remove(hapd, sta->addr) &&
  354. sta->flags & WLAN_STA_ASSOC) {
  355. wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR
  356. " from kernel driver.", MAC2STR(sta->addr));
  357. return -1;
  358. }
  359. return 0;
  360. }
  361. static int ap_sta_in_other_bss(struct hostapd_data *hapd,
  362. struct sta_info *sta, u32 flags)
  363. {
  364. struct hostapd_iface *iface = hapd->iface;
  365. size_t i;
  366. for (i = 0; i < iface->num_bss; i++) {
  367. struct hostapd_data *bss = iface->bss[i];
  368. struct sta_info *sta2;
  369. /* bss should always be set during operation, but it may be
  370. * NULL during reconfiguration. Assume the STA is not
  371. * associated to another BSS in that case to avoid NULL pointer
  372. * dereferences. */
  373. if (bss == hapd || bss == NULL)
  374. continue;
  375. sta2 = ap_get_sta(bss, sta->addr);
  376. if (sta2 && ((sta2->flags & flags) == flags))
  377. return 1;
  378. }
  379. return 0;
  380. }
  381. void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
  382. u16 reason)
  383. {
  384. wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
  385. hapd->conf->iface, MAC2STR(sta->addr));
  386. sta->flags &= ~WLAN_STA_ASSOC;
  387. if (!ap_sta_in_other_bss(hapd, sta, WLAN_STA_ASSOC))
  388. ap_sta_remove(hapd, sta);
  389. sta->timeout_next = STA_DEAUTH;
  390. eloop_cancel_timeout(ap_handle_timer, hapd, sta);
  391. eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
  392. ap_handle_timer, hapd, sta);
  393. accounting_sta_stop(hapd, sta);
  394. ieee802_1x_free_station(sta);
  395. mlme_disassociate_indication(hapd, sta, reason);
  396. }
  397. void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
  398. u16 reason)
  399. {
  400. wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
  401. hapd->conf->iface, MAC2STR(sta->addr));
  402. sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
  403. if (!ap_sta_in_other_bss(hapd, sta, WLAN_STA_ASSOC))
  404. ap_sta_remove(hapd, sta);
  405. sta->timeout_next = STA_REMOVE;
  406. eloop_cancel_timeout(ap_handle_timer, hapd, sta);
  407. eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
  408. ap_handle_timer, hapd, sta);
  409. accounting_sta_stop(hapd, sta);
  410. ieee802_1x_free_station(sta);
  411. mlme_deauthenticate_indication(hapd, sta, reason);
  412. }
  413. int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
  414. int old_vlanid)
  415. {
  416. const char *iface;
  417. struct hostapd_vlan *vlan = NULL;
  418. /*
  419. * Do not proceed furthur if the vlan id remains same. We do not want
  420. * duplicate dynamic vlan entries.
  421. */
  422. if (sta->vlan_id == old_vlanid)
  423. return 0;
  424. /*
  425. * During 1x reauth, if the vlan id changes, then remove the old id and
  426. * proceed furthur to add the new one.
  427. */
  428. if (old_vlanid > 0)
  429. vlan_remove_dynamic(hapd, old_vlanid);
  430. iface = hapd->conf->iface;
  431. if (sta->ssid->vlan[0])
  432. iface = sta->ssid->vlan;
  433. if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
  434. sta->vlan_id = 0;
  435. else if (sta->vlan_id > 0) {
  436. vlan = hapd->conf->vlan;
  437. while (vlan) {
  438. if (vlan->vlan_id == sta->vlan_id ||
  439. vlan->vlan_id == VLAN_ID_WILDCARD) {
  440. iface = vlan->ifname;
  441. break;
  442. }
  443. vlan = vlan->next;
  444. }
  445. }
  446. if (sta->vlan_id > 0 && vlan == NULL) {
  447. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  448. HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
  449. "binding station to (vlan_id=%d)",
  450. sta->vlan_id);
  451. return -1;
  452. } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
  453. vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
  454. if (vlan == NULL) {
  455. hostapd_logger(hapd, sta->addr,
  456. HOSTAPD_MODULE_IEEE80211,
  457. HOSTAPD_LEVEL_DEBUG, "could not add "
  458. "dynamic VLAN interface for vlan_id=%d",
  459. sta->vlan_id);
  460. return -1;
  461. }
  462. iface = vlan->ifname;
  463. if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
  464. hostapd_logger(hapd, sta->addr,
  465. HOSTAPD_MODULE_IEEE80211,
  466. HOSTAPD_LEVEL_DEBUG, "could not "
  467. "configure encryption for dynamic VLAN "
  468. "interface for vlan_id=%d",
  469. sta->vlan_id);
  470. }
  471. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  472. HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
  473. "interface '%s'", iface);
  474. } else if (vlan && vlan->vlan_id == sta->vlan_id) {
  475. if (sta->vlan_id > 0) {
  476. vlan->dynamic_vlan++;
  477. hostapd_logger(hapd, sta->addr,
  478. HOSTAPD_MODULE_IEEE80211,
  479. HOSTAPD_LEVEL_DEBUG, "updated existing "
  480. "dynamic VLAN interface '%s'", iface);
  481. }
  482. /*
  483. * Update encryption configuration for statically generated
  484. * VLAN interface. This is only used for static WEP
  485. * configuration for the case where hostapd did not yet know
  486. * which keys are to be used when the interface was added.
  487. */
  488. if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
  489. hostapd_logger(hapd, sta->addr,
  490. HOSTAPD_MODULE_IEEE80211,
  491. HOSTAPD_LEVEL_DEBUG, "could not "
  492. "configure encryption for VLAN "
  493. "interface for vlan_id=%d",
  494. sta->vlan_id);
  495. }
  496. }
  497. hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
  498. HOSTAPD_LEVEL_DEBUG, "binding station to interface "
  499. "'%s'", iface);
  500. if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
  501. wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
  502. return hostapd_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
  503. }