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); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 168 | static int wpas_p2p_disallowed_freq(struct wpa_global *global, |
| 169 | unsigned int freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 170 | |
| 171 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 172 | static int wpas_get_6ghz_he_chwidth_capab(struct hostapd_hw_modes *mode) |
| 173 | { |
| 174 | int he_capab = 0; |
| 175 | |
| 176 | if (mode) |
| 177 | he_capab = mode->he_capab[WPAS_MODE_INFRA].phy_cap[ |
| 178 | HE_PHYCAP_CHANNEL_WIDTH_SET_IDX]; |
| 179 | return he_capab; |
| 180 | } |
| 181 | |
| 182 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 183 | /* |
| 184 | * Get the number of concurrent channels that the HW can operate, but that are |
| 185 | * currently not in use by any of the wpa_supplicant interfaces. |
| 186 | */ |
| 187 | static int wpas_p2p_num_unused_channels(struct wpa_supplicant *wpa_s) |
| 188 | { |
| 189 | int *freqs; |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 190 | int num, unused; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 191 | |
| 192 | freqs = os_calloc(wpa_s->num_multichan_concurrent, sizeof(int)); |
| 193 | if (!freqs) |
| 194 | return -1; |
| 195 | |
| 196 | num = get_shared_radio_freqs(wpa_s, freqs, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 197 | wpa_s->num_multichan_concurrent, false); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 198 | os_free(freqs); |
| 199 | |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 200 | unused = wpa_s->num_multichan_concurrent - num; |
| 201 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: num_unused_channels: %d", unused); |
| 202 | return unused; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | |
| 206 | /* |
| 207 | * Get the frequencies that are currently in use by one or more of the virtual |
| 208 | * interfaces, and that are also valid for P2P operation. |
| 209 | */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 210 | static unsigned int |
| 211 | wpas_p2p_valid_oper_freqs(struct wpa_supplicant *wpa_s, |
| 212 | struct wpa_used_freq_data *p2p_freqs, |
| 213 | unsigned int len) |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 214 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 215 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 216 | unsigned int num, i, j; |
| 217 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 218 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 219 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 220 | if (!freqs) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 221 | return 0; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 222 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 223 | num = get_shared_radio_freqs_data(wpa_s, freqs, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 224 | wpa_s->num_multichan_concurrent, |
| 225 | false); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 226 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 227 | os_memset(p2p_freqs, 0, sizeof(struct wpa_used_freq_data) * len); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 228 | |
| 229 | for (i = 0, j = 0; i < num && j < len; i++) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 230 | if (p2p_supported_freq(wpa_s->global->p2p, freqs[i].freq)) |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 231 | p2p_freqs[j++] = freqs[i]; |
| 232 | } |
| 233 | |
| 234 | os_free(freqs); |
| 235 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 236 | dump_freq_data(wpa_s, "valid for P2P", p2p_freqs, j); |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 237 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 238 | return j; |
| 239 | } |
| 240 | |
| 241 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 242 | static void wpas_p2p_set_own_freq_preference(struct wpa_supplicant *wpa_s, |
| 243 | int freq) |
| 244 | { |
| 245 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 246 | return; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 247 | |
| 248 | /* Use the wpa_s used to control the P2P Device operation */ |
| 249 | wpa_s = wpa_s->global->p2p_init_wpa_s; |
| 250 | |
| 251 | if (wpa_s->conf->p2p_ignore_shared_freq && |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 252 | freq > 0 && wpa_s->num_multichan_concurrent > 1 && |
| 253 | wpas_p2p_num_unused_channels(wpa_s) > 0) { |
| 254 | wpa_printf(MSG_DEBUG, "P2P: Ignore own channel preference %d MHz due to p2p_ignore_shared_freq=1 configuration", |
| 255 | freq); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 256 | freq = 0; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 257 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 258 | p2p_set_own_freq_preference(wpa_s->global->p2p, freq); |
| 259 | } |
| 260 | |
| 261 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 262 | static void wpas_p2p_scan_res_handled(struct wpa_supplicant *wpa_s) |
| 263 | { |
| 264 | unsigned int delay = wpas_p2p_search_delay(wpa_s); |
| 265 | |
| 266 | /* In case of concurrent P2P and external scans, delay P2P search. */ |
| 267 | if (external_scan_running(wpa_s->radio)) { |
| 268 | delay = wpa_s->conf->p2p_search_delay; |
| 269 | wpa_printf(MSG_DEBUG, |
| 270 | "P2P: Delay next P2P search by %d ms to let externally triggered scan complete", |
| 271 | delay); |
| 272 | } |
| 273 | |
| 274 | p2p_scan_res_handled(wpa_s->global->p2p, delay); |
| 275 | } |
| 276 | |
| 277 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 278 | static void wpas_p2p_scan_res_handler(struct wpa_supplicant *wpa_s, |
| 279 | struct wpa_scan_results *scan_res) |
| 280 | { |
| 281 | size_t i; |
| 282 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 283 | if (wpa_s->p2p_scan_work) { |
| 284 | struct wpa_radio_work *work = wpa_s->p2p_scan_work; |
| 285 | wpa_s->p2p_scan_work = NULL; |
| 286 | radio_work_done(work); |
| 287 | } |
| 288 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 289 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 290 | return; |
| 291 | |
| 292 | wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS)", |
| 293 | (int) scan_res->num); |
| 294 | |
| 295 | for (i = 0; i < scan_res->num; i++) { |
| 296 | struct wpa_scan_res *bss = scan_res->res[i]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 297 | struct os_reltime time_tmp_age, entry_ts; |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 298 | const u8 *ies; |
| 299 | size_t ies_len; |
| 300 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 301 | time_tmp_age.sec = bss->age / 1000; |
| 302 | time_tmp_age.usec = (bss->age % 1000) * 1000; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 303 | os_reltime_sub(&scan_res->fetch_time, &time_tmp_age, &entry_ts); |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 304 | |
| 305 | ies = (const u8 *) (bss + 1); |
| 306 | ies_len = bss->ie_len; |
| 307 | if (bss->beacon_ie_len > 0 && |
| 308 | !wpa_scan_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) && |
| 309 | wpa_scan_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { |
| 310 | wpa_printf(MSG_DEBUG, "P2P: Use P2P IE(s) from Beacon frame since no P2P IE(s) in Probe Response frames received for " |
| 311 | MACSTR, MAC2STR(bss->bssid)); |
| 312 | ies = ies + ies_len; |
| 313 | ies_len = bss->beacon_ie_len; |
| 314 | } |
| 315 | |
| 316 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 317 | if (p2p_scan_res_handler(wpa_s->global->p2p, bss->bssid, |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 318 | bss->freq, &entry_ts, bss->level, |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 319 | ies, ies_len) > 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 320 | break; |
| 321 | } |
| 322 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 323 | wpas_p2p_scan_res_handled(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 327 | 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] | 328 | { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 329 | if (wpa_s->p2p_scan_work) { |
| 330 | struct wpa_radio_work *work = wpa_s->p2p_scan_work; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 331 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 332 | wpa_s->p2p_scan_work = NULL; |
| 333 | radio_work_done(work); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 336 | if (wpa_s->global->p2p_disabled || !wpa_s->global->p2p) |
| 337 | return; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 338 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 339 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 340 | "P2P: Failed to get scan results - try to continue"); |
| 341 | wpas_p2p_scan_res_handled(wpa_s); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 345 | void wpas_p2p_scan_freqs(struct wpa_supplicant *wpa_s, |
| 346 | struct wpa_driver_scan_params *params, |
| 347 | bool include_6ghz) |
| 348 | { |
| 349 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, |
| 350 | params, false, false, false); |
| 351 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211G, |
| 352 | params, false, false, false); |
| 353 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211AD, |
| 354 | params, false, false, false); |
| 355 | if (!wpa_s->conf->p2p_6ghz_disable && |
| 356 | is_p2p_allow_6ghz(wpa_s->global->p2p) && include_6ghz) |
| 357 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, |
| 358 | params, true, true, false); |
| 359 | } |
| 360 | |
| 361 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 362 | static void wpas_p2p_trigger_scan_cb(struct wpa_radio_work *work, int deinit) |
| 363 | { |
| 364 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 365 | struct wpa_driver_scan_params *params = work->ctx; |
| 366 | int ret; |
| 367 | |
| 368 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 369 | if (!work->started) { |
| 370 | wpa_scan_free_params(params); |
| 371 | return; |
| 372 | } |
| 373 | |
| 374 | wpa_s->p2p_scan_work = NULL; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 375 | return; |
| 376 | } |
| 377 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 378 | if (wpa_s->clear_driver_scan_cache) { |
| 379 | wpa_printf(MSG_DEBUG, |
| 380 | "Request driver to clear scan cache due to local BSS flush"); |
| 381 | params->only_new_results = 1; |
| 382 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 383 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 384 | if (!params->freqs) |
| 385 | wpas_p2p_scan_freqs(wpa_s, params, params->p2p_include_6ghz); |
| 386 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 387 | ret = wpa_drv_scan(wpa_s, params); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 388 | if (ret == 0) |
| 389 | wpa_s->curr_scan_cookie = params->scan_cookie; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 390 | wpa_scan_free_params(params); |
| 391 | work->ctx = NULL; |
| 392 | if (ret) { |
| 393 | radio_work_done(work); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 394 | p2p_notify_scan_trigger_status(wpa_s->global->p2p, ret); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 395 | return; |
| 396 | } |
| 397 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 398 | p2p_notify_scan_trigger_status(wpa_s->global->p2p, ret); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 399 | os_get_reltime(&wpa_s->scan_trigger_time); |
| 400 | wpa_s->scan_res_handler = wpas_p2p_scan_res_handler; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 401 | wpa_s->scan_res_fail_handler = wpas_p2p_scan_res_fail_handler; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 402 | wpa_s->own_scan_requested = 1; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 403 | wpa_s->clear_driver_scan_cache = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 404 | wpa_s->p2p_scan_work = work; |
| 405 | } |
| 406 | |
| 407 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 408 | static int wpas_p2p_search_social_channel(struct wpa_supplicant *wpa_s, |
| 409 | int freq) |
| 410 | { |
| 411 | if (wpa_s->global->p2p_24ghz_social_channels && |
| 412 | (freq == 2412 || freq == 2437 || freq == 2462)) { |
| 413 | /* |
| 414 | * Search all social channels regardless of whether these have |
| 415 | * been disabled for P2P operating channel use to avoid missing |
| 416 | * peers. |
| 417 | */ |
| 418 | return 1; |
| 419 | } |
| 420 | return p2p_supported_freq(wpa_s->global->p2p, freq); |
| 421 | } |
| 422 | |
| 423 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 424 | static int wpas_p2p_scan(void *ctx, enum p2p_scan_type type, int freq, |
| 425 | unsigned int num_req_dev_types, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 426 | const u8 *req_dev_types, const u8 *dev_id, u16 pw_id, |
| 427 | bool include_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 428 | { |
| 429 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 430 | struct wpa_driver_scan_params *params = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 431 | struct wpabuf *wps_ie, *ies; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 432 | unsigned int num_channels = 0; |
| 433 | int social_channels_freq[] = { 2412, 2437, 2462, 60480 }; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 434 | size_t ielen; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 435 | u8 *n, i; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 436 | unsigned int bands; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 437 | |
| 438 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 439 | return -1; |
| 440 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 441 | if (wpa_s->p2p_scan_work) { |
| 442 | wpa_dbg(wpa_s, MSG_INFO, "P2P: Reject scan trigger since one is already pending"); |
| 443 | return -1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 446 | params = os_zalloc(sizeof(*params)); |
| 447 | if (params == NULL) |
| 448 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 449 | |
| 450 | /* P2P Wildcard SSID */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 451 | params->num_ssids = 1; |
| 452 | n = os_malloc(P2P_WILDCARD_SSID_LEN); |
| 453 | if (n == NULL) |
| 454 | goto fail; |
| 455 | os_memcpy(n, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN); |
| 456 | params->ssids[0].ssid = n; |
| 457 | params->ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 458 | |
| 459 | wpa_s->wps->dev.p2p = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 460 | wps_ie = wps_build_probe_req_ie(pw_id, &wpa_s->wps->dev, |
| 461 | wpa_s->wps->uuid, WPS_REQ_ENROLLEE, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 462 | num_req_dev_types, req_dev_types); |
| 463 | if (wps_ie == NULL) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 464 | goto fail; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 465 | |
| 466 | /* |
| 467 | * In case 6 GHz channels are requested as part of the P2P scan, only |
| 468 | * the PSCs would be included as P2P GOs are not expected to be |
| 469 | * collocated, i.e., they would not be announced in the RNR element of |
| 470 | * other APs. |
| 471 | */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 472 | if (!wpa_s->conf->p2p_6ghz_disable) |
| 473 | params->p2p_include_6ghz = include_6ghz; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 474 | switch (type) { |
| 475 | case P2P_SCAN_SOCIAL: |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 476 | params->freqs = os_calloc(ARRAY_SIZE(social_channels_freq) + 1, |
| 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 | params->freqs[num_channels++] = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 487 | break; |
| 488 | case P2P_SCAN_FULL: |
| 489 | break; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 490 | case P2P_SCAN_SPECIFIC: |
| 491 | params->freqs = os_calloc(2, sizeof(int)); |
| 492 | if (params->freqs == NULL) |
| 493 | goto fail; |
| 494 | params->freqs[0] = freq; |
| 495 | params->freqs[1] = 0; |
| 496 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 497 | case P2P_SCAN_SOCIAL_PLUS_ONE: |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 498 | params->freqs = os_calloc(ARRAY_SIZE(social_channels_freq) + 2, |
| 499 | sizeof(int)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 500 | if (params->freqs == NULL) |
| 501 | goto fail; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 502 | for (i = 0; i < ARRAY_SIZE(social_channels_freq); i++) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 503 | if (wpas_p2p_search_social_channel( |
| 504 | wpa_s, social_channels_freq[i])) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 505 | params->freqs[num_channels++] = |
| 506 | social_channels_freq[i]; |
| 507 | } |
| 508 | if (p2p_supported_freq(wpa_s->global->p2p, freq)) |
| 509 | params->freqs[num_channels++] = freq; |
| 510 | params->freqs[num_channels++] = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 511 | break; |
| 512 | } |
| 513 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 514 | ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p); |
| 515 | ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen); |
| 516 | if (ies == NULL) { |
| 517 | wpabuf_free(wps_ie); |
| 518 | goto fail; |
| 519 | } |
| 520 | wpabuf_put_buf(ies, wps_ie); |
| 521 | wpabuf_free(wps_ie); |
| 522 | |
| 523 | bands = wpas_get_bands(wpa_s, params->freqs); |
| 524 | p2p_scan_ie(wpa_s->global->p2p, ies, dev_id, bands); |
| 525 | |
| 526 | params->p2p_probe = 1; |
| 527 | n = os_malloc(wpabuf_len(ies)); |
| 528 | if (n == NULL) { |
| 529 | wpabuf_free(ies); |
| 530 | goto fail; |
| 531 | } |
| 532 | os_memcpy(n, wpabuf_head(ies), wpabuf_len(ies)); |
| 533 | params->extra_ies = n; |
| 534 | params->extra_ies_len = wpabuf_len(ies); |
| 535 | wpabuf_free(ies); |
| 536 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 537 | radio_remove_works(wpa_s, "p2p-scan", 0); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 538 | if (radio_add_work(wpa_s, 0, "p2p-scan", 0, wpas_p2p_trigger_scan_cb, |
| 539 | params) < 0) |
| 540 | goto fail; |
| 541 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 542 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 543 | fail: |
| 544 | wpa_scan_free_params(params); |
| 545 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 549 | static enum wpa_driver_if_type wpas_p2p_if_type(int p2p_group_interface) |
| 550 | { |
| 551 | switch (p2p_group_interface) { |
| 552 | case P2P_GROUP_INTERFACE_PENDING: |
| 553 | return WPA_IF_P2P_GROUP; |
| 554 | case P2P_GROUP_INTERFACE_GO: |
| 555 | return WPA_IF_P2P_GO; |
| 556 | case P2P_GROUP_INTERFACE_CLIENT: |
| 557 | return WPA_IF_P2P_CLIENT; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 558 | default: |
| 559 | return WPA_IF_P2P_GROUP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 560 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | |
| 564 | static struct wpa_supplicant * wpas_get_p2p_group(struct wpa_supplicant *wpa_s, |
| 565 | const u8 *ssid, |
| 566 | size_t ssid_len, int *go) |
| 567 | { |
| 568 | struct wpa_ssid *s; |
| 569 | |
| 570 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 571 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 572 | if (s->disabled != 0 || !s->p2p_group || |
| 573 | s->ssid_len != ssid_len || |
| 574 | os_memcmp(ssid, s->ssid, ssid_len) != 0) |
| 575 | continue; |
| 576 | if (s->mode == WPAS_MODE_P2P_GO && |
| 577 | s != wpa_s->current_ssid) |
| 578 | continue; |
| 579 | if (go) |
| 580 | *go = s->mode == WPAS_MODE_P2P_GO; |
| 581 | return wpa_s; |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | return NULL; |
| 586 | } |
| 587 | |
| 588 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 589 | static void run_wpas_p2p_disconnect(void *eloop_ctx, void *timeout_ctx) |
| 590 | { |
| 591 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 592 | wpa_printf(MSG_DEBUG, |
| 593 | "P2P: Complete previously requested removal of %s", |
| 594 | wpa_s->ifname); |
| 595 | wpas_p2p_disconnect(wpa_s); |
| 596 | } |
| 597 | |
| 598 | |
| 599 | static int wpas_p2p_disconnect_safely(struct wpa_supplicant *wpa_s, |
| 600 | struct wpa_supplicant *calling_wpa_s) |
| 601 | { |
| 602 | if (calling_wpa_s == wpa_s && wpa_s && |
| 603 | wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) { |
| 604 | /* |
| 605 | * The calling wpa_s instance is going to be removed. Do that |
| 606 | * from an eloop callback to keep the instance available until |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 607 | * the caller has returned. This may be needed, e.g., to provide |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 608 | * control interface responses on the per-interface socket. |
| 609 | */ |
| 610 | if (eloop_register_timeout(0, 0, run_wpas_p2p_disconnect, |
| 611 | wpa_s, NULL) < 0) |
| 612 | return -1; |
| 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | return wpas_p2p_disconnect(wpa_s); |
| 617 | } |
| 618 | |
| 619 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 620 | /* Determine total number of clients in active groups where we are the GO */ |
| 621 | static unsigned int p2p_group_go_member_count(struct wpa_supplicant *wpa_s) |
| 622 | { |
| 623 | unsigned int count = 0; |
| 624 | struct wpa_ssid *s; |
| 625 | |
| 626 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 627 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 628 | wpa_printf(MSG_DEBUG, |
| 629 | "P2P: sup:%p ssid:%p disabled:%d p2p:%d mode:%d", |
| 630 | wpa_s, s, s->disabled, s->p2p_group, |
| 631 | s->mode); |
| 632 | if (!s->disabled && s->p2p_group && |
| 633 | s->mode == WPAS_MODE_P2P_GO) { |
| 634 | count += p2p_get_group_num_members( |
| 635 | wpa_s->p2p_group); |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | return count; |
| 641 | } |
| 642 | |
| 643 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 644 | static unsigned int p2p_is_active_persistent_group(struct wpa_supplicant *wpa_s) |
| 645 | { |
| 646 | return !wpa_s->p2p_mgmt && wpa_s->current_ssid && |
| 647 | !wpa_s->current_ssid->disabled && |
| 648 | wpa_s->current_ssid->p2p_group && |
| 649 | wpa_s->current_ssid->p2p_persistent_group; |
| 650 | } |
| 651 | |
| 652 | |
| 653 | static unsigned int p2p_is_active_persistent_go(struct wpa_supplicant *wpa_s) |
| 654 | { |
| 655 | return p2p_is_active_persistent_group(wpa_s) && |
| 656 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO; |
| 657 | } |
| 658 | |
| 659 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 660 | /* Find an interface for a P2P group where we are the GO */ |
| 661 | static struct wpa_supplicant * |
| 662 | wpas_p2p_get_go_group(struct wpa_supplicant *wpa_s) |
| 663 | { |
| 664 | struct wpa_supplicant *save = NULL; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 665 | |
| 666 | if (!wpa_s) |
| 667 | return NULL; |
| 668 | |
| 669 | 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] | 670 | if (!p2p_is_active_persistent_go(wpa_s)) |
| 671 | continue; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 672 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 673 | /* Prefer a group with connected clients */ |
| 674 | if (p2p_get_group_num_members(wpa_s->p2p_group)) |
| 675 | return wpa_s; |
| 676 | save = wpa_s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | /* No group with connected clients, so pick the one without (if any) */ |
| 680 | return save; |
| 681 | } |
| 682 | |
| 683 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 684 | 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] | 685 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 686 | return p2p_is_active_persistent_group(wpa_s) && |
| 687 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA; |
| 688 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 689 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 690 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 691 | /* Find an interface for a P2P group where we are the P2P Client */ |
| 692 | static struct wpa_supplicant * |
| 693 | wpas_p2p_get_cli_group(struct wpa_supplicant *wpa_s) |
| 694 | { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 695 | 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] | 696 | if (p2p_is_active_persistent_cli(wpa_s)) |
| 697 | return wpa_s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 698 | } |
| 699 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 700 | return NULL; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | |
| 704 | /* Find a persistent group where we are the GO */ |
| 705 | static struct wpa_ssid * |
| 706 | wpas_p2p_get_persistent_go(struct wpa_supplicant *wpa_s) |
| 707 | { |
| 708 | struct wpa_ssid *s; |
| 709 | |
| 710 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 711 | if (s->disabled == 2 && s->mode == WPAS_MODE_P2P_GO) |
| 712 | return s; |
| 713 | } |
| 714 | |
| 715 | return NULL; |
| 716 | } |
| 717 | |
| 718 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 719 | static u8 p2ps_group_capability(void *ctx, u8 incoming, u8 role, |
| 720 | unsigned int *force_freq, |
| 721 | unsigned int *pref_freq) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 722 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 723 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 724 | struct wpa_ssid *s; |
| 725 | u8 conncap = P2PS_SETUP_NONE; |
| 726 | unsigned int owned_members = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 727 | struct wpa_supplicant *go_wpa_s, *cli_wpa_s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 728 | struct wpa_ssid *persistent_go; |
| 729 | int p2p_no_group_iface; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 730 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 731 | unsigned int size; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 732 | |
| 733 | wpa_printf(MSG_DEBUG, "P2P: Conncap - in:%d role:%d", incoming, role); |
| 734 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 735 | if (force_freq) |
| 736 | *force_freq = 0; |
| 737 | if (pref_freq) |
| 738 | *pref_freq = 0; |
| 739 | |
| 740 | size = P2P_MAX_PREF_CHANNELS; |
| 741 | if (force_freq && pref_freq && |
| 742 | !wpas_p2p_setup_freqs(wpa_s, 0, (int *) force_freq, |
| 743 | (int *) pref_freq, 0, pref_freq_list, &size)) |
| 744 | wpas_p2p_set_own_freq_preference(wpa_s, |
| 745 | *force_freq ? *force_freq : |
| 746 | *pref_freq); |
| 747 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 748 | /* |
| 749 | * For non-concurrent capable devices: |
| 750 | * If persistent_go, then no new. |
| 751 | * If GO, then no client. |
| 752 | * If client, then no GO. |
| 753 | */ |
| 754 | go_wpa_s = wpas_p2p_get_go_group(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 755 | if (go_wpa_s) |
| 756 | owned_members = p2p_get_group_num_members(go_wpa_s->p2p_group); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 757 | persistent_go = wpas_p2p_get_persistent_go(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 758 | p2p_no_group_iface = !wpas_p2p_create_iface(wpa_s); |
| 759 | cli_wpa_s = wpas_p2p_get_cli_group(wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 760 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 761 | wpa_printf(MSG_DEBUG, |
| 762 | "P2P: GO(iface)=%p members=%u CLI(iface)=%p persistent(ssid)=%p", |
| 763 | go_wpa_s, owned_members, cli_wpa_s, persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 764 | |
| 765 | /* If not concurrent, restrict our choices */ |
| 766 | if (p2p_no_group_iface) { |
| 767 | wpa_printf(MSG_DEBUG, "P2P: p2p_no_group_iface"); |
| 768 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 769 | if (cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 770 | return P2PS_SETUP_NONE; |
| 771 | |
| 772 | if (go_wpa_s) { |
| 773 | if (role == P2PS_SETUP_CLIENT || |
| 774 | incoming == P2PS_SETUP_GROUP_OWNER || |
| 775 | p2p_client_limit_reached(go_wpa_s->p2p_group)) |
| 776 | return P2PS_SETUP_NONE; |
| 777 | |
| 778 | return P2PS_SETUP_GROUP_OWNER; |
| 779 | } |
| 780 | |
| 781 | if (persistent_go) { |
| 782 | if (role == P2PS_SETUP_NONE || role == P2PS_SETUP_NEW) { |
| 783 | if (!incoming) |
| 784 | return P2PS_SETUP_GROUP_OWNER | |
| 785 | P2PS_SETUP_CLIENT; |
| 786 | if (incoming == P2PS_SETUP_NEW) { |
| 787 | u8 r; |
| 788 | |
| 789 | if (os_get_random(&r, sizeof(r)) < 0 || |
| 790 | (r & 1)) |
| 791 | return P2PS_SETUP_CLIENT; |
| 792 | return P2PS_SETUP_GROUP_OWNER; |
| 793 | } |
| 794 | } |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | /* If a required role has been specified, handle it here */ |
| 799 | if (role && role != P2PS_SETUP_NEW) { |
| 800 | switch (incoming) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 801 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_NEW: |
| 802 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT: |
| 803 | /* |
| 804 | * Peer has an active GO, so if the role allows it and |
| 805 | * we do not have any active roles, become client. |
| 806 | */ |
| 807 | if ((role & P2PS_SETUP_CLIENT) && !go_wpa_s && |
| 808 | !cli_wpa_s) |
| 809 | return P2PS_SETUP_CLIENT; |
| 810 | |
| 811 | /* fall through */ |
| 812 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 813 | case P2PS_SETUP_NONE: |
| 814 | case P2PS_SETUP_NEW: |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 815 | conncap = role; |
| 816 | goto grp_owner; |
| 817 | |
| 818 | case P2PS_SETUP_GROUP_OWNER: |
| 819 | /* |
| 820 | * Must be a complimentary role - cannot be a client to |
| 821 | * more than one peer. |
| 822 | */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 823 | if (incoming == role || cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 824 | return P2PS_SETUP_NONE; |
| 825 | |
| 826 | return P2PS_SETUP_CLIENT; |
| 827 | |
| 828 | case P2PS_SETUP_CLIENT: |
| 829 | /* Must be a complimentary role */ |
| 830 | if (incoming != role) { |
| 831 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 832 | goto grp_owner; |
| 833 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 834 | /* fall through */ |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 835 | |
| 836 | default: |
| 837 | return P2PS_SETUP_NONE; |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | /* |
| 842 | * For now, we only will support ownership of one group, and being a |
| 843 | * client of one group. Therefore, if we have either an existing GO |
| 844 | * group, or an existing client group, we will not do a new GO |
| 845 | * negotiation, but rather try to re-use the existing groups. |
| 846 | */ |
| 847 | switch (incoming) { |
| 848 | case P2PS_SETUP_NONE: |
| 849 | case P2PS_SETUP_NEW: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 850 | if (cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 851 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 852 | else if (!owned_members) |
| 853 | conncap = P2PS_SETUP_NEW; |
| 854 | else if (incoming == P2PS_SETUP_NONE) |
| 855 | conncap = P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT; |
| 856 | else |
| 857 | conncap = P2PS_SETUP_CLIENT; |
| 858 | break; |
| 859 | |
| 860 | case P2PS_SETUP_CLIENT: |
| 861 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 862 | break; |
| 863 | |
| 864 | case P2PS_SETUP_GROUP_OWNER: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 865 | if (!cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 866 | conncap = P2PS_SETUP_CLIENT; |
| 867 | break; |
| 868 | |
| 869 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_NEW: |
| 870 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 871 | if (cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 872 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 873 | else { |
| 874 | u8 r; |
| 875 | |
| 876 | if (os_get_random(&r, sizeof(r)) < 0 || |
| 877 | (r & 1)) |
| 878 | conncap = P2PS_SETUP_CLIENT; |
| 879 | else |
| 880 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 881 | } |
| 882 | break; |
| 883 | |
| 884 | default: |
| 885 | return P2PS_SETUP_NONE; |
| 886 | } |
| 887 | |
| 888 | grp_owner: |
| 889 | if ((conncap & P2PS_SETUP_GROUP_OWNER) || |
| 890 | (!incoming && (conncap & P2PS_SETUP_NEW))) { |
| 891 | if (go_wpa_s && p2p_client_limit_reached(go_wpa_s->p2p_group)) |
| 892 | conncap &= ~P2PS_SETUP_GROUP_OWNER; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 893 | |
| 894 | s = wpas_p2p_get_persistent_go(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 895 | if (!s && !go_wpa_s && p2p_no_group_iface) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 896 | p2p_set_intended_addr(wpa_s->global->p2p, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 897 | wpa_s->p2p_mgmt ? |
| 898 | wpa_s->parent->own_addr : |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 899 | wpa_s->own_addr); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 900 | } else if (!s && !go_wpa_s) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 901 | if (wpas_p2p_add_group_interface(wpa_s, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 902 | WPA_IF_P2P_GROUP) < 0) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 903 | wpa_printf(MSG_ERROR, |
| 904 | "P2P: Failed to allocate a new interface for the group"); |
| 905 | return P2PS_SETUP_NONE; |
| 906 | } |
| 907 | wpa_s->global->pending_group_iface_for_p2ps = 1; |
| 908 | p2p_set_intended_addr(wpa_s->global->p2p, |
| 909 | wpa_s->pending_interface_addr); |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | return conncap; |
| 914 | } |
| 915 | |
| 916 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 917 | static int wpas_p2p_group_delete(struct wpa_supplicant *wpa_s, |
| 918 | enum p2p_group_removal_reason removal_reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 919 | { |
| 920 | struct wpa_ssid *ssid; |
| 921 | char *gtype; |
| 922 | const char *reason; |
| 923 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 924 | ssid = wpa_s->current_ssid; |
| 925 | if (ssid == NULL) { |
| 926 | /* |
| 927 | * The current SSID was not known, but there may still be a |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 928 | * pending P2P group interface waiting for provisioning or a |
| 929 | * P2P group that is trying to reconnect. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 930 | */ |
| 931 | ssid = wpa_s->conf->ssid; |
| 932 | while (ssid) { |
Jouni Malinen | 9d71283 | 2012-10-05 11:01:57 -0700 | [diff] [blame] | 933 | if (ssid->p2p_group && ssid->disabled != 2) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 934 | break; |
| 935 | ssid = ssid->next; |
| 936 | } |
Jouni Malinen | 5c44edb | 2012-08-31 21:35:32 +0300 | [diff] [blame] | 937 | if (ssid == NULL && |
| 938 | wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE) |
| 939 | { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 940 | wpa_printf(MSG_ERROR, "P2P: P2P group interface " |
| 941 | "not found"); |
| 942 | return -1; |
| 943 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 944 | } |
| 945 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO) |
| 946 | gtype = "GO"; |
| 947 | else if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT || |
| 948 | (ssid && ssid->mode == WPAS_MODE_INFRA)) { |
| 949 | wpa_s->reassociate = 0; |
| 950 | wpa_s->disconnected = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 951 | gtype = "client"; |
| 952 | } else |
| 953 | gtype = "GO"; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 954 | |
| 955 | if (removal_reason != P2P_GROUP_REMOVAL_SILENT && ssid) |
| 956 | wpas_notify_p2p_group_removed(wpa_s, ssid, gtype); |
| 957 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 958 | if (os_strcmp(gtype, "client") == 0) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 959 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 960 | if (eloop_is_timeout_registered(wpas_p2p_psk_failure_removal, |
| 961 | wpa_s, NULL)) { |
| 962 | wpa_printf(MSG_DEBUG, |
| 963 | "P2P: PSK failure removal was scheduled, so use PSK failure as reason for group removal"); |
| 964 | removal_reason = P2P_GROUP_REMOVAL_PSK_FAILURE; |
| 965 | eloop_cancel_timeout(wpas_p2p_psk_failure_removal, |
| 966 | wpa_s, NULL); |
| 967 | } |
| 968 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 969 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 970 | if (wpa_s->cross_connect_in_use) { |
| 971 | wpa_s->cross_connect_in_use = 0; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 972 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 973 | P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s", |
| 974 | wpa_s->ifname, wpa_s->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 975 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 976 | switch (removal_reason) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 977 | case P2P_GROUP_REMOVAL_REQUESTED: |
| 978 | reason = " reason=REQUESTED"; |
| 979 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 980 | case P2P_GROUP_REMOVAL_FORMATION_FAILED: |
| 981 | reason = " reason=FORMATION_FAILED"; |
| 982 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 983 | case P2P_GROUP_REMOVAL_IDLE_TIMEOUT: |
| 984 | reason = " reason=IDLE"; |
| 985 | break; |
| 986 | case P2P_GROUP_REMOVAL_UNAVAILABLE: |
| 987 | reason = " reason=UNAVAILABLE"; |
| 988 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 989 | case P2P_GROUP_REMOVAL_GO_ENDING_SESSION: |
| 990 | reason = " reason=GO_ENDING_SESSION"; |
| 991 | break; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 992 | case P2P_GROUP_REMOVAL_PSK_FAILURE: |
| 993 | reason = " reason=PSK_FAILURE"; |
| 994 | break; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 995 | case P2P_GROUP_REMOVAL_FREQ_CONFLICT: |
| 996 | reason = " reason=FREQ_CONFLICT"; |
| 997 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 998 | default: |
| 999 | reason = ""; |
| 1000 | break; |
| 1001 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1002 | if (removal_reason != P2P_GROUP_REMOVAL_SILENT) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1003 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1004 | P2P_EVENT_GROUP_REMOVED "%s %s%s", |
| 1005 | wpa_s->ifname, gtype, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1006 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1007 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1008 | if (eloop_cancel_timeout(wpas_p2p_group_freq_conflict, wpa_s, NULL) > 0) |
| 1009 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group freq_conflict timeout"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1010 | if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0) |
| 1011 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1012 | if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1013 | wpa_s->p2pdev, NULL) > 0) { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1014 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group formation " |
| 1015 | "timeout"); |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 1016 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1017 | wpas_p2p_group_formation_failed(wpa_s, 1); |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 1018 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1019 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 1020 | wpa_s->p2p_in_invitation = 0; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 1021 | wpa_s->p2p_retry_limit = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1022 | eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL); |
| 1023 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, wpa_s, NULL); |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 1024 | |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1025 | /* |
| 1026 | * Make sure wait for the first client does not remain active after the |
| 1027 | * group has been removed. |
| 1028 | */ |
| 1029 | wpa_s->global->p2p_go_wait_client.sec = 0; |
| 1030 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1031 | if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) { |
| 1032 | struct wpa_global *global; |
| 1033 | char *ifname; |
| 1034 | enum wpa_driver_if_type type; |
| 1035 | wpa_printf(MSG_DEBUG, "P2P: Remove group interface %s", |
| 1036 | wpa_s->ifname); |
| 1037 | global = wpa_s->global; |
| 1038 | ifname = os_strdup(wpa_s->ifname); |
| 1039 | type = wpas_p2p_if_type(wpa_s->p2p_group_interface); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1040 | eloop_cancel_timeout(run_wpas_p2p_disconnect, wpa_s, NULL); |
Dmitry Shmidt | e15c7b5 | 2011-08-03 15:04:35 -0700 | [diff] [blame] | 1041 | wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1042 | wpa_s = global->ifaces; |
| 1043 | if (wpa_s && ifname) |
| 1044 | wpa_drv_if_remove(wpa_s, type, ifname); |
| 1045 | os_free(ifname); |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 1046 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1049 | /* |
| 1050 | * The primary interface was used for P2P group operations, so |
| 1051 | * need to reset its p2pdev. |
| 1052 | */ |
| 1053 | wpa_s->p2pdev = wpa_s->parent; |
| 1054 | |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1055 | if (!wpa_s->p2p_go_group_formation_completed) { |
| 1056 | wpa_s->global->p2p_group_formation = NULL; |
| 1057 | wpa_s->p2p_in_provisioning = 0; |
| 1058 | } |
| 1059 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1060 | wpa_s->show_group_started = 0; |
| 1061 | os_free(wpa_s->go_params); |
| 1062 | wpa_s->go_params = NULL; |
| 1063 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1064 | os_free(wpa_s->p2p_group_common_freqs); |
| 1065 | wpa_s->p2p_group_common_freqs = NULL; |
| 1066 | wpa_s->p2p_group_common_freqs_num = 0; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1067 | wpa_s->p2p_go_do_acs = 0; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1068 | wpa_s->p2p_go_allow_dfs = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1069 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1070 | wpa_s->waiting_presence_resp = 0; |
| 1071 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1072 | wpa_printf(MSG_DEBUG, "P2P: Remove temporary group network"); |
| 1073 | if (ssid && (ssid->p2p_group || |
| 1074 | ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION || |
| 1075 | (ssid->key_mgmt & WPA_KEY_MGMT_WPS))) { |
| 1076 | int id = ssid->id; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1077 | if (ssid == wpa_s->current_ssid) { |
| 1078 | wpa_sm_set_config(wpa_s->wpa, NULL); |
| 1079 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1080 | wpa_s->current_ssid = NULL; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1081 | } |
| 1082 | /* |
| 1083 | * Networks objects created during any P2P activities are not |
| 1084 | * exposed out as they might/will confuse certain non-P2P aware |
| 1085 | * applications since these network objects won't behave like |
| 1086 | * regular ones. |
| 1087 | * |
| 1088 | * Likewise, we don't send out network removed signals for such |
| 1089 | * network objects. |
| 1090 | */ |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1091 | wpas_notify_network_removed(wpa_s, ssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1092 | wpa_config_remove_network(wpa_s->conf, id); |
| 1093 | wpa_supplicant_clear_status(wpa_s); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1094 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1095 | } else { |
| 1096 | wpa_printf(MSG_DEBUG, "P2P: Temporary group network not " |
| 1097 | "found"); |
| 1098 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1099 | if (wpa_s->ap_iface) |
| 1100 | wpa_supplicant_ap_deinit(wpa_s); |
| 1101 | else |
| 1102 | wpa_drv_deinit_p2p_cli(wpa_s); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1103 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1104 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
| 1105 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1106 | wpa_s->p2p_go_no_pri_sec_switch = 0; |
| 1107 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1108 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | |
| 1112 | static int wpas_p2p_persistent_group(struct wpa_supplicant *wpa_s, |
| 1113 | u8 *go_dev_addr, |
| 1114 | const u8 *ssid, size_t ssid_len) |
| 1115 | { |
| 1116 | struct wpa_bss *bss; |
| 1117 | const u8 *bssid; |
| 1118 | struct wpabuf *p2p; |
| 1119 | u8 group_capab; |
| 1120 | const u8 *addr; |
| 1121 | |
| 1122 | if (wpa_s->go_params) |
| 1123 | bssid = wpa_s->go_params->peer_interface_addr; |
| 1124 | else |
| 1125 | bssid = wpa_s->bssid; |
| 1126 | |
| 1127 | bss = wpa_bss_get(wpa_s, bssid, ssid, ssid_len); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1128 | if (bss == NULL && wpa_s->go_params && |
| 1129 | !is_zero_ether_addr(wpa_s->go_params->peer_device_addr)) |
| 1130 | bss = wpa_bss_get_p2p_dev_addr( |
| 1131 | wpa_s, wpa_s->go_params->peer_device_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1132 | if (bss == NULL) { |
| 1133 | u8 iface_addr[ETH_ALEN]; |
| 1134 | if (p2p_get_interface_addr(wpa_s->global->p2p, bssid, |
| 1135 | iface_addr) == 0) |
| 1136 | bss = wpa_bss_get(wpa_s, iface_addr, ssid, ssid_len); |
| 1137 | } |
| 1138 | if (bss == NULL) { |
| 1139 | wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether " |
| 1140 | "group is persistent - BSS " MACSTR " not found", |
| 1141 | MAC2STR(bssid)); |
| 1142 | return 0; |
| 1143 | } |
| 1144 | |
| 1145 | p2p = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE); |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1146 | if (p2p == NULL) |
| 1147 | p2p = wpa_bss_get_vendor_ie_multi_beacon(bss, |
| 1148 | P2P_IE_VENDOR_TYPE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1149 | if (p2p == NULL) { |
| 1150 | wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether " |
| 1151 | "group is persistent - BSS " MACSTR |
| 1152 | " did not include P2P IE", MAC2STR(bssid)); |
| 1153 | wpa_hexdump(MSG_DEBUG, "P2P: Probe Response IEs", |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1154 | wpa_bss_ie_ptr(bss), bss->ie_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1155 | wpa_hexdump(MSG_DEBUG, "P2P: Beacon IEs", |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1156 | wpa_bss_ie_ptr(bss) + bss->ie_len, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1157 | bss->beacon_ie_len); |
| 1158 | return 0; |
| 1159 | } |
| 1160 | |
| 1161 | group_capab = p2p_get_group_capab(p2p); |
| 1162 | addr = p2p_get_go_dev_addr(p2p); |
| 1163 | wpa_printf(MSG_DEBUG, "P2P: Checking whether group is persistent: " |
| 1164 | "group_capab=0x%x", group_capab); |
| 1165 | if (addr) { |
| 1166 | os_memcpy(go_dev_addr, addr, ETH_ALEN); |
| 1167 | wpa_printf(MSG_DEBUG, "P2P: GO Device Address " MACSTR, |
| 1168 | MAC2STR(addr)); |
| 1169 | } else |
| 1170 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 1171 | wpabuf_free(p2p); |
| 1172 | |
| 1173 | wpa_printf(MSG_DEBUG, "P2P: BSS " MACSTR " group_capab=0x%x " |
| 1174 | "go_dev_addr=" MACSTR, |
| 1175 | MAC2STR(bssid), group_capab, MAC2STR(go_dev_addr)); |
| 1176 | |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 1177 | return !!(group_capab & P2P_GROUP_CAPAB_PERSISTENT_GROUP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1181 | static int wpas_p2p_store_persistent_group(struct wpa_supplicant *wpa_s, |
| 1182 | struct wpa_ssid *ssid, |
| 1183 | const u8 *go_dev_addr) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1184 | { |
| 1185 | struct wpa_ssid *s; |
| 1186 | int changed = 0; |
| 1187 | |
| 1188 | wpa_printf(MSG_DEBUG, "P2P: Storing credentials for a persistent " |
| 1189 | "group (GO Dev Addr " MACSTR ")", MAC2STR(go_dev_addr)); |
| 1190 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 1191 | if (s->disabled == 2 && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1192 | ether_addr_equal(go_dev_addr, s->bssid) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1193 | s->ssid_len == ssid->ssid_len && |
| 1194 | os_memcmp(ssid->ssid, s->ssid, ssid->ssid_len) == 0) |
| 1195 | break; |
| 1196 | } |
| 1197 | |
| 1198 | if (s) { |
| 1199 | wpa_printf(MSG_DEBUG, "P2P: Update existing persistent group " |
| 1200 | "entry"); |
| 1201 | if (ssid->passphrase && !s->passphrase) |
| 1202 | changed = 1; |
| 1203 | else if (ssid->passphrase && s->passphrase && |
| 1204 | os_strcmp(ssid->passphrase, s->passphrase) != 0) |
| 1205 | changed = 1; |
| 1206 | } else { |
| 1207 | wpa_printf(MSG_DEBUG, "P2P: Create a new persistent group " |
| 1208 | "entry"); |
| 1209 | changed = 1; |
| 1210 | s = wpa_config_add_network(wpa_s->conf); |
| 1211 | if (s == NULL) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1212 | return -1; |
| 1213 | |
| 1214 | /* |
| 1215 | * Instead of network_added we emit persistent_group_added |
| 1216 | * notification. Also to keep the defense checks in |
| 1217 | * persistent_group obj registration method, we set the |
| 1218 | * relevant flags in s to designate it as a persistent group. |
| 1219 | */ |
| 1220 | s->p2p_group = 1; |
| 1221 | s->p2p_persistent_group = 1; |
| 1222 | wpas_notify_persistent_group_added(wpa_s, s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1223 | wpa_config_set_network_defaults(s); |
| 1224 | } |
| 1225 | |
| 1226 | s->p2p_group = 1; |
| 1227 | s->p2p_persistent_group = 1; |
| 1228 | s->disabled = 2; |
| 1229 | s->bssid_set = 1; |
| 1230 | os_memcpy(s->bssid, go_dev_addr, ETH_ALEN); |
| 1231 | s->mode = ssid->mode; |
| 1232 | s->auth_alg = WPA_AUTH_ALG_OPEN; |
| 1233 | s->key_mgmt = WPA_KEY_MGMT_PSK; |
| 1234 | s->proto = WPA_PROTO_RSN; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1235 | s->pbss = ssid->pbss; |
| 1236 | s->pairwise_cipher = ssid->pbss ? WPA_CIPHER_GCMP : WPA_CIPHER_CCMP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1237 | s->export_keys = 1; |
| 1238 | if (ssid->passphrase) { |
| 1239 | os_free(s->passphrase); |
| 1240 | s->passphrase = os_strdup(ssid->passphrase); |
| 1241 | } |
| 1242 | if (ssid->psk_set) { |
| 1243 | s->psk_set = 1; |
| 1244 | os_memcpy(s->psk, ssid->psk, 32); |
| 1245 | } |
| 1246 | if (s->passphrase && !s->psk_set) |
| 1247 | wpa_config_update_psk(s); |
| 1248 | if (s->ssid == NULL || s->ssid_len < ssid->ssid_len) { |
| 1249 | os_free(s->ssid); |
| 1250 | s->ssid = os_malloc(ssid->ssid_len); |
| 1251 | } |
| 1252 | if (s->ssid) { |
| 1253 | s->ssid_len = ssid->ssid_len; |
| 1254 | os_memcpy(s->ssid, ssid->ssid, s->ssid_len); |
| 1255 | } |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1256 | if (ssid->mode == WPAS_MODE_P2P_GO && wpa_s->global->add_psk) { |
| 1257 | dl_list_add(&s->psk_list, &wpa_s->global->add_psk->list); |
| 1258 | wpa_s->global->add_psk = NULL; |
| 1259 | changed = 1; |
| 1260 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1261 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1262 | if (changed && wpa_s->conf->update_config && |
| 1263 | wpa_config_write(wpa_s->confname, wpa_s->conf)) { |
| 1264 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
| 1265 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1266 | |
| 1267 | return s->id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1271 | static void wpas_p2p_add_persistent_group_client(struct wpa_supplicant *wpa_s, |
| 1272 | const u8 *addr) |
| 1273 | { |
| 1274 | struct wpa_ssid *ssid, *s; |
| 1275 | u8 *n; |
| 1276 | size_t i; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1277 | int found = 0; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1278 | 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] | 1279 | |
| 1280 | ssid = wpa_s->current_ssid; |
| 1281 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || |
| 1282 | !ssid->p2p_persistent_group) |
| 1283 | return; |
| 1284 | |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1285 | for (s = p2p_wpa_s->conf->ssid; s; s = s->next) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1286 | if (s->disabled != 2 || s->mode != WPAS_MODE_P2P_GO) |
| 1287 | continue; |
| 1288 | |
| 1289 | if (s->ssid_len == ssid->ssid_len && |
| 1290 | os_memcmp(s->ssid, ssid->ssid, s->ssid_len) == 0) |
| 1291 | break; |
| 1292 | } |
| 1293 | |
| 1294 | if (s == NULL) |
| 1295 | return; |
| 1296 | |
| 1297 | for (i = 0; s->p2p_client_list && i < s->num_p2p_clients; i++) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1298 | if (!ether_addr_equal(s->p2p_client_list + i * 2 * ETH_ALEN, |
| 1299 | addr)) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1300 | continue; |
| 1301 | |
| 1302 | if (i == s->num_p2p_clients - 1) |
| 1303 | return; /* already the most recent entry */ |
| 1304 | |
| 1305 | /* move the entry to mark it most recent */ |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1306 | os_memmove(s->p2p_client_list + i * 2 * ETH_ALEN, |
| 1307 | s->p2p_client_list + (i + 1) * 2 * ETH_ALEN, |
| 1308 | (s->num_p2p_clients - i - 1) * 2 * ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1309 | os_memcpy(s->p2p_client_list + |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1310 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN, addr, |
| 1311 | ETH_ALEN); |
| 1312 | os_memset(s->p2p_client_list + |
| 1313 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN + ETH_ALEN, |
| 1314 | 0xff, ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1315 | found = 1; |
| 1316 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1317 | } |
| 1318 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1319 | if (!found && s->num_p2p_clients < P2P_MAX_STORED_CLIENTS) { |
| 1320 | n = os_realloc_array(s->p2p_client_list, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1321 | s->num_p2p_clients + 1, 2 * ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1322 | if (n == NULL) |
| 1323 | return; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1324 | os_memcpy(n + s->num_p2p_clients * 2 * ETH_ALEN, addr, |
| 1325 | ETH_ALEN); |
| 1326 | os_memset(n + s->num_p2p_clients * 2 * ETH_ALEN + ETH_ALEN, |
| 1327 | 0xff, ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1328 | s->p2p_client_list = n; |
| 1329 | s->num_p2p_clients++; |
Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 1330 | } else if (!found && s->p2p_client_list) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1331 | /* Not enough room for an additional entry - drop the oldest |
| 1332 | * entry */ |
| 1333 | os_memmove(s->p2p_client_list, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1334 | s->p2p_client_list + 2 * ETH_ALEN, |
| 1335 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1336 | os_memcpy(s->p2p_client_list + |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1337 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1338 | addr, ETH_ALEN); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1339 | os_memset(s->p2p_client_list + |
| 1340 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN + ETH_ALEN, |
| 1341 | 0xff, ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1342 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1343 | |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1344 | if (p2p_wpa_s->conf->update_config && |
| 1345 | wpa_config_write(p2p_wpa_s->confname, p2p_wpa_s->conf)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1346 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1350 | static void wpas_p2p_group_started(struct wpa_supplicant *wpa_s, |
| 1351 | int go, struct wpa_ssid *ssid, int freq, |
| 1352 | const u8 *psk, const char *passphrase, |
| 1353 | const u8 *go_dev_addr, int persistent, |
| 1354 | const char *extra) |
| 1355 | { |
| 1356 | const char *ssid_txt; |
| 1357 | char psk_txt[65]; |
| 1358 | |
| 1359 | if (psk) |
| 1360 | wpa_snprintf_hex(psk_txt, sizeof(psk_txt), psk, 32); |
| 1361 | else |
| 1362 | psk_txt[0] = '\0'; |
| 1363 | |
| 1364 | if (ssid) |
| 1365 | ssid_txt = wpa_ssid_txt(ssid->ssid, ssid->ssid_len); |
| 1366 | else |
| 1367 | ssid_txt = ""; |
| 1368 | |
| 1369 | if (passphrase && passphrase[0] == '\0') |
| 1370 | passphrase = NULL; |
| 1371 | |
| 1372 | /* |
| 1373 | * Include PSK/passphrase only in the control interface message and |
| 1374 | * leave it out from the debug log entry. |
| 1375 | */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1376 | wpa_msg_global_ctrl(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1377 | P2P_EVENT_GROUP_STARTED |
| 1378 | "%s %s ssid=\"%s\" freq=%d%s%s%s%s%s go_dev_addr=" |
| 1379 | MACSTR "%s%s", |
| 1380 | wpa_s->ifname, go ? "GO" : "client", ssid_txt, freq, |
| 1381 | psk ? " psk=" : "", psk_txt, |
| 1382 | passphrase ? " passphrase=\"" : "", |
| 1383 | passphrase ? passphrase : "", |
| 1384 | passphrase ? "\"" : "", |
| 1385 | MAC2STR(go_dev_addr), |
| 1386 | persistent ? " [PERSISTENT]" : "", extra); |
| 1387 | wpa_printf(MSG_INFO, P2P_EVENT_GROUP_STARTED |
| 1388 | "%s %s ssid=\"%s\" freq=%d go_dev_addr=" MACSTR "%s%s", |
| 1389 | wpa_s->ifname, go ? "GO" : "client", ssid_txt, freq, |
| 1390 | MAC2STR(go_dev_addr), persistent ? " [PERSISTENT]" : "", |
| 1391 | extra); |
| 1392 | } |
| 1393 | |
| 1394 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1395 | static void wpas_group_formation_completed(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 1396 | int success, int already_deleted) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1397 | { |
| 1398 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1399 | int client; |
| 1400 | int persistent; |
| 1401 | u8 go_dev_addr[ETH_ALEN]; |
| 1402 | |
| 1403 | /* |
| 1404 | * This callback is likely called for the main interface. Update wpa_s |
| 1405 | * to use the group interface if a new interface was created for the |
| 1406 | * group. |
| 1407 | */ |
| 1408 | if (wpa_s->global->p2p_group_formation) |
| 1409 | wpa_s = wpa_s->global->p2p_group_formation; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1410 | if (wpa_s->p2p_go_group_formation_completed) { |
| 1411 | wpa_s->global->p2p_group_formation = NULL; |
| 1412 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1413 | } else if (wpa_s->p2p_in_provisioning && !success) { |
| 1414 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1415 | "P2P: Stop provisioning state due to failure"); |
| 1416 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1417 | } |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 1418 | wpa_s->p2p_in_invitation = 0; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 1419 | wpa_s->p2p_retry_limit = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1420 | wpa_s->group_formation_reported = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1421 | |
| 1422 | if (!success) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1423 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1424 | P2P_EVENT_GROUP_FORMATION_FAILURE); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1425 | wpas_notify_p2p_group_formation_failure(wpa_s, ""); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 1426 | if (already_deleted) |
| 1427 | return; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1428 | wpas_p2p_group_delete(wpa_s, |
| 1429 | P2P_GROUP_REMOVAL_FORMATION_FAILED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1430 | return; |
| 1431 | } |
| 1432 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1433 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1434 | P2P_EVENT_GROUP_FORMATION_SUCCESS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1435 | |
| 1436 | ssid = wpa_s->current_ssid; |
| 1437 | if (ssid && ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) { |
| 1438 | ssid->mode = WPAS_MODE_P2P_GO; |
| 1439 | p2p_group_notif_formation_done(wpa_s->p2p_group); |
| 1440 | wpa_supplicant_ap_mac_addr_filter(wpa_s, NULL); |
| 1441 | } |
| 1442 | |
| 1443 | persistent = 0; |
| 1444 | if (ssid) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1445 | client = ssid->mode == WPAS_MODE_INFRA; |
| 1446 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 1447 | persistent = ssid->p2p_persistent_group; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 1448 | os_memcpy(go_dev_addr, wpa_s->global->p2p_dev_addr, |
| 1449 | ETH_ALEN); |
George Burgess IV | 0d2d1bf | 2021-11-01 03:08:33 -0700 | [diff] [blame] | 1450 | } else { |
| 1451 | os_memset(go_dev_addr, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1452 | persistent = wpas_p2p_persistent_group(wpa_s, |
| 1453 | go_dev_addr, |
| 1454 | ssid->ssid, |
| 1455 | ssid->ssid_len); |
George Burgess IV | 0d2d1bf | 2021-11-01 03:08:33 -0700 | [diff] [blame] | 1456 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1457 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1458 | client = wpa_s->p2p_group_interface == |
| 1459 | P2P_GROUP_INTERFACE_CLIENT; |
| 1460 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 1461 | } |
| 1462 | |
| 1463 | wpa_s->show_group_started = 0; |
| 1464 | if (client) { |
| 1465 | /* |
| 1466 | * Indicate event only after successfully completed 4-way |
| 1467 | * handshake, i.e., when the interface is ready for data |
| 1468 | * packets. |
| 1469 | */ |
| 1470 | wpa_s->show_group_started = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1471 | } else { |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1472 | wpas_p2p_group_started(wpa_s, 1, ssid, |
| 1473 | ssid ? ssid->frequency : 0, |
| 1474 | ssid && ssid->passphrase == NULL && |
| 1475 | ssid->psk_set ? ssid->psk : NULL, |
| 1476 | ssid ? ssid->passphrase : NULL, |
| 1477 | go_dev_addr, persistent, ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1478 | wpas_p2p_cross_connect_setup(wpa_s); |
| 1479 | wpas_p2p_set_group_idle_timeout(wpa_s); |
| 1480 | } |
| 1481 | |
| 1482 | if (persistent) |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1483 | wpas_p2p_store_persistent_group(wpa_s->p2pdev, |
| 1484 | ssid, go_dev_addr); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1485 | else { |
| 1486 | os_free(wpa_s->global->add_psk); |
| 1487 | wpa_s->global->add_psk = NULL; |
| 1488 | } |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1489 | |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 1490 | if (!client) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1491 | wpas_notify_p2p_group_started(wpa_s, ssid, persistent, 0, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1492 | os_get_reltime(&wpa_s->global->p2p_go_wait_client); |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 1493 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1497 | struct send_action_work { |
| 1498 | unsigned int freq; |
| 1499 | u8 dst[ETH_ALEN]; |
| 1500 | u8 src[ETH_ALEN]; |
| 1501 | u8 bssid[ETH_ALEN]; |
| 1502 | size_t len; |
| 1503 | unsigned int wait_time; |
| 1504 | u8 buf[0]; |
| 1505 | }; |
| 1506 | |
| 1507 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1508 | static void wpas_p2p_free_send_action_work(struct wpa_supplicant *wpa_s) |
| 1509 | { |
| 1510 | struct send_action_work *awork = wpa_s->p2p_send_action_work->ctx; |
| 1511 | |
| 1512 | wpa_printf(MSG_DEBUG, |
| 1513 | "P2P: Free Action frame radio work @%p (freq=%u dst=" |
| 1514 | MACSTR " src=" MACSTR " bssid=" MACSTR " wait_time=%u)", |
| 1515 | wpa_s->p2p_send_action_work, awork->freq, |
| 1516 | MAC2STR(awork->dst), MAC2STR(awork->src), |
| 1517 | MAC2STR(awork->bssid), awork->wait_time); |
| 1518 | wpa_hexdump(MSG_DEBUG, "P2P: Freeing pending Action frame", |
| 1519 | awork->buf, awork->len); |
| 1520 | os_free(awork); |
| 1521 | wpa_s->p2p_send_action_work->ctx = NULL; |
| 1522 | radio_work_done(wpa_s->p2p_send_action_work); |
| 1523 | wpa_s->p2p_send_action_work = NULL; |
| 1524 | } |
| 1525 | |
| 1526 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1527 | static void wpas_p2p_send_action_work_timeout(void *eloop_ctx, |
| 1528 | void *timeout_ctx) |
| 1529 | { |
| 1530 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 1531 | |
| 1532 | if (!wpa_s->p2p_send_action_work) |
| 1533 | return; |
| 1534 | |
| 1535 | wpa_printf(MSG_DEBUG, "P2P: Send Action frame radio work timed out"); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1536 | wpas_p2p_free_send_action_work(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 1540 | static void wpas_p2p_action_tx_clear(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1541 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1542 | if (wpa_s->p2p_send_action_work) { |
| 1543 | struct send_action_work *awork; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1544 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1545 | awork = wpa_s->p2p_send_action_work->ctx; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1546 | wpa_printf(MSG_DEBUG, |
| 1547 | "P2P: Clear Action TX work @%p (wait_time=%u)", |
| 1548 | wpa_s->p2p_send_action_work, awork->wait_time); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1549 | if (awork->wait_time == 0) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1550 | wpas_p2p_free_send_action_work(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1551 | } else { |
| 1552 | /* |
| 1553 | * In theory, this should not be needed, but number of |
| 1554 | * places in the P2P code is still using non-zero wait |
| 1555 | * time for the last Action frame in the sequence and |
| 1556 | * some of these do not call send_action_done(). |
| 1557 | */ |
| 1558 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 1559 | wpa_s, NULL); |
| 1560 | eloop_register_timeout( |
| 1561 | 0, awork->wait_time * 1000, |
| 1562 | wpas_p2p_send_action_work_timeout, |
| 1563 | wpa_s, NULL); |
| 1564 | } |
| 1565 | } |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | |
| 1569 | static void wpas_p2p_send_action_tx_status(struct wpa_supplicant *wpa_s, |
| 1570 | unsigned int freq, |
| 1571 | const u8 *dst, const u8 *src, |
| 1572 | const u8 *bssid, |
| 1573 | const u8 *data, size_t data_len, |
| 1574 | enum offchannel_send_action_result |
| 1575 | result) |
| 1576 | { |
| 1577 | enum p2p_send_action_result res = P2P_SEND_ACTION_SUCCESS; |
| 1578 | |
| 1579 | wpas_p2p_action_tx_clear(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1580 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1581 | if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) |
| 1582 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1583 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1584 | switch (result) { |
| 1585 | case OFFCHANNEL_SEND_ACTION_SUCCESS: |
| 1586 | res = P2P_SEND_ACTION_SUCCESS; |
| 1587 | break; |
| 1588 | case OFFCHANNEL_SEND_ACTION_NO_ACK: |
| 1589 | res = P2P_SEND_ACTION_NO_ACK; |
| 1590 | break; |
| 1591 | case OFFCHANNEL_SEND_ACTION_FAILED: |
| 1592 | res = P2P_SEND_ACTION_FAILED; |
| 1593 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1594 | } |
| 1595 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1596 | 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] | 1597 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1598 | if (result != OFFCHANNEL_SEND_ACTION_SUCCESS && |
| 1599 | wpa_s->pending_pd_before_join && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1600 | (ether_addr_equal(dst, wpa_s->pending_join_dev_addr) || |
| 1601 | ether_addr_equal(dst, wpa_s->pending_join_iface_addr)) && |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1602 | wpa_s->p2p_fallback_to_go_neg) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1603 | wpa_s->pending_pd_before_join = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1604 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No ACK for PD Req " |
| 1605 | "during p2p_connect-auto"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1606 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1607 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 1608 | "reason=no-ACK-to-PD-Req"); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1609 | wpas_p2p_fallback_to_go_neg(wpa_s, 0); |
| 1610 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1611 | } |
| 1612 | } |
| 1613 | |
| 1614 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1615 | static void wpas_send_action_cb(struct wpa_radio_work *work, int deinit) |
| 1616 | { |
| 1617 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 1618 | struct send_action_work *awork = work->ctx; |
| 1619 | |
| 1620 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 1621 | if (work->started) { |
| 1622 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 1623 | wpa_s, NULL); |
| 1624 | wpa_s->p2p_send_action_work = NULL; |
| 1625 | offchannel_send_action_done(wpa_s); |
| 1626 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1627 | os_free(awork); |
| 1628 | return; |
| 1629 | } |
| 1630 | |
| 1631 | if (offchannel_send_action(wpa_s, awork->freq, awork->dst, awork->src, |
| 1632 | awork->bssid, awork->buf, awork->len, |
| 1633 | awork->wait_time, |
| 1634 | wpas_p2p_send_action_tx_status, 1) < 0) { |
| 1635 | os_free(awork); |
| 1636 | radio_work_done(work); |
| 1637 | return; |
| 1638 | } |
| 1639 | wpa_s->p2p_send_action_work = work; |
| 1640 | } |
| 1641 | |
| 1642 | |
| 1643 | static int wpas_send_action_work(struct wpa_supplicant *wpa_s, |
| 1644 | unsigned int freq, const u8 *dst, |
| 1645 | const u8 *src, const u8 *bssid, const u8 *buf, |
| 1646 | size_t len, unsigned int wait_time) |
| 1647 | { |
| 1648 | struct send_action_work *awork; |
| 1649 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1650 | if (radio_work_pending(wpa_s, "p2p-send-action")) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1651 | wpa_printf(MSG_DEBUG, "P2P: Cannot schedule new p2p-send-action work since one is already pending"); |
| 1652 | return -1; |
| 1653 | } |
| 1654 | |
| 1655 | awork = os_zalloc(sizeof(*awork) + len); |
| 1656 | if (awork == NULL) |
| 1657 | return -1; |
| 1658 | |
| 1659 | awork->freq = freq; |
| 1660 | os_memcpy(awork->dst, dst, ETH_ALEN); |
| 1661 | os_memcpy(awork->src, src, ETH_ALEN); |
| 1662 | os_memcpy(awork->bssid, bssid, ETH_ALEN); |
| 1663 | awork->len = len; |
| 1664 | awork->wait_time = wait_time; |
| 1665 | os_memcpy(awork->buf, buf, len); |
| 1666 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1667 | if (radio_add_work(wpa_s, freq, "p2p-send-action", 1, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1668 | wpas_send_action_cb, awork) < 0) { |
| 1669 | os_free(awork); |
| 1670 | return -1; |
| 1671 | } |
| 1672 | |
| 1673 | return 0; |
| 1674 | } |
| 1675 | |
| 1676 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1677 | static int wpas_send_action(void *ctx, unsigned int freq, const u8 *dst, |
| 1678 | const u8 *src, const u8 *bssid, const u8 *buf, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1679 | size_t len, unsigned int wait_time, int *scheduled) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1680 | { |
| 1681 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1682 | int listen_freq = -1, send_freq = -1; |
| 1683 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1684 | if (scheduled) |
| 1685 | *scheduled = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1686 | if (wpa_s->p2p_listen_work) |
| 1687 | listen_freq = wpa_s->p2p_listen_work->freq; |
| 1688 | if (wpa_s->p2p_send_action_work) |
| 1689 | send_freq = wpa_s->p2p_send_action_work->freq; |
| 1690 | if (listen_freq != (int) freq && send_freq != (int) freq) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1691 | int res; |
| 1692 | |
| 1693 | wpa_printf(MSG_DEBUG, "P2P: Schedule new radio work for Action frame TX (listen_freq=%d send_freq=%d freq=%u)", |
| 1694 | listen_freq, send_freq, freq); |
| 1695 | res = wpas_send_action_work(wpa_s, freq, dst, src, bssid, buf, |
| 1696 | len, wait_time); |
| 1697 | if (res == 0 && scheduled) |
| 1698 | *scheduled = 1; |
| 1699 | return res; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | 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] | 1703 | return offchannel_send_action(wpa_s, freq, dst, src, bssid, buf, len, |
| 1704 | wait_time, |
| 1705 | wpas_p2p_send_action_tx_status, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1706 | } |
| 1707 | |
| 1708 | |
| 1709 | static void wpas_send_action_done(void *ctx) |
| 1710 | { |
| 1711 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1712 | |
| 1713 | if (wpa_s->p2p_send_action_work) { |
| 1714 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 1715 | wpa_s, NULL); |
| 1716 | os_free(wpa_s->p2p_send_action_work->ctx); |
| 1717 | radio_work_done(wpa_s->p2p_send_action_work); |
| 1718 | wpa_s->p2p_send_action_work = NULL; |
| 1719 | } |
| 1720 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1721 | offchannel_send_action_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | |
| 1725 | static int wpas_copy_go_neg_results(struct wpa_supplicant *wpa_s, |
| 1726 | struct p2p_go_neg_results *params) |
| 1727 | { |
| 1728 | if (wpa_s->go_params == NULL) { |
| 1729 | wpa_s->go_params = os_malloc(sizeof(*params)); |
| 1730 | if (wpa_s->go_params == NULL) |
| 1731 | return -1; |
| 1732 | } |
| 1733 | os_memcpy(wpa_s->go_params, params, sizeof(*params)); |
| 1734 | return 0; |
| 1735 | } |
| 1736 | |
| 1737 | |
| 1738 | static void wpas_start_wps_enrollee(struct wpa_supplicant *wpa_s, |
| 1739 | struct p2p_go_neg_results *res) |
| 1740 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1741 | wpa_s->group_formation_reported = 0; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1742 | wpa_printf(MSG_DEBUG, "P2P: Start WPS Enrollee for peer " MACSTR |
| 1743 | " dev_addr " MACSTR " wps_method %d", |
| 1744 | MAC2STR(res->peer_interface_addr), |
| 1745 | MAC2STR(res->peer_device_addr), res->wps_method); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1746 | wpa_hexdump_ascii(MSG_DEBUG, "P2P: Start WPS Enrollee for SSID", |
| 1747 | res->ssid, res->ssid_len); |
| 1748 | wpa_supplicant_ap_deinit(wpa_s); |
| 1749 | wpas_copy_go_neg_results(wpa_s, res); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1750 | if (res->wps_method == WPS_PBC) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1751 | wpas_wps_start_pbc(wpa_s, res->peer_interface_addr, 1, 0); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1752 | #ifdef CONFIG_WPS_NFC |
| 1753 | } else if (res->wps_method == WPS_NFC) { |
| 1754 | wpas_wps_start_nfc(wpa_s, res->peer_device_addr, |
| 1755 | res->peer_interface_addr, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1756 | wpa_s->p2pdev->p2p_oob_dev_pw, |
| 1757 | wpa_s->p2pdev->p2p_oob_dev_pw_id, 1, |
| 1758 | wpa_s->p2pdev->p2p_oob_dev_pw_id == |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1759 | DEV_PW_NFC_CONNECTION_HANDOVER ? |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1760 | wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1761 | NULL, |
| 1762 | NULL, 0, 0); |
| 1763 | #endif /* CONFIG_WPS_NFC */ |
| 1764 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1765 | u16 dev_pw_id = DEV_PW_DEFAULT; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1766 | if (wpa_s->p2p_wps_method == WPS_P2PS) |
| 1767 | dev_pw_id = DEV_PW_P2PS_DEFAULT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1768 | if (wpa_s->p2p_wps_method == WPS_PIN_KEYPAD) |
| 1769 | dev_pw_id = DEV_PW_REGISTRAR_SPECIFIED; |
| 1770 | wpas_wps_start_pin(wpa_s, res->peer_interface_addr, |
| 1771 | wpa_s->p2p_pin, 1, dev_pw_id); |
| 1772 | } |
| 1773 | } |
| 1774 | |
| 1775 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1776 | static void wpas_p2p_add_psk_list(struct wpa_supplicant *wpa_s, |
| 1777 | struct wpa_ssid *ssid) |
| 1778 | { |
| 1779 | struct wpa_ssid *persistent; |
| 1780 | struct psk_list_entry *psk; |
| 1781 | struct hostapd_data *hapd; |
| 1782 | |
| 1783 | if (!wpa_s->ap_iface) |
| 1784 | return; |
| 1785 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1786 | persistent = wpas_p2p_get_persistent(wpa_s->p2pdev, NULL, ssid->ssid, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1787 | ssid->ssid_len); |
| 1788 | if (persistent == NULL) |
| 1789 | return; |
| 1790 | |
| 1791 | hapd = wpa_s->ap_iface->bss[0]; |
| 1792 | |
| 1793 | dl_list_for_each(psk, &persistent->psk_list, struct psk_list_entry, |
| 1794 | list) { |
| 1795 | struct hostapd_wpa_psk *hpsk; |
| 1796 | |
| 1797 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add persistent group PSK entry for " |
| 1798 | MACSTR " psk=%d", |
| 1799 | MAC2STR(psk->addr), psk->p2p); |
| 1800 | hpsk = os_zalloc(sizeof(*hpsk)); |
| 1801 | if (hpsk == NULL) |
| 1802 | break; |
| 1803 | os_memcpy(hpsk->psk, psk->psk, PMK_LEN); |
| 1804 | if (psk->p2p) |
| 1805 | os_memcpy(hpsk->p2p_dev_addr, psk->addr, ETH_ALEN); |
| 1806 | else |
| 1807 | os_memcpy(hpsk->addr, psk->addr, ETH_ALEN); |
| 1808 | hpsk->next = hapd->conf->ssid.wpa_psk; |
| 1809 | hapd->conf->ssid.wpa_psk = hpsk; |
| 1810 | } |
| 1811 | } |
| 1812 | |
| 1813 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1814 | static void p2p_go_dump_common_freqs(struct wpa_supplicant *wpa_s) |
| 1815 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1816 | char buf[20 + P2P_MAX_CHANNELS * 6]; |
| 1817 | char *pos, *end; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1818 | unsigned int i; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1819 | int res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1820 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1821 | pos = buf; |
| 1822 | end = pos + sizeof(buf); |
| 1823 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 1824 | res = os_snprintf(pos, end - pos, " %d", |
| 1825 | wpa_s->p2p_group_common_freqs[i]); |
| 1826 | if (os_snprintf_error(end - pos, res)) |
| 1827 | break; |
| 1828 | pos += res; |
| 1829 | } |
| 1830 | *pos = '\0'; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1831 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1832 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Common group frequencies:%s", buf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | |
| 1836 | static void p2p_go_save_group_common_freqs(struct wpa_supplicant *wpa_s, |
| 1837 | struct p2p_go_neg_results *params) |
| 1838 | { |
| 1839 | unsigned int i, len = int_array_len(wpa_s->go_params->freq_list); |
| 1840 | |
| 1841 | wpa_s->p2p_group_common_freqs_num = 0; |
| 1842 | os_free(wpa_s->p2p_group_common_freqs); |
| 1843 | wpa_s->p2p_group_common_freqs = os_calloc(len, sizeof(int)); |
| 1844 | if (!wpa_s->p2p_group_common_freqs) |
| 1845 | return; |
| 1846 | |
| 1847 | for (i = 0; i < len; i++) { |
| 1848 | if (!wpa_s->go_params->freq_list[i]) |
| 1849 | break; |
| 1850 | wpa_s->p2p_group_common_freqs[i] = |
| 1851 | wpa_s->go_params->freq_list[i]; |
| 1852 | } |
| 1853 | wpa_s->p2p_group_common_freqs_num = i; |
| 1854 | } |
| 1855 | |
| 1856 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1857 | static void p2p_config_write(struct wpa_supplicant *wpa_s) |
| 1858 | { |
| 1859 | #ifndef CONFIG_NO_CONFIG_WRITE |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1860 | if (wpa_s->p2pdev->conf->update_config && |
| 1861 | wpa_config_write(wpa_s->p2pdev->confname, wpa_s->p2pdev->conf)) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1862 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
| 1863 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 1864 | } |
| 1865 | |
| 1866 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1867 | static void p2p_go_configured(void *ctx, void *data) |
| 1868 | { |
| 1869 | struct wpa_supplicant *wpa_s = ctx; |
| 1870 | struct p2p_go_neg_results *params = data; |
| 1871 | struct wpa_ssid *ssid; |
| 1872 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 1873 | wpa_s->ap_configured_cb = NULL; |
| 1874 | wpa_s->ap_configured_cb_ctx = NULL; |
| 1875 | wpa_s->ap_configured_cb_data = NULL; |
| 1876 | if (!wpa_s->go_params) { |
| 1877 | wpa_printf(MSG_ERROR, |
| 1878 | "P2P: p2p_go_configured() called with wpa_s->go_params == NULL"); |
| 1879 | return; |
| 1880 | } |
| 1881 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1882 | p2p_go_save_group_common_freqs(wpa_s, params); |
| 1883 | p2p_go_dump_common_freqs(wpa_s); |
| 1884 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1885 | ssid = wpa_s->current_ssid; |
| 1886 | if (ssid && ssid->mode == WPAS_MODE_P2P_GO) { |
| 1887 | wpa_printf(MSG_DEBUG, "P2P: Group setup without provisioning"); |
| 1888 | if (wpa_s->global->p2p_group_formation == wpa_s) |
| 1889 | wpa_s->global->p2p_group_formation = NULL; |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1890 | wpas_p2p_group_started(wpa_s, 1, ssid, ssid->frequency, |
| 1891 | params->passphrase[0] == '\0' ? |
| 1892 | params->psk : NULL, |
| 1893 | params->passphrase, |
| 1894 | wpa_s->global->p2p_dev_addr, |
| 1895 | params->persistent_group, ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1896 | wpa_s->group_formation_reported = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1897 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1898 | if (wpa_s->p2pdev->p2ps_method_config_any) { |
| 1899 | if (is_zero_ether_addr(wpa_s->p2pdev->p2ps_join_addr)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1900 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1901 | "P2PS: Setting default PIN for ANY"); |
| 1902 | wpa_supplicant_ap_wps_pin(wpa_s, NULL, |
| 1903 | "12345670", NULL, 0, |
| 1904 | 0); |
| 1905 | } else { |
| 1906 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1907 | "P2PS: Setting default PIN for " MACSTR, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1908 | MAC2STR(wpa_s->p2pdev->p2ps_join_addr)); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1909 | wpa_supplicant_ap_wps_pin( |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1910 | wpa_s, wpa_s->p2pdev->p2ps_join_addr, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1911 | "12345670", NULL, 0, 0); |
| 1912 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1913 | wpa_s->p2pdev->p2ps_method_config_any = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1914 | } |
| 1915 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1916 | os_get_reltime(&wpa_s->global->p2p_go_wait_client); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1917 | if (params->persistent_group) { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1918 | wpas_p2p_store_persistent_group( |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1919 | wpa_s->p2pdev, ssid, |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 1920 | wpa_s->global->p2p_dev_addr); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1921 | wpas_p2p_add_psk_list(wpa_s, ssid); |
| 1922 | } |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1923 | |
| 1924 | wpas_notify_p2p_group_started(wpa_s, ssid, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1925 | params->persistent_group, 0, |
| 1926 | NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1927 | wpas_p2p_cross_connect_setup(wpa_s); |
| 1928 | wpas_p2p_set_group_idle_timeout(wpa_s); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1929 | |
| 1930 | if (wpa_s->p2p_first_connection_timeout) { |
| 1931 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1932 | "P2P: Start group formation timeout of %d seconds until first data connection on GO", |
| 1933 | wpa_s->p2p_first_connection_timeout); |
| 1934 | wpa_s->p2p_go_group_formation_completed = 0; |
| 1935 | wpa_s->global->p2p_group_formation = wpa_s; |
| 1936 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1937 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1938 | eloop_register_timeout( |
| 1939 | wpa_s->p2p_first_connection_timeout, 0, |
| 1940 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1941 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1942 | } |
| 1943 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1944 | return; |
| 1945 | } |
| 1946 | |
| 1947 | wpa_printf(MSG_DEBUG, "P2P: Setting up WPS for GO provisioning"); |
| 1948 | if (wpa_supplicant_ap_mac_addr_filter(wpa_s, |
| 1949 | params->peer_interface_addr)) { |
| 1950 | wpa_printf(MSG_DEBUG, "P2P: Failed to setup MAC address " |
| 1951 | "filtering"); |
| 1952 | return; |
| 1953 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1954 | if (params->wps_method == WPS_PBC) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1955 | wpa_supplicant_ap_wps_pbc(wpa_s, params->peer_interface_addr, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1956 | params->peer_device_addr); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1957 | #ifdef CONFIG_WPS_NFC |
| 1958 | } else if (params->wps_method == WPS_NFC) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1959 | if (wpa_s->p2pdev->p2p_oob_dev_pw_id != |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1960 | DEV_PW_NFC_CONNECTION_HANDOVER && |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1961 | !wpa_s->p2pdev->p2p_oob_dev_pw) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1962 | wpa_printf(MSG_DEBUG, "P2P: No NFC Dev Pw known"); |
| 1963 | return; |
| 1964 | } |
| 1965 | wpas_ap_wps_add_nfc_pw( |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1966 | wpa_s, wpa_s->p2pdev->p2p_oob_dev_pw_id, |
| 1967 | wpa_s->p2pdev->p2p_oob_dev_pw, |
| 1968 | wpa_s->p2pdev->p2p_peer_oob_pk_hash_known ? |
| 1969 | wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : NULL); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1970 | #endif /* CONFIG_WPS_NFC */ |
| 1971 | } else if (wpa_s->p2p_pin[0]) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1972 | wpa_supplicant_ap_wps_pin(wpa_s, params->peer_interface_addr, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1973 | wpa_s->p2p_pin, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1974 | os_free(wpa_s->go_params); |
| 1975 | wpa_s->go_params = NULL; |
| 1976 | } |
| 1977 | |
| 1978 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1979 | /** |
| 1980 | * wpas_p2p_freq_to_edmg_channel - Convert frequency into EDMG channel |
| 1981 | * @freq: Frequency (MHz) to convert |
| 1982 | * @op_class: Buffer for returning operating class |
| 1983 | * @op_edmg_channel: Buffer for returning channel number |
| 1984 | * Returns: 0 on success, -1 on failure |
| 1985 | * |
| 1986 | * This can be used to find the highest channel bonding which includes the |
| 1987 | * specified frequency. |
| 1988 | */ |
| 1989 | static int wpas_p2p_freq_to_edmg_channel(struct wpa_supplicant *wpa_s, |
| 1990 | unsigned int freq, |
| 1991 | u8 *op_class, u8 *op_edmg_channel) |
| 1992 | { |
| 1993 | struct hostapd_hw_modes *hwmode; |
| 1994 | struct ieee80211_edmg_config edmg; |
| 1995 | unsigned int i; |
| 1996 | enum chan_width chanwidth[] = { |
| 1997 | CHAN_WIDTH_8640, |
| 1998 | CHAN_WIDTH_6480, |
| 1999 | CHAN_WIDTH_4320, |
| 2000 | }; |
| 2001 | |
| 2002 | if (!wpa_s->hw.modes) |
| 2003 | return -1; |
| 2004 | |
| 2005 | hwmode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2006 | HOSTAPD_MODE_IEEE80211AD, false); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2007 | if (!hwmode) { |
| 2008 | wpa_printf(MSG_ERROR, |
| 2009 | "Unsupported AP mode: HOSTAPD_MODE_IEEE80211AD"); |
| 2010 | return -1; |
| 2011 | } |
| 2012 | |
| 2013 | /* Find the highest EDMG channel bandwidth to start the P2P GO */ |
| 2014 | for (i = 0; i < ARRAY_SIZE(chanwidth); i++) { |
| 2015 | if (ieee80211_chaninfo_to_channel(freq, chanwidth[i], 0, |
| 2016 | op_class, |
| 2017 | op_edmg_channel) < 0) |
| 2018 | continue; |
| 2019 | |
| 2020 | hostapd_encode_edmg_chan(1, *op_edmg_channel, 0, &edmg); |
| 2021 | if (edmg.channels && |
| 2022 | ieee802_edmg_is_allowed(hwmode->edmg, edmg)) { |
| 2023 | wpa_printf(MSG_DEBUG, |
| 2024 | "Freq %u to EDMG channel %u at opclass %u", |
| 2025 | freq, *op_edmg_channel, *op_class); |
| 2026 | return 0; |
| 2027 | } |
| 2028 | } |
| 2029 | |
| 2030 | return -1; |
| 2031 | } |
| 2032 | |
| 2033 | |
| 2034 | int wpas_p2p_try_edmg_channel(struct wpa_supplicant *wpa_s, |
| 2035 | struct p2p_go_neg_results *params) |
| 2036 | { |
| 2037 | u8 op_channel, op_class; |
| 2038 | int freq; |
| 2039 | |
| 2040 | /* Try social channel as primary channel frequency */ |
| 2041 | freq = (!params->freq) ? 58320 + 1 * 2160 : params->freq; |
| 2042 | |
| 2043 | if (wpas_p2p_freq_to_edmg_channel(wpa_s, freq, &op_class, |
| 2044 | &op_channel) == 0) { |
| 2045 | wpa_printf(MSG_DEBUG, |
| 2046 | "Freq %d will be used to set an EDMG connection (channel=%u opclass=%u)", |
| 2047 | freq, op_channel, op_class); |
| 2048 | params->freq = freq; |
| 2049 | return 0; |
| 2050 | } |
| 2051 | |
| 2052 | return -1; |
| 2053 | } |
| 2054 | |
| 2055 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2056 | static void wpas_start_wps_go(struct wpa_supplicant *wpa_s, |
| 2057 | struct p2p_go_neg_results *params, |
| 2058 | int group_formation) |
| 2059 | { |
| 2060 | struct wpa_ssid *ssid; |
| 2061 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2062 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Starting GO"); |
| 2063 | if (wpas_copy_go_neg_results(wpa_s, params) < 0) { |
| 2064 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not copy GO Negotiation " |
| 2065 | "results"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2066 | return; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2067 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2068 | |
| 2069 | ssid = wpa_config_add_network(wpa_s->conf); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2070 | if (ssid == NULL) { |
| 2071 | 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] | 2072 | return; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2073 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2074 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2075 | wpa_s->show_group_started = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2076 | wpa_s->p2p_go_group_formation_completed = 0; |
| 2077 | wpa_s->group_formation_reported = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2078 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2079 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2080 | wpa_config_set_network_defaults(ssid); |
| 2081 | ssid->temporary = 1; |
| 2082 | ssid->p2p_group = 1; |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 2083 | ssid->p2p_persistent_group = !!params->persistent_group; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2084 | ssid->mode = group_formation ? WPAS_MODE_P2P_GROUP_FORMATION : |
| 2085 | WPAS_MODE_P2P_GO; |
| 2086 | ssid->frequency = params->freq; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2087 | ssid->ht40 = params->ht40; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2088 | ssid->vht = params->vht; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 2089 | ssid->max_oper_chwidth = params->max_oper_chwidth; |
| 2090 | ssid->vht_center_freq2 = params->vht_center_freq2; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2091 | ssid->he = params->he; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2092 | if (params->edmg) { |
| 2093 | u8 op_channel, op_class; |
| 2094 | |
| 2095 | if (!wpas_p2p_freq_to_edmg_channel(wpa_s, params->freq, |
| 2096 | &op_class, &op_channel)) { |
| 2097 | ssid->edmg_channel = op_channel; |
| 2098 | ssid->enable_edmg = params->edmg; |
| 2099 | } else { |
| 2100 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2101 | "P2P: Could not match EDMG channel, freq %d, for GO", |
| 2102 | params->freq); |
| 2103 | } |
| 2104 | } |
| 2105 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2106 | ssid->ssid = os_zalloc(params->ssid_len + 1); |
| 2107 | if (ssid->ssid) { |
| 2108 | os_memcpy(ssid->ssid, params->ssid, params->ssid_len); |
| 2109 | ssid->ssid_len = params->ssid_len; |
| 2110 | } |
| 2111 | ssid->auth_alg = WPA_AUTH_ALG_OPEN; |
| 2112 | ssid->key_mgmt = WPA_KEY_MGMT_PSK; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2113 | if (is_6ghz_freq(ssid->frequency) && |
| 2114 | is_p2p_6ghz_capable(wpa_s->global->p2p)) { |
| 2115 | ssid->auth_alg |= WPA_AUTH_ALG_SAE; |
| 2116 | ssid->key_mgmt = WPA_KEY_MGMT_SAE; |
| 2117 | ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2118 | ssid->sae_pwe = SAE_PWE_HASH_TO_ELEMENT; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2119 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use SAE auth_alg and key_mgmt"); |
| 2120 | } else { |
| 2121 | p2p_set_6ghz_dev_capab(wpa_s->global->p2p, false); |
| 2122 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2123 | ssid->proto = WPA_PROTO_RSN; |
| 2124 | ssid->pairwise_cipher = WPA_CIPHER_CCMP; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2125 | ssid->group_cipher = WPA_CIPHER_CCMP; |
| 2126 | if (params->freq > 56160) { |
| 2127 | /* |
| 2128 | * Enable GCMP instead of CCMP as pairwise_cipher and |
| 2129 | * group_cipher in 60 GHz. |
| 2130 | */ |
| 2131 | ssid->pairwise_cipher = WPA_CIPHER_GCMP; |
| 2132 | ssid->group_cipher = WPA_CIPHER_GCMP; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2133 | /* P2P GO in 60 GHz is always a PCP (PBSS) */ |
| 2134 | ssid->pbss = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2135 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2136 | if (os_strlen(params->passphrase) > 0) { |
| 2137 | ssid->passphrase = os_strdup(params->passphrase); |
| 2138 | if (ssid->passphrase == NULL) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2139 | wpa_msg_global(wpa_s, MSG_ERROR, |
| 2140 | "P2P: Failed to copy passphrase for GO"); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2141 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 2142 | return; |
| 2143 | } |
| 2144 | } else |
| 2145 | ssid->passphrase = NULL; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2146 | ssid->psk_set = params->psk_set; |
| 2147 | if (ssid->psk_set) |
| 2148 | os_memcpy(ssid->psk, params->psk, sizeof(ssid->psk)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2149 | else if (ssid->passphrase) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2150 | wpa_config_update_psk(ssid); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2151 | ssid->ap_max_inactivity = wpa_s->p2pdev->conf->p2p_go_max_inactivity; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2152 | |
| 2153 | wpa_s->ap_configured_cb = p2p_go_configured; |
| 2154 | wpa_s->ap_configured_cb_ctx = wpa_s; |
| 2155 | wpa_s->ap_configured_cb_data = wpa_s->go_params; |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 2156 | wpa_s->scan_req = NORMAL_SCAN_REQ; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2157 | wpa_s->connect_without_scan = ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2158 | wpa_s->reassociate = 1; |
| 2159 | wpa_s->disconnected = 0; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2160 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Request scan (that will be skipped) to " |
| 2161 | "start GO)"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2162 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 2163 | } |
| 2164 | |
| 2165 | |
| 2166 | static void wpas_p2p_clone_config(struct wpa_supplicant *dst, |
| 2167 | const struct wpa_supplicant *src) |
| 2168 | { |
| 2169 | struct wpa_config *d; |
| 2170 | const struct wpa_config *s; |
| 2171 | |
| 2172 | d = dst->conf; |
| 2173 | s = src->conf; |
| 2174 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2175 | #define C(n) \ |
| 2176 | do { \ |
| 2177 | if (s->n && !d->n) \ |
| 2178 | d->n = os_strdup(s->n); \ |
| 2179 | } while (0) |
| 2180 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2181 | C(device_name); |
| 2182 | C(manufacturer); |
| 2183 | C(model_name); |
| 2184 | C(model_number); |
| 2185 | C(serial_number); |
| 2186 | C(config_methods); |
| 2187 | #undef C |
| 2188 | |
| 2189 | os_memcpy(d->device_type, s->device_type, WPS_DEV_TYPE_LEN); |
| 2190 | os_memcpy(d->sec_device_type, s->sec_device_type, |
| 2191 | sizeof(d->sec_device_type)); |
| 2192 | d->num_sec_device_types = s->num_sec_device_types; |
| 2193 | |
| 2194 | d->p2p_group_idle = s->p2p_group_idle; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2195 | d->p2p_go_freq_change_policy = s->p2p_go_freq_change_policy; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2196 | d->p2p_intra_bss = s->p2p_intra_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2197 | d->persistent_reconnect = s->persistent_reconnect; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2198 | d->max_num_sta = s->max_num_sta; |
| 2199 | d->pbc_in_m1 = s->pbc_in_m1; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2200 | d->ignore_old_scan_res = s->ignore_old_scan_res; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 2201 | d->beacon_int = s->beacon_int; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2202 | d->dtim_period = s->dtim_period; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2203 | d->p2p_go_ctwindow = s->p2p_go_ctwindow; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2204 | d->disassoc_low_ack = s->disassoc_low_ack; |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 2205 | d->disable_scan_offload = s->disable_scan_offload; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2206 | d->passive_scan = s->passive_scan; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2207 | d->pmf = s->pmf; |
| 2208 | d->p2p_6ghz_disable = s->p2p_6ghz_disable; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2209 | d->sae_pwe = s->sae_pwe; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2210 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2211 | if (s->wps_nfc_dh_privkey && s->wps_nfc_dh_pubkey && |
| 2212 | !d->wps_nfc_pw_from_config) { |
| 2213 | wpabuf_free(d->wps_nfc_dh_privkey); |
| 2214 | wpabuf_free(d->wps_nfc_dh_pubkey); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2215 | d->wps_nfc_dh_privkey = wpabuf_dup(s->wps_nfc_dh_privkey); |
| 2216 | d->wps_nfc_dh_pubkey = wpabuf_dup(s->wps_nfc_dh_pubkey); |
| 2217 | } |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2218 | d->p2p_cli_probe = s->p2p_cli_probe; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2219 | d->go_interworking = s->go_interworking; |
| 2220 | d->go_access_network_type = s->go_access_network_type; |
| 2221 | d->go_internet = s->go_internet; |
| 2222 | d->go_venue_group = s->go_venue_group; |
| 2223 | d->go_venue_type = s->go_venue_type; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2224 | d->p2p_add_cli_chan = s->p2p_add_cli_chan; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2225 | } |
| 2226 | |
| 2227 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2228 | static void wpas_p2p_get_group_ifname(struct wpa_supplicant *wpa_s, |
| 2229 | char *ifname, size_t len) |
| 2230 | { |
| 2231 | char *ifname_ptr = wpa_s->ifname; |
| 2232 | |
| 2233 | if (os_strncmp(wpa_s->ifname, P2P_MGMT_DEVICE_PREFIX, |
| 2234 | os_strlen(P2P_MGMT_DEVICE_PREFIX)) == 0) { |
| 2235 | ifname_ptr = os_strrchr(wpa_s->ifname, '-') + 1; |
| 2236 | } |
| 2237 | |
| 2238 | os_snprintf(ifname, len, "p2p-%s-%d", ifname_ptr, wpa_s->p2p_group_idx); |
| 2239 | if (os_strlen(ifname) >= IFNAMSIZ && |
| 2240 | os_strlen(wpa_s->ifname) < IFNAMSIZ) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2241 | int res; |
| 2242 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2243 | /* Try to avoid going over the IFNAMSIZ length limit */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2244 | res = os_snprintf(ifname, len, "p2p-%d", wpa_s->p2p_group_idx); |
| 2245 | if (os_snprintf_error(len, res) && len) |
| 2246 | ifname[len - 1] = '\0'; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2247 | } |
| 2248 | } |
| 2249 | |
| 2250 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2251 | static int wpas_p2p_add_group_interface(struct wpa_supplicant *wpa_s, |
| 2252 | enum wpa_driver_if_type type) |
| 2253 | { |
| 2254 | char ifname[120], force_ifname[120]; |
| 2255 | |
| 2256 | if (wpa_s->pending_interface_name[0]) { |
| 2257 | wpa_printf(MSG_DEBUG, "P2P: Pending virtual interface exists " |
| 2258 | "- skip creation of a new one"); |
| 2259 | if (is_zero_ether_addr(wpa_s->pending_interface_addr)) { |
| 2260 | wpa_printf(MSG_DEBUG, "P2P: Pending virtual address " |
| 2261 | "unknown?! ifname='%s'", |
| 2262 | wpa_s->pending_interface_name); |
| 2263 | return -1; |
| 2264 | } |
| 2265 | return 0; |
| 2266 | } |
| 2267 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2268 | wpas_p2p_get_group_ifname(wpa_s, ifname, sizeof(ifname)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2269 | force_ifname[0] = '\0'; |
| 2270 | |
| 2271 | wpa_printf(MSG_DEBUG, "P2P: Create a new interface %s for the group", |
| 2272 | ifname); |
| 2273 | wpa_s->p2p_group_idx++; |
| 2274 | |
| 2275 | wpa_s->pending_interface_type = type; |
| 2276 | if (wpa_drv_if_add(wpa_s, type, ifname, NULL, NULL, force_ifname, |
| 2277 | wpa_s->pending_interface_addr, NULL) < 0) { |
| 2278 | wpa_printf(MSG_ERROR, "P2P: Failed to create new group " |
| 2279 | "interface"); |
| 2280 | return -1; |
| 2281 | } |
| 2282 | |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2283 | if (wpa_s->conf->p2p_interface_random_mac_addr) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2284 | random_mac_addr(wpa_s->pending_interface_addr); |
| 2285 | wpa_printf(MSG_DEBUG, "P2P: Generate random MAC address " MACSTR |
| 2286 | " for the group", |
| 2287 | MAC2STR(wpa_s->pending_interface_addr)); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2288 | } |
| 2289 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2290 | if (force_ifname[0]) { |
| 2291 | wpa_printf(MSG_DEBUG, "P2P: Driver forced interface name %s", |
| 2292 | force_ifname); |
| 2293 | os_strlcpy(wpa_s->pending_interface_name, force_ifname, |
| 2294 | sizeof(wpa_s->pending_interface_name)); |
| 2295 | } else |
| 2296 | os_strlcpy(wpa_s->pending_interface_name, ifname, |
| 2297 | sizeof(wpa_s->pending_interface_name)); |
| 2298 | wpa_printf(MSG_DEBUG, "P2P: Created pending virtual interface %s addr " |
| 2299 | MACSTR, wpa_s->pending_interface_name, |
| 2300 | MAC2STR(wpa_s->pending_interface_addr)); |
| 2301 | |
| 2302 | return 0; |
| 2303 | } |
| 2304 | |
| 2305 | |
| 2306 | static void wpas_p2p_remove_pending_group_interface( |
| 2307 | struct wpa_supplicant *wpa_s) |
| 2308 | { |
| 2309 | if (!wpa_s->pending_interface_name[0] || |
| 2310 | is_zero_ether_addr(wpa_s->pending_interface_addr)) |
| 2311 | return; /* No pending virtual interface */ |
| 2312 | |
| 2313 | wpa_printf(MSG_DEBUG, "P2P: Removing pending group interface %s", |
| 2314 | wpa_s->pending_interface_name); |
| 2315 | wpa_drv_if_remove(wpa_s, wpa_s->pending_interface_type, |
| 2316 | wpa_s->pending_interface_name); |
| 2317 | os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN); |
| 2318 | wpa_s->pending_interface_name[0] = '\0'; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2319 | wpa_s->global->pending_group_iface_for_p2ps = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | |
| 2323 | static struct wpa_supplicant * |
| 2324 | wpas_p2p_init_group_interface(struct wpa_supplicant *wpa_s, int go) |
| 2325 | { |
| 2326 | struct wpa_interface iface; |
| 2327 | struct wpa_supplicant *group_wpa_s; |
| 2328 | |
| 2329 | if (!wpa_s->pending_interface_name[0]) { |
| 2330 | wpa_printf(MSG_ERROR, "P2P: No pending group interface"); |
| 2331 | if (!wpas_p2p_create_iface(wpa_s)) |
| 2332 | return NULL; |
| 2333 | /* |
| 2334 | * Something has forced us to remove the pending interface; try |
| 2335 | * to create a new one and hope for the best that we will get |
| 2336 | * the same local address. |
| 2337 | */ |
| 2338 | if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO : |
| 2339 | WPA_IF_P2P_CLIENT) < 0) |
| 2340 | return NULL; |
| 2341 | } |
| 2342 | |
| 2343 | os_memset(&iface, 0, sizeof(iface)); |
| 2344 | iface.ifname = wpa_s->pending_interface_name; |
| 2345 | iface.driver = wpa_s->driver->name; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2346 | if (wpa_s->conf->ctrl_interface == NULL && |
| 2347 | wpa_s->parent != wpa_s && |
| 2348 | wpa_s->p2p_mgmt && |
| 2349 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) |
| 2350 | iface.ctrl_interface = wpa_s->parent->conf->ctrl_interface; |
| 2351 | else |
| 2352 | iface.ctrl_interface = wpa_s->conf->ctrl_interface; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2353 | iface.driver_param = wpa_s->conf->driver_param; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 2354 | 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] | 2355 | if (group_wpa_s == NULL) { |
| 2356 | wpa_printf(MSG_ERROR, "P2P: Failed to create new " |
| 2357 | "wpa_supplicant interface"); |
| 2358 | return NULL; |
| 2359 | } |
| 2360 | wpa_s->pending_interface_name[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2361 | group_wpa_s->p2p_group_interface = go ? P2P_GROUP_INTERFACE_GO : |
| 2362 | P2P_GROUP_INTERFACE_CLIENT; |
| 2363 | wpa_s->global->p2p_group_formation = group_wpa_s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2364 | wpa_s->global->pending_group_iface_for_p2ps = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2365 | |
| 2366 | wpas_p2p_clone_config(group_wpa_s, wpa_s); |
| 2367 | |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2368 | if (wpa_s->conf->p2p_interface_random_mac_addr) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2369 | if (wpa_drv_set_mac_addr(group_wpa_s, |
| 2370 | wpa_s->pending_interface_addr) < 0) { |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2371 | wpa_msg(group_wpa_s, MSG_INFO, |
| 2372 | "Failed to set random MAC address"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2373 | wpa_supplicant_remove_iface(wpa_s->global, group_wpa_s, |
| 2374 | 0); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2375 | return NULL; |
| 2376 | } |
| 2377 | |
| 2378 | if (wpa_supplicant_update_mac_addr(group_wpa_s) < 0) { |
| 2379 | wpa_msg(group_wpa_s, MSG_INFO, |
| 2380 | "Could not update MAC address information"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2381 | wpa_supplicant_remove_iface(wpa_s->global, group_wpa_s, |
| 2382 | 0); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2383 | return NULL; |
| 2384 | } |
| 2385 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2386 | wpa_printf(MSG_DEBUG, "P2P: Using random MAC address " MACSTR |
| 2387 | " for the group", |
| 2388 | MAC2STR(wpa_s->pending_interface_addr)); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2389 | } |
| 2390 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2391 | return group_wpa_s; |
| 2392 | } |
| 2393 | |
| 2394 | |
| 2395 | static void wpas_p2p_group_formation_timeout(void *eloop_ctx, |
| 2396 | void *timeout_ctx) |
| 2397 | { |
| 2398 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 2399 | wpa_printf(MSG_DEBUG, "P2P: Group Formation timed out"); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2400 | wpas_p2p_group_formation_failed(wpa_s, 0); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2401 | } |
| 2402 | |
| 2403 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2404 | static void wpas_p2p_group_formation_failed(struct wpa_supplicant *wpa_s, |
| 2405 | int already_deleted) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2406 | { |
| 2407 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2408 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2409 | if (wpa_s->global->p2p) |
| 2410 | p2p_group_formation_failed(wpa_s->global->p2p); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2411 | wpas_group_formation_completed(wpa_s, 0, already_deleted); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2415 | static void wpas_p2p_grpform_fail_after_wps(struct wpa_supplicant *wpa_s) |
| 2416 | { |
| 2417 | wpa_printf(MSG_DEBUG, "P2P: Reject group formation due to WPS provisioning failure"); |
| 2418 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2419 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2420 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2421 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2422 | wpa_s->global->p2p_fail_on_wps_complete = 0; |
| 2423 | } |
| 2424 | |
| 2425 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2426 | void wpas_p2p_ap_setup_failed(struct wpa_supplicant *wpa_s) |
| 2427 | { |
| 2428 | if (wpa_s->global->p2p_group_formation != wpa_s) |
| 2429 | return; |
| 2430 | /* Speed up group formation timeout since this cannot succeed */ |
| 2431 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2432 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2433 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2434 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 2438 | bool wpas_p2p_retry_limit_exceeded(struct wpa_supplicant *wpa_s) |
| 2439 | { |
| 2440 | if (!wpa_s->p2p_in_invitation || !wpa_s->p2p_retry_limit || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2441 | wpa_s->p2p_in_invitation <= wpa_s->p2p_retry_limit) |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 2442 | return false; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2443 | |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 2444 | wpa_printf(MSG_DEBUG, "P2P: Group join retry limit exceeded"); |
| 2445 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
| 2446 | wpa_s->p2pdev, NULL); |
| 2447 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
| 2448 | wpa_s->p2pdev, NULL); |
| 2449 | return true; |
| 2450 | } |
| 2451 | |
| 2452 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2453 | 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] | 2454 | { |
| 2455 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2456 | struct wpa_supplicant *group_wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2457 | |
| 2458 | if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) { |
| 2459 | wpa_drv_cancel_remain_on_channel(wpa_s); |
| 2460 | wpa_s->off_channel_freq = 0; |
| 2461 | wpa_s->roc_waiting_drv_freq = 0; |
| 2462 | } |
| 2463 | |
| 2464 | if (res->status) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2465 | wpa_msg_global(wpa_s, MSG_INFO, |
| 2466 | P2P_EVENT_GO_NEG_FAILURE "status=%d", |
| 2467 | res->status); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2468 | wpas_notify_p2p_go_neg_completed(wpa_s, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2469 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 2470 | return; |
| 2471 | } |
| 2472 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2473 | if (!res->role_go) { |
| 2474 | /* Inform driver of the operating channel of GO. */ |
| 2475 | wpa_drv_set_prob_oper_freq(wpa_s, res->freq); |
| 2476 | } |
| 2477 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2478 | if (wpa_s->p2p_go_ht40) |
| 2479 | res->ht40 = 1; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2480 | if (wpa_s->p2p_go_vht) |
| 2481 | res->vht = 1; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2482 | if (wpa_s->p2p_go_he) |
| 2483 | res->he = 1; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2484 | if (wpa_s->p2p_go_edmg) |
| 2485 | res->edmg = 1; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 2486 | res->max_oper_chwidth = wpa_s->p2p_go_max_oper_chwidth; |
| 2487 | res->vht_center_freq2 = wpa_s->p2p_go_vht_center_freq2; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2488 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2489 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_SUCCESS "role=%s " |
| 2490 | "freq=%d ht40=%d peer_dev=" MACSTR " peer_iface=" MACSTR |
| 2491 | " wps_method=%s", |
| 2492 | res->role_go ? "GO" : "client", res->freq, res->ht40, |
| 2493 | MAC2STR(res->peer_device_addr), |
| 2494 | MAC2STR(res->peer_interface_addr), |
| 2495 | p2p_wps_method_text(res->wps_method)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2496 | wpas_notify_p2p_go_neg_completed(wpa_s, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2497 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2498 | if (res->role_go && wpa_s->p2p_persistent_id >= 0) { |
| 2499 | struct wpa_ssid *ssid; |
| 2500 | ssid = wpa_config_get_network(wpa_s->conf, |
| 2501 | wpa_s->p2p_persistent_id); |
| 2502 | if (ssid && ssid->disabled == 2 && |
| 2503 | ssid->mode == WPAS_MODE_P2P_GO && ssid->passphrase) { |
| 2504 | size_t len = os_strlen(ssid->passphrase); |
| 2505 | wpa_printf(MSG_DEBUG, "P2P: Override passphrase based " |
| 2506 | "on requested persistent group"); |
| 2507 | os_memcpy(res->passphrase, ssid->passphrase, len); |
| 2508 | res->passphrase[len] = '\0'; |
| 2509 | } |
| 2510 | } |
| 2511 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2512 | if (wpa_s->create_p2p_iface) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2513 | group_wpa_s = |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2514 | wpas_p2p_init_group_interface(wpa_s, res->role_go); |
| 2515 | if (group_wpa_s == NULL) { |
| 2516 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 2517 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, |
| 2518 | wpa_s, NULL); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2519 | wpas_p2p_group_formation_failed(wpa_s, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2520 | return; |
| 2521 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2522 | os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN); |
| 2523 | wpa_s->pending_interface_name[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2524 | } else { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2525 | group_wpa_s = wpa_s->parent; |
| 2526 | wpa_s->global->p2p_group_formation = group_wpa_s; |
| 2527 | if (group_wpa_s != wpa_s) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2528 | wpas_p2p_clone_config(group_wpa_s, wpa_s); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2529 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2530 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2531 | group_wpa_s->p2p_in_provisioning = 1; |
| 2532 | group_wpa_s->p2pdev = wpa_s; |
| 2533 | if (group_wpa_s != wpa_s) { |
| 2534 | os_memcpy(group_wpa_s->p2p_pin, wpa_s->p2p_pin, |
| 2535 | sizeof(group_wpa_s->p2p_pin)); |
| 2536 | group_wpa_s->p2p_wps_method = wpa_s->p2p_wps_method; |
| 2537 | } |
| 2538 | if (res->role_go) { |
| 2539 | wpas_start_wps_go(group_wpa_s, res, 1); |
| 2540 | } else { |
| 2541 | os_get_reltime(&group_wpa_s->scan_min_time); |
| 2542 | wpas_start_wps_enrollee(group_wpa_s, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2543 | } |
| 2544 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2545 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2546 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
| 2547 | |
| 2548 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 2549 | eloop_register_timeout(15 + res->peer_config_timeout / 100, |
| 2550 | (res->peer_config_timeout % 100) * 10000, |
| 2551 | wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 2552 | } |
| 2553 | |
| 2554 | |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 2555 | static void wpas_go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id, |
| 2556 | u8 go_intent) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2557 | { |
| 2558 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2559 | 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] | 2560 | " dev_passwd_id=%u go_intent=%u", MAC2STR(src), |
| 2561 | dev_passwd_id, go_intent); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2562 | |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 2563 | 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] | 2564 | } |
| 2565 | |
| 2566 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2567 | static void wpas_dev_found(void *ctx, const u8 *addr, |
| 2568 | const struct p2p_peer_info *info, |
| 2569 | int new_device) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2570 | { |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2571 | u8 *wfd_dev_info = NULL; |
| 2572 | u8 wfd_dev_info_len = 0; |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2573 | u8 *wfd_r2_dev_info = NULL; |
Jimmy Chen | 57e19f5 | 2021-03-04 14:19:52 +0800 | [diff] [blame] | 2574 | u8 wfd_r2_dev_info_len = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2575 | #ifndef CONFIG_NO_STDOUT_DEBUG |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2576 | struct wpa_supplicant *wpa_s = ctx; |
| 2577 | char devtype[WPS_DEV_TYPE_BUFSIZE]; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2578 | char *wfd_dev_info_hex = NULL; |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2579 | char *wfd_r2_dev_info_hex = NULL; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2580 | |
Irfan Sheriff | 8367dc9 | 2012-09-09 17:08:19 -0700 | [diff] [blame] | 2581 | #ifdef CONFIG_WIFI_DISPLAY |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2582 | wfd_dev_info_hex = wifi_display_subelem_hex(info->wfd_subelems, |
| 2583 | WFD_SUBELEM_DEVICE_INFO); |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2584 | if (wfd_dev_info_hex) { |
| 2585 | wfd_dev_info_len = strlen(wfd_dev_info_hex) / 2; |
| 2586 | wfd_dev_info = os_zalloc(wfd_dev_info_len); |
| 2587 | // Only used for notification, so not handling error. |
| 2588 | hexstr2bin(wfd_dev_info_hex, wfd_dev_info, wfd_dev_info_len); |
| 2589 | } |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2590 | |
| 2591 | wfd_r2_dev_info_hex = wifi_display_subelem_hex(info->wfd_subelems, |
| 2592 | WFD_SUBELEM_R2_DEVICE_INFO); |
| 2593 | if (wfd_r2_dev_info_hex) { |
| 2594 | wfd_r2_dev_info_len = strlen(wfd_r2_dev_info_hex) / 2; |
| 2595 | wfd_r2_dev_info = os_zalloc(wfd_r2_dev_info_len); |
| 2596 | // Only used for notification, so not handling error. |
| 2597 | hexstr2bin(wfd_r2_dev_info_hex, wfd_r2_dev_info, wfd_r2_dev_info_len); |
| 2598 | } |
Irfan Sheriff | 8367dc9 | 2012-09-09 17:08:19 -0700 | [diff] [blame] | 2599 | #endif /* CONFIG_WIFI_DISPLAY */ |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2600 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2601 | if (info->p2ps_instance) { |
| 2602 | char str[256]; |
| 2603 | const u8 *buf = wpabuf_head(info->p2ps_instance); |
| 2604 | size_t len = wpabuf_len(info->p2ps_instance); |
| 2605 | |
| 2606 | while (len) { |
| 2607 | u32 id; |
| 2608 | u16 methods; |
| 2609 | u8 str_len; |
| 2610 | |
| 2611 | if (len < 4 + 2 + 1) |
| 2612 | break; |
| 2613 | id = WPA_GET_LE32(buf); |
| 2614 | buf += sizeof(u32); |
| 2615 | methods = WPA_GET_BE16(buf); |
| 2616 | buf += sizeof(u16); |
| 2617 | str_len = *buf++; |
| 2618 | if (str_len > len - 4 - 2 - 1) |
| 2619 | break; |
| 2620 | os_memcpy(str, buf, str_len); |
| 2621 | str[str_len] = '\0'; |
| 2622 | buf += str_len; |
| 2623 | len -= str_len + sizeof(u32) + sizeof(u16) + sizeof(u8); |
| 2624 | |
| 2625 | wpa_msg_global(wpa_s, MSG_INFO, |
| 2626 | P2P_EVENT_DEVICE_FOUND MACSTR |
| 2627 | " p2p_dev_addr=" MACSTR |
| 2628 | " pri_dev_type=%s name='%s'" |
| 2629 | " config_methods=0x%x" |
| 2630 | " dev_capab=0x%x" |
| 2631 | " group_capab=0x%x" |
| 2632 | " adv_id=%x asp_svc=%s%s", |
| 2633 | MAC2STR(addr), |
| 2634 | MAC2STR(info->p2p_device_addr), |
| 2635 | wps_dev_type_bin2str( |
| 2636 | info->pri_dev_type, |
| 2637 | devtype, sizeof(devtype)), |
| 2638 | info->device_name, methods, |
| 2639 | info->dev_capab, info->group_capab, |
| 2640 | id, str, |
| 2641 | info->vendor_elems ? |
| 2642 | " vendor_elems=1" : ""); |
| 2643 | } |
| 2644 | goto done; |
| 2645 | } |
| 2646 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2647 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_FOUND MACSTR |
| 2648 | " p2p_dev_addr=" MACSTR |
| 2649 | " pri_dev_type=%s name='%s' config_methods=0x%x " |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2650 | "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] | 2651 | MAC2STR(addr), MAC2STR(info->p2p_device_addr), |
| 2652 | wps_dev_type_bin2str(info->pri_dev_type, devtype, |
| 2653 | sizeof(devtype)), |
| 2654 | info->device_name, info->config_methods, |
| 2655 | info->dev_capab, info->group_capab, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2656 | wfd_dev_info_hex ? " wfd_dev_info=0x" : "", |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 2657 | wfd_dev_info_hex ? wfd_dev_info_hex : "", |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2658 | wfd_r2_dev_info_hex ? " wfd_r2_dev_info=0x" : "", |
| 2659 | wfd_r2_dev_info_hex ? wfd_r2_dev_info_hex : "", |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2660 | info->vendor_elems ? " vendor_elems=1" : "", |
| 2661 | new_device); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2662 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2663 | done: |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2664 | os_free(wfd_dev_info_hex); |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2665 | os_free(wfd_r2_dev_info_hex); |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 2666 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2667 | |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2668 | wpas_notify_p2p_device_found(ctx, addr, info, wfd_dev_info, |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2669 | wfd_dev_info_len, wfd_r2_dev_info, |
| 2670 | wfd_r2_dev_info_len, new_device); |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2671 | os_free(wfd_dev_info); |
jiangpingping | a96a5e8 | 2023-11-16 15:02:17 +0800 | [diff] [blame] | 2672 | os_free(wfd_r2_dev_info); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | |
| 2676 | static void wpas_dev_lost(void *ctx, const u8 *dev_addr) |
| 2677 | { |
| 2678 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2679 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2680 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_LOST |
| 2681 | "p2p_dev_addr=" MACSTR, MAC2STR(dev_addr)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2682 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2683 | wpas_notify_p2p_device_lost(wpa_s, dev_addr); |
| 2684 | } |
| 2685 | |
| 2686 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2687 | static void wpas_find_stopped(void *ctx) |
| 2688 | { |
| 2689 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2690 | |
| 2691 | if (wpa_s->p2p_scan_work && wpas_abort_ongoing_scan(wpa_s) < 0) |
| 2692 | wpa_printf(MSG_DEBUG, "P2P: Abort ongoing scan failed"); |
| 2693 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2694 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_FIND_STOPPED); |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 2695 | wpas_notify_p2p_find_stopped(wpa_s); |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2699 | struct wpas_p2p_listen_work { |
| 2700 | unsigned int freq; |
| 2701 | unsigned int duration; |
| 2702 | struct wpabuf *probe_resp_ie; |
| 2703 | }; |
| 2704 | |
| 2705 | |
| 2706 | static void wpas_p2p_listen_work_free(struct wpas_p2p_listen_work *lwork) |
| 2707 | { |
| 2708 | if (lwork == NULL) |
| 2709 | return; |
| 2710 | wpabuf_free(lwork->probe_resp_ie); |
| 2711 | os_free(lwork); |
| 2712 | } |
| 2713 | |
| 2714 | |
| 2715 | static void wpas_p2p_listen_work_done(struct wpa_supplicant *wpa_s) |
| 2716 | { |
| 2717 | struct wpas_p2p_listen_work *lwork; |
| 2718 | |
| 2719 | if (!wpa_s->p2p_listen_work) |
| 2720 | return; |
| 2721 | |
| 2722 | lwork = wpa_s->p2p_listen_work->ctx; |
| 2723 | wpas_p2p_listen_work_free(lwork); |
| 2724 | radio_work_done(wpa_s->p2p_listen_work); |
| 2725 | wpa_s->p2p_listen_work = NULL; |
| 2726 | } |
| 2727 | |
| 2728 | |
| 2729 | static void wpas_start_listen_cb(struct wpa_radio_work *work, int deinit) |
| 2730 | { |
| 2731 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 2732 | struct wpas_p2p_listen_work *lwork = work->ctx; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2733 | unsigned int duration; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2734 | |
| 2735 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 2736 | if (work->started) { |
| 2737 | wpa_s->p2p_listen_work = NULL; |
| 2738 | wpas_stop_listen(wpa_s); |
| 2739 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2740 | wpas_p2p_listen_work_free(lwork); |
| 2741 | return; |
| 2742 | } |
| 2743 | |
| 2744 | wpa_s->p2p_listen_work = work; |
| 2745 | |
| 2746 | wpa_drv_set_ap_wps_ie(wpa_s, NULL, lwork->probe_resp_ie, NULL); |
| 2747 | |
| 2748 | if (wpa_drv_probe_req_report(wpa_s, 1) < 0) { |
| 2749 | wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver to " |
| 2750 | "report received Probe Request frames"); |
| 2751 | wpas_p2p_listen_work_done(wpa_s); |
| 2752 | return; |
| 2753 | } |
| 2754 | |
| 2755 | wpa_s->pending_listen_freq = lwork->freq; |
| 2756 | wpa_s->pending_listen_duration = lwork->duration; |
| 2757 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2758 | duration = lwork->duration; |
| 2759 | #ifdef CONFIG_TESTING_OPTIONS |
| 2760 | if (wpa_s->extra_roc_dur) { |
| 2761 | wpa_printf(MSG_DEBUG, "TESTING: Increase ROC duration %u -> %u", |
| 2762 | duration, duration + wpa_s->extra_roc_dur); |
| 2763 | duration += wpa_s->extra_roc_dur; |
| 2764 | } |
| 2765 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2766 | |
| 2767 | if (wpa_drv_remain_on_channel(wpa_s, lwork->freq, duration) < 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2768 | wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver " |
| 2769 | "to remain on channel (%u MHz) for Listen " |
| 2770 | "state", lwork->freq); |
| 2771 | wpas_p2p_listen_work_done(wpa_s); |
| 2772 | wpa_s->pending_listen_freq = 0; |
| 2773 | return; |
| 2774 | } |
| 2775 | wpa_s->off_channel_freq = 0; |
| 2776 | wpa_s->roc_waiting_drv_freq = lwork->freq; |
| 2777 | } |
| 2778 | |
| 2779 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2780 | static int wpas_start_listen(void *ctx, unsigned int freq, |
| 2781 | unsigned int duration, |
| 2782 | const struct wpabuf *probe_resp_ie) |
| 2783 | { |
| 2784 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2785 | struct wpas_p2p_listen_work *lwork; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2786 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2787 | if (wpa_s->p2p_listen_work) { |
| 2788 | 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] | 2789 | return -1; |
| 2790 | } |
| 2791 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2792 | lwork = os_zalloc(sizeof(*lwork)); |
| 2793 | if (lwork == NULL) |
| 2794 | return -1; |
| 2795 | lwork->freq = freq; |
| 2796 | lwork->duration = duration; |
| 2797 | if (probe_resp_ie) { |
| 2798 | lwork->probe_resp_ie = wpabuf_dup(probe_resp_ie); |
| 2799 | if (lwork->probe_resp_ie == NULL) { |
| 2800 | wpas_p2p_listen_work_free(lwork); |
| 2801 | return -1; |
| 2802 | } |
| 2803 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2804 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2805 | if (radio_add_work(wpa_s, freq, "p2p-listen", 0, wpas_start_listen_cb, |
| 2806 | lwork) < 0) { |
| 2807 | wpas_p2p_listen_work_free(lwork); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2808 | return -1; |
| 2809 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2810 | |
| 2811 | return 0; |
| 2812 | } |
| 2813 | |
| 2814 | |
| 2815 | static void wpas_stop_listen(void *ctx) |
| 2816 | { |
| 2817 | struct wpa_supplicant *wpa_s = ctx; |
| 2818 | if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) { |
| 2819 | wpa_drv_cancel_remain_on_channel(wpa_s); |
| 2820 | wpa_s->off_channel_freq = 0; |
| 2821 | wpa_s->roc_waiting_drv_freq = 0; |
| 2822 | } |
| 2823 | wpa_drv_set_ap_wps_ie(wpa_s, NULL, NULL, NULL); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2824 | |
| 2825 | /* |
| 2826 | * Don't cancel Probe Request RX reporting for a connected P2P Client |
| 2827 | * handling Probe Request frames. |
| 2828 | */ |
| 2829 | if (!wpa_s->p2p_cli_probe) |
| 2830 | wpa_drv_probe_req_report(wpa_s, 0); |
| 2831 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2832 | wpas_p2p_listen_work_done(wpa_s); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2833 | |
| 2834 | if (radio_work_pending(wpa_s, "p2p-listen")) { |
| 2835 | wpa_printf(MSG_DEBUG, |
| 2836 | "P2P: p2p-listen is still pending - remove it"); |
| 2837 | radio_remove_works(wpa_s, "p2p-listen", 0); |
| 2838 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2839 | } |
| 2840 | |
| 2841 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2842 | static int wpas_send_probe_resp(void *ctx, const struct wpabuf *buf, |
| 2843 | unsigned int freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2844 | { |
| 2845 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2846 | 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] | 2847 | freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2848 | } |
| 2849 | |
| 2850 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2851 | static void wpas_prov_disc_local_display(struct wpa_supplicant *wpa_s, |
| 2852 | const u8 *peer, const char *params, |
| 2853 | unsigned int generated_pin) |
| 2854 | { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2855 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR |
| 2856 | " %08d%s", MAC2STR(peer), generated_pin, params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2857 | } |
| 2858 | |
| 2859 | |
| 2860 | static void wpas_prov_disc_local_keypad(struct wpa_supplicant *wpa_s, |
| 2861 | const u8 *peer, const char *params) |
| 2862 | { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2863 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR |
| 2864 | "%s", MAC2STR(peer), params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2865 | } |
| 2866 | |
| 2867 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2868 | static void wpas_prov_disc_req(void *ctx, const u8 *peer, u16 config_methods, |
| 2869 | const u8 *dev_addr, const u8 *pri_dev_type, |
| 2870 | const char *dev_name, u16 supp_config_methods, |
| 2871 | u8 dev_capab, u8 group_capab, const u8 *group_id, |
| 2872 | size_t group_id_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2873 | { |
| 2874 | struct wpa_supplicant *wpa_s = ctx; |
| 2875 | char devtype[WPS_DEV_TYPE_BUFSIZE]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2876 | char params[300]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2877 | u8 empty_dev_type[8]; |
| 2878 | unsigned int generated_pin = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2879 | struct wpa_supplicant *group = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2880 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2881 | |
| 2882 | if (group_id) { |
| 2883 | for (group = wpa_s->global->ifaces; group; group = group->next) |
| 2884 | { |
| 2885 | struct wpa_ssid *s = group->current_ssid; |
| 2886 | if (s != NULL && |
| 2887 | s->mode == WPAS_MODE_P2P_GO && |
| 2888 | group_id_len - ETH_ALEN == s->ssid_len && |
| 2889 | os_memcmp(group_id + ETH_ALEN, s->ssid, |
| 2890 | s->ssid_len) == 0) |
| 2891 | break; |
| 2892 | } |
| 2893 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2894 | |
| 2895 | if (pri_dev_type == NULL) { |
| 2896 | os_memset(empty_dev_type, 0, sizeof(empty_dev_type)); |
| 2897 | pri_dev_type = empty_dev_type; |
| 2898 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2899 | res = os_snprintf(params, sizeof(params), " p2p_dev_addr=" MACSTR |
| 2900 | " pri_dev_type=%s name='%s' config_methods=0x%x " |
| 2901 | "dev_capab=0x%x group_capab=0x%x%s%s", |
| 2902 | MAC2STR(dev_addr), |
| 2903 | wps_dev_type_bin2str(pri_dev_type, devtype, |
| 2904 | sizeof(devtype)), |
| 2905 | dev_name, supp_config_methods, dev_capab, group_capab, |
| 2906 | group ? " group=" : "", |
| 2907 | group ? group->ifname : ""); |
| 2908 | if (os_snprintf_error(sizeof(params), res)) |
| 2909 | wpa_printf(MSG_DEBUG, "P2P: PD Request event truncated"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2910 | params[sizeof(params) - 1] = '\0'; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2911 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2912 | if (config_methods & WPS_CONFIG_DISPLAY) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2913 | if (wps_generate_pin(&generated_pin) < 0) { |
| 2914 | wpa_printf(MSG_DEBUG, "P2P: Could not generate PIN"); |
| 2915 | wpas_notify_p2p_provision_discovery( |
| 2916 | wpa_s, peer, 0 /* response */, |
Sunil Ravi | 8bae425 | 2023-11-16 03:05:19 +0000 | [diff] [blame] | 2917 | P2P_PROV_DISC_INFO_UNAVAILABLE, 0, 0, NULL); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2918 | return; |
| 2919 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2920 | wpas_prov_disc_local_display(wpa_s, peer, params, |
| 2921 | generated_pin); |
| 2922 | } else if (config_methods & WPS_CONFIG_KEYPAD) |
| 2923 | wpas_prov_disc_local_keypad(wpa_s, peer, params); |
| 2924 | else if (config_methods & WPS_CONFIG_PUSHBUTTON) |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2925 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_REQ |
| 2926 | MACSTR "%s", MAC2STR(peer), params); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2927 | |
| 2928 | wpas_notify_p2p_provision_discovery(wpa_s, peer, 1 /* request */, |
| 2929 | P2P_PROV_DISC_SUCCESS, |
Sunil Ravi | 8bae425 | 2023-11-16 03:05:19 +0000 | [diff] [blame] | 2930 | config_methods, generated_pin, |
| 2931 | group ? group->ifname : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2932 | } |
| 2933 | |
| 2934 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2935 | 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] | 2936 | { |
| 2937 | struct wpa_supplicant *wpa_s = ctx; |
| 2938 | unsigned int generated_pin = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2939 | char params[20]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2940 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2941 | if (wpa_s->pending_pd_before_join && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2942 | (ether_addr_equal(peer, wpa_s->pending_join_dev_addr) || |
| 2943 | ether_addr_equal(peer, wpa_s->pending_join_iface_addr))) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2944 | wpa_s->pending_pd_before_join = 0; |
| 2945 | wpa_printf(MSG_DEBUG, "P2P: Starting pending " |
| 2946 | "join-existing-group operation"); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2947 | wpas_p2p_join_start(wpa_s, 0, NULL, 0); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2948 | return; |
| 2949 | } |
| 2950 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2951 | if (wpa_s->pending_pd_use == AUTO_PD_JOIN || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2952 | wpa_s->pending_pd_use == AUTO_PD_GO_NEG) { |
| 2953 | int res; |
| 2954 | |
| 2955 | res = os_snprintf(params, sizeof(params), " peer_go=%d", |
| 2956 | wpa_s->pending_pd_use == AUTO_PD_JOIN); |
| 2957 | if (os_snprintf_error(sizeof(params), res)) |
| 2958 | params[sizeof(params) - 1] = '\0'; |
| 2959 | } else |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2960 | params[0] = '\0'; |
| 2961 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2962 | if (config_methods & WPS_CONFIG_DISPLAY) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2963 | wpas_prov_disc_local_keypad(wpa_s, peer, params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2964 | else if (config_methods & WPS_CONFIG_KEYPAD) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2965 | if (wps_generate_pin(&generated_pin) < 0) { |
| 2966 | wpa_printf(MSG_DEBUG, "P2P: Could not generate PIN"); |
| 2967 | wpas_notify_p2p_provision_discovery( |
| 2968 | wpa_s, peer, 0 /* response */, |
Sunil Ravi | 8bae425 | 2023-11-16 03:05:19 +0000 | [diff] [blame] | 2969 | P2P_PROV_DISC_INFO_UNAVAILABLE, 0, 0, NULL); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2970 | return; |
| 2971 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2972 | wpas_prov_disc_local_display(wpa_s, peer, params, |
| 2973 | generated_pin); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2974 | } else if (config_methods & WPS_CONFIG_PUSHBUTTON) |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2975 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_RESP |
| 2976 | MACSTR "%s", MAC2STR(peer), params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2977 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2978 | wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */, |
| 2979 | P2P_PROV_DISC_SUCCESS, |
Sunil Ravi | 8bae425 | 2023-11-16 03:05:19 +0000 | [diff] [blame] | 2980 | config_methods, generated_pin, |
| 2981 | NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2985 | static void wpas_prov_disc_fail(void *ctx, const u8 *peer, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2986 | enum p2p_prov_disc_status status, |
| 2987 | u32 adv_id, const u8 *adv_mac, |
| 2988 | const char *deferred_session_resp) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2989 | { |
| 2990 | struct wpa_supplicant *wpa_s = ctx; |
| 2991 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2992 | if (wpa_s->p2p_fallback_to_go_neg) { |
| 2993 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: PD for p2p_connect-auto " |
| 2994 | "failed - fall back to GO Negotiation"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2995 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2996 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 2997 | "reason=PD-failed"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2998 | wpas_p2p_fallback_to_go_neg(wpa_s, 0); |
| 2999 | return; |
| 3000 | } |
| 3001 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3002 | if (status == P2P_PROV_DISC_TIMEOUT_JOIN) { |
Dmitry Shmidt | 2b38048 | 2012-09-13 10:52:13 -0700 | [diff] [blame] | 3003 | wpa_s->pending_pd_before_join = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3004 | wpa_printf(MSG_DEBUG, "P2P: Starting pending " |
| 3005 | "join-existing-group operation (no ACK for PD " |
| 3006 | "Req attempts)"); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3007 | wpas_p2p_join_start(wpa_s, 0, NULL, 0); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3008 | return; |
Dmitry Shmidt | 2b38048 | 2012-09-13 10:52:13 -0700 | [diff] [blame] | 3009 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3010 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3011 | if (adv_id && adv_mac && deferred_session_resp) { |
| 3012 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE |
| 3013 | " p2p_dev_addr=" MACSTR " status=%d adv_id=%x" |
| 3014 | " deferred_session_resp='%s'", |
| 3015 | MAC2STR(peer), status, adv_id, |
| 3016 | deferred_session_resp); |
| 3017 | } else if (adv_id && adv_mac) { |
| 3018 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE |
| 3019 | " p2p_dev_addr=" MACSTR " status=%d adv_id=%x", |
| 3020 | MAC2STR(peer), status, adv_id); |
| 3021 | } else { |
| 3022 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE |
| 3023 | " p2p_dev_addr=" MACSTR " status=%d", |
| 3024 | MAC2STR(peer), status); |
| 3025 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3026 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 3027 | wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */, |
Sunil Ravi | 8bae425 | 2023-11-16 03:05:19 +0000 | [diff] [blame] | 3028 | status, 0, 0, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 3029 | } |
| 3030 | |
| 3031 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3032 | static int freq_included(struct wpa_supplicant *wpa_s, |
| 3033 | const struct p2p_channels *channels, |
| 3034 | unsigned int freq) |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3035 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3036 | if ((channels == NULL || p2p_channels_includes_freq(channels, freq)) && |
| 3037 | wpas_p2p_go_is_peer_freq(wpa_s, freq)) |
| 3038 | return 1; |
| 3039 | return 0; |
| 3040 | } |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3041 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3042 | |
| 3043 | static void wpas_p2p_go_update_common_freqs(struct wpa_supplicant *wpa_s) |
| 3044 | { |
| 3045 | unsigned int num = P2P_MAX_CHANNELS; |
| 3046 | int *common_freqs; |
| 3047 | int ret; |
| 3048 | |
| 3049 | p2p_go_dump_common_freqs(wpa_s); |
| 3050 | common_freqs = os_calloc(num, sizeof(int)); |
| 3051 | if (!common_freqs) |
| 3052 | return; |
| 3053 | |
| 3054 | ret = p2p_group_get_common_freqs(wpa_s->p2p_group, common_freqs, &num); |
| 3055 | if (ret < 0) { |
| 3056 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 3057 | "P2P: Failed to get group common freqs"); |
| 3058 | os_free(common_freqs); |
| 3059 | return; |
| 3060 | } |
| 3061 | |
| 3062 | os_free(wpa_s->p2p_group_common_freqs); |
| 3063 | wpa_s->p2p_group_common_freqs = common_freqs; |
| 3064 | wpa_s->p2p_group_common_freqs_num = num; |
| 3065 | p2p_go_dump_common_freqs(wpa_s); |
| 3066 | } |
| 3067 | |
| 3068 | |
| 3069 | /* |
| 3070 | * Check if the given frequency is one of the possible operating frequencies |
| 3071 | * set after the completion of the GO Negotiation. |
| 3072 | */ |
| 3073 | static int wpas_p2p_go_is_peer_freq(struct wpa_supplicant *wpa_s, int freq) |
| 3074 | { |
| 3075 | unsigned int i; |
| 3076 | |
| 3077 | p2p_go_dump_common_freqs(wpa_s); |
| 3078 | |
| 3079 | /* assume no restrictions */ |
| 3080 | if (!wpa_s->p2p_group_common_freqs_num) |
| 3081 | return 1; |
| 3082 | |
| 3083 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 3084 | if (wpa_s->p2p_group_common_freqs[i] == freq) |
| 3085 | return 1; |
| 3086 | } |
| 3087 | return 0; |
| 3088 | } |
| 3089 | |
| 3090 | |
| 3091 | static int wpas_sta_check_ecsa(struct hostapd_data *hapd, |
| 3092 | struct sta_info *sta, void *ctx) |
| 3093 | { |
| 3094 | int *ecsa_support = ctx; |
| 3095 | |
| 3096 | *ecsa_support &= sta->ecsa_supported; |
| 3097 | |
| 3098 | return 0; |
| 3099 | } |
| 3100 | |
| 3101 | |
| 3102 | /* Check if all the peers support eCSA */ |
| 3103 | static int wpas_p2p_go_clients_support_ecsa(struct wpa_supplicant *wpa_s) |
| 3104 | { |
| 3105 | int ecsa_support = 1; |
| 3106 | |
| 3107 | ap_for_each_sta(wpa_s->ap_iface->bss[0], wpas_sta_check_ecsa, |
| 3108 | &ecsa_support); |
| 3109 | |
| 3110 | return ecsa_support; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3111 | } |
| 3112 | |
| 3113 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3114 | /** |
| 3115 | * Pick the best frequency to use from all the currently used frequencies. |
| 3116 | */ |
| 3117 | static int wpas_p2p_pick_best_used_freq(struct wpa_supplicant *wpa_s, |
| 3118 | struct wpa_used_freq_data *freqs, |
| 3119 | unsigned int num) |
| 3120 | { |
| 3121 | unsigned int i, c; |
| 3122 | |
| 3123 | /* find a candidate freq that is supported by P2P */ |
| 3124 | for (c = 0; c < num; c++) |
| 3125 | if (p2p_supported_freq(wpa_s->global->p2p, freqs[c].freq)) |
| 3126 | break; |
| 3127 | |
| 3128 | if (c == num) |
| 3129 | return 0; |
| 3130 | |
| 3131 | /* once we have a candidate, try to find a 'better' one */ |
| 3132 | for (i = c + 1; i < num; i++) { |
| 3133 | if (!p2p_supported_freq(wpa_s->global->p2p, freqs[i].freq)) |
| 3134 | continue; |
| 3135 | |
| 3136 | /* |
| 3137 | * 1. Infrastructure station interfaces have higher preference. |
| 3138 | * 2. P2P Clients have higher preference. |
| 3139 | * 3. All others. |
| 3140 | */ |
| 3141 | if (freqs[i].flags & WPA_FREQ_USED_BY_INFRA_STATION) { |
| 3142 | c = i; |
| 3143 | break; |
| 3144 | } |
| 3145 | |
| 3146 | if ((freqs[i].flags & WPA_FREQ_USED_BY_P2P_CLIENT)) |
| 3147 | c = i; |
| 3148 | } |
| 3149 | return freqs[c].freq; |
| 3150 | } |
| 3151 | |
| 3152 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3153 | /** |
| 3154 | * Pick the best frequency the driver suggests. |
| 3155 | * |
| 3156 | * num_pref_freq is used as both input and output |
| 3157 | * - input: the max size of pref_freq_list, |
| 3158 | * - output: the valid size of pref_freq_list filled with data. |
| 3159 | */ |
| 3160 | static int wpas_p2p_pick_best_pref_freq(struct wpa_supplicant *wpa_s, bool go, |
| 3161 | struct weighted_pcl *pref_freq_list, |
| 3162 | unsigned int *num_pref_freq) |
| 3163 | { |
| 3164 | int best_freq = 0; |
| 3165 | unsigned int max_pref_freq, i; |
| 3166 | int res; |
| 3167 | enum wpa_driver_if_type iface_type; |
| 3168 | |
| 3169 | max_pref_freq = *num_pref_freq; |
| 3170 | *num_pref_freq = 0; |
| 3171 | |
| 3172 | if (go) |
| 3173 | iface_type = WPA_IF_P2P_GO; |
| 3174 | else |
| 3175 | iface_type = WPA_IF_P2P_CLIENT; |
| 3176 | |
| 3177 | res = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &max_pref_freq, |
| 3178 | pref_freq_list); |
| 3179 | if (!res && !is_p2p_allow_6ghz(wpa_s->global->p2p)) |
| 3180 | max_pref_freq = p2p_remove_6ghz_channels(pref_freq_list, |
| 3181 | max_pref_freq); |
| 3182 | if (res || !max_pref_freq) { |
| 3183 | wpa_printf(MSG_DEBUG, |
| 3184 | "P2P: No preferred frequency list available"); |
| 3185 | return 0; |
| 3186 | } |
| 3187 | |
| 3188 | *num_pref_freq = max_pref_freq; |
| 3189 | i = 0; |
| 3190 | while (i < *num_pref_freq && |
| 3191 | (!p2p_supported_freq(wpa_s->global->p2p, |
| 3192 | pref_freq_list[i].freq) || |
| 3193 | wpas_p2p_disallowed_freq(wpa_s->global, |
| 3194 | pref_freq_list[i].freq) || |
| 3195 | !p2p_pref_freq_allowed(&pref_freq_list[i], go))) { |
| 3196 | wpa_printf(MSG_DEBUG, |
| 3197 | "P2P: preferred_freq_list[%d]=%d is disallowed", |
| 3198 | i, pref_freq_list[i].freq); |
| 3199 | i++; |
| 3200 | } |
| 3201 | if (i != *num_pref_freq) { |
| 3202 | best_freq = pref_freq_list[i].freq; |
| 3203 | wpa_printf(MSG_DEBUG, "P2P: Using preferred_freq_list[%d]=%d", |
| 3204 | i, best_freq); |
| 3205 | } else { |
| 3206 | wpa_printf(MSG_DEBUG, |
| 3207 | "P2P: All driver preferred frequencies are disallowed for P2P use"); |
| 3208 | *num_pref_freq = 0; |
| 3209 | } |
| 3210 | |
| 3211 | return best_freq; |
| 3212 | } |
| 3213 | |
| 3214 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3215 | static u8 wpas_invitation_process(void *ctx, const u8 *sa, const u8 *bssid, |
| 3216 | const u8 *go_dev_addr, const u8 *ssid, |
| 3217 | size_t ssid_len, int *go, u8 *group_bssid, |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3218 | int *force_freq, int persistent_group, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3219 | const struct p2p_channels *channels, |
| 3220 | int dev_pw_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3221 | { |
| 3222 | struct wpa_supplicant *wpa_s = ctx; |
| 3223 | struct wpa_ssid *s; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3224 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3225 | struct wpa_supplicant *grp; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3226 | int best_freq; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3227 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 3228 | unsigned int num_pref_freq; |
| 3229 | int res; |
| 3230 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3231 | |
| 3232 | if (!persistent_group) { |
| 3233 | wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3234 | " to join an active group (SSID: %s)", |
| 3235 | MAC2STR(sa), wpa_ssid_txt(ssid, ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3236 | if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3237 | (ether_addr_equal(go_dev_addr, wpa_s->p2p_auth_invite) || |
| 3238 | ether_addr_equal(sa, wpa_s->p2p_auth_invite))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3239 | wpa_printf(MSG_DEBUG, "P2P: Accept previously " |
| 3240 | "authorized invitation"); |
| 3241 | goto accept_inv; |
| 3242 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3243 | |
| 3244 | #ifdef CONFIG_WPS_NFC |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3245 | if (dev_pw_id >= 0 && wpa_s->p2p_nfc_tag_enabled && |
| 3246 | dev_pw_id == wpa_s->p2p_oob_dev_pw_id) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3247 | 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] | 3248 | wpa_s->p2p_wps_method = WPS_NFC; |
| 3249 | wpa_s->pending_join_wps_method = WPS_NFC; |
| 3250 | os_memcpy(wpa_s->pending_join_dev_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3251 | go_dev_addr, ETH_ALEN); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3252 | os_memcpy(wpa_s->pending_join_iface_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3253 | bssid, ETH_ALEN); |
| 3254 | goto accept_inv; |
| 3255 | } |
| 3256 | #endif /* CONFIG_WPS_NFC */ |
| 3257 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3258 | /* |
| 3259 | * Do not accept the invitation automatically; notify user and |
| 3260 | * request approval. |
| 3261 | */ |
| 3262 | return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; |
| 3263 | } |
| 3264 | |
| 3265 | grp = wpas_get_p2p_group(wpa_s, ssid, ssid_len, go); |
| 3266 | if (grp) { |
| 3267 | wpa_printf(MSG_DEBUG, "P2P: Accept invitation to already " |
| 3268 | "running persistent group"); |
| 3269 | if (*go) |
| 3270 | os_memcpy(group_bssid, grp->own_addr, ETH_ALEN); |
| 3271 | goto accept_inv; |
| 3272 | } |
| 3273 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3274 | if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3275 | ether_addr_equal(sa, wpa_s->p2p_auth_invite)) { |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3276 | wpa_printf(MSG_DEBUG, "P2P: Accept previously initiated " |
| 3277 | "invitation to re-invoke a persistent group"); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3278 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3279 | } else if (!wpa_s->conf->persistent_reconnect) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3280 | return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; |
| 3281 | |
| 3282 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 3283 | if (s->disabled == 2 && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3284 | ether_addr_equal(s->bssid, go_dev_addr) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3285 | s->ssid_len == ssid_len && |
| 3286 | os_memcmp(ssid, s->ssid, ssid_len) == 0) |
| 3287 | break; |
| 3288 | } |
| 3289 | |
| 3290 | if (!s) { |
| 3291 | wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR |
| 3292 | " requested reinvocation of an unknown group", |
| 3293 | MAC2STR(sa)); |
| 3294 | return P2P_SC_FAIL_UNKNOWN_GROUP; |
| 3295 | } |
| 3296 | |
| 3297 | if (s->mode == WPAS_MODE_P2P_GO && !wpas_p2p_create_iface(wpa_s)) { |
| 3298 | *go = 1; |
| 3299 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
| 3300 | wpa_printf(MSG_DEBUG, "P2P: The only available " |
| 3301 | "interface is already in use - reject " |
| 3302 | "invitation"); |
| 3303 | return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; |
| 3304 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3305 | if (wpa_s->p2p_mgmt) |
| 3306 | os_memcpy(group_bssid, wpa_s->parent->own_addr, |
| 3307 | ETH_ALEN); |
| 3308 | else |
| 3309 | os_memcpy(group_bssid, wpa_s->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3310 | } else if (s->mode == WPAS_MODE_P2P_GO) { |
| 3311 | *go = 1; |
| 3312 | if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO) < 0) |
| 3313 | { |
| 3314 | wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " |
| 3315 | "interface address for the group"); |
| 3316 | return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; |
| 3317 | } |
| 3318 | os_memcpy(group_bssid, wpa_s->pending_interface_addr, |
| 3319 | ETH_ALEN); |
| 3320 | } |
| 3321 | |
| 3322 | accept_inv: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3323 | wpas_p2p_set_own_freq_preference(wpa_s, 0); |
| 3324 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3325 | best_freq = 0; |
| 3326 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 3327 | sizeof(struct wpa_used_freq_data)); |
| 3328 | if (freqs) { |
| 3329 | int num_channels = wpa_s->num_multichan_concurrent; |
| 3330 | int num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, num_channels); |
| 3331 | best_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num); |
| 3332 | os_free(freqs); |
| 3333 | } |
| 3334 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3335 | num_pref_freq = P2P_MAX_PREF_CHANNELS; |
| 3336 | res = wpas_p2p_pick_best_pref_freq(wpa_s, *go, pref_freq_list, |
| 3337 | &num_pref_freq); |
| 3338 | if (res > 0) |
| 3339 | best_freq = res; |
| 3340 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3341 | /* Get one of the frequencies currently in use */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3342 | if (best_freq > 0) { |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 3343 | 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] | 3344 | wpas_p2p_set_own_freq_preference(wpa_s, best_freq); |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 3345 | |
| 3346 | if (wpa_s->num_multichan_concurrent < 2 || |
| 3347 | wpas_p2p_num_unused_channels(wpa_s) < 1) { |
| 3348 | 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] | 3349 | *force_freq = best_freq; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 3350 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3351 | } |
| 3352 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3353 | if (*force_freq > 0 && wpa_s->num_multichan_concurrent > 1 && |
| 3354 | wpas_p2p_num_unused_channels(wpa_s) > 0) { |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3355 | if (*go == 0) { |
| 3356 | /* We are the client */ |
| 3357 | wpa_printf(MSG_DEBUG, "P2P: Peer was found to be " |
| 3358 | "running a GO but we are capable of MCC, " |
| 3359 | "figure out the best channel to use"); |
| 3360 | *force_freq = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3361 | } else if (!freq_included(wpa_s, channels, *force_freq)) { |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3362 | /* We are the GO, and *force_freq is not in the |
| 3363 | * intersection */ |
| 3364 | wpa_printf(MSG_DEBUG, "P2P: Forced GO freq %d MHz not " |
| 3365 | "in intersection but we are capable of MCC, " |
| 3366 | "figure out the best channel to use", |
| 3367 | *force_freq); |
| 3368 | *force_freq = 0; |
| 3369 | } |
| 3370 | } |
| 3371 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3372 | return P2P_SC_SUCCESS; |
| 3373 | } |
| 3374 | |
| 3375 | |
| 3376 | static void wpas_invitation_received(void *ctx, const u8 *sa, const u8 *bssid, |
| 3377 | const u8 *ssid, size_t ssid_len, |
| 3378 | const u8 *go_dev_addr, u8 status, |
| 3379 | int op_freq) |
| 3380 | { |
| 3381 | struct wpa_supplicant *wpa_s = ctx; |
| 3382 | struct wpa_ssid *s; |
| 3383 | |
| 3384 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 3385 | if (s->disabled == 2 && |
| 3386 | s->ssid_len == ssid_len && |
| 3387 | os_memcmp(ssid, s->ssid, ssid_len) == 0) |
| 3388 | break; |
| 3389 | } |
| 3390 | |
| 3391 | if (status == P2P_SC_SUCCESS) { |
| 3392 | wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3393 | " was accepted; op_freq=%d MHz, SSID=%s", |
| 3394 | MAC2STR(sa), op_freq, wpa_ssid_txt(ssid, ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3395 | if (s) { |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 3396 | int go = s->mode == WPAS_MODE_P2P_GO; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 3397 | if (go) { |
| 3398 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3399 | P2P_EVENT_INVITATION_ACCEPTED |
| 3400 | "sa=" MACSTR |
| 3401 | " persistent=%d freq=%d", |
| 3402 | MAC2STR(sa), s->id, op_freq); |
| 3403 | } else { |
| 3404 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3405 | P2P_EVENT_INVITATION_ACCEPTED |
| 3406 | "sa=" MACSTR |
| 3407 | " persistent=%d", |
| 3408 | MAC2STR(sa), s->id); |
| 3409 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3410 | wpas_p2p_group_add_persistent( |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3411 | wpa_s, s, go, 0, op_freq, 0, |
| 3412 | wpa_s->conf->p2p_go_ht40, |
| 3413 | wpa_s->conf->p2p_go_vht, |
| 3414 | 0, |
| 3415 | wpa_s->conf->p2p_go_he, |
| 3416 | wpa_s->conf->p2p_go_edmg, NULL, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3417 | go ? P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0, |
Matthew Wang | 124e5f4 | 2022-12-29 07:23:06 +0000 | [diff] [blame] | 3418 | 1, is_p2p_allow_6ghz(wpa_s->global->p2p), 0, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3419 | NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3420 | } else if (bssid) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3421 | wpa_s->user_initiated_pd = 0; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 3422 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3423 | P2P_EVENT_INVITATION_ACCEPTED |
| 3424 | "sa=" MACSTR " go_dev_addr=" MACSTR |
| 3425 | " bssid=" MACSTR " unknown-network", |
| 3426 | MAC2STR(sa), MAC2STR(go_dev_addr), |
| 3427 | MAC2STR(bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3428 | wpas_p2p_join(wpa_s, bssid, go_dev_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3429 | wpa_s->p2p_wps_method, 0, op_freq, |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3430 | ssid, ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3431 | } |
| 3432 | return; |
| 3433 | } |
| 3434 | |
| 3435 | if (status != P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) { |
| 3436 | wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR |
| 3437 | " was rejected (status %u)", MAC2STR(sa), status); |
| 3438 | return; |
| 3439 | } |
| 3440 | |
| 3441 | if (!s) { |
| 3442 | if (bssid) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3443 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3444 | P2P_EVENT_INVITATION_RECEIVED |
| 3445 | "sa=" MACSTR " go_dev_addr=" MACSTR |
| 3446 | " bssid=" MACSTR " unknown-network", |
| 3447 | MAC2STR(sa), MAC2STR(go_dev_addr), |
| 3448 | MAC2STR(bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3449 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3450 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3451 | P2P_EVENT_INVITATION_RECEIVED |
| 3452 | "sa=" MACSTR " go_dev_addr=" MACSTR |
| 3453 | " unknown-network", |
| 3454 | MAC2STR(sa), MAC2STR(go_dev_addr)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3455 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3456 | wpas_notify_p2p_invitation_received(wpa_s, sa, go_dev_addr, |
| 3457 | bssid, 0, op_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3458 | return; |
| 3459 | } |
| 3460 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3461 | if (s->mode == WPAS_MODE_P2P_GO && op_freq) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3462 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED |
| 3463 | "sa=" MACSTR " persistent=%d freq=%d", |
| 3464 | MAC2STR(sa), s->id, op_freq); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3465 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3466 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED |
| 3467 | "sa=" MACSTR " persistent=%d", |
| 3468 | MAC2STR(sa), s->id); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3469 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3470 | wpas_notify_p2p_invitation_received(wpa_s, sa, go_dev_addr, bssid, |
| 3471 | s->id, op_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3472 | } |
| 3473 | |
| 3474 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3475 | static void wpas_remove_persistent_peer(struct wpa_supplicant *wpa_s, |
| 3476 | struct wpa_ssid *ssid, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3477 | const u8 *peer, int inv) |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3478 | { |
| 3479 | size_t i; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 3480 | 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] | 3481 | |
| 3482 | if (ssid == NULL) |
| 3483 | return; |
| 3484 | |
| 3485 | for (i = 0; ssid->p2p_client_list && i < ssid->num_p2p_clients; i++) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3486 | if (ether_addr_equal(ssid->p2p_client_list + i * 2 * ETH_ALEN, |
| 3487 | peer)) |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3488 | break; |
| 3489 | } |
Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 3490 | if (i >= ssid->num_p2p_clients || !ssid->p2p_client_list) { |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3491 | if (ssid->mode != WPAS_MODE_P2P_GO && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3492 | ether_addr_equal(ssid->bssid, peer)) { |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3493 | wpa_printf(MSG_DEBUG, "P2P: Remove persistent group %d " |
| 3494 | "due to invitation result", ssid->id); |
| 3495 | wpas_notify_network_removed(wpa_s, ssid); |
| 3496 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 3497 | return; |
| 3498 | } |
| 3499 | return; /* Peer not found in client list */ |
| 3500 | } |
| 3501 | |
| 3502 | wpa_printf(MSG_DEBUG, "P2P: Remove peer " MACSTR " from persistent " |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3503 | "group %d client list%s", |
| 3504 | MAC2STR(peer), ssid->id, |
| 3505 | inv ? " due to invitation result" : ""); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3506 | os_memmove(ssid->p2p_client_list + i * 2 * ETH_ALEN, |
| 3507 | ssid->p2p_client_list + (i + 1) * 2 * ETH_ALEN, |
| 3508 | (ssid->num_p2p_clients - i - 1) * 2 * ETH_ALEN); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3509 | ssid->num_p2p_clients--; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 3510 | if (p2p_wpa_s->conf->update_config && |
| 3511 | wpa_config_write(p2p_wpa_s->confname, p2p_wpa_s->conf)) |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3512 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | |
| 3516 | static void wpas_remove_persistent_client(struct wpa_supplicant *wpa_s, |
| 3517 | const u8 *peer) |
| 3518 | { |
| 3519 | struct wpa_ssid *ssid; |
| 3520 | |
| 3521 | wpa_s = wpa_s->global->p2p_invite_group; |
| 3522 | if (wpa_s == NULL) |
| 3523 | return; /* No known invitation group */ |
| 3524 | ssid = wpa_s->current_ssid; |
| 3525 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || |
| 3526 | !ssid->p2p_persistent_group) |
| 3527 | return; /* Not operating as a GO in persistent group */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3528 | ssid = wpas_p2p_get_persistent(wpa_s->p2pdev, peer, |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3529 | ssid->ssid, ssid->ssid_len); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3530 | wpas_remove_persistent_peer(wpa_s, ssid, peer, 1); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3531 | } |
| 3532 | |
| 3533 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3534 | static void wpas_invitation_result(void *ctx, int status, const u8 *bssid, |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3535 | const struct p2p_channels *channels, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3536 | const u8 *peer, int neg_freq, |
| 3537 | int peer_oper_freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3538 | { |
| 3539 | struct wpa_supplicant *wpa_s = ctx; |
| 3540 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3541 | int freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3542 | |
| 3543 | if (bssid) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3544 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT |
| 3545 | "status=%d " MACSTR, |
| 3546 | status, MAC2STR(bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3547 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3548 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT |
| 3549 | "status=%d ", status); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3550 | } |
| 3551 | wpas_notify_p2p_invitation_result(wpa_s, status, bssid); |
| 3552 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3553 | wpa_printf(MSG_DEBUG, "P2P: Invitation result - status=%d peer=" MACSTR, |
| 3554 | status, MAC2STR(peer)); |
| 3555 | if (wpa_s->pending_invite_ssid_id == -1) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3556 | struct wpa_supplicant *group_if = |
| 3557 | wpa_s->global->p2p_invite_group; |
| 3558 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3559 | if (status == P2P_SC_FAIL_UNKNOWN_GROUP) |
| 3560 | wpas_remove_persistent_client(wpa_s, peer); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3561 | |
| 3562 | /* |
| 3563 | * Invitation to an active group. If this is successful and we |
| 3564 | * are the GO, set the client wait to postpone some concurrent |
| 3565 | * operations and to allow provisioning and connection to happen |
| 3566 | * more quickly. |
| 3567 | */ |
| 3568 | if (status == P2P_SC_SUCCESS && |
| 3569 | group_if && group_if->current_ssid && |
| 3570 | group_if->current_ssid->mode == WPAS_MODE_P2P_GO) { |
| 3571 | os_get_reltime(&wpa_s->global->p2p_go_wait_client); |
| 3572 | #ifdef CONFIG_TESTING_OPTIONS |
| 3573 | if (group_if->p2p_go_csa_on_inv) { |
| 3574 | wpa_printf(MSG_DEBUG, |
| 3575 | "Testing: force P2P GO CSA after invitation"); |
| 3576 | eloop_cancel_timeout( |
| 3577 | wpas_p2p_reconsider_moving_go, |
| 3578 | wpa_s, NULL); |
| 3579 | eloop_register_timeout( |
| 3580 | 0, 50000, |
| 3581 | wpas_p2p_reconsider_moving_go, |
| 3582 | wpa_s, NULL); |
| 3583 | } |
| 3584 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 3585 | } |
| 3586 | return; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3587 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3588 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3589 | if (status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) { |
| 3590 | wpa_printf(MSG_DEBUG, "P2P: Waiting for peer to start another " |
| 3591 | "invitation exchange to indicate readiness for " |
| 3592 | "re-invocation"); |
| 3593 | } |
| 3594 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3595 | if (status != P2P_SC_SUCCESS) { |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3596 | if (status == P2P_SC_FAIL_UNKNOWN_GROUP) { |
| 3597 | ssid = wpa_config_get_network( |
| 3598 | wpa_s->conf, wpa_s->pending_invite_ssid_id); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3599 | wpas_remove_persistent_peer(wpa_s, ssid, peer, 1); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3600 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3601 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 3602 | return; |
| 3603 | } |
| 3604 | |
| 3605 | ssid = wpa_config_get_network(wpa_s->conf, |
| 3606 | wpa_s->pending_invite_ssid_id); |
| 3607 | if (ssid == NULL) { |
| 3608 | wpa_printf(MSG_ERROR, "P2P: Could not find persistent group " |
| 3609 | "data matching with invitation"); |
| 3610 | return; |
| 3611 | } |
| 3612 | |
Jouni Malinen | 2c5b17d | 2012-10-13 21:52:46 -0700 | [diff] [blame] | 3613 | /* |
| 3614 | * The peer could have missed our ctrl::ack frame for Invitation |
| 3615 | * Response and continue retransmitting the frame. To reduce the |
| 3616 | * likelihood of the peer not getting successful TX status for the |
| 3617 | * Invitation Response frame, wait a short time here before starting |
| 3618 | * the persistent group so that we will remain on the current channel to |
| 3619 | * acknowledge any possible retransmission from the peer. |
| 3620 | */ |
| 3621 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: 50 ms wait on current channel before " |
| 3622 | "starting persistent group"); |
| 3623 | os_sleep(0, 50000); |
| 3624 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3625 | if (neg_freq > 0 && ssid->mode == WPAS_MODE_P2P_GO && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3626 | freq_included(wpa_s, channels, neg_freq)) |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3627 | freq = neg_freq; |
| 3628 | else if (peer_oper_freq > 0 && ssid->mode != WPAS_MODE_P2P_GO && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3629 | freq_included(wpa_s, channels, peer_oper_freq)) |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3630 | freq = peer_oper_freq; |
| 3631 | else |
| 3632 | freq = 0; |
| 3633 | |
| 3634 | wpa_printf(MSG_DEBUG, "P2P: Persistent group invitation success - op_freq=%d MHz SSID=%s", |
| 3635 | freq, wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3636 | wpas_p2p_group_add_persistent(wpa_s, ssid, |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 3637 | ssid->mode == WPAS_MODE_P2P_GO, |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 3638 | wpa_s->p2p_persistent_go_freq, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3639 | freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3640 | wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3641 | wpa_s->p2p_go_ht40, wpa_s->p2p_go_vht, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3642 | wpa_s->p2p_go_max_oper_chwidth, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3643 | wpa_s->p2p_go_he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3644 | wpa_s->p2p_go_edmg, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3645 | channels, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3646 | ssid->mode == WPAS_MODE_P2P_GO ? |
| 3647 | P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3648 | 0, 1, |
Matthew Wang | 124e5f4 | 2022-12-29 07:23:06 +0000 | [diff] [blame] | 3649 | is_p2p_allow_6ghz(wpa_s->global->p2p), 0, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3650 | NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3651 | } |
| 3652 | |
| 3653 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3654 | static int wpas_p2p_disallowed_freq(struct wpa_global *global, |
| 3655 | unsigned int freq) |
| 3656 | { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3657 | if (freq_range_list_includes(&global->p2p_go_avoid_freq, freq)) |
| 3658 | return 1; |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 3659 | return freq_range_list_includes(&global->p2p_disallow_freq, freq); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | |
| 3663 | static void wpas_p2p_add_chan(struct p2p_reg_class *reg, u8 chan) |
| 3664 | { |
| 3665 | reg->channel[reg->channels] = chan; |
| 3666 | reg->channels++; |
| 3667 | } |
| 3668 | |
| 3669 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3670 | static int wpas_p2p_default_channels(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3671 | struct p2p_channels *chan, |
| 3672 | struct p2p_channels *cli_chan) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3673 | { |
| 3674 | int i, cla = 0; |
| 3675 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3676 | wpa_s->global->p2p_24ghz_social_channels = 1; |
| 3677 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3678 | os_memset(cli_chan, 0, sizeof(*cli_chan)); |
| 3679 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3680 | wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for 2.4 GHz " |
| 3681 | "band"); |
| 3682 | |
| 3683 | /* Operating class 81 - 2.4 GHz band channels 1..13 */ |
| 3684 | chan->reg_class[cla].reg_class = 81; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3685 | chan->reg_class[cla].channels = 0; |
| 3686 | for (i = 0; i < 11; i++) { |
| 3687 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 2412 + i * 5)) |
| 3688 | wpas_p2p_add_chan(&chan->reg_class[cla], i + 1); |
| 3689 | } |
| 3690 | if (chan->reg_class[cla].channels) |
| 3691 | cla++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3692 | |
| 3693 | wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for lower 5 GHz " |
| 3694 | "band"); |
| 3695 | |
| 3696 | /* Operating class 115 - 5 GHz, channels 36-48 */ |
| 3697 | chan->reg_class[cla].reg_class = 115; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3698 | chan->reg_class[cla].channels = 0; |
| 3699 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 36 * 5)) |
| 3700 | wpas_p2p_add_chan(&chan->reg_class[cla], 36); |
| 3701 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 40 * 5)) |
| 3702 | wpas_p2p_add_chan(&chan->reg_class[cla], 40); |
| 3703 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 44 * 5)) |
| 3704 | wpas_p2p_add_chan(&chan->reg_class[cla], 44); |
| 3705 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 48 * 5)) |
| 3706 | wpas_p2p_add_chan(&chan->reg_class[cla], 48); |
| 3707 | if (chan->reg_class[cla].channels) |
| 3708 | cla++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3709 | |
| 3710 | wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for higher 5 GHz " |
| 3711 | "band"); |
| 3712 | |
| 3713 | /* Operating class 124 - 5 GHz, channels 149,153,157,161 */ |
| 3714 | chan->reg_class[cla].reg_class = 124; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3715 | chan->reg_class[cla].channels = 0; |
| 3716 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 149 * 5)) |
| 3717 | wpas_p2p_add_chan(&chan->reg_class[cla], 149); |
| 3718 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 153 * 5)) |
| 3719 | wpas_p2p_add_chan(&chan->reg_class[cla], 153); |
| 3720 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 156 * 5)) |
| 3721 | wpas_p2p_add_chan(&chan->reg_class[cla], 157); |
| 3722 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 161 * 5)) |
| 3723 | wpas_p2p_add_chan(&chan->reg_class[cla], 161); |
| 3724 | if (chan->reg_class[cla].channels) |
| 3725 | cla++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3726 | |
| 3727 | chan->reg_classes = cla; |
| 3728 | return 0; |
| 3729 | } |
| 3730 | |
| 3731 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3732 | static enum chan_allowed has_channel(struct wpa_global *global, |
| 3733 | struct hostapd_hw_modes *mode, u8 op_class, |
| 3734 | u8 chan, int *flags) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3735 | { |
| 3736 | int i; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3737 | unsigned int freq; |
| 3738 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3739 | freq = ieee80211_chan_to_freq(NULL, op_class, chan); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3740 | if (wpas_p2p_disallowed_freq(global, freq)) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3741 | return NOT_ALLOWED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3742 | |
| 3743 | for (i = 0; i < mode->num_channels; i++) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3744 | if ((unsigned int) mode->channels[i].freq == freq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3745 | if (flags) |
| 3746 | *flags = mode->channels[i].flag; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3747 | if (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3748 | return NOT_ALLOWED; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3749 | if (mode->channels[i].flag & HOSTAPD_CHAN_NO_IR) |
| 3750 | return NO_IR; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3751 | if (mode->channels[i].flag & HOSTAPD_CHAN_RADAR) |
| 3752 | return RADAR; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3753 | return ALLOWED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3754 | } |
| 3755 | } |
| 3756 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3757 | return NOT_ALLOWED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3761 | static int wpas_p2p_get_center_80mhz(struct wpa_supplicant *wpa_s, |
| 3762 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3763 | u8 channel, const u8 *center_channels, |
| 3764 | size_t num_chan) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3765 | { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 3766 | size_t i; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3767 | |
| 3768 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 3769 | return 0; |
| 3770 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3771 | for (i = 0; i < num_chan; i++) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3772 | /* |
| 3773 | * In 80 MHz, the bandwidth "spans" 12 channels (e.g., 36-48), |
| 3774 | * so the center channel is 6 channels away from the start/end. |
| 3775 | */ |
| 3776 | if (channel >= center_channels[i] - 6 && |
| 3777 | channel <= center_channels[i] + 6) |
| 3778 | return center_channels[i]; |
| 3779 | |
| 3780 | return 0; |
| 3781 | } |
| 3782 | |
| 3783 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3784 | static const u8 center_channels_5ghz_80mhz[] = { 42, 58, 106, 122, 138, |
| 3785 | 155, 171 }; |
| 3786 | static const u8 center_channels_6ghz_80mhz[] = { 7, 23, 39, 55, 71, 87, 103, |
| 3787 | 119, 135, 151, 167, 183, 199, |
| 3788 | 215 }; |
| 3789 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3790 | static enum chan_allowed wpas_p2p_verify_80mhz(struct wpa_supplicant *wpa_s, |
| 3791 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3792 | u8 op_class, u8 channel, u8 bw) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3793 | { |
| 3794 | u8 center_chan; |
| 3795 | int i, flags; |
| 3796 | enum chan_allowed res, ret = ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3797 | const u8 *chans; |
| 3798 | size_t num_chans; |
| 3799 | bool is_6ghz = is_6ghz_op_class(op_class); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3800 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3801 | if (is_6ghz) { |
| 3802 | chans = center_channels_6ghz_80mhz; |
| 3803 | num_chans = ARRAY_SIZE(center_channels_6ghz_80mhz); |
| 3804 | } else { |
| 3805 | chans = center_channels_5ghz_80mhz; |
| 3806 | num_chans = ARRAY_SIZE(center_channels_5ghz_80mhz); |
| 3807 | } |
| 3808 | center_chan = wpas_p2p_get_center_80mhz(wpa_s, mode, channel, |
| 3809 | chans, num_chans); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3810 | if (!center_chan) |
| 3811 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3812 | if (!wpa_s->p2p_go_allow_dfs && |
| 3813 | !is_6ghz && center_chan >= 58 && center_chan <= 138) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3814 | return NOT_ALLOWED; /* Do not allow DFS channels for P2P */ |
| 3815 | |
| 3816 | /* check all the channels are available */ |
| 3817 | for (i = 0; i < 4; i++) { |
| 3818 | int adj_chan = center_chan - 6 + i * 4; |
| 3819 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3820 | res = has_channel(wpa_s->global, mode, op_class, adj_chan, |
| 3821 | &flags); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3822 | if (res == NOT_ALLOWED) |
| 3823 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3824 | if (res == RADAR) |
| 3825 | ret = RADAR; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3826 | if (res == NO_IR) |
| 3827 | ret = NO_IR; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3828 | if (!is_6ghz) { |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3829 | if (!(flags & HOSTAPD_CHAN_VHT_80MHZ_SUBCHANNEL)) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3830 | return NOT_ALLOWED; |
| 3831 | } else if (is_6ghz && |
| 3832 | (!(wpas_get_6ghz_he_chwidth_capab(mode) & |
| 3833 | HE_PHYCAP_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G))) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3834 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3835 | } |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3836 | } |
| 3837 | |
| 3838 | return ret; |
| 3839 | } |
| 3840 | |
| 3841 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3842 | static int wpas_p2p_get_center_160mhz(struct wpa_supplicant *wpa_s, |
| 3843 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3844 | u8 channel, const u8 *center_channels, |
| 3845 | size_t num_chan) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3846 | { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3847 | unsigned int i; |
| 3848 | |
| 3849 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 3850 | return 0; |
| 3851 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3852 | for (i = 0; i < num_chan; i++) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3853 | /* |
| 3854 | * In 160 MHz, the bandwidth "spans" 28 channels (e.g., 36-64), |
| 3855 | * so the center channel is 14 channels away from the start/end. |
| 3856 | */ |
| 3857 | if (channel >= center_channels[i] - 14 && |
| 3858 | channel <= center_channels[i] + 14) |
| 3859 | return center_channels[i]; |
| 3860 | |
| 3861 | return 0; |
| 3862 | } |
| 3863 | |
| 3864 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3865 | static const u8 center_channels_5ghz_160mhz[] = { 50, 114, 163 }; |
| 3866 | static const u8 center_channels_6ghz_160mhz[] = { 15, 47, 79, 111, 143, 175, |
| 3867 | 207 }; |
| 3868 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3869 | static enum chan_allowed wpas_p2p_verify_160mhz(struct wpa_supplicant *wpa_s, |
| 3870 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3871 | u8 op_class, u8 channel, u8 bw) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3872 | { |
| 3873 | u8 center_chan; |
| 3874 | int i, flags; |
| 3875 | enum chan_allowed res, ret = ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3876 | const u8 *chans; |
| 3877 | size_t num_chans; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3878 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3879 | if (is_6ghz_op_class(op_class)) { |
| 3880 | chans = center_channels_6ghz_160mhz; |
| 3881 | num_chans = ARRAY_SIZE(center_channels_6ghz_160mhz); |
| 3882 | } else { |
| 3883 | chans = center_channels_5ghz_160mhz; |
| 3884 | num_chans = ARRAY_SIZE(center_channels_5ghz_160mhz); |
| 3885 | } |
| 3886 | center_chan = wpas_p2p_get_center_160mhz(wpa_s, mode, channel, |
| 3887 | chans, num_chans); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3888 | if (!center_chan) |
| 3889 | return NOT_ALLOWED; |
| 3890 | /* VHT 160 MHz uses DFS channels in most countries. */ |
| 3891 | |
| 3892 | /* Check all the channels are available */ |
| 3893 | for (i = 0; i < 8; i++) { |
| 3894 | int adj_chan = center_chan - 14 + i * 4; |
| 3895 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3896 | res = has_channel(wpa_s->global, mode, op_class, adj_chan, |
| 3897 | &flags); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3898 | if (res == NOT_ALLOWED) |
| 3899 | return NOT_ALLOWED; |
| 3900 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3901 | if (res == RADAR) |
| 3902 | ret = RADAR; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3903 | if (res == NO_IR) |
| 3904 | ret = NO_IR; |
| 3905 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3906 | if (!is_6ghz_op_class(op_class)) { |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3907 | if (!(flags & HOSTAPD_CHAN_VHT_80MHZ_SUBCHANNEL) || |
| 3908 | !(flags & HOSTAPD_CHAN_VHT_160MHZ_SUBCHANNEL)) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3909 | return NOT_ALLOWED; |
| 3910 | } else if (is_6ghz_op_class(op_class) && |
| 3911 | (!(wpas_get_6ghz_he_chwidth_capab(mode) & |
| 3912 | HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G))) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3913 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3914 | } |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3915 | } |
| 3916 | |
| 3917 | return ret; |
| 3918 | } |
| 3919 | |
| 3920 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3921 | static enum chan_allowed wpas_p2p_verify_edmg(struct wpa_supplicant *wpa_s, |
| 3922 | struct hostapd_hw_modes *mode, |
| 3923 | u8 channel) |
| 3924 | { |
| 3925 | struct ieee80211_edmg_config edmg; |
| 3926 | |
| 3927 | hostapd_encode_edmg_chan(1, channel, 0, &edmg); |
| 3928 | if (edmg.channels && ieee802_edmg_is_allowed(mode->edmg, edmg)) |
| 3929 | return ALLOWED; |
| 3930 | |
| 3931 | return NOT_ALLOWED; |
| 3932 | } |
| 3933 | |
| 3934 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3935 | static enum chan_allowed wpas_p2p_verify_channel(struct wpa_supplicant *wpa_s, |
| 3936 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3937 | u8 op_class, u8 channel, u8 bw) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3938 | { |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 3939 | int flag = 0; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3940 | enum chan_allowed res, res2; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3941 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3942 | if (is_6ghz_op_class(op_class) && !is_6ghz_psc_frequency( |
| 3943 | p2p_channel_to_freq(op_class, channel))) |
| 3944 | return NOT_ALLOWED; |
| 3945 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3946 | res2 = res = has_channel(wpa_s->global, mode, op_class, channel, &flag); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3947 | if (bw == BW40MINUS) { |
| 3948 | if (!(flag & HOSTAPD_CHAN_HT40MINUS)) |
| 3949 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3950 | res2 = has_channel(wpa_s->global, mode, op_class, channel - 4, |
| 3951 | NULL); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3952 | } else if (bw == BW40PLUS) { |
| 3953 | if (!(flag & HOSTAPD_CHAN_HT40PLUS)) |
| 3954 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3955 | res2 = has_channel(wpa_s->global, mode, op_class, channel + 4, |
| 3956 | NULL); |
| 3957 | } else if (is_6ghz_op_class(op_class) && bw == BW40) { |
| 3958 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 3959 | return NOT_ALLOWED; |
| 3960 | if (get_6ghz_sec_channel(channel) < 0) |
| 3961 | res2 = has_channel(wpa_s->global, mode, op_class, |
| 3962 | channel - 4, NULL); |
| 3963 | else |
| 3964 | res2 = has_channel(wpa_s->global, mode, op_class, |
| 3965 | channel + 4, NULL); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3966 | } else if (bw == BW80) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3967 | res2 = wpas_p2p_verify_80mhz(wpa_s, mode, op_class, channel, |
| 3968 | bw); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3969 | } else if (bw == BW160) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3970 | res2 = wpas_p2p_verify_160mhz(wpa_s, mode, op_class, channel, |
| 3971 | bw); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3972 | } else if (bw == BW4320 || bw == BW6480 || bw == BW8640) { |
| 3973 | return wpas_p2p_verify_edmg(wpa_s, mode, channel); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3974 | } |
| 3975 | |
| 3976 | if (res == NOT_ALLOWED || res2 == NOT_ALLOWED) |
| 3977 | return NOT_ALLOWED; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3978 | if (res == NO_IR || res2 == NO_IR) |
| 3979 | return NO_IR; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3980 | if (res == RADAR || res2 == RADAR) |
| 3981 | return RADAR; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3982 | return res; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3983 | } |
| 3984 | |
| 3985 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3986 | static int wpas_p2p_setup_channels(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3987 | struct p2p_channels *chan, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3988 | struct p2p_channels *cli_chan, |
| 3989 | bool p2p_disable_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3990 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3991 | struct hostapd_hw_modes *mode; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3992 | int cla, op, cli_cla; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3993 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3994 | if (wpa_s->hw.modes == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3995 | wpa_printf(MSG_DEBUG, "P2P: Driver did not support fetching " |
| 3996 | "of all supported channels; assume dualband " |
| 3997 | "support"); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3998 | return wpas_p2p_default_channels(wpa_s, chan, cli_chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3999 | } |
| 4000 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4001 | cla = cli_cla = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4002 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4003 | for (op = 0; global_op_class[op].op_class; op++) { |
| 4004 | const struct oper_class_map *o = &global_op_class[op]; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4005 | unsigned int ch; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4006 | struct p2p_reg_class *reg = NULL, *cli_reg = NULL; |
Shuibing Dai | e2fad41 | 2023-05-05 14:08:11 -0700 | [diff] [blame] | 4007 | bool check_dfs_supported = (is_p2p_dfs_chan_enabled(wpa_s->global->p2p) |
Shuibing Dai | 64a8a89 | 2023-03-08 10:26:22 -0800 | [diff] [blame] | 4008 | && is_dfs_global_op_class(o->op_class)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4009 | |
Shuibing Dai | 64a8a89 | 2023-03-08 10:26:22 -0800 | [diff] [blame] | 4010 | if ((!check_dfs_supported && o->p2p == NO_P2P_SUPP) || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4011 | (is_6ghz_op_class(o->op_class) && p2p_disable_6ghz)) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4012 | continue; |
| 4013 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4014 | mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, o->mode, |
| 4015 | is_6ghz_op_class(o->op_class)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4016 | if (mode == NULL) |
| 4017 | continue; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4018 | if (mode->mode == HOSTAPD_MODE_IEEE80211G) |
| 4019 | wpa_s->global->p2p_24ghz_social_channels = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4020 | for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4021 | enum chan_allowed res; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4022 | |
| 4023 | /* Check for non-continuous jump in channel index |
| 4024 | * incrementation */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4025 | if ((o->op_class >= 128 && o->op_class <= 130) && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4026 | ch < 149 && ch + o->inc > 149) |
| 4027 | ch = 149; |
| 4028 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4029 | res = wpas_p2p_verify_channel(wpa_s, mode, o->op_class, |
| 4030 | ch, o->bw); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4031 | if (res == ALLOWED) { |
| 4032 | if (reg == NULL) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4033 | if (cla == P2P_MAX_REG_CLASSES) |
| 4034 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4035 | wpa_printf(MSG_DEBUG, "P2P: Add operating class %u", |
| 4036 | o->op_class); |
| 4037 | reg = &chan->reg_class[cla]; |
| 4038 | cla++; |
| 4039 | reg->reg_class = o->op_class; |
| 4040 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4041 | if (reg->channels == P2P_MAX_REG_CLASS_CHANNELS) |
| 4042 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4043 | reg->channel[reg->channels] = ch; |
| 4044 | reg->channels++; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4045 | } else if (res == NO_IR && |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4046 | wpa_s->conf->p2p_add_cli_chan) { |
| 4047 | if (cli_reg == NULL) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4048 | if (cli_cla == P2P_MAX_REG_CLASSES) |
| 4049 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4050 | wpa_printf(MSG_DEBUG, "P2P: Add operating class %u (client only)", |
| 4051 | o->op_class); |
| 4052 | cli_reg = &cli_chan->reg_class[cli_cla]; |
| 4053 | cli_cla++; |
| 4054 | cli_reg->reg_class = o->op_class; |
| 4055 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4056 | if (cli_reg->channels == |
| 4057 | P2P_MAX_REG_CLASS_CHANNELS) |
| 4058 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4059 | cli_reg->channel[cli_reg->channels] = ch; |
| 4060 | cli_reg->channels++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4061 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4062 | } |
| 4063 | if (reg) { |
| 4064 | wpa_hexdump(MSG_DEBUG, "P2P: Channels", |
| 4065 | reg->channel, reg->channels); |
| 4066 | } |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4067 | if (cli_reg) { |
| 4068 | wpa_hexdump(MSG_DEBUG, "P2P: Channels (client only)", |
| 4069 | cli_reg->channel, cli_reg->channels); |
| 4070 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4071 | } |
| 4072 | |
| 4073 | chan->reg_classes = cla; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4074 | cli_chan->reg_classes = cli_cla; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4075 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4076 | return 0; |
| 4077 | } |
| 4078 | |
| 4079 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4080 | int wpas_p2p_get_sec_channel_offset_40mhz(struct wpa_supplicant *wpa_s, |
| 4081 | struct hostapd_hw_modes *mode, |
| 4082 | u8 channel) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4083 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4084 | int op; |
| 4085 | enum chan_allowed ret; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4086 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4087 | for (op = 0; global_op_class[op].op_class; op++) { |
| 4088 | const struct oper_class_map *o = &global_op_class[op]; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4089 | u16 ch = 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4090 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4091 | /* Allow DFS channels marked as NO_P2P_SUPP to be used with |
| 4092 | * driver offloaded DFS. */ |
| 4093 | if ((o->p2p == NO_P2P_SUPP && |
| 4094 | (!is_dfs_global_op_class(o->op_class) || |
| 4095 | !wpa_s->p2p_go_allow_dfs)) || |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4096 | (is_6ghz_op_class(o->op_class) && |
| 4097 | wpa_s->conf->p2p_6ghz_disable)) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4098 | continue; |
| 4099 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4100 | /* IEEE Std 802.11ax-2021 26.17.2.3.2: "A 6 GHz-only AP should |
| 4101 | * set up the BSS with a primary 20 MHz channel that coincides |
| 4102 | * with a preferred scanning channel (PSC)." |
| 4103 | * 6 GHz BW40 operation class 132 in wpa_supplicant uses the |
| 4104 | * lowest 20 MHz channel for simplicity, so increase ch by 4 to |
| 4105 | * match the PSC. |
| 4106 | */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4107 | if (is_6ghz_op_class(o->op_class) && o->bw == BW40 && |
| 4108 | get_6ghz_sec_channel(channel) < 0) |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4109 | ch = 4; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4110 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4111 | for (ch += o->min_chan; ch <= o->max_chan; ch += o->inc) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4112 | if (o->mode != HOSTAPD_MODE_IEEE80211A || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4113 | (o->bw != BW40PLUS && o->bw != BW40MINUS && |
| 4114 | o->bw != BW40) || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4115 | ch != channel) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4116 | continue; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4117 | ret = wpas_p2p_verify_channel(wpa_s, mode, o->op_class, |
| 4118 | ch, o->bw); |
| 4119 | if (ret == ALLOWED) { |
| 4120 | if (is_6ghz_op_class(o->op_class) && |
| 4121 | o->bw == BW40) |
| 4122 | return get_6ghz_sec_channel(channel); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4123 | return (o->bw == BW40MINUS) ? -1 : 1; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4124 | } |
| 4125 | if (ret == RADAR && wpa_s->p2p_go_allow_dfs) { |
| 4126 | /* Allow RADAR channels used for driver |
| 4127 | * offloaded DFS */ |
| 4128 | return (o->bw == BW40MINUS) ? -1 : 1; |
| 4129 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4130 | } |
| 4131 | } |
| 4132 | return 0; |
| 4133 | } |
| 4134 | |
| 4135 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4136 | int wpas_p2p_get_vht80_center(struct wpa_supplicant *wpa_s, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4137 | struct hostapd_hw_modes *mode, u8 channel, |
| 4138 | u8 op_class) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4139 | { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4140 | const u8 *chans; |
| 4141 | size_t num_chans; |
| 4142 | enum chan_allowed ret; |
| 4143 | |
| 4144 | ret = wpas_p2p_verify_channel(wpa_s, mode, op_class, channel, BW80); |
| 4145 | if (!(ret == ALLOWED || (ret == RADAR && wpa_s->p2p_go_allow_dfs))) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4146 | return 0; |
| 4147 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4148 | if (is_6ghz_op_class(op_class)) { |
| 4149 | chans = center_channels_6ghz_80mhz; |
| 4150 | num_chans = ARRAY_SIZE(center_channels_6ghz_80mhz); |
| 4151 | } else { |
| 4152 | chans = center_channels_5ghz_80mhz; |
| 4153 | num_chans = ARRAY_SIZE(center_channels_5ghz_80mhz); |
| 4154 | } |
| 4155 | return wpas_p2p_get_center_80mhz(wpa_s, mode, channel, |
| 4156 | chans, num_chans); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4157 | } |
| 4158 | |
| 4159 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4160 | int wpas_p2p_get_vht160_center(struct wpa_supplicant *wpa_s, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4161 | struct hostapd_hw_modes *mode, u8 channel, |
| 4162 | u8 op_class) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4163 | { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4164 | const u8 *chans; |
| 4165 | size_t num_chans; |
| 4166 | enum chan_allowed ret; |
| 4167 | |
| 4168 | ret = wpas_p2p_verify_channel(wpa_s, mode, op_class, channel, BW160); |
| 4169 | if (!(ret == ALLOWED || (ret == RADAR && wpa_s->p2p_go_allow_dfs))) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4170 | return 0; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4171 | if (is_6ghz_op_class(op_class)) { |
| 4172 | chans = center_channels_6ghz_160mhz; |
| 4173 | num_chans = ARRAY_SIZE(center_channels_6ghz_160mhz); |
| 4174 | } else { |
| 4175 | chans = center_channels_5ghz_160mhz; |
| 4176 | num_chans = ARRAY_SIZE(center_channels_5ghz_160mhz); |
| 4177 | } |
| 4178 | return wpas_p2p_get_center_160mhz(wpa_s, mode, channel, |
| 4179 | chans, num_chans); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4180 | } |
| 4181 | |
| 4182 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4183 | static int wpas_get_noa(void *ctx, const u8 *interface_addr, u8 *buf, |
| 4184 | size_t buf_len) |
| 4185 | { |
| 4186 | struct wpa_supplicant *wpa_s = ctx; |
| 4187 | |
| 4188 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4189 | if (ether_addr_equal(wpa_s->own_addr, interface_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4190 | break; |
| 4191 | } |
| 4192 | if (wpa_s == NULL) |
| 4193 | return -1; |
| 4194 | |
| 4195 | return wpa_drv_get_noa(wpa_s, buf, buf_len); |
| 4196 | } |
| 4197 | |
| 4198 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4199 | struct wpa_supplicant * wpas_get_p2p_go_iface(struct wpa_supplicant *wpa_s, |
| 4200 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4201 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4202 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 4203 | struct wpa_ssid *s = wpa_s->current_ssid; |
| 4204 | if (s == NULL) |
| 4205 | continue; |
| 4206 | if (s->mode != WPAS_MODE_P2P_GO && |
| 4207 | s->mode != WPAS_MODE_AP && |
| 4208 | s->mode != WPAS_MODE_P2P_GROUP_FORMATION) |
| 4209 | continue; |
| 4210 | if (s->ssid_len != ssid_len || |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 4211 | os_memcmp(ssid, s->ssid, ssid_len) != 0) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4212 | continue; |
| 4213 | return wpa_s; |
| 4214 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4215 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4216 | return NULL; |
| 4217 | |
| 4218 | } |
| 4219 | |
| 4220 | |
| 4221 | struct wpa_supplicant * wpas_get_p2p_client_iface(struct wpa_supplicant *wpa_s, |
| 4222 | const u8 *peer_dev_addr) |
| 4223 | { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4224 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 4225 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4226 | if (ssid && (ssid->mode != WPAS_MODE_INFRA || !ssid->p2p_group)) |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4227 | continue; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4228 | if (ether_addr_equal(wpa_s->go_dev_addr, peer_dev_addr)) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4229 | return wpa_s; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4230 | } |
| 4231 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4232 | return NULL; |
| 4233 | } |
| 4234 | |
| 4235 | |
| 4236 | static int wpas_go_connected(void *ctx, const u8 *dev_addr) |
| 4237 | { |
| 4238 | struct wpa_supplicant *wpa_s = ctx; |
| 4239 | |
| 4240 | return wpas_get_p2p_client_iface(wpa_s, dev_addr) != NULL; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4241 | } |
| 4242 | |
| 4243 | |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 4244 | static int wpas_is_concurrent_session_active(void *ctx) |
| 4245 | { |
| 4246 | struct wpa_supplicant *wpa_s = ctx; |
| 4247 | struct wpa_supplicant *ifs; |
| 4248 | |
| 4249 | for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) { |
| 4250 | if (ifs == wpa_s) |
| 4251 | continue; |
| 4252 | if (ifs->wpa_state > WPA_ASSOCIATED) |
| 4253 | return 1; |
| 4254 | } |
| 4255 | return 0; |
| 4256 | } |
| 4257 | |
| 4258 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 4259 | static void wpas_p2p_debug_print(void *ctx, int level, const char *msg) |
| 4260 | { |
| 4261 | struct wpa_supplicant *wpa_s = ctx; |
| 4262 | wpa_msg_global(wpa_s, level, "P2P: %s", msg); |
| 4263 | } |
| 4264 | |
| 4265 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4266 | int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s, |
| 4267 | const char *conf_p2p_dev) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4268 | { |
| 4269 | struct wpa_interface iface; |
| 4270 | struct wpa_supplicant *p2pdev_wpa_s; |
| 4271 | char ifname[100]; |
| 4272 | char force_name[100]; |
| 4273 | int ret; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4274 | const u8 *if_addr = NULL; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4275 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4276 | ret = os_snprintf(ifname, sizeof(ifname), P2P_MGMT_DEVICE_PREFIX "%s", |
| 4277 | wpa_s->ifname); |
| 4278 | if (os_snprintf_error(sizeof(ifname), ret)) |
| 4279 | return -1; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4280 | /* Cut length at the maximum size. Note that we don't need to ensure |
| 4281 | * collision free names here as the created interface is not a netdev. |
| 4282 | */ |
| 4283 | ifname[IFNAMSIZ - 1] = '\0'; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4284 | force_name[0] = '\0'; |
| 4285 | wpa_s->pending_interface_type = WPA_IF_P2P_DEVICE; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4286 | |
| 4287 | if (wpa_s->conf->p2p_device_random_mac_addr == 2 && |
| 4288 | !is_zero_ether_addr(wpa_s->conf->p2p_device_persistent_mac_addr)) |
| 4289 | if_addr = wpa_s->conf->p2p_device_persistent_mac_addr; |
| 4290 | |
| 4291 | 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] | 4292 | force_name, wpa_s->pending_interface_addr, NULL); |
| 4293 | if (ret < 0) { |
| 4294 | wpa_printf(MSG_DEBUG, "P2P: Failed to create P2P Device interface"); |
| 4295 | return ret; |
| 4296 | } |
| 4297 | os_strlcpy(wpa_s->pending_interface_name, ifname, |
| 4298 | sizeof(wpa_s->pending_interface_name)); |
| 4299 | |
| 4300 | os_memset(&iface, 0, sizeof(iface)); |
| 4301 | iface.p2p_mgmt = 1; |
| 4302 | iface.ifname = wpa_s->pending_interface_name; |
| 4303 | iface.driver = wpa_s->driver->name; |
| 4304 | iface.driver_param = wpa_s->conf->driver_param; |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4305 | |
| 4306 | /* |
| 4307 | * If a P2P Device configuration file was given, use it as the interface |
| 4308 | * configuration file (instead of using parent's configuration file. |
| 4309 | */ |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4310 | if (conf_p2p_dev) { |
| 4311 | iface.confname = conf_p2p_dev; |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4312 | iface.ctrl_interface = NULL; |
| 4313 | } else { |
| 4314 | iface.confname = wpa_s->confname; |
| 4315 | iface.ctrl_interface = wpa_s->conf->ctrl_interface; |
| 4316 | } |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4317 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4318 | 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] | 4319 | if (!p2pdev_wpa_s) { |
| 4320 | wpa_printf(MSG_DEBUG, "P2P: Failed to add P2P Device interface"); |
| 4321 | return -1; |
| 4322 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4323 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4324 | p2pdev_wpa_s->p2pdev = p2pdev_wpa_s; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4325 | wpa_s->pending_interface_name[0] = '\0'; |
| 4326 | return 0; |
| 4327 | } |
| 4328 | |
| 4329 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4330 | static void wpas_presence_resp(void *ctx, const u8 *src, u8 status, |
| 4331 | const u8 *noa, size_t noa_len) |
| 4332 | { |
| 4333 | struct wpa_supplicant *wpa_s, *intf = ctx; |
| 4334 | char hex[100]; |
| 4335 | |
| 4336 | for (wpa_s = intf->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 4337 | if (wpa_s->waiting_presence_resp) |
| 4338 | break; |
| 4339 | } |
| 4340 | if (!wpa_s) { |
| 4341 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No group interface was waiting for presence response"); |
| 4342 | return; |
| 4343 | } |
| 4344 | wpa_s->waiting_presence_resp = 0; |
| 4345 | |
| 4346 | wpa_snprintf_hex(hex, sizeof(hex), noa, noa_len); |
| 4347 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PRESENCE_RESPONSE "src=" MACSTR |
| 4348 | " status=%u noa=%s", MAC2STR(src), status, hex); |
| 4349 | } |
| 4350 | |
| 4351 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4352 | static int wpas_get_persistent_group(void *ctx, const u8 *addr, const u8 *ssid, |
| 4353 | size_t ssid_len, u8 *go_dev_addr, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4354 | u8 *ret_ssid, size_t *ret_ssid_len, |
| 4355 | u8 *intended_iface_addr) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4356 | { |
| 4357 | struct wpa_supplicant *wpa_s = ctx; |
| 4358 | struct wpa_ssid *s; |
| 4359 | |
| 4360 | s = wpas_p2p_get_persistent(wpa_s, addr, ssid, ssid_len); |
| 4361 | if (s) { |
| 4362 | os_memcpy(ret_ssid, s->ssid, s->ssid_len); |
| 4363 | *ret_ssid_len = s->ssid_len; |
| 4364 | os_memcpy(go_dev_addr, s->bssid, ETH_ALEN); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4365 | |
| 4366 | if (s->mode != WPAS_MODE_P2P_GO) { |
| 4367 | os_memset(intended_iface_addr, 0, ETH_ALEN); |
| 4368 | } else if (wpas_p2p_create_iface(wpa_s)) { |
| 4369 | if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO)) |
| 4370 | return 0; |
| 4371 | |
| 4372 | os_memcpy(intended_iface_addr, |
| 4373 | wpa_s->pending_interface_addr, ETH_ALEN); |
| 4374 | } else { |
| 4375 | os_memcpy(intended_iface_addr, wpa_s->own_addr, |
| 4376 | ETH_ALEN); |
| 4377 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4378 | return 1; |
| 4379 | } |
| 4380 | |
| 4381 | return 0; |
| 4382 | } |
| 4383 | |
| 4384 | |
| 4385 | static int wpas_get_go_info(void *ctx, u8 *intended_addr, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4386 | u8 *ssid, size_t *ssid_len, int *group_iface, |
| 4387 | unsigned int *freq) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4388 | { |
| 4389 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4390 | struct wpa_supplicant *go; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4391 | struct wpa_ssid *s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4392 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4393 | /* |
| 4394 | * group_iface will be set to 1 only if a dedicated interface for P2P |
| 4395 | * role is required. First, we try to reuse an active GO. However, |
| 4396 | * if it is not present, we will try to reactivate an existing |
| 4397 | * persistent group and set group_iface to 1, so the caller will know |
| 4398 | * that the pending interface should be used. |
| 4399 | */ |
| 4400 | *group_iface = 0; |
| 4401 | |
| 4402 | if (freq) |
| 4403 | *freq = 0; |
| 4404 | |
| 4405 | go = wpas_p2p_get_go_group(wpa_s); |
| 4406 | if (!go) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4407 | s = wpas_p2p_get_persistent_go(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4408 | *group_iface = wpas_p2p_create_iface(wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4409 | if (s) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4410 | os_memcpy(intended_addr, s->bssid, ETH_ALEN); |
| 4411 | else |
| 4412 | return 0; |
| 4413 | } else { |
| 4414 | s = go->current_ssid; |
| 4415 | os_memcpy(intended_addr, go->own_addr, ETH_ALEN); |
| 4416 | if (freq) |
| 4417 | *freq = go->assoc_freq; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4418 | } |
| 4419 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4420 | os_memcpy(ssid, s->ssid, s->ssid_len); |
| 4421 | *ssid_len = s->ssid_len; |
| 4422 | |
| 4423 | return 1; |
| 4424 | } |
| 4425 | |
| 4426 | |
| 4427 | static int wpas_remove_stale_groups(void *ctx, const u8 *peer, const u8 *go, |
| 4428 | const u8 *ssid, size_t ssid_len) |
| 4429 | { |
| 4430 | struct wpa_supplicant *wpa_s = ctx; |
| 4431 | struct wpa_ssid *s; |
| 4432 | int save_config = 0; |
| 4433 | size_t i; |
| 4434 | |
| 4435 | /* Start with our first choice of Persistent Groups */ |
| 4436 | while ((s = wpas_p2p_get_persistent(wpa_s, peer, NULL, 0))) { |
| 4437 | if (go && ssid && ssid_len && |
| 4438 | s->ssid_len == ssid_len && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4439 | ether_addr_equal(go, s->bssid) && |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4440 | os_memcmp(ssid, s->ssid, ssid_len) == 0) |
| 4441 | break; |
| 4442 | |
| 4443 | /* Remove stale persistent group */ |
| 4444 | if (s->mode != WPAS_MODE_P2P_GO || s->num_p2p_clients <= 1) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4445 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4446 | "P2P: Remove stale persistent group id=%d", |
| 4447 | s->id); |
| 4448 | wpas_notify_persistent_group_removed(wpa_s, s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4449 | wpa_config_remove_network(wpa_s->conf, s->id); |
| 4450 | save_config = 1; |
| 4451 | continue; |
| 4452 | } |
| 4453 | |
| 4454 | for (i = 0; i < s->num_p2p_clients; i++) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4455 | if (!ether_addr_equal(s->p2p_client_list + |
| 4456 | i * 2 * ETH_ALEN, peer)) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4457 | continue; |
| 4458 | |
| 4459 | os_memmove(s->p2p_client_list + i * 2 * ETH_ALEN, |
| 4460 | s->p2p_client_list + (i + 1) * 2 * ETH_ALEN, |
| 4461 | (s->num_p2p_clients - i - 1) * 2 * ETH_ALEN); |
| 4462 | break; |
| 4463 | } |
| 4464 | s->num_p2p_clients--; |
| 4465 | save_config = 1; |
| 4466 | } |
| 4467 | |
| 4468 | if (save_config) |
| 4469 | p2p_config_write(wpa_s); |
| 4470 | |
| 4471 | /* Return TRUE if valid SSID remains */ |
| 4472 | return s != NULL; |
| 4473 | } |
| 4474 | |
| 4475 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4476 | static void wpas_p2ps_get_feat_cap_str(char *buf, size_t buf_len, |
| 4477 | const u8 *feat_cap, size_t feat_cap_len) |
| 4478 | { |
| 4479 | static const char pref[] = " feature_cap="; |
| 4480 | int ret; |
| 4481 | |
| 4482 | buf[0] = '\0'; |
| 4483 | |
| 4484 | /* |
| 4485 | * We expect a feature capability to contain at least one byte to be |
| 4486 | * reported. The string buffer provided by the caller function is |
| 4487 | * expected to be big enough to contain all bytes of the attribute for |
| 4488 | * known specifications. This function truncates the reported bytes if |
| 4489 | * the feature capability data exceeds the string buffer size. |
| 4490 | */ |
| 4491 | if (!feat_cap || !feat_cap_len || buf_len < sizeof(pref) + 2) |
| 4492 | return; |
| 4493 | |
| 4494 | os_memcpy(buf, pref, sizeof(pref)); |
| 4495 | ret = wpa_snprintf_hex(&buf[sizeof(pref) - 1], |
| 4496 | buf_len - sizeof(pref) + 1, |
| 4497 | feat_cap, feat_cap_len); |
| 4498 | |
| 4499 | if (ret != (2 * (int) feat_cap_len)) |
| 4500 | wpa_printf(MSG_WARNING, "P2PS feature_cap bytes truncated"); |
| 4501 | } |
| 4502 | |
| 4503 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4504 | static void wpas_p2ps_prov_complete(void *ctx, u8 status, const u8 *dev, |
| 4505 | const u8 *adv_mac, const u8 *ses_mac, |
| 4506 | const u8 *grp_mac, u32 adv_id, u32 ses_id, |
| 4507 | u8 conncap, int passwd_id, |
| 4508 | const u8 *persist_ssid, |
| 4509 | size_t persist_ssid_size, int response_done, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4510 | int prov_start, const char *session_info, |
| 4511 | const u8 *feat_cap, size_t feat_cap_len, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4512 | unsigned int freq, |
| 4513 | const u8 *group_ssid, size_t group_ssid_len) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4514 | { |
| 4515 | struct wpa_supplicant *wpa_s = ctx; |
| 4516 | u8 mac[ETH_ALEN]; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4517 | struct wpa_ssid *persistent_go, *stale, *s = NULL; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4518 | int save_config = 0; |
| 4519 | struct wpa_supplicant *go_wpa_s; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4520 | char feat_cap_str[256]; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4521 | |
| 4522 | if (!dev) |
| 4523 | return; |
| 4524 | |
| 4525 | os_memset(mac, 0, ETH_ALEN); |
| 4526 | if (!adv_mac) |
| 4527 | adv_mac = mac; |
| 4528 | if (!ses_mac) |
| 4529 | ses_mac = mac; |
| 4530 | if (!grp_mac) |
| 4531 | grp_mac = mac; |
| 4532 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4533 | wpas_p2ps_get_feat_cap_str(feat_cap_str, sizeof(feat_cap_str), |
| 4534 | feat_cap, feat_cap_len); |
| 4535 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4536 | if (prov_start) { |
| 4537 | if (session_info == NULL) { |
| 4538 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4539 | P2P_EVENT_P2PS_PROVISION_START MACSTR |
| 4540 | " adv_id=%x conncap=%x" |
| 4541 | " adv_mac=" MACSTR |
| 4542 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4543 | " dev_passwd_id=%d%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4544 | MAC2STR(dev), adv_id, conncap, |
| 4545 | MAC2STR(adv_mac), |
| 4546 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4547 | passwd_id, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4548 | } else { |
| 4549 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4550 | P2P_EVENT_P2PS_PROVISION_START MACSTR |
| 4551 | " adv_id=%x conncap=%x" |
| 4552 | " adv_mac=" MACSTR |
| 4553 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4554 | " dev_passwd_id=%d info='%s'%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4555 | MAC2STR(dev), adv_id, conncap, |
| 4556 | MAC2STR(adv_mac), |
| 4557 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4558 | passwd_id, session_info, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4559 | } |
| 4560 | return; |
| 4561 | } |
| 4562 | |
| 4563 | go_wpa_s = wpas_p2p_get_go_group(wpa_s); |
| 4564 | persistent_go = wpas_p2p_get_persistent_go(wpa_s); |
| 4565 | |
| 4566 | if (status && status != P2P_SC_SUCCESS_DEFERRED) { |
| 4567 | if (go_wpa_s && !p2p_group_go_member_count(wpa_s)) |
| 4568 | wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname); |
| 4569 | |
| 4570 | if (persistent_go && !persistent_go->num_p2p_clients) { |
| 4571 | /* remove empty persistent GO */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4572 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4573 | "P2P: Remove empty persistent group id=%d", |
| 4574 | persistent_go->id); |
| 4575 | wpas_notify_persistent_group_removed(wpa_s, |
| 4576 | persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4577 | wpa_config_remove_network(wpa_s->conf, |
| 4578 | persistent_go->id); |
| 4579 | } |
| 4580 | |
| 4581 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4582 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4583 | " status=%d" |
| 4584 | " adv_id=%x adv_mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4585 | " session=%x mac=" MACSTR "%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4586 | MAC2STR(dev), status, |
| 4587 | adv_id, MAC2STR(adv_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4588 | ses_id, MAC2STR(ses_mac), feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4589 | return; |
| 4590 | } |
| 4591 | |
| 4592 | /* Clean up stale persistent groups with this device */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4593 | if (persist_ssid && persist_ssid_size) |
| 4594 | s = wpas_p2p_get_persistent(wpa_s, dev, persist_ssid, |
| 4595 | persist_ssid_size); |
| 4596 | |
| 4597 | if (persist_ssid && s && s->mode != WPAS_MODE_P2P_GO && |
| 4598 | is_zero_ether_addr(grp_mac)) { |
| 4599 | wpa_dbg(wpa_s, MSG_ERROR, |
| 4600 | "P2P: Peer device is a GO in a persistent group, but it did not provide the intended MAC address"); |
| 4601 | return; |
| 4602 | } |
| 4603 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4604 | for (;;) { |
| 4605 | stale = wpas_p2p_get_persistent(wpa_s, dev, NULL, 0); |
| 4606 | if (!stale) |
| 4607 | break; |
| 4608 | |
| 4609 | if (s && s->ssid_len == stale->ssid_len && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4610 | ether_addr_equal(stale->bssid, s->bssid) && |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4611 | os_memcmp(stale->ssid, s->ssid, s->ssid_len) == 0) |
| 4612 | break; |
| 4613 | |
| 4614 | /* Remove stale persistent group */ |
| 4615 | if (stale->mode != WPAS_MODE_P2P_GO || |
| 4616 | stale->num_p2p_clients <= 1) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4617 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4618 | "P2P: Remove stale persistent group id=%d", |
| 4619 | stale->id); |
| 4620 | wpas_notify_persistent_group_removed(wpa_s, stale); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4621 | wpa_config_remove_network(wpa_s->conf, stale->id); |
| 4622 | } else { |
| 4623 | size_t i; |
| 4624 | |
| 4625 | for (i = 0; i < stale->num_p2p_clients; i++) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4626 | if (ether_addr_equal(stale->p2p_client_list + |
| 4627 | i * ETH_ALEN, dev)) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4628 | os_memmove(stale->p2p_client_list + |
| 4629 | i * ETH_ALEN, |
| 4630 | stale->p2p_client_list + |
| 4631 | (i + 1) * ETH_ALEN, |
| 4632 | (stale->num_p2p_clients - |
| 4633 | i - 1) * ETH_ALEN); |
| 4634 | break; |
| 4635 | } |
| 4636 | } |
| 4637 | stale->num_p2p_clients--; |
| 4638 | } |
| 4639 | save_config = 1; |
| 4640 | } |
| 4641 | |
| 4642 | if (save_config) |
| 4643 | p2p_config_write(wpa_s); |
| 4644 | |
| 4645 | if (s) { |
| 4646 | if (go_wpa_s && !p2p_group_go_member_count(wpa_s)) |
| 4647 | wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname); |
| 4648 | |
| 4649 | if (persistent_go && s != persistent_go && |
| 4650 | !persistent_go->num_p2p_clients) { |
| 4651 | /* remove empty persistent GO */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4652 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4653 | "P2P: Remove empty persistent group id=%d", |
| 4654 | persistent_go->id); |
| 4655 | wpas_notify_persistent_group_removed(wpa_s, |
| 4656 | persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4657 | wpa_config_remove_network(wpa_s->conf, |
| 4658 | persistent_go->id); |
| 4659 | /* Save config */ |
| 4660 | } |
| 4661 | |
| 4662 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4663 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4664 | " status=%d" |
| 4665 | " adv_id=%x adv_mac=" MACSTR |
| 4666 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4667 | " persist=%d%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4668 | MAC2STR(dev), status, |
| 4669 | adv_id, MAC2STR(adv_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4670 | ses_id, MAC2STR(ses_mac), s->id, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4671 | return; |
| 4672 | } |
| 4673 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4674 | wpa_s->global->pending_p2ps_group = 0; |
| 4675 | wpa_s->global->pending_p2ps_group_freq = 0; |
| 4676 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4677 | if (conncap == P2PS_SETUP_GROUP_OWNER) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4678 | /* |
| 4679 | * We need to copy the interface name. Simply saving a |
| 4680 | * pointer isn't enough, since if we use pending_interface_name |
| 4681 | * it will be overwritten when the group is added. |
| 4682 | */ |
| 4683 | char go_ifname[100]; |
| 4684 | |
| 4685 | go_ifname[0] = '\0'; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4686 | if (!go_wpa_s) { |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4687 | if (!response_done) { |
| 4688 | wpa_s->global->pending_p2ps_group = 1; |
| 4689 | wpa_s->global->pending_p2ps_group_freq = freq; |
| 4690 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4691 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4692 | if (!wpas_p2p_create_iface(wpa_s)) |
| 4693 | os_memcpy(go_ifname, wpa_s->ifname, |
| 4694 | sizeof(go_ifname)); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4695 | else if (wpa_s->pending_interface_name[0]) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4696 | os_memcpy(go_ifname, |
| 4697 | wpa_s->pending_interface_name, |
| 4698 | sizeof(go_ifname)); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4699 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4700 | if (!go_ifname[0]) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4701 | wpas_p2ps_prov_complete( |
| 4702 | wpa_s, P2P_SC_FAIL_UNKNOWN_GROUP, |
| 4703 | dev, adv_mac, ses_mac, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4704 | grp_mac, adv_id, ses_id, 0, 0, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4705 | NULL, 0, 0, 0, NULL, NULL, 0, 0, |
| 4706 | NULL, 0); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4707 | return; |
| 4708 | } |
| 4709 | |
| 4710 | /* If PD Resp complete, start up the GO */ |
| 4711 | if (response_done && persistent_go) { |
| 4712 | wpas_p2p_group_add_persistent( |
| 4713 | wpa_s, persistent_go, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4714 | 0, 0, freq, 0, 0, 0, 0, 0, 0, NULL, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4715 | persistent_go->mode == |
| 4716 | WPAS_MODE_P2P_GO ? |
| 4717 | P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4718 | 0, 0, false, 0, NULL); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4719 | } else if (response_done) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4720 | wpas_p2p_group_add(wpa_s, 1, freq, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4721 | 0, 0, 0, 0, 0, 0, false); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4722 | } |
| 4723 | |
| 4724 | if (passwd_id == DEV_PW_P2PS_DEFAULT) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4725 | os_memcpy(wpa_s->p2ps_join_addr, grp_mac, |
| 4726 | ETH_ALEN); |
| 4727 | wpa_s->p2ps_method_config_any = 1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4728 | } |
| 4729 | } else if (passwd_id == DEV_PW_P2PS_DEFAULT) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4730 | os_memcpy(go_ifname, go_wpa_s->ifname, |
| 4731 | sizeof(go_ifname)); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4732 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4733 | if (is_zero_ether_addr(grp_mac)) { |
| 4734 | wpa_dbg(go_wpa_s, MSG_DEBUG, |
| 4735 | "P2P: Setting PIN-1 for ANY"); |
| 4736 | wpa_supplicant_ap_wps_pin(go_wpa_s, NULL, |
| 4737 | "12345670", NULL, 0, |
| 4738 | 0); |
| 4739 | } else { |
| 4740 | wpa_dbg(go_wpa_s, MSG_DEBUG, |
| 4741 | "P2P: Setting PIN-1 for " MACSTR, |
| 4742 | MAC2STR(grp_mac)); |
| 4743 | wpa_supplicant_ap_wps_pin(go_wpa_s, grp_mac, |
| 4744 | "12345670", NULL, 0, |
| 4745 | 0); |
| 4746 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4747 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4748 | os_memcpy(wpa_s->p2ps_join_addr, grp_mac, ETH_ALEN); |
| 4749 | wpa_s->p2ps_method_config_any = 1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4750 | } |
| 4751 | |
| 4752 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4753 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4754 | " status=%d conncap=%x" |
| 4755 | " adv_id=%x adv_mac=" MACSTR |
| 4756 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4757 | " dev_passwd_id=%d go=%s%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4758 | MAC2STR(dev), status, conncap, |
| 4759 | adv_id, MAC2STR(adv_mac), |
| 4760 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4761 | passwd_id, go_ifname, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4762 | return; |
| 4763 | } |
| 4764 | |
| 4765 | if (go_wpa_s && !p2p_group_go_member_count(wpa_s)) |
| 4766 | wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname); |
| 4767 | |
| 4768 | if (persistent_go && !persistent_go->num_p2p_clients) { |
| 4769 | /* remove empty persistent GO */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4770 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4771 | "P2P: Remove empty persistent group id=%d", |
| 4772 | persistent_go->id); |
| 4773 | wpas_notify_persistent_group_removed(wpa_s, persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4774 | wpa_config_remove_network(wpa_s->conf, persistent_go->id); |
| 4775 | } |
| 4776 | |
| 4777 | if (conncap == P2PS_SETUP_CLIENT) { |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4778 | char ssid_hex[32 * 2 + 1]; |
| 4779 | |
| 4780 | if (group_ssid) |
| 4781 | wpa_snprintf_hex(ssid_hex, sizeof(ssid_hex), |
| 4782 | group_ssid, group_ssid_len); |
| 4783 | else |
| 4784 | ssid_hex[0] = '\0'; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4785 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4786 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4787 | " status=%d conncap=%x" |
| 4788 | " adv_id=%x adv_mac=" MACSTR |
| 4789 | " session=%x mac=" MACSTR |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4790 | " dev_passwd_id=%d join=" MACSTR "%s%s%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4791 | MAC2STR(dev), status, conncap, |
| 4792 | adv_id, MAC2STR(adv_mac), |
| 4793 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4794 | passwd_id, MAC2STR(grp_mac), feat_cap_str, |
| 4795 | group_ssid ? " group_ssid=" : "", ssid_hex); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4796 | } else { |
| 4797 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4798 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4799 | " status=%d conncap=%x" |
| 4800 | " adv_id=%x adv_mac=" MACSTR |
| 4801 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4802 | " dev_passwd_id=%d%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4803 | MAC2STR(dev), status, conncap, |
| 4804 | adv_id, MAC2STR(adv_mac), |
| 4805 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4806 | passwd_id, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4807 | } |
| 4808 | } |
| 4809 | |
| 4810 | |
Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 4811 | static int _wpas_p2p_in_progress(void *ctx) |
| 4812 | { |
| 4813 | struct wpa_supplicant *wpa_s = ctx; |
| 4814 | return wpas_p2p_in_progress(wpa_s); |
| 4815 | } |
| 4816 | |
| 4817 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4818 | static int wpas_prov_disc_resp_cb(void *ctx) |
| 4819 | { |
| 4820 | struct wpa_supplicant *wpa_s = ctx; |
| 4821 | struct wpa_ssid *persistent_go; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4822 | unsigned int freq; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4823 | |
| 4824 | if (!wpa_s->global->pending_p2ps_group) |
| 4825 | return 0; |
| 4826 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4827 | freq = wpa_s->global->pending_p2ps_group_freq; |
| 4828 | wpa_s->global->pending_p2ps_group_freq = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4829 | wpa_s->global->pending_p2ps_group = 0; |
| 4830 | |
| 4831 | if (wpas_p2p_get_go_group(wpa_s)) |
| 4832 | return 0; |
| 4833 | persistent_go = wpas_p2p_get_persistent_go(wpa_s); |
| 4834 | |
| 4835 | if (persistent_go) { |
| 4836 | wpas_p2p_group_add_persistent( |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4837 | wpa_s, persistent_go, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 4838 | NULL, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4839 | persistent_go->mode == WPAS_MODE_P2P_GO ? |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4840 | P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0, 0, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4841 | is_p2p_allow_6ghz(wpa_s->global->p2p), 0, NULL); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4842 | } else { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4843 | wpas_p2p_group_add(wpa_s, 1, freq, 0, 0, 0, 0, 0, 0, |
| 4844 | is_p2p_allow_6ghz(wpa_s->global->p2p)); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4845 | } |
| 4846 | |
| 4847 | return 1; |
| 4848 | } |
| 4849 | |
| 4850 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4851 | static int wpas_p2p_get_pref_freq_list(void *ctx, int go, |
| 4852 | unsigned int *len, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4853 | struct weighted_pcl *freq_list) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4854 | { |
| 4855 | struct wpa_supplicant *wpa_s = ctx; |
| 4856 | |
| 4857 | return wpa_drv_get_pref_freq_list(wpa_s, go ? WPA_IF_P2P_GO : |
| 4858 | WPA_IF_P2P_CLIENT, len, freq_list); |
| 4859 | } |
| 4860 | |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4861 | int wpas_p2p_mac_setup(struct wpa_supplicant *wpa_s) |
| 4862 | { |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4863 | int ret = 0; |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4864 | u8 addr[ETH_ALEN] = {0}; |
| 4865 | |
| 4866 | if (wpa_s->conf->p2p_device_random_mac_addr == 0) |
| 4867 | return 0; |
| 4868 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4869 | if (wpa_s->conf->p2p_device_random_mac_addr == 2) { |
| 4870 | if (is_zero_ether_addr( |
| 4871 | wpa_s->conf->p2p_device_persistent_mac_addr) && |
| 4872 | !is_zero_ether_addr(wpa_s->own_addr)) { |
| 4873 | os_memcpy(wpa_s->conf->p2p_device_persistent_mac_addr, |
| 4874 | wpa_s->own_addr, ETH_ALEN); |
| 4875 | } |
| 4876 | return 0; |
| 4877 | } |
| 4878 | |
| 4879 | if (!wpa_s->conf->ssid) { |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4880 | if (random_mac_addr(addr) < 0) { |
| 4881 | wpa_msg(wpa_s, MSG_INFO, |
| 4882 | "Failed to generate random MAC address"); |
| 4883 | return -EINVAL; |
| 4884 | } |
| 4885 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 4886 | /* Store generated MAC address. */ |
| 4887 | os_memcpy(wpa_s->conf->p2p_device_persistent_mac_addr, addr, |
| 4888 | ETH_ALEN); |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4889 | } else { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 4890 | /* If there are existing saved groups, restore last MAC address. |
| 4891 | * if there is no last used MAC address, the last one is |
| 4892 | * factory MAC. */ |
| 4893 | if (is_zero_ether_addr( |
| 4894 | wpa_s->conf->p2p_device_persistent_mac_addr)) |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4895 | return 0; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 4896 | os_memcpy(addr, wpa_s->conf->p2p_device_persistent_mac_addr, |
| 4897 | ETH_ALEN); |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4898 | wpa_msg(wpa_s, MSG_DEBUG, "Restore last used MAC address."); |
| 4899 | } |
| 4900 | |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4901 | ret = wpa_drv_set_mac_addr(wpa_s, addr); |
| 4902 | |
| 4903 | if (ret < 0) { |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4904 | wpa_msg(wpa_s, MSG_INFO, |
| 4905 | "Failed to set random MAC address"); |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4906 | return ret; |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4907 | } |
| 4908 | |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4909 | ret = wpa_supplicant_update_mac_addr(wpa_s); |
| 4910 | |
| 4911 | if (ret < 0) { |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4912 | wpa_msg(wpa_s, MSG_INFO, |
| 4913 | "Could not update MAC address information"); |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4914 | return ret; |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4915 | } |
| 4916 | |
| 4917 | wpa_msg(wpa_s, MSG_DEBUG, "Using random MAC address " MACSTR, |
| 4918 | MAC2STR(addr)); |
| 4919 | |
| 4920 | return 0; |
| 4921 | } |
| 4922 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4923 | /** |
| 4924 | * wpas_p2p_init - Initialize P2P module for %wpa_supplicant |
| 4925 | * @global: Pointer to global data from wpa_supplicant_init() |
| 4926 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 4927 | * Returns: 0 on success, -1 on failure |
| 4928 | */ |
| 4929 | int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s) |
| 4930 | { |
| 4931 | struct p2p_config p2p; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4932 | int i; |
| 4933 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 4934 | if (wpa_s->conf->p2p_disabled) |
| 4935 | return 0; |
| 4936 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4937 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE)) |
| 4938 | return 0; |
| 4939 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4940 | if (global->p2p) |
| 4941 | return 0; |
| 4942 | |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4943 | if (wpas_p2p_mac_setup(wpa_s) < 0) { |
| 4944 | wpa_msg(wpa_s, MSG_ERROR, |
| 4945 | "Failed to initialize P2P random MAC address."); |
| 4946 | return -1; |
| 4947 | } |
| 4948 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4949 | os_memset(&p2p, 0, sizeof(p2p)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4950 | p2p.cb_ctx = wpa_s; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 4951 | p2p.debug_print = wpas_p2p_debug_print; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4952 | p2p.p2p_scan = wpas_p2p_scan; |
| 4953 | p2p.send_action = wpas_send_action; |
| 4954 | p2p.send_action_done = wpas_send_action_done; |
| 4955 | p2p.go_neg_completed = wpas_go_neg_completed; |
| 4956 | p2p.go_neg_req_rx = wpas_go_neg_req_rx; |
| 4957 | p2p.dev_found = wpas_dev_found; |
| 4958 | p2p.dev_lost = wpas_dev_lost; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 4959 | p2p.find_stopped = wpas_find_stopped; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4960 | p2p.start_listen = wpas_start_listen; |
| 4961 | p2p.stop_listen = wpas_stop_listen; |
| 4962 | p2p.send_probe_resp = wpas_send_probe_resp; |
| 4963 | p2p.sd_request = wpas_sd_request; |
| 4964 | p2p.sd_response = wpas_sd_response; |
| 4965 | p2p.prov_disc_req = wpas_prov_disc_req; |
| 4966 | p2p.prov_disc_resp = wpas_prov_disc_resp; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 4967 | p2p.prov_disc_fail = wpas_prov_disc_fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4968 | p2p.invitation_process = wpas_invitation_process; |
| 4969 | p2p.invitation_received = wpas_invitation_received; |
| 4970 | p2p.invitation_result = wpas_invitation_result; |
| 4971 | p2p.get_noa = wpas_get_noa; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4972 | p2p.go_connected = wpas_go_connected; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4973 | p2p.presence_resp = wpas_presence_resp; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 4974 | p2p.is_concurrent_session_active = wpas_is_concurrent_session_active; |
Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 4975 | p2p.is_p2p_in_progress = _wpas_p2p_in_progress; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4976 | p2p.get_persistent_group = wpas_get_persistent_group; |
| 4977 | p2p.get_go_info = wpas_get_go_info; |
| 4978 | p2p.remove_stale_groups = wpas_remove_stale_groups; |
| 4979 | p2p.p2ps_prov_complete = wpas_p2ps_prov_complete; |
| 4980 | p2p.prov_disc_resp_cb = wpas_prov_disc_resp_cb; |
| 4981 | p2p.p2ps_group_capability = p2ps_group_capability; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4982 | p2p.get_pref_freq_list = wpas_p2p_get_pref_freq_list; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4983 | p2p.p2p_6ghz_disable = wpa_s->conf->p2p_6ghz_disable; |
Shuibing Dai | e2fad41 | 2023-05-05 14:08:11 -0700 | [diff] [blame] | 4984 | p2p.p2p_dfs_chan_enable = wpa_s->conf->p2p_dfs_chan_enable; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4985 | |
| 4986 | 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] | 4987 | 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] | 4988 | p2p.dev_name = wpa_s->conf->device_name; |
| 4989 | p2p.manufacturer = wpa_s->conf->manufacturer; |
| 4990 | p2p.model_name = wpa_s->conf->model_name; |
| 4991 | p2p.model_number = wpa_s->conf->model_number; |
| 4992 | p2p.serial_number = wpa_s->conf->serial_number; |
| 4993 | if (wpa_s->wps) { |
| 4994 | os_memcpy(p2p.uuid, wpa_s->wps->uuid, 16); |
| 4995 | p2p.config_methods = wpa_s->wps->config_methods; |
| 4996 | } |
| 4997 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4998 | if (wpas_p2p_setup_channels(wpa_s, &p2p.channels, &p2p.cli_channels, |
| 4999 | p2p.p2p_6ghz_disable)) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5000 | wpa_printf(MSG_ERROR, |
| 5001 | "P2P: Failed to configure supported channel list"); |
| 5002 | return -1; |
| 5003 | } |
| 5004 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5005 | if (wpa_s->conf->p2p_listen_reg_class && |
| 5006 | wpa_s->conf->p2p_listen_channel) { |
| 5007 | p2p.reg_class = wpa_s->conf->p2p_listen_reg_class; |
| 5008 | p2p.channel = wpa_s->conf->p2p_listen_channel; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5009 | p2p.channel_forced = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5010 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5011 | /* |
| 5012 | * Pick one of the social channels randomly as the listen |
| 5013 | * channel. |
| 5014 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5015 | if (p2p_config_get_random_social(&p2p, &p2p.reg_class, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5016 | &p2p.channel, |
| 5017 | &global->p2p_go_avoid_freq, |
| 5018 | &global->p2p_disallow_freq) != |
| 5019 | 0) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 5020 | wpa_printf(MSG_INFO, |
| 5021 | "P2P: No social channels supported by the driver - do not enable P2P"); |
| 5022 | return 0; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5023 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5024 | p2p.channel_forced = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5025 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5026 | wpa_printf(MSG_DEBUG, "P2P: Own listen channel: %d:%d", |
| 5027 | p2p.reg_class, p2p.channel); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5028 | |
| 5029 | if (wpa_s->conf->p2p_oper_reg_class && |
| 5030 | wpa_s->conf->p2p_oper_channel) { |
| 5031 | p2p.op_reg_class = wpa_s->conf->p2p_oper_reg_class; |
| 5032 | p2p.op_channel = wpa_s->conf->p2p_oper_channel; |
| 5033 | p2p.cfg_op_channel = 1; |
| 5034 | wpa_printf(MSG_DEBUG, "P2P: Configured operating channel: " |
| 5035 | "%d:%d", p2p.op_reg_class, p2p.op_channel); |
| 5036 | |
| 5037 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5038 | /* |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5039 | * Use random operation channel from 2.4 GHz band social |
| 5040 | * channels (1, 6, 11) or band 60 GHz social channel (2) if no |
| 5041 | * other preference is indicated. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5042 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5043 | if (p2p_config_get_random_social(&p2p, &p2p.op_reg_class, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5044 | &p2p.op_channel, NULL, |
| 5045 | NULL) != 0) { |
| 5046 | wpa_printf(MSG_INFO, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5047 | "P2P: Failed to select random social channel as operation channel"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5048 | p2p.op_reg_class = 0; |
| 5049 | p2p.op_channel = 0; |
| 5050 | /* This will be overridden during group setup in |
| 5051 | * p2p_prepare_channel(), so allow setup to continue. */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5052 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5053 | p2p.cfg_op_channel = 0; |
| 5054 | wpa_printf(MSG_DEBUG, "P2P: Random operating channel: " |
| 5055 | "%d:%d", p2p.op_reg_class, p2p.op_channel); |
| 5056 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 5057 | |
| 5058 | if (wpa_s->conf->p2p_pref_chan && wpa_s->conf->num_p2p_pref_chan) { |
| 5059 | p2p.pref_chan = wpa_s->conf->p2p_pref_chan; |
| 5060 | p2p.num_pref_chan = wpa_s->conf->num_p2p_pref_chan; |
| 5061 | } |
| 5062 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5063 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) { |
| 5064 | os_memcpy(p2p.country, wpa_s->conf->country, 2); |
| 5065 | p2p.country[2] = 0x04; |
| 5066 | } else |
| 5067 | os_memcpy(p2p.country, "XX\x04", 3); |
| 5068 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5069 | os_memcpy(p2p.pri_dev_type, wpa_s->conf->device_type, |
| 5070 | WPS_DEV_TYPE_LEN); |
| 5071 | |
| 5072 | p2p.num_sec_dev_types = wpa_s->conf->num_sec_device_types; |
| 5073 | os_memcpy(p2p.sec_dev_type, wpa_s->conf->sec_device_type, |
| 5074 | p2p.num_sec_dev_types * WPS_DEV_TYPE_LEN); |
| 5075 | |
| 5076 | p2p.concurrent_operations = !!(wpa_s->drv_flags & |
| 5077 | WPA_DRIVER_FLAGS_P2P_CONCURRENT); |
| 5078 | |
| 5079 | p2p.max_peers = 100; |
| 5080 | |
| 5081 | if (wpa_s->conf->p2p_ssid_postfix) { |
| 5082 | p2p.ssid_postfix_len = |
| 5083 | os_strlen(wpa_s->conf->p2p_ssid_postfix); |
| 5084 | if (p2p.ssid_postfix_len > sizeof(p2p.ssid_postfix)) |
| 5085 | p2p.ssid_postfix_len = sizeof(p2p.ssid_postfix); |
| 5086 | os_memcpy(p2p.ssid_postfix, wpa_s->conf->p2p_ssid_postfix, |
| 5087 | p2p.ssid_postfix_len); |
| 5088 | } |
| 5089 | |
| 5090 | p2p.p2p_intra_bss = wpa_s->conf->p2p_intra_bss; |
| 5091 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5092 | p2p.max_listen = wpa_s->max_remain_on_chan; |
| 5093 | |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 5094 | if (wpa_s->conf->p2p_passphrase_len >= 8 && |
| 5095 | wpa_s->conf->p2p_passphrase_len <= 63) |
| 5096 | p2p.passphrase_len = wpa_s->conf->p2p_passphrase_len; |
| 5097 | else |
| 5098 | p2p.passphrase_len = 8; |
| 5099 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5100 | global->p2p = p2p_init(&p2p); |
| 5101 | if (global->p2p == NULL) |
| 5102 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5103 | global->p2p_init_wpa_s = wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5104 | |
| 5105 | for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) { |
| 5106 | if (wpa_s->conf->wps_vendor_ext[i] == NULL) |
| 5107 | continue; |
| 5108 | p2p_add_wps_vendor_extension( |
| 5109 | global->p2p, wpa_s->conf->wps_vendor_ext[i]); |
| 5110 | } |
| 5111 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5112 | p2p_set_no_go_freq(global->p2p, &wpa_s->conf->p2p_no_go_freq); |
| 5113 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5114 | return 0; |
| 5115 | } |
| 5116 | |
| 5117 | |
| 5118 | /** |
| 5119 | * wpas_p2p_deinit - Deinitialize per-interface P2P data |
| 5120 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 5121 | * |
| 5122 | * This function deinitialize per-interface P2P data. |
| 5123 | */ |
| 5124 | void wpas_p2p_deinit(struct wpa_supplicant *wpa_s) |
| 5125 | { |
| 5126 | if (wpa_s->driver && wpa_s->drv_priv) |
| 5127 | wpa_drv_probe_req_report(wpa_s, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5128 | |
| 5129 | if (wpa_s->go_params) { |
| 5130 | /* Clear any stored provisioning info */ |
| 5131 | p2p_clear_provisioning_info( |
| 5132 | wpa_s->global->p2p, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5133 | wpa_s->go_params->peer_device_addr); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5134 | } |
| 5135 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5136 | os_free(wpa_s->go_params); |
| 5137 | wpa_s->go_params = NULL; |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 5138 | eloop_cancel_timeout(wpas_p2p_psk_failure_removal, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5139 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 5140 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5141 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5142 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
| 5143 | eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL); |
| 5144 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 5145 | eloop_cancel_timeout(wpas_p2p_group_freq_conflict, wpa_s, NULL); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5146 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, wpa_s, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5147 | wpas_p2p_listen_work_done(wpa_s); |
| 5148 | if (wpa_s->p2p_send_action_work) { |
| 5149 | os_free(wpa_s->p2p_send_action_work->ctx); |
| 5150 | radio_work_done(wpa_s->p2p_send_action_work); |
| 5151 | wpa_s->p2p_send_action_work = NULL; |
| 5152 | } |
| 5153 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5154 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5155 | wpabuf_free(wpa_s->p2p_oob_dev_pw); |
| 5156 | wpa_s->p2p_oob_dev_pw = NULL; |
| 5157 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5158 | os_free(wpa_s->p2p_group_common_freqs); |
| 5159 | wpa_s->p2p_group_common_freqs = NULL; |
| 5160 | wpa_s->p2p_group_common_freqs_num = 0; |
| 5161 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5162 | /* TODO: remove group interface from the driver if this wpa_s instance |
| 5163 | * is on top of a P2P group interface */ |
| 5164 | } |
| 5165 | |
| 5166 | |
| 5167 | /** |
| 5168 | * wpas_p2p_deinit_global - Deinitialize global P2P module |
| 5169 | * @global: Pointer to global data from wpa_supplicant_init() |
| 5170 | * |
| 5171 | * This function deinitializes the global (per device) P2P module. |
| 5172 | */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5173 | static void wpas_p2p_deinit_global(struct wpa_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5174 | { |
| 5175 | struct wpa_supplicant *wpa_s, *tmp; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5176 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5177 | wpa_s = global->ifaces; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5178 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5179 | wpas_p2p_service_flush(global->p2p_init_wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5180 | |
| 5181 | /* Remove remaining P2P group interfaces */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5182 | while (wpa_s && wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) |
| 5183 | wpa_s = wpa_s->next; |
| 5184 | while (wpa_s) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5185 | tmp = global->ifaces; |
| 5186 | while (tmp && |
| 5187 | (tmp == wpa_s || |
| 5188 | tmp->p2p_group_interface == NOT_P2P_GROUP_INTERFACE)) { |
| 5189 | tmp = tmp->next; |
| 5190 | } |
| 5191 | if (tmp == NULL) |
| 5192 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5193 | /* Disconnect from the P2P group and deinit the interface */ |
| 5194 | wpas_p2p_disconnect(tmp); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5195 | } |
| 5196 | |
| 5197 | /* |
| 5198 | * Deinit GO data on any possibly remaining interface (if main |
| 5199 | * interface is used as GO). |
| 5200 | */ |
| 5201 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 5202 | if (wpa_s->ap_iface) |
| 5203 | wpas_p2p_group_deinit(wpa_s); |
| 5204 | } |
| 5205 | |
| 5206 | p2p_deinit(global->p2p); |
| 5207 | global->p2p = NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5208 | global->p2p_init_wpa_s = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5209 | } |
| 5210 | |
| 5211 | |
| 5212 | static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s) |
| 5213 | { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5214 | if (wpa_s->conf->p2p_no_group_iface) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5215 | return 0; /* separate interface disabled per configuration */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5216 | if (wpa_s->drv_flags & |
| 5217 | (WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE | |
| 5218 | WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P)) |
| 5219 | return 1; /* P2P group requires a new interface in every case |
| 5220 | */ |
| 5221 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CONCURRENT)) |
| 5222 | return 0; /* driver does not support concurrent operations */ |
| 5223 | if (wpa_s->global->ifaces->next) |
| 5224 | return 1; /* more that one interface already in use */ |
| 5225 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
| 5226 | return 1; /* this interface is already in use */ |
| 5227 | return 0; |
| 5228 | } |
| 5229 | |
| 5230 | |
| 5231 | static int wpas_p2p_start_go_neg(struct wpa_supplicant *wpa_s, |
| 5232 | const u8 *peer_addr, |
| 5233 | enum p2p_wps_method wps_method, |
| 5234 | int go_intent, const u8 *own_interface_addr, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5235 | unsigned int force_freq, int persistent_group, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5236 | struct wpa_ssid *ssid, unsigned int pref_freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5237 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5238 | if (persistent_group && wpa_s->conf->persistent_reconnect) |
| 5239 | persistent_group = 2; |
| 5240 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5241 | /* |
| 5242 | * Increase GO config timeout if HT40 is used since it takes some time |
| 5243 | * to scan channels for coex purposes before the BSS can be started. |
| 5244 | */ |
| 5245 | p2p_set_config_timeout(wpa_s->global->p2p, |
| 5246 | wpa_s->p2p_go_ht40 ? 255 : 100, 20); |
| 5247 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5248 | return p2p_connect(wpa_s->global->p2p, peer_addr, wps_method, |
| 5249 | go_intent, own_interface_addr, force_freq, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5250 | persistent_group, ssid ? ssid->ssid : NULL, |
| 5251 | ssid ? ssid->ssid_len : 0, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5252 | wpa_s->p2p_pd_before_go_neg, pref_freq, |
| 5253 | wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id : |
| 5254 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5255 | } |
| 5256 | |
| 5257 | |
| 5258 | static int wpas_p2p_auth_go_neg(struct wpa_supplicant *wpa_s, |
| 5259 | const u8 *peer_addr, |
| 5260 | enum p2p_wps_method wps_method, |
| 5261 | int go_intent, const u8 *own_interface_addr, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5262 | unsigned int force_freq, int persistent_group, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5263 | struct wpa_ssid *ssid, unsigned int pref_freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5264 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5265 | if (persistent_group && wpa_s->conf->persistent_reconnect) |
| 5266 | persistent_group = 2; |
| 5267 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5268 | return p2p_authorize(wpa_s->global->p2p, peer_addr, wps_method, |
| 5269 | go_intent, own_interface_addr, force_freq, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5270 | persistent_group, ssid ? ssid->ssid : NULL, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5271 | ssid ? ssid->ssid_len : 0, pref_freq, |
| 5272 | wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id : |
| 5273 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5274 | } |
| 5275 | |
| 5276 | |
| 5277 | static void wpas_p2p_check_join_scan_limit(struct wpa_supplicant *wpa_s) |
| 5278 | { |
| 5279 | wpa_s->p2p_join_scan_count++; |
| 5280 | wpa_printf(MSG_DEBUG, "P2P: Join scan attempt %d", |
| 5281 | wpa_s->p2p_join_scan_count); |
| 5282 | if (wpa_s->p2p_join_scan_count > P2P_MAX_JOIN_SCAN_ATTEMPTS) { |
| 5283 | wpa_printf(MSG_DEBUG, "P2P: Failed to find GO " MACSTR |
| 5284 | " for join operationg - stop join attempt", |
| 5285 | MAC2STR(wpa_s->pending_join_iface_addr)); |
| 5286 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5287 | if (wpa_s->p2p_auto_pd) { |
| 5288 | wpa_s->p2p_auto_pd = 0; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5289 | wpa_msg_global(wpa_s, MSG_INFO, |
| 5290 | P2P_EVENT_PROV_DISC_FAILURE |
| 5291 | " p2p_dev_addr=" MACSTR " status=N/A", |
| 5292 | MAC2STR(wpa_s->pending_join_dev_addr)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5293 | return; |
| 5294 | } |
Jimmy Chen | b7b3f4d | 2020-09-02 16:50:11 +0800 | [diff] [blame] | 5295 | if (wpa_s->p2p_fallback_to_go_neg) { |
| 5296 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Join operating " |
| 5297 | "failed - fall back to GO Negotiation"); |
| 5298 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
| 5299 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 5300 | "reason=join-failed"); |
| 5301 | wpas_p2p_fallback_to_go_neg(wpa_s, 0); |
| 5302 | return; |
| 5303 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5304 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5305 | P2P_EVENT_GROUP_FORMATION_FAILURE); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5306 | wpas_notify_p2p_group_formation_failure(wpa_s, ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5307 | } |
| 5308 | } |
| 5309 | |
| 5310 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5311 | static int wpas_check_freq_conflict(struct wpa_supplicant *wpa_s, int freq) |
| 5312 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5313 | int res; |
| 5314 | unsigned int num, i; |
| 5315 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5316 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5317 | if (wpas_p2p_num_unused_channels(wpa_s) > 0) { |
| 5318 | /* Multiple channels are supported and not all are in use */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5319 | return 0; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5320 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5321 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5322 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 5323 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5324 | if (!freqs) |
| 5325 | return 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5326 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5327 | num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, |
| 5328 | wpa_s->num_multichan_concurrent); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5329 | |
| 5330 | for (i = 0; i < num; i++) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5331 | if (freqs[i].freq == freq) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5332 | wpa_printf(MSG_DEBUG, "P2P: Frequency %d MHz in use by another virtual interface and can be used", |
| 5333 | freq); |
| 5334 | res = 0; |
| 5335 | goto exit_free; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5336 | } |
| 5337 | } |
| 5338 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5339 | wpa_printf(MSG_DEBUG, "P2P: No valid operating frequencies"); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5340 | res = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5341 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5342 | exit_free: |
| 5343 | os_free(freqs); |
| 5344 | return res; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5345 | } |
| 5346 | |
| 5347 | |
| 5348 | static int wpas_p2p_peer_go(struct wpa_supplicant *wpa_s, |
| 5349 | const u8 *peer_dev_addr) |
| 5350 | { |
| 5351 | struct wpa_bss *bss; |
| 5352 | int updated; |
| 5353 | |
| 5354 | bss = wpa_bss_get_p2p_dev_addr(wpa_s, peer_dev_addr); |
| 5355 | if (bss == NULL) |
| 5356 | return -1; |
| 5357 | if (bss->last_update_idx < wpa_s->bss_update_idx) { |
| 5358 | wpa_printf(MSG_DEBUG, "P2P: Peer BSS entry not updated in the " |
| 5359 | "last scan"); |
| 5360 | return 0; |
| 5361 | } |
| 5362 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5363 | updated = os_reltime_before(&wpa_s->p2p_auto_started, |
| 5364 | &bss->last_update); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5365 | wpa_printf(MSG_DEBUG, "P2P: Current BSS entry for peer updated at " |
| 5366 | "%ld.%06ld (%supdated in last scan)", |
| 5367 | bss->last_update.sec, bss->last_update.usec, |
| 5368 | updated ? "": "not "); |
| 5369 | |
| 5370 | return updated; |
| 5371 | } |
| 5372 | |
| 5373 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5374 | static void wpas_p2p_scan_res_join(struct wpa_supplicant *wpa_s, |
| 5375 | struct wpa_scan_results *scan_res) |
| 5376 | { |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5377 | struct wpa_bss *bss = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5378 | int freq; |
| 5379 | u8 iface_addr[ETH_ALEN]; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5380 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5381 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
| 5382 | |
| 5383 | if (wpa_s->global->p2p_disabled) |
| 5384 | return; |
| 5385 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5386 | wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS) for %sjoin", |
| 5387 | scan_res ? (int) scan_res->num : -1, |
| 5388 | wpa_s->p2p_auto_join ? "auto_" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5389 | |
| 5390 | if (scan_res) |
| 5391 | wpas_p2p_scan_res_handler(wpa_s, scan_res); |
| 5392 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5393 | if (wpa_s->p2p_auto_pd) { |
| 5394 | int join = wpas_p2p_peer_go(wpa_s, |
| 5395 | wpa_s->pending_join_dev_addr); |
| 5396 | if (join == 0 && |
| 5397 | wpa_s->auto_pd_scan_retry < P2P_AUTO_PD_SCAN_ATTEMPTS) { |
| 5398 | wpa_s->auto_pd_scan_retry++; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5399 | bss = wpa_bss_get_bssid_latest( |
| 5400 | wpa_s, wpa_s->pending_join_dev_addr); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5401 | if (bss) { |
| 5402 | freq = bss->freq; |
| 5403 | wpa_printf(MSG_DEBUG, "P2P: Scan retry %d for " |
| 5404 | "the peer " MACSTR " at %d MHz", |
| 5405 | wpa_s->auto_pd_scan_retry, |
| 5406 | MAC2STR(wpa_s-> |
| 5407 | pending_join_dev_addr), |
| 5408 | freq); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5409 | wpas_p2p_join_scan_req(wpa_s, freq, NULL, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5410 | return; |
| 5411 | } |
| 5412 | } |
| 5413 | |
| 5414 | if (join < 0) |
| 5415 | join = 0; |
| 5416 | |
| 5417 | wpa_s->p2p_auto_pd = 0; |
| 5418 | wpa_s->pending_pd_use = join ? AUTO_PD_JOIN : AUTO_PD_GO_NEG; |
| 5419 | wpa_printf(MSG_DEBUG, "P2P: Auto PD with " MACSTR " join=%d", |
| 5420 | MAC2STR(wpa_s->pending_join_dev_addr), join); |
| 5421 | if (p2p_prov_disc_req(wpa_s->global->p2p, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5422 | wpa_s->pending_join_dev_addr, NULL, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5423 | wpa_s->pending_pd_config_methods, join, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5424 | 0, wpa_s->user_initiated_pd) < 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5425 | wpa_s->p2p_auto_pd = 0; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5426 | wpa_msg_global(wpa_s, MSG_INFO, |
| 5427 | P2P_EVENT_PROV_DISC_FAILURE |
| 5428 | " p2p_dev_addr=" MACSTR " status=N/A", |
| 5429 | MAC2STR(wpa_s->pending_join_dev_addr)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5430 | } |
| 5431 | return; |
| 5432 | } |
| 5433 | |
| 5434 | if (wpa_s->p2p_auto_join) { |
| 5435 | int join = wpas_p2p_peer_go(wpa_s, |
| 5436 | wpa_s->pending_join_dev_addr); |
| 5437 | if (join < 0) { |
| 5438 | wpa_printf(MSG_DEBUG, "P2P: Peer was not found to be " |
| 5439 | "running a GO -> use GO Negotiation"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5440 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5441 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 5442 | "reason=peer-not-running-GO"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5443 | wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr, |
| 5444 | wpa_s->p2p_pin, wpa_s->p2p_wps_method, |
| 5445 | wpa_s->p2p_persistent_group, 0, 0, 0, |
| 5446 | wpa_s->p2p_go_intent, |
| 5447 | wpa_s->p2p_connect_freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5448 | wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5449 | wpa_s->p2p_persistent_id, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5450 | wpa_s->p2p_pd_before_go_neg, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5451 | wpa_s->p2p_go_ht40, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5452 | wpa_s->p2p_go_vht, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5453 | wpa_s->p2p_go_max_oper_chwidth, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5454 | wpa_s->p2p_go_he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 5455 | wpa_s->p2p_go_edmg, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5456 | NULL, 0, |
| 5457 | is_p2p_allow_6ghz(wpa_s->global->p2p)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5458 | return; |
| 5459 | } |
| 5460 | |
| 5461 | wpa_printf(MSG_DEBUG, "P2P: Peer was found running GO%s -> " |
| 5462 | "try to join the group", join ? "" : |
| 5463 | " in older scan"); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5464 | if (!join) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5465 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5466 | P2P_EVENT_FALLBACK_TO_GO_NEG_ENABLED); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5467 | wpa_s->p2p_fallback_to_go_neg = 1; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5468 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5469 | } |
| 5470 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5471 | freq = p2p_get_oper_freq(wpa_s->global->p2p, |
| 5472 | wpa_s->pending_join_iface_addr); |
| 5473 | if (freq < 0 && |
| 5474 | p2p_get_interface_addr(wpa_s->global->p2p, |
| 5475 | wpa_s->pending_join_dev_addr, |
| 5476 | iface_addr) == 0 && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5477 | !ether_addr_equal(iface_addr, wpa_s->pending_join_dev_addr) && |
| 5478 | !wpa_bss_get_bssid(wpa_s, wpa_s->pending_join_iface_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5479 | wpa_printf(MSG_DEBUG, "P2P: Overwrite pending interface " |
| 5480 | "address for join from " MACSTR " to " MACSTR |
| 5481 | " based on newly discovered P2P peer entry", |
| 5482 | MAC2STR(wpa_s->pending_join_iface_addr), |
| 5483 | MAC2STR(iface_addr)); |
| 5484 | os_memcpy(wpa_s->pending_join_iface_addr, iface_addr, |
| 5485 | ETH_ALEN); |
| 5486 | |
| 5487 | freq = p2p_get_oper_freq(wpa_s->global->p2p, |
| 5488 | wpa_s->pending_join_iface_addr); |
| 5489 | } |
| 5490 | if (freq >= 0) { |
| 5491 | wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency " |
| 5492 | "from P2P peer table: %d MHz", freq); |
| 5493 | } |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5494 | if (wpa_s->p2p_join_ssid_len) { |
| 5495 | wpa_printf(MSG_DEBUG, "P2P: Trying to find target GO BSS entry based on BSSID " |
| 5496 | MACSTR " and SSID %s", |
| 5497 | MAC2STR(wpa_s->pending_join_iface_addr), |
| 5498 | wpa_ssid_txt(wpa_s->p2p_join_ssid, |
| 5499 | wpa_s->p2p_join_ssid_len)); |
| 5500 | bss = wpa_bss_get(wpa_s, wpa_s->pending_join_iface_addr, |
| 5501 | wpa_s->p2p_join_ssid, |
| 5502 | wpa_s->p2p_join_ssid_len); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5503 | } else if (!bss) { |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5504 | wpa_printf(MSG_DEBUG, "P2P: Trying to find target GO BSS entry based on BSSID " |
| 5505 | MACSTR, MAC2STR(wpa_s->pending_join_iface_addr)); |
| 5506 | bss = wpa_bss_get_bssid_latest(wpa_s, |
| 5507 | wpa_s->pending_join_iface_addr); |
| 5508 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5509 | if (bss) { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5510 | u8 dev_addr[ETH_ALEN]; |
| 5511 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5512 | freq = bss->freq; |
| 5513 | wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency " |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 5514 | "from BSS table: %d MHz (SSID %s)", freq, |
| 5515 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5516 | 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] | 5517 | dev_addr) == 0 && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5518 | ether_addr_equal(wpa_s->pending_join_dev_addr, |
| 5519 | wpa_s->pending_join_iface_addr) && |
| 5520 | !ether_addr_equal(dev_addr, wpa_s->pending_join_dev_addr)) { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5521 | wpa_printf(MSG_DEBUG, |
| 5522 | "P2P: Update target GO device address based on BSS entry: " MACSTR " (was " MACSTR ")", |
| 5523 | MAC2STR(dev_addr), |
| 5524 | MAC2STR(wpa_s->pending_join_dev_addr)); |
| 5525 | os_memcpy(wpa_s->pending_join_dev_addr, dev_addr, |
| 5526 | ETH_ALEN); |
| 5527 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5528 | } |
| 5529 | if (freq > 0) { |
| 5530 | u16 method; |
| 5531 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5532 | if (wpas_check_freq_conflict(wpa_s, freq) > 0) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5533 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5534 | P2P_EVENT_GROUP_FORMATION_FAILURE |
| 5535 | "reason=FREQ_CONFLICT"); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5536 | wpas_notify_p2p_group_formation_failure( |
| 5537 | wpa_s, "FREQ_CONFLICT"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5538 | return; |
| 5539 | } |
| 5540 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5541 | wpa_printf(MSG_DEBUG, "P2P: Send Provision Discovery Request " |
| 5542 | "prior to joining an existing group (GO " MACSTR |
| 5543 | " freq=%u MHz)", |
| 5544 | MAC2STR(wpa_s->pending_join_dev_addr), freq); |
| 5545 | wpa_s->pending_pd_before_join = 1; |
| 5546 | |
| 5547 | switch (wpa_s->pending_join_wps_method) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5548 | case WPS_PIN_DISPLAY: |
| 5549 | method = WPS_CONFIG_KEYPAD; |
| 5550 | break; |
| 5551 | case WPS_PIN_KEYPAD: |
| 5552 | method = WPS_CONFIG_DISPLAY; |
| 5553 | break; |
| 5554 | case WPS_PBC: |
| 5555 | method = WPS_CONFIG_PUSHBUTTON; |
| 5556 | break; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5557 | case WPS_P2PS: |
| 5558 | method = WPS_CONFIG_P2PS; |
| 5559 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5560 | default: |
| 5561 | method = 0; |
| 5562 | break; |
| 5563 | } |
| 5564 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5565 | if ((p2p_get_provisioning_info(wpa_s->global->p2p, |
| 5566 | wpa_s->pending_join_dev_addr) == |
| 5567 | method)) { |
| 5568 | /* |
| 5569 | * We have already performed provision discovery for |
| 5570 | * joining the group. Proceed directly to join |
| 5571 | * operation without duplicated provision discovery. */ |
| 5572 | wpa_printf(MSG_DEBUG, "P2P: Provision discovery " |
| 5573 | "with " MACSTR " already done - proceed to " |
| 5574 | "join", |
| 5575 | MAC2STR(wpa_s->pending_join_dev_addr)); |
| 5576 | wpa_s->pending_pd_before_join = 0; |
| 5577 | goto start; |
| 5578 | } |
| 5579 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5580 | if (p2p_prov_disc_req(wpa_s->global->p2p, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5581 | wpa_s->pending_join_dev_addr, |
| 5582 | NULL, method, 1, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5583 | freq, wpa_s->user_initiated_pd) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5584 | wpa_printf(MSG_DEBUG, "P2P: Failed to send Provision " |
| 5585 | "Discovery Request before joining an " |
| 5586 | "existing group"); |
| 5587 | wpa_s->pending_pd_before_join = 0; |
| 5588 | goto start; |
| 5589 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5590 | return; |
| 5591 | } |
| 5592 | |
| 5593 | wpa_printf(MSG_DEBUG, "P2P: Failed to find BSS/GO - try again later"); |
| 5594 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
| 5595 | eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL); |
| 5596 | wpas_p2p_check_join_scan_limit(wpa_s); |
| 5597 | return; |
| 5598 | |
| 5599 | start: |
| 5600 | /* Start join operation immediately */ |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5601 | wpas_p2p_join_start(wpa_s, 0, wpa_s->p2p_join_ssid, |
| 5602 | wpa_s->p2p_join_ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5603 | } |
| 5604 | |
| 5605 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5606 | static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq, |
| 5607 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5608 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5609 | int ret; |
| 5610 | struct wpa_driver_scan_params params; |
| 5611 | struct wpabuf *wps_ie, *ies; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5612 | size_t ielen; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5613 | int freqs[2] = { 0, 0 }; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5614 | unsigned int bands; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5615 | |
| 5616 | os_memset(¶ms, 0, sizeof(params)); |
| 5617 | |
| 5618 | /* P2P Wildcard SSID */ |
| 5619 | params.num_ssids = 1; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5620 | if (ssid && ssid_len) { |
| 5621 | params.ssids[0].ssid = ssid; |
| 5622 | params.ssids[0].ssid_len = ssid_len; |
| 5623 | os_memcpy(wpa_s->p2p_join_ssid, ssid, ssid_len); |
| 5624 | wpa_s->p2p_join_ssid_len = ssid_len; |
| 5625 | } else { |
| 5626 | params.ssids[0].ssid = (u8 *) P2P_WILDCARD_SSID; |
| 5627 | params.ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN; |
| 5628 | wpa_s->p2p_join_ssid_len = 0; |
| 5629 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5630 | |
| 5631 | wpa_s->wps->dev.p2p = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5632 | wps_ie = wps_build_probe_req_ie(DEV_PW_DEFAULT, &wpa_s->wps->dev, |
| 5633 | wpa_s->wps->uuid, WPS_REQ_ENROLLEE, 0, |
| 5634 | NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5635 | if (wps_ie == NULL) { |
| 5636 | wpas_p2p_scan_res_join(wpa_s, NULL); |
| 5637 | return; |
| 5638 | } |
| 5639 | |
Dmitry Shmidt | 9e3f8ee | 2014-01-17 10:52:01 -0800 | [diff] [blame] | 5640 | if (!freq) { |
| 5641 | int oper_freq; |
| 5642 | /* |
| 5643 | * If freq is not provided, check the operating freq of the GO |
| 5644 | * and use a single channel scan on if possible. |
| 5645 | */ |
| 5646 | oper_freq = p2p_get_oper_freq(wpa_s->global->p2p, |
| 5647 | wpa_s->pending_join_iface_addr); |
| 5648 | if (oper_freq > 0) |
| 5649 | freq = oper_freq; |
| 5650 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5651 | if (freq > 0) { |
| 5652 | freqs[0] = freq; |
| 5653 | params.freqs = freqs; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 5654 | } else { |
| 5655 | wpas_p2p_scan_freqs(wpa_s, ¶ms, true); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5656 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5657 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5658 | ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p); |
| 5659 | ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen); |
| 5660 | if (ies == NULL) { |
| 5661 | wpabuf_free(wps_ie); |
| 5662 | wpas_p2p_scan_res_join(wpa_s, NULL); |
| 5663 | return; |
| 5664 | } |
| 5665 | wpabuf_put_buf(ies, wps_ie); |
| 5666 | wpabuf_free(wps_ie); |
| 5667 | |
| 5668 | bands = wpas_get_bands(wpa_s, freqs); |
| 5669 | p2p_scan_ie(wpa_s->global->p2p, ies, NULL, bands); |
| 5670 | |
| 5671 | params.p2p_probe = 1; |
| 5672 | params.extra_ies = wpabuf_head(ies); |
| 5673 | params.extra_ies_len = wpabuf_len(ies); |
| 5674 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 5675 | if (wpa_s->clear_driver_scan_cache) { |
| 5676 | wpa_printf(MSG_DEBUG, |
| 5677 | "Request driver to clear scan cache due to local BSS flush"); |
| 5678 | params.only_new_results = 1; |
| 5679 | } |
| 5680 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5681 | /* |
| 5682 | * Run a scan to update BSS table and start Provision Discovery once |
| 5683 | * the new scan results become available. |
| 5684 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5685 | ret = wpa_drv_scan(wpa_s, ¶ms); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5686 | if (params.freqs != freqs) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5687 | os_free(params.freqs); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5688 | if (!ret) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5689 | os_get_reltime(&wpa_s->scan_trigger_time); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5690 | wpa_s->scan_res_handler = wpas_p2p_scan_res_join; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5691 | wpa_s->own_scan_requested = 1; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 5692 | wpa_s->clear_driver_scan_cache = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5693 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5694 | |
| 5695 | wpabuf_free(ies); |
| 5696 | |
| 5697 | if (ret) { |
| 5698 | wpa_printf(MSG_DEBUG, "P2P: Failed to start scan for join - " |
| 5699 | "try again later"); |
| 5700 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
| 5701 | eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL); |
| 5702 | wpas_p2p_check_join_scan_limit(wpa_s); |
| 5703 | } |
| 5704 | } |
| 5705 | |
| 5706 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5707 | static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx) |
| 5708 | { |
| 5709 | struct wpa_supplicant *wpa_s = eloop_ctx; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5710 | wpas_p2p_join_scan_req(wpa_s, 0, NULL, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5711 | } |
| 5712 | |
| 5713 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5714 | 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] | 5715 | const u8 *dev_addr, enum p2p_wps_method wps_method, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5716 | int auto_join, int op_freq, |
| 5717 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5718 | { |
| 5719 | wpa_printf(MSG_DEBUG, "P2P: Request to join existing group (iface " |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5720 | MACSTR " dev " MACSTR " op_freq=%d)%s", |
| 5721 | MAC2STR(iface_addr), MAC2STR(dev_addr), op_freq, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5722 | auto_join ? " (auto_join)" : ""); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5723 | if (ssid && ssid_len) { |
| 5724 | wpa_printf(MSG_DEBUG, "P2P: Group SSID specified: %s", |
| 5725 | wpa_ssid_txt(ssid, ssid_len)); |
| 5726 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5727 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5728 | wpa_s->p2p_auto_pd = 0; |
| 5729 | wpa_s->p2p_auto_join = !!auto_join; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5730 | os_memcpy(wpa_s->pending_join_iface_addr, iface_addr, ETH_ALEN); |
| 5731 | os_memcpy(wpa_s->pending_join_dev_addr, dev_addr, ETH_ALEN); |
| 5732 | wpa_s->pending_join_wps_method = wps_method; |
| 5733 | |
| 5734 | /* Make sure we are not running find during connection establishment */ |
| 5735 | wpas_p2p_stop_find(wpa_s); |
| 5736 | |
| 5737 | wpa_s->p2p_join_scan_count = 0; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5738 | wpas_p2p_join_scan_req(wpa_s, op_freq, ssid, ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5739 | return 0; |
| 5740 | } |
| 5741 | |
| 5742 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5743 | static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s, int freq, |
| 5744 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5745 | { |
| 5746 | struct wpa_supplicant *group; |
| 5747 | struct p2p_go_neg_results res; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5748 | struct wpa_bss *bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5749 | |
| 5750 | group = wpas_p2p_get_group_iface(wpa_s, 0, 0); |
| 5751 | if (group == NULL) |
| 5752 | return -1; |
| 5753 | if (group != wpa_s) { |
| 5754 | os_memcpy(group->p2p_pin, wpa_s->p2p_pin, |
| 5755 | sizeof(group->p2p_pin)); |
| 5756 | group->p2p_wps_method = wpa_s->p2p_wps_method; |
| 5757 | } |
| 5758 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5759 | /* |
| 5760 | * Need to mark the current interface for p2p_group_formation |
| 5761 | * when a separate group interface is not used. This is needed |
| 5762 | * to allow p2p_cancel stop a pending p2p_connect-join. |
| 5763 | * wpas_p2p_init_group_interface() addresses this for the case |
| 5764 | * where a separate group interface is used. |
| 5765 | */ |
| 5766 | if (group == wpa_s->parent) |
| 5767 | wpa_s->global->p2p_group_formation = group; |
| 5768 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5769 | group->p2p_in_provisioning = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5770 | 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] | 5771 | |
| 5772 | os_memset(&res, 0, sizeof(res)); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5773 | 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] | 5774 | os_memcpy(res.peer_interface_addr, wpa_s->pending_join_iface_addr, |
| 5775 | ETH_ALEN); |
| 5776 | res.wps_method = wpa_s->pending_join_wps_method; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5777 | if (freq && ssid && ssid_len) { |
| 5778 | res.freq = freq; |
| 5779 | res.ssid_len = ssid_len; |
| 5780 | os_memcpy(res.ssid, ssid, ssid_len); |
| 5781 | } else { |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5782 | if (ssid && ssid_len) { |
| 5783 | bss = wpa_bss_get(wpa_s, wpa_s->pending_join_iface_addr, |
| 5784 | ssid, ssid_len); |
| 5785 | } else { |
| 5786 | bss = wpa_bss_get_bssid_latest( |
| 5787 | wpa_s, wpa_s->pending_join_iface_addr); |
| 5788 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5789 | if (bss) { |
| 5790 | res.freq = bss->freq; |
| 5791 | res.ssid_len = bss->ssid_len; |
| 5792 | os_memcpy(res.ssid, bss->ssid, bss->ssid_len); |
| 5793 | wpa_printf(MSG_DEBUG, "P2P: Join target GO operating frequency from BSS table: %d MHz (SSID %s)", |
| 5794 | bss->freq, |
| 5795 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5796 | } else if (ssid && ssid_len) { |
| 5797 | res.ssid_len = ssid_len; |
| 5798 | os_memcpy(res.ssid, ssid, ssid_len); |
| 5799 | wpa_printf(MSG_DEBUG, "P2P: Join target GO (SSID %s)", |
| 5800 | wpa_ssid_txt(ssid, ssid_len)); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5801 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5802 | } |
| 5803 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5804 | if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) { |
| 5805 | wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel prior to " |
| 5806 | "starting client"); |
| 5807 | wpa_drv_cancel_remain_on_channel(wpa_s); |
| 5808 | wpa_s->off_channel_freq = 0; |
| 5809 | wpa_s->roc_waiting_drv_freq = 0; |
| 5810 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5811 | wpas_start_wps_enrollee(group, &res); |
| 5812 | |
| 5813 | /* |
| 5814 | * Allow a longer timeout for join-a-running-group than normal 15 |
| 5815 | * second group formation timeout since the GO may not have authorized |
| 5816 | * our connection yet. |
| 5817 | */ |
| 5818 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 5819 | eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout, |
| 5820 | wpa_s, NULL); |
| 5821 | |
| 5822 | return 0; |
| 5823 | } |
| 5824 | |
| 5825 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5826 | 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] | 5827 | int *force_freq, int *pref_freq, int go, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5828 | struct weighted_pcl *pref_freq_list, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5829 | unsigned int *num_pref_freq) |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5830 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5831 | struct wpa_used_freq_data *freqs; |
| 5832 | int res, best_freq, num_unused; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5833 | unsigned int freq_in_use = 0, num, i, max_pref_freq; |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5834 | int p2p_pref_freq; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5835 | |
| 5836 | max_pref_freq = *num_pref_freq; |
| 5837 | *num_pref_freq = 0; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5838 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5839 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 5840 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5841 | if (!freqs) |
| 5842 | return -1; |
| 5843 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5844 | num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, |
| 5845 | wpa_s->num_multichan_concurrent); |
| 5846 | |
| 5847 | /* |
| 5848 | * It is possible that the total number of used frequencies is bigger |
| 5849 | * than the number of frequencies used for P2P, so get the system wide |
| 5850 | * number of unused frequencies. |
| 5851 | */ |
| 5852 | num_unused = wpas_p2p_num_unused_channels(wpa_s); |
| 5853 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5854 | wpa_printf(MSG_DEBUG, |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5855 | "P2P: Setup freqs: freq=%d num_MCC=%d shared_freqs=%u num_unused=%d", |
| 5856 | freq, wpa_s->num_multichan_concurrent, num, num_unused); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5857 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5858 | if (freq > 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5859 | int ret; |
| 5860 | if (go) |
| 5861 | ret = p2p_supported_freq(wpa_s->global->p2p, freq); |
| 5862 | else |
| 5863 | ret = p2p_supported_freq_cli(wpa_s->global->p2p, freq); |
| 5864 | if (!ret) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5865 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5866 | ieee80211_is_dfs(freq, wpa_s->hw.modes, |
| 5867 | wpa_s->hw.num_modes)) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5868 | /* |
| 5869 | * If freq is a DFS channel and DFS is offloaded |
| 5870 | * to the driver, allow P2P GO to use it. |
| 5871 | */ |
| 5872 | wpa_printf(MSG_DEBUG, |
| 5873 | "P2P: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded to the driver", |
| 5874 | freq); |
| 5875 | } else { |
| 5876 | wpa_printf(MSG_DEBUG, |
| 5877 | "P2P: The forced channel (%u MHz) is not supported for P2P uses", |
| 5878 | freq); |
| 5879 | res = -3; |
| 5880 | goto exit_free; |
| 5881 | } |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5882 | } |
| 5883 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5884 | for (i = 0; i < num; i++) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5885 | if (freqs[i].freq == freq) |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5886 | freq_in_use = 1; |
| 5887 | } |
| 5888 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5889 | if (num_unused <= 0 && !freq_in_use) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5890 | wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group on %u MHz as there are no available channels", |
| 5891 | freq); |
| 5892 | res = -2; |
| 5893 | goto exit_free; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5894 | } |
| 5895 | wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the " |
| 5896 | "requested channel (%u MHz)", freq); |
| 5897 | *force_freq = freq; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5898 | goto exit_ok; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5899 | } |
| 5900 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5901 | best_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5902 | |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5903 | if (*pref_freq == 0) { |
| 5904 | if (wpa_s->conf->num_p2p_pref_chan && IS_2GHZ(best_freq)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5905 | i = 0; |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5906 | while (i < wpa_s->conf->num_p2p_pref_chan) { |
| 5907 | p2p_pref_freq = ieee80211_chan_to_freq(NULL, |
| 5908 | wpa_s->conf->p2p_pref_chan[i].op_class, |
| 5909 | wpa_s->conf->p2p_pref_chan[i].chan); |
| 5910 | |
| 5911 | if (p2p_supported_freq(wpa_s->global->p2p, p2p_pref_freq) && |
| 5912 | !wpas_p2p_disallowed_freq(wpa_s->global, p2p_pref_freq)) { |
| 5913 | best_freq = p2p_pref_freq; |
| 5914 | wpa_printf(MSG_DEBUG, "P2P: Using frequency (%u MHz) " |
| 5915 | "from P2P preferred channel list", best_freq); |
| 5916 | break; |
| 5917 | } else { |
| 5918 | wpa_printf(MSG_MSGDUMP, "P2P: Skipping preferred " |
| 5919 | "frequency (%u MHz) ", p2p_pref_freq); |
| 5920 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5921 | i++; |
| 5922 | } |
Sreeramya Soratkal | f928e8f | 2022-03-22 17:33:31 +0530 | [diff] [blame] | 5923 | } else if (!wpa_s->conf->num_p2p_pref_chan) { |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5924 | wpa_printf(MSG_DEBUG, "P2P: best_freq=%d, go=%d", |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 5925 | best_freq, go); |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5926 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 5927 | *num_pref_freq = max_pref_freq; |
| 5928 | res = wpas_p2p_pick_best_pref_freq(wpa_s, go, pref_freq_list, |
| 5929 | num_pref_freq); |
| 5930 | if (res > 0) |
| 5931 | best_freq = res; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5932 | } |
| 5933 | } |
| 5934 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5935 | /* We have a candidate frequency to use */ |
| 5936 | if (best_freq > 0) { |
| 5937 | if (*pref_freq == 0 && num_unused > 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5938 | 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] | 5939 | best_freq); |
| 5940 | *pref_freq = best_freq; |
Dmitry Shmidt | 51a47d5 | 2013-09-10 10:52:57 -0700 | [diff] [blame] | 5941 | } else { |
| 5942 | 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] | 5943 | best_freq); |
| 5944 | *force_freq = best_freq; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5945 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5946 | } else if (num_unused > 0) { |
| 5947 | wpa_printf(MSG_DEBUG, |
| 5948 | "P2P: Current operating channels are not available for P2P. Try to use another channel"); |
| 5949 | *force_freq = 0; |
| 5950 | } else { |
| 5951 | wpa_printf(MSG_DEBUG, |
| 5952 | "P2P: All channels are in use and none of them are P2P enabled. Cannot start P2P group"); |
| 5953 | res = -2; |
| 5954 | goto exit_free; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5955 | } |
| 5956 | |
| 5957 | exit_ok: |
| 5958 | res = 0; |
| 5959 | exit_free: |
| 5960 | os_free(freqs); |
| 5961 | return res; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5962 | } |
| 5963 | |
| 5964 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5965 | static bool is_p2p_6ghz_supported(struct wpa_supplicant *wpa_s, |
| 5966 | const u8 *peer_addr) |
| 5967 | { |
| 5968 | if (wpa_s->conf->p2p_6ghz_disable || |
| 5969 | !get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
| 5970 | HOSTAPD_MODE_IEEE80211A, true)) |
| 5971 | return false; |
| 5972 | |
| 5973 | if (!p2p_wfd_enabled(wpa_s->global->p2p)) |
| 5974 | return false; |
| 5975 | if (peer_addr && !p2p_peer_wfd_enabled(wpa_s->global->p2p, peer_addr)) |
| 5976 | return false; |
| 5977 | |
| 5978 | return true; |
| 5979 | } |
| 5980 | |
| 5981 | |
| 5982 | static int wpas_p2p_check_6ghz(struct wpa_supplicant *wpa_s, |
| 5983 | const u8 *peer_addr, bool allow_6ghz, int freq) |
| 5984 | { |
| 5985 | if (allow_6ghz && is_p2p_6ghz_supported(wpa_s, peer_addr)) { |
| 5986 | wpa_printf(MSG_DEBUG, |
| 5987 | "P2P: Allow connection on 6 GHz channels"); |
| 5988 | p2p_set_6ghz_dev_capab(wpa_s->global->p2p, true); |
| 5989 | } else { |
| 5990 | if (is_6ghz_freq(freq)) |
| 5991 | return -2; |
| 5992 | p2p_set_6ghz_dev_capab(wpa_s->global->p2p, false); |
| 5993 | } |
| 5994 | |
| 5995 | return 0; |
| 5996 | } |
| 5997 | |
| 5998 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5999 | /** |
| 6000 | * wpas_p2p_connect - Request P2P Group Formation to be started |
| 6001 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 6002 | * @peer_addr: Address of the peer P2P Device |
| 6003 | * @pin: PIN to use during provisioning or %NULL to indicate PBC mode |
| 6004 | * @persistent_group: Whether to create a persistent group |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6005 | * @auto_join: Whether to select join vs. GO Negotiation automatically |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6006 | * @join: Whether to join an existing group (as a client) instead of starting |
| 6007 | * Group Owner negotiation; @peer_addr is BSSID in that case |
| 6008 | * @auth: Whether to only authorize the connection instead of doing that and |
| 6009 | * initiating Group Owner negotiation |
| 6010 | * @go_intent: GO Intent or -1 to use default |
| 6011 | * @freq: Frequency for the group or 0 for auto-selection |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6012 | * @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] | 6013 | * @persistent_id: Persistent group credentials to use for forcing GO |
| 6014 | * parameters or -1 to generate new values (SSID/passphrase) |
| 6015 | * @pd: Whether to send Provision Discovery prior to GO Negotiation as an |
| 6016 | * interoperability workaround when initiating group formation |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6017 | * @ht40: Start GO with 40 MHz channel width |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6018 | * @vht: Start GO with VHT support |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6019 | * @vht_chwidth: Channel width supported by GO operating with VHT support |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6020 | * (CHANWIDTH_*). |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 6021 | * @group_ssid: Specific Group SSID for join or %NULL if not set |
| 6022 | * @group_ssid_len: Length of @group_ssid in octets |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6023 | * @allow_6ghz: Allow P2P connection on 6 GHz channels |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6024 | * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified |
| 6025 | * failure, -2 on failure due to channel not currently available, |
| 6026 | * -3 if forced channel is not supported |
| 6027 | */ |
| 6028 | int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr, |
| 6029 | const char *pin, enum p2p_wps_method wps_method, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6030 | int persistent_group, int auto_join, int join, int auth, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6031 | int go_intent, int freq, unsigned int vht_center_freq2, |
| 6032 | int persistent_id, int pd, int ht40, int vht, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6033 | unsigned int vht_chwidth, int he, int edmg, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6034 | const u8 *group_ssid, size_t group_ssid_len, |
| 6035 | bool allow_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6036 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6037 | int force_freq = 0, pref_freq = 0; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6038 | int ret = 0, res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6039 | enum wpa_driver_if_type iftype; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6040 | const u8 *if_addr; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6041 | struct wpa_ssid *ssid = NULL; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6042 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 6043 | unsigned int size; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6044 | |
| 6045 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 6046 | return -1; |
| 6047 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6048 | if (persistent_id >= 0) { |
| 6049 | ssid = wpa_config_get_network(wpa_s->conf, persistent_id); |
| 6050 | if (ssid == NULL || ssid->disabled != 2 || |
| 6051 | ssid->mode != WPAS_MODE_P2P_GO) |
| 6052 | return -1; |
| 6053 | } |
| 6054 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6055 | if (wpas_p2p_check_6ghz(wpa_s, peer_addr, allow_6ghz, freq)) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6056 | return -2; |
| 6057 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6058 | os_free(wpa_s->global->add_psk); |
| 6059 | wpa_s->global->add_psk = NULL; |
| 6060 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6061 | wpa_s->global->p2p_fail_on_wps_complete = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6062 | wpa_s->global->pending_p2ps_group = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6063 | wpa_s->global->pending_p2ps_group_freq = 0; |
| 6064 | wpa_s->p2ps_method_config_any = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6065 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6066 | if (go_intent < 0) |
| 6067 | go_intent = wpa_s->conf->p2p_go_intent; |
| 6068 | |
| 6069 | if (!auth) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6070 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6071 | |
| 6072 | wpa_s->p2p_wps_method = wps_method; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6073 | wpa_s->p2p_persistent_group = !!persistent_group; |
| 6074 | wpa_s->p2p_persistent_id = persistent_id; |
| 6075 | wpa_s->p2p_go_intent = go_intent; |
| 6076 | wpa_s->p2p_connect_freq = freq; |
| 6077 | wpa_s->p2p_fallback_to_go_neg = 0; |
| 6078 | wpa_s->p2p_pd_before_go_neg = !!pd; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6079 | wpa_s->p2p_go_ht40 = !!ht40; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6080 | wpa_s->p2p_go_vht = !!vht; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6081 | wpa_s->p2p_go_vht_center_freq2 = vht_center_freq2; |
| 6082 | wpa_s->p2p_go_max_oper_chwidth = vht_chwidth; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6083 | wpa_s->p2p_go_he = !!he; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6084 | wpa_s->p2p_go_edmg = !!edmg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6085 | |
| 6086 | if (pin) |
| 6087 | os_strlcpy(wpa_s->p2p_pin, pin, sizeof(wpa_s->p2p_pin)); |
| 6088 | else if (wps_method == WPS_PIN_DISPLAY) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6089 | if (wps_generate_pin((unsigned int *) &ret) < 0) |
| 6090 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6091 | res = os_snprintf(wpa_s->p2p_pin, sizeof(wpa_s->p2p_pin), |
| 6092 | "%08d", ret); |
| 6093 | if (os_snprintf_error(sizeof(wpa_s->p2p_pin), res)) |
| 6094 | wpa_s->p2p_pin[sizeof(wpa_s->p2p_pin) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6095 | wpa_printf(MSG_DEBUG, "P2P: Randomly generated PIN: %s", |
| 6096 | wpa_s->p2p_pin); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6097 | } else if (wps_method == WPS_P2PS) { |
| 6098 | /* Force the P2Ps default PIN to be used */ |
| 6099 | os_strlcpy(wpa_s->p2p_pin, "12345670", sizeof(wpa_s->p2p_pin)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6100 | } else |
| 6101 | wpa_s->p2p_pin[0] = '\0'; |
| 6102 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6103 | if (join || auto_join) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6104 | u8 iface_addr[ETH_ALEN], dev_addr[ETH_ALEN]; |
| 6105 | if (auth) { |
| 6106 | wpa_printf(MSG_DEBUG, "P2P: Authorize invitation to " |
| 6107 | "connect a running group from " MACSTR, |
| 6108 | MAC2STR(peer_addr)); |
| 6109 | os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN); |
| 6110 | return ret; |
| 6111 | } |
| 6112 | os_memcpy(dev_addr, peer_addr, ETH_ALEN); |
| 6113 | if (p2p_get_interface_addr(wpa_s->global->p2p, peer_addr, |
| 6114 | iface_addr) < 0) { |
| 6115 | os_memcpy(iface_addr, peer_addr, ETH_ALEN); |
| 6116 | p2p_get_dev_addr(wpa_s->global->p2p, peer_addr, |
| 6117 | dev_addr); |
| 6118 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6119 | if (auto_join) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6120 | os_get_reltime(&wpa_s->p2p_auto_started); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6121 | wpa_printf(MSG_DEBUG, "P2P: Auto join started at " |
| 6122 | "%ld.%06ld", |
| 6123 | wpa_s->p2p_auto_started.sec, |
| 6124 | wpa_s->p2p_auto_started.usec); |
| 6125 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6126 | wpa_s->user_initiated_pd = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6127 | if (wpas_p2p_join(wpa_s, iface_addr, dev_addr, wps_method, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 6128 | auto_join, freq, |
| 6129 | group_ssid, group_ssid_len) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6130 | return -1; |
| 6131 | return ret; |
| 6132 | } |
| 6133 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6134 | size = P2P_MAX_PREF_CHANNELS; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6135 | res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6136 | go_intent == 15, pref_freq_list, &size); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6137 | if (res) |
| 6138 | return res; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 6139 | wpas_p2p_set_own_freq_preference(wpa_s, |
| 6140 | force_freq ? force_freq : pref_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6141 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6142 | p2p_set_own_pref_freq_list(wpa_s->global->p2p, pref_freq_list, size); |
| 6143 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6144 | wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s); |
| 6145 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6146 | if (wpa_s->create_p2p_iface) { |
| 6147 | /* Prepare to add a new interface for the group */ |
| 6148 | iftype = WPA_IF_P2P_GROUP; |
| 6149 | if (go_intent == 15) |
| 6150 | iftype = WPA_IF_P2P_GO; |
| 6151 | if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) { |
| 6152 | wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " |
| 6153 | "interface for the group"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6154 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6155 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6156 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6157 | if_addr = wpa_s->pending_interface_addr; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6158 | } else { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6159 | if (wpa_s->p2p_mgmt) |
| 6160 | if_addr = wpa_s->parent->own_addr; |
| 6161 | else |
| 6162 | if_addr = wpa_s->own_addr; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6163 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
| 6164 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6165 | |
| 6166 | if (auth) { |
| 6167 | if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6168 | go_intent, if_addr, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6169 | force_freq, persistent_group, ssid, |
| 6170 | pref_freq) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6171 | return -1; |
| 6172 | return ret; |
| 6173 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6174 | |
| 6175 | if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method, |
| 6176 | go_intent, if_addr, force_freq, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6177 | persistent_group, ssid, pref_freq) < 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6178 | if (wpa_s->create_p2p_iface) |
| 6179 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6180 | return -1; |
| 6181 | } |
| 6182 | return ret; |
| 6183 | } |
| 6184 | |
| 6185 | |
| 6186 | /** |
| 6187 | * wpas_p2p_remain_on_channel_cb - Indication of remain-on-channel start |
| 6188 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 6189 | * @freq: Frequency of the channel in MHz |
| 6190 | * @duration: Duration of the stay on the channel in milliseconds |
| 6191 | * |
| 6192 | * This callback is called when the driver indicates that it has started the |
| 6193 | * requested remain-on-channel duration. |
| 6194 | */ |
| 6195 | void wpas_p2p_remain_on_channel_cb(struct wpa_supplicant *wpa_s, |
| 6196 | unsigned int freq, unsigned int duration) |
| 6197 | { |
| 6198 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 6199 | return; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6200 | 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)", |
| 6201 | wpa_s->off_channel_freq, wpa_s->pending_listen_freq, |
| 6202 | wpa_s->roc_waiting_drv_freq, freq, duration); |
| 6203 | if (wpa_s->off_channel_freq && |
| 6204 | wpa_s->off_channel_freq == wpa_s->pending_listen_freq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6205 | p2p_listen_cb(wpa_s->global->p2p, wpa_s->pending_listen_freq, |
| 6206 | wpa_s->pending_listen_duration); |
| 6207 | wpa_s->pending_listen_freq = 0; |
Dmitry Shmidt | 7f93d6f | 2014-02-21 11:22:49 -0800 | [diff] [blame] | 6208 | } else { |
| 6209 | wpa_printf(MSG_DEBUG, "P2P: Ignore remain-on-channel callback (off_channel_freq=%u pending_listen_freq=%d freq=%u duration=%u)", |
| 6210 | wpa_s->off_channel_freq, wpa_s->pending_listen_freq, |
| 6211 | freq, duration); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6212 | } |
| 6213 | } |
| 6214 | |
| 6215 | |
Jithu Jance | 57cea1a | 2014-08-20 10:22:04 -0700 | [diff] [blame] | 6216 | 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] | 6217 | { |
| 6218 | /* Limit maximum Listen state time based on driver limitation. */ |
| 6219 | if (timeout > wpa_s->max_remain_on_chan) |
| 6220 | timeout = wpa_s->max_remain_on_chan; |
| 6221 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6222 | return p2p_listen(wpa_s->global->p2p, timeout); |
| 6223 | } |
| 6224 | |
| 6225 | |
| 6226 | /** |
| 6227 | * wpas_p2p_cancel_remain_on_channel_cb - Remain-on-channel timeout |
| 6228 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 6229 | * @freq: Frequency of the channel in MHz |
| 6230 | * |
| 6231 | * This callback is called when the driver indicates that a remain-on-channel |
| 6232 | * operation has been completed, i.e., the duration on the requested channel |
| 6233 | * has timed out. |
| 6234 | */ |
| 6235 | void wpas_p2p_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s, |
| 6236 | unsigned int freq) |
| 6237 | { |
| 6238 | wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel callback " |
| 6239 | "(p2p_long_listen=%d ms pending_action_tx=%p)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6240 | wpa_s->global->p2p_long_listen, |
| 6241 | offchannel_pending_action_tx(wpa_s)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6242 | wpas_p2p_listen_work_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6243 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 6244 | return; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6245 | if (wpa_s->global->p2p_long_listen > 0) |
| 6246 | wpa_s->global->p2p_long_listen -= wpa_s->max_remain_on_chan; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6247 | if (p2p_listen_end(wpa_s->global->p2p, freq) > 0) |
| 6248 | return; /* P2P module started a new operation */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6249 | if (offchannel_pending_action_tx(wpa_s)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6250 | return; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6251 | if (wpa_s->global->p2p_long_listen > 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6252 | wpa_printf(MSG_DEBUG, "P2P: Continuing long Listen state"); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6253 | wpas_p2p_listen_start(wpa_s, wpa_s->global->p2p_long_listen); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6254 | } else { |
| 6255 | /* |
| 6256 | * When listen duration is over, stop listen & update p2p_state |
| 6257 | * to IDLE. |
| 6258 | */ |
| 6259 | p2p_stop_listen(wpa_s->global->p2p); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6260 | } |
| 6261 | } |
| 6262 | |
| 6263 | |
| 6264 | /** |
| 6265 | * wpas_p2p_group_remove - Remove a P2P group |
| 6266 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 6267 | * @ifname: Network interface name of the group interface or "*" to remove all |
| 6268 | * groups |
| 6269 | * Returns: 0 on success, -1 on failure |
| 6270 | * |
| 6271 | * This function is used to remove a P2P group. This can be used to disconnect |
| 6272 | * from a group in which the local end is a P2P Client or to end a P2P Group in |
| 6273 | * case the local end is the Group Owner. If a virtual network interface was |
| 6274 | * created for this group, that interface will be removed. Otherwise, only the |
| 6275 | * configured P2P group network will be removed from the interface. |
| 6276 | */ |
| 6277 | int wpas_p2p_group_remove(struct wpa_supplicant *wpa_s, const char *ifname) |
| 6278 | { |
| 6279 | struct wpa_global *global = wpa_s->global; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6280 | struct wpa_supplicant *calling_wpa_s = wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6281 | |
| 6282 | if (os_strcmp(ifname, "*") == 0) { |
| 6283 | struct wpa_supplicant *prev; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6284 | bool calling_wpa_s_group_removed = false; |
| 6285 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6286 | wpa_s = global->ifaces; |
| 6287 | while (wpa_s) { |
| 6288 | prev = wpa_s; |
| 6289 | wpa_s = wpa_s->next; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6290 | if (prev->p2p_group_interface != |
| 6291 | NOT_P2P_GROUP_INTERFACE || |
| 6292 | (prev->current_ssid && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6293 | prev->current_ssid->p2p_group)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6294 | wpas_p2p_disconnect_safely(prev, calling_wpa_s); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6295 | if (prev == calling_wpa_s) |
| 6296 | calling_wpa_s_group_removed = true; |
| 6297 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6298 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6299 | |
| 6300 | if (!calling_wpa_s_group_removed && |
| 6301 | (calling_wpa_s->p2p_group_interface != |
| 6302 | NOT_P2P_GROUP_INTERFACE || |
| 6303 | (calling_wpa_s->current_ssid && |
| 6304 | calling_wpa_s->current_ssid->p2p_group))) { |
| 6305 | wpa_printf(MSG_DEBUG, "Remove calling_wpa_s P2P group"); |
| 6306 | wpas_p2p_disconnect_safely(calling_wpa_s, |
| 6307 | calling_wpa_s); |
| 6308 | } |
| 6309 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6310 | return 0; |
| 6311 | } |
| 6312 | |
| 6313 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 6314 | if (os_strcmp(wpa_s->ifname, ifname) == 0) |
| 6315 | break; |
| 6316 | } |
| 6317 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6318 | return wpas_p2p_disconnect_safely(wpa_s, calling_wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6319 | } |
| 6320 | |
| 6321 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6322 | static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq) |
| 6323 | { |
| 6324 | unsigned int r; |
| 6325 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6326 | if (!wpa_s->conf->num_p2p_pref_chan && !freq) { |
| 6327 | unsigned int i, size = P2P_MAX_PREF_CHANNELS; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6328 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6329 | int res; |
| 6330 | |
| 6331 | res = wpa_drv_get_pref_freq_list(wpa_s, WPA_IF_P2P_GO, |
| 6332 | &size, pref_freq_list); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 6333 | if (!res && size > 0 && !is_p2p_allow_6ghz(wpa_s->global->p2p)) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6334 | size = p2p_remove_6ghz_channels(pref_freq_list, size); |
| 6335 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6336 | if (!res && size > 0) { |
| 6337 | i = 0; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 6338 | while (i < size && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6339 | (!p2p_supported_freq(wpa_s->global->p2p, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6340 | pref_freq_list[i].freq) || |
| 6341 | wpas_p2p_disallowed_freq( |
| 6342 | wpa_s->global, |
| 6343 | pref_freq_list[i].freq) || |
| 6344 | !p2p_pref_freq_allowed(&pref_freq_list[i], |
| 6345 | true))) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6346 | wpa_printf(MSG_DEBUG, |
| 6347 | "P2P: preferred_freq_list[%d]=%d is disallowed", |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6348 | i, pref_freq_list[i].freq); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6349 | i++; |
| 6350 | } |
| 6351 | if (i != size) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6352 | freq = pref_freq_list[i].freq; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6353 | wpa_printf(MSG_DEBUG, |
| 6354 | "P2P: Using preferred_freq_list[%d]=%d", |
| 6355 | i, freq); |
| 6356 | } else { |
| 6357 | wpa_printf(MSG_DEBUG, |
| 6358 | "P2P: All driver preferred frequencies are disallowed for P2P use"); |
| 6359 | } |
| 6360 | } else { |
| 6361 | wpa_printf(MSG_DEBUG, |
| 6362 | "P2P: No preferred frequency list available"); |
| 6363 | } |
| 6364 | } |
| 6365 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6366 | if (freq == 2) { |
| 6367 | wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 2.4 GHz " |
| 6368 | "band"); |
| 6369 | if (wpa_s->best_24_freq > 0 && |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6370 | p2p_supported_freq_go(wpa_s->global->p2p, |
| 6371 | wpa_s->best_24_freq)) { |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6372 | freq = wpa_s->best_24_freq; |
| 6373 | wpa_printf(MSG_DEBUG, "P2P: Use best 2.4 GHz band " |
| 6374 | "channel: %d MHz", freq); |
| 6375 | } else { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6376 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 6377 | return -1; |
Jimmy Chen | 801bf46 | 2021-11-09 23:08:48 +0800 | [diff] [blame] | 6378 | int possible_2g_freqs[] = { |
| 6379 | /* operating class 81 */ |
| 6380 | 2412, 2437, 2462, |
| 6381 | }; |
| 6382 | int possible_2g_freqs_num = |
| 6383 | sizeof(possible_2g_freqs)/sizeof(possible_2g_freqs[0]); |
| 6384 | int i; |
| 6385 | for (i = 0; i < possible_2g_freqs_num; i++, r++) { |
| 6386 | freq = possible_2g_freqs[r % possible_2g_freqs_num]; |
| 6387 | if (p2p_supported_freq_go(wpa_s->global->p2p, freq)) { |
| 6388 | break; |
| 6389 | } |
| 6390 | } |
| 6391 | |
| 6392 | if (i >= possible_2g_freqs_num) { |
| 6393 | wpa_printf(MSG_DEBUG, "P2P: Could not select " |
| 6394 | "2.4 GHz channel for P2P group"); |
| 6395 | return -1; |
| 6396 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6397 | wpa_printf(MSG_DEBUG, "P2P: Use random 2.4 GHz band " |
| 6398 | "channel: %d MHz", freq); |
| 6399 | } |
| 6400 | } |
| 6401 | |
| 6402 | if (freq == 5) { |
| 6403 | wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 5 GHz " |
| 6404 | "band"); |
| 6405 | if (wpa_s->best_5_freq > 0 && |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6406 | p2p_supported_freq_go(wpa_s->global->p2p, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6407 | wpa_s->best_5_freq)) { |
| 6408 | freq = wpa_s->best_5_freq; |
| 6409 | wpa_printf(MSG_DEBUG, "P2P: Use best 5 GHz band " |
| 6410 | "channel: %d MHz", freq); |
| 6411 | } else { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6412 | const int freqs[] = { |
| 6413 | /* operating class 115 */ |
| 6414 | 5180, 5200, 5220, 5240, |
| 6415 | /* operating class 124 */ |
| 6416 | 5745, 5765, 5785, 5805, |
| 6417 | }; |
| 6418 | unsigned int i, num_freqs = ARRAY_SIZE(freqs); |
| 6419 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6420 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 6421 | return -1; |
Jimmy Chen | 64b9063 | 2020-09-29 17:27:34 +0800 | [diff] [blame] | 6422 | |
| 6423 | /* |
| 6424 | * most of 5G channels are DFS, only operating class 115 and 124 |
| 6425 | * are available possibly, randomly pick a start to check them. |
| 6426 | */ |
| 6427 | int possible_5g_freqs[] = { |
| 6428 | /* operating class 115 */ |
| 6429 | 5180, 5200, 5220, 5240, |
| 6430 | /* operating class 124 */ |
| 6431 | 5745, 5765, 5785, 5805, |
| 6432 | }; |
| 6433 | int possible_5g_freqs_num = |
| 6434 | sizeof(possible_5g_freqs)/sizeof(possible_5g_freqs[0]); |
| 6435 | |
Jimmy Chen | 64b9063 | 2020-09-29 17:27:34 +0800 | [diff] [blame] | 6436 | for (i = 0; i < possible_5g_freqs_num; i++, r++) { |
| 6437 | if (p2p_supported_freq_go( |
| 6438 | wpa_s->global->p2p, |
| 6439 | possible_5g_freqs[r % possible_5g_freqs_num])) { |
| 6440 | freq = possible_5g_freqs[r % possible_5g_freqs_num]; |
| 6441 | break; |
| 6442 | } |
| 6443 | } |
| 6444 | |
| 6445 | if (i >= possible_5g_freqs_num) { |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6446 | wpa_printf(MSG_DEBUG, "P2P: Could not select " |
| 6447 | "5 GHz channel for P2P group"); |
| 6448 | return -1; |
| 6449 | } |
| 6450 | wpa_printf(MSG_DEBUG, "P2P: Use random 5 GHz band " |
| 6451 | "channel: %d MHz", freq); |
| 6452 | } |
| 6453 | } |
| 6454 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6455 | if (freq > 0 && !p2p_supported_freq_go(wpa_s->global->p2p, freq)) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6456 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6457 | ieee80211_is_dfs(freq, wpa_s->hw.modes, |
| 6458 | wpa_s->hw.num_modes)) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6459 | /* |
| 6460 | * If freq is a DFS channel and DFS is offloaded to the |
| 6461 | * driver, allow P2P GO to use it. |
| 6462 | */ |
| 6463 | wpa_printf(MSG_DEBUG, "P2P: " |
| 6464 | "%s: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded", |
| 6465 | __func__, freq); |
| 6466 | return freq; |
| 6467 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6468 | wpa_printf(MSG_DEBUG, "P2P: The forced channel for GO " |
| 6469 | "(%u MHz) is not supported for P2P uses", |
| 6470 | freq); |
| 6471 | return -1; |
| 6472 | } |
| 6473 | |
| 6474 | return freq; |
| 6475 | } |
| 6476 | |
| 6477 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6478 | static int wpas_p2p_supported_freq_go(struct wpa_supplicant *wpa_s, |
| 6479 | const struct p2p_channels *channels, |
| 6480 | int freq) |
| 6481 | { |
| 6482 | if (!wpas_p2p_disallowed_freq(wpa_s->global, freq) && |
| 6483 | p2p_supported_freq_go(wpa_s->global->p2p, freq) && |
| 6484 | freq_included(wpa_s, channels, freq)) |
| 6485 | return 1; |
| 6486 | return 0; |
| 6487 | } |
| 6488 | |
| 6489 | |
| 6490 | static void wpas_p2p_select_go_freq_no_pref(struct wpa_supplicant *wpa_s, |
| 6491 | struct p2p_go_neg_results *params, |
| 6492 | const struct p2p_channels *channels) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6493 | { |
| 6494 | unsigned int i, r; |
| 6495 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6496 | /* try all channels in operating class 115 */ |
| 6497 | for (i = 0; i < 4; i++) { |
| 6498 | params->freq = 5180 + i * 20; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6499 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6500 | goto out; |
| 6501 | } |
| 6502 | |
| 6503 | /* try all channels in operating class 124 */ |
| 6504 | for (i = 0; i < 4; i++) { |
| 6505 | params->freq = 5745 + i * 20; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6506 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6507 | goto out; |
| 6508 | } |
| 6509 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6510 | /* try social channel class 180 channel 2 */ |
| 6511 | params->freq = 58320 + 1 * 2160; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6512 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6513 | goto out; |
| 6514 | |
| 6515 | /* try all channels in reg. class 180 */ |
| 6516 | for (i = 0; i < 4; i++) { |
| 6517 | params->freq = 58320 + i * 2160; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6518 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6519 | goto out; |
| 6520 | } |
| 6521 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6522 | /* try some random selection of the social channels */ |
| 6523 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 6524 | return; |
| 6525 | |
| 6526 | for (i = 0; i < 3; i++) { |
| 6527 | params->freq = 2412 + ((r + i) % 3) * 25; |
| 6528 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
| 6529 | goto out; |
| 6530 | } |
| 6531 | |
| 6532 | /* try all other channels in operating class 81 */ |
| 6533 | for (i = 0; i < 11; i++) { |
| 6534 | params->freq = 2412 + i * 5; |
| 6535 | |
| 6536 | /* skip social channels; covered in the previous loop */ |
| 6537 | if (params->freq == 2412 || |
| 6538 | params->freq == 2437 || |
| 6539 | params->freq == 2462) |
| 6540 | continue; |
| 6541 | |
| 6542 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
| 6543 | goto out; |
| 6544 | } |
| 6545 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6546 | params->freq = 0; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6547 | 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] | 6548 | return; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6549 | out: |
| 6550 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz (no preference known)", |
| 6551 | params->freq); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6552 | } |
| 6553 | |
| 6554 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6555 | static int wpas_same_band(int freq1, int freq2) |
| 6556 | { |
| 6557 | enum hostapd_hw_mode mode1, mode2; |
| 6558 | u8 chan1, chan2; |
| 6559 | |
| 6560 | mode1 = ieee80211_freq_to_chan(freq1, &chan1); |
| 6561 | mode2 = ieee80211_freq_to_chan(freq2, &chan2); |
| 6562 | if (mode1 == NUM_HOSTAPD_MODES) |
| 6563 | return 0; |
| 6564 | return mode1 == mode2; |
| 6565 | } |
| 6566 | |
| 6567 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6568 | static int wpas_p2p_init_go_params(struct wpa_supplicant *wpa_s, |
| 6569 | struct p2p_go_neg_results *params, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6570 | int freq, int vht_center_freq2, int ht40, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6571 | int vht, int max_oper_chwidth, int he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6572 | int edmg, |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6573 | const struct p2p_channels *channels) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6574 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6575 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6576 | unsigned int cand; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6577 | unsigned int num, i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6578 | int ignore_no_freqs = 0; |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6579 | int unused_channels = wpas_p2p_num_unused_channels(wpa_s) > 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6580 | |
| 6581 | os_memset(params, 0, sizeof(*params)); |
| 6582 | params->role_go = 1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6583 | params->ht40 = ht40; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6584 | params->vht = vht; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6585 | params->he = he; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6586 | params->max_oper_chwidth = max_oper_chwidth; |
| 6587 | params->vht_center_freq2 = vht_center_freq2; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6588 | params->edmg = edmg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6589 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6590 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 6591 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6592 | if (!freqs) |
| 6593 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6594 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6595 | num = get_shared_radio_freqs_data(wpa_s, freqs, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6596 | wpa_s->num_multichan_concurrent, |
| 6597 | false); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6598 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6599 | if (wpa_s->current_ssid && |
| 6600 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO && |
| 6601 | wpa_s->wpa_state == WPA_COMPLETED) { |
| 6602 | wpa_printf(MSG_DEBUG, "P2P: %s called for an active GO", |
| 6603 | __func__); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6604 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6605 | /* |
| 6606 | * If the frequency selection is done for an active P2P GO that |
| 6607 | * is not sharing a frequency, allow to select a new frequency |
| 6608 | * even if there are no unused frequencies as we are about to |
| 6609 | * move the P2P GO so its frequency can be re-used. |
| 6610 | */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6611 | for (i = 0; i < num; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6612 | if (freqs[i].freq == wpa_s->current_ssid->frequency && |
| 6613 | freqs[i].flags == 0) { |
| 6614 | ignore_no_freqs = 1; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6615 | break; |
| 6616 | } |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6617 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 6618 | } |
| 6619 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6620 | /* Try to use EDMG channel */ |
| 6621 | if (params->edmg) { |
| 6622 | if (wpas_p2p_try_edmg_channel(wpa_s, params) == 0) |
| 6623 | goto success; |
| 6624 | params->edmg = 0; |
| 6625 | } |
| 6626 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6627 | /* try using the forced freq */ |
| 6628 | if (freq) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6629 | if (wpas_p2p_disallowed_freq(wpa_s->global, freq) || |
| 6630 | !freq_included(wpa_s, channels, freq)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6631 | wpa_printf(MSG_DEBUG, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6632 | "P2P: Forced GO freq %d MHz disallowed", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6633 | freq); |
| 6634 | goto fail; |
| 6635 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6636 | if (!p2p_supported_freq_go(wpa_s->global->p2p, freq)) { |
| 6637 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6638 | ieee80211_is_dfs(freq, wpa_s->hw.modes, |
| 6639 | wpa_s->hw.num_modes)) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6640 | /* |
| 6641 | * If freq is a DFS channel and DFS is offloaded |
| 6642 | * to the driver, allow P2P GO to use it. |
| 6643 | */ |
| 6644 | wpa_printf(MSG_DEBUG, |
| 6645 | "P2P: %s: The forced channel for GO (%u MHz) requires DFS and DFS is offloaded", |
| 6646 | __func__, freq); |
| 6647 | } else { |
| 6648 | wpa_printf(MSG_DEBUG, |
| 6649 | "P2P: The forced channel for GO (%u MHz) is not supported for P2P uses", |
| 6650 | freq); |
| 6651 | goto fail; |
| 6652 | } |
| 6653 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6654 | |
| 6655 | for (i = 0; i < num; i++) { |
| 6656 | if (freqs[i].freq == freq) { |
| 6657 | wpa_printf(MSG_DEBUG, |
| 6658 | "P2P: forced freq (%d MHz) is also shared", |
| 6659 | freq); |
| 6660 | params->freq = freq; |
| 6661 | goto success; |
| 6662 | } |
| 6663 | } |
| 6664 | |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6665 | if (!ignore_no_freqs && !unused_channels) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6666 | wpa_printf(MSG_DEBUG, |
| 6667 | "P2P: Cannot force GO on freq (%d MHz) as all the channels are in use", |
| 6668 | freq); |
| 6669 | goto fail; |
| 6670 | } |
| 6671 | |
| 6672 | wpa_printf(MSG_DEBUG, |
| 6673 | "P2P: force GO freq (%d MHz) on a free channel", |
| 6674 | freq); |
| 6675 | params->freq = freq; |
| 6676 | goto success; |
| 6677 | } |
| 6678 | |
| 6679 | /* consider using one of the shared frequencies */ |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6680 | if (num && |
| 6681 | (!wpa_s->conf->p2p_ignore_shared_freq || !unused_channels)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6682 | cand = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num); |
| 6683 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6684 | wpa_printf(MSG_DEBUG, |
| 6685 | "P2P: Use shared freq (%d MHz) for GO", |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6686 | cand); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6687 | params->freq = cand; |
| 6688 | goto success; |
| 6689 | } |
| 6690 | |
| 6691 | /* try using one of the shared freqs */ |
| 6692 | for (i = 0; i < num; i++) { |
| 6693 | if (wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6694 | freqs[i].freq)) { |
| 6695 | wpa_printf(MSG_DEBUG, |
| 6696 | "P2P: Use shared freq (%d MHz) for GO", |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6697 | freqs[i].freq); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6698 | params->freq = freqs[i].freq; |
| 6699 | goto success; |
| 6700 | } |
| 6701 | } |
| 6702 | } |
| 6703 | |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6704 | if (!ignore_no_freqs && !unused_channels) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6705 | wpa_printf(MSG_DEBUG, |
| 6706 | "P2P: Cannot force GO on any of the channels we are already using"); |
| 6707 | goto fail; |
| 6708 | } |
| 6709 | |
| 6710 | /* try using the setting from the configuration file */ |
| 6711 | if (wpa_s->conf->p2p_oper_reg_class == 81 && |
| 6712 | wpa_s->conf->p2p_oper_channel >= 1 && |
| 6713 | wpa_s->conf->p2p_oper_channel <= 11 && |
| 6714 | wpas_p2p_supported_freq_go( |
| 6715 | wpa_s, channels, |
| 6716 | 2407 + 5 * wpa_s->conf->p2p_oper_channel)) { |
| 6717 | params->freq = 2407 + 5 * wpa_s->conf->p2p_oper_channel; |
| 6718 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured " |
| 6719 | "frequency %d MHz", params->freq); |
| 6720 | goto success; |
| 6721 | } |
| 6722 | |
| 6723 | if ((wpa_s->conf->p2p_oper_reg_class == 115 || |
| 6724 | wpa_s->conf->p2p_oper_reg_class == 116 || |
| 6725 | wpa_s->conf->p2p_oper_reg_class == 117 || |
| 6726 | wpa_s->conf->p2p_oper_reg_class == 124 || |
| 6727 | wpa_s->conf->p2p_oper_reg_class == 125 || |
| 6728 | wpa_s->conf->p2p_oper_reg_class == 126 || |
| 6729 | wpa_s->conf->p2p_oper_reg_class == 127) && |
| 6730 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6731 | 5000 + |
| 6732 | 5 * wpa_s->conf->p2p_oper_channel)) { |
| 6733 | params->freq = 5000 + 5 * wpa_s->conf->p2p_oper_channel; |
| 6734 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured " |
| 6735 | "frequency %d MHz", params->freq); |
| 6736 | goto success; |
| 6737 | } |
| 6738 | |
| 6739 | /* Try using best channels */ |
| 6740 | if (wpa_s->conf->p2p_oper_channel == 0 && |
| 6741 | wpa_s->best_overall_freq > 0 && |
| 6742 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6743 | wpa_s->best_overall_freq)) { |
| 6744 | params->freq = wpa_s->best_overall_freq; |
| 6745 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best overall " |
| 6746 | "channel %d MHz", params->freq); |
| 6747 | goto success; |
| 6748 | } |
| 6749 | |
| 6750 | if (wpa_s->conf->p2p_oper_channel == 0 && |
| 6751 | wpa_s->best_24_freq > 0 && |
| 6752 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6753 | wpa_s->best_24_freq)) { |
| 6754 | params->freq = wpa_s->best_24_freq; |
| 6755 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 2.4 GHz " |
| 6756 | "channel %d MHz", params->freq); |
| 6757 | goto success; |
| 6758 | } |
| 6759 | |
| 6760 | if (wpa_s->conf->p2p_oper_channel == 0 && |
| 6761 | wpa_s->best_5_freq > 0 && |
| 6762 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6763 | wpa_s->best_5_freq)) { |
| 6764 | params->freq = wpa_s->best_5_freq; |
| 6765 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 5 GHz " |
| 6766 | "channel %d MHz", params->freq); |
| 6767 | goto success; |
| 6768 | } |
| 6769 | |
| 6770 | /* try using preferred channels */ |
| 6771 | cand = p2p_get_pref_freq(wpa_s->global->p2p, channels); |
| 6772 | if (cand && wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6773 | params->freq = cand; |
| 6774 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz from preferred " |
| 6775 | "channels", params->freq); |
| 6776 | goto success; |
| 6777 | } |
| 6778 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6779 | /* Try using a channel that allows VHT to be used with 80 MHz */ |
| 6780 | if (wpa_s->hw.modes && wpa_s->p2p_group_common_freqs) { |
| 6781 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 6782 | enum hostapd_hw_mode mode; |
| 6783 | struct hostapd_hw_modes *hwmode; |
| 6784 | u8 chan; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6785 | u8 op_class; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6786 | |
| 6787 | cand = wpa_s->p2p_group_common_freqs[i]; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6788 | op_class = is_6ghz_freq(cand) ? 133 : 128; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6789 | mode = ieee80211_freq_to_chan(cand, &chan); |
| 6790 | hwmode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6791 | mode, is_6ghz_freq(cand)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6792 | if (!hwmode || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6793 | wpas_p2p_verify_channel(wpa_s, hwmode, op_class, |
| 6794 | chan, BW80) != ALLOWED) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6795 | continue; |
| 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 and allowing VHT80", |
| 6800 | params->freq); |
| 6801 | goto success; |
| 6802 | } |
| 6803 | } |
| 6804 | } |
| 6805 | |
| 6806 | /* Try using a channel that allows HT to be used with 40 MHz on the same |
| 6807 | * band so that CSA can be used */ |
| 6808 | if (wpa_s->current_ssid && wpa_s->hw.modes && |
| 6809 | wpa_s->p2p_group_common_freqs) { |
| 6810 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 6811 | enum hostapd_hw_mode mode; |
| 6812 | struct hostapd_hw_modes *hwmode; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6813 | u8 chan, op_class; |
| 6814 | bool is_6ghz, supported = false; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6815 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6816 | is_6ghz = is_6ghz_freq(cand); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6817 | cand = wpa_s->p2p_group_common_freqs[i]; |
| 6818 | mode = ieee80211_freq_to_chan(cand, &chan); |
| 6819 | hwmode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6820 | mode, is_6ghz); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6821 | if (!wpas_same_band(wpa_s->current_ssid->frequency, |
| 6822 | cand) || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6823 | !hwmode) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6824 | continue; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6825 | if (is_6ghz && |
| 6826 | wpas_p2p_verify_channel(wpa_s, hwmode, 132, chan, |
| 6827 | BW40) == ALLOWED) |
| 6828 | supported = true; |
| 6829 | |
| 6830 | if (!is_6ghz && |
| 6831 | ieee80211_freq_to_channel_ext( |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6832 | cand, -1, CONF_OPER_CHWIDTH_USE_HT, |
| 6833 | &op_class, &chan) != NUM_HOSTAPD_MODES && |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6834 | wpas_p2p_verify_channel( |
| 6835 | wpa_s, hwmode, op_class, chan, |
| 6836 | BW40MINUS) == ALLOWED) |
| 6837 | supported = true; |
| 6838 | |
| 6839 | if (!supported && !is_6ghz && |
| 6840 | ieee80211_freq_to_channel_ext( |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6841 | cand, 1, CONF_OPER_CHWIDTH_USE_HT, |
| 6842 | &op_class, &chan) != NUM_HOSTAPD_MODES && |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6843 | wpas_p2p_verify_channel( |
| 6844 | wpa_s, hwmode, op_class, chan, |
| 6845 | BW40PLUS) == ALLOWED) |
| 6846 | supported = true; |
| 6847 | |
| 6848 | if (!supported) |
| 6849 | continue; |
| 6850 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6851 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6852 | params->freq = cand; |
| 6853 | wpa_printf(MSG_DEBUG, |
| 6854 | "P2P: Use freq %d MHz common with the peer, allowing HT40, and maintaining same band", |
| 6855 | params->freq); |
| 6856 | goto success; |
| 6857 | } |
| 6858 | } |
| 6859 | } |
| 6860 | |
| 6861 | /* Try using one of the group common freqs on the same band so that CSA |
| 6862 | * can be used */ |
| 6863 | if (wpa_s->current_ssid && wpa_s->p2p_group_common_freqs) { |
| 6864 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 6865 | cand = wpa_s->p2p_group_common_freqs[i]; |
| 6866 | if (!wpas_same_band(wpa_s->current_ssid->frequency, |
| 6867 | cand)) |
| 6868 | continue; |
| 6869 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6870 | params->freq = cand; |
| 6871 | wpa_printf(MSG_DEBUG, |
| 6872 | "P2P: Use freq %d MHz common with the peer and maintaining same band", |
| 6873 | params->freq); |
| 6874 | goto success; |
| 6875 | } |
| 6876 | } |
| 6877 | } |
| 6878 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6879 | /* Try using one of the group common freqs */ |
| 6880 | if (wpa_s->p2p_group_common_freqs) { |
| 6881 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 6882 | cand = wpa_s->p2p_group_common_freqs[i]; |
| 6883 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6884 | params->freq = cand; |
| 6885 | wpa_printf(MSG_DEBUG, |
| 6886 | "P2P: Use freq %d MHz common with the peer", |
| 6887 | params->freq); |
| 6888 | goto success; |
| 6889 | } |
| 6890 | } |
| 6891 | } |
| 6892 | |
| 6893 | /* no preference, select some channel */ |
| 6894 | wpas_p2p_select_go_freq_no_pref(wpa_s, params, channels); |
| 6895 | |
| 6896 | if (params->freq == 0) { |
| 6897 | wpa_printf(MSG_DEBUG, "P2P: did not find a freq for GO use"); |
| 6898 | goto fail; |
| 6899 | } |
| 6900 | |
| 6901 | success: |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6902 | os_free(freqs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6903 | return 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6904 | fail: |
| 6905 | os_free(freqs); |
| 6906 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6907 | } |
| 6908 | |
| 6909 | |
| 6910 | static struct wpa_supplicant * |
| 6911 | wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated, |
| 6912 | int go) |
| 6913 | { |
| 6914 | struct wpa_supplicant *group_wpa_s; |
| 6915 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6916 | if (!wpas_p2p_create_iface(wpa_s)) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6917 | if (wpa_s->p2p_mgmt) { |
| 6918 | /* |
| 6919 | * We may be called on the p2p_dev interface which |
| 6920 | * cannot be used for group operations, so always use |
| 6921 | * the primary interface. |
| 6922 | */ |
| 6923 | wpa_s->parent->p2pdev = wpa_s; |
| 6924 | wpa_s = wpa_s->parent; |
| 6925 | } |
| 6926 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 6927 | "P2P: Use primary interface for group operations"); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6928 | wpa_s->p2p_first_connection_timeout = 0; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6929 | if (wpa_s != wpa_s->p2pdev) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6930 | wpas_p2p_clone_config(wpa_s, wpa_s->p2pdev); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6931 | return wpa_s; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6932 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6933 | |
| 6934 | 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] | 6935 | WPA_IF_P2P_CLIENT) < 0) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6936 | wpa_msg_global(wpa_s, MSG_ERROR, |
| 6937 | "P2P: Failed to add group interface"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6938 | return NULL; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6939 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6940 | group_wpa_s = wpas_p2p_init_group_interface(wpa_s, go); |
| 6941 | if (group_wpa_s == NULL) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6942 | wpa_msg_global(wpa_s, MSG_ERROR, |
| 6943 | "P2P: Failed to initialize group interface"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6944 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 6945 | return NULL; |
| 6946 | } |
| 6947 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6948 | if (go && wpa_s->p2p_go_do_acs) { |
| 6949 | group_wpa_s->p2p_go_do_acs = wpa_s->p2p_go_do_acs; |
| 6950 | group_wpa_s->p2p_go_acs_band = wpa_s->p2p_go_acs_band; |
| 6951 | wpa_s->p2p_go_do_acs = 0; |
| 6952 | } |
| 6953 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6954 | if (go && wpa_s->p2p_go_allow_dfs) { |
| 6955 | group_wpa_s->p2p_go_allow_dfs = wpa_s->p2p_go_allow_dfs; |
| 6956 | wpa_s->p2p_go_allow_dfs = 0; |
| 6957 | } |
| 6958 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6959 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use separate group interface %s", |
| 6960 | group_wpa_s->ifname); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6961 | group_wpa_s->p2p_first_connection_timeout = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6962 | return group_wpa_s; |
| 6963 | } |
| 6964 | |
| 6965 | |
| 6966 | /** |
| 6967 | * wpas_p2p_group_add - Add a new P2P group with local end as Group Owner |
| 6968 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 6969 | * @persistent_group: Whether to create a persistent group |
| 6970 | * @freq: Frequency for the group or 0 to indicate no hardcoding |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6971 | * @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] | 6972 | * @ht40: Start GO with 40 MHz channel width |
| 6973 | * @vht: Start GO with VHT support |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6974 | * @vht_chwidth: channel bandwidth for GO operating with VHT support |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6975 | * @edmg: Start GO with EDMG support |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6976 | * @allow_6ghz: Allow P2P group creation on a 6 GHz channel |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6977 | * Returns: 0 on success, -1 on failure |
| 6978 | * |
| 6979 | * This function creates a new P2P group with the local end as the Group Owner, |
| 6980 | * i.e., without using Group Owner Negotiation. |
| 6981 | */ |
| 6982 | 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] | 6983 | int freq, int vht_center_freq2, int ht40, int vht, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6984 | int max_oper_chwidth, int he, int edmg, |
| 6985 | bool allow_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6986 | { |
| 6987 | struct p2p_go_neg_results params; |
Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 6988 | int selected_freq = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6989 | |
| 6990 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 6991 | return -1; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6992 | if (wpas_p2p_check_6ghz(wpa_s, NULL, allow_6ghz, freq)) |
| 6993 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6994 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6995 | os_free(wpa_s->global->add_psk); |
| 6996 | wpa_s->global->add_psk = NULL; |
| 6997 | |
Dmitry Shmidt | dca3979 | 2011-09-06 11:17:33 -0700 | [diff] [blame] | 6998 | /* Make sure we are not running find during connection establishment */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6999 | wpa_printf(MSG_DEBUG, "P2P: Stop any on-going P2P FIND"); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7000 | wpas_p2p_stop_find_oper(wpa_s); |
Dmitry Shmidt | dca3979 | 2011-09-06 11:17:33 -0700 | [diff] [blame] | 7001 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7002 | if (!wpa_s->p2p_go_do_acs) { |
Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 7003 | selected_freq = wpas_p2p_select_go_freq(wpa_s, freq); |
| 7004 | if (selected_freq < 0) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7005 | return -1; |
| 7006 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7007 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7008 | if (wpas_p2p_init_go_params(wpa_s, ¶ms, selected_freq, |
| 7009 | vht_center_freq2, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7010 | ht40, vht, max_oper_chwidth, he, edmg, |
| 7011 | NULL)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7012 | return -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7013 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7014 | p2p_go_params(wpa_s->global->p2p, ¶ms); |
| 7015 | params.persistent_group = persistent_group; |
| 7016 | |
| 7017 | wpa_s = wpas_p2p_get_group_iface(wpa_s, 0, 1); |
| 7018 | if (wpa_s == NULL) |
| 7019 | return -1; |
Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 7020 | if (freq > 0) |
| 7021 | wpa_s->p2p_go_no_pri_sec_switch = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7022 | wpas_start_wps_go(wpa_s, ¶ms, 0); |
| 7023 | |
| 7024 | return 0; |
| 7025 | } |
| 7026 | |
| 7027 | |
| 7028 | static int wpas_start_p2p_client(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7029 | struct wpa_ssid *params, int addr_allocated, |
Matthew Wang | 124e5f4 | 2022-12-29 07:23:06 +0000 | [diff] [blame] | 7030 | int freq, int force_scan, int retry_limit, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 7031 | const u8 *go_bssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7032 | { |
| 7033 | struct wpa_ssid *ssid; |
Matthew Wang | 9ae940b | 2022-09-14 21:25:34 -0700 | [diff] [blame] | 7034 | int other_iface_found = 0; |
| 7035 | struct wpa_supplicant *ifs; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7036 | |
| 7037 | wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 0); |
| 7038 | if (wpa_s == NULL) |
| 7039 | return -1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7040 | if (force_scan) |
| 7041 | os_get_reltime(&wpa_s->scan_min_time); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 7042 | wpa_s->p2p_last_4way_hs_fail = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7043 | |
| 7044 | wpa_supplicant_ap_deinit(wpa_s); |
| 7045 | |
| 7046 | ssid = wpa_config_add_network(wpa_s->conf); |
| 7047 | if (ssid == NULL) |
| 7048 | return -1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7049 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7050 | wpa_config_set_network_defaults(ssid); |
| 7051 | ssid->temporary = 1; |
| 7052 | ssid->proto = WPA_PROTO_RSN; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7053 | ssid->pbss = params->pbss; |
| 7054 | ssid->pairwise_cipher = params->pbss ? WPA_CIPHER_GCMP : |
| 7055 | WPA_CIPHER_CCMP; |
| 7056 | ssid->group_cipher = params->pbss ? WPA_CIPHER_GCMP : WPA_CIPHER_CCMP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7057 | ssid->key_mgmt = WPA_KEY_MGMT_PSK; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 7058 | if (is_6ghz_freq(freq) && |
| 7059 | is_p2p_6ghz_capable(wpa_s->global->p2p)) { |
| 7060 | ssid->auth_alg |= WPA_AUTH_ALG_SAE; |
| 7061 | ssid->key_mgmt |= WPA_KEY_MGMT_SAE; |
| 7062 | ssid->ieee80211w = MGMT_FRAME_PROTECTION_OPTIONAL; |
| 7063 | ssid->sae_pwe = SAE_PWE_HASH_TO_ELEMENT; |
| 7064 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 7065 | "P2P: Enable SAE auth_alg and key_mgmt"); |
| 7066 | } |
| 7067 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7068 | ssid->ssid = os_malloc(params->ssid_len); |
| 7069 | if (ssid->ssid == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7070 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 7071 | return -1; |
| 7072 | } |
| 7073 | os_memcpy(ssid->ssid, params->ssid, params->ssid_len); |
| 7074 | ssid->ssid_len = params->ssid_len; |
| 7075 | ssid->p2p_group = 1; |
| 7076 | ssid->export_keys = 1; |
| 7077 | if (params->psk_set) { |
| 7078 | os_memcpy(ssid->psk, params->psk, 32); |
| 7079 | ssid->psk_set = 1; |
| 7080 | } |
| 7081 | if (params->passphrase) |
| 7082 | ssid->passphrase = os_strdup(params->passphrase); |
| 7083 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 7084 | if (go_bssid) { |
Matthew Wang | dcf1945 | 2022-11-07 20:42:52 -0800 | [diff] [blame] | 7085 | ssid->bssid_set = 1; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 7086 | os_memcpy(ssid->bssid, go_bssid, ETH_ALEN); |
Matthew Wang | dcf1945 | 2022-11-07 20:42:52 -0800 | [diff] [blame] | 7087 | } |
| 7088 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7089 | wpa_s->show_group_started = 1; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7090 | wpa_s->p2p_in_invitation = 1; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 7091 | wpa_s->p2p_retry_limit = retry_limit; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7092 | wpa_s->p2p_invite_go_freq = freq; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7093 | wpa_s->p2p_go_group_formation_completed = 0; |
| 7094 | wpa_s->global->p2p_group_formation = wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7095 | |
Matthew Wang | 9ae940b | 2022-09-14 21:25:34 -0700 | [diff] [blame] | 7096 | /* |
| 7097 | * Get latest scan results from driver in case cached scan results from |
| 7098 | * interfaces on the same wiphy allow us to skip the next scan by fast |
| 7099 | * associating. Also update the scan time to the most recent scan result |
| 7100 | * fetch time on the same radio so it reflects the actual time the last |
| 7101 | * scan result event occurred. |
| 7102 | */ |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7103 | wpa_supplicant_update_scan_results(wpa_s, go_bssid); |
Matthew Wang | 9ae940b | 2022-09-14 21:25:34 -0700 | [diff] [blame] | 7104 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 7105 | radio_list) { |
| 7106 | if (ifs == wpa_s) |
| 7107 | continue; |
| 7108 | if (!other_iface_found || os_reltime_before(&wpa_s->last_scan, |
| 7109 | &ifs->last_scan)) { |
| 7110 | other_iface_found = 1; |
| 7111 | wpa_s->last_scan.sec = ifs->last_scan.sec; |
| 7112 | wpa_s->last_scan.usec = ifs->last_scan.usec; |
| 7113 | } |
| 7114 | } |
| 7115 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7116 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->p2pdev, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7117 | NULL); |
| 7118 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, |
| 7119 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7120 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 7121 | wpa_supplicant_select_network(wpa_s, ssid); |
| 7122 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7123 | return 0; |
| 7124 | } |
| 7125 | |
| 7126 | |
| 7127 | int wpas_p2p_group_add_persistent(struct wpa_supplicant *wpa_s, |
| 7128 | struct wpa_ssid *ssid, int addr_allocated, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7129 | int force_freq, int neg_freq, |
| 7130 | int vht_center_freq2, int ht40, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7131 | int vht, int max_oper_chwidth, int he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7132 | int edmg, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7133 | const struct p2p_channels *channels, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7134 | int connection_timeout, int force_scan, |
Matthew Wang | 124e5f4 | 2022-12-29 07:23:06 +0000 | [diff] [blame] | 7135 | bool allow_6ghz, int retry_limit, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 7136 | const u8 *go_bssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7137 | { |
| 7138 | struct p2p_go_neg_results params; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 7139 | int go = 0, freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7140 | |
| 7141 | if (ssid->disabled != 2 || ssid->ssid == NULL) |
| 7142 | return -1; |
| 7143 | |
| 7144 | if (wpas_get_p2p_group(wpa_s, ssid->ssid, ssid->ssid_len, &go) && |
| 7145 | go == (ssid->mode == WPAS_MODE_P2P_GO)) { |
| 7146 | wpa_printf(MSG_DEBUG, "P2P: Requested persistent group is " |
| 7147 | "already running"); |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 7148 | if (go == 0 && |
| 7149 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7150 | wpa_s->p2pdev, NULL)) { |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 7151 | /* |
| 7152 | * This can happen if Invitation Response frame was lost |
| 7153 | * and the peer (GO of a persistent group) tries to |
| 7154 | * invite us again. Reschedule the timeout to avoid |
| 7155 | * terminating the wait for the connection too early |
| 7156 | * since we now know that the peer is still trying to |
| 7157 | * invite us instead of having already started the GO. |
| 7158 | */ |
| 7159 | wpa_printf(MSG_DEBUG, |
| 7160 | "P2P: Reschedule group formation timeout since peer is still trying to invite us"); |
| 7161 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, |
| 7162 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7163 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 7164 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7165 | return 0; |
| 7166 | } |
| 7167 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 7168 | os_free(wpa_s->global->add_psk); |
| 7169 | wpa_s->global->add_psk = NULL; |
| 7170 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7171 | /* Make sure we are not running find during connection establishment */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7172 | wpas_p2p_stop_find_oper(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7173 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7174 | wpa_s->p2p_fallback_to_go_neg = 0; |
| 7175 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7176 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 7177 | if (force_freq > 0) { |
| 7178 | freq = wpas_p2p_select_go_freq(wpa_s, force_freq); |
| 7179 | if (freq < 0) |
| 7180 | return -1; |
Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 7181 | wpa_s->p2p_go_no_pri_sec_switch = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7182 | } else { |
| 7183 | freq = wpas_p2p_select_go_freq(wpa_s, neg_freq); |
| 7184 | if (freq < 0 || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7185 | (freq > 0 && !freq_included(wpa_s, channels, freq))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7186 | freq = 0; |
| 7187 | } |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7188 | } else if (ssid->mode == WPAS_MODE_INFRA) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7189 | freq = neg_freq; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7190 | if (freq <= 0 || !freq_included(wpa_s, channels, freq)) { |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7191 | struct os_reltime now; |
| 7192 | struct wpa_bss *bss = |
| 7193 | wpa_bss_get_p2p_dev_addr(wpa_s, ssid->bssid); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7194 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7195 | os_get_reltime(&now); |
| 7196 | if (bss && |
| 7197 | !os_reltime_expired(&now, &bss->last_update, 5) && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7198 | freq_included(wpa_s, channels, bss->freq)) |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7199 | freq = bss->freq; |
| 7200 | else |
| 7201 | freq = 0; |
| 7202 | } |
| 7203 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7204 | return wpas_start_p2p_client(wpa_s, ssid, addr_allocated, freq, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 7205 | force_scan, retry_limit, go_bssid); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7206 | } else { |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7207 | return -1; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7208 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7209 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7210 | 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] | 7211 | ht40, vht, max_oper_chwidth, he, edmg, |
| 7212 | channels)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7213 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7214 | |
| 7215 | params.role_go = 1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7216 | params.psk_set = ssid->psk_set; |
| 7217 | if (params.psk_set) |
| 7218 | os_memcpy(params.psk, ssid->psk, sizeof(params.psk)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7219 | if (ssid->passphrase) { |
| 7220 | if (os_strlen(ssid->passphrase) >= sizeof(params.passphrase)) { |
| 7221 | wpa_printf(MSG_ERROR, "P2P: Invalid passphrase in " |
| 7222 | "persistent group"); |
| 7223 | return -1; |
| 7224 | } |
| 7225 | os_strlcpy(params.passphrase, ssid->passphrase, |
| 7226 | sizeof(params.passphrase)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7227 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7228 | os_memcpy(params.ssid, ssid->ssid, ssid->ssid_len); |
| 7229 | params.ssid_len = ssid->ssid_len; |
| 7230 | params.persistent_group = 1; |
| 7231 | |
| 7232 | wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 1); |
| 7233 | if (wpa_s == NULL) |
| 7234 | return -1; |
| 7235 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7236 | p2p_channels_to_freqs(channels, params.freq_list, P2P_MAX_CHANNELS); |
| 7237 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7238 | wpa_s->p2p_first_connection_timeout = connection_timeout; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7239 | wpas_start_wps_go(wpa_s, ¶ms, 0); |
| 7240 | |
| 7241 | return 0; |
| 7242 | } |
| 7243 | |
| 7244 | |
| 7245 | static void wpas_p2p_ie_update(void *ctx, struct wpabuf *beacon_ies, |
| 7246 | struct wpabuf *proberesp_ies) |
| 7247 | { |
| 7248 | struct wpa_supplicant *wpa_s = ctx; |
| 7249 | if (wpa_s->ap_iface) { |
| 7250 | struct hostapd_data *hapd = wpa_s->ap_iface->bss[0]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7251 | if (!(hapd->conf->p2p & P2P_GROUP_OWNER)) { |
| 7252 | wpabuf_free(beacon_ies); |
| 7253 | wpabuf_free(proberesp_ies); |
| 7254 | return; |
| 7255 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7256 | if (beacon_ies) { |
| 7257 | wpabuf_free(hapd->p2p_beacon_ie); |
| 7258 | hapd->p2p_beacon_ie = beacon_ies; |
| 7259 | } |
| 7260 | wpabuf_free(hapd->p2p_probe_resp_ie); |
| 7261 | hapd->p2p_probe_resp_ie = proberesp_ies; |
| 7262 | } else { |
| 7263 | wpabuf_free(beacon_ies); |
| 7264 | wpabuf_free(proberesp_ies); |
| 7265 | } |
| 7266 | wpa_supplicant_ap_update_beacon(wpa_s); |
| 7267 | } |
| 7268 | |
| 7269 | |
| 7270 | static void wpas_p2p_idle_update(void *ctx, int idle) |
| 7271 | { |
| 7272 | struct wpa_supplicant *wpa_s = ctx; |
| 7273 | if (!wpa_s->ap_iface) |
| 7274 | return; |
| 7275 | wpa_printf(MSG_DEBUG, "P2P: GO - group %sidle", idle ? "" : "not "); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7276 | if (idle) { |
| 7277 | if (wpa_s->global->p2p_fail_on_wps_complete && |
| 7278 | wpa_s->p2p_in_provisioning) { |
| 7279 | wpas_p2p_grpform_fail_after_wps(wpa_s); |
| 7280 | return; |
| 7281 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7282 | wpas_p2p_set_group_idle_timeout(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7283 | } else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7284 | eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL); |
| 7285 | } |
| 7286 | |
| 7287 | |
| 7288 | struct p2p_group * wpas_p2p_group_init(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7289 | struct wpa_ssid *ssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7290 | { |
| 7291 | struct p2p_group *group; |
| 7292 | struct p2p_group_config *cfg; |
| 7293 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 7294 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL || |
| 7295 | !ssid->p2p_group) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7296 | return NULL; |
| 7297 | |
| 7298 | cfg = os_zalloc(sizeof(*cfg)); |
| 7299 | if (cfg == NULL) |
| 7300 | return NULL; |
| 7301 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7302 | if (ssid->p2p_persistent_group && wpa_s->conf->persistent_reconnect) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7303 | cfg->persistent_group = 2; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7304 | else if (ssid->p2p_persistent_group) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7305 | cfg->persistent_group = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7306 | os_memcpy(cfg->interface_addr, wpa_s->own_addr, ETH_ALEN); |
| 7307 | if (wpa_s->max_stations && |
| 7308 | wpa_s->max_stations < wpa_s->conf->max_num_sta) |
| 7309 | cfg->max_clients = wpa_s->max_stations; |
| 7310 | else |
| 7311 | cfg->max_clients = wpa_s->conf->max_num_sta; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7312 | os_memcpy(cfg->ssid, ssid->ssid, ssid->ssid_len); |
| 7313 | cfg->ssid_len = ssid->ssid_len; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7314 | cfg->freq = ssid->frequency; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7315 | cfg->cb_ctx = wpa_s; |
| 7316 | cfg->ie_update = wpas_p2p_ie_update; |
| 7317 | cfg->idle_update = wpas_p2p_idle_update; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7318 | cfg->ip_addr_alloc = WPA_GET_BE32(wpa_s->p2pdev->conf->ip_addr_start) |
| 7319 | != 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7320 | |
| 7321 | group = p2p_group_init(wpa_s->global->p2p, cfg); |
| 7322 | if (group == NULL) |
| 7323 | os_free(cfg); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7324 | if (ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7325 | p2p_group_notif_formation_done(group); |
| 7326 | wpa_s->p2p_group = group; |
| 7327 | return group; |
| 7328 | } |
| 7329 | |
| 7330 | |
| 7331 | void wpas_p2p_wps_success(struct wpa_supplicant *wpa_s, const u8 *peer_addr, |
| 7332 | int registrar) |
| 7333 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7334 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 7335 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7336 | if (!wpa_s->p2p_in_provisioning) { |
| 7337 | wpa_printf(MSG_DEBUG, "P2P: Ignore WPS success event - P2P " |
| 7338 | "provisioning not in progress"); |
| 7339 | return; |
| 7340 | } |
| 7341 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7342 | if (ssid && ssid->mode == WPAS_MODE_INFRA) { |
| 7343 | u8 go_dev_addr[ETH_ALEN]; |
| 7344 | os_memcpy(go_dev_addr, wpa_s->bssid, ETH_ALEN); |
| 7345 | wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid, |
| 7346 | ssid->ssid_len); |
| 7347 | /* Clear any stored provisioning info */ |
| 7348 | p2p_clear_provisioning_info(wpa_s->global->p2p, go_dev_addr); |
| 7349 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7350 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7351 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->p2pdev, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7352 | NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7353 | wpa_s->p2p_go_group_formation_completed = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7354 | if (ssid && ssid->mode == WPAS_MODE_INFRA) { |
| 7355 | /* |
| 7356 | * Use a separate timeout for initial data connection to |
| 7357 | * complete to allow the group to be removed automatically if |
| 7358 | * something goes wrong in this step before the P2P group idle |
| 7359 | * timeout mechanism is taken into use. |
| 7360 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7361 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 7362 | "P2P: Re-start group formation timeout (%d seconds) as client for initial connection", |
| 7363 | P2P_MAX_INITIAL_CONN_WAIT); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7364 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, |
| 7365 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7366 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7367 | /* Complete group formation on successful data connection. */ |
| 7368 | wpa_s->p2p_go_group_formation_completed = 0; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7369 | } else if (ssid) { |
| 7370 | /* |
| 7371 | * Use a separate timeout for initial data connection to |
| 7372 | * complete to allow the group to be removed automatically if |
| 7373 | * the client does not complete data connection successfully. |
| 7374 | */ |
| 7375 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 7376 | "P2P: Re-start group formation timeout (%d seconds) as GO for initial connection", |
| 7377 | P2P_MAX_INITIAL_CONN_WAIT_GO); |
| 7378 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT_GO, 0, |
| 7379 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7380 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7381 | /* |
| 7382 | * Complete group formation on first successful data connection |
| 7383 | */ |
| 7384 | wpa_s->p2p_go_group_formation_completed = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7385 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7386 | if (wpa_s->global->p2p) |
| 7387 | p2p_wps_success_cb(wpa_s->global->p2p, peer_addr); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 7388 | wpas_group_formation_completed(wpa_s, 1, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7389 | } |
| 7390 | |
| 7391 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7392 | void wpas_p2p_wps_failed(struct wpa_supplicant *wpa_s, |
| 7393 | struct wps_event_fail *fail) |
| 7394 | { |
| 7395 | if (!wpa_s->p2p_in_provisioning) { |
| 7396 | wpa_printf(MSG_DEBUG, "P2P: Ignore WPS fail event - P2P " |
| 7397 | "provisioning not in progress"); |
| 7398 | return; |
| 7399 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7400 | |
| 7401 | if (wpa_s->go_params) { |
| 7402 | p2p_clear_provisioning_info( |
| 7403 | wpa_s->global->p2p, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7404 | wpa_s->go_params->peer_device_addr); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7405 | } |
| 7406 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7407 | wpas_notify_p2p_wps_failed(wpa_s, fail); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7408 | |
| 7409 | if (wpa_s == wpa_s->global->p2p_group_formation) { |
| 7410 | /* |
| 7411 | * Allow some time for the failed WPS negotiation exchange to |
| 7412 | * complete, but remove the group since group formation cannot |
| 7413 | * succeed after provisioning failure. |
| 7414 | */ |
| 7415 | wpa_printf(MSG_DEBUG, "P2P: WPS step failed during group formation - reject connection from timeout"); |
| 7416 | wpa_s->global->p2p_fail_on_wps_complete = 1; |
| 7417 | eloop_deplete_timeout(0, 50000, |
| 7418 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7419 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7420 | } |
| 7421 | } |
| 7422 | |
| 7423 | |
| 7424 | int wpas_p2p_wps_eapol_cb(struct wpa_supplicant *wpa_s) |
| 7425 | { |
| 7426 | if (!wpa_s->global->p2p_fail_on_wps_complete || |
| 7427 | !wpa_s->p2p_in_provisioning) |
| 7428 | return 0; |
| 7429 | |
| 7430 | wpas_p2p_grpform_fail_after_wps(wpa_s); |
| 7431 | |
| 7432 | return 1; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7433 | } |
| 7434 | |
| 7435 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7436 | 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] | 7437 | const char *config_method, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7438 | enum wpas_p2p_prov_disc_use use, |
| 7439 | struct p2ps_provision *p2ps_prov) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7440 | { |
| 7441 | u16 config_methods; |
| 7442 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7443 | wpa_s->global->pending_p2ps_group = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7444 | wpa_s->global->pending_p2ps_group_freq = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7445 | wpa_s->p2p_fallback_to_go_neg = 0; |
| 7446 | wpa_s->pending_pd_use = NORMAL_PD; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7447 | if (p2ps_prov && use == WPAS_P2P_PD_FOR_ASP) { |
| 7448 | p2ps_prov->conncap = p2ps_group_capability( |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7449 | wpa_s, P2PS_SETUP_NONE, p2ps_prov->role, |
| 7450 | &p2ps_prov->force_freq, &p2ps_prov->pref_freq); |
| 7451 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7452 | wpa_printf(MSG_DEBUG, |
| 7453 | "P2P: %s conncap: %d - ASP parsed: %x %x %d %s", |
| 7454 | __func__, p2ps_prov->conncap, |
| 7455 | p2ps_prov->adv_id, p2ps_prov->conncap, |
| 7456 | p2ps_prov->status, p2ps_prov->info); |
| 7457 | |
| 7458 | config_methods = 0; |
| 7459 | } else if (os_strncmp(config_method, "display", 7) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7460 | config_methods = WPS_CONFIG_DISPLAY; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7461 | else if (os_strncmp(config_method, "keypad", 6) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7462 | config_methods = WPS_CONFIG_KEYPAD; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7463 | else if (os_strncmp(config_method, "pbc", 3) == 0 || |
| 7464 | os_strncmp(config_method, "pushbutton", 10) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7465 | config_methods = WPS_CONFIG_PUSHBUTTON; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7466 | else { |
| 7467 | wpa_printf(MSG_DEBUG, "P2P: Unknown config method"); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7468 | os_free(p2ps_prov); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7469 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7470 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7471 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7472 | if (use == WPAS_P2P_PD_AUTO) { |
| 7473 | os_memcpy(wpa_s->pending_join_dev_addr, peer_addr, ETH_ALEN); |
| 7474 | wpa_s->pending_pd_config_methods = config_methods; |
| 7475 | wpa_s->p2p_auto_pd = 1; |
| 7476 | wpa_s->p2p_auto_join = 0; |
| 7477 | wpa_s->pending_pd_before_join = 0; |
| 7478 | wpa_s->auto_pd_scan_retry = 0; |
| 7479 | wpas_p2p_stop_find(wpa_s); |
| 7480 | wpa_s->p2p_join_scan_count = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7481 | os_get_reltime(&wpa_s->p2p_auto_started); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7482 | wpa_printf(MSG_DEBUG, "P2P: Auto PD started at %ld.%06ld", |
| 7483 | wpa_s->p2p_auto_started.sec, |
| 7484 | wpa_s->p2p_auto_started.usec); |
| 7485 | wpas_p2p_join_scan(wpa_s, NULL); |
| 7486 | return 0; |
| 7487 | } |
| 7488 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7489 | if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) { |
| 7490 | os_free(p2ps_prov); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7491 | return -1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7492 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7493 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7494 | 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] | 7495 | config_methods, use == WPAS_P2P_PD_FOR_JOIN, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7496 | 0, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7497 | } |
| 7498 | |
| 7499 | |
| 7500 | int wpas_p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf, |
| 7501 | char *end) |
| 7502 | { |
| 7503 | return p2p_scan_result_text(ies, ies_len, buf, end); |
| 7504 | } |
| 7505 | |
| 7506 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7507 | static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant *wpa_s, |
| 7508 | bool force) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7509 | { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7510 | if (!offchannel_pending_action_tx(wpa_s) && !force) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7511 | return; |
| 7512 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 7513 | if (wpa_s->p2p_send_action_work) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7514 | wpas_p2p_free_send_action_work(wpa_s); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 7515 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 7516 | wpa_s, NULL); |
| 7517 | offchannel_send_action_done(wpa_s); |
| 7518 | } |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 7519 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7520 | if (!offchannel_pending_action_tx(wpa_s)) |
| 7521 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7522 | wpa_printf(MSG_DEBUG, "P2P: Drop pending Action TX due to new " |
| 7523 | "operation request"); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7524 | offchannel_clear_pending_action_tx(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7525 | } |
| 7526 | |
| 7527 | |
| 7528 | int wpas_p2p_find(struct wpa_supplicant *wpa_s, unsigned int timeout, |
| 7529 | enum p2p_discovery_type type, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7530 | unsigned int num_req_dev_types, const u8 *req_dev_types, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7531 | const u8 *dev_id, unsigned int search_delay, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7532 | u8 seek_cnt, const char **seek_string, int freq, |
| 7533 | bool include_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7534 | { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7535 | wpas_p2p_clear_pending_action_tx(wpa_s, false); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7536 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7537 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7538 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7539 | wpa_s->p2p_in_provisioning) { |
| 7540 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Reject p2p_find operation%s%s", |
| 7541 | (wpa_s->global->p2p_disabled || !wpa_s->global->p2p) ? |
| 7542 | " (P2P disabled)" : "", |
| 7543 | wpa_s->p2p_in_provisioning ? |
| 7544 | " (p2p_in_provisioning)" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7545 | return -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7546 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7547 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7548 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 7549 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7550 | return p2p_find(wpa_s->global->p2p, timeout, type, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7551 | num_req_dev_types, req_dev_types, dev_id, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7552 | search_delay, seek_cnt, seek_string, freq, |
| 7553 | include_6ghz); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7554 | } |
| 7555 | |
| 7556 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7557 | static void wpas_p2p_scan_res_ignore_search(struct wpa_supplicant *wpa_s, |
| 7558 | struct wpa_scan_results *scan_res) |
| 7559 | { |
| 7560 | wpa_printf(MSG_DEBUG, "P2P: Ignore scan results"); |
| 7561 | |
| 7562 | if (wpa_s->p2p_scan_work) { |
| 7563 | struct wpa_radio_work *work = wpa_s->p2p_scan_work; |
| 7564 | wpa_s->p2p_scan_work = NULL; |
| 7565 | radio_work_done(work); |
| 7566 | } |
| 7567 | |
| 7568 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7569 | return; |
| 7570 | |
| 7571 | /* |
| 7572 | * Indicate that results have been processed so that the P2P module can |
| 7573 | * continue pending tasks. |
| 7574 | */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 7575 | wpas_p2p_scan_res_handled(wpa_s); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7576 | } |
| 7577 | |
| 7578 | |
| 7579 | static void wpas_p2p_stop_find_oper(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7580 | { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7581 | wpas_p2p_clear_pending_action_tx(wpa_s, true); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7582 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7583 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
| 7584 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7585 | |
| 7586 | if (wpa_s->global->p2p) |
| 7587 | p2p_stop_find(wpa_s->global->p2p); |
| 7588 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7589 | if (wpa_s->scan_res_handler == wpas_p2p_scan_res_handler) { |
| 7590 | wpa_printf(MSG_DEBUG, |
| 7591 | "P2P: Do not consider the scan results after stop_find"); |
| 7592 | wpa_s->scan_res_handler = wpas_p2p_scan_res_ignore_search; |
| 7593 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7594 | } |
| 7595 | |
| 7596 | |
| 7597 | void wpas_p2p_stop_find(struct wpa_supplicant *wpa_s) |
| 7598 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7599 | wpas_p2p_stop_find_oper(wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7600 | if (!wpa_s->global->pending_group_iface_for_p2ps) |
| 7601 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7602 | } |
| 7603 | |
| 7604 | |
| 7605 | static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx) |
| 7606 | { |
| 7607 | struct wpa_supplicant *wpa_s = eloop_ctx; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7608 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7609 | } |
| 7610 | |
| 7611 | |
| 7612 | int wpas_p2p_listen(struct wpa_supplicant *wpa_s, unsigned int timeout) |
| 7613 | { |
| 7614 | int res; |
| 7615 | |
| 7616 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7617 | return -1; |
| 7618 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 7619 | if (wpa_s->p2p_lo_started) { |
| 7620 | wpa_printf(MSG_DEBUG, |
| 7621 | "P2P: Cannot start P2P listen, it is offloaded"); |
| 7622 | return -1; |
| 7623 | } |
| 7624 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7625 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7626 | wpas_p2p_clear_pending_action_tx(wpa_s, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7627 | |
| 7628 | if (timeout == 0) { |
| 7629 | /* |
| 7630 | * This is a request for unlimited Listen state. However, at |
| 7631 | * least for now, this is mapped to a Listen state for one |
| 7632 | * hour. |
| 7633 | */ |
| 7634 | timeout = 3600; |
| 7635 | } |
| 7636 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7637 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7638 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7639 | /* |
| 7640 | * Stop previous find/listen operation to avoid trying to request a new |
| 7641 | * remain-on-channel operation while the driver is still running the |
| 7642 | * previous one. |
| 7643 | */ |
| 7644 | if (wpa_s->global->p2p) |
| 7645 | p2p_stop_find(wpa_s->global->p2p); |
| 7646 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7647 | res = wpas_p2p_listen_start(wpa_s, timeout * 1000); |
| 7648 | if (res == 0 && timeout * 1000 > wpa_s->max_remain_on_chan) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7649 | wpa_s->global->p2p_long_listen = timeout * 1000; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7650 | eloop_register_timeout(timeout, 0, |
| 7651 | wpas_p2p_long_listen_timeout, |
| 7652 | wpa_s, NULL); |
| 7653 | } |
| 7654 | |
| 7655 | return res; |
| 7656 | } |
| 7657 | |
| 7658 | |
| 7659 | int wpas_p2p_assoc_req_ie(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
| 7660 | u8 *buf, size_t len, int p2p_group) |
| 7661 | { |
| 7662 | struct wpabuf *p2p_ie; |
| 7663 | int ret; |
| 7664 | |
| 7665 | if (wpa_s->global->p2p_disabled) |
| 7666 | return -1; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 7667 | /* |
| 7668 | * Advertize mandatory cross connection capability even on |
| 7669 | * p2p_disabled=1 interface when associating with a P2P Manager WLAN AP. |
| 7670 | */ |
| 7671 | if (wpa_s->conf->p2p_disabled && p2p_group) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7672 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7673 | if (wpa_s->global->p2p == NULL) |
| 7674 | return -1; |
| 7675 | if (bss == NULL) |
| 7676 | return -1; |
| 7677 | |
| 7678 | p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE); |
| 7679 | ret = p2p_assoc_req_ie(wpa_s->global->p2p, bss->bssid, buf, len, |
| 7680 | p2p_group, p2p_ie); |
| 7681 | wpabuf_free(p2p_ie); |
| 7682 | |
| 7683 | return ret; |
| 7684 | } |
| 7685 | |
| 7686 | |
| 7687 | 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] | 7688 | const u8 *dst, const u8 *bssid, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 7689 | const u8 *ie, size_t ie_len, |
| 7690 | unsigned int rx_freq, int ssi_signal) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7691 | { |
| 7692 | if (wpa_s->global->p2p_disabled) |
| 7693 | return 0; |
| 7694 | if (wpa_s->global->p2p == NULL) |
| 7695 | return 0; |
| 7696 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7697 | switch (p2p_probe_req_rx(wpa_s->global->p2p, addr, dst, bssid, |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 7698 | ie, ie_len, rx_freq, wpa_s->p2p_lo_started)) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7699 | case P2P_PREQ_NOT_P2P: |
| 7700 | wpas_notify_preq(wpa_s, addr, dst, bssid, ie, ie_len, |
| 7701 | ssi_signal); |
| 7702 | /* fall through */ |
| 7703 | case P2P_PREQ_MALFORMED: |
| 7704 | case P2P_PREQ_NOT_LISTEN: |
| 7705 | case P2P_PREQ_NOT_PROCESSED: |
| 7706 | default: /* make gcc happy */ |
| 7707 | return 0; |
| 7708 | case P2P_PREQ_PROCESSED: |
| 7709 | return 1; |
| 7710 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7711 | } |
| 7712 | |
| 7713 | |
| 7714 | void wpas_p2p_rx_action(struct wpa_supplicant *wpa_s, const u8 *da, |
| 7715 | const u8 *sa, const u8 *bssid, |
| 7716 | u8 category, const u8 *data, size_t len, int freq) |
| 7717 | { |
| 7718 | if (wpa_s->global->p2p_disabled) |
| 7719 | return; |
| 7720 | if (wpa_s->global->p2p == NULL) |
| 7721 | return; |
| 7722 | |
| 7723 | p2p_rx_action(wpa_s->global->p2p, da, sa, bssid, category, data, len, |
| 7724 | freq); |
| 7725 | } |
| 7726 | |
| 7727 | |
| 7728 | void wpas_p2p_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ies) |
| 7729 | { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7730 | unsigned int bands; |
| 7731 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7732 | if (wpa_s->global->p2p_disabled) |
| 7733 | return; |
| 7734 | if (wpa_s->global->p2p == NULL) |
| 7735 | return; |
| 7736 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7737 | bands = wpas_get_bands(wpa_s, NULL); |
| 7738 | p2p_scan_ie(wpa_s->global->p2p, ies, NULL, bands); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7739 | } |
| 7740 | |
| 7741 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7742 | static void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7743 | { |
| 7744 | p2p_group_deinit(wpa_s->p2p_group); |
| 7745 | wpa_s->p2p_group = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7746 | |
| 7747 | wpa_s->ap_configured_cb = NULL; |
| 7748 | wpa_s->ap_configured_cb_ctx = NULL; |
| 7749 | wpa_s->ap_configured_cb_data = NULL; |
| 7750 | wpa_s->connect_without_scan = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7751 | } |
| 7752 | |
| 7753 | |
| 7754 | int wpas_p2p_reject(struct wpa_supplicant *wpa_s, const u8 *addr) |
| 7755 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7756 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7757 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7758 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7759 | return -1; |
| 7760 | |
| 7761 | return p2p_reject(wpa_s->global->p2p, addr); |
| 7762 | } |
| 7763 | |
| 7764 | |
| 7765 | /* Invite to reinvoke a persistent group */ |
| 7766 | 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] | 7767 | struct wpa_ssid *ssid, const u8 *go_dev_addr, int freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7768 | int vht_center_freq2, int ht40, int vht, int max_chwidth, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7769 | int pref_freq, int he, int edmg, bool allow_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7770 | { |
| 7771 | enum p2p_invite_role role; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7772 | u8 *bssid = NULL; |
| 7773 | int force_freq = 0; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7774 | int res; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 7775 | int no_pref_freq_given = pref_freq == 0; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 7776 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 7777 | unsigned int size; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7778 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7779 | if (wpas_p2p_check_6ghz(wpa_s, NULL, allow_6ghz, freq)) |
| 7780 | return -1; |
| 7781 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7782 | wpa_s->global->p2p_invite_group = NULL; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7783 | if (peer_addr) |
| 7784 | os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN); |
| 7785 | else |
| 7786 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7787 | |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 7788 | wpa_s->p2p_persistent_go_freq = freq; |
| 7789 | wpa_s->p2p_go_ht40 = !!ht40; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7790 | wpa_s->p2p_go_vht = !!vht; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7791 | wpa_s->p2p_go_he = !!he; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7792 | wpa_s->p2p_go_max_oper_chwidth = max_chwidth; |
| 7793 | wpa_s->p2p_go_vht_center_freq2 = vht_center_freq2; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7794 | wpa_s->p2p_go_edmg = !!edmg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7795 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 7796 | role = P2P_INVITE_ROLE_GO; |
| 7797 | if (peer_addr == NULL) { |
| 7798 | wpa_printf(MSG_DEBUG, "P2P: Missing peer " |
| 7799 | "address in invitation command"); |
| 7800 | return -1; |
| 7801 | } |
| 7802 | if (wpas_p2p_create_iface(wpa_s)) { |
| 7803 | if (wpas_p2p_add_group_interface(wpa_s, |
| 7804 | WPA_IF_P2P_GO) < 0) { |
| 7805 | wpa_printf(MSG_ERROR, "P2P: Failed to " |
| 7806 | "allocate a new interface for the " |
| 7807 | "group"); |
| 7808 | return -1; |
| 7809 | } |
| 7810 | bssid = wpa_s->pending_interface_addr; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7811 | } else if (wpa_s->p2p_mgmt) |
| 7812 | bssid = wpa_s->parent->own_addr; |
| 7813 | else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7814 | bssid = wpa_s->own_addr; |
| 7815 | } else { |
| 7816 | role = P2P_INVITE_ROLE_CLIENT; |
| 7817 | peer_addr = ssid->bssid; |
| 7818 | } |
| 7819 | wpa_s->pending_invite_ssid_id = ssid->id; |
| 7820 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7821 | size = P2P_MAX_PREF_CHANNELS; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7822 | res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7823 | role == P2P_INVITE_ROLE_GO, |
| 7824 | pref_freq_list, &size); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7825 | if (res) |
| 7826 | return res; |
Irfan Sheriff | af84a57 | 2012-09-22 16:59:30 -0700 | [diff] [blame] | 7827 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7828 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7829 | return -1; |
| 7830 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7831 | p2p_set_own_pref_freq_list(wpa_s->global->p2p, pref_freq_list, size); |
| 7832 | |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 7833 | if (wpa_s->parent->conf->p2p_ignore_shared_freq && |
| 7834 | no_pref_freq_given && pref_freq > 0 && |
| 7835 | wpa_s->num_multichan_concurrent > 1 && |
| 7836 | wpas_p2p_num_unused_channels(wpa_s) > 0) { |
| 7837 | wpa_printf(MSG_DEBUG, "P2P: Ignore own channel preference %d MHz for invitation due to p2p_ignore_shared_freq=1 configuration", |
| 7838 | pref_freq); |
| 7839 | pref_freq = 0; |
| 7840 | } |
| 7841 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7842 | /* |
| 7843 | * Stop any find/listen operations before invitation and possibly |
| 7844 | * connection establishment. |
| 7845 | */ |
| 7846 | wpas_p2p_stop_find_oper(wpa_s); |
| 7847 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7848 | return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid, |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7849 | ssid->ssid, ssid->ssid_len, force_freq, go_dev_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7850 | 1, pref_freq, -1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7851 | } |
| 7852 | |
| 7853 | |
| 7854 | /* Invite to join an active group */ |
| 7855 | 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] | 7856 | const u8 *peer_addr, const u8 *go_dev_addr, |
| 7857 | bool allow_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7858 | { |
| 7859 | struct wpa_global *global = wpa_s->global; |
| 7860 | enum p2p_invite_role role; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7861 | u8 *bssid = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7862 | struct wpa_ssid *ssid; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7863 | int persistent; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7864 | int freq = 0, force_freq = 0, pref_freq = 0; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7865 | int res; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 7866 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 7867 | unsigned int size; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7868 | |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 7869 | wpa_s->p2p_persistent_go_freq = 0; |
| 7870 | wpa_s->p2p_go_ht40 = 0; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7871 | wpa_s->p2p_go_vht = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7872 | wpa_s->p2p_go_vht_center_freq2 = 0; |
| 7873 | wpa_s->p2p_go_max_oper_chwidth = 0; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7874 | wpa_s->p2p_go_edmg = 0; |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 7875 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7876 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 7877 | if (os_strcmp(wpa_s->ifname, ifname) == 0) |
| 7878 | break; |
| 7879 | } |
| 7880 | if (wpa_s == NULL) { |
| 7881 | wpa_printf(MSG_DEBUG, "P2P: Interface '%s' not found", ifname); |
| 7882 | return -1; |
| 7883 | } |
| 7884 | |
| 7885 | ssid = wpa_s->current_ssid; |
| 7886 | if (ssid == NULL) { |
| 7887 | wpa_printf(MSG_DEBUG, "P2P: No current SSID to use for " |
| 7888 | "invitation"); |
| 7889 | return -1; |
| 7890 | } |
| 7891 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7892 | wpa_s->global->p2p_invite_group = wpa_s; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7893 | persistent = ssid->p2p_persistent_group && |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7894 | wpas_p2p_get_persistent(wpa_s->p2pdev, peer_addr, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7895 | ssid->ssid, ssid->ssid_len); |
| 7896 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7897 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 7898 | role = P2P_INVITE_ROLE_ACTIVE_GO; |
| 7899 | bssid = wpa_s->own_addr; |
| 7900 | if (go_dev_addr == NULL) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7901 | go_dev_addr = wpa_s->global->p2p_dev_addr; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7902 | freq = ssid->frequency; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7903 | } else { |
| 7904 | role = P2P_INVITE_ROLE_CLIENT; |
| 7905 | if (wpa_s->wpa_state < WPA_ASSOCIATED) { |
| 7906 | wpa_printf(MSG_DEBUG, "P2P: Not associated - cannot " |
| 7907 | "invite to current group"); |
| 7908 | return -1; |
| 7909 | } |
| 7910 | bssid = wpa_s->bssid; |
| 7911 | if (go_dev_addr == NULL && |
| 7912 | !is_zero_ether_addr(wpa_s->go_dev_addr)) |
| 7913 | go_dev_addr = wpa_s->go_dev_addr; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7914 | freq = wpa_s->current_bss ? wpa_s->current_bss->freq : |
| 7915 | (int) wpa_s->assoc_freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7916 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7917 | wpa_s->p2pdev->pending_invite_ssid_id = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7918 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7919 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7920 | return -1; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7921 | if (wpas_p2p_check_6ghz(wpa_s, peer_addr, allow_6ghz, freq)) |
| 7922 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7923 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7924 | size = P2P_MAX_PREF_CHANNELS; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7925 | res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7926 | role == P2P_INVITE_ROLE_ACTIVE_GO, |
| 7927 | pref_freq_list, &size); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7928 | if (res) |
| 7929 | return res; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7930 | wpas_p2p_set_own_freq_preference(wpa_s, force_freq); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7931 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7932 | return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid, |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7933 | ssid->ssid, ssid->ssid_len, force_freq, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7934 | go_dev_addr, persistent, pref_freq, -1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7935 | } |
| 7936 | |
| 7937 | |
| 7938 | void wpas_p2p_completed(struct wpa_supplicant *wpa_s) |
| 7939 | { |
| 7940 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7941 | u8 go_dev_addr[ETH_ALEN]; |
| 7942 | int persistent; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7943 | int freq; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 7944 | u8 ip[3 * 4], *ip_ptr = NULL; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7945 | char ip_addr[100]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7946 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7947 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION) { |
| 7948 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7949 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7950 | } |
| 7951 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7952 | if (!wpa_s->show_group_started || !ssid) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7953 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7954 | |
| 7955 | wpa_s->show_group_started = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7956 | if (!wpa_s->p2p_go_group_formation_completed && |
| 7957 | wpa_s->global->p2p_group_formation == wpa_s) { |
| 7958 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 7959 | "P2P: Marking group formation completed on client on data connection"); |
| 7960 | wpa_s->p2p_go_group_formation_completed = 1; |
| 7961 | wpa_s->global->p2p_group_formation = NULL; |
| 7962 | wpa_s->p2p_in_provisioning = 0; |
| 7963 | wpa_s->p2p_in_invitation = 0; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 7964 | wpa_s->p2p_retry_limit = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7965 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7966 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7967 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 7968 | if (ssid->bssid_set) |
| 7969 | os_memcpy(go_dev_addr, ssid->bssid, ETH_ALEN); |
| 7970 | persistent = wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid, |
| 7971 | ssid->ssid_len); |
| 7972 | os_memcpy(wpa_s->go_dev_addr, go_dev_addr, ETH_ALEN); |
| 7973 | |
| 7974 | if (wpa_s->global->p2p_group_formation == wpa_s) |
| 7975 | wpa_s->global->p2p_group_formation = NULL; |
| 7976 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7977 | freq = wpa_s->current_bss ? wpa_s->current_bss->freq : |
| 7978 | (int) wpa_s->assoc_freq; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7979 | |
| 7980 | ip_addr[0] = '\0'; |
| 7981 | if (wpa_sm_get_p2p_ip_addr(wpa_s->wpa, ip) == 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7982 | int res; |
| 7983 | |
| 7984 | res = os_snprintf(ip_addr, sizeof(ip_addr), |
| 7985 | " ip_addr=%u.%u.%u.%u " |
| 7986 | "ip_mask=%u.%u.%u.%u go_ip_addr=%u.%u.%u.%u", |
| 7987 | ip[0], ip[1], ip[2], ip[3], |
| 7988 | ip[4], ip[5], ip[6], ip[7], |
| 7989 | ip[8], ip[9], ip[10], ip[11]); |
| 7990 | if (os_snprintf_error(sizeof(ip_addr), res)) |
| 7991 | ip_addr[0] = '\0'; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 7992 | ip_ptr = ip; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7993 | } |
| 7994 | |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 7995 | wpas_p2p_group_started(wpa_s, 0, ssid, freq, |
| 7996 | ssid->passphrase == NULL && ssid->psk_set ? |
| 7997 | ssid->psk : NULL, |
| 7998 | ssid->passphrase, go_dev_addr, persistent, |
| 7999 | ip_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8000 | |
| 8001 | if (persistent) |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 8002 | wpas_p2p_store_persistent_group(wpa_s->p2pdev, |
| 8003 | ssid, go_dev_addr); |
| 8004 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 8005 | wpas_notify_p2p_group_started(wpa_s, ssid, persistent, 1, ip_ptr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8006 | } |
| 8007 | |
| 8008 | |
| 8009 | int wpas_p2p_presence_req(struct wpa_supplicant *wpa_s, u32 duration1, |
| 8010 | u32 interval1, u32 duration2, u32 interval2) |
| 8011 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8012 | int ret; |
| 8013 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8014 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8015 | return -1; |
| 8016 | |
| 8017 | if (wpa_s->wpa_state < WPA_ASSOCIATED || |
| 8018 | wpa_s->current_ssid == NULL || |
| 8019 | wpa_s->current_ssid->mode != WPAS_MODE_INFRA) |
| 8020 | return -1; |
| 8021 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8022 | ret = p2p_presence_req(wpa_s->global->p2p, wpa_s->bssid, |
| 8023 | wpa_s->own_addr, wpa_s->assoc_freq, |
| 8024 | duration1, interval1, duration2, interval2); |
| 8025 | if (ret == 0) |
| 8026 | wpa_s->waiting_presence_resp = 1; |
| 8027 | |
| 8028 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8029 | } |
| 8030 | |
| 8031 | |
| 8032 | int wpas_p2p_ext_listen(struct wpa_supplicant *wpa_s, unsigned int period, |
| 8033 | unsigned int interval) |
| 8034 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8035 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8036 | return -1; |
| 8037 | |
| 8038 | return p2p_ext_listen(wpa_s->global->p2p, period, interval); |
| 8039 | } |
| 8040 | |
| 8041 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8042 | static int wpas_p2p_is_client(struct wpa_supplicant *wpa_s) |
| 8043 | { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 8044 | if (wpa_s->current_ssid == NULL) { |
| 8045 | /* |
| 8046 | * current_ssid can be cleared when P2P client interface gets |
| 8047 | * disconnected, so assume this interface was used as P2P |
| 8048 | * client. |
| 8049 | */ |
| 8050 | return 1; |
| 8051 | } |
| 8052 | return wpa_s->current_ssid->p2p_group && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8053 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA; |
| 8054 | } |
| 8055 | |
| 8056 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8057 | static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx) |
| 8058 | { |
| 8059 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 8060 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8061 | 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] | 8062 | wpa_printf(MSG_DEBUG, "P2P: Ignore group idle timeout - " |
| 8063 | "disabled"); |
| 8064 | return; |
| 8065 | } |
| 8066 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8067 | wpa_printf(MSG_DEBUG, "P2P: Group idle timeout reached - terminate " |
| 8068 | "group"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8069 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_IDLE_TIMEOUT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8070 | } |
| 8071 | |
| 8072 | |
| 8073 | static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s) |
| 8074 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8075 | int timeout; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8076 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8077 | if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0) |
| 8078 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout"); |
| 8079 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8080 | if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group) |
| 8081 | return; |
| 8082 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8083 | timeout = wpa_s->conf->p2p_group_idle; |
| 8084 | if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA && |
| 8085 | (timeout == 0 || timeout > P2P_MAX_CLIENT_IDLE)) |
| 8086 | timeout = P2P_MAX_CLIENT_IDLE; |
| 8087 | |
| 8088 | if (timeout == 0) |
| 8089 | return; |
| 8090 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8091 | if (timeout < 0) { |
| 8092 | if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA) |
| 8093 | timeout = 0; /* special client mode no-timeout */ |
| 8094 | else |
| 8095 | return; |
| 8096 | } |
| 8097 | |
| 8098 | if (wpa_s->p2p_in_provisioning) { |
| 8099 | /* |
| 8100 | * Use the normal group formation timeout during the |
| 8101 | * provisioning phase to avoid terminating this process too |
| 8102 | * early due to group idle timeout. |
| 8103 | */ |
| 8104 | wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout " |
| 8105 | "during provisioning"); |
| 8106 | return; |
| 8107 | } |
Deepthi Gowri | 9e4e8ac | 2013-04-16 11:57:05 +0530 | [diff] [blame] | 8108 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8109 | if (wpa_s->show_group_started) { |
| 8110 | /* |
| 8111 | * Use the normal group formation timeout between the end of |
| 8112 | * the provisioning phase and completion of 4-way handshake to |
| 8113 | * avoid terminating this process too early due to group idle |
| 8114 | * timeout. |
| 8115 | */ |
| 8116 | wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout " |
| 8117 | "while waiting for initial 4-way handshake to " |
| 8118 | "complete"); |
| 8119 | return; |
| 8120 | } |
| 8121 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8122 | 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] | 8123 | timeout); |
| 8124 | eloop_register_timeout(timeout, 0, wpas_p2p_group_idle_timeout, |
| 8125 | wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8126 | } |
| 8127 | |
| 8128 | |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8129 | /* Returns 1 if the interface was removed */ |
| 8130 | int wpas_p2p_deauth_notif(struct wpa_supplicant *wpa_s, const u8 *bssid, |
| 8131 | u16 reason_code, const u8 *ie, size_t ie_len, |
| 8132 | int locally_generated) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8133 | { |
| 8134 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8135 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8136 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8137 | if (!locally_generated) |
| 8138 | p2p_deauth_notif(wpa_s->global->p2p, bssid, reason_code, ie, |
| 8139 | ie_len); |
| 8140 | |
| 8141 | if (reason_code == WLAN_REASON_DEAUTH_LEAVING && !locally_generated && |
| 8142 | wpa_s->current_ssid && |
| 8143 | wpa_s->current_ssid->p2p_group && |
| 8144 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA) { |
| 8145 | wpa_printf(MSG_DEBUG, "P2P: GO indicated that the P2P Group " |
| 8146 | "session is ending"); |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8147 | if (wpas_p2p_group_delete(wpa_s, |
| 8148 | P2P_GROUP_REMOVAL_GO_ENDING_SESSION) |
| 8149 | > 0) |
| 8150 | return 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8151 | } |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8152 | |
| 8153 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8154 | } |
| 8155 | |
| 8156 | |
| 8157 | 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] | 8158 | u16 reason_code, const u8 *ie, size_t ie_len, |
| 8159 | int locally_generated) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8160 | { |
| 8161 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8162 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8163 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8164 | if (!locally_generated) |
| 8165 | p2p_disassoc_notif(wpa_s->global->p2p, bssid, reason_code, ie, |
| 8166 | ie_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8167 | } |
| 8168 | |
| 8169 | |
| 8170 | void wpas_p2p_update_config(struct wpa_supplicant *wpa_s) |
| 8171 | { |
| 8172 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 8173 | |
| 8174 | if (p2p == NULL) |
| 8175 | return; |
| 8176 | |
| 8177 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE)) |
| 8178 | return; |
| 8179 | |
| 8180 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_NAME) |
| 8181 | p2p_set_dev_name(p2p, wpa_s->conf->device_name); |
| 8182 | |
| 8183 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_TYPE) |
| 8184 | p2p_set_pri_dev_type(p2p, wpa_s->conf->device_type); |
| 8185 | |
| 8186 | if (wpa_s->wps && |
| 8187 | (wpa_s->conf->changed_parameters & CFG_CHANGED_CONFIG_METHODS)) |
| 8188 | p2p_set_config_methods(p2p, wpa_s->wps->config_methods); |
| 8189 | |
| 8190 | if (wpa_s->wps && (wpa_s->conf->changed_parameters & CFG_CHANGED_UUID)) |
| 8191 | p2p_set_uuid(p2p, wpa_s->wps->uuid); |
| 8192 | |
| 8193 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_WPS_STRING) { |
| 8194 | p2p_set_manufacturer(p2p, wpa_s->conf->manufacturer); |
| 8195 | p2p_set_model_name(p2p, wpa_s->conf->model_name); |
| 8196 | p2p_set_model_number(p2p, wpa_s->conf->model_number); |
| 8197 | p2p_set_serial_number(p2p, wpa_s->conf->serial_number); |
| 8198 | } |
| 8199 | |
| 8200 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_SEC_DEVICE_TYPE) |
| 8201 | p2p_set_sec_dev_types(p2p, |
| 8202 | (void *) wpa_s->conf->sec_device_type, |
| 8203 | wpa_s->conf->num_sec_device_types); |
| 8204 | |
| 8205 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_VENDOR_EXTENSION) { |
| 8206 | int i; |
| 8207 | p2p_remove_wps_vendor_extensions(p2p); |
| 8208 | for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) { |
| 8209 | if (wpa_s->conf->wps_vendor_ext[i] == NULL) |
| 8210 | continue; |
| 8211 | p2p_add_wps_vendor_extension( |
| 8212 | p2p, wpa_s->conf->wps_vendor_ext[i]); |
| 8213 | } |
| 8214 | } |
| 8215 | |
| 8216 | if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) && |
| 8217 | wpa_s->conf->country[0] && wpa_s->conf->country[1]) { |
| 8218 | char country[3]; |
| 8219 | country[0] = wpa_s->conf->country[0]; |
| 8220 | country[1] = wpa_s->conf->country[1]; |
| 8221 | country[2] = 0x04; |
| 8222 | p2p_set_country(p2p, country); |
| 8223 | } |
| 8224 | |
| 8225 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_SSID_POSTFIX) { |
| 8226 | p2p_set_ssid_postfix(p2p, (u8 *) wpa_s->conf->p2p_ssid_postfix, |
| 8227 | wpa_s->conf->p2p_ssid_postfix ? |
| 8228 | os_strlen(wpa_s->conf->p2p_ssid_postfix) : |
| 8229 | 0); |
| 8230 | } |
| 8231 | |
| 8232 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_INTRA_BSS) |
| 8233 | p2p_set_intra_bss_dist(p2p, wpa_s->conf->p2p_intra_bss); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8234 | |
| 8235 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_LISTEN_CHANNEL) { |
| 8236 | u8 reg_class, channel; |
| 8237 | int ret; |
| 8238 | unsigned int r; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8239 | u8 channel_forced; |
| 8240 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8241 | if (wpa_s->conf->p2p_listen_reg_class && |
| 8242 | wpa_s->conf->p2p_listen_channel) { |
| 8243 | reg_class = wpa_s->conf->p2p_listen_reg_class; |
| 8244 | channel = wpa_s->conf->p2p_listen_channel; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8245 | channel_forced = 1; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8246 | } else { |
| 8247 | reg_class = 81; |
| 8248 | /* |
| 8249 | * Pick one of the social channels randomly as the |
| 8250 | * listen channel. |
| 8251 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8252 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 8253 | channel = 1; |
| 8254 | else |
| 8255 | channel = 1 + (r % 3) * 5; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8256 | channel_forced = 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8257 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8258 | ret = p2p_set_listen_channel(p2p, reg_class, channel, |
| 8259 | channel_forced); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8260 | if (ret) |
| 8261 | wpa_printf(MSG_ERROR, "P2P: Own listen channel update " |
| 8262 | "failed: %d", ret); |
| 8263 | } |
| 8264 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_OPER_CHANNEL) { |
| 8265 | u8 op_reg_class, op_channel, cfg_op_channel; |
| 8266 | int ret = 0; |
| 8267 | unsigned int r; |
| 8268 | if (wpa_s->conf->p2p_oper_reg_class && |
| 8269 | wpa_s->conf->p2p_oper_channel) { |
| 8270 | op_reg_class = wpa_s->conf->p2p_oper_reg_class; |
| 8271 | op_channel = wpa_s->conf->p2p_oper_channel; |
| 8272 | cfg_op_channel = 1; |
| 8273 | } else { |
| 8274 | op_reg_class = 81; |
| 8275 | /* |
| 8276 | * Use random operation channel from (1, 6, 11) |
| 8277 | *if no other preference is indicated. |
| 8278 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8279 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 8280 | op_channel = 1; |
| 8281 | else |
| 8282 | op_channel = 1 + (r % 3) * 5; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8283 | cfg_op_channel = 0; |
| 8284 | } |
| 8285 | ret = p2p_set_oper_channel(p2p, op_reg_class, op_channel, |
| 8286 | cfg_op_channel); |
| 8287 | if (ret) |
| 8288 | wpa_printf(MSG_ERROR, "P2P: Own oper channel update " |
| 8289 | "failed: %d", ret); |
| 8290 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8291 | |
| 8292 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PREF_CHAN) { |
| 8293 | if (p2p_set_pref_chan(p2p, wpa_s->conf->num_p2p_pref_chan, |
| 8294 | wpa_s->conf->p2p_pref_chan) < 0) { |
| 8295 | wpa_printf(MSG_ERROR, "P2P: Preferred channel list " |
| 8296 | "update failed"); |
| 8297 | } |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8298 | |
| 8299 | if (p2p_set_no_go_freq(p2p, &wpa_s->conf->p2p_no_go_freq) < 0) { |
| 8300 | wpa_printf(MSG_ERROR, "P2P: No GO channel list " |
| 8301 | "update failed"); |
| 8302 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8303 | } |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 8304 | |
| 8305 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PASSPHRASE_LEN) |
| 8306 | p2p_set_passphrase_len(p2p, wpa_s->conf->p2p_passphrase_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8307 | } |
| 8308 | |
| 8309 | |
| 8310 | int wpas_p2p_set_noa(struct wpa_supplicant *wpa_s, u8 count, int start, |
| 8311 | int duration) |
| 8312 | { |
| 8313 | if (!wpa_s->ap_iface) |
| 8314 | return -1; |
| 8315 | return hostapd_p2p_set_noa(wpa_s->ap_iface->bss[0], count, start, |
| 8316 | duration); |
| 8317 | } |
| 8318 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8319 | |
| 8320 | int wpas_p2p_set_cross_connect(struct wpa_supplicant *wpa_s, int enabled) |
| 8321 | { |
| 8322 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8323 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8324 | |
| 8325 | wpa_s->global->cross_connection = enabled; |
| 8326 | p2p_set_cross_connect(wpa_s->global->p2p, enabled); |
| 8327 | |
| 8328 | if (!enabled) { |
| 8329 | struct wpa_supplicant *iface; |
| 8330 | |
| 8331 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) |
| 8332 | { |
| 8333 | if (iface->cross_connect_enabled == 0) |
| 8334 | continue; |
| 8335 | |
| 8336 | iface->cross_connect_enabled = 0; |
| 8337 | iface->cross_connect_in_use = 0; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8338 | wpa_msg_global(iface->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8339 | P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s", |
| 8340 | iface->ifname, |
| 8341 | iface->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8342 | } |
| 8343 | } |
| 8344 | |
| 8345 | return 0; |
| 8346 | } |
| 8347 | |
| 8348 | |
| 8349 | static void wpas_p2p_enable_cross_connect(struct wpa_supplicant *uplink) |
| 8350 | { |
| 8351 | struct wpa_supplicant *iface; |
| 8352 | |
| 8353 | if (!uplink->global->cross_connection) |
| 8354 | return; |
| 8355 | |
| 8356 | for (iface = uplink->global->ifaces; iface; iface = iface->next) { |
| 8357 | if (!iface->cross_connect_enabled) |
| 8358 | continue; |
| 8359 | if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) != |
| 8360 | 0) |
| 8361 | continue; |
| 8362 | if (iface->ap_iface == NULL) |
| 8363 | continue; |
| 8364 | if (iface->cross_connect_in_use) |
| 8365 | continue; |
| 8366 | |
| 8367 | iface->cross_connect_in_use = 1; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8368 | wpa_msg_global(iface->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8369 | P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s", |
| 8370 | iface->ifname, iface->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8371 | } |
| 8372 | } |
| 8373 | |
| 8374 | |
| 8375 | static void wpas_p2p_disable_cross_connect(struct wpa_supplicant *uplink) |
| 8376 | { |
| 8377 | struct wpa_supplicant *iface; |
| 8378 | |
| 8379 | for (iface = uplink->global->ifaces; iface; iface = iface->next) { |
| 8380 | if (!iface->cross_connect_enabled) |
| 8381 | continue; |
| 8382 | if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) != |
| 8383 | 0) |
| 8384 | continue; |
| 8385 | if (!iface->cross_connect_in_use) |
| 8386 | continue; |
| 8387 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8388 | wpa_msg_global(iface->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8389 | P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s", |
| 8390 | iface->ifname, iface->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8391 | iface->cross_connect_in_use = 0; |
| 8392 | } |
| 8393 | } |
| 8394 | |
| 8395 | |
| 8396 | void wpas_p2p_notif_connected(struct wpa_supplicant *wpa_s) |
| 8397 | { |
| 8398 | if (wpa_s->ap_iface || wpa_s->current_ssid == NULL || |
| 8399 | wpa_s->current_ssid->mode != WPAS_MODE_INFRA || |
| 8400 | wpa_s->cross_connect_disallowed) |
| 8401 | wpas_p2p_disable_cross_connect(wpa_s); |
| 8402 | else |
| 8403 | wpas_p2p_enable_cross_connect(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8404 | if (!wpa_s->ap_iface && |
| 8405 | eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0) |
| 8406 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8407 | } |
| 8408 | |
| 8409 | |
| 8410 | void wpas_p2p_notif_disconnected(struct wpa_supplicant *wpa_s) |
| 8411 | { |
| 8412 | wpas_p2p_disable_cross_connect(wpa_s); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8413 | if (!wpa_s->ap_iface && |
| 8414 | !eloop_is_timeout_registered(wpas_p2p_group_idle_timeout, |
| 8415 | wpa_s, NULL)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8416 | wpas_p2p_set_group_idle_timeout(wpa_s); |
| 8417 | } |
| 8418 | |
| 8419 | |
| 8420 | static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s) |
| 8421 | { |
| 8422 | struct wpa_supplicant *iface; |
| 8423 | |
| 8424 | if (!wpa_s->global->cross_connection) |
| 8425 | return; |
| 8426 | |
| 8427 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 8428 | if (iface == wpa_s) |
| 8429 | continue; |
| 8430 | if (iface->drv_flags & |
| 8431 | WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE) |
| 8432 | continue; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8433 | if ((iface->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) && |
| 8434 | iface != wpa_s->parent) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8435 | continue; |
| 8436 | |
| 8437 | wpa_s->cross_connect_enabled = 1; |
| 8438 | os_strlcpy(wpa_s->cross_connect_uplink, iface->ifname, |
| 8439 | sizeof(wpa_s->cross_connect_uplink)); |
| 8440 | wpa_printf(MSG_DEBUG, "P2P: Enable cross connection from " |
| 8441 | "%s to %s whenever uplink is available", |
| 8442 | wpa_s->ifname, wpa_s->cross_connect_uplink); |
| 8443 | |
| 8444 | if (iface->ap_iface || iface->current_ssid == NULL || |
| 8445 | iface->current_ssid->mode != WPAS_MODE_INFRA || |
| 8446 | iface->cross_connect_disallowed || |
| 8447 | iface->wpa_state != WPA_COMPLETED) |
| 8448 | break; |
| 8449 | |
| 8450 | wpa_s->cross_connect_in_use = 1; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8451 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8452 | P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s", |
| 8453 | wpa_s->ifname, wpa_s->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8454 | break; |
| 8455 | } |
| 8456 | } |
| 8457 | |
| 8458 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 8459 | static int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8460 | { |
| 8461 | if (wpa_s->p2p_group_interface != P2P_GROUP_INTERFACE_CLIENT && |
| 8462 | !wpa_s->p2p_in_provisioning) |
| 8463 | return 0; /* not P2P client operation */ |
| 8464 | |
| 8465 | wpa_printf(MSG_DEBUG, "P2P: Terminate connection due to WPS PBC " |
| 8466 | "session overlap"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8467 | if (wpa_s != wpa_s->p2pdev) |
| 8468 | wpa_msg_ctrl(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_OVERLAP); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8469 | wpas_p2p_group_formation_failed(wpa_s, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8470 | return 1; |
| 8471 | } |
| 8472 | |
| 8473 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8474 | void wpas_p2p_pbc_overlap_cb(void *eloop_ctx, void *timeout_ctx) |
| 8475 | { |
| 8476 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 8477 | wpas_p2p_notif_pbc_overlap(wpa_s); |
| 8478 | } |
| 8479 | |
| 8480 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8481 | void wpas_p2p_update_channel_list(struct wpa_supplicant *wpa_s, |
| 8482 | enum wpas_p2p_channel_update_trig trig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8483 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8484 | struct p2p_channels chan, cli_chan; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8485 | struct wpa_used_freq_data *freqs = NULL; |
| 8486 | unsigned int num = wpa_s->num_multichan_concurrent; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8487 | |
| 8488 | if (wpa_s->global == NULL || wpa_s->global->p2p == NULL) |
| 8489 | return; |
| 8490 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8491 | freqs = os_calloc(num, sizeof(struct wpa_used_freq_data)); |
| 8492 | if (!freqs) |
| 8493 | return; |
| 8494 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 8495 | num = get_shared_radio_freqs_data(wpa_s, freqs, num, false); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8496 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8497 | os_memset(&chan, 0, sizeof(chan)); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8498 | os_memset(&cli_chan, 0, sizeof(cli_chan)); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8499 | if (wpas_p2p_setup_channels(wpa_s, &chan, &cli_chan, |
| 8500 | is_p2p_6ghz_disabled(wpa_s->global->p2p))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8501 | wpa_printf(MSG_ERROR, "P2P: Failed to update supported " |
| 8502 | "channel list"); |
| 8503 | return; |
| 8504 | } |
| 8505 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8506 | p2p_update_channel_list(wpa_s->global->p2p, &chan, &cli_chan); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 8507 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8508 | wpas_p2p_optimize_listen_channel(wpa_s, freqs, num); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 8509 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8510 | /* |
| 8511 | * The used frequencies map changed, so it is possible that a GO is |
| 8512 | * using a channel that is no longer valid for P2P use. It is also |
| 8513 | * possible that due to policy consideration, it would be preferable to |
| 8514 | * move it to a frequency already used by other station interfaces. |
| 8515 | */ |
| 8516 | wpas_p2p_consider_moving_gos(wpa_s, freqs, num, trig); |
| 8517 | |
| 8518 | os_free(freqs); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8519 | } |
| 8520 | |
| 8521 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8522 | static void wpas_p2p_scan_res_ignore(struct wpa_supplicant *wpa_s, |
| 8523 | struct wpa_scan_results *scan_res) |
| 8524 | { |
| 8525 | wpa_printf(MSG_DEBUG, "P2P: Ignore scan results"); |
| 8526 | } |
| 8527 | |
| 8528 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8529 | int wpas_p2p_cancel(struct wpa_supplicant *wpa_s) |
| 8530 | { |
| 8531 | struct wpa_global *global = wpa_s->global; |
| 8532 | int found = 0; |
| 8533 | const u8 *peer; |
| 8534 | |
| 8535 | if (global->p2p == NULL) |
| 8536 | return -1; |
| 8537 | |
| 8538 | wpa_printf(MSG_DEBUG, "P2P: Request to cancel group formation"); |
| 8539 | |
| 8540 | if (wpa_s->pending_interface_name[0] && |
| 8541 | !is_zero_ether_addr(wpa_s->pending_interface_addr)) |
| 8542 | found = 1; |
| 8543 | |
| 8544 | peer = p2p_get_go_neg_peer(global->p2p); |
| 8545 | if (peer) { |
| 8546 | wpa_printf(MSG_DEBUG, "P2P: Unauthorize pending GO Neg peer " |
| 8547 | MACSTR, MAC2STR(peer)); |
| 8548 | p2p_unauthorize(global->p2p, peer); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8549 | found = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8550 | } |
| 8551 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8552 | if (wpa_s->scan_res_handler == wpas_p2p_scan_res_join) { |
| 8553 | wpa_printf(MSG_DEBUG, "P2P: Stop pending scan for join"); |
| 8554 | wpa_s->scan_res_handler = wpas_p2p_scan_res_ignore; |
| 8555 | found = 1; |
| 8556 | } |
| 8557 | |
| 8558 | if (wpa_s->pending_pd_before_join) { |
| 8559 | wpa_printf(MSG_DEBUG, "P2P: Stop pending PD before join"); |
| 8560 | wpa_s->pending_pd_before_join = 0; |
| 8561 | found = 1; |
| 8562 | } |
| 8563 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8564 | wpas_p2p_stop_find(wpa_s); |
| 8565 | |
| 8566 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 8567 | if (wpa_s == global->p2p_group_formation && |
| 8568 | (wpa_s->p2p_in_provisioning || |
| 8569 | wpa_s->parent->pending_interface_type == |
| 8570 | WPA_IF_P2P_CLIENT)) { |
| 8571 | wpa_printf(MSG_DEBUG, "P2P: Interface %s in group " |
| 8572 | "formation found - cancelling", |
| 8573 | wpa_s->ifname); |
| 8574 | found = 1; |
| 8575 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8576 | wpa_s->p2pdev, NULL); |
Jouni Malinen | adddfc4 | 2012-10-03 14:31:41 -0700 | [diff] [blame] | 8577 | if (wpa_s->p2p_in_provisioning) { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8578 | wpas_group_formation_completed(wpa_s, 0, 0); |
Jouni Malinen | adddfc4 | 2012-10-03 14:31:41 -0700 | [diff] [blame] | 8579 | break; |
| 8580 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8581 | wpas_p2p_group_delete(wpa_s, |
| 8582 | P2P_GROUP_REMOVAL_REQUESTED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8583 | break; |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 8584 | } else if (wpa_s->p2p_in_invitation) { |
| 8585 | wpa_printf(MSG_DEBUG, "P2P: Interface %s in invitation found - cancelling", |
| 8586 | wpa_s->ifname); |
| 8587 | found = 1; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8588 | wpas_p2p_group_formation_failed(wpa_s, 0); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8589 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8590 | } |
| 8591 | } |
| 8592 | |
| 8593 | if (!found) { |
| 8594 | wpa_printf(MSG_DEBUG, "P2P: No ongoing group formation found"); |
| 8595 | return -1; |
| 8596 | } |
| 8597 | |
| 8598 | return 0; |
| 8599 | } |
| 8600 | |
| 8601 | |
| 8602 | void wpas_p2p_interface_unavailable(struct wpa_supplicant *wpa_s) |
| 8603 | { |
| 8604 | if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group) |
| 8605 | return; |
| 8606 | |
| 8607 | wpa_printf(MSG_DEBUG, "P2P: Remove group due to driver resource not " |
| 8608 | "being available anymore"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8609 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_UNAVAILABLE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8610 | } |
| 8611 | |
| 8612 | |
| 8613 | void wpas_p2p_update_best_channels(struct wpa_supplicant *wpa_s, |
| 8614 | int freq_24, int freq_5, int freq_overall) |
| 8615 | { |
| 8616 | struct p2p_data *p2p = wpa_s->global->p2p; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8617 | if (p2p == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8618 | return; |
| 8619 | p2p_set_best_channels(p2p, freq_24, freq_5, freq_overall); |
| 8620 | } |
| 8621 | |
| 8622 | |
| 8623 | int wpas_p2p_unauthorize(struct wpa_supplicant *wpa_s, const char *addr) |
| 8624 | { |
| 8625 | u8 peer[ETH_ALEN]; |
| 8626 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 8627 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8628 | if (p2p == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8629 | return -1; |
| 8630 | |
| 8631 | if (hwaddr_aton(addr, peer)) |
| 8632 | return -1; |
| 8633 | |
| 8634 | return p2p_unauthorize(p2p, peer); |
| 8635 | } |
| 8636 | |
| 8637 | |
| 8638 | /** |
| 8639 | * wpas_p2p_disconnect - Disconnect from a P2P Group |
| 8640 | * @wpa_s: Pointer to wpa_supplicant data |
| 8641 | * Returns: 0 on success, -1 on failure |
| 8642 | * |
| 8643 | * This can be used to disconnect from a group in which the local end is a P2P |
| 8644 | * Client or to end a P2P Group in case the local end is the Group Owner. If a |
| 8645 | * virtual network interface was created for this group, that interface will be |
| 8646 | * removed. Otherwise, only the configured P2P group network will be removed |
| 8647 | * from the interface. |
| 8648 | */ |
| 8649 | int wpas_p2p_disconnect(struct wpa_supplicant *wpa_s) |
| 8650 | { |
| 8651 | |
| 8652 | if (wpa_s == NULL) |
| 8653 | return -1; |
| 8654 | |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8655 | return wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_REQUESTED) < 0 ? |
| 8656 | -1 : 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8657 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8658 | |
| 8659 | |
| 8660 | int wpas_p2p_in_progress(struct wpa_supplicant *wpa_s) |
| 8661 | { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8662 | int ret; |
| 8663 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8664 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8665 | return 0; |
| 8666 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8667 | ret = p2p_in_progress(wpa_s->global->p2p); |
| 8668 | if (ret == 0) { |
| 8669 | /* |
| 8670 | * Check whether there is an ongoing WPS provisioning step (or |
| 8671 | * other parts of group formation) on another interface since |
| 8672 | * p2p_in_progress() does not report this to avoid issues for |
| 8673 | * scans during such provisioning step. |
| 8674 | */ |
| 8675 | if (wpa_s->global->p2p_group_formation && |
| 8676 | wpa_s->global->p2p_group_formation != wpa_s) { |
| 8677 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Another interface (%s) " |
| 8678 | "in group formation", |
| 8679 | wpa_s->global->p2p_group_formation->ifname); |
| 8680 | ret = 1; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 8681 | } else if (wpa_s->global->p2p_group_formation == wpa_s) { |
| 8682 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 8683 | "P2P: Skip Extended Listen timeout and allow scans on current interface for group formation"); |
| 8684 | ret = 2; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8685 | } |
| 8686 | } |
| 8687 | |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 8688 | if (!ret && wpa_s->global->p2p_go_wait_client.sec) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8689 | struct os_reltime now; |
| 8690 | os_get_reltime(&now); |
| 8691 | if (os_reltime_expired(&now, &wpa_s->global->p2p_go_wait_client, |
| 8692 | P2P_MAX_INITIAL_CONN_WAIT_GO)) { |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 8693 | /* Wait for the first client has expired */ |
| 8694 | wpa_s->global->p2p_go_wait_client.sec = 0; |
| 8695 | } else { |
| 8696 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Waiting for initial client connection during group formation"); |
| 8697 | ret = 1; |
| 8698 | } |
| 8699 | } |
| 8700 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8701 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8702 | } |
| 8703 | |
| 8704 | |
| 8705 | void wpas_p2p_network_removed(struct wpa_supplicant *wpa_s, |
| 8706 | struct wpa_ssid *ssid) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8707 | { |
| 8708 | if (wpa_s->p2p_in_provisioning && ssid->p2p_group && |
| 8709 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8710 | wpa_s->p2pdev, NULL) > 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8711 | /** |
| 8712 | * Remove the network by scheduling the group formation |
| 8713 | * timeout to happen immediately. The teardown code |
| 8714 | * needs to be scheduled to run asynch later so that we |
| 8715 | * don't delete data from under ourselves unexpectedly. |
| 8716 | * Calling wpas_p2p_group_formation_timeout directly |
| 8717 | * causes a series of crashes in WPS failure scenarios. |
| 8718 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8719 | wpa_printf(MSG_DEBUG, "P2P: Canceled group formation due to " |
| 8720 | "P2P group network getting removed"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8721 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8722 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8723 | } |
| 8724 | } |
| 8725 | |
| 8726 | |
| 8727 | struct wpa_ssid * wpas_p2p_get_persistent(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8728 | const u8 *addr, const u8 *ssid, |
| 8729 | size_t ssid_len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8730 | { |
| 8731 | struct wpa_ssid *s; |
| 8732 | size_t i; |
| 8733 | |
| 8734 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 8735 | if (s->disabled != 2) |
| 8736 | continue; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8737 | if (ssid && |
| 8738 | (ssid_len != s->ssid_len || |
| 8739 | os_memcmp(ssid, s->ssid, ssid_len) != 0)) |
| 8740 | continue; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8741 | if (addr == NULL) { |
| 8742 | if (s->mode == WPAS_MODE_P2P_GO) |
| 8743 | return s; |
| 8744 | continue; |
| 8745 | } |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 8746 | if (ether_addr_equal(s->bssid, addr)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8747 | return s; /* peer is GO in the persistent group */ |
| 8748 | if (s->mode != WPAS_MODE_P2P_GO || s->p2p_client_list == NULL) |
| 8749 | continue; |
| 8750 | for (i = 0; i < s->num_p2p_clients; i++) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 8751 | if (ether_addr_equal(s->p2p_client_list + |
| 8752 | i * 2 * ETH_ALEN, addr)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8753 | return s; /* peer is P2P client in persistent |
| 8754 | * group */ |
| 8755 | } |
| 8756 | } |
| 8757 | |
| 8758 | return NULL; |
| 8759 | } |
| 8760 | |
| 8761 | |
| 8762 | void wpas_p2p_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s, |
| 8763 | const u8 *addr) |
| 8764 | { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8765 | if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8766 | wpa_s->p2pdev, NULL) > 0) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8767 | /* |
| 8768 | * This can happen if WPS provisioning step is not terminated |
| 8769 | * cleanly (e.g., P2P Client does not send WSC_Done). Since the |
| 8770 | * peer was able to connect, there is no need to time out group |
| 8771 | * formation after this, though. In addition, this is used with |
| 8772 | * the initial connection wait on the GO as a separate formation |
| 8773 | * timeout and as such, expected to be hit after the initial WPS |
| 8774 | * provisioning step. |
| 8775 | */ |
| 8776 | 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] | 8777 | |
| 8778 | if (!wpa_s->p2p_go_group_formation_completed && |
| 8779 | !wpa_s->group_formation_reported) { |
| 8780 | /* |
| 8781 | * GO has not yet notified group formation success since |
| 8782 | * the WPS step was not completed cleanly. Do that |
| 8783 | * notification now since the P2P Client was able to |
| 8784 | * connect and as such, must have received the |
| 8785 | * credential from the WPS step. |
| 8786 | */ |
| 8787 | if (wpa_s->global->p2p) |
| 8788 | p2p_wps_success_cb(wpa_s->global->p2p, addr); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8789 | wpas_group_formation_completed(wpa_s, 1, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8790 | } |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8791 | } |
| 8792 | if (!wpa_s->p2p_go_group_formation_completed) { |
| 8793 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Marking group formation completed on GO on first data connection"); |
| 8794 | wpa_s->p2p_go_group_formation_completed = 1; |
| 8795 | wpa_s->global->p2p_group_formation = NULL; |
| 8796 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 8797 | wpa_s->p2p_in_invitation = 0; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 8798 | wpa_s->p2p_retry_limit = 0; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8799 | } |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 8800 | wpa_s->global->p2p_go_wait_client.sec = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8801 | if (addr == NULL) |
| 8802 | return; |
| 8803 | wpas_p2p_add_persistent_group_client(wpa_s, addr); |
| 8804 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8805 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8806 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8807 | static int wpas_p2p_fallback_to_go_neg(struct wpa_supplicant *wpa_s, |
| 8808 | int group_added) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8809 | { |
| 8810 | struct wpa_supplicant *group = wpa_s; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8811 | int ret = 0; |
| 8812 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8813 | if (wpa_s->global->p2p_group_formation) |
| 8814 | group = wpa_s->global->p2p_group_formation; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8815 | wpa_s = wpa_s->global->p2p_init_wpa_s; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8816 | offchannel_send_action_done(wpa_s); |
| 8817 | if (group_added) |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8818 | ret = wpas_p2p_group_delete(group, P2P_GROUP_REMOVAL_SILENT); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8819 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Fall back to GO Negotiation"); |
| 8820 | wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr, wpa_s->p2p_pin, |
| 8821 | wpa_s->p2p_wps_method, wpa_s->p2p_persistent_group, 0, |
| 8822 | 0, 0, wpa_s->p2p_go_intent, wpa_s->p2p_connect_freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8823 | wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8824 | wpa_s->p2p_persistent_id, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8825 | wpa_s->p2p_pd_before_go_neg, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8826 | wpa_s->p2p_go_ht40, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8827 | wpa_s->p2p_go_vht, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8828 | wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8829 | wpa_s->p2p_go_he, |
| 8830 | wpa_s->p2p_go_edmg, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 8831 | NULL, 0, is_p2p_allow_6ghz(wpa_s->global->p2p)); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8832 | return ret; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8833 | } |
| 8834 | |
| 8835 | |
| 8836 | int wpas_p2p_scan_no_go_seen(struct wpa_supplicant *wpa_s) |
| 8837 | { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8838 | int res; |
| 8839 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8840 | if (!wpa_s->p2p_fallback_to_go_neg || |
| 8841 | wpa_s->p2p_in_provisioning <= 5) |
| 8842 | return 0; |
| 8843 | |
| 8844 | if (wpas_p2p_peer_go(wpa_s, wpa_s->pending_join_dev_addr) > 0) |
| 8845 | return 0; /* peer operating as a GO */ |
| 8846 | |
| 8847 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: GO not found for p2p_connect-auto - " |
| 8848 | "fallback to GO Negotiation"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8849 | 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] | 8850 | "reason=GO-not-found"); |
| 8851 | res = wpas_p2p_fallback_to_go_neg(wpa_s, 1); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8852 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8853 | return res == 1 ? 2 : 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8854 | } |
| 8855 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8856 | |
| 8857 | unsigned int wpas_p2p_search_delay(struct wpa_supplicant *wpa_s) |
| 8858 | { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8859 | struct wpa_supplicant *ifs; |
| 8860 | |
| 8861 | if (wpa_s->wpa_state > WPA_SCANNING) { |
| 8862 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search delay due to " |
| 8863 | "concurrent operation", |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 8864 | wpa_s->conf->p2p_search_delay); |
| 8865 | return wpa_s->conf->p2p_search_delay; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8866 | } |
| 8867 | |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 8868 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 8869 | radio_list) { |
| 8870 | if (ifs != wpa_s && ifs->wpa_state > WPA_SCANNING) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8871 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search " |
| 8872 | "delay due to concurrent operation on " |
| 8873 | "interface %s", |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 8874 | wpa_s->conf->p2p_search_delay, |
| 8875 | ifs->ifname); |
| 8876 | return wpa_s->conf->p2p_search_delay; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8877 | } |
| 8878 | } |
| 8879 | |
| 8880 | return 0; |
| 8881 | } |
| 8882 | |
Dmitry Shmidt | 37d4d6a | 2013-03-18 13:09:42 -0700 | [diff] [blame] | 8883 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8884 | static int wpas_p2p_remove_psk_entry(struct wpa_supplicant *wpa_s, |
| 8885 | struct wpa_ssid *s, const u8 *addr, |
| 8886 | int iface_addr) |
| 8887 | { |
| 8888 | struct psk_list_entry *psk, *tmp; |
| 8889 | int changed = 0; |
| 8890 | |
| 8891 | dl_list_for_each_safe(psk, tmp, &s->psk_list, struct psk_list_entry, |
| 8892 | list) { |
| 8893 | if ((iface_addr && !psk->p2p && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 8894 | ether_addr_equal(addr, psk->addr)) || |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8895 | (!iface_addr && psk->p2p && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 8896 | ether_addr_equal(addr, psk->addr))) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8897 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 8898 | "P2P: Remove persistent group PSK list entry for " |
| 8899 | MACSTR " p2p=%u", |
| 8900 | MAC2STR(psk->addr), psk->p2p); |
| 8901 | dl_list_del(&psk->list); |
| 8902 | os_free(psk); |
| 8903 | changed++; |
| 8904 | } |
| 8905 | } |
| 8906 | |
| 8907 | return changed; |
| 8908 | } |
| 8909 | |
| 8910 | |
| 8911 | void wpas_p2p_new_psk_cb(struct wpa_supplicant *wpa_s, const u8 *mac_addr, |
| 8912 | const u8 *p2p_dev_addr, |
| 8913 | const u8 *psk, size_t psk_len) |
| 8914 | { |
| 8915 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 8916 | struct wpa_ssid *persistent; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 8917 | struct psk_list_entry *p, *last; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8918 | |
| 8919 | if (psk_len != sizeof(p->psk)) |
| 8920 | return; |
| 8921 | |
| 8922 | if (p2p_dev_addr) { |
| 8923 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New PSK for addr=" MACSTR |
| 8924 | " p2p_dev_addr=" MACSTR, |
| 8925 | MAC2STR(mac_addr), MAC2STR(p2p_dev_addr)); |
| 8926 | if (is_zero_ether_addr(p2p_dev_addr)) |
| 8927 | p2p_dev_addr = NULL; |
| 8928 | } else { |
| 8929 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New PSK for addr=" MACSTR, |
| 8930 | MAC2STR(mac_addr)); |
| 8931 | } |
| 8932 | |
| 8933 | if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) { |
| 8934 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: new_psk_cb during group formation"); |
| 8935 | /* To be added to persistent group once created */ |
| 8936 | if (wpa_s->global->add_psk == NULL) { |
| 8937 | wpa_s->global->add_psk = os_zalloc(sizeof(*p)); |
| 8938 | if (wpa_s->global->add_psk == NULL) |
| 8939 | return; |
| 8940 | } |
| 8941 | p = wpa_s->global->add_psk; |
| 8942 | if (p2p_dev_addr) { |
| 8943 | p->p2p = 1; |
| 8944 | os_memcpy(p->addr, p2p_dev_addr, ETH_ALEN); |
| 8945 | } else { |
| 8946 | p->p2p = 0; |
| 8947 | os_memcpy(p->addr, mac_addr, ETH_ALEN); |
| 8948 | } |
| 8949 | os_memcpy(p->psk, psk, psk_len); |
| 8950 | return; |
| 8951 | } |
| 8952 | |
| 8953 | if (ssid->mode != WPAS_MODE_P2P_GO || !ssid->p2p_persistent_group) { |
| 8954 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Ignore new_psk_cb on not-persistent GO"); |
| 8955 | return; |
| 8956 | } |
| 8957 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8958 | persistent = wpas_p2p_get_persistent(wpa_s->p2pdev, NULL, ssid->ssid, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8959 | ssid->ssid_len); |
| 8960 | if (!persistent) { |
| 8961 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not find persistent group information to store the new PSK"); |
| 8962 | return; |
| 8963 | } |
| 8964 | |
| 8965 | p = os_zalloc(sizeof(*p)); |
| 8966 | if (p == NULL) |
| 8967 | return; |
| 8968 | if (p2p_dev_addr) { |
| 8969 | p->p2p = 1; |
| 8970 | os_memcpy(p->addr, p2p_dev_addr, ETH_ALEN); |
| 8971 | } else { |
| 8972 | p->p2p = 0; |
| 8973 | os_memcpy(p->addr, mac_addr, ETH_ALEN); |
| 8974 | } |
| 8975 | os_memcpy(p->psk, psk, psk_len); |
| 8976 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 8977 | if (dl_list_len(&persistent->psk_list) > P2P_MAX_STORED_CLIENTS && |
| 8978 | (last = dl_list_last(&persistent->psk_list, |
| 8979 | struct psk_list_entry, list))) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8980 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove oldest PSK entry for " |
| 8981 | MACSTR " (p2p=%u) to make room for a new one", |
| 8982 | MAC2STR(last->addr), last->p2p); |
| 8983 | dl_list_del(&last->list); |
| 8984 | os_free(last); |
| 8985 | } |
| 8986 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8987 | wpas_p2p_remove_psk_entry(wpa_s->p2pdev, persistent, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8988 | p2p_dev_addr ? p2p_dev_addr : mac_addr, |
| 8989 | p2p_dev_addr == NULL); |
| 8990 | if (p2p_dev_addr) { |
| 8991 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for p2p_dev_addr=" |
| 8992 | MACSTR, MAC2STR(p2p_dev_addr)); |
| 8993 | } else { |
| 8994 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for addr=" MACSTR, |
| 8995 | MAC2STR(mac_addr)); |
| 8996 | } |
| 8997 | dl_list_add(&persistent->psk_list, &p->list); |
| 8998 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8999 | if (wpa_s->p2pdev->conf->update_config && |
| 9000 | wpa_config_write(wpa_s->p2pdev->confname, wpa_s->p2pdev->conf)) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9001 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9002 | } |
| 9003 | |
| 9004 | |
| 9005 | static void wpas_p2p_remove_psk(struct wpa_supplicant *wpa_s, |
| 9006 | struct wpa_ssid *s, const u8 *addr, |
| 9007 | int iface_addr) |
| 9008 | { |
| 9009 | int res; |
| 9010 | |
| 9011 | res = wpas_p2p_remove_psk_entry(wpa_s, s, addr, iface_addr); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 9012 | if (res > 0 && wpa_s->conf->update_config && |
| 9013 | wpa_config_write(wpa_s->confname, wpa_s->conf)) |
| 9014 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9015 | "P2P: Failed to update configuration"); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9016 | } |
| 9017 | |
| 9018 | |
| 9019 | static void wpas_p2p_remove_client_go(struct wpa_supplicant *wpa_s, |
| 9020 | const u8 *peer, int iface_addr) |
| 9021 | { |
| 9022 | struct hostapd_data *hapd; |
| 9023 | struct hostapd_wpa_psk *psk, *prev, *rem; |
| 9024 | struct sta_info *sta; |
| 9025 | |
| 9026 | if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL || |
| 9027 | wpa_s->current_ssid->mode != WPAS_MODE_P2P_GO) |
| 9028 | return; |
| 9029 | |
| 9030 | /* Remove per-station PSK entry */ |
| 9031 | hapd = wpa_s->ap_iface->bss[0]; |
| 9032 | prev = NULL; |
| 9033 | psk = hapd->conf->ssid.wpa_psk; |
| 9034 | while (psk) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9035 | if ((iface_addr && ether_addr_equal(peer, psk->addr)) || |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9036 | (!iface_addr && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9037 | ether_addr_equal(peer, psk->p2p_dev_addr))) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9038 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove operating group PSK entry for " |
| 9039 | MACSTR " iface_addr=%d", |
| 9040 | MAC2STR(peer), iface_addr); |
| 9041 | if (prev) |
| 9042 | prev->next = psk->next; |
| 9043 | else |
| 9044 | hapd->conf->ssid.wpa_psk = psk->next; |
| 9045 | rem = psk; |
| 9046 | psk = psk->next; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 9047 | bin_clear_free(rem, sizeof(*rem)); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9048 | } else { |
| 9049 | prev = psk; |
| 9050 | psk = psk->next; |
| 9051 | } |
| 9052 | } |
| 9053 | |
| 9054 | /* Disconnect from group */ |
| 9055 | if (iface_addr) |
| 9056 | sta = ap_get_sta(hapd, peer); |
| 9057 | else |
| 9058 | sta = ap_get_sta_p2p(hapd, peer); |
| 9059 | if (sta) { |
| 9060 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disconnect peer " MACSTR |
| 9061 | " (iface_addr=%d) from group", |
| 9062 | MAC2STR(peer), iface_addr); |
| 9063 | hostapd_drv_sta_deauth(hapd, sta->addr, |
| 9064 | WLAN_REASON_DEAUTH_LEAVING); |
| 9065 | ap_sta_deauthenticate(hapd, sta, WLAN_REASON_DEAUTH_LEAVING); |
| 9066 | } |
| 9067 | } |
| 9068 | |
| 9069 | |
| 9070 | void wpas_p2p_remove_client(struct wpa_supplicant *wpa_s, const u8 *peer, |
| 9071 | int iface_addr) |
| 9072 | { |
| 9073 | struct wpa_ssid *s; |
| 9074 | struct wpa_supplicant *w; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 9075 | 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] | 9076 | |
| 9077 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove client " MACSTR, MAC2STR(peer)); |
| 9078 | |
| 9079 | /* Remove from any persistent group */ |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 9080 | for (s = p2p_wpa_s->conf->ssid; s; s = s->next) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9081 | if (s->disabled != 2 || s->mode != WPAS_MODE_P2P_GO) |
| 9082 | continue; |
| 9083 | if (!iface_addr) |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 9084 | wpas_remove_persistent_peer(p2p_wpa_s, s, peer, 0); |
| 9085 | wpas_p2p_remove_psk(p2p_wpa_s, s, peer, iface_addr); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9086 | } |
| 9087 | |
| 9088 | /* Remove from any operating group */ |
| 9089 | for (w = wpa_s->global->ifaces; w; w = w->next) |
| 9090 | wpas_p2p_remove_client_go(w, peer, iface_addr); |
| 9091 | } |
| 9092 | |
| 9093 | |
| 9094 | static void wpas_p2p_psk_failure_removal(void *eloop_ctx, void *timeout_ctx) |
| 9095 | { |
| 9096 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 9097 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_PSK_FAILURE); |
| 9098 | } |
| 9099 | |
| 9100 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 9101 | static void wpas_p2p_group_freq_conflict(void *eloop_ctx, void *timeout_ctx) |
| 9102 | { |
| 9103 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 9104 | |
| 9105 | wpa_printf(MSG_DEBUG, "P2P: Frequency conflict - terminate group"); |
| 9106 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_FREQ_CONFLICT); |
| 9107 | } |
| 9108 | |
| 9109 | |
| 9110 | int wpas_p2p_handle_frequency_conflicts(struct wpa_supplicant *wpa_s, int freq, |
| 9111 | struct wpa_ssid *ssid) |
| 9112 | { |
| 9113 | struct wpa_supplicant *iface; |
| 9114 | |
| 9115 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 9116 | if (!iface->current_ssid || |
| 9117 | iface->current_ssid->frequency == freq || |
| 9118 | (iface->p2p_group_interface == NOT_P2P_GROUP_INTERFACE && |
| 9119 | !iface->current_ssid->p2p_group)) |
| 9120 | continue; |
| 9121 | |
| 9122 | /* Remove the connection with least priority */ |
| 9123 | if (!wpas_is_p2p_prioritized(iface)) { |
| 9124 | /* STA connection has priority over existing |
| 9125 | * P2P connection, so remove the interface. */ |
| 9126 | wpa_printf(MSG_DEBUG, "P2P: Removing P2P connection due to single channel concurrent mode frequency conflict"); |
| 9127 | eloop_register_timeout(0, 0, |
| 9128 | wpas_p2p_group_freq_conflict, |
| 9129 | iface, NULL); |
| 9130 | /* If connection in progress is P2P connection, do not |
| 9131 | * proceed for the connection. */ |
| 9132 | if (wpa_s == iface) |
| 9133 | return -1; |
| 9134 | else |
| 9135 | return 0; |
| 9136 | } else { |
| 9137 | /* P2P connection has priority, disable the STA network |
| 9138 | */ |
| 9139 | wpa_supplicant_disable_network(wpa_s->global->ifaces, |
| 9140 | ssid); |
| 9141 | wpa_msg(wpa_s->global->ifaces, MSG_INFO, |
| 9142 | WPA_EVENT_FREQ_CONFLICT " id=%d", ssid->id); |
| 9143 | os_memset(wpa_s->global->ifaces->pending_bssid, 0, |
| 9144 | ETH_ALEN); |
| 9145 | /* If P2P connection is in progress, continue |
| 9146 | * connecting...*/ |
| 9147 | if (wpa_s == iface) |
| 9148 | return 0; |
| 9149 | else |
| 9150 | return -1; |
| 9151 | } |
| 9152 | } |
| 9153 | |
| 9154 | return 0; |
| 9155 | } |
| 9156 | |
| 9157 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9158 | int wpas_p2p_4way_hs_failed(struct wpa_supplicant *wpa_s) |
| 9159 | { |
| 9160 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 9161 | |
| 9162 | if (ssid == NULL || !ssid->p2p_group) |
| 9163 | return 0; |
| 9164 | |
| 9165 | if (wpa_s->p2p_last_4way_hs_fail && |
| 9166 | wpa_s->p2p_last_4way_hs_fail == ssid) { |
| 9167 | u8 go_dev_addr[ETH_ALEN]; |
| 9168 | struct wpa_ssid *persistent; |
| 9169 | |
| 9170 | if (wpas_p2p_persistent_group(wpa_s, go_dev_addr, |
| 9171 | ssid->ssid, |
| 9172 | ssid->ssid_len) <= 0) { |
| 9173 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not determine whether 4-way handshake failures were for a persistent group"); |
| 9174 | goto disconnect; |
| 9175 | } |
| 9176 | |
| 9177 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Two 4-way handshake failures for a P2P group - go_dev_addr=" |
| 9178 | MACSTR, MAC2STR(go_dev_addr)); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9179 | persistent = wpas_p2p_get_persistent(wpa_s->p2pdev, go_dev_addr, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9180 | ssid->ssid, |
| 9181 | ssid->ssid_len); |
| 9182 | if (persistent == NULL || persistent->mode != WPAS_MODE_INFRA) { |
| 9183 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No matching persistent group stored"); |
| 9184 | goto disconnect; |
| 9185 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9186 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9187 | P2P_EVENT_PERSISTENT_PSK_FAIL "%d", |
| 9188 | persistent->id); |
| 9189 | disconnect: |
| 9190 | wpa_s->p2p_last_4way_hs_fail = NULL; |
| 9191 | /* |
| 9192 | * Remove the group from a timeout to avoid issues with caller |
| 9193 | * continuing to use the interface if this is on a P2P group |
| 9194 | * interface. |
| 9195 | */ |
| 9196 | eloop_register_timeout(0, 0, wpas_p2p_psk_failure_removal, |
| 9197 | wpa_s, NULL); |
| 9198 | return 1; |
| 9199 | } |
| 9200 | |
| 9201 | wpa_s->p2p_last_4way_hs_fail = ssid; |
| 9202 | return 0; |
| 9203 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9204 | |
| 9205 | |
| 9206 | #ifdef CONFIG_WPS_NFC |
| 9207 | |
| 9208 | static struct wpabuf * wpas_p2p_nfc_handover(int ndef, struct wpabuf *wsc, |
| 9209 | struct wpabuf *p2p) |
| 9210 | { |
| 9211 | struct wpabuf *ret; |
| 9212 | size_t wsc_len; |
| 9213 | |
| 9214 | if (p2p == NULL) { |
| 9215 | wpabuf_free(wsc); |
| 9216 | wpa_printf(MSG_DEBUG, "P2P: No p2p buffer for handover"); |
| 9217 | return NULL; |
| 9218 | } |
| 9219 | |
| 9220 | wsc_len = wsc ? wpabuf_len(wsc) : 0; |
| 9221 | ret = wpabuf_alloc(2 + wsc_len + 2 + wpabuf_len(p2p)); |
| 9222 | if (ret == NULL) { |
| 9223 | wpabuf_free(wsc); |
| 9224 | wpabuf_free(p2p); |
| 9225 | return NULL; |
| 9226 | } |
| 9227 | |
| 9228 | wpabuf_put_be16(ret, wsc_len); |
| 9229 | if (wsc) |
| 9230 | wpabuf_put_buf(ret, wsc); |
| 9231 | wpabuf_put_be16(ret, wpabuf_len(p2p)); |
| 9232 | wpabuf_put_buf(ret, p2p); |
| 9233 | |
| 9234 | wpabuf_free(wsc); |
| 9235 | wpabuf_free(p2p); |
| 9236 | wpa_hexdump_buf(MSG_DEBUG, |
| 9237 | "P2P: Generated NFC connection handover message", ret); |
| 9238 | |
| 9239 | if (ndef && ret) { |
| 9240 | struct wpabuf *tmp; |
| 9241 | tmp = ndef_build_p2p(ret); |
| 9242 | wpabuf_free(ret); |
| 9243 | if (tmp == NULL) { |
| 9244 | wpa_printf(MSG_DEBUG, "P2P: Failed to NDEF encapsulate handover request"); |
| 9245 | return NULL; |
| 9246 | } |
| 9247 | ret = tmp; |
| 9248 | } |
| 9249 | |
| 9250 | return ret; |
| 9251 | } |
| 9252 | |
| 9253 | |
| 9254 | static int wpas_p2p_cli_freq(struct wpa_supplicant *wpa_s, |
| 9255 | struct wpa_ssid **ssid, u8 *go_dev_addr) |
| 9256 | { |
| 9257 | struct wpa_supplicant *iface; |
| 9258 | |
| 9259 | if (go_dev_addr) |
| 9260 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 9261 | if (ssid) |
| 9262 | *ssid = NULL; |
| 9263 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 9264 | if (iface->wpa_state < WPA_ASSOCIATING || |
| 9265 | iface->current_ssid == NULL || iface->assoc_freq == 0 || |
| 9266 | !iface->current_ssid->p2p_group || |
| 9267 | iface->current_ssid->mode != WPAS_MODE_INFRA) |
| 9268 | continue; |
| 9269 | if (ssid) |
| 9270 | *ssid = iface->current_ssid; |
| 9271 | if (go_dev_addr) |
| 9272 | os_memcpy(go_dev_addr, iface->go_dev_addr, ETH_ALEN); |
| 9273 | return iface->assoc_freq; |
| 9274 | } |
| 9275 | return 0; |
| 9276 | } |
| 9277 | |
| 9278 | |
| 9279 | struct wpabuf * wpas_p2p_nfc_handover_req(struct wpa_supplicant *wpa_s, |
| 9280 | int ndef) |
| 9281 | { |
| 9282 | struct wpabuf *wsc, *p2p; |
| 9283 | struct wpa_ssid *ssid; |
| 9284 | u8 go_dev_addr[ETH_ALEN]; |
| 9285 | int cli_freq = wpas_p2p_cli_freq(wpa_s, &ssid, go_dev_addr); |
| 9286 | |
| 9287 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) { |
| 9288 | wpa_printf(MSG_DEBUG, "P2P: P2P disabled - cannot build handover request"); |
| 9289 | return NULL; |
| 9290 | } |
| 9291 | |
| 9292 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL && |
| 9293 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, |
| 9294 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) { |
| 9295 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No DH key available for handover request"); |
| 9296 | return NULL; |
| 9297 | } |
| 9298 | |
| 9299 | if (cli_freq == 0) { |
| 9300 | wsc = wps_build_nfc_handover_req_p2p( |
| 9301 | wpa_s->parent->wps, wpa_s->conf->wps_nfc_dh_pubkey); |
| 9302 | } else |
| 9303 | wsc = NULL; |
| 9304 | p2p = p2p_build_nfc_handover_req(wpa_s->global->p2p, cli_freq, |
| 9305 | go_dev_addr, ssid ? ssid->ssid : NULL, |
| 9306 | ssid ? ssid->ssid_len : 0); |
| 9307 | |
| 9308 | return wpas_p2p_nfc_handover(ndef, wsc, p2p); |
| 9309 | } |
| 9310 | |
| 9311 | |
| 9312 | struct wpabuf * wpas_p2p_nfc_handover_sel(struct wpa_supplicant *wpa_s, |
| 9313 | int ndef, int tag) |
| 9314 | { |
| 9315 | struct wpabuf *wsc, *p2p; |
| 9316 | struct wpa_ssid *ssid; |
| 9317 | u8 go_dev_addr[ETH_ALEN]; |
| 9318 | int cli_freq = wpas_p2p_cli_freq(wpa_s, &ssid, go_dev_addr); |
| 9319 | |
| 9320 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 9321 | return NULL; |
| 9322 | |
| 9323 | if (!tag && wpa_s->conf->wps_nfc_dh_pubkey == NULL && |
| 9324 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, |
| 9325 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) |
| 9326 | return NULL; |
| 9327 | |
| 9328 | if (cli_freq == 0) { |
| 9329 | wsc = wps_build_nfc_handover_sel_p2p( |
| 9330 | wpa_s->parent->wps, |
| 9331 | tag ? wpa_s->conf->wps_nfc_dev_pw_id : |
| 9332 | DEV_PW_NFC_CONNECTION_HANDOVER, |
| 9333 | wpa_s->conf->wps_nfc_dh_pubkey, |
| 9334 | tag ? wpa_s->conf->wps_nfc_dev_pw : NULL); |
| 9335 | } else |
| 9336 | wsc = NULL; |
| 9337 | p2p = p2p_build_nfc_handover_sel(wpa_s->global->p2p, cli_freq, |
| 9338 | go_dev_addr, ssid ? ssid->ssid : NULL, |
| 9339 | ssid ? ssid->ssid_len : 0); |
| 9340 | |
| 9341 | return wpas_p2p_nfc_handover(ndef, wsc, p2p); |
| 9342 | } |
| 9343 | |
| 9344 | |
| 9345 | static int wpas_p2p_nfc_join_group(struct wpa_supplicant *wpa_s, |
| 9346 | struct p2p_nfc_params *params) |
| 9347 | { |
| 9348 | wpa_printf(MSG_DEBUG, "P2P: Initiate join-group based on NFC " |
| 9349 | "connection handover (freq=%d)", |
| 9350 | params->go_freq); |
| 9351 | |
| 9352 | if (params->go_freq && params->go_ssid_len) { |
| 9353 | wpa_s->p2p_wps_method = WPS_NFC; |
| 9354 | wpa_s->pending_join_wps_method = WPS_NFC; |
| 9355 | os_memset(wpa_s->pending_join_iface_addr, 0, ETH_ALEN); |
| 9356 | os_memcpy(wpa_s->pending_join_dev_addr, params->go_dev_addr, |
| 9357 | ETH_ALEN); |
| 9358 | return wpas_p2p_join_start(wpa_s, params->go_freq, |
| 9359 | params->go_ssid, |
| 9360 | params->go_ssid_len); |
| 9361 | } |
| 9362 | |
| 9363 | return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL, |
| 9364 | WPS_NFC, 0, 0, 1, 0, wpa_s->conf->p2p_go_intent, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9365 | params->go_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, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 9368 | params->go_ssid_len ? params->go_ssid : NULL, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9369 | params->go_ssid_len, false); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9370 | } |
| 9371 | |
| 9372 | |
| 9373 | static int wpas_p2p_nfc_auth_join(struct wpa_supplicant *wpa_s, |
| 9374 | struct p2p_nfc_params *params, int tag) |
| 9375 | { |
| 9376 | int res, persistent; |
| 9377 | struct wpa_ssid *ssid; |
| 9378 | |
| 9379 | wpa_printf(MSG_DEBUG, "P2P: Authorize join-group based on NFC " |
| 9380 | "connection handover"); |
| 9381 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 9382 | ssid = wpa_s->current_ssid; |
| 9383 | if (ssid == NULL) |
| 9384 | continue; |
| 9385 | if (ssid->mode != WPAS_MODE_P2P_GO) |
| 9386 | continue; |
| 9387 | if (wpa_s->ap_iface == NULL) |
| 9388 | continue; |
| 9389 | break; |
| 9390 | } |
| 9391 | if (wpa_s == NULL) { |
| 9392 | wpa_printf(MSG_DEBUG, "P2P: Could not find GO interface"); |
| 9393 | return -1; |
| 9394 | } |
| 9395 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9396 | if (wpa_s->p2pdev->p2p_oob_dev_pw_id != |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9397 | DEV_PW_NFC_CONNECTION_HANDOVER && |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9398 | !wpa_s->p2pdev->p2p_oob_dev_pw) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9399 | wpa_printf(MSG_DEBUG, "P2P: No NFC Dev Pw known"); |
| 9400 | return -1; |
| 9401 | } |
| 9402 | res = wpas_ap_wps_add_nfc_pw( |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9403 | wpa_s, wpa_s->p2pdev->p2p_oob_dev_pw_id, |
| 9404 | wpa_s->p2pdev->p2p_oob_dev_pw, |
| 9405 | wpa_s->p2pdev->p2p_peer_oob_pk_hash_known ? |
| 9406 | wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : NULL); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9407 | if (res) |
| 9408 | return res; |
| 9409 | |
| 9410 | if (!tag) { |
| 9411 | wpa_printf(MSG_DEBUG, "P2P: Negotiated handover - wait for peer to join without invitation"); |
| 9412 | return 0; |
| 9413 | } |
| 9414 | |
| 9415 | if (!params->peer || |
| 9416 | !(params->peer->dev_capab & P2P_DEV_CAPAB_INVITATION_PROCEDURE)) |
| 9417 | return 0; |
| 9418 | |
| 9419 | wpa_printf(MSG_DEBUG, "P2P: Static handover - invite peer " MACSTR |
| 9420 | " to join", MAC2STR(params->peer->p2p_device_addr)); |
| 9421 | |
| 9422 | wpa_s->global->p2p_invite_group = wpa_s; |
| 9423 | persistent = ssid->p2p_persistent_group && |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9424 | wpas_p2p_get_persistent(wpa_s->p2pdev, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9425 | params->peer->p2p_device_addr, |
| 9426 | ssid->ssid, ssid->ssid_len); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9427 | wpa_s->p2pdev->pending_invite_ssid_id = -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9428 | |
| 9429 | return p2p_invite(wpa_s->global->p2p, params->peer->p2p_device_addr, |
| 9430 | P2P_INVITE_ROLE_ACTIVE_GO, wpa_s->own_addr, |
| 9431 | ssid->ssid, ssid->ssid_len, ssid->frequency, |
| 9432 | wpa_s->global->p2p_dev_addr, persistent, 0, |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9433 | wpa_s->p2pdev->p2p_oob_dev_pw_id); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9434 | } |
| 9435 | |
| 9436 | |
| 9437 | static int wpas_p2p_nfc_init_go_neg(struct wpa_supplicant *wpa_s, |
| 9438 | struct p2p_nfc_params *params, |
| 9439 | int forced_freq) |
| 9440 | { |
| 9441 | wpa_printf(MSG_DEBUG, "P2P: Initiate GO Negotiation based on NFC " |
| 9442 | "connection handover"); |
| 9443 | return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL, |
| 9444 | WPS_NFC, 0, 0, 0, 0, wpa_s->conf->p2p_go_intent, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9445 | forced_freq, wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 9446 | -1, 0, 1, 1, wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9447 | wpa_s->p2p_go_he, wpa_s->p2p_go_edmg, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9448 | NULL, 0, false); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9449 | } |
| 9450 | |
| 9451 | |
| 9452 | static int wpas_p2p_nfc_resp_go_neg(struct wpa_supplicant *wpa_s, |
| 9453 | struct p2p_nfc_params *params, |
| 9454 | int forced_freq) |
| 9455 | { |
| 9456 | int res; |
| 9457 | |
| 9458 | wpa_printf(MSG_DEBUG, "P2P: Authorize GO Negotiation based on NFC " |
| 9459 | "connection handover"); |
| 9460 | res = wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL, |
| 9461 | WPS_NFC, 0, 0, 0, 1, wpa_s->conf->p2p_go_intent, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9462 | forced_freq, wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 9463 | -1, 0, 1, 1, wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9464 | wpa_s->p2p_go_he, wpa_s->p2p_go_edmg, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9465 | NULL, 0, false); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9466 | if (res) |
| 9467 | return res; |
| 9468 | |
| 9469 | res = wpas_p2p_listen(wpa_s, 60); |
| 9470 | if (res) { |
| 9471 | p2p_unauthorize(wpa_s->global->p2p, |
| 9472 | params->peer->p2p_device_addr); |
| 9473 | } |
| 9474 | |
| 9475 | return res; |
| 9476 | } |
| 9477 | |
| 9478 | |
| 9479 | static int wpas_p2p_nfc_connection_handover(struct wpa_supplicant *wpa_s, |
| 9480 | const struct wpabuf *data, |
| 9481 | int sel, int tag, int forced_freq) |
| 9482 | { |
| 9483 | const u8 *pos, *end; |
| 9484 | u16 len, id; |
| 9485 | struct p2p_nfc_params params; |
| 9486 | int res; |
| 9487 | |
| 9488 | os_memset(¶ms, 0, sizeof(params)); |
| 9489 | params.sel = sel; |
| 9490 | |
| 9491 | wpa_hexdump_buf(MSG_DEBUG, "P2P: Received NFC tag payload", data); |
| 9492 | |
| 9493 | pos = wpabuf_head(data); |
| 9494 | end = pos + wpabuf_len(data); |
| 9495 | |
| 9496 | if (end - pos < 2) { |
| 9497 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for Length of WSC " |
| 9498 | "attributes"); |
| 9499 | return -1; |
| 9500 | } |
| 9501 | len = WPA_GET_BE16(pos); |
| 9502 | pos += 2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9503 | if (len > end - pos) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9504 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for WSC " |
| 9505 | "attributes"); |
| 9506 | return -1; |
| 9507 | } |
| 9508 | params.wsc_attr = pos; |
| 9509 | params.wsc_len = len; |
| 9510 | pos += len; |
| 9511 | |
| 9512 | if (end - pos < 2) { |
| 9513 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for Length of P2P " |
| 9514 | "attributes"); |
| 9515 | return -1; |
| 9516 | } |
| 9517 | len = WPA_GET_BE16(pos); |
| 9518 | pos += 2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9519 | if (len > end - pos) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9520 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for P2P " |
| 9521 | "attributes"); |
| 9522 | return -1; |
| 9523 | } |
| 9524 | params.p2p_attr = pos; |
| 9525 | params.p2p_len = len; |
| 9526 | pos += len; |
| 9527 | |
| 9528 | wpa_hexdump(MSG_DEBUG, "P2P: WSC attributes", |
| 9529 | params.wsc_attr, params.wsc_len); |
| 9530 | wpa_hexdump(MSG_DEBUG, "P2P: P2P attributes", |
| 9531 | params.p2p_attr, params.p2p_len); |
| 9532 | if (pos < end) { |
| 9533 | wpa_hexdump(MSG_DEBUG, |
| 9534 | "P2P: Ignored extra data after P2P attributes", |
| 9535 | pos, end - pos); |
| 9536 | } |
| 9537 | |
| 9538 | res = p2p_process_nfc_connection_handover(wpa_s->global->p2p, ¶ms); |
| 9539 | if (res) |
| 9540 | return res; |
| 9541 | |
| 9542 | if (params.next_step == NO_ACTION) |
| 9543 | return 0; |
| 9544 | |
| 9545 | if (params.next_step == BOTH_GO) { |
| 9546 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_BOTH_GO "peer=" MACSTR, |
| 9547 | MAC2STR(params.peer->p2p_device_addr)); |
| 9548 | return 0; |
| 9549 | } |
| 9550 | |
| 9551 | if (params.next_step == PEER_CLIENT) { |
| 9552 | if (!is_zero_ether_addr(params.go_dev_addr)) { |
| 9553 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_PEER_CLIENT |
| 9554 | "peer=" MACSTR " freq=%d go_dev_addr=" MACSTR |
| 9555 | " ssid=\"%s\"", |
| 9556 | MAC2STR(params.peer->p2p_device_addr), |
| 9557 | params.go_freq, |
| 9558 | MAC2STR(params.go_dev_addr), |
| 9559 | wpa_ssid_txt(params.go_ssid, |
| 9560 | params.go_ssid_len)); |
| 9561 | } else { |
| 9562 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_PEER_CLIENT |
| 9563 | "peer=" MACSTR " freq=%d", |
| 9564 | MAC2STR(params.peer->p2p_device_addr), |
| 9565 | params.go_freq); |
| 9566 | } |
| 9567 | return 0; |
| 9568 | } |
| 9569 | |
| 9570 | if (wpas_p2p_cli_freq(wpa_s, NULL, NULL)) { |
| 9571 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_WHILE_CLIENT "peer=" |
| 9572 | MACSTR, MAC2STR(params.peer->p2p_device_addr)); |
| 9573 | return 0; |
| 9574 | } |
| 9575 | |
| 9576 | wpabuf_free(wpa_s->p2p_oob_dev_pw); |
| 9577 | wpa_s->p2p_oob_dev_pw = NULL; |
| 9578 | |
| 9579 | if (params.oob_dev_pw_len < WPS_OOB_PUBKEY_HASH_LEN + 2) { |
| 9580 | wpa_printf(MSG_DEBUG, "P2P: No peer OOB Dev Pw " |
| 9581 | "received"); |
| 9582 | return -1; |
| 9583 | } |
| 9584 | |
| 9585 | id = WPA_GET_BE16(params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN); |
| 9586 | wpa_printf(MSG_DEBUG, "P2P: Peer OOB Dev Pw %u", id); |
| 9587 | wpa_hexdump(MSG_DEBUG, "P2P: Peer OOB Public Key hash", |
| 9588 | params.oob_dev_pw, WPS_OOB_PUBKEY_HASH_LEN); |
| 9589 | os_memcpy(wpa_s->p2p_peer_oob_pubkey_hash, |
| 9590 | params.oob_dev_pw, WPS_OOB_PUBKEY_HASH_LEN); |
| 9591 | wpa_s->p2p_peer_oob_pk_hash_known = 1; |
| 9592 | |
| 9593 | if (tag) { |
| 9594 | if (id < 0x10) { |
| 9595 | wpa_printf(MSG_DEBUG, "P2P: Static handover - invalid " |
| 9596 | "peer OOB Device Password Id %u", id); |
| 9597 | return -1; |
| 9598 | } |
| 9599 | wpa_printf(MSG_DEBUG, "P2P: Static handover - use peer OOB " |
| 9600 | "Device Password Id %u", id); |
| 9601 | wpa_hexdump_key(MSG_DEBUG, "P2P: Peer OOB Device Password", |
| 9602 | params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN + 2, |
| 9603 | params.oob_dev_pw_len - |
| 9604 | WPS_OOB_PUBKEY_HASH_LEN - 2); |
| 9605 | wpa_s->p2p_oob_dev_pw_id = id; |
| 9606 | wpa_s->p2p_oob_dev_pw = wpabuf_alloc_copy( |
| 9607 | params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN + 2, |
| 9608 | params.oob_dev_pw_len - |
| 9609 | WPS_OOB_PUBKEY_HASH_LEN - 2); |
| 9610 | if (wpa_s->p2p_oob_dev_pw == NULL) |
| 9611 | return -1; |
| 9612 | |
| 9613 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL && |
| 9614 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, |
| 9615 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) |
| 9616 | return -1; |
| 9617 | } else { |
| 9618 | wpa_printf(MSG_DEBUG, "P2P: Using abbreviated WPS handshake " |
| 9619 | "without Device Password"); |
| 9620 | wpa_s->p2p_oob_dev_pw_id = DEV_PW_NFC_CONNECTION_HANDOVER; |
| 9621 | } |
| 9622 | |
| 9623 | switch (params.next_step) { |
| 9624 | case NO_ACTION: |
| 9625 | case BOTH_GO: |
| 9626 | case PEER_CLIENT: |
| 9627 | /* already covered above */ |
| 9628 | return 0; |
| 9629 | case JOIN_GROUP: |
| 9630 | return wpas_p2p_nfc_join_group(wpa_s, ¶ms); |
| 9631 | case AUTH_JOIN: |
| 9632 | return wpas_p2p_nfc_auth_join(wpa_s, ¶ms, tag); |
| 9633 | case INIT_GO_NEG: |
| 9634 | return wpas_p2p_nfc_init_go_neg(wpa_s, ¶ms, forced_freq); |
| 9635 | case RESP_GO_NEG: |
| 9636 | /* TODO: use own OOB Dev Pw */ |
| 9637 | return wpas_p2p_nfc_resp_go_neg(wpa_s, ¶ms, forced_freq); |
| 9638 | } |
| 9639 | |
| 9640 | return -1; |
| 9641 | } |
| 9642 | |
| 9643 | |
| 9644 | int wpas_p2p_nfc_tag_process(struct wpa_supplicant *wpa_s, |
| 9645 | const struct wpabuf *data, int forced_freq) |
| 9646 | { |
| 9647 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 9648 | return -1; |
| 9649 | |
| 9650 | return wpas_p2p_nfc_connection_handover(wpa_s, data, 1, 1, forced_freq); |
| 9651 | } |
| 9652 | |
| 9653 | |
| 9654 | int wpas_p2p_nfc_report_handover(struct wpa_supplicant *wpa_s, int init, |
| 9655 | const struct wpabuf *req, |
| 9656 | const struct wpabuf *sel, int forced_freq) |
| 9657 | { |
| 9658 | struct wpabuf *tmp; |
| 9659 | int ret; |
| 9660 | |
| 9661 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 9662 | return -1; |
| 9663 | |
| 9664 | wpa_printf(MSG_DEBUG, "NFC: P2P connection handover reported"); |
| 9665 | |
| 9666 | wpa_hexdump_ascii(MSG_DEBUG, "NFC: Req", |
| 9667 | wpabuf_head(req), wpabuf_len(req)); |
| 9668 | wpa_hexdump_ascii(MSG_DEBUG, "NFC: Sel", |
| 9669 | wpabuf_head(sel), wpabuf_len(sel)); |
| 9670 | if (forced_freq) |
| 9671 | wpa_printf(MSG_DEBUG, "NFC: Forced freq %d", forced_freq); |
| 9672 | tmp = ndef_parse_p2p(init ? sel : req); |
| 9673 | if (tmp == NULL) { |
| 9674 | wpa_printf(MSG_DEBUG, "P2P: Could not parse NDEF"); |
| 9675 | return -1; |
| 9676 | } |
| 9677 | |
| 9678 | ret = wpas_p2p_nfc_connection_handover(wpa_s, tmp, init, 0, |
| 9679 | forced_freq); |
| 9680 | wpabuf_free(tmp); |
| 9681 | |
| 9682 | return ret; |
| 9683 | } |
| 9684 | |
| 9685 | |
| 9686 | int wpas_p2p_nfc_tag_enabled(struct wpa_supplicant *wpa_s, int enabled) |
| 9687 | { |
| 9688 | const u8 *if_addr; |
| 9689 | int go_intent = wpa_s->conf->p2p_go_intent; |
| 9690 | struct wpa_supplicant *iface; |
| 9691 | |
| 9692 | if (wpa_s->global->p2p == NULL) |
| 9693 | return -1; |
| 9694 | |
| 9695 | if (!enabled) { |
| 9696 | wpa_printf(MSG_DEBUG, "P2P: Disable use of own NFC Tag"); |
| 9697 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) |
| 9698 | { |
| 9699 | if (!iface->ap_iface) |
| 9700 | continue; |
| 9701 | hostapd_wps_nfc_token_disable(iface->ap_iface->bss[0]); |
| 9702 | } |
| 9703 | p2p_set_authorized_oob_dev_pw_id(wpa_s->global->p2p, 0, |
| 9704 | 0, NULL); |
| 9705 | if (wpa_s->p2p_nfc_tag_enabled) |
| 9706 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 9707 | wpa_s->p2p_nfc_tag_enabled = 0; |
| 9708 | return 0; |
| 9709 | } |
| 9710 | |
| 9711 | if (wpa_s->global->p2p_disabled) |
| 9712 | return -1; |
| 9713 | |
| 9714 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL || |
| 9715 | wpa_s->conf->wps_nfc_dh_privkey == NULL || |
| 9716 | wpa_s->conf->wps_nfc_dev_pw == NULL || |
| 9717 | wpa_s->conf->wps_nfc_dev_pw_id < 0x10) { |
| 9718 | wpa_printf(MSG_DEBUG, "P2P: NFC password token not configured " |
| 9719 | "to allow static handover cases"); |
| 9720 | return -1; |
| 9721 | } |
| 9722 | |
| 9723 | wpa_printf(MSG_DEBUG, "P2P: Enable use of own NFC Tag"); |
| 9724 | |
| 9725 | wpa_s->p2p_oob_dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id; |
| 9726 | wpabuf_free(wpa_s->p2p_oob_dev_pw); |
| 9727 | wpa_s->p2p_oob_dev_pw = wpabuf_dup(wpa_s->conf->wps_nfc_dev_pw); |
| 9728 | if (wpa_s->p2p_oob_dev_pw == NULL) |
| 9729 | return -1; |
| 9730 | wpa_s->p2p_peer_oob_pk_hash_known = 0; |
| 9731 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 9732 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO || |
| 9733 | wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT) { |
| 9734 | /* |
| 9735 | * P2P Group Interface present and the command came on group |
| 9736 | * interface, so enable the token for the current interface. |
| 9737 | */ |
| 9738 | wpa_s->create_p2p_iface = 0; |
| 9739 | } else { |
| 9740 | wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s); |
| 9741 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9742 | |
| 9743 | if (wpa_s->create_p2p_iface) { |
| 9744 | enum wpa_driver_if_type iftype; |
| 9745 | /* Prepare to add a new interface for the group */ |
| 9746 | iftype = WPA_IF_P2P_GROUP; |
| 9747 | if (go_intent == 15) |
| 9748 | iftype = WPA_IF_P2P_GO; |
| 9749 | if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) { |
| 9750 | wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " |
| 9751 | "interface for the group"); |
| 9752 | return -1; |
| 9753 | } |
| 9754 | |
| 9755 | if_addr = wpa_s->pending_interface_addr; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9756 | } else if (wpa_s->p2p_mgmt) |
| 9757 | if_addr = wpa_s->parent->own_addr; |
| 9758 | else |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9759 | if_addr = wpa_s->own_addr; |
| 9760 | |
| 9761 | wpa_s->p2p_nfc_tag_enabled = enabled; |
| 9762 | |
| 9763 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 9764 | struct hostapd_data *hapd; |
| 9765 | if (iface->ap_iface == NULL) |
| 9766 | continue; |
| 9767 | hapd = iface->ap_iface->bss[0]; |
| 9768 | wpabuf_free(hapd->conf->wps_nfc_dh_pubkey); |
| 9769 | hapd->conf->wps_nfc_dh_pubkey = |
| 9770 | wpabuf_dup(wpa_s->conf->wps_nfc_dh_pubkey); |
| 9771 | wpabuf_free(hapd->conf->wps_nfc_dh_privkey); |
| 9772 | hapd->conf->wps_nfc_dh_privkey = |
| 9773 | wpabuf_dup(wpa_s->conf->wps_nfc_dh_privkey); |
| 9774 | wpabuf_free(hapd->conf->wps_nfc_dev_pw); |
| 9775 | hapd->conf->wps_nfc_dev_pw = |
| 9776 | wpabuf_dup(wpa_s->conf->wps_nfc_dev_pw); |
| 9777 | hapd->conf->wps_nfc_dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id; |
| 9778 | |
| 9779 | if (hostapd_wps_nfc_token_enable(iface->ap_iface->bss[0]) < 0) { |
| 9780 | wpa_dbg(iface, MSG_DEBUG, |
| 9781 | "P2P: Failed to enable NFC Tag for GO"); |
| 9782 | } |
| 9783 | } |
| 9784 | p2p_set_authorized_oob_dev_pw_id( |
| 9785 | wpa_s->global->p2p, wpa_s->conf->wps_nfc_dev_pw_id, go_intent, |
| 9786 | if_addr); |
| 9787 | |
| 9788 | return 0; |
| 9789 | } |
| 9790 | |
| 9791 | #endif /* CONFIG_WPS_NFC */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9792 | |
| 9793 | |
| 9794 | static void wpas_p2p_optimize_listen_channel(struct wpa_supplicant *wpa_s, |
| 9795 | struct wpa_used_freq_data *freqs, |
| 9796 | unsigned int num) |
| 9797 | { |
| 9798 | u8 curr_chan, cand, chan; |
| 9799 | unsigned int i; |
| 9800 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9801 | /* |
| 9802 | * If possible, optimize the Listen channel to be a channel that is |
| 9803 | * already used by one of the other interfaces. |
| 9804 | */ |
| 9805 | if (!wpa_s->conf->p2p_optimize_listen_chan) |
| 9806 | return; |
| 9807 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9808 | curr_chan = p2p_get_listen_channel(wpa_s->global->p2p); |
| 9809 | for (i = 0, cand = 0; i < num; i++) { |
| 9810 | ieee80211_freq_to_chan(freqs[i].freq, &chan); |
| 9811 | if (curr_chan == chan) { |
| 9812 | cand = 0; |
| 9813 | break; |
| 9814 | } |
| 9815 | |
| 9816 | if (chan == 1 || chan == 6 || chan == 11) |
| 9817 | cand = chan; |
| 9818 | } |
| 9819 | |
| 9820 | if (cand) { |
| 9821 | wpa_dbg(wpa_s, MSG_DEBUG, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 9822 | "P2P: Update Listen channel to %u based on operating channel", |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9823 | cand); |
| 9824 | p2p_set_listen_channel(wpa_s->global->p2p, 81, cand, 0); |
| 9825 | } |
| 9826 | } |
| 9827 | |
| 9828 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9829 | static int wpas_p2p_move_go_csa(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9830 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9831 | struct hostapd_config *conf; |
| 9832 | struct p2p_go_neg_results params; |
| 9833 | struct csa_settings csa_settings; |
| 9834 | struct wpa_ssid *current_ssid = wpa_s->current_ssid; |
| 9835 | int old_freq = current_ssid->frequency; |
| 9836 | int ret; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9837 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9838 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
| 9839 | wpa_dbg(wpa_s, MSG_DEBUG, "CSA is not enabled"); |
| 9840 | return -1; |
| 9841 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9842 | |
| 9843 | /* |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9844 | * TODO: This function may not always work correctly. For example, |
| 9845 | * 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] | 9846 | */ |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9847 | if (wpas_p2p_init_go_params(wpa_s, ¶ms, 0, 0, 0, 0, 0, 0, 0, |
| 9848 | NULL)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9849 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9850 | "P2P CSA: Failed to select new frequency for GO"); |
| 9851 | return -1; |
| 9852 | } |
| 9853 | |
| 9854 | if (current_ssid->frequency == params.freq) { |
| 9855 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9856 | "P2P CSA: Selected same frequency - not moving GO"); |
| 9857 | return 0; |
| 9858 | } |
| 9859 | |
| 9860 | conf = hostapd_config_defaults(); |
| 9861 | if (!conf) { |
| 9862 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9863 | "P2P CSA: Failed to allocate default config"); |
| 9864 | return -1; |
| 9865 | } |
| 9866 | |
| 9867 | current_ssid->frequency = params.freq; |
| 9868 | if (wpa_supplicant_conf_ap_ht(wpa_s, current_ssid, conf)) { |
| 9869 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9870 | "P2P CSA: Failed to create new GO config"); |
| 9871 | ret = -1; |
| 9872 | goto out; |
| 9873 | } |
| 9874 | |
Sunil | 4a3f9f5 | 2022-07-19 22:04:39 +0000 | [diff] [blame] | 9875 | if (conf->hw_mode != wpa_s->ap_iface->current_mode->mode && |
| 9876 | (wpa_s->ap_iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A || |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 9877 | is_6ghz_freq(wpa_s->ap_iface->freq) || |
Sunil | 4a3f9f5 | 2022-07-19 22:04:39 +0000 | [diff] [blame] | 9878 | conf->hw_mode != HOSTAPD_MODE_IEEE80211G)) { |
| 9879 | wpa_dbg(wpa_s, MSG_INFO, |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 9880 | "P2P CSA: CSA from hardware mode %d%s to %d is not supported", |
| 9881 | wpa_s->ap_iface->current_mode->mode, |
| 9882 | is_6ghz_freq(wpa_s->ap_iface->freq) ? " (6 GHz)" : "", |
| 9883 | conf->hw_mode); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9884 | ret = -1; |
| 9885 | goto out; |
| 9886 | } |
| 9887 | |
| 9888 | os_memset(&csa_settings, 0, sizeof(csa_settings)); |
| 9889 | csa_settings.cs_count = P2P_GO_CSA_COUNT; |
| 9890 | csa_settings.block_tx = P2P_GO_CSA_BLOCK_TX; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9891 | csa_settings.link_id = -1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9892 | csa_settings.freq_params.freq = params.freq; |
| 9893 | csa_settings.freq_params.sec_channel_offset = conf->secondary_channel; |
| 9894 | csa_settings.freq_params.ht_enabled = conf->ieee80211n; |
| 9895 | csa_settings.freq_params.bandwidth = conf->secondary_channel ? 40 : 20; |
| 9896 | |
| 9897 | if (conf->ieee80211ac) { |
| 9898 | int freq1 = 0, freq2 = 0; |
| 9899 | u8 chan, opclass; |
| 9900 | |
| 9901 | if (ieee80211_freq_to_channel_ext(params.freq, |
| 9902 | conf->secondary_channel, |
| 9903 | conf->vht_oper_chwidth, |
| 9904 | &opclass, &chan) == |
| 9905 | NUM_HOSTAPD_MODES) { |
| 9906 | wpa_printf(MSG_ERROR, "P2P CSA: Bad freq"); |
| 9907 | ret = -1; |
| 9908 | goto out; |
| 9909 | } |
| 9910 | |
| 9911 | if (conf->vht_oper_centr_freq_seg0_idx) |
| 9912 | freq1 = ieee80211_chan_to_freq( |
| 9913 | NULL, opclass, |
| 9914 | conf->vht_oper_centr_freq_seg0_idx); |
| 9915 | |
| 9916 | if (conf->vht_oper_centr_freq_seg1_idx) |
| 9917 | freq2 = ieee80211_chan_to_freq( |
| 9918 | NULL, opclass, |
| 9919 | conf->vht_oper_centr_freq_seg1_idx); |
| 9920 | |
| 9921 | if (freq1 < 0 || freq2 < 0) { |
| 9922 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9923 | "P2P CSA: Selected invalid VHT center freqs"); |
| 9924 | ret = -1; |
| 9925 | goto out; |
| 9926 | } |
| 9927 | |
| 9928 | csa_settings.freq_params.vht_enabled = conf->ieee80211ac; |
| 9929 | csa_settings.freq_params.center_freq1 = freq1; |
| 9930 | csa_settings.freq_params.center_freq2 = freq2; |
| 9931 | |
| 9932 | switch (conf->vht_oper_chwidth) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 9933 | case CONF_OPER_CHWIDTH_80MHZ: |
| 9934 | case CONF_OPER_CHWIDTH_80P80MHZ: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9935 | csa_settings.freq_params.bandwidth = 80; |
| 9936 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 9937 | case CONF_OPER_CHWIDTH_160MHZ: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9938 | csa_settings.freq_params.bandwidth = 160; |
| 9939 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 9940 | default: |
| 9941 | break; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9942 | } |
| 9943 | } |
| 9944 | |
| 9945 | ret = ap_switch_channel(wpa_s, &csa_settings); |
| 9946 | out: |
| 9947 | current_ssid->frequency = old_freq; |
| 9948 | hostapd_config_free(conf); |
| 9949 | return ret; |
| 9950 | } |
| 9951 | |
| 9952 | |
| 9953 | static void wpas_p2p_move_go_no_csa(struct wpa_supplicant *wpa_s) |
| 9954 | { |
| 9955 | struct p2p_go_neg_results params; |
| 9956 | struct wpa_ssid *current_ssid = wpa_s->current_ssid; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9957 | void (*ap_configured_cb)(void *ctx, void *data); |
| 9958 | void *ap_configured_cb_ctx, *ap_configured_cb_data; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9959 | |
| 9960 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP); |
| 9961 | |
| 9962 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Move GO from freq=%d MHz", |
| 9963 | current_ssid->frequency); |
| 9964 | |
| 9965 | /* Stop the AP functionality */ |
| 9966 | /* TODO: Should do this in a way that does not indicated to possible |
| 9967 | * P2P Clients in the group that the group is terminated. */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9968 | /* If this action occurs before a group is started, the callback should |
| 9969 | * be preserved, or GROUP-STARTED event would be lost. If this action |
| 9970 | * occurs after a group is started, these pointers are all NULL and |
| 9971 | * harmless. */ |
| 9972 | ap_configured_cb = wpa_s->ap_configured_cb; |
| 9973 | ap_configured_cb_ctx = wpa_s->ap_configured_cb_ctx; |
| 9974 | ap_configured_cb_data = wpa_s->ap_configured_cb_data; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9975 | wpa_supplicant_ap_deinit(wpa_s); |
| 9976 | |
| 9977 | /* Reselect the GO frequency */ |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9978 | if (wpas_p2p_init_go_params(wpa_s, ¶ms, 0, 0, 0, 0, 0, 0, 0, |
| 9979 | NULL)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9980 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Failed to reselect freq"); |
| 9981 | wpas_p2p_group_delete(wpa_s, |
| 9982 | P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL); |
| 9983 | return; |
| 9984 | } |
| 9985 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New freq selected for the GO (%u MHz)", |
| 9986 | params.freq); |
| 9987 | |
| 9988 | if (params.freq && |
| 9989 | !p2p_supported_freq_go(wpa_s->global->p2p, params.freq)) { |
| 9990 | wpa_printf(MSG_DEBUG, |
| 9991 | "P2P: Selected freq (%u MHz) is not valid for P2P", |
| 9992 | params.freq); |
| 9993 | wpas_p2p_group_delete(wpa_s, |
| 9994 | P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL); |
| 9995 | return; |
| 9996 | } |
| 9997 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9998 | /* Restore preserved callback parameters */ |
Jimmy Chen | 4b2a502 | 2020-08-26 18:55:45 +0800 | [diff] [blame] | 9999 | wpa_s->ap_configured_cb = ap_configured_cb; |
| 10000 | wpa_s->ap_configured_cb_ctx = ap_configured_cb_ctx; |
| 10001 | wpa_s->ap_configured_cb_data = ap_configured_cb_data; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10002 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10003 | /* Update the frequency */ |
| 10004 | current_ssid->frequency = params.freq; |
| 10005 | wpa_s->connect_without_scan = current_ssid; |
| 10006 | wpa_s->reassociate = 1; |
| 10007 | wpa_s->disconnected = 0; |
| 10008 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 10009 | } |
| 10010 | |
| 10011 | |
| 10012 | static void wpas_p2p_move_go(void *eloop_ctx, void *timeout_ctx) |
| 10013 | { |
| 10014 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 10015 | |
| 10016 | if (!wpa_s->ap_iface || !wpa_s->current_ssid) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10017 | return; |
| 10018 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10019 | wpas_p2p_go_update_common_freqs(wpa_s); |
| 10020 | |
| 10021 | /* Do not move GO in the middle of a CSA */ |
| 10022 | if (hostapd_csa_in_progress(wpa_s->ap_iface)) { |
| 10023 | wpa_printf(MSG_DEBUG, |
| 10024 | "P2P: CSA is in progress - not moving GO"); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10025 | return; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10026 | } |
| 10027 | |
| 10028 | /* |
| 10029 | * First, try a channel switch flow. If it is not supported or fails, |
| 10030 | * take down the GO and bring it up again. |
| 10031 | */ |
| 10032 | if (wpas_p2p_move_go_csa(wpa_s) < 0) |
| 10033 | wpas_p2p_move_go_no_csa(wpa_s); |
| 10034 | } |
| 10035 | |
| 10036 | |
| 10037 | static void wpas_p2p_reconsider_moving_go(void *eloop_ctx, void *timeout_ctx) |
| 10038 | { |
| 10039 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 10040 | struct wpa_used_freq_data *freqs = NULL; |
| 10041 | unsigned int num = wpa_s->num_multichan_concurrent; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10042 | |
| 10043 | freqs = os_calloc(num, sizeof(struct wpa_used_freq_data)); |
| 10044 | if (!freqs) |
| 10045 | return; |
| 10046 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 10047 | num = get_shared_radio_freqs_data(wpa_s, freqs, num, false); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10048 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10049 | /* Previous attempt to move a GO was not possible -- try again. */ |
| 10050 | wpas_p2p_consider_moving_gos(wpa_s, freqs, num, |
| 10051 | WPAS_P2P_CHANNEL_UPDATE_ANY); |
| 10052 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10053 | os_free(freqs); |
| 10054 | } |
| 10055 | |
| 10056 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10057 | /* |
| 10058 | * Consider moving a GO from its currently used frequency: |
| 10059 | * 1. It is possible that due to regulatory consideration the frequency |
| 10060 | * can no longer be used and there is a need to evacuate the GO. |
| 10061 | * 2. It is possible that due to MCC considerations, it would be preferable |
| 10062 | * to move the GO to a channel that is currently used by some other |
| 10063 | * station interface. |
| 10064 | * |
| 10065 | * In case a frequency that became invalid is once again valid, cancel a |
| 10066 | * previously initiated GO frequency change. |
| 10067 | */ |
| 10068 | static void wpas_p2p_consider_moving_one_go(struct wpa_supplicant *wpa_s, |
| 10069 | struct wpa_used_freq_data *freqs, |
| 10070 | unsigned int num) |
| 10071 | { |
| 10072 | unsigned int i, invalid_freq = 0, policy_move = 0, flags = 0; |
| 10073 | unsigned int timeout; |
| 10074 | int freq; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10075 | int dfs_offload; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10076 | |
| 10077 | wpas_p2p_go_update_common_freqs(wpa_s); |
| 10078 | |
| 10079 | freq = wpa_s->current_ssid->frequency; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10080 | dfs_offload = (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10081 | 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] | 10082 | for (i = 0, invalid_freq = 0; i < num; i++) { |
| 10083 | if (freqs[i].freq == freq) { |
| 10084 | flags = freqs[i].flags; |
| 10085 | |
| 10086 | /* The channel is invalid, must change it */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10087 | if (!p2p_supported_freq_go(wpa_s->global->p2p, freq) && |
| 10088 | !dfs_offload) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10089 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10090 | "P2P: Freq=%d MHz no longer valid for GO", |
| 10091 | freq); |
| 10092 | invalid_freq = 1; |
| 10093 | } |
| 10094 | } else if (freqs[i].flags == 0) { |
| 10095 | /* Freq is not used by any other station interface */ |
| 10096 | continue; |
| 10097 | } else if (!p2p_supported_freq(wpa_s->global->p2p, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10098 | freqs[i].freq) && !dfs_offload) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10099 | /* Freq is not valid for P2P use cases */ |
| 10100 | continue; |
| 10101 | } else if (wpa_s->conf->p2p_go_freq_change_policy == |
| 10102 | P2P_GO_FREQ_MOVE_SCM) { |
| 10103 | policy_move = 1; |
| 10104 | } else if (wpa_s->conf->p2p_go_freq_change_policy == |
| 10105 | P2P_GO_FREQ_MOVE_SCM_PEER_SUPPORTS && |
| 10106 | wpas_p2p_go_is_peer_freq(wpa_s, freqs[i].freq)) { |
| 10107 | policy_move = 1; |
| 10108 | } else if ((wpa_s->conf->p2p_go_freq_change_policy == |
| 10109 | P2P_GO_FREQ_MOVE_SCM_ECSA) && |
| 10110 | wpas_p2p_go_is_peer_freq(wpa_s, freqs[i].freq)) { |
| 10111 | if (!p2p_get_group_num_members(wpa_s->p2p_group)) { |
| 10112 | policy_move = 1; |
| 10113 | } else if ((wpa_s->drv_flags & |
| 10114 | WPA_DRIVER_FLAGS_AP_CSA) && |
| 10115 | wpas_p2p_go_clients_support_ecsa(wpa_s)) { |
| 10116 | u8 chan; |
| 10117 | |
| 10118 | /* |
| 10119 | * We do not support CSA between bands, so move |
| 10120 | * GO only within the same band. |
| 10121 | */ |
| 10122 | if (wpa_s->ap_iface->current_mode->mode == |
| 10123 | ieee80211_freq_to_chan(freqs[i].freq, |
| 10124 | &chan)) |
| 10125 | policy_move = 1; |
| 10126 | } |
| 10127 | } |
| 10128 | } |
| 10129 | |
| 10130 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10131 | "P2P: GO move: invalid_freq=%u, policy_move=%u, flags=0x%X", |
| 10132 | invalid_freq, policy_move, flags); |
| 10133 | |
| 10134 | /* |
| 10135 | * The channel is valid, or we are going to have a policy move, so |
| 10136 | * cancel timeout. |
| 10137 | */ |
| 10138 | if (!invalid_freq || policy_move) { |
| 10139 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10140 | "P2P: Cancel a GO move from freq=%d MHz", freq); |
| 10141 | eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL); |
| 10142 | |
| 10143 | if (wpas_p2p_in_progress(wpa_s)) { |
| 10144 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10145 | "P2P: GO move: policy CS is not allowed - setting timeout to re-consider GO move"); |
| 10146 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, |
| 10147 | wpa_s, NULL); |
| 10148 | eloop_register_timeout(P2P_RECONSIDER_GO_MOVE_DELAY, 0, |
| 10149 | wpas_p2p_reconsider_moving_go, |
| 10150 | wpa_s, NULL); |
| 10151 | return; |
| 10152 | } |
| 10153 | } |
| 10154 | |
| 10155 | if (!invalid_freq && (!policy_move || flags != 0)) { |
| 10156 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10157 | "P2P: Not initiating a GO frequency change"); |
| 10158 | return; |
| 10159 | } |
| 10160 | |
| 10161 | /* |
| 10162 | * Do not consider moving GO if it is in the middle of a CSA. When the |
| 10163 | * CSA is finished this flow should be retriggered. |
| 10164 | */ |
| 10165 | if (hostapd_csa_in_progress(wpa_s->ap_iface)) { |
| 10166 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10167 | "P2P: Not initiating a GO frequency change - CSA is in progress"); |
| 10168 | return; |
| 10169 | } |
| 10170 | |
| 10171 | if (invalid_freq && !wpas_p2p_disallowed_freq(wpa_s->global, freq)) |
| 10172 | timeout = P2P_GO_FREQ_CHANGE_TIME; |
| 10173 | else |
| 10174 | timeout = 0; |
| 10175 | |
| 10176 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Move GO from freq=%d MHz in %d secs", |
| 10177 | freq, timeout); |
| 10178 | eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL); |
| 10179 | eloop_register_timeout(timeout, 0, wpas_p2p_move_go, wpa_s, NULL); |
| 10180 | } |
| 10181 | |
| 10182 | |
| 10183 | static void wpas_p2p_consider_moving_gos(struct wpa_supplicant *wpa_s, |
| 10184 | struct wpa_used_freq_data *freqs, |
| 10185 | unsigned int num, |
| 10186 | enum wpas_p2p_channel_update_trig trig) |
| 10187 | { |
| 10188 | struct wpa_supplicant *ifs; |
| 10189 | |
| 10190 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, ELOOP_ALL_CTX, |
| 10191 | NULL); |
| 10192 | |
| 10193 | /* |
| 10194 | * Travers all the radio interfaces, and for each GO interface, check |
| 10195 | * if there is a need to move the GO from the frequency it is using, |
| 10196 | * or in case the frequency is valid again, cancel the evacuation flow. |
| 10197 | */ |
| 10198 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 10199 | radio_list) { |
| 10200 | if (ifs->current_ssid == NULL || |
| 10201 | ifs->current_ssid->mode != WPAS_MODE_P2P_GO) |
| 10202 | continue; |
| 10203 | |
| 10204 | /* |
| 10205 | * The GO was just started or completed channel switch, no need |
| 10206 | * to move it. |
| 10207 | */ |
| 10208 | if (wpa_s == ifs && |
| 10209 | (trig == WPAS_P2P_CHANNEL_UPDATE_STATE_CHANGE || |
| 10210 | trig == WPAS_P2P_CHANNEL_UPDATE_CS)) { |
| 10211 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10212 | "P2P: GO move - schedule re-consideration"); |
| 10213 | eloop_register_timeout(P2P_RECONSIDER_GO_MOVE_DELAY, 0, |
| 10214 | wpas_p2p_reconsider_moving_go, |
| 10215 | wpa_s, NULL); |
| 10216 | continue; |
| 10217 | } |
| 10218 | |
| 10219 | wpas_p2p_consider_moving_one_go(ifs, freqs, num); |
| 10220 | } |
| 10221 | } |
| 10222 | |
| 10223 | |
| 10224 | void wpas_p2p_indicate_state_change(struct wpa_supplicant *wpa_s) |
| 10225 | { |
| 10226 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 10227 | return; |
| 10228 | |
| 10229 | wpas_p2p_update_channel_list(wpa_s, |
| 10230 | WPAS_P2P_CHANNEL_UPDATE_STATE_CHANGE); |
| 10231 | } |
| 10232 | |
| 10233 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10234 | void wpas_p2p_deinit_iface(struct wpa_supplicant *wpa_s) |
| 10235 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10236 | if (wpa_s == wpa_s->global->p2p_init_wpa_s && wpa_s->global->p2p) { |
| 10237 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disable P2P since removing " |
| 10238 | "the management interface is being removed"); |
| 10239 | wpas_p2p_deinit_global(wpa_s->global); |
| 10240 | } |
| 10241 | } |
| 10242 | |
| 10243 | |
| 10244 | void wpas_p2p_ap_deinit(struct wpa_supplicant *wpa_s) |
| 10245 | { |
| 10246 | if (wpa_s->ap_iface->bss) |
| 10247 | wpa_s->ap_iface->bss[0]->p2p_group = NULL; |
| 10248 | wpas_p2p_group_deinit(wpa_s); |
| 10249 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10250 | |
| 10251 | |
| 10252 | int wpas_p2p_lo_start(struct wpa_supplicant *wpa_s, unsigned int freq, |
| 10253 | unsigned int period, unsigned int interval, |
| 10254 | unsigned int count) |
| 10255 | { |
| 10256 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 10257 | u8 *device_types; |
| 10258 | size_t dev_types_len; |
| 10259 | struct wpabuf *buf; |
| 10260 | int ret; |
| 10261 | |
| 10262 | if (wpa_s->p2p_lo_started) { |
| 10263 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10264 | "P2P Listen offload is already started"); |
| 10265 | return 0; |
| 10266 | } |
| 10267 | |
| 10268 | if (wpa_s->global->p2p == NULL || |
| 10269 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) { |
| 10270 | wpa_printf(MSG_DEBUG, "P2P: Listen offload not supported"); |
| 10271 | return -1; |
| 10272 | } |
| 10273 | |
| 10274 | if (!p2p_supported_freq(wpa_s->global->p2p, freq)) { |
| 10275 | wpa_printf(MSG_ERROR, "P2P: Input channel not supported: %u", |
| 10276 | freq); |
| 10277 | return -1; |
| 10278 | } |
| 10279 | |
| 10280 | /* Get device type */ |
| 10281 | dev_types_len = (wpa_s->conf->num_sec_device_types + 1) * |
| 10282 | WPS_DEV_TYPE_LEN; |
| 10283 | device_types = os_malloc(dev_types_len); |
| 10284 | if (!device_types) |
| 10285 | return -1; |
| 10286 | os_memcpy(device_types, wpa_s->conf->device_type, WPS_DEV_TYPE_LEN); |
| 10287 | os_memcpy(&device_types[WPS_DEV_TYPE_LEN], wpa_s->conf->sec_device_type, |
| 10288 | wpa_s->conf->num_sec_device_types * WPS_DEV_TYPE_LEN); |
| 10289 | |
| 10290 | /* Get Probe Response IE(s) */ |
| 10291 | buf = p2p_build_probe_resp_template(p2p, freq); |
| 10292 | if (!buf) { |
| 10293 | os_free(device_types); |
| 10294 | return -1; |
| 10295 | } |
| 10296 | |
| 10297 | ret = wpa_drv_p2p_lo_start(wpa_s, freq, period, interval, count, |
| 10298 | device_types, dev_types_len, |
| 10299 | wpabuf_mhead_u8(buf), wpabuf_len(buf)); |
| 10300 | if (ret < 0) |
| 10301 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10302 | "P2P: Failed to start P2P listen offload"); |
| 10303 | |
| 10304 | os_free(device_types); |
| 10305 | wpabuf_free(buf); |
| 10306 | |
| 10307 | if (ret == 0) { |
| 10308 | wpa_s->p2p_lo_started = 1; |
| 10309 | |
| 10310 | /* Stop current P2P listen if any */ |
| 10311 | wpas_stop_listen(wpa_s); |
| 10312 | } |
| 10313 | |
| 10314 | return ret; |
| 10315 | } |
| 10316 | |
| 10317 | |
| 10318 | int wpas_p2p_lo_stop(struct wpa_supplicant *wpa_s) |
| 10319 | { |
| 10320 | int ret; |
| 10321 | |
| 10322 | if (!wpa_s->p2p_lo_started) |
| 10323 | return 0; |
| 10324 | |
| 10325 | ret = wpa_drv_p2p_lo_stop(wpa_s); |
| 10326 | if (ret < 0) |
| 10327 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10328 | "P2P: Failed to stop P2P listen offload"); |
| 10329 | |
| 10330 | wpa_s->p2p_lo_started = 0; |
| 10331 | return ret; |
| 10332 | } |