ap.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  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_WPS
  265. /*
  266. * Enable WPS by default for open and WPA/WPA2-Personal network, but
  267. * require user interaction to actually use it. Only the internal
  268. * Registrar is supported.
  269. */
  270. if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
  271. bss->ssid.security_policy != SECURITY_PLAINTEXT)
  272. goto no_wps;
  273. #ifdef CONFIG_WPS2
  274. if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
  275. (!(bss->rsn_pairwise & WPA_CIPHER_CCMP) || !(bss->wpa & 2)))
  276. goto no_wps; /* WPS2 does not allow WPA/TKIP-only
  277. * configuration */
  278. #endif /* CONFIG_WPS2 */
  279. bss->eap_server = 1;
  280. if (!ssid->ignore_broadcast_ssid)
  281. bss->wps_state = 2;
  282. bss->ap_setup_locked = 2;
  283. if (wpa_s->conf->config_methods)
  284. bss->config_methods = os_strdup(wpa_s->conf->config_methods);
  285. os_memcpy(bss->device_type, wpa_s->conf->device_type,
  286. WPS_DEV_TYPE_LEN);
  287. if (wpa_s->conf->device_name) {
  288. bss->device_name = os_strdup(wpa_s->conf->device_name);
  289. bss->friendly_name = os_strdup(wpa_s->conf->device_name);
  290. }
  291. if (wpa_s->conf->manufacturer)
  292. bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
  293. if (wpa_s->conf->model_name)
  294. bss->model_name = os_strdup(wpa_s->conf->model_name);
  295. if (wpa_s->conf->model_number)
  296. bss->model_number = os_strdup(wpa_s->conf->model_number);
  297. if (wpa_s->conf->serial_number)
  298. bss->serial_number = os_strdup(wpa_s->conf->serial_number);
  299. if (is_nil_uuid(wpa_s->conf->uuid))
  300. os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
  301. else
  302. os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
  303. os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
  304. bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
  305. no_wps:
  306. #endif /* CONFIG_WPS */
  307. if (wpa_s->max_stations &&
  308. wpa_s->max_stations < wpa_s->conf->max_num_sta)
  309. bss->max_num_sta = wpa_s->max_stations;
  310. else
  311. bss->max_num_sta = wpa_s->conf->max_num_sta;
  312. bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
  313. if (wpa_s->conf->ap_vendor_elements) {
  314. bss->vendor_elements =
  315. wpabuf_dup(wpa_s->conf->ap_vendor_elements);
  316. }
  317. return 0;
  318. }
  319. static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
  320. {
  321. #ifdef CONFIG_P2P
  322. struct wpa_supplicant *wpa_s = ctx;
  323. const struct ieee80211_mgmt *mgmt;
  324. size_t hdr_len;
  325. mgmt = (const struct ieee80211_mgmt *) buf;
  326. hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
  327. if (hdr_len > len)
  328. return;
  329. if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
  330. return;
  331. wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
  332. mgmt->u.action.category,
  333. &mgmt->u.action.u.vs_public_action.action,
  334. len - hdr_len, freq);
  335. #endif /* CONFIG_P2P */
  336. }
  337. static void ap_wps_event_cb(void *ctx, enum wps_event event,
  338. union wps_event_data *data)
  339. {
  340. #ifdef CONFIG_P2P
  341. struct wpa_supplicant *wpa_s = ctx;
  342. if (event == WPS_EV_FAIL) {
  343. struct wps_event_fail *fail = &data->fail;
  344. if (wpa_s->parent && wpa_s->parent != wpa_s &&
  345. wpa_s == wpa_s->global->p2p_group_formation) {
  346. /*
  347. * src/ap/wps_hostapd.c has already sent this on the
  348. * main interface, so only send on the parent interface
  349. * here if needed.
  350. */
  351. wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
  352. "msg=%d config_error=%d",
  353. fail->msg, fail->config_error);
  354. }
  355. wpas_p2p_wps_failed(wpa_s, fail);
  356. }
  357. #endif /* CONFIG_P2P */
  358. }
  359. static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
  360. int authorized, const u8 *p2p_dev_addr)
  361. {
  362. wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
  363. }
  364. #ifdef CONFIG_P2P
  365. static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
  366. const u8 *psk, size_t psk_len)
  367. {
  368. struct wpa_supplicant *wpa_s = ctx;
  369. if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
  370. return;
  371. wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
  372. }
  373. #endif /* CONFIG_P2P */
  374. static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
  375. {
  376. #ifdef CONFIG_P2P
  377. struct wpa_supplicant *wpa_s = ctx;
  378. const struct ieee80211_mgmt *mgmt;
  379. size_t hdr_len;
  380. mgmt = (const struct ieee80211_mgmt *) buf;
  381. hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
  382. if (hdr_len > len)
  383. return -1;
  384. wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
  385. mgmt->u.action.category,
  386. &mgmt->u.action.u.vs_public_action.action,
  387. len - hdr_len, freq);
  388. #endif /* CONFIG_P2P */
  389. return 0;
  390. }
  391. static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
  392. const u8 *bssid, const u8 *ie, size_t ie_len,
  393. int ssi_signal)
  394. {
  395. #ifdef CONFIG_P2P
  396. struct wpa_supplicant *wpa_s = ctx;
  397. return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
  398. ssi_signal);
  399. #else /* CONFIG_P2P */
  400. return 0;
  401. #endif /* CONFIG_P2P */
  402. }
  403. static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
  404. const u8 *uuid_e)
  405. {
  406. #ifdef CONFIG_P2P
  407. struct wpa_supplicant *wpa_s = ctx;
  408. wpas_p2p_wps_success(wpa_s, mac_addr, 1);
  409. #endif /* CONFIG_P2P */
  410. }
  411. static void wpas_ap_configured_cb(void *ctx)
  412. {
  413. struct wpa_supplicant *wpa_s = ctx;
  414. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  415. if (wpa_s->ap_configured_cb)
  416. wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
  417. wpa_s->ap_configured_cb_data);
  418. }
  419. int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
  420. struct wpa_ssid *ssid)
  421. {
  422. struct wpa_driver_associate_params params;
  423. struct hostapd_iface *hapd_iface;
  424. struct hostapd_config *conf;
  425. size_t i;
  426. if (ssid->ssid == NULL || ssid->ssid_len == 0) {
  427. wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
  428. return -1;
  429. }
  430. wpa_supplicant_ap_deinit(wpa_s);
  431. wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
  432. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  433. os_memset(&params, 0, sizeof(params));
  434. params.ssid = ssid->ssid;
  435. params.ssid_len = ssid->ssid_len;
  436. switch (ssid->mode) {
  437. case WPAS_MODE_AP:
  438. case WPAS_MODE_P2P_GO:
  439. case WPAS_MODE_P2P_GROUP_FORMATION:
  440. params.mode = IEEE80211_MODE_AP;
  441. break;
  442. default:
  443. return -1;
  444. }
  445. if (ssid->frequency == 0)
  446. ssid->frequency = 2462; /* default channel 11 */
  447. params.freq = ssid->frequency;
  448. params.wpa_proto = ssid->proto;
  449. if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
  450. wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
  451. else
  452. wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
  453. params.key_mgmt_suite = wpa_s->key_mgmt;
  454. wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
  455. 1);
  456. if (wpa_s->pairwise_cipher < 0) {
  457. wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
  458. "cipher.");
  459. return -1;
  460. }
  461. params.pairwise_suite = wpa_s->pairwise_cipher;
  462. params.group_suite = params.pairwise_suite;
  463. #ifdef CONFIG_P2P
  464. if (ssid->mode == WPAS_MODE_P2P_GO ||
  465. ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  466. params.p2p = 1;
  467. #endif /* CONFIG_P2P */
  468. if (wpa_s->parent->set_ap_uapsd)
  469. params.uapsd = wpa_s->parent->ap_uapsd;
  470. else
  471. params.uapsd = -1;
  472. if (wpa_drv_associate(wpa_s, &params) < 0) {
  473. wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
  474. return -1;
  475. }
  476. wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
  477. if (hapd_iface == NULL)
  478. return -1;
  479. hapd_iface->owner = wpa_s;
  480. hapd_iface->drv_flags = wpa_s->drv_flags;
  481. hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
  482. hapd_iface->extended_capa = wpa_s->extended_capa;
  483. hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
  484. hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
  485. wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
  486. if (conf == NULL) {
  487. wpa_supplicant_ap_deinit(wpa_s);
  488. return -1;
  489. }
  490. os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
  491. wpa_s->conf->wmm_ac_params,
  492. sizeof(wpa_s->conf->wmm_ac_params));
  493. if (params.uapsd > 0) {
  494. conf->bss[0]->wmm_enabled = 1;
  495. conf->bss[0]->wmm_uapsd = 1;
  496. }
  497. if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
  498. wpa_printf(MSG_ERROR, "Failed to create AP configuration");
  499. wpa_supplicant_ap_deinit(wpa_s);
  500. return -1;
  501. }
  502. #ifdef CONFIG_P2P
  503. if (ssid->mode == WPAS_MODE_P2P_GO)
  504. conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
  505. else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  506. conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
  507. P2P_GROUP_FORMATION;
  508. #endif /* CONFIG_P2P */
  509. hapd_iface->num_bss = conf->num_bss;
  510. hapd_iface->bss = os_calloc(conf->num_bss,
  511. sizeof(struct hostapd_data *));
  512. if (hapd_iface->bss == NULL) {
  513. wpa_supplicant_ap_deinit(wpa_s);
  514. return -1;
  515. }
  516. for (i = 0; i < conf->num_bss; i++) {
  517. hapd_iface->bss[i] =
  518. hostapd_alloc_bss_data(hapd_iface, conf,
  519. conf->bss[i]);
  520. if (hapd_iface->bss[i] == NULL) {
  521. wpa_supplicant_ap_deinit(wpa_s);
  522. return -1;
  523. }
  524. hapd_iface->bss[i]->msg_ctx = wpa_s;
  525. hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent;
  526. hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
  527. hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
  528. hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
  529. hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
  530. hostapd_register_probereq_cb(hapd_iface->bss[i],
  531. ap_probe_req_rx, wpa_s);
  532. hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
  533. hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
  534. hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
  535. hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
  536. hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
  537. hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
  538. #ifdef CONFIG_P2P
  539. hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
  540. hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
  541. hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
  542. hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
  543. ssid);
  544. #endif /* CONFIG_P2P */
  545. hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
  546. hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
  547. }
  548. os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
  549. hapd_iface->bss[0]->driver = wpa_s->driver;
  550. hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
  551. wpa_s->current_ssid = ssid;
  552. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  553. os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
  554. wpa_s->assoc_freq = ssid->frequency;
  555. if (hostapd_setup_interface(wpa_s->ap_iface)) {
  556. wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
  557. wpa_supplicant_ap_deinit(wpa_s);
  558. return -1;
  559. }
  560. return 0;
  561. }
  562. void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
  563. {
  564. #ifdef CONFIG_WPS
  565. eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
  566. #endif /* CONFIG_WPS */
  567. if (wpa_s->ap_iface == NULL)
  568. return;
  569. wpa_s->current_ssid = NULL;
  570. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  571. wpa_s->assoc_freq = 0;
  572. #ifdef CONFIG_P2P
  573. if (wpa_s->ap_iface->bss)
  574. wpa_s->ap_iface->bss[0]->p2p_group = NULL;
  575. wpas_p2p_group_deinit(wpa_s);
  576. #endif /* CONFIG_P2P */
  577. hostapd_interface_deinit(wpa_s->ap_iface);
  578. hostapd_interface_free(wpa_s->ap_iface);
  579. wpa_s->ap_iface = NULL;
  580. wpa_drv_deinit_ap(wpa_s);
  581. }
  582. void ap_tx_status(void *ctx, const u8 *addr,
  583. const u8 *buf, size_t len, int ack)
  584. {
  585. #ifdef NEED_AP_MLME
  586. struct wpa_supplicant *wpa_s = ctx;
  587. hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
  588. #endif /* NEED_AP_MLME */
  589. }
  590. void ap_eapol_tx_status(void *ctx, const u8 *dst,
  591. const u8 *data, size_t len, int ack)
  592. {
  593. #ifdef NEED_AP_MLME
  594. struct wpa_supplicant *wpa_s = ctx;
  595. if (!wpa_s->ap_iface)
  596. return;
  597. hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
  598. #endif /* NEED_AP_MLME */
  599. }
  600. void ap_client_poll_ok(void *ctx, const u8 *addr)
  601. {
  602. #ifdef NEED_AP_MLME
  603. struct wpa_supplicant *wpa_s = ctx;
  604. if (wpa_s->ap_iface)
  605. hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
  606. #endif /* NEED_AP_MLME */
  607. }
  608. void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
  609. {
  610. #ifdef NEED_AP_MLME
  611. struct wpa_supplicant *wpa_s = ctx;
  612. ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
  613. #endif /* NEED_AP_MLME */
  614. }
  615. void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
  616. {
  617. #ifdef NEED_AP_MLME
  618. struct wpa_supplicant *wpa_s = ctx;
  619. struct hostapd_frame_info fi;
  620. os_memset(&fi, 0, sizeof(fi));
  621. fi.datarate = rx_mgmt->datarate;
  622. fi.ssi_signal = rx_mgmt->ssi_signal;
  623. ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
  624. rx_mgmt->frame_len, &fi);
  625. #endif /* NEED_AP_MLME */
  626. }
  627. void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
  628. {
  629. #ifdef NEED_AP_MLME
  630. struct wpa_supplicant *wpa_s = ctx;
  631. ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
  632. #endif /* NEED_AP_MLME */
  633. }
  634. void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
  635. const u8 *src_addr, const u8 *buf, size_t len)
  636. {
  637. ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
  638. }
  639. #ifdef CONFIG_WPS
  640. int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
  641. const u8 *p2p_dev_addr)
  642. {
  643. if (!wpa_s->ap_iface)
  644. return -1;
  645. return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
  646. p2p_dev_addr);
  647. }
  648. int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
  649. {
  650. struct wps_registrar *reg;
  651. int reg_sel = 0, wps_sta = 0;
  652. if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
  653. return -1;
  654. reg = wpa_s->ap_iface->bss[0]->wps->registrar;
  655. reg_sel = wps_registrar_wps_cancel(reg);
  656. wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
  657. ap_sta_wps_cancel, NULL);
  658. if (!reg_sel && !wps_sta) {
  659. wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
  660. "time");
  661. return -1;
  662. }
  663. /*
  664. * There are 2 cases to return wps cancel as success:
  665. * 1. When wps cancel was initiated but no connection has been
  666. * established with client yet.
  667. * 2. Client is in the middle of exchanging WPS messages.
  668. */
  669. return 0;
  670. }
  671. int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
  672. const char *pin, char *buf, size_t buflen,
  673. int timeout)
  674. {
  675. int ret, ret_len = 0;
  676. if (!wpa_s->ap_iface)
  677. return -1;
  678. if (pin == NULL) {
  679. unsigned int rpin = wps_generate_pin();
  680. ret_len = os_snprintf(buf, buflen, "%08d", rpin);
  681. pin = buf;
  682. } else
  683. ret_len = os_snprintf(buf, buflen, "%s", pin);
  684. ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
  685. timeout);
  686. if (ret)
  687. return -1;
  688. return ret_len;
  689. }
  690. static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
  691. {
  692. struct wpa_supplicant *wpa_s = eloop_data;
  693. wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
  694. wpas_wps_ap_pin_disable(wpa_s);
  695. }
  696. static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
  697. {
  698. struct hostapd_data *hapd;
  699. if (wpa_s->ap_iface == NULL)
  700. return;
  701. hapd = wpa_s->ap_iface->bss[0];
  702. wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
  703. hapd->ap_pin_failures = 0;
  704. eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
  705. if (timeout > 0)
  706. eloop_register_timeout(timeout, 0,
  707. wpas_wps_ap_pin_timeout, wpa_s, NULL);
  708. }
  709. void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
  710. {
  711. struct hostapd_data *hapd;
  712. if (wpa_s->ap_iface == NULL)
  713. return;
  714. wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
  715. hapd = wpa_s->ap_iface->bss[0];
  716. os_free(hapd->conf->ap_pin);
  717. hapd->conf->ap_pin = NULL;
  718. eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
  719. }
  720. const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
  721. {
  722. struct hostapd_data *hapd;
  723. unsigned int pin;
  724. char pin_txt[9];
  725. if (wpa_s->ap_iface == NULL)
  726. return NULL;
  727. hapd = wpa_s->ap_iface->bss[0];
  728. pin = wps_generate_pin();
  729. os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
  730. os_free(hapd->conf->ap_pin);
  731. hapd->conf->ap_pin = os_strdup(pin_txt);
  732. if (hapd->conf->ap_pin == NULL)
  733. return NULL;
  734. wpas_wps_ap_pin_enable(wpa_s, timeout);
  735. return hapd->conf->ap_pin;
  736. }
  737. const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
  738. {
  739. struct hostapd_data *hapd;
  740. if (wpa_s->ap_iface == NULL)
  741. return NULL;
  742. hapd = wpa_s->ap_iface->bss[0];
  743. return hapd->conf->ap_pin;
  744. }
  745. int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
  746. int timeout)
  747. {
  748. struct hostapd_data *hapd;
  749. char pin_txt[9];
  750. int ret;
  751. if (wpa_s->ap_iface == NULL)
  752. return -1;
  753. hapd = wpa_s->ap_iface->bss[0];
  754. ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
  755. if (ret < 0 || ret >= (int) sizeof(pin_txt))
  756. return -1;
  757. os_free(hapd->conf->ap_pin);
  758. hapd->conf->ap_pin = os_strdup(pin_txt);
  759. if (hapd->conf->ap_pin == NULL)
  760. return -1;
  761. wpas_wps_ap_pin_enable(wpa_s, timeout);
  762. return 0;
  763. }
  764. void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
  765. {
  766. struct hostapd_data *hapd;
  767. if (wpa_s->ap_iface == NULL)
  768. return;
  769. hapd = wpa_s->ap_iface->bss[0];
  770. /*
  771. * Registrar failed to prove its knowledge of the AP PIN. Disable AP
  772. * PIN if this happens multiple times to slow down brute force attacks.
  773. */
  774. hapd->ap_pin_failures++;
  775. wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
  776. hapd->ap_pin_failures);
  777. if (hapd->ap_pin_failures < 3)
  778. return;
  779. wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
  780. hapd->ap_pin_failures = 0;
  781. os_free(hapd->conf->ap_pin);
  782. hapd->conf->ap_pin = NULL;
  783. }
  784. #ifdef CONFIG_WPS_NFC
  785. struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
  786. int ndef)
  787. {
  788. struct hostapd_data *hapd;
  789. if (wpa_s->ap_iface == NULL)
  790. return NULL;
  791. hapd = wpa_s->ap_iface->bss[0];
  792. return hostapd_wps_nfc_config_token(hapd, ndef);
  793. }
  794. struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
  795. int ndef)
  796. {
  797. struct hostapd_data *hapd;
  798. if (wpa_s->ap_iface == NULL)
  799. return NULL;
  800. hapd = wpa_s->ap_iface->bss[0];
  801. return hostapd_wps_nfc_hs_cr(hapd, ndef);
  802. }
  803. int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
  804. const struct wpabuf *req,
  805. const struct wpabuf *sel)
  806. {
  807. struct hostapd_data *hapd;
  808. if (wpa_s->ap_iface == NULL)
  809. return -1;
  810. hapd = wpa_s->ap_iface->bss[0];
  811. return hostapd_wps_nfc_report_handover(hapd, req, sel);
  812. }
  813. #endif /* CONFIG_WPS_NFC */
  814. #endif /* CONFIG_WPS */
  815. #ifdef CONFIG_CTRL_IFACE
  816. int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
  817. char *buf, size_t buflen)
  818. {
  819. if (wpa_s->ap_iface == NULL)
  820. return -1;
  821. return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
  822. buf, buflen);
  823. }
  824. int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
  825. char *buf, size_t buflen)
  826. {
  827. if (wpa_s->ap_iface == NULL)
  828. return -1;
  829. return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
  830. buf, buflen);
  831. }
  832. int ap_ctrl_iface_sta_next(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_next(wpa_s->ap_iface->bss[0], txtaddr,
  838. buf, buflen);
  839. }
  840. int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
  841. const char *txtaddr)
  842. {
  843. if (wpa_s->ap_iface == NULL)
  844. return -1;
  845. return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
  846. txtaddr);
  847. }
  848. int ap_ctrl_iface_sta_deauthenticate(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_deauthenticate(wpa_s->ap_iface->bss[0],
  854. txtaddr);
  855. }
  856. int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
  857. size_t buflen, int verbose)
  858. {
  859. char *pos = buf, *end = buf + buflen;
  860. int ret;
  861. struct hostapd_bss_config *conf;
  862. if (wpa_s->ap_iface == NULL)
  863. return -1;
  864. conf = wpa_s->ap_iface->bss[0]->conf;
  865. if (conf->wpa == 0)
  866. return 0;
  867. ret = os_snprintf(pos, end - pos,
  868. "pairwise_cipher=%s\n"
  869. "group_cipher=%s\n"
  870. "key_mgmt=%s\n",
  871. wpa_cipher_txt(conf->rsn_pairwise),
  872. wpa_cipher_txt(conf->wpa_group),
  873. wpa_key_mgmt_txt(conf->wpa_key_mgmt,
  874. conf->wpa));
  875. if (ret < 0 || ret >= end - pos)
  876. return pos - buf;
  877. pos += ret;
  878. return pos - buf;
  879. }
  880. #endif /* CONFIG_CTRL_IFACE */
  881. int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
  882. {
  883. struct hostapd_iface *iface = wpa_s->ap_iface;
  884. struct wpa_ssid *ssid = wpa_s->current_ssid;
  885. struct hostapd_data *hapd;
  886. if (ssid == NULL || wpa_s->ap_iface == NULL ||
  887. ssid->mode == WPAS_MODE_INFRA ||
  888. ssid->mode == WPAS_MODE_IBSS)
  889. return -1;
  890. #ifdef CONFIG_P2P
  891. if (ssid->mode == WPAS_MODE_P2P_GO)
  892. iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
  893. else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  894. iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
  895. P2P_GROUP_FORMATION;
  896. #endif /* CONFIG_P2P */
  897. hapd = iface->bss[0];
  898. if (hapd->drv_priv == NULL)
  899. return -1;
  900. ieee802_11_set_beacons(iface);
  901. hostapd_set_ap_wps_ie(hapd);
  902. return 0;
  903. }
  904. int ap_switch_channel(struct wpa_supplicant *wpa_s,
  905. struct csa_settings *settings)
  906. {
  907. #ifdef NEED_AP_MLME
  908. if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
  909. return -1;
  910. return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
  911. #else /* NEED_AP_MLME */
  912. return -1;
  913. #endif /* NEED_AP_MLME */
  914. }
  915. int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
  916. {
  917. struct csa_settings settings;
  918. int ret = hostapd_parse_csa_settings(pos, &settings);
  919. if (ret)
  920. return ret;
  921. return ap_switch_channel(wpa_s, &settings);
  922. }
  923. void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
  924. int offset, int width, int cf1, int cf2)
  925. {
  926. if (!wpa_s->ap_iface)
  927. return;
  928. wpa_s->assoc_freq = freq;
  929. hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht, offset, width, cf1, cf1);
  930. }
  931. int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
  932. const u8 *addr)
  933. {
  934. struct hostapd_data *hapd;
  935. struct hostapd_bss_config *conf;
  936. if (!wpa_s->ap_iface)
  937. return -1;
  938. if (addr)
  939. wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
  940. MAC2STR(addr));
  941. else
  942. wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
  943. hapd = wpa_s->ap_iface->bss[0];
  944. conf = hapd->conf;
  945. os_free(conf->accept_mac);
  946. conf->accept_mac = NULL;
  947. conf->num_accept_mac = 0;
  948. os_free(conf->deny_mac);
  949. conf->deny_mac = NULL;
  950. conf->num_deny_mac = 0;
  951. if (addr == NULL) {
  952. conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
  953. return 0;
  954. }
  955. conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
  956. conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
  957. if (conf->accept_mac == NULL)
  958. return -1;
  959. os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
  960. conf->num_accept_mac = 1;
  961. return 0;
  962. }
  963. #ifdef CONFIG_WPS_NFC
  964. int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
  965. const struct wpabuf *pw, const u8 *pubkey_hash)
  966. {
  967. struct hostapd_data *hapd;
  968. struct wps_context *wps;
  969. if (!wpa_s->ap_iface)
  970. return -1;
  971. hapd = wpa_s->ap_iface->bss[0];
  972. wps = hapd->wps;
  973. if (wpa_s->parent->conf->wps_nfc_dh_pubkey == NULL ||
  974. wpa_s->parent->conf->wps_nfc_dh_privkey == NULL) {
  975. wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
  976. return -1;
  977. }
  978. dh5_free(wps->dh_ctx);
  979. wpabuf_free(wps->dh_pubkey);
  980. wpabuf_free(wps->dh_privkey);
  981. wps->dh_privkey = wpabuf_dup(
  982. wpa_s->parent->conf->wps_nfc_dh_privkey);
  983. wps->dh_pubkey = wpabuf_dup(
  984. wpa_s->parent->conf->wps_nfc_dh_pubkey);
  985. if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
  986. wps->dh_ctx = NULL;
  987. wpabuf_free(wps->dh_pubkey);
  988. wps->dh_pubkey = NULL;
  989. wpabuf_free(wps->dh_privkey);
  990. wps->dh_privkey = NULL;
  991. return -1;
  992. }
  993. wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
  994. if (wps->dh_ctx == NULL)
  995. return -1;
  996. return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
  997. pw_id,
  998. pw ? wpabuf_head(pw) : NULL,
  999. pw ? wpabuf_len(pw) : 0, 1);
  1000. }
  1001. #endif /* CONFIG_WPS_NFC */