ap.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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. if (wpa_s->conf->device_name) {
  149. bss->device_name = os_strdup(wpa_s->conf->device_name);
  150. bss->friendly_name = os_strdup(wpa_s->conf->device_name);
  151. }
  152. if (wpa_s->conf->manufacturer)
  153. bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
  154. if (wpa_s->conf->model_name)
  155. bss->model_name = os_strdup(wpa_s->conf->model_name);
  156. if (wpa_s->conf->model_number)
  157. bss->model_number = os_strdup(wpa_s->conf->model_number);
  158. if (wpa_s->conf->serial_number)
  159. bss->serial_number = os_strdup(wpa_s->conf->serial_number);
  160. os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
  161. os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
  162. #endif /* CONFIG_WPS */
  163. return 0;
  164. }
  165. static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
  166. {
  167. #ifdef CONFIG_P2P
  168. struct wpa_supplicant *wpa_s = ctx;
  169. const struct ieee80211_mgmt *mgmt;
  170. size_t hdr_len;
  171. mgmt = (const struct ieee80211_mgmt *) buf;
  172. hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
  173. if (hdr_len > len)
  174. return;
  175. wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
  176. mgmt->u.action.category,
  177. &mgmt->u.action.u.vs_public_action.action,
  178. len - hdr_len, freq);
  179. #endif /* CONFIG_P2P */
  180. }
  181. static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
  182. {
  183. #ifdef CONFIG_P2P
  184. struct wpa_supplicant *wpa_s = ctx;
  185. const struct ieee80211_mgmt *mgmt;
  186. size_t hdr_len;
  187. mgmt = (const struct ieee80211_mgmt *) buf;
  188. hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
  189. if (hdr_len > len)
  190. return -1;
  191. wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
  192. mgmt->u.action.category,
  193. &mgmt->u.action.u.vs_public_action.action,
  194. len - hdr_len, freq);
  195. #endif /* CONFIG_P2P */
  196. return 0;
  197. }
  198. static int ap_probe_req_rx(void *ctx, const u8 *addr, const u8 *ie,
  199. size_t ie_len)
  200. {
  201. #ifdef CONFIG_P2P
  202. struct wpa_supplicant *wpa_s = ctx;
  203. return wpas_p2p_probe_req_rx(wpa_s, addr, ie, ie_len);
  204. #else /* CONFIG_P2P */
  205. return 0;
  206. #endif /* CONFIG_P2P */
  207. }
  208. static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
  209. const u8 *uuid_e)
  210. {
  211. #ifdef CONFIG_P2P
  212. struct wpa_supplicant *wpa_s = ctx;
  213. wpas_p2p_wps_success(wpa_s, mac_addr, 1);
  214. #endif /* CONFIG_P2P */
  215. }
  216. int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
  217. struct wpa_ssid *ssid)
  218. {
  219. struct wpa_driver_associate_params params;
  220. struct hostapd_iface *hapd_iface;
  221. struct hostapd_config *conf;
  222. size_t i;
  223. if (ssid->ssid == NULL || ssid->ssid_len == 0) {
  224. wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
  225. return -1;
  226. }
  227. wpa_supplicant_ap_deinit(wpa_s);
  228. wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
  229. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  230. os_memset(&params, 0, sizeof(params));
  231. params.ssid = ssid->ssid;
  232. params.ssid_len = ssid->ssid_len;
  233. switch (ssid->mode) {
  234. case WPAS_MODE_INFRA:
  235. params.mode = IEEE80211_MODE_INFRA;
  236. break;
  237. case WPAS_MODE_IBSS:
  238. params.mode = IEEE80211_MODE_IBSS;
  239. break;
  240. case WPAS_MODE_AP:
  241. case WPAS_MODE_P2P_GO:
  242. case WPAS_MODE_P2P_GROUP_FORMATION:
  243. params.mode = IEEE80211_MODE_AP;
  244. break;
  245. }
  246. params.freq = ssid->frequency;
  247. if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
  248. wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
  249. else
  250. wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
  251. params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt);
  252. if (ssid->pairwise_cipher & WPA_CIPHER_CCMP)
  253. wpa_s->pairwise_cipher = WPA_CIPHER_CCMP;
  254. else if (ssid->pairwise_cipher & WPA_CIPHER_TKIP)
  255. wpa_s->pairwise_cipher = WPA_CIPHER_TKIP;
  256. else if (ssid->pairwise_cipher & WPA_CIPHER_NONE)
  257. wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
  258. else {
  259. wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
  260. "cipher.");
  261. return -1;
  262. }
  263. params.pairwise_suite = cipher_suite2driver(wpa_s->pairwise_cipher);
  264. params.group_suite = params.pairwise_suite;
  265. #ifdef CONFIG_P2P
  266. if (ssid->mode == WPAS_MODE_P2P_GO ||
  267. ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  268. params.p2p = 1;
  269. #endif /* CONFIG_P2P */
  270. if (wpa_s->parent->set_ap_uapsd)
  271. params.uapsd = wpa_s->parent->ap_uapsd;
  272. else
  273. params.uapsd = -1;
  274. if (wpa_drv_associate(wpa_s, &params) < 0) {
  275. wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
  276. return -1;
  277. }
  278. wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
  279. if (hapd_iface == NULL)
  280. return -1;
  281. hapd_iface->owner = wpa_s;
  282. wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
  283. if (conf == NULL) {
  284. wpa_supplicant_ap_deinit(wpa_s);
  285. return -1;
  286. }
  287. if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
  288. wpa_printf(MSG_ERROR, "Failed to create AP configuration");
  289. wpa_supplicant_ap_deinit(wpa_s);
  290. return -1;
  291. }
  292. #ifdef CONFIG_P2P
  293. if (ssid->mode == WPAS_MODE_P2P_GO)
  294. conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
  295. else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  296. conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
  297. P2P_GROUP_FORMATION;
  298. #endif /* CONFIG_P2P */
  299. hapd_iface->num_bss = conf->num_bss;
  300. hapd_iface->bss = os_zalloc(conf->num_bss *
  301. sizeof(struct hostapd_data *));
  302. if (hapd_iface->bss == NULL) {
  303. wpa_supplicant_ap_deinit(wpa_s);
  304. return -1;
  305. }
  306. for (i = 0; i < conf->num_bss; i++) {
  307. hapd_iface->bss[i] =
  308. hostapd_alloc_bss_data(hapd_iface, conf,
  309. &conf->bss[i]);
  310. if (hapd_iface->bss[i] == NULL) {
  311. wpa_supplicant_ap_deinit(wpa_s);
  312. return -1;
  313. }
  314. hapd_iface->bss[i]->msg_ctx = wpa_s;
  315. hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
  316. hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
  317. hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
  318. hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
  319. hostapd_register_probereq_cb(hapd_iface->bss[i],
  320. ap_probe_req_rx, wpa_s);
  321. hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
  322. hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
  323. #ifdef CONFIG_P2P
  324. hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
  325. hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(
  326. wpa_s, ssid->p2p_persistent_group,
  327. ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION);
  328. #endif /* CONFIG_P2P */
  329. }
  330. os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
  331. hapd_iface->bss[0]->driver = wpa_s->driver;
  332. hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
  333. if (hostapd_setup_interface(wpa_s->ap_iface)) {
  334. wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
  335. wpa_supplicant_ap_deinit(wpa_s);
  336. return -1;
  337. }
  338. wpa_s->current_ssid = ssid;
  339. os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
  340. wpa_s->assoc_freq = ssid->frequency;
  341. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  342. if (wpa_s->ap_configured_cb)
  343. wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
  344. wpa_s->ap_configured_cb_data);
  345. return 0;
  346. }
  347. void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
  348. {
  349. if (wpa_s->ap_iface == NULL)
  350. return;
  351. wpa_s->current_ssid = NULL;
  352. #ifdef CONFIG_P2P
  353. if (wpa_s->ap_iface->bss)
  354. wpa_s->ap_iface->bss[0]->p2p_group = NULL;
  355. wpas_p2p_group_deinit(wpa_s);
  356. #endif /* CONFIG_P2P */
  357. hostapd_interface_deinit(wpa_s->ap_iface);
  358. hostapd_interface_free(wpa_s->ap_iface);
  359. wpa_s->ap_iface = NULL;
  360. wpa_drv_deinit_ap(wpa_s);
  361. }
  362. void ap_tx_status(void *ctx, const u8 *addr,
  363. const u8 *buf, size_t len, int ack)
  364. {
  365. #ifdef NEED_AP_MLME
  366. struct wpa_supplicant *wpa_s = ctx;
  367. hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
  368. #endif /* NEED_AP_MLME */
  369. }
  370. void ap_rx_from_unknown_sta(void *ctx, const u8 *frame, size_t len)
  371. {
  372. #ifdef NEED_AP_MLME
  373. struct wpa_supplicant *wpa_s = ctx;
  374. const struct ieee80211_hdr *hdr =
  375. (const struct ieee80211_hdr *) frame;
  376. u16 fc = le_to_host16(hdr->frame_control);
  377. ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], hdr->addr2,
  378. (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
  379. (WLAN_FC_TODS | WLAN_FC_FROMDS));
  380. #endif /* NEED_AP_MLME */
  381. }
  382. void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
  383. {
  384. #ifdef NEED_AP_MLME
  385. struct wpa_supplicant *wpa_s = ctx;
  386. struct hostapd_frame_info fi;
  387. os_memset(&fi, 0, sizeof(fi));
  388. fi.datarate = rx_mgmt->datarate;
  389. fi.ssi_signal = rx_mgmt->ssi_signal;
  390. ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
  391. rx_mgmt->frame_len, &fi);
  392. #endif /* NEED_AP_MLME */
  393. }
  394. void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
  395. {
  396. #ifdef NEED_AP_MLME
  397. struct wpa_supplicant *wpa_s = ctx;
  398. ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
  399. #endif /* NEED_AP_MLME */
  400. }
  401. void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
  402. const u8 *src_addr, const u8 *buf, size_t len)
  403. {
  404. ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
  405. }
  406. #ifdef CONFIG_WPS
  407. int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid)
  408. {
  409. if (!wpa_s->ap_iface)
  410. return -1;
  411. return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0]);
  412. }
  413. int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
  414. const char *pin, char *buf, size_t buflen)
  415. {
  416. int ret, ret_len = 0;
  417. if (!wpa_s->ap_iface)
  418. return -1;
  419. if (pin == NULL) {
  420. unsigned int rpin = wps_generate_pin();
  421. ret_len = os_snprintf(buf, buflen, "%d", rpin);
  422. pin = buf;
  423. } else
  424. ret_len = os_snprintf(buf, buflen, "%s", pin);
  425. ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
  426. 0);
  427. if (ret)
  428. return -1;
  429. return ret_len;
  430. }
  431. #endif /* CONFIG_WPS */
  432. #ifdef CONFIG_CTRL_IFACE
  433. int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
  434. char *buf, size_t buflen)
  435. {
  436. if (wpa_s->ap_iface == NULL)
  437. return -1;
  438. return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
  439. buf, buflen);
  440. }
  441. int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
  442. char *buf, size_t buflen)
  443. {
  444. if (wpa_s->ap_iface == NULL)
  445. return -1;
  446. return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
  447. buf, buflen);
  448. }
  449. int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
  450. char *buf, size_t buflen)
  451. {
  452. if (wpa_s->ap_iface == NULL)
  453. return -1;
  454. return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
  455. buf, buflen);
  456. }
  457. int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
  458. size_t buflen, int verbose)
  459. {
  460. char *pos = buf, *end = buf + buflen;
  461. int ret;
  462. struct hostapd_bss_config *conf;
  463. if (wpa_s->ap_iface == NULL)
  464. return -1;
  465. conf = wpa_s->ap_iface->bss[0]->conf;
  466. if (conf->wpa == 0)
  467. return 0;
  468. ret = os_snprintf(pos, end - pos,
  469. "pairwise_cipher=%s\n"
  470. "group_cipher=%s\n"
  471. "key_mgmt=%s\n",
  472. wpa_cipher_txt(conf->rsn_pairwise),
  473. wpa_cipher_txt(conf->wpa_group),
  474. wpa_key_mgmt_txt(conf->wpa_key_mgmt,
  475. conf->wpa));
  476. if (ret < 0 || ret >= end - pos)
  477. return pos - buf;
  478. pos += ret;
  479. return pos - buf;
  480. }
  481. #endif /* CONFIG_CTRL_IFACE */
  482. int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
  483. {
  484. struct hostapd_iface *iface = wpa_s->ap_iface;
  485. struct wpa_ssid *ssid = wpa_s->current_ssid;
  486. struct hostapd_data *hapd;
  487. if (ssid == NULL || wpa_s->ap_iface == NULL)
  488. return -1;
  489. #ifdef CONFIG_P2P
  490. if (ssid->mode == WPAS_MODE_P2P_GO)
  491. iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
  492. else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  493. iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
  494. P2P_GROUP_FORMATION;
  495. #endif /* CONFIG_P2P */
  496. ieee802_11_set_beacons(iface);
  497. hapd = iface->bss[0];
  498. hapd->drv.set_ap_wps_ie(hapd);
  499. return 0;
  500. }
  501. int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
  502. const u8 *addr)
  503. {
  504. struct hostapd_data *hapd;
  505. struct hostapd_bss_config *conf;
  506. if (!wpa_s->ap_iface)
  507. return -1;
  508. if (addr)
  509. wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
  510. MAC2STR(addr));
  511. else
  512. wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
  513. hapd = wpa_s->ap_iface->bss[0];
  514. conf = hapd->conf;
  515. os_free(conf->accept_mac);
  516. conf->accept_mac = NULL;
  517. conf->num_accept_mac = 0;
  518. os_free(conf->deny_mac);
  519. conf->deny_mac = NULL;
  520. conf->num_deny_mac = 0;
  521. if (addr == NULL) {
  522. conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
  523. return 0;
  524. }
  525. conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
  526. conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
  527. if (conf->accept_mac == NULL)
  528. return -1;
  529. os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
  530. conf->num_accept_mac = 1;
  531. return 0;
  532. }