ap.c 34 KB

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