ap.c 31 KB

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