ap.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  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 software may be distributed under the terms of the BSD license.
  7. * See README for more details.
  8. */
  9. #include "utils/includes.h"
  10. #include "utils/common.h"
  11. #include "utils/eloop.h"
  12. #include "utils/uuid.h"
  13. #include "common/ieee802_11_defs.h"
  14. #include "common/wpa_ctrl.h"
  15. #include "eapol_supp/eapol_supp_sm.h"
  16. #include "crypto/dh_group5.h"
  17. #include "ap/hostapd.h"
  18. #include "ap/ap_config.h"
  19. #include "ap/ap_drv_ops.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 "wps/wps.h"
  28. #include "common/ieee802_11_defs.h"
  29. #include "config_ssid.h"
  30. #include "config.h"
  31. #include "wpa_supplicant_i.h"
  32. #include "driver_i.h"
  33. #include "p2p_supplicant.h"
  34. #include "ap.h"
  35. #include "ap/sta_info.h"
  36. #include "notify.h"
  37. #ifdef CONFIG_WPS
  38. static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx);
  39. #endif /* CONFIG_WPS */
  40. #ifdef CONFIG_IEEE80211N
  41. static void wpas_conf_ap_vht(struct wpa_supplicant *wpa_s,
  42. struct hostapd_config *conf,
  43. struct hostapd_hw_modes *mode)
  44. {
  45. u8 center_chan = 0;
  46. u8 channel = conf->channel;
  47. if (!conf->secondary_channel)
  48. goto no_vht;
  49. center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel);
  50. if (!center_chan)
  51. goto no_vht;
  52. /* Use 80 MHz channel */
  53. conf->vht_oper_chwidth = 1;
  54. conf->vht_oper_centr_freq_seg0_idx = center_chan;
  55. return;
  56. no_vht:
  57. conf->vht_oper_centr_freq_seg0_idx =
  58. channel + conf->secondary_channel * 2;
  59. }
  60. #endif /* CONFIG_IEEE80211N */
  61. static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
  62. struct wpa_ssid *ssid,
  63. struct hostapd_config *conf)
  64. {
  65. struct hostapd_bss_config *bss = conf->bss[0];
  66. conf->driver = wpa_s->driver;
  67. os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
  68. conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
  69. &conf->channel);
  70. if (conf->hw_mode == NUM_HOSTAPD_MODES) {
  71. wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
  72. ssid->frequency);
  73. return -1;
  74. }
  75. /* TODO: enable HT40 if driver supports it;
  76. * drop to 11b if driver does not support 11g */
  77. #ifdef CONFIG_IEEE80211N
  78. /*
  79. * Enable HT20 if the driver supports it, by setting conf->ieee80211n
  80. * and a mask of allowed capabilities within conf->ht_capab.
  81. * Using default config settings for: conf->ht_op_mode_fixed,
  82. * conf->secondary_channel, conf->require_ht
  83. */
  84. if (wpa_s->hw.modes) {
  85. struct hostapd_hw_modes *mode = NULL;
  86. int i, no_ht = 0;
  87. for (i = 0; i < wpa_s->hw.num_modes; i++) {
  88. if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
  89. mode = &wpa_s->hw.modes[i];
  90. break;
  91. }
  92. }
  93. #ifdef CONFIG_HT_OVERRIDES
  94. if (ssid->disable_ht) {
  95. conf->ieee80211n = 0;
  96. conf->ht_capab = 0;
  97. no_ht = 1;
  98. }
  99. #endif /* CONFIG_HT_OVERRIDES */
  100. if (!no_ht && mode && mode->ht_capab) {
  101. conf->ieee80211n = 1;
  102. #ifdef CONFIG_P2P
  103. if (conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
  104. (mode->ht_capab &
  105. HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
  106. ssid->ht40)
  107. conf->secondary_channel =
  108. wpas_p2p_get_ht40_mode(wpa_s, mode,
  109. conf->channel);
  110. if (conf->secondary_channel)
  111. conf->ht_capab |=
  112. HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
  113. #endif /* CONFIG_P2P */
  114. /*
  115. * white-list capabilities that won't cause issues
  116. * to connecting stations, while leaving the current
  117. * capabilities intact (currently disabled SMPS).
  118. */
  119. conf->ht_capab |= mode->ht_capab &
  120. (HT_CAP_INFO_GREEN_FIELD |
  121. HT_CAP_INFO_SHORT_GI20MHZ |
  122. HT_CAP_INFO_SHORT_GI40MHZ |
  123. HT_CAP_INFO_RX_STBC_MASK |
  124. HT_CAP_INFO_MAX_AMSDU_SIZE);
  125. if (mode->vht_capab && ssid->vht) {
  126. conf->ieee80211ac = 1;
  127. wpas_conf_ap_vht(wpa_s, conf, mode);
  128. }
  129. }
  130. }
  131. #endif /* CONFIG_IEEE80211N */
  132. #ifdef CONFIG_P2P
  133. if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
  134. (ssid->mode == WPAS_MODE_P2P_GO ||
  135. ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
  136. /* Remove 802.11b rates from supported and basic rate sets */
  137. int *list = os_malloc(4 * sizeof(int));
  138. if (list) {
  139. list[0] = 60;
  140. list[1] = 120;
  141. list[2] = 240;
  142. list[3] = -1;
  143. }
  144. conf->basic_rates = list;
  145. list = os_malloc(9 * sizeof(int));
  146. if (list) {
  147. list[0] = 60;
  148. list[1] = 90;
  149. list[2] = 120;
  150. list[3] = 180;
  151. list[4] = 240;
  152. list[5] = 360;
  153. list[6] = 480;
  154. list[7] = 540;
  155. list[8] = -1;
  156. }
  157. conf->supported_rates = list;
  158. }
  159. bss->isolate = !wpa_s->conf->p2p_intra_bss;
  160. bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
  161. if (ssid->p2p_group) {
  162. os_memcpy(bss->ip_addr_go, wpa_s->parent->conf->ip_addr_go, 4);
  163. os_memcpy(bss->ip_addr_mask, wpa_s->parent->conf->ip_addr_mask,
  164. 4);
  165. os_memcpy(bss->ip_addr_start,
  166. wpa_s->parent->conf->ip_addr_start, 4);
  167. os_memcpy(bss->ip_addr_end, wpa_s->parent->conf->ip_addr_end,
  168. 4);
  169. }
  170. #endif /* CONFIG_P2P */
  171. if (ssid->ssid_len == 0) {
  172. wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
  173. return -1;
  174. }
  175. os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
  176. bss->ssid.ssid_len = ssid->ssid_len;
  177. bss->ssid.ssid_set = 1;
  178. bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
  179. if (ssid->auth_alg)
  180. bss->auth_algs = ssid->auth_alg;
  181. if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
  182. bss->wpa = ssid->proto;
  183. bss->wpa_key_mgmt = ssid->key_mgmt;
  184. bss->wpa_pairwise = ssid->pairwise_cipher;
  185. if (ssid->psk_set) {
  186. os_free(bss->ssid.wpa_psk);
  187. bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
  188. if (bss->ssid.wpa_psk == NULL)
  189. return -1;
  190. os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
  191. bss->ssid.wpa_psk->group = 1;
  192. } else if (ssid->passphrase) {
  193. bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
  194. } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
  195. ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
  196. struct hostapd_wep_keys *wep = &bss->ssid.wep;
  197. int i;
  198. for (i = 0; i < NUM_WEP_KEYS; i++) {
  199. if (ssid->wep_key_len[i] == 0)
  200. continue;
  201. wep->key[i] = os_malloc(ssid->wep_key_len[i]);
  202. if (wep->key[i] == NULL)
  203. return -1;
  204. os_memcpy(wep->key[i], ssid->wep_key[i],
  205. ssid->wep_key_len[i]);
  206. wep->len[i] = ssid->wep_key_len[i];
  207. }
  208. wep->idx = ssid->wep_tx_keyidx;
  209. wep->keys_set = 1;
  210. }
  211. if (ssid->ap_max_inactivity)
  212. bss->ap_max_inactivity = ssid->ap_max_inactivity;
  213. if (ssid->dtim_period)
  214. bss->dtim_period = ssid->dtim_period;
  215. else if (wpa_s->conf->dtim_period)
  216. bss->dtim_period = wpa_s->conf->dtim_period;
  217. if (ssid->beacon_int)
  218. conf->beacon_int = ssid->beacon_int;
  219. else if (wpa_s->conf->beacon_int)
  220. conf->beacon_int = wpa_s->conf->beacon_int;
  221. if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
  222. bss->rsn_pairwise = bss->wpa_pairwise;
  223. bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
  224. bss->rsn_pairwise);
  225. if (bss->wpa && bss->ieee802_1x)
  226. bss->ssid.security_policy = SECURITY_WPA;
  227. else if (bss->wpa)
  228. bss->ssid.security_policy = SECURITY_WPA_PSK;
  229. else if (bss->ieee802_1x) {
  230. int cipher = WPA_CIPHER_NONE;
  231. bss->ssid.security_policy = SECURITY_IEEE_802_1X;
  232. bss->ssid.wep.default_len = bss->default_wep_key_len;
  233. if (bss->default_wep_key_len)
  234. cipher = bss->default_wep_key_len >= 13 ?
  235. WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
  236. bss->wpa_group = cipher;
  237. bss->wpa_pairwise = cipher;
  238. bss->rsn_pairwise = cipher;
  239. } else if (bss->ssid.wep.keys_set) {
  240. int cipher = WPA_CIPHER_WEP40;
  241. if (bss->ssid.wep.len[0] >= 13)
  242. cipher = WPA_CIPHER_WEP104;
  243. bss->ssid.security_policy = SECURITY_STATIC_WEP;
  244. bss->wpa_group = cipher;
  245. bss->wpa_pairwise = cipher;
  246. bss->rsn_pairwise = cipher;
  247. } else {
  248. bss->ssid.security_policy = SECURITY_PLAINTEXT;
  249. bss->wpa_group = WPA_CIPHER_NONE;
  250. bss->wpa_pairwise = WPA_CIPHER_NONE;
  251. bss->rsn_pairwise = WPA_CIPHER_NONE;
  252. }
  253. if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
  254. (bss->wpa_group == WPA_CIPHER_CCMP ||
  255. bss->wpa_group == WPA_CIPHER_GCMP ||
  256. bss->wpa_group == WPA_CIPHER_CCMP_256 ||
  257. bss->wpa_group == WPA_CIPHER_GCMP_256)) {
  258. /*
  259. * Strong ciphers do not need frequent rekeying, so increase
  260. * the default GTK rekeying period to 24 hours.
  261. */
  262. bss->wpa_group_rekey = 86400;
  263. }
  264. #ifdef CONFIG_IEEE80211W
  265. if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT)
  266. bss->ieee80211w = ssid->ieee80211w;
  267. #endif /* CONFIG_IEEE80211W */
  268. #ifdef CONFIG_WPS
  269. /*
  270. * Enable WPS by default for open and WPA/WPA2-Personal network, but
  271. * require user interaction to actually use it. Only the internal
  272. * Registrar is supported.
  273. */
  274. if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
  275. bss->ssid.security_policy != SECURITY_PLAINTEXT)
  276. goto no_wps;
  277. #ifdef CONFIG_WPS2
  278. if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
  279. (!(bss->rsn_pairwise & WPA_CIPHER_CCMP) || !(bss->wpa & 2)))
  280. goto no_wps; /* WPS2 does not allow WPA/TKIP-only
  281. * configuration */
  282. #endif /* CONFIG_WPS2 */
  283. bss->eap_server = 1;
  284. if (!ssid->ignore_broadcast_ssid)
  285. bss->wps_state = 2;
  286. bss->ap_setup_locked = 2;
  287. if (wpa_s->conf->config_methods)
  288. bss->config_methods = os_strdup(wpa_s->conf->config_methods);
  289. os_memcpy(bss->device_type, wpa_s->conf->device_type,
  290. WPS_DEV_TYPE_LEN);
  291. if (wpa_s->conf->device_name) {
  292. bss->device_name = os_strdup(wpa_s->conf->device_name);
  293. bss->friendly_name = os_strdup(wpa_s->conf->device_name);
  294. }
  295. if (wpa_s->conf->manufacturer)
  296. bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
  297. if (wpa_s->conf->model_name)
  298. bss->model_name = os_strdup(wpa_s->conf->model_name);
  299. if (wpa_s->conf->model_number)
  300. bss->model_number = os_strdup(wpa_s->conf->model_number);
  301. if (wpa_s->conf->serial_number)
  302. bss->serial_number = os_strdup(wpa_s->conf->serial_number);
  303. if (is_nil_uuid(wpa_s->conf->uuid))
  304. os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
  305. else
  306. os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
  307. os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
  308. bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
  309. no_wps:
  310. #endif /* CONFIG_WPS */
  311. if (wpa_s->max_stations &&
  312. wpa_s->max_stations < wpa_s->conf->max_num_sta)
  313. bss->max_num_sta = wpa_s->max_stations;
  314. else
  315. bss->max_num_sta = wpa_s->conf->max_num_sta;
  316. bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
  317. if (wpa_s->conf->ap_vendor_elements) {
  318. bss->vendor_elements =
  319. wpabuf_dup(wpa_s->conf->ap_vendor_elements);
  320. }
  321. return 0;
  322. }
  323. static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
  324. {
  325. #ifdef CONFIG_P2P
  326. struct wpa_supplicant *wpa_s = ctx;
  327. const struct ieee80211_mgmt *mgmt;
  328. size_t hdr_len;
  329. mgmt = (const struct ieee80211_mgmt *) buf;
  330. hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
  331. if (hdr_len > len)
  332. return;
  333. if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
  334. return;
  335. wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
  336. mgmt->u.action.category,
  337. &mgmt->u.action.u.vs_public_action.action,
  338. len - hdr_len, freq);
  339. #endif /* CONFIG_P2P */
  340. }
  341. static void ap_wps_event_cb(void *ctx, enum wps_event event,
  342. union wps_event_data *data)
  343. {
  344. #ifdef CONFIG_P2P
  345. struct wpa_supplicant *wpa_s = ctx;
  346. if (event == WPS_EV_FAIL) {
  347. struct wps_event_fail *fail = &data->fail;
  348. if (wpa_s->parent && wpa_s->parent != wpa_s &&
  349. wpa_s == wpa_s->global->p2p_group_formation) {
  350. /*
  351. * src/ap/wps_hostapd.c has already sent this on the
  352. * main interface, so only send on the parent interface
  353. * here if needed.
  354. */
  355. wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
  356. "msg=%d config_error=%d",
  357. fail->msg, fail->config_error);
  358. }
  359. wpas_p2p_wps_failed(wpa_s, fail);
  360. }
  361. #endif /* CONFIG_P2P */
  362. }
  363. static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
  364. int authorized, const u8 *p2p_dev_addr)
  365. {
  366. wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
  367. }
  368. #ifdef CONFIG_P2P
  369. static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
  370. const u8 *psk, size_t psk_len)
  371. {
  372. struct wpa_supplicant *wpa_s = ctx;
  373. if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
  374. return;
  375. wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
  376. }
  377. #endif /* CONFIG_P2P */
  378. static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
  379. {
  380. #ifdef CONFIG_P2P
  381. struct wpa_supplicant *wpa_s = ctx;
  382. const struct ieee80211_mgmt *mgmt;
  383. size_t hdr_len;
  384. mgmt = (const struct ieee80211_mgmt *) buf;
  385. hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
  386. if (hdr_len > len)
  387. return -1;
  388. wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
  389. mgmt->u.action.category,
  390. &mgmt->u.action.u.vs_public_action.action,
  391. len - hdr_len, freq);
  392. #endif /* CONFIG_P2P */
  393. return 0;
  394. }
  395. static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
  396. const u8 *bssid, const u8 *ie, size_t ie_len,
  397. int ssi_signal)
  398. {
  399. #ifdef CONFIG_P2P
  400. struct wpa_supplicant *wpa_s = ctx;
  401. return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
  402. ssi_signal);
  403. #else /* CONFIG_P2P */
  404. return 0;
  405. #endif /* CONFIG_P2P */
  406. }
  407. static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
  408. const u8 *uuid_e)
  409. {
  410. #ifdef CONFIG_P2P
  411. struct wpa_supplicant *wpa_s = ctx;
  412. wpas_p2p_wps_success(wpa_s, mac_addr, 1);
  413. #endif /* CONFIG_P2P */
  414. }
  415. static void wpas_ap_configured_cb(void *ctx)
  416. {
  417. struct wpa_supplicant *wpa_s = ctx;
  418. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  419. if (wpa_s->ap_configured_cb)
  420. wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
  421. wpa_s->ap_configured_cb_data);
  422. }
  423. int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
  424. struct wpa_ssid *ssid)
  425. {
  426. struct wpa_driver_associate_params params;
  427. struct hostapd_iface *hapd_iface;
  428. struct hostapd_config *conf;
  429. size_t i;
  430. if (ssid->ssid == NULL || ssid->ssid_len == 0) {
  431. wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
  432. return -1;
  433. }
  434. wpa_supplicant_ap_deinit(wpa_s);
  435. wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
  436. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  437. os_memset(&params, 0, sizeof(params));
  438. params.ssid = ssid->ssid;
  439. params.ssid_len = ssid->ssid_len;
  440. switch (ssid->mode) {
  441. case WPAS_MODE_AP:
  442. case WPAS_MODE_P2P_GO:
  443. case WPAS_MODE_P2P_GROUP_FORMATION:
  444. params.mode = IEEE80211_MODE_AP;
  445. break;
  446. default:
  447. return -1;
  448. }
  449. if (ssid->frequency == 0)
  450. ssid->frequency = 2462; /* default channel 11 */
  451. params.freq = ssid->frequency;
  452. params.wpa_proto = ssid->proto;
  453. if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
  454. wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
  455. else
  456. wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
  457. params.key_mgmt_suite = wpa_s->key_mgmt;
  458. wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
  459. 1);
  460. if (wpa_s->pairwise_cipher < 0) {
  461. wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
  462. "cipher.");
  463. return -1;
  464. }
  465. params.pairwise_suite = wpa_s->pairwise_cipher;
  466. params.group_suite = params.pairwise_suite;
  467. #ifdef CONFIG_P2P
  468. if (ssid->mode == WPAS_MODE_P2P_GO ||
  469. ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  470. params.p2p = 1;
  471. #endif /* CONFIG_P2P */
  472. if (wpa_s->parent->set_ap_uapsd)
  473. params.uapsd = wpa_s->parent->ap_uapsd;
  474. else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
  475. params.uapsd = 1; /* mandatory for P2P GO */
  476. else
  477. params.uapsd = -1;
  478. if (wpa_drv_associate(wpa_s, &params) < 0) {
  479. wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
  480. return -1;
  481. }
  482. wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
  483. if (hapd_iface == NULL)
  484. return -1;
  485. hapd_iface->owner = wpa_s;
  486. hapd_iface->drv_flags = wpa_s->drv_flags;
  487. hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
  488. hapd_iface->extended_capa = wpa_s->extended_capa;
  489. hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
  490. hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
  491. wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
  492. if (conf == NULL) {
  493. wpa_supplicant_ap_deinit(wpa_s);
  494. return -1;
  495. }
  496. os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
  497. wpa_s->conf->wmm_ac_params,
  498. sizeof(wpa_s->conf->wmm_ac_params));
  499. if (params.uapsd > 0) {
  500. conf->bss[0]->wmm_enabled = 1;
  501. conf->bss[0]->wmm_uapsd = 1;
  502. }
  503. if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
  504. wpa_printf(MSG_ERROR, "Failed to create AP configuration");
  505. wpa_supplicant_ap_deinit(wpa_s);
  506. return -1;
  507. }
  508. #ifdef CONFIG_P2P
  509. if (ssid->mode == WPAS_MODE_P2P_GO)
  510. conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
  511. else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  512. conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
  513. P2P_GROUP_FORMATION;
  514. #endif /* CONFIG_P2P */
  515. hapd_iface->num_bss = conf->num_bss;
  516. hapd_iface->bss = os_calloc(conf->num_bss,
  517. sizeof(struct hostapd_data *));
  518. if (hapd_iface->bss == NULL) {
  519. wpa_supplicant_ap_deinit(wpa_s);
  520. return -1;
  521. }
  522. for (i = 0; i < conf->num_bss; i++) {
  523. hapd_iface->bss[i] =
  524. hostapd_alloc_bss_data(hapd_iface, conf,
  525. conf->bss[i]);
  526. if (hapd_iface->bss[i] == NULL) {
  527. wpa_supplicant_ap_deinit(wpa_s);
  528. return -1;
  529. }
  530. hapd_iface->bss[i]->msg_ctx = wpa_s;
  531. hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent;
  532. hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
  533. hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
  534. hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
  535. hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
  536. hostapd_register_probereq_cb(hapd_iface->bss[i],
  537. ap_probe_req_rx, wpa_s);
  538. hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
  539. hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
  540. hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
  541. hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
  542. hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
  543. hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
  544. #ifdef CONFIG_P2P
  545. hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
  546. hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
  547. hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
  548. hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
  549. ssid);
  550. #endif /* CONFIG_P2P */
  551. hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
  552. hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
  553. }
  554. os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
  555. hapd_iface->bss[0]->driver = wpa_s->driver;
  556. hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
  557. wpa_s->current_ssid = ssid;
  558. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  559. os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
  560. wpa_s->assoc_freq = ssid->frequency;
  561. if (hostapd_setup_interface(wpa_s->ap_iface)) {
  562. wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
  563. wpa_supplicant_ap_deinit(wpa_s);
  564. return -1;
  565. }
  566. return 0;
  567. }
  568. void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
  569. {
  570. #ifdef CONFIG_WPS
  571. eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
  572. #endif /* CONFIG_WPS */
  573. if (wpa_s->ap_iface == NULL)
  574. return;
  575. wpa_s->current_ssid = NULL;
  576. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  577. wpa_s->assoc_freq = 0;
  578. #ifdef CONFIG_P2P
  579. if (wpa_s->ap_iface->bss)
  580. wpa_s->ap_iface->bss[0]->p2p_group = NULL;
  581. wpas_p2p_group_deinit(wpa_s);
  582. #endif /* CONFIG_P2P */
  583. wpa_s->ap_iface->driver_ap_teardown =
  584. !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
  585. hostapd_interface_deinit(wpa_s->ap_iface);
  586. hostapd_interface_free(wpa_s->ap_iface);
  587. wpa_s->ap_iface = NULL;
  588. wpa_drv_deinit_ap(wpa_s);
  589. }
  590. void ap_tx_status(void *ctx, const u8 *addr,
  591. const u8 *buf, size_t len, int ack)
  592. {
  593. #ifdef NEED_AP_MLME
  594. struct wpa_supplicant *wpa_s = ctx;
  595. hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
  596. #endif /* NEED_AP_MLME */
  597. }
  598. void ap_eapol_tx_status(void *ctx, const u8 *dst,
  599. const u8 *data, size_t len, int ack)
  600. {
  601. #ifdef NEED_AP_MLME
  602. struct wpa_supplicant *wpa_s = ctx;
  603. if (!wpa_s->ap_iface)
  604. return;
  605. hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
  606. #endif /* NEED_AP_MLME */
  607. }
  608. void ap_client_poll_ok(void *ctx, const u8 *addr)
  609. {
  610. #ifdef NEED_AP_MLME
  611. struct wpa_supplicant *wpa_s = ctx;
  612. if (wpa_s->ap_iface)
  613. hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
  614. #endif /* NEED_AP_MLME */
  615. }
  616. void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
  617. {
  618. #ifdef NEED_AP_MLME
  619. struct wpa_supplicant *wpa_s = ctx;
  620. ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
  621. #endif /* NEED_AP_MLME */
  622. }
  623. void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
  624. {
  625. #ifdef NEED_AP_MLME
  626. struct wpa_supplicant *wpa_s = ctx;
  627. struct hostapd_frame_info fi;
  628. os_memset(&fi, 0, sizeof(fi));
  629. fi.datarate = rx_mgmt->datarate;
  630. fi.ssi_signal = rx_mgmt->ssi_signal;
  631. ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
  632. rx_mgmt->frame_len, &fi);
  633. #endif /* NEED_AP_MLME */
  634. }
  635. void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
  636. {
  637. #ifdef NEED_AP_MLME
  638. struct wpa_supplicant *wpa_s = ctx;
  639. ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
  640. #endif /* NEED_AP_MLME */
  641. }
  642. void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
  643. const u8 *src_addr, const u8 *buf, size_t len)
  644. {
  645. ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
  646. }
  647. #ifdef CONFIG_WPS
  648. int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
  649. const u8 *p2p_dev_addr)
  650. {
  651. if (!wpa_s->ap_iface)
  652. return -1;
  653. return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
  654. p2p_dev_addr);
  655. }
  656. int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
  657. {
  658. struct wps_registrar *reg;
  659. int reg_sel = 0, wps_sta = 0;
  660. if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
  661. return -1;
  662. reg = wpa_s->ap_iface->bss[0]->wps->registrar;
  663. reg_sel = wps_registrar_wps_cancel(reg);
  664. wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
  665. ap_sta_wps_cancel, NULL);
  666. if (!reg_sel && !wps_sta) {
  667. wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
  668. "time");
  669. return -1;
  670. }
  671. /*
  672. * There are 2 cases to return wps cancel as success:
  673. * 1. When wps cancel was initiated but no connection has been
  674. * established with client yet.
  675. * 2. Client is in the middle of exchanging WPS messages.
  676. */
  677. return 0;
  678. }
  679. int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
  680. const char *pin, char *buf, size_t buflen,
  681. int timeout)
  682. {
  683. int ret, ret_len = 0;
  684. if (!wpa_s->ap_iface)
  685. return -1;
  686. if (pin == NULL) {
  687. unsigned int rpin = wps_generate_pin();
  688. ret_len = os_snprintf(buf, buflen, "%08d", rpin);
  689. pin = buf;
  690. } else
  691. ret_len = os_snprintf(buf, buflen, "%s", pin);
  692. ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
  693. timeout);
  694. if (ret)
  695. return -1;
  696. return ret_len;
  697. }
  698. static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
  699. {
  700. struct wpa_supplicant *wpa_s = eloop_data;
  701. wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
  702. wpas_wps_ap_pin_disable(wpa_s);
  703. }
  704. static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
  705. {
  706. struct hostapd_data *hapd;
  707. if (wpa_s->ap_iface == NULL)
  708. return;
  709. hapd = wpa_s->ap_iface->bss[0];
  710. wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
  711. hapd->ap_pin_failures = 0;
  712. eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
  713. if (timeout > 0)
  714. eloop_register_timeout(timeout, 0,
  715. wpas_wps_ap_pin_timeout, wpa_s, NULL);
  716. }
  717. void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
  718. {
  719. struct hostapd_data *hapd;
  720. if (wpa_s->ap_iface == NULL)
  721. return;
  722. wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
  723. hapd = wpa_s->ap_iface->bss[0];
  724. os_free(hapd->conf->ap_pin);
  725. hapd->conf->ap_pin = NULL;
  726. eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
  727. }
  728. const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
  729. {
  730. struct hostapd_data *hapd;
  731. unsigned int pin;
  732. char pin_txt[9];
  733. if (wpa_s->ap_iface == NULL)
  734. return NULL;
  735. hapd = wpa_s->ap_iface->bss[0];
  736. pin = wps_generate_pin();
  737. os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
  738. os_free(hapd->conf->ap_pin);
  739. hapd->conf->ap_pin = os_strdup(pin_txt);
  740. if (hapd->conf->ap_pin == NULL)
  741. return NULL;
  742. wpas_wps_ap_pin_enable(wpa_s, timeout);
  743. return hapd->conf->ap_pin;
  744. }
  745. const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
  746. {
  747. struct hostapd_data *hapd;
  748. if (wpa_s->ap_iface == NULL)
  749. return NULL;
  750. hapd = wpa_s->ap_iface->bss[0];
  751. return hapd->conf->ap_pin;
  752. }
  753. int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
  754. int timeout)
  755. {
  756. struct hostapd_data *hapd;
  757. char pin_txt[9];
  758. int ret;
  759. if (wpa_s->ap_iface == NULL)
  760. return -1;
  761. hapd = wpa_s->ap_iface->bss[0];
  762. ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
  763. if (ret < 0 || ret >= (int) sizeof(pin_txt))
  764. return -1;
  765. os_free(hapd->conf->ap_pin);
  766. hapd->conf->ap_pin = os_strdup(pin_txt);
  767. if (hapd->conf->ap_pin == NULL)
  768. return -1;
  769. wpas_wps_ap_pin_enable(wpa_s, timeout);
  770. return 0;
  771. }
  772. void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
  773. {
  774. struct hostapd_data *hapd;
  775. if (wpa_s->ap_iface == NULL)
  776. return;
  777. hapd = wpa_s->ap_iface->bss[0];
  778. /*
  779. * Registrar failed to prove its knowledge of the AP PIN. Disable AP
  780. * PIN if this happens multiple times to slow down brute force attacks.
  781. */
  782. hapd->ap_pin_failures++;
  783. wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
  784. hapd->ap_pin_failures);
  785. if (hapd->ap_pin_failures < 3)
  786. return;
  787. wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
  788. hapd->ap_pin_failures = 0;
  789. os_free(hapd->conf->ap_pin);
  790. hapd->conf->ap_pin = NULL;
  791. }
  792. #ifdef CONFIG_WPS_NFC
  793. struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
  794. int ndef)
  795. {
  796. struct hostapd_data *hapd;
  797. if (wpa_s->ap_iface == NULL)
  798. return NULL;
  799. hapd = wpa_s->ap_iface->bss[0];
  800. return hostapd_wps_nfc_config_token(hapd, ndef);
  801. }
  802. struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
  803. int ndef)
  804. {
  805. struct hostapd_data *hapd;
  806. if (wpa_s->ap_iface == NULL)
  807. return NULL;
  808. hapd = wpa_s->ap_iface->bss[0];
  809. return hostapd_wps_nfc_hs_cr(hapd, ndef);
  810. }
  811. int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
  812. const struct wpabuf *req,
  813. const struct wpabuf *sel)
  814. {
  815. struct hostapd_data *hapd;
  816. if (wpa_s->ap_iface == NULL)
  817. return -1;
  818. hapd = wpa_s->ap_iface->bss[0];
  819. return hostapd_wps_nfc_report_handover(hapd, req, sel);
  820. }
  821. #endif /* CONFIG_WPS_NFC */
  822. #endif /* CONFIG_WPS */
  823. #ifdef CONFIG_CTRL_IFACE
  824. int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
  825. char *buf, size_t buflen)
  826. {
  827. if (wpa_s->ap_iface == NULL)
  828. return -1;
  829. return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
  830. buf, buflen);
  831. }
  832. int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
  833. char *buf, size_t buflen)
  834. {
  835. if (wpa_s->ap_iface == NULL)
  836. return -1;
  837. return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
  838. buf, buflen);
  839. }
  840. int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
  841. char *buf, size_t buflen)
  842. {
  843. if (wpa_s->ap_iface == NULL)
  844. return -1;
  845. return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
  846. buf, buflen);
  847. }
  848. int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
  849. const char *txtaddr)
  850. {
  851. if (wpa_s->ap_iface == NULL)
  852. return -1;
  853. return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
  854. txtaddr);
  855. }
  856. int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
  857. const char *txtaddr)
  858. {
  859. if (wpa_s->ap_iface == NULL)
  860. return -1;
  861. return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
  862. txtaddr);
  863. }
  864. int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
  865. size_t buflen, int verbose)
  866. {
  867. char *pos = buf, *end = buf + buflen;
  868. int ret;
  869. struct hostapd_bss_config *conf;
  870. if (wpa_s->ap_iface == NULL)
  871. return -1;
  872. conf = wpa_s->ap_iface->bss[0]->conf;
  873. if (conf->wpa == 0)
  874. return 0;
  875. ret = os_snprintf(pos, end - pos,
  876. "pairwise_cipher=%s\n"
  877. "group_cipher=%s\n"
  878. "key_mgmt=%s\n",
  879. wpa_cipher_txt(conf->rsn_pairwise),
  880. wpa_cipher_txt(conf->wpa_group),
  881. wpa_key_mgmt_txt(conf->wpa_key_mgmt,
  882. conf->wpa));
  883. if (ret < 0 || ret >= end - pos)
  884. return pos - buf;
  885. pos += ret;
  886. return pos - buf;
  887. }
  888. #endif /* CONFIG_CTRL_IFACE */
  889. int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
  890. {
  891. struct hostapd_iface *iface = wpa_s->ap_iface;
  892. struct wpa_ssid *ssid = wpa_s->current_ssid;
  893. struct hostapd_data *hapd;
  894. if (ssid == NULL || wpa_s->ap_iface == NULL ||
  895. ssid->mode == WPAS_MODE_INFRA ||
  896. ssid->mode == WPAS_MODE_IBSS)
  897. return -1;
  898. #ifdef CONFIG_P2P
  899. if (ssid->mode == WPAS_MODE_P2P_GO)
  900. iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
  901. else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  902. iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
  903. P2P_GROUP_FORMATION;
  904. #endif /* CONFIG_P2P */
  905. hapd = iface->bss[0];
  906. if (hapd->drv_priv == NULL)
  907. return -1;
  908. ieee802_11_set_beacons(iface);
  909. hostapd_set_ap_wps_ie(hapd);
  910. return 0;
  911. }
  912. int ap_switch_channel(struct wpa_supplicant *wpa_s,
  913. struct csa_settings *settings)
  914. {
  915. #ifdef NEED_AP_MLME
  916. if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
  917. return -1;
  918. return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
  919. #else /* NEED_AP_MLME */
  920. return -1;
  921. #endif /* NEED_AP_MLME */
  922. }
  923. int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
  924. {
  925. struct csa_settings settings;
  926. int ret = hostapd_parse_csa_settings(pos, &settings);
  927. if (ret)
  928. return ret;
  929. return ap_switch_channel(wpa_s, &settings);
  930. }
  931. void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
  932. int offset, int width, int cf1, int cf2)
  933. {
  934. if (!wpa_s->ap_iface)
  935. return;
  936. wpa_s->assoc_freq = freq;
  937. hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht, offset, width, cf1, cf1);
  938. }
  939. int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
  940. const u8 *addr)
  941. {
  942. struct hostapd_data *hapd;
  943. struct hostapd_bss_config *conf;
  944. if (!wpa_s->ap_iface)
  945. return -1;
  946. if (addr)
  947. wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
  948. MAC2STR(addr));
  949. else
  950. wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
  951. hapd = wpa_s->ap_iface->bss[0];
  952. conf = hapd->conf;
  953. os_free(conf->accept_mac);
  954. conf->accept_mac = NULL;
  955. conf->num_accept_mac = 0;
  956. os_free(conf->deny_mac);
  957. conf->deny_mac = NULL;
  958. conf->num_deny_mac = 0;
  959. if (addr == NULL) {
  960. conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
  961. return 0;
  962. }
  963. conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
  964. conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
  965. if (conf->accept_mac == NULL)
  966. return -1;
  967. os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
  968. conf->num_accept_mac = 1;
  969. return 0;
  970. }
  971. #ifdef CONFIG_WPS_NFC
  972. int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
  973. const struct wpabuf *pw, const u8 *pubkey_hash)
  974. {
  975. struct hostapd_data *hapd;
  976. struct wps_context *wps;
  977. if (!wpa_s->ap_iface)
  978. return -1;
  979. hapd = wpa_s->ap_iface->bss[0];
  980. wps = hapd->wps;
  981. if (wpa_s->parent->conf->wps_nfc_dh_pubkey == NULL ||
  982. wpa_s->parent->conf->wps_nfc_dh_privkey == NULL) {
  983. wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
  984. return -1;
  985. }
  986. dh5_free(wps->dh_ctx);
  987. wpabuf_free(wps->dh_pubkey);
  988. wpabuf_free(wps->dh_privkey);
  989. wps->dh_privkey = wpabuf_dup(
  990. wpa_s->parent->conf->wps_nfc_dh_privkey);
  991. wps->dh_pubkey = wpabuf_dup(
  992. wpa_s->parent->conf->wps_nfc_dh_pubkey);
  993. if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
  994. wps->dh_ctx = NULL;
  995. wpabuf_free(wps->dh_pubkey);
  996. wps->dh_pubkey = NULL;
  997. wpabuf_free(wps->dh_privkey);
  998. wps->dh_privkey = NULL;
  999. return -1;
  1000. }
  1001. wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
  1002. if (wps->dh_ctx == NULL)
  1003. return -1;
  1004. return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
  1005. pw_id,
  1006. pw ? wpabuf_head(pw) : NULL,
  1007. pw ? wpabuf_len(pw) : 0, 1);
  1008. }
  1009. #endif /* CONFIG_WPS_NFC */