ap.c 31 KB

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