ap.c 35 KB

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