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 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1091 | wpa_config_remove_network(wpa_s->conf, id); |
| 1092 | wpa_supplicant_clear_status(wpa_s); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1093 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1094 | } else { |
| 1095 | wpa_printf(MSG_DEBUG, "P2P: Temporary group network not " |
| 1096 | "found"); |
| 1097 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1098 | if (wpa_s->ap_iface) |
| 1099 | wpa_supplicant_ap_deinit(wpa_s); |
| 1100 | else |
| 1101 | wpa_drv_deinit_p2p_cli(wpa_s); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1102 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1103 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
| 1104 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1105 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | |
| 1109 | static int wpas_p2p_persistent_group(struct wpa_supplicant *wpa_s, |
| 1110 | u8 *go_dev_addr, |
| 1111 | const u8 *ssid, size_t ssid_len) |
| 1112 | { |
| 1113 | struct wpa_bss *bss; |
| 1114 | const u8 *bssid; |
| 1115 | struct wpabuf *p2p; |
| 1116 | u8 group_capab; |
| 1117 | const u8 *addr; |
| 1118 | |
| 1119 | if (wpa_s->go_params) |
| 1120 | bssid = wpa_s->go_params->peer_interface_addr; |
| 1121 | else |
| 1122 | bssid = wpa_s->bssid; |
| 1123 | |
| 1124 | bss = wpa_bss_get(wpa_s, bssid, ssid, ssid_len); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1125 | if (bss == NULL && wpa_s->go_params && |
| 1126 | !is_zero_ether_addr(wpa_s->go_params->peer_device_addr)) |
| 1127 | bss = wpa_bss_get_p2p_dev_addr( |
| 1128 | wpa_s, wpa_s->go_params->peer_device_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1129 | if (bss == NULL) { |
| 1130 | u8 iface_addr[ETH_ALEN]; |
| 1131 | if (p2p_get_interface_addr(wpa_s->global->p2p, bssid, |
| 1132 | iface_addr) == 0) |
| 1133 | bss = wpa_bss_get(wpa_s, iface_addr, ssid, ssid_len); |
| 1134 | } |
| 1135 | if (bss == NULL) { |
| 1136 | wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether " |
| 1137 | "group is persistent - BSS " MACSTR " not found", |
| 1138 | MAC2STR(bssid)); |
| 1139 | return 0; |
| 1140 | } |
| 1141 | |
| 1142 | p2p = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE); |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1143 | if (p2p == NULL) |
| 1144 | p2p = wpa_bss_get_vendor_ie_multi_beacon(bss, |
| 1145 | P2P_IE_VENDOR_TYPE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1146 | if (p2p == NULL) { |
| 1147 | wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether " |
| 1148 | "group is persistent - BSS " MACSTR |
| 1149 | " did not include P2P IE", MAC2STR(bssid)); |
| 1150 | wpa_hexdump(MSG_DEBUG, "P2P: Probe Response IEs", |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1151 | wpa_bss_ie_ptr(bss), bss->ie_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1152 | wpa_hexdump(MSG_DEBUG, "P2P: Beacon IEs", |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1153 | wpa_bss_ie_ptr(bss) + bss->ie_len, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1154 | bss->beacon_ie_len); |
| 1155 | return 0; |
| 1156 | } |
| 1157 | |
| 1158 | group_capab = p2p_get_group_capab(p2p); |
| 1159 | addr = p2p_get_go_dev_addr(p2p); |
| 1160 | wpa_printf(MSG_DEBUG, "P2P: Checking whether group is persistent: " |
| 1161 | "group_capab=0x%x", group_capab); |
| 1162 | if (addr) { |
| 1163 | os_memcpy(go_dev_addr, addr, ETH_ALEN); |
| 1164 | wpa_printf(MSG_DEBUG, "P2P: GO Device Address " MACSTR, |
| 1165 | MAC2STR(addr)); |
| 1166 | } else |
| 1167 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 1168 | wpabuf_free(p2p); |
| 1169 | |
| 1170 | wpa_printf(MSG_DEBUG, "P2P: BSS " MACSTR " group_capab=0x%x " |
| 1171 | "go_dev_addr=" MACSTR, |
| 1172 | MAC2STR(bssid), group_capab, MAC2STR(go_dev_addr)); |
| 1173 | |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 1174 | return !!(group_capab & P2P_GROUP_CAPAB_PERSISTENT_GROUP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1178 | static int wpas_p2p_store_persistent_group(struct wpa_supplicant *wpa_s, |
| 1179 | struct wpa_ssid *ssid, |
| 1180 | const u8 *go_dev_addr) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1181 | { |
| 1182 | struct wpa_ssid *s; |
| 1183 | int changed = 0; |
| 1184 | |
| 1185 | wpa_printf(MSG_DEBUG, "P2P: Storing credentials for a persistent " |
| 1186 | "group (GO Dev Addr " MACSTR ")", MAC2STR(go_dev_addr)); |
| 1187 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 1188 | if (s->disabled == 2 && |
| 1189 | os_memcmp(go_dev_addr, s->bssid, ETH_ALEN) == 0 && |
| 1190 | s->ssid_len == ssid->ssid_len && |
| 1191 | os_memcmp(ssid->ssid, s->ssid, ssid->ssid_len) == 0) |
| 1192 | break; |
| 1193 | } |
| 1194 | |
| 1195 | if (s) { |
| 1196 | wpa_printf(MSG_DEBUG, "P2P: Update existing persistent group " |
| 1197 | "entry"); |
| 1198 | if (ssid->passphrase && !s->passphrase) |
| 1199 | changed = 1; |
| 1200 | else if (ssid->passphrase && s->passphrase && |
| 1201 | os_strcmp(ssid->passphrase, s->passphrase) != 0) |
| 1202 | changed = 1; |
| 1203 | } else { |
| 1204 | wpa_printf(MSG_DEBUG, "P2P: Create a new persistent group " |
| 1205 | "entry"); |
| 1206 | changed = 1; |
| 1207 | s = wpa_config_add_network(wpa_s->conf); |
| 1208 | if (s == NULL) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1209 | return -1; |
| 1210 | |
| 1211 | /* |
| 1212 | * Instead of network_added we emit persistent_group_added |
| 1213 | * notification. Also to keep the defense checks in |
| 1214 | * persistent_group obj registration method, we set the |
| 1215 | * relevant flags in s to designate it as a persistent group. |
| 1216 | */ |
| 1217 | s->p2p_group = 1; |
| 1218 | s->p2p_persistent_group = 1; |
| 1219 | wpas_notify_persistent_group_added(wpa_s, s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1220 | wpa_config_set_network_defaults(s); |
| 1221 | } |
| 1222 | |
| 1223 | s->p2p_group = 1; |
| 1224 | s->p2p_persistent_group = 1; |
| 1225 | s->disabled = 2; |
| 1226 | s->bssid_set = 1; |
| 1227 | os_memcpy(s->bssid, go_dev_addr, ETH_ALEN); |
| 1228 | s->mode = ssid->mode; |
| 1229 | s->auth_alg = WPA_AUTH_ALG_OPEN; |
| 1230 | s->key_mgmt = WPA_KEY_MGMT_PSK; |
| 1231 | s->proto = WPA_PROTO_RSN; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1232 | s->pbss = ssid->pbss; |
| 1233 | s->pairwise_cipher = ssid->pbss ? WPA_CIPHER_GCMP : WPA_CIPHER_CCMP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1234 | s->export_keys = 1; |
| 1235 | if (ssid->passphrase) { |
| 1236 | os_free(s->passphrase); |
| 1237 | s->passphrase = os_strdup(ssid->passphrase); |
| 1238 | } |
| 1239 | if (ssid->psk_set) { |
| 1240 | s->psk_set = 1; |
| 1241 | os_memcpy(s->psk, ssid->psk, 32); |
| 1242 | } |
| 1243 | if (s->passphrase && !s->psk_set) |
| 1244 | wpa_config_update_psk(s); |
| 1245 | if (s->ssid == NULL || s->ssid_len < ssid->ssid_len) { |
| 1246 | os_free(s->ssid); |
| 1247 | s->ssid = os_malloc(ssid->ssid_len); |
| 1248 | } |
| 1249 | if (s->ssid) { |
| 1250 | s->ssid_len = ssid->ssid_len; |
| 1251 | os_memcpy(s->ssid, ssid->ssid, s->ssid_len); |
| 1252 | } |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1253 | if (ssid->mode == WPAS_MODE_P2P_GO && wpa_s->global->add_psk) { |
| 1254 | dl_list_add(&s->psk_list, &wpa_s->global->add_psk->list); |
| 1255 | wpa_s->global->add_psk = NULL; |
| 1256 | changed = 1; |
| 1257 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1258 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1259 | if (changed && wpa_s->conf->update_config && |
| 1260 | wpa_config_write(wpa_s->confname, wpa_s->conf)) { |
| 1261 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
| 1262 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1263 | |
| 1264 | return s->id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1268 | static void wpas_p2p_add_persistent_group_client(struct wpa_supplicant *wpa_s, |
| 1269 | const u8 *addr) |
| 1270 | { |
| 1271 | struct wpa_ssid *ssid, *s; |
| 1272 | u8 *n; |
| 1273 | size_t i; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1274 | int found = 0; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1275 | 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] | 1276 | |
| 1277 | ssid = wpa_s->current_ssid; |
| 1278 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || |
| 1279 | !ssid->p2p_persistent_group) |
| 1280 | return; |
| 1281 | |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1282 | for (s = p2p_wpa_s->conf->ssid; s; s = s->next) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1283 | if (s->disabled != 2 || s->mode != WPAS_MODE_P2P_GO) |
| 1284 | continue; |
| 1285 | |
| 1286 | if (s->ssid_len == ssid->ssid_len && |
| 1287 | os_memcmp(s->ssid, ssid->ssid, s->ssid_len) == 0) |
| 1288 | break; |
| 1289 | } |
| 1290 | |
| 1291 | if (s == NULL) |
| 1292 | return; |
| 1293 | |
| 1294 | for (i = 0; s->p2p_client_list && i < s->num_p2p_clients; i++) { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1295 | if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN, addr, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1296 | ETH_ALEN) != 0) |
| 1297 | continue; |
| 1298 | |
| 1299 | if (i == s->num_p2p_clients - 1) |
| 1300 | return; /* already the most recent entry */ |
| 1301 | |
| 1302 | /* move the entry to mark it most recent */ |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1303 | os_memmove(s->p2p_client_list + i * 2 * ETH_ALEN, |
| 1304 | s->p2p_client_list + (i + 1) * 2 * ETH_ALEN, |
| 1305 | (s->num_p2p_clients - i - 1) * 2 * ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1306 | os_memcpy(s->p2p_client_list + |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1307 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN, addr, |
| 1308 | ETH_ALEN); |
| 1309 | os_memset(s->p2p_client_list + |
| 1310 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN + ETH_ALEN, |
| 1311 | 0xff, ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1312 | found = 1; |
| 1313 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1314 | } |
| 1315 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1316 | if (!found && s->num_p2p_clients < P2P_MAX_STORED_CLIENTS) { |
| 1317 | n = os_realloc_array(s->p2p_client_list, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1318 | s->num_p2p_clients + 1, 2 * ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1319 | if (n == NULL) |
| 1320 | return; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1321 | os_memcpy(n + s->num_p2p_clients * 2 * ETH_ALEN, addr, |
| 1322 | ETH_ALEN); |
| 1323 | os_memset(n + s->num_p2p_clients * 2 * ETH_ALEN + ETH_ALEN, |
| 1324 | 0xff, ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1325 | s->p2p_client_list = n; |
| 1326 | s->num_p2p_clients++; |
Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 1327 | } else if (!found && s->p2p_client_list) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1328 | /* Not enough room for an additional entry - drop the oldest |
| 1329 | * entry */ |
| 1330 | os_memmove(s->p2p_client_list, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1331 | s->p2p_client_list + 2 * ETH_ALEN, |
| 1332 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1333 | os_memcpy(s->p2p_client_list + |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1334 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1335 | addr, ETH_ALEN); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1336 | os_memset(s->p2p_client_list + |
| 1337 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN + ETH_ALEN, |
| 1338 | 0xff, ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1339 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1340 | |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1341 | if (p2p_wpa_s->conf->update_config && |
| 1342 | wpa_config_write(p2p_wpa_s->confname, p2p_wpa_s->conf)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1343 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1347 | static void wpas_p2p_group_started(struct wpa_supplicant *wpa_s, |
| 1348 | int go, struct wpa_ssid *ssid, int freq, |
| 1349 | const u8 *psk, const char *passphrase, |
| 1350 | const u8 *go_dev_addr, int persistent, |
| 1351 | const char *extra) |
| 1352 | { |
| 1353 | const char *ssid_txt; |
| 1354 | char psk_txt[65]; |
| 1355 | |
| 1356 | if (psk) |
| 1357 | wpa_snprintf_hex(psk_txt, sizeof(psk_txt), psk, 32); |
| 1358 | else |
| 1359 | psk_txt[0] = '\0'; |
| 1360 | |
| 1361 | if (ssid) |
| 1362 | ssid_txt = wpa_ssid_txt(ssid->ssid, ssid->ssid_len); |
| 1363 | else |
| 1364 | ssid_txt = ""; |
| 1365 | |
| 1366 | if (passphrase && passphrase[0] == '\0') |
| 1367 | passphrase = NULL; |
| 1368 | |
| 1369 | /* |
| 1370 | * Include PSK/passphrase only in the control interface message and |
| 1371 | * leave it out from the debug log entry. |
| 1372 | */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1373 | wpa_msg_global_ctrl(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1374 | P2P_EVENT_GROUP_STARTED |
| 1375 | "%s %s ssid=\"%s\" freq=%d%s%s%s%s%s go_dev_addr=" |
| 1376 | MACSTR "%s%s", |
| 1377 | wpa_s->ifname, go ? "GO" : "client", ssid_txt, freq, |
| 1378 | psk ? " psk=" : "", psk_txt, |
| 1379 | passphrase ? " passphrase=\"" : "", |
| 1380 | passphrase ? passphrase : "", |
| 1381 | passphrase ? "\"" : "", |
| 1382 | MAC2STR(go_dev_addr), |
| 1383 | persistent ? " [PERSISTENT]" : "", extra); |
| 1384 | wpa_printf(MSG_INFO, P2P_EVENT_GROUP_STARTED |
| 1385 | "%s %s ssid=\"%s\" freq=%d go_dev_addr=" MACSTR "%s%s", |
| 1386 | wpa_s->ifname, go ? "GO" : "client", ssid_txt, freq, |
| 1387 | MAC2STR(go_dev_addr), persistent ? " [PERSISTENT]" : "", |
| 1388 | extra); |
| 1389 | } |
| 1390 | |
| 1391 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1392 | static void wpas_group_formation_completed(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 1393 | int success, int already_deleted) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1394 | { |
| 1395 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1396 | int client; |
| 1397 | int persistent; |
| 1398 | u8 go_dev_addr[ETH_ALEN]; |
| 1399 | |
| 1400 | /* |
| 1401 | * This callback is likely called for the main interface. Update wpa_s |
| 1402 | * to use the group interface if a new interface was created for the |
| 1403 | * group. |
| 1404 | */ |
| 1405 | if (wpa_s->global->p2p_group_formation) |
| 1406 | wpa_s = wpa_s->global->p2p_group_formation; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1407 | if (wpa_s->p2p_go_group_formation_completed) { |
| 1408 | wpa_s->global->p2p_group_formation = NULL; |
| 1409 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1410 | } else if (wpa_s->p2p_in_provisioning && !success) { |
| 1411 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1412 | "P2P: Stop provisioning state due to failure"); |
| 1413 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1414 | } |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 1415 | wpa_s->p2p_in_invitation = 0; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 1416 | wpa_s->p2p_retry_limit = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1417 | wpa_s->group_formation_reported = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1418 | |
| 1419 | if (!success) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1420 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1421 | P2P_EVENT_GROUP_FORMATION_FAILURE); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1422 | wpas_notify_p2p_group_formation_failure(wpa_s, ""); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 1423 | if (already_deleted) |
| 1424 | return; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1425 | wpas_p2p_group_delete(wpa_s, |
| 1426 | P2P_GROUP_REMOVAL_FORMATION_FAILED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1427 | return; |
| 1428 | } |
| 1429 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1430 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1431 | P2P_EVENT_GROUP_FORMATION_SUCCESS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1432 | |
| 1433 | ssid = wpa_s->current_ssid; |
| 1434 | if (ssid && ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) { |
| 1435 | ssid->mode = WPAS_MODE_P2P_GO; |
| 1436 | p2p_group_notif_formation_done(wpa_s->p2p_group); |
| 1437 | wpa_supplicant_ap_mac_addr_filter(wpa_s, NULL); |
| 1438 | } |
| 1439 | |
| 1440 | persistent = 0; |
| 1441 | if (ssid) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1442 | client = ssid->mode == WPAS_MODE_INFRA; |
| 1443 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 1444 | persistent = ssid->p2p_persistent_group; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 1445 | os_memcpy(go_dev_addr, wpa_s->global->p2p_dev_addr, |
| 1446 | ETH_ALEN); |
George Burgess IV | 0d2d1bf | 2021-11-01 03:08:33 -0700 | [diff] [blame] | 1447 | } else { |
| 1448 | os_memset(go_dev_addr, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1449 | persistent = wpas_p2p_persistent_group(wpa_s, |
| 1450 | go_dev_addr, |
| 1451 | ssid->ssid, |
| 1452 | ssid->ssid_len); |
George Burgess IV | 0d2d1bf | 2021-11-01 03:08:33 -0700 | [diff] [blame] | 1453 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1454 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1455 | client = wpa_s->p2p_group_interface == |
| 1456 | P2P_GROUP_INTERFACE_CLIENT; |
| 1457 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 1458 | } |
| 1459 | |
| 1460 | wpa_s->show_group_started = 0; |
| 1461 | if (client) { |
| 1462 | /* |
| 1463 | * Indicate event only after successfully completed 4-way |
| 1464 | * handshake, i.e., when the interface is ready for data |
| 1465 | * packets. |
| 1466 | */ |
| 1467 | wpa_s->show_group_started = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1468 | } else { |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1469 | wpas_p2p_group_started(wpa_s, 1, ssid, |
| 1470 | ssid ? ssid->frequency : 0, |
| 1471 | ssid && ssid->passphrase == NULL && |
| 1472 | ssid->psk_set ? ssid->psk : NULL, |
| 1473 | ssid ? ssid->passphrase : NULL, |
| 1474 | go_dev_addr, persistent, ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1475 | wpas_p2p_cross_connect_setup(wpa_s); |
| 1476 | wpas_p2p_set_group_idle_timeout(wpa_s); |
| 1477 | } |
| 1478 | |
| 1479 | if (persistent) |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1480 | wpas_p2p_store_persistent_group(wpa_s->p2pdev, |
| 1481 | ssid, go_dev_addr); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1482 | else { |
| 1483 | os_free(wpa_s->global->add_psk); |
| 1484 | wpa_s->global->add_psk = NULL; |
| 1485 | } |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1486 | |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 1487 | if (!client) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1488 | wpas_notify_p2p_group_started(wpa_s, ssid, persistent, 0, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1489 | os_get_reltime(&wpa_s->global->p2p_go_wait_client); |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 1490 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1494 | struct send_action_work { |
| 1495 | unsigned int freq; |
| 1496 | u8 dst[ETH_ALEN]; |
| 1497 | u8 src[ETH_ALEN]; |
| 1498 | u8 bssid[ETH_ALEN]; |
| 1499 | size_t len; |
| 1500 | unsigned int wait_time; |
| 1501 | u8 buf[0]; |
| 1502 | }; |
| 1503 | |
| 1504 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1505 | static void wpas_p2p_free_send_action_work(struct wpa_supplicant *wpa_s) |
| 1506 | { |
| 1507 | struct send_action_work *awork = wpa_s->p2p_send_action_work->ctx; |
| 1508 | |
| 1509 | wpa_printf(MSG_DEBUG, |
| 1510 | "P2P: Free Action frame radio work @%p (freq=%u dst=" |
| 1511 | MACSTR " src=" MACSTR " bssid=" MACSTR " wait_time=%u)", |
| 1512 | wpa_s->p2p_send_action_work, awork->freq, |
| 1513 | MAC2STR(awork->dst), MAC2STR(awork->src), |
| 1514 | MAC2STR(awork->bssid), awork->wait_time); |
| 1515 | wpa_hexdump(MSG_DEBUG, "P2P: Freeing pending Action frame", |
| 1516 | awork->buf, awork->len); |
| 1517 | os_free(awork); |
| 1518 | wpa_s->p2p_send_action_work->ctx = NULL; |
| 1519 | radio_work_done(wpa_s->p2p_send_action_work); |
| 1520 | wpa_s->p2p_send_action_work = NULL; |
| 1521 | } |
| 1522 | |
| 1523 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1524 | static void wpas_p2p_send_action_work_timeout(void *eloop_ctx, |
| 1525 | void *timeout_ctx) |
| 1526 | { |
| 1527 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 1528 | |
| 1529 | if (!wpa_s->p2p_send_action_work) |
| 1530 | return; |
| 1531 | |
| 1532 | wpa_printf(MSG_DEBUG, "P2P: Send Action frame radio work timed out"); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1533 | wpas_p2p_free_send_action_work(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 1537 | static void wpas_p2p_action_tx_clear(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1538 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1539 | if (wpa_s->p2p_send_action_work) { |
| 1540 | struct send_action_work *awork; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1541 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1542 | awork = wpa_s->p2p_send_action_work->ctx; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1543 | wpa_printf(MSG_DEBUG, |
| 1544 | "P2P: Clear Action TX work @%p (wait_time=%u)", |
| 1545 | wpa_s->p2p_send_action_work, awork->wait_time); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1546 | if (awork->wait_time == 0) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1547 | wpas_p2p_free_send_action_work(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1548 | } else { |
| 1549 | /* |
| 1550 | * In theory, this should not be needed, but number of |
| 1551 | * places in the P2P code is still using non-zero wait |
| 1552 | * time for the last Action frame in the sequence and |
| 1553 | * some of these do not call send_action_done(). |
| 1554 | */ |
| 1555 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 1556 | wpa_s, NULL); |
| 1557 | eloop_register_timeout( |
| 1558 | 0, awork->wait_time * 1000, |
| 1559 | wpas_p2p_send_action_work_timeout, |
| 1560 | wpa_s, NULL); |
| 1561 | } |
| 1562 | } |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | |
| 1566 | static void wpas_p2p_send_action_tx_status(struct wpa_supplicant *wpa_s, |
| 1567 | unsigned int freq, |
| 1568 | const u8 *dst, const u8 *src, |
| 1569 | const u8 *bssid, |
| 1570 | const u8 *data, size_t data_len, |
| 1571 | enum offchannel_send_action_result |
| 1572 | result) |
| 1573 | { |
| 1574 | enum p2p_send_action_result res = P2P_SEND_ACTION_SUCCESS; |
| 1575 | |
| 1576 | wpas_p2p_action_tx_clear(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1577 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1578 | if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) |
| 1579 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1580 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1581 | switch (result) { |
| 1582 | case OFFCHANNEL_SEND_ACTION_SUCCESS: |
| 1583 | res = P2P_SEND_ACTION_SUCCESS; |
| 1584 | break; |
| 1585 | case OFFCHANNEL_SEND_ACTION_NO_ACK: |
| 1586 | res = P2P_SEND_ACTION_NO_ACK; |
| 1587 | break; |
| 1588 | case OFFCHANNEL_SEND_ACTION_FAILED: |
| 1589 | res = P2P_SEND_ACTION_FAILED; |
| 1590 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1591 | } |
| 1592 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1593 | 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] | 1594 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1595 | if (result != OFFCHANNEL_SEND_ACTION_SUCCESS && |
| 1596 | wpa_s->pending_pd_before_join && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1597 | (os_memcmp(dst, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 || |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1598 | os_memcmp(dst, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0) && |
| 1599 | wpa_s->p2p_fallback_to_go_neg) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1600 | wpa_s->pending_pd_before_join = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1601 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No ACK for PD Req " |
| 1602 | "during p2p_connect-auto"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1603 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1604 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 1605 | "reason=no-ACK-to-PD-Req"); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1606 | wpas_p2p_fallback_to_go_neg(wpa_s, 0); |
| 1607 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1612 | static void wpas_send_action_cb(struct wpa_radio_work *work, int deinit) |
| 1613 | { |
| 1614 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 1615 | struct send_action_work *awork = work->ctx; |
| 1616 | |
| 1617 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 1618 | if (work->started) { |
| 1619 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 1620 | wpa_s, NULL); |
| 1621 | wpa_s->p2p_send_action_work = NULL; |
| 1622 | offchannel_send_action_done(wpa_s); |
| 1623 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1624 | os_free(awork); |
| 1625 | return; |
| 1626 | } |
| 1627 | |
| 1628 | if (offchannel_send_action(wpa_s, awork->freq, awork->dst, awork->src, |
| 1629 | awork->bssid, awork->buf, awork->len, |
| 1630 | awork->wait_time, |
| 1631 | wpas_p2p_send_action_tx_status, 1) < 0) { |
| 1632 | os_free(awork); |
| 1633 | radio_work_done(work); |
| 1634 | return; |
| 1635 | } |
| 1636 | wpa_s->p2p_send_action_work = work; |
| 1637 | } |
| 1638 | |
| 1639 | |
| 1640 | static int wpas_send_action_work(struct wpa_supplicant *wpa_s, |
| 1641 | unsigned int freq, const u8 *dst, |
| 1642 | const u8 *src, const u8 *bssid, const u8 *buf, |
| 1643 | size_t len, unsigned int wait_time) |
| 1644 | { |
| 1645 | struct send_action_work *awork; |
| 1646 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1647 | if (radio_work_pending(wpa_s, "p2p-send-action")) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1648 | wpa_printf(MSG_DEBUG, "P2P: Cannot schedule new p2p-send-action work since one is already pending"); |
| 1649 | return -1; |
| 1650 | } |
| 1651 | |
| 1652 | awork = os_zalloc(sizeof(*awork) + len); |
| 1653 | if (awork == NULL) |
| 1654 | return -1; |
| 1655 | |
| 1656 | awork->freq = freq; |
| 1657 | os_memcpy(awork->dst, dst, ETH_ALEN); |
| 1658 | os_memcpy(awork->src, src, ETH_ALEN); |
| 1659 | os_memcpy(awork->bssid, bssid, ETH_ALEN); |
| 1660 | awork->len = len; |
| 1661 | awork->wait_time = wait_time; |
| 1662 | os_memcpy(awork->buf, buf, len); |
| 1663 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1664 | if (radio_add_work(wpa_s, freq, "p2p-send-action", 1, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1665 | wpas_send_action_cb, awork) < 0) { |
| 1666 | os_free(awork); |
| 1667 | return -1; |
| 1668 | } |
| 1669 | |
| 1670 | return 0; |
| 1671 | } |
| 1672 | |
| 1673 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1674 | static int wpas_send_action(void *ctx, unsigned int freq, const u8 *dst, |
| 1675 | const u8 *src, const u8 *bssid, const u8 *buf, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1676 | size_t len, unsigned int wait_time, int *scheduled) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1677 | { |
| 1678 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1679 | int listen_freq = -1, send_freq = -1; |
| 1680 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1681 | if (scheduled) |
| 1682 | *scheduled = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1683 | if (wpa_s->p2p_listen_work) |
| 1684 | listen_freq = wpa_s->p2p_listen_work->freq; |
| 1685 | if (wpa_s->p2p_send_action_work) |
| 1686 | send_freq = wpa_s->p2p_send_action_work->freq; |
| 1687 | if (listen_freq != (int) freq && send_freq != (int) freq) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1688 | int res; |
| 1689 | |
| 1690 | wpa_printf(MSG_DEBUG, "P2P: Schedule new radio work for Action frame TX (listen_freq=%d send_freq=%d freq=%u)", |
| 1691 | listen_freq, send_freq, freq); |
| 1692 | res = wpas_send_action_work(wpa_s, freq, dst, src, bssid, buf, |
| 1693 | len, wait_time); |
| 1694 | if (res == 0 && scheduled) |
| 1695 | *scheduled = 1; |
| 1696 | return res; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1697 | } |
| 1698 | |
| 1699 | 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] | 1700 | return offchannel_send_action(wpa_s, freq, dst, src, bssid, buf, len, |
| 1701 | wait_time, |
| 1702 | wpas_p2p_send_action_tx_status, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | |
| 1706 | static void wpas_send_action_done(void *ctx) |
| 1707 | { |
| 1708 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1709 | |
| 1710 | if (wpa_s->p2p_send_action_work) { |
| 1711 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 1712 | wpa_s, NULL); |
| 1713 | os_free(wpa_s->p2p_send_action_work->ctx); |
| 1714 | radio_work_done(wpa_s->p2p_send_action_work); |
| 1715 | wpa_s->p2p_send_action_work = NULL; |
| 1716 | } |
| 1717 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1718 | offchannel_send_action_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | |
| 1722 | static int wpas_copy_go_neg_results(struct wpa_supplicant *wpa_s, |
| 1723 | struct p2p_go_neg_results *params) |
| 1724 | { |
| 1725 | if (wpa_s->go_params == NULL) { |
| 1726 | wpa_s->go_params = os_malloc(sizeof(*params)); |
| 1727 | if (wpa_s->go_params == NULL) |
| 1728 | return -1; |
| 1729 | } |
| 1730 | os_memcpy(wpa_s->go_params, params, sizeof(*params)); |
| 1731 | return 0; |
| 1732 | } |
| 1733 | |
| 1734 | |
| 1735 | static void wpas_start_wps_enrollee(struct wpa_supplicant *wpa_s, |
| 1736 | struct p2p_go_neg_results *res) |
| 1737 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1738 | wpa_s->group_formation_reported = 0; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1739 | wpa_printf(MSG_DEBUG, "P2P: Start WPS Enrollee for peer " MACSTR |
| 1740 | " dev_addr " MACSTR " wps_method %d", |
| 1741 | MAC2STR(res->peer_interface_addr), |
| 1742 | MAC2STR(res->peer_device_addr), res->wps_method); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1743 | wpa_hexdump_ascii(MSG_DEBUG, "P2P: Start WPS Enrollee for SSID", |
| 1744 | res->ssid, res->ssid_len); |
| 1745 | wpa_supplicant_ap_deinit(wpa_s); |
| 1746 | wpas_copy_go_neg_results(wpa_s, res); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1747 | if (res->wps_method == WPS_PBC) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1748 | wpas_wps_start_pbc(wpa_s, res->peer_interface_addr, 1, 0); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1749 | #ifdef CONFIG_WPS_NFC |
| 1750 | } else if (res->wps_method == WPS_NFC) { |
| 1751 | wpas_wps_start_nfc(wpa_s, res->peer_device_addr, |
| 1752 | res->peer_interface_addr, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1753 | wpa_s->p2pdev->p2p_oob_dev_pw, |
| 1754 | wpa_s->p2pdev->p2p_oob_dev_pw_id, 1, |
| 1755 | wpa_s->p2pdev->p2p_oob_dev_pw_id == |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1756 | DEV_PW_NFC_CONNECTION_HANDOVER ? |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1757 | wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1758 | NULL, |
| 1759 | NULL, 0, 0); |
| 1760 | #endif /* CONFIG_WPS_NFC */ |
| 1761 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1762 | u16 dev_pw_id = DEV_PW_DEFAULT; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1763 | if (wpa_s->p2p_wps_method == WPS_P2PS) |
| 1764 | dev_pw_id = DEV_PW_P2PS_DEFAULT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1765 | if (wpa_s->p2p_wps_method == WPS_PIN_KEYPAD) |
| 1766 | dev_pw_id = DEV_PW_REGISTRAR_SPECIFIED; |
| 1767 | wpas_wps_start_pin(wpa_s, res->peer_interface_addr, |
| 1768 | wpa_s->p2p_pin, 1, dev_pw_id); |
| 1769 | } |
| 1770 | } |
| 1771 | |
| 1772 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1773 | static void wpas_p2p_add_psk_list(struct wpa_supplicant *wpa_s, |
| 1774 | struct wpa_ssid *ssid) |
| 1775 | { |
| 1776 | struct wpa_ssid *persistent; |
| 1777 | struct psk_list_entry *psk; |
| 1778 | struct hostapd_data *hapd; |
| 1779 | |
| 1780 | if (!wpa_s->ap_iface) |
| 1781 | return; |
| 1782 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1783 | persistent = wpas_p2p_get_persistent(wpa_s->p2pdev, NULL, ssid->ssid, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1784 | ssid->ssid_len); |
| 1785 | if (persistent == NULL) |
| 1786 | return; |
| 1787 | |
| 1788 | hapd = wpa_s->ap_iface->bss[0]; |
| 1789 | |
| 1790 | dl_list_for_each(psk, &persistent->psk_list, struct psk_list_entry, |
| 1791 | list) { |
| 1792 | struct hostapd_wpa_psk *hpsk; |
| 1793 | |
| 1794 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add persistent group PSK entry for " |
| 1795 | MACSTR " psk=%d", |
| 1796 | MAC2STR(psk->addr), psk->p2p); |
| 1797 | hpsk = os_zalloc(sizeof(*hpsk)); |
| 1798 | if (hpsk == NULL) |
| 1799 | break; |
| 1800 | os_memcpy(hpsk->psk, psk->psk, PMK_LEN); |
| 1801 | if (psk->p2p) |
| 1802 | os_memcpy(hpsk->p2p_dev_addr, psk->addr, ETH_ALEN); |
| 1803 | else |
| 1804 | os_memcpy(hpsk->addr, psk->addr, ETH_ALEN); |
| 1805 | hpsk->next = hapd->conf->ssid.wpa_psk; |
| 1806 | hapd->conf->ssid.wpa_psk = hpsk; |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1811 | static void p2p_go_dump_common_freqs(struct wpa_supplicant *wpa_s) |
| 1812 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1813 | char buf[20 + P2P_MAX_CHANNELS * 6]; |
| 1814 | char *pos, *end; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1815 | unsigned int i; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1816 | int res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1817 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1818 | pos = buf; |
| 1819 | end = pos + sizeof(buf); |
| 1820 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 1821 | res = os_snprintf(pos, end - pos, " %d", |
| 1822 | wpa_s->p2p_group_common_freqs[i]); |
| 1823 | if (os_snprintf_error(end - pos, res)) |
| 1824 | break; |
| 1825 | pos += res; |
| 1826 | } |
| 1827 | *pos = '\0'; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1828 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1829 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Common group frequencies:%s", buf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | |
| 1833 | static void p2p_go_save_group_common_freqs(struct wpa_supplicant *wpa_s, |
| 1834 | struct p2p_go_neg_results *params) |
| 1835 | { |
| 1836 | unsigned int i, len = int_array_len(wpa_s->go_params->freq_list); |
| 1837 | |
| 1838 | wpa_s->p2p_group_common_freqs_num = 0; |
| 1839 | os_free(wpa_s->p2p_group_common_freqs); |
| 1840 | wpa_s->p2p_group_common_freqs = os_calloc(len, sizeof(int)); |
| 1841 | if (!wpa_s->p2p_group_common_freqs) |
| 1842 | return; |
| 1843 | |
| 1844 | for (i = 0; i < len; i++) { |
| 1845 | if (!wpa_s->go_params->freq_list[i]) |
| 1846 | break; |
| 1847 | wpa_s->p2p_group_common_freqs[i] = |
| 1848 | wpa_s->go_params->freq_list[i]; |
| 1849 | } |
| 1850 | wpa_s->p2p_group_common_freqs_num = i; |
| 1851 | } |
| 1852 | |
| 1853 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1854 | static void p2p_config_write(struct wpa_supplicant *wpa_s) |
| 1855 | { |
| 1856 | #ifndef CONFIG_NO_CONFIG_WRITE |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1857 | if (wpa_s->p2pdev->conf->update_config && |
| 1858 | wpa_config_write(wpa_s->p2pdev->confname, wpa_s->p2pdev->conf)) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1859 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
| 1860 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 1861 | } |
| 1862 | |
| 1863 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1864 | static void p2p_go_configured(void *ctx, void *data) |
| 1865 | { |
| 1866 | struct wpa_supplicant *wpa_s = ctx; |
| 1867 | struct p2p_go_neg_results *params = data; |
| 1868 | struct wpa_ssid *ssid; |
| 1869 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 1870 | wpa_s->ap_configured_cb = NULL; |
| 1871 | wpa_s->ap_configured_cb_ctx = NULL; |
| 1872 | wpa_s->ap_configured_cb_data = NULL; |
| 1873 | if (!wpa_s->go_params) { |
| 1874 | wpa_printf(MSG_ERROR, |
| 1875 | "P2P: p2p_go_configured() called with wpa_s->go_params == NULL"); |
| 1876 | return; |
| 1877 | } |
| 1878 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1879 | p2p_go_save_group_common_freqs(wpa_s, params); |
| 1880 | p2p_go_dump_common_freqs(wpa_s); |
| 1881 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1882 | ssid = wpa_s->current_ssid; |
| 1883 | if (ssid && ssid->mode == WPAS_MODE_P2P_GO) { |
| 1884 | wpa_printf(MSG_DEBUG, "P2P: Group setup without provisioning"); |
| 1885 | if (wpa_s->global->p2p_group_formation == wpa_s) |
| 1886 | wpa_s->global->p2p_group_formation = NULL; |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1887 | wpas_p2p_group_started(wpa_s, 1, ssid, ssid->frequency, |
| 1888 | params->passphrase[0] == '\0' ? |
| 1889 | params->psk : NULL, |
| 1890 | params->passphrase, |
| 1891 | wpa_s->global->p2p_dev_addr, |
| 1892 | params->persistent_group, ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1893 | wpa_s->group_formation_reported = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1894 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1895 | if (wpa_s->p2pdev->p2ps_method_config_any) { |
| 1896 | if (is_zero_ether_addr(wpa_s->p2pdev->p2ps_join_addr)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1897 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1898 | "P2PS: Setting default PIN for ANY"); |
| 1899 | wpa_supplicant_ap_wps_pin(wpa_s, NULL, |
| 1900 | "12345670", NULL, 0, |
| 1901 | 0); |
| 1902 | } else { |
| 1903 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1904 | "P2PS: Setting default PIN for " MACSTR, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1905 | MAC2STR(wpa_s->p2pdev->p2ps_join_addr)); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1906 | wpa_supplicant_ap_wps_pin( |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1907 | wpa_s, wpa_s->p2pdev->p2ps_join_addr, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1908 | "12345670", NULL, 0, 0); |
| 1909 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1910 | wpa_s->p2pdev->p2ps_method_config_any = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1911 | } |
| 1912 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1913 | os_get_reltime(&wpa_s->global->p2p_go_wait_client); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1914 | if (params->persistent_group) { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1915 | wpas_p2p_store_persistent_group( |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1916 | wpa_s->p2pdev, ssid, |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 1917 | wpa_s->global->p2p_dev_addr); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1918 | wpas_p2p_add_psk_list(wpa_s, ssid); |
| 1919 | } |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1920 | |
| 1921 | wpas_notify_p2p_group_started(wpa_s, ssid, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1922 | params->persistent_group, 0, |
| 1923 | NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1924 | wpas_p2p_cross_connect_setup(wpa_s); |
| 1925 | wpas_p2p_set_group_idle_timeout(wpa_s); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1926 | |
| 1927 | if (wpa_s->p2p_first_connection_timeout) { |
| 1928 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1929 | "P2P: Start group formation timeout of %d seconds until first data connection on GO", |
| 1930 | wpa_s->p2p_first_connection_timeout); |
| 1931 | wpa_s->p2p_go_group_formation_completed = 0; |
| 1932 | wpa_s->global->p2p_group_formation = wpa_s; |
| 1933 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1934 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1935 | eloop_register_timeout( |
| 1936 | wpa_s->p2p_first_connection_timeout, 0, |
| 1937 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1938 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1941 | return; |
| 1942 | } |
| 1943 | |
| 1944 | wpa_printf(MSG_DEBUG, "P2P: Setting up WPS for GO provisioning"); |
| 1945 | if (wpa_supplicant_ap_mac_addr_filter(wpa_s, |
| 1946 | params->peer_interface_addr)) { |
| 1947 | wpa_printf(MSG_DEBUG, "P2P: Failed to setup MAC address " |
| 1948 | "filtering"); |
| 1949 | return; |
| 1950 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1951 | if (params->wps_method == WPS_PBC) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1952 | wpa_supplicant_ap_wps_pbc(wpa_s, params->peer_interface_addr, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1953 | params->peer_device_addr); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1954 | #ifdef CONFIG_WPS_NFC |
| 1955 | } else if (params->wps_method == WPS_NFC) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1956 | if (wpa_s->p2pdev->p2p_oob_dev_pw_id != |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1957 | DEV_PW_NFC_CONNECTION_HANDOVER && |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1958 | !wpa_s->p2pdev->p2p_oob_dev_pw) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1959 | wpa_printf(MSG_DEBUG, "P2P: No NFC Dev Pw known"); |
| 1960 | return; |
| 1961 | } |
| 1962 | wpas_ap_wps_add_nfc_pw( |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1963 | wpa_s, wpa_s->p2pdev->p2p_oob_dev_pw_id, |
| 1964 | wpa_s->p2pdev->p2p_oob_dev_pw, |
| 1965 | wpa_s->p2pdev->p2p_peer_oob_pk_hash_known ? |
| 1966 | wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : NULL); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1967 | #endif /* CONFIG_WPS_NFC */ |
| 1968 | } else if (wpa_s->p2p_pin[0]) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1969 | wpa_supplicant_ap_wps_pin(wpa_s, params->peer_interface_addr, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1970 | wpa_s->p2p_pin, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1971 | os_free(wpa_s->go_params); |
| 1972 | wpa_s->go_params = NULL; |
| 1973 | } |
| 1974 | |
| 1975 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1976 | /** |
| 1977 | * wpas_p2p_freq_to_edmg_channel - Convert frequency into EDMG channel |
| 1978 | * @freq: Frequency (MHz) to convert |
| 1979 | * @op_class: Buffer for returning operating class |
| 1980 | * @op_edmg_channel: Buffer for returning channel number |
| 1981 | * Returns: 0 on success, -1 on failure |
| 1982 | * |
| 1983 | * This can be used to find the highest channel bonding which includes the |
| 1984 | * specified frequency. |
| 1985 | */ |
| 1986 | static int wpas_p2p_freq_to_edmg_channel(struct wpa_supplicant *wpa_s, |
| 1987 | unsigned int freq, |
| 1988 | u8 *op_class, u8 *op_edmg_channel) |
| 1989 | { |
| 1990 | struct hostapd_hw_modes *hwmode; |
| 1991 | struct ieee80211_edmg_config edmg; |
| 1992 | unsigned int i; |
| 1993 | enum chan_width chanwidth[] = { |
| 1994 | CHAN_WIDTH_8640, |
| 1995 | CHAN_WIDTH_6480, |
| 1996 | CHAN_WIDTH_4320, |
| 1997 | }; |
| 1998 | |
| 1999 | if (!wpa_s->hw.modes) |
| 2000 | return -1; |
| 2001 | |
| 2002 | hwmode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2003 | HOSTAPD_MODE_IEEE80211AD, false); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2004 | if (!hwmode) { |
| 2005 | wpa_printf(MSG_ERROR, |
| 2006 | "Unsupported AP mode: HOSTAPD_MODE_IEEE80211AD"); |
| 2007 | return -1; |
| 2008 | } |
| 2009 | |
| 2010 | /* Find the highest EDMG channel bandwidth to start the P2P GO */ |
| 2011 | for (i = 0; i < ARRAY_SIZE(chanwidth); i++) { |
| 2012 | if (ieee80211_chaninfo_to_channel(freq, chanwidth[i], 0, |
| 2013 | op_class, |
| 2014 | op_edmg_channel) < 0) |
| 2015 | continue; |
| 2016 | |
| 2017 | hostapd_encode_edmg_chan(1, *op_edmg_channel, 0, &edmg); |
| 2018 | if (edmg.channels && |
| 2019 | ieee802_edmg_is_allowed(hwmode->edmg, edmg)) { |
| 2020 | wpa_printf(MSG_DEBUG, |
| 2021 | "Freq %u to EDMG channel %u at opclass %u", |
| 2022 | freq, *op_edmg_channel, *op_class); |
| 2023 | return 0; |
| 2024 | } |
| 2025 | } |
| 2026 | |
| 2027 | return -1; |
| 2028 | } |
| 2029 | |
| 2030 | |
| 2031 | int wpas_p2p_try_edmg_channel(struct wpa_supplicant *wpa_s, |
| 2032 | struct p2p_go_neg_results *params) |
| 2033 | { |
| 2034 | u8 op_channel, op_class; |
| 2035 | int freq; |
| 2036 | |
| 2037 | /* Try social channel as primary channel frequency */ |
| 2038 | freq = (!params->freq) ? 58320 + 1 * 2160 : params->freq; |
| 2039 | |
| 2040 | if (wpas_p2p_freq_to_edmg_channel(wpa_s, freq, &op_class, |
| 2041 | &op_channel) == 0) { |
| 2042 | wpa_printf(MSG_DEBUG, |
| 2043 | "Freq %d will be used to set an EDMG connection (channel=%u opclass=%u)", |
| 2044 | freq, op_channel, op_class); |
| 2045 | params->freq = freq; |
| 2046 | return 0; |
| 2047 | } |
| 2048 | |
| 2049 | return -1; |
| 2050 | } |
| 2051 | |
| 2052 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2053 | static void wpas_start_wps_go(struct wpa_supplicant *wpa_s, |
| 2054 | struct p2p_go_neg_results *params, |
| 2055 | int group_formation) |
| 2056 | { |
| 2057 | struct wpa_ssid *ssid; |
| 2058 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2059 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Starting GO"); |
| 2060 | if (wpas_copy_go_neg_results(wpa_s, params) < 0) { |
| 2061 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not copy GO Negotiation " |
| 2062 | "results"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2063 | return; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2064 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2065 | |
| 2066 | ssid = wpa_config_add_network(wpa_s->conf); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2067 | if (ssid == NULL) { |
| 2068 | 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] | 2069 | return; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2070 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2071 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2072 | wpa_s->show_group_started = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2073 | wpa_s->p2p_go_group_formation_completed = 0; |
| 2074 | wpa_s->group_formation_reported = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2075 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2076 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2077 | wpa_config_set_network_defaults(ssid); |
| 2078 | ssid->temporary = 1; |
| 2079 | ssid->p2p_group = 1; |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 2080 | ssid->p2p_persistent_group = !!params->persistent_group; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2081 | ssid->mode = group_formation ? WPAS_MODE_P2P_GROUP_FORMATION : |
| 2082 | WPAS_MODE_P2P_GO; |
| 2083 | ssid->frequency = params->freq; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2084 | ssid->ht40 = params->ht40; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2085 | ssid->vht = params->vht; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 2086 | ssid->max_oper_chwidth = params->max_oper_chwidth; |
| 2087 | ssid->vht_center_freq2 = params->vht_center_freq2; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2088 | ssid->he = params->he; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2089 | if (params->edmg) { |
| 2090 | u8 op_channel, op_class; |
| 2091 | |
| 2092 | if (!wpas_p2p_freq_to_edmg_channel(wpa_s, params->freq, |
| 2093 | &op_class, &op_channel)) { |
| 2094 | ssid->edmg_channel = op_channel; |
| 2095 | ssid->enable_edmg = params->edmg; |
| 2096 | } else { |
| 2097 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2098 | "P2P: Could not match EDMG channel, freq %d, for GO", |
| 2099 | params->freq); |
| 2100 | } |
| 2101 | } |
| 2102 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2103 | ssid->ssid = os_zalloc(params->ssid_len + 1); |
| 2104 | if (ssid->ssid) { |
| 2105 | os_memcpy(ssid->ssid, params->ssid, params->ssid_len); |
| 2106 | ssid->ssid_len = params->ssid_len; |
| 2107 | } |
| 2108 | ssid->auth_alg = WPA_AUTH_ALG_OPEN; |
| 2109 | ssid->key_mgmt = WPA_KEY_MGMT_PSK; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2110 | if (is_6ghz_freq(ssid->frequency) && |
| 2111 | is_p2p_6ghz_capable(wpa_s->global->p2p)) { |
| 2112 | ssid->auth_alg |= WPA_AUTH_ALG_SAE; |
| 2113 | ssid->key_mgmt = WPA_KEY_MGMT_SAE; |
| 2114 | ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2115 | ssid->sae_pwe = SAE_PWE_HASH_TO_ELEMENT; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2116 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use SAE auth_alg and key_mgmt"); |
| 2117 | } else { |
| 2118 | p2p_set_6ghz_dev_capab(wpa_s->global->p2p, false); |
| 2119 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2120 | ssid->proto = WPA_PROTO_RSN; |
| 2121 | ssid->pairwise_cipher = WPA_CIPHER_CCMP; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2122 | ssid->group_cipher = WPA_CIPHER_CCMP; |
| 2123 | if (params->freq > 56160) { |
| 2124 | /* |
| 2125 | * Enable GCMP instead of CCMP as pairwise_cipher and |
| 2126 | * group_cipher in 60 GHz. |
| 2127 | */ |
| 2128 | ssid->pairwise_cipher = WPA_CIPHER_GCMP; |
| 2129 | ssid->group_cipher = WPA_CIPHER_GCMP; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2130 | /* P2P GO in 60 GHz is always a PCP (PBSS) */ |
| 2131 | ssid->pbss = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2132 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2133 | if (os_strlen(params->passphrase) > 0) { |
| 2134 | ssid->passphrase = os_strdup(params->passphrase); |
| 2135 | if (ssid->passphrase == NULL) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2136 | wpa_msg_global(wpa_s, MSG_ERROR, |
| 2137 | "P2P: Failed to copy passphrase for GO"); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2138 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 2139 | return; |
| 2140 | } |
| 2141 | } else |
| 2142 | ssid->passphrase = NULL; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2143 | ssid->psk_set = params->psk_set; |
| 2144 | if (ssid->psk_set) |
| 2145 | os_memcpy(ssid->psk, params->psk, sizeof(ssid->psk)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2146 | else if (ssid->passphrase) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2147 | wpa_config_update_psk(ssid); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2148 | ssid->ap_max_inactivity = wpa_s->p2pdev->conf->p2p_go_max_inactivity; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2149 | |
| 2150 | wpa_s->ap_configured_cb = p2p_go_configured; |
| 2151 | wpa_s->ap_configured_cb_ctx = wpa_s; |
| 2152 | wpa_s->ap_configured_cb_data = wpa_s->go_params; |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 2153 | wpa_s->scan_req = NORMAL_SCAN_REQ; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2154 | wpa_s->connect_without_scan = ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2155 | wpa_s->reassociate = 1; |
| 2156 | wpa_s->disconnected = 0; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2157 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Request scan (that will be skipped) to " |
| 2158 | "start GO)"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2159 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 2160 | } |
| 2161 | |
| 2162 | |
| 2163 | static void wpas_p2p_clone_config(struct wpa_supplicant *dst, |
| 2164 | const struct wpa_supplicant *src) |
| 2165 | { |
| 2166 | struct wpa_config *d; |
| 2167 | const struct wpa_config *s; |
| 2168 | |
| 2169 | d = dst->conf; |
| 2170 | s = src->conf; |
| 2171 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2172 | #define C(n) \ |
| 2173 | do { \ |
| 2174 | if (s->n && !d->n) \ |
| 2175 | d->n = os_strdup(s->n); \ |
| 2176 | } while (0) |
| 2177 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2178 | C(device_name); |
| 2179 | C(manufacturer); |
| 2180 | C(model_name); |
| 2181 | C(model_number); |
| 2182 | C(serial_number); |
| 2183 | C(config_methods); |
| 2184 | #undef C |
| 2185 | |
| 2186 | os_memcpy(d->device_type, s->device_type, WPS_DEV_TYPE_LEN); |
| 2187 | os_memcpy(d->sec_device_type, s->sec_device_type, |
| 2188 | sizeof(d->sec_device_type)); |
| 2189 | d->num_sec_device_types = s->num_sec_device_types; |
| 2190 | |
| 2191 | d->p2p_group_idle = s->p2p_group_idle; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2192 | d->p2p_go_freq_change_policy = s->p2p_go_freq_change_policy; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2193 | d->p2p_intra_bss = s->p2p_intra_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2194 | d->persistent_reconnect = s->persistent_reconnect; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2195 | d->max_num_sta = s->max_num_sta; |
| 2196 | d->pbc_in_m1 = s->pbc_in_m1; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2197 | d->ignore_old_scan_res = s->ignore_old_scan_res; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 2198 | d->beacon_int = s->beacon_int; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2199 | d->dtim_period = s->dtim_period; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2200 | d->p2p_go_ctwindow = s->p2p_go_ctwindow; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2201 | d->disassoc_low_ack = s->disassoc_low_ack; |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 2202 | d->disable_scan_offload = s->disable_scan_offload; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2203 | d->passive_scan = s->passive_scan; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2204 | d->pmf = s->pmf; |
| 2205 | d->p2p_6ghz_disable = s->p2p_6ghz_disable; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2206 | d->sae_pwe = s->sae_pwe; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2207 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2208 | if (s->wps_nfc_dh_privkey && s->wps_nfc_dh_pubkey && |
| 2209 | !d->wps_nfc_pw_from_config) { |
| 2210 | wpabuf_free(d->wps_nfc_dh_privkey); |
| 2211 | wpabuf_free(d->wps_nfc_dh_pubkey); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2212 | d->wps_nfc_dh_privkey = wpabuf_dup(s->wps_nfc_dh_privkey); |
| 2213 | d->wps_nfc_dh_pubkey = wpabuf_dup(s->wps_nfc_dh_pubkey); |
| 2214 | } |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2215 | d->p2p_cli_probe = s->p2p_cli_probe; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2216 | d->go_interworking = s->go_interworking; |
| 2217 | d->go_access_network_type = s->go_access_network_type; |
| 2218 | d->go_internet = s->go_internet; |
| 2219 | d->go_venue_group = s->go_venue_group; |
| 2220 | d->go_venue_type = s->go_venue_type; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2221 | d->p2p_add_cli_chan = s->p2p_add_cli_chan; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2222 | } |
| 2223 | |
| 2224 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2225 | static void wpas_p2p_get_group_ifname(struct wpa_supplicant *wpa_s, |
| 2226 | char *ifname, size_t len) |
| 2227 | { |
| 2228 | char *ifname_ptr = wpa_s->ifname; |
| 2229 | |
| 2230 | if (os_strncmp(wpa_s->ifname, P2P_MGMT_DEVICE_PREFIX, |
| 2231 | os_strlen(P2P_MGMT_DEVICE_PREFIX)) == 0) { |
| 2232 | ifname_ptr = os_strrchr(wpa_s->ifname, '-') + 1; |
| 2233 | } |
| 2234 | |
| 2235 | os_snprintf(ifname, len, "p2p-%s-%d", ifname_ptr, wpa_s->p2p_group_idx); |
| 2236 | if (os_strlen(ifname) >= IFNAMSIZ && |
| 2237 | os_strlen(wpa_s->ifname) < IFNAMSIZ) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2238 | int res; |
| 2239 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2240 | /* Try to avoid going over the IFNAMSIZ length limit */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2241 | res = os_snprintf(ifname, len, "p2p-%d", wpa_s->p2p_group_idx); |
| 2242 | if (os_snprintf_error(len, res) && len) |
| 2243 | ifname[len - 1] = '\0'; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2244 | } |
| 2245 | } |
| 2246 | |
| 2247 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2248 | static int wpas_p2p_add_group_interface(struct wpa_supplicant *wpa_s, |
| 2249 | enum wpa_driver_if_type type) |
| 2250 | { |
| 2251 | char ifname[120], force_ifname[120]; |
| 2252 | |
| 2253 | if (wpa_s->pending_interface_name[0]) { |
| 2254 | wpa_printf(MSG_DEBUG, "P2P: Pending virtual interface exists " |
| 2255 | "- skip creation of a new one"); |
| 2256 | if (is_zero_ether_addr(wpa_s->pending_interface_addr)) { |
| 2257 | wpa_printf(MSG_DEBUG, "P2P: Pending virtual address " |
| 2258 | "unknown?! ifname='%s'", |
| 2259 | wpa_s->pending_interface_name); |
| 2260 | return -1; |
| 2261 | } |
| 2262 | return 0; |
| 2263 | } |
| 2264 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2265 | wpas_p2p_get_group_ifname(wpa_s, ifname, sizeof(ifname)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2266 | force_ifname[0] = '\0'; |
| 2267 | |
| 2268 | wpa_printf(MSG_DEBUG, "P2P: Create a new interface %s for the group", |
| 2269 | ifname); |
| 2270 | wpa_s->p2p_group_idx++; |
| 2271 | |
| 2272 | wpa_s->pending_interface_type = type; |
| 2273 | if (wpa_drv_if_add(wpa_s, type, ifname, NULL, NULL, force_ifname, |
| 2274 | wpa_s->pending_interface_addr, NULL) < 0) { |
| 2275 | wpa_printf(MSG_ERROR, "P2P: Failed to create new group " |
| 2276 | "interface"); |
| 2277 | return -1; |
| 2278 | } |
| 2279 | |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2280 | if (wpa_s->conf->p2p_interface_random_mac_addr) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2281 | random_mac_addr(wpa_s->pending_interface_addr); |
| 2282 | wpa_printf(MSG_DEBUG, "P2P: Generate random MAC address " MACSTR |
| 2283 | " for the group", |
| 2284 | MAC2STR(wpa_s->pending_interface_addr)); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2285 | } |
| 2286 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2287 | if (force_ifname[0]) { |
| 2288 | wpa_printf(MSG_DEBUG, "P2P: Driver forced interface name %s", |
| 2289 | force_ifname); |
| 2290 | os_strlcpy(wpa_s->pending_interface_name, force_ifname, |
| 2291 | sizeof(wpa_s->pending_interface_name)); |
| 2292 | } else |
| 2293 | os_strlcpy(wpa_s->pending_interface_name, ifname, |
| 2294 | sizeof(wpa_s->pending_interface_name)); |
| 2295 | wpa_printf(MSG_DEBUG, "P2P: Created pending virtual interface %s addr " |
| 2296 | MACSTR, wpa_s->pending_interface_name, |
| 2297 | MAC2STR(wpa_s->pending_interface_addr)); |
| 2298 | |
| 2299 | return 0; |
| 2300 | } |
| 2301 | |
| 2302 | |
| 2303 | static void wpas_p2p_remove_pending_group_interface( |
| 2304 | struct wpa_supplicant *wpa_s) |
| 2305 | { |
| 2306 | if (!wpa_s->pending_interface_name[0] || |
| 2307 | is_zero_ether_addr(wpa_s->pending_interface_addr)) |
| 2308 | return; /* No pending virtual interface */ |
| 2309 | |
| 2310 | wpa_printf(MSG_DEBUG, "P2P: Removing pending group interface %s", |
| 2311 | wpa_s->pending_interface_name); |
| 2312 | wpa_drv_if_remove(wpa_s, wpa_s->pending_interface_type, |
| 2313 | wpa_s->pending_interface_name); |
| 2314 | os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN); |
| 2315 | wpa_s->pending_interface_name[0] = '\0'; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2316 | wpa_s->global->pending_group_iface_for_p2ps = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | |
| 2320 | static struct wpa_supplicant * |
| 2321 | wpas_p2p_init_group_interface(struct wpa_supplicant *wpa_s, int go) |
| 2322 | { |
| 2323 | struct wpa_interface iface; |
| 2324 | struct wpa_supplicant *group_wpa_s; |
| 2325 | |
| 2326 | if (!wpa_s->pending_interface_name[0]) { |
| 2327 | wpa_printf(MSG_ERROR, "P2P: No pending group interface"); |
| 2328 | if (!wpas_p2p_create_iface(wpa_s)) |
| 2329 | return NULL; |
| 2330 | /* |
| 2331 | * Something has forced us to remove the pending interface; try |
| 2332 | * to create a new one and hope for the best that we will get |
| 2333 | * the same local address. |
| 2334 | */ |
| 2335 | if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO : |
| 2336 | WPA_IF_P2P_CLIENT) < 0) |
| 2337 | return NULL; |
| 2338 | } |
| 2339 | |
| 2340 | os_memset(&iface, 0, sizeof(iface)); |
| 2341 | iface.ifname = wpa_s->pending_interface_name; |
| 2342 | iface.driver = wpa_s->driver->name; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2343 | if (wpa_s->conf->ctrl_interface == NULL && |
| 2344 | wpa_s->parent != wpa_s && |
| 2345 | wpa_s->p2p_mgmt && |
| 2346 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) |
| 2347 | iface.ctrl_interface = wpa_s->parent->conf->ctrl_interface; |
| 2348 | else |
| 2349 | iface.ctrl_interface = wpa_s->conf->ctrl_interface; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2350 | iface.driver_param = wpa_s->conf->driver_param; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 2351 | 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] | 2352 | if (group_wpa_s == NULL) { |
| 2353 | wpa_printf(MSG_ERROR, "P2P: Failed to create new " |
| 2354 | "wpa_supplicant interface"); |
| 2355 | return NULL; |
| 2356 | } |
| 2357 | wpa_s->pending_interface_name[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2358 | group_wpa_s->p2p_group_interface = go ? P2P_GROUP_INTERFACE_GO : |
| 2359 | P2P_GROUP_INTERFACE_CLIENT; |
| 2360 | wpa_s->global->p2p_group_formation = group_wpa_s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2361 | wpa_s->global->pending_group_iface_for_p2ps = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2362 | |
| 2363 | wpas_p2p_clone_config(group_wpa_s, wpa_s); |
| 2364 | |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2365 | if (wpa_s->conf->p2p_interface_random_mac_addr) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2366 | if (wpa_drv_set_mac_addr(group_wpa_s, |
| 2367 | wpa_s->pending_interface_addr) < 0) { |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2368 | wpa_msg(group_wpa_s, MSG_INFO, |
| 2369 | "Failed to set random MAC address"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2370 | wpa_supplicant_remove_iface(wpa_s->global, group_wpa_s, |
| 2371 | 0); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2372 | return NULL; |
| 2373 | } |
| 2374 | |
| 2375 | if (wpa_supplicant_update_mac_addr(group_wpa_s) < 0) { |
| 2376 | wpa_msg(group_wpa_s, MSG_INFO, |
| 2377 | "Could not update MAC address information"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2378 | wpa_supplicant_remove_iface(wpa_s->global, group_wpa_s, |
| 2379 | 0); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2380 | return NULL; |
| 2381 | } |
| 2382 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2383 | wpa_printf(MSG_DEBUG, "P2P: Using random MAC address " MACSTR |
| 2384 | " for the group", |
| 2385 | MAC2STR(wpa_s->pending_interface_addr)); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2386 | } |
| 2387 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2388 | return group_wpa_s; |
| 2389 | } |
| 2390 | |
| 2391 | |
| 2392 | static void wpas_p2p_group_formation_timeout(void *eloop_ctx, |
| 2393 | void *timeout_ctx) |
| 2394 | { |
| 2395 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 2396 | wpa_printf(MSG_DEBUG, "P2P: Group Formation timed out"); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2397 | wpas_p2p_group_formation_failed(wpa_s, 0); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2398 | } |
| 2399 | |
| 2400 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2401 | static void wpas_p2p_group_formation_failed(struct wpa_supplicant *wpa_s, |
| 2402 | int already_deleted) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2403 | { |
| 2404 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2405 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2406 | if (wpa_s->global->p2p) |
| 2407 | p2p_group_formation_failed(wpa_s->global->p2p); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2408 | wpas_group_formation_completed(wpa_s, 0, already_deleted); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2409 | } |
| 2410 | |
| 2411 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2412 | static void wpas_p2p_grpform_fail_after_wps(struct wpa_supplicant *wpa_s) |
| 2413 | { |
| 2414 | wpa_printf(MSG_DEBUG, "P2P: Reject group formation due to WPS provisioning failure"); |
| 2415 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2416 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2417 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2418 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2419 | wpa_s->global->p2p_fail_on_wps_complete = 0; |
| 2420 | } |
| 2421 | |
| 2422 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2423 | void wpas_p2p_ap_setup_failed(struct wpa_supplicant *wpa_s) |
| 2424 | { |
| 2425 | if (wpa_s->global->p2p_group_formation != wpa_s) |
| 2426 | return; |
| 2427 | /* Speed up group formation timeout since this cannot succeed */ |
| 2428 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2429 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2430 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2431 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2432 | } |
| 2433 | |
| 2434 | |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 2435 | bool wpas_p2p_retry_limit_exceeded(struct wpa_supplicant *wpa_s) |
| 2436 | { |
| 2437 | if (!wpa_s->p2p_in_invitation || !wpa_s->p2p_retry_limit || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2438 | wpa_s->p2p_in_invitation <= wpa_s->p2p_retry_limit) |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 2439 | return false; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2440 | |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 2441 | wpa_printf(MSG_DEBUG, "P2P: Group join retry limit exceeded"); |
| 2442 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
| 2443 | wpa_s->p2pdev, NULL); |
| 2444 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
| 2445 | wpa_s->p2pdev, NULL); |
| 2446 | return true; |
| 2447 | } |
| 2448 | |
| 2449 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2450 | 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] | 2451 | { |
| 2452 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2453 | struct wpa_supplicant *group_wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2454 | |
| 2455 | if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) { |
| 2456 | wpa_drv_cancel_remain_on_channel(wpa_s); |
| 2457 | wpa_s->off_channel_freq = 0; |
| 2458 | wpa_s->roc_waiting_drv_freq = 0; |
| 2459 | } |
| 2460 | |
| 2461 | if (res->status) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2462 | wpa_msg_global(wpa_s, MSG_INFO, |
| 2463 | P2P_EVENT_GO_NEG_FAILURE "status=%d", |
| 2464 | res->status); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2465 | wpas_notify_p2p_go_neg_completed(wpa_s, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2466 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 2467 | return; |
| 2468 | } |
| 2469 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2470 | if (!res->role_go) { |
| 2471 | /* Inform driver of the operating channel of GO. */ |
| 2472 | wpa_drv_set_prob_oper_freq(wpa_s, res->freq); |
| 2473 | } |
| 2474 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2475 | if (wpa_s->p2p_go_ht40) |
| 2476 | res->ht40 = 1; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2477 | if (wpa_s->p2p_go_vht) |
| 2478 | res->vht = 1; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2479 | if (wpa_s->p2p_go_he) |
| 2480 | res->he = 1; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2481 | if (wpa_s->p2p_go_edmg) |
| 2482 | res->edmg = 1; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 2483 | res->max_oper_chwidth = wpa_s->p2p_go_max_oper_chwidth; |
| 2484 | res->vht_center_freq2 = wpa_s->p2p_go_vht_center_freq2; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2485 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2486 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_SUCCESS "role=%s " |
| 2487 | "freq=%d ht40=%d peer_dev=" MACSTR " peer_iface=" MACSTR |
| 2488 | " wps_method=%s", |
| 2489 | res->role_go ? "GO" : "client", res->freq, res->ht40, |
| 2490 | MAC2STR(res->peer_device_addr), |
| 2491 | MAC2STR(res->peer_interface_addr), |
| 2492 | p2p_wps_method_text(res->wps_method)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2493 | wpas_notify_p2p_go_neg_completed(wpa_s, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2494 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2495 | if (res->role_go && wpa_s->p2p_persistent_id >= 0) { |
| 2496 | struct wpa_ssid *ssid; |
| 2497 | ssid = wpa_config_get_network(wpa_s->conf, |
| 2498 | wpa_s->p2p_persistent_id); |
| 2499 | if (ssid && ssid->disabled == 2 && |
| 2500 | ssid->mode == WPAS_MODE_P2P_GO && ssid->passphrase) { |
| 2501 | size_t len = os_strlen(ssid->passphrase); |
| 2502 | wpa_printf(MSG_DEBUG, "P2P: Override passphrase based " |
| 2503 | "on requested persistent group"); |
| 2504 | os_memcpy(res->passphrase, ssid->passphrase, len); |
| 2505 | res->passphrase[len] = '\0'; |
| 2506 | } |
| 2507 | } |
| 2508 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2509 | if (wpa_s->create_p2p_iface) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2510 | group_wpa_s = |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2511 | wpas_p2p_init_group_interface(wpa_s, res->role_go); |
| 2512 | if (group_wpa_s == NULL) { |
| 2513 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 2514 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, |
| 2515 | wpa_s, NULL); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2516 | wpas_p2p_group_formation_failed(wpa_s, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2517 | return; |
| 2518 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2519 | os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN); |
| 2520 | wpa_s->pending_interface_name[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2521 | } else { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2522 | group_wpa_s = wpa_s->parent; |
| 2523 | wpa_s->global->p2p_group_formation = group_wpa_s; |
| 2524 | if (group_wpa_s != wpa_s) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2525 | wpas_p2p_clone_config(group_wpa_s, wpa_s); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2526 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2527 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2528 | group_wpa_s->p2p_in_provisioning = 1; |
| 2529 | group_wpa_s->p2pdev = wpa_s; |
| 2530 | if (group_wpa_s != wpa_s) { |
| 2531 | os_memcpy(group_wpa_s->p2p_pin, wpa_s->p2p_pin, |
| 2532 | sizeof(group_wpa_s->p2p_pin)); |
| 2533 | group_wpa_s->p2p_wps_method = wpa_s->p2p_wps_method; |
| 2534 | } |
| 2535 | if (res->role_go) { |
| 2536 | wpas_start_wps_go(group_wpa_s, res, 1); |
| 2537 | } else { |
| 2538 | os_get_reltime(&group_wpa_s->scan_min_time); |
| 2539 | wpas_start_wps_enrollee(group_wpa_s, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2540 | } |
| 2541 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2542 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2543 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
| 2544 | |
| 2545 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 2546 | eloop_register_timeout(15 + res->peer_config_timeout / 100, |
| 2547 | (res->peer_config_timeout % 100) * 10000, |
| 2548 | wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 2549 | } |
| 2550 | |
| 2551 | |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 2552 | static void wpas_go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id, |
| 2553 | u8 go_intent) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2554 | { |
| 2555 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2556 | 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] | 2557 | " dev_passwd_id=%u go_intent=%u", MAC2STR(src), |
| 2558 | dev_passwd_id, go_intent); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2559 | |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 2560 | 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] | 2561 | } |
| 2562 | |
| 2563 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2564 | static void wpas_dev_found(void *ctx, const u8 *addr, |
| 2565 | const struct p2p_peer_info *info, |
| 2566 | int new_device) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2567 | { |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2568 | u8 *wfd_dev_info = NULL; |
| 2569 | u8 wfd_dev_info_len = 0; |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2570 | u8 *wfd_r2_dev_info = NULL; |
Jimmy Chen | 57e19f5 | 2021-03-04 14:19:52 +0800 | [diff] [blame] | 2571 | u8 wfd_r2_dev_info_len = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2572 | #ifndef CONFIG_NO_STDOUT_DEBUG |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2573 | struct wpa_supplicant *wpa_s = ctx; |
| 2574 | char devtype[WPS_DEV_TYPE_BUFSIZE]; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2575 | char *wfd_dev_info_hex = NULL; |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2576 | char *wfd_r2_dev_info_hex = NULL; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2577 | |
Irfan Sheriff | 8367dc9 | 2012-09-09 17:08:19 -0700 | [diff] [blame] | 2578 | #ifdef CONFIG_WIFI_DISPLAY |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2579 | wfd_dev_info_hex = wifi_display_subelem_hex(info->wfd_subelems, |
| 2580 | WFD_SUBELEM_DEVICE_INFO); |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2581 | if (wfd_dev_info_hex) { |
| 2582 | wfd_dev_info_len = strlen(wfd_dev_info_hex) / 2; |
| 2583 | wfd_dev_info = os_zalloc(wfd_dev_info_len); |
| 2584 | // Only used for notification, so not handling error. |
| 2585 | hexstr2bin(wfd_dev_info_hex, wfd_dev_info, wfd_dev_info_len); |
| 2586 | } |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2587 | |
| 2588 | wfd_r2_dev_info_hex = wifi_display_subelem_hex(info->wfd_subelems, |
| 2589 | WFD_SUBELEM_R2_DEVICE_INFO); |
| 2590 | if (wfd_r2_dev_info_hex) { |
| 2591 | wfd_r2_dev_info_len = strlen(wfd_r2_dev_info_hex) / 2; |
| 2592 | wfd_r2_dev_info = os_zalloc(wfd_r2_dev_info_len); |
| 2593 | // Only used for notification, so not handling error. |
| 2594 | hexstr2bin(wfd_r2_dev_info_hex, wfd_r2_dev_info, wfd_r2_dev_info_len); |
| 2595 | } |
Irfan Sheriff | 8367dc9 | 2012-09-09 17:08:19 -0700 | [diff] [blame] | 2596 | #endif /* CONFIG_WIFI_DISPLAY */ |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2597 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2598 | if (info->p2ps_instance) { |
| 2599 | char str[256]; |
| 2600 | const u8 *buf = wpabuf_head(info->p2ps_instance); |
| 2601 | size_t len = wpabuf_len(info->p2ps_instance); |
| 2602 | |
| 2603 | while (len) { |
| 2604 | u32 id; |
| 2605 | u16 methods; |
| 2606 | u8 str_len; |
| 2607 | |
| 2608 | if (len < 4 + 2 + 1) |
| 2609 | break; |
| 2610 | id = WPA_GET_LE32(buf); |
| 2611 | buf += sizeof(u32); |
| 2612 | methods = WPA_GET_BE16(buf); |
| 2613 | buf += sizeof(u16); |
| 2614 | str_len = *buf++; |
| 2615 | if (str_len > len - 4 - 2 - 1) |
| 2616 | break; |
| 2617 | os_memcpy(str, buf, str_len); |
| 2618 | str[str_len] = '\0'; |
| 2619 | buf += str_len; |
| 2620 | len -= str_len + sizeof(u32) + sizeof(u16) + sizeof(u8); |
| 2621 | |
| 2622 | wpa_msg_global(wpa_s, MSG_INFO, |
| 2623 | P2P_EVENT_DEVICE_FOUND MACSTR |
| 2624 | " p2p_dev_addr=" MACSTR |
| 2625 | " pri_dev_type=%s name='%s'" |
| 2626 | " config_methods=0x%x" |
| 2627 | " dev_capab=0x%x" |
| 2628 | " group_capab=0x%x" |
| 2629 | " adv_id=%x asp_svc=%s%s", |
| 2630 | MAC2STR(addr), |
| 2631 | MAC2STR(info->p2p_device_addr), |
| 2632 | wps_dev_type_bin2str( |
| 2633 | info->pri_dev_type, |
| 2634 | devtype, sizeof(devtype)), |
| 2635 | info->device_name, methods, |
| 2636 | info->dev_capab, info->group_capab, |
| 2637 | id, str, |
| 2638 | info->vendor_elems ? |
| 2639 | " vendor_elems=1" : ""); |
| 2640 | } |
| 2641 | goto done; |
| 2642 | } |
| 2643 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2644 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_FOUND MACSTR |
| 2645 | " p2p_dev_addr=" MACSTR |
| 2646 | " pri_dev_type=%s name='%s' config_methods=0x%x " |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2647 | "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] | 2648 | MAC2STR(addr), MAC2STR(info->p2p_device_addr), |
| 2649 | wps_dev_type_bin2str(info->pri_dev_type, devtype, |
| 2650 | sizeof(devtype)), |
| 2651 | info->device_name, info->config_methods, |
| 2652 | info->dev_capab, info->group_capab, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2653 | wfd_dev_info_hex ? " wfd_dev_info=0x" : "", |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 2654 | wfd_dev_info_hex ? wfd_dev_info_hex : "", |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2655 | wfd_r2_dev_info_hex ? " wfd_r2_dev_info=0x" : "", |
| 2656 | wfd_r2_dev_info_hex ? wfd_r2_dev_info_hex : "", |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2657 | info->vendor_elems ? " vendor_elems=1" : "", |
| 2658 | new_device); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2659 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2660 | done: |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2661 | os_free(wfd_dev_info_hex); |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2662 | os_free(wfd_r2_dev_info_hex); |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 2663 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2664 | |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2665 | wpas_notify_p2p_device_found(ctx, addr, info, wfd_dev_info, |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2666 | wfd_dev_info_len, wfd_r2_dev_info, |
| 2667 | wfd_r2_dev_info_len, new_device); |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2668 | os_free(wfd_dev_info); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | |
| 2672 | static void wpas_dev_lost(void *ctx, const u8 *dev_addr) |
| 2673 | { |
| 2674 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2675 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2676 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_LOST |
| 2677 | "p2p_dev_addr=" MACSTR, MAC2STR(dev_addr)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2678 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2679 | wpas_notify_p2p_device_lost(wpa_s, dev_addr); |
| 2680 | } |
| 2681 | |
| 2682 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2683 | static void wpas_find_stopped(void *ctx) |
| 2684 | { |
| 2685 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2686 | |
| 2687 | if (wpa_s->p2p_scan_work && wpas_abort_ongoing_scan(wpa_s) < 0) |
| 2688 | wpa_printf(MSG_DEBUG, "P2P: Abort ongoing scan failed"); |
| 2689 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2690 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_FIND_STOPPED); |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 2691 | wpas_notify_p2p_find_stopped(wpa_s); |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2692 | } |
| 2693 | |
| 2694 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2695 | struct wpas_p2p_listen_work { |
| 2696 | unsigned int freq; |
| 2697 | unsigned int duration; |
| 2698 | struct wpabuf *probe_resp_ie; |
| 2699 | }; |
| 2700 | |
| 2701 | |
| 2702 | static void wpas_p2p_listen_work_free(struct wpas_p2p_listen_work *lwork) |
| 2703 | { |
| 2704 | if (lwork == NULL) |
| 2705 | return; |
| 2706 | wpabuf_free(lwork->probe_resp_ie); |
| 2707 | os_free(lwork); |
| 2708 | } |
| 2709 | |
| 2710 | |
| 2711 | static void wpas_p2p_listen_work_done(struct wpa_supplicant *wpa_s) |
| 2712 | { |
| 2713 | struct wpas_p2p_listen_work *lwork; |
| 2714 | |
| 2715 | if (!wpa_s->p2p_listen_work) |
| 2716 | return; |
| 2717 | |
| 2718 | lwork = wpa_s->p2p_listen_work->ctx; |
| 2719 | wpas_p2p_listen_work_free(lwork); |
| 2720 | radio_work_done(wpa_s->p2p_listen_work); |
| 2721 | wpa_s->p2p_listen_work = NULL; |
| 2722 | } |
| 2723 | |
| 2724 | |
| 2725 | static void wpas_start_listen_cb(struct wpa_radio_work *work, int deinit) |
| 2726 | { |
| 2727 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 2728 | struct wpas_p2p_listen_work *lwork = work->ctx; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2729 | unsigned int duration; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2730 | |
| 2731 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 2732 | if (work->started) { |
| 2733 | wpa_s->p2p_listen_work = NULL; |
| 2734 | wpas_stop_listen(wpa_s); |
| 2735 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2736 | wpas_p2p_listen_work_free(lwork); |
| 2737 | return; |
| 2738 | } |
| 2739 | |
| 2740 | wpa_s->p2p_listen_work = work; |
| 2741 | |
| 2742 | wpa_drv_set_ap_wps_ie(wpa_s, NULL, lwork->probe_resp_ie, NULL); |
| 2743 | |
| 2744 | if (wpa_drv_probe_req_report(wpa_s, 1) < 0) { |
| 2745 | wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver to " |
| 2746 | "report received Probe Request frames"); |
| 2747 | wpas_p2p_listen_work_done(wpa_s); |
| 2748 | return; |
| 2749 | } |
| 2750 | |
| 2751 | wpa_s->pending_listen_freq = lwork->freq; |
| 2752 | wpa_s->pending_listen_duration = lwork->duration; |
| 2753 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2754 | duration = lwork->duration; |
| 2755 | #ifdef CONFIG_TESTING_OPTIONS |
| 2756 | if (wpa_s->extra_roc_dur) { |
| 2757 | wpa_printf(MSG_DEBUG, "TESTING: Increase ROC duration %u -> %u", |
| 2758 | duration, duration + wpa_s->extra_roc_dur); |
| 2759 | duration += wpa_s->extra_roc_dur; |
| 2760 | } |
| 2761 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2762 | |
| 2763 | if (wpa_drv_remain_on_channel(wpa_s, lwork->freq, duration) < 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2764 | wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver " |
| 2765 | "to remain on channel (%u MHz) for Listen " |
| 2766 | "state", lwork->freq); |
| 2767 | wpas_p2p_listen_work_done(wpa_s); |
| 2768 | wpa_s->pending_listen_freq = 0; |
| 2769 | return; |
| 2770 | } |
| 2771 | wpa_s->off_channel_freq = 0; |
| 2772 | wpa_s->roc_waiting_drv_freq = lwork->freq; |
| 2773 | } |
| 2774 | |
| 2775 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2776 | static int wpas_start_listen(void *ctx, unsigned int freq, |
| 2777 | unsigned int duration, |
| 2778 | const struct wpabuf *probe_resp_ie) |
| 2779 | { |
| 2780 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2781 | struct wpas_p2p_listen_work *lwork; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2782 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2783 | if (wpa_s->p2p_listen_work) { |
| 2784 | 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] | 2785 | return -1; |
| 2786 | } |
| 2787 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2788 | lwork = os_zalloc(sizeof(*lwork)); |
| 2789 | if (lwork == NULL) |
| 2790 | return -1; |
| 2791 | lwork->freq = freq; |
| 2792 | lwork->duration = duration; |
| 2793 | if (probe_resp_ie) { |
| 2794 | lwork->probe_resp_ie = wpabuf_dup(probe_resp_ie); |
| 2795 | if (lwork->probe_resp_ie == NULL) { |
| 2796 | wpas_p2p_listen_work_free(lwork); |
| 2797 | return -1; |
| 2798 | } |
| 2799 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2800 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2801 | if (radio_add_work(wpa_s, freq, "p2p-listen", 0, wpas_start_listen_cb, |
| 2802 | lwork) < 0) { |
| 2803 | wpas_p2p_listen_work_free(lwork); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2804 | return -1; |
| 2805 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2806 | |
| 2807 | return 0; |
| 2808 | } |
| 2809 | |
| 2810 | |
| 2811 | static void wpas_stop_listen(void *ctx) |
| 2812 | { |
| 2813 | struct wpa_supplicant *wpa_s = ctx; |
| 2814 | if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) { |
| 2815 | wpa_drv_cancel_remain_on_channel(wpa_s); |
| 2816 | wpa_s->off_channel_freq = 0; |
| 2817 | wpa_s->roc_waiting_drv_freq = 0; |
| 2818 | } |
| 2819 | wpa_drv_set_ap_wps_ie(wpa_s, NULL, NULL, NULL); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2820 | |
| 2821 | /* |
| 2822 | * Don't cancel Probe Request RX reporting for a connected P2P Client |
| 2823 | * handling Probe Request frames. |
| 2824 | */ |
| 2825 | if (!wpa_s->p2p_cli_probe) |
| 2826 | wpa_drv_probe_req_report(wpa_s, 0); |
| 2827 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2828 | wpas_p2p_listen_work_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2829 | } |
| 2830 | |
| 2831 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2832 | static int wpas_send_probe_resp(void *ctx, const struct wpabuf *buf, |
| 2833 | unsigned int freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2834 | { |
| 2835 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2836 | 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] | 2837 | freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2841 | static void wpas_prov_disc_local_display(struct wpa_supplicant *wpa_s, |
| 2842 | const u8 *peer, const char *params, |
| 2843 | unsigned int generated_pin) |
| 2844 | { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2845 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR |
| 2846 | " %08d%s", MAC2STR(peer), generated_pin, params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2847 | } |
| 2848 | |
| 2849 | |
| 2850 | static void wpas_prov_disc_local_keypad(struct wpa_supplicant *wpa_s, |
| 2851 | const u8 *peer, const char *params) |
| 2852 | { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2853 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR |
| 2854 | "%s", MAC2STR(peer), params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2858 | static void wpas_prov_disc_req(void *ctx, const u8 *peer, u16 config_methods, |
| 2859 | const u8 *dev_addr, const u8 *pri_dev_type, |
| 2860 | const char *dev_name, u16 supp_config_methods, |
| 2861 | u8 dev_capab, u8 group_capab, const u8 *group_id, |
| 2862 | size_t group_id_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2863 | { |
| 2864 | struct wpa_supplicant *wpa_s = ctx; |
| 2865 | char devtype[WPS_DEV_TYPE_BUFSIZE]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2866 | char params[300]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2867 | u8 empty_dev_type[8]; |
| 2868 | unsigned int generated_pin = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2869 | struct wpa_supplicant *group = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2870 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2871 | |
| 2872 | if (group_id) { |
| 2873 | for (group = wpa_s->global->ifaces; group; group = group->next) |
| 2874 | { |
| 2875 | struct wpa_ssid *s = group->current_ssid; |
| 2876 | if (s != NULL && |
| 2877 | s->mode == WPAS_MODE_P2P_GO && |
| 2878 | group_id_len - ETH_ALEN == s->ssid_len && |
| 2879 | os_memcmp(group_id + ETH_ALEN, s->ssid, |
| 2880 | s->ssid_len) == 0) |
| 2881 | break; |
| 2882 | } |
| 2883 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2884 | |
| 2885 | if (pri_dev_type == NULL) { |
| 2886 | os_memset(empty_dev_type, 0, sizeof(empty_dev_type)); |
| 2887 | pri_dev_type = empty_dev_type; |
| 2888 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2889 | res = os_snprintf(params, sizeof(params), " p2p_dev_addr=" MACSTR |
| 2890 | " pri_dev_type=%s name='%s' config_methods=0x%x " |
| 2891 | "dev_capab=0x%x group_capab=0x%x%s%s", |
| 2892 | MAC2STR(dev_addr), |
| 2893 | wps_dev_type_bin2str(pri_dev_type, devtype, |
| 2894 | sizeof(devtype)), |
| 2895 | dev_name, supp_config_methods, dev_capab, group_capab, |
| 2896 | group ? " group=" : "", |
| 2897 | group ? group->ifname : ""); |
| 2898 | if (os_snprintf_error(sizeof(params), res)) |
| 2899 | wpa_printf(MSG_DEBUG, "P2P: PD Request event truncated"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2900 | params[sizeof(params) - 1] = '\0'; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2901 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2902 | if (config_methods & WPS_CONFIG_DISPLAY) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2903 | if (wps_generate_pin(&generated_pin) < 0) { |
| 2904 | wpa_printf(MSG_DEBUG, "P2P: Could not generate PIN"); |
| 2905 | wpas_notify_p2p_provision_discovery( |
| 2906 | wpa_s, peer, 0 /* response */, |
| 2907 | P2P_PROV_DISC_INFO_UNAVAILABLE, 0, 0); |
| 2908 | return; |
| 2909 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2910 | wpas_prov_disc_local_display(wpa_s, peer, params, |
| 2911 | generated_pin); |
| 2912 | } else if (config_methods & WPS_CONFIG_KEYPAD) |
| 2913 | wpas_prov_disc_local_keypad(wpa_s, peer, params); |
| 2914 | else if (config_methods & WPS_CONFIG_PUSHBUTTON) |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2915 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_REQ |
| 2916 | MACSTR "%s", MAC2STR(peer), params); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2917 | |
| 2918 | wpas_notify_p2p_provision_discovery(wpa_s, peer, 1 /* request */, |
| 2919 | P2P_PROV_DISC_SUCCESS, |
| 2920 | config_methods, generated_pin); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2921 | } |
| 2922 | |
| 2923 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2924 | 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] | 2925 | { |
| 2926 | struct wpa_supplicant *wpa_s = ctx; |
| 2927 | unsigned int generated_pin = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2928 | char params[20]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2929 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2930 | if (wpa_s->pending_pd_before_join && |
| 2931 | (os_memcmp(peer, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 || |
| 2932 | os_memcmp(peer, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0)) { |
| 2933 | wpa_s->pending_pd_before_join = 0; |
| 2934 | wpa_printf(MSG_DEBUG, "P2P: Starting pending " |
| 2935 | "join-existing-group operation"); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2936 | wpas_p2p_join_start(wpa_s, 0, NULL, 0); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2937 | return; |
| 2938 | } |
| 2939 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2940 | if (wpa_s->pending_pd_use == AUTO_PD_JOIN || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2941 | wpa_s->pending_pd_use == AUTO_PD_GO_NEG) { |
| 2942 | int res; |
| 2943 | |
| 2944 | res = os_snprintf(params, sizeof(params), " peer_go=%d", |
| 2945 | wpa_s->pending_pd_use == AUTO_PD_JOIN); |
| 2946 | if (os_snprintf_error(sizeof(params), res)) |
| 2947 | params[sizeof(params) - 1] = '\0'; |
| 2948 | } else |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2949 | params[0] = '\0'; |
| 2950 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2951 | if (config_methods & WPS_CONFIG_DISPLAY) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2952 | wpas_prov_disc_local_keypad(wpa_s, peer, params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2953 | else if (config_methods & WPS_CONFIG_KEYPAD) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2954 | if (wps_generate_pin(&generated_pin) < 0) { |
| 2955 | wpa_printf(MSG_DEBUG, "P2P: Could not generate PIN"); |
| 2956 | wpas_notify_p2p_provision_discovery( |
| 2957 | wpa_s, peer, 0 /* response */, |
| 2958 | P2P_PROV_DISC_INFO_UNAVAILABLE, 0, 0); |
| 2959 | return; |
| 2960 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2961 | wpas_prov_disc_local_display(wpa_s, peer, params, |
| 2962 | generated_pin); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2963 | } else if (config_methods & WPS_CONFIG_PUSHBUTTON) |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2964 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_RESP |
| 2965 | MACSTR "%s", MAC2STR(peer), params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2966 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2967 | wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */, |
| 2968 | P2P_PROV_DISC_SUCCESS, |
| 2969 | config_methods, generated_pin); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2970 | } |
| 2971 | |
| 2972 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2973 | static void wpas_prov_disc_fail(void *ctx, const u8 *peer, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2974 | enum p2p_prov_disc_status status, |
| 2975 | u32 adv_id, const u8 *adv_mac, |
| 2976 | const char *deferred_session_resp) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2977 | { |
| 2978 | struct wpa_supplicant *wpa_s = ctx; |
| 2979 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2980 | if (wpa_s->p2p_fallback_to_go_neg) { |
| 2981 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: PD for p2p_connect-auto " |
| 2982 | "failed - fall back to GO Negotiation"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2983 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2984 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 2985 | "reason=PD-failed"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2986 | wpas_p2p_fallback_to_go_neg(wpa_s, 0); |
| 2987 | return; |
| 2988 | } |
| 2989 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2990 | if (status == P2P_PROV_DISC_TIMEOUT_JOIN) { |
Dmitry Shmidt | 2b38048 | 2012-09-13 10:52:13 -0700 | [diff] [blame] | 2991 | wpa_s->pending_pd_before_join = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2992 | wpa_printf(MSG_DEBUG, "P2P: Starting pending " |
| 2993 | "join-existing-group operation (no ACK for PD " |
| 2994 | "Req attempts)"); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2995 | wpas_p2p_join_start(wpa_s, 0, NULL, 0); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2996 | return; |
Dmitry Shmidt | 2b38048 | 2012-09-13 10:52:13 -0700 | [diff] [blame] | 2997 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2998 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2999 | if (adv_id && adv_mac && deferred_session_resp) { |
| 3000 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE |
| 3001 | " p2p_dev_addr=" MACSTR " status=%d adv_id=%x" |
| 3002 | " deferred_session_resp='%s'", |
| 3003 | MAC2STR(peer), status, adv_id, |
| 3004 | deferred_session_resp); |
| 3005 | } else if (adv_id && adv_mac) { |
| 3006 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE |
| 3007 | " p2p_dev_addr=" MACSTR " status=%d adv_id=%x", |
| 3008 | MAC2STR(peer), status, adv_id); |
| 3009 | } else { |
| 3010 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE |
| 3011 | " p2p_dev_addr=" MACSTR " status=%d", |
| 3012 | MAC2STR(peer), status); |
| 3013 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3014 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 3015 | wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */, |
| 3016 | status, 0, 0); |
| 3017 | } |
| 3018 | |
| 3019 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3020 | static int freq_included(struct wpa_supplicant *wpa_s, |
| 3021 | const struct p2p_channels *channels, |
| 3022 | unsigned int freq) |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3023 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3024 | if ((channels == NULL || p2p_channels_includes_freq(channels, freq)) && |
| 3025 | wpas_p2p_go_is_peer_freq(wpa_s, freq)) |
| 3026 | return 1; |
| 3027 | return 0; |
| 3028 | } |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3029 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3030 | |
| 3031 | static void wpas_p2p_go_update_common_freqs(struct wpa_supplicant *wpa_s) |
| 3032 | { |
| 3033 | unsigned int num = P2P_MAX_CHANNELS; |
| 3034 | int *common_freqs; |
| 3035 | int ret; |
| 3036 | |
| 3037 | p2p_go_dump_common_freqs(wpa_s); |
| 3038 | common_freqs = os_calloc(num, sizeof(int)); |
| 3039 | if (!common_freqs) |
| 3040 | return; |
| 3041 | |
| 3042 | ret = p2p_group_get_common_freqs(wpa_s->p2p_group, common_freqs, &num); |
| 3043 | if (ret < 0) { |
| 3044 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 3045 | "P2P: Failed to get group common freqs"); |
| 3046 | os_free(common_freqs); |
| 3047 | return; |
| 3048 | } |
| 3049 | |
| 3050 | os_free(wpa_s->p2p_group_common_freqs); |
| 3051 | wpa_s->p2p_group_common_freqs = common_freqs; |
| 3052 | wpa_s->p2p_group_common_freqs_num = num; |
| 3053 | p2p_go_dump_common_freqs(wpa_s); |
| 3054 | } |
| 3055 | |
| 3056 | |
| 3057 | /* |
| 3058 | * Check if the given frequency is one of the possible operating frequencies |
| 3059 | * set after the completion of the GO Negotiation. |
| 3060 | */ |
| 3061 | static int wpas_p2p_go_is_peer_freq(struct wpa_supplicant *wpa_s, int freq) |
| 3062 | { |
| 3063 | unsigned int i; |
| 3064 | |
| 3065 | p2p_go_dump_common_freqs(wpa_s); |
| 3066 | |
| 3067 | /* assume no restrictions */ |
| 3068 | if (!wpa_s->p2p_group_common_freqs_num) |
| 3069 | return 1; |
| 3070 | |
| 3071 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 3072 | if (wpa_s->p2p_group_common_freqs[i] == freq) |
| 3073 | return 1; |
| 3074 | } |
| 3075 | return 0; |
| 3076 | } |
| 3077 | |
| 3078 | |
| 3079 | static int wpas_sta_check_ecsa(struct hostapd_data *hapd, |
| 3080 | struct sta_info *sta, void *ctx) |
| 3081 | { |
| 3082 | int *ecsa_support = ctx; |
| 3083 | |
| 3084 | *ecsa_support &= sta->ecsa_supported; |
| 3085 | |
| 3086 | return 0; |
| 3087 | } |
| 3088 | |
| 3089 | |
| 3090 | /* Check if all the peers support eCSA */ |
| 3091 | static int wpas_p2p_go_clients_support_ecsa(struct wpa_supplicant *wpa_s) |
| 3092 | { |
| 3093 | int ecsa_support = 1; |
| 3094 | |
| 3095 | ap_for_each_sta(wpa_s->ap_iface->bss[0], wpas_sta_check_ecsa, |
| 3096 | &ecsa_support); |
| 3097 | |
| 3098 | return ecsa_support; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3099 | } |
| 3100 | |
| 3101 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3102 | /** |
| 3103 | * Pick the best frequency to use from all the currently used frequencies. |
| 3104 | */ |
| 3105 | static int wpas_p2p_pick_best_used_freq(struct wpa_supplicant *wpa_s, |
| 3106 | struct wpa_used_freq_data *freqs, |
| 3107 | unsigned int num) |
| 3108 | { |
| 3109 | unsigned int i, c; |
| 3110 | |
| 3111 | /* find a candidate freq that is supported by P2P */ |
| 3112 | for (c = 0; c < num; c++) |
| 3113 | if (p2p_supported_freq(wpa_s->global->p2p, freqs[c].freq)) |
| 3114 | break; |
| 3115 | |
| 3116 | if (c == num) |
| 3117 | return 0; |
| 3118 | |
| 3119 | /* once we have a candidate, try to find a 'better' one */ |
| 3120 | for (i = c + 1; i < num; i++) { |
| 3121 | if (!p2p_supported_freq(wpa_s->global->p2p, freqs[i].freq)) |
| 3122 | continue; |
| 3123 | |
| 3124 | /* |
| 3125 | * 1. Infrastructure station interfaces have higher preference. |
| 3126 | * 2. P2P Clients have higher preference. |
| 3127 | * 3. All others. |
| 3128 | */ |
| 3129 | if (freqs[i].flags & WPA_FREQ_USED_BY_INFRA_STATION) { |
| 3130 | c = i; |
| 3131 | break; |
| 3132 | } |
| 3133 | |
| 3134 | if ((freqs[i].flags & WPA_FREQ_USED_BY_P2P_CLIENT)) |
| 3135 | c = i; |
| 3136 | } |
| 3137 | return freqs[c].freq; |
| 3138 | } |
| 3139 | |
| 3140 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3141 | /** |
| 3142 | * Pick the best frequency the driver suggests. |
| 3143 | * |
| 3144 | * num_pref_freq is used as both input and output |
| 3145 | * - input: the max size of pref_freq_list, |
| 3146 | * - output: the valid size of pref_freq_list filled with data. |
| 3147 | */ |
| 3148 | static int wpas_p2p_pick_best_pref_freq(struct wpa_supplicant *wpa_s, bool go, |
| 3149 | struct weighted_pcl *pref_freq_list, |
| 3150 | unsigned int *num_pref_freq) |
| 3151 | { |
| 3152 | int best_freq = 0; |
| 3153 | unsigned int max_pref_freq, i; |
| 3154 | int res; |
| 3155 | enum wpa_driver_if_type iface_type; |
| 3156 | |
| 3157 | max_pref_freq = *num_pref_freq; |
| 3158 | *num_pref_freq = 0; |
| 3159 | |
| 3160 | if (go) |
| 3161 | iface_type = WPA_IF_P2P_GO; |
| 3162 | else |
| 3163 | iface_type = WPA_IF_P2P_CLIENT; |
| 3164 | |
| 3165 | res = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &max_pref_freq, |
| 3166 | pref_freq_list); |
| 3167 | if (!res && !is_p2p_allow_6ghz(wpa_s->global->p2p)) |
| 3168 | max_pref_freq = p2p_remove_6ghz_channels(pref_freq_list, |
| 3169 | max_pref_freq); |
| 3170 | if (res || !max_pref_freq) { |
| 3171 | wpa_printf(MSG_DEBUG, |
| 3172 | "P2P: No preferred frequency list available"); |
| 3173 | return 0; |
| 3174 | } |
| 3175 | |
| 3176 | *num_pref_freq = max_pref_freq; |
| 3177 | i = 0; |
| 3178 | while (i < *num_pref_freq && |
| 3179 | (!p2p_supported_freq(wpa_s->global->p2p, |
| 3180 | pref_freq_list[i].freq) || |
| 3181 | wpas_p2p_disallowed_freq(wpa_s->global, |
| 3182 | pref_freq_list[i].freq) || |
| 3183 | !p2p_pref_freq_allowed(&pref_freq_list[i], go))) { |
| 3184 | wpa_printf(MSG_DEBUG, |
| 3185 | "P2P: preferred_freq_list[%d]=%d is disallowed", |
| 3186 | i, pref_freq_list[i].freq); |
| 3187 | i++; |
| 3188 | } |
| 3189 | if (i != *num_pref_freq) { |
| 3190 | best_freq = pref_freq_list[i].freq; |
| 3191 | wpa_printf(MSG_DEBUG, "P2P: Using preferred_freq_list[%d]=%d", |
| 3192 | i, best_freq); |
| 3193 | } else { |
| 3194 | wpa_printf(MSG_DEBUG, |
| 3195 | "P2P: All driver preferred frequencies are disallowed for P2P use"); |
| 3196 | *num_pref_freq = 0; |
| 3197 | } |
| 3198 | |
| 3199 | return best_freq; |
| 3200 | } |
| 3201 | |
| 3202 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3203 | static u8 wpas_invitation_process(void *ctx, const u8 *sa, const u8 *bssid, |
| 3204 | const u8 *go_dev_addr, const u8 *ssid, |
| 3205 | size_t ssid_len, int *go, u8 *group_bssid, |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3206 | int *force_freq, int persistent_group, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3207 | const struct p2p_channels *channels, |
| 3208 | int dev_pw_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3209 | { |
| 3210 | struct wpa_supplicant *wpa_s = ctx; |
| 3211 | struct wpa_ssid *s; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3212 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3213 | struct wpa_supplicant *grp; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3214 | int best_freq; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3215 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 3216 | unsigned int num_pref_freq; |
| 3217 | int res; |
| 3218 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3219 | |
| 3220 | if (!persistent_group) { |
| 3221 | wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3222 | " to join an active group (SSID: %s)", |
| 3223 | MAC2STR(sa), wpa_ssid_txt(ssid, ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3224 | if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) && |
| 3225 | (os_memcmp(go_dev_addr, wpa_s->p2p_auth_invite, ETH_ALEN) |
| 3226 | == 0 || |
| 3227 | os_memcmp(sa, wpa_s->p2p_auth_invite, ETH_ALEN) == 0)) { |
| 3228 | wpa_printf(MSG_DEBUG, "P2P: Accept previously " |
| 3229 | "authorized invitation"); |
| 3230 | goto accept_inv; |
| 3231 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3232 | |
| 3233 | #ifdef CONFIG_WPS_NFC |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3234 | if (dev_pw_id >= 0 && wpa_s->p2p_nfc_tag_enabled && |
| 3235 | dev_pw_id == wpa_s->p2p_oob_dev_pw_id) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3236 | 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] | 3237 | wpa_s->p2p_wps_method = WPS_NFC; |
| 3238 | wpa_s->pending_join_wps_method = WPS_NFC; |
| 3239 | os_memcpy(wpa_s->pending_join_dev_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3240 | go_dev_addr, ETH_ALEN); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3241 | os_memcpy(wpa_s->pending_join_iface_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3242 | bssid, ETH_ALEN); |
| 3243 | goto accept_inv; |
| 3244 | } |
| 3245 | #endif /* CONFIG_WPS_NFC */ |
| 3246 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3247 | /* |
| 3248 | * Do not accept the invitation automatically; notify user and |
| 3249 | * request approval. |
| 3250 | */ |
| 3251 | return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; |
| 3252 | } |
| 3253 | |
| 3254 | grp = wpas_get_p2p_group(wpa_s, ssid, ssid_len, go); |
| 3255 | if (grp) { |
| 3256 | wpa_printf(MSG_DEBUG, "P2P: Accept invitation to already " |
| 3257 | "running persistent group"); |
| 3258 | if (*go) |
| 3259 | os_memcpy(group_bssid, grp->own_addr, ETH_ALEN); |
| 3260 | goto accept_inv; |
| 3261 | } |
| 3262 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3263 | if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) && |
| 3264 | os_memcmp(sa, wpa_s->p2p_auth_invite, ETH_ALEN) == 0) { |
| 3265 | wpa_printf(MSG_DEBUG, "P2P: Accept previously initiated " |
| 3266 | "invitation to re-invoke a persistent group"); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3267 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3268 | } else if (!wpa_s->conf->persistent_reconnect) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3269 | return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; |
| 3270 | |
| 3271 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 3272 | if (s->disabled == 2 && |
| 3273 | os_memcmp(s->bssid, go_dev_addr, ETH_ALEN) == 0 && |
| 3274 | s->ssid_len == ssid_len && |
| 3275 | os_memcmp(ssid, s->ssid, ssid_len) == 0) |
| 3276 | break; |
| 3277 | } |
| 3278 | |
| 3279 | if (!s) { |
| 3280 | wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR |
| 3281 | " requested reinvocation of an unknown group", |
| 3282 | MAC2STR(sa)); |
| 3283 | return P2P_SC_FAIL_UNKNOWN_GROUP; |
| 3284 | } |
| 3285 | |
| 3286 | if (s->mode == WPAS_MODE_P2P_GO && !wpas_p2p_create_iface(wpa_s)) { |
| 3287 | *go = 1; |
| 3288 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
| 3289 | wpa_printf(MSG_DEBUG, "P2P: The only available " |
| 3290 | "interface is already in use - reject " |
| 3291 | "invitation"); |
| 3292 | return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; |
| 3293 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3294 | if (wpa_s->p2p_mgmt) |
| 3295 | os_memcpy(group_bssid, wpa_s->parent->own_addr, |
| 3296 | ETH_ALEN); |
| 3297 | else |
| 3298 | os_memcpy(group_bssid, wpa_s->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3299 | } else if (s->mode == WPAS_MODE_P2P_GO) { |
| 3300 | *go = 1; |
| 3301 | if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO) < 0) |
| 3302 | { |
| 3303 | wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " |
| 3304 | "interface address for the group"); |
| 3305 | return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; |
| 3306 | } |
| 3307 | os_memcpy(group_bssid, wpa_s->pending_interface_addr, |
| 3308 | ETH_ALEN); |
| 3309 | } |
| 3310 | |
| 3311 | accept_inv: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3312 | wpas_p2p_set_own_freq_preference(wpa_s, 0); |
| 3313 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3314 | best_freq = 0; |
| 3315 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 3316 | sizeof(struct wpa_used_freq_data)); |
| 3317 | if (freqs) { |
| 3318 | int num_channels = wpa_s->num_multichan_concurrent; |
| 3319 | int num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, num_channels); |
| 3320 | best_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num); |
| 3321 | os_free(freqs); |
| 3322 | } |
| 3323 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3324 | num_pref_freq = P2P_MAX_PREF_CHANNELS; |
| 3325 | res = wpas_p2p_pick_best_pref_freq(wpa_s, *go, pref_freq_list, |
| 3326 | &num_pref_freq); |
| 3327 | if (res > 0) |
| 3328 | best_freq = res; |
| 3329 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3330 | /* Get one of the frequencies currently in use */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3331 | if (best_freq > 0) { |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 3332 | 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] | 3333 | wpas_p2p_set_own_freq_preference(wpa_s, best_freq); |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 3334 | |
| 3335 | if (wpa_s->num_multichan_concurrent < 2 || |
| 3336 | wpas_p2p_num_unused_channels(wpa_s) < 1) { |
| 3337 | 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] | 3338 | *force_freq = best_freq; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 3339 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3340 | } |
| 3341 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3342 | if (*force_freq > 0 && wpa_s->num_multichan_concurrent > 1 && |
| 3343 | wpas_p2p_num_unused_channels(wpa_s) > 0) { |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3344 | if (*go == 0) { |
| 3345 | /* We are the client */ |
| 3346 | wpa_printf(MSG_DEBUG, "P2P: Peer was found to be " |
| 3347 | "running a GO but we are capable of MCC, " |
| 3348 | "figure out the best channel to use"); |
| 3349 | *force_freq = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3350 | } else if (!freq_included(wpa_s, channels, *force_freq)) { |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3351 | /* We are the GO, and *force_freq is not in the |
| 3352 | * intersection */ |
| 3353 | wpa_printf(MSG_DEBUG, "P2P: Forced GO freq %d MHz not " |
| 3354 | "in intersection but we are capable of MCC, " |
| 3355 | "figure out the best channel to use", |
| 3356 | *force_freq); |
| 3357 | *force_freq = 0; |
| 3358 | } |
| 3359 | } |
| 3360 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3361 | return P2P_SC_SUCCESS; |
| 3362 | } |
| 3363 | |
| 3364 | |
| 3365 | static void wpas_invitation_received(void *ctx, const u8 *sa, const u8 *bssid, |
| 3366 | const u8 *ssid, size_t ssid_len, |
| 3367 | const u8 *go_dev_addr, u8 status, |
| 3368 | int op_freq) |
| 3369 | { |
| 3370 | struct wpa_supplicant *wpa_s = ctx; |
| 3371 | struct wpa_ssid *s; |
| 3372 | |
| 3373 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 3374 | if (s->disabled == 2 && |
| 3375 | s->ssid_len == ssid_len && |
| 3376 | os_memcmp(ssid, s->ssid, ssid_len) == 0) |
| 3377 | break; |
| 3378 | } |
| 3379 | |
| 3380 | if (status == P2P_SC_SUCCESS) { |
| 3381 | wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3382 | " was accepted; op_freq=%d MHz, SSID=%s", |
| 3383 | MAC2STR(sa), op_freq, wpa_ssid_txt(ssid, ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3384 | if (s) { |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 3385 | int go = s->mode == WPAS_MODE_P2P_GO; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 3386 | if (go) { |
| 3387 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3388 | P2P_EVENT_INVITATION_ACCEPTED |
| 3389 | "sa=" MACSTR |
| 3390 | " persistent=%d freq=%d", |
| 3391 | MAC2STR(sa), s->id, op_freq); |
| 3392 | } else { |
| 3393 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3394 | P2P_EVENT_INVITATION_ACCEPTED |
| 3395 | "sa=" MACSTR |
| 3396 | " persistent=%d", |
| 3397 | MAC2STR(sa), s->id); |
| 3398 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3399 | wpas_p2p_group_add_persistent( |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3400 | wpa_s, s, go, 0, op_freq, 0, |
| 3401 | wpa_s->conf->p2p_go_ht40, |
| 3402 | wpa_s->conf->p2p_go_vht, |
| 3403 | 0, |
| 3404 | wpa_s->conf->p2p_go_he, |
| 3405 | wpa_s->conf->p2p_go_edmg, NULL, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3406 | go ? P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0, |
Matthew Wang | 124e5f4 | 2022-12-29 07:23:06 +0000 | [diff] [blame] | 3407 | 1, is_p2p_allow_6ghz(wpa_s->global->p2p), 0, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3408 | NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3409 | } else if (bssid) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3410 | wpa_s->user_initiated_pd = 0; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 3411 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3412 | P2P_EVENT_INVITATION_ACCEPTED |
| 3413 | "sa=" MACSTR " go_dev_addr=" MACSTR |
| 3414 | " bssid=" MACSTR " unknown-network", |
| 3415 | MAC2STR(sa), MAC2STR(go_dev_addr), |
| 3416 | MAC2STR(bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3417 | wpas_p2p_join(wpa_s, bssid, go_dev_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3418 | wpa_s->p2p_wps_method, 0, op_freq, |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3419 | ssid, ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3420 | } |
| 3421 | return; |
| 3422 | } |
| 3423 | |
| 3424 | if (status != P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) { |
| 3425 | wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR |
| 3426 | " was rejected (status %u)", MAC2STR(sa), status); |
| 3427 | return; |
| 3428 | } |
| 3429 | |
| 3430 | if (!s) { |
| 3431 | if (bssid) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3432 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3433 | P2P_EVENT_INVITATION_RECEIVED |
| 3434 | "sa=" MACSTR " go_dev_addr=" MACSTR |
| 3435 | " bssid=" MACSTR " unknown-network", |
| 3436 | MAC2STR(sa), MAC2STR(go_dev_addr), |
| 3437 | MAC2STR(bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3438 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3439 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3440 | P2P_EVENT_INVITATION_RECEIVED |
| 3441 | "sa=" MACSTR " go_dev_addr=" MACSTR |
| 3442 | " unknown-network", |
| 3443 | MAC2STR(sa), MAC2STR(go_dev_addr)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3444 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3445 | wpas_notify_p2p_invitation_received(wpa_s, sa, go_dev_addr, |
| 3446 | bssid, 0, op_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3447 | return; |
| 3448 | } |
| 3449 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3450 | if (s->mode == WPAS_MODE_P2P_GO && op_freq) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3451 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED |
| 3452 | "sa=" MACSTR " persistent=%d freq=%d", |
| 3453 | MAC2STR(sa), s->id, op_freq); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3454 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3455 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED |
| 3456 | "sa=" MACSTR " persistent=%d", |
| 3457 | MAC2STR(sa), s->id); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3458 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3459 | wpas_notify_p2p_invitation_received(wpa_s, sa, go_dev_addr, bssid, |
| 3460 | s->id, op_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3461 | } |
| 3462 | |
| 3463 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3464 | static void wpas_remove_persistent_peer(struct wpa_supplicant *wpa_s, |
| 3465 | struct wpa_ssid *ssid, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3466 | const u8 *peer, int inv) |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3467 | { |
| 3468 | size_t i; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 3469 | 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] | 3470 | |
| 3471 | if (ssid == NULL) |
| 3472 | return; |
| 3473 | |
| 3474 | for (i = 0; ssid->p2p_client_list && i < ssid->num_p2p_clients; i++) { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3475 | if (os_memcmp(ssid->p2p_client_list + i * 2 * ETH_ALEN, peer, |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3476 | ETH_ALEN) == 0) |
| 3477 | break; |
| 3478 | } |
Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 3479 | if (i >= ssid->num_p2p_clients || !ssid->p2p_client_list) { |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3480 | if (ssid->mode != WPAS_MODE_P2P_GO && |
| 3481 | os_memcmp(ssid->bssid, peer, ETH_ALEN) == 0) { |
| 3482 | wpa_printf(MSG_DEBUG, "P2P: Remove persistent group %d " |
| 3483 | "due to invitation result", ssid->id); |
| 3484 | wpas_notify_network_removed(wpa_s, ssid); |
| 3485 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 3486 | return; |
| 3487 | } |
| 3488 | return; /* Peer not found in client list */ |
| 3489 | } |
| 3490 | |
| 3491 | wpa_printf(MSG_DEBUG, "P2P: Remove peer " MACSTR " from persistent " |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3492 | "group %d client list%s", |
| 3493 | MAC2STR(peer), ssid->id, |
| 3494 | inv ? " due to invitation result" : ""); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3495 | os_memmove(ssid->p2p_client_list + i * 2 * ETH_ALEN, |
| 3496 | ssid->p2p_client_list + (i + 1) * 2 * ETH_ALEN, |
| 3497 | (ssid->num_p2p_clients - i - 1) * 2 * ETH_ALEN); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3498 | ssid->num_p2p_clients--; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 3499 | if (p2p_wpa_s->conf->update_config && |
| 3500 | wpa_config_write(p2p_wpa_s->confname, p2p_wpa_s->conf)) |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3501 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3502 | } |
| 3503 | |
| 3504 | |
| 3505 | static void wpas_remove_persistent_client(struct wpa_supplicant *wpa_s, |
| 3506 | const u8 *peer) |
| 3507 | { |
| 3508 | struct wpa_ssid *ssid; |
| 3509 | |
| 3510 | wpa_s = wpa_s->global->p2p_invite_group; |
| 3511 | if (wpa_s == NULL) |
| 3512 | return; /* No known invitation group */ |
| 3513 | ssid = wpa_s->current_ssid; |
| 3514 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || |
| 3515 | !ssid->p2p_persistent_group) |
| 3516 | return; /* Not operating as a GO in persistent group */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3517 | ssid = wpas_p2p_get_persistent(wpa_s->p2pdev, peer, |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3518 | ssid->ssid, ssid->ssid_len); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3519 | wpas_remove_persistent_peer(wpa_s, ssid, peer, 1); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3523 | static void wpas_invitation_result(void *ctx, int status, const u8 *bssid, |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3524 | const struct p2p_channels *channels, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3525 | const u8 *peer, int neg_freq, |
| 3526 | int peer_oper_freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3527 | { |
| 3528 | struct wpa_supplicant *wpa_s = ctx; |
| 3529 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3530 | int freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3531 | |
| 3532 | if (bssid) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3533 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT |
| 3534 | "status=%d " MACSTR, |
| 3535 | status, MAC2STR(bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3536 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3537 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT |
| 3538 | "status=%d ", status); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3539 | } |
| 3540 | wpas_notify_p2p_invitation_result(wpa_s, status, bssid); |
| 3541 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3542 | wpa_printf(MSG_DEBUG, "P2P: Invitation result - status=%d peer=" MACSTR, |
| 3543 | status, MAC2STR(peer)); |
| 3544 | if (wpa_s->pending_invite_ssid_id == -1) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3545 | struct wpa_supplicant *group_if = |
| 3546 | wpa_s->global->p2p_invite_group; |
| 3547 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3548 | if (status == P2P_SC_FAIL_UNKNOWN_GROUP) |
| 3549 | wpas_remove_persistent_client(wpa_s, peer); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3550 | |
| 3551 | /* |
| 3552 | * Invitation to an active group. If this is successful and we |
| 3553 | * are the GO, set the client wait to postpone some concurrent |
| 3554 | * operations and to allow provisioning and connection to happen |
| 3555 | * more quickly. |
| 3556 | */ |
| 3557 | if (status == P2P_SC_SUCCESS && |
| 3558 | group_if && group_if->current_ssid && |
| 3559 | group_if->current_ssid->mode == WPAS_MODE_P2P_GO) { |
| 3560 | os_get_reltime(&wpa_s->global->p2p_go_wait_client); |
| 3561 | #ifdef CONFIG_TESTING_OPTIONS |
| 3562 | if (group_if->p2p_go_csa_on_inv) { |
| 3563 | wpa_printf(MSG_DEBUG, |
| 3564 | "Testing: force P2P GO CSA after invitation"); |
| 3565 | eloop_cancel_timeout( |
| 3566 | wpas_p2p_reconsider_moving_go, |
| 3567 | wpa_s, NULL); |
| 3568 | eloop_register_timeout( |
| 3569 | 0, 50000, |
| 3570 | wpas_p2p_reconsider_moving_go, |
| 3571 | wpa_s, NULL); |
| 3572 | } |
| 3573 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 3574 | } |
| 3575 | return; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3576 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3577 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3578 | if (status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) { |
| 3579 | wpa_printf(MSG_DEBUG, "P2P: Waiting for peer to start another " |
| 3580 | "invitation exchange to indicate readiness for " |
| 3581 | "re-invocation"); |
| 3582 | } |
| 3583 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3584 | if (status != P2P_SC_SUCCESS) { |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3585 | if (status == P2P_SC_FAIL_UNKNOWN_GROUP) { |
| 3586 | ssid = wpa_config_get_network( |
| 3587 | wpa_s->conf, wpa_s->pending_invite_ssid_id); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3588 | wpas_remove_persistent_peer(wpa_s, ssid, peer, 1); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3589 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3590 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 3591 | return; |
| 3592 | } |
| 3593 | |
| 3594 | ssid = wpa_config_get_network(wpa_s->conf, |
| 3595 | wpa_s->pending_invite_ssid_id); |
| 3596 | if (ssid == NULL) { |
| 3597 | wpa_printf(MSG_ERROR, "P2P: Could not find persistent group " |
| 3598 | "data matching with invitation"); |
| 3599 | return; |
| 3600 | } |
| 3601 | |
Jouni Malinen | 2c5b17d | 2012-10-13 21:52:46 -0700 | [diff] [blame] | 3602 | /* |
| 3603 | * The peer could have missed our ctrl::ack frame for Invitation |
| 3604 | * Response and continue retransmitting the frame. To reduce the |
| 3605 | * likelihood of the peer not getting successful TX status for the |
| 3606 | * Invitation Response frame, wait a short time here before starting |
| 3607 | * the persistent group so that we will remain on the current channel to |
| 3608 | * acknowledge any possible retransmission from the peer. |
| 3609 | */ |
| 3610 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: 50 ms wait on current channel before " |
| 3611 | "starting persistent group"); |
| 3612 | os_sleep(0, 50000); |
| 3613 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3614 | if (neg_freq > 0 && ssid->mode == WPAS_MODE_P2P_GO && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3615 | freq_included(wpa_s, channels, neg_freq)) |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3616 | freq = neg_freq; |
| 3617 | else if (peer_oper_freq > 0 && ssid->mode != WPAS_MODE_P2P_GO && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3618 | freq_included(wpa_s, channels, peer_oper_freq)) |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3619 | freq = peer_oper_freq; |
| 3620 | else |
| 3621 | freq = 0; |
| 3622 | |
| 3623 | wpa_printf(MSG_DEBUG, "P2P: Persistent group invitation success - op_freq=%d MHz SSID=%s", |
| 3624 | freq, wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3625 | wpas_p2p_group_add_persistent(wpa_s, ssid, |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 3626 | ssid->mode == WPAS_MODE_P2P_GO, |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 3627 | wpa_s->p2p_persistent_go_freq, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3628 | freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3629 | wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3630 | wpa_s->p2p_go_ht40, wpa_s->p2p_go_vht, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3631 | wpa_s->p2p_go_max_oper_chwidth, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3632 | wpa_s->p2p_go_he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3633 | wpa_s->p2p_go_edmg, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3634 | channels, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3635 | ssid->mode == WPAS_MODE_P2P_GO ? |
| 3636 | P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3637 | 0, 1, |
Matthew Wang | 124e5f4 | 2022-12-29 07:23:06 +0000 | [diff] [blame] | 3638 | is_p2p_allow_6ghz(wpa_s->global->p2p), 0, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3639 | NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3640 | } |
| 3641 | |
| 3642 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3643 | static int wpas_p2p_disallowed_freq(struct wpa_global *global, |
| 3644 | unsigned int freq) |
| 3645 | { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3646 | if (freq_range_list_includes(&global->p2p_go_avoid_freq, freq)) |
| 3647 | return 1; |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 3648 | return freq_range_list_includes(&global->p2p_disallow_freq, freq); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3649 | } |
| 3650 | |
| 3651 | |
| 3652 | static void wpas_p2p_add_chan(struct p2p_reg_class *reg, u8 chan) |
| 3653 | { |
| 3654 | reg->channel[reg->channels] = chan; |
| 3655 | reg->channels++; |
| 3656 | } |
| 3657 | |
| 3658 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3659 | static int wpas_p2p_default_channels(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3660 | struct p2p_channels *chan, |
| 3661 | struct p2p_channels *cli_chan) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3662 | { |
| 3663 | int i, cla = 0; |
| 3664 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3665 | wpa_s->global->p2p_24ghz_social_channels = 1; |
| 3666 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3667 | os_memset(cli_chan, 0, sizeof(*cli_chan)); |
| 3668 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3669 | wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for 2.4 GHz " |
| 3670 | "band"); |
| 3671 | |
| 3672 | /* Operating class 81 - 2.4 GHz band channels 1..13 */ |
| 3673 | chan->reg_class[cla].reg_class = 81; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3674 | chan->reg_class[cla].channels = 0; |
| 3675 | for (i = 0; i < 11; i++) { |
| 3676 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 2412 + i * 5)) |
| 3677 | wpas_p2p_add_chan(&chan->reg_class[cla], i + 1); |
| 3678 | } |
| 3679 | if (chan->reg_class[cla].channels) |
| 3680 | cla++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3681 | |
| 3682 | wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for lower 5 GHz " |
| 3683 | "band"); |
| 3684 | |
| 3685 | /* Operating class 115 - 5 GHz, channels 36-48 */ |
| 3686 | chan->reg_class[cla].reg_class = 115; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3687 | chan->reg_class[cla].channels = 0; |
| 3688 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 36 * 5)) |
| 3689 | wpas_p2p_add_chan(&chan->reg_class[cla], 36); |
| 3690 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 40 * 5)) |
| 3691 | wpas_p2p_add_chan(&chan->reg_class[cla], 40); |
| 3692 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 44 * 5)) |
| 3693 | wpas_p2p_add_chan(&chan->reg_class[cla], 44); |
| 3694 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 48 * 5)) |
| 3695 | wpas_p2p_add_chan(&chan->reg_class[cla], 48); |
| 3696 | if (chan->reg_class[cla].channels) |
| 3697 | cla++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3698 | |
| 3699 | wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for higher 5 GHz " |
| 3700 | "band"); |
| 3701 | |
| 3702 | /* Operating class 124 - 5 GHz, channels 149,153,157,161 */ |
| 3703 | chan->reg_class[cla].reg_class = 124; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3704 | chan->reg_class[cla].channels = 0; |
| 3705 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 149 * 5)) |
| 3706 | wpas_p2p_add_chan(&chan->reg_class[cla], 149); |
| 3707 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 153 * 5)) |
| 3708 | wpas_p2p_add_chan(&chan->reg_class[cla], 153); |
| 3709 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 156 * 5)) |
| 3710 | wpas_p2p_add_chan(&chan->reg_class[cla], 157); |
| 3711 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 161 * 5)) |
| 3712 | wpas_p2p_add_chan(&chan->reg_class[cla], 161); |
| 3713 | if (chan->reg_class[cla].channels) |
| 3714 | cla++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3715 | |
| 3716 | chan->reg_classes = cla; |
| 3717 | return 0; |
| 3718 | } |
| 3719 | |
| 3720 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3721 | static enum chan_allowed has_channel(struct wpa_global *global, |
| 3722 | struct hostapd_hw_modes *mode, u8 op_class, |
| 3723 | u8 chan, int *flags) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3724 | { |
| 3725 | int i; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3726 | unsigned int freq; |
| 3727 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3728 | freq = ieee80211_chan_to_freq(NULL, op_class, chan); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3729 | if (wpas_p2p_disallowed_freq(global, freq)) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3730 | return NOT_ALLOWED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3731 | |
| 3732 | for (i = 0; i < mode->num_channels; i++) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3733 | if ((unsigned int) mode->channels[i].freq == freq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3734 | if (flags) |
| 3735 | *flags = mode->channels[i].flag; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3736 | if (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3737 | return NOT_ALLOWED; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3738 | if (mode->channels[i].flag & HOSTAPD_CHAN_NO_IR) |
| 3739 | return NO_IR; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3740 | if (mode->channels[i].flag & HOSTAPD_CHAN_RADAR) |
| 3741 | return RADAR; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3742 | return ALLOWED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3743 | } |
| 3744 | } |
| 3745 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3746 | return NOT_ALLOWED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3747 | } |
| 3748 | |
| 3749 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3750 | static int wpas_p2p_get_center_80mhz(struct wpa_supplicant *wpa_s, |
| 3751 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3752 | u8 channel, const u8 *center_channels, |
| 3753 | size_t num_chan) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3754 | { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 3755 | size_t i; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3756 | |
| 3757 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 3758 | return 0; |
| 3759 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3760 | for (i = 0; i < num_chan; i++) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3761 | /* |
| 3762 | * In 80 MHz, the bandwidth "spans" 12 channels (e.g., 36-48), |
| 3763 | * so the center channel is 6 channels away from the start/end. |
| 3764 | */ |
| 3765 | if (channel >= center_channels[i] - 6 && |
| 3766 | channel <= center_channels[i] + 6) |
| 3767 | return center_channels[i]; |
| 3768 | |
| 3769 | return 0; |
| 3770 | } |
| 3771 | |
| 3772 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3773 | static const u8 center_channels_5ghz_80mhz[] = { 42, 58, 106, 122, 138, |
| 3774 | 155, 171 }; |
| 3775 | static const u8 center_channels_6ghz_80mhz[] = { 7, 23, 39, 55, 71, 87, 103, |
| 3776 | 119, 135, 151, 167, 183, 199, |
| 3777 | 215 }; |
| 3778 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3779 | static enum chan_allowed wpas_p2p_verify_80mhz(struct wpa_supplicant *wpa_s, |
| 3780 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3781 | u8 op_class, u8 channel, u8 bw) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3782 | { |
| 3783 | u8 center_chan; |
| 3784 | int i, flags; |
| 3785 | enum chan_allowed res, ret = ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3786 | const u8 *chans; |
| 3787 | size_t num_chans; |
| 3788 | bool is_6ghz = is_6ghz_op_class(op_class); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3789 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3790 | if (is_6ghz) { |
| 3791 | chans = center_channels_6ghz_80mhz; |
| 3792 | num_chans = ARRAY_SIZE(center_channels_6ghz_80mhz); |
| 3793 | } else { |
| 3794 | chans = center_channels_5ghz_80mhz; |
| 3795 | num_chans = ARRAY_SIZE(center_channels_5ghz_80mhz); |
| 3796 | } |
| 3797 | center_chan = wpas_p2p_get_center_80mhz(wpa_s, mode, channel, |
| 3798 | chans, num_chans); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3799 | if (!center_chan) |
| 3800 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3801 | if (!wpa_s->p2p_go_allow_dfs && |
| 3802 | !is_6ghz && center_chan >= 58 && center_chan <= 138) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3803 | return NOT_ALLOWED; /* Do not allow DFS channels for P2P */ |
| 3804 | |
| 3805 | /* check all the channels are available */ |
| 3806 | for (i = 0; i < 4; i++) { |
| 3807 | int adj_chan = center_chan - 6 + i * 4; |
| 3808 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3809 | res = has_channel(wpa_s->global, mode, op_class, adj_chan, |
| 3810 | &flags); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3811 | if (res == NOT_ALLOWED) |
| 3812 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3813 | if (res == RADAR) |
| 3814 | ret = RADAR; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3815 | if (res == NO_IR) |
| 3816 | ret = NO_IR; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3817 | if (!is_6ghz) { |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3818 | if (!(flags & HOSTAPD_CHAN_VHT_80MHZ_SUBCHANNEL)) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3819 | return NOT_ALLOWED; |
| 3820 | } else if (is_6ghz && |
| 3821 | (!(wpas_get_6ghz_he_chwidth_capab(mode) & |
| 3822 | HE_PHYCAP_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G))) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3823 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3824 | } |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3825 | } |
| 3826 | |
| 3827 | return ret; |
| 3828 | } |
| 3829 | |
| 3830 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3831 | static int wpas_p2p_get_center_160mhz(struct wpa_supplicant *wpa_s, |
| 3832 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3833 | u8 channel, const u8 *center_channels, |
| 3834 | size_t num_chan) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3835 | { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3836 | unsigned int i; |
| 3837 | |
| 3838 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 3839 | return 0; |
| 3840 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3841 | for (i = 0; i < num_chan; i++) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3842 | /* |
| 3843 | * In 160 MHz, the bandwidth "spans" 28 channels (e.g., 36-64), |
| 3844 | * so the center channel is 14 channels away from the start/end. |
| 3845 | */ |
| 3846 | if (channel >= center_channels[i] - 14 && |
| 3847 | channel <= center_channels[i] + 14) |
| 3848 | return center_channels[i]; |
| 3849 | |
| 3850 | return 0; |
| 3851 | } |
| 3852 | |
| 3853 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3854 | static const u8 center_channels_5ghz_160mhz[] = { 50, 114, 163 }; |
| 3855 | static const u8 center_channels_6ghz_160mhz[] = { 15, 47, 79, 111, 143, 175, |
| 3856 | 207 }; |
| 3857 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3858 | static enum chan_allowed wpas_p2p_verify_160mhz(struct wpa_supplicant *wpa_s, |
| 3859 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3860 | u8 op_class, u8 channel, u8 bw) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3861 | { |
| 3862 | u8 center_chan; |
| 3863 | int i, flags; |
| 3864 | enum chan_allowed res, ret = ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3865 | const u8 *chans; |
| 3866 | size_t num_chans; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3867 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3868 | if (is_6ghz_op_class(op_class)) { |
| 3869 | chans = center_channels_6ghz_160mhz; |
| 3870 | num_chans = ARRAY_SIZE(center_channels_6ghz_160mhz); |
| 3871 | } else { |
| 3872 | chans = center_channels_5ghz_160mhz; |
| 3873 | num_chans = ARRAY_SIZE(center_channels_5ghz_160mhz); |
| 3874 | } |
| 3875 | center_chan = wpas_p2p_get_center_160mhz(wpa_s, mode, channel, |
| 3876 | chans, num_chans); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3877 | if (!center_chan) |
| 3878 | return NOT_ALLOWED; |
| 3879 | /* VHT 160 MHz uses DFS channels in most countries. */ |
| 3880 | |
| 3881 | /* Check all the channels are available */ |
| 3882 | for (i = 0; i < 8; i++) { |
| 3883 | int adj_chan = center_chan - 14 + i * 4; |
| 3884 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3885 | res = has_channel(wpa_s->global, mode, op_class, adj_chan, |
| 3886 | &flags); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3887 | if (res == NOT_ALLOWED) |
| 3888 | return NOT_ALLOWED; |
| 3889 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3890 | if (res == RADAR) |
| 3891 | ret = RADAR; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3892 | if (res == NO_IR) |
| 3893 | ret = NO_IR; |
| 3894 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3895 | if (!is_6ghz_op_class(op_class)) { |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3896 | if (!(flags & HOSTAPD_CHAN_VHT_80MHZ_SUBCHANNEL) || |
| 3897 | !(flags & HOSTAPD_CHAN_VHT_160MHZ_SUBCHANNEL)) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3898 | return NOT_ALLOWED; |
| 3899 | } else if (is_6ghz_op_class(op_class) && |
| 3900 | (!(wpas_get_6ghz_he_chwidth_capab(mode) & |
| 3901 | HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G))) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3902 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3903 | } |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3904 | } |
| 3905 | |
| 3906 | return ret; |
| 3907 | } |
| 3908 | |
| 3909 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3910 | static enum chan_allowed wpas_p2p_verify_edmg(struct wpa_supplicant *wpa_s, |
| 3911 | struct hostapd_hw_modes *mode, |
| 3912 | u8 channel) |
| 3913 | { |
| 3914 | struct ieee80211_edmg_config edmg; |
| 3915 | |
| 3916 | hostapd_encode_edmg_chan(1, channel, 0, &edmg); |
| 3917 | if (edmg.channels && ieee802_edmg_is_allowed(mode->edmg, edmg)) |
| 3918 | return ALLOWED; |
| 3919 | |
| 3920 | return NOT_ALLOWED; |
| 3921 | } |
| 3922 | |
| 3923 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3924 | static enum chan_allowed wpas_p2p_verify_channel(struct wpa_supplicant *wpa_s, |
| 3925 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3926 | u8 op_class, u8 channel, u8 bw) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3927 | { |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 3928 | int flag = 0; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3929 | enum chan_allowed res, res2; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3930 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3931 | if (is_6ghz_op_class(op_class) && !is_6ghz_psc_frequency( |
| 3932 | p2p_channel_to_freq(op_class, channel))) |
| 3933 | return NOT_ALLOWED; |
| 3934 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3935 | res2 = res = has_channel(wpa_s->global, mode, op_class, channel, &flag); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3936 | if (bw == BW40MINUS) { |
| 3937 | if (!(flag & HOSTAPD_CHAN_HT40MINUS)) |
| 3938 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3939 | res2 = has_channel(wpa_s->global, mode, op_class, channel - 4, |
| 3940 | NULL); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3941 | } else if (bw == BW40PLUS) { |
| 3942 | if (!(flag & HOSTAPD_CHAN_HT40PLUS)) |
| 3943 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3944 | res2 = has_channel(wpa_s->global, mode, op_class, channel + 4, |
| 3945 | NULL); |
| 3946 | } else if (is_6ghz_op_class(op_class) && bw == BW40) { |
| 3947 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 3948 | return NOT_ALLOWED; |
| 3949 | if (get_6ghz_sec_channel(channel) < 0) |
| 3950 | res2 = has_channel(wpa_s->global, mode, op_class, |
| 3951 | channel - 4, NULL); |
| 3952 | else |
| 3953 | res2 = has_channel(wpa_s->global, mode, op_class, |
| 3954 | channel + 4, NULL); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3955 | } else if (bw == BW80) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3956 | res2 = wpas_p2p_verify_80mhz(wpa_s, mode, op_class, channel, |
| 3957 | bw); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3958 | } else if (bw == BW160) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3959 | res2 = wpas_p2p_verify_160mhz(wpa_s, mode, op_class, channel, |
| 3960 | bw); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3961 | } else if (bw == BW4320 || bw == BW6480 || bw == BW8640) { |
| 3962 | return wpas_p2p_verify_edmg(wpa_s, mode, channel); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3963 | } |
| 3964 | |
| 3965 | if (res == NOT_ALLOWED || res2 == NOT_ALLOWED) |
| 3966 | return NOT_ALLOWED; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3967 | if (res == NO_IR || res2 == NO_IR) |
| 3968 | return NO_IR; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3969 | if (res == RADAR || res2 == RADAR) |
| 3970 | return RADAR; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3971 | return res; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3972 | } |
| 3973 | |
| 3974 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3975 | static int wpas_p2p_setup_channels(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3976 | struct p2p_channels *chan, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3977 | struct p2p_channels *cli_chan, |
| 3978 | bool p2p_disable_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3979 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3980 | struct hostapd_hw_modes *mode; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3981 | int cla, op, cli_cla; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3982 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3983 | if (wpa_s->hw.modes == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3984 | wpa_printf(MSG_DEBUG, "P2P: Driver did not support fetching " |
| 3985 | "of all supported channels; assume dualband " |
| 3986 | "support"); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3987 | return wpas_p2p_default_channels(wpa_s, chan, cli_chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3988 | } |
| 3989 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3990 | cla = cli_cla = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3991 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3992 | for (op = 0; global_op_class[op].op_class; op++) { |
| 3993 | const struct oper_class_map *o = &global_op_class[op]; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3994 | unsigned int ch; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3995 | struct p2p_reg_class *reg = NULL, *cli_reg = NULL; |
Shuibing Dai | 64a8a89 | 2023-03-08 10:26:22 -0800 | [diff] [blame^] | 3996 | bool check_dfs_supported = (wpa_s->conf->p2p_dfs_chan_enable |
| 3997 | && is_dfs_global_op_class(o->op_class)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3998 | |
Shuibing Dai | 64a8a89 | 2023-03-08 10:26:22 -0800 | [diff] [blame^] | 3999 | if ((!check_dfs_supported && o->p2p == NO_P2P_SUPP) || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4000 | (is_6ghz_op_class(o->op_class) && p2p_disable_6ghz)) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4001 | continue; |
| 4002 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4003 | mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, o->mode, |
| 4004 | is_6ghz_op_class(o->op_class)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4005 | if (mode == NULL) |
| 4006 | continue; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4007 | if (mode->mode == HOSTAPD_MODE_IEEE80211G) |
| 4008 | wpa_s->global->p2p_24ghz_social_channels = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4009 | for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4010 | enum chan_allowed res; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4011 | |
| 4012 | /* Check for non-continuous jump in channel index |
| 4013 | * incrementation */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4014 | if ((o->op_class >= 128 && o->op_class <= 130) && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4015 | ch < 149 && ch + o->inc > 149) |
| 4016 | ch = 149; |
| 4017 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4018 | res = wpas_p2p_verify_channel(wpa_s, mode, o->op_class, |
| 4019 | ch, o->bw); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4020 | if (res == ALLOWED) { |
| 4021 | if (reg == NULL) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4022 | if (cla == P2P_MAX_REG_CLASSES) |
| 4023 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4024 | wpa_printf(MSG_DEBUG, "P2P: Add operating class %u", |
| 4025 | o->op_class); |
| 4026 | reg = &chan->reg_class[cla]; |
| 4027 | cla++; |
| 4028 | reg->reg_class = o->op_class; |
| 4029 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4030 | if (reg->channels == P2P_MAX_REG_CLASS_CHANNELS) |
| 4031 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4032 | reg->channel[reg->channels] = ch; |
| 4033 | reg->channels++; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4034 | } else if (res == NO_IR && |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4035 | wpa_s->conf->p2p_add_cli_chan) { |
| 4036 | if (cli_reg == NULL) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4037 | if (cli_cla == P2P_MAX_REG_CLASSES) |
| 4038 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4039 | wpa_printf(MSG_DEBUG, "P2P: Add operating class %u (client only)", |
| 4040 | o->op_class); |
| 4041 | cli_reg = &cli_chan->reg_class[cli_cla]; |
| 4042 | cli_cla++; |
| 4043 | cli_reg->reg_class = o->op_class; |
| 4044 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4045 | if (cli_reg->channels == |
| 4046 | P2P_MAX_REG_CLASS_CHANNELS) |
| 4047 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4048 | cli_reg->channel[cli_reg->channels] = ch; |
| 4049 | cli_reg->channels++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4050 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4051 | } |
| 4052 | if (reg) { |
| 4053 | wpa_hexdump(MSG_DEBUG, "P2P: Channels", |
| 4054 | reg->channel, reg->channels); |
| 4055 | } |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4056 | if (cli_reg) { |
| 4057 | wpa_hexdump(MSG_DEBUG, "P2P: Channels (client only)", |
| 4058 | cli_reg->channel, cli_reg->channels); |
| 4059 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | chan->reg_classes = cla; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4063 | cli_chan->reg_classes = cli_cla; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4064 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4065 | return 0; |
| 4066 | } |
| 4067 | |
| 4068 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4069 | int wpas_p2p_get_sec_channel_offset_40mhz(struct wpa_supplicant *wpa_s, |
| 4070 | struct hostapd_hw_modes *mode, |
| 4071 | u8 channel) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4072 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4073 | int op; |
| 4074 | enum chan_allowed ret; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4075 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4076 | for (op = 0; global_op_class[op].op_class; op++) { |
| 4077 | const struct oper_class_map *o = &global_op_class[op]; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4078 | u16 ch = 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4079 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4080 | /* Allow DFS channels marked as NO_P2P_SUPP to be used with |
| 4081 | * driver offloaded DFS. */ |
| 4082 | if ((o->p2p == NO_P2P_SUPP && |
| 4083 | (!is_dfs_global_op_class(o->op_class) || |
| 4084 | !wpa_s->p2p_go_allow_dfs)) || |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4085 | (is_6ghz_op_class(o->op_class) && |
| 4086 | wpa_s->conf->p2p_6ghz_disable)) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4087 | continue; |
| 4088 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4089 | /* IEEE Std 802.11ax-2021 26.17.2.3.2: "A 6 GHz-only AP should |
| 4090 | * set up the BSS with a primary 20 MHz channel that coincides |
| 4091 | * with a preferred scanning channel (PSC)." |
| 4092 | * 6 GHz BW40 operation class 132 in wpa_supplicant uses the |
| 4093 | * lowest 20 MHz channel for simplicity, so increase ch by 4 to |
| 4094 | * match the PSC. |
| 4095 | */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4096 | if (is_6ghz_op_class(o->op_class) && o->bw == BW40 && |
| 4097 | get_6ghz_sec_channel(channel) < 0) |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4098 | ch = 4; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4099 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4100 | for (ch += o->min_chan; ch <= o->max_chan; ch += o->inc) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4101 | if (o->mode != HOSTAPD_MODE_IEEE80211A || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4102 | (o->bw != BW40PLUS && o->bw != BW40MINUS && |
| 4103 | o->bw != BW40) || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4104 | ch != channel) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4105 | continue; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4106 | ret = wpas_p2p_verify_channel(wpa_s, mode, o->op_class, |
| 4107 | ch, o->bw); |
| 4108 | if (ret == ALLOWED) { |
| 4109 | if (is_6ghz_op_class(o->op_class) && |
| 4110 | o->bw == BW40) |
| 4111 | return get_6ghz_sec_channel(channel); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4112 | return (o->bw == BW40MINUS) ? -1 : 1; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4113 | } |
| 4114 | if (ret == RADAR && wpa_s->p2p_go_allow_dfs) { |
| 4115 | /* Allow RADAR channels used for driver |
| 4116 | * offloaded DFS */ |
| 4117 | return (o->bw == BW40MINUS) ? -1 : 1; |
| 4118 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4119 | } |
| 4120 | } |
| 4121 | return 0; |
| 4122 | } |
| 4123 | |
| 4124 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4125 | int wpas_p2p_get_vht80_center(struct wpa_supplicant *wpa_s, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4126 | struct hostapd_hw_modes *mode, u8 channel, |
| 4127 | u8 op_class) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4128 | { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4129 | const u8 *chans; |
| 4130 | size_t num_chans; |
| 4131 | enum chan_allowed ret; |
| 4132 | |
| 4133 | ret = wpas_p2p_verify_channel(wpa_s, mode, op_class, channel, BW80); |
| 4134 | if (!(ret == ALLOWED || (ret == RADAR && wpa_s->p2p_go_allow_dfs))) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4135 | return 0; |
| 4136 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4137 | if (is_6ghz_op_class(op_class)) { |
| 4138 | chans = center_channels_6ghz_80mhz; |
| 4139 | num_chans = ARRAY_SIZE(center_channels_6ghz_80mhz); |
| 4140 | } else { |
| 4141 | chans = center_channels_5ghz_80mhz; |
| 4142 | num_chans = ARRAY_SIZE(center_channels_5ghz_80mhz); |
| 4143 | } |
| 4144 | return wpas_p2p_get_center_80mhz(wpa_s, mode, channel, |
| 4145 | chans, num_chans); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4146 | } |
| 4147 | |
| 4148 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4149 | int wpas_p2p_get_vht160_center(struct wpa_supplicant *wpa_s, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4150 | struct hostapd_hw_modes *mode, u8 channel, |
| 4151 | u8 op_class) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4152 | { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4153 | const u8 *chans; |
| 4154 | size_t num_chans; |
| 4155 | enum chan_allowed ret; |
| 4156 | |
| 4157 | ret = wpas_p2p_verify_channel(wpa_s, mode, op_class, channel, BW160); |
| 4158 | if (!(ret == ALLOWED || (ret == RADAR && wpa_s->p2p_go_allow_dfs))) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4159 | return 0; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4160 | if (is_6ghz_op_class(op_class)) { |
| 4161 | chans = center_channels_6ghz_160mhz; |
| 4162 | num_chans = ARRAY_SIZE(center_channels_6ghz_160mhz); |
| 4163 | } else { |
| 4164 | chans = center_channels_5ghz_160mhz; |
| 4165 | num_chans = ARRAY_SIZE(center_channels_5ghz_160mhz); |
| 4166 | } |
| 4167 | return wpas_p2p_get_center_160mhz(wpa_s, mode, channel, |
| 4168 | chans, num_chans); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4169 | } |
| 4170 | |
| 4171 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4172 | static int wpas_get_noa(void *ctx, const u8 *interface_addr, u8 *buf, |
| 4173 | size_t buf_len) |
| 4174 | { |
| 4175 | struct wpa_supplicant *wpa_s = ctx; |
| 4176 | |
| 4177 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 4178 | if (os_memcmp(wpa_s->own_addr, interface_addr, ETH_ALEN) == 0) |
| 4179 | break; |
| 4180 | } |
| 4181 | if (wpa_s == NULL) |
| 4182 | return -1; |
| 4183 | |
| 4184 | return wpa_drv_get_noa(wpa_s, buf, buf_len); |
| 4185 | } |
| 4186 | |
| 4187 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4188 | struct wpa_supplicant * wpas_get_p2p_go_iface(struct wpa_supplicant *wpa_s, |
| 4189 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4190 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4191 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 4192 | struct wpa_ssid *s = wpa_s->current_ssid; |
| 4193 | if (s == NULL) |
| 4194 | continue; |
| 4195 | if (s->mode != WPAS_MODE_P2P_GO && |
| 4196 | s->mode != WPAS_MODE_AP && |
| 4197 | s->mode != WPAS_MODE_P2P_GROUP_FORMATION) |
| 4198 | continue; |
| 4199 | if (s->ssid_len != ssid_len || |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 4200 | os_memcmp(ssid, s->ssid, ssid_len) != 0) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4201 | continue; |
| 4202 | return wpa_s; |
| 4203 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4204 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4205 | return NULL; |
| 4206 | |
| 4207 | } |
| 4208 | |
| 4209 | |
| 4210 | struct wpa_supplicant * wpas_get_p2p_client_iface(struct wpa_supplicant *wpa_s, |
| 4211 | const u8 *peer_dev_addr) |
| 4212 | { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4213 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 4214 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4215 | if (ssid && (ssid->mode != WPAS_MODE_INFRA || !ssid->p2p_group)) |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4216 | continue; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4217 | if (os_memcmp(wpa_s->go_dev_addr, peer_dev_addr, ETH_ALEN) == 0) |
| 4218 | return wpa_s; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4219 | } |
| 4220 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4221 | return NULL; |
| 4222 | } |
| 4223 | |
| 4224 | |
| 4225 | static int wpas_go_connected(void *ctx, const u8 *dev_addr) |
| 4226 | { |
| 4227 | struct wpa_supplicant *wpa_s = ctx; |
| 4228 | |
| 4229 | return wpas_get_p2p_client_iface(wpa_s, dev_addr) != NULL; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 4233 | static int wpas_is_concurrent_session_active(void *ctx) |
| 4234 | { |
| 4235 | struct wpa_supplicant *wpa_s = ctx; |
| 4236 | struct wpa_supplicant *ifs; |
| 4237 | |
| 4238 | for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) { |
| 4239 | if (ifs == wpa_s) |
| 4240 | continue; |
| 4241 | if (ifs->wpa_state > WPA_ASSOCIATED) |
| 4242 | return 1; |
| 4243 | } |
| 4244 | return 0; |
| 4245 | } |
| 4246 | |
| 4247 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 4248 | static void wpas_p2p_debug_print(void *ctx, int level, const char *msg) |
| 4249 | { |
| 4250 | struct wpa_supplicant *wpa_s = ctx; |
| 4251 | wpa_msg_global(wpa_s, level, "P2P: %s", msg); |
| 4252 | } |
| 4253 | |
| 4254 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4255 | int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s, |
| 4256 | const char *conf_p2p_dev) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4257 | { |
| 4258 | struct wpa_interface iface; |
| 4259 | struct wpa_supplicant *p2pdev_wpa_s; |
| 4260 | char ifname[100]; |
| 4261 | char force_name[100]; |
| 4262 | int ret; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4263 | const u8 *if_addr = NULL; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4264 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4265 | ret = os_snprintf(ifname, sizeof(ifname), P2P_MGMT_DEVICE_PREFIX "%s", |
| 4266 | wpa_s->ifname); |
| 4267 | if (os_snprintf_error(sizeof(ifname), ret)) |
| 4268 | return -1; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4269 | /* Cut length at the maximum size. Note that we don't need to ensure |
| 4270 | * collision free names here as the created interface is not a netdev. |
| 4271 | */ |
| 4272 | ifname[IFNAMSIZ - 1] = '\0'; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4273 | force_name[0] = '\0'; |
| 4274 | wpa_s->pending_interface_type = WPA_IF_P2P_DEVICE; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4275 | |
| 4276 | if (wpa_s->conf->p2p_device_random_mac_addr == 2 && |
| 4277 | !is_zero_ether_addr(wpa_s->conf->p2p_device_persistent_mac_addr)) |
| 4278 | if_addr = wpa_s->conf->p2p_device_persistent_mac_addr; |
| 4279 | |
| 4280 | 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] | 4281 | force_name, wpa_s->pending_interface_addr, NULL); |
| 4282 | if (ret < 0) { |
| 4283 | wpa_printf(MSG_DEBUG, "P2P: Failed to create P2P Device interface"); |
| 4284 | return ret; |
| 4285 | } |
| 4286 | os_strlcpy(wpa_s->pending_interface_name, ifname, |
| 4287 | sizeof(wpa_s->pending_interface_name)); |
| 4288 | |
| 4289 | os_memset(&iface, 0, sizeof(iface)); |
| 4290 | iface.p2p_mgmt = 1; |
| 4291 | iface.ifname = wpa_s->pending_interface_name; |
| 4292 | iface.driver = wpa_s->driver->name; |
| 4293 | iface.driver_param = wpa_s->conf->driver_param; |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4294 | |
| 4295 | /* |
| 4296 | * If a P2P Device configuration file was given, use it as the interface |
| 4297 | * configuration file (instead of using parent's configuration file. |
| 4298 | */ |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4299 | if (conf_p2p_dev) { |
| 4300 | iface.confname = conf_p2p_dev; |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4301 | iface.ctrl_interface = NULL; |
| 4302 | } else { |
| 4303 | iface.confname = wpa_s->confname; |
| 4304 | iface.ctrl_interface = wpa_s->conf->ctrl_interface; |
| 4305 | } |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4306 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4307 | 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] | 4308 | if (!p2pdev_wpa_s) { |
| 4309 | wpa_printf(MSG_DEBUG, "P2P: Failed to add P2P Device interface"); |
| 4310 | return -1; |
| 4311 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4312 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4313 | p2pdev_wpa_s->p2pdev = p2pdev_wpa_s; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4314 | wpa_s->pending_interface_name[0] = '\0'; |
| 4315 | return 0; |
| 4316 | } |
| 4317 | |
| 4318 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4319 | static void wpas_presence_resp(void *ctx, const u8 *src, u8 status, |
| 4320 | const u8 *noa, size_t noa_len) |
| 4321 | { |
| 4322 | struct wpa_supplicant *wpa_s, *intf = ctx; |
| 4323 | char hex[100]; |
| 4324 | |
| 4325 | for (wpa_s = intf->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 4326 | if (wpa_s->waiting_presence_resp) |
| 4327 | break; |
| 4328 | } |
| 4329 | if (!wpa_s) { |
| 4330 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No group interface was waiting for presence response"); |
| 4331 | return; |
| 4332 | } |
| 4333 | wpa_s->waiting_presence_resp = 0; |
| 4334 | |
| 4335 | wpa_snprintf_hex(hex, sizeof(hex), noa, noa_len); |
| 4336 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PRESENCE_RESPONSE "src=" MACSTR |
| 4337 | " status=%u noa=%s", MAC2STR(src), status, hex); |
| 4338 | } |
| 4339 | |
| 4340 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4341 | static int wpas_get_persistent_group(void *ctx, const u8 *addr, const u8 *ssid, |
| 4342 | size_t ssid_len, u8 *go_dev_addr, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4343 | u8 *ret_ssid, size_t *ret_ssid_len, |
| 4344 | u8 *intended_iface_addr) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4345 | { |
| 4346 | struct wpa_supplicant *wpa_s = ctx; |
| 4347 | struct wpa_ssid *s; |
| 4348 | |
| 4349 | s = wpas_p2p_get_persistent(wpa_s, addr, ssid, ssid_len); |
| 4350 | if (s) { |
| 4351 | os_memcpy(ret_ssid, s->ssid, s->ssid_len); |
| 4352 | *ret_ssid_len = s->ssid_len; |
| 4353 | os_memcpy(go_dev_addr, s->bssid, ETH_ALEN); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4354 | |
| 4355 | if (s->mode != WPAS_MODE_P2P_GO) { |
| 4356 | os_memset(intended_iface_addr, 0, ETH_ALEN); |
| 4357 | } else if (wpas_p2p_create_iface(wpa_s)) { |
| 4358 | if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO)) |
| 4359 | return 0; |
| 4360 | |
| 4361 | os_memcpy(intended_iface_addr, |
| 4362 | wpa_s->pending_interface_addr, ETH_ALEN); |
| 4363 | } else { |
| 4364 | os_memcpy(intended_iface_addr, wpa_s->own_addr, |
| 4365 | ETH_ALEN); |
| 4366 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4367 | return 1; |
| 4368 | } |
| 4369 | |
| 4370 | return 0; |
| 4371 | } |
| 4372 | |
| 4373 | |
| 4374 | static int wpas_get_go_info(void *ctx, u8 *intended_addr, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4375 | u8 *ssid, size_t *ssid_len, int *group_iface, |
| 4376 | unsigned int *freq) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4377 | { |
| 4378 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4379 | struct wpa_supplicant *go; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4380 | struct wpa_ssid *s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4381 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4382 | /* |
| 4383 | * group_iface will be set to 1 only if a dedicated interface for P2P |
| 4384 | * role is required. First, we try to reuse an active GO. However, |
| 4385 | * if it is not present, we will try to reactivate an existing |
| 4386 | * persistent group and set group_iface to 1, so the caller will know |
| 4387 | * that the pending interface should be used. |
| 4388 | */ |
| 4389 | *group_iface = 0; |
| 4390 | |
| 4391 | if (freq) |
| 4392 | *freq = 0; |
| 4393 | |
| 4394 | go = wpas_p2p_get_go_group(wpa_s); |
| 4395 | if (!go) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4396 | s = wpas_p2p_get_persistent_go(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4397 | *group_iface = wpas_p2p_create_iface(wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4398 | if (s) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4399 | os_memcpy(intended_addr, s->bssid, ETH_ALEN); |
| 4400 | else |
| 4401 | return 0; |
| 4402 | } else { |
| 4403 | s = go->current_ssid; |
| 4404 | os_memcpy(intended_addr, go->own_addr, ETH_ALEN); |
| 4405 | if (freq) |
| 4406 | *freq = go->assoc_freq; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4407 | } |
| 4408 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4409 | os_memcpy(ssid, s->ssid, s->ssid_len); |
| 4410 | *ssid_len = s->ssid_len; |
| 4411 | |
| 4412 | return 1; |
| 4413 | } |
| 4414 | |
| 4415 | |
| 4416 | static int wpas_remove_stale_groups(void *ctx, const u8 *peer, const u8 *go, |
| 4417 | const u8 *ssid, size_t ssid_len) |
| 4418 | { |
| 4419 | struct wpa_supplicant *wpa_s = ctx; |
| 4420 | struct wpa_ssid *s; |
| 4421 | int save_config = 0; |
| 4422 | size_t i; |
| 4423 | |
| 4424 | /* Start with our first choice of Persistent Groups */ |
| 4425 | while ((s = wpas_p2p_get_persistent(wpa_s, peer, NULL, 0))) { |
| 4426 | if (go && ssid && ssid_len && |
| 4427 | s->ssid_len == ssid_len && |
| 4428 | os_memcmp(go, s->bssid, ETH_ALEN) == 0 && |
| 4429 | os_memcmp(ssid, s->ssid, ssid_len) == 0) |
| 4430 | break; |
| 4431 | |
| 4432 | /* Remove stale persistent group */ |
| 4433 | if (s->mode != WPAS_MODE_P2P_GO || s->num_p2p_clients <= 1) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4434 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4435 | "P2P: Remove stale persistent group id=%d", |
| 4436 | s->id); |
| 4437 | wpas_notify_persistent_group_removed(wpa_s, s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4438 | wpa_config_remove_network(wpa_s->conf, s->id); |
| 4439 | save_config = 1; |
| 4440 | continue; |
| 4441 | } |
| 4442 | |
| 4443 | for (i = 0; i < s->num_p2p_clients; i++) { |
| 4444 | if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN, |
| 4445 | peer, ETH_ALEN) != 0) |
| 4446 | continue; |
| 4447 | |
| 4448 | os_memmove(s->p2p_client_list + i * 2 * ETH_ALEN, |
| 4449 | s->p2p_client_list + (i + 1) * 2 * ETH_ALEN, |
| 4450 | (s->num_p2p_clients - i - 1) * 2 * ETH_ALEN); |
| 4451 | break; |
| 4452 | } |
| 4453 | s->num_p2p_clients--; |
| 4454 | save_config = 1; |
| 4455 | } |
| 4456 | |
| 4457 | if (save_config) |
| 4458 | p2p_config_write(wpa_s); |
| 4459 | |
| 4460 | /* Return TRUE if valid SSID remains */ |
| 4461 | return s != NULL; |
| 4462 | } |
| 4463 | |
| 4464 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4465 | static void wpas_p2ps_get_feat_cap_str(char *buf, size_t buf_len, |
| 4466 | const u8 *feat_cap, size_t feat_cap_len) |
| 4467 | { |
| 4468 | static const char pref[] = " feature_cap="; |
| 4469 | int ret; |
| 4470 | |
| 4471 | buf[0] = '\0'; |
| 4472 | |
| 4473 | /* |
| 4474 | * We expect a feature capability to contain at least one byte to be |
| 4475 | * reported. The string buffer provided by the caller function is |
| 4476 | * expected to be big enough to contain all bytes of the attribute for |
| 4477 | * known specifications. This function truncates the reported bytes if |
| 4478 | * the feature capability data exceeds the string buffer size. |
| 4479 | */ |
| 4480 | if (!feat_cap || !feat_cap_len || buf_len < sizeof(pref) + 2) |
| 4481 | return; |
| 4482 | |
| 4483 | os_memcpy(buf, pref, sizeof(pref)); |
| 4484 | ret = wpa_snprintf_hex(&buf[sizeof(pref) - 1], |
| 4485 | buf_len - sizeof(pref) + 1, |
| 4486 | feat_cap, feat_cap_len); |
| 4487 | |
| 4488 | if (ret != (2 * (int) feat_cap_len)) |
| 4489 | wpa_printf(MSG_WARNING, "P2PS feature_cap bytes truncated"); |
| 4490 | } |
| 4491 | |
| 4492 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4493 | static void wpas_p2ps_prov_complete(void *ctx, u8 status, const u8 *dev, |
| 4494 | const u8 *adv_mac, const u8 *ses_mac, |
| 4495 | const u8 *grp_mac, u32 adv_id, u32 ses_id, |
| 4496 | u8 conncap, int passwd_id, |
| 4497 | const u8 *persist_ssid, |
| 4498 | size_t persist_ssid_size, int response_done, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4499 | int prov_start, const char *session_info, |
| 4500 | const u8 *feat_cap, size_t feat_cap_len, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4501 | unsigned int freq, |
| 4502 | const u8 *group_ssid, size_t group_ssid_len) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4503 | { |
| 4504 | struct wpa_supplicant *wpa_s = ctx; |
| 4505 | u8 mac[ETH_ALEN]; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4506 | struct wpa_ssid *persistent_go, *stale, *s = NULL; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4507 | int save_config = 0; |
| 4508 | struct wpa_supplicant *go_wpa_s; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4509 | char feat_cap_str[256]; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4510 | |
| 4511 | if (!dev) |
| 4512 | return; |
| 4513 | |
| 4514 | os_memset(mac, 0, ETH_ALEN); |
| 4515 | if (!adv_mac) |
| 4516 | adv_mac = mac; |
| 4517 | if (!ses_mac) |
| 4518 | ses_mac = mac; |
| 4519 | if (!grp_mac) |
| 4520 | grp_mac = mac; |
| 4521 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4522 | wpas_p2ps_get_feat_cap_str(feat_cap_str, sizeof(feat_cap_str), |
| 4523 | feat_cap, feat_cap_len); |
| 4524 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4525 | if (prov_start) { |
| 4526 | if (session_info == NULL) { |
| 4527 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4528 | P2P_EVENT_P2PS_PROVISION_START MACSTR |
| 4529 | " adv_id=%x conncap=%x" |
| 4530 | " adv_mac=" MACSTR |
| 4531 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4532 | " dev_passwd_id=%d%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4533 | MAC2STR(dev), adv_id, conncap, |
| 4534 | MAC2STR(adv_mac), |
| 4535 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4536 | passwd_id, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4537 | } else { |
| 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 info='%s'%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, session_info, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4548 | } |
| 4549 | return; |
| 4550 | } |
| 4551 | |
| 4552 | go_wpa_s = wpas_p2p_get_go_group(wpa_s); |
| 4553 | persistent_go = wpas_p2p_get_persistent_go(wpa_s); |
| 4554 | |
| 4555 | if (status && status != P2P_SC_SUCCESS_DEFERRED) { |
| 4556 | if (go_wpa_s && !p2p_group_go_member_count(wpa_s)) |
| 4557 | wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname); |
| 4558 | |
| 4559 | if (persistent_go && !persistent_go->num_p2p_clients) { |
| 4560 | /* remove empty persistent GO */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4561 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4562 | "P2P: Remove empty persistent group id=%d", |
| 4563 | persistent_go->id); |
| 4564 | wpas_notify_persistent_group_removed(wpa_s, |
| 4565 | persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4566 | wpa_config_remove_network(wpa_s->conf, |
| 4567 | persistent_go->id); |
| 4568 | } |
| 4569 | |
| 4570 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4571 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4572 | " status=%d" |
| 4573 | " adv_id=%x adv_mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4574 | " session=%x mac=" MACSTR "%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4575 | MAC2STR(dev), status, |
| 4576 | adv_id, MAC2STR(adv_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4577 | ses_id, MAC2STR(ses_mac), feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4578 | return; |
| 4579 | } |
| 4580 | |
| 4581 | /* Clean up stale persistent groups with this device */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4582 | if (persist_ssid && persist_ssid_size) |
| 4583 | s = wpas_p2p_get_persistent(wpa_s, dev, persist_ssid, |
| 4584 | persist_ssid_size); |
| 4585 | |
| 4586 | if (persist_ssid && s && s->mode != WPAS_MODE_P2P_GO && |
| 4587 | is_zero_ether_addr(grp_mac)) { |
| 4588 | wpa_dbg(wpa_s, MSG_ERROR, |
| 4589 | "P2P: Peer device is a GO in a persistent group, but it did not provide the intended MAC address"); |
| 4590 | return; |
| 4591 | } |
| 4592 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4593 | for (;;) { |
| 4594 | stale = wpas_p2p_get_persistent(wpa_s, dev, NULL, 0); |
| 4595 | if (!stale) |
| 4596 | break; |
| 4597 | |
| 4598 | if (s && s->ssid_len == stale->ssid_len && |
| 4599 | os_memcmp(stale->bssid, s->bssid, ETH_ALEN) == 0 && |
| 4600 | os_memcmp(stale->ssid, s->ssid, s->ssid_len) == 0) |
| 4601 | break; |
| 4602 | |
| 4603 | /* Remove stale persistent group */ |
| 4604 | if (stale->mode != WPAS_MODE_P2P_GO || |
| 4605 | stale->num_p2p_clients <= 1) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4606 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4607 | "P2P: Remove stale persistent group id=%d", |
| 4608 | stale->id); |
| 4609 | wpas_notify_persistent_group_removed(wpa_s, stale); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4610 | wpa_config_remove_network(wpa_s->conf, stale->id); |
| 4611 | } else { |
| 4612 | size_t i; |
| 4613 | |
| 4614 | for (i = 0; i < stale->num_p2p_clients; i++) { |
| 4615 | if (os_memcmp(stale->p2p_client_list + |
| 4616 | i * ETH_ALEN, |
| 4617 | dev, ETH_ALEN) == 0) { |
| 4618 | os_memmove(stale->p2p_client_list + |
| 4619 | i * ETH_ALEN, |
| 4620 | stale->p2p_client_list + |
| 4621 | (i + 1) * ETH_ALEN, |
| 4622 | (stale->num_p2p_clients - |
| 4623 | i - 1) * ETH_ALEN); |
| 4624 | break; |
| 4625 | } |
| 4626 | } |
| 4627 | stale->num_p2p_clients--; |
| 4628 | } |
| 4629 | save_config = 1; |
| 4630 | } |
| 4631 | |
| 4632 | if (save_config) |
| 4633 | p2p_config_write(wpa_s); |
| 4634 | |
| 4635 | if (s) { |
| 4636 | if (go_wpa_s && !p2p_group_go_member_count(wpa_s)) |
| 4637 | wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname); |
| 4638 | |
| 4639 | if (persistent_go && s != persistent_go && |
| 4640 | !persistent_go->num_p2p_clients) { |
| 4641 | /* remove empty persistent GO */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4642 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4643 | "P2P: Remove empty persistent group id=%d", |
| 4644 | persistent_go->id); |
| 4645 | wpas_notify_persistent_group_removed(wpa_s, |
| 4646 | persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4647 | wpa_config_remove_network(wpa_s->conf, |
| 4648 | persistent_go->id); |
| 4649 | /* Save config */ |
| 4650 | } |
| 4651 | |
| 4652 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4653 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4654 | " status=%d" |
| 4655 | " adv_id=%x adv_mac=" MACSTR |
| 4656 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4657 | " persist=%d%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4658 | MAC2STR(dev), status, |
| 4659 | adv_id, MAC2STR(adv_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4660 | ses_id, MAC2STR(ses_mac), s->id, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4661 | return; |
| 4662 | } |
| 4663 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4664 | wpa_s->global->pending_p2ps_group = 0; |
| 4665 | wpa_s->global->pending_p2ps_group_freq = 0; |
| 4666 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4667 | if (conncap == P2PS_SETUP_GROUP_OWNER) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4668 | /* |
| 4669 | * We need to copy the interface name. Simply saving a |
| 4670 | * pointer isn't enough, since if we use pending_interface_name |
| 4671 | * it will be overwritten when the group is added. |
| 4672 | */ |
| 4673 | char go_ifname[100]; |
| 4674 | |
| 4675 | go_ifname[0] = '\0'; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4676 | if (!go_wpa_s) { |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4677 | if (!response_done) { |
| 4678 | wpa_s->global->pending_p2ps_group = 1; |
| 4679 | wpa_s->global->pending_p2ps_group_freq = freq; |
| 4680 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4681 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4682 | if (!wpas_p2p_create_iface(wpa_s)) |
| 4683 | os_memcpy(go_ifname, wpa_s->ifname, |
| 4684 | sizeof(go_ifname)); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4685 | else if (wpa_s->pending_interface_name[0]) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4686 | os_memcpy(go_ifname, |
| 4687 | wpa_s->pending_interface_name, |
| 4688 | sizeof(go_ifname)); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4689 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4690 | if (!go_ifname[0]) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4691 | wpas_p2ps_prov_complete( |
| 4692 | wpa_s, P2P_SC_FAIL_UNKNOWN_GROUP, |
| 4693 | dev, adv_mac, ses_mac, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4694 | grp_mac, adv_id, ses_id, 0, 0, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4695 | NULL, 0, 0, 0, NULL, NULL, 0, 0, |
| 4696 | NULL, 0); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4697 | return; |
| 4698 | } |
| 4699 | |
| 4700 | /* If PD Resp complete, start up the GO */ |
| 4701 | if (response_done && persistent_go) { |
| 4702 | wpas_p2p_group_add_persistent( |
| 4703 | wpa_s, persistent_go, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4704 | 0, 0, freq, 0, 0, 0, 0, 0, 0, NULL, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4705 | persistent_go->mode == |
| 4706 | WPAS_MODE_P2P_GO ? |
| 4707 | P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4708 | 0, 0, false, 0, NULL); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4709 | } else if (response_done) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4710 | wpas_p2p_group_add(wpa_s, 1, freq, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4711 | 0, 0, 0, 0, 0, 0, false); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4712 | } |
| 4713 | |
| 4714 | if (passwd_id == DEV_PW_P2PS_DEFAULT) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4715 | os_memcpy(wpa_s->p2ps_join_addr, grp_mac, |
| 4716 | ETH_ALEN); |
| 4717 | wpa_s->p2ps_method_config_any = 1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4718 | } |
| 4719 | } else if (passwd_id == DEV_PW_P2PS_DEFAULT) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4720 | os_memcpy(go_ifname, go_wpa_s->ifname, |
| 4721 | sizeof(go_ifname)); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4722 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4723 | if (is_zero_ether_addr(grp_mac)) { |
| 4724 | wpa_dbg(go_wpa_s, MSG_DEBUG, |
| 4725 | "P2P: Setting PIN-1 for ANY"); |
| 4726 | wpa_supplicant_ap_wps_pin(go_wpa_s, NULL, |
| 4727 | "12345670", NULL, 0, |
| 4728 | 0); |
| 4729 | } else { |
| 4730 | wpa_dbg(go_wpa_s, MSG_DEBUG, |
| 4731 | "P2P: Setting PIN-1 for " MACSTR, |
| 4732 | MAC2STR(grp_mac)); |
| 4733 | wpa_supplicant_ap_wps_pin(go_wpa_s, grp_mac, |
| 4734 | "12345670", NULL, 0, |
| 4735 | 0); |
| 4736 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4737 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4738 | os_memcpy(wpa_s->p2ps_join_addr, grp_mac, ETH_ALEN); |
| 4739 | wpa_s->p2ps_method_config_any = 1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4740 | } |
| 4741 | |
| 4742 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4743 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4744 | " status=%d conncap=%x" |
| 4745 | " adv_id=%x adv_mac=" MACSTR |
| 4746 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4747 | " dev_passwd_id=%d go=%s%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4748 | MAC2STR(dev), status, conncap, |
| 4749 | adv_id, MAC2STR(adv_mac), |
| 4750 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4751 | passwd_id, go_ifname, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4752 | return; |
| 4753 | } |
| 4754 | |
| 4755 | if (go_wpa_s && !p2p_group_go_member_count(wpa_s)) |
| 4756 | wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname); |
| 4757 | |
| 4758 | if (persistent_go && !persistent_go->num_p2p_clients) { |
| 4759 | /* remove empty persistent GO */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4760 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4761 | "P2P: Remove empty persistent group id=%d", |
| 4762 | persistent_go->id); |
| 4763 | wpas_notify_persistent_group_removed(wpa_s, persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4764 | wpa_config_remove_network(wpa_s->conf, persistent_go->id); |
| 4765 | } |
| 4766 | |
| 4767 | if (conncap == P2PS_SETUP_CLIENT) { |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4768 | char ssid_hex[32 * 2 + 1]; |
| 4769 | |
| 4770 | if (group_ssid) |
| 4771 | wpa_snprintf_hex(ssid_hex, sizeof(ssid_hex), |
| 4772 | group_ssid, group_ssid_len); |
| 4773 | else |
| 4774 | ssid_hex[0] = '\0'; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4775 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4776 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4777 | " status=%d conncap=%x" |
| 4778 | " adv_id=%x adv_mac=" MACSTR |
| 4779 | " session=%x mac=" MACSTR |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4780 | " dev_passwd_id=%d join=" MACSTR "%s%s%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4781 | MAC2STR(dev), status, conncap, |
| 4782 | adv_id, MAC2STR(adv_mac), |
| 4783 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4784 | passwd_id, MAC2STR(grp_mac), feat_cap_str, |
| 4785 | group_ssid ? " group_ssid=" : "", ssid_hex); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4786 | } else { |
| 4787 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4788 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4789 | " status=%d conncap=%x" |
| 4790 | " adv_id=%x adv_mac=" MACSTR |
| 4791 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4792 | " dev_passwd_id=%d%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4793 | MAC2STR(dev), status, conncap, |
| 4794 | adv_id, MAC2STR(adv_mac), |
| 4795 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4796 | passwd_id, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4797 | } |
| 4798 | } |
| 4799 | |
| 4800 | |
Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 4801 | static int _wpas_p2p_in_progress(void *ctx) |
| 4802 | { |
| 4803 | struct wpa_supplicant *wpa_s = ctx; |
| 4804 | return wpas_p2p_in_progress(wpa_s); |
| 4805 | } |
| 4806 | |
| 4807 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4808 | static int wpas_prov_disc_resp_cb(void *ctx) |
| 4809 | { |
| 4810 | struct wpa_supplicant *wpa_s = ctx; |
| 4811 | struct wpa_ssid *persistent_go; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4812 | unsigned int freq; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4813 | |
| 4814 | if (!wpa_s->global->pending_p2ps_group) |
| 4815 | return 0; |
| 4816 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4817 | freq = wpa_s->global->pending_p2ps_group_freq; |
| 4818 | wpa_s->global->pending_p2ps_group_freq = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4819 | wpa_s->global->pending_p2ps_group = 0; |
| 4820 | |
| 4821 | if (wpas_p2p_get_go_group(wpa_s)) |
| 4822 | return 0; |
| 4823 | persistent_go = wpas_p2p_get_persistent_go(wpa_s); |
| 4824 | |
| 4825 | if (persistent_go) { |
| 4826 | wpas_p2p_group_add_persistent( |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4827 | wpa_s, persistent_go, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 4828 | NULL, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4829 | persistent_go->mode == WPAS_MODE_P2P_GO ? |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4830 | P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0, 0, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4831 | is_p2p_allow_6ghz(wpa_s->global->p2p), 0, NULL); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4832 | } else { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4833 | wpas_p2p_group_add(wpa_s, 1, freq, 0, 0, 0, 0, 0, 0, |
| 4834 | is_p2p_allow_6ghz(wpa_s->global->p2p)); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4835 | } |
| 4836 | |
| 4837 | return 1; |
| 4838 | } |
| 4839 | |
| 4840 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4841 | static int wpas_p2p_get_pref_freq_list(void *ctx, int go, |
| 4842 | unsigned int *len, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4843 | struct weighted_pcl *freq_list) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4844 | { |
| 4845 | struct wpa_supplicant *wpa_s = ctx; |
| 4846 | |
| 4847 | return wpa_drv_get_pref_freq_list(wpa_s, go ? WPA_IF_P2P_GO : |
| 4848 | WPA_IF_P2P_CLIENT, len, freq_list); |
| 4849 | } |
| 4850 | |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4851 | int wpas_p2p_mac_setup(struct wpa_supplicant *wpa_s) |
| 4852 | { |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4853 | int ret = 0; |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4854 | u8 addr[ETH_ALEN] = {0}; |
| 4855 | |
| 4856 | if (wpa_s->conf->p2p_device_random_mac_addr == 0) |
| 4857 | return 0; |
| 4858 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4859 | if (wpa_s->conf->p2p_device_random_mac_addr == 2) { |
| 4860 | if (is_zero_ether_addr( |
| 4861 | wpa_s->conf->p2p_device_persistent_mac_addr) && |
| 4862 | !is_zero_ether_addr(wpa_s->own_addr)) { |
| 4863 | os_memcpy(wpa_s->conf->p2p_device_persistent_mac_addr, |
| 4864 | wpa_s->own_addr, ETH_ALEN); |
| 4865 | } |
| 4866 | return 0; |
| 4867 | } |
| 4868 | |
| 4869 | if (!wpa_s->conf->ssid) { |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4870 | if (random_mac_addr(addr) < 0) { |
| 4871 | wpa_msg(wpa_s, MSG_INFO, |
| 4872 | "Failed to generate random MAC address"); |
| 4873 | return -EINVAL; |
| 4874 | } |
| 4875 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 4876 | /* Store generated MAC address. */ |
| 4877 | os_memcpy(wpa_s->conf->p2p_device_persistent_mac_addr, addr, |
| 4878 | ETH_ALEN); |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4879 | } else { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 4880 | /* If there are existing saved groups, restore last MAC address. |
| 4881 | * if there is no last used MAC address, the last one is |
| 4882 | * factory MAC. */ |
| 4883 | if (is_zero_ether_addr( |
| 4884 | wpa_s->conf->p2p_device_persistent_mac_addr)) |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4885 | return 0; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 4886 | os_memcpy(addr, wpa_s->conf->p2p_device_persistent_mac_addr, |
| 4887 | ETH_ALEN); |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4888 | wpa_msg(wpa_s, MSG_DEBUG, "Restore last used MAC address."); |
| 4889 | } |
| 4890 | |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4891 | ret = wpa_drv_set_mac_addr(wpa_s, addr); |
| 4892 | |
| 4893 | if (ret < 0) { |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4894 | wpa_msg(wpa_s, MSG_INFO, |
| 4895 | "Failed to set random MAC address"); |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4896 | return ret; |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4897 | } |
| 4898 | |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4899 | ret = wpa_supplicant_update_mac_addr(wpa_s); |
| 4900 | |
| 4901 | if (ret < 0) { |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4902 | wpa_msg(wpa_s, MSG_INFO, |
| 4903 | "Could not update MAC address information"); |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4904 | return ret; |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4905 | } |
| 4906 | |
| 4907 | wpa_msg(wpa_s, MSG_DEBUG, "Using random MAC address " MACSTR, |
| 4908 | MAC2STR(addr)); |
| 4909 | |
| 4910 | return 0; |
| 4911 | } |
| 4912 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4913 | /** |
| 4914 | * wpas_p2p_init - Initialize P2P module for %wpa_supplicant |
| 4915 | * @global: Pointer to global data from wpa_supplicant_init() |
| 4916 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 4917 | * Returns: 0 on success, -1 on failure |
| 4918 | */ |
| 4919 | int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s) |
| 4920 | { |
| 4921 | struct p2p_config p2p; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4922 | int i; |
| 4923 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 4924 | if (wpa_s->conf->p2p_disabled) |
| 4925 | return 0; |
| 4926 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4927 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE)) |
| 4928 | return 0; |
| 4929 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4930 | if (global->p2p) |
| 4931 | return 0; |
| 4932 | |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4933 | if (wpas_p2p_mac_setup(wpa_s) < 0) { |
| 4934 | wpa_msg(wpa_s, MSG_ERROR, |
| 4935 | "Failed to initialize P2P random MAC address."); |
| 4936 | return -1; |
| 4937 | } |
| 4938 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4939 | os_memset(&p2p, 0, sizeof(p2p)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4940 | p2p.cb_ctx = wpa_s; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 4941 | p2p.debug_print = wpas_p2p_debug_print; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4942 | p2p.p2p_scan = wpas_p2p_scan; |
| 4943 | p2p.send_action = wpas_send_action; |
| 4944 | p2p.send_action_done = wpas_send_action_done; |
| 4945 | p2p.go_neg_completed = wpas_go_neg_completed; |
| 4946 | p2p.go_neg_req_rx = wpas_go_neg_req_rx; |
| 4947 | p2p.dev_found = wpas_dev_found; |
| 4948 | p2p.dev_lost = wpas_dev_lost; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 4949 | p2p.find_stopped = wpas_find_stopped; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4950 | p2p.start_listen = wpas_start_listen; |
| 4951 | p2p.stop_listen = wpas_stop_listen; |
| 4952 | p2p.send_probe_resp = wpas_send_probe_resp; |
| 4953 | p2p.sd_request = wpas_sd_request; |
| 4954 | p2p.sd_response = wpas_sd_response; |
| 4955 | p2p.prov_disc_req = wpas_prov_disc_req; |
| 4956 | p2p.prov_disc_resp = wpas_prov_disc_resp; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 4957 | p2p.prov_disc_fail = wpas_prov_disc_fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4958 | p2p.invitation_process = wpas_invitation_process; |
| 4959 | p2p.invitation_received = wpas_invitation_received; |
| 4960 | p2p.invitation_result = wpas_invitation_result; |
| 4961 | p2p.get_noa = wpas_get_noa; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4962 | p2p.go_connected = wpas_go_connected; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4963 | p2p.presence_resp = wpas_presence_resp; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 4964 | p2p.is_concurrent_session_active = wpas_is_concurrent_session_active; |
Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 4965 | p2p.is_p2p_in_progress = _wpas_p2p_in_progress; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4966 | p2p.get_persistent_group = wpas_get_persistent_group; |
| 4967 | p2p.get_go_info = wpas_get_go_info; |
| 4968 | p2p.remove_stale_groups = wpas_remove_stale_groups; |
| 4969 | p2p.p2ps_prov_complete = wpas_p2ps_prov_complete; |
| 4970 | p2p.prov_disc_resp_cb = wpas_prov_disc_resp_cb; |
| 4971 | p2p.p2ps_group_capability = p2ps_group_capability; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4972 | p2p.get_pref_freq_list = wpas_p2p_get_pref_freq_list; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4973 | p2p.p2p_6ghz_disable = wpa_s->conf->p2p_6ghz_disable; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4974 | |
| 4975 | 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] | 4976 | 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] | 4977 | p2p.dev_name = wpa_s->conf->device_name; |
| 4978 | p2p.manufacturer = wpa_s->conf->manufacturer; |
| 4979 | p2p.model_name = wpa_s->conf->model_name; |
| 4980 | p2p.model_number = wpa_s->conf->model_number; |
| 4981 | p2p.serial_number = wpa_s->conf->serial_number; |
| 4982 | if (wpa_s->wps) { |
| 4983 | os_memcpy(p2p.uuid, wpa_s->wps->uuid, 16); |
| 4984 | p2p.config_methods = wpa_s->wps->config_methods; |
| 4985 | } |
| 4986 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4987 | if (wpas_p2p_setup_channels(wpa_s, &p2p.channels, &p2p.cli_channels, |
| 4988 | p2p.p2p_6ghz_disable)) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4989 | wpa_printf(MSG_ERROR, |
| 4990 | "P2P: Failed to configure supported channel list"); |
| 4991 | return -1; |
| 4992 | } |
| 4993 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4994 | if (wpa_s->conf->p2p_listen_reg_class && |
| 4995 | wpa_s->conf->p2p_listen_channel) { |
| 4996 | p2p.reg_class = wpa_s->conf->p2p_listen_reg_class; |
| 4997 | p2p.channel = wpa_s->conf->p2p_listen_channel; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 4998 | p2p.channel_forced = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4999 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5000 | /* |
| 5001 | * Pick one of the social channels randomly as the listen |
| 5002 | * channel. |
| 5003 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5004 | if (p2p_config_get_random_social(&p2p, &p2p.reg_class, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5005 | &p2p.channel, |
| 5006 | &global->p2p_go_avoid_freq, |
| 5007 | &global->p2p_disallow_freq) != |
| 5008 | 0) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 5009 | wpa_printf(MSG_INFO, |
| 5010 | "P2P: No social channels supported by the driver - do not enable P2P"); |
| 5011 | return 0; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5012 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5013 | p2p.channel_forced = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5014 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5015 | wpa_printf(MSG_DEBUG, "P2P: Own listen channel: %d:%d", |
| 5016 | p2p.reg_class, p2p.channel); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5017 | |
| 5018 | if (wpa_s->conf->p2p_oper_reg_class && |
| 5019 | wpa_s->conf->p2p_oper_channel) { |
| 5020 | p2p.op_reg_class = wpa_s->conf->p2p_oper_reg_class; |
| 5021 | p2p.op_channel = wpa_s->conf->p2p_oper_channel; |
| 5022 | p2p.cfg_op_channel = 1; |
| 5023 | wpa_printf(MSG_DEBUG, "P2P: Configured operating channel: " |
| 5024 | "%d:%d", p2p.op_reg_class, p2p.op_channel); |
| 5025 | |
| 5026 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5027 | /* |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5028 | * Use random operation channel from 2.4 GHz band social |
| 5029 | * channels (1, 6, 11) or band 60 GHz social channel (2) if no |
| 5030 | * other preference is indicated. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5031 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5032 | if (p2p_config_get_random_social(&p2p, &p2p.op_reg_class, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5033 | &p2p.op_channel, NULL, |
| 5034 | NULL) != 0) { |
| 5035 | wpa_printf(MSG_INFO, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5036 | "P2P: Failed to select random social channel as operation channel"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5037 | p2p.op_reg_class = 0; |
| 5038 | p2p.op_channel = 0; |
| 5039 | /* This will be overridden during group setup in |
| 5040 | * p2p_prepare_channel(), so allow setup to continue. */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5041 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5042 | p2p.cfg_op_channel = 0; |
| 5043 | wpa_printf(MSG_DEBUG, "P2P: Random operating channel: " |
| 5044 | "%d:%d", p2p.op_reg_class, p2p.op_channel); |
| 5045 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 5046 | |
| 5047 | if (wpa_s->conf->p2p_pref_chan && wpa_s->conf->num_p2p_pref_chan) { |
| 5048 | p2p.pref_chan = wpa_s->conf->p2p_pref_chan; |
| 5049 | p2p.num_pref_chan = wpa_s->conf->num_p2p_pref_chan; |
| 5050 | } |
| 5051 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5052 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) { |
| 5053 | os_memcpy(p2p.country, wpa_s->conf->country, 2); |
| 5054 | p2p.country[2] = 0x04; |
| 5055 | } else |
| 5056 | os_memcpy(p2p.country, "XX\x04", 3); |
| 5057 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5058 | os_memcpy(p2p.pri_dev_type, wpa_s->conf->device_type, |
| 5059 | WPS_DEV_TYPE_LEN); |
| 5060 | |
| 5061 | p2p.num_sec_dev_types = wpa_s->conf->num_sec_device_types; |
| 5062 | os_memcpy(p2p.sec_dev_type, wpa_s->conf->sec_device_type, |
| 5063 | p2p.num_sec_dev_types * WPS_DEV_TYPE_LEN); |
| 5064 | |
| 5065 | p2p.concurrent_operations = !!(wpa_s->drv_flags & |
| 5066 | WPA_DRIVER_FLAGS_P2P_CONCURRENT); |
| 5067 | |
| 5068 | p2p.max_peers = 100; |
| 5069 | |
| 5070 | if (wpa_s->conf->p2p_ssid_postfix) { |
| 5071 | p2p.ssid_postfix_len = |
| 5072 | os_strlen(wpa_s->conf->p2p_ssid_postfix); |
| 5073 | if (p2p.ssid_postfix_len > sizeof(p2p.ssid_postfix)) |
| 5074 | p2p.ssid_postfix_len = sizeof(p2p.ssid_postfix); |
| 5075 | os_memcpy(p2p.ssid_postfix, wpa_s->conf->p2p_ssid_postfix, |
| 5076 | p2p.ssid_postfix_len); |
| 5077 | } |
| 5078 | |
| 5079 | p2p.p2p_intra_bss = wpa_s->conf->p2p_intra_bss; |
| 5080 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5081 | p2p.max_listen = wpa_s->max_remain_on_chan; |
| 5082 | |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 5083 | if (wpa_s->conf->p2p_passphrase_len >= 8 && |
| 5084 | wpa_s->conf->p2p_passphrase_len <= 63) |
| 5085 | p2p.passphrase_len = wpa_s->conf->p2p_passphrase_len; |
| 5086 | else |
| 5087 | p2p.passphrase_len = 8; |
| 5088 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5089 | global->p2p = p2p_init(&p2p); |
| 5090 | if (global->p2p == NULL) |
| 5091 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5092 | global->p2p_init_wpa_s = wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5093 | |
| 5094 | for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) { |
| 5095 | if (wpa_s->conf->wps_vendor_ext[i] == NULL) |
| 5096 | continue; |
| 5097 | p2p_add_wps_vendor_extension( |
| 5098 | global->p2p, wpa_s->conf->wps_vendor_ext[i]); |
| 5099 | } |
| 5100 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5101 | p2p_set_no_go_freq(global->p2p, &wpa_s->conf->p2p_no_go_freq); |
| 5102 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5103 | return 0; |
| 5104 | } |
| 5105 | |
| 5106 | |
| 5107 | /** |
| 5108 | * wpas_p2p_deinit - Deinitialize per-interface P2P data |
| 5109 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 5110 | * |
| 5111 | * This function deinitialize per-interface P2P data. |
| 5112 | */ |
| 5113 | void wpas_p2p_deinit(struct wpa_supplicant *wpa_s) |
| 5114 | { |
| 5115 | if (wpa_s->driver && wpa_s->drv_priv) |
| 5116 | wpa_drv_probe_req_report(wpa_s, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5117 | |
| 5118 | if (wpa_s->go_params) { |
| 5119 | /* Clear any stored provisioning info */ |
| 5120 | p2p_clear_provisioning_info( |
| 5121 | wpa_s->global->p2p, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5122 | wpa_s->go_params->peer_device_addr); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5123 | } |
| 5124 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5125 | os_free(wpa_s->go_params); |
| 5126 | wpa_s->go_params = NULL; |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 5127 | eloop_cancel_timeout(wpas_p2p_psk_failure_removal, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5128 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 5129 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5130 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5131 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
| 5132 | eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL); |
| 5133 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 5134 | eloop_cancel_timeout(wpas_p2p_group_freq_conflict, wpa_s, NULL); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5135 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, wpa_s, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5136 | wpas_p2p_listen_work_done(wpa_s); |
| 5137 | if (wpa_s->p2p_send_action_work) { |
| 5138 | os_free(wpa_s->p2p_send_action_work->ctx); |
| 5139 | radio_work_done(wpa_s->p2p_send_action_work); |
| 5140 | wpa_s->p2p_send_action_work = NULL; |
| 5141 | } |
| 5142 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5143 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5144 | wpabuf_free(wpa_s->p2p_oob_dev_pw); |
| 5145 | wpa_s->p2p_oob_dev_pw = NULL; |
| 5146 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5147 | os_free(wpa_s->p2p_group_common_freqs); |
| 5148 | wpa_s->p2p_group_common_freqs = NULL; |
| 5149 | wpa_s->p2p_group_common_freqs_num = 0; |
| 5150 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5151 | /* TODO: remove group interface from the driver if this wpa_s instance |
| 5152 | * is on top of a P2P group interface */ |
| 5153 | } |
| 5154 | |
| 5155 | |
| 5156 | /** |
| 5157 | * wpas_p2p_deinit_global - Deinitialize global P2P module |
| 5158 | * @global: Pointer to global data from wpa_supplicant_init() |
| 5159 | * |
| 5160 | * This function deinitializes the global (per device) P2P module. |
| 5161 | */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5162 | static void wpas_p2p_deinit_global(struct wpa_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5163 | { |
| 5164 | struct wpa_supplicant *wpa_s, *tmp; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5165 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5166 | wpa_s = global->ifaces; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5167 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5168 | wpas_p2p_service_flush(global->p2p_init_wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5169 | |
| 5170 | /* Remove remaining P2P group interfaces */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5171 | while (wpa_s && wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) |
| 5172 | wpa_s = wpa_s->next; |
| 5173 | while (wpa_s) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5174 | tmp = global->ifaces; |
| 5175 | while (tmp && |
| 5176 | (tmp == wpa_s || |
| 5177 | tmp->p2p_group_interface == NOT_P2P_GROUP_INTERFACE)) { |
| 5178 | tmp = tmp->next; |
| 5179 | } |
| 5180 | if (tmp == NULL) |
| 5181 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5182 | /* Disconnect from the P2P group and deinit the interface */ |
| 5183 | wpas_p2p_disconnect(tmp); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5184 | } |
| 5185 | |
| 5186 | /* |
| 5187 | * Deinit GO data on any possibly remaining interface (if main |
| 5188 | * interface is used as GO). |
| 5189 | */ |
| 5190 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 5191 | if (wpa_s->ap_iface) |
| 5192 | wpas_p2p_group_deinit(wpa_s); |
| 5193 | } |
| 5194 | |
| 5195 | p2p_deinit(global->p2p); |
| 5196 | global->p2p = NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5197 | global->p2p_init_wpa_s = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5198 | } |
| 5199 | |
| 5200 | |
| 5201 | static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s) |
| 5202 | { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5203 | if (wpa_s->conf->p2p_no_group_iface) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5204 | return 0; /* separate interface disabled per configuration */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5205 | if (wpa_s->drv_flags & |
| 5206 | (WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE | |
| 5207 | WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P)) |
| 5208 | return 1; /* P2P group requires a new interface in every case |
| 5209 | */ |
| 5210 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CONCURRENT)) |
| 5211 | return 0; /* driver does not support concurrent operations */ |
| 5212 | if (wpa_s->global->ifaces->next) |
| 5213 | return 1; /* more that one interface already in use */ |
| 5214 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
| 5215 | return 1; /* this interface is already in use */ |
| 5216 | return 0; |
| 5217 | } |
| 5218 | |
| 5219 | |
| 5220 | static int wpas_p2p_start_go_neg(struct wpa_supplicant *wpa_s, |
| 5221 | const u8 *peer_addr, |
| 5222 | enum p2p_wps_method wps_method, |
| 5223 | int go_intent, const u8 *own_interface_addr, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5224 | unsigned int force_freq, int persistent_group, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5225 | struct wpa_ssid *ssid, unsigned int pref_freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5226 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5227 | if (persistent_group && wpa_s->conf->persistent_reconnect) |
| 5228 | persistent_group = 2; |
| 5229 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5230 | /* |
| 5231 | * Increase GO config timeout if HT40 is used since it takes some time |
| 5232 | * to scan channels for coex purposes before the BSS can be started. |
| 5233 | */ |
| 5234 | p2p_set_config_timeout(wpa_s->global->p2p, |
| 5235 | wpa_s->p2p_go_ht40 ? 255 : 100, 20); |
| 5236 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5237 | return p2p_connect(wpa_s->global->p2p, peer_addr, wps_method, |
| 5238 | go_intent, own_interface_addr, force_freq, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5239 | persistent_group, ssid ? ssid->ssid : NULL, |
| 5240 | ssid ? ssid->ssid_len : 0, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5241 | wpa_s->p2p_pd_before_go_neg, pref_freq, |
| 5242 | wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id : |
| 5243 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5244 | } |
| 5245 | |
| 5246 | |
| 5247 | static int wpas_p2p_auth_go_neg(struct wpa_supplicant *wpa_s, |
| 5248 | const u8 *peer_addr, |
| 5249 | enum p2p_wps_method wps_method, |
| 5250 | int go_intent, const u8 *own_interface_addr, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5251 | unsigned int force_freq, int persistent_group, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5252 | struct wpa_ssid *ssid, unsigned int pref_freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5253 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5254 | if (persistent_group && wpa_s->conf->persistent_reconnect) |
| 5255 | persistent_group = 2; |
| 5256 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5257 | return p2p_authorize(wpa_s->global->p2p, peer_addr, wps_method, |
| 5258 | go_intent, own_interface_addr, force_freq, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5259 | persistent_group, ssid ? ssid->ssid : NULL, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5260 | ssid ? ssid->ssid_len : 0, pref_freq, |
| 5261 | wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id : |
| 5262 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5263 | } |
| 5264 | |
| 5265 | |
| 5266 | static void wpas_p2p_check_join_scan_limit(struct wpa_supplicant *wpa_s) |
| 5267 | { |
| 5268 | wpa_s->p2p_join_scan_count++; |
| 5269 | wpa_printf(MSG_DEBUG, "P2P: Join scan attempt %d", |
| 5270 | wpa_s->p2p_join_scan_count); |
| 5271 | if (wpa_s->p2p_join_scan_count > P2P_MAX_JOIN_SCAN_ATTEMPTS) { |
| 5272 | wpa_printf(MSG_DEBUG, "P2P: Failed to find GO " MACSTR |
| 5273 | " for join operationg - stop join attempt", |
| 5274 | MAC2STR(wpa_s->pending_join_iface_addr)); |
| 5275 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5276 | if (wpa_s->p2p_auto_pd) { |
| 5277 | wpa_s->p2p_auto_pd = 0; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5278 | wpa_msg_global(wpa_s, MSG_INFO, |
| 5279 | P2P_EVENT_PROV_DISC_FAILURE |
| 5280 | " p2p_dev_addr=" MACSTR " status=N/A", |
| 5281 | MAC2STR(wpa_s->pending_join_dev_addr)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5282 | return; |
| 5283 | } |
Jimmy Chen | b7b3f4d | 2020-09-02 16:50:11 +0800 | [diff] [blame] | 5284 | if (wpa_s->p2p_fallback_to_go_neg) { |
| 5285 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Join operating " |
| 5286 | "failed - fall back to GO Negotiation"); |
| 5287 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
| 5288 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 5289 | "reason=join-failed"); |
| 5290 | wpas_p2p_fallback_to_go_neg(wpa_s, 0); |
| 5291 | return; |
| 5292 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5293 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5294 | P2P_EVENT_GROUP_FORMATION_FAILURE); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5295 | wpas_notify_p2p_group_formation_failure(wpa_s, ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5296 | } |
| 5297 | } |
| 5298 | |
| 5299 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5300 | static int wpas_check_freq_conflict(struct wpa_supplicant *wpa_s, int freq) |
| 5301 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5302 | int res; |
| 5303 | unsigned int num, i; |
| 5304 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5305 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5306 | if (wpas_p2p_num_unused_channels(wpa_s) > 0) { |
| 5307 | /* Multiple channels are supported and not all are in use */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5308 | return 0; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5309 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5310 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5311 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 5312 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5313 | if (!freqs) |
| 5314 | return 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5315 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5316 | num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, |
| 5317 | wpa_s->num_multichan_concurrent); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5318 | |
| 5319 | for (i = 0; i < num; i++) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5320 | if (freqs[i].freq == freq) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5321 | wpa_printf(MSG_DEBUG, "P2P: Frequency %d MHz in use by another virtual interface and can be used", |
| 5322 | freq); |
| 5323 | res = 0; |
| 5324 | goto exit_free; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5325 | } |
| 5326 | } |
| 5327 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5328 | wpa_printf(MSG_DEBUG, "P2P: No valid operating frequencies"); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5329 | res = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5330 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5331 | exit_free: |
| 5332 | os_free(freqs); |
| 5333 | return res; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5334 | } |
| 5335 | |
| 5336 | |
| 5337 | static int wpas_p2p_peer_go(struct wpa_supplicant *wpa_s, |
| 5338 | const u8 *peer_dev_addr) |
| 5339 | { |
| 5340 | struct wpa_bss *bss; |
| 5341 | int updated; |
| 5342 | |
| 5343 | bss = wpa_bss_get_p2p_dev_addr(wpa_s, peer_dev_addr); |
| 5344 | if (bss == NULL) |
| 5345 | return -1; |
| 5346 | if (bss->last_update_idx < wpa_s->bss_update_idx) { |
| 5347 | wpa_printf(MSG_DEBUG, "P2P: Peer BSS entry not updated in the " |
| 5348 | "last scan"); |
| 5349 | return 0; |
| 5350 | } |
| 5351 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5352 | updated = os_reltime_before(&wpa_s->p2p_auto_started, |
| 5353 | &bss->last_update); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5354 | wpa_printf(MSG_DEBUG, "P2P: Current BSS entry for peer updated at " |
| 5355 | "%ld.%06ld (%supdated in last scan)", |
| 5356 | bss->last_update.sec, bss->last_update.usec, |
| 5357 | updated ? "": "not "); |
| 5358 | |
| 5359 | return updated; |
| 5360 | } |
| 5361 | |
| 5362 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5363 | static void wpas_p2p_scan_res_join(struct wpa_supplicant *wpa_s, |
| 5364 | struct wpa_scan_results *scan_res) |
| 5365 | { |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5366 | struct wpa_bss *bss = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5367 | int freq; |
| 5368 | u8 iface_addr[ETH_ALEN]; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5369 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5370 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
| 5371 | |
| 5372 | if (wpa_s->global->p2p_disabled) |
| 5373 | return; |
| 5374 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5375 | wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS) for %sjoin", |
| 5376 | scan_res ? (int) scan_res->num : -1, |
| 5377 | wpa_s->p2p_auto_join ? "auto_" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5378 | |
| 5379 | if (scan_res) |
| 5380 | wpas_p2p_scan_res_handler(wpa_s, scan_res); |
| 5381 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5382 | if (wpa_s->p2p_auto_pd) { |
| 5383 | int join = wpas_p2p_peer_go(wpa_s, |
| 5384 | wpa_s->pending_join_dev_addr); |
| 5385 | if (join == 0 && |
| 5386 | wpa_s->auto_pd_scan_retry < P2P_AUTO_PD_SCAN_ATTEMPTS) { |
| 5387 | wpa_s->auto_pd_scan_retry++; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5388 | bss = wpa_bss_get_bssid_latest( |
| 5389 | wpa_s, wpa_s->pending_join_dev_addr); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5390 | if (bss) { |
| 5391 | freq = bss->freq; |
| 5392 | wpa_printf(MSG_DEBUG, "P2P: Scan retry %d for " |
| 5393 | "the peer " MACSTR " at %d MHz", |
| 5394 | wpa_s->auto_pd_scan_retry, |
| 5395 | MAC2STR(wpa_s-> |
| 5396 | pending_join_dev_addr), |
| 5397 | freq); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5398 | wpas_p2p_join_scan_req(wpa_s, freq, NULL, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5399 | return; |
| 5400 | } |
| 5401 | } |
| 5402 | |
| 5403 | if (join < 0) |
| 5404 | join = 0; |
| 5405 | |
| 5406 | wpa_s->p2p_auto_pd = 0; |
| 5407 | wpa_s->pending_pd_use = join ? AUTO_PD_JOIN : AUTO_PD_GO_NEG; |
| 5408 | wpa_printf(MSG_DEBUG, "P2P: Auto PD with " MACSTR " join=%d", |
| 5409 | MAC2STR(wpa_s->pending_join_dev_addr), join); |
| 5410 | if (p2p_prov_disc_req(wpa_s->global->p2p, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5411 | wpa_s->pending_join_dev_addr, NULL, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5412 | wpa_s->pending_pd_config_methods, join, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5413 | 0, wpa_s->user_initiated_pd) < 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5414 | wpa_s->p2p_auto_pd = 0; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5415 | wpa_msg_global(wpa_s, MSG_INFO, |
| 5416 | P2P_EVENT_PROV_DISC_FAILURE |
| 5417 | " p2p_dev_addr=" MACSTR " status=N/A", |
| 5418 | MAC2STR(wpa_s->pending_join_dev_addr)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5419 | } |
| 5420 | return; |
| 5421 | } |
| 5422 | |
| 5423 | if (wpa_s->p2p_auto_join) { |
| 5424 | int join = wpas_p2p_peer_go(wpa_s, |
| 5425 | wpa_s->pending_join_dev_addr); |
| 5426 | if (join < 0) { |
| 5427 | wpa_printf(MSG_DEBUG, "P2P: Peer was not found to be " |
| 5428 | "running a GO -> use GO Negotiation"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5429 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5430 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 5431 | "reason=peer-not-running-GO"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5432 | wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr, |
| 5433 | wpa_s->p2p_pin, wpa_s->p2p_wps_method, |
| 5434 | wpa_s->p2p_persistent_group, 0, 0, 0, |
| 5435 | wpa_s->p2p_go_intent, |
| 5436 | wpa_s->p2p_connect_freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5437 | wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5438 | wpa_s->p2p_persistent_id, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5439 | wpa_s->p2p_pd_before_go_neg, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5440 | wpa_s->p2p_go_ht40, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5441 | wpa_s->p2p_go_vht, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5442 | wpa_s->p2p_go_max_oper_chwidth, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5443 | wpa_s->p2p_go_he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 5444 | wpa_s->p2p_go_edmg, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5445 | NULL, 0, |
| 5446 | is_p2p_allow_6ghz(wpa_s->global->p2p)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5447 | return; |
| 5448 | } |
| 5449 | |
| 5450 | wpa_printf(MSG_DEBUG, "P2P: Peer was found running GO%s -> " |
| 5451 | "try to join the group", join ? "" : |
| 5452 | " in older scan"); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5453 | if (!join) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5454 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5455 | P2P_EVENT_FALLBACK_TO_GO_NEG_ENABLED); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5456 | wpa_s->p2p_fallback_to_go_neg = 1; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5457 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5458 | } |
| 5459 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5460 | freq = p2p_get_oper_freq(wpa_s->global->p2p, |
| 5461 | wpa_s->pending_join_iface_addr); |
| 5462 | if (freq < 0 && |
| 5463 | p2p_get_interface_addr(wpa_s->global->p2p, |
| 5464 | wpa_s->pending_join_dev_addr, |
| 5465 | iface_addr) == 0 && |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5466 | os_memcmp(iface_addr, wpa_s->pending_join_dev_addr, ETH_ALEN) != 0 |
| 5467 | && !wpa_bss_get_bssid(wpa_s, wpa_s->pending_join_iface_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5468 | wpa_printf(MSG_DEBUG, "P2P: Overwrite pending interface " |
| 5469 | "address for join from " MACSTR " to " MACSTR |
| 5470 | " based on newly discovered P2P peer entry", |
| 5471 | MAC2STR(wpa_s->pending_join_iface_addr), |
| 5472 | MAC2STR(iface_addr)); |
| 5473 | os_memcpy(wpa_s->pending_join_iface_addr, iface_addr, |
| 5474 | ETH_ALEN); |
| 5475 | |
| 5476 | freq = p2p_get_oper_freq(wpa_s->global->p2p, |
| 5477 | wpa_s->pending_join_iface_addr); |
| 5478 | } |
| 5479 | if (freq >= 0) { |
| 5480 | wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency " |
| 5481 | "from P2P peer table: %d MHz", freq); |
| 5482 | } |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5483 | if (wpa_s->p2p_join_ssid_len) { |
| 5484 | wpa_printf(MSG_DEBUG, "P2P: Trying to find target GO BSS entry based on BSSID " |
| 5485 | MACSTR " and SSID %s", |
| 5486 | MAC2STR(wpa_s->pending_join_iface_addr), |
| 5487 | wpa_ssid_txt(wpa_s->p2p_join_ssid, |
| 5488 | wpa_s->p2p_join_ssid_len)); |
| 5489 | bss = wpa_bss_get(wpa_s, wpa_s->pending_join_iface_addr, |
| 5490 | wpa_s->p2p_join_ssid, |
| 5491 | wpa_s->p2p_join_ssid_len); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5492 | } else if (!bss) { |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5493 | wpa_printf(MSG_DEBUG, "P2P: Trying to find target GO BSS entry based on BSSID " |
| 5494 | MACSTR, MAC2STR(wpa_s->pending_join_iface_addr)); |
| 5495 | bss = wpa_bss_get_bssid_latest(wpa_s, |
| 5496 | wpa_s->pending_join_iface_addr); |
| 5497 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5498 | if (bss) { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5499 | u8 dev_addr[ETH_ALEN]; |
| 5500 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5501 | freq = bss->freq; |
| 5502 | wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency " |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 5503 | "from BSS table: %d MHz (SSID %s)", freq, |
| 5504 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5505 | 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] | 5506 | dev_addr) == 0 && |
| 5507 | os_memcmp(wpa_s->pending_join_dev_addr, |
| 5508 | wpa_s->pending_join_iface_addr, ETH_ALEN) == 0 && |
| 5509 | os_memcmp(dev_addr, wpa_s->pending_join_dev_addr, |
| 5510 | ETH_ALEN) != 0) { |
| 5511 | wpa_printf(MSG_DEBUG, |
| 5512 | "P2P: Update target GO device address based on BSS entry: " MACSTR " (was " MACSTR ")", |
| 5513 | MAC2STR(dev_addr), |
| 5514 | MAC2STR(wpa_s->pending_join_dev_addr)); |
| 5515 | os_memcpy(wpa_s->pending_join_dev_addr, dev_addr, |
| 5516 | ETH_ALEN); |
| 5517 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5518 | } |
| 5519 | if (freq > 0) { |
| 5520 | u16 method; |
| 5521 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5522 | if (wpas_check_freq_conflict(wpa_s, freq) > 0) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5523 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5524 | P2P_EVENT_GROUP_FORMATION_FAILURE |
| 5525 | "reason=FREQ_CONFLICT"); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5526 | wpas_notify_p2p_group_formation_failure( |
| 5527 | wpa_s, "FREQ_CONFLICT"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5528 | return; |
| 5529 | } |
| 5530 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5531 | wpa_printf(MSG_DEBUG, "P2P: Send Provision Discovery Request " |
| 5532 | "prior to joining an existing group (GO " MACSTR |
| 5533 | " freq=%u MHz)", |
| 5534 | MAC2STR(wpa_s->pending_join_dev_addr), freq); |
| 5535 | wpa_s->pending_pd_before_join = 1; |
| 5536 | |
| 5537 | switch (wpa_s->pending_join_wps_method) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5538 | case WPS_PIN_DISPLAY: |
| 5539 | method = WPS_CONFIG_KEYPAD; |
| 5540 | break; |
| 5541 | case WPS_PIN_KEYPAD: |
| 5542 | method = WPS_CONFIG_DISPLAY; |
| 5543 | break; |
| 5544 | case WPS_PBC: |
| 5545 | method = WPS_CONFIG_PUSHBUTTON; |
| 5546 | break; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5547 | case WPS_P2PS: |
| 5548 | method = WPS_CONFIG_P2PS; |
| 5549 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5550 | default: |
| 5551 | method = 0; |
| 5552 | break; |
| 5553 | } |
| 5554 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5555 | if ((p2p_get_provisioning_info(wpa_s->global->p2p, |
| 5556 | wpa_s->pending_join_dev_addr) == |
| 5557 | method)) { |
| 5558 | /* |
| 5559 | * We have already performed provision discovery for |
| 5560 | * joining the group. Proceed directly to join |
| 5561 | * operation without duplicated provision discovery. */ |
| 5562 | wpa_printf(MSG_DEBUG, "P2P: Provision discovery " |
| 5563 | "with " MACSTR " already done - proceed to " |
| 5564 | "join", |
| 5565 | MAC2STR(wpa_s->pending_join_dev_addr)); |
| 5566 | wpa_s->pending_pd_before_join = 0; |
| 5567 | goto start; |
| 5568 | } |
| 5569 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5570 | if (p2p_prov_disc_req(wpa_s->global->p2p, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5571 | wpa_s->pending_join_dev_addr, |
| 5572 | NULL, method, 1, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5573 | freq, wpa_s->user_initiated_pd) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5574 | wpa_printf(MSG_DEBUG, "P2P: Failed to send Provision " |
| 5575 | "Discovery Request before joining an " |
| 5576 | "existing group"); |
| 5577 | wpa_s->pending_pd_before_join = 0; |
| 5578 | goto start; |
| 5579 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5580 | return; |
| 5581 | } |
| 5582 | |
| 5583 | wpa_printf(MSG_DEBUG, "P2P: Failed to find BSS/GO - try again later"); |
| 5584 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
| 5585 | eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL); |
| 5586 | wpas_p2p_check_join_scan_limit(wpa_s); |
| 5587 | return; |
| 5588 | |
| 5589 | start: |
| 5590 | /* Start join operation immediately */ |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5591 | wpas_p2p_join_start(wpa_s, 0, wpa_s->p2p_join_ssid, |
| 5592 | wpa_s->p2p_join_ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5593 | } |
| 5594 | |
| 5595 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5596 | static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq, |
| 5597 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5598 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5599 | int ret; |
| 5600 | struct wpa_driver_scan_params params; |
| 5601 | struct wpabuf *wps_ie, *ies; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5602 | size_t ielen; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5603 | int freqs[2] = { 0, 0 }; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5604 | unsigned int bands; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5605 | |
| 5606 | os_memset(¶ms, 0, sizeof(params)); |
| 5607 | |
| 5608 | /* P2P Wildcard SSID */ |
| 5609 | params.num_ssids = 1; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5610 | if (ssid && ssid_len) { |
| 5611 | params.ssids[0].ssid = ssid; |
| 5612 | params.ssids[0].ssid_len = ssid_len; |
| 5613 | os_memcpy(wpa_s->p2p_join_ssid, ssid, ssid_len); |
| 5614 | wpa_s->p2p_join_ssid_len = ssid_len; |
| 5615 | } else { |
| 5616 | params.ssids[0].ssid = (u8 *) P2P_WILDCARD_SSID; |
| 5617 | params.ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN; |
| 5618 | wpa_s->p2p_join_ssid_len = 0; |
| 5619 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5620 | |
| 5621 | wpa_s->wps->dev.p2p = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5622 | wps_ie = wps_build_probe_req_ie(DEV_PW_DEFAULT, &wpa_s->wps->dev, |
| 5623 | wpa_s->wps->uuid, WPS_REQ_ENROLLEE, 0, |
| 5624 | NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5625 | if (wps_ie == NULL) { |
| 5626 | wpas_p2p_scan_res_join(wpa_s, NULL); |
| 5627 | return; |
| 5628 | } |
| 5629 | |
Dmitry Shmidt | 9e3f8ee | 2014-01-17 10:52:01 -0800 | [diff] [blame] | 5630 | if (!freq) { |
| 5631 | int oper_freq; |
| 5632 | /* |
| 5633 | * If freq is not provided, check the operating freq of the GO |
| 5634 | * and use a single channel scan on if possible. |
| 5635 | */ |
| 5636 | oper_freq = p2p_get_oper_freq(wpa_s->global->p2p, |
| 5637 | wpa_s->pending_join_iface_addr); |
| 5638 | if (oper_freq > 0) |
| 5639 | freq = oper_freq; |
| 5640 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5641 | if (freq > 0) { |
| 5642 | freqs[0] = freq; |
| 5643 | params.freqs = freqs; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 5644 | } else { |
| 5645 | wpas_p2p_scan_freqs(wpa_s, ¶ms, true); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5646 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5647 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5648 | ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p); |
| 5649 | ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen); |
| 5650 | if (ies == NULL) { |
| 5651 | wpabuf_free(wps_ie); |
| 5652 | wpas_p2p_scan_res_join(wpa_s, NULL); |
| 5653 | return; |
| 5654 | } |
| 5655 | wpabuf_put_buf(ies, wps_ie); |
| 5656 | wpabuf_free(wps_ie); |
| 5657 | |
| 5658 | bands = wpas_get_bands(wpa_s, freqs); |
| 5659 | p2p_scan_ie(wpa_s->global->p2p, ies, NULL, bands); |
| 5660 | |
| 5661 | params.p2p_probe = 1; |
| 5662 | params.extra_ies = wpabuf_head(ies); |
| 5663 | params.extra_ies_len = wpabuf_len(ies); |
| 5664 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 5665 | if (wpa_s->clear_driver_scan_cache) { |
| 5666 | wpa_printf(MSG_DEBUG, |
| 5667 | "Request driver to clear scan cache due to local BSS flush"); |
| 5668 | params.only_new_results = 1; |
| 5669 | } |
| 5670 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5671 | /* |
| 5672 | * Run a scan to update BSS table and start Provision Discovery once |
| 5673 | * the new scan results become available. |
| 5674 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5675 | ret = wpa_drv_scan(wpa_s, ¶ms); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5676 | if (params.freqs != freqs) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5677 | os_free(params.freqs); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5678 | if (!ret) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5679 | os_get_reltime(&wpa_s->scan_trigger_time); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5680 | wpa_s->scan_res_handler = wpas_p2p_scan_res_join; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5681 | wpa_s->own_scan_requested = 1; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 5682 | wpa_s->clear_driver_scan_cache = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5683 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5684 | |
| 5685 | wpabuf_free(ies); |
| 5686 | |
| 5687 | if (ret) { |
| 5688 | wpa_printf(MSG_DEBUG, "P2P: Failed to start scan for join - " |
| 5689 | "try again later"); |
| 5690 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
| 5691 | eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL); |
| 5692 | wpas_p2p_check_join_scan_limit(wpa_s); |
| 5693 | } |
| 5694 | } |
| 5695 | |
| 5696 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5697 | static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx) |
| 5698 | { |
| 5699 | struct wpa_supplicant *wpa_s = eloop_ctx; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5700 | wpas_p2p_join_scan_req(wpa_s, 0, NULL, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5701 | } |
| 5702 | |
| 5703 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5704 | 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] | 5705 | const u8 *dev_addr, enum p2p_wps_method wps_method, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5706 | int auto_join, int op_freq, |
| 5707 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5708 | { |
| 5709 | wpa_printf(MSG_DEBUG, "P2P: Request to join existing group (iface " |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5710 | MACSTR " dev " MACSTR " op_freq=%d)%s", |
| 5711 | MAC2STR(iface_addr), MAC2STR(dev_addr), op_freq, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5712 | auto_join ? " (auto_join)" : ""); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5713 | if (ssid && ssid_len) { |
| 5714 | wpa_printf(MSG_DEBUG, "P2P: Group SSID specified: %s", |
| 5715 | wpa_ssid_txt(ssid, ssid_len)); |
| 5716 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5717 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5718 | wpa_s->p2p_auto_pd = 0; |
| 5719 | wpa_s->p2p_auto_join = !!auto_join; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5720 | os_memcpy(wpa_s->pending_join_iface_addr, iface_addr, ETH_ALEN); |
| 5721 | os_memcpy(wpa_s->pending_join_dev_addr, dev_addr, ETH_ALEN); |
| 5722 | wpa_s->pending_join_wps_method = wps_method; |
| 5723 | |
| 5724 | /* Make sure we are not running find during connection establishment */ |
| 5725 | wpas_p2p_stop_find(wpa_s); |
| 5726 | |
| 5727 | wpa_s->p2p_join_scan_count = 0; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5728 | wpas_p2p_join_scan_req(wpa_s, op_freq, ssid, ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5729 | return 0; |
| 5730 | } |
| 5731 | |
| 5732 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5733 | static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s, int freq, |
| 5734 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5735 | { |
| 5736 | struct wpa_supplicant *group; |
| 5737 | struct p2p_go_neg_results res; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5738 | struct wpa_bss *bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5739 | |
| 5740 | group = wpas_p2p_get_group_iface(wpa_s, 0, 0); |
| 5741 | if (group == NULL) |
| 5742 | return -1; |
| 5743 | if (group != wpa_s) { |
| 5744 | os_memcpy(group->p2p_pin, wpa_s->p2p_pin, |
| 5745 | sizeof(group->p2p_pin)); |
| 5746 | group->p2p_wps_method = wpa_s->p2p_wps_method; |
| 5747 | } |
| 5748 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5749 | /* |
| 5750 | * Need to mark the current interface for p2p_group_formation |
| 5751 | * when a separate group interface is not used. This is needed |
| 5752 | * to allow p2p_cancel stop a pending p2p_connect-join. |
| 5753 | * wpas_p2p_init_group_interface() addresses this for the case |
| 5754 | * where a separate group interface is used. |
| 5755 | */ |
| 5756 | if (group == wpa_s->parent) |
| 5757 | wpa_s->global->p2p_group_formation = group; |
| 5758 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5759 | group->p2p_in_provisioning = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5760 | 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] | 5761 | |
| 5762 | os_memset(&res, 0, sizeof(res)); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5763 | 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] | 5764 | os_memcpy(res.peer_interface_addr, wpa_s->pending_join_iface_addr, |
| 5765 | ETH_ALEN); |
| 5766 | res.wps_method = wpa_s->pending_join_wps_method; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5767 | if (freq && ssid && ssid_len) { |
| 5768 | res.freq = freq; |
| 5769 | res.ssid_len = ssid_len; |
| 5770 | os_memcpy(res.ssid, ssid, ssid_len); |
| 5771 | } else { |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5772 | if (ssid && ssid_len) { |
| 5773 | bss = wpa_bss_get(wpa_s, wpa_s->pending_join_iface_addr, |
| 5774 | ssid, ssid_len); |
| 5775 | } else { |
| 5776 | bss = wpa_bss_get_bssid_latest( |
| 5777 | wpa_s, wpa_s->pending_join_iface_addr); |
| 5778 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5779 | if (bss) { |
| 5780 | res.freq = bss->freq; |
| 5781 | res.ssid_len = bss->ssid_len; |
| 5782 | os_memcpy(res.ssid, bss->ssid, bss->ssid_len); |
| 5783 | wpa_printf(MSG_DEBUG, "P2P: Join target GO operating frequency from BSS table: %d MHz (SSID %s)", |
| 5784 | bss->freq, |
| 5785 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5786 | } else if (ssid && ssid_len) { |
| 5787 | res.ssid_len = ssid_len; |
| 5788 | os_memcpy(res.ssid, ssid, ssid_len); |
| 5789 | wpa_printf(MSG_DEBUG, "P2P: Join target GO (SSID %s)", |
| 5790 | wpa_ssid_txt(ssid, ssid_len)); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5791 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5792 | } |
| 5793 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5794 | if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) { |
| 5795 | wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel prior to " |
| 5796 | "starting client"); |
| 5797 | wpa_drv_cancel_remain_on_channel(wpa_s); |
| 5798 | wpa_s->off_channel_freq = 0; |
| 5799 | wpa_s->roc_waiting_drv_freq = 0; |
| 5800 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5801 | wpas_start_wps_enrollee(group, &res); |
| 5802 | |
| 5803 | /* |
| 5804 | * Allow a longer timeout for join-a-running-group than normal 15 |
| 5805 | * second group formation timeout since the GO may not have authorized |
| 5806 | * our connection yet. |
| 5807 | */ |
| 5808 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 5809 | eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout, |
| 5810 | wpa_s, NULL); |
| 5811 | |
| 5812 | return 0; |
| 5813 | } |
| 5814 | |
| 5815 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5816 | 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] | 5817 | int *force_freq, int *pref_freq, int go, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5818 | struct weighted_pcl *pref_freq_list, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5819 | unsigned int *num_pref_freq) |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5820 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5821 | struct wpa_used_freq_data *freqs; |
| 5822 | int res, best_freq, num_unused; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5823 | unsigned int freq_in_use = 0, num, i, max_pref_freq; |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5824 | int p2p_pref_freq; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5825 | |
| 5826 | max_pref_freq = *num_pref_freq; |
| 5827 | *num_pref_freq = 0; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5828 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5829 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 5830 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5831 | if (!freqs) |
| 5832 | return -1; |
| 5833 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5834 | num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, |
| 5835 | wpa_s->num_multichan_concurrent); |
| 5836 | |
| 5837 | /* |
| 5838 | * It is possible that the total number of used frequencies is bigger |
| 5839 | * than the number of frequencies used for P2P, so get the system wide |
| 5840 | * number of unused frequencies. |
| 5841 | */ |
| 5842 | num_unused = wpas_p2p_num_unused_channels(wpa_s); |
| 5843 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5844 | wpa_printf(MSG_DEBUG, |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5845 | "P2P: Setup freqs: freq=%d num_MCC=%d shared_freqs=%u num_unused=%d", |
| 5846 | freq, wpa_s->num_multichan_concurrent, num, num_unused); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5847 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5848 | if (freq > 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5849 | int ret; |
| 5850 | if (go) |
| 5851 | ret = p2p_supported_freq(wpa_s->global->p2p, freq); |
| 5852 | else |
| 5853 | ret = p2p_supported_freq_cli(wpa_s->global->p2p, freq); |
| 5854 | if (!ret) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5855 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5856 | ieee80211_is_dfs(freq, wpa_s->hw.modes, |
| 5857 | wpa_s->hw.num_modes)) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5858 | /* |
| 5859 | * If freq is a DFS channel and DFS is offloaded |
| 5860 | * to the driver, allow P2P GO to use it. |
| 5861 | */ |
| 5862 | wpa_printf(MSG_DEBUG, |
| 5863 | "P2P: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded to the driver", |
| 5864 | freq); |
| 5865 | } else { |
| 5866 | wpa_printf(MSG_DEBUG, |
| 5867 | "P2P: The forced channel (%u MHz) is not supported for P2P uses", |
| 5868 | freq); |
| 5869 | res = -3; |
| 5870 | goto exit_free; |
| 5871 | } |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5872 | } |
| 5873 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5874 | for (i = 0; i < num; i++) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5875 | if (freqs[i].freq == freq) |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5876 | freq_in_use = 1; |
| 5877 | } |
| 5878 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5879 | if (num_unused <= 0 && !freq_in_use) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5880 | wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group on %u MHz as there are no available channels", |
| 5881 | freq); |
| 5882 | res = -2; |
| 5883 | goto exit_free; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5884 | } |
| 5885 | wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the " |
| 5886 | "requested channel (%u MHz)", freq); |
| 5887 | *force_freq = freq; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5888 | goto exit_ok; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5889 | } |
| 5890 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5891 | best_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5892 | |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5893 | if (*pref_freq == 0) { |
| 5894 | if (wpa_s->conf->num_p2p_pref_chan && IS_2GHZ(best_freq)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5895 | i = 0; |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5896 | while (i < wpa_s->conf->num_p2p_pref_chan) { |
| 5897 | p2p_pref_freq = ieee80211_chan_to_freq(NULL, |
| 5898 | wpa_s->conf->p2p_pref_chan[i].op_class, |
| 5899 | wpa_s->conf->p2p_pref_chan[i].chan); |
| 5900 | |
| 5901 | if (p2p_supported_freq(wpa_s->global->p2p, p2p_pref_freq) && |
| 5902 | !wpas_p2p_disallowed_freq(wpa_s->global, p2p_pref_freq)) { |
| 5903 | best_freq = p2p_pref_freq; |
| 5904 | wpa_printf(MSG_DEBUG, "P2P: Using frequency (%u MHz) " |
| 5905 | "from P2P preferred channel list", best_freq); |
| 5906 | break; |
| 5907 | } else { |
| 5908 | wpa_printf(MSG_MSGDUMP, "P2P: Skipping preferred " |
| 5909 | "frequency (%u MHz) ", p2p_pref_freq); |
| 5910 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5911 | i++; |
| 5912 | } |
Sreeramya Soratkal | f928e8f | 2022-03-22 17:33:31 +0530 | [diff] [blame] | 5913 | } else if (!wpa_s->conf->num_p2p_pref_chan) { |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5914 | wpa_printf(MSG_DEBUG, "P2P: best_freq=%d, go=%d", |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 5915 | best_freq, go); |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5916 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 5917 | *num_pref_freq = max_pref_freq; |
| 5918 | res = wpas_p2p_pick_best_pref_freq(wpa_s, go, pref_freq_list, |
| 5919 | num_pref_freq); |
| 5920 | if (res > 0) |
| 5921 | best_freq = res; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5922 | } |
| 5923 | } |
| 5924 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5925 | /* We have a candidate frequency to use */ |
| 5926 | if (best_freq > 0) { |
| 5927 | if (*pref_freq == 0 && num_unused > 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5928 | 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] | 5929 | best_freq); |
| 5930 | *pref_freq = best_freq; |
Dmitry Shmidt | 51a47d5 | 2013-09-10 10:52:57 -0700 | [diff] [blame] | 5931 | } else { |
| 5932 | 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] | 5933 | best_freq); |
| 5934 | *force_freq = best_freq; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5935 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5936 | } else if (num_unused > 0) { |
| 5937 | wpa_printf(MSG_DEBUG, |
| 5938 | "P2P: Current operating channels are not available for P2P. Try to use another channel"); |
| 5939 | *force_freq = 0; |
| 5940 | } else { |
| 5941 | wpa_printf(MSG_DEBUG, |
| 5942 | "P2P: All channels are in use and none of them are P2P enabled. Cannot start P2P group"); |
| 5943 | res = -2; |
| 5944 | goto exit_free; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5945 | } |
| 5946 | |
| 5947 | exit_ok: |
| 5948 | res = 0; |
| 5949 | exit_free: |
| 5950 | os_free(freqs); |
| 5951 | return res; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5952 | } |
| 5953 | |
| 5954 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5955 | static bool is_p2p_6ghz_supported(struct wpa_supplicant *wpa_s, |
| 5956 | const u8 *peer_addr) |
| 5957 | { |
| 5958 | if (wpa_s->conf->p2p_6ghz_disable || |
| 5959 | !get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
| 5960 | HOSTAPD_MODE_IEEE80211A, true)) |
| 5961 | return false; |
| 5962 | |
| 5963 | if (!p2p_wfd_enabled(wpa_s->global->p2p)) |
| 5964 | return false; |
| 5965 | if (peer_addr && !p2p_peer_wfd_enabled(wpa_s->global->p2p, peer_addr)) |
| 5966 | return false; |
| 5967 | |
| 5968 | return true; |
| 5969 | } |
| 5970 | |
| 5971 | |
| 5972 | static int wpas_p2p_check_6ghz(struct wpa_supplicant *wpa_s, |
| 5973 | const u8 *peer_addr, bool allow_6ghz, int freq) |
| 5974 | { |
| 5975 | if (allow_6ghz && is_p2p_6ghz_supported(wpa_s, peer_addr)) { |
| 5976 | wpa_printf(MSG_DEBUG, |
| 5977 | "P2P: Allow connection on 6 GHz channels"); |
| 5978 | p2p_set_6ghz_dev_capab(wpa_s->global->p2p, true); |
| 5979 | } else { |
| 5980 | if (is_6ghz_freq(freq)) |
| 5981 | return -2; |
| 5982 | p2p_set_6ghz_dev_capab(wpa_s->global->p2p, false); |
| 5983 | } |
| 5984 | |
| 5985 | return 0; |
| 5986 | } |
| 5987 | |
| 5988 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5989 | /** |
| 5990 | * wpas_p2p_connect - Request P2P Group Formation to be started |
| 5991 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 5992 | * @peer_addr: Address of the peer P2P Device |
| 5993 | * @pin: PIN to use during provisioning or %NULL to indicate PBC mode |
| 5994 | * @persistent_group: Whether to create a persistent group |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5995 | * @auto_join: Whether to select join vs. GO Negotiation automatically |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5996 | * @join: Whether to join an existing group (as a client) instead of starting |
| 5997 | * Group Owner negotiation; @peer_addr is BSSID in that case |
| 5998 | * @auth: Whether to only authorize the connection instead of doing that and |
| 5999 | * initiating Group Owner negotiation |
| 6000 | * @go_intent: GO Intent or -1 to use default |
| 6001 | * @freq: Frequency for the group or 0 for auto-selection |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6002 | * @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] | 6003 | * @persistent_id: Persistent group credentials to use for forcing GO |
| 6004 | * parameters or -1 to generate new values (SSID/passphrase) |
| 6005 | * @pd: Whether to send Provision Discovery prior to GO Negotiation as an |
| 6006 | * interoperability workaround when initiating group formation |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6007 | * @ht40: Start GO with 40 MHz channel width |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6008 | * @vht: Start GO with VHT support |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6009 | * @vht_chwidth: Channel width supported by GO operating with VHT support |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6010 | * (CHANWIDTH_*). |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 6011 | * @group_ssid: Specific Group SSID for join or %NULL if not set |
| 6012 | * @group_ssid_len: Length of @group_ssid in octets |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6013 | * @allow_6ghz: Allow P2P connection on 6 GHz channels |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6014 | * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified |
| 6015 | * failure, -2 on failure due to channel not currently available, |
| 6016 | * -3 if forced channel is not supported |
| 6017 | */ |
| 6018 | int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr, |
| 6019 | const char *pin, enum p2p_wps_method wps_method, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6020 | int persistent_group, int auto_join, int join, int auth, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6021 | int go_intent, int freq, unsigned int vht_center_freq2, |
| 6022 | int persistent_id, int pd, int ht40, int vht, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6023 | unsigned int vht_chwidth, int he, int edmg, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6024 | const u8 *group_ssid, size_t group_ssid_len, |
| 6025 | bool allow_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6026 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6027 | int force_freq = 0, pref_freq = 0; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6028 | int ret = 0, res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6029 | enum wpa_driver_if_type iftype; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6030 | const u8 *if_addr; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6031 | struct wpa_ssid *ssid = NULL; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6032 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 6033 | unsigned int size; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6034 | |
| 6035 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 6036 | return -1; |
| 6037 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6038 | if (persistent_id >= 0) { |
| 6039 | ssid = wpa_config_get_network(wpa_s->conf, persistent_id); |
| 6040 | if (ssid == NULL || ssid->disabled != 2 || |
| 6041 | ssid->mode != WPAS_MODE_P2P_GO) |
| 6042 | return -1; |
| 6043 | } |
| 6044 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6045 | if (wpas_p2p_check_6ghz(wpa_s, peer_addr, allow_6ghz, freq)) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6046 | return -2; |
| 6047 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6048 | os_free(wpa_s->global->add_psk); |
| 6049 | wpa_s->global->add_psk = NULL; |
| 6050 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6051 | wpa_s->global->p2p_fail_on_wps_complete = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6052 | wpa_s->global->pending_p2ps_group = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6053 | wpa_s->global->pending_p2ps_group_freq = 0; |
| 6054 | wpa_s->p2ps_method_config_any = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6055 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6056 | if (go_intent < 0) |
| 6057 | go_intent = wpa_s->conf->p2p_go_intent; |
| 6058 | |
| 6059 | if (!auth) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6060 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6061 | |
| 6062 | wpa_s->p2p_wps_method = wps_method; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6063 | wpa_s->p2p_persistent_group = !!persistent_group; |
| 6064 | wpa_s->p2p_persistent_id = persistent_id; |
| 6065 | wpa_s->p2p_go_intent = go_intent; |
| 6066 | wpa_s->p2p_connect_freq = freq; |
| 6067 | wpa_s->p2p_fallback_to_go_neg = 0; |
| 6068 | wpa_s->p2p_pd_before_go_neg = !!pd; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6069 | wpa_s->p2p_go_ht40 = !!ht40; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6070 | wpa_s->p2p_go_vht = !!vht; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6071 | wpa_s->p2p_go_vht_center_freq2 = vht_center_freq2; |
| 6072 | wpa_s->p2p_go_max_oper_chwidth = vht_chwidth; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6073 | wpa_s->p2p_go_he = !!he; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6074 | wpa_s->p2p_go_edmg = !!edmg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6075 | |
| 6076 | if (pin) |
| 6077 | os_strlcpy(wpa_s->p2p_pin, pin, sizeof(wpa_s->p2p_pin)); |
| 6078 | else if (wps_method == WPS_PIN_DISPLAY) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6079 | if (wps_generate_pin((unsigned int *) &ret) < 0) |
| 6080 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6081 | res = os_snprintf(wpa_s->p2p_pin, sizeof(wpa_s->p2p_pin), |
| 6082 | "%08d", ret); |
| 6083 | if (os_snprintf_error(sizeof(wpa_s->p2p_pin), res)) |
| 6084 | wpa_s->p2p_pin[sizeof(wpa_s->p2p_pin) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6085 | wpa_printf(MSG_DEBUG, "P2P: Randomly generated PIN: %s", |
| 6086 | wpa_s->p2p_pin); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6087 | } else if (wps_method == WPS_P2PS) { |
| 6088 | /* Force the P2Ps default PIN to be used */ |
| 6089 | os_strlcpy(wpa_s->p2p_pin, "12345670", sizeof(wpa_s->p2p_pin)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6090 | } else |
| 6091 | wpa_s->p2p_pin[0] = '\0'; |
| 6092 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6093 | if (join || auto_join) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6094 | u8 iface_addr[ETH_ALEN], dev_addr[ETH_ALEN]; |
| 6095 | if (auth) { |
| 6096 | wpa_printf(MSG_DEBUG, "P2P: Authorize invitation to " |
| 6097 | "connect a running group from " MACSTR, |
| 6098 | MAC2STR(peer_addr)); |
| 6099 | os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN); |
| 6100 | return ret; |
| 6101 | } |
| 6102 | os_memcpy(dev_addr, peer_addr, ETH_ALEN); |
| 6103 | if (p2p_get_interface_addr(wpa_s->global->p2p, peer_addr, |
| 6104 | iface_addr) < 0) { |
| 6105 | os_memcpy(iface_addr, peer_addr, ETH_ALEN); |
| 6106 | p2p_get_dev_addr(wpa_s->global->p2p, peer_addr, |
| 6107 | dev_addr); |
| 6108 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6109 | if (auto_join) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6110 | os_get_reltime(&wpa_s->p2p_auto_started); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6111 | wpa_printf(MSG_DEBUG, "P2P: Auto join started at " |
| 6112 | "%ld.%06ld", |
| 6113 | wpa_s->p2p_auto_started.sec, |
| 6114 | wpa_s->p2p_auto_started.usec); |
| 6115 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6116 | wpa_s->user_initiated_pd = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6117 | if (wpas_p2p_join(wpa_s, iface_addr, dev_addr, wps_method, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 6118 | auto_join, freq, |
| 6119 | group_ssid, group_ssid_len) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6120 | return -1; |
| 6121 | return ret; |
| 6122 | } |
| 6123 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6124 | size = P2P_MAX_PREF_CHANNELS; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6125 | res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6126 | go_intent == 15, pref_freq_list, &size); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6127 | if (res) |
| 6128 | return res; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 6129 | wpas_p2p_set_own_freq_preference(wpa_s, |
| 6130 | force_freq ? force_freq : pref_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6131 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6132 | p2p_set_own_pref_freq_list(wpa_s->global->p2p, pref_freq_list, size); |
| 6133 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6134 | wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s); |
| 6135 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6136 | if (wpa_s->create_p2p_iface) { |
| 6137 | /* Prepare to add a new interface for the group */ |
| 6138 | iftype = WPA_IF_P2P_GROUP; |
| 6139 | if (go_intent == 15) |
| 6140 | iftype = WPA_IF_P2P_GO; |
| 6141 | if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) { |
| 6142 | wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " |
| 6143 | "interface for the group"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6144 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6145 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6146 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6147 | if_addr = wpa_s->pending_interface_addr; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6148 | } else { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6149 | if (wpa_s->p2p_mgmt) |
| 6150 | if_addr = wpa_s->parent->own_addr; |
| 6151 | else |
| 6152 | if_addr = wpa_s->own_addr; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6153 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
| 6154 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6155 | |
| 6156 | if (auth) { |
| 6157 | if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6158 | go_intent, if_addr, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6159 | force_freq, persistent_group, ssid, |
| 6160 | pref_freq) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6161 | return -1; |
| 6162 | return ret; |
| 6163 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6164 | |
| 6165 | if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method, |
| 6166 | go_intent, if_addr, force_freq, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6167 | persistent_group, ssid, pref_freq) < 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6168 | if (wpa_s->create_p2p_iface) |
| 6169 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6170 | return -1; |
| 6171 | } |
| 6172 | return ret; |
| 6173 | } |
| 6174 | |
| 6175 | |
| 6176 | /** |
| 6177 | * wpas_p2p_remain_on_channel_cb - Indication of remain-on-channel start |
| 6178 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 6179 | * @freq: Frequency of the channel in MHz |
| 6180 | * @duration: Duration of the stay on the channel in milliseconds |
| 6181 | * |
| 6182 | * This callback is called when the driver indicates that it has started the |
| 6183 | * requested remain-on-channel duration. |
| 6184 | */ |
| 6185 | void wpas_p2p_remain_on_channel_cb(struct wpa_supplicant *wpa_s, |
| 6186 | unsigned int freq, unsigned int duration) |
| 6187 | { |
| 6188 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 6189 | return; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6190 | 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)", |
| 6191 | wpa_s->off_channel_freq, wpa_s->pending_listen_freq, |
| 6192 | wpa_s->roc_waiting_drv_freq, freq, duration); |
| 6193 | if (wpa_s->off_channel_freq && |
| 6194 | wpa_s->off_channel_freq == wpa_s->pending_listen_freq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6195 | p2p_listen_cb(wpa_s->global->p2p, wpa_s->pending_listen_freq, |
| 6196 | wpa_s->pending_listen_duration); |
| 6197 | wpa_s->pending_listen_freq = 0; |
Dmitry Shmidt | 7f93d6f | 2014-02-21 11:22:49 -0800 | [diff] [blame] | 6198 | } else { |
| 6199 | wpa_printf(MSG_DEBUG, "P2P: Ignore remain-on-channel callback (off_channel_freq=%u pending_listen_freq=%d freq=%u duration=%u)", |
| 6200 | wpa_s->off_channel_freq, wpa_s->pending_listen_freq, |
| 6201 | freq, duration); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6202 | } |
| 6203 | } |
| 6204 | |
| 6205 | |
Jithu Jance | 57cea1a | 2014-08-20 10:22:04 -0700 | [diff] [blame] | 6206 | 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] | 6207 | { |
| 6208 | /* Limit maximum Listen state time based on driver limitation. */ |
| 6209 | if (timeout > wpa_s->max_remain_on_chan) |
| 6210 | timeout = wpa_s->max_remain_on_chan; |
| 6211 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6212 | return p2p_listen(wpa_s->global->p2p, timeout); |
| 6213 | } |
| 6214 | |
| 6215 | |
| 6216 | /** |
| 6217 | * wpas_p2p_cancel_remain_on_channel_cb - Remain-on-channel timeout |
| 6218 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 6219 | * @freq: Frequency of the channel in MHz |
| 6220 | * |
| 6221 | * This callback is called when the driver indicates that a remain-on-channel |
| 6222 | * operation has been completed, i.e., the duration on the requested channel |
| 6223 | * has timed out. |
| 6224 | */ |
| 6225 | void wpas_p2p_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s, |
| 6226 | unsigned int freq) |
| 6227 | { |
| 6228 | wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel callback " |
| 6229 | "(p2p_long_listen=%d ms pending_action_tx=%p)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6230 | wpa_s->global->p2p_long_listen, |
| 6231 | offchannel_pending_action_tx(wpa_s)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6232 | wpas_p2p_listen_work_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6233 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 6234 | return; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6235 | if (wpa_s->global->p2p_long_listen > 0) |
| 6236 | wpa_s->global->p2p_long_listen -= wpa_s->max_remain_on_chan; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6237 | if (p2p_listen_end(wpa_s->global->p2p, freq) > 0) |
| 6238 | return; /* P2P module started a new operation */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6239 | if (offchannel_pending_action_tx(wpa_s)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6240 | return; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6241 | if (wpa_s->global->p2p_long_listen > 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6242 | wpa_printf(MSG_DEBUG, "P2P: Continuing long Listen state"); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6243 | wpas_p2p_listen_start(wpa_s, wpa_s->global->p2p_long_listen); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6244 | } else { |
| 6245 | /* |
| 6246 | * When listen duration is over, stop listen & update p2p_state |
| 6247 | * to IDLE. |
| 6248 | */ |
| 6249 | p2p_stop_listen(wpa_s->global->p2p); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6250 | } |
| 6251 | } |
| 6252 | |
| 6253 | |
| 6254 | /** |
| 6255 | * wpas_p2p_group_remove - Remove a P2P group |
| 6256 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 6257 | * @ifname: Network interface name of the group interface or "*" to remove all |
| 6258 | * groups |
| 6259 | * Returns: 0 on success, -1 on failure |
| 6260 | * |
| 6261 | * This function is used to remove a P2P group. This can be used to disconnect |
| 6262 | * from a group in which the local end is a P2P Client or to end a P2P Group in |
| 6263 | * case the local end is the Group Owner. If a virtual network interface was |
| 6264 | * created for this group, that interface will be removed. Otherwise, only the |
| 6265 | * configured P2P group network will be removed from the interface. |
| 6266 | */ |
| 6267 | int wpas_p2p_group_remove(struct wpa_supplicant *wpa_s, const char *ifname) |
| 6268 | { |
| 6269 | struct wpa_global *global = wpa_s->global; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6270 | struct wpa_supplicant *calling_wpa_s = wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6271 | |
| 6272 | if (os_strcmp(ifname, "*") == 0) { |
| 6273 | struct wpa_supplicant *prev; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6274 | bool calling_wpa_s_group_removed = false; |
| 6275 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6276 | wpa_s = global->ifaces; |
| 6277 | while (wpa_s) { |
| 6278 | prev = wpa_s; |
| 6279 | wpa_s = wpa_s->next; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6280 | if (prev->p2p_group_interface != |
| 6281 | NOT_P2P_GROUP_INTERFACE || |
| 6282 | (prev->current_ssid && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6283 | prev->current_ssid->p2p_group)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6284 | wpas_p2p_disconnect_safely(prev, calling_wpa_s); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6285 | if (prev == calling_wpa_s) |
| 6286 | calling_wpa_s_group_removed = true; |
| 6287 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6288 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6289 | |
| 6290 | if (!calling_wpa_s_group_removed && |
| 6291 | (calling_wpa_s->p2p_group_interface != |
| 6292 | NOT_P2P_GROUP_INTERFACE || |
| 6293 | (calling_wpa_s->current_ssid && |
| 6294 | calling_wpa_s->current_ssid->p2p_group))) { |
| 6295 | wpa_printf(MSG_DEBUG, "Remove calling_wpa_s P2P group"); |
| 6296 | wpas_p2p_disconnect_safely(calling_wpa_s, |
| 6297 | calling_wpa_s); |
| 6298 | } |
| 6299 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6300 | return 0; |
| 6301 | } |
| 6302 | |
| 6303 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 6304 | if (os_strcmp(wpa_s->ifname, ifname) == 0) |
| 6305 | break; |
| 6306 | } |
| 6307 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6308 | return wpas_p2p_disconnect_safely(wpa_s, calling_wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6309 | } |
| 6310 | |
| 6311 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6312 | static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq) |
| 6313 | { |
| 6314 | unsigned int r; |
| 6315 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6316 | if (!wpa_s->conf->num_p2p_pref_chan && !freq) { |
| 6317 | unsigned int i, size = P2P_MAX_PREF_CHANNELS; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6318 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6319 | int res; |
| 6320 | |
| 6321 | res = wpa_drv_get_pref_freq_list(wpa_s, WPA_IF_P2P_GO, |
| 6322 | &size, pref_freq_list); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6323 | if (!is_p2p_allow_6ghz(wpa_s->global->p2p)) |
| 6324 | size = p2p_remove_6ghz_channels(pref_freq_list, size); |
| 6325 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6326 | if (!res && size > 0) { |
| 6327 | i = 0; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 6328 | while (i < size && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6329 | (!p2p_supported_freq(wpa_s->global->p2p, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6330 | pref_freq_list[i].freq) || |
| 6331 | wpas_p2p_disallowed_freq( |
| 6332 | wpa_s->global, |
| 6333 | pref_freq_list[i].freq) || |
| 6334 | !p2p_pref_freq_allowed(&pref_freq_list[i], |
| 6335 | true))) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6336 | wpa_printf(MSG_DEBUG, |
| 6337 | "P2P: preferred_freq_list[%d]=%d is disallowed", |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6338 | i, pref_freq_list[i].freq); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6339 | i++; |
| 6340 | } |
| 6341 | if (i != size) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6342 | freq = pref_freq_list[i].freq; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6343 | wpa_printf(MSG_DEBUG, |
| 6344 | "P2P: Using preferred_freq_list[%d]=%d", |
| 6345 | i, freq); |
| 6346 | } else { |
| 6347 | wpa_printf(MSG_DEBUG, |
| 6348 | "P2P: All driver preferred frequencies are disallowed for P2P use"); |
| 6349 | } |
| 6350 | } else { |
| 6351 | wpa_printf(MSG_DEBUG, |
| 6352 | "P2P: No preferred frequency list available"); |
| 6353 | } |
| 6354 | } |
| 6355 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6356 | if (freq == 2) { |
| 6357 | wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 2.4 GHz " |
| 6358 | "band"); |
| 6359 | if (wpa_s->best_24_freq > 0 && |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6360 | p2p_supported_freq_go(wpa_s->global->p2p, |
| 6361 | wpa_s->best_24_freq)) { |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6362 | freq = wpa_s->best_24_freq; |
| 6363 | wpa_printf(MSG_DEBUG, "P2P: Use best 2.4 GHz band " |
| 6364 | "channel: %d MHz", freq); |
| 6365 | } else { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6366 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 6367 | return -1; |
Jimmy Chen | 801bf46 | 2021-11-09 23:08:48 +0800 | [diff] [blame] | 6368 | int possible_2g_freqs[] = { |
| 6369 | /* operating class 81 */ |
| 6370 | 2412, 2437, 2462, |
| 6371 | }; |
| 6372 | int possible_2g_freqs_num = |
| 6373 | sizeof(possible_2g_freqs)/sizeof(possible_2g_freqs[0]); |
| 6374 | int i; |
| 6375 | for (i = 0; i < possible_2g_freqs_num; i++, r++) { |
| 6376 | freq = possible_2g_freqs[r % possible_2g_freqs_num]; |
| 6377 | if (p2p_supported_freq_go(wpa_s->global->p2p, freq)) { |
| 6378 | break; |
| 6379 | } |
| 6380 | } |
| 6381 | |
| 6382 | if (i >= possible_2g_freqs_num) { |
| 6383 | wpa_printf(MSG_DEBUG, "P2P: Could not select " |
| 6384 | "2.4 GHz channel for P2P group"); |
| 6385 | return -1; |
| 6386 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6387 | wpa_printf(MSG_DEBUG, "P2P: Use random 2.4 GHz band " |
| 6388 | "channel: %d MHz", freq); |
| 6389 | } |
| 6390 | } |
| 6391 | |
| 6392 | if (freq == 5) { |
| 6393 | wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 5 GHz " |
| 6394 | "band"); |
| 6395 | if (wpa_s->best_5_freq > 0 && |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6396 | p2p_supported_freq_go(wpa_s->global->p2p, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6397 | wpa_s->best_5_freq)) { |
| 6398 | freq = wpa_s->best_5_freq; |
| 6399 | wpa_printf(MSG_DEBUG, "P2P: Use best 5 GHz band " |
| 6400 | "channel: %d MHz", freq); |
| 6401 | } else { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6402 | const int freqs[] = { |
| 6403 | /* operating class 115 */ |
| 6404 | 5180, 5200, 5220, 5240, |
| 6405 | /* operating class 124 */ |
| 6406 | 5745, 5765, 5785, 5805, |
| 6407 | }; |
| 6408 | unsigned int i, num_freqs = ARRAY_SIZE(freqs); |
| 6409 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6410 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 6411 | return -1; |
Jimmy Chen | 64b9063 | 2020-09-29 17:27:34 +0800 | [diff] [blame] | 6412 | |
| 6413 | /* |
| 6414 | * most of 5G channels are DFS, only operating class 115 and 124 |
| 6415 | * are available possibly, randomly pick a start to check them. |
| 6416 | */ |
| 6417 | int possible_5g_freqs[] = { |
| 6418 | /* operating class 115 */ |
| 6419 | 5180, 5200, 5220, 5240, |
| 6420 | /* operating class 124 */ |
| 6421 | 5745, 5765, 5785, 5805, |
| 6422 | }; |
| 6423 | int possible_5g_freqs_num = |
| 6424 | sizeof(possible_5g_freqs)/sizeof(possible_5g_freqs[0]); |
| 6425 | |
Jimmy Chen | 64b9063 | 2020-09-29 17:27:34 +0800 | [diff] [blame] | 6426 | for (i = 0; i < possible_5g_freqs_num; i++, r++) { |
| 6427 | if (p2p_supported_freq_go( |
| 6428 | wpa_s->global->p2p, |
| 6429 | possible_5g_freqs[r % possible_5g_freqs_num])) { |
| 6430 | freq = possible_5g_freqs[r % possible_5g_freqs_num]; |
| 6431 | break; |
| 6432 | } |
| 6433 | } |
| 6434 | |
| 6435 | if (i >= possible_5g_freqs_num) { |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6436 | wpa_printf(MSG_DEBUG, "P2P: Could not select " |
| 6437 | "5 GHz channel for P2P group"); |
| 6438 | return -1; |
| 6439 | } |
| 6440 | wpa_printf(MSG_DEBUG, "P2P: Use random 5 GHz band " |
| 6441 | "channel: %d MHz", freq); |
| 6442 | } |
| 6443 | } |
| 6444 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6445 | if (freq > 0 && !p2p_supported_freq_go(wpa_s->global->p2p, freq)) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6446 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6447 | ieee80211_is_dfs(freq, wpa_s->hw.modes, |
| 6448 | wpa_s->hw.num_modes)) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6449 | /* |
| 6450 | * If freq is a DFS channel and DFS is offloaded to the |
| 6451 | * driver, allow P2P GO to use it. |
| 6452 | */ |
| 6453 | wpa_printf(MSG_DEBUG, "P2P: " |
| 6454 | "%s: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded", |
| 6455 | __func__, freq); |
| 6456 | return freq; |
| 6457 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6458 | wpa_printf(MSG_DEBUG, "P2P: The forced channel for GO " |
| 6459 | "(%u MHz) is not supported for P2P uses", |
| 6460 | freq); |
| 6461 | return -1; |
| 6462 | } |
| 6463 | |
| 6464 | return freq; |
| 6465 | } |
| 6466 | |
| 6467 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6468 | static int wpas_p2p_supported_freq_go(struct wpa_supplicant *wpa_s, |
| 6469 | const struct p2p_channels *channels, |
| 6470 | int freq) |
| 6471 | { |
| 6472 | if (!wpas_p2p_disallowed_freq(wpa_s->global, freq) && |
| 6473 | p2p_supported_freq_go(wpa_s->global->p2p, freq) && |
| 6474 | freq_included(wpa_s, channels, freq)) |
| 6475 | return 1; |
| 6476 | return 0; |
| 6477 | } |
| 6478 | |
| 6479 | |
| 6480 | static void wpas_p2p_select_go_freq_no_pref(struct wpa_supplicant *wpa_s, |
| 6481 | struct p2p_go_neg_results *params, |
| 6482 | const struct p2p_channels *channels) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6483 | { |
| 6484 | unsigned int i, r; |
| 6485 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6486 | /* try all channels in operating class 115 */ |
| 6487 | for (i = 0; i < 4; i++) { |
| 6488 | params->freq = 5180 + i * 20; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6489 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6490 | goto out; |
| 6491 | } |
| 6492 | |
| 6493 | /* try all channels in operating class 124 */ |
| 6494 | for (i = 0; i < 4; i++) { |
| 6495 | params->freq = 5745 + i * 20; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6496 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6497 | goto out; |
| 6498 | } |
| 6499 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6500 | /* try social channel class 180 channel 2 */ |
| 6501 | params->freq = 58320 + 1 * 2160; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6502 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6503 | goto out; |
| 6504 | |
| 6505 | /* try all channels in reg. class 180 */ |
| 6506 | for (i = 0; i < 4; i++) { |
| 6507 | params->freq = 58320 + i * 2160; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6508 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6509 | goto out; |
| 6510 | } |
| 6511 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6512 | /* try some random selection of the social channels */ |
| 6513 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 6514 | return; |
| 6515 | |
| 6516 | for (i = 0; i < 3; i++) { |
| 6517 | params->freq = 2412 + ((r + i) % 3) * 25; |
| 6518 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
| 6519 | goto out; |
| 6520 | } |
| 6521 | |
| 6522 | /* try all other channels in operating class 81 */ |
| 6523 | for (i = 0; i < 11; i++) { |
| 6524 | params->freq = 2412 + i * 5; |
| 6525 | |
| 6526 | /* skip social channels; covered in the previous loop */ |
| 6527 | if (params->freq == 2412 || |
| 6528 | params->freq == 2437 || |
| 6529 | params->freq == 2462) |
| 6530 | continue; |
| 6531 | |
| 6532 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
| 6533 | goto out; |
| 6534 | } |
| 6535 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6536 | params->freq = 0; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6537 | 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] | 6538 | return; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6539 | out: |
| 6540 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz (no preference known)", |
| 6541 | params->freq); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6542 | } |
| 6543 | |
| 6544 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6545 | static int wpas_same_band(int freq1, int freq2) |
| 6546 | { |
| 6547 | enum hostapd_hw_mode mode1, mode2; |
| 6548 | u8 chan1, chan2; |
| 6549 | |
| 6550 | mode1 = ieee80211_freq_to_chan(freq1, &chan1); |
| 6551 | mode2 = ieee80211_freq_to_chan(freq2, &chan2); |
| 6552 | if (mode1 == NUM_HOSTAPD_MODES) |
| 6553 | return 0; |
| 6554 | return mode1 == mode2; |
| 6555 | } |
| 6556 | |
| 6557 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6558 | static int wpas_p2p_init_go_params(struct wpa_supplicant *wpa_s, |
| 6559 | struct p2p_go_neg_results *params, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6560 | int freq, int vht_center_freq2, int ht40, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6561 | int vht, int max_oper_chwidth, int he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6562 | int edmg, |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6563 | const struct p2p_channels *channels) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6564 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6565 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6566 | unsigned int cand; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6567 | unsigned int num, i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6568 | int ignore_no_freqs = 0; |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6569 | int unused_channels = wpas_p2p_num_unused_channels(wpa_s) > 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6570 | |
| 6571 | os_memset(params, 0, sizeof(*params)); |
| 6572 | params->role_go = 1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6573 | params->ht40 = ht40; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6574 | params->vht = vht; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6575 | params->he = he; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6576 | params->max_oper_chwidth = max_oper_chwidth; |
| 6577 | params->vht_center_freq2 = vht_center_freq2; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6578 | params->edmg = edmg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6579 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6580 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 6581 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6582 | if (!freqs) |
| 6583 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6584 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6585 | num = get_shared_radio_freqs_data(wpa_s, freqs, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6586 | wpa_s->num_multichan_concurrent, |
| 6587 | false); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6588 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6589 | if (wpa_s->current_ssid && |
| 6590 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO && |
| 6591 | wpa_s->wpa_state == WPA_COMPLETED) { |
| 6592 | wpa_printf(MSG_DEBUG, "P2P: %s called for an active GO", |
| 6593 | __func__); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6594 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6595 | /* |
| 6596 | * If the frequency selection is done for an active P2P GO that |
| 6597 | * is not sharing a frequency, allow to select a new frequency |
| 6598 | * even if there are no unused frequencies as we are about to |
| 6599 | * move the P2P GO so its frequency can be re-used. |
| 6600 | */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6601 | for (i = 0; i < num; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6602 | if (freqs[i].freq == wpa_s->current_ssid->frequency && |
| 6603 | freqs[i].flags == 0) { |
| 6604 | ignore_no_freqs = 1; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6605 | break; |
| 6606 | } |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6607 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 6608 | } |
| 6609 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6610 | /* Try to use EDMG channel */ |
| 6611 | if (params->edmg) { |
| 6612 | if (wpas_p2p_try_edmg_channel(wpa_s, params) == 0) |
| 6613 | goto success; |
| 6614 | params->edmg = 0; |
| 6615 | } |
| 6616 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6617 | /* try using the forced freq */ |
| 6618 | if (freq) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6619 | if (wpas_p2p_disallowed_freq(wpa_s->global, freq) || |
| 6620 | !freq_included(wpa_s, channels, freq)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6621 | wpa_printf(MSG_DEBUG, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6622 | "P2P: Forced GO freq %d MHz disallowed", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6623 | freq); |
| 6624 | goto fail; |
| 6625 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6626 | if (!p2p_supported_freq_go(wpa_s->global->p2p, freq)) { |
| 6627 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6628 | ieee80211_is_dfs(freq, wpa_s->hw.modes, |
| 6629 | wpa_s->hw.num_modes)) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6630 | /* |
| 6631 | * If freq is a DFS channel and DFS is offloaded |
| 6632 | * to the driver, allow P2P GO to use it. |
| 6633 | */ |
| 6634 | wpa_printf(MSG_DEBUG, |
| 6635 | "P2P: %s: The forced channel for GO (%u MHz) requires DFS and DFS is offloaded", |
| 6636 | __func__, freq); |
| 6637 | } else { |
| 6638 | wpa_printf(MSG_DEBUG, |
| 6639 | "P2P: The forced channel for GO (%u MHz) is not supported for P2P uses", |
| 6640 | freq); |
| 6641 | goto fail; |
| 6642 | } |
| 6643 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6644 | |
| 6645 | for (i = 0; i < num; i++) { |
| 6646 | if (freqs[i].freq == freq) { |
| 6647 | wpa_printf(MSG_DEBUG, |
| 6648 | "P2P: forced freq (%d MHz) is also shared", |
| 6649 | freq); |
| 6650 | params->freq = freq; |
| 6651 | goto success; |
| 6652 | } |
| 6653 | } |
| 6654 | |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6655 | if (!ignore_no_freqs && !unused_channels) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6656 | wpa_printf(MSG_DEBUG, |
| 6657 | "P2P: Cannot force GO on freq (%d MHz) as all the channels are in use", |
| 6658 | freq); |
| 6659 | goto fail; |
| 6660 | } |
| 6661 | |
| 6662 | wpa_printf(MSG_DEBUG, |
| 6663 | "P2P: force GO freq (%d MHz) on a free channel", |
| 6664 | freq); |
| 6665 | params->freq = freq; |
| 6666 | goto success; |
| 6667 | } |
| 6668 | |
| 6669 | /* consider using one of the shared frequencies */ |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6670 | if (num && |
| 6671 | (!wpa_s->conf->p2p_ignore_shared_freq || !unused_channels)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6672 | cand = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num); |
| 6673 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6674 | wpa_printf(MSG_DEBUG, |
| 6675 | "P2P: Use shared freq (%d MHz) for GO", |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6676 | cand); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6677 | params->freq = cand; |
| 6678 | goto success; |
| 6679 | } |
| 6680 | |
| 6681 | /* try using one of the shared freqs */ |
| 6682 | for (i = 0; i < num; i++) { |
| 6683 | if (wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6684 | freqs[i].freq)) { |
| 6685 | wpa_printf(MSG_DEBUG, |
| 6686 | "P2P: Use shared freq (%d MHz) for GO", |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6687 | freqs[i].freq); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6688 | params->freq = freqs[i].freq; |
| 6689 | goto success; |
| 6690 | } |
| 6691 | } |
| 6692 | } |
| 6693 | |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6694 | if (!ignore_no_freqs && !unused_channels) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6695 | wpa_printf(MSG_DEBUG, |
| 6696 | "P2P: Cannot force GO on any of the channels we are already using"); |
| 6697 | goto fail; |
| 6698 | } |
| 6699 | |
| 6700 | /* try using the setting from the configuration file */ |
| 6701 | if (wpa_s->conf->p2p_oper_reg_class == 81 && |
| 6702 | wpa_s->conf->p2p_oper_channel >= 1 && |
| 6703 | wpa_s->conf->p2p_oper_channel <= 11 && |
| 6704 | wpas_p2p_supported_freq_go( |
| 6705 | wpa_s, channels, |
| 6706 | 2407 + 5 * wpa_s->conf->p2p_oper_channel)) { |
| 6707 | params->freq = 2407 + 5 * wpa_s->conf->p2p_oper_channel; |
| 6708 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured " |
| 6709 | "frequency %d MHz", params->freq); |
| 6710 | goto success; |
| 6711 | } |
| 6712 | |
| 6713 | if ((wpa_s->conf->p2p_oper_reg_class == 115 || |
| 6714 | wpa_s->conf->p2p_oper_reg_class == 116 || |
| 6715 | wpa_s->conf->p2p_oper_reg_class == 117 || |
| 6716 | wpa_s->conf->p2p_oper_reg_class == 124 || |
| 6717 | wpa_s->conf->p2p_oper_reg_class == 125 || |
| 6718 | wpa_s->conf->p2p_oper_reg_class == 126 || |
| 6719 | wpa_s->conf->p2p_oper_reg_class == 127) && |
| 6720 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6721 | 5000 + |
| 6722 | 5 * wpa_s->conf->p2p_oper_channel)) { |
| 6723 | params->freq = 5000 + 5 * wpa_s->conf->p2p_oper_channel; |
| 6724 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured " |
| 6725 | "frequency %d MHz", params->freq); |
| 6726 | goto success; |
| 6727 | } |
| 6728 | |
| 6729 | /* Try using best channels */ |
| 6730 | if (wpa_s->conf->p2p_oper_channel == 0 && |
| 6731 | wpa_s->best_overall_freq > 0 && |
| 6732 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6733 | wpa_s->best_overall_freq)) { |
| 6734 | params->freq = wpa_s->best_overall_freq; |
| 6735 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best overall " |
| 6736 | "channel %d MHz", params->freq); |
| 6737 | goto success; |
| 6738 | } |
| 6739 | |
| 6740 | if (wpa_s->conf->p2p_oper_channel == 0 && |
| 6741 | wpa_s->best_24_freq > 0 && |
| 6742 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6743 | wpa_s->best_24_freq)) { |
| 6744 | params->freq = wpa_s->best_24_freq; |
| 6745 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 2.4 GHz " |
| 6746 | "channel %d MHz", params->freq); |
| 6747 | goto success; |
| 6748 | } |
| 6749 | |
| 6750 | if (wpa_s->conf->p2p_oper_channel == 0 && |
| 6751 | wpa_s->best_5_freq > 0 && |
| 6752 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6753 | wpa_s->best_5_freq)) { |
| 6754 | params->freq = wpa_s->best_5_freq; |
| 6755 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 5 GHz " |
| 6756 | "channel %d MHz", params->freq); |
| 6757 | goto success; |
| 6758 | } |
| 6759 | |
| 6760 | /* try using preferred channels */ |
| 6761 | cand = p2p_get_pref_freq(wpa_s->global->p2p, channels); |
| 6762 | if (cand && wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6763 | params->freq = cand; |
| 6764 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz from preferred " |
| 6765 | "channels", params->freq); |
| 6766 | goto success; |
| 6767 | } |
| 6768 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6769 | /* Try using a channel that allows VHT to be used with 80 MHz */ |
| 6770 | if (wpa_s->hw.modes && wpa_s->p2p_group_common_freqs) { |
| 6771 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 6772 | enum hostapd_hw_mode mode; |
| 6773 | struct hostapd_hw_modes *hwmode; |
| 6774 | u8 chan; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6775 | u8 op_class; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6776 | |
| 6777 | cand = wpa_s->p2p_group_common_freqs[i]; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6778 | op_class = is_6ghz_freq(cand) ? 133 : 128; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6779 | mode = ieee80211_freq_to_chan(cand, &chan); |
| 6780 | hwmode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6781 | mode, is_6ghz_freq(cand)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6782 | if (!hwmode || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6783 | wpas_p2p_verify_channel(wpa_s, hwmode, op_class, |
| 6784 | chan, BW80) != ALLOWED) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6785 | continue; |
| 6786 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6787 | params->freq = cand; |
| 6788 | wpa_printf(MSG_DEBUG, |
| 6789 | "P2P: Use freq %d MHz common with the peer and allowing VHT80", |
| 6790 | params->freq); |
| 6791 | goto success; |
| 6792 | } |
| 6793 | } |
| 6794 | } |
| 6795 | |
| 6796 | /* Try using a channel that allows HT to be used with 40 MHz on the same |
| 6797 | * band so that CSA can be used */ |
| 6798 | if (wpa_s->current_ssid && wpa_s->hw.modes && |
| 6799 | wpa_s->p2p_group_common_freqs) { |
| 6800 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 6801 | enum hostapd_hw_mode mode; |
| 6802 | struct hostapd_hw_modes *hwmode; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6803 | u8 chan, op_class; |
| 6804 | bool is_6ghz, supported = false; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6805 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6806 | is_6ghz = is_6ghz_freq(cand); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6807 | cand = wpa_s->p2p_group_common_freqs[i]; |
| 6808 | mode = ieee80211_freq_to_chan(cand, &chan); |
| 6809 | hwmode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6810 | mode, is_6ghz); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6811 | if (!wpas_same_band(wpa_s->current_ssid->frequency, |
| 6812 | cand) || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6813 | !hwmode) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6814 | continue; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6815 | if (is_6ghz && |
| 6816 | wpas_p2p_verify_channel(wpa_s, hwmode, 132, chan, |
| 6817 | BW40) == ALLOWED) |
| 6818 | supported = true; |
| 6819 | |
| 6820 | if (!is_6ghz && |
| 6821 | ieee80211_freq_to_channel_ext( |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6822 | cand, -1, CONF_OPER_CHWIDTH_USE_HT, |
| 6823 | &op_class, &chan) != NUM_HOSTAPD_MODES && |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6824 | wpas_p2p_verify_channel( |
| 6825 | wpa_s, hwmode, op_class, chan, |
| 6826 | BW40MINUS) == ALLOWED) |
| 6827 | supported = true; |
| 6828 | |
| 6829 | if (!supported && !is_6ghz && |
| 6830 | ieee80211_freq_to_channel_ext( |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6831 | cand, 1, CONF_OPER_CHWIDTH_USE_HT, |
| 6832 | &op_class, &chan) != NUM_HOSTAPD_MODES && |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6833 | wpas_p2p_verify_channel( |
| 6834 | wpa_s, hwmode, op_class, chan, |
| 6835 | BW40PLUS) == ALLOWED) |
| 6836 | supported = true; |
| 6837 | |
| 6838 | if (!supported) |
| 6839 | continue; |
| 6840 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6841 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6842 | params->freq = cand; |
| 6843 | wpa_printf(MSG_DEBUG, |
| 6844 | "P2P: Use freq %d MHz common with the peer, allowing HT40, and maintaining same band", |
| 6845 | params->freq); |
| 6846 | goto success; |
| 6847 | } |
| 6848 | } |
| 6849 | } |
| 6850 | |
| 6851 | /* Try using one of the group common freqs on the same band so that CSA |
| 6852 | * can be used */ |
| 6853 | if (wpa_s->current_ssid && wpa_s->p2p_group_common_freqs) { |
| 6854 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 6855 | cand = wpa_s->p2p_group_common_freqs[i]; |
| 6856 | if (!wpas_same_band(wpa_s->current_ssid->frequency, |
| 6857 | cand)) |
| 6858 | continue; |
| 6859 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6860 | params->freq = cand; |
| 6861 | wpa_printf(MSG_DEBUG, |
| 6862 | "P2P: Use freq %d MHz common with the peer and maintaining same band", |
| 6863 | params->freq); |
| 6864 | goto success; |
| 6865 | } |
| 6866 | } |
| 6867 | } |
| 6868 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6869 | /* Try using one of the group common freqs */ |
| 6870 | if (wpa_s->p2p_group_common_freqs) { |
| 6871 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 6872 | cand = wpa_s->p2p_group_common_freqs[i]; |
| 6873 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6874 | params->freq = cand; |
| 6875 | wpa_printf(MSG_DEBUG, |
| 6876 | "P2P: Use freq %d MHz common with the peer", |
| 6877 | params->freq); |
| 6878 | goto success; |
| 6879 | } |
| 6880 | } |
| 6881 | } |
| 6882 | |
| 6883 | /* no preference, select some channel */ |
| 6884 | wpas_p2p_select_go_freq_no_pref(wpa_s, params, channels); |
| 6885 | |
| 6886 | if (params->freq == 0) { |
| 6887 | wpa_printf(MSG_DEBUG, "P2P: did not find a freq for GO use"); |
| 6888 | goto fail; |
| 6889 | } |
| 6890 | |
| 6891 | success: |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6892 | os_free(freqs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6893 | return 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6894 | fail: |
| 6895 | os_free(freqs); |
| 6896 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6897 | } |
| 6898 | |
| 6899 | |
| 6900 | static struct wpa_supplicant * |
| 6901 | wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated, |
| 6902 | int go) |
| 6903 | { |
| 6904 | struct wpa_supplicant *group_wpa_s; |
| 6905 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6906 | if (!wpas_p2p_create_iface(wpa_s)) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6907 | if (wpa_s->p2p_mgmt) { |
| 6908 | /* |
| 6909 | * We may be called on the p2p_dev interface which |
| 6910 | * cannot be used for group operations, so always use |
| 6911 | * the primary interface. |
| 6912 | */ |
| 6913 | wpa_s->parent->p2pdev = wpa_s; |
| 6914 | wpa_s = wpa_s->parent; |
| 6915 | } |
| 6916 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 6917 | "P2P: Use primary interface for group operations"); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6918 | wpa_s->p2p_first_connection_timeout = 0; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6919 | if (wpa_s != wpa_s->p2pdev) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6920 | wpas_p2p_clone_config(wpa_s, wpa_s->p2pdev); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6921 | return wpa_s; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6922 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6923 | |
| 6924 | 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] | 6925 | WPA_IF_P2P_CLIENT) < 0) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6926 | wpa_msg_global(wpa_s, MSG_ERROR, |
| 6927 | "P2P: Failed to add group interface"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6928 | return NULL; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6929 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6930 | group_wpa_s = wpas_p2p_init_group_interface(wpa_s, go); |
| 6931 | if (group_wpa_s == NULL) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6932 | wpa_msg_global(wpa_s, MSG_ERROR, |
| 6933 | "P2P: Failed to initialize group interface"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6934 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 6935 | return NULL; |
| 6936 | } |
| 6937 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6938 | if (go && wpa_s->p2p_go_do_acs) { |
| 6939 | group_wpa_s->p2p_go_do_acs = wpa_s->p2p_go_do_acs; |
| 6940 | group_wpa_s->p2p_go_acs_band = wpa_s->p2p_go_acs_band; |
| 6941 | wpa_s->p2p_go_do_acs = 0; |
| 6942 | } |
| 6943 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6944 | if (go && wpa_s->p2p_go_allow_dfs) { |
| 6945 | group_wpa_s->p2p_go_allow_dfs = wpa_s->p2p_go_allow_dfs; |
| 6946 | wpa_s->p2p_go_allow_dfs = 0; |
| 6947 | } |
| 6948 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6949 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use separate group interface %s", |
| 6950 | group_wpa_s->ifname); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6951 | group_wpa_s->p2p_first_connection_timeout = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6952 | return group_wpa_s; |
| 6953 | } |
| 6954 | |
| 6955 | |
| 6956 | /** |
| 6957 | * wpas_p2p_group_add - Add a new P2P group with local end as Group Owner |
| 6958 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 6959 | * @persistent_group: Whether to create a persistent group |
| 6960 | * @freq: Frequency for the group or 0 to indicate no hardcoding |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6961 | * @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] | 6962 | * @ht40: Start GO with 40 MHz channel width |
| 6963 | * @vht: Start GO with VHT support |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6964 | * @vht_chwidth: channel bandwidth for GO operating with VHT support |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6965 | * @edmg: Start GO with EDMG support |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6966 | * @allow_6ghz: Allow P2P group creation on a 6 GHz channel |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6967 | * Returns: 0 on success, -1 on failure |
| 6968 | * |
| 6969 | * This function creates a new P2P group with the local end as the Group Owner, |
| 6970 | * i.e., without using Group Owner Negotiation. |
| 6971 | */ |
| 6972 | 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] | 6973 | int freq, int vht_center_freq2, int ht40, int vht, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6974 | int max_oper_chwidth, int he, int edmg, |
| 6975 | bool allow_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6976 | { |
| 6977 | struct p2p_go_neg_results params; |
Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 6978 | int selected_freq = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6979 | |
| 6980 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 6981 | return -1; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6982 | if (wpas_p2p_check_6ghz(wpa_s, NULL, allow_6ghz, freq)) |
| 6983 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6984 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6985 | os_free(wpa_s->global->add_psk); |
| 6986 | wpa_s->global->add_psk = NULL; |
| 6987 | |
Dmitry Shmidt | dca3979 | 2011-09-06 11:17:33 -0700 | [diff] [blame] | 6988 | /* Make sure we are not running find during connection establishment */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6989 | wpa_printf(MSG_DEBUG, "P2P: Stop any on-going P2P FIND"); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6990 | wpas_p2p_stop_find_oper(wpa_s); |
Dmitry Shmidt | dca3979 | 2011-09-06 11:17:33 -0700 | [diff] [blame] | 6991 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6992 | if (!wpa_s->p2p_go_do_acs) { |
Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 6993 | selected_freq = wpas_p2p_select_go_freq(wpa_s, freq); |
| 6994 | if (selected_freq < 0) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6995 | return -1; |
| 6996 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6997 | |
Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 6998 | if (wpas_p2p_init_go_params(wpa_s, ¶ms, selected_freq, vht_center_freq2, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6999 | ht40, vht, max_oper_chwidth, he, edmg, |
| 7000 | NULL)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7001 | return -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7002 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7003 | p2p_go_params(wpa_s->global->p2p, ¶ms); |
| 7004 | params.persistent_group = persistent_group; |
| 7005 | |
| 7006 | wpa_s = wpas_p2p_get_group_iface(wpa_s, 0, 1); |
| 7007 | if (wpa_s == NULL) |
| 7008 | return -1; |
Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 7009 | if (freq > 0) |
| 7010 | wpa_s->p2p_go_no_pri_sec_switch = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7011 | wpas_start_wps_go(wpa_s, ¶ms, 0); |
| 7012 | |
| 7013 | return 0; |
| 7014 | } |
| 7015 | |
| 7016 | |
| 7017 | static int wpas_start_p2p_client(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7018 | struct wpa_ssid *params, int addr_allocated, |
Matthew Wang | 124e5f4 | 2022-12-29 07:23:06 +0000 | [diff] [blame] | 7019 | int freq, int force_scan, int retry_limit, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 7020 | const u8 *go_bssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7021 | { |
| 7022 | struct wpa_ssid *ssid; |
Matthew Wang | 9ae940b | 2022-09-14 21:25:34 -0700 | [diff] [blame] | 7023 | int other_iface_found = 0; |
| 7024 | struct wpa_supplicant *ifs; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7025 | |
| 7026 | wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 0); |
| 7027 | if (wpa_s == NULL) |
| 7028 | return -1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7029 | if (force_scan) |
| 7030 | os_get_reltime(&wpa_s->scan_min_time); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 7031 | wpa_s->p2p_last_4way_hs_fail = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7032 | |
| 7033 | wpa_supplicant_ap_deinit(wpa_s); |
| 7034 | |
| 7035 | ssid = wpa_config_add_network(wpa_s->conf); |
| 7036 | if (ssid == NULL) |
| 7037 | return -1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7038 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7039 | wpa_config_set_network_defaults(ssid); |
| 7040 | ssid->temporary = 1; |
| 7041 | ssid->proto = WPA_PROTO_RSN; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7042 | ssid->pbss = params->pbss; |
| 7043 | ssid->pairwise_cipher = params->pbss ? WPA_CIPHER_GCMP : |
| 7044 | WPA_CIPHER_CCMP; |
| 7045 | ssid->group_cipher = params->pbss ? WPA_CIPHER_GCMP : WPA_CIPHER_CCMP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7046 | ssid->key_mgmt = WPA_KEY_MGMT_PSK; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 7047 | if (is_6ghz_freq(freq) && |
| 7048 | is_p2p_6ghz_capable(wpa_s->global->p2p)) { |
| 7049 | ssid->auth_alg |= WPA_AUTH_ALG_SAE; |
| 7050 | ssid->key_mgmt |= WPA_KEY_MGMT_SAE; |
| 7051 | ssid->ieee80211w = MGMT_FRAME_PROTECTION_OPTIONAL; |
| 7052 | ssid->sae_pwe = SAE_PWE_HASH_TO_ELEMENT; |
| 7053 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 7054 | "P2P: Enable SAE auth_alg and key_mgmt"); |
| 7055 | } |
| 7056 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7057 | ssid->ssid = os_malloc(params->ssid_len); |
| 7058 | if (ssid->ssid == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7059 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 7060 | return -1; |
| 7061 | } |
| 7062 | os_memcpy(ssid->ssid, params->ssid, params->ssid_len); |
| 7063 | ssid->ssid_len = params->ssid_len; |
| 7064 | ssid->p2p_group = 1; |
| 7065 | ssid->export_keys = 1; |
| 7066 | if (params->psk_set) { |
| 7067 | os_memcpy(ssid->psk, params->psk, 32); |
| 7068 | ssid->psk_set = 1; |
| 7069 | } |
| 7070 | if (params->passphrase) |
| 7071 | ssid->passphrase = os_strdup(params->passphrase); |
| 7072 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 7073 | if (go_bssid) { |
Matthew Wang | dcf1945 | 2022-11-07 20:42:52 -0800 | [diff] [blame] | 7074 | ssid->bssid_set = 1; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 7075 | os_memcpy(ssid->bssid, go_bssid, ETH_ALEN); |
Matthew Wang | dcf1945 | 2022-11-07 20:42:52 -0800 | [diff] [blame] | 7076 | } |
| 7077 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7078 | wpa_s->show_group_started = 1; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7079 | wpa_s->p2p_in_invitation = 1; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 7080 | wpa_s->p2p_retry_limit = retry_limit; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7081 | wpa_s->p2p_invite_go_freq = freq; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7082 | wpa_s->p2p_go_group_formation_completed = 0; |
| 7083 | wpa_s->global->p2p_group_formation = wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7084 | |
Matthew Wang | 9ae940b | 2022-09-14 21:25:34 -0700 | [diff] [blame] | 7085 | /* |
| 7086 | * Get latest scan results from driver in case cached scan results from |
| 7087 | * interfaces on the same wiphy allow us to skip the next scan by fast |
| 7088 | * associating. Also update the scan time to the most recent scan result |
| 7089 | * fetch time on the same radio so it reflects the actual time the last |
| 7090 | * scan result event occurred. |
| 7091 | */ |
| 7092 | wpa_supplicant_update_scan_results(wpa_s); |
| 7093 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 7094 | radio_list) { |
| 7095 | if (ifs == wpa_s) |
| 7096 | continue; |
| 7097 | if (!other_iface_found || os_reltime_before(&wpa_s->last_scan, |
| 7098 | &ifs->last_scan)) { |
| 7099 | other_iface_found = 1; |
| 7100 | wpa_s->last_scan.sec = ifs->last_scan.sec; |
| 7101 | wpa_s->last_scan.usec = ifs->last_scan.usec; |
| 7102 | } |
| 7103 | } |
| 7104 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7105 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->p2pdev, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7106 | NULL); |
| 7107 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, |
| 7108 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7109 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 7110 | wpa_supplicant_select_network(wpa_s, ssid); |
| 7111 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7112 | return 0; |
| 7113 | } |
| 7114 | |
| 7115 | |
| 7116 | int wpas_p2p_group_add_persistent(struct wpa_supplicant *wpa_s, |
| 7117 | struct wpa_ssid *ssid, int addr_allocated, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7118 | int force_freq, int neg_freq, |
| 7119 | int vht_center_freq2, int ht40, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7120 | int vht, int max_oper_chwidth, int he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7121 | int edmg, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7122 | const struct p2p_channels *channels, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7123 | int connection_timeout, int force_scan, |
Matthew Wang | 124e5f4 | 2022-12-29 07:23:06 +0000 | [diff] [blame] | 7124 | bool allow_6ghz, int retry_limit, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 7125 | const u8 *go_bssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7126 | { |
| 7127 | struct p2p_go_neg_results params; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 7128 | int go = 0, freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7129 | |
| 7130 | if (ssid->disabled != 2 || ssid->ssid == NULL) |
| 7131 | return -1; |
| 7132 | |
| 7133 | if (wpas_get_p2p_group(wpa_s, ssid->ssid, ssid->ssid_len, &go) && |
| 7134 | go == (ssid->mode == WPAS_MODE_P2P_GO)) { |
| 7135 | wpa_printf(MSG_DEBUG, "P2P: Requested persistent group is " |
| 7136 | "already running"); |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 7137 | if (go == 0 && |
| 7138 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7139 | wpa_s->p2pdev, NULL)) { |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 7140 | /* |
| 7141 | * This can happen if Invitation Response frame was lost |
| 7142 | * and the peer (GO of a persistent group) tries to |
| 7143 | * invite us again. Reschedule the timeout to avoid |
| 7144 | * terminating the wait for the connection too early |
| 7145 | * since we now know that the peer is still trying to |
| 7146 | * invite us instead of having already started the GO. |
| 7147 | */ |
| 7148 | wpa_printf(MSG_DEBUG, |
| 7149 | "P2P: Reschedule group formation timeout since peer is still trying to invite us"); |
| 7150 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, |
| 7151 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7152 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 7153 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7154 | return 0; |
| 7155 | } |
| 7156 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 7157 | os_free(wpa_s->global->add_psk); |
| 7158 | wpa_s->global->add_psk = NULL; |
| 7159 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7160 | /* Make sure we are not running find during connection establishment */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7161 | wpas_p2p_stop_find_oper(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7162 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7163 | wpa_s->p2p_fallback_to_go_neg = 0; |
| 7164 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7165 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 7166 | if (force_freq > 0) { |
| 7167 | freq = wpas_p2p_select_go_freq(wpa_s, force_freq); |
| 7168 | if (freq < 0) |
| 7169 | return -1; |
Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 7170 | wpa_s->p2p_go_no_pri_sec_switch = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7171 | } else { |
| 7172 | freq = wpas_p2p_select_go_freq(wpa_s, neg_freq); |
| 7173 | if (freq < 0 || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7174 | (freq > 0 && !freq_included(wpa_s, channels, freq))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7175 | freq = 0; |
| 7176 | } |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7177 | } else if (ssid->mode == WPAS_MODE_INFRA) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7178 | freq = neg_freq; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7179 | if (freq <= 0 || !freq_included(wpa_s, channels, freq)) { |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7180 | struct os_reltime now; |
| 7181 | struct wpa_bss *bss = |
| 7182 | wpa_bss_get_p2p_dev_addr(wpa_s, ssid->bssid); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7183 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7184 | os_get_reltime(&now); |
| 7185 | if (bss && |
| 7186 | !os_reltime_expired(&now, &bss->last_update, 5) && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7187 | freq_included(wpa_s, channels, bss->freq)) |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7188 | freq = bss->freq; |
| 7189 | else |
| 7190 | freq = 0; |
| 7191 | } |
| 7192 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7193 | return wpas_start_p2p_client(wpa_s, ssid, addr_allocated, freq, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 7194 | force_scan, retry_limit, go_bssid); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7195 | } else { |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7196 | return -1; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7197 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7198 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7199 | 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] | 7200 | ht40, vht, max_oper_chwidth, he, edmg, |
| 7201 | channels)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7202 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7203 | |
| 7204 | params.role_go = 1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7205 | params.psk_set = ssid->psk_set; |
| 7206 | if (params.psk_set) |
| 7207 | os_memcpy(params.psk, ssid->psk, sizeof(params.psk)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7208 | if (ssid->passphrase) { |
| 7209 | if (os_strlen(ssid->passphrase) >= sizeof(params.passphrase)) { |
| 7210 | wpa_printf(MSG_ERROR, "P2P: Invalid passphrase in " |
| 7211 | "persistent group"); |
| 7212 | return -1; |
| 7213 | } |
| 7214 | os_strlcpy(params.passphrase, ssid->passphrase, |
| 7215 | sizeof(params.passphrase)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7216 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7217 | os_memcpy(params.ssid, ssid->ssid, ssid->ssid_len); |
| 7218 | params.ssid_len = ssid->ssid_len; |
| 7219 | params.persistent_group = 1; |
| 7220 | |
| 7221 | wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 1); |
| 7222 | if (wpa_s == NULL) |
| 7223 | return -1; |
| 7224 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7225 | p2p_channels_to_freqs(channels, params.freq_list, P2P_MAX_CHANNELS); |
| 7226 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7227 | wpa_s->p2p_first_connection_timeout = connection_timeout; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7228 | wpas_start_wps_go(wpa_s, ¶ms, 0); |
| 7229 | |
| 7230 | return 0; |
| 7231 | } |
| 7232 | |
| 7233 | |
| 7234 | static void wpas_p2p_ie_update(void *ctx, struct wpabuf *beacon_ies, |
| 7235 | struct wpabuf *proberesp_ies) |
| 7236 | { |
| 7237 | struct wpa_supplicant *wpa_s = ctx; |
| 7238 | if (wpa_s->ap_iface) { |
| 7239 | struct hostapd_data *hapd = wpa_s->ap_iface->bss[0]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7240 | if (!(hapd->conf->p2p & P2P_GROUP_OWNER)) { |
| 7241 | wpabuf_free(beacon_ies); |
| 7242 | wpabuf_free(proberesp_ies); |
| 7243 | return; |
| 7244 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7245 | if (beacon_ies) { |
| 7246 | wpabuf_free(hapd->p2p_beacon_ie); |
| 7247 | hapd->p2p_beacon_ie = beacon_ies; |
| 7248 | } |
| 7249 | wpabuf_free(hapd->p2p_probe_resp_ie); |
| 7250 | hapd->p2p_probe_resp_ie = proberesp_ies; |
| 7251 | } else { |
| 7252 | wpabuf_free(beacon_ies); |
| 7253 | wpabuf_free(proberesp_ies); |
| 7254 | } |
| 7255 | wpa_supplicant_ap_update_beacon(wpa_s); |
| 7256 | } |
| 7257 | |
| 7258 | |
| 7259 | static void wpas_p2p_idle_update(void *ctx, int idle) |
| 7260 | { |
| 7261 | struct wpa_supplicant *wpa_s = ctx; |
| 7262 | if (!wpa_s->ap_iface) |
| 7263 | return; |
| 7264 | wpa_printf(MSG_DEBUG, "P2P: GO - group %sidle", idle ? "" : "not "); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7265 | if (idle) { |
| 7266 | if (wpa_s->global->p2p_fail_on_wps_complete && |
| 7267 | wpa_s->p2p_in_provisioning) { |
| 7268 | wpas_p2p_grpform_fail_after_wps(wpa_s); |
| 7269 | return; |
| 7270 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7271 | wpas_p2p_set_group_idle_timeout(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7272 | } else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7273 | eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL); |
| 7274 | } |
| 7275 | |
| 7276 | |
| 7277 | struct p2p_group * wpas_p2p_group_init(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7278 | struct wpa_ssid *ssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7279 | { |
| 7280 | struct p2p_group *group; |
| 7281 | struct p2p_group_config *cfg; |
| 7282 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 7283 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL || |
| 7284 | !ssid->p2p_group) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7285 | return NULL; |
| 7286 | |
| 7287 | cfg = os_zalloc(sizeof(*cfg)); |
| 7288 | if (cfg == NULL) |
| 7289 | return NULL; |
| 7290 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7291 | if (ssid->p2p_persistent_group && wpa_s->conf->persistent_reconnect) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7292 | cfg->persistent_group = 2; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7293 | else if (ssid->p2p_persistent_group) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7294 | cfg->persistent_group = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7295 | os_memcpy(cfg->interface_addr, wpa_s->own_addr, ETH_ALEN); |
| 7296 | if (wpa_s->max_stations && |
| 7297 | wpa_s->max_stations < wpa_s->conf->max_num_sta) |
| 7298 | cfg->max_clients = wpa_s->max_stations; |
| 7299 | else |
| 7300 | cfg->max_clients = wpa_s->conf->max_num_sta; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7301 | os_memcpy(cfg->ssid, ssid->ssid, ssid->ssid_len); |
| 7302 | cfg->ssid_len = ssid->ssid_len; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7303 | cfg->freq = ssid->frequency; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7304 | cfg->cb_ctx = wpa_s; |
| 7305 | cfg->ie_update = wpas_p2p_ie_update; |
| 7306 | cfg->idle_update = wpas_p2p_idle_update; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7307 | cfg->ip_addr_alloc = WPA_GET_BE32(wpa_s->p2pdev->conf->ip_addr_start) |
| 7308 | != 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7309 | |
| 7310 | group = p2p_group_init(wpa_s->global->p2p, cfg); |
| 7311 | if (group == NULL) |
| 7312 | os_free(cfg); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7313 | if (ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7314 | p2p_group_notif_formation_done(group); |
| 7315 | wpa_s->p2p_group = group; |
| 7316 | return group; |
| 7317 | } |
| 7318 | |
| 7319 | |
| 7320 | void wpas_p2p_wps_success(struct wpa_supplicant *wpa_s, const u8 *peer_addr, |
| 7321 | int registrar) |
| 7322 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7323 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 7324 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7325 | if (!wpa_s->p2p_in_provisioning) { |
| 7326 | wpa_printf(MSG_DEBUG, "P2P: Ignore WPS success event - P2P " |
| 7327 | "provisioning not in progress"); |
| 7328 | return; |
| 7329 | } |
| 7330 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7331 | if (ssid && ssid->mode == WPAS_MODE_INFRA) { |
| 7332 | u8 go_dev_addr[ETH_ALEN]; |
| 7333 | os_memcpy(go_dev_addr, wpa_s->bssid, ETH_ALEN); |
| 7334 | wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid, |
| 7335 | ssid->ssid_len); |
| 7336 | /* Clear any stored provisioning info */ |
| 7337 | p2p_clear_provisioning_info(wpa_s->global->p2p, go_dev_addr); |
| 7338 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7339 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7340 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->p2pdev, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7341 | NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7342 | wpa_s->p2p_go_group_formation_completed = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7343 | if (ssid && ssid->mode == WPAS_MODE_INFRA) { |
| 7344 | /* |
| 7345 | * Use a separate timeout for initial data connection to |
| 7346 | * complete to allow the group to be removed automatically if |
| 7347 | * something goes wrong in this step before the P2P group idle |
| 7348 | * timeout mechanism is taken into use. |
| 7349 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7350 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 7351 | "P2P: Re-start group formation timeout (%d seconds) as client for initial connection", |
| 7352 | P2P_MAX_INITIAL_CONN_WAIT); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7353 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, |
| 7354 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7355 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7356 | /* Complete group formation on successful data connection. */ |
| 7357 | wpa_s->p2p_go_group_formation_completed = 0; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7358 | } else if (ssid) { |
| 7359 | /* |
| 7360 | * Use a separate timeout for initial data connection to |
| 7361 | * complete to allow the group to be removed automatically if |
| 7362 | * the client does not complete data connection successfully. |
| 7363 | */ |
| 7364 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 7365 | "P2P: Re-start group formation timeout (%d seconds) as GO for initial connection", |
| 7366 | P2P_MAX_INITIAL_CONN_WAIT_GO); |
| 7367 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT_GO, 0, |
| 7368 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7369 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7370 | /* |
| 7371 | * Complete group formation on first successful data connection |
| 7372 | */ |
| 7373 | wpa_s->p2p_go_group_formation_completed = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7374 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7375 | if (wpa_s->global->p2p) |
| 7376 | p2p_wps_success_cb(wpa_s->global->p2p, peer_addr); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 7377 | wpas_group_formation_completed(wpa_s, 1, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7378 | } |
| 7379 | |
| 7380 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7381 | void wpas_p2p_wps_failed(struct wpa_supplicant *wpa_s, |
| 7382 | struct wps_event_fail *fail) |
| 7383 | { |
| 7384 | if (!wpa_s->p2p_in_provisioning) { |
| 7385 | wpa_printf(MSG_DEBUG, "P2P: Ignore WPS fail event - P2P " |
| 7386 | "provisioning not in progress"); |
| 7387 | return; |
| 7388 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7389 | |
| 7390 | if (wpa_s->go_params) { |
| 7391 | p2p_clear_provisioning_info( |
| 7392 | wpa_s->global->p2p, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7393 | wpa_s->go_params->peer_device_addr); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7394 | } |
| 7395 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7396 | wpas_notify_p2p_wps_failed(wpa_s, fail); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7397 | |
| 7398 | if (wpa_s == wpa_s->global->p2p_group_formation) { |
| 7399 | /* |
| 7400 | * Allow some time for the failed WPS negotiation exchange to |
| 7401 | * complete, but remove the group since group formation cannot |
| 7402 | * succeed after provisioning failure. |
| 7403 | */ |
| 7404 | wpa_printf(MSG_DEBUG, "P2P: WPS step failed during group formation - reject connection from timeout"); |
| 7405 | wpa_s->global->p2p_fail_on_wps_complete = 1; |
| 7406 | eloop_deplete_timeout(0, 50000, |
| 7407 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7408 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7409 | } |
| 7410 | } |
| 7411 | |
| 7412 | |
| 7413 | int wpas_p2p_wps_eapol_cb(struct wpa_supplicant *wpa_s) |
| 7414 | { |
| 7415 | if (!wpa_s->global->p2p_fail_on_wps_complete || |
| 7416 | !wpa_s->p2p_in_provisioning) |
| 7417 | return 0; |
| 7418 | |
| 7419 | wpas_p2p_grpform_fail_after_wps(wpa_s); |
| 7420 | |
| 7421 | return 1; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7422 | } |
| 7423 | |
| 7424 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7425 | 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] | 7426 | const char *config_method, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7427 | enum wpas_p2p_prov_disc_use use, |
| 7428 | struct p2ps_provision *p2ps_prov) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7429 | { |
| 7430 | u16 config_methods; |
| 7431 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7432 | wpa_s->global->pending_p2ps_group = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7433 | wpa_s->global->pending_p2ps_group_freq = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7434 | wpa_s->p2p_fallback_to_go_neg = 0; |
| 7435 | wpa_s->pending_pd_use = NORMAL_PD; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7436 | if (p2ps_prov && use == WPAS_P2P_PD_FOR_ASP) { |
| 7437 | p2ps_prov->conncap = p2ps_group_capability( |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7438 | wpa_s, P2PS_SETUP_NONE, p2ps_prov->role, |
| 7439 | &p2ps_prov->force_freq, &p2ps_prov->pref_freq); |
| 7440 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7441 | wpa_printf(MSG_DEBUG, |
| 7442 | "P2P: %s conncap: %d - ASP parsed: %x %x %d %s", |
| 7443 | __func__, p2ps_prov->conncap, |
| 7444 | p2ps_prov->adv_id, p2ps_prov->conncap, |
| 7445 | p2ps_prov->status, p2ps_prov->info); |
| 7446 | |
| 7447 | config_methods = 0; |
| 7448 | } else if (os_strncmp(config_method, "display", 7) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7449 | config_methods = WPS_CONFIG_DISPLAY; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7450 | else if (os_strncmp(config_method, "keypad", 6) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7451 | config_methods = WPS_CONFIG_KEYPAD; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7452 | else if (os_strncmp(config_method, "pbc", 3) == 0 || |
| 7453 | os_strncmp(config_method, "pushbutton", 10) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7454 | config_methods = WPS_CONFIG_PUSHBUTTON; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7455 | else { |
| 7456 | wpa_printf(MSG_DEBUG, "P2P: Unknown config method"); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7457 | os_free(p2ps_prov); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7458 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7459 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7460 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7461 | if (use == WPAS_P2P_PD_AUTO) { |
| 7462 | os_memcpy(wpa_s->pending_join_dev_addr, peer_addr, ETH_ALEN); |
| 7463 | wpa_s->pending_pd_config_methods = config_methods; |
| 7464 | wpa_s->p2p_auto_pd = 1; |
| 7465 | wpa_s->p2p_auto_join = 0; |
| 7466 | wpa_s->pending_pd_before_join = 0; |
| 7467 | wpa_s->auto_pd_scan_retry = 0; |
| 7468 | wpas_p2p_stop_find(wpa_s); |
| 7469 | wpa_s->p2p_join_scan_count = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7470 | os_get_reltime(&wpa_s->p2p_auto_started); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7471 | wpa_printf(MSG_DEBUG, "P2P: Auto PD started at %ld.%06ld", |
| 7472 | wpa_s->p2p_auto_started.sec, |
| 7473 | wpa_s->p2p_auto_started.usec); |
| 7474 | wpas_p2p_join_scan(wpa_s, NULL); |
| 7475 | return 0; |
| 7476 | } |
| 7477 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7478 | if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) { |
| 7479 | os_free(p2ps_prov); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7480 | return -1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7481 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7482 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7483 | 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] | 7484 | config_methods, use == WPAS_P2P_PD_FOR_JOIN, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7485 | 0, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7486 | } |
| 7487 | |
| 7488 | |
| 7489 | int wpas_p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf, |
| 7490 | char *end) |
| 7491 | { |
| 7492 | return p2p_scan_result_text(ies, ies_len, buf, end); |
| 7493 | } |
| 7494 | |
| 7495 | |
| 7496 | static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant *wpa_s) |
| 7497 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7498 | if (!offchannel_pending_action_tx(wpa_s)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7499 | return; |
| 7500 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 7501 | if (wpa_s->p2p_send_action_work) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7502 | wpas_p2p_free_send_action_work(wpa_s); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 7503 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 7504 | wpa_s, NULL); |
| 7505 | offchannel_send_action_done(wpa_s); |
| 7506 | } |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 7507 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7508 | wpa_printf(MSG_DEBUG, "P2P: Drop pending Action TX due to new " |
| 7509 | "operation request"); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7510 | offchannel_clear_pending_action_tx(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7511 | } |
| 7512 | |
| 7513 | |
| 7514 | int wpas_p2p_find(struct wpa_supplicant *wpa_s, unsigned int timeout, |
| 7515 | enum p2p_discovery_type type, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7516 | unsigned int num_req_dev_types, const u8 *req_dev_types, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7517 | const u8 *dev_id, unsigned int search_delay, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7518 | u8 seek_cnt, const char **seek_string, int freq, |
| 7519 | bool include_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7520 | { |
| 7521 | wpas_p2p_clear_pending_action_tx(wpa_s); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7522 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7523 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7524 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7525 | wpa_s->p2p_in_provisioning) { |
| 7526 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Reject p2p_find operation%s%s", |
| 7527 | (wpa_s->global->p2p_disabled || !wpa_s->global->p2p) ? |
| 7528 | " (P2P disabled)" : "", |
| 7529 | wpa_s->p2p_in_provisioning ? |
| 7530 | " (p2p_in_provisioning)" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7531 | return -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7532 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7533 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7534 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 7535 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7536 | return p2p_find(wpa_s->global->p2p, timeout, type, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7537 | num_req_dev_types, req_dev_types, dev_id, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7538 | search_delay, seek_cnt, seek_string, freq, |
| 7539 | include_6ghz); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7540 | } |
| 7541 | |
| 7542 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7543 | static void wpas_p2p_scan_res_ignore_search(struct wpa_supplicant *wpa_s, |
| 7544 | struct wpa_scan_results *scan_res) |
| 7545 | { |
| 7546 | wpa_printf(MSG_DEBUG, "P2P: Ignore scan results"); |
| 7547 | |
| 7548 | if (wpa_s->p2p_scan_work) { |
| 7549 | struct wpa_radio_work *work = wpa_s->p2p_scan_work; |
| 7550 | wpa_s->p2p_scan_work = NULL; |
| 7551 | radio_work_done(work); |
| 7552 | } |
| 7553 | |
| 7554 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7555 | return; |
| 7556 | |
| 7557 | /* |
| 7558 | * Indicate that results have been processed so that the P2P module can |
| 7559 | * continue pending tasks. |
| 7560 | */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 7561 | wpas_p2p_scan_res_handled(wpa_s); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7562 | } |
| 7563 | |
| 7564 | |
| 7565 | static void wpas_p2p_stop_find_oper(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7566 | { |
| 7567 | wpas_p2p_clear_pending_action_tx(wpa_s); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7568 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7569 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
| 7570 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7571 | |
| 7572 | if (wpa_s->global->p2p) |
| 7573 | p2p_stop_find(wpa_s->global->p2p); |
| 7574 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7575 | if (wpa_s->scan_res_handler == wpas_p2p_scan_res_handler) { |
| 7576 | wpa_printf(MSG_DEBUG, |
| 7577 | "P2P: Do not consider the scan results after stop_find"); |
| 7578 | wpa_s->scan_res_handler = wpas_p2p_scan_res_ignore_search; |
| 7579 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7580 | } |
| 7581 | |
| 7582 | |
| 7583 | void wpas_p2p_stop_find(struct wpa_supplicant *wpa_s) |
| 7584 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7585 | wpas_p2p_stop_find_oper(wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7586 | if (!wpa_s->global->pending_group_iface_for_p2ps) |
| 7587 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7588 | } |
| 7589 | |
| 7590 | |
| 7591 | static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx) |
| 7592 | { |
| 7593 | struct wpa_supplicant *wpa_s = eloop_ctx; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7594 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7595 | } |
| 7596 | |
| 7597 | |
| 7598 | int wpas_p2p_listen(struct wpa_supplicant *wpa_s, unsigned int timeout) |
| 7599 | { |
| 7600 | int res; |
| 7601 | |
| 7602 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7603 | return -1; |
| 7604 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 7605 | if (wpa_s->p2p_lo_started) { |
| 7606 | wpa_printf(MSG_DEBUG, |
| 7607 | "P2P: Cannot start P2P listen, it is offloaded"); |
| 7608 | return -1; |
| 7609 | } |
| 7610 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7611 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7612 | wpas_p2p_clear_pending_action_tx(wpa_s); |
| 7613 | |
| 7614 | if (timeout == 0) { |
| 7615 | /* |
| 7616 | * This is a request for unlimited Listen state. However, at |
| 7617 | * least for now, this is mapped to a Listen state for one |
| 7618 | * hour. |
| 7619 | */ |
| 7620 | timeout = 3600; |
| 7621 | } |
| 7622 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7623 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7624 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7625 | /* |
| 7626 | * Stop previous find/listen operation to avoid trying to request a new |
| 7627 | * remain-on-channel operation while the driver is still running the |
| 7628 | * previous one. |
| 7629 | */ |
| 7630 | if (wpa_s->global->p2p) |
| 7631 | p2p_stop_find(wpa_s->global->p2p); |
| 7632 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7633 | res = wpas_p2p_listen_start(wpa_s, timeout * 1000); |
| 7634 | if (res == 0 && timeout * 1000 > wpa_s->max_remain_on_chan) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7635 | wpa_s->global->p2p_long_listen = timeout * 1000; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7636 | eloop_register_timeout(timeout, 0, |
| 7637 | wpas_p2p_long_listen_timeout, |
| 7638 | wpa_s, NULL); |
| 7639 | } |
| 7640 | |
| 7641 | return res; |
| 7642 | } |
| 7643 | |
| 7644 | |
| 7645 | int wpas_p2p_assoc_req_ie(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
| 7646 | u8 *buf, size_t len, int p2p_group) |
| 7647 | { |
| 7648 | struct wpabuf *p2p_ie; |
| 7649 | int ret; |
| 7650 | |
| 7651 | if (wpa_s->global->p2p_disabled) |
| 7652 | return -1; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 7653 | /* |
| 7654 | * Advertize mandatory cross connection capability even on |
| 7655 | * p2p_disabled=1 interface when associating with a P2P Manager WLAN AP. |
| 7656 | */ |
| 7657 | if (wpa_s->conf->p2p_disabled && p2p_group) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7658 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7659 | if (wpa_s->global->p2p == NULL) |
| 7660 | return -1; |
| 7661 | if (bss == NULL) |
| 7662 | return -1; |
| 7663 | |
| 7664 | p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE); |
| 7665 | ret = p2p_assoc_req_ie(wpa_s->global->p2p, bss->bssid, buf, len, |
| 7666 | p2p_group, p2p_ie); |
| 7667 | wpabuf_free(p2p_ie); |
| 7668 | |
| 7669 | return ret; |
| 7670 | } |
| 7671 | |
| 7672 | |
| 7673 | 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] | 7674 | const u8 *dst, const u8 *bssid, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 7675 | const u8 *ie, size_t ie_len, |
| 7676 | unsigned int rx_freq, int ssi_signal) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7677 | { |
| 7678 | if (wpa_s->global->p2p_disabled) |
| 7679 | return 0; |
| 7680 | if (wpa_s->global->p2p == NULL) |
| 7681 | return 0; |
| 7682 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7683 | switch (p2p_probe_req_rx(wpa_s->global->p2p, addr, dst, bssid, |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 7684 | ie, ie_len, rx_freq, wpa_s->p2p_lo_started)) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7685 | case P2P_PREQ_NOT_P2P: |
| 7686 | wpas_notify_preq(wpa_s, addr, dst, bssid, ie, ie_len, |
| 7687 | ssi_signal); |
| 7688 | /* fall through */ |
| 7689 | case P2P_PREQ_MALFORMED: |
| 7690 | case P2P_PREQ_NOT_LISTEN: |
| 7691 | case P2P_PREQ_NOT_PROCESSED: |
| 7692 | default: /* make gcc happy */ |
| 7693 | return 0; |
| 7694 | case P2P_PREQ_PROCESSED: |
| 7695 | return 1; |
| 7696 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7697 | } |
| 7698 | |
| 7699 | |
| 7700 | void wpas_p2p_rx_action(struct wpa_supplicant *wpa_s, const u8 *da, |
| 7701 | const u8 *sa, const u8 *bssid, |
| 7702 | u8 category, const u8 *data, size_t len, int freq) |
| 7703 | { |
| 7704 | if (wpa_s->global->p2p_disabled) |
| 7705 | return; |
| 7706 | if (wpa_s->global->p2p == NULL) |
| 7707 | return; |
| 7708 | |
| 7709 | p2p_rx_action(wpa_s->global->p2p, da, sa, bssid, category, data, len, |
| 7710 | freq); |
| 7711 | } |
| 7712 | |
| 7713 | |
| 7714 | void wpas_p2p_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ies) |
| 7715 | { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7716 | unsigned int bands; |
| 7717 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7718 | if (wpa_s->global->p2p_disabled) |
| 7719 | return; |
| 7720 | if (wpa_s->global->p2p == NULL) |
| 7721 | return; |
| 7722 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7723 | bands = wpas_get_bands(wpa_s, NULL); |
| 7724 | p2p_scan_ie(wpa_s->global->p2p, ies, NULL, bands); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7725 | } |
| 7726 | |
| 7727 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7728 | static void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7729 | { |
| 7730 | p2p_group_deinit(wpa_s->p2p_group); |
| 7731 | wpa_s->p2p_group = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7732 | |
| 7733 | wpa_s->ap_configured_cb = NULL; |
| 7734 | wpa_s->ap_configured_cb_ctx = NULL; |
| 7735 | wpa_s->ap_configured_cb_data = NULL; |
| 7736 | wpa_s->connect_without_scan = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7737 | } |
| 7738 | |
| 7739 | |
| 7740 | int wpas_p2p_reject(struct wpa_supplicant *wpa_s, const u8 *addr) |
| 7741 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7742 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7743 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7744 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7745 | return -1; |
| 7746 | |
| 7747 | return p2p_reject(wpa_s->global->p2p, addr); |
| 7748 | } |
| 7749 | |
| 7750 | |
| 7751 | /* Invite to reinvoke a persistent group */ |
| 7752 | 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] | 7753 | struct wpa_ssid *ssid, const u8 *go_dev_addr, int freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7754 | int vht_center_freq2, int ht40, int vht, int max_chwidth, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7755 | int pref_freq, int he, int edmg, bool allow_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7756 | { |
| 7757 | enum p2p_invite_role role; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7758 | u8 *bssid = NULL; |
| 7759 | int force_freq = 0; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7760 | int res; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 7761 | int no_pref_freq_given = pref_freq == 0; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 7762 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 7763 | unsigned int size; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7764 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7765 | if (wpas_p2p_check_6ghz(wpa_s, NULL, allow_6ghz, freq)) |
| 7766 | return -1; |
| 7767 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7768 | wpa_s->global->p2p_invite_group = NULL; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7769 | if (peer_addr) |
| 7770 | os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN); |
| 7771 | else |
| 7772 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7773 | |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 7774 | wpa_s->p2p_persistent_go_freq = freq; |
| 7775 | wpa_s->p2p_go_ht40 = !!ht40; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7776 | wpa_s->p2p_go_vht = !!vht; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7777 | wpa_s->p2p_go_he = !!he; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7778 | wpa_s->p2p_go_max_oper_chwidth = max_chwidth; |
| 7779 | wpa_s->p2p_go_vht_center_freq2 = vht_center_freq2; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7780 | wpa_s->p2p_go_edmg = !!edmg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7781 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 7782 | role = P2P_INVITE_ROLE_GO; |
| 7783 | if (peer_addr == NULL) { |
| 7784 | wpa_printf(MSG_DEBUG, "P2P: Missing peer " |
| 7785 | "address in invitation command"); |
| 7786 | return -1; |
| 7787 | } |
| 7788 | if (wpas_p2p_create_iface(wpa_s)) { |
| 7789 | if (wpas_p2p_add_group_interface(wpa_s, |
| 7790 | WPA_IF_P2P_GO) < 0) { |
| 7791 | wpa_printf(MSG_ERROR, "P2P: Failed to " |
| 7792 | "allocate a new interface for the " |
| 7793 | "group"); |
| 7794 | return -1; |
| 7795 | } |
| 7796 | bssid = wpa_s->pending_interface_addr; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7797 | } else if (wpa_s->p2p_mgmt) |
| 7798 | bssid = wpa_s->parent->own_addr; |
| 7799 | else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7800 | bssid = wpa_s->own_addr; |
| 7801 | } else { |
| 7802 | role = P2P_INVITE_ROLE_CLIENT; |
| 7803 | peer_addr = ssid->bssid; |
| 7804 | } |
| 7805 | wpa_s->pending_invite_ssid_id = ssid->id; |
| 7806 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7807 | size = P2P_MAX_PREF_CHANNELS; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7808 | res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7809 | role == P2P_INVITE_ROLE_GO, |
| 7810 | pref_freq_list, &size); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7811 | if (res) |
| 7812 | return res; |
Irfan Sheriff | af84a57 | 2012-09-22 16:59:30 -0700 | [diff] [blame] | 7813 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7814 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7815 | return -1; |
| 7816 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7817 | p2p_set_own_pref_freq_list(wpa_s->global->p2p, pref_freq_list, size); |
| 7818 | |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 7819 | if (wpa_s->parent->conf->p2p_ignore_shared_freq && |
| 7820 | no_pref_freq_given && pref_freq > 0 && |
| 7821 | wpa_s->num_multichan_concurrent > 1 && |
| 7822 | wpas_p2p_num_unused_channels(wpa_s) > 0) { |
| 7823 | wpa_printf(MSG_DEBUG, "P2P: Ignore own channel preference %d MHz for invitation due to p2p_ignore_shared_freq=1 configuration", |
| 7824 | pref_freq); |
| 7825 | pref_freq = 0; |
| 7826 | } |
| 7827 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7828 | /* |
| 7829 | * Stop any find/listen operations before invitation and possibly |
| 7830 | * connection establishment. |
| 7831 | */ |
| 7832 | wpas_p2p_stop_find_oper(wpa_s); |
| 7833 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7834 | return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid, |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7835 | ssid->ssid, ssid->ssid_len, force_freq, go_dev_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7836 | 1, pref_freq, -1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7837 | } |
| 7838 | |
| 7839 | |
| 7840 | /* Invite to join an active group */ |
| 7841 | 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] | 7842 | const u8 *peer_addr, const u8 *go_dev_addr, |
| 7843 | bool allow_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7844 | { |
| 7845 | struct wpa_global *global = wpa_s->global; |
| 7846 | enum p2p_invite_role role; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7847 | u8 *bssid = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7848 | struct wpa_ssid *ssid; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7849 | int persistent; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7850 | int freq = 0, force_freq = 0, pref_freq = 0; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7851 | int res; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 7852 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 7853 | unsigned int size; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7854 | |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 7855 | wpa_s->p2p_persistent_go_freq = 0; |
| 7856 | wpa_s->p2p_go_ht40 = 0; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7857 | wpa_s->p2p_go_vht = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7858 | wpa_s->p2p_go_vht_center_freq2 = 0; |
| 7859 | wpa_s->p2p_go_max_oper_chwidth = 0; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7860 | wpa_s->p2p_go_edmg = 0; |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 7861 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7862 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 7863 | if (os_strcmp(wpa_s->ifname, ifname) == 0) |
| 7864 | break; |
| 7865 | } |
| 7866 | if (wpa_s == NULL) { |
| 7867 | wpa_printf(MSG_DEBUG, "P2P: Interface '%s' not found", ifname); |
| 7868 | return -1; |
| 7869 | } |
| 7870 | |
| 7871 | ssid = wpa_s->current_ssid; |
| 7872 | if (ssid == NULL) { |
| 7873 | wpa_printf(MSG_DEBUG, "P2P: No current SSID to use for " |
| 7874 | "invitation"); |
| 7875 | return -1; |
| 7876 | } |
| 7877 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7878 | wpa_s->global->p2p_invite_group = wpa_s; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7879 | persistent = ssid->p2p_persistent_group && |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7880 | wpas_p2p_get_persistent(wpa_s->p2pdev, peer_addr, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7881 | ssid->ssid, ssid->ssid_len); |
| 7882 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7883 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 7884 | role = P2P_INVITE_ROLE_ACTIVE_GO; |
| 7885 | bssid = wpa_s->own_addr; |
| 7886 | if (go_dev_addr == NULL) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7887 | go_dev_addr = wpa_s->global->p2p_dev_addr; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7888 | freq = ssid->frequency; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7889 | } else { |
| 7890 | role = P2P_INVITE_ROLE_CLIENT; |
| 7891 | if (wpa_s->wpa_state < WPA_ASSOCIATED) { |
| 7892 | wpa_printf(MSG_DEBUG, "P2P: Not associated - cannot " |
| 7893 | "invite to current group"); |
| 7894 | return -1; |
| 7895 | } |
| 7896 | bssid = wpa_s->bssid; |
| 7897 | if (go_dev_addr == NULL && |
| 7898 | !is_zero_ether_addr(wpa_s->go_dev_addr)) |
| 7899 | go_dev_addr = wpa_s->go_dev_addr; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7900 | freq = wpa_s->current_bss ? wpa_s->current_bss->freq : |
| 7901 | (int) wpa_s->assoc_freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7902 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7903 | wpa_s->p2pdev->pending_invite_ssid_id = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7904 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7905 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7906 | return -1; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7907 | if (wpas_p2p_check_6ghz(wpa_s, peer_addr, allow_6ghz, freq)) |
| 7908 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7909 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7910 | size = P2P_MAX_PREF_CHANNELS; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7911 | res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7912 | role == P2P_INVITE_ROLE_ACTIVE_GO, |
| 7913 | pref_freq_list, &size); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7914 | if (res) |
| 7915 | return res; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7916 | wpas_p2p_set_own_freq_preference(wpa_s, force_freq); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7917 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7918 | return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid, |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7919 | ssid->ssid, ssid->ssid_len, force_freq, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7920 | go_dev_addr, persistent, pref_freq, -1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7921 | } |
| 7922 | |
| 7923 | |
| 7924 | void wpas_p2p_completed(struct wpa_supplicant *wpa_s) |
| 7925 | { |
| 7926 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7927 | u8 go_dev_addr[ETH_ALEN]; |
| 7928 | int persistent; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7929 | int freq; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 7930 | u8 ip[3 * 4], *ip_ptr = NULL; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7931 | char ip_addr[100]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7932 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7933 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION) { |
| 7934 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7935 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7936 | } |
| 7937 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7938 | if (!wpa_s->show_group_started || !ssid) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7939 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7940 | |
| 7941 | wpa_s->show_group_started = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7942 | if (!wpa_s->p2p_go_group_formation_completed && |
| 7943 | wpa_s->global->p2p_group_formation == wpa_s) { |
| 7944 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 7945 | "P2P: Marking group formation completed on client on data connection"); |
| 7946 | wpa_s->p2p_go_group_formation_completed = 1; |
| 7947 | wpa_s->global->p2p_group_formation = NULL; |
| 7948 | wpa_s->p2p_in_provisioning = 0; |
| 7949 | wpa_s->p2p_in_invitation = 0; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 7950 | wpa_s->p2p_retry_limit = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7951 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7952 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7953 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 7954 | if (ssid->bssid_set) |
| 7955 | os_memcpy(go_dev_addr, ssid->bssid, ETH_ALEN); |
| 7956 | persistent = wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid, |
| 7957 | ssid->ssid_len); |
| 7958 | os_memcpy(wpa_s->go_dev_addr, go_dev_addr, ETH_ALEN); |
| 7959 | |
| 7960 | if (wpa_s->global->p2p_group_formation == wpa_s) |
| 7961 | wpa_s->global->p2p_group_formation = NULL; |
| 7962 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7963 | freq = wpa_s->current_bss ? wpa_s->current_bss->freq : |
| 7964 | (int) wpa_s->assoc_freq; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7965 | |
| 7966 | ip_addr[0] = '\0'; |
| 7967 | if (wpa_sm_get_p2p_ip_addr(wpa_s->wpa, ip) == 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7968 | int res; |
| 7969 | |
| 7970 | res = os_snprintf(ip_addr, sizeof(ip_addr), |
| 7971 | " ip_addr=%u.%u.%u.%u " |
| 7972 | "ip_mask=%u.%u.%u.%u go_ip_addr=%u.%u.%u.%u", |
| 7973 | ip[0], ip[1], ip[2], ip[3], |
| 7974 | ip[4], ip[5], ip[6], ip[7], |
| 7975 | ip[8], ip[9], ip[10], ip[11]); |
| 7976 | if (os_snprintf_error(sizeof(ip_addr), res)) |
| 7977 | ip_addr[0] = '\0'; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 7978 | ip_ptr = ip; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7979 | } |
| 7980 | |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 7981 | wpas_p2p_group_started(wpa_s, 0, ssid, freq, |
| 7982 | ssid->passphrase == NULL && ssid->psk_set ? |
| 7983 | ssid->psk : NULL, |
| 7984 | ssid->passphrase, go_dev_addr, persistent, |
| 7985 | ip_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7986 | |
| 7987 | if (persistent) |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 7988 | wpas_p2p_store_persistent_group(wpa_s->p2pdev, |
| 7989 | ssid, go_dev_addr); |
| 7990 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 7991 | wpas_notify_p2p_group_started(wpa_s, ssid, persistent, 1, ip_ptr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7992 | } |
| 7993 | |
| 7994 | |
| 7995 | int wpas_p2p_presence_req(struct wpa_supplicant *wpa_s, u32 duration1, |
| 7996 | u32 interval1, u32 duration2, u32 interval2) |
| 7997 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7998 | int ret; |
| 7999 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8000 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8001 | return -1; |
| 8002 | |
| 8003 | if (wpa_s->wpa_state < WPA_ASSOCIATED || |
| 8004 | wpa_s->current_ssid == NULL || |
| 8005 | wpa_s->current_ssid->mode != WPAS_MODE_INFRA) |
| 8006 | return -1; |
| 8007 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8008 | ret = p2p_presence_req(wpa_s->global->p2p, wpa_s->bssid, |
| 8009 | wpa_s->own_addr, wpa_s->assoc_freq, |
| 8010 | duration1, interval1, duration2, interval2); |
| 8011 | if (ret == 0) |
| 8012 | wpa_s->waiting_presence_resp = 1; |
| 8013 | |
| 8014 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8015 | } |
| 8016 | |
| 8017 | |
| 8018 | int wpas_p2p_ext_listen(struct wpa_supplicant *wpa_s, unsigned int period, |
| 8019 | unsigned int interval) |
| 8020 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8021 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8022 | return -1; |
| 8023 | |
| 8024 | return p2p_ext_listen(wpa_s->global->p2p, period, interval); |
| 8025 | } |
| 8026 | |
| 8027 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8028 | static int wpas_p2p_is_client(struct wpa_supplicant *wpa_s) |
| 8029 | { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 8030 | if (wpa_s->current_ssid == NULL) { |
| 8031 | /* |
| 8032 | * current_ssid can be cleared when P2P client interface gets |
| 8033 | * disconnected, so assume this interface was used as P2P |
| 8034 | * client. |
| 8035 | */ |
| 8036 | return 1; |
| 8037 | } |
| 8038 | return wpa_s->current_ssid->p2p_group && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8039 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA; |
| 8040 | } |
| 8041 | |
| 8042 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8043 | static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx) |
| 8044 | { |
| 8045 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 8046 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8047 | 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] | 8048 | wpa_printf(MSG_DEBUG, "P2P: Ignore group idle timeout - " |
| 8049 | "disabled"); |
| 8050 | return; |
| 8051 | } |
| 8052 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8053 | wpa_printf(MSG_DEBUG, "P2P: Group idle timeout reached - terminate " |
| 8054 | "group"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8055 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_IDLE_TIMEOUT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8056 | } |
| 8057 | |
| 8058 | |
| 8059 | static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s) |
| 8060 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8061 | int timeout; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8062 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8063 | if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0) |
| 8064 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout"); |
| 8065 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8066 | if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group) |
| 8067 | return; |
| 8068 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8069 | timeout = wpa_s->conf->p2p_group_idle; |
| 8070 | if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA && |
| 8071 | (timeout == 0 || timeout > P2P_MAX_CLIENT_IDLE)) |
| 8072 | timeout = P2P_MAX_CLIENT_IDLE; |
| 8073 | |
| 8074 | if (timeout == 0) |
| 8075 | return; |
| 8076 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8077 | if (timeout < 0) { |
| 8078 | if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA) |
| 8079 | timeout = 0; /* special client mode no-timeout */ |
| 8080 | else |
| 8081 | return; |
| 8082 | } |
| 8083 | |
| 8084 | if (wpa_s->p2p_in_provisioning) { |
| 8085 | /* |
| 8086 | * Use the normal group formation timeout during the |
| 8087 | * provisioning phase to avoid terminating this process too |
| 8088 | * early due to group idle timeout. |
| 8089 | */ |
| 8090 | wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout " |
| 8091 | "during provisioning"); |
| 8092 | return; |
| 8093 | } |
Deepthi Gowri | 9e4e8ac | 2013-04-16 11:57:05 +0530 | [diff] [blame] | 8094 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8095 | if (wpa_s->show_group_started) { |
| 8096 | /* |
| 8097 | * Use the normal group formation timeout between the end of |
| 8098 | * the provisioning phase and completion of 4-way handshake to |
| 8099 | * avoid terminating this process too early due to group idle |
| 8100 | * timeout. |
| 8101 | */ |
| 8102 | wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout " |
| 8103 | "while waiting for initial 4-way handshake to " |
| 8104 | "complete"); |
| 8105 | return; |
| 8106 | } |
| 8107 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8108 | 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] | 8109 | timeout); |
| 8110 | eloop_register_timeout(timeout, 0, wpas_p2p_group_idle_timeout, |
| 8111 | wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8112 | } |
| 8113 | |
| 8114 | |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8115 | /* Returns 1 if the interface was removed */ |
| 8116 | int wpas_p2p_deauth_notif(struct wpa_supplicant *wpa_s, const u8 *bssid, |
| 8117 | u16 reason_code, const u8 *ie, size_t ie_len, |
| 8118 | int locally_generated) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8119 | { |
| 8120 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8121 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8122 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8123 | if (!locally_generated) |
| 8124 | p2p_deauth_notif(wpa_s->global->p2p, bssid, reason_code, ie, |
| 8125 | ie_len); |
| 8126 | |
| 8127 | if (reason_code == WLAN_REASON_DEAUTH_LEAVING && !locally_generated && |
| 8128 | wpa_s->current_ssid && |
| 8129 | wpa_s->current_ssid->p2p_group && |
| 8130 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA) { |
| 8131 | wpa_printf(MSG_DEBUG, "P2P: GO indicated that the P2P Group " |
| 8132 | "session is ending"); |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8133 | if (wpas_p2p_group_delete(wpa_s, |
| 8134 | P2P_GROUP_REMOVAL_GO_ENDING_SESSION) |
| 8135 | > 0) |
| 8136 | return 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8137 | } |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8138 | |
| 8139 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8140 | } |
| 8141 | |
| 8142 | |
| 8143 | 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] | 8144 | u16 reason_code, const u8 *ie, size_t ie_len, |
| 8145 | int locally_generated) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8146 | { |
| 8147 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8148 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8149 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8150 | if (!locally_generated) |
| 8151 | p2p_disassoc_notif(wpa_s->global->p2p, bssid, reason_code, ie, |
| 8152 | ie_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8153 | } |
| 8154 | |
| 8155 | |
| 8156 | void wpas_p2p_update_config(struct wpa_supplicant *wpa_s) |
| 8157 | { |
| 8158 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 8159 | |
| 8160 | if (p2p == NULL) |
| 8161 | return; |
| 8162 | |
| 8163 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE)) |
| 8164 | return; |
| 8165 | |
| 8166 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_NAME) |
| 8167 | p2p_set_dev_name(p2p, wpa_s->conf->device_name); |
| 8168 | |
| 8169 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_TYPE) |
| 8170 | p2p_set_pri_dev_type(p2p, wpa_s->conf->device_type); |
| 8171 | |
| 8172 | if (wpa_s->wps && |
| 8173 | (wpa_s->conf->changed_parameters & CFG_CHANGED_CONFIG_METHODS)) |
| 8174 | p2p_set_config_methods(p2p, wpa_s->wps->config_methods); |
| 8175 | |
| 8176 | if (wpa_s->wps && (wpa_s->conf->changed_parameters & CFG_CHANGED_UUID)) |
| 8177 | p2p_set_uuid(p2p, wpa_s->wps->uuid); |
| 8178 | |
| 8179 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_WPS_STRING) { |
| 8180 | p2p_set_manufacturer(p2p, wpa_s->conf->manufacturer); |
| 8181 | p2p_set_model_name(p2p, wpa_s->conf->model_name); |
| 8182 | p2p_set_model_number(p2p, wpa_s->conf->model_number); |
| 8183 | p2p_set_serial_number(p2p, wpa_s->conf->serial_number); |
| 8184 | } |
| 8185 | |
| 8186 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_SEC_DEVICE_TYPE) |
| 8187 | p2p_set_sec_dev_types(p2p, |
| 8188 | (void *) wpa_s->conf->sec_device_type, |
| 8189 | wpa_s->conf->num_sec_device_types); |
| 8190 | |
| 8191 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_VENDOR_EXTENSION) { |
| 8192 | int i; |
| 8193 | p2p_remove_wps_vendor_extensions(p2p); |
| 8194 | for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) { |
| 8195 | if (wpa_s->conf->wps_vendor_ext[i] == NULL) |
| 8196 | continue; |
| 8197 | p2p_add_wps_vendor_extension( |
| 8198 | p2p, wpa_s->conf->wps_vendor_ext[i]); |
| 8199 | } |
| 8200 | } |
| 8201 | |
| 8202 | if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) && |
| 8203 | wpa_s->conf->country[0] && wpa_s->conf->country[1]) { |
| 8204 | char country[3]; |
| 8205 | country[0] = wpa_s->conf->country[0]; |
| 8206 | country[1] = wpa_s->conf->country[1]; |
| 8207 | country[2] = 0x04; |
| 8208 | p2p_set_country(p2p, country); |
| 8209 | } |
| 8210 | |
| 8211 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_SSID_POSTFIX) { |
| 8212 | p2p_set_ssid_postfix(p2p, (u8 *) wpa_s->conf->p2p_ssid_postfix, |
| 8213 | wpa_s->conf->p2p_ssid_postfix ? |
| 8214 | os_strlen(wpa_s->conf->p2p_ssid_postfix) : |
| 8215 | 0); |
| 8216 | } |
| 8217 | |
| 8218 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_INTRA_BSS) |
| 8219 | p2p_set_intra_bss_dist(p2p, wpa_s->conf->p2p_intra_bss); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8220 | |
| 8221 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_LISTEN_CHANNEL) { |
| 8222 | u8 reg_class, channel; |
| 8223 | int ret; |
| 8224 | unsigned int r; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8225 | u8 channel_forced; |
| 8226 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8227 | if (wpa_s->conf->p2p_listen_reg_class && |
| 8228 | wpa_s->conf->p2p_listen_channel) { |
| 8229 | reg_class = wpa_s->conf->p2p_listen_reg_class; |
| 8230 | channel = wpa_s->conf->p2p_listen_channel; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8231 | channel_forced = 1; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8232 | } else { |
| 8233 | reg_class = 81; |
| 8234 | /* |
| 8235 | * Pick one of the social channels randomly as the |
| 8236 | * listen channel. |
| 8237 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8238 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 8239 | channel = 1; |
| 8240 | else |
| 8241 | channel = 1 + (r % 3) * 5; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8242 | channel_forced = 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8243 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8244 | ret = p2p_set_listen_channel(p2p, reg_class, channel, |
| 8245 | channel_forced); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8246 | if (ret) |
| 8247 | wpa_printf(MSG_ERROR, "P2P: Own listen channel update " |
| 8248 | "failed: %d", ret); |
| 8249 | } |
| 8250 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_OPER_CHANNEL) { |
| 8251 | u8 op_reg_class, op_channel, cfg_op_channel; |
| 8252 | int ret = 0; |
| 8253 | unsigned int r; |
| 8254 | if (wpa_s->conf->p2p_oper_reg_class && |
| 8255 | wpa_s->conf->p2p_oper_channel) { |
| 8256 | op_reg_class = wpa_s->conf->p2p_oper_reg_class; |
| 8257 | op_channel = wpa_s->conf->p2p_oper_channel; |
| 8258 | cfg_op_channel = 1; |
| 8259 | } else { |
| 8260 | op_reg_class = 81; |
| 8261 | /* |
| 8262 | * Use random operation channel from (1, 6, 11) |
| 8263 | *if no other preference is indicated. |
| 8264 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8265 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 8266 | op_channel = 1; |
| 8267 | else |
| 8268 | op_channel = 1 + (r % 3) * 5; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8269 | cfg_op_channel = 0; |
| 8270 | } |
| 8271 | ret = p2p_set_oper_channel(p2p, op_reg_class, op_channel, |
| 8272 | cfg_op_channel); |
| 8273 | if (ret) |
| 8274 | wpa_printf(MSG_ERROR, "P2P: Own oper channel update " |
| 8275 | "failed: %d", ret); |
| 8276 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8277 | |
| 8278 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PREF_CHAN) { |
| 8279 | if (p2p_set_pref_chan(p2p, wpa_s->conf->num_p2p_pref_chan, |
| 8280 | wpa_s->conf->p2p_pref_chan) < 0) { |
| 8281 | wpa_printf(MSG_ERROR, "P2P: Preferred channel list " |
| 8282 | "update failed"); |
| 8283 | } |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8284 | |
| 8285 | if (p2p_set_no_go_freq(p2p, &wpa_s->conf->p2p_no_go_freq) < 0) { |
| 8286 | wpa_printf(MSG_ERROR, "P2P: No GO channel list " |
| 8287 | "update failed"); |
| 8288 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8289 | } |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 8290 | |
| 8291 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PASSPHRASE_LEN) |
| 8292 | p2p_set_passphrase_len(p2p, wpa_s->conf->p2p_passphrase_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8293 | } |
| 8294 | |
| 8295 | |
| 8296 | int wpas_p2p_set_noa(struct wpa_supplicant *wpa_s, u8 count, int start, |
| 8297 | int duration) |
| 8298 | { |
| 8299 | if (!wpa_s->ap_iface) |
| 8300 | return -1; |
| 8301 | return hostapd_p2p_set_noa(wpa_s->ap_iface->bss[0], count, start, |
| 8302 | duration); |
| 8303 | } |
| 8304 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8305 | |
| 8306 | int wpas_p2p_set_cross_connect(struct wpa_supplicant *wpa_s, int enabled) |
| 8307 | { |
| 8308 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8309 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8310 | |
| 8311 | wpa_s->global->cross_connection = enabled; |
| 8312 | p2p_set_cross_connect(wpa_s->global->p2p, enabled); |
| 8313 | |
| 8314 | if (!enabled) { |
| 8315 | struct wpa_supplicant *iface; |
| 8316 | |
| 8317 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) |
| 8318 | { |
| 8319 | if (iface->cross_connect_enabled == 0) |
| 8320 | continue; |
| 8321 | |
| 8322 | iface->cross_connect_enabled = 0; |
| 8323 | iface->cross_connect_in_use = 0; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8324 | wpa_msg_global(iface->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8325 | P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s", |
| 8326 | iface->ifname, |
| 8327 | iface->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8328 | } |
| 8329 | } |
| 8330 | |
| 8331 | return 0; |
| 8332 | } |
| 8333 | |
| 8334 | |
| 8335 | static void wpas_p2p_enable_cross_connect(struct wpa_supplicant *uplink) |
| 8336 | { |
| 8337 | struct wpa_supplicant *iface; |
| 8338 | |
| 8339 | if (!uplink->global->cross_connection) |
| 8340 | return; |
| 8341 | |
| 8342 | for (iface = uplink->global->ifaces; iface; iface = iface->next) { |
| 8343 | if (!iface->cross_connect_enabled) |
| 8344 | continue; |
| 8345 | if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) != |
| 8346 | 0) |
| 8347 | continue; |
| 8348 | if (iface->ap_iface == NULL) |
| 8349 | continue; |
| 8350 | if (iface->cross_connect_in_use) |
| 8351 | continue; |
| 8352 | |
| 8353 | iface->cross_connect_in_use = 1; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8354 | wpa_msg_global(iface->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8355 | P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s", |
| 8356 | iface->ifname, iface->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8357 | } |
| 8358 | } |
| 8359 | |
| 8360 | |
| 8361 | static void wpas_p2p_disable_cross_connect(struct wpa_supplicant *uplink) |
| 8362 | { |
| 8363 | struct wpa_supplicant *iface; |
| 8364 | |
| 8365 | for (iface = uplink->global->ifaces; iface; iface = iface->next) { |
| 8366 | if (!iface->cross_connect_enabled) |
| 8367 | continue; |
| 8368 | if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) != |
| 8369 | 0) |
| 8370 | continue; |
| 8371 | if (!iface->cross_connect_in_use) |
| 8372 | continue; |
| 8373 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8374 | wpa_msg_global(iface->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8375 | P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s", |
| 8376 | iface->ifname, iface->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8377 | iface->cross_connect_in_use = 0; |
| 8378 | } |
| 8379 | } |
| 8380 | |
| 8381 | |
| 8382 | void wpas_p2p_notif_connected(struct wpa_supplicant *wpa_s) |
| 8383 | { |
| 8384 | if (wpa_s->ap_iface || wpa_s->current_ssid == NULL || |
| 8385 | wpa_s->current_ssid->mode != WPAS_MODE_INFRA || |
| 8386 | wpa_s->cross_connect_disallowed) |
| 8387 | wpas_p2p_disable_cross_connect(wpa_s); |
| 8388 | else |
| 8389 | wpas_p2p_enable_cross_connect(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8390 | if (!wpa_s->ap_iface && |
| 8391 | eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0) |
| 8392 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8393 | } |
| 8394 | |
| 8395 | |
| 8396 | void wpas_p2p_notif_disconnected(struct wpa_supplicant *wpa_s) |
| 8397 | { |
| 8398 | wpas_p2p_disable_cross_connect(wpa_s); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8399 | if (!wpa_s->ap_iface && |
| 8400 | !eloop_is_timeout_registered(wpas_p2p_group_idle_timeout, |
| 8401 | wpa_s, NULL)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8402 | wpas_p2p_set_group_idle_timeout(wpa_s); |
| 8403 | } |
| 8404 | |
| 8405 | |
| 8406 | static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s) |
| 8407 | { |
| 8408 | struct wpa_supplicant *iface; |
| 8409 | |
| 8410 | if (!wpa_s->global->cross_connection) |
| 8411 | return; |
| 8412 | |
| 8413 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 8414 | if (iface == wpa_s) |
| 8415 | continue; |
| 8416 | if (iface->drv_flags & |
| 8417 | WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE) |
| 8418 | continue; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8419 | if ((iface->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) && |
| 8420 | iface != wpa_s->parent) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8421 | continue; |
| 8422 | |
| 8423 | wpa_s->cross_connect_enabled = 1; |
| 8424 | os_strlcpy(wpa_s->cross_connect_uplink, iface->ifname, |
| 8425 | sizeof(wpa_s->cross_connect_uplink)); |
| 8426 | wpa_printf(MSG_DEBUG, "P2P: Enable cross connection from " |
| 8427 | "%s to %s whenever uplink is available", |
| 8428 | wpa_s->ifname, wpa_s->cross_connect_uplink); |
| 8429 | |
| 8430 | if (iface->ap_iface || iface->current_ssid == NULL || |
| 8431 | iface->current_ssid->mode != WPAS_MODE_INFRA || |
| 8432 | iface->cross_connect_disallowed || |
| 8433 | iface->wpa_state != WPA_COMPLETED) |
| 8434 | break; |
| 8435 | |
| 8436 | wpa_s->cross_connect_in_use = 1; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8437 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8438 | P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s", |
| 8439 | wpa_s->ifname, wpa_s->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8440 | break; |
| 8441 | } |
| 8442 | } |
| 8443 | |
| 8444 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 8445 | static int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8446 | { |
| 8447 | if (wpa_s->p2p_group_interface != P2P_GROUP_INTERFACE_CLIENT && |
| 8448 | !wpa_s->p2p_in_provisioning) |
| 8449 | return 0; /* not P2P client operation */ |
| 8450 | |
| 8451 | wpa_printf(MSG_DEBUG, "P2P: Terminate connection due to WPS PBC " |
| 8452 | "session overlap"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8453 | if (wpa_s != wpa_s->p2pdev) |
| 8454 | wpa_msg_ctrl(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_OVERLAP); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8455 | wpas_p2p_group_formation_failed(wpa_s, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8456 | return 1; |
| 8457 | } |
| 8458 | |
| 8459 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8460 | void wpas_p2p_pbc_overlap_cb(void *eloop_ctx, void *timeout_ctx) |
| 8461 | { |
| 8462 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 8463 | wpas_p2p_notif_pbc_overlap(wpa_s); |
| 8464 | } |
| 8465 | |
| 8466 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8467 | void wpas_p2p_update_channel_list(struct wpa_supplicant *wpa_s, |
| 8468 | enum wpas_p2p_channel_update_trig trig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8469 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8470 | struct p2p_channels chan, cli_chan; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8471 | struct wpa_used_freq_data *freqs = NULL; |
| 8472 | unsigned int num = wpa_s->num_multichan_concurrent; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8473 | |
| 8474 | if (wpa_s->global == NULL || wpa_s->global->p2p == NULL) |
| 8475 | return; |
| 8476 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8477 | freqs = os_calloc(num, sizeof(struct wpa_used_freq_data)); |
| 8478 | if (!freqs) |
| 8479 | return; |
| 8480 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 8481 | num = get_shared_radio_freqs_data(wpa_s, freqs, num, false); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8482 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8483 | os_memset(&chan, 0, sizeof(chan)); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8484 | os_memset(&cli_chan, 0, sizeof(cli_chan)); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8485 | if (wpas_p2p_setup_channels(wpa_s, &chan, &cli_chan, |
| 8486 | is_p2p_6ghz_disabled(wpa_s->global->p2p))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8487 | wpa_printf(MSG_ERROR, "P2P: Failed to update supported " |
| 8488 | "channel list"); |
| 8489 | return; |
| 8490 | } |
| 8491 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8492 | p2p_update_channel_list(wpa_s->global->p2p, &chan, &cli_chan); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 8493 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8494 | wpas_p2p_optimize_listen_channel(wpa_s, freqs, num); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 8495 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8496 | /* |
| 8497 | * The used frequencies map changed, so it is possible that a GO is |
| 8498 | * using a channel that is no longer valid for P2P use. It is also |
| 8499 | * possible that due to policy consideration, it would be preferable to |
| 8500 | * move it to a frequency already used by other station interfaces. |
| 8501 | */ |
| 8502 | wpas_p2p_consider_moving_gos(wpa_s, freqs, num, trig); |
| 8503 | |
| 8504 | os_free(freqs); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8505 | } |
| 8506 | |
| 8507 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8508 | static void wpas_p2p_scan_res_ignore(struct wpa_supplicant *wpa_s, |
| 8509 | struct wpa_scan_results *scan_res) |
| 8510 | { |
| 8511 | wpa_printf(MSG_DEBUG, "P2P: Ignore scan results"); |
| 8512 | } |
| 8513 | |
| 8514 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8515 | int wpas_p2p_cancel(struct wpa_supplicant *wpa_s) |
| 8516 | { |
| 8517 | struct wpa_global *global = wpa_s->global; |
| 8518 | int found = 0; |
| 8519 | const u8 *peer; |
| 8520 | |
| 8521 | if (global->p2p == NULL) |
| 8522 | return -1; |
| 8523 | |
| 8524 | wpa_printf(MSG_DEBUG, "P2P: Request to cancel group formation"); |
| 8525 | |
| 8526 | if (wpa_s->pending_interface_name[0] && |
| 8527 | !is_zero_ether_addr(wpa_s->pending_interface_addr)) |
| 8528 | found = 1; |
| 8529 | |
| 8530 | peer = p2p_get_go_neg_peer(global->p2p); |
| 8531 | if (peer) { |
| 8532 | wpa_printf(MSG_DEBUG, "P2P: Unauthorize pending GO Neg peer " |
| 8533 | MACSTR, MAC2STR(peer)); |
| 8534 | p2p_unauthorize(global->p2p, peer); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8535 | found = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8536 | } |
| 8537 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8538 | if (wpa_s->scan_res_handler == wpas_p2p_scan_res_join) { |
| 8539 | wpa_printf(MSG_DEBUG, "P2P: Stop pending scan for join"); |
| 8540 | wpa_s->scan_res_handler = wpas_p2p_scan_res_ignore; |
| 8541 | found = 1; |
| 8542 | } |
| 8543 | |
| 8544 | if (wpa_s->pending_pd_before_join) { |
| 8545 | wpa_printf(MSG_DEBUG, "P2P: Stop pending PD before join"); |
| 8546 | wpa_s->pending_pd_before_join = 0; |
| 8547 | found = 1; |
| 8548 | } |
| 8549 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8550 | wpas_p2p_stop_find(wpa_s); |
| 8551 | |
| 8552 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 8553 | if (wpa_s == global->p2p_group_formation && |
| 8554 | (wpa_s->p2p_in_provisioning || |
| 8555 | wpa_s->parent->pending_interface_type == |
| 8556 | WPA_IF_P2P_CLIENT)) { |
| 8557 | wpa_printf(MSG_DEBUG, "P2P: Interface %s in group " |
| 8558 | "formation found - cancelling", |
| 8559 | wpa_s->ifname); |
| 8560 | found = 1; |
| 8561 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8562 | wpa_s->p2pdev, NULL); |
Jouni Malinen | adddfc4 | 2012-10-03 14:31:41 -0700 | [diff] [blame] | 8563 | if (wpa_s->p2p_in_provisioning) { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8564 | wpas_group_formation_completed(wpa_s, 0, 0); |
Jouni Malinen | adddfc4 | 2012-10-03 14:31:41 -0700 | [diff] [blame] | 8565 | break; |
| 8566 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8567 | wpas_p2p_group_delete(wpa_s, |
| 8568 | P2P_GROUP_REMOVAL_REQUESTED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8569 | break; |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 8570 | } else if (wpa_s->p2p_in_invitation) { |
| 8571 | wpa_printf(MSG_DEBUG, "P2P: Interface %s in invitation found - cancelling", |
| 8572 | wpa_s->ifname); |
| 8573 | found = 1; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8574 | wpas_p2p_group_formation_failed(wpa_s, 0); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8575 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8576 | } |
| 8577 | } |
| 8578 | |
| 8579 | if (!found) { |
| 8580 | wpa_printf(MSG_DEBUG, "P2P: No ongoing group formation found"); |
| 8581 | return -1; |
| 8582 | } |
| 8583 | |
| 8584 | return 0; |
| 8585 | } |
| 8586 | |
| 8587 | |
| 8588 | void wpas_p2p_interface_unavailable(struct wpa_supplicant *wpa_s) |
| 8589 | { |
| 8590 | if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group) |
| 8591 | return; |
| 8592 | |
| 8593 | wpa_printf(MSG_DEBUG, "P2P: Remove group due to driver resource not " |
| 8594 | "being available anymore"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8595 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_UNAVAILABLE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8596 | } |
| 8597 | |
| 8598 | |
| 8599 | void wpas_p2p_update_best_channels(struct wpa_supplicant *wpa_s, |
| 8600 | int freq_24, int freq_5, int freq_overall) |
| 8601 | { |
| 8602 | struct p2p_data *p2p = wpa_s->global->p2p; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8603 | if (p2p == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8604 | return; |
| 8605 | p2p_set_best_channels(p2p, freq_24, freq_5, freq_overall); |
| 8606 | } |
| 8607 | |
| 8608 | |
| 8609 | int wpas_p2p_unauthorize(struct wpa_supplicant *wpa_s, const char *addr) |
| 8610 | { |
| 8611 | u8 peer[ETH_ALEN]; |
| 8612 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 8613 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8614 | if (p2p == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8615 | return -1; |
| 8616 | |
| 8617 | if (hwaddr_aton(addr, peer)) |
| 8618 | return -1; |
| 8619 | |
| 8620 | return p2p_unauthorize(p2p, peer); |
| 8621 | } |
| 8622 | |
| 8623 | |
| 8624 | /** |
| 8625 | * wpas_p2p_disconnect - Disconnect from a P2P Group |
| 8626 | * @wpa_s: Pointer to wpa_supplicant data |
| 8627 | * Returns: 0 on success, -1 on failure |
| 8628 | * |
| 8629 | * This can be used to disconnect from a group in which the local end is a P2P |
| 8630 | * Client or to end a P2P Group in case the local end is the Group Owner. If a |
| 8631 | * virtual network interface was created for this group, that interface will be |
| 8632 | * removed. Otherwise, only the configured P2P group network will be removed |
| 8633 | * from the interface. |
| 8634 | */ |
| 8635 | int wpas_p2p_disconnect(struct wpa_supplicant *wpa_s) |
| 8636 | { |
| 8637 | |
| 8638 | if (wpa_s == NULL) |
| 8639 | return -1; |
| 8640 | |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8641 | return wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_REQUESTED) < 0 ? |
| 8642 | -1 : 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8643 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8644 | |
| 8645 | |
| 8646 | int wpas_p2p_in_progress(struct wpa_supplicant *wpa_s) |
| 8647 | { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8648 | int ret; |
| 8649 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8650 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8651 | return 0; |
| 8652 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8653 | ret = p2p_in_progress(wpa_s->global->p2p); |
| 8654 | if (ret == 0) { |
| 8655 | /* |
| 8656 | * Check whether there is an ongoing WPS provisioning step (or |
| 8657 | * other parts of group formation) on another interface since |
| 8658 | * p2p_in_progress() does not report this to avoid issues for |
| 8659 | * scans during such provisioning step. |
| 8660 | */ |
| 8661 | if (wpa_s->global->p2p_group_formation && |
| 8662 | wpa_s->global->p2p_group_formation != wpa_s) { |
| 8663 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Another interface (%s) " |
| 8664 | "in group formation", |
| 8665 | wpa_s->global->p2p_group_formation->ifname); |
| 8666 | ret = 1; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 8667 | } else if (wpa_s->global->p2p_group_formation == wpa_s) { |
| 8668 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 8669 | "P2P: Skip Extended Listen timeout and allow scans on current interface for group formation"); |
| 8670 | ret = 2; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8671 | } |
| 8672 | } |
| 8673 | |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 8674 | if (!ret && wpa_s->global->p2p_go_wait_client.sec) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8675 | struct os_reltime now; |
| 8676 | os_get_reltime(&now); |
| 8677 | if (os_reltime_expired(&now, &wpa_s->global->p2p_go_wait_client, |
| 8678 | P2P_MAX_INITIAL_CONN_WAIT_GO)) { |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 8679 | /* Wait for the first client has expired */ |
| 8680 | wpa_s->global->p2p_go_wait_client.sec = 0; |
| 8681 | } else { |
| 8682 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Waiting for initial client connection during group formation"); |
| 8683 | ret = 1; |
| 8684 | } |
| 8685 | } |
| 8686 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8687 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8688 | } |
| 8689 | |
| 8690 | |
| 8691 | void wpas_p2p_network_removed(struct wpa_supplicant *wpa_s, |
| 8692 | struct wpa_ssid *ssid) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8693 | { |
| 8694 | if (wpa_s->p2p_in_provisioning && ssid->p2p_group && |
| 8695 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8696 | wpa_s->p2pdev, NULL) > 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8697 | /** |
| 8698 | * Remove the network by scheduling the group formation |
| 8699 | * timeout to happen immediately. The teardown code |
| 8700 | * needs to be scheduled to run asynch later so that we |
| 8701 | * don't delete data from under ourselves unexpectedly. |
| 8702 | * Calling wpas_p2p_group_formation_timeout directly |
| 8703 | * causes a series of crashes in WPS failure scenarios. |
| 8704 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8705 | wpa_printf(MSG_DEBUG, "P2P: Canceled group formation due to " |
| 8706 | "P2P group network getting removed"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8707 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8708 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8709 | } |
| 8710 | } |
| 8711 | |
| 8712 | |
| 8713 | struct wpa_ssid * wpas_p2p_get_persistent(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8714 | const u8 *addr, const u8 *ssid, |
| 8715 | size_t ssid_len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8716 | { |
| 8717 | struct wpa_ssid *s; |
| 8718 | size_t i; |
| 8719 | |
| 8720 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 8721 | if (s->disabled != 2) |
| 8722 | continue; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8723 | if (ssid && |
| 8724 | (ssid_len != s->ssid_len || |
| 8725 | os_memcmp(ssid, s->ssid, ssid_len) != 0)) |
| 8726 | continue; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8727 | if (addr == NULL) { |
| 8728 | if (s->mode == WPAS_MODE_P2P_GO) |
| 8729 | return s; |
| 8730 | continue; |
| 8731 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8732 | if (os_memcmp(s->bssid, addr, ETH_ALEN) == 0) |
| 8733 | return s; /* peer is GO in the persistent group */ |
| 8734 | if (s->mode != WPAS_MODE_P2P_GO || s->p2p_client_list == NULL) |
| 8735 | continue; |
| 8736 | for (i = 0; i < s->num_p2p_clients; i++) { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8737 | if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8738 | addr, ETH_ALEN) == 0) |
| 8739 | return s; /* peer is P2P client in persistent |
| 8740 | * group */ |
| 8741 | } |
| 8742 | } |
| 8743 | |
| 8744 | return NULL; |
| 8745 | } |
| 8746 | |
| 8747 | |
| 8748 | void wpas_p2p_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s, |
| 8749 | const u8 *addr) |
| 8750 | { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8751 | if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8752 | wpa_s->p2pdev, NULL) > 0) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8753 | /* |
| 8754 | * This can happen if WPS provisioning step is not terminated |
| 8755 | * cleanly (e.g., P2P Client does not send WSC_Done). Since the |
| 8756 | * peer was able to connect, there is no need to time out group |
| 8757 | * formation after this, though. In addition, this is used with |
| 8758 | * the initial connection wait on the GO as a separate formation |
| 8759 | * timeout and as such, expected to be hit after the initial WPS |
| 8760 | * provisioning step. |
| 8761 | */ |
| 8762 | 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] | 8763 | |
| 8764 | if (!wpa_s->p2p_go_group_formation_completed && |
| 8765 | !wpa_s->group_formation_reported) { |
| 8766 | /* |
| 8767 | * GO has not yet notified group formation success since |
| 8768 | * the WPS step was not completed cleanly. Do that |
| 8769 | * notification now since the P2P Client was able to |
| 8770 | * connect and as such, must have received the |
| 8771 | * credential from the WPS step. |
| 8772 | */ |
| 8773 | if (wpa_s->global->p2p) |
| 8774 | p2p_wps_success_cb(wpa_s->global->p2p, addr); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8775 | wpas_group_formation_completed(wpa_s, 1, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8776 | } |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8777 | } |
| 8778 | if (!wpa_s->p2p_go_group_formation_completed) { |
| 8779 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Marking group formation completed on GO on first data connection"); |
| 8780 | wpa_s->p2p_go_group_formation_completed = 1; |
| 8781 | wpa_s->global->p2p_group_formation = NULL; |
| 8782 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 8783 | wpa_s->p2p_in_invitation = 0; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 8784 | wpa_s->p2p_retry_limit = 0; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8785 | } |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 8786 | wpa_s->global->p2p_go_wait_client.sec = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8787 | if (addr == NULL) |
| 8788 | return; |
| 8789 | wpas_p2p_add_persistent_group_client(wpa_s, addr); |
| 8790 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8791 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8792 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8793 | static int wpas_p2p_fallback_to_go_neg(struct wpa_supplicant *wpa_s, |
| 8794 | int group_added) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8795 | { |
| 8796 | struct wpa_supplicant *group = wpa_s; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8797 | int ret = 0; |
| 8798 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8799 | if (wpa_s->global->p2p_group_formation) |
| 8800 | group = wpa_s->global->p2p_group_formation; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8801 | wpa_s = wpa_s->global->p2p_init_wpa_s; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8802 | offchannel_send_action_done(wpa_s); |
| 8803 | if (group_added) |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8804 | ret = wpas_p2p_group_delete(group, P2P_GROUP_REMOVAL_SILENT); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8805 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Fall back to GO Negotiation"); |
| 8806 | wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr, wpa_s->p2p_pin, |
| 8807 | wpa_s->p2p_wps_method, wpa_s->p2p_persistent_group, 0, |
| 8808 | 0, 0, wpa_s->p2p_go_intent, wpa_s->p2p_connect_freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8809 | wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8810 | wpa_s->p2p_persistent_id, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8811 | wpa_s->p2p_pd_before_go_neg, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8812 | wpa_s->p2p_go_ht40, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8813 | wpa_s->p2p_go_vht, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8814 | wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8815 | wpa_s->p2p_go_he, |
| 8816 | wpa_s->p2p_go_edmg, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 8817 | NULL, 0, is_p2p_allow_6ghz(wpa_s->global->p2p)); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8818 | return ret; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8819 | } |
| 8820 | |
| 8821 | |
| 8822 | int wpas_p2p_scan_no_go_seen(struct wpa_supplicant *wpa_s) |
| 8823 | { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8824 | int res; |
| 8825 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8826 | if (!wpa_s->p2p_fallback_to_go_neg || |
| 8827 | wpa_s->p2p_in_provisioning <= 5) |
| 8828 | return 0; |
| 8829 | |
| 8830 | if (wpas_p2p_peer_go(wpa_s, wpa_s->pending_join_dev_addr) > 0) |
| 8831 | return 0; /* peer operating as a GO */ |
| 8832 | |
| 8833 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: GO not found for p2p_connect-auto - " |
| 8834 | "fallback to GO Negotiation"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8835 | 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] | 8836 | "reason=GO-not-found"); |
| 8837 | res = wpas_p2p_fallback_to_go_neg(wpa_s, 1); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8838 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8839 | return res == 1 ? 2 : 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8840 | } |
| 8841 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8842 | |
| 8843 | unsigned int wpas_p2p_search_delay(struct wpa_supplicant *wpa_s) |
| 8844 | { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8845 | struct wpa_supplicant *ifs; |
| 8846 | |
| 8847 | if (wpa_s->wpa_state > WPA_SCANNING) { |
| 8848 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search delay due to " |
| 8849 | "concurrent operation", |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 8850 | wpa_s->conf->p2p_search_delay); |
| 8851 | return wpa_s->conf->p2p_search_delay; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8852 | } |
| 8853 | |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 8854 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 8855 | radio_list) { |
| 8856 | if (ifs != wpa_s && ifs->wpa_state > WPA_SCANNING) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8857 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search " |
| 8858 | "delay due to concurrent operation on " |
| 8859 | "interface %s", |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 8860 | wpa_s->conf->p2p_search_delay, |
| 8861 | ifs->ifname); |
| 8862 | return wpa_s->conf->p2p_search_delay; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8863 | } |
| 8864 | } |
| 8865 | |
| 8866 | return 0; |
| 8867 | } |
| 8868 | |
Dmitry Shmidt | 37d4d6a | 2013-03-18 13:09:42 -0700 | [diff] [blame] | 8869 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8870 | static int wpas_p2p_remove_psk_entry(struct wpa_supplicant *wpa_s, |
| 8871 | struct wpa_ssid *s, const u8 *addr, |
| 8872 | int iface_addr) |
| 8873 | { |
| 8874 | struct psk_list_entry *psk, *tmp; |
| 8875 | int changed = 0; |
| 8876 | |
| 8877 | dl_list_for_each_safe(psk, tmp, &s->psk_list, struct psk_list_entry, |
| 8878 | list) { |
| 8879 | if ((iface_addr && !psk->p2p && |
| 8880 | os_memcmp(addr, psk->addr, ETH_ALEN) == 0) || |
| 8881 | (!iface_addr && psk->p2p && |
| 8882 | os_memcmp(addr, psk->addr, ETH_ALEN) == 0)) { |
| 8883 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 8884 | "P2P: Remove persistent group PSK list entry for " |
| 8885 | MACSTR " p2p=%u", |
| 8886 | MAC2STR(psk->addr), psk->p2p); |
| 8887 | dl_list_del(&psk->list); |
| 8888 | os_free(psk); |
| 8889 | changed++; |
| 8890 | } |
| 8891 | } |
| 8892 | |
| 8893 | return changed; |
| 8894 | } |
| 8895 | |
| 8896 | |
| 8897 | void wpas_p2p_new_psk_cb(struct wpa_supplicant *wpa_s, const u8 *mac_addr, |
| 8898 | const u8 *p2p_dev_addr, |
| 8899 | const u8 *psk, size_t psk_len) |
| 8900 | { |
| 8901 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 8902 | struct wpa_ssid *persistent; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 8903 | struct psk_list_entry *p, *last; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8904 | |
| 8905 | if (psk_len != sizeof(p->psk)) |
| 8906 | return; |
| 8907 | |
| 8908 | if (p2p_dev_addr) { |
| 8909 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New PSK for addr=" MACSTR |
| 8910 | " p2p_dev_addr=" MACSTR, |
| 8911 | MAC2STR(mac_addr), MAC2STR(p2p_dev_addr)); |
| 8912 | if (is_zero_ether_addr(p2p_dev_addr)) |
| 8913 | p2p_dev_addr = NULL; |
| 8914 | } else { |
| 8915 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New PSK for addr=" MACSTR, |
| 8916 | MAC2STR(mac_addr)); |
| 8917 | } |
| 8918 | |
| 8919 | if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) { |
| 8920 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: new_psk_cb during group formation"); |
| 8921 | /* To be added to persistent group once created */ |
| 8922 | if (wpa_s->global->add_psk == NULL) { |
| 8923 | wpa_s->global->add_psk = os_zalloc(sizeof(*p)); |
| 8924 | if (wpa_s->global->add_psk == NULL) |
| 8925 | return; |
| 8926 | } |
| 8927 | p = wpa_s->global->add_psk; |
| 8928 | if (p2p_dev_addr) { |
| 8929 | p->p2p = 1; |
| 8930 | os_memcpy(p->addr, p2p_dev_addr, ETH_ALEN); |
| 8931 | } else { |
| 8932 | p->p2p = 0; |
| 8933 | os_memcpy(p->addr, mac_addr, ETH_ALEN); |
| 8934 | } |
| 8935 | os_memcpy(p->psk, psk, psk_len); |
| 8936 | return; |
| 8937 | } |
| 8938 | |
| 8939 | if (ssid->mode != WPAS_MODE_P2P_GO || !ssid->p2p_persistent_group) { |
| 8940 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Ignore new_psk_cb on not-persistent GO"); |
| 8941 | return; |
| 8942 | } |
| 8943 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8944 | persistent = wpas_p2p_get_persistent(wpa_s->p2pdev, NULL, ssid->ssid, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8945 | ssid->ssid_len); |
| 8946 | if (!persistent) { |
| 8947 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not find persistent group information to store the new PSK"); |
| 8948 | return; |
| 8949 | } |
| 8950 | |
| 8951 | p = os_zalloc(sizeof(*p)); |
| 8952 | if (p == NULL) |
| 8953 | return; |
| 8954 | if (p2p_dev_addr) { |
| 8955 | p->p2p = 1; |
| 8956 | os_memcpy(p->addr, p2p_dev_addr, ETH_ALEN); |
| 8957 | } else { |
| 8958 | p->p2p = 0; |
| 8959 | os_memcpy(p->addr, mac_addr, ETH_ALEN); |
| 8960 | } |
| 8961 | os_memcpy(p->psk, psk, psk_len); |
| 8962 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 8963 | if (dl_list_len(&persistent->psk_list) > P2P_MAX_STORED_CLIENTS && |
| 8964 | (last = dl_list_last(&persistent->psk_list, |
| 8965 | struct psk_list_entry, list))) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8966 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove oldest PSK entry for " |
| 8967 | MACSTR " (p2p=%u) to make room for a new one", |
| 8968 | MAC2STR(last->addr), last->p2p); |
| 8969 | dl_list_del(&last->list); |
| 8970 | os_free(last); |
| 8971 | } |
| 8972 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8973 | wpas_p2p_remove_psk_entry(wpa_s->p2pdev, persistent, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8974 | p2p_dev_addr ? p2p_dev_addr : mac_addr, |
| 8975 | p2p_dev_addr == NULL); |
| 8976 | if (p2p_dev_addr) { |
| 8977 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for p2p_dev_addr=" |
| 8978 | MACSTR, MAC2STR(p2p_dev_addr)); |
| 8979 | } else { |
| 8980 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for addr=" MACSTR, |
| 8981 | MAC2STR(mac_addr)); |
| 8982 | } |
| 8983 | dl_list_add(&persistent->psk_list, &p->list); |
| 8984 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8985 | if (wpa_s->p2pdev->conf->update_config && |
| 8986 | wpa_config_write(wpa_s->p2pdev->confname, wpa_s->p2pdev->conf)) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8987 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8988 | } |
| 8989 | |
| 8990 | |
| 8991 | static void wpas_p2p_remove_psk(struct wpa_supplicant *wpa_s, |
| 8992 | struct wpa_ssid *s, const u8 *addr, |
| 8993 | int iface_addr) |
| 8994 | { |
| 8995 | int res; |
| 8996 | |
| 8997 | res = wpas_p2p_remove_psk_entry(wpa_s, s, addr, iface_addr); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 8998 | if (res > 0 && wpa_s->conf->update_config && |
| 8999 | wpa_config_write(wpa_s->confname, wpa_s->conf)) |
| 9000 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9001 | "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_client_go(struct wpa_supplicant *wpa_s, |
| 9006 | const u8 *peer, int iface_addr) |
| 9007 | { |
| 9008 | struct hostapd_data *hapd; |
| 9009 | struct hostapd_wpa_psk *psk, *prev, *rem; |
| 9010 | struct sta_info *sta; |
| 9011 | |
| 9012 | if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL || |
| 9013 | wpa_s->current_ssid->mode != WPAS_MODE_P2P_GO) |
| 9014 | return; |
| 9015 | |
| 9016 | /* Remove per-station PSK entry */ |
| 9017 | hapd = wpa_s->ap_iface->bss[0]; |
| 9018 | prev = NULL; |
| 9019 | psk = hapd->conf->ssid.wpa_psk; |
| 9020 | while (psk) { |
| 9021 | if ((iface_addr && os_memcmp(peer, psk->addr, ETH_ALEN) == 0) || |
| 9022 | (!iface_addr && |
| 9023 | os_memcmp(peer, psk->p2p_dev_addr, ETH_ALEN) == 0)) { |
| 9024 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove operating group PSK entry for " |
| 9025 | MACSTR " iface_addr=%d", |
| 9026 | MAC2STR(peer), iface_addr); |
| 9027 | if (prev) |
| 9028 | prev->next = psk->next; |
| 9029 | else |
| 9030 | hapd->conf->ssid.wpa_psk = psk->next; |
| 9031 | rem = psk; |
| 9032 | psk = psk->next; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 9033 | bin_clear_free(rem, sizeof(*rem)); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9034 | } else { |
| 9035 | prev = psk; |
| 9036 | psk = psk->next; |
| 9037 | } |
| 9038 | } |
| 9039 | |
| 9040 | /* Disconnect from group */ |
| 9041 | if (iface_addr) |
| 9042 | sta = ap_get_sta(hapd, peer); |
| 9043 | else |
| 9044 | sta = ap_get_sta_p2p(hapd, peer); |
| 9045 | if (sta) { |
| 9046 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disconnect peer " MACSTR |
| 9047 | " (iface_addr=%d) from group", |
| 9048 | MAC2STR(peer), iface_addr); |
| 9049 | hostapd_drv_sta_deauth(hapd, sta->addr, |
| 9050 | WLAN_REASON_DEAUTH_LEAVING); |
| 9051 | ap_sta_deauthenticate(hapd, sta, WLAN_REASON_DEAUTH_LEAVING); |
| 9052 | } |
| 9053 | } |
| 9054 | |
| 9055 | |
| 9056 | void wpas_p2p_remove_client(struct wpa_supplicant *wpa_s, const u8 *peer, |
| 9057 | int iface_addr) |
| 9058 | { |
| 9059 | struct wpa_ssid *s; |
| 9060 | struct wpa_supplicant *w; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 9061 | 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] | 9062 | |
| 9063 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove client " MACSTR, MAC2STR(peer)); |
| 9064 | |
| 9065 | /* Remove from any persistent group */ |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 9066 | for (s = p2p_wpa_s->conf->ssid; s; s = s->next) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9067 | if (s->disabled != 2 || s->mode != WPAS_MODE_P2P_GO) |
| 9068 | continue; |
| 9069 | if (!iface_addr) |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 9070 | wpas_remove_persistent_peer(p2p_wpa_s, s, peer, 0); |
| 9071 | wpas_p2p_remove_psk(p2p_wpa_s, s, peer, iface_addr); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9072 | } |
| 9073 | |
| 9074 | /* Remove from any operating group */ |
| 9075 | for (w = wpa_s->global->ifaces; w; w = w->next) |
| 9076 | wpas_p2p_remove_client_go(w, peer, iface_addr); |
| 9077 | } |
| 9078 | |
| 9079 | |
| 9080 | static void wpas_p2p_psk_failure_removal(void *eloop_ctx, void *timeout_ctx) |
| 9081 | { |
| 9082 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 9083 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_PSK_FAILURE); |
| 9084 | } |
| 9085 | |
| 9086 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 9087 | static void wpas_p2p_group_freq_conflict(void *eloop_ctx, void *timeout_ctx) |
| 9088 | { |
| 9089 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 9090 | |
| 9091 | wpa_printf(MSG_DEBUG, "P2P: Frequency conflict - terminate group"); |
| 9092 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_FREQ_CONFLICT); |
| 9093 | } |
| 9094 | |
| 9095 | |
| 9096 | int wpas_p2p_handle_frequency_conflicts(struct wpa_supplicant *wpa_s, int freq, |
| 9097 | struct wpa_ssid *ssid) |
| 9098 | { |
| 9099 | struct wpa_supplicant *iface; |
| 9100 | |
| 9101 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 9102 | if (!iface->current_ssid || |
| 9103 | iface->current_ssid->frequency == freq || |
| 9104 | (iface->p2p_group_interface == NOT_P2P_GROUP_INTERFACE && |
| 9105 | !iface->current_ssid->p2p_group)) |
| 9106 | continue; |
| 9107 | |
| 9108 | /* Remove the connection with least priority */ |
| 9109 | if (!wpas_is_p2p_prioritized(iface)) { |
| 9110 | /* STA connection has priority over existing |
| 9111 | * P2P connection, so remove the interface. */ |
| 9112 | wpa_printf(MSG_DEBUG, "P2P: Removing P2P connection due to single channel concurrent mode frequency conflict"); |
| 9113 | eloop_register_timeout(0, 0, |
| 9114 | wpas_p2p_group_freq_conflict, |
| 9115 | iface, NULL); |
| 9116 | /* If connection in progress is P2P connection, do not |
| 9117 | * proceed for the connection. */ |
| 9118 | if (wpa_s == iface) |
| 9119 | return -1; |
| 9120 | else |
| 9121 | return 0; |
| 9122 | } else { |
| 9123 | /* P2P connection has priority, disable the STA network |
| 9124 | */ |
| 9125 | wpa_supplicant_disable_network(wpa_s->global->ifaces, |
| 9126 | ssid); |
| 9127 | wpa_msg(wpa_s->global->ifaces, MSG_INFO, |
| 9128 | WPA_EVENT_FREQ_CONFLICT " id=%d", ssid->id); |
| 9129 | os_memset(wpa_s->global->ifaces->pending_bssid, 0, |
| 9130 | ETH_ALEN); |
| 9131 | /* If P2P connection is in progress, continue |
| 9132 | * connecting...*/ |
| 9133 | if (wpa_s == iface) |
| 9134 | return 0; |
| 9135 | else |
| 9136 | return -1; |
| 9137 | } |
| 9138 | } |
| 9139 | |
| 9140 | return 0; |
| 9141 | } |
| 9142 | |
| 9143 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9144 | int wpas_p2p_4way_hs_failed(struct wpa_supplicant *wpa_s) |
| 9145 | { |
| 9146 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 9147 | |
| 9148 | if (ssid == NULL || !ssid->p2p_group) |
| 9149 | return 0; |
| 9150 | |
| 9151 | if (wpa_s->p2p_last_4way_hs_fail && |
| 9152 | wpa_s->p2p_last_4way_hs_fail == ssid) { |
| 9153 | u8 go_dev_addr[ETH_ALEN]; |
| 9154 | struct wpa_ssid *persistent; |
| 9155 | |
| 9156 | if (wpas_p2p_persistent_group(wpa_s, go_dev_addr, |
| 9157 | ssid->ssid, |
| 9158 | ssid->ssid_len) <= 0) { |
| 9159 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not determine whether 4-way handshake failures were for a persistent group"); |
| 9160 | goto disconnect; |
| 9161 | } |
| 9162 | |
| 9163 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Two 4-way handshake failures for a P2P group - go_dev_addr=" |
| 9164 | MACSTR, MAC2STR(go_dev_addr)); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9165 | persistent = wpas_p2p_get_persistent(wpa_s->p2pdev, go_dev_addr, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9166 | ssid->ssid, |
| 9167 | ssid->ssid_len); |
| 9168 | if (persistent == NULL || persistent->mode != WPAS_MODE_INFRA) { |
| 9169 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No matching persistent group stored"); |
| 9170 | goto disconnect; |
| 9171 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9172 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9173 | P2P_EVENT_PERSISTENT_PSK_FAIL "%d", |
| 9174 | persistent->id); |
| 9175 | disconnect: |
| 9176 | wpa_s->p2p_last_4way_hs_fail = NULL; |
| 9177 | /* |
| 9178 | * Remove the group from a timeout to avoid issues with caller |
| 9179 | * continuing to use the interface if this is on a P2P group |
| 9180 | * interface. |
| 9181 | */ |
| 9182 | eloop_register_timeout(0, 0, wpas_p2p_psk_failure_removal, |
| 9183 | wpa_s, NULL); |
| 9184 | return 1; |
| 9185 | } |
| 9186 | |
| 9187 | wpa_s->p2p_last_4way_hs_fail = ssid; |
| 9188 | return 0; |
| 9189 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9190 | |
| 9191 | |
| 9192 | #ifdef CONFIG_WPS_NFC |
| 9193 | |
| 9194 | static struct wpabuf * wpas_p2p_nfc_handover(int ndef, struct wpabuf *wsc, |
| 9195 | struct wpabuf *p2p) |
| 9196 | { |
| 9197 | struct wpabuf *ret; |
| 9198 | size_t wsc_len; |
| 9199 | |
| 9200 | if (p2p == NULL) { |
| 9201 | wpabuf_free(wsc); |
| 9202 | wpa_printf(MSG_DEBUG, "P2P: No p2p buffer for handover"); |
| 9203 | return NULL; |
| 9204 | } |
| 9205 | |
| 9206 | wsc_len = wsc ? wpabuf_len(wsc) : 0; |
| 9207 | ret = wpabuf_alloc(2 + wsc_len + 2 + wpabuf_len(p2p)); |
| 9208 | if (ret == NULL) { |
| 9209 | wpabuf_free(wsc); |
| 9210 | wpabuf_free(p2p); |
| 9211 | return NULL; |
| 9212 | } |
| 9213 | |
| 9214 | wpabuf_put_be16(ret, wsc_len); |
| 9215 | if (wsc) |
| 9216 | wpabuf_put_buf(ret, wsc); |
| 9217 | wpabuf_put_be16(ret, wpabuf_len(p2p)); |
| 9218 | wpabuf_put_buf(ret, p2p); |
| 9219 | |
| 9220 | wpabuf_free(wsc); |
| 9221 | wpabuf_free(p2p); |
| 9222 | wpa_hexdump_buf(MSG_DEBUG, |
| 9223 | "P2P: Generated NFC connection handover message", ret); |
| 9224 | |
| 9225 | if (ndef && ret) { |
| 9226 | struct wpabuf *tmp; |
| 9227 | tmp = ndef_build_p2p(ret); |
| 9228 | wpabuf_free(ret); |
| 9229 | if (tmp == NULL) { |
| 9230 | wpa_printf(MSG_DEBUG, "P2P: Failed to NDEF encapsulate handover request"); |
| 9231 | return NULL; |
| 9232 | } |
| 9233 | ret = tmp; |
| 9234 | } |
| 9235 | |
| 9236 | return ret; |
| 9237 | } |
| 9238 | |
| 9239 | |
| 9240 | static int wpas_p2p_cli_freq(struct wpa_supplicant *wpa_s, |
| 9241 | struct wpa_ssid **ssid, u8 *go_dev_addr) |
| 9242 | { |
| 9243 | struct wpa_supplicant *iface; |
| 9244 | |
| 9245 | if (go_dev_addr) |
| 9246 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 9247 | if (ssid) |
| 9248 | *ssid = NULL; |
| 9249 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 9250 | if (iface->wpa_state < WPA_ASSOCIATING || |
| 9251 | iface->current_ssid == NULL || iface->assoc_freq == 0 || |
| 9252 | !iface->current_ssid->p2p_group || |
| 9253 | iface->current_ssid->mode != WPAS_MODE_INFRA) |
| 9254 | continue; |
| 9255 | if (ssid) |
| 9256 | *ssid = iface->current_ssid; |
| 9257 | if (go_dev_addr) |
| 9258 | os_memcpy(go_dev_addr, iface->go_dev_addr, ETH_ALEN); |
| 9259 | return iface->assoc_freq; |
| 9260 | } |
| 9261 | return 0; |
| 9262 | } |
| 9263 | |
| 9264 | |
| 9265 | struct wpabuf * wpas_p2p_nfc_handover_req(struct wpa_supplicant *wpa_s, |
| 9266 | int ndef) |
| 9267 | { |
| 9268 | struct wpabuf *wsc, *p2p; |
| 9269 | struct wpa_ssid *ssid; |
| 9270 | u8 go_dev_addr[ETH_ALEN]; |
| 9271 | int cli_freq = wpas_p2p_cli_freq(wpa_s, &ssid, go_dev_addr); |
| 9272 | |
| 9273 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) { |
| 9274 | wpa_printf(MSG_DEBUG, "P2P: P2P disabled - cannot build handover request"); |
| 9275 | return NULL; |
| 9276 | } |
| 9277 | |
| 9278 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL && |
| 9279 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, |
| 9280 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) { |
| 9281 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No DH key available for handover request"); |
| 9282 | return NULL; |
| 9283 | } |
| 9284 | |
| 9285 | if (cli_freq == 0) { |
| 9286 | wsc = wps_build_nfc_handover_req_p2p( |
| 9287 | wpa_s->parent->wps, wpa_s->conf->wps_nfc_dh_pubkey); |
| 9288 | } else |
| 9289 | wsc = NULL; |
| 9290 | p2p = p2p_build_nfc_handover_req(wpa_s->global->p2p, cli_freq, |
| 9291 | go_dev_addr, ssid ? ssid->ssid : NULL, |
| 9292 | ssid ? ssid->ssid_len : 0); |
| 9293 | |
| 9294 | return wpas_p2p_nfc_handover(ndef, wsc, p2p); |
| 9295 | } |
| 9296 | |
| 9297 | |
| 9298 | struct wpabuf * wpas_p2p_nfc_handover_sel(struct wpa_supplicant *wpa_s, |
| 9299 | int ndef, int tag) |
| 9300 | { |
| 9301 | struct wpabuf *wsc, *p2p; |
| 9302 | struct wpa_ssid *ssid; |
| 9303 | u8 go_dev_addr[ETH_ALEN]; |
| 9304 | int cli_freq = wpas_p2p_cli_freq(wpa_s, &ssid, go_dev_addr); |
| 9305 | |
| 9306 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 9307 | return NULL; |
| 9308 | |
| 9309 | if (!tag && wpa_s->conf->wps_nfc_dh_pubkey == NULL && |
| 9310 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, |
| 9311 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) |
| 9312 | return NULL; |
| 9313 | |
| 9314 | if (cli_freq == 0) { |
| 9315 | wsc = wps_build_nfc_handover_sel_p2p( |
| 9316 | wpa_s->parent->wps, |
| 9317 | tag ? wpa_s->conf->wps_nfc_dev_pw_id : |
| 9318 | DEV_PW_NFC_CONNECTION_HANDOVER, |
| 9319 | wpa_s->conf->wps_nfc_dh_pubkey, |
| 9320 | tag ? wpa_s->conf->wps_nfc_dev_pw : NULL); |
| 9321 | } else |
| 9322 | wsc = NULL; |
| 9323 | p2p = p2p_build_nfc_handover_sel(wpa_s->global->p2p, cli_freq, |
| 9324 | go_dev_addr, ssid ? ssid->ssid : NULL, |
| 9325 | ssid ? ssid->ssid_len : 0); |
| 9326 | |
| 9327 | return wpas_p2p_nfc_handover(ndef, wsc, p2p); |
| 9328 | } |
| 9329 | |
| 9330 | |
| 9331 | static int wpas_p2p_nfc_join_group(struct wpa_supplicant *wpa_s, |
| 9332 | struct p2p_nfc_params *params) |
| 9333 | { |
| 9334 | wpa_printf(MSG_DEBUG, "P2P: Initiate join-group based on NFC " |
| 9335 | "connection handover (freq=%d)", |
| 9336 | params->go_freq); |
| 9337 | |
| 9338 | if (params->go_freq && params->go_ssid_len) { |
| 9339 | wpa_s->p2p_wps_method = WPS_NFC; |
| 9340 | wpa_s->pending_join_wps_method = WPS_NFC; |
| 9341 | os_memset(wpa_s->pending_join_iface_addr, 0, ETH_ALEN); |
| 9342 | os_memcpy(wpa_s->pending_join_dev_addr, params->go_dev_addr, |
| 9343 | ETH_ALEN); |
| 9344 | return wpas_p2p_join_start(wpa_s, params->go_freq, |
| 9345 | params->go_ssid, |
| 9346 | params->go_ssid_len); |
| 9347 | } |
| 9348 | |
| 9349 | return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL, |
| 9350 | WPS_NFC, 0, 0, 1, 0, wpa_s->conf->p2p_go_intent, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9351 | params->go_freq, wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 9352 | -1, 0, 1, 1, wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9353 | wpa_s->p2p_go_he, wpa_s->p2p_go_edmg, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 9354 | params->go_ssid_len ? params->go_ssid : NULL, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9355 | params->go_ssid_len, false); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9356 | } |
| 9357 | |
| 9358 | |
| 9359 | static int wpas_p2p_nfc_auth_join(struct wpa_supplicant *wpa_s, |
| 9360 | struct p2p_nfc_params *params, int tag) |
| 9361 | { |
| 9362 | int res, persistent; |
| 9363 | struct wpa_ssid *ssid; |
| 9364 | |
| 9365 | wpa_printf(MSG_DEBUG, "P2P: Authorize join-group based on NFC " |
| 9366 | "connection handover"); |
| 9367 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 9368 | ssid = wpa_s->current_ssid; |
| 9369 | if (ssid == NULL) |
| 9370 | continue; |
| 9371 | if (ssid->mode != WPAS_MODE_P2P_GO) |
| 9372 | continue; |
| 9373 | if (wpa_s->ap_iface == NULL) |
| 9374 | continue; |
| 9375 | break; |
| 9376 | } |
| 9377 | if (wpa_s == NULL) { |
| 9378 | wpa_printf(MSG_DEBUG, "P2P: Could not find GO interface"); |
| 9379 | return -1; |
| 9380 | } |
| 9381 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9382 | if (wpa_s->p2pdev->p2p_oob_dev_pw_id != |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9383 | DEV_PW_NFC_CONNECTION_HANDOVER && |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9384 | !wpa_s->p2pdev->p2p_oob_dev_pw) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9385 | wpa_printf(MSG_DEBUG, "P2P: No NFC Dev Pw known"); |
| 9386 | return -1; |
| 9387 | } |
| 9388 | res = wpas_ap_wps_add_nfc_pw( |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9389 | wpa_s, wpa_s->p2pdev->p2p_oob_dev_pw_id, |
| 9390 | wpa_s->p2pdev->p2p_oob_dev_pw, |
| 9391 | wpa_s->p2pdev->p2p_peer_oob_pk_hash_known ? |
| 9392 | wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : NULL); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9393 | if (res) |
| 9394 | return res; |
| 9395 | |
| 9396 | if (!tag) { |
| 9397 | wpa_printf(MSG_DEBUG, "P2P: Negotiated handover - wait for peer to join without invitation"); |
| 9398 | return 0; |
| 9399 | } |
| 9400 | |
| 9401 | if (!params->peer || |
| 9402 | !(params->peer->dev_capab & P2P_DEV_CAPAB_INVITATION_PROCEDURE)) |
| 9403 | return 0; |
| 9404 | |
| 9405 | wpa_printf(MSG_DEBUG, "P2P: Static handover - invite peer " MACSTR |
| 9406 | " to join", MAC2STR(params->peer->p2p_device_addr)); |
| 9407 | |
| 9408 | wpa_s->global->p2p_invite_group = wpa_s; |
| 9409 | persistent = ssid->p2p_persistent_group && |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9410 | wpas_p2p_get_persistent(wpa_s->p2pdev, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9411 | params->peer->p2p_device_addr, |
| 9412 | ssid->ssid, ssid->ssid_len); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9413 | wpa_s->p2pdev->pending_invite_ssid_id = -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9414 | |
| 9415 | return p2p_invite(wpa_s->global->p2p, params->peer->p2p_device_addr, |
| 9416 | P2P_INVITE_ROLE_ACTIVE_GO, wpa_s->own_addr, |
| 9417 | ssid->ssid, ssid->ssid_len, ssid->frequency, |
| 9418 | wpa_s->global->p2p_dev_addr, persistent, 0, |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9419 | wpa_s->p2pdev->p2p_oob_dev_pw_id); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9420 | } |
| 9421 | |
| 9422 | |
| 9423 | static int wpas_p2p_nfc_init_go_neg(struct wpa_supplicant *wpa_s, |
| 9424 | struct p2p_nfc_params *params, |
| 9425 | int forced_freq) |
| 9426 | { |
| 9427 | wpa_printf(MSG_DEBUG, "P2P: Initiate GO Negotiation based on NFC " |
| 9428 | "connection handover"); |
| 9429 | return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL, |
| 9430 | WPS_NFC, 0, 0, 0, 0, wpa_s->conf->p2p_go_intent, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9431 | forced_freq, wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 9432 | -1, 0, 1, 1, wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9433 | wpa_s->p2p_go_he, wpa_s->p2p_go_edmg, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9434 | NULL, 0, false); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9435 | } |
| 9436 | |
| 9437 | |
| 9438 | static int wpas_p2p_nfc_resp_go_neg(struct wpa_supplicant *wpa_s, |
| 9439 | struct p2p_nfc_params *params, |
| 9440 | int forced_freq) |
| 9441 | { |
| 9442 | int res; |
| 9443 | |
| 9444 | wpa_printf(MSG_DEBUG, "P2P: Authorize GO Negotiation based on NFC " |
| 9445 | "connection handover"); |
| 9446 | res = wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL, |
| 9447 | WPS_NFC, 0, 0, 0, 1, wpa_s->conf->p2p_go_intent, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9448 | forced_freq, wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 9449 | -1, 0, 1, 1, wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9450 | wpa_s->p2p_go_he, wpa_s->p2p_go_edmg, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9451 | NULL, 0, false); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9452 | if (res) |
| 9453 | return res; |
| 9454 | |
| 9455 | res = wpas_p2p_listen(wpa_s, 60); |
| 9456 | if (res) { |
| 9457 | p2p_unauthorize(wpa_s->global->p2p, |
| 9458 | params->peer->p2p_device_addr); |
| 9459 | } |
| 9460 | |
| 9461 | return res; |
| 9462 | } |
| 9463 | |
| 9464 | |
| 9465 | static int wpas_p2p_nfc_connection_handover(struct wpa_supplicant *wpa_s, |
| 9466 | const struct wpabuf *data, |
| 9467 | int sel, int tag, int forced_freq) |
| 9468 | { |
| 9469 | const u8 *pos, *end; |
| 9470 | u16 len, id; |
| 9471 | struct p2p_nfc_params params; |
| 9472 | int res; |
| 9473 | |
| 9474 | os_memset(¶ms, 0, sizeof(params)); |
| 9475 | params.sel = sel; |
| 9476 | |
| 9477 | wpa_hexdump_buf(MSG_DEBUG, "P2P: Received NFC tag payload", data); |
| 9478 | |
| 9479 | pos = wpabuf_head(data); |
| 9480 | end = pos + wpabuf_len(data); |
| 9481 | |
| 9482 | if (end - pos < 2) { |
| 9483 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for Length of WSC " |
| 9484 | "attributes"); |
| 9485 | return -1; |
| 9486 | } |
| 9487 | len = WPA_GET_BE16(pos); |
| 9488 | pos += 2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9489 | if (len > end - pos) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9490 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for WSC " |
| 9491 | "attributes"); |
| 9492 | return -1; |
| 9493 | } |
| 9494 | params.wsc_attr = pos; |
| 9495 | params.wsc_len = len; |
| 9496 | pos += len; |
| 9497 | |
| 9498 | if (end - pos < 2) { |
| 9499 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for Length of P2P " |
| 9500 | "attributes"); |
| 9501 | return -1; |
| 9502 | } |
| 9503 | len = WPA_GET_BE16(pos); |
| 9504 | pos += 2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9505 | if (len > end - pos) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9506 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for P2P " |
| 9507 | "attributes"); |
| 9508 | return -1; |
| 9509 | } |
| 9510 | params.p2p_attr = pos; |
| 9511 | params.p2p_len = len; |
| 9512 | pos += len; |
| 9513 | |
| 9514 | wpa_hexdump(MSG_DEBUG, "P2P: WSC attributes", |
| 9515 | params.wsc_attr, params.wsc_len); |
| 9516 | wpa_hexdump(MSG_DEBUG, "P2P: P2P attributes", |
| 9517 | params.p2p_attr, params.p2p_len); |
| 9518 | if (pos < end) { |
| 9519 | wpa_hexdump(MSG_DEBUG, |
| 9520 | "P2P: Ignored extra data after P2P attributes", |
| 9521 | pos, end - pos); |
| 9522 | } |
| 9523 | |
| 9524 | res = p2p_process_nfc_connection_handover(wpa_s->global->p2p, ¶ms); |
| 9525 | if (res) |
| 9526 | return res; |
| 9527 | |
| 9528 | if (params.next_step == NO_ACTION) |
| 9529 | return 0; |
| 9530 | |
| 9531 | if (params.next_step == BOTH_GO) { |
| 9532 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_BOTH_GO "peer=" MACSTR, |
| 9533 | MAC2STR(params.peer->p2p_device_addr)); |
| 9534 | return 0; |
| 9535 | } |
| 9536 | |
| 9537 | if (params.next_step == PEER_CLIENT) { |
| 9538 | if (!is_zero_ether_addr(params.go_dev_addr)) { |
| 9539 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_PEER_CLIENT |
| 9540 | "peer=" MACSTR " freq=%d go_dev_addr=" MACSTR |
| 9541 | " ssid=\"%s\"", |
| 9542 | MAC2STR(params.peer->p2p_device_addr), |
| 9543 | params.go_freq, |
| 9544 | MAC2STR(params.go_dev_addr), |
| 9545 | wpa_ssid_txt(params.go_ssid, |
| 9546 | params.go_ssid_len)); |
| 9547 | } else { |
| 9548 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_PEER_CLIENT |
| 9549 | "peer=" MACSTR " freq=%d", |
| 9550 | MAC2STR(params.peer->p2p_device_addr), |
| 9551 | params.go_freq); |
| 9552 | } |
| 9553 | return 0; |
| 9554 | } |
| 9555 | |
| 9556 | if (wpas_p2p_cli_freq(wpa_s, NULL, NULL)) { |
| 9557 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_WHILE_CLIENT "peer=" |
| 9558 | MACSTR, MAC2STR(params.peer->p2p_device_addr)); |
| 9559 | return 0; |
| 9560 | } |
| 9561 | |
| 9562 | wpabuf_free(wpa_s->p2p_oob_dev_pw); |
| 9563 | wpa_s->p2p_oob_dev_pw = NULL; |
| 9564 | |
| 9565 | if (params.oob_dev_pw_len < WPS_OOB_PUBKEY_HASH_LEN + 2) { |
| 9566 | wpa_printf(MSG_DEBUG, "P2P: No peer OOB Dev Pw " |
| 9567 | "received"); |
| 9568 | return -1; |
| 9569 | } |
| 9570 | |
| 9571 | id = WPA_GET_BE16(params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN); |
| 9572 | wpa_printf(MSG_DEBUG, "P2P: Peer OOB Dev Pw %u", id); |
| 9573 | wpa_hexdump(MSG_DEBUG, "P2P: Peer OOB Public Key hash", |
| 9574 | params.oob_dev_pw, WPS_OOB_PUBKEY_HASH_LEN); |
| 9575 | os_memcpy(wpa_s->p2p_peer_oob_pubkey_hash, |
| 9576 | params.oob_dev_pw, WPS_OOB_PUBKEY_HASH_LEN); |
| 9577 | wpa_s->p2p_peer_oob_pk_hash_known = 1; |
| 9578 | |
| 9579 | if (tag) { |
| 9580 | if (id < 0x10) { |
| 9581 | wpa_printf(MSG_DEBUG, "P2P: Static handover - invalid " |
| 9582 | "peer OOB Device Password Id %u", id); |
| 9583 | return -1; |
| 9584 | } |
| 9585 | wpa_printf(MSG_DEBUG, "P2P: Static handover - use peer OOB " |
| 9586 | "Device Password Id %u", id); |
| 9587 | wpa_hexdump_key(MSG_DEBUG, "P2P: Peer OOB Device Password", |
| 9588 | params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN + 2, |
| 9589 | params.oob_dev_pw_len - |
| 9590 | WPS_OOB_PUBKEY_HASH_LEN - 2); |
| 9591 | wpa_s->p2p_oob_dev_pw_id = id; |
| 9592 | wpa_s->p2p_oob_dev_pw = wpabuf_alloc_copy( |
| 9593 | params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN + 2, |
| 9594 | params.oob_dev_pw_len - |
| 9595 | WPS_OOB_PUBKEY_HASH_LEN - 2); |
| 9596 | if (wpa_s->p2p_oob_dev_pw == NULL) |
| 9597 | return -1; |
| 9598 | |
| 9599 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL && |
| 9600 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, |
| 9601 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) |
| 9602 | return -1; |
| 9603 | } else { |
| 9604 | wpa_printf(MSG_DEBUG, "P2P: Using abbreviated WPS handshake " |
| 9605 | "without Device Password"); |
| 9606 | wpa_s->p2p_oob_dev_pw_id = DEV_PW_NFC_CONNECTION_HANDOVER; |
| 9607 | } |
| 9608 | |
| 9609 | switch (params.next_step) { |
| 9610 | case NO_ACTION: |
| 9611 | case BOTH_GO: |
| 9612 | case PEER_CLIENT: |
| 9613 | /* already covered above */ |
| 9614 | return 0; |
| 9615 | case JOIN_GROUP: |
| 9616 | return wpas_p2p_nfc_join_group(wpa_s, ¶ms); |
| 9617 | case AUTH_JOIN: |
| 9618 | return wpas_p2p_nfc_auth_join(wpa_s, ¶ms, tag); |
| 9619 | case INIT_GO_NEG: |
| 9620 | return wpas_p2p_nfc_init_go_neg(wpa_s, ¶ms, forced_freq); |
| 9621 | case RESP_GO_NEG: |
| 9622 | /* TODO: use own OOB Dev Pw */ |
| 9623 | return wpas_p2p_nfc_resp_go_neg(wpa_s, ¶ms, forced_freq); |
| 9624 | } |
| 9625 | |
| 9626 | return -1; |
| 9627 | } |
| 9628 | |
| 9629 | |
| 9630 | int wpas_p2p_nfc_tag_process(struct wpa_supplicant *wpa_s, |
| 9631 | const struct wpabuf *data, int forced_freq) |
| 9632 | { |
| 9633 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 9634 | return -1; |
| 9635 | |
| 9636 | return wpas_p2p_nfc_connection_handover(wpa_s, data, 1, 1, forced_freq); |
| 9637 | } |
| 9638 | |
| 9639 | |
| 9640 | int wpas_p2p_nfc_report_handover(struct wpa_supplicant *wpa_s, int init, |
| 9641 | const struct wpabuf *req, |
| 9642 | const struct wpabuf *sel, int forced_freq) |
| 9643 | { |
| 9644 | struct wpabuf *tmp; |
| 9645 | int ret; |
| 9646 | |
| 9647 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 9648 | return -1; |
| 9649 | |
| 9650 | wpa_printf(MSG_DEBUG, "NFC: P2P connection handover reported"); |
| 9651 | |
| 9652 | wpa_hexdump_ascii(MSG_DEBUG, "NFC: Req", |
| 9653 | wpabuf_head(req), wpabuf_len(req)); |
| 9654 | wpa_hexdump_ascii(MSG_DEBUG, "NFC: Sel", |
| 9655 | wpabuf_head(sel), wpabuf_len(sel)); |
| 9656 | if (forced_freq) |
| 9657 | wpa_printf(MSG_DEBUG, "NFC: Forced freq %d", forced_freq); |
| 9658 | tmp = ndef_parse_p2p(init ? sel : req); |
| 9659 | if (tmp == NULL) { |
| 9660 | wpa_printf(MSG_DEBUG, "P2P: Could not parse NDEF"); |
| 9661 | return -1; |
| 9662 | } |
| 9663 | |
| 9664 | ret = wpas_p2p_nfc_connection_handover(wpa_s, tmp, init, 0, |
| 9665 | forced_freq); |
| 9666 | wpabuf_free(tmp); |
| 9667 | |
| 9668 | return ret; |
| 9669 | } |
| 9670 | |
| 9671 | |
| 9672 | int wpas_p2p_nfc_tag_enabled(struct wpa_supplicant *wpa_s, int enabled) |
| 9673 | { |
| 9674 | const u8 *if_addr; |
| 9675 | int go_intent = wpa_s->conf->p2p_go_intent; |
| 9676 | struct wpa_supplicant *iface; |
| 9677 | |
| 9678 | if (wpa_s->global->p2p == NULL) |
| 9679 | return -1; |
| 9680 | |
| 9681 | if (!enabled) { |
| 9682 | wpa_printf(MSG_DEBUG, "P2P: Disable use of own NFC Tag"); |
| 9683 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) |
| 9684 | { |
| 9685 | if (!iface->ap_iface) |
| 9686 | continue; |
| 9687 | hostapd_wps_nfc_token_disable(iface->ap_iface->bss[0]); |
| 9688 | } |
| 9689 | p2p_set_authorized_oob_dev_pw_id(wpa_s->global->p2p, 0, |
| 9690 | 0, NULL); |
| 9691 | if (wpa_s->p2p_nfc_tag_enabled) |
| 9692 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 9693 | wpa_s->p2p_nfc_tag_enabled = 0; |
| 9694 | return 0; |
| 9695 | } |
| 9696 | |
| 9697 | if (wpa_s->global->p2p_disabled) |
| 9698 | return -1; |
| 9699 | |
| 9700 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL || |
| 9701 | wpa_s->conf->wps_nfc_dh_privkey == NULL || |
| 9702 | wpa_s->conf->wps_nfc_dev_pw == NULL || |
| 9703 | wpa_s->conf->wps_nfc_dev_pw_id < 0x10) { |
| 9704 | wpa_printf(MSG_DEBUG, "P2P: NFC password token not configured " |
| 9705 | "to allow static handover cases"); |
| 9706 | return -1; |
| 9707 | } |
| 9708 | |
| 9709 | wpa_printf(MSG_DEBUG, "P2P: Enable use of own NFC Tag"); |
| 9710 | |
| 9711 | wpa_s->p2p_oob_dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id; |
| 9712 | wpabuf_free(wpa_s->p2p_oob_dev_pw); |
| 9713 | wpa_s->p2p_oob_dev_pw = wpabuf_dup(wpa_s->conf->wps_nfc_dev_pw); |
| 9714 | if (wpa_s->p2p_oob_dev_pw == NULL) |
| 9715 | return -1; |
| 9716 | wpa_s->p2p_peer_oob_pk_hash_known = 0; |
| 9717 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 9718 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO || |
| 9719 | wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT) { |
| 9720 | /* |
| 9721 | * P2P Group Interface present and the command came on group |
| 9722 | * interface, so enable the token for the current interface. |
| 9723 | */ |
| 9724 | wpa_s->create_p2p_iface = 0; |
| 9725 | } else { |
| 9726 | wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s); |
| 9727 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9728 | |
| 9729 | if (wpa_s->create_p2p_iface) { |
| 9730 | enum wpa_driver_if_type iftype; |
| 9731 | /* Prepare to add a new interface for the group */ |
| 9732 | iftype = WPA_IF_P2P_GROUP; |
| 9733 | if (go_intent == 15) |
| 9734 | iftype = WPA_IF_P2P_GO; |
| 9735 | if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) { |
| 9736 | wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " |
| 9737 | "interface for the group"); |
| 9738 | return -1; |
| 9739 | } |
| 9740 | |
| 9741 | if_addr = wpa_s->pending_interface_addr; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9742 | } else if (wpa_s->p2p_mgmt) |
| 9743 | if_addr = wpa_s->parent->own_addr; |
| 9744 | else |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9745 | if_addr = wpa_s->own_addr; |
| 9746 | |
| 9747 | wpa_s->p2p_nfc_tag_enabled = enabled; |
| 9748 | |
| 9749 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 9750 | struct hostapd_data *hapd; |
| 9751 | if (iface->ap_iface == NULL) |
| 9752 | continue; |
| 9753 | hapd = iface->ap_iface->bss[0]; |
| 9754 | wpabuf_free(hapd->conf->wps_nfc_dh_pubkey); |
| 9755 | hapd->conf->wps_nfc_dh_pubkey = |
| 9756 | wpabuf_dup(wpa_s->conf->wps_nfc_dh_pubkey); |
| 9757 | wpabuf_free(hapd->conf->wps_nfc_dh_privkey); |
| 9758 | hapd->conf->wps_nfc_dh_privkey = |
| 9759 | wpabuf_dup(wpa_s->conf->wps_nfc_dh_privkey); |
| 9760 | wpabuf_free(hapd->conf->wps_nfc_dev_pw); |
| 9761 | hapd->conf->wps_nfc_dev_pw = |
| 9762 | wpabuf_dup(wpa_s->conf->wps_nfc_dev_pw); |
| 9763 | hapd->conf->wps_nfc_dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id; |
| 9764 | |
| 9765 | if (hostapd_wps_nfc_token_enable(iface->ap_iface->bss[0]) < 0) { |
| 9766 | wpa_dbg(iface, MSG_DEBUG, |
| 9767 | "P2P: Failed to enable NFC Tag for GO"); |
| 9768 | } |
| 9769 | } |
| 9770 | p2p_set_authorized_oob_dev_pw_id( |
| 9771 | wpa_s->global->p2p, wpa_s->conf->wps_nfc_dev_pw_id, go_intent, |
| 9772 | if_addr); |
| 9773 | |
| 9774 | return 0; |
| 9775 | } |
| 9776 | |
| 9777 | #endif /* CONFIG_WPS_NFC */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9778 | |
| 9779 | |
| 9780 | static void wpas_p2p_optimize_listen_channel(struct wpa_supplicant *wpa_s, |
| 9781 | struct wpa_used_freq_data *freqs, |
| 9782 | unsigned int num) |
| 9783 | { |
| 9784 | u8 curr_chan, cand, chan; |
| 9785 | unsigned int i; |
| 9786 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9787 | /* |
| 9788 | * If possible, optimize the Listen channel to be a channel that is |
| 9789 | * already used by one of the other interfaces. |
| 9790 | */ |
| 9791 | if (!wpa_s->conf->p2p_optimize_listen_chan) |
| 9792 | return; |
| 9793 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9794 | curr_chan = p2p_get_listen_channel(wpa_s->global->p2p); |
| 9795 | for (i = 0, cand = 0; i < num; i++) { |
| 9796 | ieee80211_freq_to_chan(freqs[i].freq, &chan); |
| 9797 | if (curr_chan == chan) { |
| 9798 | cand = 0; |
| 9799 | break; |
| 9800 | } |
| 9801 | |
| 9802 | if (chan == 1 || chan == 6 || chan == 11) |
| 9803 | cand = chan; |
| 9804 | } |
| 9805 | |
| 9806 | if (cand) { |
| 9807 | wpa_dbg(wpa_s, MSG_DEBUG, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 9808 | "P2P: Update Listen channel to %u based on operating channel", |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9809 | cand); |
| 9810 | p2p_set_listen_channel(wpa_s->global->p2p, 81, cand, 0); |
| 9811 | } |
| 9812 | } |
| 9813 | |
| 9814 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9815 | static int wpas_p2p_move_go_csa(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9816 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9817 | struct hostapd_config *conf; |
| 9818 | struct p2p_go_neg_results params; |
| 9819 | struct csa_settings csa_settings; |
| 9820 | struct wpa_ssid *current_ssid = wpa_s->current_ssid; |
| 9821 | int old_freq = current_ssid->frequency; |
| 9822 | int ret; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9823 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9824 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
| 9825 | wpa_dbg(wpa_s, MSG_DEBUG, "CSA is not enabled"); |
| 9826 | return -1; |
| 9827 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9828 | |
| 9829 | /* |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9830 | * TODO: This function may not always work correctly. For example, |
| 9831 | * 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] | 9832 | */ |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9833 | if (wpas_p2p_init_go_params(wpa_s, ¶ms, 0, 0, 0, 0, 0, 0, 0, |
| 9834 | NULL)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9835 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9836 | "P2P CSA: Failed to select new frequency for GO"); |
| 9837 | return -1; |
| 9838 | } |
| 9839 | |
| 9840 | if (current_ssid->frequency == params.freq) { |
| 9841 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9842 | "P2P CSA: Selected same frequency - not moving GO"); |
| 9843 | return 0; |
| 9844 | } |
| 9845 | |
| 9846 | conf = hostapd_config_defaults(); |
| 9847 | if (!conf) { |
| 9848 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9849 | "P2P CSA: Failed to allocate default config"); |
| 9850 | return -1; |
| 9851 | } |
| 9852 | |
| 9853 | current_ssid->frequency = params.freq; |
| 9854 | if (wpa_supplicant_conf_ap_ht(wpa_s, current_ssid, conf)) { |
| 9855 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9856 | "P2P CSA: Failed to create new GO config"); |
| 9857 | ret = -1; |
| 9858 | goto out; |
| 9859 | } |
| 9860 | |
Sunil | 4a3f9f5 | 2022-07-19 22:04:39 +0000 | [diff] [blame] | 9861 | if (conf->hw_mode != wpa_s->ap_iface->current_mode->mode && |
| 9862 | (wpa_s->ap_iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A || |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 9863 | is_6ghz_freq(wpa_s->ap_iface->freq) || |
Sunil | 4a3f9f5 | 2022-07-19 22:04:39 +0000 | [diff] [blame] | 9864 | conf->hw_mode != HOSTAPD_MODE_IEEE80211G)) { |
| 9865 | wpa_dbg(wpa_s, MSG_INFO, |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 9866 | "P2P CSA: CSA from hardware mode %d%s to %d is not supported", |
| 9867 | wpa_s->ap_iface->current_mode->mode, |
| 9868 | is_6ghz_freq(wpa_s->ap_iface->freq) ? " (6 GHz)" : "", |
| 9869 | conf->hw_mode); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9870 | ret = -1; |
| 9871 | goto out; |
| 9872 | } |
| 9873 | |
| 9874 | os_memset(&csa_settings, 0, sizeof(csa_settings)); |
| 9875 | csa_settings.cs_count = P2P_GO_CSA_COUNT; |
| 9876 | csa_settings.block_tx = P2P_GO_CSA_BLOCK_TX; |
| 9877 | csa_settings.freq_params.freq = params.freq; |
| 9878 | csa_settings.freq_params.sec_channel_offset = conf->secondary_channel; |
| 9879 | csa_settings.freq_params.ht_enabled = conf->ieee80211n; |
| 9880 | csa_settings.freq_params.bandwidth = conf->secondary_channel ? 40 : 20; |
| 9881 | |
| 9882 | if (conf->ieee80211ac) { |
| 9883 | int freq1 = 0, freq2 = 0; |
| 9884 | u8 chan, opclass; |
| 9885 | |
| 9886 | if (ieee80211_freq_to_channel_ext(params.freq, |
| 9887 | conf->secondary_channel, |
| 9888 | conf->vht_oper_chwidth, |
| 9889 | &opclass, &chan) == |
| 9890 | NUM_HOSTAPD_MODES) { |
| 9891 | wpa_printf(MSG_ERROR, "P2P CSA: Bad freq"); |
| 9892 | ret = -1; |
| 9893 | goto out; |
| 9894 | } |
| 9895 | |
| 9896 | if (conf->vht_oper_centr_freq_seg0_idx) |
| 9897 | freq1 = ieee80211_chan_to_freq( |
| 9898 | NULL, opclass, |
| 9899 | conf->vht_oper_centr_freq_seg0_idx); |
| 9900 | |
| 9901 | if (conf->vht_oper_centr_freq_seg1_idx) |
| 9902 | freq2 = ieee80211_chan_to_freq( |
| 9903 | NULL, opclass, |
| 9904 | conf->vht_oper_centr_freq_seg1_idx); |
| 9905 | |
| 9906 | if (freq1 < 0 || freq2 < 0) { |
| 9907 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9908 | "P2P CSA: Selected invalid VHT center freqs"); |
| 9909 | ret = -1; |
| 9910 | goto out; |
| 9911 | } |
| 9912 | |
| 9913 | csa_settings.freq_params.vht_enabled = conf->ieee80211ac; |
| 9914 | csa_settings.freq_params.center_freq1 = freq1; |
| 9915 | csa_settings.freq_params.center_freq2 = freq2; |
| 9916 | |
| 9917 | switch (conf->vht_oper_chwidth) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 9918 | case CONF_OPER_CHWIDTH_80MHZ: |
| 9919 | case CONF_OPER_CHWIDTH_80P80MHZ: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9920 | csa_settings.freq_params.bandwidth = 80; |
| 9921 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 9922 | case CONF_OPER_CHWIDTH_160MHZ: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9923 | csa_settings.freq_params.bandwidth = 160; |
| 9924 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 9925 | default: |
| 9926 | break; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9927 | } |
| 9928 | } |
| 9929 | |
| 9930 | ret = ap_switch_channel(wpa_s, &csa_settings); |
| 9931 | out: |
| 9932 | current_ssid->frequency = old_freq; |
| 9933 | hostapd_config_free(conf); |
| 9934 | return ret; |
| 9935 | } |
| 9936 | |
| 9937 | |
| 9938 | static void wpas_p2p_move_go_no_csa(struct wpa_supplicant *wpa_s) |
| 9939 | { |
| 9940 | struct p2p_go_neg_results params; |
| 9941 | struct wpa_ssid *current_ssid = wpa_s->current_ssid; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9942 | void (*ap_configured_cb)(void *ctx, void *data); |
| 9943 | void *ap_configured_cb_ctx, *ap_configured_cb_data; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9944 | |
| 9945 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP); |
| 9946 | |
| 9947 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Move GO from freq=%d MHz", |
| 9948 | current_ssid->frequency); |
| 9949 | |
| 9950 | /* Stop the AP functionality */ |
| 9951 | /* TODO: Should do this in a way that does not indicated to possible |
| 9952 | * P2P Clients in the group that the group is terminated. */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9953 | /* If this action occurs before a group is started, the callback should |
| 9954 | * be preserved, or GROUP-STARTED event would be lost. If this action |
| 9955 | * occurs after a group is started, these pointers are all NULL and |
| 9956 | * harmless. */ |
| 9957 | ap_configured_cb = wpa_s->ap_configured_cb; |
| 9958 | ap_configured_cb_ctx = wpa_s->ap_configured_cb_ctx; |
| 9959 | ap_configured_cb_data = wpa_s->ap_configured_cb_data; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9960 | wpa_supplicant_ap_deinit(wpa_s); |
| 9961 | |
| 9962 | /* Reselect the GO frequency */ |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9963 | if (wpas_p2p_init_go_params(wpa_s, ¶ms, 0, 0, 0, 0, 0, 0, 0, |
| 9964 | NULL)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9965 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Failed to reselect freq"); |
| 9966 | wpas_p2p_group_delete(wpa_s, |
| 9967 | P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL); |
| 9968 | return; |
| 9969 | } |
| 9970 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New freq selected for the GO (%u MHz)", |
| 9971 | params.freq); |
| 9972 | |
| 9973 | if (params.freq && |
| 9974 | !p2p_supported_freq_go(wpa_s->global->p2p, params.freq)) { |
| 9975 | wpa_printf(MSG_DEBUG, |
| 9976 | "P2P: Selected freq (%u MHz) is not valid for P2P", |
| 9977 | params.freq); |
| 9978 | wpas_p2p_group_delete(wpa_s, |
| 9979 | P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL); |
| 9980 | return; |
| 9981 | } |
| 9982 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9983 | /* Restore preserved callback parameters */ |
Jimmy Chen | 4b2a502 | 2020-08-26 18:55:45 +0800 | [diff] [blame] | 9984 | wpa_s->ap_configured_cb = ap_configured_cb; |
| 9985 | wpa_s->ap_configured_cb_ctx = ap_configured_cb_ctx; |
| 9986 | wpa_s->ap_configured_cb_data = ap_configured_cb_data; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9987 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9988 | /* Update the frequency */ |
| 9989 | current_ssid->frequency = params.freq; |
| 9990 | wpa_s->connect_without_scan = current_ssid; |
| 9991 | wpa_s->reassociate = 1; |
| 9992 | wpa_s->disconnected = 0; |
| 9993 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 9994 | } |
| 9995 | |
| 9996 | |
| 9997 | static void wpas_p2p_move_go(void *eloop_ctx, void *timeout_ctx) |
| 9998 | { |
| 9999 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 10000 | |
| 10001 | if (!wpa_s->ap_iface || !wpa_s->current_ssid) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10002 | return; |
| 10003 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10004 | wpas_p2p_go_update_common_freqs(wpa_s); |
| 10005 | |
| 10006 | /* Do not move GO in the middle of a CSA */ |
| 10007 | if (hostapd_csa_in_progress(wpa_s->ap_iface)) { |
| 10008 | wpa_printf(MSG_DEBUG, |
| 10009 | "P2P: CSA is in progress - not moving GO"); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10010 | return; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10011 | } |
| 10012 | |
| 10013 | /* |
| 10014 | * First, try a channel switch flow. If it is not supported or fails, |
| 10015 | * take down the GO and bring it up again. |
| 10016 | */ |
| 10017 | if (wpas_p2p_move_go_csa(wpa_s) < 0) |
| 10018 | wpas_p2p_move_go_no_csa(wpa_s); |
| 10019 | } |
| 10020 | |
| 10021 | |
| 10022 | static void wpas_p2p_reconsider_moving_go(void *eloop_ctx, void *timeout_ctx) |
| 10023 | { |
| 10024 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 10025 | struct wpa_used_freq_data *freqs = NULL; |
| 10026 | unsigned int num = wpa_s->num_multichan_concurrent; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10027 | |
| 10028 | freqs = os_calloc(num, sizeof(struct wpa_used_freq_data)); |
| 10029 | if (!freqs) |
| 10030 | return; |
| 10031 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 10032 | num = get_shared_radio_freqs_data(wpa_s, freqs, num, false); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10033 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10034 | /* Previous attempt to move a GO was not possible -- try again. */ |
| 10035 | wpas_p2p_consider_moving_gos(wpa_s, freqs, num, |
| 10036 | WPAS_P2P_CHANNEL_UPDATE_ANY); |
| 10037 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10038 | os_free(freqs); |
| 10039 | } |
| 10040 | |
| 10041 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10042 | /* |
| 10043 | * Consider moving a GO from its currently used frequency: |
| 10044 | * 1. It is possible that due to regulatory consideration the frequency |
| 10045 | * can no longer be used and there is a need to evacuate the GO. |
| 10046 | * 2. It is possible that due to MCC considerations, it would be preferable |
| 10047 | * to move the GO to a channel that is currently used by some other |
| 10048 | * station interface. |
| 10049 | * |
| 10050 | * In case a frequency that became invalid is once again valid, cancel a |
| 10051 | * previously initiated GO frequency change. |
| 10052 | */ |
| 10053 | static void wpas_p2p_consider_moving_one_go(struct wpa_supplicant *wpa_s, |
| 10054 | struct wpa_used_freq_data *freqs, |
| 10055 | unsigned int num) |
| 10056 | { |
| 10057 | unsigned int i, invalid_freq = 0, policy_move = 0, flags = 0; |
| 10058 | unsigned int timeout; |
| 10059 | int freq; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10060 | int dfs_offload; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10061 | |
| 10062 | wpas_p2p_go_update_common_freqs(wpa_s); |
| 10063 | |
| 10064 | freq = wpa_s->current_ssid->frequency; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10065 | dfs_offload = (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10066 | 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] | 10067 | for (i = 0, invalid_freq = 0; i < num; i++) { |
| 10068 | if (freqs[i].freq == freq) { |
| 10069 | flags = freqs[i].flags; |
| 10070 | |
| 10071 | /* The channel is invalid, must change it */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10072 | if (!p2p_supported_freq_go(wpa_s->global->p2p, freq) && |
| 10073 | !dfs_offload) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10074 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10075 | "P2P: Freq=%d MHz no longer valid for GO", |
| 10076 | freq); |
| 10077 | invalid_freq = 1; |
| 10078 | } |
| 10079 | } else if (freqs[i].flags == 0) { |
| 10080 | /* Freq is not used by any other station interface */ |
| 10081 | continue; |
| 10082 | } else if (!p2p_supported_freq(wpa_s->global->p2p, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10083 | freqs[i].freq) && !dfs_offload) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10084 | /* Freq is not valid for P2P use cases */ |
| 10085 | continue; |
| 10086 | } else if (wpa_s->conf->p2p_go_freq_change_policy == |
| 10087 | P2P_GO_FREQ_MOVE_SCM) { |
| 10088 | policy_move = 1; |
| 10089 | } else if (wpa_s->conf->p2p_go_freq_change_policy == |
| 10090 | P2P_GO_FREQ_MOVE_SCM_PEER_SUPPORTS && |
| 10091 | wpas_p2p_go_is_peer_freq(wpa_s, freqs[i].freq)) { |
| 10092 | policy_move = 1; |
| 10093 | } else if ((wpa_s->conf->p2p_go_freq_change_policy == |
| 10094 | P2P_GO_FREQ_MOVE_SCM_ECSA) && |
| 10095 | wpas_p2p_go_is_peer_freq(wpa_s, freqs[i].freq)) { |
| 10096 | if (!p2p_get_group_num_members(wpa_s->p2p_group)) { |
| 10097 | policy_move = 1; |
| 10098 | } else if ((wpa_s->drv_flags & |
| 10099 | WPA_DRIVER_FLAGS_AP_CSA) && |
| 10100 | wpas_p2p_go_clients_support_ecsa(wpa_s)) { |
| 10101 | u8 chan; |
| 10102 | |
| 10103 | /* |
| 10104 | * We do not support CSA between bands, so move |
| 10105 | * GO only within the same band. |
| 10106 | */ |
| 10107 | if (wpa_s->ap_iface->current_mode->mode == |
| 10108 | ieee80211_freq_to_chan(freqs[i].freq, |
| 10109 | &chan)) |
| 10110 | policy_move = 1; |
| 10111 | } |
| 10112 | } |
| 10113 | } |
| 10114 | |
| 10115 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10116 | "P2P: GO move: invalid_freq=%u, policy_move=%u, flags=0x%X", |
| 10117 | invalid_freq, policy_move, flags); |
| 10118 | |
| 10119 | /* |
| 10120 | * The channel is valid, or we are going to have a policy move, so |
| 10121 | * cancel timeout. |
| 10122 | */ |
| 10123 | if (!invalid_freq || policy_move) { |
| 10124 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10125 | "P2P: Cancel a GO move from freq=%d MHz", freq); |
| 10126 | eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL); |
| 10127 | |
| 10128 | if (wpas_p2p_in_progress(wpa_s)) { |
| 10129 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10130 | "P2P: GO move: policy CS is not allowed - setting timeout to re-consider GO move"); |
| 10131 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, |
| 10132 | wpa_s, NULL); |
| 10133 | eloop_register_timeout(P2P_RECONSIDER_GO_MOVE_DELAY, 0, |
| 10134 | wpas_p2p_reconsider_moving_go, |
| 10135 | wpa_s, NULL); |
| 10136 | return; |
| 10137 | } |
| 10138 | } |
| 10139 | |
| 10140 | if (!invalid_freq && (!policy_move || flags != 0)) { |
| 10141 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10142 | "P2P: Not initiating a GO frequency change"); |
| 10143 | return; |
| 10144 | } |
| 10145 | |
| 10146 | /* |
| 10147 | * Do not consider moving GO if it is in the middle of a CSA. When the |
| 10148 | * CSA is finished this flow should be retriggered. |
| 10149 | */ |
| 10150 | if (hostapd_csa_in_progress(wpa_s->ap_iface)) { |
| 10151 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10152 | "P2P: Not initiating a GO frequency change - CSA is in progress"); |
| 10153 | return; |
| 10154 | } |
| 10155 | |
| 10156 | if (invalid_freq && !wpas_p2p_disallowed_freq(wpa_s->global, freq)) |
| 10157 | timeout = P2P_GO_FREQ_CHANGE_TIME; |
| 10158 | else |
| 10159 | timeout = 0; |
| 10160 | |
| 10161 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Move GO from freq=%d MHz in %d secs", |
| 10162 | freq, timeout); |
| 10163 | eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL); |
| 10164 | eloop_register_timeout(timeout, 0, wpas_p2p_move_go, wpa_s, NULL); |
| 10165 | } |
| 10166 | |
| 10167 | |
| 10168 | static void wpas_p2p_consider_moving_gos(struct wpa_supplicant *wpa_s, |
| 10169 | struct wpa_used_freq_data *freqs, |
| 10170 | unsigned int num, |
| 10171 | enum wpas_p2p_channel_update_trig trig) |
| 10172 | { |
| 10173 | struct wpa_supplicant *ifs; |
| 10174 | |
| 10175 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, ELOOP_ALL_CTX, |
| 10176 | NULL); |
| 10177 | |
| 10178 | /* |
| 10179 | * Travers all the radio interfaces, and for each GO interface, check |
| 10180 | * if there is a need to move the GO from the frequency it is using, |
| 10181 | * or in case the frequency is valid again, cancel the evacuation flow. |
| 10182 | */ |
| 10183 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 10184 | radio_list) { |
| 10185 | if (ifs->current_ssid == NULL || |
| 10186 | ifs->current_ssid->mode != WPAS_MODE_P2P_GO) |
| 10187 | continue; |
| 10188 | |
| 10189 | /* |
| 10190 | * The GO was just started or completed channel switch, no need |
| 10191 | * to move it. |
| 10192 | */ |
| 10193 | if (wpa_s == ifs && |
| 10194 | (trig == WPAS_P2P_CHANNEL_UPDATE_STATE_CHANGE || |
| 10195 | trig == WPAS_P2P_CHANNEL_UPDATE_CS)) { |
| 10196 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10197 | "P2P: GO move - schedule re-consideration"); |
| 10198 | eloop_register_timeout(P2P_RECONSIDER_GO_MOVE_DELAY, 0, |
| 10199 | wpas_p2p_reconsider_moving_go, |
| 10200 | wpa_s, NULL); |
| 10201 | continue; |
| 10202 | } |
| 10203 | |
| 10204 | wpas_p2p_consider_moving_one_go(ifs, freqs, num); |
| 10205 | } |
| 10206 | } |
| 10207 | |
| 10208 | |
| 10209 | void wpas_p2p_indicate_state_change(struct wpa_supplicant *wpa_s) |
| 10210 | { |
| 10211 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 10212 | return; |
| 10213 | |
| 10214 | wpas_p2p_update_channel_list(wpa_s, |
| 10215 | WPAS_P2P_CHANNEL_UPDATE_STATE_CHANGE); |
| 10216 | } |
| 10217 | |
| 10218 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10219 | void wpas_p2p_deinit_iface(struct wpa_supplicant *wpa_s) |
| 10220 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10221 | if (wpa_s == wpa_s->global->p2p_init_wpa_s && wpa_s->global->p2p) { |
| 10222 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disable P2P since removing " |
| 10223 | "the management interface is being removed"); |
| 10224 | wpas_p2p_deinit_global(wpa_s->global); |
| 10225 | } |
| 10226 | } |
| 10227 | |
| 10228 | |
| 10229 | void wpas_p2p_ap_deinit(struct wpa_supplicant *wpa_s) |
| 10230 | { |
| 10231 | if (wpa_s->ap_iface->bss) |
| 10232 | wpa_s->ap_iface->bss[0]->p2p_group = NULL; |
| 10233 | wpas_p2p_group_deinit(wpa_s); |
| 10234 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10235 | |
| 10236 | |
| 10237 | int wpas_p2p_lo_start(struct wpa_supplicant *wpa_s, unsigned int freq, |
| 10238 | unsigned int period, unsigned int interval, |
| 10239 | unsigned int count) |
| 10240 | { |
| 10241 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 10242 | u8 *device_types; |
| 10243 | size_t dev_types_len; |
| 10244 | struct wpabuf *buf; |
| 10245 | int ret; |
| 10246 | |
| 10247 | if (wpa_s->p2p_lo_started) { |
| 10248 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10249 | "P2P Listen offload is already started"); |
| 10250 | return 0; |
| 10251 | } |
| 10252 | |
| 10253 | if (wpa_s->global->p2p == NULL || |
| 10254 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) { |
| 10255 | wpa_printf(MSG_DEBUG, "P2P: Listen offload not supported"); |
| 10256 | return -1; |
| 10257 | } |
| 10258 | |
| 10259 | if (!p2p_supported_freq(wpa_s->global->p2p, freq)) { |
| 10260 | wpa_printf(MSG_ERROR, "P2P: Input channel not supported: %u", |
| 10261 | freq); |
| 10262 | return -1; |
| 10263 | } |
| 10264 | |
| 10265 | /* Get device type */ |
| 10266 | dev_types_len = (wpa_s->conf->num_sec_device_types + 1) * |
| 10267 | WPS_DEV_TYPE_LEN; |
| 10268 | device_types = os_malloc(dev_types_len); |
| 10269 | if (!device_types) |
| 10270 | return -1; |
| 10271 | os_memcpy(device_types, wpa_s->conf->device_type, WPS_DEV_TYPE_LEN); |
| 10272 | os_memcpy(&device_types[WPS_DEV_TYPE_LEN], wpa_s->conf->sec_device_type, |
| 10273 | wpa_s->conf->num_sec_device_types * WPS_DEV_TYPE_LEN); |
| 10274 | |
| 10275 | /* Get Probe Response IE(s) */ |
| 10276 | buf = p2p_build_probe_resp_template(p2p, freq); |
| 10277 | if (!buf) { |
| 10278 | os_free(device_types); |
| 10279 | return -1; |
| 10280 | } |
| 10281 | |
| 10282 | ret = wpa_drv_p2p_lo_start(wpa_s, freq, period, interval, count, |
| 10283 | device_types, dev_types_len, |
| 10284 | wpabuf_mhead_u8(buf), wpabuf_len(buf)); |
| 10285 | if (ret < 0) |
| 10286 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10287 | "P2P: Failed to start P2P listen offload"); |
| 10288 | |
| 10289 | os_free(device_types); |
| 10290 | wpabuf_free(buf); |
| 10291 | |
| 10292 | if (ret == 0) { |
| 10293 | wpa_s->p2p_lo_started = 1; |
| 10294 | |
| 10295 | /* Stop current P2P listen if any */ |
| 10296 | wpas_stop_listen(wpa_s); |
| 10297 | } |
| 10298 | |
| 10299 | return ret; |
| 10300 | } |
| 10301 | |
| 10302 | |
| 10303 | int wpas_p2p_lo_stop(struct wpa_supplicant *wpa_s) |
| 10304 | { |
| 10305 | int ret; |
| 10306 | |
| 10307 | if (!wpa_s->p2p_lo_started) |
| 10308 | return 0; |
| 10309 | |
| 10310 | ret = wpa_drv_p2p_lo_stop(wpa_s); |
| 10311 | if (ret < 0) |
| 10312 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10313 | "P2P: Failed to stop P2P listen offload"); |
| 10314 | |
| 10315 | wpa_s->p2p_lo_started = 0; |
| 10316 | return ret; |
| 10317 | } |