ap.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  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 "includes.h"
  16. #include "common.h"
  17. #include "ap/hostapd.h"
  18. #include "ap/config.h"
  19. #ifdef NEED_AP_MLME
  20. #include "ap/ieee802_11.h"
  21. #endif /* NEED_AP_MLME */
  22. #include "ap/wps_hostapd.h"
  23. #include "ap/ctrl_iface_ap.h"
  24. #include "eap_common/eap_defs.h"
  25. #include "eap_server/eap_methods.h"
  26. #include "eap_common/eap_wsc_common.h"
  27. #include "wps/wps.h"
  28. #include "config_ssid.h"
  29. #include "config.h"
  30. #include "wpa_supplicant_i.h"
  31. #include "driver_i.h"
  32. #include "ap.h"
  33. struct hapd_interfaces {
  34. size_t count;
  35. struct hostapd_iface **iface;
  36. };
  37. int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
  38. int (*cb)(struct hostapd_iface *iface,
  39. void *ctx), void *ctx)
  40. {
  41. /* TODO */
  42. return 0;
  43. }
  44. int hostapd_ctrl_iface_init(struct hostapd_data *hapd)
  45. {
  46. return 0;
  47. }
  48. void hostapd_ctrl_iface_deinit(struct hostapd_data *hapd)
  49. {
  50. }
  51. struct ap_driver_data {
  52. struct hostapd_data *hapd;
  53. };
  54. static void * ap_driver_init(struct hostapd_data *hapd,
  55. struct wpa_init_params *params)
  56. {
  57. struct ap_driver_data *drv;
  58. struct wpa_supplicant *wpa_s = hapd->iface->owner;
  59. drv = os_zalloc(sizeof(struct ap_driver_data));
  60. if (drv == NULL) {
  61. wpa_printf(MSG_ERROR, "Could not allocate memory for AP "
  62. "driver data");
  63. return NULL;
  64. }
  65. drv->hapd = hapd;
  66. os_memcpy(hapd->own_addr, wpa_s->own_addr, ETH_ALEN);
  67. return drv;
  68. }
  69. static void ap_driver_deinit(void *priv)
  70. {
  71. struct ap_driver_data *drv = priv;
  72. os_free(drv);
  73. }
  74. static int ap_driver_send_ether(void *priv, const u8 *dst, const u8 *src,
  75. u16 proto, const u8 *data, size_t data_len)
  76. {
  77. wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__);
  78. return -1;
  79. }
  80. static int ap_driver_set_key(const char *iface, void *priv, wpa_alg alg,
  81. const u8 *addr, int key_idx, int set_tx,
  82. const u8 *seq, size_t seq_len, const u8 *key,
  83. size_t key_len)
  84. {
  85. struct ap_driver_data *drv = priv;
  86. struct wpa_supplicant *wpa_s = drv->hapd->iface->owner;
  87. return wpa_drv_set_key(wpa_s, alg, addr, key_idx, set_tx, seq, seq_len,
  88. key, key_len);
  89. }
  90. static int ap_driver_get_seqnum(const char *iface, void *priv, const u8 *addr,
  91. int idx, u8 *seq)
  92. {
  93. wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__);
  94. return -1;
  95. }
  96. static int ap_driver_flush(void *priv)
  97. {
  98. wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__);
  99. return -1;
  100. }
  101. static int ap_driver_read_sta_data(void *priv,
  102. struct hostap_sta_driver_data *data,
  103. const u8 *addr)
  104. {
  105. wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__);
  106. return -1;
  107. }
  108. static int ap_driver_sta_set_flags(void *priv, const u8 *addr, int total_flags,
  109. int flags_or, int flags_and)
  110. {
  111. struct ap_driver_data *drv = priv;
  112. struct wpa_supplicant *wpa_s = drv->hapd->iface->owner;
  113. return wpa_drv_sta_set_flags(wpa_s, addr, total_flags, flags_or,
  114. flags_and);
  115. }
  116. static int ap_driver_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
  117. int reason)
  118. {
  119. wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__);
  120. return -1;
  121. }
  122. static int ap_driver_sta_disassoc(void *priv, const u8 *own_addr,
  123. const u8 *addr, int reason)
  124. {
  125. wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__);
  126. return -1;
  127. }
  128. static int ap_driver_sta_remove(void *priv, const u8 *addr)
  129. {
  130. struct ap_driver_data *drv = priv;
  131. struct wpa_supplicant *wpa_s = drv->hapd->iface->owner;
  132. return wpa_drv_sta_remove(wpa_s, addr);
  133. }
  134. static int ap_driver_send_mlme(void *priv, const u8 *data, size_t len)
  135. {
  136. struct ap_driver_data *drv = priv;
  137. struct wpa_supplicant *wpa_s = drv->hapd->iface->owner;
  138. return wpa_drv_send_mlme(wpa_s, data, len);
  139. }
  140. static int ap_driver_sta_add(const char *ifname, void *priv,
  141. struct hostapd_sta_add_params *params)
  142. {
  143. struct ap_driver_data *drv = priv;
  144. struct wpa_supplicant *wpa_s = drv->hapd->iface->owner;
  145. return wpa_drv_sta_add(wpa_s, params);
  146. }
  147. static int ap_driver_get_inact_sec(void *priv, const u8 *addr)
  148. {
  149. wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__);
  150. return -1;
  151. }
  152. static int ap_driver_set_freq(void *priv, struct hostapd_freq_params *freq)
  153. {
  154. wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__);
  155. return 0;
  156. }
  157. static int ap_driver_set_beacon(const char *iface, void *priv,
  158. const u8 *head, size_t head_len,
  159. const u8 *tail, size_t tail_len,
  160. int dtim_period, int beacon_int)
  161. {
  162. struct ap_driver_data *drv = priv;
  163. struct wpa_supplicant *wpa_s = drv->hapd->iface->owner;
  164. return wpa_drv_set_beacon(wpa_s, head, head_len, tail, tail_len,
  165. dtim_period, beacon_int);
  166. }
  167. static int ap_driver_set_cts_protect(void *priv, int value)
  168. {
  169. wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__);
  170. return -1;
  171. }
  172. static int ap_driver_set_preamble(void *priv, int value)
  173. {
  174. wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__);
  175. return -1;
  176. }
  177. static int ap_driver_set_short_slot_time(void *priv, int value)
  178. {
  179. wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__);
  180. return -1;
  181. }
  182. static int ap_driver_set_tx_queue_params(void *priv, int queue, int aifs,
  183. int cw_min, int cw_max,
  184. int burst_time)
  185. {
  186. wpa_printf(MSG_DEBUG, "AP TODO: %s", __func__);
  187. return -1;
  188. }
  189. static struct hostapd_hw_modes *ap_driver_get_hw_feature_data(void *priv,
  190. u16 *num_modes,
  191. u16 *flags)
  192. {
  193. struct ap_driver_data *drv = priv;
  194. struct wpa_supplicant *wpa_s = drv->hapd->iface->owner;
  195. return wpa_drv_get_hw_feature_data(wpa_s, num_modes, flags);
  196. }
  197. static int ap_driver_hapd_send_eapol(void *priv, const u8 *addr,
  198. const u8 *data, size_t data_len,
  199. int encrypt, const u8 *own_addr)
  200. {
  201. struct ap_driver_data *drv = priv;
  202. struct wpa_supplicant *wpa_s = drv->hapd->iface->owner;
  203. return wpa_drv_hapd_send_eapol(wpa_s, addr, data, data_len, encrypt,
  204. own_addr);
  205. }
  206. struct wpa_driver_ops ap_driver_ops =
  207. {
  208. .name = "wpa_supplicant",
  209. .hapd_init = ap_driver_init,
  210. .hapd_deinit = ap_driver_deinit,
  211. .send_ether = ap_driver_send_ether,
  212. .set_key = ap_driver_set_key,
  213. .get_seqnum = ap_driver_get_seqnum,
  214. .flush = ap_driver_flush,
  215. .read_sta_data = ap_driver_read_sta_data,
  216. .sta_set_flags = ap_driver_sta_set_flags,
  217. .sta_deauth = ap_driver_sta_deauth,
  218. .sta_disassoc = ap_driver_sta_disassoc,
  219. .sta_remove = ap_driver_sta_remove,
  220. .send_mlme = ap_driver_send_mlme,
  221. .sta_add = ap_driver_sta_add,
  222. .get_inact_sec = ap_driver_get_inact_sec,
  223. .set_freq = ap_driver_set_freq,
  224. .set_beacon = ap_driver_set_beacon,
  225. .set_cts_protect = ap_driver_set_cts_protect,
  226. .set_preamble = ap_driver_set_preamble,
  227. .set_short_slot_time = ap_driver_set_short_slot_time,
  228. .set_tx_queue_params = ap_driver_set_tx_queue_params,
  229. .get_hw_feature_data = ap_driver_get_hw_feature_data,
  230. .hapd_send_eapol = ap_driver_hapd_send_eapol,
  231. };
  232. extern struct wpa_driver_ops *wpa_drivers[];
  233. static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
  234. struct wpa_ssid *ssid,
  235. struct hostapd_config *conf)
  236. {
  237. struct hostapd_bss_config *bss = &conf->bss[0];
  238. int j, pairwise;
  239. for (j = 0; wpa_drivers[j]; j++) {
  240. if (os_strcmp("wpa_supplicant", wpa_drivers[j]->name) == 0) {
  241. conf->driver = wpa_drivers[j];
  242. break;
  243. }
  244. }
  245. if (conf->driver == NULL) {
  246. wpa_printf(MSG_ERROR, "No AP driver ops found");
  247. return -1;
  248. }
  249. os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
  250. if (ssid->frequency == 0) {
  251. /* default channel 11 */
  252. conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
  253. conf->channel = 11;
  254. } else if (ssid->frequency >= 2412 && ssid->frequency <= 2472) {
  255. conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
  256. conf->channel = (ssid->frequency - 2407) / 5;
  257. } else if ((ssid->frequency >= 5180 && ssid->frequency <= 5240) ||
  258. (ssid->frequency >= 5745 && ssid->frequency <= 5825)) {
  259. conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
  260. conf->channel = (ssid->frequency - 5000) / 5;
  261. } else {
  262. wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
  263. ssid->frequency);
  264. return -1;
  265. }
  266. /* TODO: enable HT if driver supports it;
  267. * drop to 11b if driver does not support 11g */
  268. if (ssid->ssid_len == 0) {
  269. wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
  270. return -1;
  271. }
  272. os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
  273. bss->ssid.ssid[ssid->ssid_len] = '\0';
  274. bss->ssid.ssid_len = ssid->ssid_len;
  275. bss->ssid.ssid_set = 1;
  276. if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
  277. bss->wpa = ssid->proto;
  278. bss->wpa_key_mgmt = ssid->key_mgmt;
  279. bss->wpa_pairwise = ssid->pairwise_cipher;
  280. if (ssid->passphrase) {
  281. bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
  282. } else if (ssid->psk_set) {
  283. os_free(bss->ssid.wpa_psk);
  284. bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
  285. if (bss->ssid.wpa_psk == NULL)
  286. return -1;
  287. os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
  288. bss->ssid.wpa_psk->group = 1;
  289. }
  290. /* Select group cipher based on the enabled pairwise cipher suites */
  291. pairwise = 0;
  292. if (bss->wpa & 1)
  293. pairwise |= bss->wpa_pairwise;
  294. if (bss->wpa & 2) {
  295. if (bss->rsn_pairwise == 0)
  296. bss->rsn_pairwise = bss->wpa_pairwise;
  297. pairwise |= bss->rsn_pairwise;
  298. }
  299. if (pairwise & WPA_CIPHER_TKIP)
  300. bss->wpa_group = WPA_CIPHER_TKIP;
  301. else
  302. bss->wpa_group = WPA_CIPHER_CCMP;
  303. if (bss->wpa && bss->ieee802_1x)
  304. bss->ssid.security_policy = SECURITY_WPA;
  305. else if (bss->wpa)
  306. bss->ssid.security_policy = SECURITY_WPA_PSK;
  307. else if (bss->ieee802_1x) {
  308. bss->ssid.security_policy = SECURITY_IEEE_802_1X;
  309. bss->ssid.wep.default_len = bss->default_wep_key_len;
  310. } else if (bss->ssid.wep.keys_set)
  311. bss->ssid.security_policy = SECURITY_STATIC_WEP;
  312. else
  313. bss->ssid.security_policy = SECURITY_PLAINTEXT;
  314. #ifdef CONFIG_WPS
  315. /*
  316. * Enable WPS by default, but require user interaction to actually use
  317. * it. Only the internal Registrar is supported.
  318. */
  319. bss->eap_server = 1;
  320. bss->wps_state = 2;
  321. bss->ap_setup_locked = 1;
  322. if (wpa_s->conf->config_methods)
  323. bss->config_methods = os_strdup(wpa_s->conf->config_methods);
  324. if (wpa_s->conf->device_type)
  325. bss->device_type = os_strdup(wpa_s->conf->device_type);
  326. #endif /* CONFIG_WPS */
  327. return 0;
  328. }
  329. static int hostapd_driver_init(struct hostapd_iface *iface)
  330. {
  331. struct wpa_init_params params;
  332. struct hostapd_data *hapd = iface->bss[0];
  333. if (hapd->driver == NULL || hapd->driver->hapd_init == NULL) {
  334. wpa_printf(MSG_ERROR, "No hostapd driver wrapper available");
  335. return -1;
  336. }
  337. os_memset(&params, 0, sizeof(params));
  338. params.ifname = hapd->conf->iface;
  339. params.ssid = (const u8 *) hapd->conf->ssid.ssid;
  340. params.ssid_len = hapd->conf->ssid.ssid_len;
  341. params.num_bridge = hapd->iface->num_bss;
  342. params.bridge = os_zalloc(hapd->iface->num_bss * sizeof(char *));
  343. if (params.bridge == NULL)
  344. return -1;
  345. params.own_addr = hapd->own_addr;
  346. hapd->drv_priv = hapd->driver->hapd_init(hapd, &params);
  347. os_free(params.bridge);
  348. if (hapd->drv_priv == NULL) {
  349. wpa_printf(MSG_ERROR, "%s driver initialization failed.",
  350. hapd->driver->name);
  351. hapd->driver = NULL;
  352. return -1;
  353. }
  354. return 0;
  355. }
  356. int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
  357. struct wpa_ssid *ssid)
  358. {
  359. struct wpa_driver_associate_params params;
  360. struct hostapd_iface *hapd_iface;
  361. struct hostapd_config *conf;
  362. size_t i;
  363. if (ssid->ssid == NULL || ssid->ssid_len == 0) {
  364. wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
  365. return -1;
  366. }
  367. wpa_supplicant_ap_deinit(wpa_s);
  368. wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
  369. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  370. os_memset(&params, 0, sizeof(params));
  371. params.ssid = ssid->ssid;
  372. params.ssid_len = ssid->ssid_len;
  373. params.mode = ssid->mode;
  374. params.freq = ssid->frequency;
  375. if (wpa_drv_associate(wpa_s, &params) < 0) {
  376. wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
  377. return -1;
  378. }
  379. wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
  380. if (hapd_iface == NULL)
  381. return -1;
  382. hapd_iface->owner = wpa_s;
  383. wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
  384. if (conf == NULL) {
  385. wpa_supplicant_ap_deinit(wpa_s);
  386. return -1;
  387. }
  388. if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
  389. wpa_printf(MSG_ERROR, "Failed to create AP configuration");
  390. wpa_supplicant_ap_deinit(wpa_s);
  391. return -1;
  392. }
  393. hapd_iface->num_bss = conf->num_bss;
  394. hapd_iface->bss = os_zalloc(conf->num_bss *
  395. sizeof(struct hostapd_data *));
  396. if (hapd_iface->bss == NULL) {
  397. wpa_supplicant_ap_deinit(wpa_s);
  398. return -1;
  399. }
  400. for (i = 0; i < conf->num_bss; i++) {
  401. hapd_iface->bss[i] =
  402. hostapd_alloc_bss_data(hapd_iface, conf,
  403. &conf->bss[i]);
  404. if (hapd_iface->bss[i] == NULL) {
  405. wpa_supplicant_ap_deinit(wpa_s);
  406. return -1;
  407. }
  408. hapd_iface->bss[i]->msg_ctx = wpa_s;
  409. }
  410. if (hostapd_driver_init(wpa_s->ap_iface) ||
  411. hostapd_setup_interface(wpa_s->ap_iface)) {
  412. wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
  413. wpa_supplicant_ap_deinit(wpa_s);
  414. return -1;
  415. }
  416. wpa_s->current_ssid = ssid;
  417. os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
  418. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  419. return 0;
  420. }
  421. void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
  422. {
  423. const struct wpa_driver_ops *driver;
  424. void *drv_priv;
  425. if (wpa_s->ap_iface == NULL)
  426. return;
  427. driver = wpa_s->ap_iface->bss[0]->driver;
  428. drv_priv = wpa_s->ap_iface->bss[0]->drv_priv;
  429. hostapd_interface_deinit(wpa_s->ap_iface);
  430. wpa_s->ap_iface = NULL;
  431. if (driver && driver->hapd_deinit)
  432. driver->hapd_deinit(drv_priv);
  433. }
  434. void ap_tx_status(void *ctx, const u8 *addr,
  435. const u8 *buf, size_t len, int ack)
  436. {
  437. #ifdef NEED_AP_MLME
  438. struct wpa_supplicant *wpa_s = ctx;
  439. hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
  440. #endif /* NEED_AP_MLME */
  441. }
  442. void ap_rx_from_unknown_sta(void *ctx, const struct ieee80211_hdr *hdr,
  443. size_t len)
  444. {
  445. #ifdef NEED_AP_MLME
  446. struct wpa_supplicant *wpa_s = ctx;
  447. u16 fc = le_to_host16(hdr->frame_control);
  448. ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], hdr->addr2,
  449. (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
  450. (WLAN_FC_TODS | WLAN_FC_FROMDS));
  451. #endif /* NEED_AP_MLME */
  452. }
  453. void ap_mgmt_rx(void *ctx, const u8 *buf, size_t len,
  454. struct hostapd_frame_info *fi)
  455. {
  456. #ifdef NEED_AP_MLME
  457. struct wpa_supplicant *wpa_s = ctx;
  458. ieee802_11_mgmt(wpa_s->ap_iface->bss[0], buf, len, fi);
  459. #endif /* NEED_AP_MLME */
  460. }
  461. void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
  462. {
  463. #ifdef NEED_AP_MLME
  464. struct wpa_supplicant *wpa_s = ctx;
  465. ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
  466. #endif /* NEED_AP_MLME */
  467. }
  468. void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
  469. const u8 *src_addr, const u8 *buf, size_t len)
  470. {
  471. hostapd_eapol_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
  472. }
  473. #ifdef CONFIG_WPS
  474. int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid)
  475. {
  476. return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0]);
  477. }
  478. int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
  479. const char *pin, char *buf, size_t buflen)
  480. {
  481. int ret, ret_len = 0;
  482. if (pin == NULL) {
  483. unsigned int rpin = wps_generate_pin();
  484. ret_len = os_snprintf(buf, buflen, "%d", rpin);
  485. pin = buf;
  486. }
  487. ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], "any", pin, 0);
  488. if (ret)
  489. return -1;
  490. return ret_len;
  491. }
  492. #endif /* CONFIG_WPS */
  493. #ifdef CONFIG_CTRL_IFACE
  494. int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
  495. char *buf, size_t buflen)
  496. {
  497. if (wpa_s->ap_iface == NULL)
  498. return -1;
  499. return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
  500. buf, buflen);
  501. }
  502. int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
  503. char *buf, size_t buflen)
  504. {
  505. if (wpa_s->ap_iface == NULL)
  506. return -1;
  507. return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
  508. buf, buflen);
  509. }
  510. int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
  511. char *buf, size_t buflen)
  512. {
  513. if (wpa_s->ap_iface == NULL)
  514. return -1;
  515. return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
  516. buf, buflen);
  517. }
  518. int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
  519. size_t buflen, int verbose)
  520. {
  521. char *pos = buf, *end = buf + buflen;
  522. int ret;
  523. struct hostapd_bss_config *conf;
  524. if (wpa_s->ap_iface == NULL)
  525. return -1;
  526. conf = wpa_s->ap_iface->bss[0]->conf;
  527. if (conf->wpa == 0)
  528. return 0;
  529. ret = os_snprintf(pos, end - pos,
  530. "pairwise_cipher=%s\n"
  531. "group_cipher=%s\n"
  532. "key_mgmt=%s\n",
  533. wpa_cipher_txt(conf->rsn_pairwise),
  534. wpa_cipher_txt(conf->wpa_group),
  535. wpa_key_mgmt_txt(conf->wpa_key_mgmt,
  536. conf->wpa));
  537. if (ret < 0 || ret >= end - pos)
  538. return pos - buf;
  539. pos += ret;
  540. return pos - buf;
  541. }
  542. #endif /* CONFIG_CTRL_IFACE */