ap.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. /*
  2. * WPA Supplicant - Basic AP mode support routines
  3. * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
  4. * Copyright (c) 2009, Atheros Communications
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Alternatively, this software may be distributed under the terms of BSD
  11. * license.
  12. *
  13. * See README and COPYING for more details.
  14. */
  15. #include "utils/includes.h"
  16. #include "utils/common.h"
  17. #include "common/ieee802_11_defs.h"
  18. #include "ap/hostapd.h"
  19. #include "ap/ap_config.h"
  20. #ifdef NEED_AP_MLME
  21. #include "ap/ieee802_11.h"
  22. #endif /* NEED_AP_MLME */
  23. #include "ap/beacon.h"
  24. #include "ap/ieee802_1x.h"
  25. #include "ap/wps_hostapd.h"
  26. #include "ap/ctrl_iface_ap.h"
  27. #include "eap_common/eap_defs.h"
  28. #include "eap_server/eap_methods.h"
  29. #include "eap_common/eap_wsc_common.h"
  30. #include "wps/wps.h"
  31. #include "common/ieee802_11_defs.h"
  32. #include "config_ssid.h"
  33. #include "config.h"
  34. #include "wpa_supplicant_i.h"
  35. #include "driver_i.h"
  36. #include "p2p_supplicant.h"
  37. #include "ap.h"
  38. static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
  39. struct wpa_ssid *ssid,
  40. struct hostapd_config *conf)
  41. {
  42. struct hostapd_bss_config *bss = &conf->bss[0];
  43. int pairwise;
  44. conf->driver = wpa_s->driver;
  45. os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
  46. if (ssid->frequency == 0) {
  47. /* default channel 11 */
  48. conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
  49. conf->channel = 11;
  50. } else if (ssid->frequency >= 2412 && ssid->frequency <= 2472) {
  51. conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
  52. conf->channel = (ssid->frequency - 2407) / 5;
  53. } else if ((ssid->frequency >= 5180 && ssid->frequency <= 5240) ||
  54. (ssid->frequency >= 5745 && ssid->frequency <= 5825)) {
  55. conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
  56. conf->channel = (ssid->frequency - 5000) / 5;
  57. } else {
  58. wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
  59. ssid->frequency);
  60. return -1;
  61. }
  62. /* TODO: enable HT if driver supports it;
  63. * drop to 11b if driver does not support 11g */
  64. #ifdef CONFIG_P2P
  65. if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G) {
  66. /* Remove 802.11b rates from supported and basic rate sets */
  67. int *list = os_malloc(4 * sizeof(int));
  68. if (list) {
  69. list[0] = 60;
  70. list[1] = 120;
  71. list[2] = 240;
  72. list[3] = -1;
  73. }
  74. conf->basic_rates = list;
  75. list = os_malloc(9 * sizeof(int));
  76. if (list) {
  77. list[0] = 60;
  78. list[1] = 90;
  79. list[2] = 120;
  80. list[3] = 180;
  81. list[4] = 240;
  82. list[5] = 360;
  83. list[6] = 480;
  84. list[7] = 540;
  85. list[8] = -1;
  86. }
  87. conf->supported_rates = list;
  88. }
  89. #endif /* CONFIG_P2P */
  90. if (ssid->ssid_len == 0) {
  91. wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
  92. return -1;
  93. }
  94. os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
  95. bss->ssid.ssid[ssid->ssid_len] = '\0';
  96. bss->ssid.ssid_len = ssid->ssid_len;
  97. bss->ssid.ssid_set = 1;
  98. if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
  99. bss->wpa = ssid->proto;
  100. bss->wpa_key_mgmt = ssid->key_mgmt;
  101. bss->wpa_pairwise = ssid->pairwise_cipher;
  102. if (ssid->passphrase) {
  103. bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
  104. } else if (ssid->psk_set) {
  105. os_free(bss->ssid.wpa_psk);
  106. bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
  107. if (bss->ssid.wpa_psk == NULL)
  108. return -1;
  109. os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
  110. bss->ssid.wpa_psk->group = 1;
  111. }
  112. /* Select group cipher based on the enabled pairwise cipher suites */
  113. pairwise = 0;
  114. if (bss->wpa & 1)
  115. pairwise |= bss->wpa_pairwise;
  116. if (bss->wpa & 2) {
  117. if (bss->rsn_pairwise == 0)
  118. bss->rsn_pairwise = bss->wpa_pairwise;
  119. pairwise |= bss->rsn_pairwise;
  120. }
  121. if (pairwise & WPA_CIPHER_TKIP)
  122. bss->wpa_group = WPA_CIPHER_TKIP;
  123. else
  124. bss->wpa_group = WPA_CIPHER_CCMP;
  125. if (bss->wpa && bss->ieee802_1x)
  126. bss->ssid.security_policy = SECURITY_WPA;
  127. else if (bss->wpa)
  128. bss->ssid.security_policy = SECURITY_WPA_PSK;
  129. else if (bss->ieee802_1x) {
  130. bss->ssid.security_policy = SECURITY_IEEE_802_1X;
  131. bss->ssid.wep.default_len = bss->default_wep_key_len;
  132. } else if (bss->ssid.wep.keys_set)
  133. bss->ssid.security_policy = SECURITY_STATIC_WEP;
  134. else
  135. bss->ssid.security_policy = SECURITY_PLAINTEXT;
  136. #ifdef CONFIG_WPS
  137. /*
  138. * Enable WPS by default, but require user interaction to actually use
  139. * it. Only the internal Registrar is supported.
  140. */
  141. bss->eap_server = 1;
  142. bss->wps_state = 2;
  143. bss->ap_setup_locked = 1;
  144. if (wpa_s->conf->config_methods)
  145. bss->config_methods = os_strdup(wpa_s->conf->config_methods);
  146. if (wpa_s->conf->device_type)
  147. bss->device_type = os_strdup(wpa_s->conf->device_type);
  148. #endif /* CONFIG_WPS */
  149. #ifdef CONFIG_P2P
  150. if (wpa_s->conf->device_name) {
  151. bss->device_name = os_strdup(wpa_s->conf->device_name);
  152. bss->friendly_name = os_strdup(wpa_s->conf->device_name);
  153. }
  154. #endif /* CONFIG_P2P */
  155. return 0;
  156. }
  157. static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
  158. {
  159. #ifdef CONFIG_P2P
  160. struct wpa_supplicant *wpa_s = ctx;
  161. const struct ieee80211_mgmt *mgmt;
  162. size_t hdr_len;
  163. mgmt = (const struct ieee80211_mgmt *) buf;
  164. hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
  165. if (hdr_len > len)
  166. return;
  167. wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
  168. mgmt->u.action.category,
  169. &mgmt->u.action.u.vs_public_action.action,
  170. len - hdr_len, freq);
  171. #endif /* CONFIG_P2P */
  172. }
  173. static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
  174. {
  175. #ifdef CONFIG_P2P
  176. struct wpa_supplicant *wpa_s = ctx;
  177. const struct ieee80211_mgmt *mgmt;
  178. size_t hdr_len;
  179. mgmt = (const struct ieee80211_mgmt *) buf;
  180. hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
  181. if (hdr_len > len)
  182. return -1;
  183. wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
  184. mgmt->u.action.category,
  185. &mgmt->u.action.u.vs_public_action.action,
  186. len - hdr_len, freq);
  187. #endif /* CONFIG_P2P */
  188. return 0;
  189. }
  190. static int ap_probe_req_rx(void *ctx, const u8 *addr, const u8 *ie,
  191. size_t ie_len)
  192. {
  193. #ifdef CONFIG_P2P
  194. struct wpa_supplicant *wpa_s = ctx;
  195. return wpas_p2p_probe_req_rx(wpa_s, addr, ie, ie_len);
  196. #else /* CONFIG_P2P */
  197. return 0;
  198. #endif /* CONFIG_P2P */
  199. }
  200. static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
  201. const u8 *uuid_e)
  202. {
  203. #ifdef CONFIG_P2P
  204. struct wpa_supplicant *wpa_s = ctx;
  205. wpas_p2p_wps_success(wpa_s, mac_addr, 1);
  206. #endif /* CONFIG_P2P */
  207. }
  208. int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
  209. struct wpa_ssid *ssid)
  210. {
  211. struct wpa_driver_associate_params params;
  212. struct hostapd_iface *hapd_iface;
  213. struct hostapd_config *conf;
  214. size_t i;
  215. if (ssid->ssid == NULL || ssid->ssid_len == 0) {
  216. wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
  217. return -1;
  218. }
  219. wpa_supplicant_ap_deinit(wpa_s);
  220. wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
  221. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  222. os_memset(&params, 0, sizeof(params));
  223. params.ssid = ssid->ssid;
  224. params.ssid_len = ssid->ssid_len;
  225. switch (ssid->mode) {
  226. case WPAS_MODE_INFRA:
  227. params.mode = IEEE80211_MODE_INFRA;
  228. break;
  229. case WPAS_MODE_IBSS:
  230. params.mode = IEEE80211_MODE_IBSS;
  231. break;
  232. case WPAS_MODE_AP:
  233. case WPAS_MODE_P2P_GO:
  234. case WPAS_MODE_P2P_GROUP_FORMATION:
  235. params.mode = IEEE80211_MODE_AP;
  236. break;
  237. }
  238. params.freq = ssid->frequency;
  239. if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
  240. wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
  241. else
  242. wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
  243. params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt);
  244. if (ssid->pairwise_cipher & WPA_CIPHER_CCMP)
  245. wpa_s->pairwise_cipher = WPA_CIPHER_CCMP;
  246. else if (ssid->pairwise_cipher & WPA_CIPHER_TKIP)
  247. wpa_s->pairwise_cipher = WPA_CIPHER_TKIP;
  248. else if (ssid->pairwise_cipher & WPA_CIPHER_NONE)
  249. wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
  250. else {
  251. wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
  252. "cipher.");
  253. return -1;
  254. }
  255. params.pairwise_suite = cipher_suite2driver(wpa_s->pairwise_cipher);
  256. params.group_suite = params.pairwise_suite;
  257. #ifdef CONFIG_P2P
  258. if (ssid->mode == WPAS_MODE_P2P_GO ||
  259. ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  260. params.p2p = 1;
  261. #endif /* CONFIG_P2P */
  262. if (wpa_s->parent->set_ap_uapsd)
  263. params.uapsd = wpa_s->parent->ap_uapsd;
  264. else
  265. params.uapsd = -1;
  266. if (wpa_drv_associate(wpa_s, &params) < 0) {
  267. wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
  268. return -1;
  269. }
  270. wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
  271. if (hapd_iface == NULL)
  272. return -1;
  273. hapd_iface->owner = wpa_s;
  274. wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
  275. if (conf == NULL) {
  276. wpa_supplicant_ap_deinit(wpa_s);
  277. return -1;
  278. }
  279. if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
  280. wpa_printf(MSG_ERROR, "Failed to create AP configuration");
  281. wpa_supplicant_ap_deinit(wpa_s);
  282. return -1;
  283. }
  284. #ifdef CONFIG_P2P
  285. if (ssid->mode == WPAS_MODE_P2P_GO)
  286. conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
  287. else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  288. conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
  289. P2P_GROUP_FORMATION;
  290. #endif /* CONFIG_P2P */
  291. hapd_iface->num_bss = conf->num_bss;
  292. hapd_iface->bss = os_zalloc(conf->num_bss *
  293. sizeof(struct hostapd_data *));
  294. if (hapd_iface->bss == NULL) {
  295. wpa_supplicant_ap_deinit(wpa_s);
  296. return -1;
  297. }
  298. for (i = 0; i < conf->num_bss; i++) {
  299. hapd_iface->bss[i] =
  300. hostapd_alloc_bss_data(hapd_iface, conf,
  301. &conf->bss[i]);
  302. if (hapd_iface->bss[i] == NULL) {
  303. wpa_supplicant_ap_deinit(wpa_s);
  304. return -1;
  305. }
  306. hapd_iface->bss[i]->msg_ctx = wpa_s;
  307. hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
  308. hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
  309. hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
  310. hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
  311. hostapd_register_probereq_cb(hapd_iface->bss[i],
  312. ap_probe_req_rx, wpa_s);
  313. hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
  314. hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
  315. #ifdef CONFIG_P2P
  316. hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
  317. hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(
  318. wpa_s, ssid->p2p_persistent_group,
  319. ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION);
  320. #endif /* CONFIG_P2P */
  321. }
  322. os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
  323. hapd_iface->bss[0]->driver = wpa_s->driver;
  324. hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
  325. if (hostapd_setup_interface(wpa_s->ap_iface)) {
  326. wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
  327. wpa_supplicant_ap_deinit(wpa_s);
  328. return -1;
  329. }
  330. wpa_s->current_ssid = ssid;
  331. os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
  332. wpa_s->assoc_freq = ssid->frequency;
  333. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  334. if (wpa_s->ap_configured_cb)
  335. wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
  336. wpa_s->ap_configured_cb_data);
  337. return 0;
  338. }
  339. void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
  340. {
  341. if (wpa_s->ap_iface == NULL)
  342. return;
  343. wpa_s->current_ssid = NULL;
  344. #ifdef CONFIG_P2P
  345. wpa_s->ap_iface->bss[0]->p2p_group = NULL;
  346. wpas_p2p_group_deinit(wpa_s);
  347. #endif /* CONFIG_P2P */
  348. hostapd_interface_deinit(wpa_s->ap_iface);
  349. hostapd_interface_free(wpa_s->ap_iface);
  350. wpa_s->ap_iface = NULL;
  351. wpa_drv_deinit_ap(wpa_s);
  352. }
  353. void ap_tx_status(void *ctx, const u8 *addr,
  354. const u8 *buf, size_t len, int ack)
  355. {
  356. #ifdef NEED_AP_MLME
  357. struct wpa_supplicant *wpa_s = ctx;
  358. hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
  359. #endif /* NEED_AP_MLME */
  360. }
  361. void ap_rx_from_unknown_sta(void *ctx, const u8 *frame, size_t len)
  362. {
  363. #ifdef NEED_AP_MLME
  364. struct wpa_supplicant *wpa_s = ctx;
  365. const struct ieee80211_hdr *hdr =
  366. (const struct ieee80211_hdr *) frame;
  367. u16 fc = le_to_host16(hdr->frame_control);
  368. ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], hdr->addr2,
  369. (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
  370. (WLAN_FC_TODS | WLAN_FC_FROMDS));
  371. #endif /* NEED_AP_MLME */
  372. }
  373. void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
  374. {
  375. #ifdef NEED_AP_MLME
  376. struct wpa_supplicant *wpa_s = ctx;
  377. struct hostapd_frame_info fi;
  378. os_memset(&fi, 0, sizeof(fi));
  379. fi.datarate = rx_mgmt->datarate;
  380. fi.ssi_signal = rx_mgmt->ssi_signal;
  381. ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
  382. rx_mgmt->frame_len, &fi);
  383. #endif /* NEED_AP_MLME */
  384. }
  385. void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
  386. {
  387. #ifdef NEED_AP_MLME
  388. struct wpa_supplicant *wpa_s = ctx;
  389. ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
  390. #endif /* NEED_AP_MLME */
  391. }
  392. void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
  393. const u8 *src_addr, const u8 *buf, size_t len)
  394. {
  395. ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
  396. }
  397. #ifdef CONFIG_WPS
  398. int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid)
  399. {
  400. if (!wpa_s->ap_iface)
  401. return -1;
  402. return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0]);
  403. }
  404. int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
  405. const char *pin, char *buf, size_t buflen)
  406. {
  407. int ret, ret_len = 0;
  408. if (!wpa_s->ap_iface)
  409. return -1;
  410. if (pin == NULL) {
  411. unsigned int rpin = wps_generate_pin();
  412. ret_len = os_snprintf(buf, buflen, "%d", rpin);
  413. pin = buf;
  414. } else
  415. ret_len = os_snprintf(buf, buflen, "%s", pin);
  416. ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
  417. 0);
  418. if (ret)
  419. return -1;
  420. return ret_len;
  421. }
  422. #endif /* CONFIG_WPS */
  423. #ifdef CONFIG_CTRL_IFACE
  424. int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
  425. char *buf, size_t buflen)
  426. {
  427. if (wpa_s->ap_iface == NULL)
  428. return -1;
  429. return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
  430. buf, buflen);
  431. }
  432. int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
  433. char *buf, size_t buflen)
  434. {
  435. if (wpa_s->ap_iface == NULL)
  436. return -1;
  437. return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
  438. buf, buflen);
  439. }
  440. int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
  441. char *buf, size_t buflen)
  442. {
  443. if (wpa_s->ap_iface == NULL)
  444. return -1;
  445. return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
  446. buf, buflen);
  447. }
  448. int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
  449. size_t buflen, int verbose)
  450. {
  451. char *pos = buf, *end = buf + buflen;
  452. int ret;
  453. struct hostapd_bss_config *conf;
  454. if (wpa_s->ap_iface == NULL)
  455. return -1;
  456. conf = wpa_s->ap_iface->bss[0]->conf;
  457. if (conf->wpa == 0)
  458. return 0;
  459. ret = os_snprintf(pos, end - pos,
  460. "pairwise_cipher=%s\n"
  461. "group_cipher=%s\n"
  462. "key_mgmt=%s\n",
  463. wpa_cipher_txt(conf->rsn_pairwise),
  464. wpa_cipher_txt(conf->wpa_group),
  465. wpa_key_mgmt_txt(conf->wpa_key_mgmt,
  466. conf->wpa));
  467. if (ret < 0 || ret >= end - pos)
  468. return pos - buf;
  469. pos += ret;
  470. return pos - buf;
  471. }
  472. #endif /* CONFIG_CTRL_IFACE */
  473. int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
  474. {
  475. struct hostapd_iface *iface = wpa_s->ap_iface;
  476. struct wpa_ssid *ssid = wpa_s->current_ssid;
  477. struct hostapd_data *hapd;
  478. if (ssid == NULL || wpa_s->ap_iface == NULL)
  479. return -1;
  480. #ifdef CONFIG_P2P
  481. if (ssid->mode == WPAS_MODE_P2P_GO)
  482. iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
  483. else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  484. iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
  485. P2P_GROUP_FORMATION;
  486. #endif /* CONFIG_P2P */
  487. ieee802_11_set_beacons(iface);
  488. hapd = iface->bss[0];
  489. hapd->drv.set_ap_wps_ie(hapd);
  490. return 0;
  491. }
  492. int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
  493. const u8 *addr)
  494. {
  495. struct hostapd_data *hapd;
  496. struct hostapd_bss_config *conf;
  497. if (!wpa_s->ap_iface)
  498. return -1;
  499. if (addr)
  500. wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
  501. MAC2STR(addr));
  502. else
  503. wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
  504. hapd = wpa_s->ap_iface->bss[0];
  505. conf = hapd->conf;
  506. os_free(conf->accept_mac);
  507. conf->accept_mac = NULL;
  508. conf->num_accept_mac = 0;
  509. os_free(conf->deny_mac);
  510. conf->deny_mac = NULL;
  511. conf->num_deny_mac = 0;
  512. if (addr == NULL) {
  513. conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
  514. return 0;
  515. }
  516. conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
  517. conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
  518. if (conf->accept_mac == NULL)
  519. return -1;
  520. os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
  521. conf->num_accept_mac = 1;
  522. return 0;
  523. }