ap.c 32 KB

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