ap.c 35 KB

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