ap.c 31 KB

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