Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * wpa_supplicant - P2P |
| 3 | * Copyright (c) 2009-2010, Atheros Communications |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4 | * Copyright (c) 2010-2014, Jouni Malinen <j@w1.fi> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6 | * This software may be distributed under the terms of the BSD license. |
| 7 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include "includes.h" |
| 11 | |
| 12 | #include "common.h" |
| 13 | #include "eloop.h" |
| 14 | #include "common/ieee802_11_common.h" |
| 15 | #include "common/ieee802_11_defs.h" |
| 16 | #include "common/wpa_ctrl.h" |
| 17 | #include "wps/wps_i.h" |
| 18 | #include "p2p/p2p.h" |
| 19 | #include "ap/hostapd.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 20 | #include "ap/ap_config.h" |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 21 | #include "ap/sta_info.h" |
| 22 | #include "ap/ap_drv_ops.h" |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 23 | #include "ap/wps_hostapd.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 24 | #include "ap/p2p_hostapd.h" |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 25 | #include "ap/dfs.h" |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 26 | #include "eapol_supp/eapol_supp_sm.h" |
| 27 | #include "rsn_supp/wpa.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 28 | #include "wpa_supplicant_i.h" |
| 29 | #include "driver_i.h" |
| 30 | #include "ap.h" |
| 31 | #include "config_ssid.h" |
| 32 | #include "config.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 33 | #include "notify.h" |
| 34 | #include "scan.h" |
| 35 | #include "bss.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 36 | #include "offchannel.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 37 | #include "wps_supplicant.h" |
| 38 | #include "p2p_supplicant.h" |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 39 | #include "wifi_display.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 40 | |
| 41 | |
| 42 | /* |
| 43 | * How many times to try to scan to find the GO before giving up on join |
| 44 | * request. |
| 45 | */ |
| 46 | #define P2P_MAX_JOIN_SCAN_ATTEMPTS 10 |
| 47 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 48 | #define P2P_AUTO_PD_SCAN_ATTEMPTS 5 |
| 49 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 50 | /** |
| 51 | * Defines time interval in seconds when a GO needs to evacuate a frequency that |
| 52 | * it is currently using, but is no longer valid for P2P use cases. |
| 53 | */ |
| 54 | #define P2P_GO_FREQ_CHANGE_TIME 5 |
| 55 | |
| 56 | /** |
| 57 | * Defines CSA parameters which are used when GO evacuates the no longer valid |
| 58 | * channel (and if the driver supports channel switch). |
| 59 | */ |
| 60 | #define P2P_GO_CSA_COUNT 7 |
| 61 | #define P2P_GO_CSA_BLOCK_TX 0 |
| 62 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 63 | #ifndef P2P_MAX_CLIENT_IDLE |
| 64 | /* |
| 65 | * How many seconds to try to reconnect to the GO when connection in P2P client |
| 66 | * role has been lost. |
| 67 | */ |
| 68 | #define P2P_MAX_CLIENT_IDLE 10 |
| 69 | #endif /* P2P_MAX_CLIENT_IDLE */ |
| 70 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 71 | #ifndef P2P_MAX_INITIAL_CONN_WAIT |
| 72 | /* |
| 73 | * How many seconds to wait for initial 4-way handshake to get completed after |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 74 | * WPS provisioning step or after the re-invocation of a persistent group on a |
| 75 | * P2P Client. |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 76 | */ |
| 77 | #define P2P_MAX_INITIAL_CONN_WAIT 10 |
| 78 | #endif /* P2P_MAX_INITIAL_CONN_WAIT */ |
| 79 | |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 80 | #ifndef P2P_MAX_INITIAL_CONN_WAIT_GO |
| 81 | /* |
| 82 | * How many seconds to wait for initial 4-way handshake to get completed after |
| 83 | * WPS provisioning step on the GO. This controls the extra time the P2P |
| 84 | * operation is considered to be in progress (e.g., to delay other scans) after |
| 85 | * WPS provisioning has been completed on the GO during group formation. |
| 86 | */ |
| 87 | #define P2P_MAX_INITIAL_CONN_WAIT_GO 10 |
| 88 | #endif /* P2P_MAX_INITIAL_CONN_WAIT_GO */ |
| 89 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 90 | #ifndef P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE |
| 91 | /* |
| 92 | * How many seconds to wait for initial 4-way handshake to get completed after |
| 93 | * re-invocation of a persistent group on the GO when the client is expected |
| 94 | * to connect automatically (no user interaction). |
| 95 | */ |
| 96 | #define P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE 15 |
| 97 | #endif /* P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE */ |
| 98 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 99 | #define P2P_MGMT_DEVICE_PREFIX "p2p-dev-" |
| 100 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 101 | /* |
| 102 | * How many seconds to wait to re-attempt to move GOs, in case previous attempt |
| 103 | * was not possible. |
| 104 | */ |
| 105 | #define P2P_RECONSIDER_GO_MOVE_DELAY 30 |
| 106 | |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 107 | /* Check if frequency is 2GHz */ |
| 108 | #define IS_2GHZ(n) (n >= 2412 && n <= 2484) |
| 109 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 110 | enum p2p_group_removal_reason { |
| 111 | P2P_GROUP_REMOVAL_UNKNOWN, |
| 112 | P2P_GROUP_REMOVAL_SILENT, |
| 113 | P2P_GROUP_REMOVAL_FORMATION_FAILED, |
| 114 | P2P_GROUP_REMOVAL_REQUESTED, |
| 115 | P2P_GROUP_REMOVAL_IDLE_TIMEOUT, |
| 116 | P2P_GROUP_REMOVAL_UNAVAILABLE, |
| 117 | P2P_GROUP_REMOVAL_GO_ENDING_SESSION, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 118 | P2P_GROUP_REMOVAL_PSK_FAILURE, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 119 | P2P_GROUP_REMOVAL_FREQ_CONFLICT, |
| 120 | P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
Jouni Malinen | dc7b713 | 2012-09-14 12:53:47 -0700 | [diff] [blame] | 123 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 124 | static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx); |
| 125 | static struct wpa_supplicant * |
| 126 | wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated, |
| 127 | int go); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 128 | static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s, int freq, |
| 129 | const u8 *ssid, size_t ssid_len); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 130 | static int wpas_p2p_setup_freqs(struct wpa_supplicant *wpa_s, int freq, |
| 131 | int *force_freq, int *pref_freq, int go, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 132 | struct weighted_pcl *pref_freq_list, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 133 | unsigned int *num_pref_freq); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 134 | static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq, |
| 135 | const u8 *ssid, size_t ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 136 | static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx); |
| 137 | static int wpas_p2p_join(struct wpa_supplicant *wpa_s, const u8 *iface_addr, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 138 | const u8 *dev_addr, enum p2p_wps_method wps_method, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 139 | int auto_join, int freq, |
| 140 | const u8 *ssid, size_t ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 141 | static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s); |
| 142 | static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s); |
| 143 | static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx); |
| 144 | static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 145 | static void wpas_p2p_group_formation_timeout(void *eloop_ctx, |
| 146 | void *timeout_ctx); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 147 | static void wpas_p2p_group_freq_conflict(void *eloop_ctx, void *timeout_ctx); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 148 | static int wpas_p2p_fallback_to_go_neg(struct wpa_supplicant *wpa_s, |
| 149 | int group_added); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 150 | static void wpas_p2p_stop_find_oper(struct wpa_supplicant *wpa_s); |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 151 | static void wpas_stop_listen(void *ctx); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 152 | static void wpas_p2p_psk_failure_removal(void *eloop_ctx, void *timeout_ctx); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 153 | static void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 154 | static int wpas_p2p_add_group_interface(struct wpa_supplicant *wpa_s, |
| 155 | enum wpa_driver_if_type type); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 156 | static void wpas_p2p_group_formation_failed(struct wpa_supplicant *wpa_s, |
| 157 | int already_deleted); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 158 | static void wpas_p2p_optimize_listen_channel(struct wpa_supplicant *wpa_s, |
| 159 | struct wpa_used_freq_data *freqs, |
| 160 | unsigned int num); |
| 161 | static void wpas_p2p_move_go(void *eloop_ctx, void *timeout_ctx); |
| 162 | static int wpas_p2p_go_is_peer_freq(struct wpa_supplicant *wpa_s, int freq); |
| 163 | static void |
| 164 | wpas_p2p_consider_moving_gos(struct wpa_supplicant *wpa_s, |
| 165 | struct wpa_used_freq_data *freqs, unsigned int num, |
| 166 | enum wpas_p2p_channel_update_trig trig); |
| 167 | static void wpas_p2p_reconsider_moving_go(void *eloop_ctx, void *timeout_ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 168 | |
| 169 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 170 | static int wpas_get_6ghz_he_chwidth_capab(struct hostapd_hw_modes *mode) |
| 171 | { |
| 172 | int he_capab = 0; |
| 173 | |
| 174 | if (mode) |
| 175 | he_capab = mode->he_capab[WPAS_MODE_INFRA].phy_cap[ |
| 176 | HE_PHYCAP_CHANNEL_WIDTH_SET_IDX]; |
| 177 | return he_capab; |
| 178 | } |
| 179 | |
| 180 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 181 | /* |
| 182 | * Get the number of concurrent channels that the HW can operate, but that are |
| 183 | * currently not in use by any of the wpa_supplicant interfaces. |
| 184 | */ |
| 185 | static int wpas_p2p_num_unused_channels(struct wpa_supplicant *wpa_s) |
| 186 | { |
| 187 | int *freqs; |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 188 | int num, unused; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 189 | |
| 190 | freqs = os_calloc(wpa_s->num_multichan_concurrent, sizeof(int)); |
| 191 | if (!freqs) |
| 192 | return -1; |
| 193 | |
| 194 | num = get_shared_radio_freqs(wpa_s, freqs, |
| 195 | wpa_s->num_multichan_concurrent); |
| 196 | os_free(freqs); |
| 197 | |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 198 | unused = wpa_s->num_multichan_concurrent - num; |
| 199 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: num_unused_channels: %d", unused); |
| 200 | return unused; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | |
| 204 | /* |
| 205 | * Get the frequencies that are currently in use by one or more of the virtual |
| 206 | * interfaces, and that are also valid for P2P operation. |
| 207 | */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 208 | static unsigned int |
| 209 | wpas_p2p_valid_oper_freqs(struct wpa_supplicant *wpa_s, |
| 210 | struct wpa_used_freq_data *p2p_freqs, |
| 211 | unsigned int len) |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 212 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 213 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 214 | unsigned int num, i, j; |
| 215 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 216 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 217 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 218 | if (!freqs) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 219 | return 0; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 220 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 221 | num = get_shared_radio_freqs_data(wpa_s, freqs, |
| 222 | wpa_s->num_multichan_concurrent); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 223 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 224 | os_memset(p2p_freqs, 0, sizeof(struct wpa_used_freq_data) * len); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 225 | |
| 226 | for (i = 0, j = 0; i < num && j < len; i++) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 227 | if (p2p_supported_freq(wpa_s->global->p2p, freqs[i].freq)) |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 228 | p2p_freqs[j++] = freqs[i]; |
| 229 | } |
| 230 | |
| 231 | os_free(freqs); |
| 232 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 233 | dump_freq_data(wpa_s, "valid for P2P", p2p_freqs, j); |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 234 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 235 | return j; |
| 236 | } |
| 237 | |
| 238 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 239 | static void wpas_p2p_set_own_freq_preference(struct wpa_supplicant *wpa_s, |
| 240 | int freq) |
| 241 | { |
| 242 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 243 | return; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 244 | |
| 245 | /* Use the wpa_s used to control the P2P Device operation */ |
| 246 | wpa_s = wpa_s->global->p2p_init_wpa_s; |
| 247 | |
| 248 | if (wpa_s->conf->p2p_ignore_shared_freq && |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 249 | freq > 0 && wpa_s->num_multichan_concurrent > 1 && |
| 250 | wpas_p2p_num_unused_channels(wpa_s) > 0) { |
| 251 | wpa_printf(MSG_DEBUG, "P2P: Ignore own channel preference %d MHz due to p2p_ignore_shared_freq=1 configuration", |
| 252 | freq); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 253 | freq = 0; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 254 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 255 | p2p_set_own_freq_preference(wpa_s->global->p2p, freq); |
| 256 | } |
| 257 | |
| 258 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 259 | static void wpas_p2p_scan_res_handled(struct wpa_supplicant *wpa_s) |
| 260 | { |
| 261 | unsigned int delay = wpas_p2p_search_delay(wpa_s); |
| 262 | |
| 263 | /* In case of concurrent P2P and external scans, delay P2P search. */ |
| 264 | if (external_scan_running(wpa_s->radio)) { |
| 265 | delay = wpa_s->conf->p2p_search_delay; |
| 266 | wpa_printf(MSG_DEBUG, |
| 267 | "P2P: Delay next P2P search by %d ms to let externally triggered scan complete", |
| 268 | delay); |
| 269 | } |
| 270 | |
| 271 | p2p_scan_res_handled(wpa_s->global->p2p, delay); |
| 272 | } |
| 273 | |
| 274 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 275 | static void wpas_p2p_scan_res_handler(struct wpa_supplicant *wpa_s, |
| 276 | struct wpa_scan_results *scan_res) |
| 277 | { |
| 278 | size_t i; |
| 279 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 280 | if (wpa_s->p2p_scan_work) { |
| 281 | struct wpa_radio_work *work = wpa_s->p2p_scan_work; |
| 282 | wpa_s->p2p_scan_work = NULL; |
| 283 | radio_work_done(work); |
| 284 | } |
| 285 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 286 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 287 | return; |
| 288 | |
| 289 | wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS)", |
| 290 | (int) scan_res->num); |
| 291 | |
| 292 | for (i = 0; i < scan_res->num; i++) { |
| 293 | struct wpa_scan_res *bss = scan_res->res[i]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 294 | struct os_reltime time_tmp_age, entry_ts; |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 295 | const u8 *ies; |
| 296 | size_t ies_len; |
| 297 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 298 | time_tmp_age.sec = bss->age / 1000; |
| 299 | time_tmp_age.usec = (bss->age % 1000) * 1000; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 300 | os_reltime_sub(&scan_res->fetch_time, &time_tmp_age, &entry_ts); |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 301 | |
| 302 | ies = (const u8 *) (bss + 1); |
| 303 | ies_len = bss->ie_len; |
| 304 | if (bss->beacon_ie_len > 0 && |
| 305 | !wpa_scan_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) && |
| 306 | wpa_scan_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { |
| 307 | wpa_printf(MSG_DEBUG, "P2P: Use P2P IE(s) from Beacon frame since no P2P IE(s) in Probe Response frames received for " |
| 308 | MACSTR, MAC2STR(bss->bssid)); |
| 309 | ies = ies + ies_len; |
| 310 | ies_len = bss->beacon_ie_len; |
| 311 | } |
| 312 | |
| 313 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 314 | if (p2p_scan_res_handler(wpa_s->global->p2p, bss->bssid, |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 315 | bss->freq, &entry_ts, bss->level, |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 316 | ies, ies_len) > 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 317 | break; |
| 318 | } |
| 319 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 320 | wpas_p2p_scan_res_handled(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 324 | static void wpas_p2p_scan_res_fail_handler(struct wpa_supplicant *wpa_s) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 325 | { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 326 | if (wpa_s->p2p_scan_work) { |
| 327 | struct wpa_radio_work *work = wpa_s->p2p_scan_work; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 328 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 329 | wpa_s->p2p_scan_work = NULL; |
| 330 | radio_work_done(work); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 333 | if (wpa_s->global->p2p_disabled || !wpa_s->global->p2p) |
| 334 | return; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 335 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 336 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 337 | "P2P: Failed to get scan results - try to continue"); |
| 338 | wpas_p2p_scan_res_handled(wpa_s); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 342 | static void wpas_p2p_trigger_scan_cb(struct wpa_radio_work *work, int deinit) |
| 343 | { |
| 344 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 345 | struct wpa_driver_scan_params *params = work->ctx; |
| 346 | int ret; |
| 347 | |
| 348 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 349 | if (!work->started) { |
| 350 | wpa_scan_free_params(params); |
| 351 | return; |
| 352 | } |
| 353 | |
| 354 | wpa_s->p2p_scan_work = NULL; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 355 | return; |
| 356 | } |
| 357 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 358 | if (wpa_s->clear_driver_scan_cache) { |
| 359 | wpa_printf(MSG_DEBUG, |
| 360 | "Request driver to clear scan cache due to local BSS flush"); |
| 361 | params->only_new_results = 1; |
| 362 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 363 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 364 | if (!params->p2p_include_6ghz && !params->freqs) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 365 | wpa_printf(MSG_DEBUG, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 366 | "P2P: Exclude 6 GHz channels - update the scan frequency list"); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 367 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211G, params, |
| 368 | 0); |
| 369 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, params, |
| 370 | 0); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 371 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 372 | ret = wpa_drv_scan(wpa_s, params); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 373 | if (ret == 0) |
| 374 | wpa_s->curr_scan_cookie = params->scan_cookie; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 375 | wpa_scan_free_params(params); |
| 376 | work->ctx = NULL; |
| 377 | if (ret) { |
| 378 | radio_work_done(work); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 379 | p2p_notify_scan_trigger_status(wpa_s->global->p2p, ret); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 380 | return; |
| 381 | } |
| 382 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 383 | p2p_notify_scan_trigger_status(wpa_s->global->p2p, ret); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 384 | os_get_reltime(&wpa_s->scan_trigger_time); |
| 385 | wpa_s->scan_res_handler = wpas_p2p_scan_res_handler; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 386 | wpa_s->scan_res_fail_handler = wpas_p2p_scan_res_fail_handler; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 387 | wpa_s->own_scan_requested = 1; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 388 | wpa_s->clear_driver_scan_cache = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 389 | wpa_s->p2p_scan_work = work; |
| 390 | } |
| 391 | |
| 392 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 393 | static int wpas_p2p_search_social_channel(struct wpa_supplicant *wpa_s, |
| 394 | int freq) |
| 395 | { |
| 396 | if (wpa_s->global->p2p_24ghz_social_channels && |
| 397 | (freq == 2412 || freq == 2437 || freq == 2462)) { |
| 398 | /* |
| 399 | * Search all social channels regardless of whether these have |
| 400 | * been disabled for P2P operating channel use to avoid missing |
| 401 | * peers. |
| 402 | */ |
| 403 | return 1; |
| 404 | } |
| 405 | return p2p_supported_freq(wpa_s->global->p2p, freq); |
| 406 | } |
| 407 | |
| 408 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 409 | static int wpas_p2p_scan(void *ctx, enum p2p_scan_type type, int freq, |
| 410 | unsigned int num_req_dev_types, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 411 | const u8 *req_dev_types, const u8 *dev_id, u16 pw_id, |
| 412 | bool include_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 413 | { |
| 414 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 415 | struct wpa_driver_scan_params *params = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 416 | struct wpabuf *wps_ie, *ies; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 417 | unsigned int num_channels = 0; |
| 418 | int social_channels_freq[] = { 2412, 2437, 2462, 60480 }; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 419 | size_t ielen; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 420 | u8 *n, i; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 421 | unsigned int bands; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 422 | |
| 423 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 424 | return -1; |
| 425 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 426 | if (wpa_s->p2p_scan_work) { |
| 427 | wpa_dbg(wpa_s, MSG_INFO, "P2P: Reject scan trigger since one is already pending"); |
| 428 | return -1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 431 | params = os_zalloc(sizeof(*params)); |
| 432 | if (params == NULL) |
| 433 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 434 | |
| 435 | /* P2P Wildcard SSID */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 436 | params->num_ssids = 1; |
| 437 | n = os_malloc(P2P_WILDCARD_SSID_LEN); |
| 438 | if (n == NULL) |
| 439 | goto fail; |
| 440 | os_memcpy(n, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN); |
| 441 | params->ssids[0].ssid = n; |
| 442 | params->ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 443 | |
| 444 | wpa_s->wps->dev.p2p = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 445 | wps_ie = wps_build_probe_req_ie(pw_id, &wpa_s->wps->dev, |
| 446 | wpa_s->wps->uuid, WPS_REQ_ENROLLEE, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 447 | num_req_dev_types, req_dev_types); |
| 448 | if (wps_ie == NULL) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 449 | goto fail; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 450 | if (!wpa_s->conf->p2p_6ghz_disable) |
| 451 | params->p2p_include_6ghz = include_6ghz; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 452 | switch (type) { |
| 453 | case P2P_SCAN_SOCIAL: |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 454 | params->freqs = os_calloc(ARRAY_SIZE(social_channels_freq) + 1, |
| 455 | sizeof(int)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 456 | if (params->freqs == NULL) |
| 457 | goto fail; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 458 | for (i = 0; i < ARRAY_SIZE(social_channels_freq); i++) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 459 | if (wpas_p2p_search_social_channel( |
| 460 | wpa_s, social_channels_freq[i])) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 461 | params->freqs[num_channels++] = |
| 462 | social_channels_freq[i]; |
| 463 | } |
| 464 | params->freqs[num_channels++] = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 465 | break; |
| 466 | case P2P_SCAN_FULL: |
| 467 | break; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 468 | case P2P_SCAN_SPECIFIC: |
| 469 | params->freqs = os_calloc(2, sizeof(int)); |
| 470 | if (params->freqs == NULL) |
| 471 | goto fail; |
| 472 | params->freqs[0] = freq; |
| 473 | params->freqs[1] = 0; |
| 474 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 475 | case P2P_SCAN_SOCIAL_PLUS_ONE: |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 476 | params->freqs = os_calloc(ARRAY_SIZE(social_channels_freq) + 2, |
| 477 | sizeof(int)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 478 | if (params->freqs == NULL) |
| 479 | goto fail; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 480 | for (i = 0; i < ARRAY_SIZE(social_channels_freq); i++) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 481 | if (wpas_p2p_search_social_channel( |
| 482 | wpa_s, social_channels_freq[i])) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 483 | params->freqs[num_channels++] = |
| 484 | social_channels_freq[i]; |
| 485 | } |
| 486 | if (p2p_supported_freq(wpa_s->global->p2p, freq)) |
| 487 | params->freqs[num_channels++] = freq; |
| 488 | params->freqs[num_channels++] = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 489 | break; |
| 490 | } |
| 491 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 492 | ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p); |
| 493 | ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen); |
| 494 | if (ies == NULL) { |
| 495 | wpabuf_free(wps_ie); |
| 496 | goto fail; |
| 497 | } |
| 498 | wpabuf_put_buf(ies, wps_ie); |
| 499 | wpabuf_free(wps_ie); |
| 500 | |
| 501 | bands = wpas_get_bands(wpa_s, params->freqs); |
| 502 | p2p_scan_ie(wpa_s->global->p2p, ies, dev_id, bands); |
| 503 | |
| 504 | params->p2p_probe = 1; |
| 505 | n = os_malloc(wpabuf_len(ies)); |
| 506 | if (n == NULL) { |
| 507 | wpabuf_free(ies); |
| 508 | goto fail; |
| 509 | } |
| 510 | os_memcpy(n, wpabuf_head(ies), wpabuf_len(ies)); |
| 511 | params->extra_ies = n; |
| 512 | params->extra_ies_len = wpabuf_len(ies); |
| 513 | wpabuf_free(ies); |
| 514 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 515 | radio_remove_works(wpa_s, "p2p-scan", 0); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 516 | if (radio_add_work(wpa_s, 0, "p2p-scan", 0, wpas_p2p_trigger_scan_cb, |
| 517 | params) < 0) |
| 518 | goto fail; |
| 519 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 520 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 521 | fail: |
| 522 | wpa_scan_free_params(params); |
| 523 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 527 | static enum wpa_driver_if_type wpas_p2p_if_type(int p2p_group_interface) |
| 528 | { |
| 529 | switch (p2p_group_interface) { |
| 530 | case P2P_GROUP_INTERFACE_PENDING: |
| 531 | return WPA_IF_P2P_GROUP; |
| 532 | case P2P_GROUP_INTERFACE_GO: |
| 533 | return WPA_IF_P2P_GO; |
| 534 | case P2P_GROUP_INTERFACE_CLIENT: |
| 535 | return WPA_IF_P2P_CLIENT; |
| 536 | } |
| 537 | |
| 538 | return WPA_IF_P2P_GROUP; |
| 539 | } |
| 540 | |
| 541 | |
| 542 | static struct wpa_supplicant * wpas_get_p2p_group(struct wpa_supplicant *wpa_s, |
| 543 | const u8 *ssid, |
| 544 | size_t ssid_len, int *go) |
| 545 | { |
| 546 | struct wpa_ssid *s; |
| 547 | |
| 548 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 549 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 550 | if (s->disabled != 0 || !s->p2p_group || |
| 551 | s->ssid_len != ssid_len || |
| 552 | os_memcmp(ssid, s->ssid, ssid_len) != 0) |
| 553 | continue; |
| 554 | if (s->mode == WPAS_MODE_P2P_GO && |
| 555 | s != wpa_s->current_ssid) |
| 556 | continue; |
| 557 | if (go) |
| 558 | *go = s->mode == WPAS_MODE_P2P_GO; |
| 559 | return wpa_s; |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | return NULL; |
| 564 | } |
| 565 | |
| 566 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 567 | static void run_wpas_p2p_disconnect(void *eloop_ctx, void *timeout_ctx) |
| 568 | { |
| 569 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 570 | wpa_printf(MSG_DEBUG, |
| 571 | "P2P: Complete previously requested removal of %s", |
| 572 | wpa_s->ifname); |
| 573 | wpas_p2p_disconnect(wpa_s); |
| 574 | } |
| 575 | |
| 576 | |
| 577 | static int wpas_p2p_disconnect_safely(struct wpa_supplicant *wpa_s, |
| 578 | struct wpa_supplicant *calling_wpa_s) |
| 579 | { |
| 580 | if (calling_wpa_s == wpa_s && wpa_s && |
| 581 | wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) { |
| 582 | /* |
| 583 | * The calling wpa_s instance is going to be removed. Do that |
| 584 | * from an eloop callback to keep the instance available until |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 585 | * the caller has returned. This may be needed, e.g., to provide |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 586 | * control interface responses on the per-interface socket. |
| 587 | */ |
| 588 | if (eloop_register_timeout(0, 0, run_wpas_p2p_disconnect, |
| 589 | wpa_s, NULL) < 0) |
| 590 | return -1; |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | return wpas_p2p_disconnect(wpa_s); |
| 595 | } |
| 596 | |
| 597 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 598 | /* Determine total number of clients in active groups where we are the GO */ |
| 599 | static unsigned int p2p_group_go_member_count(struct wpa_supplicant *wpa_s) |
| 600 | { |
| 601 | unsigned int count = 0; |
| 602 | struct wpa_ssid *s; |
| 603 | |
| 604 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 605 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 606 | wpa_printf(MSG_DEBUG, |
| 607 | "P2P: sup:%p ssid:%p disabled:%d p2p:%d mode:%d", |
| 608 | wpa_s, s, s->disabled, s->p2p_group, |
| 609 | s->mode); |
| 610 | if (!s->disabled && s->p2p_group && |
| 611 | s->mode == WPAS_MODE_P2P_GO) { |
| 612 | count += p2p_get_group_num_members( |
| 613 | wpa_s->p2p_group); |
| 614 | } |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | return count; |
| 619 | } |
| 620 | |
| 621 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 622 | static unsigned int p2p_is_active_persistent_group(struct wpa_supplicant *wpa_s) |
| 623 | { |
| 624 | return !wpa_s->p2p_mgmt && wpa_s->current_ssid && |
| 625 | !wpa_s->current_ssid->disabled && |
| 626 | wpa_s->current_ssid->p2p_group && |
| 627 | wpa_s->current_ssid->p2p_persistent_group; |
| 628 | } |
| 629 | |
| 630 | |
| 631 | static unsigned int p2p_is_active_persistent_go(struct wpa_supplicant *wpa_s) |
| 632 | { |
| 633 | return p2p_is_active_persistent_group(wpa_s) && |
| 634 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO; |
| 635 | } |
| 636 | |
| 637 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 638 | /* Find an interface for a P2P group where we are the GO */ |
| 639 | static struct wpa_supplicant * |
| 640 | wpas_p2p_get_go_group(struct wpa_supplicant *wpa_s) |
| 641 | { |
| 642 | struct wpa_supplicant *save = NULL; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 643 | |
| 644 | if (!wpa_s) |
| 645 | return NULL; |
| 646 | |
| 647 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 648 | if (!p2p_is_active_persistent_go(wpa_s)) |
| 649 | continue; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 650 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 651 | /* Prefer a group with connected clients */ |
| 652 | if (p2p_get_group_num_members(wpa_s->p2p_group)) |
| 653 | return wpa_s; |
| 654 | save = wpa_s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | /* No group with connected clients, so pick the one without (if any) */ |
| 658 | return save; |
| 659 | } |
| 660 | |
| 661 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 662 | static unsigned int p2p_is_active_persistent_cli(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 663 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 664 | return p2p_is_active_persistent_group(wpa_s) && |
| 665 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA; |
| 666 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 667 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 668 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 669 | /* Find an interface for a P2P group where we are the P2P Client */ |
| 670 | static struct wpa_supplicant * |
| 671 | wpas_p2p_get_cli_group(struct wpa_supplicant *wpa_s) |
| 672 | { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 673 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 674 | if (p2p_is_active_persistent_cli(wpa_s)) |
| 675 | return wpa_s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 676 | } |
| 677 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 678 | return NULL; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | |
| 682 | /* Find a persistent group where we are the GO */ |
| 683 | static struct wpa_ssid * |
| 684 | wpas_p2p_get_persistent_go(struct wpa_supplicant *wpa_s) |
| 685 | { |
| 686 | struct wpa_ssid *s; |
| 687 | |
| 688 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 689 | if (s->disabled == 2 && s->mode == WPAS_MODE_P2P_GO) |
| 690 | return s; |
| 691 | } |
| 692 | |
| 693 | return NULL; |
| 694 | } |
| 695 | |
| 696 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 697 | static u8 p2ps_group_capability(void *ctx, u8 incoming, u8 role, |
| 698 | unsigned int *force_freq, |
| 699 | unsigned int *pref_freq) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 700 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 701 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 702 | struct wpa_ssid *s; |
| 703 | u8 conncap = P2PS_SETUP_NONE; |
| 704 | unsigned int owned_members = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 705 | struct wpa_supplicant *go_wpa_s, *cli_wpa_s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 706 | struct wpa_ssid *persistent_go; |
| 707 | int p2p_no_group_iface; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 708 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 709 | unsigned int size; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 710 | |
| 711 | wpa_printf(MSG_DEBUG, "P2P: Conncap - in:%d role:%d", incoming, role); |
| 712 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 713 | if (force_freq) |
| 714 | *force_freq = 0; |
| 715 | if (pref_freq) |
| 716 | *pref_freq = 0; |
| 717 | |
| 718 | size = P2P_MAX_PREF_CHANNELS; |
| 719 | if (force_freq && pref_freq && |
| 720 | !wpas_p2p_setup_freqs(wpa_s, 0, (int *) force_freq, |
| 721 | (int *) pref_freq, 0, pref_freq_list, &size)) |
| 722 | wpas_p2p_set_own_freq_preference(wpa_s, |
| 723 | *force_freq ? *force_freq : |
| 724 | *pref_freq); |
| 725 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 726 | /* |
| 727 | * For non-concurrent capable devices: |
| 728 | * If persistent_go, then no new. |
| 729 | * If GO, then no client. |
| 730 | * If client, then no GO. |
| 731 | */ |
| 732 | go_wpa_s = wpas_p2p_get_go_group(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 733 | if (go_wpa_s) |
| 734 | owned_members = p2p_get_group_num_members(go_wpa_s->p2p_group); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 735 | persistent_go = wpas_p2p_get_persistent_go(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 736 | p2p_no_group_iface = !wpas_p2p_create_iface(wpa_s); |
| 737 | cli_wpa_s = wpas_p2p_get_cli_group(wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 738 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 739 | wpa_printf(MSG_DEBUG, |
| 740 | "P2P: GO(iface)=%p members=%u CLI(iface)=%p persistent(ssid)=%p", |
| 741 | go_wpa_s, owned_members, cli_wpa_s, persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 742 | |
| 743 | /* If not concurrent, restrict our choices */ |
| 744 | if (p2p_no_group_iface) { |
| 745 | wpa_printf(MSG_DEBUG, "P2P: p2p_no_group_iface"); |
| 746 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 747 | if (cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 748 | return P2PS_SETUP_NONE; |
| 749 | |
| 750 | if (go_wpa_s) { |
| 751 | if (role == P2PS_SETUP_CLIENT || |
| 752 | incoming == P2PS_SETUP_GROUP_OWNER || |
| 753 | p2p_client_limit_reached(go_wpa_s->p2p_group)) |
| 754 | return P2PS_SETUP_NONE; |
| 755 | |
| 756 | return P2PS_SETUP_GROUP_OWNER; |
| 757 | } |
| 758 | |
| 759 | if (persistent_go) { |
| 760 | if (role == P2PS_SETUP_NONE || role == P2PS_SETUP_NEW) { |
| 761 | if (!incoming) |
| 762 | return P2PS_SETUP_GROUP_OWNER | |
| 763 | P2PS_SETUP_CLIENT; |
| 764 | if (incoming == P2PS_SETUP_NEW) { |
| 765 | u8 r; |
| 766 | |
| 767 | if (os_get_random(&r, sizeof(r)) < 0 || |
| 768 | (r & 1)) |
| 769 | return P2PS_SETUP_CLIENT; |
| 770 | return P2PS_SETUP_GROUP_OWNER; |
| 771 | } |
| 772 | } |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | /* If a required role has been specified, handle it here */ |
| 777 | if (role && role != P2PS_SETUP_NEW) { |
| 778 | switch (incoming) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 779 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_NEW: |
| 780 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT: |
| 781 | /* |
| 782 | * Peer has an active GO, so if the role allows it and |
| 783 | * we do not have any active roles, become client. |
| 784 | */ |
| 785 | if ((role & P2PS_SETUP_CLIENT) && !go_wpa_s && |
| 786 | !cli_wpa_s) |
| 787 | return P2PS_SETUP_CLIENT; |
| 788 | |
| 789 | /* fall through */ |
| 790 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 791 | case P2PS_SETUP_NONE: |
| 792 | case P2PS_SETUP_NEW: |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 793 | conncap = role; |
| 794 | goto grp_owner; |
| 795 | |
| 796 | case P2PS_SETUP_GROUP_OWNER: |
| 797 | /* |
| 798 | * Must be a complimentary role - cannot be a client to |
| 799 | * more than one peer. |
| 800 | */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 801 | if (incoming == role || cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 802 | return P2PS_SETUP_NONE; |
| 803 | |
| 804 | return P2PS_SETUP_CLIENT; |
| 805 | |
| 806 | case P2PS_SETUP_CLIENT: |
| 807 | /* Must be a complimentary role */ |
| 808 | if (incoming != role) { |
| 809 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 810 | goto grp_owner; |
| 811 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 812 | /* fall through */ |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 813 | |
| 814 | default: |
| 815 | return P2PS_SETUP_NONE; |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | /* |
| 820 | * For now, we only will support ownership of one group, and being a |
| 821 | * client of one group. Therefore, if we have either an existing GO |
| 822 | * group, or an existing client group, we will not do a new GO |
| 823 | * negotiation, but rather try to re-use the existing groups. |
| 824 | */ |
| 825 | switch (incoming) { |
| 826 | case P2PS_SETUP_NONE: |
| 827 | case P2PS_SETUP_NEW: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 828 | if (cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 829 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 830 | else if (!owned_members) |
| 831 | conncap = P2PS_SETUP_NEW; |
| 832 | else if (incoming == P2PS_SETUP_NONE) |
| 833 | conncap = P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT; |
| 834 | else |
| 835 | conncap = P2PS_SETUP_CLIENT; |
| 836 | break; |
| 837 | |
| 838 | case P2PS_SETUP_CLIENT: |
| 839 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 840 | break; |
| 841 | |
| 842 | case P2PS_SETUP_GROUP_OWNER: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 843 | if (!cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 844 | conncap = P2PS_SETUP_CLIENT; |
| 845 | break; |
| 846 | |
| 847 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_NEW: |
| 848 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 849 | if (cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 850 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 851 | else { |
| 852 | u8 r; |
| 853 | |
| 854 | if (os_get_random(&r, sizeof(r)) < 0 || |
| 855 | (r & 1)) |
| 856 | conncap = P2PS_SETUP_CLIENT; |
| 857 | else |
| 858 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 859 | } |
| 860 | break; |
| 861 | |
| 862 | default: |
| 863 | return P2PS_SETUP_NONE; |
| 864 | } |
| 865 | |
| 866 | grp_owner: |
| 867 | if ((conncap & P2PS_SETUP_GROUP_OWNER) || |
| 868 | (!incoming && (conncap & P2PS_SETUP_NEW))) { |
| 869 | if (go_wpa_s && p2p_client_limit_reached(go_wpa_s->p2p_group)) |
| 870 | conncap &= ~P2PS_SETUP_GROUP_OWNER; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 871 | |
| 872 | s = wpas_p2p_get_persistent_go(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 873 | if (!s && !go_wpa_s && p2p_no_group_iface) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 874 | p2p_set_intended_addr(wpa_s->global->p2p, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 875 | wpa_s->p2p_mgmt ? |
| 876 | wpa_s->parent->own_addr : |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 877 | wpa_s->own_addr); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 878 | } else if (!s && !go_wpa_s) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 879 | if (wpas_p2p_add_group_interface(wpa_s, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 880 | WPA_IF_P2P_GROUP) < 0) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 881 | wpa_printf(MSG_ERROR, |
| 882 | "P2P: Failed to allocate a new interface for the group"); |
| 883 | return P2PS_SETUP_NONE; |
| 884 | } |
| 885 | wpa_s->global->pending_group_iface_for_p2ps = 1; |
| 886 | p2p_set_intended_addr(wpa_s->global->p2p, |
| 887 | wpa_s->pending_interface_addr); |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | return conncap; |
| 892 | } |
| 893 | |
| 894 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 895 | static int wpas_p2p_group_delete(struct wpa_supplicant *wpa_s, |
| 896 | enum p2p_group_removal_reason removal_reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 897 | { |
| 898 | struct wpa_ssid *ssid; |
| 899 | char *gtype; |
| 900 | const char *reason; |
| 901 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 902 | ssid = wpa_s->current_ssid; |
| 903 | if (ssid == NULL) { |
| 904 | /* |
| 905 | * The current SSID was not known, but there may still be a |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 906 | * pending P2P group interface waiting for provisioning or a |
| 907 | * P2P group that is trying to reconnect. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 908 | */ |
| 909 | ssid = wpa_s->conf->ssid; |
| 910 | while (ssid) { |
Jouni Malinen | 9d71283 | 2012-10-05 11:01:57 -0700 | [diff] [blame] | 911 | if (ssid->p2p_group && ssid->disabled != 2) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 912 | break; |
| 913 | ssid = ssid->next; |
| 914 | } |
Jouni Malinen | 5c44edb | 2012-08-31 21:35:32 +0300 | [diff] [blame] | 915 | if (ssid == NULL && |
| 916 | wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE) |
| 917 | { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 918 | wpa_printf(MSG_ERROR, "P2P: P2P group interface " |
| 919 | "not found"); |
| 920 | return -1; |
| 921 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 922 | } |
| 923 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO) |
| 924 | gtype = "GO"; |
| 925 | else if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT || |
| 926 | (ssid && ssid->mode == WPAS_MODE_INFRA)) { |
| 927 | wpa_s->reassociate = 0; |
| 928 | wpa_s->disconnected = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 929 | gtype = "client"; |
| 930 | } else |
| 931 | gtype = "GO"; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 932 | |
| 933 | if (removal_reason != P2P_GROUP_REMOVAL_SILENT && ssid) |
| 934 | wpas_notify_p2p_group_removed(wpa_s, ssid, gtype); |
| 935 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 936 | if (os_strcmp(gtype, "client") == 0) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 937 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 938 | if (eloop_is_timeout_registered(wpas_p2p_psk_failure_removal, |
| 939 | wpa_s, NULL)) { |
| 940 | wpa_printf(MSG_DEBUG, |
| 941 | "P2P: PSK failure removal was scheduled, so use PSK failure as reason for group removal"); |
| 942 | removal_reason = P2P_GROUP_REMOVAL_PSK_FAILURE; |
| 943 | eloop_cancel_timeout(wpas_p2p_psk_failure_removal, |
| 944 | wpa_s, NULL); |
| 945 | } |
| 946 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 947 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 948 | if (wpa_s->cross_connect_in_use) { |
| 949 | wpa_s->cross_connect_in_use = 0; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 950 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 951 | P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s", |
| 952 | wpa_s->ifname, wpa_s->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 953 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 954 | switch (removal_reason) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 955 | case P2P_GROUP_REMOVAL_REQUESTED: |
| 956 | reason = " reason=REQUESTED"; |
| 957 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 958 | case P2P_GROUP_REMOVAL_FORMATION_FAILED: |
| 959 | reason = " reason=FORMATION_FAILED"; |
| 960 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 961 | case P2P_GROUP_REMOVAL_IDLE_TIMEOUT: |
| 962 | reason = " reason=IDLE"; |
| 963 | break; |
| 964 | case P2P_GROUP_REMOVAL_UNAVAILABLE: |
| 965 | reason = " reason=UNAVAILABLE"; |
| 966 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 967 | case P2P_GROUP_REMOVAL_GO_ENDING_SESSION: |
| 968 | reason = " reason=GO_ENDING_SESSION"; |
| 969 | break; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 970 | case P2P_GROUP_REMOVAL_PSK_FAILURE: |
| 971 | reason = " reason=PSK_FAILURE"; |
| 972 | break; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 973 | case P2P_GROUP_REMOVAL_FREQ_CONFLICT: |
| 974 | reason = " reason=FREQ_CONFLICT"; |
| 975 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 976 | default: |
| 977 | reason = ""; |
| 978 | break; |
| 979 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 980 | if (removal_reason != P2P_GROUP_REMOVAL_SILENT) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 981 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 982 | P2P_EVENT_GROUP_REMOVED "%s %s%s", |
| 983 | wpa_s->ifname, gtype, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 984 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 985 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 986 | if (eloop_cancel_timeout(wpas_p2p_group_freq_conflict, wpa_s, NULL) > 0) |
| 987 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group freq_conflict timeout"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 988 | if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0) |
| 989 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 990 | if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 991 | wpa_s->p2pdev, NULL) > 0) { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 992 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group formation " |
| 993 | "timeout"); |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 994 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 995 | wpas_p2p_group_formation_failed(wpa_s, 1); |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 996 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 997 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 998 | wpa_s->p2p_in_invitation = 0; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame^] | 999 | wpa_s->p2p_retry_limit = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1000 | eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL); |
| 1001 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, wpa_s, NULL); |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 1002 | |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1003 | /* |
| 1004 | * Make sure wait for the first client does not remain active after the |
| 1005 | * group has been removed. |
| 1006 | */ |
| 1007 | wpa_s->global->p2p_go_wait_client.sec = 0; |
| 1008 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1009 | if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) { |
| 1010 | struct wpa_global *global; |
| 1011 | char *ifname; |
| 1012 | enum wpa_driver_if_type type; |
| 1013 | wpa_printf(MSG_DEBUG, "P2P: Remove group interface %s", |
| 1014 | wpa_s->ifname); |
| 1015 | global = wpa_s->global; |
| 1016 | ifname = os_strdup(wpa_s->ifname); |
| 1017 | type = wpas_p2p_if_type(wpa_s->p2p_group_interface); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1018 | eloop_cancel_timeout(run_wpas_p2p_disconnect, wpa_s, NULL); |
Dmitry Shmidt | e15c7b5 | 2011-08-03 15:04:35 -0700 | [diff] [blame] | 1019 | wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1020 | wpa_s = global->ifaces; |
| 1021 | if (wpa_s && ifname) |
| 1022 | wpa_drv_if_remove(wpa_s, type, ifname); |
| 1023 | os_free(ifname); |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 1024 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1027 | /* |
| 1028 | * The primary interface was used for P2P group operations, so |
| 1029 | * need to reset its p2pdev. |
| 1030 | */ |
| 1031 | wpa_s->p2pdev = wpa_s->parent; |
| 1032 | |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1033 | if (!wpa_s->p2p_go_group_formation_completed) { |
| 1034 | wpa_s->global->p2p_group_formation = NULL; |
| 1035 | wpa_s->p2p_in_provisioning = 0; |
| 1036 | } |
| 1037 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1038 | wpa_s->show_group_started = 0; |
| 1039 | os_free(wpa_s->go_params); |
| 1040 | wpa_s->go_params = NULL; |
| 1041 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1042 | os_free(wpa_s->p2p_group_common_freqs); |
| 1043 | wpa_s->p2p_group_common_freqs = NULL; |
| 1044 | wpa_s->p2p_group_common_freqs_num = 0; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1045 | wpa_s->p2p_go_do_acs = 0; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1046 | wpa_s->p2p_go_allow_dfs = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1047 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1048 | wpa_s->waiting_presence_resp = 0; |
| 1049 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1050 | wpa_printf(MSG_DEBUG, "P2P: Remove temporary group network"); |
| 1051 | if (ssid && (ssid->p2p_group || |
| 1052 | ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION || |
| 1053 | (ssid->key_mgmt & WPA_KEY_MGMT_WPS))) { |
| 1054 | int id = ssid->id; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1055 | if (ssid == wpa_s->current_ssid) { |
| 1056 | wpa_sm_set_config(wpa_s->wpa, NULL); |
| 1057 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1058 | wpa_s->current_ssid = NULL; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1059 | } |
| 1060 | /* |
| 1061 | * Networks objects created during any P2P activities are not |
| 1062 | * exposed out as they might/will confuse certain non-P2P aware |
| 1063 | * applications since these network objects won't behave like |
| 1064 | * regular ones. |
| 1065 | * |
| 1066 | * Likewise, we don't send out network removed signals for such |
| 1067 | * network objects. |
| 1068 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1069 | wpa_config_remove_network(wpa_s->conf, id); |
| 1070 | wpa_supplicant_clear_status(wpa_s); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1071 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1072 | } else { |
| 1073 | wpa_printf(MSG_DEBUG, "P2P: Temporary group network not " |
| 1074 | "found"); |
| 1075 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1076 | if (wpa_s->ap_iface) |
| 1077 | wpa_supplicant_ap_deinit(wpa_s); |
| 1078 | else |
| 1079 | wpa_drv_deinit_p2p_cli(wpa_s); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1080 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1081 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
| 1082 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1083 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | |
| 1087 | static int wpas_p2p_persistent_group(struct wpa_supplicant *wpa_s, |
| 1088 | u8 *go_dev_addr, |
| 1089 | const u8 *ssid, size_t ssid_len) |
| 1090 | { |
| 1091 | struct wpa_bss *bss; |
| 1092 | const u8 *bssid; |
| 1093 | struct wpabuf *p2p; |
| 1094 | u8 group_capab; |
| 1095 | const u8 *addr; |
| 1096 | |
| 1097 | if (wpa_s->go_params) |
| 1098 | bssid = wpa_s->go_params->peer_interface_addr; |
| 1099 | else |
| 1100 | bssid = wpa_s->bssid; |
| 1101 | |
| 1102 | bss = wpa_bss_get(wpa_s, bssid, ssid, ssid_len); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1103 | if (bss == NULL && wpa_s->go_params && |
| 1104 | !is_zero_ether_addr(wpa_s->go_params->peer_device_addr)) |
| 1105 | bss = wpa_bss_get_p2p_dev_addr( |
| 1106 | wpa_s, wpa_s->go_params->peer_device_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1107 | if (bss == NULL) { |
| 1108 | u8 iface_addr[ETH_ALEN]; |
| 1109 | if (p2p_get_interface_addr(wpa_s->global->p2p, bssid, |
| 1110 | iface_addr) == 0) |
| 1111 | bss = wpa_bss_get(wpa_s, iface_addr, ssid, ssid_len); |
| 1112 | } |
| 1113 | if (bss == NULL) { |
| 1114 | wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether " |
| 1115 | "group is persistent - BSS " MACSTR " not found", |
| 1116 | MAC2STR(bssid)); |
| 1117 | return 0; |
| 1118 | } |
| 1119 | |
| 1120 | p2p = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE); |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1121 | if (p2p == NULL) |
| 1122 | p2p = wpa_bss_get_vendor_ie_multi_beacon(bss, |
| 1123 | P2P_IE_VENDOR_TYPE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1124 | if (p2p == NULL) { |
| 1125 | wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether " |
| 1126 | "group is persistent - BSS " MACSTR |
| 1127 | " did not include P2P IE", MAC2STR(bssid)); |
| 1128 | wpa_hexdump(MSG_DEBUG, "P2P: Probe Response IEs", |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1129 | wpa_bss_ie_ptr(bss), bss->ie_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1130 | wpa_hexdump(MSG_DEBUG, "P2P: Beacon IEs", |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1131 | wpa_bss_ie_ptr(bss) + bss->ie_len, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1132 | bss->beacon_ie_len); |
| 1133 | return 0; |
| 1134 | } |
| 1135 | |
| 1136 | group_capab = p2p_get_group_capab(p2p); |
| 1137 | addr = p2p_get_go_dev_addr(p2p); |
| 1138 | wpa_printf(MSG_DEBUG, "P2P: Checking whether group is persistent: " |
| 1139 | "group_capab=0x%x", group_capab); |
| 1140 | if (addr) { |
| 1141 | os_memcpy(go_dev_addr, addr, ETH_ALEN); |
| 1142 | wpa_printf(MSG_DEBUG, "P2P: GO Device Address " MACSTR, |
| 1143 | MAC2STR(addr)); |
| 1144 | } else |
| 1145 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 1146 | wpabuf_free(p2p); |
| 1147 | |
| 1148 | wpa_printf(MSG_DEBUG, "P2P: BSS " MACSTR " group_capab=0x%x " |
| 1149 | "go_dev_addr=" MACSTR, |
| 1150 | MAC2STR(bssid), group_capab, MAC2STR(go_dev_addr)); |
| 1151 | |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 1152 | return !!(group_capab & P2P_GROUP_CAPAB_PERSISTENT_GROUP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1156 | static int wpas_p2p_store_persistent_group(struct wpa_supplicant *wpa_s, |
| 1157 | struct wpa_ssid *ssid, |
| 1158 | const u8 *go_dev_addr) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1159 | { |
| 1160 | struct wpa_ssid *s; |
| 1161 | int changed = 0; |
| 1162 | |
| 1163 | wpa_printf(MSG_DEBUG, "P2P: Storing credentials for a persistent " |
| 1164 | "group (GO Dev Addr " MACSTR ")", MAC2STR(go_dev_addr)); |
| 1165 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 1166 | if (s->disabled == 2 && |
| 1167 | os_memcmp(go_dev_addr, s->bssid, ETH_ALEN) == 0 && |
| 1168 | s->ssid_len == ssid->ssid_len && |
| 1169 | os_memcmp(ssid->ssid, s->ssid, ssid->ssid_len) == 0) |
| 1170 | break; |
| 1171 | } |
| 1172 | |
| 1173 | if (s) { |
| 1174 | wpa_printf(MSG_DEBUG, "P2P: Update existing persistent group " |
| 1175 | "entry"); |
| 1176 | if (ssid->passphrase && !s->passphrase) |
| 1177 | changed = 1; |
| 1178 | else if (ssid->passphrase && s->passphrase && |
| 1179 | os_strcmp(ssid->passphrase, s->passphrase) != 0) |
| 1180 | changed = 1; |
| 1181 | } else { |
| 1182 | wpa_printf(MSG_DEBUG, "P2P: Create a new persistent group " |
| 1183 | "entry"); |
| 1184 | changed = 1; |
| 1185 | s = wpa_config_add_network(wpa_s->conf); |
| 1186 | if (s == NULL) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1187 | return -1; |
| 1188 | |
| 1189 | /* |
| 1190 | * Instead of network_added we emit persistent_group_added |
| 1191 | * notification. Also to keep the defense checks in |
| 1192 | * persistent_group obj registration method, we set the |
| 1193 | * relevant flags in s to designate it as a persistent group. |
| 1194 | */ |
| 1195 | s->p2p_group = 1; |
| 1196 | s->p2p_persistent_group = 1; |
| 1197 | wpas_notify_persistent_group_added(wpa_s, s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1198 | wpa_config_set_network_defaults(s); |
| 1199 | } |
| 1200 | |
| 1201 | s->p2p_group = 1; |
| 1202 | s->p2p_persistent_group = 1; |
| 1203 | s->disabled = 2; |
| 1204 | s->bssid_set = 1; |
| 1205 | os_memcpy(s->bssid, go_dev_addr, ETH_ALEN); |
| 1206 | s->mode = ssid->mode; |
| 1207 | s->auth_alg = WPA_AUTH_ALG_OPEN; |
| 1208 | s->key_mgmt = WPA_KEY_MGMT_PSK; |
| 1209 | s->proto = WPA_PROTO_RSN; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1210 | s->pbss = ssid->pbss; |
| 1211 | s->pairwise_cipher = ssid->pbss ? WPA_CIPHER_GCMP : WPA_CIPHER_CCMP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1212 | s->export_keys = 1; |
| 1213 | if (ssid->passphrase) { |
| 1214 | os_free(s->passphrase); |
| 1215 | s->passphrase = os_strdup(ssid->passphrase); |
| 1216 | } |
| 1217 | if (ssid->psk_set) { |
| 1218 | s->psk_set = 1; |
| 1219 | os_memcpy(s->psk, ssid->psk, 32); |
| 1220 | } |
| 1221 | if (s->passphrase && !s->psk_set) |
| 1222 | wpa_config_update_psk(s); |
| 1223 | if (s->ssid == NULL || s->ssid_len < ssid->ssid_len) { |
| 1224 | os_free(s->ssid); |
| 1225 | s->ssid = os_malloc(ssid->ssid_len); |
| 1226 | } |
| 1227 | if (s->ssid) { |
| 1228 | s->ssid_len = ssid->ssid_len; |
| 1229 | os_memcpy(s->ssid, ssid->ssid, s->ssid_len); |
| 1230 | } |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1231 | if (ssid->mode == WPAS_MODE_P2P_GO && wpa_s->global->add_psk) { |
| 1232 | dl_list_add(&s->psk_list, &wpa_s->global->add_psk->list); |
| 1233 | wpa_s->global->add_psk = NULL; |
| 1234 | changed = 1; |
| 1235 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1236 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1237 | if (changed && wpa_s->conf->update_config && |
| 1238 | wpa_config_write(wpa_s->confname, wpa_s->conf)) { |
| 1239 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
| 1240 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1241 | |
| 1242 | return s->id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1246 | static void wpas_p2p_add_persistent_group_client(struct wpa_supplicant *wpa_s, |
| 1247 | const u8 *addr) |
| 1248 | { |
| 1249 | struct wpa_ssid *ssid, *s; |
| 1250 | u8 *n; |
| 1251 | size_t i; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1252 | int found = 0; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1253 | struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1254 | |
| 1255 | ssid = wpa_s->current_ssid; |
| 1256 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || |
| 1257 | !ssid->p2p_persistent_group) |
| 1258 | return; |
| 1259 | |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1260 | for (s = p2p_wpa_s->conf->ssid; s; s = s->next) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1261 | if (s->disabled != 2 || s->mode != WPAS_MODE_P2P_GO) |
| 1262 | continue; |
| 1263 | |
| 1264 | if (s->ssid_len == ssid->ssid_len && |
| 1265 | os_memcmp(s->ssid, ssid->ssid, s->ssid_len) == 0) |
| 1266 | break; |
| 1267 | } |
| 1268 | |
| 1269 | if (s == NULL) |
| 1270 | return; |
| 1271 | |
| 1272 | for (i = 0; s->p2p_client_list && i < s->num_p2p_clients; i++) { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1273 | if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN, addr, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1274 | ETH_ALEN) != 0) |
| 1275 | continue; |
| 1276 | |
| 1277 | if (i == s->num_p2p_clients - 1) |
| 1278 | return; /* already the most recent entry */ |
| 1279 | |
| 1280 | /* move the entry to mark it most recent */ |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1281 | os_memmove(s->p2p_client_list + i * 2 * ETH_ALEN, |
| 1282 | s->p2p_client_list + (i + 1) * 2 * ETH_ALEN, |
| 1283 | (s->num_p2p_clients - i - 1) * 2 * ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1284 | os_memcpy(s->p2p_client_list + |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1285 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN, addr, |
| 1286 | ETH_ALEN); |
| 1287 | os_memset(s->p2p_client_list + |
| 1288 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN + ETH_ALEN, |
| 1289 | 0xff, ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1290 | found = 1; |
| 1291 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1292 | } |
| 1293 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1294 | if (!found && s->num_p2p_clients < P2P_MAX_STORED_CLIENTS) { |
| 1295 | n = os_realloc_array(s->p2p_client_list, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1296 | s->num_p2p_clients + 1, 2 * ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1297 | if (n == NULL) |
| 1298 | return; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1299 | os_memcpy(n + s->num_p2p_clients * 2 * ETH_ALEN, addr, |
| 1300 | ETH_ALEN); |
| 1301 | os_memset(n + s->num_p2p_clients * 2 * ETH_ALEN + ETH_ALEN, |
| 1302 | 0xff, ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1303 | s->p2p_client_list = n; |
| 1304 | s->num_p2p_clients++; |
Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 1305 | } else if (!found && s->p2p_client_list) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1306 | /* Not enough room for an additional entry - drop the oldest |
| 1307 | * entry */ |
| 1308 | os_memmove(s->p2p_client_list, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1309 | s->p2p_client_list + 2 * ETH_ALEN, |
| 1310 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1311 | os_memcpy(s->p2p_client_list + |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1312 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1313 | addr, ETH_ALEN); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1314 | os_memset(s->p2p_client_list + |
| 1315 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN + ETH_ALEN, |
| 1316 | 0xff, ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1317 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1318 | |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1319 | if (p2p_wpa_s->conf->update_config && |
| 1320 | wpa_config_write(p2p_wpa_s->confname, p2p_wpa_s->conf)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1321 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1325 | static void wpas_p2p_group_started(struct wpa_supplicant *wpa_s, |
| 1326 | int go, struct wpa_ssid *ssid, int freq, |
| 1327 | const u8 *psk, const char *passphrase, |
| 1328 | const u8 *go_dev_addr, int persistent, |
| 1329 | const char *extra) |
| 1330 | { |
| 1331 | const char *ssid_txt; |
| 1332 | char psk_txt[65]; |
| 1333 | |
| 1334 | if (psk) |
| 1335 | wpa_snprintf_hex(psk_txt, sizeof(psk_txt), psk, 32); |
| 1336 | else |
| 1337 | psk_txt[0] = '\0'; |
| 1338 | |
| 1339 | if (ssid) |
| 1340 | ssid_txt = wpa_ssid_txt(ssid->ssid, ssid->ssid_len); |
| 1341 | else |
| 1342 | ssid_txt = ""; |
| 1343 | |
| 1344 | if (passphrase && passphrase[0] == '\0') |
| 1345 | passphrase = NULL; |
| 1346 | |
| 1347 | /* |
| 1348 | * Include PSK/passphrase only in the control interface message and |
| 1349 | * leave it out from the debug log entry. |
| 1350 | */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1351 | wpa_msg_global_ctrl(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1352 | P2P_EVENT_GROUP_STARTED |
| 1353 | "%s %s ssid=\"%s\" freq=%d%s%s%s%s%s go_dev_addr=" |
| 1354 | MACSTR "%s%s", |
| 1355 | wpa_s->ifname, go ? "GO" : "client", ssid_txt, freq, |
| 1356 | psk ? " psk=" : "", psk_txt, |
| 1357 | passphrase ? " passphrase=\"" : "", |
| 1358 | passphrase ? passphrase : "", |
| 1359 | passphrase ? "\"" : "", |
| 1360 | MAC2STR(go_dev_addr), |
| 1361 | persistent ? " [PERSISTENT]" : "", extra); |
| 1362 | wpa_printf(MSG_INFO, P2P_EVENT_GROUP_STARTED |
| 1363 | "%s %s ssid=\"%s\" freq=%d go_dev_addr=" MACSTR "%s%s", |
| 1364 | wpa_s->ifname, go ? "GO" : "client", ssid_txt, freq, |
| 1365 | MAC2STR(go_dev_addr), persistent ? " [PERSISTENT]" : "", |
| 1366 | extra); |
| 1367 | } |
| 1368 | |
| 1369 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1370 | static void wpas_group_formation_completed(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 1371 | int success, int already_deleted) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1372 | { |
| 1373 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1374 | int client; |
| 1375 | int persistent; |
| 1376 | u8 go_dev_addr[ETH_ALEN]; |
| 1377 | |
| 1378 | /* |
| 1379 | * This callback is likely called for the main interface. Update wpa_s |
| 1380 | * to use the group interface if a new interface was created for the |
| 1381 | * group. |
| 1382 | */ |
| 1383 | if (wpa_s->global->p2p_group_formation) |
| 1384 | wpa_s = wpa_s->global->p2p_group_formation; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1385 | if (wpa_s->p2p_go_group_formation_completed) { |
| 1386 | wpa_s->global->p2p_group_formation = NULL; |
| 1387 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1388 | } else if (wpa_s->p2p_in_provisioning && !success) { |
| 1389 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1390 | "P2P: Stop provisioning state due to failure"); |
| 1391 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1392 | } |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 1393 | wpa_s->p2p_in_invitation = 0; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame^] | 1394 | wpa_s->p2p_retry_limit = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1395 | wpa_s->group_formation_reported = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1396 | |
| 1397 | if (!success) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1398 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1399 | P2P_EVENT_GROUP_FORMATION_FAILURE); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1400 | wpas_notify_p2p_group_formation_failure(wpa_s, ""); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 1401 | if (already_deleted) |
| 1402 | return; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1403 | wpas_p2p_group_delete(wpa_s, |
| 1404 | P2P_GROUP_REMOVAL_FORMATION_FAILED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1405 | return; |
| 1406 | } |
| 1407 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1408 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1409 | P2P_EVENT_GROUP_FORMATION_SUCCESS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1410 | |
| 1411 | ssid = wpa_s->current_ssid; |
| 1412 | if (ssid && ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) { |
| 1413 | ssid->mode = WPAS_MODE_P2P_GO; |
| 1414 | p2p_group_notif_formation_done(wpa_s->p2p_group); |
| 1415 | wpa_supplicant_ap_mac_addr_filter(wpa_s, NULL); |
| 1416 | } |
| 1417 | |
| 1418 | persistent = 0; |
| 1419 | if (ssid) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1420 | client = ssid->mode == WPAS_MODE_INFRA; |
| 1421 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 1422 | persistent = ssid->p2p_persistent_group; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 1423 | os_memcpy(go_dev_addr, wpa_s->global->p2p_dev_addr, |
| 1424 | ETH_ALEN); |
George Burgess IV | 0d2d1bf | 2021-11-01 03:08:33 -0700 | [diff] [blame] | 1425 | } else { |
| 1426 | os_memset(go_dev_addr, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1427 | persistent = wpas_p2p_persistent_group(wpa_s, |
| 1428 | go_dev_addr, |
| 1429 | ssid->ssid, |
| 1430 | ssid->ssid_len); |
George Burgess IV | 0d2d1bf | 2021-11-01 03:08:33 -0700 | [diff] [blame] | 1431 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1432 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1433 | client = wpa_s->p2p_group_interface == |
| 1434 | P2P_GROUP_INTERFACE_CLIENT; |
| 1435 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 1436 | } |
| 1437 | |
| 1438 | wpa_s->show_group_started = 0; |
| 1439 | if (client) { |
| 1440 | /* |
| 1441 | * Indicate event only after successfully completed 4-way |
| 1442 | * handshake, i.e., when the interface is ready for data |
| 1443 | * packets. |
| 1444 | */ |
| 1445 | wpa_s->show_group_started = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1446 | } else { |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1447 | wpas_p2p_group_started(wpa_s, 1, ssid, |
| 1448 | ssid ? ssid->frequency : 0, |
| 1449 | ssid && ssid->passphrase == NULL && |
| 1450 | ssid->psk_set ? ssid->psk : NULL, |
| 1451 | ssid ? ssid->passphrase : NULL, |
| 1452 | go_dev_addr, persistent, ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1453 | wpas_p2p_cross_connect_setup(wpa_s); |
| 1454 | wpas_p2p_set_group_idle_timeout(wpa_s); |
| 1455 | } |
| 1456 | |
| 1457 | if (persistent) |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1458 | wpas_p2p_store_persistent_group(wpa_s->p2pdev, |
| 1459 | ssid, go_dev_addr); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1460 | else { |
| 1461 | os_free(wpa_s->global->add_psk); |
| 1462 | wpa_s->global->add_psk = NULL; |
| 1463 | } |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1464 | |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 1465 | if (!client) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1466 | wpas_notify_p2p_group_started(wpa_s, ssid, persistent, 0, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1467 | os_get_reltime(&wpa_s->global->p2p_go_wait_client); |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 1468 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1472 | struct send_action_work { |
| 1473 | unsigned int freq; |
| 1474 | u8 dst[ETH_ALEN]; |
| 1475 | u8 src[ETH_ALEN]; |
| 1476 | u8 bssid[ETH_ALEN]; |
| 1477 | size_t len; |
| 1478 | unsigned int wait_time; |
| 1479 | u8 buf[0]; |
| 1480 | }; |
| 1481 | |
| 1482 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1483 | static void wpas_p2p_free_send_action_work(struct wpa_supplicant *wpa_s) |
| 1484 | { |
| 1485 | struct send_action_work *awork = wpa_s->p2p_send_action_work->ctx; |
| 1486 | |
| 1487 | wpa_printf(MSG_DEBUG, |
| 1488 | "P2P: Free Action frame radio work @%p (freq=%u dst=" |
| 1489 | MACSTR " src=" MACSTR " bssid=" MACSTR " wait_time=%u)", |
| 1490 | wpa_s->p2p_send_action_work, awork->freq, |
| 1491 | MAC2STR(awork->dst), MAC2STR(awork->src), |
| 1492 | MAC2STR(awork->bssid), awork->wait_time); |
| 1493 | wpa_hexdump(MSG_DEBUG, "P2P: Freeing pending Action frame", |
| 1494 | awork->buf, awork->len); |
| 1495 | os_free(awork); |
| 1496 | wpa_s->p2p_send_action_work->ctx = NULL; |
| 1497 | radio_work_done(wpa_s->p2p_send_action_work); |
| 1498 | wpa_s->p2p_send_action_work = NULL; |
| 1499 | } |
| 1500 | |
| 1501 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1502 | static void wpas_p2p_send_action_work_timeout(void *eloop_ctx, |
| 1503 | void *timeout_ctx) |
| 1504 | { |
| 1505 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 1506 | |
| 1507 | if (!wpa_s->p2p_send_action_work) |
| 1508 | return; |
| 1509 | |
| 1510 | wpa_printf(MSG_DEBUG, "P2P: Send Action frame radio work timed out"); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1511 | wpas_p2p_free_send_action_work(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 1515 | static void wpas_p2p_action_tx_clear(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1516 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1517 | if (wpa_s->p2p_send_action_work) { |
| 1518 | struct send_action_work *awork; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1519 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1520 | awork = wpa_s->p2p_send_action_work->ctx; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1521 | wpa_printf(MSG_DEBUG, |
| 1522 | "P2P: Clear Action TX work @%p (wait_time=%u)", |
| 1523 | wpa_s->p2p_send_action_work, awork->wait_time); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1524 | if (awork->wait_time == 0) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1525 | wpas_p2p_free_send_action_work(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1526 | } else { |
| 1527 | /* |
| 1528 | * In theory, this should not be needed, but number of |
| 1529 | * places in the P2P code is still using non-zero wait |
| 1530 | * time for the last Action frame in the sequence and |
| 1531 | * some of these do not call send_action_done(). |
| 1532 | */ |
| 1533 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 1534 | wpa_s, NULL); |
| 1535 | eloop_register_timeout( |
| 1536 | 0, awork->wait_time * 1000, |
| 1537 | wpas_p2p_send_action_work_timeout, |
| 1538 | wpa_s, NULL); |
| 1539 | } |
| 1540 | } |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | |
| 1544 | static void wpas_p2p_send_action_tx_status(struct wpa_supplicant *wpa_s, |
| 1545 | unsigned int freq, |
| 1546 | const u8 *dst, const u8 *src, |
| 1547 | const u8 *bssid, |
| 1548 | const u8 *data, size_t data_len, |
| 1549 | enum offchannel_send_action_result |
| 1550 | result) |
| 1551 | { |
| 1552 | enum p2p_send_action_result res = P2P_SEND_ACTION_SUCCESS; |
| 1553 | |
| 1554 | wpas_p2p_action_tx_clear(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1555 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1556 | if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) |
| 1557 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1558 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1559 | switch (result) { |
| 1560 | case OFFCHANNEL_SEND_ACTION_SUCCESS: |
| 1561 | res = P2P_SEND_ACTION_SUCCESS; |
| 1562 | break; |
| 1563 | case OFFCHANNEL_SEND_ACTION_NO_ACK: |
| 1564 | res = P2P_SEND_ACTION_NO_ACK; |
| 1565 | break; |
| 1566 | case OFFCHANNEL_SEND_ACTION_FAILED: |
| 1567 | res = P2P_SEND_ACTION_FAILED; |
| 1568 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1571 | p2p_send_action_cb(wpa_s->global->p2p, freq, dst, src, bssid, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1572 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1573 | if (result != OFFCHANNEL_SEND_ACTION_SUCCESS && |
| 1574 | wpa_s->pending_pd_before_join && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1575 | (os_memcmp(dst, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 || |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1576 | os_memcmp(dst, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0) && |
| 1577 | wpa_s->p2p_fallback_to_go_neg) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1578 | wpa_s->pending_pd_before_join = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1579 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No ACK for PD Req " |
| 1580 | "during p2p_connect-auto"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1581 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1582 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 1583 | "reason=no-ACK-to-PD-Req"); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1584 | wpas_p2p_fallback_to_go_neg(wpa_s, 0); |
| 1585 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1586 | } |
| 1587 | } |
| 1588 | |
| 1589 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1590 | static void wpas_send_action_cb(struct wpa_radio_work *work, int deinit) |
| 1591 | { |
| 1592 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 1593 | struct send_action_work *awork = work->ctx; |
| 1594 | |
| 1595 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 1596 | if (work->started) { |
| 1597 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 1598 | wpa_s, NULL); |
| 1599 | wpa_s->p2p_send_action_work = NULL; |
| 1600 | offchannel_send_action_done(wpa_s); |
| 1601 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1602 | os_free(awork); |
| 1603 | return; |
| 1604 | } |
| 1605 | |
| 1606 | if (offchannel_send_action(wpa_s, awork->freq, awork->dst, awork->src, |
| 1607 | awork->bssid, awork->buf, awork->len, |
| 1608 | awork->wait_time, |
| 1609 | wpas_p2p_send_action_tx_status, 1) < 0) { |
| 1610 | os_free(awork); |
| 1611 | radio_work_done(work); |
| 1612 | return; |
| 1613 | } |
| 1614 | wpa_s->p2p_send_action_work = work; |
| 1615 | } |
| 1616 | |
| 1617 | |
| 1618 | static int wpas_send_action_work(struct wpa_supplicant *wpa_s, |
| 1619 | unsigned int freq, const u8 *dst, |
| 1620 | const u8 *src, const u8 *bssid, const u8 *buf, |
| 1621 | size_t len, unsigned int wait_time) |
| 1622 | { |
| 1623 | struct send_action_work *awork; |
| 1624 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1625 | if (radio_work_pending(wpa_s, "p2p-send-action")) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1626 | wpa_printf(MSG_DEBUG, "P2P: Cannot schedule new p2p-send-action work since one is already pending"); |
| 1627 | return -1; |
| 1628 | } |
| 1629 | |
| 1630 | awork = os_zalloc(sizeof(*awork) + len); |
| 1631 | if (awork == NULL) |
| 1632 | return -1; |
| 1633 | |
| 1634 | awork->freq = freq; |
| 1635 | os_memcpy(awork->dst, dst, ETH_ALEN); |
| 1636 | os_memcpy(awork->src, src, ETH_ALEN); |
| 1637 | os_memcpy(awork->bssid, bssid, ETH_ALEN); |
| 1638 | awork->len = len; |
| 1639 | awork->wait_time = wait_time; |
| 1640 | os_memcpy(awork->buf, buf, len); |
| 1641 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1642 | if (radio_add_work(wpa_s, freq, "p2p-send-action", 1, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1643 | wpas_send_action_cb, awork) < 0) { |
| 1644 | os_free(awork); |
| 1645 | return -1; |
| 1646 | } |
| 1647 | |
| 1648 | return 0; |
| 1649 | } |
| 1650 | |
| 1651 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1652 | static int wpas_send_action(void *ctx, unsigned int freq, const u8 *dst, |
| 1653 | const u8 *src, const u8 *bssid, const u8 *buf, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1654 | size_t len, unsigned int wait_time, int *scheduled) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1655 | { |
| 1656 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1657 | int listen_freq = -1, send_freq = -1; |
| 1658 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1659 | if (scheduled) |
| 1660 | *scheduled = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1661 | if (wpa_s->p2p_listen_work) |
| 1662 | listen_freq = wpa_s->p2p_listen_work->freq; |
| 1663 | if (wpa_s->p2p_send_action_work) |
| 1664 | send_freq = wpa_s->p2p_send_action_work->freq; |
| 1665 | if (listen_freq != (int) freq && send_freq != (int) freq) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1666 | int res; |
| 1667 | |
| 1668 | wpa_printf(MSG_DEBUG, "P2P: Schedule new radio work for Action frame TX (listen_freq=%d send_freq=%d freq=%u)", |
| 1669 | listen_freq, send_freq, freq); |
| 1670 | res = wpas_send_action_work(wpa_s, freq, dst, src, bssid, buf, |
| 1671 | len, wait_time); |
| 1672 | if (res == 0 && scheduled) |
| 1673 | *scheduled = 1; |
| 1674 | return res; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1675 | } |
| 1676 | |
| 1677 | wpa_printf(MSG_DEBUG, "P2P: Use ongoing radio work for Action frame TX"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1678 | return offchannel_send_action(wpa_s, freq, dst, src, bssid, buf, len, |
| 1679 | wait_time, |
| 1680 | wpas_p2p_send_action_tx_status, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | |
| 1684 | static void wpas_send_action_done(void *ctx) |
| 1685 | { |
| 1686 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1687 | |
| 1688 | if (wpa_s->p2p_send_action_work) { |
| 1689 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 1690 | wpa_s, NULL); |
| 1691 | os_free(wpa_s->p2p_send_action_work->ctx); |
| 1692 | radio_work_done(wpa_s->p2p_send_action_work); |
| 1693 | wpa_s->p2p_send_action_work = NULL; |
| 1694 | } |
| 1695 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1696 | offchannel_send_action_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
| 1699 | |
| 1700 | static int wpas_copy_go_neg_results(struct wpa_supplicant *wpa_s, |
| 1701 | struct p2p_go_neg_results *params) |
| 1702 | { |
| 1703 | if (wpa_s->go_params == NULL) { |
| 1704 | wpa_s->go_params = os_malloc(sizeof(*params)); |
| 1705 | if (wpa_s->go_params == NULL) |
| 1706 | return -1; |
| 1707 | } |
| 1708 | os_memcpy(wpa_s->go_params, params, sizeof(*params)); |
| 1709 | return 0; |
| 1710 | } |
| 1711 | |
| 1712 | |
| 1713 | static void wpas_start_wps_enrollee(struct wpa_supplicant *wpa_s, |
| 1714 | struct p2p_go_neg_results *res) |
| 1715 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1716 | wpa_s->group_formation_reported = 0; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1717 | wpa_printf(MSG_DEBUG, "P2P: Start WPS Enrollee for peer " MACSTR |
| 1718 | " dev_addr " MACSTR " wps_method %d", |
| 1719 | MAC2STR(res->peer_interface_addr), |
| 1720 | MAC2STR(res->peer_device_addr), res->wps_method); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1721 | wpa_hexdump_ascii(MSG_DEBUG, "P2P: Start WPS Enrollee for SSID", |
| 1722 | res->ssid, res->ssid_len); |
| 1723 | wpa_supplicant_ap_deinit(wpa_s); |
| 1724 | wpas_copy_go_neg_results(wpa_s, res); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1725 | if (res->wps_method == WPS_PBC) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1726 | wpas_wps_start_pbc(wpa_s, res->peer_interface_addr, 1, 0); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1727 | #ifdef CONFIG_WPS_NFC |
| 1728 | } else if (res->wps_method == WPS_NFC) { |
| 1729 | wpas_wps_start_nfc(wpa_s, res->peer_device_addr, |
| 1730 | res->peer_interface_addr, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1731 | wpa_s->p2pdev->p2p_oob_dev_pw, |
| 1732 | wpa_s->p2pdev->p2p_oob_dev_pw_id, 1, |
| 1733 | wpa_s->p2pdev->p2p_oob_dev_pw_id == |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1734 | DEV_PW_NFC_CONNECTION_HANDOVER ? |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1735 | wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1736 | NULL, |
| 1737 | NULL, 0, 0); |
| 1738 | #endif /* CONFIG_WPS_NFC */ |
| 1739 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1740 | u16 dev_pw_id = DEV_PW_DEFAULT; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1741 | if (wpa_s->p2p_wps_method == WPS_P2PS) |
| 1742 | dev_pw_id = DEV_PW_P2PS_DEFAULT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1743 | if (wpa_s->p2p_wps_method == WPS_PIN_KEYPAD) |
| 1744 | dev_pw_id = DEV_PW_REGISTRAR_SPECIFIED; |
| 1745 | wpas_wps_start_pin(wpa_s, res->peer_interface_addr, |
| 1746 | wpa_s->p2p_pin, 1, dev_pw_id); |
| 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1751 | static void wpas_p2p_add_psk_list(struct wpa_supplicant *wpa_s, |
| 1752 | struct wpa_ssid *ssid) |
| 1753 | { |
| 1754 | struct wpa_ssid *persistent; |
| 1755 | struct psk_list_entry *psk; |
| 1756 | struct hostapd_data *hapd; |
| 1757 | |
| 1758 | if (!wpa_s->ap_iface) |
| 1759 | return; |
| 1760 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1761 | persistent = wpas_p2p_get_persistent(wpa_s->p2pdev, NULL, ssid->ssid, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1762 | ssid->ssid_len); |
| 1763 | if (persistent == NULL) |
| 1764 | return; |
| 1765 | |
| 1766 | hapd = wpa_s->ap_iface->bss[0]; |
| 1767 | |
| 1768 | dl_list_for_each(psk, &persistent->psk_list, struct psk_list_entry, |
| 1769 | list) { |
| 1770 | struct hostapd_wpa_psk *hpsk; |
| 1771 | |
| 1772 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add persistent group PSK entry for " |
| 1773 | MACSTR " psk=%d", |
| 1774 | MAC2STR(psk->addr), psk->p2p); |
| 1775 | hpsk = os_zalloc(sizeof(*hpsk)); |
| 1776 | if (hpsk == NULL) |
| 1777 | break; |
| 1778 | os_memcpy(hpsk->psk, psk->psk, PMK_LEN); |
| 1779 | if (psk->p2p) |
| 1780 | os_memcpy(hpsk->p2p_dev_addr, psk->addr, ETH_ALEN); |
| 1781 | else |
| 1782 | os_memcpy(hpsk->addr, psk->addr, ETH_ALEN); |
| 1783 | hpsk->next = hapd->conf->ssid.wpa_psk; |
| 1784 | hapd->conf->ssid.wpa_psk = hpsk; |
| 1785 | } |
| 1786 | } |
| 1787 | |
| 1788 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1789 | static void p2p_go_dump_common_freqs(struct wpa_supplicant *wpa_s) |
| 1790 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1791 | char buf[20 + P2P_MAX_CHANNELS * 6]; |
| 1792 | char *pos, *end; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1793 | unsigned int i; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1794 | int res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1795 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1796 | pos = buf; |
| 1797 | end = pos + sizeof(buf); |
| 1798 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 1799 | res = os_snprintf(pos, end - pos, " %d", |
| 1800 | wpa_s->p2p_group_common_freqs[i]); |
| 1801 | if (os_snprintf_error(end - pos, res)) |
| 1802 | break; |
| 1803 | pos += res; |
| 1804 | } |
| 1805 | *pos = '\0'; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1806 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1807 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Common group frequencies:%s", buf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | |
| 1811 | static void p2p_go_save_group_common_freqs(struct wpa_supplicant *wpa_s, |
| 1812 | struct p2p_go_neg_results *params) |
| 1813 | { |
| 1814 | unsigned int i, len = int_array_len(wpa_s->go_params->freq_list); |
| 1815 | |
| 1816 | wpa_s->p2p_group_common_freqs_num = 0; |
| 1817 | os_free(wpa_s->p2p_group_common_freqs); |
| 1818 | wpa_s->p2p_group_common_freqs = os_calloc(len, sizeof(int)); |
| 1819 | if (!wpa_s->p2p_group_common_freqs) |
| 1820 | return; |
| 1821 | |
| 1822 | for (i = 0; i < len; i++) { |
| 1823 | if (!wpa_s->go_params->freq_list[i]) |
| 1824 | break; |
| 1825 | wpa_s->p2p_group_common_freqs[i] = |
| 1826 | wpa_s->go_params->freq_list[i]; |
| 1827 | } |
| 1828 | wpa_s->p2p_group_common_freqs_num = i; |
| 1829 | } |
| 1830 | |
| 1831 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1832 | static void p2p_config_write(struct wpa_supplicant *wpa_s) |
| 1833 | { |
| 1834 | #ifndef CONFIG_NO_CONFIG_WRITE |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1835 | if (wpa_s->p2pdev->conf->update_config && |
| 1836 | wpa_config_write(wpa_s->p2pdev->confname, wpa_s->p2pdev->conf)) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1837 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
| 1838 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 1839 | } |
| 1840 | |
| 1841 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1842 | static void p2p_go_configured(void *ctx, void *data) |
| 1843 | { |
| 1844 | struct wpa_supplicant *wpa_s = ctx; |
| 1845 | struct p2p_go_neg_results *params = data; |
| 1846 | struct wpa_ssid *ssid; |
| 1847 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 1848 | wpa_s->ap_configured_cb = NULL; |
| 1849 | wpa_s->ap_configured_cb_ctx = NULL; |
| 1850 | wpa_s->ap_configured_cb_data = NULL; |
| 1851 | if (!wpa_s->go_params) { |
| 1852 | wpa_printf(MSG_ERROR, |
| 1853 | "P2P: p2p_go_configured() called with wpa_s->go_params == NULL"); |
| 1854 | return; |
| 1855 | } |
| 1856 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1857 | p2p_go_save_group_common_freqs(wpa_s, params); |
| 1858 | p2p_go_dump_common_freqs(wpa_s); |
| 1859 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1860 | ssid = wpa_s->current_ssid; |
| 1861 | if (ssid && ssid->mode == WPAS_MODE_P2P_GO) { |
| 1862 | wpa_printf(MSG_DEBUG, "P2P: Group setup without provisioning"); |
| 1863 | if (wpa_s->global->p2p_group_formation == wpa_s) |
| 1864 | wpa_s->global->p2p_group_formation = NULL; |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1865 | wpas_p2p_group_started(wpa_s, 1, ssid, ssid->frequency, |
| 1866 | params->passphrase[0] == '\0' ? |
| 1867 | params->psk : NULL, |
| 1868 | params->passphrase, |
| 1869 | wpa_s->global->p2p_dev_addr, |
| 1870 | params->persistent_group, ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1871 | wpa_s->group_formation_reported = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1872 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1873 | if (wpa_s->p2pdev->p2ps_method_config_any) { |
| 1874 | if (is_zero_ether_addr(wpa_s->p2pdev->p2ps_join_addr)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1875 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1876 | "P2PS: Setting default PIN for ANY"); |
| 1877 | wpa_supplicant_ap_wps_pin(wpa_s, NULL, |
| 1878 | "12345670", NULL, 0, |
| 1879 | 0); |
| 1880 | } else { |
| 1881 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1882 | "P2PS: Setting default PIN for " MACSTR, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1883 | MAC2STR(wpa_s->p2pdev->p2ps_join_addr)); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1884 | wpa_supplicant_ap_wps_pin( |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1885 | wpa_s, wpa_s->p2pdev->p2ps_join_addr, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1886 | "12345670", NULL, 0, 0); |
| 1887 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1888 | wpa_s->p2pdev->p2ps_method_config_any = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1889 | } |
| 1890 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1891 | os_get_reltime(&wpa_s->global->p2p_go_wait_client); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1892 | if (params->persistent_group) { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1893 | wpas_p2p_store_persistent_group( |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1894 | wpa_s->p2pdev, ssid, |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 1895 | wpa_s->global->p2p_dev_addr); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1896 | wpas_p2p_add_psk_list(wpa_s, ssid); |
| 1897 | } |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1898 | |
| 1899 | wpas_notify_p2p_group_started(wpa_s, ssid, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1900 | params->persistent_group, 0, |
| 1901 | NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1902 | wpas_p2p_cross_connect_setup(wpa_s); |
| 1903 | wpas_p2p_set_group_idle_timeout(wpa_s); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1904 | |
| 1905 | if (wpa_s->p2p_first_connection_timeout) { |
| 1906 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1907 | "P2P: Start group formation timeout of %d seconds until first data connection on GO", |
| 1908 | wpa_s->p2p_first_connection_timeout); |
| 1909 | wpa_s->p2p_go_group_formation_completed = 0; |
| 1910 | wpa_s->global->p2p_group_formation = wpa_s; |
| 1911 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1912 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1913 | eloop_register_timeout( |
| 1914 | wpa_s->p2p_first_connection_timeout, 0, |
| 1915 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1916 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1917 | } |
| 1918 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1919 | return; |
| 1920 | } |
| 1921 | |
| 1922 | wpa_printf(MSG_DEBUG, "P2P: Setting up WPS for GO provisioning"); |
| 1923 | if (wpa_supplicant_ap_mac_addr_filter(wpa_s, |
| 1924 | params->peer_interface_addr)) { |
| 1925 | wpa_printf(MSG_DEBUG, "P2P: Failed to setup MAC address " |
| 1926 | "filtering"); |
| 1927 | return; |
| 1928 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1929 | if (params->wps_method == WPS_PBC) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1930 | wpa_supplicant_ap_wps_pbc(wpa_s, params->peer_interface_addr, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1931 | params->peer_device_addr); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1932 | #ifdef CONFIG_WPS_NFC |
| 1933 | } else if (params->wps_method == WPS_NFC) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1934 | if (wpa_s->p2pdev->p2p_oob_dev_pw_id != |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1935 | DEV_PW_NFC_CONNECTION_HANDOVER && |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1936 | !wpa_s->p2pdev->p2p_oob_dev_pw) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1937 | wpa_printf(MSG_DEBUG, "P2P: No NFC Dev Pw known"); |
| 1938 | return; |
| 1939 | } |
| 1940 | wpas_ap_wps_add_nfc_pw( |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1941 | wpa_s, wpa_s->p2pdev->p2p_oob_dev_pw_id, |
| 1942 | wpa_s->p2pdev->p2p_oob_dev_pw, |
| 1943 | wpa_s->p2pdev->p2p_peer_oob_pk_hash_known ? |
| 1944 | wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : NULL); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1945 | #endif /* CONFIG_WPS_NFC */ |
| 1946 | } else if (wpa_s->p2p_pin[0]) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1947 | wpa_supplicant_ap_wps_pin(wpa_s, params->peer_interface_addr, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1948 | wpa_s->p2p_pin, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1949 | os_free(wpa_s->go_params); |
| 1950 | wpa_s->go_params = NULL; |
| 1951 | } |
| 1952 | |
| 1953 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1954 | /** |
| 1955 | * wpas_p2p_freq_to_edmg_channel - Convert frequency into EDMG channel |
| 1956 | * @freq: Frequency (MHz) to convert |
| 1957 | * @op_class: Buffer for returning operating class |
| 1958 | * @op_edmg_channel: Buffer for returning channel number |
| 1959 | * Returns: 0 on success, -1 on failure |
| 1960 | * |
| 1961 | * This can be used to find the highest channel bonding which includes the |
| 1962 | * specified frequency. |
| 1963 | */ |
| 1964 | static int wpas_p2p_freq_to_edmg_channel(struct wpa_supplicant *wpa_s, |
| 1965 | unsigned int freq, |
| 1966 | u8 *op_class, u8 *op_edmg_channel) |
| 1967 | { |
| 1968 | struct hostapd_hw_modes *hwmode; |
| 1969 | struct ieee80211_edmg_config edmg; |
| 1970 | unsigned int i; |
| 1971 | enum chan_width chanwidth[] = { |
| 1972 | CHAN_WIDTH_8640, |
| 1973 | CHAN_WIDTH_6480, |
| 1974 | CHAN_WIDTH_4320, |
| 1975 | }; |
| 1976 | |
| 1977 | if (!wpa_s->hw.modes) |
| 1978 | return -1; |
| 1979 | |
| 1980 | hwmode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1981 | HOSTAPD_MODE_IEEE80211AD, false); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1982 | if (!hwmode) { |
| 1983 | wpa_printf(MSG_ERROR, |
| 1984 | "Unsupported AP mode: HOSTAPD_MODE_IEEE80211AD"); |
| 1985 | return -1; |
| 1986 | } |
| 1987 | |
| 1988 | /* Find the highest EDMG channel bandwidth to start the P2P GO */ |
| 1989 | for (i = 0; i < ARRAY_SIZE(chanwidth); i++) { |
| 1990 | if (ieee80211_chaninfo_to_channel(freq, chanwidth[i], 0, |
| 1991 | op_class, |
| 1992 | op_edmg_channel) < 0) |
| 1993 | continue; |
| 1994 | |
| 1995 | hostapd_encode_edmg_chan(1, *op_edmg_channel, 0, &edmg); |
| 1996 | if (edmg.channels && |
| 1997 | ieee802_edmg_is_allowed(hwmode->edmg, edmg)) { |
| 1998 | wpa_printf(MSG_DEBUG, |
| 1999 | "Freq %u to EDMG channel %u at opclass %u", |
| 2000 | freq, *op_edmg_channel, *op_class); |
| 2001 | return 0; |
| 2002 | } |
| 2003 | } |
| 2004 | |
| 2005 | return -1; |
| 2006 | } |
| 2007 | |
| 2008 | |
| 2009 | int wpas_p2p_try_edmg_channel(struct wpa_supplicant *wpa_s, |
| 2010 | struct p2p_go_neg_results *params) |
| 2011 | { |
| 2012 | u8 op_channel, op_class; |
| 2013 | int freq; |
| 2014 | |
| 2015 | /* Try social channel as primary channel frequency */ |
| 2016 | freq = (!params->freq) ? 58320 + 1 * 2160 : params->freq; |
| 2017 | |
| 2018 | if (wpas_p2p_freq_to_edmg_channel(wpa_s, freq, &op_class, |
| 2019 | &op_channel) == 0) { |
| 2020 | wpa_printf(MSG_DEBUG, |
| 2021 | "Freq %d will be used to set an EDMG connection (channel=%u opclass=%u)", |
| 2022 | freq, op_channel, op_class); |
| 2023 | params->freq = freq; |
| 2024 | return 0; |
| 2025 | } |
| 2026 | |
| 2027 | return -1; |
| 2028 | } |
| 2029 | |
| 2030 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2031 | static void wpas_start_wps_go(struct wpa_supplicant *wpa_s, |
| 2032 | struct p2p_go_neg_results *params, |
| 2033 | int group_formation) |
| 2034 | { |
| 2035 | struct wpa_ssid *ssid; |
| 2036 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2037 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Starting GO"); |
| 2038 | if (wpas_copy_go_neg_results(wpa_s, params) < 0) { |
| 2039 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not copy GO Negotiation " |
| 2040 | "results"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2041 | return; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2042 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2043 | |
| 2044 | ssid = wpa_config_add_network(wpa_s->conf); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2045 | if (ssid == NULL) { |
| 2046 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not add network for GO"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2047 | return; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2048 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2049 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2050 | wpa_s->show_group_started = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2051 | wpa_s->p2p_go_group_formation_completed = 0; |
| 2052 | wpa_s->group_formation_reported = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2053 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2054 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2055 | wpa_config_set_network_defaults(ssid); |
| 2056 | ssid->temporary = 1; |
| 2057 | ssid->p2p_group = 1; |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 2058 | ssid->p2p_persistent_group = !!params->persistent_group; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2059 | ssid->mode = group_formation ? WPAS_MODE_P2P_GROUP_FORMATION : |
| 2060 | WPAS_MODE_P2P_GO; |
| 2061 | ssid->frequency = params->freq; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2062 | ssid->ht40 = params->ht40; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2063 | ssid->vht = params->vht; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 2064 | ssid->max_oper_chwidth = params->max_oper_chwidth; |
| 2065 | ssid->vht_center_freq2 = params->vht_center_freq2; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2066 | ssid->he = params->he; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2067 | if (params->edmg) { |
| 2068 | u8 op_channel, op_class; |
| 2069 | |
| 2070 | if (!wpas_p2p_freq_to_edmg_channel(wpa_s, params->freq, |
| 2071 | &op_class, &op_channel)) { |
| 2072 | ssid->edmg_channel = op_channel; |
| 2073 | ssid->enable_edmg = params->edmg; |
| 2074 | } else { |
| 2075 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2076 | "P2P: Could not match EDMG channel, freq %d, for GO", |
| 2077 | params->freq); |
| 2078 | } |
| 2079 | } |
| 2080 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2081 | ssid->ssid = os_zalloc(params->ssid_len + 1); |
| 2082 | if (ssid->ssid) { |
| 2083 | os_memcpy(ssid->ssid, params->ssid, params->ssid_len); |
| 2084 | ssid->ssid_len = params->ssid_len; |
| 2085 | } |
| 2086 | ssid->auth_alg = WPA_AUTH_ALG_OPEN; |
| 2087 | ssid->key_mgmt = WPA_KEY_MGMT_PSK; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2088 | if (is_6ghz_freq(ssid->frequency) && |
| 2089 | is_p2p_6ghz_capable(wpa_s->global->p2p)) { |
| 2090 | ssid->auth_alg |= WPA_AUTH_ALG_SAE; |
| 2091 | ssid->key_mgmt = WPA_KEY_MGMT_SAE; |
| 2092 | ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED; |
| 2093 | ssid->sae_pwe = 1; |
| 2094 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use SAE auth_alg and key_mgmt"); |
| 2095 | } else { |
| 2096 | p2p_set_6ghz_dev_capab(wpa_s->global->p2p, false); |
| 2097 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2098 | ssid->proto = WPA_PROTO_RSN; |
| 2099 | ssid->pairwise_cipher = WPA_CIPHER_CCMP; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2100 | ssid->group_cipher = WPA_CIPHER_CCMP; |
| 2101 | if (params->freq > 56160) { |
| 2102 | /* |
| 2103 | * Enable GCMP instead of CCMP as pairwise_cipher and |
| 2104 | * group_cipher in 60 GHz. |
| 2105 | */ |
| 2106 | ssid->pairwise_cipher = WPA_CIPHER_GCMP; |
| 2107 | ssid->group_cipher = WPA_CIPHER_GCMP; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2108 | /* P2P GO in 60 GHz is always a PCP (PBSS) */ |
| 2109 | ssid->pbss = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2110 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2111 | if (os_strlen(params->passphrase) > 0) { |
| 2112 | ssid->passphrase = os_strdup(params->passphrase); |
| 2113 | if (ssid->passphrase == NULL) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2114 | wpa_msg_global(wpa_s, MSG_ERROR, |
| 2115 | "P2P: Failed to copy passphrase for GO"); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2116 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 2117 | return; |
| 2118 | } |
| 2119 | } else |
| 2120 | ssid->passphrase = NULL; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2121 | ssid->psk_set = params->psk_set; |
| 2122 | if (ssid->psk_set) |
| 2123 | os_memcpy(ssid->psk, params->psk, sizeof(ssid->psk)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2124 | else if (ssid->passphrase) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2125 | wpa_config_update_psk(ssid); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2126 | ssid->ap_max_inactivity = wpa_s->p2pdev->conf->p2p_go_max_inactivity; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2127 | |
| 2128 | wpa_s->ap_configured_cb = p2p_go_configured; |
| 2129 | wpa_s->ap_configured_cb_ctx = wpa_s; |
| 2130 | wpa_s->ap_configured_cb_data = wpa_s->go_params; |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 2131 | wpa_s->scan_req = NORMAL_SCAN_REQ; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2132 | wpa_s->connect_without_scan = ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2133 | wpa_s->reassociate = 1; |
| 2134 | wpa_s->disconnected = 0; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2135 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Request scan (that will be skipped) to " |
| 2136 | "start GO)"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2137 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 2138 | } |
| 2139 | |
| 2140 | |
| 2141 | static void wpas_p2p_clone_config(struct wpa_supplicant *dst, |
| 2142 | const struct wpa_supplicant *src) |
| 2143 | { |
| 2144 | struct wpa_config *d; |
| 2145 | const struct wpa_config *s; |
| 2146 | |
| 2147 | d = dst->conf; |
| 2148 | s = src->conf; |
| 2149 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2150 | #define C(n) \ |
| 2151 | do { \ |
| 2152 | if (s->n && !d->n) \ |
| 2153 | d->n = os_strdup(s->n); \ |
| 2154 | } while (0) |
| 2155 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2156 | C(device_name); |
| 2157 | C(manufacturer); |
| 2158 | C(model_name); |
| 2159 | C(model_number); |
| 2160 | C(serial_number); |
| 2161 | C(config_methods); |
| 2162 | #undef C |
| 2163 | |
| 2164 | os_memcpy(d->device_type, s->device_type, WPS_DEV_TYPE_LEN); |
| 2165 | os_memcpy(d->sec_device_type, s->sec_device_type, |
| 2166 | sizeof(d->sec_device_type)); |
| 2167 | d->num_sec_device_types = s->num_sec_device_types; |
| 2168 | |
| 2169 | d->p2p_group_idle = s->p2p_group_idle; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2170 | d->p2p_go_freq_change_policy = s->p2p_go_freq_change_policy; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2171 | d->p2p_intra_bss = s->p2p_intra_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2172 | d->persistent_reconnect = s->persistent_reconnect; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2173 | d->max_num_sta = s->max_num_sta; |
| 2174 | d->pbc_in_m1 = s->pbc_in_m1; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2175 | d->ignore_old_scan_res = s->ignore_old_scan_res; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 2176 | d->beacon_int = s->beacon_int; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2177 | d->dtim_period = s->dtim_period; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2178 | d->p2p_go_ctwindow = s->p2p_go_ctwindow; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2179 | d->disassoc_low_ack = s->disassoc_low_ack; |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 2180 | d->disable_scan_offload = s->disable_scan_offload; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2181 | d->passive_scan = s->passive_scan; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2182 | d->pmf = s->pmf; |
| 2183 | d->p2p_6ghz_disable = s->p2p_6ghz_disable; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2184 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2185 | if (s->wps_nfc_dh_privkey && s->wps_nfc_dh_pubkey && |
| 2186 | !d->wps_nfc_pw_from_config) { |
| 2187 | wpabuf_free(d->wps_nfc_dh_privkey); |
| 2188 | wpabuf_free(d->wps_nfc_dh_pubkey); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2189 | d->wps_nfc_dh_privkey = wpabuf_dup(s->wps_nfc_dh_privkey); |
| 2190 | d->wps_nfc_dh_pubkey = wpabuf_dup(s->wps_nfc_dh_pubkey); |
| 2191 | } |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2192 | d->p2p_cli_probe = s->p2p_cli_probe; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2193 | d->go_interworking = s->go_interworking; |
| 2194 | d->go_access_network_type = s->go_access_network_type; |
| 2195 | d->go_internet = s->go_internet; |
| 2196 | d->go_venue_group = s->go_venue_group; |
| 2197 | d->go_venue_type = s->go_venue_type; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2198 | d->p2p_add_cli_chan = s->p2p_add_cli_chan; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2202 | static void wpas_p2p_get_group_ifname(struct wpa_supplicant *wpa_s, |
| 2203 | char *ifname, size_t len) |
| 2204 | { |
| 2205 | char *ifname_ptr = wpa_s->ifname; |
| 2206 | |
| 2207 | if (os_strncmp(wpa_s->ifname, P2P_MGMT_DEVICE_PREFIX, |
| 2208 | os_strlen(P2P_MGMT_DEVICE_PREFIX)) == 0) { |
| 2209 | ifname_ptr = os_strrchr(wpa_s->ifname, '-') + 1; |
| 2210 | } |
| 2211 | |
| 2212 | os_snprintf(ifname, len, "p2p-%s-%d", ifname_ptr, wpa_s->p2p_group_idx); |
| 2213 | if (os_strlen(ifname) >= IFNAMSIZ && |
| 2214 | os_strlen(wpa_s->ifname) < IFNAMSIZ) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2215 | int res; |
| 2216 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2217 | /* Try to avoid going over the IFNAMSIZ length limit */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2218 | res = os_snprintf(ifname, len, "p2p-%d", wpa_s->p2p_group_idx); |
| 2219 | if (os_snprintf_error(len, res) && len) |
| 2220 | ifname[len - 1] = '\0'; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2221 | } |
| 2222 | } |
| 2223 | |
| 2224 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2225 | static int wpas_p2p_add_group_interface(struct wpa_supplicant *wpa_s, |
| 2226 | enum wpa_driver_if_type type) |
| 2227 | { |
| 2228 | char ifname[120], force_ifname[120]; |
| 2229 | |
| 2230 | if (wpa_s->pending_interface_name[0]) { |
| 2231 | wpa_printf(MSG_DEBUG, "P2P: Pending virtual interface exists " |
| 2232 | "- skip creation of a new one"); |
| 2233 | if (is_zero_ether_addr(wpa_s->pending_interface_addr)) { |
| 2234 | wpa_printf(MSG_DEBUG, "P2P: Pending virtual address " |
| 2235 | "unknown?! ifname='%s'", |
| 2236 | wpa_s->pending_interface_name); |
| 2237 | return -1; |
| 2238 | } |
| 2239 | return 0; |
| 2240 | } |
| 2241 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2242 | wpas_p2p_get_group_ifname(wpa_s, ifname, sizeof(ifname)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2243 | force_ifname[0] = '\0'; |
| 2244 | |
| 2245 | wpa_printf(MSG_DEBUG, "P2P: Create a new interface %s for the group", |
| 2246 | ifname); |
| 2247 | wpa_s->p2p_group_idx++; |
| 2248 | |
| 2249 | wpa_s->pending_interface_type = type; |
| 2250 | if (wpa_drv_if_add(wpa_s, type, ifname, NULL, NULL, force_ifname, |
| 2251 | wpa_s->pending_interface_addr, NULL) < 0) { |
| 2252 | wpa_printf(MSG_ERROR, "P2P: Failed to create new group " |
| 2253 | "interface"); |
| 2254 | return -1; |
| 2255 | } |
| 2256 | |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2257 | if (wpa_s->conf->p2p_interface_random_mac_addr) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2258 | random_mac_addr(wpa_s->pending_interface_addr); |
| 2259 | wpa_printf(MSG_DEBUG, "P2P: Generate random MAC address " MACSTR |
| 2260 | " for the group", |
| 2261 | MAC2STR(wpa_s->pending_interface_addr)); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2262 | } |
| 2263 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2264 | if (force_ifname[0]) { |
| 2265 | wpa_printf(MSG_DEBUG, "P2P: Driver forced interface name %s", |
| 2266 | force_ifname); |
| 2267 | os_strlcpy(wpa_s->pending_interface_name, force_ifname, |
| 2268 | sizeof(wpa_s->pending_interface_name)); |
| 2269 | } else |
| 2270 | os_strlcpy(wpa_s->pending_interface_name, ifname, |
| 2271 | sizeof(wpa_s->pending_interface_name)); |
| 2272 | wpa_printf(MSG_DEBUG, "P2P: Created pending virtual interface %s addr " |
| 2273 | MACSTR, wpa_s->pending_interface_name, |
| 2274 | MAC2STR(wpa_s->pending_interface_addr)); |
| 2275 | |
| 2276 | return 0; |
| 2277 | } |
| 2278 | |
| 2279 | |
| 2280 | static void wpas_p2p_remove_pending_group_interface( |
| 2281 | struct wpa_supplicant *wpa_s) |
| 2282 | { |
| 2283 | if (!wpa_s->pending_interface_name[0] || |
| 2284 | is_zero_ether_addr(wpa_s->pending_interface_addr)) |
| 2285 | return; /* No pending virtual interface */ |
| 2286 | |
| 2287 | wpa_printf(MSG_DEBUG, "P2P: Removing pending group interface %s", |
| 2288 | wpa_s->pending_interface_name); |
| 2289 | wpa_drv_if_remove(wpa_s, wpa_s->pending_interface_type, |
| 2290 | wpa_s->pending_interface_name); |
| 2291 | os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN); |
| 2292 | wpa_s->pending_interface_name[0] = '\0'; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2293 | wpa_s->global->pending_group_iface_for_p2ps = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | |
| 2297 | static struct wpa_supplicant * |
| 2298 | wpas_p2p_init_group_interface(struct wpa_supplicant *wpa_s, int go) |
| 2299 | { |
| 2300 | struct wpa_interface iface; |
| 2301 | struct wpa_supplicant *group_wpa_s; |
| 2302 | |
| 2303 | if (!wpa_s->pending_interface_name[0]) { |
| 2304 | wpa_printf(MSG_ERROR, "P2P: No pending group interface"); |
| 2305 | if (!wpas_p2p_create_iface(wpa_s)) |
| 2306 | return NULL; |
| 2307 | /* |
| 2308 | * Something has forced us to remove the pending interface; try |
| 2309 | * to create a new one and hope for the best that we will get |
| 2310 | * the same local address. |
| 2311 | */ |
| 2312 | if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO : |
| 2313 | WPA_IF_P2P_CLIENT) < 0) |
| 2314 | return NULL; |
| 2315 | } |
| 2316 | |
| 2317 | os_memset(&iface, 0, sizeof(iface)); |
| 2318 | iface.ifname = wpa_s->pending_interface_name; |
| 2319 | iface.driver = wpa_s->driver->name; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2320 | if (wpa_s->conf->ctrl_interface == NULL && |
| 2321 | wpa_s->parent != wpa_s && |
| 2322 | wpa_s->p2p_mgmt && |
| 2323 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) |
| 2324 | iface.ctrl_interface = wpa_s->parent->conf->ctrl_interface; |
| 2325 | else |
| 2326 | iface.ctrl_interface = wpa_s->conf->ctrl_interface; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2327 | iface.driver_param = wpa_s->conf->driver_param; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 2328 | group_wpa_s = wpa_supplicant_add_iface(wpa_s->global, &iface, wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2329 | if (group_wpa_s == NULL) { |
| 2330 | wpa_printf(MSG_ERROR, "P2P: Failed to create new " |
| 2331 | "wpa_supplicant interface"); |
| 2332 | return NULL; |
| 2333 | } |
| 2334 | wpa_s->pending_interface_name[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2335 | group_wpa_s->p2p_group_interface = go ? P2P_GROUP_INTERFACE_GO : |
| 2336 | P2P_GROUP_INTERFACE_CLIENT; |
| 2337 | wpa_s->global->p2p_group_formation = group_wpa_s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2338 | wpa_s->global->pending_group_iface_for_p2ps = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2339 | |
| 2340 | wpas_p2p_clone_config(group_wpa_s, wpa_s); |
| 2341 | |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2342 | if (wpa_s->conf->p2p_interface_random_mac_addr) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2343 | if (wpa_drv_set_mac_addr(group_wpa_s, |
| 2344 | wpa_s->pending_interface_addr) < 0) { |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2345 | wpa_msg(group_wpa_s, MSG_INFO, |
| 2346 | "Failed to set random MAC address"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2347 | wpa_supplicant_remove_iface(wpa_s->global, group_wpa_s, |
| 2348 | 0); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2349 | return NULL; |
| 2350 | } |
| 2351 | |
| 2352 | if (wpa_supplicant_update_mac_addr(group_wpa_s) < 0) { |
| 2353 | wpa_msg(group_wpa_s, MSG_INFO, |
| 2354 | "Could not update MAC address information"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2355 | wpa_supplicant_remove_iface(wpa_s->global, group_wpa_s, |
| 2356 | 0); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2357 | return NULL; |
| 2358 | } |
| 2359 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2360 | wpa_printf(MSG_DEBUG, "P2P: Using random MAC address " MACSTR |
| 2361 | " for the group", |
| 2362 | MAC2STR(wpa_s->pending_interface_addr)); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2363 | } |
| 2364 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2365 | return group_wpa_s; |
| 2366 | } |
| 2367 | |
| 2368 | |
| 2369 | static void wpas_p2p_group_formation_timeout(void *eloop_ctx, |
| 2370 | void *timeout_ctx) |
| 2371 | { |
| 2372 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 2373 | wpa_printf(MSG_DEBUG, "P2P: Group Formation timed out"); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2374 | wpas_p2p_group_formation_failed(wpa_s, 0); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2378 | static void wpas_p2p_group_formation_failed(struct wpa_supplicant *wpa_s, |
| 2379 | int already_deleted) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2380 | { |
| 2381 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2382 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2383 | if (wpa_s->global->p2p) |
| 2384 | p2p_group_formation_failed(wpa_s->global->p2p); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2385 | wpas_group_formation_completed(wpa_s, 0, already_deleted); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2386 | } |
| 2387 | |
| 2388 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2389 | static void wpas_p2p_grpform_fail_after_wps(struct wpa_supplicant *wpa_s) |
| 2390 | { |
| 2391 | wpa_printf(MSG_DEBUG, "P2P: Reject group formation due to WPS provisioning failure"); |
| 2392 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2393 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2394 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2395 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2396 | wpa_s->global->p2p_fail_on_wps_complete = 0; |
| 2397 | } |
| 2398 | |
| 2399 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2400 | void wpas_p2p_ap_setup_failed(struct wpa_supplicant *wpa_s) |
| 2401 | { |
| 2402 | if (wpa_s->global->p2p_group_formation != wpa_s) |
| 2403 | return; |
| 2404 | /* Speed up group formation timeout since this cannot succeed */ |
| 2405 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2406 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2407 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2408 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2409 | } |
| 2410 | |
| 2411 | |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame^] | 2412 | bool wpas_p2p_retry_limit_exceeded(struct wpa_supplicant *wpa_s) |
| 2413 | { |
| 2414 | if (!wpa_s->p2p_in_invitation || !wpa_s->p2p_retry_limit || |
| 2415 | wpa_s->p2p_in_invitation <= wpa_s->p2p_retry_limit) { |
| 2416 | return false; |
| 2417 | } |
| 2418 | wpa_printf(MSG_DEBUG, "P2P: Group join retry limit exceeded"); |
| 2419 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
| 2420 | wpa_s->p2pdev, NULL); |
| 2421 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
| 2422 | wpa_s->p2pdev, NULL); |
| 2423 | return true; |
| 2424 | } |
| 2425 | |
| 2426 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2427 | static void wpas_go_neg_completed(void *ctx, struct p2p_go_neg_results *res) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2428 | { |
| 2429 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2430 | struct wpa_supplicant *group_wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2431 | |
| 2432 | if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) { |
| 2433 | wpa_drv_cancel_remain_on_channel(wpa_s); |
| 2434 | wpa_s->off_channel_freq = 0; |
| 2435 | wpa_s->roc_waiting_drv_freq = 0; |
| 2436 | } |
| 2437 | |
| 2438 | if (res->status) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2439 | wpa_msg_global(wpa_s, MSG_INFO, |
| 2440 | P2P_EVENT_GO_NEG_FAILURE "status=%d", |
| 2441 | res->status); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2442 | wpas_notify_p2p_go_neg_completed(wpa_s, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2443 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 2444 | return; |
| 2445 | } |
| 2446 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2447 | if (!res->role_go) { |
| 2448 | /* Inform driver of the operating channel of GO. */ |
| 2449 | wpa_drv_set_prob_oper_freq(wpa_s, res->freq); |
| 2450 | } |
| 2451 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2452 | if (wpa_s->p2p_go_ht40) |
| 2453 | res->ht40 = 1; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2454 | if (wpa_s->p2p_go_vht) |
| 2455 | res->vht = 1; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2456 | if (wpa_s->p2p_go_he) |
| 2457 | res->he = 1; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2458 | if (wpa_s->p2p_go_edmg) |
| 2459 | res->edmg = 1; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 2460 | res->max_oper_chwidth = wpa_s->p2p_go_max_oper_chwidth; |
| 2461 | res->vht_center_freq2 = wpa_s->p2p_go_vht_center_freq2; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2462 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2463 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_SUCCESS "role=%s " |
| 2464 | "freq=%d ht40=%d peer_dev=" MACSTR " peer_iface=" MACSTR |
| 2465 | " wps_method=%s", |
| 2466 | res->role_go ? "GO" : "client", res->freq, res->ht40, |
| 2467 | MAC2STR(res->peer_device_addr), |
| 2468 | MAC2STR(res->peer_interface_addr), |
| 2469 | p2p_wps_method_text(res->wps_method)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2470 | wpas_notify_p2p_go_neg_completed(wpa_s, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2471 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2472 | if (res->role_go && wpa_s->p2p_persistent_id >= 0) { |
| 2473 | struct wpa_ssid *ssid; |
| 2474 | ssid = wpa_config_get_network(wpa_s->conf, |
| 2475 | wpa_s->p2p_persistent_id); |
| 2476 | if (ssid && ssid->disabled == 2 && |
| 2477 | ssid->mode == WPAS_MODE_P2P_GO && ssid->passphrase) { |
| 2478 | size_t len = os_strlen(ssid->passphrase); |
| 2479 | wpa_printf(MSG_DEBUG, "P2P: Override passphrase based " |
| 2480 | "on requested persistent group"); |
| 2481 | os_memcpy(res->passphrase, ssid->passphrase, len); |
| 2482 | res->passphrase[len] = '\0'; |
| 2483 | } |
| 2484 | } |
| 2485 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2486 | if (wpa_s->create_p2p_iface) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2487 | group_wpa_s = |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2488 | wpas_p2p_init_group_interface(wpa_s, res->role_go); |
| 2489 | if (group_wpa_s == NULL) { |
| 2490 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 2491 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, |
| 2492 | wpa_s, NULL); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2493 | wpas_p2p_group_formation_failed(wpa_s, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2494 | return; |
| 2495 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2496 | os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN); |
| 2497 | wpa_s->pending_interface_name[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2498 | } else { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2499 | group_wpa_s = wpa_s->parent; |
| 2500 | wpa_s->global->p2p_group_formation = group_wpa_s; |
| 2501 | if (group_wpa_s != wpa_s) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2502 | wpas_p2p_clone_config(group_wpa_s, wpa_s); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2503 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2504 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2505 | group_wpa_s->p2p_in_provisioning = 1; |
| 2506 | group_wpa_s->p2pdev = wpa_s; |
| 2507 | if (group_wpa_s != wpa_s) { |
| 2508 | os_memcpy(group_wpa_s->p2p_pin, wpa_s->p2p_pin, |
| 2509 | sizeof(group_wpa_s->p2p_pin)); |
| 2510 | group_wpa_s->p2p_wps_method = wpa_s->p2p_wps_method; |
| 2511 | } |
| 2512 | if (res->role_go) { |
| 2513 | wpas_start_wps_go(group_wpa_s, res, 1); |
| 2514 | } else { |
| 2515 | os_get_reltime(&group_wpa_s->scan_min_time); |
| 2516 | wpas_start_wps_enrollee(group_wpa_s, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2517 | } |
| 2518 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2519 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2520 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
| 2521 | |
| 2522 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 2523 | eloop_register_timeout(15 + res->peer_config_timeout / 100, |
| 2524 | (res->peer_config_timeout % 100) * 10000, |
| 2525 | wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 2526 | } |
| 2527 | |
| 2528 | |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 2529 | static void wpas_go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id, |
| 2530 | u8 go_intent) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2531 | { |
| 2532 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2533 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_REQUEST MACSTR |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 2534 | " dev_passwd_id=%u go_intent=%u", MAC2STR(src), |
| 2535 | dev_passwd_id, go_intent); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2536 | |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 2537 | wpas_notify_p2p_go_neg_req(wpa_s, src, dev_passwd_id, go_intent); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2541 | static void wpas_dev_found(void *ctx, const u8 *addr, |
| 2542 | const struct p2p_peer_info *info, |
| 2543 | int new_device) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2544 | { |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2545 | u8 *wfd_dev_info = NULL; |
| 2546 | u8 wfd_dev_info_len = 0; |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2547 | u8 *wfd_r2_dev_info = NULL; |
Jimmy Chen | 57e19f5 | 2021-03-04 14:19:52 +0800 | [diff] [blame] | 2548 | u8 wfd_r2_dev_info_len = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2549 | #ifndef CONFIG_NO_STDOUT_DEBUG |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2550 | struct wpa_supplicant *wpa_s = ctx; |
| 2551 | char devtype[WPS_DEV_TYPE_BUFSIZE]; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2552 | char *wfd_dev_info_hex = NULL; |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2553 | char *wfd_r2_dev_info_hex = NULL; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2554 | |
Irfan Sheriff | 8367dc9 | 2012-09-09 17:08:19 -0700 | [diff] [blame] | 2555 | #ifdef CONFIG_WIFI_DISPLAY |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2556 | wfd_dev_info_hex = wifi_display_subelem_hex(info->wfd_subelems, |
| 2557 | WFD_SUBELEM_DEVICE_INFO); |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2558 | if (wfd_dev_info_hex) { |
| 2559 | wfd_dev_info_len = strlen(wfd_dev_info_hex) / 2; |
| 2560 | wfd_dev_info = os_zalloc(wfd_dev_info_len); |
| 2561 | // Only used for notification, so not handling error. |
| 2562 | hexstr2bin(wfd_dev_info_hex, wfd_dev_info, wfd_dev_info_len); |
| 2563 | } |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2564 | |
| 2565 | wfd_r2_dev_info_hex = wifi_display_subelem_hex(info->wfd_subelems, |
| 2566 | WFD_SUBELEM_R2_DEVICE_INFO); |
| 2567 | if (wfd_r2_dev_info_hex) { |
| 2568 | wfd_r2_dev_info_len = strlen(wfd_r2_dev_info_hex) / 2; |
| 2569 | wfd_r2_dev_info = os_zalloc(wfd_r2_dev_info_len); |
| 2570 | // Only used for notification, so not handling error. |
| 2571 | hexstr2bin(wfd_r2_dev_info_hex, wfd_r2_dev_info, wfd_r2_dev_info_len); |
| 2572 | } |
Irfan Sheriff | 8367dc9 | 2012-09-09 17:08:19 -0700 | [diff] [blame] | 2573 | #endif /* CONFIG_WIFI_DISPLAY */ |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2574 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2575 | if (info->p2ps_instance) { |
| 2576 | char str[256]; |
| 2577 | const u8 *buf = wpabuf_head(info->p2ps_instance); |
| 2578 | size_t len = wpabuf_len(info->p2ps_instance); |
| 2579 | |
| 2580 | while (len) { |
| 2581 | u32 id; |
| 2582 | u16 methods; |
| 2583 | u8 str_len; |
| 2584 | |
| 2585 | if (len < 4 + 2 + 1) |
| 2586 | break; |
| 2587 | id = WPA_GET_LE32(buf); |
| 2588 | buf += sizeof(u32); |
| 2589 | methods = WPA_GET_BE16(buf); |
| 2590 | buf += sizeof(u16); |
| 2591 | str_len = *buf++; |
| 2592 | if (str_len > len - 4 - 2 - 1) |
| 2593 | break; |
| 2594 | os_memcpy(str, buf, str_len); |
| 2595 | str[str_len] = '\0'; |
| 2596 | buf += str_len; |
| 2597 | len -= str_len + sizeof(u32) + sizeof(u16) + sizeof(u8); |
| 2598 | |
| 2599 | wpa_msg_global(wpa_s, MSG_INFO, |
| 2600 | P2P_EVENT_DEVICE_FOUND MACSTR |
| 2601 | " p2p_dev_addr=" MACSTR |
| 2602 | " pri_dev_type=%s name='%s'" |
| 2603 | " config_methods=0x%x" |
| 2604 | " dev_capab=0x%x" |
| 2605 | " group_capab=0x%x" |
| 2606 | " adv_id=%x asp_svc=%s%s", |
| 2607 | MAC2STR(addr), |
| 2608 | MAC2STR(info->p2p_device_addr), |
| 2609 | wps_dev_type_bin2str( |
| 2610 | info->pri_dev_type, |
| 2611 | devtype, sizeof(devtype)), |
| 2612 | info->device_name, methods, |
| 2613 | info->dev_capab, info->group_capab, |
| 2614 | id, str, |
| 2615 | info->vendor_elems ? |
| 2616 | " vendor_elems=1" : ""); |
| 2617 | } |
| 2618 | goto done; |
| 2619 | } |
| 2620 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2621 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_FOUND MACSTR |
| 2622 | " p2p_dev_addr=" MACSTR |
| 2623 | " pri_dev_type=%s name='%s' config_methods=0x%x " |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2624 | "dev_capab=0x%x group_capab=0x%x%s%s%s%s%s new=%d", |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2625 | MAC2STR(addr), MAC2STR(info->p2p_device_addr), |
| 2626 | wps_dev_type_bin2str(info->pri_dev_type, devtype, |
| 2627 | sizeof(devtype)), |
| 2628 | info->device_name, info->config_methods, |
| 2629 | info->dev_capab, info->group_capab, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2630 | wfd_dev_info_hex ? " wfd_dev_info=0x" : "", |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 2631 | wfd_dev_info_hex ? wfd_dev_info_hex : "", |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2632 | wfd_r2_dev_info_hex ? " wfd_r2_dev_info=0x" : "", |
| 2633 | wfd_r2_dev_info_hex ? wfd_r2_dev_info_hex : "", |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2634 | info->vendor_elems ? " vendor_elems=1" : "", |
| 2635 | new_device); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2636 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2637 | done: |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2638 | os_free(wfd_dev_info_hex); |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2639 | os_free(wfd_r2_dev_info_hex); |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 2640 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2641 | |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2642 | wpas_notify_p2p_device_found(ctx, addr, info, wfd_dev_info, |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2643 | wfd_dev_info_len, wfd_r2_dev_info, |
| 2644 | wfd_r2_dev_info_len, new_device); |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2645 | os_free(wfd_dev_info); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2646 | } |
| 2647 | |
| 2648 | |
| 2649 | static void wpas_dev_lost(void *ctx, const u8 *dev_addr) |
| 2650 | { |
| 2651 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2652 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2653 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_LOST |
| 2654 | "p2p_dev_addr=" MACSTR, MAC2STR(dev_addr)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2655 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2656 | wpas_notify_p2p_device_lost(wpa_s, dev_addr); |
| 2657 | } |
| 2658 | |
| 2659 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2660 | static void wpas_find_stopped(void *ctx) |
| 2661 | { |
| 2662 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2663 | |
| 2664 | if (wpa_s->p2p_scan_work && wpas_abort_ongoing_scan(wpa_s) < 0) |
| 2665 | wpa_printf(MSG_DEBUG, "P2P: Abort ongoing scan failed"); |
| 2666 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2667 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_FIND_STOPPED); |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 2668 | wpas_notify_p2p_find_stopped(wpa_s); |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2672 | struct wpas_p2p_listen_work { |
| 2673 | unsigned int freq; |
| 2674 | unsigned int duration; |
| 2675 | struct wpabuf *probe_resp_ie; |
| 2676 | }; |
| 2677 | |
| 2678 | |
| 2679 | static void wpas_p2p_listen_work_free(struct wpas_p2p_listen_work *lwork) |
| 2680 | { |
| 2681 | if (lwork == NULL) |
| 2682 | return; |
| 2683 | wpabuf_free(lwork->probe_resp_ie); |
| 2684 | os_free(lwork); |
| 2685 | } |
| 2686 | |
| 2687 | |
| 2688 | static void wpas_p2p_listen_work_done(struct wpa_supplicant *wpa_s) |
| 2689 | { |
| 2690 | struct wpas_p2p_listen_work *lwork; |
| 2691 | |
| 2692 | if (!wpa_s->p2p_listen_work) |
| 2693 | return; |
| 2694 | |
| 2695 | lwork = wpa_s->p2p_listen_work->ctx; |
| 2696 | wpas_p2p_listen_work_free(lwork); |
| 2697 | radio_work_done(wpa_s->p2p_listen_work); |
| 2698 | wpa_s->p2p_listen_work = NULL; |
| 2699 | } |
| 2700 | |
| 2701 | |
| 2702 | static void wpas_start_listen_cb(struct wpa_radio_work *work, int deinit) |
| 2703 | { |
| 2704 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 2705 | struct wpas_p2p_listen_work *lwork = work->ctx; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2706 | unsigned int duration; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2707 | |
| 2708 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 2709 | if (work->started) { |
| 2710 | wpa_s->p2p_listen_work = NULL; |
| 2711 | wpas_stop_listen(wpa_s); |
| 2712 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2713 | wpas_p2p_listen_work_free(lwork); |
| 2714 | return; |
| 2715 | } |
| 2716 | |
| 2717 | wpa_s->p2p_listen_work = work; |
| 2718 | |
| 2719 | wpa_drv_set_ap_wps_ie(wpa_s, NULL, lwork->probe_resp_ie, NULL); |
| 2720 | |
| 2721 | if (wpa_drv_probe_req_report(wpa_s, 1) < 0) { |
| 2722 | wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver to " |
| 2723 | "report received Probe Request frames"); |
| 2724 | wpas_p2p_listen_work_done(wpa_s); |
| 2725 | return; |
| 2726 | } |
| 2727 | |
| 2728 | wpa_s->pending_listen_freq = lwork->freq; |
| 2729 | wpa_s->pending_listen_duration = lwork->duration; |
| 2730 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2731 | duration = lwork->duration; |
| 2732 | #ifdef CONFIG_TESTING_OPTIONS |
| 2733 | if (wpa_s->extra_roc_dur) { |
| 2734 | wpa_printf(MSG_DEBUG, "TESTING: Increase ROC duration %u -> %u", |
| 2735 | duration, duration + wpa_s->extra_roc_dur); |
| 2736 | duration += wpa_s->extra_roc_dur; |
| 2737 | } |
| 2738 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2739 | |
| 2740 | if (wpa_drv_remain_on_channel(wpa_s, lwork->freq, duration) < 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2741 | wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver " |
| 2742 | "to remain on channel (%u MHz) for Listen " |
| 2743 | "state", lwork->freq); |
| 2744 | wpas_p2p_listen_work_done(wpa_s); |
| 2745 | wpa_s->pending_listen_freq = 0; |
| 2746 | return; |
| 2747 | } |
| 2748 | wpa_s->off_channel_freq = 0; |
| 2749 | wpa_s->roc_waiting_drv_freq = lwork->freq; |
| 2750 | } |
| 2751 | |
| 2752 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2753 | static int wpas_start_listen(void *ctx, unsigned int freq, |
| 2754 | unsigned int duration, |
| 2755 | const struct wpabuf *probe_resp_ie) |
| 2756 | { |
| 2757 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2758 | struct wpas_p2p_listen_work *lwork; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2759 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2760 | if (wpa_s->p2p_listen_work) { |
| 2761 | wpa_printf(MSG_DEBUG, "P2P: Reject start_listen since p2p_listen_work already exists"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2762 | return -1; |
| 2763 | } |
| 2764 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2765 | lwork = os_zalloc(sizeof(*lwork)); |
| 2766 | if (lwork == NULL) |
| 2767 | return -1; |
| 2768 | lwork->freq = freq; |
| 2769 | lwork->duration = duration; |
| 2770 | if (probe_resp_ie) { |
| 2771 | lwork->probe_resp_ie = wpabuf_dup(probe_resp_ie); |
| 2772 | if (lwork->probe_resp_ie == NULL) { |
| 2773 | wpas_p2p_listen_work_free(lwork); |
| 2774 | return -1; |
| 2775 | } |
| 2776 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2777 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2778 | if (radio_add_work(wpa_s, freq, "p2p-listen", 0, wpas_start_listen_cb, |
| 2779 | lwork) < 0) { |
| 2780 | wpas_p2p_listen_work_free(lwork); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2781 | return -1; |
| 2782 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2783 | |
| 2784 | return 0; |
| 2785 | } |
| 2786 | |
| 2787 | |
| 2788 | static void wpas_stop_listen(void *ctx) |
| 2789 | { |
| 2790 | struct wpa_supplicant *wpa_s = ctx; |
| 2791 | if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) { |
| 2792 | wpa_drv_cancel_remain_on_channel(wpa_s); |
| 2793 | wpa_s->off_channel_freq = 0; |
| 2794 | wpa_s->roc_waiting_drv_freq = 0; |
| 2795 | } |
| 2796 | wpa_drv_set_ap_wps_ie(wpa_s, NULL, NULL, NULL); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2797 | |
| 2798 | /* |
| 2799 | * Don't cancel Probe Request RX reporting for a connected P2P Client |
| 2800 | * handling Probe Request frames. |
| 2801 | */ |
| 2802 | if (!wpa_s->p2p_cli_probe) |
| 2803 | wpa_drv_probe_req_report(wpa_s, 0); |
| 2804 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2805 | wpas_p2p_listen_work_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2806 | } |
| 2807 | |
| 2808 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2809 | static int wpas_send_probe_resp(void *ctx, const struct wpabuf *buf, |
| 2810 | unsigned int freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2811 | { |
| 2812 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2813 | return wpa_drv_send_mlme(wpa_s, wpabuf_head(buf), wpabuf_len(buf), 1, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2814 | freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2818 | static void wpas_prov_disc_local_display(struct wpa_supplicant *wpa_s, |
| 2819 | const u8 *peer, const char *params, |
| 2820 | unsigned int generated_pin) |
| 2821 | { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2822 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR |
| 2823 | " %08d%s", MAC2STR(peer), generated_pin, params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | |
| 2827 | static void wpas_prov_disc_local_keypad(struct wpa_supplicant *wpa_s, |
| 2828 | const u8 *peer, const char *params) |
| 2829 | { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2830 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR |
| 2831 | "%s", MAC2STR(peer), params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2835 | static void wpas_prov_disc_req(void *ctx, const u8 *peer, u16 config_methods, |
| 2836 | const u8 *dev_addr, const u8 *pri_dev_type, |
| 2837 | const char *dev_name, u16 supp_config_methods, |
| 2838 | u8 dev_capab, u8 group_capab, const u8 *group_id, |
| 2839 | size_t group_id_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2840 | { |
| 2841 | struct wpa_supplicant *wpa_s = ctx; |
| 2842 | char devtype[WPS_DEV_TYPE_BUFSIZE]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2843 | char params[300]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2844 | u8 empty_dev_type[8]; |
| 2845 | unsigned int generated_pin = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2846 | struct wpa_supplicant *group = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2847 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2848 | |
| 2849 | if (group_id) { |
| 2850 | for (group = wpa_s->global->ifaces; group; group = group->next) |
| 2851 | { |
| 2852 | struct wpa_ssid *s = group->current_ssid; |
| 2853 | if (s != NULL && |
| 2854 | s->mode == WPAS_MODE_P2P_GO && |
| 2855 | group_id_len - ETH_ALEN == s->ssid_len && |
| 2856 | os_memcmp(group_id + ETH_ALEN, s->ssid, |
| 2857 | s->ssid_len) == 0) |
| 2858 | break; |
| 2859 | } |
| 2860 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2861 | |
| 2862 | if (pri_dev_type == NULL) { |
| 2863 | os_memset(empty_dev_type, 0, sizeof(empty_dev_type)); |
| 2864 | pri_dev_type = empty_dev_type; |
| 2865 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2866 | res = os_snprintf(params, sizeof(params), " p2p_dev_addr=" MACSTR |
| 2867 | " pri_dev_type=%s name='%s' config_methods=0x%x " |
| 2868 | "dev_capab=0x%x group_capab=0x%x%s%s", |
| 2869 | MAC2STR(dev_addr), |
| 2870 | wps_dev_type_bin2str(pri_dev_type, devtype, |
| 2871 | sizeof(devtype)), |
| 2872 | dev_name, supp_config_methods, dev_capab, group_capab, |
| 2873 | group ? " group=" : "", |
| 2874 | group ? group->ifname : ""); |
| 2875 | if (os_snprintf_error(sizeof(params), res)) |
| 2876 | wpa_printf(MSG_DEBUG, "P2P: PD Request event truncated"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2877 | params[sizeof(params) - 1] = '\0'; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2878 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2879 | if (config_methods & WPS_CONFIG_DISPLAY) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2880 | if (wps_generate_pin(&generated_pin) < 0) { |
| 2881 | wpa_printf(MSG_DEBUG, "P2P: Could not generate PIN"); |
| 2882 | wpas_notify_p2p_provision_discovery( |
| 2883 | wpa_s, peer, 0 /* response */, |
| 2884 | P2P_PROV_DISC_INFO_UNAVAILABLE, 0, 0); |
| 2885 | return; |
| 2886 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2887 | wpas_prov_disc_local_display(wpa_s, peer, params, |
| 2888 | generated_pin); |
| 2889 | } else if (config_methods & WPS_CONFIG_KEYPAD) |
| 2890 | wpas_prov_disc_local_keypad(wpa_s, peer, params); |
| 2891 | else if (config_methods & WPS_CONFIG_PUSHBUTTON) |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2892 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_REQ |
| 2893 | MACSTR "%s", MAC2STR(peer), params); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2894 | |
| 2895 | wpas_notify_p2p_provision_discovery(wpa_s, peer, 1 /* request */, |
| 2896 | P2P_PROV_DISC_SUCCESS, |
| 2897 | config_methods, generated_pin); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2898 | } |
| 2899 | |
| 2900 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2901 | static void wpas_prov_disc_resp(void *ctx, const u8 *peer, u16 config_methods) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2902 | { |
| 2903 | struct wpa_supplicant *wpa_s = ctx; |
| 2904 | unsigned int generated_pin = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2905 | char params[20]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2906 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2907 | if (wpa_s->pending_pd_before_join && |
| 2908 | (os_memcmp(peer, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 || |
| 2909 | os_memcmp(peer, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0)) { |
| 2910 | wpa_s->pending_pd_before_join = 0; |
| 2911 | wpa_printf(MSG_DEBUG, "P2P: Starting pending " |
| 2912 | "join-existing-group operation"); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2913 | wpas_p2p_join_start(wpa_s, 0, NULL, 0); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2914 | return; |
| 2915 | } |
| 2916 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2917 | if (wpa_s->pending_pd_use == AUTO_PD_JOIN || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2918 | wpa_s->pending_pd_use == AUTO_PD_GO_NEG) { |
| 2919 | int res; |
| 2920 | |
| 2921 | res = os_snprintf(params, sizeof(params), " peer_go=%d", |
| 2922 | wpa_s->pending_pd_use == AUTO_PD_JOIN); |
| 2923 | if (os_snprintf_error(sizeof(params), res)) |
| 2924 | params[sizeof(params) - 1] = '\0'; |
| 2925 | } else |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2926 | params[0] = '\0'; |
| 2927 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2928 | if (config_methods & WPS_CONFIG_DISPLAY) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2929 | wpas_prov_disc_local_keypad(wpa_s, peer, params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2930 | else if (config_methods & WPS_CONFIG_KEYPAD) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2931 | if (wps_generate_pin(&generated_pin) < 0) { |
| 2932 | wpa_printf(MSG_DEBUG, "P2P: Could not generate PIN"); |
| 2933 | wpas_notify_p2p_provision_discovery( |
| 2934 | wpa_s, peer, 0 /* response */, |
| 2935 | P2P_PROV_DISC_INFO_UNAVAILABLE, 0, 0); |
| 2936 | return; |
| 2937 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2938 | wpas_prov_disc_local_display(wpa_s, peer, params, |
| 2939 | generated_pin); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2940 | } else if (config_methods & WPS_CONFIG_PUSHBUTTON) |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2941 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_RESP |
| 2942 | MACSTR "%s", MAC2STR(peer), params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2943 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2944 | wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */, |
| 2945 | P2P_PROV_DISC_SUCCESS, |
| 2946 | config_methods, generated_pin); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2950 | static void wpas_prov_disc_fail(void *ctx, const u8 *peer, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2951 | enum p2p_prov_disc_status status, |
| 2952 | u32 adv_id, const u8 *adv_mac, |
| 2953 | const char *deferred_session_resp) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2954 | { |
| 2955 | struct wpa_supplicant *wpa_s = ctx; |
| 2956 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2957 | if (wpa_s->p2p_fallback_to_go_neg) { |
| 2958 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: PD for p2p_connect-auto " |
| 2959 | "failed - fall back to GO Negotiation"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2960 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2961 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 2962 | "reason=PD-failed"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2963 | wpas_p2p_fallback_to_go_neg(wpa_s, 0); |
| 2964 | return; |
| 2965 | } |
| 2966 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2967 | if (status == P2P_PROV_DISC_TIMEOUT_JOIN) { |
Dmitry Shmidt | 2b38048 | 2012-09-13 10:52:13 -0700 | [diff] [blame] | 2968 | wpa_s->pending_pd_before_join = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2969 | wpa_printf(MSG_DEBUG, "P2P: Starting pending " |
| 2970 | "join-existing-group operation (no ACK for PD " |
| 2971 | "Req attempts)"); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2972 | wpas_p2p_join_start(wpa_s, 0, NULL, 0); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2973 | return; |
Dmitry Shmidt | 2b38048 | 2012-09-13 10:52:13 -0700 | [diff] [blame] | 2974 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2975 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2976 | if (adv_id && adv_mac && deferred_session_resp) { |
| 2977 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE |
| 2978 | " p2p_dev_addr=" MACSTR " status=%d adv_id=%x" |
| 2979 | " deferred_session_resp='%s'", |
| 2980 | MAC2STR(peer), status, adv_id, |
| 2981 | deferred_session_resp); |
| 2982 | } else if (adv_id && adv_mac) { |
| 2983 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE |
| 2984 | " p2p_dev_addr=" MACSTR " status=%d adv_id=%x", |
| 2985 | MAC2STR(peer), status, adv_id); |
| 2986 | } else { |
| 2987 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE |
| 2988 | " p2p_dev_addr=" MACSTR " status=%d", |
| 2989 | MAC2STR(peer), status); |
| 2990 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2991 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2992 | wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */, |
| 2993 | status, 0, 0); |
| 2994 | } |
| 2995 | |
| 2996 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2997 | static int freq_included(struct wpa_supplicant *wpa_s, |
| 2998 | const struct p2p_channels *channels, |
| 2999 | unsigned int freq) |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3000 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3001 | if ((channels == NULL || p2p_channels_includes_freq(channels, freq)) && |
| 3002 | wpas_p2p_go_is_peer_freq(wpa_s, freq)) |
| 3003 | return 1; |
| 3004 | return 0; |
| 3005 | } |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3006 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3007 | |
| 3008 | static void wpas_p2p_go_update_common_freqs(struct wpa_supplicant *wpa_s) |
| 3009 | { |
| 3010 | unsigned int num = P2P_MAX_CHANNELS; |
| 3011 | int *common_freqs; |
| 3012 | int ret; |
| 3013 | |
| 3014 | p2p_go_dump_common_freqs(wpa_s); |
| 3015 | common_freqs = os_calloc(num, sizeof(int)); |
| 3016 | if (!common_freqs) |
| 3017 | return; |
| 3018 | |
| 3019 | ret = p2p_group_get_common_freqs(wpa_s->p2p_group, common_freqs, &num); |
| 3020 | if (ret < 0) { |
| 3021 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 3022 | "P2P: Failed to get group common freqs"); |
| 3023 | os_free(common_freqs); |
| 3024 | return; |
| 3025 | } |
| 3026 | |
| 3027 | os_free(wpa_s->p2p_group_common_freqs); |
| 3028 | wpa_s->p2p_group_common_freqs = common_freqs; |
| 3029 | wpa_s->p2p_group_common_freqs_num = num; |
| 3030 | p2p_go_dump_common_freqs(wpa_s); |
| 3031 | } |
| 3032 | |
| 3033 | |
| 3034 | /* |
| 3035 | * Check if the given frequency is one of the possible operating frequencies |
| 3036 | * set after the completion of the GO Negotiation. |
| 3037 | */ |
| 3038 | static int wpas_p2p_go_is_peer_freq(struct wpa_supplicant *wpa_s, int freq) |
| 3039 | { |
| 3040 | unsigned int i; |
| 3041 | |
| 3042 | p2p_go_dump_common_freqs(wpa_s); |
| 3043 | |
| 3044 | /* assume no restrictions */ |
| 3045 | if (!wpa_s->p2p_group_common_freqs_num) |
| 3046 | return 1; |
| 3047 | |
| 3048 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 3049 | if (wpa_s->p2p_group_common_freqs[i] == freq) |
| 3050 | return 1; |
| 3051 | } |
| 3052 | return 0; |
| 3053 | } |
| 3054 | |
| 3055 | |
| 3056 | static int wpas_sta_check_ecsa(struct hostapd_data *hapd, |
| 3057 | struct sta_info *sta, void *ctx) |
| 3058 | { |
| 3059 | int *ecsa_support = ctx; |
| 3060 | |
| 3061 | *ecsa_support &= sta->ecsa_supported; |
| 3062 | |
| 3063 | return 0; |
| 3064 | } |
| 3065 | |
| 3066 | |
| 3067 | /* Check if all the peers support eCSA */ |
| 3068 | static int wpas_p2p_go_clients_support_ecsa(struct wpa_supplicant *wpa_s) |
| 3069 | { |
| 3070 | int ecsa_support = 1; |
| 3071 | |
| 3072 | ap_for_each_sta(wpa_s->ap_iface->bss[0], wpas_sta_check_ecsa, |
| 3073 | &ecsa_support); |
| 3074 | |
| 3075 | return ecsa_support; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3076 | } |
| 3077 | |
| 3078 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3079 | /** |
| 3080 | * Pick the best frequency to use from all the currently used frequencies. |
| 3081 | */ |
| 3082 | static int wpas_p2p_pick_best_used_freq(struct wpa_supplicant *wpa_s, |
| 3083 | struct wpa_used_freq_data *freqs, |
| 3084 | unsigned int num) |
| 3085 | { |
| 3086 | unsigned int i, c; |
| 3087 | |
| 3088 | /* find a candidate freq that is supported by P2P */ |
| 3089 | for (c = 0; c < num; c++) |
| 3090 | if (p2p_supported_freq(wpa_s->global->p2p, freqs[c].freq)) |
| 3091 | break; |
| 3092 | |
| 3093 | if (c == num) |
| 3094 | return 0; |
| 3095 | |
| 3096 | /* once we have a candidate, try to find a 'better' one */ |
| 3097 | for (i = c + 1; i < num; i++) { |
| 3098 | if (!p2p_supported_freq(wpa_s->global->p2p, freqs[i].freq)) |
| 3099 | continue; |
| 3100 | |
| 3101 | /* |
| 3102 | * 1. Infrastructure station interfaces have higher preference. |
| 3103 | * 2. P2P Clients have higher preference. |
| 3104 | * 3. All others. |
| 3105 | */ |
| 3106 | if (freqs[i].flags & WPA_FREQ_USED_BY_INFRA_STATION) { |
| 3107 | c = i; |
| 3108 | break; |
| 3109 | } |
| 3110 | |
| 3111 | if ((freqs[i].flags & WPA_FREQ_USED_BY_P2P_CLIENT)) |
| 3112 | c = i; |
| 3113 | } |
| 3114 | return freqs[c].freq; |
| 3115 | } |
| 3116 | |
| 3117 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3118 | static u8 wpas_invitation_process(void *ctx, const u8 *sa, const u8 *bssid, |
| 3119 | const u8 *go_dev_addr, const u8 *ssid, |
| 3120 | size_t ssid_len, int *go, u8 *group_bssid, |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3121 | int *force_freq, int persistent_group, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3122 | const struct p2p_channels *channels, |
| 3123 | int dev_pw_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3124 | { |
| 3125 | struct wpa_supplicant *wpa_s = ctx; |
| 3126 | struct wpa_ssid *s; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3127 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3128 | struct wpa_supplicant *grp; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3129 | int best_freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3130 | |
| 3131 | if (!persistent_group) { |
| 3132 | wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3133 | " to join an active group (SSID: %s)", |
| 3134 | MAC2STR(sa), wpa_ssid_txt(ssid, ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3135 | if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) && |
| 3136 | (os_memcmp(go_dev_addr, wpa_s->p2p_auth_invite, ETH_ALEN) |
| 3137 | == 0 || |
| 3138 | os_memcmp(sa, wpa_s->p2p_auth_invite, ETH_ALEN) == 0)) { |
| 3139 | wpa_printf(MSG_DEBUG, "P2P: Accept previously " |
| 3140 | "authorized invitation"); |
| 3141 | goto accept_inv; |
| 3142 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3143 | |
| 3144 | #ifdef CONFIG_WPS_NFC |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3145 | if (dev_pw_id >= 0 && wpa_s->p2p_nfc_tag_enabled && |
| 3146 | dev_pw_id == wpa_s->p2p_oob_dev_pw_id) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3147 | wpa_printf(MSG_DEBUG, "P2P: Accept invitation based on local enabled NFC Tag"); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3148 | wpa_s->p2p_wps_method = WPS_NFC; |
| 3149 | wpa_s->pending_join_wps_method = WPS_NFC; |
| 3150 | os_memcpy(wpa_s->pending_join_dev_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3151 | go_dev_addr, ETH_ALEN); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3152 | os_memcpy(wpa_s->pending_join_iface_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3153 | bssid, ETH_ALEN); |
| 3154 | goto accept_inv; |
| 3155 | } |
| 3156 | #endif /* CONFIG_WPS_NFC */ |
| 3157 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3158 | /* |
| 3159 | * Do not accept the invitation automatically; notify user and |
| 3160 | * request approval. |
| 3161 | */ |
| 3162 | return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; |
| 3163 | } |
| 3164 | |
| 3165 | grp = wpas_get_p2p_group(wpa_s, ssid, ssid_len, go); |
| 3166 | if (grp) { |
| 3167 | wpa_printf(MSG_DEBUG, "P2P: Accept invitation to already " |
| 3168 | "running persistent group"); |
| 3169 | if (*go) |
| 3170 | os_memcpy(group_bssid, grp->own_addr, ETH_ALEN); |
| 3171 | goto accept_inv; |
| 3172 | } |
| 3173 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3174 | if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) && |
| 3175 | os_memcmp(sa, wpa_s->p2p_auth_invite, ETH_ALEN) == 0) { |
| 3176 | wpa_printf(MSG_DEBUG, "P2P: Accept previously initiated " |
| 3177 | "invitation to re-invoke a persistent group"); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3178 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3179 | } else if (!wpa_s->conf->persistent_reconnect) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3180 | return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; |
| 3181 | |
| 3182 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 3183 | if (s->disabled == 2 && |
| 3184 | os_memcmp(s->bssid, go_dev_addr, ETH_ALEN) == 0 && |
| 3185 | s->ssid_len == ssid_len && |
| 3186 | os_memcmp(ssid, s->ssid, ssid_len) == 0) |
| 3187 | break; |
| 3188 | } |
| 3189 | |
| 3190 | if (!s) { |
| 3191 | wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR |
| 3192 | " requested reinvocation of an unknown group", |
| 3193 | MAC2STR(sa)); |
| 3194 | return P2P_SC_FAIL_UNKNOWN_GROUP; |
| 3195 | } |
| 3196 | |
| 3197 | if (s->mode == WPAS_MODE_P2P_GO && !wpas_p2p_create_iface(wpa_s)) { |
| 3198 | *go = 1; |
| 3199 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
| 3200 | wpa_printf(MSG_DEBUG, "P2P: The only available " |
| 3201 | "interface is already in use - reject " |
| 3202 | "invitation"); |
| 3203 | return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; |
| 3204 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3205 | if (wpa_s->p2p_mgmt) |
| 3206 | os_memcpy(group_bssid, wpa_s->parent->own_addr, |
| 3207 | ETH_ALEN); |
| 3208 | else |
| 3209 | os_memcpy(group_bssid, wpa_s->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3210 | } else if (s->mode == WPAS_MODE_P2P_GO) { |
| 3211 | *go = 1; |
| 3212 | if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO) < 0) |
| 3213 | { |
| 3214 | wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " |
| 3215 | "interface address for the group"); |
| 3216 | return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; |
| 3217 | } |
| 3218 | os_memcpy(group_bssid, wpa_s->pending_interface_addr, |
| 3219 | ETH_ALEN); |
| 3220 | } |
| 3221 | |
| 3222 | accept_inv: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3223 | wpas_p2p_set_own_freq_preference(wpa_s, 0); |
| 3224 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3225 | best_freq = 0; |
| 3226 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 3227 | sizeof(struct wpa_used_freq_data)); |
| 3228 | if (freqs) { |
| 3229 | int num_channels = wpa_s->num_multichan_concurrent; |
| 3230 | int num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, num_channels); |
| 3231 | best_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num); |
| 3232 | os_free(freqs); |
| 3233 | } |
| 3234 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3235 | /* Get one of the frequencies currently in use */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3236 | if (best_freq > 0) { |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 3237 | wpa_printf(MSG_DEBUG, "P2P: Trying to prefer a channel already used by one of the interfaces"); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3238 | wpas_p2p_set_own_freq_preference(wpa_s, best_freq); |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 3239 | |
| 3240 | if (wpa_s->num_multichan_concurrent < 2 || |
| 3241 | wpas_p2p_num_unused_channels(wpa_s) < 1) { |
| 3242 | wpa_printf(MSG_DEBUG, "P2P: No extra channels available - trying to force channel to match a channel already used by one of the interfaces"); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3243 | *force_freq = best_freq; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 3244 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3245 | } |
| 3246 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3247 | if (*force_freq > 0 && wpa_s->num_multichan_concurrent > 1 && |
| 3248 | wpas_p2p_num_unused_channels(wpa_s) > 0) { |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3249 | if (*go == 0) { |
| 3250 | /* We are the client */ |
| 3251 | wpa_printf(MSG_DEBUG, "P2P: Peer was found to be " |
| 3252 | "running a GO but we are capable of MCC, " |
| 3253 | "figure out the best channel to use"); |
| 3254 | *force_freq = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3255 | } else if (!freq_included(wpa_s, channels, *force_freq)) { |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3256 | /* We are the GO, and *force_freq is not in the |
| 3257 | * intersection */ |
| 3258 | wpa_printf(MSG_DEBUG, "P2P: Forced GO freq %d MHz not " |
| 3259 | "in intersection but we are capable of MCC, " |
| 3260 | "figure out the best channel to use", |
| 3261 | *force_freq); |
| 3262 | *force_freq = 0; |
| 3263 | } |
| 3264 | } |
| 3265 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3266 | return P2P_SC_SUCCESS; |
| 3267 | } |
| 3268 | |
| 3269 | |
| 3270 | static void wpas_invitation_received(void *ctx, const u8 *sa, const u8 *bssid, |
| 3271 | const u8 *ssid, size_t ssid_len, |
| 3272 | const u8 *go_dev_addr, u8 status, |
| 3273 | int op_freq) |
| 3274 | { |
| 3275 | struct wpa_supplicant *wpa_s = ctx; |
| 3276 | struct wpa_ssid *s; |
| 3277 | |
| 3278 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 3279 | if (s->disabled == 2 && |
| 3280 | s->ssid_len == ssid_len && |
| 3281 | os_memcmp(ssid, s->ssid, ssid_len) == 0) |
| 3282 | break; |
| 3283 | } |
| 3284 | |
| 3285 | if (status == P2P_SC_SUCCESS) { |
| 3286 | wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3287 | " was accepted; op_freq=%d MHz, SSID=%s", |
| 3288 | MAC2STR(sa), op_freq, wpa_ssid_txt(ssid, ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3289 | if (s) { |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 3290 | int go = s->mode == WPAS_MODE_P2P_GO; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 3291 | if (go) { |
| 3292 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3293 | P2P_EVENT_INVITATION_ACCEPTED |
| 3294 | "sa=" MACSTR |
| 3295 | " persistent=%d freq=%d", |
| 3296 | MAC2STR(sa), s->id, op_freq); |
| 3297 | } else { |
| 3298 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3299 | P2P_EVENT_INVITATION_ACCEPTED |
| 3300 | "sa=" MACSTR |
| 3301 | " persistent=%d", |
| 3302 | MAC2STR(sa), s->id); |
| 3303 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3304 | wpas_p2p_group_add_persistent( |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3305 | wpa_s, s, go, 0, op_freq, 0, |
| 3306 | wpa_s->conf->p2p_go_ht40, |
| 3307 | wpa_s->conf->p2p_go_vht, |
| 3308 | 0, |
| 3309 | wpa_s->conf->p2p_go_he, |
| 3310 | wpa_s->conf->p2p_go_edmg, NULL, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3311 | go ? P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0, |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame^] | 3312 | 1, is_p2p_allow_6ghz(wpa_s->global->p2p), 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3313 | } else if (bssid) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3314 | wpa_s->user_initiated_pd = 0; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 3315 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3316 | P2P_EVENT_INVITATION_ACCEPTED |
| 3317 | "sa=" MACSTR " go_dev_addr=" MACSTR |
| 3318 | " bssid=" MACSTR " unknown-network", |
| 3319 | MAC2STR(sa), MAC2STR(go_dev_addr), |
| 3320 | MAC2STR(bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3321 | wpas_p2p_join(wpa_s, bssid, go_dev_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3322 | wpa_s->p2p_wps_method, 0, op_freq, |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3323 | ssid, ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3324 | } |
| 3325 | return; |
| 3326 | } |
| 3327 | |
| 3328 | if (status != P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) { |
| 3329 | wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR |
| 3330 | " was rejected (status %u)", MAC2STR(sa), status); |
| 3331 | return; |
| 3332 | } |
| 3333 | |
| 3334 | if (!s) { |
| 3335 | if (bssid) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3336 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3337 | P2P_EVENT_INVITATION_RECEIVED |
| 3338 | "sa=" MACSTR " go_dev_addr=" MACSTR |
| 3339 | " bssid=" MACSTR " unknown-network", |
| 3340 | MAC2STR(sa), MAC2STR(go_dev_addr), |
| 3341 | MAC2STR(bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3342 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3343 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3344 | P2P_EVENT_INVITATION_RECEIVED |
| 3345 | "sa=" MACSTR " go_dev_addr=" MACSTR |
| 3346 | " unknown-network", |
| 3347 | MAC2STR(sa), MAC2STR(go_dev_addr)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3348 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3349 | wpas_notify_p2p_invitation_received(wpa_s, sa, go_dev_addr, |
| 3350 | bssid, 0, op_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3351 | return; |
| 3352 | } |
| 3353 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3354 | if (s->mode == WPAS_MODE_P2P_GO && op_freq) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3355 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED |
| 3356 | "sa=" MACSTR " persistent=%d freq=%d", |
| 3357 | MAC2STR(sa), s->id, op_freq); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3358 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3359 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED |
| 3360 | "sa=" MACSTR " persistent=%d", |
| 3361 | MAC2STR(sa), s->id); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3362 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3363 | wpas_notify_p2p_invitation_received(wpa_s, sa, go_dev_addr, bssid, |
| 3364 | s->id, op_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3365 | } |
| 3366 | |
| 3367 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3368 | static void wpas_remove_persistent_peer(struct wpa_supplicant *wpa_s, |
| 3369 | struct wpa_ssid *ssid, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3370 | const u8 *peer, int inv) |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3371 | { |
| 3372 | size_t i; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 3373 | struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3374 | |
| 3375 | if (ssid == NULL) |
| 3376 | return; |
| 3377 | |
| 3378 | for (i = 0; ssid->p2p_client_list && i < ssid->num_p2p_clients; i++) { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3379 | if (os_memcmp(ssid->p2p_client_list + i * 2 * ETH_ALEN, peer, |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3380 | ETH_ALEN) == 0) |
| 3381 | break; |
| 3382 | } |
Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 3383 | if (i >= ssid->num_p2p_clients || !ssid->p2p_client_list) { |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3384 | if (ssid->mode != WPAS_MODE_P2P_GO && |
| 3385 | os_memcmp(ssid->bssid, peer, ETH_ALEN) == 0) { |
| 3386 | wpa_printf(MSG_DEBUG, "P2P: Remove persistent group %d " |
| 3387 | "due to invitation result", ssid->id); |
| 3388 | wpas_notify_network_removed(wpa_s, ssid); |
| 3389 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 3390 | return; |
| 3391 | } |
| 3392 | return; /* Peer not found in client list */ |
| 3393 | } |
| 3394 | |
| 3395 | wpa_printf(MSG_DEBUG, "P2P: Remove peer " MACSTR " from persistent " |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3396 | "group %d client list%s", |
| 3397 | MAC2STR(peer), ssid->id, |
| 3398 | inv ? " due to invitation result" : ""); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3399 | os_memmove(ssid->p2p_client_list + i * 2 * ETH_ALEN, |
| 3400 | ssid->p2p_client_list + (i + 1) * 2 * ETH_ALEN, |
| 3401 | (ssid->num_p2p_clients - i - 1) * 2 * ETH_ALEN); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3402 | ssid->num_p2p_clients--; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 3403 | if (p2p_wpa_s->conf->update_config && |
| 3404 | wpa_config_write(p2p_wpa_s->confname, p2p_wpa_s->conf)) |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3405 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | |
| 3409 | static void wpas_remove_persistent_client(struct wpa_supplicant *wpa_s, |
| 3410 | const u8 *peer) |
| 3411 | { |
| 3412 | struct wpa_ssid *ssid; |
| 3413 | |
| 3414 | wpa_s = wpa_s->global->p2p_invite_group; |
| 3415 | if (wpa_s == NULL) |
| 3416 | return; /* No known invitation group */ |
| 3417 | ssid = wpa_s->current_ssid; |
| 3418 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || |
| 3419 | !ssid->p2p_persistent_group) |
| 3420 | return; /* Not operating as a GO in persistent group */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3421 | ssid = wpas_p2p_get_persistent(wpa_s->p2pdev, peer, |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3422 | ssid->ssid, ssid->ssid_len); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3423 | wpas_remove_persistent_peer(wpa_s, ssid, peer, 1); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3427 | static void wpas_invitation_result(void *ctx, int status, const u8 *bssid, |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3428 | const struct p2p_channels *channels, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3429 | const u8 *peer, int neg_freq, |
| 3430 | int peer_oper_freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3431 | { |
| 3432 | struct wpa_supplicant *wpa_s = ctx; |
| 3433 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3434 | int freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3435 | |
| 3436 | if (bssid) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3437 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT |
| 3438 | "status=%d " MACSTR, |
| 3439 | status, MAC2STR(bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3440 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3441 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT |
| 3442 | "status=%d ", status); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3443 | } |
| 3444 | wpas_notify_p2p_invitation_result(wpa_s, status, bssid); |
| 3445 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3446 | wpa_printf(MSG_DEBUG, "P2P: Invitation result - status=%d peer=" MACSTR, |
| 3447 | status, MAC2STR(peer)); |
| 3448 | if (wpa_s->pending_invite_ssid_id == -1) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3449 | struct wpa_supplicant *group_if = |
| 3450 | wpa_s->global->p2p_invite_group; |
| 3451 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3452 | if (status == P2P_SC_FAIL_UNKNOWN_GROUP) |
| 3453 | wpas_remove_persistent_client(wpa_s, peer); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3454 | |
| 3455 | /* |
| 3456 | * Invitation to an active group. If this is successful and we |
| 3457 | * are the GO, set the client wait to postpone some concurrent |
| 3458 | * operations and to allow provisioning and connection to happen |
| 3459 | * more quickly. |
| 3460 | */ |
| 3461 | if (status == P2P_SC_SUCCESS && |
| 3462 | group_if && group_if->current_ssid && |
| 3463 | group_if->current_ssid->mode == WPAS_MODE_P2P_GO) { |
| 3464 | os_get_reltime(&wpa_s->global->p2p_go_wait_client); |
| 3465 | #ifdef CONFIG_TESTING_OPTIONS |
| 3466 | if (group_if->p2p_go_csa_on_inv) { |
| 3467 | wpa_printf(MSG_DEBUG, |
| 3468 | "Testing: force P2P GO CSA after invitation"); |
| 3469 | eloop_cancel_timeout( |
| 3470 | wpas_p2p_reconsider_moving_go, |
| 3471 | wpa_s, NULL); |
| 3472 | eloop_register_timeout( |
| 3473 | 0, 50000, |
| 3474 | wpas_p2p_reconsider_moving_go, |
| 3475 | wpa_s, NULL); |
| 3476 | } |
| 3477 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 3478 | } |
| 3479 | return; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3480 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3481 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3482 | if (status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) { |
| 3483 | wpa_printf(MSG_DEBUG, "P2P: Waiting for peer to start another " |
| 3484 | "invitation exchange to indicate readiness for " |
| 3485 | "re-invocation"); |
| 3486 | } |
| 3487 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3488 | if (status != P2P_SC_SUCCESS) { |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3489 | if (status == P2P_SC_FAIL_UNKNOWN_GROUP) { |
| 3490 | ssid = wpa_config_get_network( |
| 3491 | wpa_s->conf, wpa_s->pending_invite_ssid_id); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3492 | wpas_remove_persistent_peer(wpa_s, ssid, peer, 1); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3493 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3494 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 3495 | return; |
| 3496 | } |
| 3497 | |
| 3498 | ssid = wpa_config_get_network(wpa_s->conf, |
| 3499 | wpa_s->pending_invite_ssid_id); |
| 3500 | if (ssid == NULL) { |
| 3501 | wpa_printf(MSG_ERROR, "P2P: Could not find persistent group " |
| 3502 | "data matching with invitation"); |
| 3503 | return; |
| 3504 | } |
| 3505 | |
Jouni Malinen | 2c5b17d | 2012-10-13 21:52:46 -0700 | [diff] [blame] | 3506 | /* |
| 3507 | * The peer could have missed our ctrl::ack frame for Invitation |
| 3508 | * Response and continue retransmitting the frame. To reduce the |
| 3509 | * likelihood of the peer not getting successful TX status for the |
| 3510 | * Invitation Response frame, wait a short time here before starting |
| 3511 | * the persistent group so that we will remain on the current channel to |
| 3512 | * acknowledge any possible retransmission from the peer. |
| 3513 | */ |
| 3514 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: 50 ms wait on current channel before " |
| 3515 | "starting persistent group"); |
| 3516 | os_sleep(0, 50000); |
| 3517 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3518 | if (neg_freq > 0 && ssid->mode == WPAS_MODE_P2P_GO && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3519 | freq_included(wpa_s, channels, neg_freq)) |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3520 | freq = neg_freq; |
| 3521 | else if (peer_oper_freq > 0 && ssid->mode != WPAS_MODE_P2P_GO && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3522 | freq_included(wpa_s, channels, peer_oper_freq)) |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3523 | freq = peer_oper_freq; |
| 3524 | else |
| 3525 | freq = 0; |
| 3526 | |
| 3527 | wpa_printf(MSG_DEBUG, "P2P: Persistent group invitation success - op_freq=%d MHz SSID=%s", |
| 3528 | freq, wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3529 | wpas_p2p_group_add_persistent(wpa_s, ssid, |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 3530 | ssid->mode == WPAS_MODE_P2P_GO, |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 3531 | wpa_s->p2p_persistent_go_freq, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3532 | freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3533 | wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3534 | wpa_s->p2p_go_ht40, wpa_s->p2p_go_vht, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3535 | wpa_s->p2p_go_max_oper_chwidth, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3536 | wpa_s->p2p_go_he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3537 | wpa_s->p2p_go_edmg, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3538 | channels, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3539 | ssid->mode == WPAS_MODE_P2P_GO ? |
| 3540 | P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3541 | 0, 1, |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame^] | 3542 | is_p2p_allow_6ghz(wpa_s->global->p2p), 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3543 | } |
| 3544 | |
| 3545 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3546 | static int wpas_p2p_disallowed_freq(struct wpa_global *global, |
| 3547 | unsigned int freq) |
| 3548 | { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3549 | if (freq_range_list_includes(&global->p2p_go_avoid_freq, freq)) |
| 3550 | return 1; |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 3551 | return freq_range_list_includes(&global->p2p_disallow_freq, freq); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3552 | } |
| 3553 | |
| 3554 | |
| 3555 | static void wpas_p2p_add_chan(struct p2p_reg_class *reg, u8 chan) |
| 3556 | { |
| 3557 | reg->channel[reg->channels] = chan; |
| 3558 | reg->channels++; |
| 3559 | } |
| 3560 | |
| 3561 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3562 | static int wpas_p2p_default_channels(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3563 | struct p2p_channels *chan, |
| 3564 | struct p2p_channels *cli_chan) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3565 | { |
| 3566 | int i, cla = 0; |
| 3567 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3568 | wpa_s->global->p2p_24ghz_social_channels = 1; |
| 3569 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3570 | os_memset(cli_chan, 0, sizeof(*cli_chan)); |
| 3571 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3572 | wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for 2.4 GHz " |
| 3573 | "band"); |
| 3574 | |
| 3575 | /* Operating class 81 - 2.4 GHz band channels 1..13 */ |
| 3576 | chan->reg_class[cla].reg_class = 81; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3577 | chan->reg_class[cla].channels = 0; |
| 3578 | for (i = 0; i < 11; i++) { |
| 3579 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 2412 + i * 5)) |
| 3580 | wpas_p2p_add_chan(&chan->reg_class[cla], i + 1); |
| 3581 | } |
| 3582 | if (chan->reg_class[cla].channels) |
| 3583 | cla++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3584 | |
| 3585 | wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for lower 5 GHz " |
| 3586 | "band"); |
| 3587 | |
| 3588 | /* Operating class 115 - 5 GHz, channels 36-48 */ |
| 3589 | chan->reg_class[cla].reg_class = 115; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3590 | chan->reg_class[cla].channels = 0; |
| 3591 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 36 * 5)) |
| 3592 | wpas_p2p_add_chan(&chan->reg_class[cla], 36); |
| 3593 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 40 * 5)) |
| 3594 | wpas_p2p_add_chan(&chan->reg_class[cla], 40); |
| 3595 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 44 * 5)) |
| 3596 | wpas_p2p_add_chan(&chan->reg_class[cla], 44); |
| 3597 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 48 * 5)) |
| 3598 | wpas_p2p_add_chan(&chan->reg_class[cla], 48); |
| 3599 | if (chan->reg_class[cla].channels) |
| 3600 | cla++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3601 | |
| 3602 | wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for higher 5 GHz " |
| 3603 | "band"); |
| 3604 | |
| 3605 | /* Operating class 124 - 5 GHz, channels 149,153,157,161 */ |
| 3606 | chan->reg_class[cla].reg_class = 124; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3607 | chan->reg_class[cla].channels = 0; |
| 3608 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 149 * 5)) |
| 3609 | wpas_p2p_add_chan(&chan->reg_class[cla], 149); |
| 3610 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 153 * 5)) |
| 3611 | wpas_p2p_add_chan(&chan->reg_class[cla], 153); |
| 3612 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 156 * 5)) |
| 3613 | wpas_p2p_add_chan(&chan->reg_class[cla], 157); |
| 3614 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 161 * 5)) |
| 3615 | wpas_p2p_add_chan(&chan->reg_class[cla], 161); |
| 3616 | if (chan->reg_class[cla].channels) |
| 3617 | cla++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3618 | |
| 3619 | chan->reg_classes = cla; |
| 3620 | return 0; |
| 3621 | } |
| 3622 | |
| 3623 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3624 | static enum chan_allowed has_channel(struct wpa_global *global, |
| 3625 | struct hostapd_hw_modes *mode, u8 op_class, |
| 3626 | u8 chan, int *flags) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3627 | { |
| 3628 | int i; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3629 | unsigned int freq; |
| 3630 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3631 | freq = ieee80211_chan_to_freq(NULL, op_class, chan); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3632 | if (wpas_p2p_disallowed_freq(global, freq)) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3633 | return NOT_ALLOWED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3634 | |
| 3635 | for (i = 0; i < mode->num_channels; i++) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3636 | if ((unsigned int) mode->channels[i].freq == freq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3637 | if (flags) |
| 3638 | *flags = mode->channels[i].flag; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3639 | if (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3640 | return NOT_ALLOWED; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3641 | if (mode->channels[i].flag & HOSTAPD_CHAN_NO_IR) |
| 3642 | return NO_IR; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3643 | if (mode->channels[i].flag & HOSTAPD_CHAN_RADAR) |
| 3644 | return RADAR; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3645 | return ALLOWED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3646 | } |
| 3647 | } |
| 3648 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3649 | return NOT_ALLOWED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3653 | static int wpas_p2p_get_center_80mhz(struct wpa_supplicant *wpa_s, |
| 3654 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3655 | u8 channel, const u8 *center_channels, |
| 3656 | size_t num_chan) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3657 | { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 3658 | size_t i; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3659 | |
| 3660 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 3661 | return 0; |
| 3662 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3663 | for (i = 0; i < num_chan; i++) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3664 | /* |
| 3665 | * In 80 MHz, the bandwidth "spans" 12 channels (e.g., 36-48), |
| 3666 | * so the center channel is 6 channels away from the start/end. |
| 3667 | */ |
| 3668 | if (channel >= center_channels[i] - 6 && |
| 3669 | channel <= center_channels[i] + 6) |
| 3670 | return center_channels[i]; |
| 3671 | |
| 3672 | return 0; |
| 3673 | } |
| 3674 | |
| 3675 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3676 | static const u8 center_channels_5ghz_80mhz[] = { 42, 58, 106, 122, 138, |
| 3677 | 155, 171 }; |
| 3678 | static const u8 center_channels_6ghz_80mhz[] = { 7, 23, 39, 55, 71, 87, 103, |
| 3679 | 119, 135, 151, 167, 183, 199, |
| 3680 | 215 }; |
| 3681 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3682 | static enum chan_allowed wpas_p2p_verify_80mhz(struct wpa_supplicant *wpa_s, |
| 3683 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3684 | u8 op_class, u8 channel, u8 bw) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3685 | { |
| 3686 | u8 center_chan; |
| 3687 | int i, flags; |
| 3688 | enum chan_allowed res, ret = ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3689 | const u8 *chans; |
| 3690 | size_t num_chans; |
| 3691 | bool is_6ghz = is_6ghz_op_class(op_class); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3692 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3693 | if (is_6ghz) { |
| 3694 | chans = center_channels_6ghz_80mhz; |
| 3695 | num_chans = ARRAY_SIZE(center_channels_6ghz_80mhz); |
| 3696 | } else { |
| 3697 | chans = center_channels_5ghz_80mhz; |
| 3698 | num_chans = ARRAY_SIZE(center_channels_5ghz_80mhz); |
| 3699 | } |
| 3700 | center_chan = wpas_p2p_get_center_80mhz(wpa_s, mode, channel, |
| 3701 | chans, num_chans); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3702 | if (!center_chan) |
| 3703 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3704 | if (!wpa_s->p2p_go_allow_dfs && |
| 3705 | !is_6ghz && center_chan >= 58 && center_chan <= 138) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3706 | return NOT_ALLOWED; /* Do not allow DFS channels for P2P */ |
| 3707 | |
| 3708 | /* check all the channels are available */ |
| 3709 | for (i = 0; i < 4; i++) { |
| 3710 | int adj_chan = center_chan - 6 + i * 4; |
| 3711 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3712 | res = has_channel(wpa_s->global, mode, op_class, adj_chan, |
| 3713 | &flags); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3714 | if (res == NOT_ALLOWED) |
| 3715 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3716 | if (res == RADAR) |
| 3717 | ret = RADAR; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3718 | if (res == NO_IR) |
| 3719 | ret = NO_IR; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3720 | if (!is_6ghz) { |
| 3721 | if (i == 0 && !(flags & HOSTAPD_CHAN_VHT_10_70)) |
| 3722 | return NOT_ALLOWED; |
| 3723 | if (i == 1 && !(flags & HOSTAPD_CHAN_VHT_30_50)) |
| 3724 | return NOT_ALLOWED; |
| 3725 | if (i == 2 && !(flags & HOSTAPD_CHAN_VHT_50_30)) |
| 3726 | return NOT_ALLOWED; |
| 3727 | if (i == 3 && !(flags & HOSTAPD_CHAN_VHT_70_10)) |
| 3728 | return NOT_ALLOWED; |
| 3729 | } else if (is_6ghz && |
| 3730 | (!(wpas_get_6ghz_he_chwidth_capab(mode) & |
| 3731 | HE_PHYCAP_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G))) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3732 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3733 | } |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3734 | } |
| 3735 | |
| 3736 | return ret; |
| 3737 | } |
| 3738 | |
| 3739 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3740 | static int wpas_p2p_get_center_160mhz(struct wpa_supplicant *wpa_s, |
| 3741 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3742 | u8 channel, const u8 *center_channels, |
| 3743 | size_t num_chan) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3744 | { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3745 | unsigned int i; |
| 3746 | |
| 3747 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 3748 | return 0; |
| 3749 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3750 | for (i = 0; i < num_chan; i++) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3751 | /* |
| 3752 | * In 160 MHz, the bandwidth "spans" 28 channels (e.g., 36-64), |
| 3753 | * so the center channel is 14 channels away from the start/end. |
| 3754 | */ |
| 3755 | if (channel >= center_channels[i] - 14 && |
| 3756 | channel <= center_channels[i] + 14) |
| 3757 | return center_channels[i]; |
| 3758 | |
| 3759 | return 0; |
| 3760 | } |
| 3761 | |
| 3762 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3763 | static const u8 center_channels_5ghz_160mhz[] = { 50, 114, 163 }; |
| 3764 | static const u8 center_channels_6ghz_160mhz[] = { 15, 47, 79, 111, 143, 175, |
| 3765 | 207 }; |
| 3766 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3767 | static enum chan_allowed wpas_p2p_verify_160mhz(struct wpa_supplicant *wpa_s, |
| 3768 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3769 | u8 op_class, u8 channel, u8 bw) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3770 | { |
| 3771 | u8 center_chan; |
| 3772 | int i, flags; |
| 3773 | enum chan_allowed res, ret = ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3774 | const u8 *chans; |
| 3775 | size_t num_chans; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3776 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3777 | if (is_6ghz_op_class(op_class)) { |
| 3778 | chans = center_channels_6ghz_160mhz; |
| 3779 | num_chans = ARRAY_SIZE(center_channels_6ghz_160mhz); |
| 3780 | } else { |
| 3781 | chans = center_channels_5ghz_160mhz; |
| 3782 | num_chans = ARRAY_SIZE(center_channels_5ghz_160mhz); |
| 3783 | } |
| 3784 | center_chan = wpas_p2p_get_center_160mhz(wpa_s, mode, channel, |
| 3785 | chans, num_chans); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3786 | if (!center_chan) |
| 3787 | return NOT_ALLOWED; |
| 3788 | /* VHT 160 MHz uses DFS channels in most countries. */ |
| 3789 | |
| 3790 | /* Check all the channels are available */ |
| 3791 | for (i = 0; i < 8; i++) { |
| 3792 | int adj_chan = center_chan - 14 + i * 4; |
| 3793 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3794 | res = has_channel(wpa_s->global, mode, op_class, adj_chan, |
| 3795 | &flags); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3796 | if (res == NOT_ALLOWED) |
| 3797 | return NOT_ALLOWED; |
| 3798 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3799 | if (res == RADAR) |
| 3800 | ret = RADAR; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3801 | if (res == NO_IR) |
| 3802 | ret = NO_IR; |
| 3803 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3804 | if (!is_6ghz_op_class(op_class)) { |
| 3805 | if (i == 0 && !(flags & HOSTAPD_CHAN_VHT_10_150)) |
| 3806 | return NOT_ALLOWED; |
| 3807 | if (i == 1 && !(flags & HOSTAPD_CHAN_VHT_30_130)) |
| 3808 | return NOT_ALLOWED; |
| 3809 | if (i == 2 && !(flags & HOSTAPD_CHAN_VHT_50_110)) |
| 3810 | return NOT_ALLOWED; |
| 3811 | if (i == 3 && !(flags & HOSTAPD_CHAN_VHT_70_90)) |
| 3812 | return NOT_ALLOWED; |
| 3813 | if (i == 4 && !(flags & HOSTAPD_CHAN_VHT_90_70)) |
| 3814 | return NOT_ALLOWED; |
| 3815 | if (i == 5 && !(flags & HOSTAPD_CHAN_VHT_110_50)) |
| 3816 | return NOT_ALLOWED; |
| 3817 | if (i == 6 && !(flags & HOSTAPD_CHAN_VHT_130_30)) |
| 3818 | return NOT_ALLOWED; |
| 3819 | if (i == 7 && !(flags & HOSTAPD_CHAN_VHT_150_10)) |
| 3820 | return NOT_ALLOWED; |
| 3821 | } else if (is_6ghz_op_class(op_class) && |
| 3822 | (!(wpas_get_6ghz_he_chwidth_capab(mode) & |
| 3823 | HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G))) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3824 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3825 | } |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3826 | } |
| 3827 | |
| 3828 | return ret; |
| 3829 | } |
| 3830 | |
| 3831 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3832 | static enum chan_allowed wpas_p2p_verify_edmg(struct wpa_supplicant *wpa_s, |
| 3833 | struct hostapd_hw_modes *mode, |
| 3834 | u8 channel) |
| 3835 | { |
| 3836 | struct ieee80211_edmg_config edmg; |
| 3837 | |
| 3838 | hostapd_encode_edmg_chan(1, channel, 0, &edmg); |
| 3839 | if (edmg.channels && ieee802_edmg_is_allowed(mode->edmg, edmg)) |
| 3840 | return ALLOWED; |
| 3841 | |
| 3842 | return NOT_ALLOWED; |
| 3843 | } |
| 3844 | |
| 3845 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3846 | static enum chan_allowed wpas_p2p_verify_channel(struct wpa_supplicant *wpa_s, |
| 3847 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3848 | u8 op_class, u8 channel, u8 bw) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3849 | { |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 3850 | int flag = 0; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3851 | enum chan_allowed res, res2; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3852 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3853 | if (is_6ghz_op_class(op_class) && !is_6ghz_psc_frequency( |
| 3854 | p2p_channel_to_freq(op_class, channel))) |
| 3855 | return NOT_ALLOWED; |
| 3856 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3857 | res2 = res = has_channel(wpa_s->global, mode, op_class, channel, &flag); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3858 | if (bw == BW40MINUS) { |
| 3859 | if (!(flag & HOSTAPD_CHAN_HT40MINUS)) |
| 3860 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3861 | res2 = has_channel(wpa_s->global, mode, op_class, channel - 4, |
| 3862 | NULL); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3863 | } else if (bw == BW40PLUS) { |
| 3864 | if (!(flag & HOSTAPD_CHAN_HT40PLUS)) |
| 3865 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3866 | res2 = has_channel(wpa_s->global, mode, op_class, channel + 4, |
| 3867 | NULL); |
| 3868 | } else if (is_6ghz_op_class(op_class) && bw == BW40) { |
| 3869 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 3870 | return NOT_ALLOWED; |
| 3871 | if (get_6ghz_sec_channel(channel) < 0) |
| 3872 | res2 = has_channel(wpa_s->global, mode, op_class, |
| 3873 | channel - 4, NULL); |
| 3874 | else |
| 3875 | res2 = has_channel(wpa_s->global, mode, op_class, |
| 3876 | channel + 4, NULL); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3877 | } else if (bw == BW80) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3878 | res2 = wpas_p2p_verify_80mhz(wpa_s, mode, op_class, channel, |
| 3879 | bw); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3880 | } else if (bw == BW160) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3881 | res2 = wpas_p2p_verify_160mhz(wpa_s, mode, op_class, channel, |
| 3882 | bw); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3883 | } else if (bw == BW4320 || bw == BW6480 || bw == BW8640) { |
| 3884 | return wpas_p2p_verify_edmg(wpa_s, mode, channel); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3885 | } |
| 3886 | |
| 3887 | if (res == NOT_ALLOWED || res2 == NOT_ALLOWED) |
| 3888 | return NOT_ALLOWED; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3889 | if (res == NO_IR || res2 == NO_IR) |
| 3890 | return NO_IR; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3891 | if (res == RADAR || res2 == RADAR) |
| 3892 | return RADAR; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3893 | return res; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3894 | } |
| 3895 | |
| 3896 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3897 | static int wpas_p2p_setup_channels(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3898 | struct p2p_channels *chan, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3899 | struct p2p_channels *cli_chan, |
| 3900 | bool p2p_disable_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3901 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3902 | struct hostapd_hw_modes *mode; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3903 | int cla, op, cli_cla; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3904 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3905 | if (wpa_s->hw.modes == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3906 | wpa_printf(MSG_DEBUG, "P2P: Driver did not support fetching " |
| 3907 | "of all supported channels; assume dualband " |
| 3908 | "support"); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3909 | return wpas_p2p_default_channels(wpa_s, chan, cli_chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3910 | } |
| 3911 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3912 | cla = cli_cla = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3913 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3914 | for (op = 0; global_op_class[op].op_class; op++) { |
| 3915 | const struct oper_class_map *o = &global_op_class[op]; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3916 | unsigned int ch; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3917 | struct p2p_reg_class *reg = NULL, *cli_reg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3918 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3919 | if (o->p2p == NO_P2P_SUPP || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3920 | (is_6ghz_op_class(o->op_class) && p2p_disable_6ghz)) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3921 | continue; |
| 3922 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3923 | mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, o->mode, |
| 3924 | is_6ghz_op_class(o->op_class)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3925 | if (mode == NULL) |
| 3926 | continue; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3927 | if (mode->mode == HOSTAPD_MODE_IEEE80211G) |
| 3928 | wpa_s->global->p2p_24ghz_social_channels = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3929 | for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3930 | enum chan_allowed res; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3931 | |
| 3932 | /* Check for non-continuous jump in channel index |
| 3933 | * incrementation */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3934 | if ((o->op_class >= 128 && o->op_class <= 130) && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3935 | ch < 149 && ch + o->inc > 149) |
| 3936 | ch = 149; |
| 3937 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3938 | res = wpas_p2p_verify_channel(wpa_s, mode, o->op_class, |
| 3939 | ch, o->bw); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3940 | if (res == ALLOWED) { |
| 3941 | if (reg == NULL) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3942 | if (cla == P2P_MAX_REG_CLASSES) |
| 3943 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3944 | wpa_printf(MSG_DEBUG, "P2P: Add operating class %u", |
| 3945 | o->op_class); |
| 3946 | reg = &chan->reg_class[cla]; |
| 3947 | cla++; |
| 3948 | reg->reg_class = o->op_class; |
| 3949 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3950 | if (reg->channels == P2P_MAX_REG_CLASS_CHANNELS) |
| 3951 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3952 | reg->channel[reg->channels] = ch; |
| 3953 | reg->channels++; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3954 | } else if (res == NO_IR && |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3955 | wpa_s->conf->p2p_add_cli_chan) { |
| 3956 | if (cli_reg == NULL) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3957 | if (cli_cla == P2P_MAX_REG_CLASSES) |
| 3958 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3959 | wpa_printf(MSG_DEBUG, "P2P: Add operating class %u (client only)", |
| 3960 | o->op_class); |
| 3961 | cli_reg = &cli_chan->reg_class[cli_cla]; |
| 3962 | cli_cla++; |
| 3963 | cli_reg->reg_class = o->op_class; |
| 3964 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3965 | if (cli_reg->channels == |
| 3966 | P2P_MAX_REG_CLASS_CHANNELS) |
| 3967 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3968 | cli_reg->channel[cli_reg->channels] = ch; |
| 3969 | cli_reg->channels++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3970 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3971 | } |
| 3972 | if (reg) { |
| 3973 | wpa_hexdump(MSG_DEBUG, "P2P: Channels", |
| 3974 | reg->channel, reg->channels); |
| 3975 | } |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3976 | if (cli_reg) { |
| 3977 | wpa_hexdump(MSG_DEBUG, "P2P: Channels (client only)", |
| 3978 | cli_reg->channel, cli_reg->channels); |
| 3979 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3980 | } |
| 3981 | |
| 3982 | chan->reg_classes = cla; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3983 | cli_chan->reg_classes = cli_cla; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3984 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3985 | return 0; |
| 3986 | } |
| 3987 | |
| 3988 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3989 | int wpas_p2p_get_sec_channel_offset_40mhz(struct wpa_supplicant *wpa_s, |
| 3990 | struct hostapd_hw_modes *mode, |
| 3991 | u8 channel) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3992 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3993 | int op; |
| 3994 | enum chan_allowed ret; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3995 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3996 | for (op = 0; global_op_class[op].op_class; op++) { |
| 3997 | const struct oper_class_map *o = &global_op_class[op]; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3998 | u16 ch; |
| 3999 | int chan = channel; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4000 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4001 | /* Allow DFS channels marked as NO_P2P_SUPP to be used with |
| 4002 | * driver offloaded DFS. */ |
| 4003 | if ((o->p2p == NO_P2P_SUPP && |
| 4004 | (!is_dfs_global_op_class(o->op_class) || |
| 4005 | !wpa_s->p2p_go_allow_dfs)) || |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4006 | (is_6ghz_op_class(o->op_class) && |
| 4007 | wpa_s->conf->p2p_6ghz_disable)) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4008 | continue; |
| 4009 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4010 | if (is_6ghz_op_class(o->op_class) && o->bw == BW40 && |
| 4011 | get_6ghz_sec_channel(channel) < 0) |
| 4012 | chan = channel - 4; |
| 4013 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4014 | for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) { |
| 4015 | if (o->mode != HOSTAPD_MODE_IEEE80211A || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4016 | (o->bw != BW40PLUS && o->bw != BW40MINUS && |
| 4017 | o->bw != BW40) || |
| 4018 | ch != chan) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4019 | continue; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4020 | ret = wpas_p2p_verify_channel(wpa_s, mode, o->op_class, |
| 4021 | ch, o->bw); |
| 4022 | if (ret == ALLOWED) { |
| 4023 | if (is_6ghz_op_class(o->op_class) && |
| 4024 | o->bw == BW40) |
| 4025 | return get_6ghz_sec_channel(channel); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4026 | return (o->bw == BW40MINUS) ? -1 : 1; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4027 | } |
| 4028 | if (ret == RADAR && wpa_s->p2p_go_allow_dfs) { |
| 4029 | /* Allow RADAR channels used for driver |
| 4030 | * offloaded DFS */ |
| 4031 | return (o->bw == BW40MINUS) ? -1 : 1; |
| 4032 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4033 | } |
| 4034 | } |
| 4035 | return 0; |
| 4036 | } |
| 4037 | |
| 4038 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4039 | int wpas_p2p_get_vht80_center(struct wpa_supplicant *wpa_s, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4040 | struct hostapd_hw_modes *mode, u8 channel, |
| 4041 | u8 op_class) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4042 | { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4043 | const u8 *chans; |
| 4044 | size_t num_chans; |
| 4045 | enum chan_allowed ret; |
| 4046 | |
| 4047 | ret = wpas_p2p_verify_channel(wpa_s, mode, op_class, channel, BW80); |
| 4048 | if (!(ret == ALLOWED || (ret == RADAR && wpa_s->p2p_go_allow_dfs))) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4049 | return 0; |
| 4050 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4051 | if (is_6ghz_op_class(op_class)) { |
| 4052 | chans = center_channels_6ghz_80mhz; |
| 4053 | num_chans = ARRAY_SIZE(center_channels_6ghz_80mhz); |
| 4054 | } else { |
| 4055 | chans = center_channels_5ghz_80mhz; |
| 4056 | num_chans = ARRAY_SIZE(center_channels_5ghz_80mhz); |
| 4057 | } |
| 4058 | return wpas_p2p_get_center_80mhz(wpa_s, mode, channel, |
| 4059 | chans, num_chans); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4063 | int wpas_p2p_get_vht160_center(struct wpa_supplicant *wpa_s, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4064 | struct hostapd_hw_modes *mode, u8 channel, |
| 4065 | u8 op_class) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4066 | { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4067 | const u8 *chans; |
| 4068 | size_t num_chans; |
| 4069 | enum chan_allowed ret; |
| 4070 | |
| 4071 | ret = wpas_p2p_verify_channel(wpa_s, mode, op_class, channel, BW160); |
| 4072 | if (!(ret == ALLOWED || (ret == RADAR && wpa_s->p2p_go_allow_dfs))) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4073 | return 0; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4074 | if (is_6ghz_op_class(op_class)) { |
| 4075 | chans = center_channels_6ghz_160mhz; |
| 4076 | num_chans = ARRAY_SIZE(center_channels_6ghz_160mhz); |
| 4077 | } else { |
| 4078 | chans = center_channels_5ghz_160mhz; |
| 4079 | num_chans = ARRAY_SIZE(center_channels_5ghz_160mhz); |
| 4080 | } |
| 4081 | return wpas_p2p_get_center_160mhz(wpa_s, mode, channel, |
| 4082 | chans, num_chans); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4083 | } |
| 4084 | |
| 4085 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4086 | static int wpas_get_noa(void *ctx, const u8 *interface_addr, u8 *buf, |
| 4087 | size_t buf_len) |
| 4088 | { |
| 4089 | struct wpa_supplicant *wpa_s = ctx; |
| 4090 | |
| 4091 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 4092 | if (os_memcmp(wpa_s->own_addr, interface_addr, ETH_ALEN) == 0) |
| 4093 | break; |
| 4094 | } |
| 4095 | if (wpa_s == NULL) |
| 4096 | return -1; |
| 4097 | |
| 4098 | return wpa_drv_get_noa(wpa_s, buf, buf_len); |
| 4099 | } |
| 4100 | |
| 4101 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4102 | struct wpa_supplicant * wpas_get_p2p_go_iface(struct wpa_supplicant *wpa_s, |
| 4103 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4104 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4105 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 4106 | struct wpa_ssid *s = wpa_s->current_ssid; |
| 4107 | if (s == NULL) |
| 4108 | continue; |
| 4109 | if (s->mode != WPAS_MODE_P2P_GO && |
| 4110 | s->mode != WPAS_MODE_AP && |
| 4111 | s->mode != WPAS_MODE_P2P_GROUP_FORMATION) |
| 4112 | continue; |
| 4113 | if (s->ssid_len != ssid_len || |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 4114 | os_memcmp(ssid, s->ssid, ssid_len) != 0) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4115 | continue; |
| 4116 | return wpa_s; |
| 4117 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4118 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4119 | return NULL; |
| 4120 | |
| 4121 | } |
| 4122 | |
| 4123 | |
| 4124 | struct wpa_supplicant * wpas_get_p2p_client_iface(struct wpa_supplicant *wpa_s, |
| 4125 | const u8 *peer_dev_addr) |
| 4126 | { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4127 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 4128 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4129 | if (ssid && (ssid->mode != WPAS_MODE_INFRA || !ssid->p2p_group)) |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4130 | continue; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4131 | if (os_memcmp(wpa_s->go_dev_addr, peer_dev_addr, ETH_ALEN) == 0) |
| 4132 | return wpa_s; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4133 | } |
| 4134 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4135 | return NULL; |
| 4136 | } |
| 4137 | |
| 4138 | |
| 4139 | static int wpas_go_connected(void *ctx, const u8 *dev_addr) |
| 4140 | { |
| 4141 | struct wpa_supplicant *wpa_s = ctx; |
| 4142 | |
| 4143 | return wpas_get_p2p_client_iface(wpa_s, dev_addr) != NULL; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4144 | } |
| 4145 | |
| 4146 | |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 4147 | static int wpas_is_concurrent_session_active(void *ctx) |
| 4148 | { |
| 4149 | struct wpa_supplicant *wpa_s = ctx; |
| 4150 | struct wpa_supplicant *ifs; |
| 4151 | |
| 4152 | for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) { |
| 4153 | if (ifs == wpa_s) |
| 4154 | continue; |
| 4155 | if (ifs->wpa_state > WPA_ASSOCIATED) |
| 4156 | return 1; |
| 4157 | } |
| 4158 | return 0; |
| 4159 | } |
| 4160 | |
| 4161 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 4162 | static void wpas_p2p_debug_print(void *ctx, int level, const char *msg) |
| 4163 | { |
| 4164 | struct wpa_supplicant *wpa_s = ctx; |
| 4165 | wpa_msg_global(wpa_s, level, "P2P: %s", msg); |
| 4166 | } |
| 4167 | |
| 4168 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4169 | int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s, |
| 4170 | const char *conf_p2p_dev) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4171 | { |
| 4172 | struct wpa_interface iface; |
| 4173 | struct wpa_supplicant *p2pdev_wpa_s; |
| 4174 | char ifname[100]; |
| 4175 | char force_name[100]; |
| 4176 | int ret; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4177 | const u8 *if_addr = NULL; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4178 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4179 | ret = os_snprintf(ifname, sizeof(ifname), P2P_MGMT_DEVICE_PREFIX "%s", |
| 4180 | wpa_s->ifname); |
| 4181 | if (os_snprintf_error(sizeof(ifname), ret)) |
| 4182 | return -1; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4183 | /* Cut length at the maximum size. Note that we don't need to ensure |
| 4184 | * collision free names here as the created interface is not a netdev. |
| 4185 | */ |
| 4186 | ifname[IFNAMSIZ - 1] = '\0'; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4187 | force_name[0] = '\0'; |
| 4188 | wpa_s->pending_interface_type = WPA_IF_P2P_DEVICE; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4189 | |
| 4190 | if (wpa_s->conf->p2p_device_random_mac_addr == 2 && |
| 4191 | !is_zero_ether_addr(wpa_s->conf->p2p_device_persistent_mac_addr)) |
| 4192 | if_addr = wpa_s->conf->p2p_device_persistent_mac_addr; |
| 4193 | |
| 4194 | ret = wpa_drv_if_add(wpa_s, WPA_IF_P2P_DEVICE, ifname, if_addr, NULL, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4195 | force_name, wpa_s->pending_interface_addr, NULL); |
| 4196 | if (ret < 0) { |
| 4197 | wpa_printf(MSG_DEBUG, "P2P: Failed to create P2P Device interface"); |
| 4198 | return ret; |
| 4199 | } |
| 4200 | os_strlcpy(wpa_s->pending_interface_name, ifname, |
| 4201 | sizeof(wpa_s->pending_interface_name)); |
| 4202 | |
| 4203 | os_memset(&iface, 0, sizeof(iface)); |
| 4204 | iface.p2p_mgmt = 1; |
| 4205 | iface.ifname = wpa_s->pending_interface_name; |
| 4206 | iface.driver = wpa_s->driver->name; |
| 4207 | iface.driver_param = wpa_s->conf->driver_param; |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4208 | |
| 4209 | /* |
| 4210 | * If a P2P Device configuration file was given, use it as the interface |
| 4211 | * configuration file (instead of using parent's configuration file. |
| 4212 | */ |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4213 | if (conf_p2p_dev) { |
| 4214 | iface.confname = conf_p2p_dev; |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4215 | iface.ctrl_interface = NULL; |
| 4216 | } else { |
| 4217 | iface.confname = wpa_s->confname; |
| 4218 | iface.ctrl_interface = wpa_s->conf->ctrl_interface; |
| 4219 | } |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4220 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4221 | p2pdev_wpa_s = wpa_supplicant_add_iface(wpa_s->global, &iface, wpa_s); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4222 | if (!p2pdev_wpa_s) { |
| 4223 | wpa_printf(MSG_DEBUG, "P2P: Failed to add P2P Device interface"); |
| 4224 | return -1; |
| 4225 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4226 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4227 | p2pdev_wpa_s->p2pdev = p2pdev_wpa_s; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4228 | wpa_s->pending_interface_name[0] = '\0'; |
| 4229 | return 0; |
| 4230 | } |
| 4231 | |
| 4232 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4233 | static void wpas_presence_resp(void *ctx, const u8 *src, u8 status, |
| 4234 | const u8 *noa, size_t noa_len) |
| 4235 | { |
| 4236 | struct wpa_supplicant *wpa_s, *intf = ctx; |
| 4237 | char hex[100]; |
| 4238 | |
| 4239 | for (wpa_s = intf->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 4240 | if (wpa_s->waiting_presence_resp) |
| 4241 | break; |
| 4242 | } |
| 4243 | if (!wpa_s) { |
| 4244 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No group interface was waiting for presence response"); |
| 4245 | return; |
| 4246 | } |
| 4247 | wpa_s->waiting_presence_resp = 0; |
| 4248 | |
| 4249 | wpa_snprintf_hex(hex, sizeof(hex), noa, noa_len); |
| 4250 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PRESENCE_RESPONSE "src=" MACSTR |
| 4251 | " status=%u noa=%s", MAC2STR(src), status, hex); |
| 4252 | } |
| 4253 | |
| 4254 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4255 | static int wpas_get_persistent_group(void *ctx, const u8 *addr, const u8 *ssid, |
| 4256 | size_t ssid_len, u8 *go_dev_addr, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4257 | u8 *ret_ssid, size_t *ret_ssid_len, |
| 4258 | u8 *intended_iface_addr) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4259 | { |
| 4260 | struct wpa_supplicant *wpa_s = ctx; |
| 4261 | struct wpa_ssid *s; |
| 4262 | |
| 4263 | s = wpas_p2p_get_persistent(wpa_s, addr, ssid, ssid_len); |
| 4264 | if (s) { |
| 4265 | os_memcpy(ret_ssid, s->ssid, s->ssid_len); |
| 4266 | *ret_ssid_len = s->ssid_len; |
| 4267 | os_memcpy(go_dev_addr, s->bssid, ETH_ALEN); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4268 | |
| 4269 | if (s->mode != WPAS_MODE_P2P_GO) { |
| 4270 | os_memset(intended_iface_addr, 0, ETH_ALEN); |
| 4271 | } else if (wpas_p2p_create_iface(wpa_s)) { |
| 4272 | if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO)) |
| 4273 | return 0; |
| 4274 | |
| 4275 | os_memcpy(intended_iface_addr, |
| 4276 | wpa_s->pending_interface_addr, ETH_ALEN); |
| 4277 | } else { |
| 4278 | os_memcpy(intended_iface_addr, wpa_s->own_addr, |
| 4279 | ETH_ALEN); |
| 4280 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4281 | return 1; |
| 4282 | } |
| 4283 | |
| 4284 | return 0; |
| 4285 | } |
| 4286 | |
| 4287 | |
| 4288 | static int wpas_get_go_info(void *ctx, u8 *intended_addr, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4289 | u8 *ssid, size_t *ssid_len, int *group_iface, |
| 4290 | unsigned int *freq) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4291 | { |
| 4292 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4293 | struct wpa_supplicant *go; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4294 | struct wpa_ssid *s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4295 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4296 | /* |
| 4297 | * group_iface will be set to 1 only if a dedicated interface for P2P |
| 4298 | * role is required. First, we try to reuse an active GO. However, |
| 4299 | * if it is not present, we will try to reactivate an existing |
| 4300 | * persistent group and set group_iface to 1, so the caller will know |
| 4301 | * that the pending interface should be used. |
| 4302 | */ |
| 4303 | *group_iface = 0; |
| 4304 | |
| 4305 | if (freq) |
| 4306 | *freq = 0; |
| 4307 | |
| 4308 | go = wpas_p2p_get_go_group(wpa_s); |
| 4309 | if (!go) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4310 | s = wpas_p2p_get_persistent_go(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4311 | *group_iface = wpas_p2p_create_iface(wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4312 | if (s) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4313 | os_memcpy(intended_addr, s->bssid, ETH_ALEN); |
| 4314 | else |
| 4315 | return 0; |
| 4316 | } else { |
| 4317 | s = go->current_ssid; |
| 4318 | os_memcpy(intended_addr, go->own_addr, ETH_ALEN); |
| 4319 | if (freq) |
| 4320 | *freq = go->assoc_freq; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4321 | } |
| 4322 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4323 | os_memcpy(ssid, s->ssid, s->ssid_len); |
| 4324 | *ssid_len = s->ssid_len; |
| 4325 | |
| 4326 | return 1; |
| 4327 | } |
| 4328 | |
| 4329 | |
| 4330 | static int wpas_remove_stale_groups(void *ctx, const u8 *peer, const u8 *go, |
| 4331 | const u8 *ssid, size_t ssid_len) |
| 4332 | { |
| 4333 | struct wpa_supplicant *wpa_s = ctx; |
| 4334 | struct wpa_ssid *s; |
| 4335 | int save_config = 0; |
| 4336 | size_t i; |
| 4337 | |
| 4338 | /* Start with our first choice of Persistent Groups */ |
| 4339 | while ((s = wpas_p2p_get_persistent(wpa_s, peer, NULL, 0))) { |
| 4340 | if (go && ssid && ssid_len && |
| 4341 | s->ssid_len == ssid_len && |
| 4342 | os_memcmp(go, s->bssid, ETH_ALEN) == 0 && |
| 4343 | os_memcmp(ssid, s->ssid, ssid_len) == 0) |
| 4344 | break; |
| 4345 | |
| 4346 | /* Remove stale persistent group */ |
| 4347 | if (s->mode != WPAS_MODE_P2P_GO || s->num_p2p_clients <= 1) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4348 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4349 | "P2P: Remove stale persistent group id=%d", |
| 4350 | s->id); |
| 4351 | wpas_notify_persistent_group_removed(wpa_s, s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4352 | wpa_config_remove_network(wpa_s->conf, s->id); |
| 4353 | save_config = 1; |
| 4354 | continue; |
| 4355 | } |
| 4356 | |
| 4357 | for (i = 0; i < s->num_p2p_clients; i++) { |
| 4358 | if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN, |
| 4359 | peer, ETH_ALEN) != 0) |
| 4360 | continue; |
| 4361 | |
| 4362 | os_memmove(s->p2p_client_list + i * 2 * ETH_ALEN, |
| 4363 | s->p2p_client_list + (i + 1) * 2 * ETH_ALEN, |
| 4364 | (s->num_p2p_clients - i - 1) * 2 * ETH_ALEN); |
| 4365 | break; |
| 4366 | } |
| 4367 | s->num_p2p_clients--; |
| 4368 | save_config = 1; |
| 4369 | } |
| 4370 | |
| 4371 | if (save_config) |
| 4372 | p2p_config_write(wpa_s); |
| 4373 | |
| 4374 | /* Return TRUE if valid SSID remains */ |
| 4375 | return s != NULL; |
| 4376 | } |
| 4377 | |
| 4378 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4379 | static void wpas_p2ps_get_feat_cap_str(char *buf, size_t buf_len, |
| 4380 | const u8 *feat_cap, size_t feat_cap_len) |
| 4381 | { |
| 4382 | static const char pref[] = " feature_cap="; |
| 4383 | int ret; |
| 4384 | |
| 4385 | buf[0] = '\0'; |
| 4386 | |
| 4387 | /* |
| 4388 | * We expect a feature capability to contain at least one byte to be |
| 4389 | * reported. The string buffer provided by the caller function is |
| 4390 | * expected to be big enough to contain all bytes of the attribute for |
| 4391 | * known specifications. This function truncates the reported bytes if |
| 4392 | * the feature capability data exceeds the string buffer size. |
| 4393 | */ |
| 4394 | if (!feat_cap || !feat_cap_len || buf_len < sizeof(pref) + 2) |
| 4395 | return; |
| 4396 | |
| 4397 | os_memcpy(buf, pref, sizeof(pref)); |
| 4398 | ret = wpa_snprintf_hex(&buf[sizeof(pref) - 1], |
| 4399 | buf_len - sizeof(pref) + 1, |
| 4400 | feat_cap, feat_cap_len); |
| 4401 | |
| 4402 | if (ret != (2 * (int) feat_cap_len)) |
| 4403 | wpa_printf(MSG_WARNING, "P2PS feature_cap bytes truncated"); |
| 4404 | } |
| 4405 | |
| 4406 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4407 | static void wpas_p2ps_prov_complete(void *ctx, u8 status, const u8 *dev, |
| 4408 | const u8 *adv_mac, const u8 *ses_mac, |
| 4409 | const u8 *grp_mac, u32 adv_id, u32 ses_id, |
| 4410 | u8 conncap, int passwd_id, |
| 4411 | const u8 *persist_ssid, |
| 4412 | size_t persist_ssid_size, int response_done, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4413 | int prov_start, const char *session_info, |
| 4414 | const u8 *feat_cap, size_t feat_cap_len, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4415 | unsigned int freq, |
| 4416 | const u8 *group_ssid, size_t group_ssid_len) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4417 | { |
| 4418 | struct wpa_supplicant *wpa_s = ctx; |
| 4419 | u8 mac[ETH_ALEN]; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4420 | struct wpa_ssid *persistent_go, *stale, *s = NULL; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4421 | int save_config = 0; |
| 4422 | struct wpa_supplicant *go_wpa_s; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4423 | char feat_cap_str[256]; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4424 | |
| 4425 | if (!dev) |
| 4426 | return; |
| 4427 | |
| 4428 | os_memset(mac, 0, ETH_ALEN); |
| 4429 | if (!adv_mac) |
| 4430 | adv_mac = mac; |
| 4431 | if (!ses_mac) |
| 4432 | ses_mac = mac; |
| 4433 | if (!grp_mac) |
| 4434 | grp_mac = mac; |
| 4435 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4436 | wpas_p2ps_get_feat_cap_str(feat_cap_str, sizeof(feat_cap_str), |
| 4437 | feat_cap, feat_cap_len); |
| 4438 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4439 | if (prov_start) { |
| 4440 | if (session_info == NULL) { |
| 4441 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4442 | P2P_EVENT_P2PS_PROVISION_START MACSTR |
| 4443 | " adv_id=%x conncap=%x" |
| 4444 | " adv_mac=" MACSTR |
| 4445 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4446 | " dev_passwd_id=%d%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4447 | MAC2STR(dev), adv_id, conncap, |
| 4448 | MAC2STR(adv_mac), |
| 4449 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4450 | passwd_id, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4451 | } else { |
| 4452 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4453 | P2P_EVENT_P2PS_PROVISION_START MACSTR |
| 4454 | " adv_id=%x conncap=%x" |
| 4455 | " adv_mac=" MACSTR |
| 4456 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4457 | " dev_passwd_id=%d info='%s'%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4458 | MAC2STR(dev), adv_id, conncap, |
| 4459 | MAC2STR(adv_mac), |
| 4460 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4461 | passwd_id, session_info, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4462 | } |
| 4463 | return; |
| 4464 | } |
| 4465 | |
| 4466 | go_wpa_s = wpas_p2p_get_go_group(wpa_s); |
| 4467 | persistent_go = wpas_p2p_get_persistent_go(wpa_s); |
| 4468 | |
| 4469 | if (status && status != P2P_SC_SUCCESS_DEFERRED) { |
| 4470 | if (go_wpa_s && !p2p_group_go_member_count(wpa_s)) |
| 4471 | wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname); |
| 4472 | |
| 4473 | if (persistent_go && !persistent_go->num_p2p_clients) { |
| 4474 | /* remove empty persistent GO */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4475 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4476 | "P2P: Remove empty persistent group id=%d", |
| 4477 | persistent_go->id); |
| 4478 | wpas_notify_persistent_group_removed(wpa_s, |
| 4479 | persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4480 | wpa_config_remove_network(wpa_s->conf, |
| 4481 | persistent_go->id); |
| 4482 | } |
| 4483 | |
| 4484 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4485 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4486 | " status=%d" |
| 4487 | " adv_id=%x adv_mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4488 | " session=%x mac=" MACSTR "%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4489 | MAC2STR(dev), status, |
| 4490 | adv_id, MAC2STR(adv_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4491 | ses_id, MAC2STR(ses_mac), feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4492 | return; |
| 4493 | } |
| 4494 | |
| 4495 | /* Clean up stale persistent groups with this device */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4496 | if (persist_ssid && persist_ssid_size) |
| 4497 | s = wpas_p2p_get_persistent(wpa_s, dev, persist_ssid, |
| 4498 | persist_ssid_size); |
| 4499 | |
| 4500 | if (persist_ssid && s && s->mode != WPAS_MODE_P2P_GO && |
| 4501 | is_zero_ether_addr(grp_mac)) { |
| 4502 | wpa_dbg(wpa_s, MSG_ERROR, |
| 4503 | "P2P: Peer device is a GO in a persistent group, but it did not provide the intended MAC address"); |
| 4504 | return; |
| 4505 | } |
| 4506 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4507 | for (;;) { |
| 4508 | stale = wpas_p2p_get_persistent(wpa_s, dev, NULL, 0); |
| 4509 | if (!stale) |
| 4510 | break; |
| 4511 | |
| 4512 | if (s && s->ssid_len == stale->ssid_len && |
| 4513 | os_memcmp(stale->bssid, s->bssid, ETH_ALEN) == 0 && |
| 4514 | os_memcmp(stale->ssid, s->ssid, s->ssid_len) == 0) |
| 4515 | break; |
| 4516 | |
| 4517 | /* Remove stale persistent group */ |
| 4518 | if (stale->mode != WPAS_MODE_P2P_GO || |
| 4519 | stale->num_p2p_clients <= 1) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4520 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4521 | "P2P: Remove stale persistent group id=%d", |
| 4522 | stale->id); |
| 4523 | wpas_notify_persistent_group_removed(wpa_s, stale); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4524 | wpa_config_remove_network(wpa_s->conf, stale->id); |
| 4525 | } else { |
| 4526 | size_t i; |
| 4527 | |
| 4528 | for (i = 0; i < stale->num_p2p_clients; i++) { |
| 4529 | if (os_memcmp(stale->p2p_client_list + |
| 4530 | i * ETH_ALEN, |
| 4531 | dev, ETH_ALEN) == 0) { |
| 4532 | os_memmove(stale->p2p_client_list + |
| 4533 | i * ETH_ALEN, |
| 4534 | stale->p2p_client_list + |
| 4535 | (i + 1) * ETH_ALEN, |
| 4536 | (stale->num_p2p_clients - |
| 4537 | i - 1) * ETH_ALEN); |
| 4538 | break; |
| 4539 | } |
| 4540 | } |
| 4541 | stale->num_p2p_clients--; |
| 4542 | } |
| 4543 | save_config = 1; |
| 4544 | } |
| 4545 | |
| 4546 | if (save_config) |
| 4547 | p2p_config_write(wpa_s); |
| 4548 | |
| 4549 | if (s) { |
| 4550 | if (go_wpa_s && !p2p_group_go_member_count(wpa_s)) |
| 4551 | wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname); |
| 4552 | |
| 4553 | if (persistent_go && s != persistent_go && |
| 4554 | !persistent_go->num_p2p_clients) { |
| 4555 | /* remove empty persistent GO */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4556 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4557 | "P2P: Remove empty persistent group id=%d", |
| 4558 | persistent_go->id); |
| 4559 | wpas_notify_persistent_group_removed(wpa_s, |
| 4560 | persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4561 | wpa_config_remove_network(wpa_s->conf, |
| 4562 | persistent_go->id); |
| 4563 | /* Save config */ |
| 4564 | } |
| 4565 | |
| 4566 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4567 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4568 | " status=%d" |
| 4569 | " adv_id=%x adv_mac=" MACSTR |
| 4570 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4571 | " persist=%d%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4572 | MAC2STR(dev), status, |
| 4573 | adv_id, MAC2STR(adv_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4574 | ses_id, MAC2STR(ses_mac), s->id, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4575 | return; |
| 4576 | } |
| 4577 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4578 | wpa_s->global->pending_p2ps_group = 0; |
| 4579 | wpa_s->global->pending_p2ps_group_freq = 0; |
| 4580 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4581 | if (conncap == P2PS_SETUP_GROUP_OWNER) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4582 | /* |
| 4583 | * We need to copy the interface name. Simply saving a |
| 4584 | * pointer isn't enough, since if we use pending_interface_name |
| 4585 | * it will be overwritten when the group is added. |
| 4586 | */ |
| 4587 | char go_ifname[100]; |
| 4588 | |
| 4589 | go_ifname[0] = '\0'; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4590 | if (!go_wpa_s) { |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4591 | if (!response_done) { |
| 4592 | wpa_s->global->pending_p2ps_group = 1; |
| 4593 | wpa_s->global->pending_p2ps_group_freq = freq; |
| 4594 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4595 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4596 | if (!wpas_p2p_create_iface(wpa_s)) |
| 4597 | os_memcpy(go_ifname, wpa_s->ifname, |
| 4598 | sizeof(go_ifname)); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4599 | else if (wpa_s->pending_interface_name[0]) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4600 | os_memcpy(go_ifname, |
| 4601 | wpa_s->pending_interface_name, |
| 4602 | sizeof(go_ifname)); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4603 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4604 | if (!go_ifname[0]) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4605 | wpas_p2ps_prov_complete( |
| 4606 | wpa_s, P2P_SC_FAIL_UNKNOWN_GROUP, |
| 4607 | dev, adv_mac, ses_mac, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4608 | grp_mac, adv_id, ses_id, 0, 0, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4609 | NULL, 0, 0, 0, NULL, NULL, 0, 0, |
| 4610 | NULL, 0); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4611 | return; |
| 4612 | } |
| 4613 | |
| 4614 | /* If PD Resp complete, start up the GO */ |
| 4615 | if (response_done && persistent_go) { |
| 4616 | wpas_p2p_group_add_persistent( |
| 4617 | wpa_s, persistent_go, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4618 | 0, 0, freq, 0, 0, 0, 0, 0, 0, NULL, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4619 | persistent_go->mode == |
| 4620 | WPAS_MODE_P2P_GO ? |
| 4621 | P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame^] | 4622 | 0, 0, false, 0); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4623 | } else if (response_done) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4624 | wpas_p2p_group_add(wpa_s, 1, freq, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4625 | 0, 0, 0, 0, 0, 0, false); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4626 | } |
| 4627 | |
| 4628 | if (passwd_id == DEV_PW_P2PS_DEFAULT) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4629 | os_memcpy(wpa_s->p2ps_join_addr, grp_mac, |
| 4630 | ETH_ALEN); |
| 4631 | wpa_s->p2ps_method_config_any = 1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4632 | } |
| 4633 | } else if (passwd_id == DEV_PW_P2PS_DEFAULT) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4634 | os_memcpy(go_ifname, go_wpa_s->ifname, |
| 4635 | sizeof(go_ifname)); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4636 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4637 | if (is_zero_ether_addr(grp_mac)) { |
| 4638 | wpa_dbg(go_wpa_s, MSG_DEBUG, |
| 4639 | "P2P: Setting PIN-1 for ANY"); |
| 4640 | wpa_supplicant_ap_wps_pin(go_wpa_s, NULL, |
| 4641 | "12345670", NULL, 0, |
| 4642 | 0); |
| 4643 | } else { |
| 4644 | wpa_dbg(go_wpa_s, MSG_DEBUG, |
| 4645 | "P2P: Setting PIN-1 for " MACSTR, |
| 4646 | MAC2STR(grp_mac)); |
| 4647 | wpa_supplicant_ap_wps_pin(go_wpa_s, grp_mac, |
| 4648 | "12345670", NULL, 0, |
| 4649 | 0); |
| 4650 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4651 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4652 | os_memcpy(wpa_s->p2ps_join_addr, grp_mac, ETH_ALEN); |
| 4653 | wpa_s->p2ps_method_config_any = 1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4654 | } |
| 4655 | |
| 4656 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4657 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4658 | " status=%d conncap=%x" |
| 4659 | " adv_id=%x adv_mac=" MACSTR |
| 4660 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4661 | " dev_passwd_id=%d go=%s%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4662 | MAC2STR(dev), status, conncap, |
| 4663 | adv_id, MAC2STR(adv_mac), |
| 4664 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4665 | passwd_id, go_ifname, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4666 | return; |
| 4667 | } |
| 4668 | |
| 4669 | if (go_wpa_s && !p2p_group_go_member_count(wpa_s)) |
| 4670 | wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname); |
| 4671 | |
| 4672 | if (persistent_go && !persistent_go->num_p2p_clients) { |
| 4673 | /* remove empty persistent GO */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4674 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4675 | "P2P: Remove empty persistent group id=%d", |
| 4676 | persistent_go->id); |
| 4677 | wpas_notify_persistent_group_removed(wpa_s, persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4678 | wpa_config_remove_network(wpa_s->conf, persistent_go->id); |
| 4679 | } |
| 4680 | |
| 4681 | if (conncap == P2PS_SETUP_CLIENT) { |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4682 | char ssid_hex[32 * 2 + 1]; |
| 4683 | |
| 4684 | if (group_ssid) |
| 4685 | wpa_snprintf_hex(ssid_hex, sizeof(ssid_hex), |
| 4686 | group_ssid, group_ssid_len); |
| 4687 | else |
| 4688 | ssid_hex[0] = '\0'; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4689 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4690 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4691 | " status=%d conncap=%x" |
| 4692 | " adv_id=%x adv_mac=" MACSTR |
| 4693 | " session=%x mac=" MACSTR |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4694 | " dev_passwd_id=%d join=" MACSTR "%s%s%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4695 | MAC2STR(dev), status, conncap, |
| 4696 | adv_id, MAC2STR(adv_mac), |
| 4697 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4698 | passwd_id, MAC2STR(grp_mac), feat_cap_str, |
| 4699 | group_ssid ? " group_ssid=" : "", ssid_hex); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4700 | } else { |
| 4701 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4702 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4703 | " status=%d conncap=%x" |
| 4704 | " adv_id=%x adv_mac=" MACSTR |
| 4705 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4706 | " dev_passwd_id=%d%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4707 | MAC2STR(dev), status, conncap, |
| 4708 | adv_id, MAC2STR(adv_mac), |
| 4709 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4710 | passwd_id, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4711 | } |
| 4712 | } |
| 4713 | |
| 4714 | |
Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 4715 | static int _wpas_p2p_in_progress(void *ctx) |
| 4716 | { |
| 4717 | struct wpa_supplicant *wpa_s = ctx; |
| 4718 | return wpas_p2p_in_progress(wpa_s); |
| 4719 | } |
| 4720 | |
| 4721 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4722 | static int wpas_prov_disc_resp_cb(void *ctx) |
| 4723 | { |
| 4724 | struct wpa_supplicant *wpa_s = ctx; |
| 4725 | struct wpa_ssid *persistent_go; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4726 | unsigned int freq; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4727 | |
| 4728 | if (!wpa_s->global->pending_p2ps_group) |
| 4729 | return 0; |
| 4730 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4731 | freq = wpa_s->global->pending_p2ps_group_freq; |
| 4732 | wpa_s->global->pending_p2ps_group_freq = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4733 | wpa_s->global->pending_p2ps_group = 0; |
| 4734 | |
| 4735 | if (wpas_p2p_get_go_group(wpa_s)) |
| 4736 | return 0; |
| 4737 | persistent_go = wpas_p2p_get_persistent_go(wpa_s); |
| 4738 | |
| 4739 | if (persistent_go) { |
| 4740 | wpas_p2p_group_add_persistent( |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4741 | wpa_s, persistent_go, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 4742 | NULL, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4743 | persistent_go->mode == WPAS_MODE_P2P_GO ? |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4744 | P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0, 0, |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame^] | 4745 | is_p2p_allow_6ghz(wpa_s->global->p2p), 0); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4746 | } else { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4747 | wpas_p2p_group_add(wpa_s, 1, freq, 0, 0, 0, 0, 0, 0, |
| 4748 | is_p2p_allow_6ghz(wpa_s->global->p2p)); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4749 | } |
| 4750 | |
| 4751 | return 1; |
| 4752 | } |
| 4753 | |
| 4754 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4755 | static int wpas_p2p_get_pref_freq_list(void *ctx, int go, |
| 4756 | unsigned int *len, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4757 | struct weighted_pcl *freq_list) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4758 | { |
| 4759 | struct wpa_supplicant *wpa_s = ctx; |
| 4760 | |
| 4761 | return wpa_drv_get_pref_freq_list(wpa_s, go ? WPA_IF_P2P_GO : |
| 4762 | WPA_IF_P2P_CLIENT, len, freq_list); |
| 4763 | } |
| 4764 | |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4765 | int wpas_p2p_mac_setup(struct wpa_supplicant *wpa_s) |
| 4766 | { |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4767 | int ret = 0; |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4768 | u8 addr[ETH_ALEN] = {0}; |
| 4769 | |
| 4770 | if (wpa_s->conf->p2p_device_random_mac_addr == 0) |
| 4771 | return 0; |
| 4772 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4773 | if (wpa_s->conf->p2p_device_random_mac_addr == 2) { |
| 4774 | if (is_zero_ether_addr( |
| 4775 | wpa_s->conf->p2p_device_persistent_mac_addr) && |
| 4776 | !is_zero_ether_addr(wpa_s->own_addr)) { |
| 4777 | os_memcpy(wpa_s->conf->p2p_device_persistent_mac_addr, |
| 4778 | wpa_s->own_addr, ETH_ALEN); |
| 4779 | } |
| 4780 | return 0; |
| 4781 | } |
| 4782 | |
| 4783 | if (!wpa_s->conf->ssid) { |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4784 | if (random_mac_addr(addr) < 0) { |
| 4785 | wpa_msg(wpa_s, MSG_INFO, |
| 4786 | "Failed to generate random MAC address"); |
| 4787 | return -EINVAL; |
| 4788 | } |
| 4789 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 4790 | /* Store generated MAC address. */ |
| 4791 | os_memcpy(wpa_s->conf->p2p_device_persistent_mac_addr, addr, |
| 4792 | ETH_ALEN); |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4793 | } else { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 4794 | /* If there are existing saved groups, restore last MAC address. |
| 4795 | * if there is no last used MAC address, the last one is |
| 4796 | * factory MAC. */ |
| 4797 | if (is_zero_ether_addr( |
| 4798 | wpa_s->conf->p2p_device_persistent_mac_addr)) |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4799 | return 0; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 4800 | os_memcpy(addr, wpa_s->conf->p2p_device_persistent_mac_addr, |
| 4801 | ETH_ALEN); |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4802 | wpa_msg(wpa_s, MSG_DEBUG, "Restore last used MAC address."); |
| 4803 | } |
| 4804 | |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4805 | ret = wpa_drv_set_mac_addr(wpa_s, addr); |
| 4806 | |
| 4807 | if (ret < 0) { |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4808 | wpa_msg(wpa_s, MSG_INFO, |
| 4809 | "Failed to set random MAC address"); |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4810 | return ret; |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4811 | } |
| 4812 | |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4813 | ret = wpa_supplicant_update_mac_addr(wpa_s); |
| 4814 | |
| 4815 | if (ret < 0) { |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4816 | wpa_msg(wpa_s, MSG_INFO, |
| 4817 | "Could not update MAC address information"); |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4818 | return ret; |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4819 | } |
| 4820 | |
| 4821 | wpa_msg(wpa_s, MSG_DEBUG, "Using random MAC address " MACSTR, |
| 4822 | MAC2STR(addr)); |
| 4823 | |
| 4824 | return 0; |
| 4825 | } |
| 4826 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4827 | /** |
| 4828 | * wpas_p2p_init - Initialize P2P module for %wpa_supplicant |
| 4829 | * @global: Pointer to global data from wpa_supplicant_init() |
| 4830 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 4831 | * Returns: 0 on success, -1 on failure |
| 4832 | */ |
| 4833 | int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s) |
| 4834 | { |
| 4835 | struct p2p_config p2p; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4836 | int i; |
| 4837 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 4838 | if (wpa_s->conf->p2p_disabled) |
| 4839 | return 0; |
| 4840 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4841 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE)) |
| 4842 | return 0; |
| 4843 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4844 | if (global->p2p) |
| 4845 | return 0; |
| 4846 | |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4847 | if (wpas_p2p_mac_setup(wpa_s) < 0) { |
| 4848 | wpa_msg(wpa_s, MSG_ERROR, |
| 4849 | "Failed to initialize P2P random MAC address."); |
| 4850 | return -1; |
| 4851 | } |
| 4852 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4853 | os_memset(&p2p, 0, sizeof(p2p)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4854 | p2p.cb_ctx = wpa_s; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 4855 | p2p.debug_print = wpas_p2p_debug_print; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4856 | p2p.p2p_scan = wpas_p2p_scan; |
| 4857 | p2p.send_action = wpas_send_action; |
| 4858 | p2p.send_action_done = wpas_send_action_done; |
| 4859 | p2p.go_neg_completed = wpas_go_neg_completed; |
| 4860 | p2p.go_neg_req_rx = wpas_go_neg_req_rx; |
| 4861 | p2p.dev_found = wpas_dev_found; |
| 4862 | p2p.dev_lost = wpas_dev_lost; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 4863 | p2p.find_stopped = wpas_find_stopped; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4864 | p2p.start_listen = wpas_start_listen; |
| 4865 | p2p.stop_listen = wpas_stop_listen; |
| 4866 | p2p.send_probe_resp = wpas_send_probe_resp; |
| 4867 | p2p.sd_request = wpas_sd_request; |
| 4868 | p2p.sd_response = wpas_sd_response; |
| 4869 | p2p.prov_disc_req = wpas_prov_disc_req; |
| 4870 | p2p.prov_disc_resp = wpas_prov_disc_resp; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 4871 | p2p.prov_disc_fail = wpas_prov_disc_fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4872 | p2p.invitation_process = wpas_invitation_process; |
| 4873 | p2p.invitation_received = wpas_invitation_received; |
| 4874 | p2p.invitation_result = wpas_invitation_result; |
| 4875 | p2p.get_noa = wpas_get_noa; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4876 | p2p.go_connected = wpas_go_connected; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4877 | p2p.presence_resp = wpas_presence_resp; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 4878 | p2p.is_concurrent_session_active = wpas_is_concurrent_session_active; |
Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 4879 | p2p.is_p2p_in_progress = _wpas_p2p_in_progress; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4880 | p2p.get_persistent_group = wpas_get_persistent_group; |
| 4881 | p2p.get_go_info = wpas_get_go_info; |
| 4882 | p2p.remove_stale_groups = wpas_remove_stale_groups; |
| 4883 | p2p.p2ps_prov_complete = wpas_p2ps_prov_complete; |
| 4884 | p2p.prov_disc_resp_cb = wpas_prov_disc_resp_cb; |
| 4885 | p2p.p2ps_group_capability = p2ps_group_capability; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4886 | p2p.get_pref_freq_list = wpas_p2p_get_pref_freq_list; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4887 | p2p.p2p_6ghz_disable = wpa_s->conf->p2p_6ghz_disable; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4888 | |
| 4889 | os_memcpy(wpa_s->global->p2p_dev_addr, wpa_s->own_addr, ETH_ALEN); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4890 | os_memcpy(p2p.dev_addr, wpa_s->global->p2p_dev_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4891 | p2p.dev_name = wpa_s->conf->device_name; |
| 4892 | p2p.manufacturer = wpa_s->conf->manufacturer; |
| 4893 | p2p.model_name = wpa_s->conf->model_name; |
| 4894 | p2p.model_number = wpa_s->conf->model_number; |
| 4895 | p2p.serial_number = wpa_s->conf->serial_number; |
| 4896 | if (wpa_s->wps) { |
| 4897 | os_memcpy(p2p.uuid, wpa_s->wps->uuid, 16); |
| 4898 | p2p.config_methods = wpa_s->wps->config_methods; |
| 4899 | } |
| 4900 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4901 | if (wpas_p2p_setup_channels(wpa_s, &p2p.channels, &p2p.cli_channels, |
| 4902 | p2p.p2p_6ghz_disable)) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4903 | wpa_printf(MSG_ERROR, |
| 4904 | "P2P: Failed to configure supported channel list"); |
| 4905 | return -1; |
| 4906 | } |
| 4907 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4908 | if (wpa_s->conf->p2p_listen_reg_class && |
| 4909 | wpa_s->conf->p2p_listen_channel) { |
| 4910 | p2p.reg_class = wpa_s->conf->p2p_listen_reg_class; |
| 4911 | p2p.channel = wpa_s->conf->p2p_listen_channel; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 4912 | p2p.channel_forced = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4913 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4914 | /* |
| 4915 | * Pick one of the social channels randomly as the listen |
| 4916 | * channel. |
| 4917 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4918 | if (p2p_config_get_random_social(&p2p, &p2p.reg_class, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4919 | &p2p.channel, |
| 4920 | &global->p2p_go_avoid_freq, |
| 4921 | &global->p2p_disallow_freq) != |
| 4922 | 0) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 4923 | wpa_printf(MSG_INFO, |
| 4924 | "P2P: No social channels supported by the driver - do not enable P2P"); |
| 4925 | return 0; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4926 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 4927 | p2p.channel_forced = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4928 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4929 | wpa_printf(MSG_DEBUG, "P2P: Own listen channel: %d:%d", |
| 4930 | p2p.reg_class, p2p.channel); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4931 | |
| 4932 | if (wpa_s->conf->p2p_oper_reg_class && |
| 4933 | wpa_s->conf->p2p_oper_channel) { |
| 4934 | p2p.op_reg_class = wpa_s->conf->p2p_oper_reg_class; |
| 4935 | p2p.op_channel = wpa_s->conf->p2p_oper_channel; |
| 4936 | p2p.cfg_op_channel = 1; |
| 4937 | wpa_printf(MSG_DEBUG, "P2P: Configured operating channel: " |
| 4938 | "%d:%d", p2p.op_reg_class, p2p.op_channel); |
| 4939 | |
| 4940 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4941 | /* |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4942 | * Use random operation channel from 2.4 GHz band social |
| 4943 | * channels (1, 6, 11) or band 60 GHz social channel (2) if no |
| 4944 | * other preference is indicated. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4945 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4946 | if (p2p_config_get_random_social(&p2p, &p2p.op_reg_class, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4947 | &p2p.op_channel, NULL, |
| 4948 | NULL) != 0) { |
| 4949 | wpa_printf(MSG_INFO, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4950 | "P2P: Failed to select random social channel as operation channel"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4951 | p2p.op_reg_class = 0; |
| 4952 | p2p.op_channel = 0; |
| 4953 | /* This will be overridden during group setup in |
| 4954 | * p2p_prepare_channel(), so allow setup to continue. */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4955 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4956 | p2p.cfg_op_channel = 0; |
| 4957 | wpa_printf(MSG_DEBUG, "P2P: Random operating channel: " |
| 4958 | "%d:%d", p2p.op_reg_class, p2p.op_channel); |
| 4959 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 4960 | |
| 4961 | if (wpa_s->conf->p2p_pref_chan && wpa_s->conf->num_p2p_pref_chan) { |
| 4962 | p2p.pref_chan = wpa_s->conf->p2p_pref_chan; |
| 4963 | p2p.num_pref_chan = wpa_s->conf->num_p2p_pref_chan; |
| 4964 | } |
| 4965 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4966 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) { |
| 4967 | os_memcpy(p2p.country, wpa_s->conf->country, 2); |
| 4968 | p2p.country[2] = 0x04; |
| 4969 | } else |
| 4970 | os_memcpy(p2p.country, "XX\x04", 3); |
| 4971 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4972 | os_memcpy(p2p.pri_dev_type, wpa_s->conf->device_type, |
| 4973 | WPS_DEV_TYPE_LEN); |
| 4974 | |
| 4975 | p2p.num_sec_dev_types = wpa_s->conf->num_sec_device_types; |
| 4976 | os_memcpy(p2p.sec_dev_type, wpa_s->conf->sec_device_type, |
| 4977 | p2p.num_sec_dev_types * WPS_DEV_TYPE_LEN); |
| 4978 | |
| 4979 | p2p.concurrent_operations = !!(wpa_s->drv_flags & |
| 4980 | WPA_DRIVER_FLAGS_P2P_CONCURRENT); |
| 4981 | |
| 4982 | p2p.max_peers = 100; |
| 4983 | |
| 4984 | if (wpa_s->conf->p2p_ssid_postfix) { |
| 4985 | p2p.ssid_postfix_len = |
| 4986 | os_strlen(wpa_s->conf->p2p_ssid_postfix); |
| 4987 | if (p2p.ssid_postfix_len > sizeof(p2p.ssid_postfix)) |
| 4988 | p2p.ssid_postfix_len = sizeof(p2p.ssid_postfix); |
| 4989 | os_memcpy(p2p.ssid_postfix, wpa_s->conf->p2p_ssid_postfix, |
| 4990 | p2p.ssid_postfix_len); |
| 4991 | } |
| 4992 | |
| 4993 | p2p.p2p_intra_bss = wpa_s->conf->p2p_intra_bss; |
| 4994 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4995 | p2p.max_listen = wpa_s->max_remain_on_chan; |
| 4996 | |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 4997 | if (wpa_s->conf->p2p_passphrase_len >= 8 && |
| 4998 | wpa_s->conf->p2p_passphrase_len <= 63) |
| 4999 | p2p.passphrase_len = wpa_s->conf->p2p_passphrase_len; |
| 5000 | else |
| 5001 | p2p.passphrase_len = 8; |
| 5002 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5003 | global->p2p = p2p_init(&p2p); |
| 5004 | if (global->p2p == NULL) |
| 5005 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5006 | global->p2p_init_wpa_s = wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5007 | |
| 5008 | for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) { |
| 5009 | if (wpa_s->conf->wps_vendor_ext[i] == NULL) |
| 5010 | continue; |
| 5011 | p2p_add_wps_vendor_extension( |
| 5012 | global->p2p, wpa_s->conf->wps_vendor_ext[i]); |
| 5013 | } |
| 5014 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5015 | p2p_set_no_go_freq(global->p2p, &wpa_s->conf->p2p_no_go_freq); |
| 5016 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5017 | return 0; |
| 5018 | } |
| 5019 | |
| 5020 | |
| 5021 | /** |
| 5022 | * wpas_p2p_deinit - Deinitialize per-interface P2P data |
| 5023 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 5024 | * |
| 5025 | * This function deinitialize per-interface P2P data. |
| 5026 | */ |
| 5027 | void wpas_p2p_deinit(struct wpa_supplicant *wpa_s) |
| 5028 | { |
| 5029 | if (wpa_s->driver && wpa_s->drv_priv) |
| 5030 | wpa_drv_probe_req_report(wpa_s, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5031 | |
| 5032 | if (wpa_s->go_params) { |
| 5033 | /* Clear any stored provisioning info */ |
| 5034 | p2p_clear_provisioning_info( |
| 5035 | wpa_s->global->p2p, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5036 | wpa_s->go_params->peer_device_addr); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5037 | } |
| 5038 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5039 | os_free(wpa_s->go_params); |
| 5040 | wpa_s->go_params = NULL; |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 5041 | eloop_cancel_timeout(wpas_p2p_psk_failure_removal, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5042 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 5043 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5044 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5045 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
| 5046 | eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL); |
| 5047 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 5048 | eloop_cancel_timeout(wpas_p2p_group_freq_conflict, wpa_s, NULL); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5049 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, wpa_s, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5050 | wpas_p2p_listen_work_done(wpa_s); |
| 5051 | if (wpa_s->p2p_send_action_work) { |
| 5052 | os_free(wpa_s->p2p_send_action_work->ctx); |
| 5053 | radio_work_done(wpa_s->p2p_send_action_work); |
| 5054 | wpa_s->p2p_send_action_work = NULL; |
| 5055 | } |
| 5056 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5057 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5058 | wpabuf_free(wpa_s->p2p_oob_dev_pw); |
| 5059 | wpa_s->p2p_oob_dev_pw = NULL; |
| 5060 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5061 | os_free(wpa_s->p2p_group_common_freqs); |
| 5062 | wpa_s->p2p_group_common_freqs = NULL; |
| 5063 | wpa_s->p2p_group_common_freqs_num = 0; |
| 5064 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5065 | /* TODO: remove group interface from the driver if this wpa_s instance |
| 5066 | * is on top of a P2P group interface */ |
| 5067 | } |
| 5068 | |
| 5069 | |
| 5070 | /** |
| 5071 | * wpas_p2p_deinit_global - Deinitialize global P2P module |
| 5072 | * @global: Pointer to global data from wpa_supplicant_init() |
| 5073 | * |
| 5074 | * This function deinitializes the global (per device) P2P module. |
| 5075 | */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5076 | static void wpas_p2p_deinit_global(struct wpa_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5077 | { |
| 5078 | struct wpa_supplicant *wpa_s, *tmp; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5079 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5080 | wpa_s = global->ifaces; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5081 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5082 | wpas_p2p_service_flush(global->p2p_init_wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5083 | |
| 5084 | /* Remove remaining P2P group interfaces */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5085 | while (wpa_s && wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) |
| 5086 | wpa_s = wpa_s->next; |
| 5087 | while (wpa_s) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5088 | tmp = global->ifaces; |
| 5089 | while (tmp && |
| 5090 | (tmp == wpa_s || |
| 5091 | tmp->p2p_group_interface == NOT_P2P_GROUP_INTERFACE)) { |
| 5092 | tmp = tmp->next; |
| 5093 | } |
| 5094 | if (tmp == NULL) |
| 5095 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5096 | /* Disconnect from the P2P group and deinit the interface */ |
| 5097 | wpas_p2p_disconnect(tmp); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5098 | } |
| 5099 | |
| 5100 | /* |
| 5101 | * Deinit GO data on any possibly remaining interface (if main |
| 5102 | * interface is used as GO). |
| 5103 | */ |
| 5104 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 5105 | if (wpa_s->ap_iface) |
| 5106 | wpas_p2p_group_deinit(wpa_s); |
| 5107 | } |
| 5108 | |
| 5109 | p2p_deinit(global->p2p); |
| 5110 | global->p2p = NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5111 | global->p2p_init_wpa_s = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5112 | } |
| 5113 | |
| 5114 | |
| 5115 | static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s) |
| 5116 | { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5117 | if (wpa_s->conf->p2p_no_group_iface) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5118 | return 0; /* separate interface disabled per configuration */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5119 | if (wpa_s->drv_flags & |
| 5120 | (WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE | |
| 5121 | WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P)) |
| 5122 | return 1; /* P2P group requires a new interface in every case |
| 5123 | */ |
| 5124 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CONCURRENT)) |
| 5125 | return 0; /* driver does not support concurrent operations */ |
| 5126 | if (wpa_s->global->ifaces->next) |
| 5127 | return 1; /* more that one interface already in use */ |
| 5128 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
| 5129 | return 1; /* this interface is already in use */ |
| 5130 | return 0; |
| 5131 | } |
| 5132 | |
| 5133 | |
| 5134 | static int wpas_p2p_start_go_neg(struct wpa_supplicant *wpa_s, |
| 5135 | const u8 *peer_addr, |
| 5136 | enum p2p_wps_method wps_method, |
| 5137 | int go_intent, const u8 *own_interface_addr, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5138 | unsigned int force_freq, int persistent_group, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5139 | struct wpa_ssid *ssid, unsigned int pref_freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5140 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5141 | if (persistent_group && wpa_s->conf->persistent_reconnect) |
| 5142 | persistent_group = 2; |
| 5143 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5144 | /* |
| 5145 | * Increase GO config timeout if HT40 is used since it takes some time |
| 5146 | * to scan channels for coex purposes before the BSS can be started. |
| 5147 | */ |
| 5148 | p2p_set_config_timeout(wpa_s->global->p2p, |
| 5149 | wpa_s->p2p_go_ht40 ? 255 : 100, 20); |
| 5150 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5151 | return p2p_connect(wpa_s->global->p2p, peer_addr, wps_method, |
| 5152 | go_intent, own_interface_addr, force_freq, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5153 | persistent_group, ssid ? ssid->ssid : NULL, |
| 5154 | ssid ? ssid->ssid_len : 0, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5155 | wpa_s->p2p_pd_before_go_neg, pref_freq, |
| 5156 | wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id : |
| 5157 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5158 | } |
| 5159 | |
| 5160 | |
| 5161 | static int wpas_p2p_auth_go_neg(struct wpa_supplicant *wpa_s, |
| 5162 | const u8 *peer_addr, |
| 5163 | enum p2p_wps_method wps_method, |
| 5164 | int go_intent, const u8 *own_interface_addr, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5165 | unsigned int force_freq, int persistent_group, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5166 | struct wpa_ssid *ssid, unsigned int pref_freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5167 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5168 | if (persistent_group && wpa_s->conf->persistent_reconnect) |
| 5169 | persistent_group = 2; |
| 5170 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5171 | return p2p_authorize(wpa_s->global->p2p, peer_addr, wps_method, |
| 5172 | go_intent, own_interface_addr, force_freq, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5173 | persistent_group, ssid ? ssid->ssid : NULL, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5174 | ssid ? ssid->ssid_len : 0, pref_freq, |
| 5175 | wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id : |
| 5176 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5177 | } |
| 5178 | |
| 5179 | |
| 5180 | static void wpas_p2p_check_join_scan_limit(struct wpa_supplicant *wpa_s) |
| 5181 | { |
| 5182 | wpa_s->p2p_join_scan_count++; |
| 5183 | wpa_printf(MSG_DEBUG, "P2P: Join scan attempt %d", |
| 5184 | wpa_s->p2p_join_scan_count); |
| 5185 | if (wpa_s->p2p_join_scan_count > P2P_MAX_JOIN_SCAN_ATTEMPTS) { |
| 5186 | wpa_printf(MSG_DEBUG, "P2P: Failed to find GO " MACSTR |
| 5187 | " for join operationg - stop join attempt", |
| 5188 | MAC2STR(wpa_s->pending_join_iface_addr)); |
| 5189 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5190 | if (wpa_s->p2p_auto_pd) { |
| 5191 | wpa_s->p2p_auto_pd = 0; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5192 | wpa_msg_global(wpa_s, MSG_INFO, |
| 5193 | P2P_EVENT_PROV_DISC_FAILURE |
| 5194 | " p2p_dev_addr=" MACSTR " status=N/A", |
| 5195 | MAC2STR(wpa_s->pending_join_dev_addr)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5196 | return; |
| 5197 | } |
Jimmy Chen | b7b3f4d | 2020-09-02 16:50:11 +0800 | [diff] [blame] | 5198 | if (wpa_s->p2p_fallback_to_go_neg) { |
| 5199 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Join operating " |
| 5200 | "failed - fall back to GO Negotiation"); |
| 5201 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
| 5202 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 5203 | "reason=join-failed"); |
| 5204 | wpas_p2p_fallback_to_go_neg(wpa_s, 0); |
| 5205 | return; |
| 5206 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5207 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5208 | P2P_EVENT_GROUP_FORMATION_FAILURE); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5209 | wpas_notify_p2p_group_formation_failure(wpa_s, ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5210 | } |
| 5211 | } |
| 5212 | |
| 5213 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5214 | static int wpas_check_freq_conflict(struct wpa_supplicant *wpa_s, int freq) |
| 5215 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5216 | int res; |
| 5217 | unsigned int num, i; |
| 5218 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5219 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5220 | if (wpas_p2p_num_unused_channels(wpa_s) > 0) { |
| 5221 | /* Multiple channels are supported and not all are in use */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5222 | return 0; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5223 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5224 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5225 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 5226 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5227 | if (!freqs) |
| 5228 | return 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5229 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5230 | num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, |
| 5231 | wpa_s->num_multichan_concurrent); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5232 | |
| 5233 | for (i = 0; i < num; i++) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5234 | if (freqs[i].freq == freq) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5235 | wpa_printf(MSG_DEBUG, "P2P: Frequency %d MHz in use by another virtual interface and can be used", |
| 5236 | freq); |
| 5237 | res = 0; |
| 5238 | goto exit_free; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5239 | } |
| 5240 | } |
| 5241 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5242 | wpa_printf(MSG_DEBUG, "P2P: No valid operating frequencies"); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5243 | res = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5244 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5245 | exit_free: |
| 5246 | os_free(freqs); |
| 5247 | return res; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5248 | } |
| 5249 | |
| 5250 | |
| 5251 | static int wpas_p2p_peer_go(struct wpa_supplicant *wpa_s, |
| 5252 | const u8 *peer_dev_addr) |
| 5253 | { |
| 5254 | struct wpa_bss *bss; |
| 5255 | int updated; |
| 5256 | |
| 5257 | bss = wpa_bss_get_p2p_dev_addr(wpa_s, peer_dev_addr); |
| 5258 | if (bss == NULL) |
| 5259 | return -1; |
| 5260 | if (bss->last_update_idx < wpa_s->bss_update_idx) { |
| 5261 | wpa_printf(MSG_DEBUG, "P2P: Peer BSS entry not updated in the " |
| 5262 | "last scan"); |
| 5263 | return 0; |
| 5264 | } |
| 5265 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5266 | updated = os_reltime_before(&wpa_s->p2p_auto_started, |
| 5267 | &bss->last_update); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5268 | wpa_printf(MSG_DEBUG, "P2P: Current BSS entry for peer updated at " |
| 5269 | "%ld.%06ld (%supdated in last scan)", |
| 5270 | bss->last_update.sec, bss->last_update.usec, |
| 5271 | updated ? "": "not "); |
| 5272 | |
| 5273 | return updated; |
| 5274 | } |
| 5275 | |
| 5276 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5277 | static void wpas_p2p_scan_res_join(struct wpa_supplicant *wpa_s, |
| 5278 | struct wpa_scan_results *scan_res) |
| 5279 | { |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5280 | struct wpa_bss *bss = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5281 | int freq; |
| 5282 | u8 iface_addr[ETH_ALEN]; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5283 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5284 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
| 5285 | |
| 5286 | if (wpa_s->global->p2p_disabled) |
| 5287 | return; |
| 5288 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5289 | wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS) for %sjoin", |
| 5290 | scan_res ? (int) scan_res->num : -1, |
| 5291 | wpa_s->p2p_auto_join ? "auto_" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5292 | |
| 5293 | if (scan_res) |
| 5294 | wpas_p2p_scan_res_handler(wpa_s, scan_res); |
| 5295 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5296 | if (wpa_s->p2p_auto_pd) { |
| 5297 | int join = wpas_p2p_peer_go(wpa_s, |
| 5298 | wpa_s->pending_join_dev_addr); |
| 5299 | if (join == 0 && |
| 5300 | wpa_s->auto_pd_scan_retry < P2P_AUTO_PD_SCAN_ATTEMPTS) { |
| 5301 | wpa_s->auto_pd_scan_retry++; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5302 | bss = wpa_bss_get_bssid_latest( |
| 5303 | wpa_s, wpa_s->pending_join_dev_addr); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5304 | if (bss) { |
| 5305 | freq = bss->freq; |
| 5306 | wpa_printf(MSG_DEBUG, "P2P: Scan retry %d for " |
| 5307 | "the peer " MACSTR " at %d MHz", |
| 5308 | wpa_s->auto_pd_scan_retry, |
| 5309 | MAC2STR(wpa_s-> |
| 5310 | pending_join_dev_addr), |
| 5311 | freq); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5312 | wpas_p2p_join_scan_req(wpa_s, freq, NULL, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5313 | return; |
| 5314 | } |
| 5315 | } |
| 5316 | |
| 5317 | if (join < 0) |
| 5318 | join = 0; |
| 5319 | |
| 5320 | wpa_s->p2p_auto_pd = 0; |
| 5321 | wpa_s->pending_pd_use = join ? AUTO_PD_JOIN : AUTO_PD_GO_NEG; |
| 5322 | wpa_printf(MSG_DEBUG, "P2P: Auto PD with " MACSTR " join=%d", |
| 5323 | MAC2STR(wpa_s->pending_join_dev_addr), join); |
| 5324 | if (p2p_prov_disc_req(wpa_s->global->p2p, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5325 | wpa_s->pending_join_dev_addr, NULL, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5326 | wpa_s->pending_pd_config_methods, join, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5327 | 0, wpa_s->user_initiated_pd) < 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5328 | wpa_s->p2p_auto_pd = 0; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5329 | wpa_msg_global(wpa_s, MSG_INFO, |
| 5330 | P2P_EVENT_PROV_DISC_FAILURE |
| 5331 | " p2p_dev_addr=" MACSTR " status=N/A", |
| 5332 | MAC2STR(wpa_s->pending_join_dev_addr)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5333 | } |
| 5334 | return; |
| 5335 | } |
| 5336 | |
| 5337 | if (wpa_s->p2p_auto_join) { |
| 5338 | int join = wpas_p2p_peer_go(wpa_s, |
| 5339 | wpa_s->pending_join_dev_addr); |
| 5340 | if (join < 0) { |
| 5341 | wpa_printf(MSG_DEBUG, "P2P: Peer was not found to be " |
| 5342 | "running a GO -> use GO Negotiation"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5343 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5344 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 5345 | "reason=peer-not-running-GO"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5346 | wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr, |
| 5347 | wpa_s->p2p_pin, wpa_s->p2p_wps_method, |
| 5348 | wpa_s->p2p_persistent_group, 0, 0, 0, |
| 5349 | wpa_s->p2p_go_intent, |
| 5350 | wpa_s->p2p_connect_freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5351 | wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5352 | wpa_s->p2p_persistent_id, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5353 | wpa_s->p2p_pd_before_go_neg, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5354 | wpa_s->p2p_go_ht40, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5355 | wpa_s->p2p_go_vht, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5356 | wpa_s->p2p_go_max_oper_chwidth, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5357 | wpa_s->p2p_go_he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 5358 | wpa_s->p2p_go_edmg, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5359 | NULL, 0, |
| 5360 | is_p2p_allow_6ghz(wpa_s->global->p2p)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5361 | return; |
| 5362 | } |
| 5363 | |
| 5364 | wpa_printf(MSG_DEBUG, "P2P: Peer was found running GO%s -> " |
| 5365 | "try to join the group", join ? "" : |
| 5366 | " in older scan"); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5367 | if (!join) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5368 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5369 | P2P_EVENT_FALLBACK_TO_GO_NEG_ENABLED); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5370 | wpa_s->p2p_fallback_to_go_neg = 1; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5371 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5372 | } |
| 5373 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5374 | freq = p2p_get_oper_freq(wpa_s->global->p2p, |
| 5375 | wpa_s->pending_join_iface_addr); |
| 5376 | if (freq < 0 && |
| 5377 | p2p_get_interface_addr(wpa_s->global->p2p, |
| 5378 | wpa_s->pending_join_dev_addr, |
| 5379 | iface_addr) == 0 && |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5380 | os_memcmp(iface_addr, wpa_s->pending_join_dev_addr, ETH_ALEN) != 0 |
| 5381 | && !wpa_bss_get_bssid(wpa_s, wpa_s->pending_join_iface_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5382 | wpa_printf(MSG_DEBUG, "P2P: Overwrite pending interface " |
| 5383 | "address for join from " MACSTR " to " MACSTR |
| 5384 | " based on newly discovered P2P peer entry", |
| 5385 | MAC2STR(wpa_s->pending_join_iface_addr), |
| 5386 | MAC2STR(iface_addr)); |
| 5387 | os_memcpy(wpa_s->pending_join_iface_addr, iface_addr, |
| 5388 | ETH_ALEN); |
| 5389 | |
| 5390 | freq = p2p_get_oper_freq(wpa_s->global->p2p, |
| 5391 | wpa_s->pending_join_iface_addr); |
| 5392 | } |
| 5393 | if (freq >= 0) { |
| 5394 | wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency " |
| 5395 | "from P2P peer table: %d MHz", freq); |
| 5396 | } |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5397 | if (wpa_s->p2p_join_ssid_len) { |
| 5398 | wpa_printf(MSG_DEBUG, "P2P: Trying to find target GO BSS entry based on BSSID " |
| 5399 | MACSTR " and SSID %s", |
| 5400 | MAC2STR(wpa_s->pending_join_iface_addr), |
| 5401 | wpa_ssid_txt(wpa_s->p2p_join_ssid, |
| 5402 | wpa_s->p2p_join_ssid_len)); |
| 5403 | bss = wpa_bss_get(wpa_s, wpa_s->pending_join_iface_addr, |
| 5404 | wpa_s->p2p_join_ssid, |
| 5405 | wpa_s->p2p_join_ssid_len); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5406 | } else if (!bss) { |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5407 | wpa_printf(MSG_DEBUG, "P2P: Trying to find target GO BSS entry based on BSSID " |
| 5408 | MACSTR, MAC2STR(wpa_s->pending_join_iface_addr)); |
| 5409 | bss = wpa_bss_get_bssid_latest(wpa_s, |
| 5410 | wpa_s->pending_join_iface_addr); |
| 5411 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5412 | if (bss) { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5413 | u8 dev_addr[ETH_ALEN]; |
| 5414 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5415 | freq = bss->freq; |
| 5416 | wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency " |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 5417 | "from BSS table: %d MHz (SSID %s)", freq, |
| 5418 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5419 | if (p2p_parse_dev_addr(wpa_bss_ie_ptr(bss), bss->ie_len, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5420 | dev_addr) == 0 && |
| 5421 | os_memcmp(wpa_s->pending_join_dev_addr, |
| 5422 | wpa_s->pending_join_iface_addr, ETH_ALEN) == 0 && |
| 5423 | os_memcmp(dev_addr, wpa_s->pending_join_dev_addr, |
| 5424 | ETH_ALEN) != 0) { |
| 5425 | wpa_printf(MSG_DEBUG, |
| 5426 | "P2P: Update target GO device address based on BSS entry: " MACSTR " (was " MACSTR ")", |
| 5427 | MAC2STR(dev_addr), |
| 5428 | MAC2STR(wpa_s->pending_join_dev_addr)); |
| 5429 | os_memcpy(wpa_s->pending_join_dev_addr, dev_addr, |
| 5430 | ETH_ALEN); |
| 5431 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5432 | } |
| 5433 | if (freq > 0) { |
| 5434 | u16 method; |
| 5435 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5436 | if (wpas_check_freq_conflict(wpa_s, freq) > 0) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5437 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5438 | P2P_EVENT_GROUP_FORMATION_FAILURE |
| 5439 | "reason=FREQ_CONFLICT"); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5440 | wpas_notify_p2p_group_formation_failure( |
| 5441 | wpa_s, "FREQ_CONFLICT"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5442 | return; |
| 5443 | } |
| 5444 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5445 | wpa_printf(MSG_DEBUG, "P2P: Send Provision Discovery Request " |
| 5446 | "prior to joining an existing group (GO " MACSTR |
| 5447 | " freq=%u MHz)", |
| 5448 | MAC2STR(wpa_s->pending_join_dev_addr), freq); |
| 5449 | wpa_s->pending_pd_before_join = 1; |
| 5450 | |
| 5451 | switch (wpa_s->pending_join_wps_method) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5452 | case WPS_PIN_DISPLAY: |
| 5453 | method = WPS_CONFIG_KEYPAD; |
| 5454 | break; |
| 5455 | case WPS_PIN_KEYPAD: |
| 5456 | method = WPS_CONFIG_DISPLAY; |
| 5457 | break; |
| 5458 | case WPS_PBC: |
| 5459 | method = WPS_CONFIG_PUSHBUTTON; |
| 5460 | break; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5461 | case WPS_P2PS: |
| 5462 | method = WPS_CONFIG_P2PS; |
| 5463 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5464 | default: |
| 5465 | method = 0; |
| 5466 | break; |
| 5467 | } |
| 5468 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5469 | if ((p2p_get_provisioning_info(wpa_s->global->p2p, |
| 5470 | wpa_s->pending_join_dev_addr) == |
| 5471 | method)) { |
| 5472 | /* |
| 5473 | * We have already performed provision discovery for |
| 5474 | * joining the group. Proceed directly to join |
| 5475 | * operation without duplicated provision discovery. */ |
| 5476 | wpa_printf(MSG_DEBUG, "P2P: Provision discovery " |
| 5477 | "with " MACSTR " already done - proceed to " |
| 5478 | "join", |
| 5479 | MAC2STR(wpa_s->pending_join_dev_addr)); |
| 5480 | wpa_s->pending_pd_before_join = 0; |
| 5481 | goto start; |
| 5482 | } |
| 5483 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5484 | if (p2p_prov_disc_req(wpa_s->global->p2p, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5485 | wpa_s->pending_join_dev_addr, |
| 5486 | NULL, method, 1, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5487 | freq, wpa_s->user_initiated_pd) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5488 | wpa_printf(MSG_DEBUG, "P2P: Failed to send Provision " |
| 5489 | "Discovery Request before joining an " |
| 5490 | "existing group"); |
| 5491 | wpa_s->pending_pd_before_join = 0; |
| 5492 | goto start; |
| 5493 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5494 | return; |
| 5495 | } |
| 5496 | |
| 5497 | wpa_printf(MSG_DEBUG, "P2P: Failed to find BSS/GO - try again later"); |
| 5498 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
| 5499 | eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL); |
| 5500 | wpas_p2p_check_join_scan_limit(wpa_s); |
| 5501 | return; |
| 5502 | |
| 5503 | start: |
| 5504 | /* Start join operation immediately */ |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5505 | wpas_p2p_join_start(wpa_s, 0, wpa_s->p2p_join_ssid, |
| 5506 | wpa_s->p2p_join_ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5507 | } |
| 5508 | |
| 5509 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5510 | static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq, |
| 5511 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5512 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5513 | int ret; |
| 5514 | struct wpa_driver_scan_params params; |
| 5515 | struct wpabuf *wps_ie, *ies; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5516 | size_t ielen; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5517 | int freqs[2] = { 0, 0 }; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5518 | unsigned int bands; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5519 | |
| 5520 | os_memset(¶ms, 0, sizeof(params)); |
| 5521 | |
| 5522 | /* P2P Wildcard SSID */ |
| 5523 | params.num_ssids = 1; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5524 | if (ssid && ssid_len) { |
| 5525 | params.ssids[0].ssid = ssid; |
| 5526 | params.ssids[0].ssid_len = ssid_len; |
| 5527 | os_memcpy(wpa_s->p2p_join_ssid, ssid, ssid_len); |
| 5528 | wpa_s->p2p_join_ssid_len = ssid_len; |
| 5529 | } else { |
| 5530 | params.ssids[0].ssid = (u8 *) P2P_WILDCARD_SSID; |
| 5531 | params.ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN; |
| 5532 | wpa_s->p2p_join_ssid_len = 0; |
| 5533 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5534 | |
| 5535 | wpa_s->wps->dev.p2p = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5536 | wps_ie = wps_build_probe_req_ie(DEV_PW_DEFAULT, &wpa_s->wps->dev, |
| 5537 | wpa_s->wps->uuid, WPS_REQ_ENROLLEE, 0, |
| 5538 | NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5539 | if (wps_ie == NULL) { |
| 5540 | wpas_p2p_scan_res_join(wpa_s, NULL); |
| 5541 | return; |
| 5542 | } |
| 5543 | |
Dmitry Shmidt | 9e3f8ee | 2014-01-17 10:52:01 -0800 | [diff] [blame] | 5544 | if (!freq) { |
| 5545 | int oper_freq; |
| 5546 | /* |
| 5547 | * If freq is not provided, check the operating freq of the GO |
| 5548 | * and use a single channel scan on if possible. |
| 5549 | */ |
| 5550 | oper_freq = p2p_get_oper_freq(wpa_s->global->p2p, |
| 5551 | wpa_s->pending_join_iface_addr); |
| 5552 | if (oper_freq > 0) |
| 5553 | freq = oper_freq; |
| 5554 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5555 | if (freq > 0) { |
| 5556 | freqs[0] = freq; |
| 5557 | params.freqs = freqs; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5558 | } else if (wpa_s->conf->p2p_6ghz_disable || |
| 5559 | !is_p2p_allow_6ghz(wpa_s->global->p2p)) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5560 | wpa_printf(MSG_DEBUG, |
| 5561 | "P2P: 6 GHz disabled - update the scan frequency list"); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5562 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211G, ¶ms, |
| 5563 | 0); |
| 5564 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, ¶ms, |
| 5565 | 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5566 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5567 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5568 | ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p); |
| 5569 | ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen); |
| 5570 | if (ies == NULL) { |
| 5571 | wpabuf_free(wps_ie); |
| 5572 | wpas_p2p_scan_res_join(wpa_s, NULL); |
| 5573 | return; |
| 5574 | } |
| 5575 | wpabuf_put_buf(ies, wps_ie); |
| 5576 | wpabuf_free(wps_ie); |
| 5577 | |
| 5578 | bands = wpas_get_bands(wpa_s, freqs); |
| 5579 | p2p_scan_ie(wpa_s->global->p2p, ies, NULL, bands); |
| 5580 | |
| 5581 | params.p2p_probe = 1; |
| 5582 | params.extra_ies = wpabuf_head(ies); |
| 5583 | params.extra_ies_len = wpabuf_len(ies); |
| 5584 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 5585 | if (wpa_s->clear_driver_scan_cache) { |
| 5586 | wpa_printf(MSG_DEBUG, |
| 5587 | "Request driver to clear scan cache due to local BSS flush"); |
| 5588 | params.only_new_results = 1; |
| 5589 | } |
| 5590 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5591 | /* |
| 5592 | * Run a scan to update BSS table and start Provision Discovery once |
| 5593 | * the new scan results become available. |
| 5594 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5595 | ret = wpa_drv_scan(wpa_s, ¶ms); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5596 | if (params.freqs != freqs) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5597 | os_free(params.freqs); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5598 | if (!ret) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5599 | os_get_reltime(&wpa_s->scan_trigger_time); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5600 | wpa_s->scan_res_handler = wpas_p2p_scan_res_join; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5601 | wpa_s->own_scan_requested = 1; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 5602 | wpa_s->clear_driver_scan_cache = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5603 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5604 | |
| 5605 | wpabuf_free(ies); |
| 5606 | |
| 5607 | if (ret) { |
| 5608 | wpa_printf(MSG_DEBUG, "P2P: Failed to start scan for join - " |
| 5609 | "try again later"); |
| 5610 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
| 5611 | eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL); |
| 5612 | wpas_p2p_check_join_scan_limit(wpa_s); |
| 5613 | } |
| 5614 | } |
| 5615 | |
| 5616 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5617 | static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx) |
| 5618 | { |
| 5619 | struct wpa_supplicant *wpa_s = eloop_ctx; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5620 | wpas_p2p_join_scan_req(wpa_s, 0, NULL, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5621 | } |
| 5622 | |
| 5623 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5624 | static int wpas_p2p_join(struct wpa_supplicant *wpa_s, const u8 *iface_addr, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5625 | const u8 *dev_addr, enum p2p_wps_method wps_method, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5626 | int auto_join, int op_freq, |
| 5627 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5628 | { |
| 5629 | wpa_printf(MSG_DEBUG, "P2P: Request to join existing group (iface " |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5630 | MACSTR " dev " MACSTR " op_freq=%d)%s", |
| 5631 | MAC2STR(iface_addr), MAC2STR(dev_addr), op_freq, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5632 | auto_join ? " (auto_join)" : ""); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5633 | if (ssid && ssid_len) { |
| 5634 | wpa_printf(MSG_DEBUG, "P2P: Group SSID specified: %s", |
| 5635 | wpa_ssid_txt(ssid, ssid_len)); |
| 5636 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5637 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5638 | wpa_s->p2p_auto_pd = 0; |
| 5639 | wpa_s->p2p_auto_join = !!auto_join; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5640 | os_memcpy(wpa_s->pending_join_iface_addr, iface_addr, ETH_ALEN); |
| 5641 | os_memcpy(wpa_s->pending_join_dev_addr, dev_addr, ETH_ALEN); |
| 5642 | wpa_s->pending_join_wps_method = wps_method; |
| 5643 | |
| 5644 | /* Make sure we are not running find during connection establishment */ |
| 5645 | wpas_p2p_stop_find(wpa_s); |
| 5646 | |
| 5647 | wpa_s->p2p_join_scan_count = 0; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5648 | wpas_p2p_join_scan_req(wpa_s, op_freq, ssid, ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5649 | return 0; |
| 5650 | } |
| 5651 | |
| 5652 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5653 | static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s, int freq, |
| 5654 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5655 | { |
| 5656 | struct wpa_supplicant *group; |
| 5657 | struct p2p_go_neg_results res; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5658 | struct wpa_bss *bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5659 | |
| 5660 | group = wpas_p2p_get_group_iface(wpa_s, 0, 0); |
| 5661 | if (group == NULL) |
| 5662 | return -1; |
| 5663 | if (group != wpa_s) { |
| 5664 | os_memcpy(group->p2p_pin, wpa_s->p2p_pin, |
| 5665 | sizeof(group->p2p_pin)); |
| 5666 | group->p2p_wps_method = wpa_s->p2p_wps_method; |
| 5667 | } |
| 5668 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5669 | /* |
| 5670 | * Need to mark the current interface for p2p_group_formation |
| 5671 | * when a separate group interface is not used. This is needed |
| 5672 | * to allow p2p_cancel stop a pending p2p_connect-join. |
| 5673 | * wpas_p2p_init_group_interface() addresses this for the case |
| 5674 | * where a separate group interface is used. |
| 5675 | */ |
| 5676 | if (group == wpa_s->parent) |
| 5677 | wpa_s->global->p2p_group_formation = group; |
| 5678 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5679 | group->p2p_in_provisioning = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5680 | group->p2p_fallback_to_go_neg = wpa_s->p2p_fallback_to_go_neg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5681 | |
| 5682 | os_memset(&res, 0, sizeof(res)); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5683 | os_memcpy(res.peer_device_addr, wpa_s->pending_join_dev_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5684 | os_memcpy(res.peer_interface_addr, wpa_s->pending_join_iface_addr, |
| 5685 | ETH_ALEN); |
| 5686 | res.wps_method = wpa_s->pending_join_wps_method; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5687 | if (freq && ssid && ssid_len) { |
| 5688 | res.freq = freq; |
| 5689 | res.ssid_len = ssid_len; |
| 5690 | os_memcpy(res.ssid, ssid, ssid_len); |
| 5691 | } else { |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5692 | if (ssid && ssid_len) { |
| 5693 | bss = wpa_bss_get(wpa_s, wpa_s->pending_join_iface_addr, |
| 5694 | ssid, ssid_len); |
| 5695 | } else { |
| 5696 | bss = wpa_bss_get_bssid_latest( |
| 5697 | wpa_s, wpa_s->pending_join_iface_addr); |
| 5698 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5699 | if (bss) { |
| 5700 | res.freq = bss->freq; |
| 5701 | res.ssid_len = bss->ssid_len; |
| 5702 | os_memcpy(res.ssid, bss->ssid, bss->ssid_len); |
| 5703 | wpa_printf(MSG_DEBUG, "P2P: Join target GO operating frequency from BSS table: %d MHz (SSID %s)", |
| 5704 | bss->freq, |
| 5705 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5706 | } else if (ssid && ssid_len) { |
| 5707 | res.ssid_len = ssid_len; |
| 5708 | os_memcpy(res.ssid, ssid, ssid_len); |
| 5709 | wpa_printf(MSG_DEBUG, "P2P: Join target GO (SSID %s)", |
| 5710 | wpa_ssid_txt(ssid, ssid_len)); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5711 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5712 | } |
| 5713 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5714 | if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) { |
| 5715 | wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel prior to " |
| 5716 | "starting client"); |
| 5717 | wpa_drv_cancel_remain_on_channel(wpa_s); |
| 5718 | wpa_s->off_channel_freq = 0; |
| 5719 | wpa_s->roc_waiting_drv_freq = 0; |
| 5720 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5721 | wpas_start_wps_enrollee(group, &res); |
| 5722 | |
| 5723 | /* |
| 5724 | * Allow a longer timeout for join-a-running-group than normal 15 |
| 5725 | * second group formation timeout since the GO may not have authorized |
| 5726 | * our connection yet. |
| 5727 | */ |
| 5728 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 5729 | eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout, |
| 5730 | wpa_s, NULL); |
| 5731 | |
| 5732 | return 0; |
| 5733 | } |
| 5734 | |
| 5735 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5736 | static int wpas_p2p_setup_freqs(struct wpa_supplicant *wpa_s, int freq, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5737 | int *force_freq, int *pref_freq, int go, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5738 | struct weighted_pcl *pref_freq_list, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5739 | unsigned int *num_pref_freq) |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5740 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5741 | struct wpa_used_freq_data *freqs; |
| 5742 | int res, best_freq, num_unused; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5743 | unsigned int freq_in_use = 0, num, i, max_pref_freq; |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5744 | int p2p_pref_freq; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5745 | |
| 5746 | max_pref_freq = *num_pref_freq; |
| 5747 | *num_pref_freq = 0; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5748 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5749 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 5750 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5751 | if (!freqs) |
| 5752 | return -1; |
| 5753 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5754 | num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, |
| 5755 | wpa_s->num_multichan_concurrent); |
| 5756 | |
| 5757 | /* |
| 5758 | * It is possible that the total number of used frequencies is bigger |
| 5759 | * than the number of frequencies used for P2P, so get the system wide |
| 5760 | * number of unused frequencies. |
| 5761 | */ |
| 5762 | num_unused = wpas_p2p_num_unused_channels(wpa_s); |
| 5763 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5764 | wpa_printf(MSG_DEBUG, |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5765 | "P2P: Setup freqs: freq=%d num_MCC=%d shared_freqs=%u num_unused=%d", |
| 5766 | freq, wpa_s->num_multichan_concurrent, num, num_unused); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5767 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5768 | if (freq > 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5769 | int ret; |
| 5770 | if (go) |
| 5771 | ret = p2p_supported_freq(wpa_s->global->p2p, freq); |
| 5772 | else |
| 5773 | ret = p2p_supported_freq_cli(wpa_s->global->p2p, freq); |
| 5774 | if (!ret) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5775 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5776 | ieee80211_is_dfs(freq, wpa_s->hw.modes, |
| 5777 | wpa_s->hw.num_modes)) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5778 | /* |
| 5779 | * If freq is a DFS channel and DFS is offloaded |
| 5780 | * to the driver, allow P2P GO to use it. |
| 5781 | */ |
| 5782 | wpa_printf(MSG_DEBUG, |
| 5783 | "P2P: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded to the driver", |
| 5784 | freq); |
| 5785 | } else { |
| 5786 | wpa_printf(MSG_DEBUG, |
| 5787 | "P2P: The forced channel (%u MHz) is not supported for P2P uses", |
| 5788 | freq); |
| 5789 | res = -3; |
| 5790 | goto exit_free; |
| 5791 | } |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5792 | } |
| 5793 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5794 | for (i = 0; i < num; i++) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5795 | if (freqs[i].freq == freq) |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5796 | freq_in_use = 1; |
| 5797 | } |
| 5798 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5799 | if (num_unused <= 0 && !freq_in_use) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5800 | wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group on %u MHz as there are no available channels", |
| 5801 | freq); |
| 5802 | res = -2; |
| 5803 | goto exit_free; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5804 | } |
| 5805 | wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the " |
| 5806 | "requested channel (%u MHz)", freq); |
| 5807 | *force_freq = freq; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5808 | goto exit_ok; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5809 | } |
| 5810 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5811 | best_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5812 | |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5813 | if (*pref_freq == 0) { |
| 5814 | if (wpa_s->conf->num_p2p_pref_chan && IS_2GHZ(best_freq)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5815 | i = 0; |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5816 | while (i < wpa_s->conf->num_p2p_pref_chan) { |
| 5817 | p2p_pref_freq = ieee80211_chan_to_freq(NULL, |
| 5818 | wpa_s->conf->p2p_pref_chan[i].op_class, |
| 5819 | wpa_s->conf->p2p_pref_chan[i].chan); |
| 5820 | |
| 5821 | if (p2p_supported_freq(wpa_s->global->p2p, p2p_pref_freq) && |
| 5822 | !wpas_p2p_disallowed_freq(wpa_s->global, p2p_pref_freq)) { |
| 5823 | best_freq = p2p_pref_freq; |
| 5824 | wpa_printf(MSG_DEBUG, "P2P: Using frequency (%u MHz) " |
| 5825 | "from P2P preferred channel list", best_freq); |
| 5826 | break; |
| 5827 | } else { |
| 5828 | wpa_printf(MSG_MSGDUMP, "P2P: Skipping preferred " |
| 5829 | "frequency (%u MHz) ", p2p_pref_freq); |
| 5830 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5831 | i++; |
| 5832 | } |
Sreeramya Soratkal | f928e8f | 2022-03-22 17:33:31 +0530 | [diff] [blame] | 5833 | } else if (!wpa_s->conf->num_p2p_pref_chan) { |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5834 | enum wpa_driver_if_type iface_type; |
| 5835 | |
| 5836 | if (go) |
| 5837 | iface_type = WPA_IF_P2P_GO; |
| 5838 | else |
| 5839 | iface_type = WPA_IF_P2P_CLIENT; |
| 5840 | |
| 5841 | wpa_printf(MSG_DEBUG, "P2P: best_freq=%d, go=%d", |
| 5842 | best_freq, go); |
| 5843 | |
| 5844 | res = wpa_drv_get_pref_freq_list(wpa_s, iface_type, |
| 5845 | &max_pref_freq, |
| 5846 | pref_freq_list); |
| 5847 | if (!res && max_pref_freq > 0) { |
| 5848 | *num_pref_freq = max_pref_freq; |
| 5849 | i = 0; |
| 5850 | while (i < *num_pref_freq && |
| 5851 | (!p2p_supported_freq(wpa_s->global->p2p, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5852 | pref_freq_list[i].freq) || |
| 5853 | wpas_p2p_disallowed_freq( |
| 5854 | wpa_s->global, |
| 5855 | pref_freq_list[i].freq) || |
| 5856 | !p2p_pref_freq_allowed(&pref_freq_list[i], |
| 5857 | go))) { |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5858 | wpa_printf(MSG_DEBUG, |
| 5859 | "P2P: preferred_freq_list[%d]=%d is disallowed", |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5860 | i, pref_freq_list[i].freq); |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5861 | i++; |
| 5862 | } |
| 5863 | if (i != *num_pref_freq) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5864 | best_freq = pref_freq_list[i].freq; |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5865 | wpa_printf(MSG_DEBUG, |
| 5866 | "P2P: Using preferred_freq_list[%d]=%d", |
| 5867 | i, best_freq); |
| 5868 | } else { |
| 5869 | wpa_printf(MSG_DEBUG, |
| 5870 | "P2P: All driver preferred frequencies are " |
| 5871 | "disallowed for P2P use"); |
| 5872 | *num_pref_freq = 0; |
| 5873 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5874 | } else { |
| 5875 | wpa_printf(MSG_DEBUG, |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5876 | "P2P: No preferred frequency list available"); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5877 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5878 | } |
| 5879 | } |
| 5880 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5881 | /* We have a candidate frequency to use */ |
| 5882 | if (best_freq > 0) { |
| 5883 | if (*pref_freq == 0 && num_unused > 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5884 | wpa_printf(MSG_DEBUG, "P2P: Try to prefer a frequency (%u MHz) we are already using", |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5885 | best_freq); |
| 5886 | *pref_freq = best_freq; |
Dmitry Shmidt | 51a47d5 | 2013-09-10 10:52:57 -0700 | [diff] [blame] | 5887 | } else { |
| 5888 | wpa_printf(MSG_DEBUG, "P2P: Try to force us to use frequency (%u MHz) which is already in use", |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5889 | best_freq); |
| 5890 | *force_freq = best_freq; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5891 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5892 | } else if (num_unused > 0) { |
| 5893 | wpa_printf(MSG_DEBUG, |
| 5894 | "P2P: Current operating channels are not available for P2P. Try to use another channel"); |
| 5895 | *force_freq = 0; |
| 5896 | } else { |
| 5897 | wpa_printf(MSG_DEBUG, |
| 5898 | "P2P: All channels are in use and none of them are P2P enabled. Cannot start P2P group"); |
| 5899 | res = -2; |
| 5900 | goto exit_free; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5901 | } |
| 5902 | |
| 5903 | exit_ok: |
| 5904 | res = 0; |
| 5905 | exit_free: |
| 5906 | os_free(freqs); |
| 5907 | return res; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5908 | } |
| 5909 | |
| 5910 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5911 | static bool is_p2p_6ghz_supported(struct wpa_supplicant *wpa_s, |
| 5912 | const u8 *peer_addr) |
| 5913 | { |
| 5914 | if (wpa_s->conf->p2p_6ghz_disable || |
| 5915 | !get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
| 5916 | HOSTAPD_MODE_IEEE80211A, true)) |
| 5917 | return false; |
| 5918 | |
| 5919 | if (!p2p_wfd_enabled(wpa_s->global->p2p)) |
| 5920 | return false; |
| 5921 | if (peer_addr && !p2p_peer_wfd_enabled(wpa_s->global->p2p, peer_addr)) |
| 5922 | return false; |
| 5923 | |
| 5924 | return true; |
| 5925 | } |
| 5926 | |
| 5927 | |
| 5928 | static int wpas_p2p_check_6ghz(struct wpa_supplicant *wpa_s, |
| 5929 | const u8 *peer_addr, bool allow_6ghz, int freq) |
| 5930 | { |
| 5931 | if (allow_6ghz && is_p2p_6ghz_supported(wpa_s, peer_addr)) { |
| 5932 | wpa_printf(MSG_DEBUG, |
| 5933 | "P2P: Allow connection on 6 GHz channels"); |
| 5934 | p2p_set_6ghz_dev_capab(wpa_s->global->p2p, true); |
| 5935 | } else { |
| 5936 | if (is_6ghz_freq(freq)) |
| 5937 | return -2; |
| 5938 | p2p_set_6ghz_dev_capab(wpa_s->global->p2p, false); |
| 5939 | } |
| 5940 | |
| 5941 | return 0; |
| 5942 | } |
| 5943 | |
| 5944 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5945 | /** |
| 5946 | * wpas_p2p_connect - Request P2P Group Formation to be started |
| 5947 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 5948 | * @peer_addr: Address of the peer P2P Device |
| 5949 | * @pin: PIN to use during provisioning or %NULL to indicate PBC mode |
| 5950 | * @persistent_group: Whether to create a persistent group |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5951 | * @auto_join: Whether to select join vs. GO Negotiation automatically |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5952 | * @join: Whether to join an existing group (as a client) instead of starting |
| 5953 | * Group Owner negotiation; @peer_addr is BSSID in that case |
| 5954 | * @auth: Whether to only authorize the connection instead of doing that and |
| 5955 | * initiating Group Owner negotiation |
| 5956 | * @go_intent: GO Intent or -1 to use default |
| 5957 | * @freq: Frequency for the group or 0 for auto-selection |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5958 | * @freq2: Center frequency of segment 1 for the GO operating in VHT 80P80 mode |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5959 | * @persistent_id: Persistent group credentials to use for forcing GO |
| 5960 | * parameters or -1 to generate new values (SSID/passphrase) |
| 5961 | * @pd: Whether to send Provision Discovery prior to GO Negotiation as an |
| 5962 | * interoperability workaround when initiating group formation |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5963 | * @ht40: Start GO with 40 MHz channel width |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5964 | * @vht: Start GO with VHT support |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5965 | * @vht_chwidth: Channel width supported by GO operating with VHT support |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5966 | * (CHANWIDTH_*). |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5967 | * @group_ssid: Specific Group SSID for join or %NULL if not set |
| 5968 | * @group_ssid_len: Length of @group_ssid in octets |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5969 | * @allow_6ghz: Allow P2P connection on 6 GHz channels |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5970 | * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified |
| 5971 | * failure, -2 on failure due to channel not currently available, |
| 5972 | * -3 if forced channel is not supported |
| 5973 | */ |
| 5974 | int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr, |
| 5975 | const char *pin, enum p2p_wps_method wps_method, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5976 | int persistent_group, int auto_join, int join, int auth, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5977 | int go_intent, int freq, unsigned int vht_center_freq2, |
| 5978 | int persistent_id, int pd, int ht40, int vht, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 5979 | unsigned int vht_chwidth, int he, int edmg, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5980 | const u8 *group_ssid, size_t group_ssid_len, |
| 5981 | bool allow_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5982 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5983 | int force_freq = 0, pref_freq = 0; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5984 | int ret = 0, res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5985 | enum wpa_driver_if_type iftype; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5986 | const u8 *if_addr; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5987 | struct wpa_ssid *ssid = NULL; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5988 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 5989 | unsigned int size; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5990 | |
| 5991 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 5992 | return -1; |
| 5993 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5994 | if (persistent_id >= 0) { |
| 5995 | ssid = wpa_config_get_network(wpa_s->conf, persistent_id); |
| 5996 | if (ssid == NULL || ssid->disabled != 2 || |
| 5997 | ssid->mode != WPAS_MODE_P2P_GO) |
| 5998 | return -1; |
| 5999 | } |
| 6000 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6001 | if (wpas_p2p_check_6ghz(wpa_s, peer_addr, allow_6ghz, freq)) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6002 | return -2; |
| 6003 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6004 | os_free(wpa_s->global->add_psk); |
| 6005 | wpa_s->global->add_psk = NULL; |
| 6006 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6007 | wpa_s->global->p2p_fail_on_wps_complete = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6008 | wpa_s->global->pending_p2ps_group = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6009 | wpa_s->global->pending_p2ps_group_freq = 0; |
| 6010 | wpa_s->p2ps_method_config_any = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6011 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6012 | if (go_intent < 0) |
| 6013 | go_intent = wpa_s->conf->p2p_go_intent; |
| 6014 | |
| 6015 | if (!auth) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6016 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6017 | |
| 6018 | wpa_s->p2p_wps_method = wps_method; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6019 | wpa_s->p2p_persistent_group = !!persistent_group; |
| 6020 | wpa_s->p2p_persistent_id = persistent_id; |
| 6021 | wpa_s->p2p_go_intent = go_intent; |
| 6022 | wpa_s->p2p_connect_freq = freq; |
| 6023 | wpa_s->p2p_fallback_to_go_neg = 0; |
| 6024 | wpa_s->p2p_pd_before_go_neg = !!pd; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6025 | wpa_s->p2p_go_ht40 = !!ht40; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6026 | wpa_s->p2p_go_vht = !!vht; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6027 | wpa_s->p2p_go_vht_center_freq2 = vht_center_freq2; |
| 6028 | wpa_s->p2p_go_max_oper_chwidth = vht_chwidth; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6029 | wpa_s->p2p_go_he = !!he; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6030 | wpa_s->p2p_go_edmg = !!edmg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6031 | |
| 6032 | if (pin) |
| 6033 | os_strlcpy(wpa_s->p2p_pin, pin, sizeof(wpa_s->p2p_pin)); |
| 6034 | else if (wps_method == WPS_PIN_DISPLAY) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6035 | if (wps_generate_pin((unsigned int *) &ret) < 0) |
| 6036 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6037 | res = os_snprintf(wpa_s->p2p_pin, sizeof(wpa_s->p2p_pin), |
| 6038 | "%08d", ret); |
| 6039 | if (os_snprintf_error(sizeof(wpa_s->p2p_pin), res)) |
| 6040 | wpa_s->p2p_pin[sizeof(wpa_s->p2p_pin) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6041 | wpa_printf(MSG_DEBUG, "P2P: Randomly generated PIN: %s", |
| 6042 | wpa_s->p2p_pin); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6043 | } else if (wps_method == WPS_P2PS) { |
| 6044 | /* Force the P2Ps default PIN to be used */ |
| 6045 | os_strlcpy(wpa_s->p2p_pin, "12345670", sizeof(wpa_s->p2p_pin)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6046 | } else |
| 6047 | wpa_s->p2p_pin[0] = '\0'; |
| 6048 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6049 | if (join || auto_join) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6050 | u8 iface_addr[ETH_ALEN], dev_addr[ETH_ALEN]; |
| 6051 | if (auth) { |
| 6052 | wpa_printf(MSG_DEBUG, "P2P: Authorize invitation to " |
| 6053 | "connect a running group from " MACSTR, |
| 6054 | MAC2STR(peer_addr)); |
| 6055 | os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN); |
| 6056 | return ret; |
| 6057 | } |
| 6058 | os_memcpy(dev_addr, peer_addr, ETH_ALEN); |
| 6059 | if (p2p_get_interface_addr(wpa_s->global->p2p, peer_addr, |
| 6060 | iface_addr) < 0) { |
| 6061 | os_memcpy(iface_addr, peer_addr, ETH_ALEN); |
| 6062 | p2p_get_dev_addr(wpa_s->global->p2p, peer_addr, |
| 6063 | dev_addr); |
| 6064 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6065 | if (auto_join) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6066 | os_get_reltime(&wpa_s->p2p_auto_started); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6067 | wpa_printf(MSG_DEBUG, "P2P: Auto join started at " |
| 6068 | "%ld.%06ld", |
| 6069 | wpa_s->p2p_auto_started.sec, |
| 6070 | wpa_s->p2p_auto_started.usec); |
| 6071 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6072 | wpa_s->user_initiated_pd = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6073 | if (wpas_p2p_join(wpa_s, iface_addr, dev_addr, wps_method, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 6074 | auto_join, freq, |
| 6075 | group_ssid, group_ssid_len) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6076 | return -1; |
| 6077 | return ret; |
| 6078 | } |
| 6079 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6080 | size = P2P_MAX_PREF_CHANNELS; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6081 | res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6082 | go_intent == 15, pref_freq_list, &size); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6083 | if (res) |
| 6084 | return res; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 6085 | wpas_p2p_set_own_freq_preference(wpa_s, |
| 6086 | force_freq ? force_freq : pref_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6087 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6088 | p2p_set_own_pref_freq_list(wpa_s->global->p2p, pref_freq_list, size); |
| 6089 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6090 | wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s); |
| 6091 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6092 | if (wpa_s->create_p2p_iface) { |
| 6093 | /* Prepare to add a new interface for the group */ |
| 6094 | iftype = WPA_IF_P2P_GROUP; |
| 6095 | if (go_intent == 15) |
| 6096 | iftype = WPA_IF_P2P_GO; |
| 6097 | if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) { |
| 6098 | wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " |
| 6099 | "interface for the group"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6100 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6101 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6102 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6103 | if_addr = wpa_s->pending_interface_addr; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6104 | } else { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6105 | if (wpa_s->p2p_mgmt) |
| 6106 | if_addr = wpa_s->parent->own_addr; |
| 6107 | else |
| 6108 | if_addr = wpa_s->own_addr; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6109 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
| 6110 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6111 | |
| 6112 | if (auth) { |
| 6113 | if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6114 | go_intent, if_addr, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6115 | force_freq, persistent_group, ssid, |
| 6116 | pref_freq) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6117 | return -1; |
| 6118 | return ret; |
| 6119 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6120 | |
| 6121 | if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method, |
| 6122 | go_intent, if_addr, force_freq, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6123 | persistent_group, ssid, pref_freq) < 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6124 | if (wpa_s->create_p2p_iface) |
| 6125 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6126 | return -1; |
| 6127 | } |
| 6128 | return ret; |
| 6129 | } |
| 6130 | |
| 6131 | |
| 6132 | /** |
| 6133 | * wpas_p2p_remain_on_channel_cb - Indication of remain-on-channel start |
| 6134 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 6135 | * @freq: Frequency of the channel in MHz |
| 6136 | * @duration: Duration of the stay on the channel in milliseconds |
| 6137 | * |
| 6138 | * This callback is called when the driver indicates that it has started the |
| 6139 | * requested remain-on-channel duration. |
| 6140 | */ |
| 6141 | void wpas_p2p_remain_on_channel_cb(struct wpa_supplicant *wpa_s, |
| 6142 | unsigned int freq, unsigned int duration) |
| 6143 | { |
| 6144 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 6145 | return; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6146 | wpa_printf(MSG_DEBUG, "P2P: remain-on-channel callback (off_channel_freq=%u pending_listen_freq=%d roc_waiting_drv_freq=%d freq=%u duration=%u)", |
| 6147 | wpa_s->off_channel_freq, wpa_s->pending_listen_freq, |
| 6148 | wpa_s->roc_waiting_drv_freq, freq, duration); |
| 6149 | if (wpa_s->off_channel_freq && |
| 6150 | wpa_s->off_channel_freq == wpa_s->pending_listen_freq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6151 | p2p_listen_cb(wpa_s->global->p2p, wpa_s->pending_listen_freq, |
| 6152 | wpa_s->pending_listen_duration); |
| 6153 | wpa_s->pending_listen_freq = 0; |
Dmitry Shmidt | 7f93d6f | 2014-02-21 11:22:49 -0800 | [diff] [blame] | 6154 | } else { |
| 6155 | wpa_printf(MSG_DEBUG, "P2P: Ignore remain-on-channel callback (off_channel_freq=%u pending_listen_freq=%d freq=%u duration=%u)", |
| 6156 | wpa_s->off_channel_freq, wpa_s->pending_listen_freq, |
| 6157 | freq, duration); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6158 | } |
| 6159 | } |
| 6160 | |
| 6161 | |
Jithu Jance | 57cea1a | 2014-08-20 10:22:04 -0700 | [diff] [blame] | 6162 | int wpas_p2p_listen_start(struct wpa_supplicant *wpa_s, unsigned int timeout) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6163 | { |
| 6164 | /* Limit maximum Listen state time based on driver limitation. */ |
| 6165 | if (timeout > wpa_s->max_remain_on_chan) |
| 6166 | timeout = wpa_s->max_remain_on_chan; |
| 6167 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6168 | return p2p_listen(wpa_s->global->p2p, timeout); |
| 6169 | } |
| 6170 | |
| 6171 | |
| 6172 | /** |
| 6173 | * wpas_p2p_cancel_remain_on_channel_cb - Remain-on-channel timeout |
| 6174 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 6175 | * @freq: Frequency of the channel in MHz |
| 6176 | * |
| 6177 | * This callback is called when the driver indicates that a remain-on-channel |
| 6178 | * operation has been completed, i.e., the duration on the requested channel |
| 6179 | * has timed out. |
| 6180 | */ |
| 6181 | void wpas_p2p_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s, |
| 6182 | unsigned int freq) |
| 6183 | { |
| 6184 | wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel callback " |
| 6185 | "(p2p_long_listen=%d ms pending_action_tx=%p)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6186 | wpa_s->global->p2p_long_listen, |
| 6187 | offchannel_pending_action_tx(wpa_s)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6188 | wpas_p2p_listen_work_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6189 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 6190 | return; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6191 | if (wpa_s->global->p2p_long_listen > 0) |
| 6192 | wpa_s->global->p2p_long_listen -= wpa_s->max_remain_on_chan; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6193 | if (p2p_listen_end(wpa_s->global->p2p, freq) > 0) |
| 6194 | return; /* P2P module started a new operation */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6195 | if (offchannel_pending_action_tx(wpa_s)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6196 | return; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6197 | if (wpa_s->global->p2p_long_listen > 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6198 | wpa_printf(MSG_DEBUG, "P2P: Continuing long Listen state"); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6199 | wpas_p2p_listen_start(wpa_s, wpa_s->global->p2p_long_listen); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6200 | } else { |
| 6201 | /* |
| 6202 | * When listen duration is over, stop listen & update p2p_state |
| 6203 | * to IDLE. |
| 6204 | */ |
| 6205 | p2p_stop_listen(wpa_s->global->p2p); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6206 | } |
| 6207 | } |
| 6208 | |
| 6209 | |
| 6210 | /** |
| 6211 | * wpas_p2p_group_remove - Remove a P2P group |
| 6212 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 6213 | * @ifname: Network interface name of the group interface or "*" to remove all |
| 6214 | * groups |
| 6215 | * Returns: 0 on success, -1 on failure |
| 6216 | * |
| 6217 | * This function is used to remove a P2P group. This can be used to disconnect |
| 6218 | * from a group in which the local end is a P2P Client or to end a P2P Group in |
| 6219 | * case the local end is the Group Owner. If a virtual network interface was |
| 6220 | * created for this group, that interface will be removed. Otherwise, only the |
| 6221 | * configured P2P group network will be removed from the interface. |
| 6222 | */ |
| 6223 | int wpas_p2p_group_remove(struct wpa_supplicant *wpa_s, const char *ifname) |
| 6224 | { |
| 6225 | struct wpa_global *global = wpa_s->global; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6226 | struct wpa_supplicant *calling_wpa_s = wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6227 | |
| 6228 | if (os_strcmp(ifname, "*") == 0) { |
| 6229 | struct wpa_supplicant *prev; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6230 | bool calling_wpa_s_group_removed = false; |
| 6231 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6232 | wpa_s = global->ifaces; |
| 6233 | while (wpa_s) { |
| 6234 | prev = wpa_s; |
| 6235 | wpa_s = wpa_s->next; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6236 | if (prev->p2p_group_interface != |
| 6237 | NOT_P2P_GROUP_INTERFACE || |
| 6238 | (prev->current_ssid && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6239 | prev->current_ssid->p2p_group)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6240 | wpas_p2p_disconnect_safely(prev, calling_wpa_s); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6241 | if (prev == calling_wpa_s) |
| 6242 | calling_wpa_s_group_removed = true; |
| 6243 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6244 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6245 | |
| 6246 | if (!calling_wpa_s_group_removed && |
| 6247 | (calling_wpa_s->p2p_group_interface != |
| 6248 | NOT_P2P_GROUP_INTERFACE || |
| 6249 | (calling_wpa_s->current_ssid && |
| 6250 | calling_wpa_s->current_ssid->p2p_group))) { |
| 6251 | wpa_printf(MSG_DEBUG, "Remove calling_wpa_s P2P group"); |
| 6252 | wpas_p2p_disconnect_safely(calling_wpa_s, |
| 6253 | calling_wpa_s); |
| 6254 | } |
| 6255 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6256 | return 0; |
| 6257 | } |
| 6258 | |
| 6259 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 6260 | if (os_strcmp(wpa_s->ifname, ifname) == 0) |
| 6261 | break; |
| 6262 | } |
| 6263 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6264 | return wpas_p2p_disconnect_safely(wpa_s, calling_wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6265 | } |
| 6266 | |
| 6267 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6268 | static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq) |
| 6269 | { |
| 6270 | unsigned int r; |
| 6271 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6272 | if (!wpa_s->conf->num_p2p_pref_chan && !freq) { |
| 6273 | unsigned int i, size = P2P_MAX_PREF_CHANNELS; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6274 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6275 | int res; |
| 6276 | |
| 6277 | res = wpa_drv_get_pref_freq_list(wpa_s, WPA_IF_P2P_GO, |
| 6278 | &size, pref_freq_list); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6279 | if (!is_p2p_allow_6ghz(wpa_s->global->p2p)) |
| 6280 | size = p2p_remove_6ghz_channels(pref_freq_list, size); |
| 6281 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6282 | if (!res && size > 0) { |
| 6283 | i = 0; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 6284 | while (i < size && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6285 | (!p2p_supported_freq(wpa_s->global->p2p, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6286 | pref_freq_list[i].freq) || |
| 6287 | wpas_p2p_disallowed_freq( |
| 6288 | wpa_s->global, |
| 6289 | pref_freq_list[i].freq) || |
| 6290 | !p2p_pref_freq_allowed(&pref_freq_list[i], |
| 6291 | true))) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6292 | wpa_printf(MSG_DEBUG, |
| 6293 | "P2P: preferred_freq_list[%d]=%d is disallowed", |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6294 | i, pref_freq_list[i].freq); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6295 | i++; |
| 6296 | } |
| 6297 | if (i != size) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6298 | freq = pref_freq_list[i].freq; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6299 | wpa_printf(MSG_DEBUG, |
| 6300 | "P2P: Using preferred_freq_list[%d]=%d", |
| 6301 | i, freq); |
| 6302 | } else { |
| 6303 | wpa_printf(MSG_DEBUG, |
| 6304 | "P2P: All driver preferred frequencies are disallowed for P2P use"); |
| 6305 | } |
| 6306 | } else { |
| 6307 | wpa_printf(MSG_DEBUG, |
| 6308 | "P2P: No preferred frequency list available"); |
| 6309 | } |
| 6310 | } |
| 6311 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6312 | if (freq == 2) { |
| 6313 | wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 2.4 GHz " |
| 6314 | "band"); |
| 6315 | if (wpa_s->best_24_freq > 0 && |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6316 | p2p_supported_freq_go(wpa_s->global->p2p, |
| 6317 | wpa_s->best_24_freq)) { |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6318 | freq = wpa_s->best_24_freq; |
| 6319 | wpa_printf(MSG_DEBUG, "P2P: Use best 2.4 GHz band " |
| 6320 | "channel: %d MHz", freq); |
| 6321 | } else { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6322 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 6323 | return -1; |
Jimmy Chen | 801bf46 | 2021-11-09 23:08:48 +0800 | [diff] [blame] | 6324 | int possible_2g_freqs[] = { |
| 6325 | /* operating class 81 */ |
| 6326 | 2412, 2437, 2462, |
| 6327 | }; |
| 6328 | int possible_2g_freqs_num = |
| 6329 | sizeof(possible_2g_freqs)/sizeof(possible_2g_freqs[0]); |
| 6330 | int i; |
| 6331 | for (i = 0; i < possible_2g_freqs_num; i++, r++) { |
| 6332 | freq = possible_2g_freqs[r % possible_2g_freqs_num]; |
| 6333 | if (p2p_supported_freq_go(wpa_s->global->p2p, freq)) { |
| 6334 | break; |
| 6335 | } |
| 6336 | } |
| 6337 | |
| 6338 | if (i >= possible_2g_freqs_num) { |
| 6339 | wpa_printf(MSG_DEBUG, "P2P: Could not select " |
| 6340 | "2.4 GHz channel for P2P group"); |
| 6341 | return -1; |
| 6342 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6343 | wpa_printf(MSG_DEBUG, "P2P: Use random 2.4 GHz band " |
| 6344 | "channel: %d MHz", freq); |
| 6345 | } |
| 6346 | } |
| 6347 | |
| 6348 | if (freq == 5) { |
| 6349 | wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 5 GHz " |
| 6350 | "band"); |
| 6351 | if (wpa_s->best_5_freq > 0 && |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6352 | p2p_supported_freq_go(wpa_s->global->p2p, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6353 | wpa_s->best_5_freq)) { |
| 6354 | freq = wpa_s->best_5_freq; |
| 6355 | wpa_printf(MSG_DEBUG, "P2P: Use best 5 GHz band " |
| 6356 | "channel: %d MHz", freq); |
| 6357 | } else { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6358 | const int freqs[] = { |
| 6359 | /* operating class 115 */ |
| 6360 | 5180, 5200, 5220, 5240, |
| 6361 | /* operating class 124 */ |
| 6362 | 5745, 5765, 5785, 5805, |
| 6363 | }; |
| 6364 | unsigned int i, num_freqs = ARRAY_SIZE(freqs); |
| 6365 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6366 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 6367 | return -1; |
Jimmy Chen | 64b9063 | 2020-09-29 17:27:34 +0800 | [diff] [blame] | 6368 | |
| 6369 | /* |
| 6370 | * most of 5G channels are DFS, only operating class 115 and 124 |
| 6371 | * are available possibly, randomly pick a start to check them. |
| 6372 | */ |
| 6373 | int possible_5g_freqs[] = { |
| 6374 | /* operating class 115 */ |
| 6375 | 5180, 5200, 5220, 5240, |
| 6376 | /* operating class 124 */ |
| 6377 | 5745, 5765, 5785, 5805, |
| 6378 | }; |
| 6379 | int possible_5g_freqs_num = |
| 6380 | sizeof(possible_5g_freqs)/sizeof(possible_5g_freqs[0]); |
| 6381 | |
Jimmy Chen | 64b9063 | 2020-09-29 17:27:34 +0800 | [diff] [blame] | 6382 | for (i = 0; i < possible_5g_freqs_num; i++, r++) { |
| 6383 | if (p2p_supported_freq_go( |
| 6384 | wpa_s->global->p2p, |
| 6385 | possible_5g_freqs[r % possible_5g_freqs_num])) { |
| 6386 | freq = possible_5g_freqs[r % possible_5g_freqs_num]; |
| 6387 | break; |
| 6388 | } |
| 6389 | } |
| 6390 | |
| 6391 | if (i >= possible_5g_freqs_num) { |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6392 | wpa_printf(MSG_DEBUG, "P2P: Could not select " |
| 6393 | "5 GHz channel for P2P group"); |
| 6394 | return -1; |
| 6395 | } |
| 6396 | wpa_printf(MSG_DEBUG, "P2P: Use random 5 GHz band " |
| 6397 | "channel: %d MHz", freq); |
| 6398 | } |
| 6399 | } |
| 6400 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6401 | if (freq > 0 && !p2p_supported_freq_go(wpa_s->global->p2p, freq)) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6402 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6403 | ieee80211_is_dfs(freq, wpa_s->hw.modes, |
| 6404 | wpa_s->hw.num_modes)) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6405 | /* |
| 6406 | * If freq is a DFS channel and DFS is offloaded to the |
| 6407 | * driver, allow P2P GO to use it. |
| 6408 | */ |
| 6409 | wpa_printf(MSG_DEBUG, "P2P: " |
| 6410 | "%s: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded", |
| 6411 | __func__, freq); |
| 6412 | return freq; |
| 6413 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6414 | wpa_printf(MSG_DEBUG, "P2P: The forced channel for GO " |
| 6415 | "(%u MHz) is not supported for P2P uses", |
| 6416 | freq); |
| 6417 | return -1; |
| 6418 | } |
| 6419 | |
| 6420 | return freq; |
| 6421 | } |
| 6422 | |
| 6423 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6424 | static int wpas_p2p_supported_freq_go(struct wpa_supplicant *wpa_s, |
| 6425 | const struct p2p_channels *channels, |
| 6426 | int freq) |
| 6427 | { |
| 6428 | if (!wpas_p2p_disallowed_freq(wpa_s->global, freq) && |
| 6429 | p2p_supported_freq_go(wpa_s->global->p2p, freq) && |
| 6430 | freq_included(wpa_s, channels, freq)) |
| 6431 | return 1; |
| 6432 | return 0; |
| 6433 | } |
| 6434 | |
| 6435 | |
| 6436 | static void wpas_p2p_select_go_freq_no_pref(struct wpa_supplicant *wpa_s, |
| 6437 | struct p2p_go_neg_results *params, |
| 6438 | const struct p2p_channels *channels) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6439 | { |
| 6440 | unsigned int i, r; |
| 6441 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6442 | /* try all channels in operating class 115 */ |
| 6443 | for (i = 0; i < 4; i++) { |
| 6444 | params->freq = 5180 + i * 20; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6445 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6446 | goto out; |
| 6447 | } |
| 6448 | |
| 6449 | /* try all channels in operating class 124 */ |
| 6450 | for (i = 0; i < 4; i++) { |
| 6451 | params->freq = 5745 + i * 20; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6452 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6453 | goto out; |
| 6454 | } |
| 6455 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6456 | /* try social channel class 180 channel 2 */ |
| 6457 | params->freq = 58320 + 1 * 2160; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6458 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6459 | goto out; |
| 6460 | |
| 6461 | /* try all channels in reg. class 180 */ |
| 6462 | for (i = 0; i < 4; i++) { |
| 6463 | params->freq = 58320 + i * 2160; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6464 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6465 | goto out; |
| 6466 | } |
| 6467 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6468 | /* try some random selection of the social channels */ |
| 6469 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 6470 | return; |
| 6471 | |
| 6472 | for (i = 0; i < 3; i++) { |
| 6473 | params->freq = 2412 + ((r + i) % 3) * 25; |
| 6474 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
| 6475 | goto out; |
| 6476 | } |
| 6477 | |
| 6478 | /* try all other channels in operating class 81 */ |
| 6479 | for (i = 0; i < 11; i++) { |
| 6480 | params->freq = 2412 + i * 5; |
| 6481 | |
| 6482 | /* skip social channels; covered in the previous loop */ |
| 6483 | if (params->freq == 2412 || |
| 6484 | params->freq == 2437 || |
| 6485 | params->freq == 2462) |
| 6486 | continue; |
| 6487 | |
| 6488 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
| 6489 | goto out; |
| 6490 | } |
| 6491 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6492 | params->freq = 0; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6493 | wpa_printf(MSG_DEBUG, "P2P: No 2.4, 5, or 60 GHz channel allowed"); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6494 | return; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6495 | out: |
| 6496 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz (no preference known)", |
| 6497 | params->freq); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6498 | } |
| 6499 | |
| 6500 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6501 | static int wpas_same_band(int freq1, int freq2) |
| 6502 | { |
| 6503 | enum hostapd_hw_mode mode1, mode2; |
| 6504 | u8 chan1, chan2; |
| 6505 | |
| 6506 | mode1 = ieee80211_freq_to_chan(freq1, &chan1); |
| 6507 | mode2 = ieee80211_freq_to_chan(freq2, &chan2); |
| 6508 | if (mode1 == NUM_HOSTAPD_MODES) |
| 6509 | return 0; |
| 6510 | return mode1 == mode2; |
| 6511 | } |
| 6512 | |
| 6513 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6514 | static int wpas_p2p_init_go_params(struct wpa_supplicant *wpa_s, |
| 6515 | struct p2p_go_neg_results *params, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6516 | int freq, int vht_center_freq2, int ht40, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6517 | int vht, int max_oper_chwidth, int he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6518 | int edmg, |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6519 | const struct p2p_channels *channels) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6520 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6521 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6522 | unsigned int cand; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6523 | unsigned int num, i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6524 | int ignore_no_freqs = 0; |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6525 | int unused_channels = wpas_p2p_num_unused_channels(wpa_s) > 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6526 | |
| 6527 | os_memset(params, 0, sizeof(*params)); |
| 6528 | params->role_go = 1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6529 | params->ht40 = ht40; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6530 | params->vht = vht; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6531 | params->he = he; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6532 | params->max_oper_chwidth = max_oper_chwidth; |
| 6533 | params->vht_center_freq2 = vht_center_freq2; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6534 | params->edmg = edmg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6535 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6536 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 6537 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6538 | if (!freqs) |
| 6539 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6540 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6541 | num = get_shared_radio_freqs_data(wpa_s, freqs, |
| 6542 | wpa_s->num_multichan_concurrent); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6543 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6544 | if (wpa_s->current_ssid && |
| 6545 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO && |
| 6546 | wpa_s->wpa_state == WPA_COMPLETED) { |
| 6547 | wpa_printf(MSG_DEBUG, "P2P: %s called for an active GO", |
| 6548 | __func__); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6549 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6550 | /* |
| 6551 | * If the frequency selection is done for an active P2P GO that |
| 6552 | * is not sharing a frequency, allow to select a new frequency |
| 6553 | * even if there are no unused frequencies as we are about to |
| 6554 | * move the P2P GO so its frequency can be re-used. |
| 6555 | */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6556 | for (i = 0; i < num; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6557 | if (freqs[i].freq == wpa_s->current_ssid->frequency && |
| 6558 | freqs[i].flags == 0) { |
| 6559 | ignore_no_freqs = 1; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6560 | break; |
| 6561 | } |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6562 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 6563 | } |
| 6564 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6565 | /* Try to use EDMG channel */ |
| 6566 | if (params->edmg) { |
| 6567 | if (wpas_p2p_try_edmg_channel(wpa_s, params) == 0) |
| 6568 | goto success; |
| 6569 | params->edmg = 0; |
| 6570 | } |
| 6571 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6572 | /* try using the forced freq */ |
| 6573 | if (freq) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6574 | if (wpas_p2p_disallowed_freq(wpa_s->global, freq) || |
| 6575 | !freq_included(wpa_s, channels, freq)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6576 | wpa_printf(MSG_DEBUG, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6577 | "P2P: Forced GO freq %d MHz disallowed", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6578 | freq); |
| 6579 | goto fail; |
| 6580 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6581 | if (!p2p_supported_freq_go(wpa_s->global->p2p, freq)) { |
| 6582 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6583 | ieee80211_is_dfs(freq, wpa_s->hw.modes, |
| 6584 | wpa_s->hw.num_modes)) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6585 | /* |
| 6586 | * If freq is a DFS channel and DFS is offloaded |
| 6587 | * to the driver, allow P2P GO to use it. |
| 6588 | */ |
| 6589 | wpa_printf(MSG_DEBUG, |
| 6590 | "P2P: %s: The forced channel for GO (%u MHz) requires DFS and DFS is offloaded", |
| 6591 | __func__, freq); |
| 6592 | } else { |
| 6593 | wpa_printf(MSG_DEBUG, |
| 6594 | "P2P: The forced channel for GO (%u MHz) is not supported for P2P uses", |
| 6595 | freq); |
| 6596 | goto fail; |
| 6597 | } |
| 6598 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6599 | |
| 6600 | for (i = 0; i < num; i++) { |
| 6601 | if (freqs[i].freq == freq) { |
| 6602 | wpa_printf(MSG_DEBUG, |
| 6603 | "P2P: forced freq (%d MHz) is also shared", |
| 6604 | freq); |
| 6605 | params->freq = freq; |
| 6606 | goto success; |
| 6607 | } |
| 6608 | } |
| 6609 | |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6610 | if (!ignore_no_freqs && !unused_channels) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6611 | wpa_printf(MSG_DEBUG, |
| 6612 | "P2P: Cannot force GO on freq (%d MHz) as all the channels are in use", |
| 6613 | freq); |
| 6614 | goto fail; |
| 6615 | } |
| 6616 | |
| 6617 | wpa_printf(MSG_DEBUG, |
| 6618 | "P2P: force GO freq (%d MHz) on a free channel", |
| 6619 | freq); |
| 6620 | params->freq = freq; |
| 6621 | goto success; |
| 6622 | } |
| 6623 | |
| 6624 | /* consider using one of the shared frequencies */ |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6625 | if (num && |
| 6626 | (!wpa_s->conf->p2p_ignore_shared_freq || !unused_channels)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6627 | cand = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num); |
| 6628 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6629 | wpa_printf(MSG_DEBUG, |
| 6630 | "P2P: Use shared freq (%d MHz) for GO", |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6631 | cand); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6632 | params->freq = cand; |
| 6633 | goto success; |
| 6634 | } |
| 6635 | |
| 6636 | /* try using one of the shared freqs */ |
| 6637 | for (i = 0; i < num; i++) { |
| 6638 | if (wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6639 | freqs[i].freq)) { |
| 6640 | wpa_printf(MSG_DEBUG, |
| 6641 | "P2P: Use shared freq (%d MHz) for GO", |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6642 | freqs[i].freq); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6643 | params->freq = freqs[i].freq; |
| 6644 | goto success; |
| 6645 | } |
| 6646 | } |
| 6647 | } |
| 6648 | |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6649 | if (!ignore_no_freqs && !unused_channels) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6650 | wpa_printf(MSG_DEBUG, |
| 6651 | "P2P: Cannot force GO on any of the channels we are already using"); |
| 6652 | goto fail; |
| 6653 | } |
| 6654 | |
| 6655 | /* try using the setting from the configuration file */ |
| 6656 | if (wpa_s->conf->p2p_oper_reg_class == 81 && |
| 6657 | wpa_s->conf->p2p_oper_channel >= 1 && |
| 6658 | wpa_s->conf->p2p_oper_channel <= 11 && |
| 6659 | wpas_p2p_supported_freq_go( |
| 6660 | wpa_s, channels, |
| 6661 | 2407 + 5 * wpa_s->conf->p2p_oper_channel)) { |
| 6662 | params->freq = 2407 + 5 * wpa_s->conf->p2p_oper_channel; |
| 6663 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured " |
| 6664 | "frequency %d MHz", params->freq); |
| 6665 | goto success; |
| 6666 | } |
| 6667 | |
| 6668 | if ((wpa_s->conf->p2p_oper_reg_class == 115 || |
| 6669 | wpa_s->conf->p2p_oper_reg_class == 116 || |
| 6670 | wpa_s->conf->p2p_oper_reg_class == 117 || |
| 6671 | wpa_s->conf->p2p_oper_reg_class == 124 || |
| 6672 | wpa_s->conf->p2p_oper_reg_class == 125 || |
| 6673 | wpa_s->conf->p2p_oper_reg_class == 126 || |
| 6674 | wpa_s->conf->p2p_oper_reg_class == 127) && |
| 6675 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6676 | 5000 + |
| 6677 | 5 * wpa_s->conf->p2p_oper_channel)) { |
| 6678 | params->freq = 5000 + 5 * wpa_s->conf->p2p_oper_channel; |
| 6679 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured " |
| 6680 | "frequency %d MHz", params->freq); |
| 6681 | goto success; |
| 6682 | } |
| 6683 | |
| 6684 | /* Try using best channels */ |
| 6685 | if (wpa_s->conf->p2p_oper_channel == 0 && |
| 6686 | wpa_s->best_overall_freq > 0 && |
| 6687 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6688 | wpa_s->best_overall_freq)) { |
| 6689 | params->freq = wpa_s->best_overall_freq; |
| 6690 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best overall " |
| 6691 | "channel %d MHz", params->freq); |
| 6692 | goto success; |
| 6693 | } |
| 6694 | |
| 6695 | if (wpa_s->conf->p2p_oper_channel == 0 && |
| 6696 | wpa_s->best_24_freq > 0 && |
| 6697 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6698 | wpa_s->best_24_freq)) { |
| 6699 | params->freq = wpa_s->best_24_freq; |
| 6700 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 2.4 GHz " |
| 6701 | "channel %d MHz", params->freq); |
| 6702 | goto success; |
| 6703 | } |
| 6704 | |
| 6705 | if (wpa_s->conf->p2p_oper_channel == 0 && |
| 6706 | wpa_s->best_5_freq > 0 && |
| 6707 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6708 | wpa_s->best_5_freq)) { |
| 6709 | params->freq = wpa_s->best_5_freq; |
| 6710 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 5 GHz " |
| 6711 | "channel %d MHz", params->freq); |
| 6712 | goto success; |
| 6713 | } |
| 6714 | |
| 6715 | /* try using preferred channels */ |
| 6716 | cand = p2p_get_pref_freq(wpa_s->global->p2p, channels); |
| 6717 | if (cand && wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6718 | params->freq = cand; |
| 6719 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz from preferred " |
| 6720 | "channels", params->freq); |
| 6721 | goto success; |
| 6722 | } |
| 6723 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6724 | /* Try using a channel that allows VHT to be used with 80 MHz */ |
| 6725 | if (wpa_s->hw.modes && wpa_s->p2p_group_common_freqs) { |
| 6726 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 6727 | enum hostapd_hw_mode mode; |
| 6728 | struct hostapd_hw_modes *hwmode; |
| 6729 | u8 chan; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6730 | u8 op_class; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6731 | |
| 6732 | cand = wpa_s->p2p_group_common_freqs[i]; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6733 | op_class = is_6ghz_freq(cand) ? 133 : 128; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6734 | mode = ieee80211_freq_to_chan(cand, &chan); |
| 6735 | hwmode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6736 | mode, is_6ghz_freq(cand)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6737 | if (!hwmode || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6738 | wpas_p2p_verify_channel(wpa_s, hwmode, op_class, |
| 6739 | chan, BW80) != ALLOWED) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6740 | continue; |
| 6741 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6742 | params->freq = cand; |
| 6743 | wpa_printf(MSG_DEBUG, |
| 6744 | "P2P: Use freq %d MHz common with the peer and allowing VHT80", |
| 6745 | params->freq); |
| 6746 | goto success; |
| 6747 | } |
| 6748 | } |
| 6749 | } |
| 6750 | |
| 6751 | /* Try using a channel that allows HT to be used with 40 MHz on the same |
| 6752 | * band so that CSA can be used */ |
| 6753 | if (wpa_s->current_ssid && wpa_s->hw.modes && |
| 6754 | wpa_s->p2p_group_common_freqs) { |
| 6755 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 6756 | enum hostapd_hw_mode mode; |
| 6757 | struct hostapd_hw_modes *hwmode; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6758 | u8 chan, op_class; |
| 6759 | bool is_6ghz, supported = false; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6760 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6761 | is_6ghz = is_6ghz_freq(cand); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6762 | cand = wpa_s->p2p_group_common_freqs[i]; |
| 6763 | mode = ieee80211_freq_to_chan(cand, &chan); |
| 6764 | hwmode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6765 | mode, is_6ghz); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6766 | if (!wpas_same_band(wpa_s->current_ssid->frequency, |
| 6767 | cand) || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6768 | !hwmode) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6769 | continue; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6770 | if (is_6ghz && |
| 6771 | wpas_p2p_verify_channel(wpa_s, hwmode, 132, chan, |
| 6772 | BW40) == ALLOWED) |
| 6773 | supported = true; |
| 6774 | |
| 6775 | if (!is_6ghz && |
| 6776 | ieee80211_freq_to_channel_ext( |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6777 | cand, -1, CONF_OPER_CHWIDTH_USE_HT, |
| 6778 | &op_class, &chan) != NUM_HOSTAPD_MODES && |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6779 | wpas_p2p_verify_channel( |
| 6780 | wpa_s, hwmode, op_class, chan, |
| 6781 | BW40MINUS) == ALLOWED) |
| 6782 | supported = true; |
| 6783 | |
| 6784 | if (!supported && !is_6ghz && |
| 6785 | ieee80211_freq_to_channel_ext( |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6786 | cand, 1, CONF_OPER_CHWIDTH_USE_HT, |
| 6787 | &op_class, &chan) != NUM_HOSTAPD_MODES && |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6788 | wpas_p2p_verify_channel( |
| 6789 | wpa_s, hwmode, op_class, chan, |
| 6790 | BW40PLUS) == ALLOWED) |
| 6791 | supported = true; |
| 6792 | |
| 6793 | if (!supported) |
| 6794 | continue; |
| 6795 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6796 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6797 | params->freq = cand; |
| 6798 | wpa_printf(MSG_DEBUG, |
| 6799 | "P2P: Use freq %d MHz common with the peer, allowing HT40, and maintaining same band", |
| 6800 | params->freq); |
| 6801 | goto success; |
| 6802 | } |
| 6803 | } |
| 6804 | } |
| 6805 | |
| 6806 | /* Try using one of the group common freqs on the same band so that CSA |
| 6807 | * can be used */ |
| 6808 | if (wpa_s->current_ssid && wpa_s->p2p_group_common_freqs) { |
| 6809 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 6810 | cand = wpa_s->p2p_group_common_freqs[i]; |
| 6811 | if (!wpas_same_band(wpa_s->current_ssid->frequency, |
| 6812 | cand)) |
| 6813 | continue; |
| 6814 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6815 | params->freq = cand; |
| 6816 | wpa_printf(MSG_DEBUG, |
| 6817 | "P2P: Use freq %d MHz common with the peer and maintaining same band", |
| 6818 | params->freq); |
| 6819 | goto success; |
| 6820 | } |
| 6821 | } |
| 6822 | } |
| 6823 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6824 | /* Try using one of the group common freqs */ |
| 6825 | if (wpa_s->p2p_group_common_freqs) { |
| 6826 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 6827 | cand = wpa_s->p2p_group_common_freqs[i]; |
| 6828 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6829 | params->freq = cand; |
| 6830 | wpa_printf(MSG_DEBUG, |
| 6831 | "P2P: Use freq %d MHz common with the peer", |
| 6832 | params->freq); |
| 6833 | goto success; |
| 6834 | } |
| 6835 | } |
| 6836 | } |
| 6837 | |
| 6838 | /* no preference, select some channel */ |
| 6839 | wpas_p2p_select_go_freq_no_pref(wpa_s, params, channels); |
| 6840 | |
| 6841 | if (params->freq == 0) { |
| 6842 | wpa_printf(MSG_DEBUG, "P2P: did not find a freq for GO use"); |
| 6843 | goto fail; |
| 6844 | } |
| 6845 | |
| 6846 | success: |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6847 | os_free(freqs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6848 | return 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6849 | fail: |
| 6850 | os_free(freqs); |
| 6851 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6852 | } |
| 6853 | |
| 6854 | |
| 6855 | static struct wpa_supplicant * |
| 6856 | wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated, |
| 6857 | int go) |
| 6858 | { |
| 6859 | struct wpa_supplicant *group_wpa_s; |
| 6860 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6861 | if (!wpas_p2p_create_iface(wpa_s)) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6862 | if (wpa_s->p2p_mgmt) { |
| 6863 | /* |
| 6864 | * We may be called on the p2p_dev interface which |
| 6865 | * cannot be used for group operations, so always use |
| 6866 | * the primary interface. |
| 6867 | */ |
| 6868 | wpa_s->parent->p2pdev = wpa_s; |
| 6869 | wpa_s = wpa_s->parent; |
| 6870 | } |
| 6871 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 6872 | "P2P: Use primary interface for group operations"); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6873 | wpa_s->p2p_first_connection_timeout = 0; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6874 | if (wpa_s != wpa_s->p2pdev) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6875 | wpas_p2p_clone_config(wpa_s, wpa_s->p2pdev); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6876 | return wpa_s; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6877 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6878 | |
| 6879 | if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO : |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6880 | WPA_IF_P2P_CLIENT) < 0) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6881 | wpa_msg_global(wpa_s, MSG_ERROR, |
| 6882 | "P2P: Failed to add group interface"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6883 | return NULL; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6884 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6885 | group_wpa_s = wpas_p2p_init_group_interface(wpa_s, go); |
| 6886 | if (group_wpa_s == NULL) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6887 | wpa_msg_global(wpa_s, MSG_ERROR, |
| 6888 | "P2P: Failed to initialize group interface"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6889 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 6890 | return NULL; |
| 6891 | } |
| 6892 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6893 | if (go && wpa_s->p2p_go_do_acs) { |
| 6894 | group_wpa_s->p2p_go_do_acs = wpa_s->p2p_go_do_acs; |
| 6895 | group_wpa_s->p2p_go_acs_band = wpa_s->p2p_go_acs_band; |
| 6896 | wpa_s->p2p_go_do_acs = 0; |
| 6897 | } |
| 6898 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6899 | if (go && wpa_s->p2p_go_allow_dfs) { |
| 6900 | group_wpa_s->p2p_go_allow_dfs = wpa_s->p2p_go_allow_dfs; |
| 6901 | wpa_s->p2p_go_allow_dfs = 0; |
| 6902 | } |
| 6903 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6904 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use separate group interface %s", |
| 6905 | group_wpa_s->ifname); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6906 | group_wpa_s->p2p_first_connection_timeout = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6907 | return group_wpa_s; |
| 6908 | } |
| 6909 | |
| 6910 | |
| 6911 | /** |
| 6912 | * wpas_p2p_group_add - Add a new P2P group with local end as Group Owner |
| 6913 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 6914 | * @persistent_group: Whether to create a persistent group |
| 6915 | * @freq: Frequency for the group or 0 to indicate no hardcoding |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6916 | * @vht_center_freq2: segment_1 center frequency for GO operating in VHT 80P80 |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6917 | * @ht40: Start GO with 40 MHz channel width |
| 6918 | * @vht: Start GO with VHT support |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6919 | * @vht_chwidth: channel bandwidth for GO operating with VHT support |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6920 | * @edmg: Start GO with EDMG support |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6921 | * @allow_6ghz: Allow P2P group creation on a 6 GHz channel |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6922 | * Returns: 0 on success, -1 on failure |
| 6923 | * |
| 6924 | * This function creates a new P2P group with the local end as the Group Owner, |
| 6925 | * i.e., without using Group Owner Negotiation. |
| 6926 | */ |
| 6927 | int wpas_p2p_group_add(struct wpa_supplicant *wpa_s, int persistent_group, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6928 | int freq, int vht_center_freq2, int ht40, int vht, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6929 | int max_oper_chwidth, int he, int edmg, |
| 6930 | bool allow_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6931 | { |
| 6932 | struct p2p_go_neg_results params; |
Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 6933 | int selected_freq = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6934 | |
| 6935 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 6936 | return -1; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6937 | if (wpas_p2p_check_6ghz(wpa_s, NULL, allow_6ghz, freq)) |
| 6938 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6939 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6940 | os_free(wpa_s->global->add_psk); |
| 6941 | wpa_s->global->add_psk = NULL; |
| 6942 | |
Dmitry Shmidt | dca3979 | 2011-09-06 11:17:33 -0700 | [diff] [blame] | 6943 | /* Make sure we are not running find during connection establishment */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6944 | wpa_printf(MSG_DEBUG, "P2P: Stop any on-going P2P FIND"); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6945 | wpas_p2p_stop_find_oper(wpa_s); |
Dmitry Shmidt | dca3979 | 2011-09-06 11:17:33 -0700 | [diff] [blame] | 6946 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6947 | if (!wpa_s->p2p_go_do_acs) { |
Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 6948 | selected_freq = wpas_p2p_select_go_freq(wpa_s, freq); |
| 6949 | if (selected_freq < 0) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6950 | return -1; |
| 6951 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6952 | |
Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 6953 | if (wpas_p2p_init_go_params(wpa_s, ¶ms, selected_freq, vht_center_freq2, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6954 | ht40, vht, max_oper_chwidth, he, edmg, |
| 6955 | NULL)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6956 | return -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6957 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6958 | p2p_go_params(wpa_s->global->p2p, ¶ms); |
| 6959 | params.persistent_group = persistent_group; |
| 6960 | |
| 6961 | wpa_s = wpas_p2p_get_group_iface(wpa_s, 0, 1); |
| 6962 | if (wpa_s == NULL) |
| 6963 | return -1; |
Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 6964 | if (freq > 0) |
| 6965 | wpa_s->p2p_go_no_pri_sec_switch = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6966 | wpas_start_wps_go(wpa_s, ¶ms, 0); |
| 6967 | |
| 6968 | return 0; |
| 6969 | } |
| 6970 | |
| 6971 | |
| 6972 | static int wpas_start_p2p_client(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6973 | struct wpa_ssid *params, int addr_allocated, |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame^] | 6974 | int freq, int force_scan, int retry_limit) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6975 | { |
| 6976 | struct wpa_ssid *ssid; |
Matthew Wang | 9ae940b | 2022-09-14 21:25:34 -0700 | [diff] [blame] | 6977 | int other_iface_found = 0; |
| 6978 | struct wpa_supplicant *ifs; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6979 | |
| 6980 | wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 0); |
| 6981 | if (wpa_s == NULL) |
| 6982 | return -1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6983 | if (force_scan) |
| 6984 | os_get_reltime(&wpa_s->scan_min_time); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6985 | wpa_s->p2p_last_4way_hs_fail = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6986 | |
| 6987 | wpa_supplicant_ap_deinit(wpa_s); |
| 6988 | |
| 6989 | ssid = wpa_config_add_network(wpa_s->conf); |
| 6990 | if (ssid == NULL) |
| 6991 | return -1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6992 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6993 | wpa_config_set_network_defaults(ssid); |
| 6994 | ssid->temporary = 1; |
| 6995 | ssid->proto = WPA_PROTO_RSN; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 6996 | ssid->pbss = params->pbss; |
| 6997 | ssid->pairwise_cipher = params->pbss ? WPA_CIPHER_GCMP : |
| 6998 | WPA_CIPHER_CCMP; |
| 6999 | ssid->group_cipher = params->pbss ? WPA_CIPHER_GCMP : WPA_CIPHER_CCMP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7000 | ssid->key_mgmt = WPA_KEY_MGMT_PSK; |
| 7001 | ssid->ssid = os_malloc(params->ssid_len); |
| 7002 | if (ssid->ssid == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7003 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 7004 | return -1; |
| 7005 | } |
| 7006 | os_memcpy(ssid->ssid, params->ssid, params->ssid_len); |
| 7007 | ssid->ssid_len = params->ssid_len; |
| 7008 | ssid->p2p_group = 1; |
| 7009 | ssid->export_keys = 1; |
| 7010 | if (params->psk_set) { |
| 7011 | os_memcpy(ssid->psk, params->psk, 32); |
| 7012 | ssid->psk_set = 1; |
| 7013 | } |
| 7014 | if (params->passphrase) |
| 7015 | ssid->passphrase = os_strdup(params->passphrase); |
| 7016 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7017 | wpa_s->show_group_started = 1; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7018 | wpa_s->p2p_in_invitation = 1; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame^] | 7019 | wpa_s->p2p_retry_limit = retry_limit; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7020 | wpa_s->p2p_invite_go_freq = freq; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7021 | wpa_s->p2p_go_group_formation_completed = 0; |
| 7022 | wpa_s->global->p2p_group_formation = wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7023 | |
Matthew Wang | 9ae940b | 2022-09-14 21:25:34 -0700 | [diff] [blame] | 7024 | /* |
| 7025 | * Get latest scan results from driver in case cached scan results from |
| 7026 | * interfaces on the same wiphy allow us to skip the next scan by fast |
| 7027 | * associating. Also update the scan time to the most recent scan result |
| 7028 | * fetch time on the same radio so it reflects the actual time the last |
| 7029 | * scan result event occurred. |
| 7030 | */ |
| 7031 | wpa_supplicant_update_scan_results(wpa_s); |
| 7032 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 7033 | radio_list) { |
| 7034 | if (ifs == wpa_s) |
| 7035 | continue; |
| 7036 | if (!other_iface_found || os_reltime_before(&wpa_s->last_scan, |
| 7037 | &ifs->last_scan)) { |
| 7038 | other_iface_found = 1; |
| 7039 | wpa_s->last_scan.sec = ifs->last_scan.sec; |
| 7040 | wpa_s->last_scan.usec = ifs->last_scan.usec; |
| 7041 | } |
| 7042 | } |
| 7043 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7044 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->p2pdev, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7045 | NULL); |
| 7046 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, |
| 7047 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7048 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 7049 | wpa_supplicant_select_network(wpa_s, ssid); |
| 7050 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7051 | return 0; |
| 7052 | } |
| 7053 | |
| 7054 | |
| 7055 | int wpas_p2p_group_add_persistent(struct wpa_supplicant *wpa_s, |
| 7056 | struct wpa_ssid *ssid, int addr_allocated, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7057 | int force_freq, int neg_freq, |
| 7058 | int vht_center_freq2, int ht40, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7059 | int vht, int max_oper_chwidth, int he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7060 | int edmg, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7061 | const struct p2p_channels *channels, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7062 | int connection_timeout, int force_scan, |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame^] | 7063 | bool allow_6ghz, int retry_limit) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7064 | { |
| 7065 | struct p2p_go_neg_results params; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 7066 | int go = 0, freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7067 | |
| 7068 | if (ssid->disabled != 2 || ssid->ssid == NULL) |
| 7069 | return -1; |
| 7070 | |
| 7071 | if (wpas_get_p2p_group(wpa_s, ssid->ssid, ssid->ssid_len, &go) && |
| 7072 | go == (ssid->mode == WPAS_MODE_P2P_GO)) { |
| 7073 | wpa_printf(MSG_DEBUG, "P2P: Requested persistent group is " |
| 7074 | "already running"); |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 7075 | if (go == 0 && |
| 7076 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7077 | wpa_s->p2pdev, NULL)) { |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 7078 | /* |
| 7079 | * This can happen if Invitation Response frame was lost |
| 7080 | * and the peer (GO of a persistent group) tries to |
| 7081 | * invite us again. Reschedule the timeout to avoid |
| 7082 | * terminating the wait for the connection too early |
| 7083 | * since we now know that the peer is still trying to |
| 7084 | * invite us instead of having already started the GO. |
| 7085 | */ |
| 7086 | wpa_printf(MSG_DEBUG, |
| 7087 | "P2P: Reschedule group formation timeout since peer is still trying to invite us"); |
| 7088 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, |
| 7089 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7090 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 7091 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7092 | return 0; |
| 7093 | } |
| 7094 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 7095 | os_free(wpa_s->global->add_psk); |
| 7096 | wpa_s->global->add_psk = NULL; |
| 7097 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7098 | /* Make sure we are not running find during connection establishment */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7099 | wpas_p2p_stop_find_oper(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7100 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7101 | wpa_s->p2p_fallback_to_go_neg = 0; |
| 7102 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7103 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 7104 | if (force_freq > 0) { |
| 7105 | freq = wpas_p2p_select_go_freq(wpa_s, force_freq); |
| 7106 | if (freq < 0) |
| 7107 | return -1; |
Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 7108 | wpa_s->p2p_go_no_pri_sec_switch = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7109 | } else { |
| 7110 | freq = wpas_p2p_select_go_freq(wpa_s, neg_freq); |
| 7111 | if (freq < 0 || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7112 | (freq > 0 && !freq_included(wpa_s, channels, freq))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7113 | freq = 0; |
| 7114 | } |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7115 | } else if (ssid->mode == WPAS_MODE_INFRA) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7116 | freq = neg_freq; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7117 | if (freq <= 0 || !freq_included(wpa_s, channels, freq)) { |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7118 | struct os_reltime now; |
| 7119 | struct wpa_bss *bss = |
| 7120 | wpa_bss_get_p2p_dev_addr(wpa_s, ssid->bssid); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7121 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7122 | os_get_reltime(&now); |
| 7123 | if (bss && |
| 7124 | !os_reltime_expired(&now, &bss->last_update, 5) && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7125 | freq_included(wpa_s, channels, bss->freq)) |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7126 | freq = bss->freq; |
| 7127 | else |
| 7128 | freq = 0; |
| 7129 | } |
| 7130 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7131 | return wpas_start_p2p_client(wpa_s, ssid, addr_allocated, freq, |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame^] | 7132 | force_scan, retry_limit); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7133 | } else { |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7134 | return -1; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7135 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7136 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7137 | if (wpas_p2p_init_go_params(wpa_s, ¶ms, freq, vht_center_freq2, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7138 | ht40, vht, max_oper_chwidth, he, edmg, |
| 7139 | channels)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7140 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7141 | |
| 7142 | params.role_go = 1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7143 | params.psk_set = ssid->psk_set; |
| 7144 | if (params.psk_set) |
| 7145 | os_memcpy(params.psk, ssid->psk, sizeof(params.psk)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7146 | if (ssid->passphrase) { |
| 7147 | if (os_strlen(ssid->passphrase) >= sizeof(params.passphrase)) { |
| 7148 | wpa_printf(MSG_ERROR, "P2P: Invalid passphrase in " |
| 7149 | "persistent group"); |
| 7150 | return -1; |
| 7151 | } |
| 7152 | os_strlcpy(params.passphrase, ssid->passphrase, |
| 7153 | sizeof(params.passphrase)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7154 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7155 | os_memcpy(params.ssid, ssid->ssid, ssid->ssid_len); |
| 7156 | params.ssid_len = ssid->ssid_len; |
| 7157 | params.persistent_group = 1; |
| 7158 | |
| 7159 | wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 1); |
| 7160 | if (wpa_s == NULL) |
| 7161 | return -1; |
| 7162 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7163 | p2p_channels_to_freqs(channels, params.freq_list, P2P_MAX_CHANNELS); |
| 7164 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7165 | wpa_s->p2p_first_connection_timeout = connection_timeout; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7166 | wpas_start_wps_go(wpa_s, ¶ms, 0); |
| 7167 | |
| 7168 | return 0; |
| 7169 | } |
| 7170 | |
| 7171 | |
| 7172 | static void wpas_p2p_ie_update(void *ctx, struct wpabuf *beacon_ies, |
| 7173 | struct wpabuf *proberesp_ies) |
| 7174 | { |
| 7175 | struct wpa_supplicant *wpa_s = ctx; |
| 7176 | if (wpa_s->ap_iface) { |
| 7177 | struct hostapd_data *hapd = wpa_s->ap_iface->bss[0]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7178 | if (!(hapd->conf->p2p & P2P_GROUP_OWNER)) { |
| 7179 | wpabuf_free(beacon_ies); |
| 7180 | wpabuf_free(proberesp_ies); |
| 7181 | return; |
| 7182 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7183 | if (beacon_ies) { |
| 7184 | wpabuf_free(hapd->p2p_beacon_ie); |
| 7185 | hapd->p2p_beacon_ie = beacon_ies; |
| 7186 | } |
| 7187 | wpabuf_free(hapd->p2p_probe_resp_ie); |
| 7188 | hapd->p2p_probe_resp_ie = proberesp_ies; |
| 7189 | } else { |
| 7190 | wpabuf_free(beacon_ies); |
| 7191 | wpabuf_free(proberesp_ies); |
| 7192 | } |
| 7193 | wpa_supplicant_ap_update_beacon(wpa_s); |
| 7194 | } |
| 7195 | |
| 7196 | |
| 7197 | static void wpas_p2p_idle_update(void *ctx, int idle) |
| 7198 | { |
| 7199 | struct wpa_supplicant *wpa_s = ctx; |
| 7200 | if (!wpa_s->ap_iface) |
| 7201 | return; |
| 7202 | wpa_printf(MSG_DEBUG, "P2P: GO - group %sidle", idle ? "" : "not "); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7203 | if (idle) { |
| 7204 | if (wpa_s->global->p2p_fail_on_wps_complete && |
| 7205 | wpa_s->p2p_in_provisioning) { |
| 7206 | wpas_p2p_grpform_fail_after_wps(wpa_s); |
| 7207 | return; |
| 7208 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7209 | wpas_p2p_set_group_idle_timeout(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7210 | } else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7211 | eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL); |
| 7212 | } |
| 7213 | |
| 7214 | |
| 7215 | struct p2p_group * wpas_p2p_group_init(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7216 | struct wpa_ssid *ssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7217 | { |
| 7218 | struct p2p_group *group; |
| 7219 | struct p2p_group_config *cfg; |
| 7220 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 7221 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL || |
| 7222 | !ssid->p2p_group) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7223 | return NULL; |
| 7224 | |
| 7225 | cfg = os_zalloc(sizeof(*cfg)); |
| 7226 | if (cfg == NULL) |
| 7227 | return NULL; |
| 7228 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7229 | if (ssid->p2p_persistent_group && wpa_s->conf->persistent_reconnect) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7230 | cfg->persistent_group = 2; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7231 | else if (ssid->p2p_persistent_group) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7232 | cfg->persistent_group = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7233 | os_memcpy(cfg->interface_addr, wpa_s->own_addr, ETH_ALEN); |
| 7234 | if (wpa_s->max_stations && |
| 7235 | wpa_s->max_stations < wpa_s->conf->max_num_sta) |
| 7236 | cfg->max_clients = wpa_s->max_stations; |
| 7237 | else |
| 7238 | cfg->max_clients = wpa_s->conf->max_num_sta; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7239 | os_memcpy(cfg->ssid, ssid->ssid, ssid->ssid_len); |
| 7240 | cfg->ssid_len = ssid->ssid_len; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7241 | cfg->freq = ssid->frequency; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7242 | cfg->cb_ctx = wpa_s; |
| 7243 | cfg->ie_update = wpas_p2p_ie_update; |
| 7244 | cfg->idle_update = wpas_p2p_idle_update; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7245 | cfg->ip_addr_alloc = WPA_GET_BE32(wpa_s->p2pdev->conf->ip_addr_start) |
| 7246 | != 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7247 | |
| 7248 | group = p2p_group_init(wpa_s->global->p2p, cfg); |
| 7249 | if (group == NULL) |
| 7250 | os_free(cfg); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7251 | if (ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7252 | p2p_group_notif_formation_done(group); |
| 7253 | wpa_s->p2p_group = group; |
| 7254 | return group; |
| 7255 | } |
| 7256 | |
| 7257 | |
| 7258 | void wpas_p2p_wps_success(struct wpa_supplicant *wpa_s, const u8 *peer_addr, |
| 7259 | int registrar) |
| 7260 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7261 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 7262 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7263 | if (!wpa_s->p2p_in_provisioning) { |
| 7264 | wpa_printf(MSG_DEBUG, "P2P: Ignore WPS success event - P2P " |
| 7265 | "provisioning not in progress"); |
| 7266 | return; |
| 7267 | } |
| 7268 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7269 | if (ssid && ssid->mode == WPAS_MODE_INFRA) { |
| 7270 | u8 go_dev_addr[ETH_ALEN]; |
| 7271 | os_memcpy(go_dev_addr, wpa_s->bssid, ETH_ALEN); |
| 7272 | wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid, |
| 7273 | ssid->ssid_len); |
| 7274 | /* Clear any stored provisioning info */ |
| 7275 | p2p_clear_provisioning_info(wpa_s->global->p2p, go_dev_addr); |
| 7276 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7277 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7278 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->p2pdev, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7279 | NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7280 | wpa_s->p2p_go_group_formation_completed = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7281 | if (ssid && ssid->mode == WPAS_MODE_INFRA) { |
| 7282 | /* |
| 7283 | * Use a separate timeout for initial data connection to |
| 7284 | * complete to allow the group to be removed automatically if |
| 7285 | * something goes wrong in this step before the P2P group idle |
| 7286 | * timeout mechanism is taken into use. |
| 7287 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7288 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 7289 | "P2P: Re-start group formation timeout (%d seconds) as client for initial connection", |
| 7290 | P2P_MAX_INITIAL_CONN_WAIT); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7291 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, |
| 7292 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7293 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7294 | /* Complete group formation on successful data connection. */ |
| 7295 | wpa_s->p2p_go_group_formation_completed = 0; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7296 | } else if (ssid) { |
| 7297 | /* |
| 7298 | * Use a separate timeout for initial data connection to |
| 7299 | * complete to allow the group to be removed automatically if |
| 7300 | * the client does not complete data connection successfully. |
| 7301 | */ |
| 7302 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 7303 | "P2P: Re-start group formation timeout (%d seconds) as GO for initial connection", |
| 7304 | P2P_MAX_INITIAL_CONN_WAIT_GO); |
| 7305 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT_GO, 0, |
| 7306 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7307 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7308 | /* |
| 7309 | * Complete group formation on first successful data connection |
| 7310 | */ |
| 7311 | wpa_s->p2p_go_group_formation_completed = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7312 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7313 | if (wpa_s->global->p2p) |
| 7314 | p2p_wps_success_cb(wpa_s->global->p2p, peer_addr); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 7315 | wpas_group_formation_completed(wpa_s, 1, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7316 | } |
| 7317 | |
| 7318 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7319 | void wpas_p2p_wps_failed(struct wpa_supplicant *wpa_s, |
| 7320 | struct wps_event_fail *fail) |
| 7321 | { |
| 7322 | if (!wpa_s->p2p_in_provisioning) { |
| 7323 | wpa_printf(MSG_DEBUG, "P2P: Ignore WPS fail event - P2P " |
| 7324 | "provisioning not in progress"); |
| 7325 | return; |
| 7326 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7327 | |
| 7328 | if (wpa_s->go_params) { |
| 7329 | p2p_clear_provisioning_info( |
| 7330 | wpa_s->global->p2p, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7331 | wpa_s->go_params->peer_device_addr); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7332 | } |
| 7333 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7334 | wpas_notify_p2p_wps_failed(wpa_s, fail); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7335 | |
| 7336 | if (wpa_s == wpa_s->global->p2p_group_formation) { |
| 7337 | /* |
| 7338 | * Allow some time for the failed WPS negotiation exchange to |
| 7339 | * complete, but remove the group since group formation cannot |
| 7340 | * succeed after provisioning failure. |
| 7341 | */ |
| 7342 | wpa_printf(MSG_DEBUG, "P2P: WPS step failed during group formation - reject connection from timeout"); |
| 7343 | wpa_s->global->p2p_fail_on_wps_complete = 1; |
| 7344 | eloop_deplete_timeout(0, 50000, |
| 7345 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7346 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7347 | } |
| 7348 | } |
| 7349 | |
| 7350 | |
| 7351 | int wpas_p2p_wps_eapol_cb(struct wpa_supplicant *wpa_s) |
| 7352 | { |
| 7353 | if (!wpa_s->global->p2p_fail_on_wps_complete || |
| 7354 | !wpa_s->p2p_in_provisioning) |
| 7355 | return 0; |
| 7356 | |
| 7357 | wpas_p2p_grpform_fail_after_wps(wpa_s); |
| 7358 | |
| 7359 | return 1; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7360 | } |
| 7361 | |
| 7362 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7363 | int wpas_p2p_prov_disc(struct wpa_supplicant *wpa_s, const u8 *peer_addr, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7364 | const char *config_method, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7365 | enum wpas_p2p_prov_disc_use use, |
| 7366 | struct p2ps_provision *p2ps_prov) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7367 | { |
| 7368 | u16 config_methods; |
| 7369 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7370 | wpa_s->global->pending_p2ps_group = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7371 | wpa_s->global->pending_p2ps_group_freq = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7372 | wpa_s->p2p_fallback_to_go_neg = 0; |
| 7373 | wpa_s->pending_pd_use = NORMAL_PD; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7374 | if (p2ps_prov && use == WPAS_P2P_PD_FOR_ASP) { |
| 7375 | p2ps_prov->conncap = p2ps_group_capability( |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7376 | wpa_s, P2PS_SETUP_NONE, p2ps_prov->role, |
| 7377 | &p2ps_prov->force_freq, &p2ps_prov->pref_freq); |
| 7378 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7379 | wpa_printf(MSG_DEBUG, |
| 7380 | "P2P: %s conncap: %d - ASP parsed: %x %x %d %s", |
| 7381 | __func__, p2ps_prov->conncap, |
| 7382 | p2ps_prov->adv_id, p2ps_prov->conncap, |
| 7383 | p2ps_prov->status, p2ps_prov->info); |
| 7384 | |
| 7385 | config_methods = 0; |
| 7386 | } else if (os_strncmp(config_method, "display", 7) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7387 | config_methods = WPS_CONFIG_DISPLAY; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7388 | else if (os_strncmp(config_method, "keypad", 6) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7389 | config_methods = WPS_CONFIG_KEYPAD; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7390 | else if (os_strncmp(config_method, "pbc", 3) == 0 || |
| 7391 | os_strncmp(config_method, "pushbutton", 10) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7392 | config_methods = WPS_CONFIG_PUSHBUTTON; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7393 | else { |
| 7394 | wpa_printf(MSG_DEBUG, "P2P: Unknown config method"); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7395 | os_free(p2ps_prov); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7396 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7397 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7398 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7399 | if (use == WPAS_P2P_PD_AUTO) { |
| 7400 | os_memcpy(wpa_s->pending_join_dev_addr, peer_addr, ETH_ALEN); |
| 7401 | wpa_s->pending_pd_config_methods = config_methods; |
| 7402 | wpa_s->p2p_auto_pd = 1; |
| 7403 | wpa_s->p2p_auto_join = 0; |
| 7404 | wpa_s->pending_pd_before_join = 0; |
| 7405 | wpa_s->auto_pd_scan_retry = 0; |
| 7406 | wpas_p2p_stop_find(wpa_s); |
| 7407 | wpa_s->p2p_join_scan_count = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7408 | os_get_reltime(&wpa_s->p2p_auto_started); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7409 | wpa_printf(MSG_DEBUG, "P2P: Auto PD started at %ld.%06ld", |
| 7410 | wpa_s->p2p_auto_started.sec, |
| 7411 | wpa_s->p2p_auto_started.usec); |
| 7412 | wpas_p2p_join_scan(wpa_s, NULL); |
| 7413 | return 0; |
| 7414 | } |
| 7415 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7416 | if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) { |
| 7417 | os_free(p2ps_prov); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7418 | return -1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7419 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7420 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7421 | return p2p_prov_disc_req(wpa_s->global->p2p, peer_addr, p2ps_prov, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7422 | config_methods, use == WPAS_P2P_PD_FOR_JOIN, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7423 | 0, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7424 | } |
| 7425 | |
| 7426 | |
| 7427 | int wpas_p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf, |
| 7428 | char *end) |
| 7429 | { |
| 7430 | return p2p_scan_result_text(ies, ies_len, buf, end); |
| 7431 | } |
| 7432 | |
| 7433 | |
| 7434 | static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant *wpa_s) |
| 7435 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7436 | if (!offchannel_pending_action_tx(wpa_s)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7437 | return; |
| 7438 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 7439 | if (wpa_s->p2p_send_action_work) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7440 | wpas_p2p_free_send_action_work(wpa_s); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 7441 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 7442 | wpa_s, NULL); |
| 7443 | offchannel_send_action_done(wpa_s); |
| 7444 | } |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 7445 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7446 | wpa_printf(MSG_DEBUG, "P2P: Drop pending Action TX due to new " |
| 7447 | "operation request"); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7448 | offchannel_clear_pending_action_tx(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7449 | } |
| 7450 | |
| 7451 | |
| 7452 | int wpas_p2p_find(struct wpa_supplicant *wpa_s, unsigned int timeout, |
| 7453 | enum p2p_discovery_type type, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7454 | unsigned int num_req_dev_types, const u8 *req_dev_types, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7455 | const u8 *dev_id, unsigned int search_delay, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7456 | u8 seek_cnt, const char **seek_string, int freq, |
| 7457 | bool include_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7458 | { |
| 7459 | wpas_p2p_clear_pending_action_tx(wpa_s); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7460 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7461 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7462 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7463 | wpa_s->p2p_in_provisioning) { |
| 7464 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Reject p2p_find operation%s%s", |
| 7465 | (wpa_s->global->p2p_disabled || !wpa_s->global->p2p) ? |
| 7466 | " (P2P disabled)" : "", |
| 7467 | wpa_s->p2p_in_provisioning ? |
| 7468 | " (p2p_in_provisioning)" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7469 | return -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7470 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7471 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7472 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 7473 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7474 | return p2p_find(wpa_s->global->p2p, timeout, type, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7475 | num_req_dev_types, req_dev_types, dev_id, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7476 | search_delay, seek_cnt, seek_string, freq, |
| 7477 | include_6ghz); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7478 | } |
| 7479 | |
| 7480 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7481 | static void wpas_p2p_scan_res_ignore_search(struct wpa_supplicant *wpa_s, |
| 7482 | struct wpa_scan_results *scan_res) |
| 7483 | { |
| 7484 | wpa_printf(MSG_DEBUG, "P2P: Ignore scan results"); |
| 7485 | |
| 7486 | if (wpa_s->p2p_scan_work) { |
| 7487 | struct wpa_radio_work *work = wpa_s->p2p_scan_work; |
| 7488 | wpa_s->p2p_scan_work = NULL; |
| 7489 | radio_work_done(work); |
| 7490 | } |
| 7491 | |
| 7492 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7493 | return; |
| 7494 | |
| 7495 | /* |
| 7496 | * Indicate that results have been processed so that the P2P module can |
| 7497 | * continue pending tasks. |
| 7498 | */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 7499 | wpas_p2p_scan_res_handled(wpa_s); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7500 | } |
| 7501 | |
| 7502 | |
| 7503 | static void wpas_p2p_stop_find_oper(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7504 | { |
| 7505 | wpas_p2p_clear_pending_action_tx(wpa_s); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7506 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7507 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
| 7508 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7509 | |
| 7510 | if (wpa_s->global->p2p) |
| 7511 | p2p_stop_find(wpa_s->global->p2p); |
| 7512 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7513 | if (wpa_s->scan_res_handler == wpas_p2p_scan_res_handler) { |
| 7514 | wpa_printf(MSG_DEBUG, |
| 7515 | "P2P: Do not consider the scan results after stop_find"); |
| 7516 | wpa_s->scan_res_handler = wpas_p2p_scan_res_ignore_search; |
| 7517 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7518 | } |
| 7519 | |
| 7520 | |
| 7521 | void wpas_p2p_stop_find(struct wpa_supplicant *wpa_s) |
| 7522 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7523 | wpas_p2p_stop_find_oper(wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7524 | if (!wpa_s->global->pending_group_iface_for_p2ps) |
| 7525 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7526 | } |
| 7527 | |
| 7528 | |
| 7529 | static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx) |
| 7530 | { |
| 7531 | struct wpa_supplicant *wpa_s = eloop_ctx; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7532 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7533 | } |
| 7534 | |
| 7535 | |
| 7536 | int wpas_p2p_listen(struct wpa_supplicant *wpa_s, unsigned int timeout) |
| 7537 | { |
| 7538 | int res; |
| 7539 | |
| 7540 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7541 | return -1; |
| 7542 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 7543 | if (wpa_s->p2p_lo_started) { |
| 7544 | wpa_printf(MSG_DEBUG, |
| 7545 | "P2P: Cannot start P2P listen, it is offloaded"); |
| 7546 | return -1; |
| 7547 | } |
| 7548 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7549 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7550 | wpas_p2p_clear_pending_action_tx(wpa_s); |
| 7551 | |
| 7552 | if (timeout == 0) { |
| 7553 | /* |
| 7554 | * This is a request for unlimited Listen state. However, at |
| 7555 | * least for now, this is mapped to a Listen state for one |
| 7556 | * hour. |
| 7557 | */ |
| 7558 | timeout = 3600; |
| 7559 | } |
| 7560 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7561 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7562 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7563 | /* |
| 7564 | * Stop previous find/listen operation to avoid trying to request a new |
| 7565 | * remain-on-channel operation while the driver is still running the |
| 7566 | * previous one. |
| 7567 | */ |
| 7568 | if (wpa_s->global->p2p) |
| 7569 | p2p_stop_find(wpa_s->global->p2p); |
| 7570 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7571 | res = wpas_p2p_listen_start(wpa_s, timeout * 1000); |
| 7572 | if (res == 0 && timeout * 1000 > wpa_s->max_remain_on_chan) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7573 | wpa_s->global->p2p_long_listen = timeout * 1000; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7574 | eloop_register_timeout(timeout, 0, |
| 7575 | wpas_p2p_long_listen_timeout, |
| 7576 | wpa_s, NULL); |
| 7577 | } |
| 7578 | |
| 7579 | return res; |
| 7580 | } |
| 7581 | |
| 7582 | |
| 7583 | int wpas_p2p_assoc_req_ie(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
| 7584 | u8 *buf, size_t len, int p2p_group) |
| 7585 | { |
| 7586 | struct wpabuf *p2p_ie; |
| 7587 | int ret; |
| 7588 | |
| 7589 | if (wpa_s->global->p2p_disabled) |
| 7590 | return -1; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 7591 | /* |
| 7592 | * Advertize mandatory cross connection capability even on |
| 7593 | * p2p_disabled=1 interface when associating with a P2P Manager WLAN AP. |
| 7594 | */ |
| 7595 | if (wpa_s->conf->p2p_disabled && p2p_group) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7596 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7597 | if (wpa_s->global->p2p == NULL) |
| 7598 | return -1; |
| 7599 | if (bss == NULL) |
| 7600 | return -1; |
| 7601 | |
| 7602 | p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE); |
| 7603 | ret = p2p_assoc_req_ie(wpa_s->global->p2p, bss->bssid, buf, len, |
| 7604 | p2p_group, p2p_ie); |
| 7605 | wpabuf_free(p2p_ie); |
| 7606 | |
| 7607 | return ret; |
| 7608 | } |
| 7609 | |
| 7610 | |
| 7611 | int wpas_p2p_probe_req_rx(struct wpa_supplicant *wpa_s, const u8 *addr, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7612 | const u8 *dst, const u8 *bssid, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 7613 | const u8 *ie, size_t ie_len, |
| 7614 | unsigned int rx_freq, int ssi_signal) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7615 | { |
| 7616 | if (wpa_s->global->p2p_disabled) |
| 7617 | return 0; |
| 7618 | if (wpa_s->global->p2p == NULL) |
| 7619 | return 0; |
| 7620 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7621 | switch (p2p_probe_req_rx(wpa_s->global->p2p, addr, dst, bssid, |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 7622 | ie, ie_len, rx_freq, wpa_s->p2p_lo_started)) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7623 | case P2P_PREQ_NOT_P2P: |
| 7624 | wpas_notify_preq(wpa_s, addr, dst, bssid, ie, ie_len, |
| 7625 | ssi_signal); |
| 7626 | /* fall through */ |
| 7627 | case P2P_PREQ_MALFORMED: |
| 7628 | case P2P_PREQ_NOT_LISTEN: |
| 7629 | case P2P_PREQ_NOT_PROCESSED: |
| 7630 | default: /* make gcc happy */ |
| 7631 | return 0; |
| 7632 | case P2P_PREQ_PROCESSED: |
| 7633 | return 1; |
| 7634 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7635 | } |
| 7636 | |
| 7637 | |
| 7638 | void wpas_p2p_rx_action(struct wpa_supplicant *wpa_s, const u8 *da, |
| 7639 | const u8 *sa, const u8 *bssid, |
| 7640 | u8 category, const u8 *data, size_t len, int freq) |
| 7641 | { |
| 7642 | if (wpa_s->global->p2p_disabled) |
| 7643 | return; |
| 7644 | if (wpa_s->global->p2p == NULL) |
| 7645 | return; |
| 7646 | |
| 7647 | p2p_rx_action(wpa_s->global->p2p, da, sa, bssid, category, data, len, |
| 7648 | freq); |
| 7649 | } |
| 7650 | |
| 7651 | |
| 7652 | void wpas_p2p_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ies) |
| 7653 | { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7654 | unsigned int bands; |
| 7655 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7656 | if (wpa_s->global->p2p_disabled) |
| 7657 | return; |
| 7658 | if (wpa_s->global->p2p == NULL) |
| 7659 | return; |
| 7660 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7661 | bands = wpas_get_bands(wpa_s, NULL); |
| 7662 | p2p_scan_ie(wpa_s->global->p2p, ies, NULL, bands); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7663 | } |
| 7664 | |
| 7665 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7666 | static void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7667 | { |
| 7668 | p2p_group_deinit(wpa_s->p2p_group); |
| 7669 | wpa_s->p2p_group = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7670 | |
| 7671 | wpa_s->ap_configured_cb = NULL; |
| 7672 | wpa_s->ap_configured_cb_ctx = NULL; |
| 7673 | wpa_s->ap_configured_cb_data = NULL; |
| 7674 | wpa_s->connect_without_scan = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7675 | } |
| 7676 | |
| 7677 | |
| 7678 | int wpas_p2p_reject(struct wpa_supplicant *wpa_s, const u8 *addr) |
| 7679 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7680 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7681 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7682 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7683 | return -1; |
| 7684 | |
| 7685 | return p2p_reject(wpa_s->global->p2p, addr); |
| 7686 | } |
| 7687 | |
| 7688 | |
| 7689 | /* Invite to reinvoke a persistent group */ |
| 7690 | int wpas_p2p_invite(struct wpa_supplicant *wpa_s, const u8 *peer_addr, |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 7691 | struct wpa_ssid *ssid, const u8 *go_dev_addr, int freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7692 | int vht_center_freq2, int ht40, int vht, int max_chwidth, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7693 | int pref_freq, int he, int edmg, bool allow_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7694 | { |
| 7695 | enum p2p_invite_role role; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7696 | u8 *bssid = NULL; |
| 7697 | int force_freq = 0; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7698 | int res; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 7699 | int no_pref_freq_given = pref_freq == 0; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 7700 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 7701 | unsigned int size; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7702 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7703 | if (wpas_p2p_check_6ghz(wpa_s, NULL, allow_6ghz, freq)) |
| 7704 | return -1; |
| 7705 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7706 | wpa_s->global->p2p_invite_group = NULL; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7707 | if (peer_addr) |
| 7708 | os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN); |
| 7709 | else |
| 7710 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7711 | |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 7712 | wpa_s->p2p_persistent_go_freq = freq; |
| 7713 | wpa_s->p2p_go_ht40 = !!ht40; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7714 | wpa_s->p2p_go_vht = !!vht; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7715 | wpa_s->p2p_go_he = !!he; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7716 | wpa_s->p2p_go_max_oper_chwidth = max_chwidth; |
| 7717 | wpa_s->p2p_go_vht_center_freq2 = vht_center_freq2; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7718 | wpa_s->p2p_go_edmg = !!edmg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7719 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 7720 | role = P2P_INVITE_ROLE_GO; |
| 7721 | if (peer_addr == NULL) { |
| 7722 | wpa_printf(MSG_DEBUG, "P2P: Missing peer " |
| 7723 | "address in invitation command"); |
| 7724 | return -1; |
| 7725 | } |
| 7726 | if (wpas_p2p_create_iface(wpa_s)) { |
| 7727 | if (wpas_p2p_add_group_interface(wpa_s, |
| 7728 | WPA_IF_P2P_GO) < 0) { |
| 7729 | wpa_printf(MSG_ERROR, "P2P: Failed to " |
| 7730 | "allocate a new interface for the " |
| 7731 | "group"); |
| 7732 | return -1; |
| 7733 | } |
| 7734 | bssid = wpa_s->pending_interface_addr; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7735 | } else if (wpa_s->p2p_mgmt) |
| 7736 | bssid = wpa_s->parent->own_addr; |
| 7737 | else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7738 | bssid = wpa_s->own_addr; |
| 7739 | } else { |
| 7740 | role = P2P_INVITE_ROLE_CLIENT; |
| 7741 | peer_addr = ssid->bssid; |
| 7742 | } |
| 7743 | wpa_s->pending_invite_ssid_id = ssid->id; |
| 7744 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7745 | size = P2P_MAX_PREF_CHANNELS; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7746 | res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7747 | role == P2P_INVITE_ROLE_GO, |
| 7748 | pref_freq_list, &size); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7749 | if (res) |
| 7750 | return res; |
Irfan Sheriff | af84a57 | 2012-09-22 16:59:30 -0700 | [diff] [blame] | 7751 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7752 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7753 | return -1; |
| 7754 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7755 | p2p_set_own_pref_freq_list(wpa_s->global->p2p, pref_freq_list, size); |
| 7756 | |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 7757 | if (wpa_s->parent->conf->p2p_ignore_shared_freq && |
| 7758 | no_pref_freq_given && pref_freq > 0 && |
| 7759 | wpa_s->num_multichan_concurrent > 1 && |
| 7760 | wpas_p2p_num_unused_channels(wpa_s) > 0) { |
| 7761 | wpa_printf(MSG_DEBUG, "P2P: Ignore own channel preference %d MHz for invitation due to p2p_ignore_shared_freq=1 configuration", |
| 7762 | pref_freq); |
| 7763 | pref_freq = 0; |
| 7764 | } |
| 7765 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7766 | /* |
| 7767 | * Stop any find/listen operations before invitation and possibly |
| 7768 | * connection establishment. |
| 7769 | */ |
| 7770 | wpas_p2p_stop_find_oper(wpa_s); |
| 7771 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7772 | return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid, |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7773 | ssid->ssid, ssid->ssid_len, force_freq, go_dev_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7774 | 1, pref_freq, -1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7775 | } |
| 7776 | |
| 7777 | |
| 7778 | /* Invite to join an active group */ |
| 7779 | int wpas_p2p_invite_group(struct wpa_supplicant *wpa_s, const char *ifname, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7780 | const u8 *peer_addr, const u8 *go_dev_addr, |
| 7781 | bool allow_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7782 | { |
| 7783 | struct wpa_global *global = wpa_s->global; |
| 7784 | enum p2p_invite_role role; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7785 | u8 *bssid = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7786 | struct wpa_ssid *ssid; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7787 | int persistent; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7788 | int freq = 0, force_freq = 0, pref_freq = 0; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7789 | int res; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 7790 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 7791 | unsigned int size; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7792 | |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 7793 | wpa_s->p2p_persistent_go_freq = 0; |
| 7794 | wpa_s->p2p_go_ht40 = 0; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7795 | wpa_s->p2p_go_vht = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7796 | wpa_s->p2p_go_vht_center_freq2 = 0; |
| 7797 | wpa_s->p2p_go_max_oper_chwidth = 0; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7798 | wpa_s->p2p_go_edmg = 0; |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 7799 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7800 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 7801 | if (os_strcmp(wpa_s->ifname, ifname) == 0) |
| 7802 | break; |
| 7803 | } |
| 7804 | if (wpa_s == NULL) { |
| 7805 | wpa_printf(MSG_DEBUG, "P2P: Interface '%s' not found", ifname); |
| 7806 | return -1; |
| 7807 | } |
| 7808 | |
| 7809 | ssid = wpa_s->current_ssid; |
| 7810 | if (ssid == NULL) { |
| 7811 | wpa_printf(MSG_DEBUG, "P2P: No current SSID to use for " |
| 7812 | "invitation"); |
| 7813 | return -1; |
| 7814 | } |
| 7815 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7816 | wpa_s->global->p2p_invite_group = wpa_s; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7817 | persistent = ssid->p2p_persistent_group && |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7818 | wpas_p2p_get_persistent(wpa_s->p2pdev, peer_addr, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7819 | ssid->ssid, ssid->ssid_len); |
| 7820 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7821 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 7822 | role = P2P_INVITE_ROLE_ACTIVE_GO; |
| 7823 | bssid = wpa_s->own_addr; |
| 7824 | if (go_dev_addr == NULL) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7825 | go_dev_addr = wpa_s->global->p2p_dev_addr; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7826 | freq = ssid->frequency; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7827 | } else { |
| 7828 | role = P2P_INVITE_ROLE_CLIENT; |
| 7829 | if (wpa_s->wpa_state < WPA_ASSOCIATED) { |
| 7830 | wpa_printf(MSG_DEBUG, "P2P: Not associated - cannot " |
| 7831 | "invite to current group"); |
| 7832 | return -1; |
| 7833 | } |
| 7834 | bssid = wpa_s->bssid; |
| 7835 | if (go_dev_addr == NULL && |
| 7836 | !is_zero_ether_addr(wpa_s->go_dev_addr)) |
| 7837 | go_dev_addr = wpa_s->go_dev_addr; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7838 | freq = wpa_s->current_bss ? wpa_s->current_bss->freq : |
| 7839 | (int) wpa_s->assoc_freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7840 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7841 | wpa_s->p2pdev->pending_invite_ssid_id = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7842 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7843 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7844 | return -1; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7845 | if (wpas_p2p_check_6ghz(wpa_s, peer_addr, allow_6ghz, freq)) |
| 7846 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7847 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7848 | size = P2P_MAX_PREF_CHANNELS; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7849 | res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7850 | role == P2P_INVITE_ROLE_ACTIVE_GO, |
| 7851 | pref_freq_list, &size); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7852 | if (res) |
| 7853 | return res; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7854 | wpas_p2p_set_own_freq_preference(wpa_s, force_freq); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7855 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7856 | return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid, |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7857 | ssid->ssid, ssid->ssid_len, force_freq, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7858 | go_dev_addr, persistent, pref_freq, -1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7859 | } |
| 7860 | |
| 7861 | |
| 7862 | void wpas_p2p_completed(struct wpa_supplicant *wpa_s) |
| 7863 | { |
| 7864 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7865 | u8 go_dev_addr[ETH_ALEN]; |
| 7866 | int persistent; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7867 | int freq; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 7868 | u8 ip[3 * 4], *ip_ptr = NULL; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7869 | char ip_addr[100]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7870 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7871 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION) { |
| 7872 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7873 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7874 | } |
| 7875 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7876 | if (!wpa_s->show_group_started || !ssid) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7877 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7878 | |
| 7879 | wpa_s->show_group_started = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7880 | if (!wpa_s->p2p_go_group_formation_completed && |
| 7881 | wpa_s->global->p2p_group_formation == wpa_s) { |
| 7882 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 7883 | "P2P: Marking group formation completed on client on data connection"); |
| 7884 | wpa_s->p2p_go_group_formation_completed = 1; |
| 7885 | wpa_s->global->p2p_group_formation = NULL; |
| 7886 | wpa_s->p2p_in_provisioning = 0; |
| 7887 | wpa_s->p2p_in_invitation = 0; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame^] | 7888 | wpa_s->p2p_retry_limit = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7889 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7890 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7891 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 7892 | if (ssid->bssid_set) |
| 7893 | os_memcpy(go_dev_addr, ssid->bssid, ETH_ALEN); |
| 7894 | persistent = wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid, |
| 7895 | ssid->ssid_len); |
| 7896 | os_memcpy(wpa_s->go_dev_addr, go_dev_addr, ETH_ALEN); |
| 7897 | |
| 7898 | if (wpa_s->global->p2p_group_formation == wpa_s) |
| 7899 | wpa_s->global->p2p_group_formation = NULL; |
| 7900 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7901 | freq = wpa_s->current_bss ? wpa_s->current_bss->freq : |
| 7902 | (int) wpa_s->assoc_freq; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7903 | |
| 7904 | ip_addr[0] = '\0'; |
| 7905 | if (wpa_sm_get_p2p_ip_addr(wpa_s->wpa, ip) == 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7906 | int res; |
| 7907 | |
| 7908 | res = os_snprintf(ip_addr, sizeof(ip_addr), |
| 7909 | " ip_addr=%u.%u.%u.%u " |
| 7910 | "ip_mask=%u.%u.%u.%u go_ip_addr=%u.%u.%u.%u", |
| 7911 | ip[0], ip[1], ip[2], ip[3], |
| 7912 | ip[4], ip[5], ip[6], ip[7], |
| 7913 | ip[8], ip[9], ip[10], ip[11]); |
| 7914 | if (os_snprintf_error(sizeof(ip_addr), res)) |
| 7915 | ip_addr[0] = '\0'; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 7916 | ip_ptr = ip; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7917 | } |
| 7918 | |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 7919 | wpas_p2p_group_started(wpa_s, 0, ssid, freq, |
| 7920 | ssid->passphrase == NULL && ssid->psk_set ? |
| 7921 | ssid->psk : NULL, |
| 7922 | ssid->passphrase, go_dev_addr, persistent, |
| 7923 | ip_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7924 | |
| 7925 | if (persistent) |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 7926 | wpas_p2p_store_persistent_group(wpa_s->p2pdev, |
| 7927 | ssid, go_dev_addr); |
| 7928 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 7929 | wpas_notify_p2p_group_started(wpa_s, ssid, persistent, 1, ip_ptr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7930 | } |
| 7931 | |
| 7932 | |
| 7933 | int wpas_p2p_presence_req(struct wpa_supplicant *wpa_s, u32 duration1, |
| 7934 | u32 interval1, u32 duration2, u32 interval2) |
| 7935 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7936 | int ret; |
| 7937 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7938 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7939 | return -1; |
| 7940 | |
| 7941 | if (wpa_s->wpa_state < WPA_ASSOCIATED || |
| 7942 | wpa_s->current_ssid == NULL || |
| 7943 | wpa_s->current_ssid->mode != WPAS_MODE_INFRA) |
| 7944 | return -1; |
| 7945 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7946 | ret = p2p_presence_req(wpa_s->global->p2p, wpa_s->bssid, |
| 7947 | wpa_s->own_addr, wpa_s->assoc_freq, |
| 7948 | duration1, interval1, duration2, interval2); |
| 7949 | if (ret == 0) |
| 7950 | wpa_s->waiting_presence_resp = 1; |
| 7951 | |
| 7952 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7953 | } |
| 7954 | |
| 7955 | |
| 7956 | int wpas_p2p_ext_listen(struct wpa_supplicant *wpa_s, unsigned int period, |
| 7957 | unsigned int interval) |
| 7958 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7959 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7960 | return -1; |
| 7961 | |
| 7962 | return p2p_ext_listen(wpa_s->global->p2p, period, interval); |
| 7963 | } |
| 7964 | |
| 7965 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7966 | static int wpas_p2p_is_client(struct wpa_supplicant *wpa_s) |
| 7967 | { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7968 | if (wpa_s->current_ssid == NULL) { |
| 7969 | /* |
| 7970 | * current_ssid can be cleared when P2P client interface gets |
| 7971 | * disconnected, so assume this interface was used as P2P |
| 7972 | * client. |
| 7973 | */ |
| 7974 | return 1; |
| 7975 | } |
| 7976 | return wpa_s->current_ssid->p2p_group && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7977 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA; |
| 7978 | } |
| 7979 | |
| 7980 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7981 | static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx) |
| 7982 | { |
| 7983 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 7984 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7985 | if (wpa_s->conf->p2p_group_idle == 0 && !wpas_p2p_is_client(wpa_s)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7986 | wpa_printf(MSG_DEBUG, "P2P: Ignore group idle timeout - " |
| 7987 | "disabled"); |
| 7988 | return; |
| 7989 | } |
| 7990 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7991 | wpa_printf(MSG_DEBUG, "P2P: Group idle timeout reached - terminate " |
| 7992 | "group"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7993 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_IDLE_TIMEOUT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7994 | } |
| 7995 | |
| 7996 | |
| 7997 | static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s) |
| 7998 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7999 | int timeout; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8000 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8001 | if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0) |
| 8002 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout"); |
| 8003 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8004 | if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group) |
| 8005 | return; |
| 8006 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8007 | timeout = wpa_s->conf->p2p_group_idle; |
| 8008 | if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA && |
| 8009 | (timeout == 0 || timeout > P2P_MAX_CLIENT_IDLE)) |
| 8010 | timeout = P2P_MAX_CLIENT_IDLE; |
| 8011 | |
| 8012 | if (timeout == 0) |
| 8013 | return; |
| 8014 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8015 | if (timeout < 0) { |
| 8016 | if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA) |
| 8017 | timeout = 0; /* special client mode no-timeout */ |
| 8018 | else |
| 8019 | return; |
| 8020 | } |
| 8021 | |
| 8022 | if (wpa_s->p2p_in_provisioning) { |
| 8023 | /* |
| 8024 | * Use the normal group formation timeout during the |
| 8025 | * provisioning phase to avoid terminating this process too |
| 8026 | * early due to group idle timeout. |
| 8027 | */ |
| 8028 | wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout " |
| 8029 | "during provisioning"); |
| 8030 | return; |
| 8031 | } |
Deepthi Gowri | 9e4e8ac | 2013-04-16 11:57:05 +0530 | [diff] [blame] | 8032 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8033 | if (wpa_s->show_group_started) { |
| 8034 | /* |
| 8035 | * Use the normal group formation timeout between the end of |
| 8036 | * the provisioning phase and completion of 4-way handshake to |
| 8037 | * avoid terminating this process too early due to group idle |
| 8038 | * timeout. |
| 8039 | */ |
| 8040 | wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout " |
| 8041 | "while waiting for initial 4-way handshake to " |
| 8042 | "complete"); |
| 8043 | return; |
| 8044 | } |
| 8045 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8046 | wpa_printf(MSG_DEBUG, "P2P: Set P2P group idle timeout to %u seconds", |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8047 | timeout); |
| 8048 | eloop_register_timeout(timeout, 0, wpas_p2p_group_idle_timeout, |
| 8049 | wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8050 | } |
| 8051 | |
| 8052 | |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8053 | /* Returns 1 if the interface was removed */ |
| 8054 | int wpas_p2p_deauth_notif(struct wpa_supplicant *wpa_s, const u8 *bssid, |
| 8055 | u16 reason_code, const u8 *ie, size_t ie_len, |
| 8056 | int locally_generated) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8057 | { |
| 8058 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8059 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8060 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8061 | if (!locally_generated) |
| 8062 | p2p_deauth_notif(wpa_s->global->p2p, bssid, reason_code, ie, |
| 8063 | ie_len); |
| 8064 | |
| 8065 | if (reason_code == WLAN_REASON_DEAUTH_LEAVING && !locally_generated && |
| 8066 | wpa_s->current_ssid && |
| 8067 | wpa_s->current_ssid->p2p_group && |
| 8068 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA) { |
| 8069 | wpa_printf(MSG_DEBUG, "P2P: GO indicated that the P2P Group " |
| 8070 | "session is ending"); |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8071 | if (wpas_p2p_group_delete(wpa_s, |
| 8072 | P2P_GROUP_REMOVAL_GO_ENDING_SESSION) |
| 8073 | > 0) |
| 8074 | return 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8075 | } |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8076 | |
| 8077 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8078 | } |
| 8079 | |
| 8080 | |
| 8081 | void wpas_p2p_disassoc_notif(struct wpa_supplicant *wpa_s, const u8 *bssid, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8082 | u16 reason_code, const u8 *ie, size_t ie_len, |
| 8083 | int locally_generated) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8084 | { |
| 8085 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8086 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8087 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8088 | if (!locally_generated) |
| 8089 | p2p_disassoc_notif(wpa_s->global->p2p, bssid, reason_code, ie, |
| 8090 | ie_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8091 | } |
| 8092 | |
| 8093 | |
| 8094 | void wpas_p2p_update_config(struct wpa_supplicant *wpa_s) |
| 8095 | { |
| 8096 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 8097 | |
| 8098 | if (p2p == NULL) |
| 8099 | return; |
| 8100 | |
| 8101 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE)) |
| 8102 | return; |
| 8103 | |
| 8104 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_NAME) |
| 8105 | p2p_set_dev_name(p2p, wpa_s->conf->device_name); |
| 8106 | |
| 8107 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_TYPE) |
| 8108 | p2p_set_pri_dev_type(p2p, wpa_s->conf->device_type); |
| 8109 | |
| 8110 | if (wpa_s->wps && |
| 8111 | (wpa_s->conf->changed_parameters & CFG_CHANGED_CONFIG_METHODS)) |
| 8112 | p2p_set_config_methods(p2p, wpa_s->wps->config_methods); |
| 8113 | |
| 8114 | if (wpa_s->wps && (wpa_s->conf->changed_parameters & CFG_CHANGED_UUID)) |
| 8115 | p2p_set_uuid(p2p, wpa_s->wps->uuid); |
| 8116 | |
| 8117 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_WPS_STRING) { |
| 8118 | p2p_set_manufacturer(p2p, wpa_s->conf->manufacturer); |
| 8119 | p2p_set_model_name(p2p, wpa_s->conf->model_name); |
| 8120 | p2p_set_model_number(p2p, wpa_s->conf->model_number); |
| 8121 | p2p_set_serial_number(p2p, wpa_s->conf->serial_number); |
| 8122 | } |
| 8123 | |
| 8124 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_SEC_DEVICE_TYPE) |
| 8125 | p2p_set_sec_dev_types(p2p, |
| 8126 | (void *) wpa_s->conf->sec_device_type, |
| 8127 | wpa_s->conf->num_sec_device_types); |
| 8128 | |
| 8129 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_VENDOR_EXTENSION) { |
| 8130 | int i; |
| 8131 | p2p_remove_wps_vendor_extensions(p2p); |
| 8132 | for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) { |
| 8133 | if (wpa_s->conf->wps_vendor_ext[i] == NULL) |
| 8134 | continue; |
| 8135 | p2p_add_wps_vendor_extension( |
| 8136 | p2p, wpa_s->conf->wps_vendor_ext[i]); |
| 8137 | } |
| 8138 | } |
| 8139 | |
| 8140 | if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) && |
| 8141 | wpa_s->conf->country[0] && wpa_s->conf->country[1]) { |
| 8142 | char country[3]; |
| 8143 | country[0] = wpa_s->conf->country[0]; |
| 8144 | country[1] = wpa_s->conf->country[1]; |
| 8145 | country[2] = 0x04; |
| 8146 | p2p_set_country(p2p, country); |
| 8147 | } |
| 8148 | |
| 8149 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_SSID_POSTFIX) { |
| 8150 | p2p_set_ssid_postfix(p2p, (u8 *) wpa_s->conf->p2p_ssid_postfix, |
| 8151 | wpa_s->conf->p2p_ssid_postfix ? |
| 8152 | os_strlen(wpa_s->conf->p2p_ssid_postfix) : |
| 8153 | 0); |
| 8154 | } |
| 8155 | |
| 8156 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_INTRA_BSS) |
| 8157 | p2p_set_intra_bss_dist(p2p, wpa_s->conf->p2p_intra_bss); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8158 | |
| 8159 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_LISTEN_CHANNEL) { |
| 8160 | u8 reg_class, channel; |
| 8161 | int ret; |
| 8162 | unsigned int r; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8163 | u8 channel_forced; |
| 8164 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8165 | if (wpa_s->conf->p2p_listen_reg_class && |
| 8166 | wpa_s->conf->p2p_listen_channel) { |
| 8167 | reg_class = wpa_s->conf->p2p_listen_reg_class; |
| 8168 | channel = wpa_s->conf->p2p_listen_channel; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8169 | channel_forced = 1; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8170 | } else { |
| 8171 | reg_class = 81; |
| 8172 | /* |
| 8173 | * Pick one of the social channels randomly as the |
| 8174 | * listen channel. |
| 8175 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8176 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 8177 | channel = 1; |
| 8178 | else |
| 8179 | channel = 1 + (r % 3) * 5; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8180 | channel_forced = 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8181 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8182 | ret = p2p_set_listen_channel(p2p, reg_class, channel, |
| 8183 | channel_forced); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8184 | if (ret) |
| 8185 | wpa_printf(MSG_ERROR, "P2P: Own listen channel update " |
| 8186 | "failed: %d", ret); |
| 8187 | } |
| 8188 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_OPER_CHANNEL) { |
| 8189 | u8 op_reg_class, op_channel, cfg_op_channel; |
| 8190 | int ret = 0; |
| 8191 | unsigned int r; |
| 8192 | if (wpa_s->conf->p2p_oper_reg_class && |
| 8193 | wpa_s->conf->p2p_oper_channel) { |
| 8194 | op_reg_class = wpa_s->conf->p2p_oper_reg_class; |
| 8195 | op_channel = wpa_s->conf->p2p_oper_channel; |
| 8196 | cfg_op_channel = 1; |
| 8197 | } else { |
| 8198 | op_reg_class = 81; |
| 8199 | /* |
| 8200 | * Use random operation channel from (1, 6, 11) |
| 8201 | *if no other preference is indicated. |
| 8202 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8203 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 8204 | op_channel = 1; |
| 8205 | else |
| 8206 | op_channel = 1 + (r % 3) * 5; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8207 | cfg_op_channel = 0; |
| 8208 | } |
| 8209 | ret = p2p_set_oper_channel(p2p, op_reg_class, op_channel, |
| 8210 | cfg_op_channel); |
| 8211 | if (ret) |
| 8212 | wpa_printf(MSG_ERROR, "P2P: Own oper channel update " |
| 8213 | "failed: %d", ret); |
| 8214 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8215 | |
| 8216 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PREF_CHAN) { |
| 8217 | if (p2p_set_pref_chan(p2p, wpa_s->conf->num_p2p_pref_chan, |
| 8218 | wpa_s->conf->p2p_pref_chan) < 0) { |
| 8219 | wpa_printf(MSG_ERROR, "P2P: Preferred channel list " |
| 8220 | "update failed"); |
| 8221 | } |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8222 | |
| 8223 | if (p2p_set_no_go_freq(p2p, &wpa_s->conf->p2p_no_go_freq) < 0) { |
| 8224 | wpa_printf(MSG_ERROR, "P2P: No GO channel list " |
| 8225 | "update failed"); |
| 8226 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8227 | } |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 8228 | |
| 8229 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PASSPHRASE_LEN) |
| 8230 | p2p_set_passphrase_len(p2p, wpa_s->conf->p2p_passphrase_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8231 | } |
| 8232 | |
| 8233 | |
| 8234 | int wpas_p2p_set_noa(struct wpa_supplicant *wpa_s, u8 count, int start, |
| 8235 | int duration) |
| 8236 | { |
| 8237 | if (!wpa_s->ap_iface) |
| 8238 | return -1; |
| 8239 | return hostapd_p2p_set_noa(wpa_s->ap_iface->bss[0], count, start, |
| 8240 | duration); |
| 8241 | } |
| 8242 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8243 | |
| 8244 | int wpas_p2p_set_cross_connect(struct wpa_supplicant *wpa_s, int enabled) |
| 8245 | { |
| 8246 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8247 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8248 | |
| 8249 | wpa_s->global->cross_connection = enabled; |
| 8250 | p2p_set_cross_connect(wpa_s->global->p2p, enabled); |
| 8251 | |
| 8252 | if (!enabled) { |
| 8253 | struct wpa_supplicant *iface; |
| 8254 | |
| 8255 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) |
| 8256 | { |
| 8257 | if (iface->cross_connect_enabled == 0) |
| 8258 | continue; |
| 8259 | |
| 8260 | iface->cross_connect_enabled = 0; |
| 8261 | iface->cross_connect_in_use = 0; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8262 | wpa_msg_global(iface->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8263 | P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s", |
| 8264 | iface->ifname, |
| 8265 | iface->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8266 | } |
| 8267 | } |
| 8268 | |
| 8269 | return 0; |
| 8270 | } |
| 8271 | |
| 8272 | |
| 8273 | static void wpas_p2p_enable_cross_connect(struct wpa_supplicant *uplink) |
| 8274 | { |
| 8275 | struct wpa_supplicant *iface; |
| 8276 | |
| 8277 | if (!uplink->global->cross_connection) |
| 8278 | return; |
| 8279 | |
| 8280 | for (iface = uplink->global->ifaces; iface; iface = iface->next) { |
| 8281 | if (!iface->cross_connect_enabled) |
| 8282 | continue; |
| 8283 | if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) != |
| 8284 | 0) |
| 8285 | continue; |
| 8286 | if (iface->ap_iface == NULL) |
| 8287 | continue; |
| 8288 | if (iface->cross_connect_in_use) |
| 8289 | continue; |
| 8290 | |
| 8291 | iface->cross_connect_in_use = 1; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8292 | wpa_msg_global(iface->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8293 | P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s", |
| 8294 | iface->ifname, iface->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8295 | } |
| 8296 | } |
| 8297 | |
| 8298 | |
| 8299 | static void wpas_p2p_disable_cross_connect(struct wpa_supplicant *uplink) |
| 8300 | { |
| 8301 | struct wpa_supplicant *iface; |
| 8302 | |
| 8303 | for (iface = uplink->global->ifaces; iface; iface = iface->next) { |
| 8304 | if (!iface->cross_connect_enabled) |
| 8305 | continue; |
| 8306 | if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) != |
| 8307 | 0) |
| 8308 | continue; |
| 8309 | if (!iface->cross_connect_in_use) |
| 8310 | continue; |
| 8311 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8312 | wpa_msg_global(iface->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8313 | P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s", |
| 8314 | iface->ifname, iface->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8315 | iface->cross_connect_in_use = 0; |
| 8316 | } |
| 8317 | } |
| 8318 | |
| 8319 | |
| 8320 | void wpas_p2p_notif_connected(struct wpa_supplicant *wpa_s) |
| 8321 | { |
| 8322 | if (wpa_s->ap_iface || wpa_s->current_ssid == NULL || |
| 8323 | wpa_s->current_ssid->mode != WPAS_MODE_INFRA || |
| 8324 | wpa_s->cross_connect_disallowed) |
| 8325 | wpas_p2p_disable_cross_connect(wpa_s); |
| 8326 | else |
| 8327 | wpas_p2p_enable_cross_connect(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8328 | if (!wpa_s->ap_iface && |
| 8329 | eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0) |
| 8330 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8331 | } |
| 8332 | |
| 8333 | |
| 8334 | void wpas_p2p_notif_disconnected(struct wpa_supplicant *wpa_s) |
| 8335 | { |
| 8336 | wpas_p2p_disable_cross_connect(wpa_s); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8337 | if (!wpa_s->ap_iface && |
| 8338 | !eloop_is_timeout_registered(wpas_p2p_group_idle_timeout, |
| 8339 | wpa_s, NULL)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8340 | wpas_p2p_set_group_idle_timeout(wpa_s); |
| 8341 | } |
| 8342 | |
| 8343 | |
| 8344 | static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s) |
| 8345 | { |
| 8346 | struct wpa_supplicant *iface; |
| 8347 | |
| 8348 | if (!wpa_s->global->cross_connection) |
| 8349 | return; |
| 8350 | |
| 8351 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 8352 | if (iface == wpa_s) |
| 8353 | continue; |
| 8354 | if (iface->drv_flags & |
| 8355 | WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE) |
| 8356 | continue; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8357 | if ((iface->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) && |
| 8358 | iface != wpa_s->parent) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8359 | continue; |
| 8360 | |
| 8361 | wpa_s->cross_connect_enabled = 1; |
| 8362 | os_strlcpy(wpa_s->cross_connect_uplink, iface->ifname, |
| 8363 | sizeof(wpa_s->cross_connect_uplink)); |
| 8364 | wpa_printf(MSG_DEBUG, "P2P: Enable cross connection from " |
| 8365 | "%s to %s whenever uplink is available", |
| 8366 | wpa_s->ifname, wpa_s->cross_connect_uplink); |
| 8367 | |
| 8368 | if (iface->ap_iface || iface->current_ssid == NULL || |
| 8369 | iface->current_ssid->mode != WPAS_MODE_INFRA || |
| 8370 | iface->cross_connect_disallowed || |
| 8371 | iface->wpa_state != WPA_COMPLETED) |
| 8372 | break; |
| 8373 | |
| 8374 | wpa_s->cross_connect_in_use = 1; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8375 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8376 | P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s", |
| 8377 | wpa_s->ifname, wpa_s->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8378 | break; |
| 8379 | } |
| 8380 | } |
| 8381 | |
| 8382 | |
| 8383 | int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant *wpa_s) |
| 8384 | { |
| 8385 | if (wpa_s->p2p_group_interface != P2P_GROUP_INTERFACE_CLIENT && |
| 8386 | !wpa_s->p2p_in_provisioning) |
| 8387 | return 0; /* not P2P client operation */ |
| 8388 | |
| 8389 | wpa_printf(MSG_DEBUG, "P2P: Terminate connection due to WPS PBC " |
| 8390 | "session overlap"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8391 | if (wpa_s != wpa_s->p2pdev) |
| 8392 | wpa_msg_ctrl(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_OVERLAP); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8393 | wpas_p2p_group_formation_failed(wpa_s, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8394 | return 1; |
| 8395 | } |
| 8396 | |
| 8397 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8398 | void wpas_p2p_pbc_overlap_cb(void *eloop_ctx, void *timeout_ctx) |
| 8399 | { |
| 8400 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 8401 | wpas_p2p_notif_pbc_overlap(wpa_s); |
| 8402 | } |
| 8403 | |
| 8404 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8405 | void wpas_p2p_update_channel_list(struct wpa_supplicant *wpa_s, |
| 8406 | enum wpas_p2p_channel_update_trig trig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8407 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8408 | struct p2p_channels chan, cli_chan; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8409 | struct wpa_used_freq_data *freqs = NULL; |
| 8410 | unsigned int num = wpa_s->num_multichan_concurrent; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8411 | |
| 8412 | if (wpa_s->global == NULL || wpa_s->global->p2p == NULL) |
| 8413 | return; |
| 8414 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8415 | freqs = os_calloc(num, sizeof(struct wpa_used_freq_data)); |
| 8416 | if (!freqs) |
| 8417 | return; |
| 8418 | |
| 8419 | num = get_shared_radio_freqs_data(wpa_s, freqs, num); |
| 8420 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8421 | os_memset(&chan, 0, sizeof(chan)); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8422 | os_memset(&cli_chan, 0, sizeof(cli_chan)); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8423 | if (wpas_p2p_setup_channels(wpa_s, &chan, &cli_chan, |
| 8424 | is_p2p_6ghz_disabled(wpa_s->global->p2p))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8425 | wpa_printf(MSG_ERROR, "P2P: Failed to update supported " |
| 8426 | "channel list"); |
| 8427 | return; |
| 8428 | } |
| 8429 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8430 | p2p_update_channel_list(wpa_s->global->p2p, &chan, &cli_chan); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 8431 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8432 | wpas_p2p_optimize_listen_channel(wpa_s, freqs, num); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 8433 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8434 | /* |
| 8435 | * The used frequencies map changed, so it is possible that a GO is |
| 8436 | * using a channel that is no longer valid for P2P use. It is also |
| 8437 | * possible that due to policy consideration, it would be preferable to |
| 8438 | * move it to a frequency already used by other station interfaces. |
| 8439 | */ |
| 8440 | wpas_p2p_consider_moving_gos(wpa_s, freqs, num, trig); |
| 8441 | |
| 8442 | os_free(freqs); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8443 | } |
| 8444 | |
| 8445 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8446 | static void wpas_p2p_scan_res_ignore(struct wpa_supplicant *wpa_s, |
| 8447 | struct wpa_scan_results *scan_res) |
| 8448 | { |
| 8449 | wpa_printf(MSG_DEBUG, "P2P: Ignore scan results"); |
| 8450 | } |
| 8451 | |
| 8452 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8453 | int wpas_p2p_cancel(struct wpa_supplicant *wpa_s) |
| 8454 | { |
| 8455 | struct wpa_global *global = wpa_s->global; |
| 8456 | int found = 0; |
| 8457 | const u8 *peer; |
| 8458 | |
| 8459 | if (global->p2p == NULL) |
| 8460 | return -1; |
| 8461 | |
| 8462 | wpa_printf(MSG_DEBUG, "P2P: Request to cancel group formation"); |
| 8463 | |
| 8464 | if (wpa_s->pending_interface_name[0] && |
| 8465 | !is_zero_ether_addr(wpa_s->pending_interface_addr)) |
| 8466 | found = 1; |
| 8467 | |
| 8468 | peer = p2p_get_go_neg_peer(global->p2p); |
| 8469 | if (peer) { |
| 8470 | wpa_printf(MSG_DEBUG, "P2P: Unauthorize pending GO Neg peer " |
| 8471 | MACSTR, MAC2STR(peer)); |
| 8472 | p2p_unauthorize(global->p2p, peer); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8473 | found = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8474 | } |
| 8475 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8476 | if (wpa_s->scan_res_handler == wpas_p2p_scan_res_join) { |
| 8477 | wpa_printf(MSG_DEBUG, "P2P: Stop pending scan for join"); |
| 8478 | wpa_s->scan_res_handler = wpas_p2p_scan_res_ignore; |
| 8479 | found = 1; |
| 8480 | } |
| 8481 | |
| 8482 | if (wpa_s->pending_pd_before_join) { |
| 8483 | wpa_printf(MSG_DEBUG, "P2P: Stop pending PD before join"); |
| 8484 | wpa_s->pending_pd_before_join = 0; |
| 8485 | found = 1; |
| 8486 | } |
| 8487 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8488 | wpas_p2p_stop_find(wpa_s); |
| 8489 | |
| 8490 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 8491 | if (wpa_s == global->p2p_group_formation && |
| 8492 | (wpa_s->p2p_in_provisioning || |
| 8493 | wpa_s->parent->pending_interface_type == |
| 8494 | WPA_IF_P2P_CLIENT)) { |
| 8495 | wpa_printf(MSG_DEBUG, "P2P: Interface %s in group " |
| 8496 | "formation found - cancelling", |
| 8497 | wpa_s->ifname); |
| 8498 | found = 1; |
| 8499 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8500 | wpa_s->p2pdev, NULL); |
Jouni Malinen | adddfc4 | 2012-10-03 14:31:41 -0700 | [diff] [blame] | 8501 | if (wpa_s->p2p_in_provisioning) { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8502 | wpas_group_formation_completed(wpa_s, 0, 0); |
Jouni Malinen | adddfc4 | 2012-10-03 14:31:41 -0700 | [diff] [blame] | 8503 | break; |
| 8504 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8505 | wpas_p2p_group_delete(wpa_s, |
| 8506 | P2P_GROUP_REMOVAL_REQUESTED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8507 | break; |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 8508 | } else if (wpa_s->p2p_in_invitation) { |
| 8509 | wpa_printf(MSG_DEBUG, "P2P: Interface %s in invitation found - cancelling", |
| 8510 | wpa_s->ifname); |
| 8511 | found = 1; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8512 | wpas_p2p_group_formation_failed(wpa_s, 0); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8513 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8514 | } |
| 8515 | } |
| 8516 | |
| 8517 | if (!found) { |
| 8518 | wpa_printf(MSG_DEBUG, "P2P: No ongoing group formation found"); |
| 8519 | return -1; |
| 8520 | } |
| 8521 | |
| 8522 | return 0; |
| 8523 | } |
| 8524 | |
| 8525 | |
| 8526 | void wpas_p2p_interface_unavailable(struct wpa_supplicant *wpa_s) |
| 8527 | { |
| 8528 | if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group) |
| 8529 | return; |
| 8530 | |
| 8531 | wpa_printf(MSG_DEBUG, "P2P: Remove group due to driver resource not " |
| 8532 | "being available anymore"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8533 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_UNAVAILABLE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8534 | } |
| 8535 | |
| 8536 | |
| 8537 | void wpas_p2p_update_best_channels(struct wpa_supplicant *wpa_s, |
| 8538 | int freq_24, int freq_5, int freq_overall) |
| 8539 | { |
| 8540 | struct p2p_data *p2p = wpa_s->global->p2p; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8541 | if (p2p == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8542 | return; |
| 8543 | p2p_set_best_channels(p2p, freq_24, freq_5, freq_overall); |
| 8544 | } |
| 8545 | |
| 8546 | |
| 8547 | int wpas_p2p_unauthorize(struct wpa_supplicant *wpa_s, const char *addr) |
| 8548 | { |
| 8549 | u8 peer[ETH_ALEN]; |
| 8550 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 8551 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8552 | if (p2p == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8553 | return -1; |
| 8554 | |
| 8555 | if (hwaddr_aton(addr, peer)) |
| 8556 | return -1; |
| 8557 | |
| 8558 | return p2p_unauthorize(p2p, peer); |
| 8559 | } |
| 8560 | |
| 8561 | |
| 8562 | /** |
| 8563 | * wpas_p2p_disconnect - Disconnect from a P2P Group |
| 8564 | * @wpa_s: Pointer to wpa_supplicant data |
| 8565 | * Returns: 0 on success, -1 on failure |
| 8566 | * |
| 8567 | * This can be used to disconnect from a group in which the local end is a P2P |
| 8568 | * Client or to end a P2P Group in case the local end is the Group Owner. If a |
| 8569 | * virtual network interface was created for this group, that interface will be |
| 8570 | * removed. Otherwise, only the configured P2P group network will be removed |
| 8571 | * from the interface. |
| 8572 | */ |
| 8573 | int wpas_p2p_disconnect(struct wpa_supplicant *wpa_s) |
| 8574 | { |
| 8575 | |
| 8576 | if (wpa_s == NULL) |
| 8577 | return -1; |
| 8578 | |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8579 | return wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_REQUESTED) < 0 ? |
| 8580 | -1 : 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8581 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8582 | |
| 8583 | |
| 8584 | int wpas_p2p_in_progress(struct wpa_supplicant *wpa_s) |
| 8585 | { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8586 | int ret; |
| 8587 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8588 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8589 | return 0; |
| 8590 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8591 | ret = p2p_in_progress(wpa_s->global->p2p); |
| 8592 | if (ret == 0) { |
| 8593 | /* |
| 8594 | * Check whether there is an ongoing WPS provisioning step (or |
| 8595 | * other parts of group formation) on another interface since |
| 8596 | * p2p_in_progress() does not report this to avoid issues for |
| 8597 | * scans during such provisioning step. |
| 8598 | */ |
| 8599 | if (wpa_s->global->p2p_group_formation && |
| 8600 | wpa_s->global->p2p_group_formation != wpa_s) { |
| 8601 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Another interface (%s) " |
| 8602 | "in group formation", |
| 8603 | wpa_s->global->p2p_group_formation->ifname); |
| 8604 | ret = 1; |
| 8605 | } |
| 8606 | } |
| 8607 | |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 8608 | if (!ret && wpa_s->global->p2p_go_wait_client.sec) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8609 | struct os_reltime now; |
| 8610 | os_get_reltime(&now); |
| 8611 | if (os_reltime_expired(&now, &wpa_s->global->p2p_go_wait_client, |
| 8612 | P2P_MAX_INITIAL_CONN_WAIT_GO)) { |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 8613 | /* Wait for the first client has expired */ |
| 8614 | wpa_s->global->p2p_go_wait_client.sec = 0; |
| 8615 | } else { |
| 8616 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Waiting for initial client connection during group formation"); |
| 8617 | ret = 1; |
| 8618 | } |
| 8619 | } |
| 8620 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8621 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8622 | } |
| 8623 | |
| 8624 | |
| 8625 | void wpas_p2p_network_removed(struct wpa_supplicant *wpa_s, |
| 8626 | struct wpa_ssid *ssid) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8627 | { |
| 8628 | if (wpa_s->p2p_in_provisioning && ssid->p2p_group && |
| 8629 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8630 | wpa_s->p2pdev, NULL) > 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8631 | /** |
| 8632 | * Remove the network by scheduling the group formation |
| 8633 | * timeout to happen immediately. The teardown code |
| 8634 | * needs to be scheduled to run asynch later so that we |
| 8635 | * don't delete data from under ourselves unexpectedly. |
| 8636 | * Calling wpas_p2p_group_formation_timeout directly |
| 8637 | * causes a series of crashes in WPS failure scenarios. |
| 8638 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8639 | wpa_printf(MSG_DEBUG, "P2P: Canceled group formation due to " |
| 8640 | "P2P group network getting removed"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8641 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8642 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8643 | } |
| 8644 | } |
| 8645 | |
| 8646 | |
| 8647 | struct wpa_ssid * wpas_p2p_get_persistent(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8648 | const u8 *addr, const u8 *ssid, |
| 8649 | size_t ssid_len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8650 | { |
| 8651 | struct wpa_ssid *s; |
| 8652 | size_t i; |
| 8653 | |
| 8654 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 8655 | if (s->disabled != 2) |
| 8656 | continue; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8657 | if (ssid && |
| 8658 | (ssid_len != s->ssid_len || |
| 8659 | os_memcmp(ssid, s->ssid, ssid_len) != 0)) |
| 8660 | continue; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8661 | if (addr == NULL) { |
| 8662 | if (s->mode == WPAS_MODE_P2P_GO) |
| 8663 | return s; |
| 8664 | continue; |
| 8665 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8666 | if (os_memcmp(s->bssid, addr, ETH_ALEN) == 0) |
| 8667 | return s; /* peer is GO in the persistent group */ |
| 8668 | if (s->mode != WPAS_MODE_P2P_GO || s->p2p_client_list == NULL) |
| 8669 | continue; |
| 8670 | for (i = 0; i < s->num_p2p_clients; i++) { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8671 | if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8672 | addr, ETH_ALEN) == 0) |
| 8673 | return s; /* peer is P2P client in persistent |
| 8674 | * group */ |
| 8675 | } |
| 8676 | } |
| 8677 | |
| 8678 | return NULL; |
| 8679 | } |
| 8680 | |
| 8681 | |
| 8682 | void wpas_p2p_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s, |
| 8683 | const u8 *addr) |
| 8684 | { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8685 | if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8686 | wpa_s->p2pdev, NULL) > 0) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8687 | /* |
| 8688 | * This can happen if WPS provisioning step is not terminated |
| 8689 | * cleanly (e.g., P2P Client does not send WSC_Done). Since the |
| 8690 | * peer was able to connect, there is no need to time out group |
| 8691 | * formation after this, though. In addition, this is used with |
| 8692 | * the initial connection wait on the GO as a separate formation |
| 8693 | * timeout and as such, expected to be hit after the initial WPS |
| 8694 | * provisioning step. |
| 8695 | */ |
| 8696 | wpa_printf(MSG_DEBUG, "P2P: Canceled P2P group formation timeout on data connection"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8697 | |
| 8698 | if (!wpa_s->p2p_go_group_formation_completed && |
| 8699 | !wpa_s->group_formation_reported) { |
| 8700 | /* |
| 8701 | * GO has not yet notified group formation success since |
| 8702 | * the WPS step was not completed cleanly. Do that |
| 8703 | * notification now since the P2P Client was able to |
| 8704 | * connect and as such, must have received the |
| 8705 | * credential from the WPS step. |
| 8706 | */ |
| 8707 | if (wpa_s->global->p2p) |
| 8708 | p2p_wps_success_cb(wpa_s->global->p2p, addr); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8709 | wpas_group_formation_completed(wpa_s, 1, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8710 | } |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8711 | } |
| 8712 | if (!wpa_s->p2p_go_group_formation_completed) { |
| 8713 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Marking group formation completed on GO on first data connection"); |
| 8714 | wpa_s->p2p_go_group_formation_completed = 1; |
| 8715 | wpa_s->global->p2p_group_formation = NULL; |
| 8716 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 8717 | wpa_s->p2p_in_invitation = 0; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame^] | 8718 | wpa_s->p2p_retry_limit = 0; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8719 | } |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 8720 | wpa_s->global->p2p_go_wait_client.sec = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8721 | if (addr == NULL) |
| 8722 | return; |
| 8723 | wpas_p2p_add_persistent_group_client(wpa_s, addr); |
| 8724 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8725 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8726 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8727 | static int wpas_p2p_fallback_to_go_neg(struct wpa_supplicant *wpa_s, |
| 8728 | int group_added) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8729 | { |
| 8730 | struct wpa_supplicant *group = wpa_s; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8731 | int ret = 0; |
| 8732 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8733 | if (wpa_s->global->p2p_group_formation) |
| 8734 | group = wpa_s->global->p2p_group_formation; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8735 | wpa_s = wpa_s->global->p2p_init_wpa_s; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8736 | offchannel_send_action_done(wpa_s); |
| 8737 | if (group_added) |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8738 | ret = wpas_p2p_group_delete(group, P2P_GROUP_REMOVAL_SILENT); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8739 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Fall back to GO Negotiation"); |
| 8740 | wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr, wpa_s->p2p_pin, |
| 8741 | wpa_s->p2p_wps_method, wpa_s->p2p_persistent_group, 0, |
| 8742 | 0, 0, wpa_s->p2p_go_intent, wpa_s->p2p_connect_freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8743 | wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8744 | wpa_s->p2p_persistent_id, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8745 | wpa_s->p2p_pd_before_go_neg, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8746 | wpa_s->p2p_go_ht40, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8747 | wpa_s->p2p_go_vht, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8748 | wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8749 | wpa_s->p2p_go_he, |
| 8750 | wpa_s->p2p_go_edmg, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 8751 | NULL, 0, is_p2p_allow_6ghz(wpa_s->global->p2p)); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8752 | return ret; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8753 | } |
| 8754 | |
| 8755 | |
| 8756 | int wpas_p2p_scan_no_go_seen(struct wpa_supplicant *wpa_s) |
| 8757 | { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8758 | int res; |
| 8759 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8760 | if (!wpa_s->p2p_fallback_to_go_neg || |
| 8761 | wpa_s->p2p_in_provisioning <= 5) |
| 8762 | return 0; |
| 8763 | |
| 8764 | if (wpas_p2p_peer_go(wpa_s, wpa_s->pending_join_dev_addr) > 0) |
| 8765 | return 0; /* peer operating as a GO */ |
| 8766 | |
| 8767 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: GO not found for p2p_connect-auto - " |
| 8768 | "fallback to GO Negotiation"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8769 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, P2P_EVENT_FALLBACK_TO_GO_NEG |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8770 | "reason=GO-not-found"); |
| 8771 | res = wpas_p2p_fallback_to_go_neg(wpa_s, 1); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8772 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8773 | return res == 1 ? 2 : 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8774 | } |
| 8775 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8776 | |
| 8777 | unsigned int wpas_p2p_search_delay(struct wpa_supplicant *wpa_s) |
| 8778 | { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8779 | struct wpa_supplicant *ifs; |
| 8780 | |
| 8781 | if (wpa_s->wpa_state > WPA_SCANNING) { |
| 8782 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search delay due to " |
| 8783 | "concurrent operation", |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 8784 | wpa_s->conf->p2p_search_delay); |
| 8785 | return wpa_s->conf->p2p_search_delay; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8786 | } |
| 8787 | |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 8788 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 8789 | radio_list) { |
| 8790 | if (ifs != wpa_s && ifs->wpa_state > WPA_SCANNING) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8791 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search " |
| 8792 | "delay due to concurrent operation on " |
| 8793 | "interface %s", |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 8794 | wpa_s->conf->p2p_search_delay, |
| 8795 | ifs->ifname); |
| 8796 | return wpa_s->conf->p2p_search_delay; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8797 | } |
| 8798 | } |
| 8799 | |
| 8800 | return 0; |
| 8801 | } |
| 8802 | |
Dmitry Shmidt | 37d4d6a | 2013-03-18 13:09:42 -0700 | [diff] [blame] | 8803 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8804 | static int wpas_p2p_remove_psk_entry(struct wpa_supplicant *wpa_s, |
| 8805 | struct wpa_ssid *s, const u8 *addr, |
| 8806 | int iface_addr) |
| 8807 | { |
| 8808 | struct psk_list_entry *psk, *tmp; |
| 8809 | int changed = 0; |
| 8810 | |
| 8811 | dl_list_for_each_safe(psk, tmp, &s->psk_list, struct psk_list_entry, |
| 8812 | list) { |
| 8813 | if ((iface_addr && !psk->p2p && |
| 8814 | os_memcmp(addr, psk->addr, ETH_ALEN) == 0) || |
| 8815 | (!iface_addr && psk->p2p && |
| 8816 | os_memcmp(addr, psk->addr, ETH_ALEN) == 0)) { |
| 8817 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 8818 | "P2P: Remove persistent group PSK list entry for " |
| 8819 | MACSTR " p2p=%u", |
| 8820 | MAC2STR(psk->addr), psk->p2p); |
| 8821 | dl_list_del(&psk->list); |
| 8822 | os_free(psk); |
| 8823 | changed++; |
| 8824 | } |
| 8825 | } |
| 8826 | |
| 8827 | return changed; |
| 8828 | } |
| 8829 | |
| 8830 | |
| 8831 | void wpas_p2p_new_psk_cb(struct wpa_supplicant *wpa_s, const u8 *mac_addr, |
| 8832 | const u8 *p2p_dev_addr, |
| 8833 | const u8 *psk, size_t psk_len) |
| 8834 | { |
| 8835 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 8836 | struct wpa_ssid *persistent; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 8837 | struct psk_list_entry *p, *last; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8838 | |
| 8839 | if (psk_len != sizeof(p->psk)) |
| 8840 | return; |
| 8841 | |
| 8842 | if (p2p_dev_addr) { |
| 8843 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New PSK for addr=" MACSTR |
| 8844 | " p2p_dev_addr=" MACSTR, |
| 8845 | MAC2STR(mac_addr), MAC2STR(p2p_dev_addr)); |
| 8846 | if (is_zero_ether_addr(p2p_dev_addr)) |
| 8847 | p2p_dev_addr = NULL; |
| 8848 | } else { |
| 8849 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New PSK for addr=" MACSTR, |
| 8850 | MAC2STR(mac_addr)); |
| 8851 | } |
| 8852 | |
| 8853 | if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) { |
| 8854 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: new_psk_cb during group formation"); |
| 8855 | /* To be added to persistent group once created */ |
| 8856 | if (wpa_s->global->add_psk == NULL) { |
| 8857 | wpa_s->global->add_psk = os_zalloc(sizeof(*p)); |
| 8858 | if (wpa_s->global->add_psk == NULL) |
| 8859 | return; |
| 8860 | } |
| 8861 | p = wpa_s->global->add_psk; |
| 8862 | if (p2p_dev_addr) { |
| 8863 | p->p2p = 1; |
| 8864 | os_memcpy(p->addr, p2p_dev_addr, ETH_ALEN); |
| 8865 | } else { |
| 8866 | p->p2p = 0; |
| 8867 | os_memcpy(p->addr, mac_addr, ETH_ALEN); |
| 8868 | } |
| 8869 | os_memcpy(p->psk, psk, psk_len); |
| 8870 | return; |
| 8871 | } |
| 8872 | |
| 8873 | if (ssid->mode != WPAS_MODE_P2P_GO || !ssid->p2p_persistent_group) { |
| 8874 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Ignore new_psk_cb on not-persistent GO"); |
| 8875 | return; |
| 8876 | } |
| 8877 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8878 | persistent = wpas_p2p_get_persistent(wpa_s->p2pdev, NULL, ssid->ssid, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8879 | ssid->ssid_len); |
| 8880 | if (!persistent) { |
| 8881 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not find persistent group information to store the new PSK"); |
| 8882 | return; |
| 8883 | } |
| 8884 | |
| 8885 | p = os_zalloc(sizeof(*p)); |
| 8886 | if (p == NULL) |
| 8887 | return; |
| 8888 | if (p2p_dev_addr) { |
| 8889 | p->p2p = 1; |
| 8890 | os_memcpy(p->addr, p2p_dev_addr, ETH_ALEN); |
| 8891 | } else { |
| 8892 | p->p2p = 0; |
| 8893 | os_memcpy(p->addr, mac_addr, ETH_ALEN); |
| 8894 | } |
| 8895 | os_memcpy(p->psk, psk, psk_len); |
| 8896 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 8897 | if (dl_list_len(&persistent->psk_list) > P2P_MAX_STORED_CLIENTS && |
| 8898 | (last = dl_list_last(&persistent->psk_list, |
| 8899 | struct psk_list_entry, list))) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8900 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove oldest PSK entry for " |
| 8901 | MACSTR " (p2p=%u) to make room for a new one", |
| 8902 | MAC2STR(last->addr), last->p2p); |
| 8903 | dl_list_del(&last->list); |
| 8904 | os_free(last); |
| 8905 | } |
| 8906 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8907 | wpas_p2p_remove_psk_entry(wpa_s->p2pdev, persistent, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8908 | p2p_dev_addr ? p2p_dev_addr : mac_addr, |
| 8909 | p2p_dev_addr == NULL); |
| 8910 | if (p2p_dev_addr) { |
| 8911 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for p2p_dev_addr=" |
| 8912 | MACSTR, MAC2STR(p2p_dev_addr)); |
| 8913 | } else { |
| 8914 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for addr=" MACSTR, |
| 8915 | MAC2STR(mac_addr)); |
| 8916 | } |
| 8917 | dl_list_add(&persistent->psk_list, &p->list); |
| 8918 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8919 | if (wpa_s->p2pdev->conf->update_config && |
| 8920 | wpa_config_write(wpa_s->p2pdev->confname, wpa_s->p2pdev->conf)) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8921 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8922 | } |
| 8923 | |
| 8924 | |
| 8925 | static void wpas_p2p_remove_psk(struct wpa_supplicant *wpa_s, |
| 8926 | struct wpa_ssid *s, const u8 *addr, |
| 8927 | int iface_addr) |
| 8928 | { |
| 8929 | int res; |
| 8930 | |
| 8931 | res = wpas_p2p_remove_psk_entry(wpa_s, s, addr, iface_addr); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 8932 | if (res > 0 && wpa_s->conf->update_config && |
| 8933 | wpa_config_write(wpa_s->confname, wpa_s->conf)) |
| 8934 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 8935 | "P2P: Failed to update configuration"); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8936 | } |
| 8937 | |
| 8938 | |
| 8939 | static void wpas_p2p_remove_client_go(struct wpa_supplicant *wpa_s, |
| 8940 | const u8 *peer, int iface_addr) |
| 8941 | { |
| 8942 | struct hostapd_data *hapd; |
| 8943 | struct hostapd_wpa_psk *psk, *prev, *rem; |
| 8944 | struct sta_info *sta; |
| 8945 | |
| 8946 | if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL || |
| 8947 | wpa_s->current_ssid->mode != WPAS_MODE_P2P_GO) |
| 8948 | return; |
| 8949 | |
| 8950 | /* Remove per-station PSK entry */ |
| 8951 | hapd = wpa_s->ap_iface->bss[0]; |
| 8952 | prev = NULL; |
| 8953 | psk = hapd->conf->ssid.wpa_psk; |
| 8954 | while (psk) { |
| 8955 | if ((iface_addr && os_memcmp(peer, psk->addr, ETH_ALEN) == 0) || |
| 8956 | (!iface_addr && |
| 8957 | os_memcmp(peer, psk->p2p_dev_addr, ETH_ALEN) == 0)) { |
| 8958 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove operating group PSK entry for " |
| 8959 | MACSTR " iface_addr=%d", |
| 8960 | MAC2STR(peer), iface_addr); |
| 8961 | if (prev) |
| 8962 | prev->next = psk->next; |
| 8963 | else |
| 8964 | hapd->conf->ssid.wpa_psk = psk->next; |
| 8965 | rem = psk; |
| 8966 | psk = psk->next; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 8967 | bin_clear_free(rem, sizeof(*rem)); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8968 | } else { |
| 8969 | prev = psk; |
| 8970 | psk = psk->next; |
| 8971 | } |
| 8972 | } |
| 8973 | |
| 8974 | /* Disconnect from group */ |
| 8975 | if (iface_addr) |
| 8976 | sta = ap_get_sta(hapd, peer); |
| 8977 | else |
| 8978 | sta = ap_get_sta_p2p(hapd, peer); |
| 8979 | if (sta) { |
| 8980 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disconnect peer " MACSTR |
| 8981 | " (iface_addr=%d) from group", |
| 8982 | MAC2STR(peer), iface_addr); |
| 8983 | hostapd_drv_sta_deauth(hapd, sta->addr, |
| 8984 | WLAN_REASON_DEAUTH_LEAVING); |
| 8985 | ap_sta_deauthenticate(hapd, sta, WLAN_REASON_DEAUTH_LEAVING); |
| 8986 | } |
| 8987 | } |
| 8988 | |
| 8989 | |
| 8990 | void wpas_p2p_remove_client(struct wpa_supplicant *wpa_s, const u8 *peer, |
| 8991 | int iface_addr) |
| 8992 | { |
| 8993 | struct wpa_ssid *s; |
| 8994 | struct wpa_supplicant *w; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 8995 | struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8996 | |
| 8997 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove client " MACSTR, MAC2STR(peer)); |
| 8998 | |
| 8999 | /* Remove from any persistent group */ |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 9000 | for (s = p2p_wpa_s->conf->ssid; s; s = s->next) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9001 | if (s->disabled != 2 || s->mode != WPAS_MODE_P2P_GO) |
| 9002 | continue; |
| 9003 | if (!iface_addr) |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 9004 | wpas_remove_persistent_peer(p2p_wpa_s, s, peer, 0); |
| 9005 | wpas_p2p_remove_psk(p2p_wpa_s, s, peer, iface_addr); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9006 | } |
| 9007 | |
| 9008 | /* Remove from any operating group */ |
| 9009 | for (w = wpa_s->global->ifaces; w; w = w->next) |
| 9010 | wpas_p2p_remove_client_go(w, peer, iface_addr); |
| 9011 | } |
| 9012 | |
| 9013 | |
| 9014 | static void wpas_p2p_psk_failure_removal(void *eloop_ctx, void *timeout_ctx) |
| 9015 | { |
| 9016 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 9017 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_PSK_FAILURE); |
| 9018 | } |
| 9019 | |
| 9020 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 9021 | static void wpas_p2p_group_freq_conflict(void *eloop_ctx, void *timeout_ctx) |
| 9022 | { |
| 9023 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 9024 | |
| 9025 | wpa_printf(MSG_DEBUG, "P2P: Frequency conflict - terminate group"); |
| 9026 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_FREQ_CONFLICT); |
| 9027 | } |
| 9028 | |
| 9029 | |
| 9030 | int wpas_p2p_handle_frequency_conflicts(struct wpa_supplicant *wpa_s, int freq, |
| 9031 | struct wpa_ssid *ssid) |
| 9032 | { |
| 9033 | struct wpa_supplicant *iface; |
| 9034 | |
| 9035 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 9036 | if (!iface->current_ssid || |
| 9037 | iface->current_ssid->frequency == freq || |
| 9038 | (iface->p2p_group_interface == NOT_P2P_GROUP_INTERFACE && |
| 9039 | !iface->current_ssid->p2p_group)) |
| 9040 | continue; |
| 9041 | |
| 9042 | /* Remove the connection with least priority */ |
| 9043 | if (!wpas_is_p2p_prioritized(iface)) { |
| 9044 | /* STA connection has priority over existing |
| 9045 | * P2P connection, so remove the interface. */ |
| 9046 | wpa_printf(MSG_DEBUG, "P2P: Removing P2P connection due to single channel concurrent mode frequency conflict"); |
| 9047 | eloop_register_timeout(0, 0, |
| 9048 | wpas_p2p_group_freq_conflict, |
| 9049 | iface, NULL); |
| 9050 | /* If connection in progress is P2P connection, do not |
| 9051 | * proceed for the connection. */ |
| 9052 | if (wpa_s == iface) |
| 9053 | return -1; |
| 9054 | else |
| 9055 | return 0; |
| 9056 | } else { |
| 9057 | /* P2P connection has priority, disable the STA network |
| 9058 | */ |
| 9059 | wpa_supplicant_disable_network(wpa_s->global->ifaces, |
| 9060 | ssid); |
| 9061 | wpa_msg(wpa_s->global->ifaces, MSG_INFO, |
| 9062 | WPA_EVENT_FREQ_CONFLICT " id=%d", ssid->id); |
| 9063 | os_memset(wpa_s->global->ifaces->pending_bssid, 0, |
| 9064 | ETH_ALEN); |
| 9065 | /* If P2P connection is in progress, continue |
| 9066 | * connecting...*/ |
| 9067 | if (wpa_s == iface) |
| 9068 | return 0; |
| 9069 | else |
| 9070 | return -1; |
| 9071 | } |
| 9072 | } |
| 9073 | |
| 9074 | return 0; |
| 9075 | } |
| 9076 | |
| 9077 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9078 | int wpas_p2p_4way_hs_failed(struct wpa_supplicant *wpa_s) |
| 9079 | { |
| 9080 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 9081 | |
| 9082 | if (ssid == NULL || !ssid->p2p_group) |
| 9083 | return 0; |
| 9084 | |
| 9085 | if (wpa_s->p2p_last_4way_hs_fail && |
| 9086 | wpa_s->p2p_last_4way_hs_fail == ssid) { |
| 9087 | u8 go_dev_addr[ETH_ALEN]; |
| 9088 | struct wpa_ssid *persistent; |
| 9089 | |
| 9090 | if (wpas_p2p_persistent_group(wpa_s, go_dev_addr, |
| 9091 | ssid->ssid, |
| 9092 | ssid->ssid_len) <= 0) { |
| 9093 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not determine whether 4-way handshake failures were for a persistent group"); |
| 9094 | goto disconnect; |
| 9095 | } |
| 9096 | |
| 9097 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Two 4-way handshake failures for a P2P group - go_dev_addr=" |
| 9098 | MACSTR, MAC2STR(go_dev_addr)); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9099 | persistent = wpas_p2p_get_persistent(wpa_s->p2pdev, go_dev_addr, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9100 | ssid->ssid, |
| 9101 | ssid->ssid_len); |
| 9102 | if (persistent == NULL || persistent->mode != WPAS_MODE_INFRA) { |
| 9103 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No matching persistent group stored"); |
| 9104 | goto disconnect; |
| 9105 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9106 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9107 | P2P_EVENT_PERSISTENT_PSK_FAIL "%d", |
| 9108 | persistent->id); |
| 9109 | disconnect: |
| 9110 | wpa_s->p2p_last_4way_hs_fail = NULL; |
| 9111 | /* |
| 9112 | * Remove the group from a timeout to avoid issues with caller |
| 9113 | * continuing to use the interface if this is on a P2P group |
| 9114 | * interface. |
| 9115 | */ |
| 9116 | eloop_register_timeout(0, 0, wpas_p2p_psk_failure_removal, |
| 9117 | wpa_s, NULL); |
| 9118 | return 1; |
| 9119 | } |
| 9120 | |
| 9121 | wpa_s->p2p_last_4way_hs_fail = ssid; |
| 9122 | return 0; |
| 9123 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9124 | |
| 9125 | |
| 9126 | #ifdef CONFIG_WPS_NFC |
| 9127 | |
| 9128 | static struct wpabuf * wpas_p2p_nfc_handover(int ndef, struct wpabuf *wsc, |
| 9129 | struct wpabuf *p2p) |
| 9130 | { |
| 9131 | struct wpabuf *ret; |
| 9132 | size_t wsc_len; |
| 9133 | |
| 9134 | if (p2p == NULL) { |
| 9135 | wpabuf_free(wsc); |
| 9136 | wpa_printf(MSG_DEBUG, "P2P: No p2p buffer for handover"); |
| 9137 | return NULL; |
| 9138 | } |
| 9139 | |
| 9140 | wsc_len = wsc ? wpabuf_len(wsc) : 0; |
| 9141 | ret = wpabuf_alloc(2 + wsc_len + 2 + wpabuf_len(p2p)); |
| 9142 | if (ret == NULL) { |
| 9143 | wpabuf_free(wsc); |
| 9144 | wpabuf_free(p2p); |
| 9145 | return NULL; |
| 9146 | } |
| 9147 | |
| 9148 | wpabuf_put_be16(ret, wsc_len); |
| 9149 | if (wsc) |
| 9150 | wpabuf_put_buf(ret, wsc); |
| 9151 | wpabuf_put_be16(ret, wpabuf_len(p2p)); |
| 9152 | wpabuf_put_buf(ret, p2p); |
| 9153 | |
| 9154 | wpabuf_free(wsc); |
| 9155 | wpabuf_free(p2p); |
| 9156 | wpa_hexdump_buf(MSG_DEBUG, |
| 9157 | "P2P: Generated NFC connection handover message", ret); |
| 9158 | |
| 9159 | if (ndef && ret) { |
| 9160 | struct wpabuf *tmp; |
| 9161 | tmp = ndef_build_p2p(ret); |
| 9162 | wpabuf_free(ret); |
| 9163 | if (tmp == NULL) { |
| 9164 | wpa_printf(MSG_DEBUG, "P2P: Failed to NDEF encapsulate handover request"); |
| 9165 | return NULL; |
| 9166 | } |
| 9167 | ret = tmp; |
| 9168 | } |
| 9169 | |
| 9170 | return ret; |
| 9171 | } |
| 9172 | |
| 9173 | |
| 9174 | static int wpas_p2p_cli_freq(struct wpa_supplicant *wpa_s, |
| 9175 | struct wpa_ssid **ssid, u8 *go_dev_addr) |
| 9176 | { |
| 9177 | struct wpa_supplicant *iface; |
| 9178 | |
| 9179 | if (go_dev_addr) |
| 9180 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 9181 | if (ssid) |
| 9182 | *ssid = NULL; |
| 9183 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 9184 | if (iface->wpa_state < WPA_ASSOCIATING || |
| 9185 | iface->current_ssid == NULL || iface->assoc_freq == 0 || |
| 9186 | !iface->current_ssid->p2p_group || |
| 9187 | iface->current_ssid->mode != WPAS_MODE_INFRA) |
| 9188 | continue; |
| 9189 | if (ssid) |
| 9190 | *ssid = iface->current_ssid; |
| 9191 | if (go_dev_addr) |
| 9192 | os_memcpy(go_dev_addr, iface->go_dev_addr, ETH_ALEN); |
| 9193 | return iface->assoc_freq; |
| 9194 | } |
| 9195 | return 0; |
| 9196 | } |
| 9197 | |
| 9198 | |
| 9199 | struct wpabuf * wpas_p2p_nfc_handover_req(struct wpa_supplicant *wpa_s, |
| 9200 | int ndef) |
| 9201 | { |
| 9202 | struct wpabuf *wsc, *p2p; |
| 9203 | struct wpa_ssid *ssid; |
| 9204 | u8 go_dev_addr[ETH_ALEN]; |
| 9205 | int cli_freq = wpas_p2p_cli_freq(wpa_s, &ssid, go_dev_addr); |
| 9206 | |
| 9207 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) { |
| 9208 | wpa_printf(MSG_DEBUG, "P2P: P2P disabled - cannot build handover request"); |
| 9209 | return NULL; |
| 9210 | } |
| 9211 | |
| 9212 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL && |
| 9213 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, |
| 9214 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) { |
| 9215 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No DH key available for handover request"); |
| 9216 | return NULL; |
| 9217 | } |
| 9218 | |
| 9219 | if (cli_freq == 0) { |
| 9220 | wsc = wps_build_nfc_handover_req_p2p( |
| 9221 | wpa_s->parent->wps, wpa_s->conf->wps_nfc_dh_pubkey); |
| 9222 | } else |
| 9223 | wsc = NULL; |
| 9224 | p2p = p2p_build_nfc_handover_req(wpa_s->global->p2p, cli_freq, |
| 9225 | go_dev_addr, ssid ? ssid->ssid : NULL, |
| 9226 | ssid ? ssid->ssid_len : 0); |
| 9227 | |
| 9228 | return wpas_p2p_nfc_handover(ndef, wsc, p2p); |
| 9229 | } |
| 9230 | |
| 9231 | |
| 9232 | struct wpabuf * wpas_p2p_nfc_handover_sel(struct wpa_supplicant *wpa_s, |
| 9233 | int ndef, int tag) |
| 9234 | { |
| 9235 | struct wpabuf *wsc, *p2p; |
| 9236 | struct wpa_ssid *ssid; |
| 9237 | u8 go_dev_addr[ETH_ALEN]; |
| 9238 | int cli_freq = wpas_p2p_cli_freq(wpa_s, &ssid, go_dev_addr); |
| 9239 | |
| 9240 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 9241 | return NULL; |
| 9242 | |
| 9243 | if (!tag && wpa_s->conf->wps_nfc_dh_pubkey == NULL && |
| 9244 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, |
| 9245 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) |
| 9246 | return NULL; |
| 9247 | |
| 9248 | if (cli_freq == 0) { |
| 9249 | wsc = wps_build_nfc_handover_sel_p2p( |
| 9250 | wpa_s->parent->wps, |
| 9251 | tag ? wpa_s->conf->wps_nfc_dev_pw_id : |
| 9252 | DEV_PW_NFC_CONNECTION_HANDOVER, |
| 9253 | wpa_s->conf->wps_nfc_dh_pubkey, |
| 9254 | tag ? wpa_s->conf->wps_nfc_dev_pw : NULL); |
| 9255 | } else |
| 9256 | wsc = NULL; |
| 9257 | p2p = p2p_build_nfc_handover_sel(wpa_s->global->p2p, cli_freq, |
| 9258 | go_dev_addr, ssid ? ssid->ssid : NULL, |
| 9259 | ssid ? ssid->ssid_len : 0); |
| 9260 | |
| 9261 | return wpas_p2p_nfc_handover(ndef, wsc, p2p); |
| 9262 | } |
| 9263 | |
| 9264 | |
| 9265 | static int wpas_p2p_nfc_join_group(struct wpa_supplicant *wpa_s, |
| 9266 | struct p2p_nfc_params *params) |
| 9267 | { |
| 9268 | wpa_printf(MSG_DEBUG, "P2P: Initiate join-group based on NFC " |
| 9269 | "connection handover (freq=%d)", |
| 9270 | params->go_freq); |
| 9271 | |
| 9272 | if (params->go_freq && params->go_ssid_len) { |
| 9273 | wpa_s->p2p_wps_method = WPS_NFC; |
| 9274 | wpa_s->pending_join_wps_method = WPS_NFC; |
| 9275 | os_memset(wpa_s->pending_join_iface_addr, 0, ETH_ALEN); |
| 9276 | os_memcpy(wpa_s->pending_join_dev_addr, params->go_dev_addr, |
| 9277 | ETH_ALEN); |
| 9278 | return wpas_p2p_join_start(wpa_s, params->go_freq, |
| 9279 | params->go_ssid, |
| 9280 | params->go_ssid_len); |
| 9281 | } |
| 9282 | |
| 9283 | return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL, |
| 9284 | WPS_NFC, 0, 0, 1, 0, wpa_s->conf->p2p_go_intent, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9285 | params->go_freq, wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 9286 | -1, 0, 1, 1, wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9287 | wpa_s->p2p_go_he, wpa_s->p2p_go_edmg, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 9288 | params->go_ssid_len ? params->go_ssid : NULL, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9289 | params->go_ssid_len, false); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9290 | } |
| 9291 | |
| 9292 | |
| 9293 | static int wpas_p2p_nfc_auth_join(struct wpa_supplicant *wpa_s, |
| 9294 | struct p2p_nfc_params *params, int tag) |
| 9295 | { |
| 9296 | int res, persistent; |
| 9297 | struct wpa_ssid *ssid; |
| 9298 | |
| 9299 | wpa_printf(MSG_DEBUG, "P2P: Authorize join-group based on NFC " |
| 9300 | "connection handover"); |
| 9301 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 9302 | ssid = wpa_s->current_ssid; |
| 9303 | if (ssid == NULL) |
| 9304 | continue; |
| 9305 | if (ssid->mode != WPAS_MODE_P2P_GO) |
| 9306 | continue; |
| 9307 | if (wpa_s->ap_iface == NULL) |
| 9308 | continue; |
| 9309 | break; |
| 9310 | } |
| 9311 | if (wpa_s == NULL) { |
| 9312 | wpa_printf(MSG_DEBUG, "P2P: Could not find GO interface"); |
| 9313 | return -1; |
| 9314 | } |
| 9315 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9316 | if (wpa_s->p2pdev->p2p_oob_dev_pw_id != |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9317 | DEV_PW_NFC_CONNECTION_HANDOVER && |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9318 | !wpa_s->p2pdev->p2p_oob_dev_pw) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9319 | wpa_printf(MSG_DEBUG, "P2P: No NFC Dev Pw known"); |
| 9320 | return -1; |
| 9321 | } |
| 9322 | res = wpas_ap_wps_add_nfc_pw( |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9323 | wpa_s, wpa_s->p2pdev->p2p_oob_dev_pw_id, |
| 9324 | wpa_s->p2pdev->p2p_oob_dev_pw, |
| 9325 | wpa_s->p2pdev->p2p_peer_oob_pk_hash_known ? |
| 9326 | wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : NULL); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9327 | if (res) |
| 9328 | return res; |
| 9329 | |
| 9330 | if (!tag) { |
| 9331 | wpa_printf(MSG_DEBUG, "P2P: Negotiated handover - wait for peer to join without invitation"); |
| 9332 | return 0; |
| 9333 | } |
| 9334 | |
| 9335 | if (!params->peer || |
| 9336 | !(params->peer->dev_capab & P2P_DEV_CAPAB_INVITATION_PROCEDURE)) |
| 9337 | return 0; |
| 9338 | |
| 9339 | wpa_printf(MSG_DEBUG, "P2P: Static handover - invite peer " MACSTR |
| 9340 | " to join", MAC2STR(params->peer->p2p_device_addr)); |
| 9341 | |
| 9342 | wpa_s->global->p2p_invite_group = wpa_s; |
| 9343 | persistent = ssid->p2p_persistent_group && |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9344 | wpas_p2p_get_persistent(wpa_s->p2pdev, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9345 | params->peer->p2p_device_addr, |
| 9346 | ssid->ssid, ssid->ssid_len); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9347 | wpa_s->p2pdev->pending_invite_ssid_id = -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9348 | |
| 9349 | return p2p_invite(wpa_s->global->p2p, params->peer->p2p_device_addr, |
| 9350 | P2P_INVITE_ROLE_ACTIVE_GO, wpa_s->own_addr, |
| 9351 | ssid->ssid, ssid->ssid_len, ssid->frequency, |
| 9352 | wpa_s->global->p2p_dev_addr, persistent, 0, |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9353 | wpa_s->p2pdev->p2p_oob_dev_pw_id); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9354 | } |
| 9355 | |
| 9356 | |
| 9357 | static int wpas_p2p_nfc_init_go_neg(struct wpa_supplicant *wpa_s, |
| 9358 | struct p2p_nfc_params *params, |
| 9359 | int forced_freq) |
| 9360 | { |
| 9361 | wpa_printf(MSG_DEBUG, "P2P: Initiate GO Negotiation based on NFC " |
| 9362 | "connection handover"); |
| 9363 | return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL, |
| 9364 | WPS_NFC, 0, 0, 0, 0, wpa_s->conf->p2p_go_intent, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9365 | forced_freq, wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 9366 | -1, 0, 1, 1, wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9367 | wpa_s->p2p_go_he, wpa_s->p2p_go_edmg, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9368 | NULL, 0, false); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9369 | } |
| 9370 | |
| 9371 | |
| 9372 | static int wpas_p2p_nfc_resp_go_neg(struct wpa_supplicant *wpa_s, |
| 9373 | struct p2p_nfc_params *params, |
| 9374 | int forced_freq) |
| 9375 | { |
| 9376 | int res; |
| 9377 | |
| 9378 | wpa_printf(MSG_DEBUG, "P2P: Authorize GO Negotiation based on NFC " |
| 9379 | "connection handover"); |
| 9380 | res = wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL, |
| 9381 | WPS_NFC, 0, 0, 0, 1, wpa_s->conf->p2p_go_intent, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9382 | forced_freq, wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 9383 | -1, 0, 1, 1, wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9384 | wpa_s->p2p_go_he, wpa_s->p2p_go_edmg, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9385 | NULL, 0, false); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9386 | if (res) |
| 9387 | return res; |
| 9388 | |
| 9389 | res = wpas_p2p_listen(wpa_s, 60); |
| 9390 | if (res) { |
| 9391 | p2p_unauthorize(wpa_s->global->p2p, |
| 9392 | params->peer->p2p_device_addr); |
| 9393 | } |
| 9394 | |
| 9395 | return res; |
| 9396 | } |
| 9397 | |
| 9398 | |
| 9399 | static int wpas_p2p_nfc_connection_handover(struct wpa_supplicant *wpa_s, |
| 9400 | const struct wpabuf *data, |
| 9401 | int sel, int tag, int forced_freq) |
| 9402 | { |
| 9403 | const u8 *pos, *end; |
| 9404 | u16 len, id; |
| 9405 | struct p2p_nfc_params params; |
| 9406 | int res; |
| 9407 | |
| 9408 | os_memset(¶ms, 0, sizeof(params)); |
| 9409 | params.sel = sel; |
| 9410 | |
| 9411 | wpa_hexdump_buf(MSG_DEBUG, "P2P: Received NFC tag payload", data); |
| 9412 | |
| 9413 | pos = wpabuf_head(data); |
| 9414 | end = pos + wpabuf_len(data); |
| 9415 | |
| 9416 | if (end - pos < 2) { |
| 9417 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for Length of WSC " |
| 9418 | "attributes"); |
| 9419 | return -1; |
| 9420 | } |
| 9421 | len = WPA_GET_BE16(pos); |
| 9422 | pos += 2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9423 | if (len > end - pos) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9424 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for WSC " |
| 9425 | "attributes"); |
| 9426 | return -1; |
| 9427 | } |
| 9428 | params.wsc_attr = pos; |
| 9429 | params.wsc_len = len; |
| 9430 | pos += len; |
| 9431 | |
| 9432 | if (end - pos < 2) { |
| 9433 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for Length of P2P " |
| 9434 | "attributes"); |
| 9435 | return -1; |
| 9436 | } |
| 9437 | len = WPA_GET_BE16(pos); |
| 9438 | pos += 2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9439 | if (len > end - pos) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9440 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for P2P " |
| 9441 | "attributes"); |
| 9442 | return -1; |
| 9443 | } |
| 9444 | params.p2p_attr = pos; |
| 9445 | params.p2p_len = len; |
| 9446 | pos += len; |
| 9447 | |
| 9448 | wpa_hexdump(MSG_DEBUG, "P2P: WSC attributes", |
| 9449 | params.wsc_attr, params.wsc_len); |
| 9450 | wpa_hexdump(MSG_DEBUG, "P2P: P2P attributes", |
| 9451 | params.p2p_attr, params.p2p_len); |
| 9452 | if (pos < end) { |
| 9453 | wpa_hexdump(MSG_DEBUG, |
| 9454 | "P2P: Ignored extra data after P2P attributes", |
| 9455 | pos, end - pos); |
| 9456 | } |
| 9457 | |
| 9458 | res = p2p_process_nfc_connection_handover(wpa_s->global->p2p, ¶ms); |
| 9459 | if (res) |
| 9460 | return res; |
| 9461 | |
| 9462 | if (params.next_step == NO_ACTION) |
| 9463 | return 0; |
| 9464 | |
| 9465 | if (params.next_step == BOTH_GO) { |
| 9466 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_BOTH_GO "peer=" MACSTR, |
| 9467 | MAC2STR(params.peer->p2p_device_addr)); |
| 9468 | return 0; |
| 9469 | } |
| 9470 | |
| 9471 | if (params.next_step == PEER_CLIENT) { |
| 9472 | if (!is_zero_ether_addr(params.go_dev_addr)) { |
| 9473 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_PEER_CLIENT |
| 9474 | "peer=" MACSTR " freq=%d go_dev_addr=" MACSTR |
| 9475 | " ssid=\"%s\"", |
| 9476 | MAC2STR(params.peer->p2p_device_addr), |
| 9477 | params.go_freq, |
| 9478 | MAC2STR(params.go_dev_addr), |
| 9479 | wpa_ssid_txt(params.go_ssid, |
| 9480 | params.go_ssid_len)); |
| 9481 | } else { |
| 9482 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_PEER_CLIENT |
| 9483 | "peer=" MACSTR " freq=%d", |
| 9484 | MAC2STR(params.peer->p2p_device_addr), |
| 9485 | params.go_freq); |
| 9486 | } |
| 9487 | return 0; |
| 9488 | } |
| 9489 | |
| 9490 | if (wpas_p2p_cli_freq(wpa_s, NULL, NULL)) { |
| 9491 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_WHILE_CLIENT "peer=" |
| 9492 | MACSTR, MAC2STR(params.peer->p2p_device_addr)); |
| 9493 | return 0; |
| 9494 | } |
| 9495 | |
| 9496 | wpabuf_free(wpa_s->p2p_oob_dev_pw); |
| 9497 | wpa_s->p2p_oob_dev_pw = NULL; |
| 9498 | |
| 9499 | if (params.oob_dev_pw_len < WPS_OOB_PUBKEY_HASH_LEN + 2) { |
| 9500 | wpa_printf(MSG_DEBUG, "P2P: No peer OOB Dev Pw " |
| 9501 | "received"); |
| 9502 | return -1; |
| 9503 | } |
| 9504 | |
| 9505 | id = WPA_GET_BE16(params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN); |
| 9506 | wpa_printf(MSG_DEBUG, "P2P: Peer OOB Dev Pw %u", id); |
| 9507 | wpa_hexdump(MSG_DEBUG, "P2P: Peer OOB Public Key hash", |
| 9508 | params.oob_dev_pw, WPS_OOB_PUBKEY_HASH_LEN); |
| 9509 | os_memcpy(wpa_s->p2p_peer_oob_pubkey_hash, |
| 9510 | params.oob_dev_pw, WPS_OOB_PUBKEY_HASH_LEN); |
| 9511 | wpa_s->p2p_peer_oob_pk_hash_known = 1; |
| 9512 | |
| 9513 | if (tag) { |
| 9514 | if (id < 0x10) { |
| 9515 | wpa_printf(MSG_DEBUG, "P2P: Static handover - invalid " |
| 9516 | "peer OOB Device Password Id %u", id); |
| 9517 | return -1; |
| 9518 | } |
| 9519 | wpa_printf(MSG_DEBUG, "P2P: Static handover - use peer OOB " |
| 9520 | "Device Password Id %u", id); |
| 9521 | wpa_hexdump_key(MSG_DEBUG, "P2P: Peer OOB Device Password", |
| 9522 | params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN + 2, |
| 9523 | params.oob_dev_pw_len - |
| 9524 | WPS_OOB_PUBKEY_HASH_LEN - 2); |
| 9525 | wpa_s->p2p_oob_dev_pw_id = id; |
| 9526 | wpa_s->p2p_oob_dev_pw = wpabuf_alloc_copy( |
| 9527 | params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN + 2, |
| 9528 | params.oob_dev_pw_len - |
| 9529 | WPS_OOB_PUBKEY_HASH_LEN - 2); |
| 9530 | if (wpa_s->p2p_oob_dev_pw == NULL) |
| 9531 | return -1; |
| 9532 | |
| 9533 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL && |
| 9534 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, |
| 9535 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) |
| 9536 | return -1; |
| 9537 | } else { |
| 9538 | wpa_printf(MSG_DEBUG, "P2P: Using abbreviated WPS handshake " |
| 9539 | "without Device Password"); |
| 9540 | wpa_s->p2p_oob_dev_pw_id = DEV_PW_NFC_CONNECTION_HANDOVER; |
| 9541 | } |
| 9542 | |
| 9543 | switch (params.next_step) { |
| 9544 | case NO_ACTION: |
| 9545 | case BOTH_GO: |
| 9546 | case PEER_CLIENT: |
| 9547 | /* already covered above */ |
| 9548 | return 0; |
| 9549 | case JOIN_GROUP: |
| 9550 | return wpas_p2p_nfc_join_group(wpa_s, ¶ms); |
| 9551 | case AUTH_JOIN: |
| 9552 | return wpas_p2p_nfc_auth_join(wpa_s, ¶ms, tag); |
| 9553 | case INIT_GO_NEG: |
| 9554 | return wpas_p2p_nfc_init_go_neg(wpa_s, ¶ms, forced_freq); |
| 9555 | case RESP_GO_NEG: |
| 9556 | /* TODO: use own OOB Dev Pw */ |
| 9557 | return wpas_p2p_nfc_resp_go_neg(wpa_s, ¶ms, forced_freq); |
| 9558 | } |
| 9559 | |
| 9560 | return -1; |
| 9561 | } |
| 9562 | |
| 9563 | |
| 9564 | int wpas_p2p_nfc_tag_process(struct wpa_supplicant *wpa_s, |
| 9565 | const struct wpabuf *data, int forced_freq) |
| 9566 | { |
| 9567 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 9568 | return -1; |
| 9569 | |
| 9570 | return wpas_p2p_nfc_connection_handover(wpa_s, data, 1, 1, forced_freq); |
| 9571 | } |
| 9572 | |
| 9573 | |
| 9574 | int wpas_p2p_nfc_report_handover(struct wpa_supplicant *wpa_s, int init, |
| 9575 | const struct wpabuf *req, |
| 9576 | const struct wpabuf *sel, int forced_freq) |
| 9577 | { |
| 9578 | struct wpabuf *tmp; |
| 9579 | int ret; |
| 9580 | |
| 9581 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 9582 | return -1; |
| 9583 | |
| 9584 | wpa_printf(MSG_DEBUG, "NFC: P2P connection handover reported"); |
| 9585 | |
| 9586 | wpa_hexdump_ascii(MSG_DEBUG, "NFC: Req", |
| 9587 | wpabuf_head(req), wpabuf_len(req)); |
| 9588 | wpa_hexdump_ascii(MSG_DEBUG, "NFC: Sel", |
| 9589 | wpabuf_head(sel), wpabuf_len(sel)); |
| 9590 | if (forced_freq) |
| 9591 | wpa_printf(MSG_DEBUG, "NFC: Forced freq %d", forced_freq); |
| 9592 | tmp = ndef_parse_p2p(init ? sel : req); |
| 9593 | if (tmp == NULL) { |
| 9594 | wpa_printf(MSG_DEBUG, "P2P: Could not parse NDEF"); |
| 9595 | return -1; |
| 9596 | } |
| 9597 | |
| 9598 | ret = wpas_p2p_nfc_connection_handover(wpa_s, tmp, init, 0, |
| 9599 | forced_freq); |
| 9600 | wpabuf_free(tmp); |
| 9601 | |
| 9602 | return ret; |
| 9603 | } |
| 9604 | |
| 9605 | |
| 9606 | int wpas_p2p_nfc_tag_enabled(struct wpa_supplicant *wpa_s, int enabled) |
| 9607 | { |
| 9608 | const u8 *if_addr; |
| 9609 | int go_intent = wpa_s->conf->p2p_go_intent; |
| 9610 | struct wpa_supplicant *iface; |
| 9611 | |
| 9612 | if (wpa_s->global->p2p == NULL) |
| 9613 | return -1; |
| 9614 | |
| 9615 | if (!enabled) { |
| 9616 | wpa_printf(MSG_DEBUG, "P2P: Disable use of own NFC Tag"); |
| 9617 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) |
| 9618 | { |
| 9619 | if (!iface->ap_iface) |
| 9620 | continue; |
| 9621 | hostapd_wps_nfc_token_disable(iface->ap_iface->bss[0]); |
| 9622 | } |
| 9623 | p2p_set_authorized_oob_dev_pw_id(wpa_s->global->p2p, 0, |
| 9624 | 0, NULL); |
| 9625 | if (wpa_s->p2p_nfc_tag_enabled) |
| 9626 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 9627 | wpa_s->p2p_nfc_tag_enabled = 0; |
| 9628 | return 0; |
| 9629 | } |
| 9630 | |
| 9631 | if (wpa_s->global->p2p_disabled) |
| 9632 | return -1; |
| 9633 | |
| 9634 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL || |
| 9635 | wpa_s->conf->wps_nfc_dh_privkey == NULL || |
| 9636 | wpa_s->conf->wps_nfc_dev_pw == NULL || |
| 9637 | wpa_s->conf->wps_nfc_dev_pw_id < 0x10) { |
| 9638 | wpa_printf(MSG_DEBUG, "P2P: NFC password token not configured " |
| 9639 | "to allow static handover cases"); |
| 9640 | return -1; |
| 9641 | } |
| 9642 | |
| 9643 | wpa_printf(MSG_DEBUG, "P2P: Enable use of own NFC Tag"); |
| 9644 | |
| 9645 | wpa_s->p2p_oob_dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id; |
| 9646 | wpabuf_free(wpa_s->p2p_oob_dev_pw); |
| 9647 | wpa_s->p2p_oob_dev_pw = wpabuf_dup(wpa_s->conf->wps_nfc_dev_pw); |
| 9648 | if (wpa_s->p2p_oob_dev_pw == NULL) |
| 9649 | return -1; |
| 9650 | wpa_s->p2p_peer_oob_pk_hash_known = 0; |
| 9651 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 9652 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO || |
| 9653 | wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT) { |
| 9654 | /* |
| 9655 | * P2P Group Interface present and the command came on group |
| 9656 | * interface, so enable the token for the current interface. |
| 9657 | */ |
| 9658 | wpa_s->create_p2p_iface = 0; |
| 9659 | } else { |
| 9660 | wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s); |
| 9661 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9662 | |
| 9663 | if (wpa_s->create_p2p_iface) { |
| 9664 | enum wpa_driver_if_type iftype; |
| 9665 | /* Prepare to add a new interface for the group */ |
| 9666 | iftype = WPA_IF_P2P_GROUP; |
| 9667 | if (go_intent == 15) |
| 9668 | iftype = WPA_IF_P2P_GO; |
| 9669 | if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) { |
| 9670 | wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " |
| 9671 | "interface for the group"); |
| 9672 | return -1; |
| 9673 | } |
| 9674 | |
| 9675 | if_addr = wpa_s->pending_interface_addr; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9676 | } else if (wpa_s->p2p_mgmt) |
| 9677 | if_addr = wpa_s->parent->own_addr; |
| 9678 | else |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9679 | if_addr = wpa_s->own_addr; |
| 9680 | |
| 9681 | wpa_s->p2p_nfc_tag_enabled = enabled; |
| 9682 | |
| 9683 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 9684 | struct hostapd_data *hapd; |
| 9685 | if (iface->ap_iface == NULL) |
| 9686 | continue; |
| 9687 | hapd = iface->ap_iface->bss[0]; |
| 9688 | wpabuf_free(hapd->conf->wps_nfc_dh_pubkey); |
| 9689 | hapd->conf->wps_nfc_dh_pubkey = |
| 9690 | wpabuf_dup(wpa_s->conf->wps_nfc_dh_pubkey); |
| 9691 | wpabuf_free(hapd->conf->wps_nfc_dh_privkey); |
| 9692 | hapd->conf->wps_nfc_dh_privkey = |
| 9693 | wpabuf_dup(wpa_s->conf->wps_nfc_dh_privkey); |
| 9694 | wpabuf_free(hapd->conf->wps_nfc_dev_pw); |
| 9695 | hapd->conf->wps_nfc_dev_pw = |
| 9696 | wpabuf_dup(wpa_s->conf->wps_nfc_dev_pw); |
| 9697 | hapd->conf->wps_nfc_dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id; |
| 9698 | |
| 9699 | if (hostapd_wps_nfc_token_enable(iface->ap_iface->bss[0]) < 0) { |
| 9700 | wpa_dbg(iface, MSG_DEBUG, |
| 9701 | "P2P: Failed to enable NFC Tag for GO"); |
| 9702 | } |
| 9703 | } |
| 9704 | p2p_set_authorized_oob_dev_pw_id( |
| 9705 | wpa_s->global->p2p, wpa_s->conf->wps_nfc_dev_pw_id, go_intent, |
| 9706 | if_addr); |
| 9707 | |
| 9708 | return 0; |
| 9709 | } |
| 9710 | |
| 9711 | #endif /* CONFIG_WPS_NFC */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9712 | |
| 9713 | |
| 9714 | static void wpas_p2p_optimize_listen_channel(struct wpa_supplicant *wpa_s, |
| 9715 | struct wpa_used_freq_data *freqs, |
| 9716 | unsigned int num) |
| 9717 | { |
| 9718 | u8 curr_chan, cand, chan; |
| 9719 | unsigned int i; |
| 9720 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9721 | /* |
| 9722 | * If possible, optimize the Listen channel to be a channel that is |
| 9723 | * already used by one of the other interfaces. |
| 9724 | */ |
| 9725 | if (!wpa_s->conf->p2p_optimize_listen_chan) |
| 9726 | return; |
| 9727 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9728 | curr_chan = p2p_get_listen_channel(wpa_s->global->p2p); |
| 9729 | for (i = 0, cand = 0; i < num; i++) { |
| 9730 | ieee80211_freq_to_chan(freqs[i].freq, &chan); |
| 9731 | if (curr_chan == chan) { |
| 9732 | cand = 0; |
| 9733 | break; |
| 9734 | } |
| 9735 | |
| 9736 | if (chan == 1 || chan == 6 || chan == 11) |
| 9737 | cand = chan; |
| 9738 | } |
| 9739 | |
| 9740 | if (cand) { |
| 9741 | wpa_dbg(wpa_s, MSG_DEBUG, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 9742 | "P2P: Update Listen channel to %u based on operating channel", |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9743 | cand); |
| 9744 | p2p_set_listen_channel(wpa_s->global->p2p, 81, cand, 0); |
| 9745 | } |
| 9746 | } |
| 9747 | |
| 9748 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9749 | static int wpas_p2p_move_go_csa(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9750 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9751 | struct hostapd_config *conf; |
| 9752 | struct p2p_go_neg_results params; |
| 9753 | struct csa_settings csa_settings; |
| 9754 | struct wpa_ssid *current_ssid = wpa_s->current_ssid; |
| 9755 | int old_freq = current_ssid->frequency; |
| 9756 | int ret; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9757 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9758 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
| 9759 | wpa_dbg(wpa_s, MSG_DEBUG, "CSA is not enabled"); |
| 9760 | return -1; |
| 9761 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9762 | |
| 9763 | /* |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9764 | * TODO: This function may not always work correctly. For example, |
| 9765 | * when we have a running GO and a BSS on a DFS channel. |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9766 | */ |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9767 | if (wpas_p2p_init_go_params(wpa_s, ¶ms, 0, 0, 0, 0, 0, 0, 0, |
| 9768 | NULL)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9769 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9770 | "P2P CSA: Failed to select new frequency for GO"); |
| 9771 | return -1; |
| 9772 | } |
| 9773 | |
| 9774 | if (current_ssid->frequency == params.freq) { |
| 9775 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9776 | "P2P CSA: Selected same frequency - not moving GO"); |
| 9777 | return 0; |
| 9778 | } |
| 9779 | |
| 9780 | conf = hostapd_config_defaults(); |
| 9781 | if (!conf) { |
| 9782 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9783 | "P2P CSA: Failed to allocate default config"); |
| 9784 | return -1; |
| 9785 | } |
| 9786 | |
| 9787 | current_ssid->frequency = params.freq; |
| 9788 | if (wpa_supplicant_conf_ap_ht(wpa_s, current_ssid, conf)) { |
| 9789 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9790 | "P2P CSA: Failed to create new GO config"); |
| 9791 | ret = -1; |
| 9792 | goto out; |
| 9793 | } |
| 9794 | |
Sunil | 4a3f9f5 | 2022-07-19 22:04:39 +0000 | [diff] [blame] | 9795 | if (conf->hw_mode != wpa_s->ap_iface->current_mode->mode && |
| 9796 | (wpa_s->ap_iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A || |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 9797 | is_6ghz_freq(wpa_s->ap_iface->freq) || |
Sunil | 4a3f9f5 | 2022-07-19 22:04:39 +0000 | [diff] [blame] | 9798 | conf->hw_mode != HOSTAPD_MODE_IEEE80211G)) { |
| 9799 | wpa_dbg(wpa_s, MSG_INFO, |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 9800 | "P2P CSA: CSA from hardware mode %d%s to %d is not supported", |
| 9801 | wpa_s->ap_iface->current_mode->mode, |
| 9802 | is_6ghz_freq(wpa_s->ap_iface->freq) ? " (6 GHz)" : "", |
| 9803 | conf->hw_mode); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9804 | ret = -1; |
| 9805 | goto out; |
| 9806 | } |
| 9807 | |
| 9808 | os_memset(&csa_settings, 0, sizeof(csa_settings)); |
| 9809 | csa_settings.cs_count = P2P_GO_CSA_COUNT; |
| 9810 | csa_settings.block_tx = P2P_GO_CSA_BLOCK_TX; |
| 9811 | csa_settings.freq_params.freq = params.freq; |
| 9812 | csa_settings.freq_params.sec_channel_offset = conf->secondary_channel; |
| 9813 | csa_settings.freq_params.ht_enabled = conf->ieee80211n; |
| 9814 | csa_settings.freq_params.bandwidth = conf->secondary_channel ? 40 : 20; |
| 9815 | |
| 9816 | if (conf->ieee80211ac) { |
| 9817 | int freq1 = 0, freq2 = 0; |
| 9818 | u8 chan, opclass; |
| 9819 | |
| 9820 | if (ieee80211_freq_to_channel_ext(params.freq, |
| 9821 | conf->secondary_channel, |
| 9822 | conf->vht_oper_chwidth, |
| 9823 | &opclass, &chan) == |
| 9824 | NUM_HOSTAPD_MODES) { |
| 9825 | wpa_printf(MSG_ERROR, "P2P CSA: Bad freq"); |
| 9826 | ret = -1; |
| 9827 | goto out; |
| 9828 | } |
| 9829 | |
| 9830 | if (conf->vht_oper_centr_freq_seg0_idx) |
| 9831 | freq1 = ieee80211_chan_to_freq( |
| 9832 | NULL, opclass, |
| 9833 | conf->vht_oper_centr_freq_seg0_idx); |
| 9834 | |
| 9835 | if (conf->vht_oper_centr_freq_seg1_idx) |
| 9836 | freq2 = ieee80211_chan_to_freq( |
| 9837 | NULL, opclass, |
| 9838 | conf->vht_oper_centr_freq_seg1_idx); |
| 9839 | |
| 9840 | if (freq1 < 0 || freq2 < 0) { |
| 9841 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9842 | "P2P CSA: Selected invalid VHT center freqs"); |
| 9843 | ret = -1; |
| 9844 | goto out; |
| 9845 | } |
| 9846 | |
| 9847 | csa_settings.freq_params.vht_enabled = conf->ieee80211ac; |
| 9848 | csa_settings.freq_params.center_freq1 = freq1; |
| 9849 | csa_settings.freq_params.center_freq2 = freq2; |
| 9850 | |
| 9851 | switch (conf->vht_oper_chwidth) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 9852 | case CONF_OPER_CHWIDTH_80MHZ: |
| 9853 | case CONF_OPER_CHWIDTH_80P80MHZ: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9854 | csa_settings.freq_params.bandwidth = 80; |
| 9855 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 9856 | case CONF_OPER_CHWIDTH_160MHZ: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9857 | csa_settings.freq_params.bandwidth = 160; |
| 9858 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 9859 | default: |
| 9860 | break; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9861 | } |
| 9862 | } |
| 9863 | |
| 9864 | ret = ap_switch_channel(wpa_s, &csa_settings); |
| 9865 | out: |
| 9866 | current_ssid->frequency = old_freq; |
| 9867 | hostapd_config_free(conf); |
| 9868 | return ret; |
| 9869 | } |
| 9870 | |
| 9871 | |
| 9872 | static void wpas_p2p_move_go_no_csa(struct wpa_supplicant *wpa_s) |
| 9873 | { |
| 9874 | struct p2p_go_neg_results params; |
| 9875 | struct wpa_ssid *current_ssid = wpa_s->current_ssid; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9876 | void (*ap_configured_cb)(void *ctx, void *data); |
| 9877 | void *ap_configured_cb_ctx, *ap_configured_cb_data; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9878 | |
| 9879 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP); |
| 9880 | |
| 9881 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Move GO from freq=%d MHz", |
| 9882 | current_ssid->frequency); |
| 9883 | |
| 9884 | /* Stop the AP functionality */ |
| 9885 | /* TODO: Should do this in a way that does not indicated to possible |
| 9886 | * P2P Clients in the group that the group is terminated. */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9887 | /* If this action occurs before a group is started, the callback should |
| 9888 | * be preserved, or GROUP-STARTED event would be lost. If this action |
| 9889 | * occurs after a group is started, these pointers are all NULL and |
| 9890 | * harmless. */ |
| 9891 | ap_configured_cb = wpa_s->ap_configured_cb; |
| 9892 | ap_configured_cb_ctx = wpa_s->ap_configured_cb_ctx; |
| 9893 | ap_configured_cb_data = wpa_s->ap_configured_cb_data; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9894 | wpa_supplicant_ap_deinit(wpa_s); |
| 9895 | |
| 9896 | /* Reselect the GO frequency */ |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9897 | if (wpas_p2p_init_go_params(wpa_s, ¶ms, 0, 0, 0, 0, 0, 0, 0, |
| 9898 | NULL)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9899 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Failed to reselect freq"); |
| 9900 | wpas_p2p_group_delete(wpa_s, |
| 9901 | P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL); |
| 9902 | return; |
| 9903 | } |
| 9904 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New freq selected for the GO (%u MHz)", |
| 9905 | params.freq); |
| 9906 | |
| 9907 | if (params.freq && |
| 9908 | !p2p_supported_freq_go(wpa_s->global->p2p, params.freq)) { |
| 9909 | wpa_printf(MSG_DEBUG, |
| 9910 | "P2P: Selected freq (%u MHz) is not valid for P2P", |
| 9911 | params.freq); |
| 9912 | wpas_p2p_group_delete(wpa_s, |
| 9913 | P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL); |
| 9914 | return; |
| 9915 | } |
| 9916 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9917 | /* Restore preserved callback parameters */ |
Jimmy Chen | 4b2a502 | 2020-08-26 18:55:45 +0800 | [diff] [blame] | 9918 | wpa_s->ap_configured_cb = ap_configured_cb; |
| 9919 | wpa_s->ap_configured_cb_ctx = ap_configured_cb_ctx; |
| 9920 | wpa_s->ap_configured_cb_data = ap_configured_cb_data; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9921 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9922 | /* Update the frequency */ |
| 9923 | current_ssid->frequency = params.freq; |
| 9924 | wpa_s->connect_without_scan = current_ssid; |
| 9925 | wpa_s->reassociate = 1; |
| 9926 | wpa_s->disconnected = 0; |
| 9927 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 9928 | } |
| 9929 | |
| 9930 | |
| 9931 | static void wpas_p2p_move_go(void *eloop_ctx, void *timeout_ctx) |
| 9932 | { |
| 9933 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 9934 | |
| 9935 | if (!wpa_s->ap_iface || !wpa_s->current_ssid) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9936 | return; |
| 9937 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9938 | wpas_p2p_go_update_common_freqs(wpa_s); |
| 9939 | |
| 9940 | /* Do not move GO in the middle of a CSA */ |
| 9941 | if (hostapd_csa_in_progress(wpa_s->ap_iface)) { |
| 9942 | wpa_printf(MSG_DEBUG, |
| 9943 | "P2P: CSA is in progress - not moving GO"); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9944 | return; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9945 | } |
| 9946 | |
| 9947 | /* |
| 9948 | * First, try a channel switch flow. If it is not supported or fails, |
| 9949 | * take down the GO and bring it up again. |
| 9950 | */ |
| 9951 | if (wpas_p2p_move_go_csa(wpa_s) < 0) |
| 9952 | wpas_p2p_move_go_no_csa(wpa_s); |
| 9953 | } |
| 9954 | |
| 9955 | |
| 9956 | static void wpas_p2p_reconsider_moving_go(void *eloop_ctx, void *timeout_ctx) |
| 9957 | { |
| 9958 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 9959 | struct wpa_used_freq_data *freqs = NULL; |
| 9960 | unsigned int num = wpa_s->num_multichan_concurrent; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9961 | |
| 9962 | freqs = os_calloc(num, sizeof(struct wpa_used_freq_data)); |
| 9963 | if (!freqs) |
| 9964 | return; |
| 9965 | |
| 9966 | num = get_shared_radio_freqs_data(wpa_s, freqs, num); |
| 9967 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9968 | /* Previous attempt to move a GO was not possible -- try again. */ |
| 9969 | wpas_p2p_consider_moving_gos(wpa_s, freqs, num, |
| 9970 | WPAS_P2P_CHANNEL_UPDATE_ANY); |
| 9971 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9972 | os_free(freqs); |
| 9973 | } |
| 9974 | |
| 9975 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9976 | /* |
| 9977 | * Consider moving a GO from its currently used frequency: |
| 9978 | * 1. It is possible that due to regulatory consideration the frequency |
| 9979 | * can no longer be used and there is a need to evacuate the GO. |
| 9980 | * 2. It is possible that due to MCC considerations, it would be preferable |
| 9981 | * to move the GO to a channel that is currently used by some other |
| 9982 | * station interface. |
| 9983 | * |
| 9984 | * In case a frequency that became invalid is once again valid, cancel a |
| 9985 | * previously initiated GO frequency change. |
| 9986 | */ |
| 9987 | static void wpas_p2p_consider_moving_one_go(struct wpa_supplicant *wpa_s, |
| 9988 | struct wpa_used_freq_data *freqs, |
| 9989 | unsigned int num) |
| 9990 | { |
| 9991 | unsigned int i, invalid_freq = 0, policy_move = 0, flags = 0; |
| 9992 | unsigned int timeout; |
| 9993 | int freq; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9994 | int dfs_offload; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9995 | |
| 9996 | wpas_p2p_go_update_common_freqs(wpa_s); |
| 9997 | |
| 9998 | freq = wpa_s->current_ssid->frequency; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9999 | dfs_offload = (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10000 | ieee80211_is_dfs(freq, wpa_s->hw.modes, wpa_s->hw.num_modes); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10001 | for (i = 0, invalid_freq = 0; i < num; i++) { |
| 10002 | if (freqs[i].freq == freq) { |
| 10003 | flags = freqs[i].flags; |
| 10004 | |
| 10005 | /* The channel is invalid, must change it */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10006 | if (!p2p_supported_freq_go(wpa_s->global->p2p, freq) && |
| 10007 | !dfs_offload) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10008 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10009 | "P2P: Freq=%d MHz no longer valid for GO", |
| 10010 | freq); |
| 10011 | invalid_freq = 1; |
| 10012 | } |
| 10013 | } else if (freqs[i].flags == 0) { |
| 10014 | /* Freq is not used by any other station interface */ |
| 10015 | continue; |
| 10016 | } else if (!p2p_supported_freq(wpa_s->global->p2p, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10017 | freqs[i].freq) && !dfs_offload) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10018 | /* Freq is not valid for P2P use cases */ |
| 10019 | continue; |
| 10020 | } else if (wpa_s->conf->p2p_go_freq_change_policy == |
| 10021 | P2P_GO_FREQ_MOVE_SCM) { |
| 10022 | policy_move = 1; |
| 10023 | } else if (wpa_s->conf->p2p_go_freq_change_policy == |
| 10024 | P2P_GO_FREQ_MOVE_SCM_PEER_SUPPORTS && |
| 10025 | wpas_p2p_go_is_peer_freq(wpa_s, freqs[i].freq)) { |
| 10026 | policy_move = 1; |
| 10027 | } else if ((wpa_s->conf->p2p_go_freq_change_policy == |
| 10028 | P2P_GO_FREQ_MOVE_SCM_ECSA) && |
| 10029 | wpas_p2p_go_is_peer_freq(wpa_s, freqs[i].freq)) { |
| 10030 | if (!p2p_get_group_num_members(wpa_s->p2p_group)) { |
| 10031 | policy_move = 1; |
| 10032 | } else if ((wpa_s->drv_flags & |
| 10033 | WPA_DRIVER_FLAGS_AP_CSA) && |
| 10034 | wpas_p2p_go_clients_support_ecsa(wpa_s)) { |
| 10035 | u8 chan; |
| 10036 | |
| 10037 | /* |
| 10038 | * We do not support CSA between bands, so move |
| 10039 | * GO only within the same band. |
| 10040 | */ |
| 10041 | if (wpa_s->ap_iface->current_mode->mode == |
| 10042 | ieee80211_freq_to_chan(freqs[i].freq, |
| 10043 | &chan)) |
| 10044 | policy_move = 1; |
| 10045 | } |
| 10046 | } |
| 10047 | } |
| 10048 | |
| 10049 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10050 | "P2P: GO move: invalid_freq=%u, policy_move=%u, flags=0x%X", |
| 10051 | invalid_freq, policy_move, flags); |
| 10052 | |
| 10053 | /* |
| 10054 | * The channel is valid, or we are going to have a policy move, so |
| 10055 | * cancel timeout. |
| 10056 | */ |
| 10057 | if (!invalid_freq || policy_move) { |
| 10058 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10059 | "P2P: Cancel a GO move from freq=%d MHz", freq); |
| 10060 | eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL); |
| 10061 | |
| 10062 | if (wpas_p2p_in_progress(wpa_s)) { |
| 10063 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10064 | "P2P: GO move: policy CS is not allowed - setting timeout to re-consider GO move"); |
| 10065 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, |
| 10066 | wpa_s, NULL); |
| 10067 | eloop_register_timeout(P2P_RECONSIDER_GO_MOVE_DELAY, 0, |
| 10068 | wpas_p2p_reconsider_moving_go, |
| 10069 | wpa_s, NULL); |
| 10070 | return; |
| 10071 | } |
| 10072 | } |
| 10073 | |
| 10074 | if (!invalid_freq && (!policy_move || flags != 0)) { |
| 10075 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10076 | "P2P: Not initiating a GO frequency change"); |
| 10077 | return; |
| 10078 | } |
| 10079 | |
| 10080 | /* |
| 10081 | * Do not consider moving GO if it is in the middle of a CSA. When the |
| 10082 | * CSA is finished this flow should be retriggered. |
| 10083 | */ |
| 10084 | if (hostapd_csa_in_progress(wpa_s->ap_iface)) { |
| 10085 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10086 | "P2P: Not initiating a GO frequency change - CSA is in progress"); |
| 10087 | return; |
| 10088 | } |
| 10089 | |
| 10090 | if (invalid_freq && !wpas_p2p_disallowed_freq(wpa_s->global, freq)) |
| 10091 | timeout = P2P_GO_FREQ_CHANGE_TIME; |
| 10092 | else |
| 10093 | timeout = 0; |
| 10094 | |
| 10095 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Move GO from freq=%d MHz in %d secs", |
| 10096 | freq, timeout); |
| 10097 | eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL); |
| 10098 | eloop_register_timeout(timeout, 0, wpas_p2p_move_go, wpa_s, NULL); |
| 10099 | } |
| 10100 | |
| 10101 | |
| 10102 | static void wpas_p2p_consider_moving_gos(struct wpa_supplicant *wpa_s, |
| 10103 | struct wpa_used_freq_data *freqs, |
| 10104 | unsigned int num, |
| 10105 | enum wpas_p2p_channel_update_trig trig) |
| 10106 | { |
| 10107 | struct wpa_supplicant *ifs; |
| 10108 | |
| 10109 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, ELOOP_ALL_CTX, |
| 10110 | NULL); |
| 10111 | |
| 10112 | /* |
| 10113 | * Travers all the radio interfaces, and for each GO interface, check |
| 10114 | * if there is a need to move the GO from the frequency it is using, |
| 10115 | * or in case the frequency is valid again, cancel the evacuation flow. |
| 10116 | */ |
| 10117 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 10118 | radio_list) { |
| 10119 | if (ifs->current_ssid == NULL || |
| 10120 | ifs->current_ssid->mode != WPAS_MODE_P2P_GO) |
| 10121 | continue; |
| 10122 | |
| 10123 | /* |
| 10124 | * The GO was just started or completed channel switch, no need |
| 10125 | * to move it. |
| 10126 | */ |
| 10127 | if (wpa_s == ifs && |
| 10128 | (trig == WPAS_P2P_CHANNEL_UPDATE_STATE_CHANGE || |
| 10129 | trig == WPAS_P2P_CHANNEL_UPDATE_CS)) { |
| 10130 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10131 | "P2P: GO move - schedule re-consideration"); |
| 10132 | eloop_register_timeout(P2P_RECONSIDER_GO_MOVE_DELAY, 0, |
| 10133 | wpas_p2p_reconsider_moving_go, |
| 10134 | wpa_s, NULL); |
| 10135 | continue; |
| 10136 | } |
| 10137 | |
| 10138 | wpas_p2p_consider_moving_one_go(ifs, freqs, num); |
| 10139 | } |
| 10140 | } |
| 10141 | |
| 10142 | |
| 10143 | void wpas_p2p_indicate_state_change(struct wpa_supplicant *wpa_s) |
| 10144 | { |
| 10145 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 10146 | return; |
| 10147 | |
| 10148 | wpas_p2p_update_channel_list(wpa_s, |
| 10149 | WPAS_P2P_CHANNEL_UPDATE_STATE_CHANGE); |
| 10150 | } |
| 10151 | |
| 10152 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10153 | void wpas_p2p_deinit_iface(struct wpa_supplicant *wpa_s) |
| 10154 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10155 | if (wpa_s == wpa_s->global->p2p_init_wpa_s && wpa_s->global->p2p) { |
| 10156 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disable P2P since removing " |
| 10157 | "the management interface is being removed"); |
| 10158 | wpas_p2p_deinit_global(wpa_s->global); |
| 10159 | } |
| 10160 | } |
| 10161 | |
| 10162 | |
| 10163 | void wpas_p2p_ap_deinit(struct wpa_supplicant *wpa_s) |
| 10164 | { |
| 10165 | if (wpa_s->ap_iface->bss) |
| 10166 | wpa_s->ap_iface->bss[0]->p2p_group = NULL; |
| 10167 | wpas_p2p_group_deinit(wpa_s); |
| 10168 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10169 | |
| 10170 | |
| 10171 | int wpas_p2p_lo_start(struct wpa_supplicant *wpa_s, unsigned int freq, |
| 10172 | unsigned int period, unsigned int interval, |
| 10173 | unsigned int count) |
| 10174 | { |
| 10175 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 10176 | u8 *device_types; |
| 10177 | size_t dev_types_len; |
| 10178 | struct wpabuf *buf; |
| 10179 | int ret; |
| 10180 | |
| 10181 | if (wpa_s->p2p_lo_started) { |
| 10182 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10183 | "P2P Listen offload is already started"); |
| 10184 | return 0; |
| 10185 | } |
| 10186 | |
| 10187 | if (wpa_s->global->p2p == NULL || |
| 10188 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) { |
| 10189 | wpa_printf(MSG_DEBUG, "P2P: Listen offload not supported"); |
| 10190 | return -1; |
| 10191 | } |
| 10192 | |
| 10193 | if (!p2p_supported_freq(wpa_s->global->p2p, freq)) { |
| 10194 | wpa_printf(MSG_ERROR, "P2P: Input channel not supported: %u", |
| 10195 | freq); |
| 10196 | return -1; |
| 10197 | } |
| 10198 | |
| 10199 | /* Get device type */ |
| 10200 | dev_types_len = (wpa_s->conf->num_sec_device_types + 1) * |
| 10201 | WPS_DEV_TYPE_LEN; |
| 10202 | device_types = os_malloc(dev_types_len); |
| 10203 | if (!device_types) |
| 10204 | return -1; |
| 10205 | os_memcpy(device_types, wpa_s->conf->device_type, WPS_DEV_TYPE_LEN); |
| 10206 | os_memcpy(&device_types[WPS_DEV_TYPE_LEN], wpa_s->conf->sec_device_type, |
| 10207 | wpa_s->conf->num_sec_device_types * WPS_DEV_TYPE_LEN); |
| 10208 | |
| 10209 | /* Get Probe Response IE(s) */ |
| 10210 | buf = p2p_build_probe_resp_template(p2p, freq); |
| 10211 | if (!buf) { |
| 10212 | os_free(device_types); |
| 10213 | return -1; |
| 10214 | } |
| 10215 | |
| 10216 | ret = wpa_drv_p2p_lo_start(wpa_s, freq, period, interval, count, |
| 10217 | device_types, dev_types_len, |
| 10218 | wpabuf_mhead_u8(buf), wpabuf_len(buf)); |
| 10219 | if (ret < 0) |
| 10220 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10221 | "P2P: Failed to start P2P listen offload"); |
| 10222 | |
| 10223 | os_free(device_types); |
| 10224 | wpabuf_free(buf); |
| 10225 | |
| 10226 | if (ret == 0) { |
| 10227 | wpa_s->p2p_lo_started = 1; |
| 10228 | |
| 10229 | /* Stop current P2P listen if any */ |
| 10230 | wpas_stop_listen(wpa_s); |
| 10231 | } |
| 10232 | |
| 10233 | return ret; |
| 10234 | } |
| 10235 | |
| 10236 | |
| 10237 | int wpas_p2p_lo_stop(struct wpa_supplicant *wpa_s) |
| 10238 | { |
| 10239 | int ret; |
| 10240 | |
| 10241 | if (!wpa_s->p2p_lo_started) |
| 10242 | return 0; |
| 10243 | |
| 10244 | ret = wpa_drv_p2p_lo_stop(wpa_s); |
| 10245 | if (ret < 0) |
| 10246 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10247 | "P2P: Failed to stop P2P listen offload"); |
| 10248 | |
| 10249 | wpa_s->p2p_lo_started = 0; |
| 10250 | return ret; |
| 10251 | } |