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" |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 26 | #include "ap/wpa_auth.h" |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 27 | #include "eapol_supp/eapol_supp_sm.h" |
| 28 | #include "rsn_supp/wpa.h" |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 29 | #include "rsn_supp/pmksa_cache.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 30 | #include "wpa_supplicant_i.h" |
| 31 | #include "driver_i.h" |
| 32 | #include "ap.h" |
| 33 | #include "config_ssid.h" |
| 34 | #include "config.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 35 | #include "notify.h" |
| 36 | #include "scan.h" |
| 37 | #include "bss.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 38 | #include "offchannel.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 39 | #include "wps_supplicant.h" |
| 40 | #include "p2p_supplicant.h" |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 41 | #include "wifi_display.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 42 | |
| 43 | |
| 44 | /* |
| 45 | * How many times to try to scan to find the GO before giving up on join |
| 46 | * request. |
| 47 | */ |
| 48 | #define P2P_MAX_JOIN_SCAN_ATTEMPTS 10 |
| 49 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 50 | #define P2P_AUTO_PD_SCAN_ATTEMPTS 5 |
| 51 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 52 | /** |
| 53 | * Defines time interval in seconds when a GO needs to evacuate a frequency that |
| 54 | * it is currently using, but is no longer valid for P2P use cases. |
| 55 | */ |
| 56 | #define P2P_GO_FREQ_CHANGE_TIME 5 |
| 57 | |
| 58 | /** |
| 59 | * Defines CSA parameters which are used when GO evacuates the no longer valid |
| 60 | * channel (and if the driver supports channel switch). |
| 61 | */ |
| 62 | #define P2P_GO_CSA_COUNT 7 |
| 63 | #define P2P_GO_CSA_BLOCK_TX 0 |
| 64 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 65 | #ifndef P2P_MAX_CLIENT_IDLE |
| 66 | /* |
| 67 | * How many seconds to try to reconnect to the GO when connection in P2P client |
| 68 | * role has been lost. |
| 69 | */ |
| 70 | #define P2P_MAX_CLIENT_IDLE 10 |
| 71 | #endif /* P2P_MAX_CLIENT_IDLE */ |
| 72 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 73 | #ifndef P2P_MAX_INITIAL_CONN_WAIT |
| 74 | /* |
| 75 | * 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] | 76 | * WPS provisioning step or after the re-invocation of a persistent group on a |
| 77 | * P2P Client. |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 78 | */ |
| 79 | #define P2P_MAX_INITIAL_CONN_WAIT 10 |
| 80 | #endif /* P2P_MAX_INITIAL_CONN_WAIT */ |
| 81 | |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 82 | #ifndef P2P_MAX_INITIAL_CONN_WAIT_GO |
| 83 | /* |
| 84 | * How many seconds to wait for initial 4-way handshake to get completed after |
| 85 | * WPS provisioning step on the GO. This controls the extra time the P2P |
| 86 | * operation is considered to be in progress (e.g., to delay other scans) after |
| 87 | * WPS provisioning has been completed on the GO during group formation. |
| 88 | */ |
| 89 | #define P2P_MAX_INITIAL_CONN_WAIT_GO 10 |
| 90 | #endif /* P2P_MAX_INITIAL_CONN_WAIT_GO */ |
| 91 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 92 | #ifndef P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE |
| 93 | /* |
| 94 | * How many seconds to wait for initial 4-way handshake to get completed after |
| 95 | * re-invocation of a persistent group on the GO when the client is expected |
| 96 | * to connect automatically (no user interaction). |
| 97 | */ |
| 98 | #define P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE 15 |
| 99 | #endif /* P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE */ |
| 100 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 101 | #define P2P_MGMT_DEVICE_PREFIX "p2p-dev-" |
| 102 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 103 | /* |
| 104 | * How many seconds to wait to re-attempt to move GOs, in case previous attempt |
| 105 | * was not possible. |
| 106 | */ |
| 107 | #define P2P_RECONSIDER_GO_MOVE_DELAY 30 |
| 108 | |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 109 | /* Check if frequency is 2GHz */ |
| 110 | #define IS_2GHZ(n) (n >= 2412 && n <= 2484) |
| 111 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 112 | enum p2p_group_removal_reason { |
| 113 | P2P_GROUP_REMOVAL_UNKNOWN, |
| 114 | P2P_GROUP_REMOVAL_SILENT, |
| 115 | P2P_GROUP_REMOVAL_FORMATION_FAILED, |
| 116 | P2P_GROUP_REMOVAL_REQUESTED, |
| 117 | P2P_GROUP_REMOVAL_IDLE_TIMEOUT, |
| 118 | P2P_GROUP_REMOVAL_UNAVAILABLE, |
| 119 | P2P_GROUP_REMOVAL_GO_ENDING_SESSION, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 120 | P2P_GROUP_REMOVAL_PSK_FAILURE, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 121 | P2P_GROUP_REMOVAL_FREQ_CONFLICT, |
| 122 | P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
Jouni Malinen | dc7b713 | 2012-09-14 12:53:47 -0700 | [diff] [blame] | 125 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 126 | static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx); |
| 127 | static struct wpa_supplicant * |
| 128 | wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated, |
| 129 | int go); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 130 | static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s, int freq, |
| 131 | const u8 *ssid, size_t ssid_len); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 132 | static int wpas_p2p_setup_freqs(struct wpa_supplicant *wpa_s, int freq, |
| 133 | int *force_freq, int *pref_freq, int go, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 134 | struct weighted_pcl *pref_freq_list, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 135 | unsigned int *num_pref_freq); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 136 | static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq, |
| 137 | const u8 *ssid, size_t ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 138 | static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx); |
| 139 | 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] | 140 | const u8 *dev_addr, enum p2p_wps_method wps_method, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 141 | int auto_join, int freq, |
| 142 | const u8 *ssid, size_t ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 143 | static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s); |
| 144 | static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s); |
| 145 | static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx); |
| 146 | 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] | 147 | static void wpas_p2p_group_formation_timeout(void *eloop_ctx, |
| 148 | void *timeout_ctx); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 149 | 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] | 150 | static int wpas_p2p_fallback_to_go_neg(struct wpa_supplicant *wpa_s, |
| 151 | int group_added); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 152 | static void wpas_p2p_stop_find_oper(struct wpa_supplicant *wpa_s); |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 153 | static void wpas_stop_listen(void *ctx); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 154 | 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] | 155 | static void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 156 | static int wpas_p2p_add_group_interface(struct wpa_supplicant *wpa_s, |
| 157 | enum wpa_driver_if_type type); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 158 | static void wpas_p2p_group_formation_failed(struct wpa_supplicant *wpa_s, |
| 159 | int already_deleted); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 160 | static void wpas_p2p_optimize_listen_channel(struct wpa_supplicant *wpa_s, |
| 161 | struct wpa_used_freq_data *freqs, |
| 162 | unsigned int num); |
| 163 | static void wpas_p2p_move_go(void *eloop_ctx, void *timeout_ctx); |
| 164 | static int wpas_p2p_go_is_peer_freq(struct wpa_supplicant *wpa_s, int freq); |
| 165 | static void |
| 166 | wpas_p2p_consider_moving_gos(struct wpa_supplicant *wpa_s, |
| 167 | struct wpa_used_freq_data *freqs, unsigned int num, |
| 168 | enum wpas_p2p_channel_update_trig trig); |
| 169 | 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] | 170 | static int wpas_p2p_disallowed_freq(struct wpa_global *global, |
| 171 | unsigned int freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 172 | |
| 173 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 174 | static int wpas_get_6ghz_he_chwidth_capab(struct hostapd_hw_modes *mode) |
| 175 | { |
| 176 | int he_capab = 0; |
| 177 | |
| 178 | if (mode) |
| 179 | he_capab = mode->he_capab[WPAS_MODE_INFRA].phy_cap[ |
| 180 | HE_PHYCAP_CHANNEL_WIDTH_SET_IDX]; |
| 181 | return he_capab; |
| 182 | } |
| 183 | |
| 184 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 185 | /* |
| 186 | * Get the number of concurrent channels that the HW can operate, but that are |
| 187 | * currently not in use by any of the wpa_supplicant interfaces. |
| 188 | */ |
| 189 | static int wpas_p2p_num_unused_channels(struct wpa_supplicant *wpa_s) |
| 190 | { |
| 191 | int *freqs; |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 192 | int num, unused; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 193 | |
| 194 | freqs = os_calloc(wpa_s->num_multichan_concurrent, sizeof(int)); |
| 195 | if (!freqs) |
| 196 | return -1; |
| 197 | |
| 198 | num = get_shared_radio_freqs(wpa_s, freqs, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 199 | wpa_s->num_multichan_concurrent, false); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 200 | os_free(freqs); |
| 201 | |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 202 | unused = wpa_s->num_multichan_concurrent - num; |
| 203 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: num_unused_channels: %d", unused); |
| 204 | return unused; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | |
| 208 | /* |
| 209 | * Get the frequencies that are currently in use by one or more of the virtual |
| 210 | * interfaces, and that are also valid for P2P operation. |
| 211 | */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 212 | static unsigned int |
| 213 | wpas_p2p_valid_oper_freqs(struct wpa_supplicant *wpa_s, |
| 214 | struct wpa_used_freq_data *p2p_freqs, |
| 215 | unsigned int len) |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 216 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 217 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 218 | unsigned int num, i, j; |
| 219 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 220 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 221 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 222 | if (!freqs) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 223 | return 0; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 224 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 225 | num = get_shared_radio_freqs_data(wpa_s, freqs, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 226 | wpa_s->num_multichan_concurrent, |
| 227 | false); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 228 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 229 | os_memset(p2p_freqs, 0, sizeof(struct wpa_used_freq_data) * len); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 230 | |
| 231 | for (i = 0, j = 0; i < num && j < len; i++) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 232 | if (p2p_supported_freq(wpa_s->global->p2p, freqs[i].freq)) |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 233 | p2p_freqs[j++] = freqs[i]; |
| 234 | } |
| 235 | |
| 236 | os_free(freqs); |
| 237 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 238 | dump_freq_data(wpa_s, "valid for P2P", p2p_freqs, j); |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 239 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 240 | return j; |
| 241 | } |
| 242 | |
| 243 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 244 | static void wpas_p2p_set_own_freq_preference(struct wpa_supplicant *wpa_s, |
| 245 | int freq) |
| 246 | { |
| 247 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 248 | return; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 249 | |
| 250 | /* Use the wpa_s used to control the P2P Device operation */ |
| 251 | wpa_s = wpa_s->global->p2p_init_wpa_s; |
| 252 | |
| 253 | if (wpa_s->conf->p2p_ignore_shared_freq && |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 254 | freq > 0 && wpa_s->num_multichan_concurrent > 1 && |
| 255 | wpas_p2p_num_unused_channels(wpa_s) > 0) { |
| 256 | wpa_printf(MSG_DEBUG, "P2P: Ignore own channel preference %d MHz due to p2p_ignore_shared_freq=1 configuration", |
| 257 | freq); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 258 | freq = 0; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 259 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 260 | p2p_set_own_freq_preference(wpa_s->global->p2p, freq); |
| 261 | } |
| 262 | |
| 263 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 264 | static void wpas_p2p_scan_res_handled(struct wpa_supplicant *wpa_s) |
| 265 | { |
| 266 | unsigned int delay = wpas_p2p_search_delay(wpa_s); |
| 267 | |
| 268 | /* In case of concurrent P2P and external scans, delay P2P search. */ |
| 269 | if (external_scan_running(wpa_s->radio)) { |
| 270 | delay = wpa_s->conf->p2p_search_delay; |
| 271 | wpa_printf(MSG_DEBUG, |
| 272 | "P2P: Delay next P2P search by %d ms to let externally triggered scan complete", |
| 273 | delay); |
| 274 | } |
| 275 | |
| 276 | p2p_scan_res_handled(wpa_s->global->p2p, delay); |
| 277 | } |
| 278 | |
| 279 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 280 | static void wpas_p2p_scan_res_handler(struct wpa_supplicant *wpa_s, |
| 281 | struct wpa_scan_results *scan_res) |
| 282 | { |
| 283 | size_t i; |
| 284 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 285 | if (wpa_s->p2p_scan_work) { |
| 286 | struct wpa_radio_work *work = wpa_s->p2p_scan_work; |
| 287 | wpa_s->p2p_scan_work = NULL; |
| 288 | radio_work_done(work); |
| 289 | } |
| 290 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 291 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 292 | return; |
| 293 | |
| 294 | wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS)", |
| 295 | (int) scan_res->num); |
| 296 | |
| 297 | for (i = 0; i < scan_res->num; i++) { |
| 298 | struct wpa_scan_res *bss = scan_res->res[i]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 299 | struct os_reltime time_tmp_age, entry_ts; |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 300 | const u8 *ies; |
| 301 | size_t ies_len; |
| 302 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 303 | time_tmp_age.sec = bss->age / 1000; |
| 304 | time_tmp_age.usec = (bss->age % 1000) * 1000; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 305 | os_reltime_sub(&scan_res->fetch_time, &time_tmp_age, &entry_ts); |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 306 | |
| 307 | ies = (const u8 *) (bss + 1); |
| 308 | ies_len = bss->ie_len; |
| 309 | if (bss->beacon_ie_len > 0 && |
| 310 | !wpa_scan_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) && |
| 311 | wpa_scan_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { |
| 312 | wpa_printf(MSG_DEBUG, "P2P: Use P2P IE(s) from Beacon frame since no P2P IE(s) in Probe Response frames received for " |
| 313 | MACSTR, MAC2STR(bss->bssid)); |
| 314 | ies = ies + ies_len; |
| 315 | ies_len = bss->beacon_ie_len; |
| 316 | } |
| 317 | |
| 318 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 319 | if (p2p_scan_res_handler(wpa_s->global->p2p, bss->bssid, |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 320 | bss->freq, &entry_ts, bss->level, |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 321 | ies, ies_len) > 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 322 | break; |
| 323 | } |
| 324 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 325 | wpas_p2p_scan_res_handled(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 329 | 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] | 330 | { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 331 | if (wpa_s->p2p_scan_work) { |
| 332 | struct wpa_radio_work *work = wpa_s->p2p_scan_work; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 333 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 334 | wpa_s->p2p_scan_work = NULL; |
| 335 | radio_work_done(work); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 338 | if (wpa_s->global->p2p_disabled || !wpa_s->global->p2p) |
| 339 | return; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 340 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 341 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 342 | "P2P: Failed to get scan results - try to continue"); |
| 343 | wpas_p2p_scan_res_handled(wpa_s); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 347 | void wpas_p2p_scan_freqs(struct wpa_supplicant *wpa_s, |
| 348 | struct wpa_driver_scan_params *params, |
| 349 | bool include_6ghz) |
| 350 | { |
| 351 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, |
| 352 | params, false, false, false); |
| 353 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211G, |
| 354 | params, false, false, false); |
| 355 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211AD, |
| 356 | params, false, false, false); |
| 357 | if (!wpa_s->conf->p2p_6ghz_disable && |
| 358 | is_p2p_allow_6ghz(wpa_s->global->p2p) && include_6ghz) |
| 359 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, |
| 360 | params, true, true, false); |
| 361 | } |
| 362 | |
| 363 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 364 | static void wpas_p2p_trigger_scan_cb(struct wpa_radio_work *work, int deinit) |
| 365 | { |
| 366 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 367 | struct wpa_driver_scan_params *params = work->ctx; |
| 368 | int ret; |
| 369 | |
| 370 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 371 | if (!work->started) { |
| 372 | wpa_scan_free_params(params); |
| 373 | return; |
| 374 | } |
| 375 | |
| 376 | wpa_s->p2p_scan_work = NULL; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 377 | return; |
| 378 | } |
| 379 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 380 | if (wpa_s->clear_driver_scan_cache) { |
| 381 | wpa_printf(MSG_DEBUG, |
| 382 | "Request driver to clear scan cache due to local BSS flush"); |
| 383 | params->only_new_results = 1; |
| 384 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 385 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 386 | if (!params->freqs) |
| 387 | wpas_p2p_scan_freqs(wpa_s, params, params->p2p_include_6ghz); |
| 388 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 389 | ret = wpa_drv_scan(wpa_s, params); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 390 | if (ret == 0) |
| 391 | wpa_s->curr_scan_cookie = params->scan_cookie; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 392 | wpa_scan_free_params(params); |
| 393 | work->ctx = NULL; |
| 394 | if (ret) { |
| 395 | radio_work_done(work); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 396 | p2p_notify_scan_trigger_status(wpa_s->global->p2p, ret); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 397 | return; |
| 398 | } |
| 399 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 400 | p2p_notify_scan_trigger_status(wpa_s->global->p2p, ret); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 401 | os_get_reltime(&wpa_s->scan_trigger_time); |
| 402 | wpa_s->scan_res_handler = wpas_p2p_scan_res_handler; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 403 | wpa_s->scan_res_fail_handler = wpas_p2p_scan_res_fail_handler; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 404 | wpa_s->own_scan_requested = 1; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 405 | wpa_s->clear_driver_scan_cache = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 406 | wpa_s->p2p_scan_work = work; |
| 407 | } |
| 408 | |
| 409 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 410 | static int wpas_p2p_search_social_channel(struct wpa_supplicant *wpa_s, |
| 411 | int freq) |
| 412 | { |
| 413 | if (wpa_s->global->p2p_24ghz_social_channels && |
| 414 | (freq == 2412 || freq == 2437 || freq == 2462)) { |
| 415 | /* |
| 416 | * Search all social channels regardless of whether these have |
| 417 | * been disabled for P2P operating channel use to avoid missing |
| 418 | * peers. |
| 419 | */ |
| 420 | return 1; |
| 421 | } |
| 422 | return p2p_supported_freq(wpa_s->global->p2p, freq); |
| 423 | } |
| 424 | |
| 425 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 426 | static int wpas_p2p_scan(void *ctx, enum p2p_scan_type type, int freq, |
| 427 | unsigned int num_req_dev_types, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 428 | const u8 *req_dev_types, const u8 *dev_id, u16 pw_id, |
| 429 | bool include_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 430 | { |
| 431 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 432 | struct wpa_driver_scan_params *params = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 433 | struct wpabuf *wps_ie, *ies; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 434 | unsigned int num_channels = 0; |
| 435 | int social_channels_freq[] = { 2412, 2437, 2462, 60480 }; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 436 | size_t ielen; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 437 | u8 *n, i; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 438 | unsigned int bands; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 439 | |
| 440 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 441 | return -1; |
| 442 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 443 | if (wpa_s->p2p_scan_work) { |
| 444 | wpa_dbg(wpa_s, MSG_INFO, "P2P: Reject scan trigger since one is already pending"); |
| 445 | return -1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 448 | params = os_zalloc(sizeof(*params)); |
| 449 | if (params == NULL) |
| 450 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 451 | |
| 452 | /* P2P Wildcard SSID */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 453 | params->num_ssids = 1; |
| 454 | n = os_malloc(P2P_WILDCARD_SSID_LEN); |
| 455 | if (n == NULL) |
| 456 | goto fail; |
| 457 | os_memcpy(n, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN); |
| 458 | params->ssids[0].ssid = n; |
| 459 | params->ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 460 | |
| 461 | wpa_s->wps->dev.p2p = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 462 | wps_ie = wps_build_probe_req_ie(pw_id, &wpa_s->wps->dev, |
| 463 | wpa_s->wps->uuid, WPS_REQ_ENROLLEE, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 464 | num_req_dev_types, req_dev_types); |
| 465 | if (wps_ie == NULL) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 466 | goto fail; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 467 | |
| 468 | /* |
| 469 | * In case 6 GHz channels are requested as part of the P2P scan, only |
| 470 | * the PSCs would be included as P2P GOs are not expected to be |
| 471 | * collocated, i.e., they would not be announced in the RNR element of |
| 472 | * other APs. |
| 473 | */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 474 | if (!wpa_s->conf->p2p_6ghz_disable) |
| 475 | params->p2p_include_6ghz = include_6ghz; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 476 | switch (type) { |
| 477 | case P2P_SCAN_SOCIAL: |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 478 | params->freqs = os_calloc(ARRAY_SIZE(social_channels_freq) + 1, |
| 479 | sizeof(int)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 480 | if (params->freqs == NULL) |
| 481 | goto fail; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 482 | for (i = 0; i < ARRAY_SIZE(social_channels_freq); i++) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 483 | if (wpas_p2p_search_social_channel( |
| 484 | wpa_s, social_channels_freq[i])) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 485 | params->freqs[num_channels++] = |
| 486 | social_channels_freq[i]; |
| 487 | } |
| 488 | params->freqs[num_channels++] = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 489 | break; |
| 490 | case P2P_SCAN_FULL: |
| 491 | break; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 492 | case P2P_SCAN_SPECIFIC: |
| 493 | params->freqs = os_calloc(2, sizeof(int)); |
| 494 | if (params->freqs == NULL) |
| 495 | goto fail; |
| 496 | params->freqs[0] = freq; |
| 497 | params->freqs[1] = 0; |
| 498 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 499 | case P2P_SCAN_SOCIAL_PLUS_ONE: |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 500 | params->freqs = os_calloc(ARRAY_SIZE(social_channels_freq) + 2, |
| 501 | sizeof(int)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 502 | if (params->freqs == NULL) |
| 503 | goto fail; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 504 | for (i = 0; i < ARRAY_SIZE(social_channels_freq); i++) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 505 | if (wpas_p2p_search_social_channel( |
| 506 | wpa_s, social_channels_freq[i])) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 507 | params->freqs[num_channels++] = |
| 508 | social_channels_freq[i]; |
| 509 | } |
| 510 | if (p2p_supported_freq(wpa_s->global->p2p, freq)) |
| 511 | params->freqs[num_channels++] = freq; |
| 512 | params->freqs[num_channels++] = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 513 | break; |
| 514 | } |
| 515 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 516 | ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p); |
| 517 | ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen); |
| 518 | if (ies == NULL) { |
| 519 | wpabuf_free(wps_ie); |
| 520 | goto fail; |
| 521 | } |
| 522 | wpabuf_put_buf(ies, wps_ie); |
| 523 | wpabuf_free(wps_ie); |
| 524 | |
| 525 | bands = wpas_get_bands(wpa_s, params->freqs); |
| 526 | p2p_scan_ie(wpa_s->global->p2p, ies, dev_id, bands); |
| 527 | |
| 528 | params->p2p_probe = 1; |
| 529 | n = os_malloc(wpabuf_len(ies)); |
| 530 | if (n == NULL) { |
| 531 | wpabuf_free(ies); |
| 532 | goto fail; |
| 533 | } |
| 534 | os_memcpy(n, wpabuf_head(ies), wpabuf_len(ies)); |
| 535 | params->extra_ies = n; |
| 536 | params->extra_ies_len = wpabuf_len(ies); |
| 537 | wpabuf_free(ies); |
| 538 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 539 | radio_remove_works(wpa_s, "p2p-scan", 0); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 540 | if (radio_add_work(wpa_s, 0, "p2p-scan", 0, wpas_p2p_trigger_scan_cb, |
| 541 | params) < 0) |
| 542 | goto fail; |
| 543 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 544 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 545 | fail: |
| 546 | wpa_scan_free_params(params); |
| 547 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 551 | static enum wpa_driver_if_type wpas_p2p_if_type(int p2p_group_interface) |
| 552 | { |
| 553 | switch (p2p_group_interface) { |
| 554 | case P2P_GROUP_INTERFACE_PENDING: |
| 555 | return WPA_IF_P2P_GROUP; |
| 556 | case P2P_GROUP_INTERFACE_GO: |
| 557 | return WPA_IF_P2P_GO; |
| 558 | case P2P_GROUP_INTERFACE_CLIENT: |
| 559 | return WPA_IF_P2P_CLIENT; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 560 | default: |
| 561 | return WPA_IF_P2P_GROUP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 562 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | |
| 566 | static struct wpa_supplicant * wpas_get_p2p_group(struct wpa_supplicant *wpa_s, |
| 567 | const u8 *ssid, |
| 568 | size_t ssid_len, int *go) |
| 569 | { |
| 570 | struct wpa_ssid *s; |
| 571 | |
| 572 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 573 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 574 | if (s->disabled != 0 || !s->p2p_group || |
| 575 | s->ssid_len != ssid_len || |
| 576 | os_memcmp(ssid, s->ssid, ssid_len) != 0) |
| 577 | continue; |
| 578 | if (s->mode == WPAS_MODE_P2P_GO && |
| 579 | s != wpa_s->current_ssid) |
| 580 | continue; |
| 581 | if (go) |
| 582 | *go = s->mode == WPAS_MODE_P2P_GO; |
| 583 | return wpa_s; |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | return NULL; |
| 588 | } |
| 589 | |
| 590 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 591 | static void run_wpas_p2p_disconnect(void *eloop_ctx, void *timeout_ctx) |
| 592 | { |
| 593 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 594 | wpa_printf(MSG_DEBUG, |
| 595 | "P2P: Complete previously requested removal of %s", |
| 596 | wpa_s->ifname); |
| 597 | wpas_p2p_disconnect(wpa_s); |
| 598 | } |
| 599 | |
| 600 | |
| 601 | static int wpas_p2p_disconnect_safely(struct wpa_supplicant *wpa_s, |
| 602 | struct wpa_supplicant *calling_wpa_s) |
| 603 | { |
| 604 | if (calling_wpa_s == wpa_s && wpa_s && |
| 605 | wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) { |
| 606 | /* |
| 607 | * The calling wpa_s instance is going to be removed. Do that |
| 608 | * from an eloop callback to keep the instance available until |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 609 | * the caller has returned. This may be needed, e.g., to provide |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 610 | * control interface responses on the per-interface socket. |
| 611 | */ |
| 612 | if (eloop_register_timeout(0, 0, run_wpas_p2p_disconnect, |
| 613 | wpa_s, NULL) < 0) |
| 614 | return -1; |
| 615 | return 0; |
| 616 | } |
| 617 | |
| 618 | return wpas_p2p_disconnect(wpa_s); |
| 619 | } |
| 620 | |
| 621 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 622 | /* Determine total number of clients in active groups where we are the GO */ |
| 623 | static unsigned int p2p_group_go_member_count(struct wpa_supplicant *wpa_s) |
| 624 | { |
| 625 | unsigned int count = 0; |
| 626 | struct wpa_ssid *s; |
| 627 | |
| 628 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 629 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 630 | wpa_printf(MSG_DEBUG, |
| 631 | "P2P: sup:%p ssid:%p disabled:%d p2p:%d mode:%d", |
| 632 | wpa_s, s, s->disabled, s->p2p_group, |
| 633 | s->mode); |
| 634 | if (!s->disabled && s->p2p_group && |
| 635 | s->mode == WPAS_MODE_P2P_GO) { |
| 636 | count += p2p_get_group_num_members( |
| 637 | wpa_s->p2p_group); |
| 638 | } |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | return count; |
| 643 | } |
| 644 | |
| 645 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 646 | static unsigned int p2p_is_active_persistent_group(struct wpa_supplicant *wpa_s) |
| 647 | { |
| 648 | return !wpa_s->p2p_mgmt && wpa_s->current_ssid && |
| 649 | !wpa_s->current_ssid->disabled && |
| 650 | wpa_s->current_ssid->p2p_group && |
| 651 | wpa_s->current_ssid->p2p_persistent_group; |
| 652 | } |
| 653 | |
| 654 | |
| 655 | static unsigned int p2p_is_active_persistent_go(struct wpa_supplicant *wpa_s) |
| 656 | { |
| 657 | return p2p_is_active_persistent_group(wpa_s) && |
| 658 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO; |
| 659 | } |
| 660 | |
| 661 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 662 | /* Find an interface for a P2P group where we are the GO */ |
| 663 | static struct wpa_supplicant * |
| 664 | wpas_p2p_get_go_group(struct wpa_supplicant *wpa_s) |
| 665 | { |
| 666 | struct wpa_supplicant *save = NULL; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 667 | |
| 668 | if (!wpa_s) |
| 669 | return NULL; |
| 670 | |
| 671 | 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] | 672 | if (!p2p_is_active_persistent_go(wpa_s)) |
| 673 | continue; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 674 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 675 | /* Prefer a group with connected clients */ |
| 676 | if (p2p_get_group_num_members(wpa_s->p2p_group)) |
| 677 | return wpa_s; |
| 678 | save = wpa_s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | /* No group with connected clients, so pick the one without (if any) */ |
| 682 | return save; |
| 683 | } |
| 684 | |
| 685 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 686 | 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] | 687 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 688 | return p2p_is_active_persistent_group(wpa_s) && |
| 689 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA; |
| 690 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 691 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 692 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 693 | /* Find an interface for a P2P group where we are the P2P Client */ |
| 694 | static struct wpa_supplicant * |
| 695 | wpas_p2p_get_cli_group(struct wpa_supplicant *wpa_s) |
| 696 | { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 697 | 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] | 698 | if (p2p_is_active_persistent_cli(wpa_s)) |
| 699 | return wpa_s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 700 | } |
| 701 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 702 | return NULL; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | |
| 706 | /* Find a persistent group where we are the GO */ |
| 707 | static struct wpa_ssid * |
| 708 | wpas_p2p_get_persistent_go(struct wpa_supplicant *wpa_s) |
| 709 | { |
| 710 | struct wpa_ssid *s; |
| 711 | |
| 712 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 713 | if (s->disabled == 2 && s->mode == WPAS_MODE_P2P_GO) |
| 714 | return s; |
| 715 | } |
| 716 | |
| 717 | return NULL; |
| 718 | } |
| 719 | |
| 720 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 721 | static u8 p2ps_group_capability(void *ctx, u8 incoming, u8 role, |
| 722 | unsigned int *force_freq, |
| 723 | unsigned int *pref_freq) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 724 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 725 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 726 | struct wpa_ssid *s; |
| 727 | u8 conncap = P2PS_SETUP_NONE; |
| 728 | unsigned int owned_members = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 729 | struct wpa_supplicant *go_wpa_s, *cli_wpa_s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 730 | struct wpa_ssid *persistent_go; |
| 731 | int p2p_no_group_iface; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 732 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 733 | unsigned int size; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 734 | |
| 735 | wpa_printf(MSG_DEBUG, "P2P: Conncap - in:%d role:%d", incoming, role); |
| 736 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 737 | if (force_freq) |
| 738 | *force_freq = 0; |
| 739 | if (pref_freq) |
| 740 | *pref_freq = 0; |
| 741 | |
| 742 | size = P2P_MAX_PREF_CHANNELS; |
| 743 | if (force_freq && pref_freq && |
| 744 | !wpas_p2p_setup_freqs(wpa_s, 0, (int *) force_freq, |
| 745 | (int *) pref_freq, 0, pref_freq_list, &size)) |
| 746 | wpas_p2p_set_own_freq_preference(wpa_s, |
| 747 | *force_freq ? *force_freq : |
| 748 | *pref_freq); |
| 749 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 750 | /* |
| 751 | * For non-concurrent capable devices: |
| 752 | * If persistent_go, then no new. |
| 753 | * If GO, then no client. |
| 754 | * If client, then no GO. |
| 755 | */ |
| 756 | go_wpa_s = wpas_p2p_get_go_group(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 757 | if (go_wpa_s) |
| 758 | owned_members = p2p_get_group_num_members(go_wpa_s->p2p_group); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 759 | persistent_go = wpas_p2p_get_persistent_go(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 760 | p2p_no_group_iface = !wpas_p2p_create_iface(wpa_s); |
| 761 | cli_wpa_s = wpas_p2p_get_cli_group(wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 762 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 763 | wpa_printf(MSG_DEBUG, |
| 764 | "P2P: GO(iface)=%p members=%u CLI(iface)=%p persistent(ssid)=%p", |
| 765 | go_wpa_s, owned_members, cli_wpa_s, persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 766 | |
| 767 | /* If not concurrent, restrict our choices */ |
| 768 | if (p2p_no_group_iface) { |
| 769 | wpa_printf(MSG_DEBUG, "P2P: p2p_no_group_iface"); |
| 770 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 771 | if (cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 772 | return P2PS_SETUP_NONE; |
| 773 | |
| 774 | if (go_wpa_s) { |
| 775 | if (role == P2PS_SETUP_CLIENT || |
| 776 | incoming == P2PS_SETUP_GROUP_OWNER || |
| 777 | p2p_client_limit_reached(go_wpa_s->p2p_group)) |
| 778 | return P2PS_SETUP_NONE; |
| 779 | |
| 780 | return P2PS_SETUP_GROUP_OWNER; |
| 781 | } |
| 782 | |
| 783 | if (persistent_go) { |
| 784 | if (role == P2PS_SETUP_NONE || role == P2PS_SETUP_NEW) { |
| 785 | if (!incoming) |
| 786 | return P2PS_SETUP_GROUP_OWNER | |
| 787 | P2PS_SETUP_CLIENT; |
| 788 | if (incoming == P2PS_SETUP_NEW) { |
| 789 | u8 r; |
| 790 | |
| 791 | if (os_get_random(&r, sizeof(r)) < 0 || |
| 792 | (r & 1)) |
| 793 | return P2PS_SETUP_CLIENT; |
| 794 | return P2PS_SETUP_GROUP_OWNER; |
| 795 | } |
| 796 | } |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | /* If a required role has been specified, handle it here */ |
| 801 | if (role && role != P2PS_SETUP_NEW) { |
| 802 | switch (incoming) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 803 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_NEW: |
| 804 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT: |
| 805 | /* |
| 806 | * Peer has an active GO, so if the role allows it and |
| 807 | * we do not have any active roles, become client. |
| 808 | */ |
| 809 | if ((role & P2PS_SETUP_CLIENT) && !go_wpa_s && |
| 810 | !cli_wpa_s) |
| 811 | return P2PS_SETUP_CLIENT; |
| 812 | |
| 813 | /* fall through */ |
| 814 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 815 | case P2PS_SETUP_NONE: |
| 816 | case P2PS_SETUP_NEW: |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 817 | conncap = role; |
| 818 | goto grp_owner; |
| 819 | |
| 820 | case P2PS_SETUP_GROUP_OWNER: |
| 821 | /* |
| 822 | * Must be a complimentary role - cannot be a client to |
| 823 | * more than one peer. |
| 824 | */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 825 | if (incoming == role || cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 826 | return P2PS_SETUP_NONE; |
| 827 | |
| 828 | return P2PS_SETUP_CLIENT; |
| 829 | |
| 830 | case P2PS_SETUP_CLIENT: |
| 831 | /* Must be a complimentary role */ |
| 832 | if (incoming != role) { |
| 833 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 834 | goto grp_owner; |
| 835 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 836 | /* fall through */ |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 837 | |
| 838 | default: |
| 839 | return P2PS_SETUP_NONE; |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | /* |
| 844 | * For now, we only will support ownership of one group, and being a |
| 845 | * client of one group. Therefore, if we have either an existing GO |
| 846 | * group, or an existing client group, we will not do a new GO |
| 847 | * negotiation, but rather try to re-use the existing groups. |
| 848 | */ |
| 849 | switch (incoming) { |
| 850 | case P2PS_SETUP_NONE: |
| 851 | case P2PS_SETUP_NEW: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 852 | if (cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 853 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 854 | else if (!owned_members) |
| 855 | conncap = P2PS_SETUP_NEW; |
| 856 | else if (incoming == P2PS_SETUP_NONE) |
| 857 | conncap = P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT; |
| 858 | else |
| 859 | conncap = P2PS_SETUP_CLIENT; |
| 860 | break; |
| 861 | |
| 862 | case P2PS_SETUP_CLIENT: |
| 863 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 864 | break; |
| 865 | |
| 866 | case P2PS_SETUP_GROUP_OWNER: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 867 | if (!cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 868 | conncap = P2PS_SETUP_CLIENT; |
| 869 | break; |
| 870 | |
| 871 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_NEW: |
| 872 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 873 | if (cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 874 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 875 | else { |
| 876 | u8 r; |
| 877 | |
| 878 | if (os_get_random(&r, sizeof(r)) < 0 || |
| 879 | (r & 1)) |
| 880 | conncap = P2PS_SETUP_CLIENT; |
| 881 | else |
| 882 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 883 | } |
| 884 | break; |
| 885 | |
| 886 | default: |
| 887 | return P2PS_SETUP_NONE; |
| 888 | } |
| 889 | |
| 890 | grp_owner: |
| 891 | if ((conncap & P2PS_SETUP_GROUP_OWNER) || |
| 892 | (!incoming && (conncap & P2PS_SETUP_NEW))) { |
| 893 | if (go_wpa_s && p2p_client_limit_reached(go_wpa_s->p2p_group)) |
| 894 | conncap &= ~P2PS_SETUP_GROUP_OWNER; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 895 | |
| 896 | s = wpas_p2p_get_persistent_go(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 897 | if (!s && !go_wpa_s && p2p_no_group_iface) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 898 | p2p_set_intended_addr(wpa_s->global->p2p, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 899 | wpa_s->p2p_mgmt ? |
| 900 | wpa_s->parent->own_addr : |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 901 | wpa_s->own_addr); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 902 | } else if (!s && !go_wpa_s) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 903 | if (wpas_p2p_add_group_interface(wpa_s, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 904 | WPA_IF_P2P_GROUP) < 0) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 905 | wpa_printf(MSG_ERROR, |
| 906 | "P2P: Failed to allocate a new interface for the group"); |
| 907 | return P2PS_SETUP_NONE; |
| 908 | } |
| 909 | wpa_s->global->pending_group_iface_for_p2ps = 1; |
| 910 | p2p_set_intended_addr(wpa_s->global->p2p, |
| 911 | wpa_s->pending_interface_addr); |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | return conncap; |
| 916 | } |
| 917 | |
| 918 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 919 | static int wpas_p2p_group_delete(struct wpa_supplicant *wpa_s, |
| 920 | enum p2p_group_removal_reason removal_reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 921 | { |
| 922 | struct wpa_ssid *ssid; |
| 923 | char *gtype; |
| 924 | const char *reason; |
| 925 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 926 | ssid = wpa_s->current_ssid; |
| 927 | if (ssid == NULL) { |
| 928 | /* |
| 929 | * The current SSID was not known, but there may still be a |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 930 | * pending P2P group interface waiting for provisioning or a |
| 931 | * P2P group that is trying to reconnect. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 932 | */ |
| 933 | ssid = wpa_s->conf->ssid; |
| 934 | while (ssid) { |
Jouni Malinen | 9d71283 | 2012-10-05 11:01:57 -0700 | [diff] [blame] | 935 | if (ssid->p2p_group && ssid->disabled != 2) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 936 | break; |
| 937 | ssid = ssid->next; |
| 938 | } |
Jouni Malinen | 5c44edb | 2012-08-31 21:35:32 +0300 | [diff] [blame] | 939 | if (ssid == NULL && |
| 940 | wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE) |
| 941 | { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 942 | wpa_printf(MSG_ERROR, "P2P: P2P group interface " |
| 943 | "not found"); |
| 944 | return -1; |
| 945 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 946 | } |
| 947 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO) |
| 948 | gtype = "GO"; |
| 949 | else if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT || |
| 950 | (ssid && ssid->mode == WPAS_MODE_INFRA)) { |
| 951 | wpa_s->reassociate = 0; |
| 952 | wpa_s->disconnected = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 953 | gtype = "client"; |
| 954 | } else |
| 955 | gtype = "GO"; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 956 | |
| 957 | if (removal_reason != P2P_GROUP_REMOVAL_SILENT && ssid) |
| 958 | wpas_notify_p2p_group_removed(wpa_s, ssid, gtype); |
| 959 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 960 | if (os_strcmp(gtype, "client") == 0) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 961 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 962 | if (eloop_is_timeout_registered(wpas_p2p_psk_failure_removal, |
| 963 | wpa_s, NULL)) { |
| 964 | wpa_printf(MSG_DEBUG, |
| 965 | "P2P: PSK failure removal was scheduled, so use PSK failure as reason for group removal"); |
| 966 | removal_reason = P2P_GROUP_REMOVAL_PSK_FAILURE; |
| 967 | eloop_cancel_timeout(wpas_p2p_psk_failure_removal, |
| 968 | wpa_s, NULL); |
| 969 | } |
| 970 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 971 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 972 | if (wpa_s->cross_connect_in_use) { |
| 973 | wpa_s->cross_connect_in_use = 0; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 974 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 975 | P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s", |
| 976 | wpa_s->ifname, wpa_s->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 977 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 978 | switch (removal_reason) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 979 | case P2P_GROUP_REMOVAL_REQUESTED: |
| 980 | reason = " reason=REQUESTED"; |
| 981 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 982 | case P2P_GROUP_REMOVAL_FORMATION_FAILED: |
| 983 | reason = " reason=FORMATION_FAILED"; |
| 984 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 985 | case P2P_GROUP_REMOVAL_IDLE_TIMEOUT: |
| 986 | reason = " reason=IDLE"; |
| 987 | break; |
| 988 | case P2P_GROUP_REMOVAL_UNAVAILABLE: |
| 989 | reason = " reason=UNAVAILABLE"; |
| 990 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 991 | case P2P_GROUP_REMOVAL_GO_ENDING_SESSION: |
| 992 | reason = " reason=GO_ENDING_SESSION"; |
| 993 | break; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 994 | case P2P_GROUP_REMOVAL_PSK_FAILURE: |
| 995 | reason = " reason=PSK_FAILURE"; |
| 996 | break; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 997 | case P2P_GROUP_REMOVAL_FREQ_CONFLICT: |
| 998 | reason = " reason=FREQ_CONFLICT"; |
| 999 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1000 | default: |
| 1001 | reason = ""; |
| 1002 | break; |
| 1003 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1004 | if (removal_reason != P2P_GROUP_REMOVAL_SILENT) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1005 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1006 | P2P_EVENT_GROUP_REMOVED "%s %s%s", |
| 1007 | wpa_s->ifname, gtype, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1008 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1009 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1010 | if (eloop_cancel_timeout(wpas_p2p_group_freq_conflict, wpa_s, NULL) > 0) |
| 1011 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group freq_conflict timeout"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1012 | if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0) |
| 1013 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1014 | if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1015 | wpa_s->p2pdev, NULL) > 0) { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1016 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group formation " |
| 1017 | "timeout"); |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 1018 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1019 | wpas_p2p_group_formation_failed(wpa_s, 1); |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 1020 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1021 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 1022 | wpa_s->p2p_in_invitation = 0; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 1023 | wpa_s->p2p_retry_limit = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1024 | eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL); |
| 1025 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, wpa_s, NULL); |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 1026 | |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1027 | /* |
| 1028 | * Make sure wait for the first client does not remain active after the |
| 1029 | * group has been removed. |
| 1030 | */ |
| 1031 | wpa_s->global->p2p_go_wait_client.sec = 0; |
| 1032 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1033 | if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) { |
| 1034 | struct wpa_global *global; |
| 1035 | char *ifname; |
| 1036 | enum wpa_driver_if_type type; |
| 1037 | wpa_printf(MSG_DEBUG, "P2P: Remove group interface %s", |
| 1038 | wpa_s->ifname); |
| 1039 | global = wpa_s->global; |
| 1040 | ifname = os_strdup(wpa_s->ifname); |
| 1041 | type = wpas_p2p_if_type(wpa_s->p2p_group_interface); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1042 | eloop_cancel_timeout(run_wpas_p2p_disconnect, wpa_s, NULL); |
Dmitry Shmidt | e15c7b5 | 2011-08-03 15:04:35 -0700 | [diff] [blame] | 1043 | wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1044 | wpa_s = global->ifaces; |
| 1045 | if (wpa_s && ifname) |
| 1046 | wpa_drv_if_remove(wpa_s, type, ifname); |
| 1047 | os_free(ifname); |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 1048 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1051 | /* |
| 1052 | * The primary interface was used for P2P group operations, so |
| 1053 | * need to reset its p2pdev. |
| 1054 | */ |
| 1055 | wpa_s->p2pdev = wpa_s->parent; |
| 1056 | |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1057 | if (!wpa_s->p2p_go_group_formation_completed) { |
| 1058 | wpa_s->global->p2p_group_formation = NULL; |
| 1059 | wpa_s->p2p_in_provisioning = 0; |
| 1060 | } |
| 1061 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1062 | wpa_s->show_group_started = 0; |
| 1063 | os_free(wpa_s->go_params); |
| 1064 | wpa_s->go_params = NULL; |
| 1065 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1066 | os_free(wpa_s->p2p_group_common_freqs); |
| 1067 | wpa_s->p2p_group_common_freqs = NULL; |
| 1068 | wpa_s->p2p_group_common_freqs_num = 0; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1069 | wpa_s->p2p_go_do_acs = 0; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1070 | wpa_s->p2p_go_allow_dfs = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1071 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1072 | wpa_s->waiting_presence_resp = 0; |
| 1073 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1074 | wpa_printf(MSG_DEBUG, "P2P: Remove temporary group network"); |
| 1075 | if (ssid && (ssid->p2p_group || |
| 1076 | ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION || |
| 1077 | (ssid->key_mgmt & WPA_KEY_MGMT_WPS))) { |
| 1078 | int id = ssid->id; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1079 | if (ssid == wpa_s->current_ssid) { |
| 1080 | wpa_sm_set_config(wpa_s->wpa, NULL); |
| 1081 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1082 | wpa_s->current_ssid = NULL; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1083 | } |
| 1084 | /* |
| 1085 | * Networks objects created during any P2P activities are not |
| 1086 | * exposed out as they might/will confuse certain non-P2P aware |
| 1087 | * applications since these network objects won't behave like |
| 1088 | * regular ones. |
| 1089 | * |
| 1090 | * Likewise, we don't send out network removed signals for such |
| 1091 | * network objects. |
| 1092 | */ |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1093 | wpas_notify_network_removed(wpa_s, ssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1094 | wpa_config_remove_network(wpa_s->conf, id); |
| 1095 | wpa_supplicant_clear_status(wpa_s); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1096 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1097 | } else { |
| 1098 | wpa_printf(MSG_DEBUG, "P2P: Temporary group network not " |
| 1099 | "found"); |
| 1100 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1101 | if (wpa_s->ap_iface) |
| 1102 | wpa_supplicant_ap_deinit(wpa_s); |
| 1103 | else |
| 1104 | wpa_drv_deinit_p2p_cli(wpa_s); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1105 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1106 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
| 1107 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1108 | wpa_s->p2p_go_no_pri_sec_switch = 0; |
| 1109 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1110 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | |
| 1114 | static int wpas_p2p_persistent_group(struct wpa_supplicant *wpa_s, |
| 1115 | u8 *go_dev_addr, |
| 1116 | const u8 *ssid, size_t ssid_len) |
| 1117 | { |
| 1118 | struct wpa_bss *bss; |
| 1119 | const u8 *bssid; |
| 1120 | struct wpabuf *p2p; |
| 1121 | u8 group_capab; |
| 1122 | const u8 *addr; |
| 1123 | |
| 1124 | if (wpa_s->go_params) |
| 1125 | bssid = wpa_s->go_params->peer_interface_addr; |
| 1126 | else |
| 1127 | bssid = wpa_s->bssid; |
| 1128 | |
| 1129 | bss = wpa_bss_get(wpa_s, bssid, ssid, ssid_len); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1130 | if (bss == NULL && wpa_s->go_params && |
| 1131 | !is_zero_ether_addr(wpa_s->go_params->peer_device_addr)) |
| 1132 | bss = wpa_bss_get_p2p_dev_addr( |
| 1133 | wpa_s, wpa_s->go_params->peer_device_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1134 | if (bss == NULL) { |
| 1135 | u8 iface_addr[ETH_ALEN]; |
| 1136 | if (p2p_get_interface_addr(wpa_s->global->p2p, bssid, |
| 1137 | iface_addr) == 0) |
| 1138 | bss = wpa_bss_get(wpa_s, iface_addr, ssid, ssid_len); |
| 1139 | } |
| 1140 | if (bss == NULL) { |
| 1141 | wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether " |
| 1142 | "group is persistent - BSS " MACSTR " not found", |
| 1143 | MAC2STR(bssid)); |
| 1144 | return 0; |
| 1145 | } |
| 1146 | |
| 1147 | p2p = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE); |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1148 | if (p2p == NULL) |
| 1149 | p2p = wpa_bss_get_vendor_ie_multi_beacon(bss, |
| 1150 | P2P_IE_VENDOR_TYPE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1151 | if (p2p == NULL) { |
| 1152 | wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether " |
| 1153 | "group is persistent - BSS " MACSTR |
| 1154 | " did not include P2P IE", MAC2STR(bssid)); |
| 1155 | wpa_hexdump(MSG_DEBUG, "P2P: Probe Response IEs", |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1156 | wpa_bss_ie_ptr(bss), bss->ie_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1157 | wpa_hexdump(MSG_DEBUG, "P2P: Beacon IEs", |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1158 | wpa_bss_ie_ptr(bss) + bss->ie_len, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1159 | bss->beacon_ie_len); |
| 1160 | return 0; |
| 1161 | } |
| 1162 | |
| 1163 | group_capab = p2p_get_group_capab(p2p); |
| 1164 | addr = p2p_get_go_dev_addr(p2p); |
| 1165 | wpa_printf(MSG_DEBUG, "P2P: Checking whether group is persistent: " |
| 1166 | "group_capab=0x%x", group_capab); |
| 1167 | if (addr) { |
| 1168 | os_memcpy(go_dev_addr, addr, ETH_ALEN); |
| 1169 | wpa_printf(MSG_DEBUG, "P2P: GO Device Address " MACSTR, |
| 1170 | MAC2STR(addr)); |
| 1171 | } else |
| 1172 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 1173 | wpabuf_free(p2p); |
| 1174 | |
| 1175 | wpa_printf(MSG_DEBUG, "P2P: BSS " MACSTR " group_capab=0x%x " |
| 1176 | "go_dev_addr=" MACSTR, |
| 1177 | MAC2STR(bssid), group_capab, MAC2STR(go_dev_addr)); |
| 1178 | |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 1179 | return !!(group_capab & P2P_GROUP_CAPAB_PERSISTENT_GROUP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1183 | static int wpas_p2p_store_persistent_group(struct wpa_supplicant *wpa_s, |
| 1184 | struct wpa_ssid *ssid, |
| 1185 | const u8 *go_dev_addr) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1186 | { |
| 1187 | struct wpa_ssid *s; |
| 1188 | int changed = 0; |
| 1189 | |
| 1190 | wpa_printf(MSG_DEBUG, "P2P: Storing credentials for a persistent " |
| 1191 | "group (GO Dev Addr " MACSTR ")", MAC2STR(go_dev_addr)); |
| 1192 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 1193 | if (s->disabled == 2 && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1194 | ether_addr_equal(go_dev_addr, s->bssid) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1195 | s->ssid_len == ssid->ssid_len && |
| 1196 | os_memcmp(ssid->ssid, s->ssid, ssid->ssid_len) == 0) |
| 1197 | break; |
| 1198 | } |
| 1199 | |
| 1200 | if (s) { |
| 1201 | wpa_printf(MSG_DEBUG, "P2P: Update existing persistent group " |
| 1202 | "entry"); |
| 1203 | if (ssid->passphrase && !s->passphrase) |
| 1204 | changed = 1; |
| 1205 | else if (ssid->passphrase && s->passphrase && |
| 1206 | os_strcmp(ssid->passphrase, s->passphrase) != 0) |
| 1207 | changed = 1; |
| 1208 | } else { |
| 1209 | wpa_printf(MSG_DEBUG, "P2P: Create a new persistent group " |
| 1210 | "entry"); |
| 1211 | changed = 1; |
| 1212 | s = wpa_config_add_network(wpa_s->conf); |
| 1213 | if (s == NULL) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1214 | return -1; |
| 1215 | |
| 1216 | /* |
| 1217 | * Instead of network_added we emit persistent_group_added |
| 1218 | * notification. Also to keep the defense checks in |
| 1219 | * persistent_group obj registration method, we set the |
| 1220 | * relevant flags in s to designate it as a persistent group. |
| 1221 | */ |
| 1222 | s->p2p_group = 1; |
| 1223 | s->p2p_persistent_group = 1; |
| 1224 | wpas_notify_persistent_group_added(wpa_s, s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1225 | wpa_config_set_network_defaults(s); |
| 1226 | } |
| 1227 | |
| 1228 | s->p2p_group = 1; |
| 1229 | s->p2p_persistent_group = 1; |
| 1230 | s->disabled = 2; |
| 1231 | s->bssid_set = 1; |
| 1232 | os_memcpy(s->bssid, go_dev_addr, ETH_ALEN); |
| 1233 | s->mode = ssid->mode; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 1234 | s->auth_alg = ssid->auth_alg; |
| 1235 | s->key_mgmt = ssid->key_mgmt; |
| 1236 | s->proto = ssid->proto; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1237 | s->pbss = ssid->pbss; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 1238 | s->pmk_valid = ssid->pmk_valid; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1239 | s->pairwise_cipher = ssid->pbss ? WPA_CIPHER_GCMP : WPA_CIPHER_CCMP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1240 | s->export_keys = 1; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 1241 | |
| 1242 | if (ssid->sae_password) { |
| 1243 | os_free(s->sae_password); |
| 1244 | s->sae_password = os_strdup(ssid->sae_password); |
| 1245 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1246 | if (ssid->passphrase) { |
| 1247 | os_free(s->passphrase); |
| 1248 | s->passphrase = os_strdup(ssid->passphrase); |
| 1249 | } |
| 1250 | if (ssid->psk_set) { |
| 1251 | s->psk_set = 1; |
| 1252 | os_memcpy(s->psk, ssid->psk, 32); |
| 1253 | } |
| 1254 | if (s->passphrase && !s->psk_set) |
| 1255 | wpa_config_update_psk(s); |
| 1256 | if (s->ssid == NULL || s->ssid_len < ssid->ssid_len) { |
| 1257 | os_free(s->ssid); |
| 1258 | s->ssid = os_malloc(ssid->ssid_len); |
| 1259 | } |
| 1260 | if (s->ssid) { |
| 1261 | s->ssid_len = ssid->ssid_len; |
| 1262 | os_memcpy(s->ssid, ssid->ssid, s->ssid_len); |
| 1263 | } |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1264 | if (ssid->mode == WPAS_MODE_P2P_GO && wpa_s->global->add_psk) { |
| 1265 | dl_list_add(&s->psk_list, &wpa_s->global->add_psk->list); |
| 1266 | wpa_s->global->add_psk = NULL; |
| 1267 | changed = 1; |
| 1268 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1269 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1270 | if (changed && wpa_s->conf->update_config && |
| 1271 | wpa_config_write(wpa_s->confname, wpa_s->conf)) { |
| 1272 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
| 1273 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1274 | |
| 1275 | return s->id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1279 | static void wpas_p2p_add_persistent_group_client(struct wpa_supplicant *wpa_s, |
| 1280 | const u8 *addr) |
| 1281 | { |
| 1282 | struct wpa_ssid *ssid, *s; |
| 1283 | u8 *n; |
| 1284 | size_t i; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1285 | int found = 0; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1286 | 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] | 1287 | |
| 1288 | ssid = wpa_s->current_ssid; |
| 1289 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || |
| 1290 | !ssid->p2p_persistent_group) |
| 1291 | return; |
| 1292 | |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1293 | for (s = p2p_wpa_s->conf->ssid; s; s = s->next) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1294 | if (s->disabled != 2 || s->mode != WPAS_MODE_P2P_GO) |
| 1295 | continue; |
| 1296 | |
| 1297 | if (s->ssid_len == ssid->ssid_len && |
| 1298 | os_memcmp(s->ssid, ssid->ssid, s->ssid_len) == 0) |
| 1299 | break; |
| 1300 | } |
| 1301 | |
| 1302 | if (s == NULL) |
| 1303 | return; |
| 1304 | |
| 1305 | for (i = 0; s->p2p_client_list && i < s->num_p2p_clients; i++) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1306 | if (!ether_addr_equal(s->p2p_client_list + i * 2 * ETH_ALEN, |
| 1307 | addr)) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1308 | continue; |
| 1309 | |
| 1310 | if (i == s->num_p2p_clients - 1) |
| 1311 | return; /* already the most recent entry */ |
| 1312 | |
| 1313 | /* move the entry to mark it most recent */ |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1314 | os_memmove(s->p2p_client_list + i * 2 * ETH_ALEN, |
| 1315 | s->p2p_client_list + (i + 1) * 2 * ETH_ALEN, |
| 1316 | (s->num_p2p_clients - i - 1) * 2 * ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1317 | os_memcpy(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, addr, |
| 1319 | ETH_ALEN); |
| 1320 | os_memset(s->p2p_client_list + |
| 1321 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN + ETH_ALEN, |
| 1322 | 0xff, ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1323 | found = 1; |
| 1324 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1325 | } |
| 1326 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1327 | if (!found && s->num_p2p_clients < P2P_MAX_STORED_CLIENTS) { |
| 1328 | n = os_realloc_array(s->p2p_client_list, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1329 | s->num_p2p_clients + 1, 2 * ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1330 | if (n == NULL) |
| 1331 | return; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1332 | os_memcpy(n + s->num_p2p_clients * 2 * ETH_ALEN, addr, |
| 1333 | ETH_ALEN); |
| 1334 | os_memset(n + s->num_p2p_clients * 2 * ETH_ALEN + ETH_ALEN, |
| 1335 | 0xff, ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1336 | s->p2p_client_list = n; |
| 1337 | s->num_p2p_clients++; |
Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 1338 | } else if (!found && s->p2p_client_list) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1339 | /* Not enough room for an additional entry - drop the oldest |
| 1340 | * entry */ |
| 1341 | os_memmove(s->p2p_client_list, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1342 | s->p2p_client_list + 2 * ETH_ALEN, |
| 1343 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1344 | os_memcpy(s->p2p_client_list + |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1345 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1346 | addr, ETH_ALEN); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1347 | os_memset(s->p2p_client_list + |
| 1348 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN + ETH_ALEN, |
| 1349 | 0xff, ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1350 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1351 | |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1352 | if (p2p_wpa_s->conf->update_config && |
| 1353 | wpa_config_write(p2p_wpa_s->confname, p2p_wpa_s->conf)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1354 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1358 | static void wpas_p2p_group_started(struct wpa_supplicant *wpa_s, |
| 1359 | int go, struct wpa_ssid *ssid, int freq, |
| 1360 | const u8 *psk, const char *passphrase, |
| 1361 | const u8 *go_dev_addr, int persistent, |
| 1362 | const char *extra) |
| 1363 | { |
| 1364 | const char *ssid_txt; |
| 1365 | char psk_txt[65]; |
| 1366 | |
| 1367 | if (psk) |
| 1368 | wpa_snprintf_hex(psk_txt, sizeof(psk_txt), psk, 32); |
| 1369 | else |
| 1370 | psk_txt[0] = '\0'; |
| 1371 | |
| 1372 | if (ssid) |
| 1373 | ssid_txt = wpa_ssid_txt(ssid->ssid, ssid->ssid_len); |
| 1374 | else |
| 1375 | ssid_txt = ""; |
| 1376 | |
| 1377 | if (passphrase && passphrase[0] == '\0') |
| 1378 | passphrase = NULL; |
| 1379 | |
| 1380 | /* |
| 1381 | * Include PSK/passphrase only in the control interface message and |
| 1382 | * leave it out from the debug log entry. |
| 1383 | */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1384 | wpa_msg_global_ctrl(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1385 | P2P_EVENT_GROUP_STARTED |
| 1386 | "%s %s ssid=\"%s\" freq=%d%s%s%s%s%s go_dev_addr=" |
| 1387 | MACSTR "%s%s", |
| 1388 | wpa_s->ifname, go ? "GO" : "client", ssid_txt, freq, |
| 1389 | psk ? " psk=" : "", psk_txt, |
| 1390 | passphrase ? " passphrase=\"" : "", |
| 1391 | passphrase ? passphrase : "", |
| 1392 | passphrase ? "\"" : "", |
| 1393 | MAC2STR(go_dev_addr), |
| 1394 | persistent ? " [PERSISTENT]" : "", extra); |
| 1395 | wpa_printf(MSG_INFO, P2P_EVENT_GROUP_STARTED |
| 1396 | "%s %s ssid=\"%s\" freq=%d go_dev_addr=" MACSTR "%s%s", |
| 1397 | wpa_s->ifname, go ? "GO" : "client", ssid_txt, freq, |
| 1398 | MAC2STR(go_dev_addr), persistent ? " [PERSISTENT]" : "", |
| 1399 | extra); |
| 1400 | } |
| 1401 | |
| 1402 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 1403 | int wpas_p2p_remove_all_identity(struct wpa_supplicant *wpa_s) |
| 1404 | { |
| 1405 | struct wpa_dev_ik *ik; |
| 1406 | |
| 1407 | for (ik = wpa_s->conf->identity; ik; ik = ik->next) |
| 1408 | wpa_config_remove_identity(wpa_s->conf, ik->id); |
| 1409 | |
| 1410 | if (wpa_s->conf->update_config && |
| 1411 | wpa_config_write(wpa_s->confname, wpa_s->conf)) { |
| 1412 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
| 1413 | return -1; |
| 1414 | } |
| 1415 | return 0; |
| 1416 | } |
| 1417 | |
| 1418 | |
| 1419 | static void wpas_p2p_store_identity(struct wpa_supplicant *wpa_s, u8 cipher, |
| 1420 | const u8 *dik_data, size_t dik_len, |
| 1421 | const u8 *pmk, size_t pmk_len, |
| 1422 | const u8 *pmkid) |
| 1423 | { |
| 1424 | struct wpa_dev_ik *ik; |
| 1425 | |
| 1426 | for (ik = wpa_s->conf->identity; ik; ik = ik->next) { |
| 1427 | if (dik_len == wpabuf_len(ik->dik) && |
| 1428 | os_memcmp(dik_data, wpabuf_head(ik->dik), dik_len) == 0) { |
| 1429 | wpa_printf(MSG_DEBUG, |
| 1430 | "P2P: Remove previous device identity entry for matching DIK"); |
| 1431 | wpa_config_remove_identity(wpa_s->conf, ik->id); |
| 1432 | break; |
| 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | wpa_printf(MSG_DEBUG, "P2P: Create a new device identity entry"); |
| 1437 | ik = wpa_config_add_identity(wpa_s->conf); |
| 1438 | if (!ik) |
| 1439 | return; |
| 1440 | |
| 1441 | ik->dik = wpabuf_alloc_copy(dik_data, dik_len); |
| 1442 | if (!ik->dik) |
| 1443 | goto fail; |
| 1444 | ik->pmk = wpabuf_alloc_copy(pmk, pmk_len); |
| 1445 | if (!ik->pmk) |
| 1446 | goto fail; |
| 1447 | ik->pmkid = wpabuf_alloc_copy(pmkid, PMKID_LEN); |
| 1448 | if (!ik->pmkid) |
| 1449 | goto fail; |
| 1450 | |
| 1451 | ik->dik_cipher = cipher; |
| 1452 | |
| 1453 | if (wpa_s->conf->update_config && |
| 1454 | wpa_config_write(wpa_s->confname, wpa_s->conf)) |
| 1455 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
| 1456 | return; |
| 1457 | |
| 1458 | fail: |
| 1459 | wpa_config_remove_identity(wpa_s->conf, ik->id); |
| 1460 | } |
| 1461 | |
| 1462 | |
| 1463 | static void wpas_p2p_store_go_identity(struct wpa_supplicant *wpa_s, |
| 1464 | const u8 *go_dev_addr, const u8 *bssid) |
| 1465 | { |
| 1466 | int ret; |
| 1467 | u8 cipher; |
| 1468 | const u8 *dik_data, *pmk, *pmkid; |
| 1469 | size_t dik_len, pmk_len; |
| 1470 | u8 iface_addr[ETH_ALEN]; |
| 1471 | struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s; |
| 1472 | |
| 1473 | if (!wpa_s->p2p2) |
| 1474 | return; |
| 1475 | |
| 1476 | ret = p2p_get_dev_identity_key(p2p_wpa_s->global->p2p, go_dev_addr, |
| 1477 | &dik_data, &dik_len, &cipher); |
| 1478 | if (ret) |
| 1479 | return; |
| 1480 | |
| 1481 | ret = p2p_get_interface_addr(p2p_wpa_s->global->p2p, go_dev_addr, |
| 1482 | iface_addr); |
| 1483 | if (ret) { |
| 1484 | wpa_printf(MSG_DEBUG, |
| 1485 | "P2P: Fetch PMK for GO BSSID " MACSTR, |
| 1486 | MAC2STR(bssid)); |
| 1487 | os_memcpy(iface_addr, bssid, ETH_ALEN); |
| 1488 | } |
| 1489 | ret = wpa_sm_pmksa_get_pmk(wpa_s->wpa, iface_addr, &pmk, &pmk_len, |
| 1490 | &pmkid); |
| 1491 | if (ret) |
| 1492 | return; |
| 1493 | |
| 1494 | wpa_printf(MSG_DEBUG, |
| 1495 | "P2P: Storing Device identity of GO (Interface Addr " MACSTR |
| 1496 | ")", |
| 1497 | MAC2STR(iface_addr)); |
| 1498 | wpas_p2p_store_identity(p2p_wpa_s, cipher, dik_data, dik_len, pmk, |
| 1499 | pmk_len, pmkid); |
| 1500 | } |
| 1501 | |
| 1502 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1503 | static void wpas_group_formation_completed(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 1504 | int success, int already_deleted) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1505 | { |
| 1506 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1507 | int client; |
| 1508 | int persistent; |
| 1509 | u8 go_dev_addr[ETH_ALEN]; |
| 1510 | |
| 1511 | /* |
| 1512 | * This callback is likely called for the main interface. Update wpa_s |
| 1513 | * to use the group interface if a new interface was created for the |
| 1514 | * group. |
| 1515 | */ |
| 1516 | if (wpa_s->global->p2p_group_formation) |
| 1517 | wpa_s = wpa_s->global->p2p_group_formation; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1518 | if (wpa_s->p2p_go_group_formation_completed) { |
| 1519 | wpa_s->global->p2p_group_formation = NULL; |
| 1520 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1521 | } else if (wpa_s->p2p_in_provisioning && !success) { |
| 1522 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1523 | "P2P: Stop provisioning state due to failure"); |
| 1524 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1525 | } |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 1526 | wpa_s->p2p_in_invitation = 0; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 1527 | wpa_s->p2p_retry_limit = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1528 | wpa_s->group_formation_reported = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1529 | |
| 1530 | if (!success) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1531 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1532 | P2P_EVENT_GROUP_FORMATION_FAILURE); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1533 | wpas_notify_p2p_group_formation_failure(wpa_s, ""); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 1534 | if (already_deleted) |
| 1535 | return; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1536 | wpas_p2p_group_delete(wpa_s, |
| 1537 | P2P_GROUP_REMOVAL_FORMATION_FAILED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1538 | return; |
| 1539 | } |
| 1540 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1541 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1542 | P2P_EVENT_GROUP_FORMATION_SUCCESS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1543 | |
| 1544 | ssid = wpa_s->current_ssid; |
| 1545 | if (ssid && ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) { |
| 1546 | ssid->mode = WPAS_MODE_P2P_GO; |
| 1547 | p2p_group_notif_formation_done(wpa_s->p2p_group); |
| 1548 | wpa_supplicant_ap_mac_addr_filter(wpa_s, NULL); |
| 1549 | } |
| 1550 | |
| 1551 | persistent = 0; |
| 1552 | if (ssid) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1553 | client = ssid->mode == WPAS_MODE_INFRA; |
| 1554 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 1555 | persistent = ssid->p2p_persistent_group; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 1556 | os_memcpy(go_dev_addr, wpa_s->global->p2p_dev_addr, |
| 1557 | ETH_ALEN); |
George Burgess IV | 0d2d1bf | 2021-11-01 03:08:33 -0700 | [diff] [blame] | 1558 | } else { |
| 1559 | os_memset(go_dev_addr, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1560 | persistent = wpas_p2p_persistent_group(wpa_s, |
| 1561 | go_dev_addr, |
| 1562 | ssid->ssid, |
| 1563 | ssid->ssid_len); |
George Burgess IV | 0d2d1bf | 2021-11-01 03:08:33 -0700 | [diff] [blame] | 1564 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1565 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1566 | client = wpa_s->p2p_group_interface == |
| 1567 | P2P_GROUP_INTERFACE_CLIENT; |
| 1568 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 1569 | } |
| 1570 | |
| 1571 | wpa_s->show_group_started = 0; |
| 1572 | if (client) { |
| 1573 | /* |
| 1574 | * Indicate event only after successfully completed 4-way |
| 1575 | * handshake, i.e., when the interface is ready for data |
| 1576 | * packets. |
| 1577 | */ |
| 1578 | wpa_s->show_group_started = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1579 | } else { |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1580 | wpas_p2p_group_started(wpa_s, 1, ssid, |
| 1581 | ssid ? ssid->frequency : 0, |
| 1582 | ssid && ssid->passphrase == NULL && |
| 1583 | ssid->psk_set ? ssid->psk : NULL, |
| 1584 | ssid ? ssid->passphrase : NULL, |
| 1585 | go_dev_addr, persistent, ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1586 | wpas_p2p_cross_connect_setup(wpa_s); |
| 1587 | wpas_p2p_set_group_idle_timeout(wpa_s); |
| 1588 | } |
| 1589 | |
| 1590 | if (persistent) |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1591 | wpas_p2p_store_persistent_group(wpa_s->p2pdev, |
| 1592 | ssid, go_dev_addr); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1593 | else { |
| 1594 | os_free(wpa_s->global->add_psk); |
| 1595 | wpa_s->global->add_psk = NULL; |
| 1596 | } |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1597 | |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 1598 | if (!client) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1599 | wpas_notify_p2p_group_started(wpa_s, ssid, persistent, 0, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1600 | os_get_reltime(&wpa_s->global->p2p_go_wait_client); |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 1601 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1605 | struct send_action_work { |
| 1606 | unsigned int freq; |
| 1607 | u8 dst[ETH_ALEN]; |
| 1608 | u8 src[ETH_ALEN]; |
| 1609 | u8 bssid[ETH_ALEN]; |
| 1610 | size_t len; |
| 1611 | unsigned int wait_time; |
| 1612 | u8 buf[0]; |
| 1613 | }; |
| 1614 | |
| 1615 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1616 | static void wpas_p2p_free_send_action_work(struct wpa_supplicant *wpa_s) |
| 1617 | { |
| 1618 | struct send_action_work *awork = wpa_s->p2p_send_action_work->ctx; |
| 1619 | |
| 1620 | wpa_printf(MSG_DEBUG, |
| 1621 | "P2P: Free Action frame radio work @%p (freq=%u dst=" |
| 1622 | MACSTR " src=" MACSTR " bssid=" MACSTR " wait_time=%u)", |
| 1623 | wpa_s->p2p_send_action_work, awork->freq, |
| 1624 | MAC2STR(awork->dst), MAC2STR(awork->src), |
| 1625 | MAC2STR(awork->bssid), awork->wait_time); |
| 1626 | wpa_hexdump(MSG_DEBUG, "P2P: Freeing pending Action frame", |
| 1627 | awork->buf, awork->len); |
| 1628 | os_free(awork); |
| 1629 | wpa_s->p2p_send_action_work->ctx = NULL; |
| 1630 | radio_work_done(wpa_s->p2p_send_action_work); |
| 1631 | wpa_s->p2p_send_action_work = NULL; |
| 1632 | } |
| 1633 | |
| 1634 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1635 | static void wpas_p2p_send_action_work_timeout(void *eloop_ctx, |
| 1636 | void *timeout_ctx) |
| 1637 | { |
| 1638 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 1639 | |
| 1640 | if (!wpa_s->p2p_send_action_work) |
| 1641 | return; |
| 1642 | |
| 1643 | wpa_printf(MSG_DEBUG, "P2P: Send Action frame radio work timed out"); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1644 | wpas_p2p_free_send_action_work(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 1648 | static void wpas_p2p_action_tx_clear(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1649 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1650 | if (wpa_s->p2p_send_action_work) { |
| 1651 | struct send_action_work *awork; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1652 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1653 | awork = wpa_s->p2p_send_action_work->ctx; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1654 | wpa_printf(MSG_DEBUG, |
| 1655 | "P2P: Clear Action TX work @%p (wait_time=%u)", |
| 1656 | wpa_s->p2p_send_action_work, awork->wait_time); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1657 | if (awork->wait_time == 0) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1658 | wpas_p2p_free_send_action_work(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1659 | } else { |
| 1660 | /* |
| 1661 | * In theory, this should not be needed, but number of |
| 1662 | * places in the P2P code is still using non-zero wait |
| 1663 | * time for the last Action frame in the sequence and |
| 1664 | * some of these do not call send_action_done(). |
| 1665 | */ |
| 1666 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 1667 | wpa_s, NULL); |
| 1668 | eloop_register_timeout( |
| 1669 | 0, awork->wait_time * 1000, |
| 1670 | wpas_p2p_send_action_work_timeout, |
| 1671 | wpa_s, NULL); |
| 1672 | } |
| 1673 | } |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | |
| 1677 | static void wpas_p2p_send_action_tx_status(struct wpa_supplicant *wpa_s, |
| 1678 | unsigned int freq, |
| 1679 | const u8 *dst, const u8 *src, |
| 1680 | const u8 *bssid, |
| 1681 | const u8 *data, size_t data_len, |
| 1682 | enum offchannel_send_action_result |
| 1683 | result) |
| 1684 | { |
| 1685 | enum p2p_send_action_result res = P2P_SEND_ACTION_SUCCESS; |
| 1686 | |
| 1687 | wpas_p2p_action_tx_clear(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1688 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1689 | if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) |
| 1690 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1691 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1692 | switch (result) { |
| 1693 | case OFFCHANNEL_SEND_ACTION_SUCCESS: |
| 1694 | res = P2P_SEND_ACTION_SUCCESS; |
| 1695 | break; |
| 1696 | case OFFCHANNEL_SEND_ACTION_NO_ACK: |
| 1697 | res = P2P_SEND_ACTION_NO_ACK; |
| 1698 | break; |
| 1699 | case OFFCHANNEL_SEND_ACTION_FAILED: |
| 1700 | res = P2P_SEND_ACTION_FAILED; |
| 1701 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1702 | } |
| 1703 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1704 | 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] | 1705 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1706 | if (result != OFFCHANNEL_SEND_ACTION_SUCCESS && |
| 1707 | wpa_s->pending_pd_before_join && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1708 | (ether_addr_equal(dst, wpa_s->pending_join_dev_addr) || |
| 1709 | ether_addr_equal(dst, wpa_s->pending_join_iface_addr)) && |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1710 | wpa_s->p2p_fallback_to_go_neg) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1711 | wpa_s->pending_pd_before_join = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1712 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No ACK for PD Req " |
| 1713 | "during p2p_connect-auto"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1714 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1715 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 1716 | "reason=no-ACK-to-PD-Req"); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1717 | wpas_p2p_fallback_to_go_neg(wpa_s, 0); |
| 1718 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1723 | static void wpas_send_action_cb(struct wpa_radio_work *work, int deinit) |
| 1724 | { |
| 1725 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 1726 | struct send_action_work *awork = work->ctx; |
| 1727 | |
| 1728 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 1729 | if (work->started) { |
| 1730 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 1731 | wpa_s, NULL); |
| 1732 | wpa_s->p2p_send_action_work = NULL; |
| 1733 | offchannel_send_action_done(wpa_s); |
| 1734 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1735 | os_free(awork); |
| 1736 | return; |
| 1737 | } |
| 1738 | |
| 1739 | if (offchannel_send_action(wpa_s, awork->freq, awork->dst, awork->src, |
| 1740 | awork->bssid, awork->buf, awork->len, |
| 1741 | awork->wait_time, |
| 1742 | wpas_p2p_send_action_tx_status, 1) < 0) { |
| 1743 | os_free(awork); |
| 1744 | radio_work_done(work); |
| 1745 | return; |
| 1746 | } |
| 1747 | wpa_s->p2p_send_action_work = work; |
| 1748 | } |
| 1749 | |
| 1750 | |
| 1751 | static int wpas_send_action_work(struct wpa_supplicant *wpa_s, |
| 1752 | unsigned int freq, const u8 *dst, |
| 1753 | const u8 *src, const u8 *bssid, const u8 *buf, |
| 1754 | size_t len, unsigned int wait_time) |
| 1755 | { |
| 1756 | struct send_action_work *awork; |
| 1757 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1758 | if (radio_work_pending(wpa_s, "p2p-send-action")) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1759 | wpa_printf(MSG_DEBUG, "P2P: Cannot schedule new p2p-send-action work since one is already pending"); |
| 1760 | return -1; |
| 1761 | } |
| 1762 | |
| 1763 | awork = os_zalloc(sizeof(*awork) + len); |
| 1764 | if (awork == NULL) |
| 1765 | return -1; |
| 1766 | |
| 1767 | awork->freq = freq; |
| 1768 | os_memcpy(awork->dst, dst, ETH_ALEN); |
| 1769 | os_memcpy(awork->src, src, ETH_ALEN); |
| 1770 | os_memcpy(awork->bssid, bssid, ETH_ALEN); |
| 1771 | awork->len = len; |
| 1772 | awork->wait_time = wait_time; |
| 1773 | os_memcpy(awork->buf, buf, len); |
| 1774 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1775 | if (radio_add_work(wpa_s, freq, "p2p-send-action", 1, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1776 | wpas_send_action_cb, awork) < 0) { |
| 1777 | os_free(awork); |
| 1778 | return -1; |
| 1779 | } |
| 1780 | |
| 1781 | return 0; |
| 1782 | } |
| 1783 | |
| 1784 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1785 | static int wpas_send_action(void *ctx, unsigned int freq, const u8 *dst, |
| 1786 | const u8 *src, const u8 *bssid, const u8 *buf, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1787 | size_t len, unsigned int wait_time, int *scheduled) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1788 | { |
| 1789 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1790 | int listen_freq = -1, send_freq = -1; |
| 1791 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1792 | if (scheduled) |
| 1793 | *scheduled = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1794 | if (wpa_s->p2p_listen_work) |
| 1795 | listen_freq = wpa_s->p2p_listen_work->freq; |
| 1796 | if (wpa_s->p2p_send_action_work) |
| 1797 | send_freq = wpa_s->p2p_send_action_work->freq; |
| 1798 | if (listen_freq != (int) freq && send_freq != (int) freq) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1799 | int res; |
| 1800 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 1801 | wpa_printf(MSG_DEBUG, |
| 1802 | "P2P: Schedule new radio work for Action frame TX (listen_freq=%d send_freq=%d freq=%u dst=" |
| 1803 | MACSTR " src=" MACSTR " bssid=" MACSTR, |
| 1804 | listen_freq, send_freq, freq, MAC2STR(dst), |
| 1805 | MAC2STR(src), MAC2STR(bssid)); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1806 | res = wpas_send_action_work(wpa_s, freq, dst, src, bssid, buf, |
| 1807 | len, wait_time); |
| 1808 | if (res == 0 && scheduled) |
| 1809 | *scheduled = 1; |
| 1810 | return res; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | 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] | 1814 | return offchannel_send_action(wpa_s, freq, dst, src, bssid, buf, len, |
| 1815 | wait_time, |
| 1816 | wpas_p2p_send_action_tx_status, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | |
| 1820 | static void wpas_send_action_done(void *ctx) |
| 1821 | { |
| 1822 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1823 | |
| 1824 | if (wpa_s->p2p_send_action_work) { |
| 1825 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 1826 | wpa_s, NULL); |
| 1827 | os_free(wpa_s->p2p_send_action_work->ctx); |
| 1828 | radio_work_done(wpa_s->p2p_send_action_work); |
| 1829 | wpa_s->p2p_send_action_work = NULL; |
| 1830 | } |
| 1831 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1832 | offchannel_send_action_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 1836 | #ifdef CONFIG_PASN |
| 1837 | |
| 1838 | struct wpa_p2p_pasn_auth_work { |
| 1839 | u8 peer_addr[ETH_ALEN]; |
| 1840 | int freq; |
| 1841 | bool verify; |
| 1842 | int force_freq; |
| 1843 | int pref_freq; |
| 1844 | enum p2p_invite_role role; |
| 1845 | u8 *ssid; |
| 1846 | size_t ssid_len; |
| 1847 | u8 bssid[ETH_ALEN]; |
| 1848 | u8 go_dev_addr[ETH_ALEN]; |
| 1849 | }; |
| 1850 | |
| 1851 | |
| 1852 | static void wpas_p2p_pasn_free_auth_work(struct wpa_p2p_pasn_auth_work *awork) |
| 1853 | { |
| 1854 | if (!awork) |
| 1855 | return; |
| 1856 | os_free(awork->ssid); |
| 1857 | os_free(awork); |
| 1858 | } |
| 1859 | |
| 1860 | |
| 1861 | static void wpas_p2p_pasn_cancel_auth_work(struct wpa_supplicant *wpa_s) |
| 1862 | { |
| 1863 | wpa_printf(MSG_DEBUG, "P2P PASN: Cancel p2p-pasn-start-auth work"); |
| 1864 | |
| 1865 | /* Remove pending/started work */ |
| 1866 | radio_remove_works(wpa_s, "p2p-pasn-start-auth", 0); |
| 1867 | } |
| 1868 | |
| 1869 | |
| 1870 | static void wpas_p2p_pasn_auth_start_cb(struct wpa_radio_work *work, int deinit) |
| 1871 | { |
| 1872 | int ret; |
| 1873 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 1874 | struct wpa_p2p_pasn_auth_work *awork = work->ctx; |
| 1875 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 1876 | const u8 *peer_addr = NULL; |
| 1877 | const u8 *bssid = NULL; |
| 1878 | const u8 *go_dev_addr = NULL; |
| 1879 | |
| 1880 | if (deinit) { |
| 1881 | if (!work->started) { |
| 1882 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
| 1883 | wpa_s->p2pdev, NULL); |
| 1884 | } |
| 1885 | wpas_p2p_pasn_free_auth_work(awork); |
| 1886 | return; |
| 1887 | } |
| 1888 | |
| 1889 | if (!is_zero_ether_addr(awork->peer_addr)) |
| 1890 | peer_addr = awork->peer_addr; |
| 1891 | if (!is_zero_ether_addr(awork->bssid)) |
| 1892 | bssid = awork->bssid; |
| 1893 | if (!is_zero_ether_addr(awork->go_dev_addr)) |
| 1894 | go_dev_addr = awork->go_dev_addr; |
| 1895 | |
| 1896 | |
| 1897 | if (awork->verify) |
| 1898 | ret = p2p_initiate_pasn_verify(p2p, peer_addr, awork->freq, |
| 1899 | awork->role, bssid, awork->ssid, |
| 1900 | awork->ssid_len, |
| 1901 | awork->force_freq, go_dev_addr, |
| 1902 | awork->pref_freq); |
| 1903 | else |
| 1904 | ret = p2p_initiate_pasn_auth(p2p, peer_addr, awork->freq); |
| 1905 | |
| 1906 | if (ret) { |
| 1907 | wpa_printf(MSG_DEBUG, |
| 1908 | "P2P PASN: Failed to start PASN authentication"); |
| 1909 | goto fail; |
| 1910 | } |
| 1911 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
| 1912 | wpa_s->p2pdev, NULL); |
| 1913 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, |
| 1914 | wpas_p2p_group_formation_timeout, |
| 1915 | wpa_s->p2pdev, NULL); |
| 1916 | wpa_s->p2p_pasn_auth_work = work; |
| 1917 | return; |
| 1918 | |
| 1919 | fail: |
| 1920 | wpas_p2p_pasn_free_auth_work(awork); |
| 1921 | work->ctx = NULL; |
| 1922 | radio_work_done(work); |
| 1923 | } |
| 1924 | |
| 1925 | |
| 1926 | static int wpas_p2p_initiate_pasn_auth(struct wpa_supplicant *wpa_s, |
| 1927 | const u8 *peer_addr, int freq) |
| 1928 | { |
| 1929 | struct wpa_p2p_pasn_auth_work *awork; |
| 1930 | |
| 1931 | wpas_p2p_pasn_cancel_auth_work(wpa_s); |
| 1932 | wpa_s->p2p_pasn_auth_work = NULL; |
| 1933 | |
| 1934 | awork = os_zalloc(sizeof(*awork)); |
| 1935 | if (!awork) |
| 1936 | return -1; |
| 1937 | |
| 1938 | awork->freq = freq; |
| 1939 | os_memcpy(awork->peer_addr, peer_addr, ETH_ALEN); |
| 1940 | |
| 1941 | if (radio_add_work(wpa_s, freq, "p2p-pasn-start-auth", 1, |
| 1942 | wpas_p2p_pasn_auth_start_cb, awork) < 0) { |
| 1943 | wpas_p2p_pasn_free_auth_work(awork); |
| 1944 | return -1; |
| 1945 | } |
| 1946 | |
| 1947 | wpa_printf(MSG_DEBUG, |
| 1948 | "P2P PASN: Authentication work successfully added"); |
| 1949 | return 0; |
| 1950 | } |
| 1951 | |
| 1952 | #endif /* CONFIG_PASN */ |
| 1953 | |
| 1954 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1955 | static int wpas_copy_go_neg_results(struct wpa_supplicant *wpa_s, |
| 1956 | struct p2p_go_neg_results *params) |
| 1957 | { |
| 1958 | if (wpa_s->go_params == NULL) { |
| 1959 | wpa_s->go_params = os_malloc(sizeof(*params)); |
| 1960 | if (wpa_s->go_params == NULL) |
| 1961 | return -1; |
| 1962 | } |
| 1963 | os_memcpy(wpa_s->go_params, params, sizeof(*params)); |
| 1964 | return 0; |
| 1965 | } |
| 1966 | |
| 1967 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 1968 | static void wpas_start_gc(struct wpa_supplicant *wpa_s, |
| 1969 | struct p2p_go_neg_results *res) |
| 1970 | { |
| 1971 | struct os_reltime now; |
| 1972 | struct wpa_ssid *ssid; |
| 1973 | struct rsn_pmksa_cache_entry *entry; |
| 1974 | |
| 1975 | if (!res->ssid_len) { |
| 1976 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: SSID info not present"); |
| 1977 | return; |
| 1978 | } |
| 1979 | |
| 1980 | wpa_s->group_formation_reported = 0; |
| 1981 | wpa_printf(MSG_DEBUG, "P2P: Start connect for peer " MACSTR |
| 1982 | " dev_addr " MACSTR, |
| 1983 | MAC2STR(res->peer_interface_addr), |
| 1984 | MAC2STR(res->peer_device_addr)); |
| 1985 | wpa_hexdump_ascii(MSG_DEBUG, "P2P: Start connect for SSID", |
| 1986 | res->ssid, res->ssid_len); |
| 1987 | wpa_supplicant_ap_deinit(wpa_s); |
| 1988 | wpas_copy_go_neg_results(wpa_s, res); |
| 1989 | |
| 1990 | ssid = wpa_config_add_network(wpa_s->conf); |
| 1991 | if (!ssid) { |
| 1992 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1993 | "P2P: Could not add network for client"); |
| 1994 | return; |
| 1995 | } |
| 1996 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
| 1997 | wpa_config_set_network_defaults(ssid); |
| 1998 | ssid->temporary = 1; |
| 1999 | ssid->p2p_group = 1; |
| 2000 | |
| 2001 | ssid->ssid = os_memdup(res->ssid, res->ssid_len); |
| 2002 | if (!ssid->ssid) |
| 2003 | return; |
| 2004 | ssid->ssid_len = res->ssid_len; |
| 2005 | |
| 2006 | os_memcpy(ssid->bssid, res->peer_interface_addr, ETH_ALEN); |
| 2007 | |
| 2008 | if (res->akmp == WPA_KEY_MGMT_PASN && res->sae_password[0]) { |
| 2009 | ssid->auth_alg = WPA_AUTH_ALG_SAE; |
| 2010 | ssid->sae_password = os_strdup(res->sae_password); |
| 2011 | if (!ssid->sae_password) |
| 2012 | return; |
| 2013 | } else if (res->akmp == WPA_KEY_MGMT_SAE && res->pmk_len) { |
| 2014 | ssid->auth_alg = WPA_AUTH_ALG_OPEN; |
| 2015 | entry = os_zalloc(sizeof(*entry)); |
| 2016 | if (!entry) |
| 2017 | return; |
| 2018 | os_memcpy(entry->aa, res->peer_interface_addr, ETH_ALEN); |
| 2019 | os_memcpy(entry->pmkid, res->pmkid, PMKID_LEN); |
| 2020 | entry->pmk_len = res->pmk_len; |
| 2021 | os_memcpy(entry->pmk, res->pmk, res->pmk_len); |
| 2022 | entry->akmp = res->akmp; |
| 2023 | os_get_reltime(&now); |
| 2024 | entry->expiration = now.sec + 43200; |
| 2025 | entry->reauth_time = now.sec + 43200 * 70 / 100; |
| 2026 | entry->network_ctx = ssid; |
| 2027 | os_memcpy(entry->spa, wpa_s->own_addr, ETH_ALEN); |
| 2028 | |
| 2029 | wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry); |
| 2030 | ssid->pmk_valid = true; |
| 2031 | } else if (res->akmp == WPA_KEY_MGMT_SAE && res->sae_password[0]) { |
| 2032 | ssid->auth_alg = WPA_AUTH_ALG_SAE; |
| 2033 | ssid->sae_password = os_strdup(res->sae_password); |
| 2034 | if (!ssid->sae_password) |
| 2035 | return; |
| 2036 | } |
| 2037 | |
| 2038 | if (res->psk_set) { |
| 2039 | os_memcpy(ssid->psk, res->psk, 32); |
| 2040 | ssid->psk_set = 1; |
| 2041 | } |
| 2042 | ssid->proto = WPA_PROTO_RSN; |
| 2043 | ssid->key_mgmt = WPA_KEY_MGMT_SAE; |
| 2044 | ssid->pairwise_cipher = WPA_CIPHER_CCMP; |
| 2045 | ssid->group_cipher = WPA_CIPHER_CCMP; |
| 2046 | if (res->cipher) |
| 2047 | ssid->pairwise_cipher |= res->cipher; |
| 2048 | ssid->sae_pwe = SAE_PWE_HASH_TO_ELEMENT; |
| 2049 | ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED; |
| 2050 | ssid->disabled = 0; |
| 2051 | wpa_s->show_group_started = 1; |
| 2052 | wpa_s->p2p_in_invitation = 1; |
| 2053 | wpa_s->p2p_go_group_formation_completed = 0; |
| 2054 | wpa_s->global->p2p_group_formation = wpa_s; |
| 2055 | ssid->rsn_overriding = RSN_OVERRIDING_ENABLED; |
| 2056 | |
| 2057 | wpa_s->current_ssid = ssid; |
| 2058 | wpa_supplicant_update_scan_results(wpa_s, res->peer_interface_addr); |
| 2059 | wpa_supplicant_select_network(wpa_s, ssid); |
| 2060 | } |
| 2061 | |
| 2062 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2063 | static void wpas_start_wps_enrollee(struct wpa_supplicant *wpa_s, |
| 2064 | struct p2p_go_neg_results *res) |
| 2065 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2066 | wpa_s->group_formation_reported = 0; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2067 | wpa_printf(MSG_DEBUG, "P2P: Start WPS Enrollee for peer " MACSTR |
| 2068 | " dev_addr " MACSTR " wps_method %d", |
| 2069 | MAC2STR(res->peer_interface_addr), |
| 2070 | MAC2STR(res->peer_device_addr), res->wps_method); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2071 | wpa_hexdump_ascii(MSG_DEBUG, "P2P: Start WPS Enrollee for SSID", |
| 2072 | res->ssid, res->ssid_len); |
| 2073 | wpa_supplicant_ap_deinit(wpa_s); |
| 2074 | wpas_copy_go_neg_results(wpa_s, res); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2075 | if (res->wps_method == WPS_PBC) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2076 | wpas_wps_start_pbc(wpa_s, res->peer_interface_addr, 1, 0); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2077 | #ifdef CONFIG_WPS_NFC |
| 2078 | } else if (res->wps_method == WPS_NFC) { |
| 2079 | wpas_wps_start_nfc(wpa_s, res->peer_device_addr, |
| 2080 | res->peer_interface_addr, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2081 | wpa_s->p2pdev->p2p_oob_dev_pw, |
| 2082 | wpa_s->p2pdev->p2p_oob_dev_pw_id, 1, |
| 2083 | wpa_s->p2pdev->p2p_oob_dev_pw_id == |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2084 | DEV_PW_NFC_CONNECTION_HANDOVER ? |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2085 | wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2086 | NULL, |
| 2087 | NULL, 0, 0); |
| 2088 | #endif /* CONFIG_WPS_NFC */ |
| 2089 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2090 | u16 dev_pw_id = DEV_PW_DEFAULT; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2091 | if (wpa_s->p2p_wps_method == WPS_P2PS) |
| 2092 | dev_pw_id = DEV_PW_P2PS_DEFAULT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2093 | if (wpa_s->p2p_wps_method == WPS_PIN_KEYPAD) |
| 2094 | dev_pw_id = DEV_PW_REGISTRAR_SPECIFIED; |
| 2095 | wpas_wps_start_pin(wpa_s, res->peer_interface_addr, |
| 2096 | wpa_s->p2p_pin, 1, dev_pw_id); |
| 2097 | } |
| 2098 | } |
| 2099 | |
| 2100 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2101 | static void wpas_p2p_add_psk_list(struct wpa_supplicant *wpa_s, |
| 2102 | struct wpa_ssid *ssid) |
| 2103 | { |
| 2104 | struct wpa_ssid *persistent; |
| 2105 | struct psk_list_entry *psk; |
| 2106 | struct hostapd_data *hapd; |
| 2107 | |
| 2108 | if (!wpa_s->ap_iface) |
| 2109 | return; |
| 2110 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2111 | persistent = wpas_p2p_get_persistent(wpa_s->p2pdev, NULL, ssid->ssid, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2112 | ssid->ssid_len); |
| 2113 | if (persistent == NULL) |
| 2114 | return; |
| 2115 | |
| 2116 | hapd = wpa_s->ap_iface->bss[0]; |
| 2117 | |
| 2118 | dl_list_for_each(psk, &persistent->psk_list, struct psk_list_entry, |
| 2119 | list) { |
| 2120 | struct hostapd_wpa_psk *hpsk; |
| 2121 | |
| 2122 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add persistent group PSK entry for " |
| 2123 | MACSTR " psk=%d", |
| 2124 | MAC2STR(psk->addr), psk->p2p); |
| 2125 | hpsk = os_zalloc(sizeof(*hpsk)); |
| 2126 | if (hpsk == NULL) |
| 2127 | break; |
| 2128 | os_memcpy(hpsk->psk, psk->psk, PMK_LEN); |
| 2129 | if (psk->p2p) |
| 2130 | os_memcpy(hpsk->p2p_dev_addr, psk->addr, ETH_ALEN); |
| 2131 | else |
| 2132 | os_memcpy(hpsk->addr, psk->addr, ETH_ALEN); |
| 2133 | hpsk->next = hapd->conf->ssid.wpa_psk; |
| 2134 | hapd->conf->ssid.wpa_psk = hpsk; |
| 2135 | } |
| 2136 | } |
| 2137 | |
| 2138 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2139 | static void p2p_go_dump_common_freqs(struct wpa_supplicant *wpa_s) |
| 2140 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2141 | char buf[20 + P2P_MAX_CHANNELS * 6]; |
| 2142 | char *pos, *end; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2143 | unsigned int i; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2144 | int res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2145 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2146 | pos = buf; |
| 2147 | end = pos + sizeof(buf); |
| 2148 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 2149 | res = os_snprintf(pos, end - pos, " %d", |
| 2150 | wpa_s->p2p_group_common_freqs[i]); |
| 2151 | if (os_snprintf_error(end - pos, res)) |
| 2152 | break; |
| 2153 | pos += res; |
| 2154 | } |
| 2155 | *pos = '\0'; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2156 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2157 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Common group frequencies:%s", buf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | |
| 2161 | static void p2p_go_save_group_common_freqs(struct wpa_supplicant *wpa_s, |
| 2162 | struct p2p_go_neg_results *params) |
| 2163 | { |
| 2164 | unsigned int i, len = int_array_len(wpa_s->go_params->freq_list); |
| 2165 | |
| 2166 | wpa_s->p2p_group_common_freqs_num = 0; |
| 2167 | os_free(wpa_s->p2p_group_common_freqs); |
| 2168 | wpa_s->p2p_group_common_freqs = os_calloc(len, sizeof(int)); |
| 2169 | if (!wpa_s->p2p_group_common_freqs) |
| 2170 | return; |
| 2171 | |
| 2172 | for (i = 0; i < len; i++) { |
| 2173 | if (!wpa_s->go_params->freq_list[i]) |
| 2174 | break; |
| 2175 | wpa_s->p2p_group_common_freqs[i] = |
| 2176 | wpa_s->go_params->freq_list[i]; |
| 2177 | } |
| 2178 | wpa_s->p2p_group_common_freqs_num = i; |
| 2179 | } |
| 2180 | |
| 2181 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2182 | static void p2p_config_write(struct wpa_supplicant *wpa_s) |
| 2183 | { |
| 2184 | #ifndef CONFIG_NO_CONFIG_WRITE |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2185 | if (wpa_s->p2pdev->conf->update_config && |
| 2186 | wpa_config_write(wpa_s->p2pdev->confname, wpa_s->p2pdev->conf)) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2187 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
| 2188 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 2189 | } |
| 2190 | |
| 2191 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2192 | static void p2p_go_configured(void *ctx, void *data) |
| 2193 | { |
| 2194 | struct wpa_supplicant *wpa_s = ctx; |
| 2195 | struct p2p_go_neg_results *params = data; |
| 2196 | struct wpa_ssid *ssid; |
| 2197 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 2198 | wpa_s->ap_configured_cb = NULL; |
| 2199 | wpa_s->ap_configured_cb_ctx = NULL; |
| 2200 | wpa_s->ap_configured_cb_data = NULL; |
| 2201 | if (!wpa_s->go_params) { |
| 2202 | wpa_printf(MSG_ERROR, |
| 2203 | "P2P: p2p_go_configured() called with wpa_s->go_params == NULL"); |
| 2204 | return; |
| 2205 | } |
| 2206 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 2207 | if (wpa_s->ap_iface && params->p2p2 && |
| 2208 | params->akmp == WPA_KEY_MGMT_SAE) { |
| 2209 | struct hostapd_data *hapd = wpa_s->ap_iface->bss[0]; |
| 2210 | |
| 2211 | wpa_auth_pmksa_add_sae(hapd->wpa_auth, |
| 2212 | params->peer_device_addr, |
| 2213 | params->pmk, params->pmk_len, |
| 2214 | params->pmkid, WPA_KEY_MGMT_SAE); |
| 2215 | hostapd_add_pmkid(hapd, params->peer_device_addr, |
| 2216 | params->pmk, params->pmk_len, |
| 2217 | params->pmkid, WPA_KEY_MGMT_SAE); |
| 2218 | } |
| 2219 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2220 | p2p_go_save_group_common_freqs(wpa_s, params); |
| 2221 | p2p_go_dump_common_freqs(wpa_s); |
| 2222 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2223 | ssid = wpa_s->current_ssid; |
| 2224 | if (ssid && ssid->mode == WPAS_MODE_P2P_GO) { |
| 2225 | wpa_printf(MSG_DEBUG, "P2P: Group setup without provisioning"); |
| 2226 | if (wpa_s->global->p2p_group_formation == wpa_s) |
| 2227 | wpa_s->global->p2p_group_formation = NULL; |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 2228 | wpas_p2p_group_started(wpa_s, 1, ssid, ssid->frequency, |
| 2229 | params->passphrase[0] == '\0' ? |
| 2230 | params->psk : NULL, |
| 2231 | params->passphrase, |
| 2232 | wpa_s->global->p2p_dev_addr, |
| 2233 | params->persistent_group, ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2234 | wpa_s->group_formation_reported = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2235 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2236 | if (wpa_s->p2pdev->p2ps_method_config_any) { |
| 2237 | if (is_zero_ether_addr(wpa_s->p2pdev->p2ps_join_addr)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2238 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2239 | "P2PS: Setting default PIN for ANY"); |
| 2240 | wpa_supplicant_ap_wps_pin(wpa_s, NULL, |
| 2241 | "12345670", NULL, 0, |
| 2242 | 0); |
| 2243 | } else { |
| 2244 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2245 | "P2PS: Setting default PIN for " MACSTR, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2246 | MAC2STR(wpa_s->p2pdev->p2ps_join_addr)); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2247 | wpa_supplicant_ap_wps_pin( |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2248 | wpa_s, wpa_s->p2pdev->p2ps_join_addr, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2249 | "12345670", NULL, 0, 0); |
| 2250 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2251 | wpa_s->p2pdev->p2ps_method_config_any = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2252 | } |
| 2253 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2254 | os_get_reltime(&wpa_s->global->p2p_go_wait_client); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2255 | if (params->persistent_group) { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2256 | wpas_p2p_store_persistent_group( |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2257 | wpa_s->p2pdev, ssid, |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 2258 | wpa_s->global->p2p_dev_addr); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2259 | wpas_p2p_add_psk_list(wpa_s, ssid); |
| 2260 | } |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2261 | |
| 2262 | wpas_notify_p2p_group_started(wpa_s, ssid, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 2263 | params->persistent_group, 0, |
| 2264 | NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2265 | wpas_p2p_cross_connect_setup(wpa_s); |
| 2266 | wpas_p2p_set_group_idle_timeout(wpa_s); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2267 | |
| 2268 | if (wpa_s->p2p_first_connection_timeout) { |
| 2269 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2270 | "P2P: Start group formation timeout of %d seconds until first data connection on GO", |
| 2271 | wpa_s->p2p_first_connection_timeout); |
| 2272 | wpa_s->p2p_go_group_formation_completed = 0; |
| 2273 | wpa_s->global->p2p_group_formation = wpa_s; |
| 2274 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2275 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2276 | eloop_register_timeout( |
| 2277 | wpa_s->p2p_first_connection_timeout, 0, |
| 2278 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2279 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2280 | } |
| 2281 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2282 | return; |
| 2283 | } |
| 2284 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2285 | if (wpa_supplicant_ap_mac_addr_filter(wpa_s, |
| 2286 | params->peer_interface_addr)) { |
| 2287 | wpa_printf(MSG_DEBUG, "P2P: Failed to setup MAC address " |
| 2288 | "filtering"); |
| 2289 | return; |
| 2290 | } |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 2291 | |
| 2292 | if (params->p2p2) { |
| 2293 | wpas_group_formation_completed(wpa_s, 1, 0); |
| 2294 | wpa_printf(MSG_DEBUG, |
| 2295 | "P2P2: Group formation completed - first connection in progress"); |
| 2296 | goto out; |
| 2297 | } |
| 2298 | |
| 2299 | wpa_printf(MSG_DEBUG, "P2P: Setting up WPS for GO provisioning"); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2300 | if (params->wps_method == WPS_PBC) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2301 | wpa_supplicant_ap_wps_pbc(wpa_s, params->peer_interface_addr, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2302 | params->peer_device_addr); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2303 | #ifdef CONFIG_WPS_NFC |
| 2304 | } else if (params->wps_method == WPS_NFC) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2305 | if (wpa_s->p2pdev->p2p_oob_dev_pw_id != |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2306 | DEV_PW_NFC_CONNECTION_HANDOVER && |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2307 | !wpa_s->p2pdev->p2p_oob_dev_pw) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2308 | wpa_printf(MSG_DEBUG, "P2P: No NFC Dev Pw known"); |
| 2309 | return; |
| 2310 | } |
| 2311 | wpas_ap_wps_add_nfc_pw( |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2312 | wpa_s, wpa_s->p2pdev->p2p_oob_dev_pw_id, |
| 2313 | wpa_s->p2pdev->p2p_oob_dev_pw, |
| 2314 | wpa_s->p2pdev->p2p_peer_oob_pk_hash_known ? |
| 2315 | wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : NULL); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2316 | #endif /* CONFIG_WPS_NFC */ |
| 2317 | } else if (wpa_s->p2p_pin[0]) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2318 | wpa_supplicant_ap_wps_pin(wpa_s, params->peer_interface_addr, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2319 | wpa_s->p2p_pin, NULL, 0, 0); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 2320 | out: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2321 | os_free(wpa_s->go_params); |
| 2322 | wpa_s->go_params = NULL; |
| 2323 | } |
| 2324 | |
| 2325 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2326 | /** |
| 2327 | * wpas_p2p_freq_to_edmg_channel - Convert frequency into EDMG channel |
| 2328 | * @freq: Frequency (MHz) to convert |
| 2329 | * @op_class: Buffer for returning operating class |
| 2330 | * @op_edmg_channel: Buffer for returning channel number |
| 2331 | * Returns: 0 on success, -1 on failure |
| 2332 | * |
| 2333 | * This can be used to find the highest channel bonding which includes the |
| 2334 | * specified frequency. |
| 2335 | */ |
| 2336 | static int wpas_p2p_freq_to_edmg_channel(struct wpa_supplicant *wpa_s, |
| 2337 | unsigned int freq, |
| 2338 | u8 *op_class, u8 *op_edmg_channel) |
| 2339 | { |
| 2340 | struct hostapd_hw_modes *hwmode; |
| 2341 | struct ieee80211_edmg_config edmg; |
| 2342 | unsigned int i; |
| 2343 | enum chan_width chanwidth[] = { |
| 2344 | CHAN_WIDTH_8640, |
| 2345 | CHAN_WIDTH_6480, |
| 2346 | CHAN_WIDTH_4320, |
| 2347 | }; |
| 2348 | |
| 2349 | if (!wpa_s->hw.modes) |
| 2350 | return -1; |
| 2351 | |
| 2352 | hwmode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2353 | HOSTAPD_MODE_IEEE80211AD, false); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2354 | if (!hwmode) { |
| 2355 | wpa_printf(MSG_ERROR, |
| 2356 | "Unsupported AP mode: HOSTAPD_MODE_IEEE80211AD"); |
| 2357 | return -1; |
| 2358 | } |
| 2359 | |
| 2360 | /* Find the highest EDMG channel bandwidth to start the P2P GO */ |
| 2361 | for (i = 0; i < ARRAY_SIZE(chanwidth); i++) { |
| 2362 | if (ieee80211_chaninfo_to_channel(freq, chanwidth[i], 0, |
| 2363 | op_class, |
| 2364 | op_edmg_channel) < 0) |
| 2365 | continue; |
| 2366 | |
| 2367 | hostapd_encode_edmg_chan(1, *op_edmg_channel, 0, &edmg); |
| 2368 | if (edmg.channels && |
| 2369 | ieee802_edmg_is_allowed(hwmode->edmg, edmg)) { |
| 2370 | wpa_printf(MSG_DEBUG, |
| 2371 | "Freq %u to EDMG channel %u at opclass %u", |
| 2372 | freq, *op_edmg_channel, *op_class); |
| 2373 | return 0; |
| 2374 | } |
| 2375 | } |
| 2376 | |
| 2377 | return -1; |
| 2378 | } |
| 2379 | |
| 2380 | |
| 2381 | int wpas_p2p_try_edmg_channel(struct wpa_supplicant *wpa_s, |
| 2382 | struct p2p_go_neg_results *params) |
| 2383 | { |
| 2384 | u8 op_channel, op_class; |
| 2385 | int freq; |
| 2386 | |
| 2387 | /* Try social channel as primary channel frequency */ |
| 2388 | freq = (!params->freq) ? 58320 + 1 * 2160 : params->freq; |
| 2389 | |
| 2390 | if (wpas_p2p_freq_to_edmg_channel(wpa_s, freq, &op_class, |
| 2391 | &op_channel) == 0) { |
| 2392 | wpa_printf(MSG_DEBUG, |
| 2393 | "Freq %d will be used to set an EDMG connection (channel=%u opclass=%u)", |
| 2394 | freq, op_channel, op_class); |
| 2395 | params->freq = freq; |
| 2396 | return 0; |
| 2397 | } |
| 2398 | |
| 2399 | return -1; |
| 2400 | } |
| 2401 | |
| 2402 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 2403 | static void wpas_start_go(struct wpa_supplicant *wpa_s, |
| 2404 | struct p2p_go_neg_results *params, |
| 2405 | int group_formation, enum wpa_p2p_mode p2p_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2406 | { |
| 2407 | struct wpa_ssid *ssid; |
| 2408 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2409 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Starting GO"); |
| 2410 | if (wpas_copy_go_neg_results(wpa_s, params) < 0) { |
| 2411 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not copy GO Negotiation " |
| 2412 | "results"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2413 | return; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2414 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2415 | |
| 2416 | ssid = wpa_config_add_network(wpa_s->conf); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2417 | if (ssid == NULL) { |
| 2418 | 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] | 2419 | return; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2420 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2421 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2422 | wpa_s->show_group_started = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2423 | wpa_s->p2p_go_group_formation_completed = 0; |
| 2424 | wpa_s->group_formation_reported = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2425 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2426 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2427 | wpa_config_set_network_defaults(ssid); |
| 2428 | ssid->temporary = 1; |
| 2429 | ssid->p2p_group = 1; |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 2430 | ssid->p2p_persistent_group = !!params->persistent_group; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2431 | ssid->mode = group_formation ? WPAS_MODE_P2P_GROUP_FORMATION : |
| 2432 | WPAS_MODE_P2P_GO; |
| 2433 | ssid->frequency = params->freq; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2434 | ssid->ht40 = params->ht40; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2435 | ssid->vht = params->vht; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 2436 | ssid->max_oper_chwidth = params->max_oper_chwidth; |
| 2437 | ssid->vht_center_freq2 = params->vht_center_freq2; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2438 | ssid->he = params->he; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2439 | if (params->edmg) { |
| 2440 | u8 op_channel, op_class; |
| 2441 | |
| 2442 | if (!wpas_p2p_freq_to_edmg_channel(wpa_s, params->freq, |
| 2443 | &op_class, &op_channel)) { |
| 2444 | ssid->edmg_channel = op_channel; |
| 2445 | ssid->enable_edmg = params->edmg; |
| 2446 | } else { |
| 2447 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2448 | "P2P: Could not match EDMG channel, freq %d, for GO", |
| 2449 | params->freq); |
| 2450 | } |
| 2451 | } |
| 2452 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2453 | ssid->ssid = os_zalloc(params->ssid_len + 1); |
| 2454 | if (ssid->ssid) { |
| 2455 | os_memcpy(ssid->ssid, params->ssid, params->ssid_len); |
| 2456 | ssid->ssid_len = params->ssid_len; |
| 2457 | } |
| 2458 | ssid->auth_alg = WPA_AUTH_ALG_OPEN; |
| 2459 | ssid->key_mgmt = WPA_KEY_MGMT_PSK; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2460 | if (is_6ghz_freq(ssid->frequency) && |
| 2461 | is_p2p_6ghz_capable(wpa_s->global->p2p)) { |
| 2462 | ssid->auth_alg |= WPA_AUTH_ALG_SAE; |
| 2463 | ssid->key_mgmt = WPA_KEY_MGMT_SAE; |
| 2464 | ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2465 | ssid->sae_pwe = SAE_PWE_HASH_TO_ELEMENT; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2466 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use SAE auth_alg and key_mgmt"); |
| 2467 | } else { |
| 2468 | p2p_set_6ghz_dev_capab(wpa_s->global->p2p, false); |
| 2469 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2470 | ssid->proto = WPA_PROTO_RSN; |
| 2471 | ssid->pairwise_cipher = WPA_CIPHER_CCMP; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2472 | ssid->group_cipher = WPA_CIPHER_CCMP; |
| 2473 | if (params->freq > 56160) { |
| 2474 | /* |
| 2475 | * Enable GCMP instead of CCMP as pairwise_cipher and |
| 2476 | * group_cipher in 60 GHz. |
| 2477 | */ |
| 2478 | ssid->pairwise_cipher = WPA_CIPHER_GCMP; |
| 2479 | ssid->group_cipher = WPA_CIPHER_GCMP; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2480 | /* P2P GO in 60 GHz is always a PCP (PBSS) */ |
| 2481 | ssid->pbss = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2482 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2483 | if (os_strlen(params->passphrase) > 0) { |
| 2484 | ssid->passphrase = os_strdup(params->passphrase); |
| 2485 | if (ssid->passphrase == NULL) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2486 | wpa_msg_global(wpa_s, MSG_ERROR, |
| 2487 | "P2P: Failed to copy passphrase for GO"); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2488 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 2489 | return; |
| 2490 | } |
| 2491 | } else |
| 2492 | ssid->passphrase = NULL; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2493 | ssid->psk_set = params->psk_set; |
| 2494 | if (ssid->psk_set) |
| 2495 | os_memcpy(ssid->psk, params->psk, sizeof(ssid->psk)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2496 | else if (ssid->passphrase) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2497 | wpa_config_update_psk(ssid); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2498 | ssid->ap_max_inactivity = wpa_s->p2pdev->conf->p2p_go_max_inactivity; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2499 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 2500 | ssid->p2p_mode = p2p_mode; |
| 2501 | if (params->p2p2) { |
| 2502 | if (params->akmp == WPA_KEY_MGMT_SAE) |
| 2503 | ssid->auth_alg = WPA_AUTH_ALG_OPEN; |
| 2504 | else |
| 2505 | ssid->auth_alg |= WPA_AUTH_ALG_SAE; |
| 2506 | |
| 2507 | ssid->key_mgmt = WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_PASN; |
| 2508 | ssid->sae_password = os_strdup(params->sae_password); |
| 2509 | /* In PCC, RSNE indicates PMF to be disabled while RSNOE/RSNO2E |
| 2510 | * requires PMF for SAE. */ |
| 2511 | if (ssid->p2p_mode != WPA_P2P_MODE_WFD_PCC) |
| 2512 | ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED; |
| 2513 | ssid->sae_pwe = SAE_PWE_HASH_TO_ELEMENT; |
| 2514 | if (params->cipher) |
| 2515 | ssid->pairwise_cipher |= params->cipher; |
| 2516 | } |
| 2517 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2518 | wpa_s->ap_configured_cb = p2p_go_configured; |
| 2519 | wpa_s->ap_configured_cb_ctx = wpa_s; |
| 2520 | wpa_s->ap_configured_cb_data = wpa_s->go_params; |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 2521 | wpa_s->scan_req = NORMAL_SCAN_REQ; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2522 | wpa_s->connect_without_scan = ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2523 | wpa_s->reassociate = 1; |
| 2524 | wpa_s->disconnected = 0; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2525 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Request scan (that will be skipped) to " |
| 2526 | "start GO)"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2527 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 2528 | } |
| 2529 | |
| 2530 | |
| 2531 | static void wpas_p2p_clone_config(struct wpa_supplicant *dst, |
| 2532 | const struct wpa_supplicant *src) |
| 2533 | { |
| 2534 | struct wpa_config *d; |
| 2535 | const struct wpa_config *s; |
| 2536 | |
| 2537 | d = dst->conf; |
| 2538 | s = src->conf; |
| 2539 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2540 | #define C(n) \ |
| 2541 | do { \ |
| 2542 | if (s->n && !d->n) \ |
| 2543 | d->n = os_strdup(s->n); \ |
| 2544 | } while (0) |
| 2545 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2546 | C(device_name); |
| 2547 | C(manufacturer); |
| 2548 | C(model_name); |
| 2549 | C(model_number); |
| 2550 | C(serial_number); |
| 2551 | C(config_methods); |
| 2552 | #undef C |
| 2553 | |
| 2554 | os_memcpy(d->device_type, s->device_type, WPS_DEV_TYPE_LEN); |
| 2555 | os_memcpy(d->sec_device_type, s->sec_device_type, |
| 2556 | sizeof(d->sec_device_type)); |
| 2557 | d->num_sec_device_types = s->num_sec_device_types; |
| 2558 | |
| 2559 | d->p2p_group_idle = s->p2p_group_idle; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2560 | d->p2p_go_freq_change_policy = s->p2p_go_freq_change_policy; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2561 | d->p2p_intra_bss = s->p2p_intra_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2562 | d->persistent_reconnect = s->persistent_reconnect; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2563 | d->max_num_sta = s->max_num_sta; |
| 2564 | d->pbc_in_m1 = s->pbc_in_m1; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2565 | d->ignore_old_scan_res = s->ignore_old_scan_res; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 2566 | d->beacon_int = s->beacon_int; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2567 | d->dtim_period = s->dtim_period; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2568 | d->p2p_go_ctwindow = s->p2p_go_ctwindow; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2569 | d->disassoc_low_ack = s->disassoc_low_ack; |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 2570 | d->disable_scan_offload = s->disable_scan_offload; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2571 | d->passive_scan = s->passive_scan; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2572 | d->pmf = s->pmf; |
| 2573 | d->p2p_6ghz_disable = s->p2p_6ghz_disable; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2574 | d->sae_pwe = s->sae_pwe; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2575 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2576 | if (s->wps_nfc_dh_privkey && s->wps_nfc_dh_pubkey && |
| 2577 | !d->wps_nfc_pw_from_config) { |
| 2578 | wpabuf_free(d->wps_nfc_dh_privkey); |
| 2579 | wpabuf_free(d->wps_nfc_dh_pubkey); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2580 | d->wps_nfc_dh_privkey = wpabuf_dup(s->wps_nfc_dh_privkey); |
| 2581 | d->wps_nfc_dh_pubkey = wpabuf_dup(s->wps_nfc_dh_pubkey); |
| 2582 | } |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2583 | d->p2p_cli_probe = s->p2p_cli_probe; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2584 | d->go_interworking = s->go_interworking; |
| 2585 | d->go_access_network_type = s->go_access_network_type; |
| 2586 | d->go_internet = s->go_internet; |
| 2587 | d->go_venue_group = s->go_venue_group; |
| 2588 | d->go_venue_type = s->go_venue_type; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2589 | d->p2p_add_cli_chan = s->p2p_add_cli_chan; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2593 | static void wpas_p2p_get_group_ifname(struct wpa_supplicant *wpa_s, |
| 2594 | char *ifname, size_t len) |
| 2595 | { |
| 2596 | char *ifname_ptr = wpa_s->ifname; |
| 2597 | |
| 2598 | if (os_strncmp(wpa_s->ifname, P2P_MGMT_DEVICE_PREFIX, |
| 2599 | os_strlen(P2P_MGMT_DEVICE_PREFIX)) == 0) { |
| 2600 | ifname_ptr = os_strrchr(wpa_s->ifname, '-') + 1; |
| 2601 | } |
| 2602 | |
| 2603 | os_snprintf(ifname, len, "p2p-%s-%d", ifname_ptr, wpa_s->p2p_group_idx); |
| 2604 | if (os_strlen(ifname) >= IFNAMSIZ && |
| 2605 | os_strlen(wpa_s->ifname) < IFNAMSIZ) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2606 | int res; |
| 2607 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2608 | /* Try to avoid going over the IFNAMSIZ length limit */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2609 | res = os_snprintf(ifname, len, "p2p-%d", wpa_s->p2p_group_idx); |
| 2610 | if (os_snprintf_error(len, res) && len) |
| 2611 | ifname[len - 1] = '\0'; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2612 | } |
| 2613 | } |
| 2614 | |
| 2615 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2616 | static int wpas_p2p_add_group_interface(struct wpa_supplicant *wpa_s, |
| 2617 | enum wpa_driver_if_type type) |
| 2618 | { |
| 2619 | char ifname[120], force_ifname[120]; |
| 2620 | |
| 2621 | if (wpa_s->pending_interface_name[0]) { |
| 2622 | wpa_printf(MSG_DEBUG, "P2P: Pending virtual interface exists " |
| 2623 | "- skip creation of a new one"); |
| 2624 | if (is_zero_ether_addr(wpa_s->pending_interface_addr)) { |
| 2625 | wpa_printf(MSG_DEBUG, "P2P: Pending virtual address " |
| 2626 | "unknown?! ifname='%s'", |
| 2627 | wpa_s->pending_interface_name); |
| 2628 | return -1; |
| 2629 | } |
| 2630 | return 0; |
| 2631 | } |
| 2632 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2633 | wpas_p2p_get_group_ifname(wpa_s, ifname, sizeof(ifname)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2634 | force_ifname[0] = '\0'; |
| 2635 | |
| 2636 | wpa_printf(MSG_DEBUG, "P2P: Create a new interface %s for the group", |
| 2637 | ifname); |
| 2638 | wpa_s->p2p_group_idx++; |
| 2639 | |
| 2640 | wpa_s->pending_interface_type = type; |
| 2641 | if (wpa_drv_if_add(wpa_s, type, ifname, NULL, NULL, force_ifname, |
| 2642 | wpa_s->pending_interface_addr, NULL) < 0) { |
| 2643 | wpa_printf(MSG_ERROR, "P2P: Failed to create new group " |
| 2644 | "interface"); |
| 2645 | return -1; |
| 2646 | } |
| 2647 | |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2648 | if (wpa_s->conf->p2p_interface_random_mac_addr) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2649 | random_mac_addr(wpa_s->pending_interface_addr); |
| 2650 | wpa_printf(MSG_DEBUG, "P2P: Generate random MAC address " MACSTR |
| 2651 | " for the group", |
| 2652 | MAC2STR(wpa_s->pending_interface_addr)); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2653 | } |
| 2654 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2655 | if (force_ifname[0]) { |
| 2656 | wpa_printf(MSG_DEBUG, "P2P: Driver forced interface name %s", |
| 2657 | force_ifname); |
| 2658 | os_strlcpy(wpa_s->pending_interface_name, force_ifname, |
| 2659 | sizeof(wpa_s->pending_interface_name)); |
| 2660 | } else |
| 2661 | os_strlcpy(wpa_s->pending_interface_name, ifname, |
| 2662 | sizeof(wpa_s->pending_interface_name)); |
| 2663 | wpa_printf(MSG_DEBUG, "P2P: Created pending virtual interface %s addr " |
| 2664 | MACSTR, wpa_s->pending_interface_name, |
| 2665 | MAC2STR(wpa_s->pending_interface_addr)); |
| 2666 | |
| 2667 | return 0; |
| 2668 | } |
| 2669 | |
| 2670 | |
| 2671 | static void wpas_p2p_remove_pending_group_interface( |
| 2672 | struct wpa_supplicant *wpa_s) |
| 2673 | { |
| 2674 | if (!wpa_s->pending_interface_name[0] || |
| 2675 | is_zero_ether_addr(wpa_s->pending_interface_addr)) |
| 2676 | return; /* No pending virtual interface */ |
| 2677 | |
| 2678 | wpa_printf(MSG_DEBUG, "P2P: Removing pending group interface %s", |
| 2679 | wpa_s->pending_interface_name); |
| 2680 | wpa_drv_if_remove(wpa_s, wpa_s->pending_interface_type, |
| 2681 | wpa_s->pending_interface_name); |
| 2682 | os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN); |
| 2683 | wpa_s->pending_interface_name[0] = '\0'; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2684 | wpa_s->global->pending_group_iface_for_p2ps = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2685 | } |
| 2686 | |
| 2687 | |
| 2688 | static struct wpa_supplicant * |
| 2689 | wpas_p2p_init_group_interface(struct wpa_supplicant *wpa_s, int go) |
| 2690 | { |
| 2691 | struct wpa_interface iface; |
| 2692 | struct wpa_supplicant *group_wpa_s; |
| 2693 | |
| 2694 | if (!wpa_s->pending_interface_name[0]) { |
| 2695 | wpa_printf(MSG_ERROR, "P2P: No pending group interface"); |
| 2696 | if (!wpas_p2p_create_iface(wpa_s)) |
| 2697 | return NULL; |
| 2698 | /* |
| 2699 | * Something has forced us to remove the pending interface; try |
| 2700 | * to create a new one and hope for the best that we will get |
| 2701 | * the same local address. |
| 2702 | */ |
| 2703 | if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO : |
| 2704 | WPA_IF_P2P_CLIENT) < 0) |
| 2705 | return NULL; |
| 2706 | } |
| 2707 | |
| 2708 | os_memset(&iface, 0, sizeof(iface)); |
| 2709 | iface.ifname = wpa_s->pending_interface_name; |
| 2710 | iface.driver = wpa_s->driver->name; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2711 | if (wpa_s->conf->ctrl_interface == NULL && |
| 2712 | wpa_s->parent != wpa_s && |
| 2713 | wpa_s->p2p_mgmt && |
| 2714 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) |
| 2715 | iface.ctrl_interface = wpa_s->parent->conf->ctrl_interface; |
| 2716 | else |
| 2717 | iface.ctrl_interface = wpa_s->conf->ctrl_interface; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2718 | iface.driver_param = wpa_s->conf->driver_param; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 2719 | 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] | 2720 | if (group_wpa_s == NULL) { |
| 2721 | wpa_printf(MSG_ERROR, "P2P: Failed to create new " |
| 2722 | "wpa_supplicant interface"); |
| 2723 | return NULL; |
| 2724 | } |
| 2725 | wpa_s->pending_interface_name[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2726 | group_wpa_s->p2p_group_interface = go ? P2P_GROUP_INTERFACE_GO : |
| 2727 | P2P_GROUP_INTERFACE_CLIENT; |
| 2728 | wpa_s->global->p2p_group_formation = group_wpa_s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2729 | wpa_s->global->pending_group_iface_for_p2ps = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2730 | |
| 2731 | wpas_p2p_clone_config(group_wpa_s, wpa_s); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 2732 | group_wpa_s->p2p2 = wpa_s->p2p2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2733 | |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2734 | if (wpa_s->conf->p2p_interface_random_mac_addr) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2735 | if (wpa_drv_set_mac_addr(group_wpa_s, |
| 2736 | wpa_s->pending_interface_addr) < 0) { |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2737 | wpa_msg(group_wpa_s, MSG_INFO, |
| 2738 | "Failed to set random MAC address"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2739 | wpa_supplicant_remove_iface(wpa_s->global, group_wpa_s, |
| 2740 | 0); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2741 | return NULL; |
| 2742 | } |
| 2743 | |
| 2744 | if (wpa_supplicant_update_mac_addr(group_wpa_s) < 0) { |
| 2745 | wpa_msg(group_wpa_s, MSG_INFO, |
| 2746 | "Could not update MAC address information"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2747 | wpa_supplicant_remove_iface(wpa_s->global, group_wpa_s, |
| 2748 | 0); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2749 | return NULL; |
| 2750 | } |
| 2751 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2752 | wpa_printf(MSG_DEBUG, "P2P: Using random MAC address " MACSTR |
| 2753 | " for the group", |
| 2754 | MAC2STR(wpa_s->pending_interface_addr)); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2755 | } |
| 2756 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2757 | return group_wpa_s; |
| 2758 | } |
| 2759 | |
| 2760 | |
| 2761 | static void wpas_p2p_group_formation_timeout(void *eloop_ctx, |
| 2762 | void *timeout_ctx) |
| 2763 | { |
| 2764 | struct wpa_supplicant *wpa_s = eloop_ctx; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 2765 | |
| 2766 | #ifdef CONFIG_PASN |
| 2767 | if (wpa_s->p2p_pasn_auth_work) { |
| 2768 | wpas_p2p_pasn_cancel_auth_work(wpa_s); |
| 2769 | wpa_s->p2p_pasn_auth_work = NULL; |
| 2770 | } |
| 2771 | #endif /* CONFIG_PASN */ |
| 2772 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2773 | wpa_printf(MSG_DEBUG, "P2P: Group Formation timed out"); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2774 | wpas_p2p_group_formation_failed(wpa_s, 0); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2775 | } |
| 2776 | |
| 2777 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2778 | static void wpas_p2p_group_formation_failed(struct wpa_supplicant *wpa_s, |
| 2779 | int already_deleted) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2780 | { |
| 2781 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2782 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2783 | if (wpa_s->global->p2p) |
| 2784 | p2p_group_formation_failed(wpa_s->global->p2p); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2785 | wpas_group_formation_completed(wpa_s, 0, already_deleted); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2789 | static void wpas_p2p_grpform_fail_after_wps(struct wpa_supplicant *wpa_s) |
| 2790 | { |
| 2791 | wpa_printf(MSG_DEBUG, "P2P: Reject group formation due to WPS provisioning failure"); |
| 2792 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2793 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2794 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2795 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2796 | wpa_s->global->p2p_fail_on_wps_complete = 0; |
| 2797 | } |
| 2798 | |
| 2799 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2800 | void wpas_p2p_ap_setup_failed(struct wpa_supplicant *wpa_s) |
| 2801 | { |
| 2802 | if (wpa_s->global->p2p_group_formation != wpa_s) |
| 2803 | return; |
| 2804 | /* Speed up group formation timeout since this cannot succeed */ |
| 2805 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2806 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2807 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2808 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2809 | } |
| 2810 | |
| 2811 | |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 2812 | bool wpas_p2p_retry_limit_exceeded(struct wpa_supplicant *wpa_s) |
| 2813 | { |
| 2814 | if (!wpa_s->p2p_in_invitation || !wpa_s->p2p_retry_limit || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2815 | wpa_s->p2p_in_invitation <= wpa_s->p2p_retry_limit) |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 2816 | return false; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2817 | |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 2818 | wpa_printf(MSG_DEBUG, "P2P: Group join retry limit exceeded"); |
| 2819 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
| 2820 | wpa_s->p2pdev, NULL); |
| 2821 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
| 2822 | wpa_s->p2pdev, NULL); |
| 2823 | return true; |
| 2824 | } |
| 2825 | |
| 2826 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 2827 | static void wpas_set_go_security_config(void *ctx, |
| 2828 | struct p2p_go_neg_results *params) |
| 2829 | { |
| 2830 | struct wpa_supplicant *wpa_s = ctx; |
| 2831 | struct wpa_supplicant *tmp, *ifs = NULL; |
| 2832 | struct hostapd_data *hapd; |
| 2833 | |
| 2834 | if (!params->p2p2) |
| 2835 | return; |
| 2836 | |
| 2837 | dl_list_for_each(tmp, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 2838 | radio_list) { |
| 2839 | struct wpa_ssid *ssid = tmp->current_ssid; |
| 2840 | |
| 2841 | if (ssid && ssid->mode == WPAS_MODE_P2P_GO && |
| 2842 | ssid->ssid && ssid->ssid_len == params->ssid_len && |
| 2843 | os_memcmp(ssid->ssid, params->ssid, params->ssid_len) == 0) |
| 2844 | { |
| 2845 | ifs = tmp; |
| 2846 | break; |
| 2847 | } |
| 2848 | } |
| 2849 | |
| 2850 | if (!ifs || !ifs->ap_iface) |
| 2851 | return; |
| 2852 | |
| 2853 | hapd = ifs->ap_iface->bss[0]; |
| 2854 | hapd->conf->wps_state = 0; |
| 2855 | |
| 2856 | if (params->akmp == WPA_KEY_MGMT_SAE) { |
| 2857 | wpa_printf(MSG_DEBUG, "P2P: Adding PMK for peer: " MACSTR, |
| 2858 | MAC2STR(params->peer_device_addr)); |
| 2859 | wpa_auth_pmksa_add_sae(hapd->wpa_auth, |
| 2860 | params->peer_device_addr, |
| 2861 | params->pmk, params->pmk_len, |
| 2862 | params->pmkid, WPA_KEY_MGMT_SAE); |
| 2863 | hostapd_add_pmkid(hapd, params->peer_device_addr, |
| 2864 | params->pmk, params->pmk_len, |
| 2865 | params->pmkid, WPA_KEY_MGMT_SAE); |
| 2866 | } |
| 2867 | } |
| 2868 | |
| 2869 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2870 | 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] | 2871 | { |
| 2872 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2873 | struct wpa_supplicant *group_wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2874 | |
| 2875 | if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) { |
| 2876 | wpa_drv_cancel_remain_on_channel(wpa_s); |
| 2877 | wpa_s->off_channel_freq = 0; |
| 2878 | wpa_s->roc_waiting_drv_freq = 0; |
| 2879 | } |
| 2880 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 2881 | #ifdef CONFIG_PASN |
| 2882 | if (wpa_s->p2p_pasn_auth_work) { |
| 2883 | wpas_p2p_pasn_cancel_auth_work(wpa_s); |
| 2884 | wpa_s->p2p_pasn_auth_work = NULL; |
| 2885 | } |
| 2886 | #endif /* CONFIG_PASN */ |
| 2887 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2888 | if (res->status) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2889 | wpa_msg_global(wpa_s, MSG_INFO, |
| 2890 | P2P_EVENT_GO_NEG_FAILURE "status=%d", |
| 2891 | res->status); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2892 | wpas_notify_p2p_go_neg_completed(wpa_s, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2893 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 2894 | return; |
| 2895 | } |
| 2896 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2897 | if (!res->role_go) { |
| 2898 | /* Inform driver of the operating channel of GO. */ |
| 2899 | wpa_drv_set_prob_oper_freq(wpa_s, res->freq); |
| 2900 | } |
| 2901 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2902 | if (wpa_s->p2p_go_ht40) |
| 2903 | res->ht40 = 1; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2904 | if (wpa_s->p2p_go_vht) |
| 2905 | res->vht = 1; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2906 | if (wpa_s->p2p_go_he) |
| 2907 | res->he = 1; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2908 | if (wpa_s->p2p_go_edmg) |
| 2909 | res->edmg = 1; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 2910 | res->max_oper_chwidth = wpa_s->p2p_go_max_oper_chwidth; |
| 2911 | res->vht_center_freq2 = wpa_s->p2p_go_vht_center_freq2; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2912 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2913 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_SUCCESS "role=%s " |
| 2914 | "freq=%d ht40=%d peer_dev=" MACSTR " peer_iface=" MACSTR |
| 2915 | " wps_method=%s", |
| 2916 | res->role_go ? "GO" : "client", res->freq, res->ht40, |
| 2917 | MAC2STR(res->peer_device_addr), |
| 2918 | MAC2STR(res->peer_interface_addr), |
| 2919 | p2p_wps_method_text(res->wps_method)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2920 | wpas_notify_p2p_go_neg_completed(wpa_s, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2921 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2922 | if (res->role_go && wpa_s->p2p_persistent_id >= 0) { |
| 2923 | struct wpa_ssid *ssid; |
| 2924 | ssid = wpa_config_get_network(wpa_s->conf, |
| 2925 | wpa_s->p2p_persistent_id); |
| 2926 | if (ssid && ssid->disabled == 2 && |
| 2927 | ssid->mode == WPAS_MODE_P2P_GO && ssid->passphrase) { |
| 2928 | size_t len = os_strlen(ssid->passphrase); |
| 2929 | wpa_printf(MSG_DEBUG, "P2P: Override passphrase based " |
| 2930 | "on requested persistent group"); |
| 2931 | os_memcpy(res->passphrase, ssid->passphrase, len); |
| 2932 | res->passphrase[len] = '\0'; |
| 2933 | } |
| 2934 | } |
| 2935 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2936 | if (wpa_s->create_p2p_iface) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2937 | group_wpa_s = |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2938 | wpas_p2p_init_group_interface(wpa_s, res->role_go); |
| 2939 | if (group_wpa_s == NULL) { |
| 2940 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 2941 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, |
| 2942 | wpa_s, NULL); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2943 | wpas_p2p_group_formation_failed(wpa_s, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2944 | return; |
| 2945 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2946 | os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN); |
| 2947 | wpa_s->pending_interface_name[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2948 | } else { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2949 | group_wpa_s = wpa_s->parent; |
| 2950 | wpa_s->global->p2p_group_formation = group_wpa_s; |
| 2951 | if (group_wpa_s != wpa_s) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2952 | wpas_p2p_clone_config(group_wpa_s, wpa_s); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2953 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2954 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2955 | group_wpa_s->p2p_in_provisioning = 1; |
| 2956 | group_wpa_s->p2pdev = wpa_s; |
| 2957 | if (group_wpa_s != wpa_s) { |
| 2958 | os_memcpy(group_wpa_s->p2p_pin, wpa_s->p2p_pin, |
| 2959 | sizeof(group_wpa_s->p2p_pin)); |
| 2960 | group_wpa_s->p2p_wps_method = wpa_s->p2p_wps_method; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 2961 | group_wpa_s->p2p2 = res->p2p2; |
| 2962 | group_wpa_s->p2p_bootstrap = wpa_s->p2p_bootstrap; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2963 | } |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 2964 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2965 | if (res->role_go) { |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 2966 | wpas_start_go(group_wpa_s, res, 1, group_wpa_s->p2p_mode); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2967 | } else { |
| 2968 | os_get_reltime(&group_wpa_s->scan_min_time); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 2969 | if (res->p2p2) |
| 2970 | wpas_start_gc(group_wpa_s, res); |
| 2971 | else |
| 2972 | wpas_start_wps_enrollee(group_wpa_s, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2973 | } |
| 2974 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2975 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2976 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
| 2977 | |
| 2978 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 2979 | eloop_register_timeout(15 + res->peer_config_timeout / 100, |
| 2980 | (res->peer_config_timeout % 100) * 10000, |
| 2981 | wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 2982 | } |
| 2983 | |
| 2984 | |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 2985 | static void wpas_go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id, |
| 2986 | u8 go_intent) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2987 | { |
| 2988 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2989 | 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] | 2990 | " dev_passwd_id=%u go_intent=%u", MAC2STR(src), |
| 2991 | dev_passwd_id, go_intent); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2992 | |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 2993 | 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] | 2994 | } |
| 2995 | |
| 2996 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2997 | static void wpas_dev_found(void *ctx, const u8 *addr, |
| 2998 | const struct p2p_peer_info *info, |
| 2999 | int new_device) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3000 | { |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 3001 | u8 *wfd_dev_info = NULL; |
| 3002 | u8 wfd_dev_info_len = 0; |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 3003 | u8 *wfd_r2_dev_info = NULL; |
Jimmy Chen | 57e19f5 | 2021-03-04 14:19:52 +0800 | [diff] [blame] | 3004 | u8 wfd_r2_dev_info_len = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3005 | #ifndef CONFIG_NO_STDOUT_DEBUG |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3006 | struct wpa_supplicant *wpa_s = ctx; |
| 3007 | char devtype[WPS_DEV_TYPE_BUFSIZE]; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 3008 | char *wfd_dev_info_hex = NULL; |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 3009 | char *wfd_r2_dev_info_hex = NULL; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 3010 | |
Irfan Sheriff | 8367dc9 | 2012-09-09 17:08:19 -0700 | [diff] [blame] | 3011 | #ifdef CONFIG_WIFI_DISPLAY |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 3012 | wfd_dev_info_hex = wifi_display_subelem_hex(info->wfd_subelems, |
| 3013 | WFD_SUBELEM_DEVICE_INFO); |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 3014 | if (wfd_dev_info_hex) { |
| 3015 | wfd_dev_info_len = strlen(wfd_dev_info_hex) / 2; |
| 3016 | wfd_dev_info = os_zalloc(wfd_dev_info_len); |
| 3017 | // Only used for notification, so not handling error. |
| 3018 | hexstr2bin(wfd_dev_info_hex, wfd_dev_info, wfd_dev_info_len); |
| 3019 | } |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 3020 | |
| 3021 | wfd_r2_dev_info_hex = wifi_display_subelem_hex(info->wfd_subelems, |
| 3022 | WFD_SUBELEM_R2_DEVICE_INFO); |
| 3023 | if (wfd_r2_dev_info_hex) { |
| 3024 | wfd_r2_dev_info_len = strlen(wfd_r2_dev_info_hex) / 2; |
| 3025 | wfd_r2_dev_info = os_zalloc(wfd_r2_dev_info_len); |
| 3026 | // Only used for notification, so not handling error. |
| 3027 | hexstr2bin(wfd_r2_dev_info_hex, wfd_r2_dev_info, wfd_r2_dev_info_len); |
| 3028 | } |
Irfan Sheriff | 8367dc9 | 2012-09-09 17:08:19 -0700 | [diff] [blame] | 3029 | #endif /* CONFIG_WIFI_DISPLAY */ |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 3030 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3031 | if (info->p2ps_instance) { |
| 3032 | char str[256]; |
| 3033 | const u8 *buf = wpabuf_head(info->p2ps_instance); |
| 3034 | size_t len = wpabuf_len(info->p2ps_instance); |
| 3035 | |
| 3036 | while (len) { |
| 3037 | u32 id; |
| 3038 | u16 methods; |
| 3039 | u8 str_len; |
| 3040 | |
| 3041 | if (len < 4 + 2 + 1) |
| 3042 | break; |
| 3043 | id = WPA_GET_LE32(buf); |
| 3044 | buf += sizeof(u32); |
| 3045 | methods = WPA_GET_BE16(buf); |
| 3046 | buf += sizeof(u16); |
| 3047 | str_len = *buf++; |
| 3048 | if (str_len > len - 4 - 2 - 1) |
| 3049 | break; |
| 3050 | os_memcpy(str, buf, str_len); |
| 3051 | str[str_len] = '\0'; |
| 3052 | buf += str_len; |
| 3053 | len -= str_len + sizeof(u32) + sizeof(u16) + sizeof(u8); |
| 3054 | |
| 3055 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3056 | P2P_EVENT_DEVICE_FOUND MACSTR |
| 3057 | " p2p_dev_addr=" MACSTR |
| 3058 | " pri_dev_type=%s name='%s'" |
| 3059 | " config_methods=0x%x" |
| 3060 | " dev_capab=0x%x" |
| 3061 | " group_capab=0x%x" |
| 3062 | " adv_id=%x asp_svc=%s%s", |
| 3063 | MAC2STR(addr), |
| 3064 | MAC2STR(info->p2p_device_addr), |
| 3065 | wps_dev_type_bin2str( |
| 3066 | info->pri_dev_type, |
| 3067 | devtype, sizeof(devtype)), |
| 3068 | info->device_name, methods, |
| 3069 | info->dev_capab, info->group_capab, |
| 3070 | id, str, |
| 3071 | info->vendor_elems ? |
| 3072 | " vendor_elems=1" : ""); |
| 3073 | } |
| 3074 | goto done; |
| 3075 | } |
| 3076 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3077 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_FOUND MACSTR |
| 3078 | " p2p_dev_addr=" MACSTR |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 3079 | " pri_dev_type=%s name='%s' config_methods=0x%x dev_capab=0x%x group_capab=0x%x%s%s%s%s%s new=%d pcea_cap_info=0x%x bootstrap_methods=0x%x pasn_type=0x%x", |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3080 | MAC2STR(addr), MAC2STR(info->p2p_device_addr), |
| 3081 | wps_dev_type_bin2str(info->pri_dev_type, devtype, |
| 3082 | sizeof(devtype)), |
| 3083 | info->device_name, info->config_methods, |
| 3084 | info->dev_capab, info->group_capab, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 3085 | wfd_dev_info_hex ? " wfd_dev_info=0x" : "", |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 3086 | wfd_dev_info_hex ? wfd_dev_info_hex : "", |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 3087 | wfd_r2_dev_info_hex ? " wfd_r2_dev_info=0x" : "", |
| 3088 | wfd_r2_dev_info_hex ? wfd_r2_dev_info_hex : "", |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3089 | info->vendor_elems ? " vendor_elems=1" : "", |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 3090 | new_device, info->pcea_cap_info, |
| 3091 | info->pairing_config.bootstrap_methods, |
| 3092 | info->pairing_config.pasn_type); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3093 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3094 | done: |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 3095 | os_free(wfd_dev_info_hex); |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 3096 | os_free(wfd_r2_dev_info_hex); |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 3097 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 3098 | |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 3099 | wpas_notify_p2p_device_found(ctx, addr, info, wfd_dev_info, |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 3100 | wfd_dev_info_len, wfd_r2_dev_info, |
| 3101 | wfd_r2_dev_info_len, new_device); |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 3102 | os_free(wfd_dev_info); |
jiangpingping | a96a5e8 | 2023-11-16 15:02:17 +0800 | [diff] [blame] | 3103 | os_free(wfd_r2_dev_info); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3104 | } |
| 3105 | |
| 3106 | |
| 3107 | static void wpas_dev_lost(void *ctx, const u8 *dev_addr) |
| 3108 | { |
| 3109 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3110 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3111 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_LOST |
| 3112 | "p2p_dev_addr=" MACSTR, MAC2STR(dev_addr)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3113 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3114 | wpas_notify_p2p_device_lost(wpa_s, dev_addr); |
| 3115 | } |
| 3116 | |
| 3117 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3118 | static void wpas_find_stopped(void *ctx) |
| 3119 | { |
| 3120 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3121 | |
| 3122 | if (wpa_s->p2p_scan_work && wpas_abort_ongoing_scan(wpa_s) < 0) |
| 3123 | wpa_printf(MSG_DEBUG, "P2P: Abort ongoing scan failed"); |
| 3124 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3125 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_FIND_STOPPED); |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 3126 | wpas_notify_p2p_find_stopped(wpa_s); |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3127 | } |
| 3128 | |
| 3129 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3130 | struct wpas_p2p_listen_work { |
| 3131 | unsigned int freq; |
| 3132 | unsigned int duration; |
| 3133 | struct wpabuf *probe_resp_ie; |
| 3134 | }; |
| 3135 | |
| 3136 | |
| 3137 | static void wpas_p2p_listen_work_free(struct wpas_p2p_listen_work *lwork) |
| 3138 | { |
| 3139 | if (lwork == NULL) |
| 3140 | return; |
| 3141 | wpabuf_free(lwork->probe_resp_ie); |
| 3142 | os_free(lwork); |
| 3143 | } |
| 3144 | |
| 3145 | |
| 3146 | static void wpas_p2p_listen_work_done(struct wpa_supplicant *wpa_s) |
| 3147 | { |
| 3148 | struct wpas_p2p_listen_work *lwork; |
| 3149 | |
| 3150 | if (!wpa_s->p2p_listen_work) |
| 3151 | return; |
| 3152 | |
| 3153 | lwork = wpa_s->p2p_listen_work->ctx; |
| 3154 | wpas_p2p_listen_work_free(lwork); |
| 3155 | radio_work_done(wpa_s->p2p_listen_work); |
| 3156 | wpa_s->p2p_listen_work = NULL; |
| 3157 | } |
| 3158 | |
| 3159 | |
| 3160 | static void wpas_start_listen_cb(struct wpa_radio_work *work, int deinit) |
| 3161 | { |
| 3162 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 3163 | struct wpas_p2p_listen_work *lwork = work->ctx; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3164 | unsigned int duration; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3165 | |
| 3166 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 3167 | if (work->started) { |
| 3168 | wpa_s->p2p_listen_work = NULL; |
| 3169 | wpas_stop_listen(wpa_s); |
| 3170 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3171 | wpas_p2p_listen_work_free(lwork); |
| 3172 | return; |
| 3173 | } |
| 3174 | |
| 3175 | wpa_s->p2p_listen_work = work; |
| 3176 | |
| 3177 | wpa_drv_set_ap_wps_ie(wpa_s, NULL, lwork->probe_resp_ie, NULL); |
| 3178 | |
| 3179 | if (wpa_drv_probe_req_report(wpa_s, 1) < 0) { |
| 3180 | wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver to " |
| 3181 | "report received Probe Request frames"); |
| 3182 | wpas_p2p_listen_work_done(wpa_s); |
| 3183 | return; |
| 3184 | } |
| 3185 | |
| 3186 | wpa_s->pending_listen_freq = lwork->freq; |
| 3187 | wpa_s->pending_listen_duration = lwork->duration; |
| 3188 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3189 | duration = lwork->duration; |
| 3190 | #ifdef CONFIG_TESTING_OPTIONS |
| 3191 | if (wpa_s->extra_roc_dur) { |
| 3192 | wpa_printf(MSG_DEBUG, "TESTING: Increase ROC duration %u -> %u", |
| 3193 | duration, duration + wpa_s->extra_roc_dur); |
| 3194 | duration += wpa_s->extra_roc_dur; |
| 3195 | } |
| 3196 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 3197 | |
| 3198 | if (wpa_drv_remain_on_channel(wpa_s, lwork->freq, duration) < 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3199 | wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver " |
| 3200 | "to remain on channel (%u MHz) for Listen " |
| 3201 | "state", lwork->freq); |
| 3202 | wpas_p2p_listen_work_done(wpa_s); |
| 3203 | wpa_s->pending_listen_freq = 0; |
| 3204 | return; |
| 3205 | } |
| 3206 | wpa_s->off_channel_freq = 0; |
| 3207 | wpa_s->roc_waiting_drv_freq = lwork->freq; |
| 3208 | } |
| 3209 | |
| 3210 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3211 | static int wpas_start_listen(void *ctx, unsigned int freq, |
| 3212 | unsigned int duration, |
| 3213 | const struct wpabuf *probe_resp_ie) |
| 3214 | { |
| 3215 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3216 | struct wpas_p2p_listen_work *lwork; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3217 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3218 | if (wpa_s->p2p_listen_work) { |
| 3219 | 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] | 3220 | return -1; |
| 3221 | } |
| 3222 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3223 | lwork = os_zalloc(sizeof(*lwork)); |
| 3224 | if (lwork == NULL) |
| 3225 | return -1; |
| 3226 | lwork->freq = freq; |
| 3227 | lwork->duration = duration; |
| 3228 | if (probe_resp_ie) { |
| 3229 | lwork->probe_resp_ie = wpabuf_dup(probe_resp_ie); |
| 3230 | if (lwork->probe_resp_ie == NULL) { |
| 3231 | wpas_p2p_listen_work_free(lwork); |
| 3232 | return -1; |
| 3233 | } |
| 3234 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3235 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3236 | if (radio_add_work(wpa_s, freq, "p2p-listen", 0, wpas_start_listen_cb, |
| 3237 | lwork) < 0) { |
| 3238 | wpas_p2p_listen_work_free(lwork); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3239 | return -1; |
| 3240 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3241 | |
| 3242 | return 0; |
| 3243 | } |
| 3244 | |
| 3245 | |
| 3246 | static void wpas_stop_listen(void *ctx) |
| 3247 | { |
| 3248 | struct wpa_supplicant *wpa_s = ctx; |
| 3249 | if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) { |
| 3250 | wpa_drv_cancel_remain_on_channel(wpa_s); |
| 3251 | wpa_s->off_channel_freq = 0; |
| 3252 | wpa_s->roc_waiting_drv_freq = 0; |
| 3253 | } |
| 3254 | wpa_drv_set_ap_wps_ie(wpa_s, NULL, NULL, NULL); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 3255 | |
| 3256 | /* |
| 3257 | * Don't cancel Probe Request RX reporting for a connected P2P Client |
| 3258 | * handling Probe Request frames. |
| 3259 | */ |
| 3260 | if (!wpa_s->p2p_cli_probe) |
| 3261 | wpa_drv_probe_req_report(wpa_s, 0); |
| 3262 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3263 | wpas_p2p_listen_work_done(wpa_s); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3264 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 3265 | if (!wpa_s->p2p_removing_listen_work && |
| 3266 | radio_work_pending(wpa_s, "p2p-listen")) { |
| 3267 | wpa_s->p2p_removing_listen_work = true; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3268 | wpa_printf(MSG_DEBUG, |
| 3269 | "P2P: p2p-listen is still pending - remove it"); |
| 3270 | radio_remove_works(wpa_s, "p2p-listen", 0); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 3271 | wpa_s->p2p_removing_listen_work = false; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3272 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3273 | } |
| 3274 | |
| 3275 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 3276 | static int wpas_send_probe_resp(void *ctx, const struct wpabuf *buf, |
| 3277 | unsigned int freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3278 | { |
| 3279 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 3280 | 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] | 3281 | freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3285 | static void wpas_prov_disc_local_display(struct wpa_supplicant *wpa_s, |
| 3286 | const u8 *peer, const char *params, |
| 3287 | unsigned int generated_pin) |
| 3288 | { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3289 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR |
| 3290 | " %08d%s", MAC2STR(peer), generated_pin, params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3291 | } |
| 3292 | |
| 3293 | |
| 3294 | static void wpas_prov_disc_local_keypad(struct wpa_supplicant *wpa_s, |
| 3295 | const u8 *peer, const char *params) |
| 3296 | { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3297 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR |
| 3298 | "%s", MAC2STR(peer), params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3299 | } |
| 3300 | |
| 3301 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3302 | static void wpas_prov_disc_req(void *ctx, const u8 *peer, u16 config_methods, |
| 3303 | const u8 *dev_addr, const u8 *pri_dev_type, |
| 3304 | const char *dev_name, u16 supp_config_methods, |
| 3305 | u8 dev_capab, u8 group_capab, const u8 *group_id, |
| 3306 | size_t group_id_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3307 | { |
| 3308 | struct wpa_supplicant *wpa_s = ctx; |
| 3309 | char devtype[WPS_DEV_TYPE_BUFSIZE]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3310 | char params[300]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3311 | u8 empty_dev_type[8]; |
| 3312 | unsigned int generated_pin = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3313 | struct wpa_supplicant *group = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3314 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3315 | |
| 3316 | if (group_id) { |
| 3317 | for (group = wpa_s->global->ifaces; group; group = group->next) |
| 3318 | { |
| 3319 | struct wpa_ssid *s = group->current_ssid; |
| 3320 | if (s != NULL && |
| 3321 | s->mode == WPAS_MODE_P2P_GO && |
| 3322 | group_id_len - ETH_ALEN == s->ssid_len && |
| 3323 | os_memcmp(group_id + ETH_ALEN, s->ssid, |
| 3324 | s->ssid_len) == 0) |
| 3325 | break; |
| 3326 | } |
| 3327 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3328 | |
| 3329 | if (pri_dev_type == NULL) { |
| 3330 | os_memset(empty_dev_type, 0, sizeof(empty_dev_type)); |
| 3331 | pri_dev_type = empty_dev_type; |
| 3332 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3333 | res = os_snprintf(params, sizeof(params), " p2p_dev_addr=" MACSTR |
| 3334 | " pri_dev_type=%s name='%s' config_methods=0x%x " |
| 3335 | "dev_capab=0x%x group_capab=0x%x%s%s", |
| 3336 | MAC2STR(dev_addr), |
| 3337 | wps_dev_type_bin2str(pri_dev_type, devtype, |
| 3338 | sizeof(devtype)), |
| 3339 | dev_name, supp_config_methods, dev_capab, group_capab, |
| 3340 | group ? " group=" : "", |
| 3341 | group ? group->ifname : ""); |
| 3342 | if (os_snprintf_error(sizeof(params), res)) |
| 3343 | wpa_printf(MSG_DEBUG, "P2P: PD Request event truncated"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3344 | params[sizeof(params) - 1] = '\0'; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3345 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3346 | if (config_methods & WPS_CONFIG_DISPLAY) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3347 | if (wps_generate_pin(&generated_pin) < 0) { |
| 3348 | wpa_printf(MSG_DEBUG, "P2P: Could not generate PIN"); |
| 3349 | wpas_notify_p2p_provision_discovery( |
| 3350 | wpa_s, peer, 0 /* response */, |
Sunil Ravi | 8bae425 | 2023-11-16 03:05:19 +0000 | [diff] [blame] | 3351 | P2P_PROV_DISC_INFO_UNAVAILABLE, 0, 0, NULL); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3352 | return; |
| 3353 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3354 | wpas_prov_disc_local_display(wpa_s, peer, params, |
| 3355 | generated_pin); |
| 3356 | } else if (config_methods & WPS_CONFIG_KEYPAD) |
| 3357 | wpas_prov_disc_local_keypad(wpa_s, peer, params); |
| 3358 | else if (config_methods & WPS_CONFIG_PUSHBUTTON) |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3359 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_REQ |
| 3360 | MACSTR "%s", MAC2STR(peer), params); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 3361 | |
| 3362 | wpas_notify_p2p_provision_discovery(wpa_s, peer, 1 /* request */, |
| 3363 | P2P_PROV_DISC_SUCCESS, |
Sunil Ravi | 8bae425 | 2023-11-16 03:05:19 +0000 | [diff] [blame] | 3364 | config_methods, generated_pin, |
| 3365 | group ? group->ifname : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3366 | } |
| 3367 | |
| 3368 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3369 | 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] | 3370 | { |
| 3371 | struct wpa_supplicant *wpa_s = ctx; |
| 3372 | unsigned int generated_pin = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3373 | char params[20]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3374 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3375 | if (wpa_s->pending_pd_before_join && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3376 | (ether_addr_equal(peer, wpa_s->pending_join_dev_addr) || |
| 3377 | ether_addr_equal(peer, wpa_s->pending_join_iface_addr))) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3378 | wpa_s->pending_pd_before_join = 0; |
| 3379 | wpa_printf(MSG_DEBUG, "P2P: Starting pending " |
| 3380 | "join-existing-group operation"); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3381 | wpas_p2p_join_start(wpa_s, 0, NULL, 0); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3382 | return; |
| 3383 | } |
| 3384 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3385 | if (wpa_s->pending_pd_use == AUTO_PD_JOIN || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3386 | wpa_s->pending_pd_use == AUTO_PD_GO_NEG) { |
| 3387 | int res; |
| 3388 | |
| 3389 | res = os_snprintf(params, sizeof(params), " peer_go=%d", |
| 3390 | wpa_s->pending_pd_use == AUTO_PD_JOIN); |
| 3391 | if (os_snprintf_error(sizeof(params), res)) |
| 3392 | params[sizeof(params) - 1] = '\0'; |
| 3393 | } else |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3394 | params[0] = '\0'; |
| 3395 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3396 | if (config_methods & WPS_CONFIG_DISPLAY) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3397 | wpas_prov_disc_local_keypad(wpa_s, peer, params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3398 | else if (config_methods & WPS_CONFIG_KEYPAD) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3399 | if (wps_generate_pin(&generated_pin) < 0) { |
| 3400 | wpa_printf(MSG_DEBUG, "P2P: Could not generate PIN"); |
| 3401 | wpas_notify_p2p_provision_discovery( |
| 3402 | wpa_s, peer, 0 /* response */, |
Sunil Ravi | 8bae425 | 2023-11-16 03:05:19 +0000 | [diff] [blame] | 3403 | P2P_PROV_DISC_INFO_UNAVAILABLE, 0, 0, NULL); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3404 | return; |
| 3405 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3406 | wpas_prov_disc_local_display(wpa_s, peer, params, |
| 3407 | generated_pin); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3408 | } else if (config_methods & WPS_CONFIG_PUSHBUTTON) |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3409 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_RESP |
| 3410 | MACSTR "%s", MAC2STR(peer), params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3411 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 3412 | wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */, |
| 3413 | P2P_PROV_DISC_SUCCESS, |
Sunil Ravi | 8bae425 | 2023-11-16 03:05:19 +0000 | [diff] [blame] | 3414 | config_methods, generated_pin, |
| 3415 | NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3416 | } |
| 3417 | |
| 3418 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3419 | static void wpas_prov_disc_fail(void *ctx, const u8 *peer, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3420 | enum p2p_prov_disc_status status, |
| 3421 | u32 adv_id, const u8 *adv_mac, |
| 3422 | const char *deferred_session_resp) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 3423 | { |
| 3424 | struct wpa_supplicant *wpa_s = ctx; |
| 3425 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3426 | if (wpa_s->p2p_fallback_to_go_neg) { |
| 3427 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: PD for p2p_connect-auto " |
| 3428 | "failed - fall back to GO Negotiation"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3429 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3430 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 3431 | "reason=PD-failed"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3432 | wpas_p2p_fallback_to_go_neg(wpa_s, 0); |
| 3433 | return; |
| 3434 | } |
| 3435 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3436 | if (status == P2P_PROV_DISC_TIMEOUT_JOIN) { |
Dmitry Shmidt | 2b38048 | 2012-09-13 10:52:13 -0700 | [diff] [blame] | 3437 | wpa_s->pending_pd_before_join = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3438 | wpa_printf(MSG_DEBUG, "P2P: Starting pending " |
| 3439 | "join-existing-group operation (no ACK for PD " |
| 3440 | "Req attempts)"); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3441 | wpas_p2p_join_start(wpa_s, 0, NULL, 0); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3442 | return; |
Dmitry Shmidt | 2b38048 | 2012-09-13 10:52:13 -0700 | [diff] [blame] | 3443 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3444 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3445 | if (adv_id && adv_mac && deferred_session_resp) { |
| 3446 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE |
| 3447 | " p2p_dev_addr=" MACSTR " status=%d adv_id=%x" |
| 3448 | " deferred_session_resp='%s'", |
| 3449 | MAC2STR(peer), status, adv_id, |
| 3450 | deferred_session_resp); |
| 3451 | } else if (adv_id && adv_mac) { |
| 3452 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE |
| 3453 | " p2p_dev_addr=" MACSTR " status=%d adv_id=%x", |
| 3454 | MAC2STR(peer), status, adv_id); |
| 3455 | } else { |
| 3456 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE |
| 3457 | " p2p_dev_addr=" MACSTR " status=%d", |
| 3458 | MAC2STR(peer), status); |
| 3459 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3460 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 3461 | wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */, |
Sunil Ravi | 8bae425 | 2023-11-16 03:05:19 +0000 | [diff] [blame] | 3462 | status, 0, 0, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 3463 | } |
| 3464 | |
| 3465 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3466 | static int freq_included(struct wpa_supplicant *wpa_s, |
| 3467 | const struct p2p_channels *channels, |
| 3468 | unsigned int freq) |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3469 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3470 | if ((channels == NULL || p2p_channels_includes_freq(channels, freq)) && |
| 3471 | wpas_p2p_go_is_peer_freq(wpa_s, freq)) |
| 3472 | return 1; |
| 3473 | return 0; |
| 3474 | } |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3475 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3476 | |
| 3477 | static void wpas_p2p_go_update_common_freqs(struct wpa_supplicant *wpa_s) |
| 3478 | { |
| 3479 | unsigned int num = P2P_MAX_CHANNELS; |
| 3480 | int *common_freqs; |
| 3481 | int ret; |
| 3482 | |
| 3483 | p2p_go_dump_common_freqs(wpa_s); |
| 3484 | common_freqs = os_calloc(num, sizeof(int)); |
| 3485 | if (!common_freqs) |
| 3486 | return; |
| 3487 | |
| 3488 | ret = p2p_group_get_common_freqs(wpa_s->p2p_group, common_freqs, &num); |
| 3489 | if (ret < 0) { |
| 3490 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 3491 | "P2P: Failed to get group common freqs"); |
| 3492 | os_free(common_freqs); |
| 3493 | return; |
| 3494 | } |
| 3495 | |
| 3496 | os_free(wpa_s->p2p_group_common_freqs); |
| 3497 | wpa_s->p2p_group_common_freqs = common_freqs; |
| 3498 | wpa_s->p2p_group_common_freqs_num = num; |
| 3499 | p2p_go_dump_common_freqs(wpa_s); |
| 3500 | } |
| 3501 | |
| 3502 | |
| 3503 | /* |
| 3504 | * Check if the given frequency is one of the possible operating frequencies |
| 3505 | * set after the completion of the GO Negotiation. |
| 3506 | */ |
| 3507 | static int wpas_p2p_go_is_peer_freq(struct wpa_supplicant *wpa_s, int freq) |
| 3508 | { |
| 3509 | unsigned int i; |
| 3510 | |
| 3511 | p2p_go_dump_common_freqs(wpa_s); |
| 3512 | |
| 3513 | /* assume no restrictions */ |
| 3514 | if (!wpa_s->p2p_group_common_freqs_num) |
| 3515 | return 1; |
| 3516 | |
| 3517 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 3518 | if (wpa_s->p2p_group_common_freqs[i] == freq) |
| 3519 | return 1; |
| 3520 | } |
| 3521 | return 0; |
| 3522 | } |
| 3523 | |
| 3524 | |
| 3525 | static int wpas_sta_check_ecsa(struct hostapd_data *hapd, |
| 3526 | struct sta_info *sta, void *ctx) |
| 3527 | { |
| 3528 | int *ecsa_support = ctx; |
| 3529 | |
| 3530 | *ecsa_support &= sta->ecsa_supported; |
| 3531 | |
| 3532 | return 0; |
| 3533 | } |
| 3534 | |
| 3535 | |
| 3536 | /* Check if all the peers support eCSA */ |
| 3537 | static int wpas_p2p_go_clients_support_ecsa(struct wpa_supplicant *wpa_s) |
| 3538 | { |
| 3539 | int ecsa_support = 1; |
| 3540 | |
| 3541 | ap_for_each_sta(wpa_s->ap_iface->bss[0], wpas_sta_check_ecsa, |
| 3542 | &ecsa_support); |
| 3543 | |
| 3544 | return ecsa_support; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3545 | } |
| 3546 | |
| 3547 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3548 | /** |
| 3549 | * Pick the best frequency to use from all the currently used frequencies. |
| 3550 | */ |
| 3551 | static int wpas_p2p_pick_best_used_freq(struct wpa_supplicant *wpa_s, |
| 3552 | struct wpa_used_freq_data *freqs, |
| 3553 | unsigned int num) |
| 3554 | { |
| 3555 | unsigned int i, c; |
| 3556 | |
| 3557 | /* find a candidate freq that is supported by P2P */ |
| 3558 | for (c = 0; c < num; c++) |
| 3559 | if (p2p_supported_freq(wpa_s->global->p2p, freqs[c].freq)) |
| 3560 | break; |
| 3561 | |
| 3562 | if (c == num) |
| 3563 | return 0; |
| 3564 | |
| 3565 | /* once we have a candidate, try to find a 'better' one */ |
| 3566 | for (i = c + 1; i < num; i++) { |
| 3567 | if (!p2p_supported_freq(wpa_s->global->p2p, freqs[i].freq)) |
| 3568 | continue; |
| 3569 | |
| 3570 | /* |
| 3571 | * 1. Infrastructure station interfaces have higher preference. |
| 3572 | * 2. P2P Clients have higher preference. |
| 3573 | * 3. All others. |
| 3574 | */ |
| 3575 | if (freqs[i].flags & WPA_FREQ_USED_BY_INFRA_STATION) { |
| 3576 | c = i; |
| 3577 | break; |
| 3578 | } |
| 3579 | |
| 3580 | if ((freqs[i].flags & WPA_FREQ_USED_BY_P2P_CLIENT)) |
| 3581 | c = i; |
| 3582 | } |
| 3583 | return freqs[c].freq; |
| 3584 | } |
| 3585 | |
| 3586 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3587 | /** |
| 3588 | * Pick the best frequency the driver suggests. |
| 3589 | * |
| 3590 | * num_pref_freq is used as both input and output |
| 3591 | * - input: the max size of pref_freq_list, |
| 3592 | * - output: the valid size of pref_freq_list filled with data. |
| 3593 | */ |
| 3594 | static int wpas_p2p_pick_best_pref_freq(struct wpa_supplicant *wpa_s, bool go, |
| 3595 | struct weighted_pcl *pref_freq_list, |
| 3596 | unsigned int *num_pref_freq) |
| 3597 | { |
| 3598 | int best_freq = 0; |
| 3599 | unsigned int max_pref_freq, i; |
| 3600 | int res; |
| 3601 | enum wpa_driver_if_type iface_type; |
| 3602 | |
| 3603 | max_pref_freq = *num_pref_freq; |
| 3604 | *num_pref_freq = 0; |
| 3605 | |
| 3606 | if (go) |
| 3607 | iface_type = WPA_IF_P2P_GO; |
| 3608 | else |
| 3609 | iface_type = WPA_IF_P2P_CLIENT; |
| 3610 | |
| 3611 | res = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &max_pref_freq, |
| 3612 | pref_freq_list); |
| 3613 | if (!res && !is_p2p_allow_6ghz(wpa_s->global->p2p)) |
| 3614 | max_pref_freq = p2p_remove_6ghz_channels(pref_freq_list, |
| 3615 | max_pref_freq); |
| 3616 | if (res || !max_pref_freq) { |
| 3617 | wpa_printf(MSG_DEBUG, |
| 3618 | "P2P: No preferred frequency list available"); |
| 3619 | return 0; |
| 3620 | } |
| 3621 | |
| 3622 | *num_pref_freq = max_pref_freq; |
| 3623 | i = 0; |
| 3624 | while (i < *num_pref_freq && |
| 3625 | (!p2p_supported_freq(wpa_s->global->p2p, |
| 3626 | pref_freq_list[i].freq) || |
| 3627 | wpas_p2p_disallowed_freq(wpa_s->global, |
| 3628 | pref_freq_list[i].freq) || |
| 3629 | !p2p_pref_freq_allowed(&pref_freq_list[i], go))) { |
| 3630 | wpa_printf(MSG_DEBUG, |
| 3631 | "P2P: preferred_freq_list[%d]=%d is disallowed", |
| 3632 | i, pref_freq_list[i].freq); |
| 3633 | i++; |
| 3634 | } |
| 3635 | if (i != *num_pref_freq) { |
| 3636 | best_freq = pref_freq_list[i].freq; |
| 3637 | wpa_printf(MSG_DEBUG, "P2P: Using preferred_freq_list[%d]=%d", |
| 3638 | i, best_freq); |
| 3639 | } else { |
| 3640 | wpa_printf(MSG_DEBUG, |
| 3641 | "P2P: All driver preferred frequencies are disallowed for P2P use"); |
| 3642 | *num_pref_freq = 0; |
| 3643 | } |
| 3644 | |
| 3645 | return best_freq; |
| 3646 | } |
| 3647 | |
| 3648 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3649 | static u8 wpas_invitation_process(void *ctx, const u8 *sa, const u8 *bssid, |
| 3650 | const u8 *go_dev_addr, const u8 *ssid, |
| 3651 | size_t ssid_len, int *go, u8 *group_bssid, |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3652 | int *force_freq, int persistent_group, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3653 | const struct p2p_channels *channels, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 3654 | int dev_pw_id, bool p2p2) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3655 | { |
| 3656 | struct wpa_supplicant *wpa_s = ctx; |
| 3657 | struct wpa_ssid *s; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3658 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3659 | struct wpa_supplicant *grp; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3660 | int best_freq; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3661 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 3662 | unsigned int num_pref_freq; |
| 3663 | int res; |
| 3664 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3665 | |
| 3666 | if (!persistent_group) { |
| 3667 | wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3668 | " to join an active group (SSID: %s)", |
| 3669 | MAC2STR(sa), wpa_ssid_txt(ssid, ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3670 | if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3671 | (ether_addr_equal(go_dev_addr, wpa_s->p2p_auth_invite) || |
| 3672 | ether_addr_equal(sa, wpa_s->p2p_auth_invite))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3673 | wpa_printf(MSG_DEBUG, "P2P: Accept previously " |
| 3674 | "authorized invitation"); |
| 3675 | goto accept_inv; |
| 3676 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3677 | |
| 3678 | #ifdef CONFIG_WPS_NFC |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3679 | if (dev_pw_id >= 0 && wpa_s->p2p_nfc_tag_enabled && |
| 3680 | dev_pw_id == wpa_s->p2p_oob_dev_pw_id) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3681 | 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] | 3682 | wpa_s->p2p_wps_method = WPS_NFC; |
| 3683 | wpa_s->pending_join_wps_method = WPS_NFC; |
| 3684 | os_memcpy(wpa_s->pending_join_dev_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3685 | go_dev_addr, ETH_ALEN); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3686 | os_memcpy(wpa_s->pending_join_iface_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3687 | bssid, ETH_ALEN); |
| 3688 | goto accept_inv; |
| 3689 | } |
| 3690 | #endif /* CONFIG_WPS_NFC */ |
| 3691 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3692 | /* |
| 3693 | * Do not accept the invitation automatically; notify user and |
| 3694 | * request approval. |
| 3695 | */ |
| 3696 | return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; |
| 3697 | } |
| 3698 | |
| 3699 | grp = wpas_get_p2p_group(wpa_s, ssid, ssid_len, go); |
| 3700 | if (grp) { |
| 3701 | wpa_printf(MSG_DEBUG, "P2P: Accept invitation to already " |
| 3702 | "running persistent group"); |
| 3703 | if (*go) |
| 3704 | os_memcpy(group_bssid, grp->own_addr, ETH_ALEN); |
| 3705 | goto accept_inv; |
| 3706 | } |
| 3707 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3708 | if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3709 | ether_addr_equal(sa, wpa_s->p2p_auth_invite)) { |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3710 | wpa_printf(MSG_DEBUG, "P2P: Accept previously initiated " |
| 3711 | "invitation to re-invoke a persistent group"); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3712 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3713 | } else if (!wpa_s->conf->persistent_reconnect) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3714 | return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; |
| 3715 | |
| 3716 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 3717 | if (s->disabled == 2 && |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 3718 | (p2p2 || ether_addr_equal(s->bssid, go_dev_addr)) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3719 | s->ssid_len == ssid_len && |
| 3720 | os_memcmp(ssid, s->ssid, ssid_len) == 0) |
| 3721 | break; |
| 3722 | } |
| 3723 | |
| 3724 | if (!s) { |
| 3725 | wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR |
| 3726 | " requested reinvocation of an unknown group", |
| 3727 | MAC2STR(sa)); |
| 3728 | return P2P_SC_FAIL_UNKNOWN_GROUP; |
| 3729 | } |
| 3730 | |
| 3731 | if (s->mode == WPAS_MODE_P2P_GO && !wpas_p2p_create_iface(wpa_s)) { |
| 3732 | *go = 1; |
| 3733 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
| 3734 | wpa_printf(MSG_DEBUG, "P2P: The only available " |
| 3735 | "interface is already in use - reject " |
| 3736 | "invitation"); |
| 3737 | return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; |
| 3738 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3739 | if (wpa_s->p2p_mgmt) |
| 3740 | os_memcpy(group_bssid, wpa_s->parent->own_addr, |
| 3741 | ETH_ALEN); |
| 3742 | else |
| 3743 | os_memcpy(group_bssid, wpa_s->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3744 | } else if (s->mode == WPAS_MODE_P2P_GO) { |
| 3745 | *go = 1; |
| 3746 | if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO) < 0) |
| 3747 | { |
| 3748 | wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " |
| 3749 | "interface address for the group"); |
| 3750 | return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; |
| 3751 | } |
| 3752 | os_memcpy(group_bssid, wpa_s->pending_interface_addr, |
| 3753 | ETH_ALEN); |
| 3754 | } |
| 3755 | |
| 3756 | accept_inv: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3757 | wpas_p2p_set_own_freq_preference(wpa_s, 0); |
| 3758 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3759 | best_freq = 0; |
| 3760 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 3761 | sizeof(struct wpa_used_freq_data)); |
| 3762 | if (freqs) { |
| 3763 | int num_channels = wpa_s->num_multichan_concurrent; |
| 3764 | int num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, num_channels); |
| 3765 | best_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num); |
| 3766 | os_free(freqs); |
| 3767 | } |
| 3768 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3769 | num_pref_freq = P2P_MAX_PREF_CHANNELS; |
| 3770 | res = wpas_p2p_pick_best_pref_freq(wpa_s, *go, pref_freq_list, |
| 3771 | &num_pref_freq); |
| 3772 | if (res > 0) |
| 3773 | best_freq = res; |
| 3774 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3775 | /* Get one of the frequencies currently in use */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3776 | if (best_freq > 0) { |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 3777 | 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] | 3778 | wpas_p2p_set_own_freq_preference(wpa_s, best_freq); |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 3779 | |
| 3780 | if (wpa_s->num_multichan_concurrent < 2 || |
| 3781 | wpas_p2p_num_unused_channels(wpa_s) < 1) { |
| 3782 | 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] | 3783 | *force_freq = best_freq; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 3784 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3785 | } |
| 3786 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3787 | if (*force_freq > 0 && wpa_s->num_multichan_concurrent > 1 && |
| 3788 | wpas_p2p_num_unused_channels(wpa_s) > 0) { |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3789 | if (*go == 0) { |
| 3790 | /* We are the client */ |
| 3791 | wpa_printf(MSG_DEBUG, "P2P: Peer was found to be " |
| 3792 | "running a GO but we are capable of MCC, " |
| 3793 | "figure out the best channel to use"); |
| 3794 | *force_freq = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3795 | } else if (!freq_included(wpa_s, channels, *force_freq)) { |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3796 | /* We are the GO, and *force_freq is not in the |
| 3797 | * intersection */ |
| 3798 | wpa_printf(MSG_DEBUG, "P2P: Forced GO freq %d MHz not " |
| 3799 | "in intersection but we are capable of MCC, " |
| 3800 | "figure out the best channel to use", |
| 3801 | *force_freq); |
| 3802 | *force_freq = 0; |
| 3803 | } |
| 3804 | } |
| 3805 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3806 | return P2P_SC_SUCCESS; |
| 3807 | } |
| 3808 | |
| 3809 | |
| 3810 | static void wpas_invitation_received(void *ctx, const u8 *sa, const u8 *bssid, |
| 3811 | const u8 *ssid, size_t ssid_len, |
| 3812 | const u8 *go_dev_addr, u8 status, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 3813 | int op_freq, const u8 *pmkid, |
| 3814 | const u8 *pmk, size_t pmk_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3815 | { |
| 3816 | struct wpa_supplicant *wpa_s = ctx; |
| 3817 | struct wpa_ssid *s; |
| 3818 | |
| 3819 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 3820 | if (s->disabled == 2 && |
| 3821 | s->ssid_len == ssid_len && |
| 3822 | os_memcmp(ssid, s->ssid, ssid_len) == 0) |
| 3823 | break; |
| 3824 | } |
| 3825 | |
| 3826 | if (status == P2P_SC_SUCCESS) { |
| 3827 | wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3828 | " was accepted; op_freq=%d MHz, SSID=%s", |
| 3829 | MAC2STR(sa), op_freq, wpa_ssid_txt(ssid, ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3830 | if (s) { |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 3831 | int go = s->mode == WPAS_MODE_P2P_GO; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 3832 | if (go) { |
| 3833 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3834 | P2P_EVENT_INVITATION_ACCEPTED |
| 3835 | "sa=" MACSTR |
| 3836 | " persistent=%d freq=%d", |
| 3837 | MAC2STR(sa), s->id, op_freq); |
| 3838 | } else { |
| 3839 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3840 | P2P_EVENT_INVITATION_ACCEPTED |
| 3841 | "sa=" MACSTR |
| 3842 | " persistent=%d", |
| 3843 | MAC2STR(sa), s->id); |
| 3844 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3845 | wpas_p2p_group_add_persistent( |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3846 | wpa_s, s, go, 0, op_freq, 0, |
| 3847 | wpa_s->conf->p2p_go_ht40, |
| 3848 | wpa_s->conf->p2p_go_vht, |
| 3849 | 0, |
| 3850 | wpa_s->conf->p2p_go_he, |
| 3851 | wpa_s->conf->p2p_go_edmg, NULL, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3852 | go ? P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0, |
Matthew Wang | 124e5f4 | 2022-12-29 07:23:06 +0000 | [diff] [blame] | 3853 | 1, is_p2p_allow_6ghz(wpa_s->global->p2p), 0, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 3854 | bssid, sa, pmkid, pmk, pmk_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3855 | } else if (bssid) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3856 | wpa_s->user_initiated_pd = 0; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 3857 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3858 | P2P_EVENT_INVITATION_ACCEPTED |
| 3859 | "sa=" MACSTR " go_dev_addr=" MACSTR |
| 3860 | " bssid=" MACSTR " unknown-network", |
| 3861 | MAC2STR(sa), MAC2STR(go_dev_addr), |
| 3862 | MAC2STR(bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3863 | wpas_p2p_join(wpa_s, bssid, go_dev_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3864 | wpa_s->p2p_wps_method, 0, op_freq, |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3865 | ssid, ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3866 | } |
| 3867 | return; |
| 3868 | } |
| 3869 | |
| 3870 | if (status != P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) { |
| 3871 | wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR |
| 3872 | " was rejected (status %u)", MAC2STR(sa), status); |
| 3873 | return; |
| 3874 | } |
| 3875 | |
| 3876 | if (!s) { |
| 3877 | if (bssid) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3878 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3879 | P2P_EVENT_INVITATION_RECEIVED |
| 3880 | "sa=" MACSTR " go_dev_addr=" MACSTR |
| 3881 | " bssid=" MACSTR " unknown-network", |
| 3882 | MAC2STR(sa), MAC2STR(go_dev_addr), |
| 3883 | MAC2STR(bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3884 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3885 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3886 | P2P_EVENT_INVITATION_RECEIVED |
| 3887 | "sa=" MACSTR " go_dev_addr=" MACSTR |
| 3888 | " unknown-network", |
| 3889 | MAC2STR(sa), MAC2STR(go_dev_addr)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3890 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3891 | wpas_notify_p2p_invitation_received(wpa_s, sa, go_dev_addr, |
| 3892 | bssid, 0, op_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3893 | return; |
| 3894 | } |
| 3895 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3896 | if (s->mode == WPAS_MODE_P2P_GO && op_freq) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3897 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED |
| 3898 | "sa=" MACSTR " persistent=%d freq=%d", |
| 3899 | MAC2STR(sa), s->id, op_freq); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3900 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3901 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED |
| 3902 | "sa=" MACSTR " persistent=%d", |
| 3903 | MAC2STR(sa), s->id); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3904 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3905 | wpas_notify_p2p_invitation_received(wpa_s, sa, go_dev_addr, bssid, |
| 3906 | s->id, op_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3907 | } |
| 3908 | |
| 3909 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3910 | static void wpas_remove_persistent_peer(struct wpa_supplicant *wpa_s, |
| 3911 | struct wpa_ssid *ssid, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3912 | const u8 *peer, int inv) |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3913 | { |
| 3914 | size_t i; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 3915 | 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] | 3916 | |
| 3917 | if (ssid == NULL) |
| 3918 | return; |
| 3919 | |
| 3920 | for (i = 0; ssid->p2p_client_list && i < ssid->num_p2p_clients; i++) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3921 | if (ether_addr_equal(ssid->p2p_client_list + i * 2 * ETH_ALEN, |
| 3922 | peer)) |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3923 | break; |
| 3924 | } |
Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 3925 | if (i >= ssid->num_p2p_clients || !ssid->p2p_client_list) { |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3926 | if (ssid->mode != WPAS_MODE_P2P_GO && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3927 | ether_addr_equal(ssid->bssid, peer)) { |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3928 | wpa_printf(MSG_DEBUG, "P2P: Remove persistent group %d " |
| 3929 | "due to invitation result", ssid->id); |
| 3930 | wpas_notify_network_removed(wpa_s, ssid); |
| 3931 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 3932 | return; |
| 3933 | } |
| 3934 | return; /* Peer not found in client list */ |
| 3935 | } |
| 3936 | |
| 3937 | wpa_printf(MSG_DEBUG, "P2P: Remove peer " MACSTR " from persistent " |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3938 | "group %d client list%s", |
| 3939 | MAC2STR(peer), ssid->id, |
| 3940 | inv ? " due to invitation result" : ""); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3941 | os_memmove(ssid->p2p_client_list + i * 2 * ETH_ALEN, |
| 3942 | ssid->p2p_client_list + (i + 1) * 2 * ETH_ALEN, |
| 3943 | (ssid->num_p2p_clients - i - 1) * 2 * ETH_ALEN); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3944 | ssid->num_p2p_clients--; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 3945 | if (p2p_wpa_s->conf->update_config && |
| 3946 | wpa_config_write(p2p_wpa_s->confname, p2p_wpa_s->conf)) |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3947 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3948 | } |
| 3949 | |
| 3950 | |
| 3951 | static void wpas_remove_persistent_client(struct wpa_supplicant *wpa_s, |
| 3952 | const u8 *peer) |
| 3953 | { |
| 3954 | struct wpa_ssid *ssid; |
| 3955 | |
| 3956 | wpa_s = wpa_s->global->p2p_invite_group; |
| 3957 | if (wpa_s == NULL) |
| 3958 | return; /* No known invitation group */ |
| 3959 | ssid = wpa_s->current_ssid; |
| 3960 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || |
| 3961 | !ssid->p2p_persistent_group) |
| 3962 | return; /* Not operating as a GO in persistent group */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3963 | ssid = wpas_p2p_get_persistent(wpa_s->p2pdev, peer, |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3964 | ssid->ssid, ssid->ssid_len); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3965 | wpas_remove_persistent_peer(wpa_s, ssid, peer, 1); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3966 | } |
| 3967 | |
| 3968 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3969 | static void wpas_invitation_result(void *ctx, int status, const u8 *bssid, |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3970 | const struct p2p_channels *channels, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3971 | const u8 *peer, int neg_freq, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 3972 | int peer_oper_freq, const u8 *pmkid, |
| 3973 | const u8 *pmk, size_t pmk_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3974 | { |
| 3975 | struct wpa_supplicant *wpa_s = ctx; |
| 3976 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3977 | int freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3978 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 3979 | #ifdef CONFIG_PASN |
| 3980 | if (wpa_s->p2p_pasn_auth_work) { |
| 3981 | wpas_p2p_pasn_cancel_auth_work(wpa_s); |
| 3982 | wpa_s->p2p_pasn_auth_work = NULL; |
| 3983 | } |
| 3984 | #endif /* CONFIG_PASN */ |
| 3985 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3986 | if (bssid) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3987 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT |
| 3988 | "status=%d " MACSTR, |
| 3989 | status, MAC2STR(bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3990 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3991 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT |
| 3992 | "status=%d ", status); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3993 | } |
| 3994 | wpas_notify_p2p_invitation_result(wpa_s, status, bssid); |
| 3995 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3996 | wpa_printf(MSG_DEBUG, "P2P: Invitation result - status=%d peer=" MACSTR, |
| 3997 | status, MAC2STR(peer)); |
| 3998 | if (wpa_s->pending_invite_ssid_id == -1) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3999 | struct wpa_supplicant *group_if = |
| 4000 | wpa_s->global->p2p_invite_group; |
| 4001 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4002 | if (status == P2P_SC_FAIL_UNKNOWN_GROUP) |
| 4003 | wpas_remove_persistent_client(wpa_s, peer); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4004 | |
| 4005 | /* |
| 4006 | * Invitation to an active group. If this is successful and we |
| 4007 | * are the GO, set the client wait to postpone some concurrent |
| 4008 | * operations and to allow provisioning and connection to happen |
| 4009 | * more quickly. |
| 4010 | */ |
| 4011 | if (status == P2P_SC_SUCCESS && |
| 4012 | group_if && group_if->current_ssid && |
| 4013 | group_if->current_ssid->mode == WPAS_MODE_P2P_GO) { |
| 4014 | os_get_reltime(&wpa_s->global->p2p_go_wait_client); |
| 4015 | #ifdef CONFIG_TESTING_OPTIONS |
| 4016 | if (group_if->p2p_go_csa_on_inv) { |
| 4017 | wpa_printf(MSG_DEBUG, |
| 4018 | "Testing: force P2P GO CSA after invitation"); |
| 4019 | eloop_cancel_timeout( |
| 4020 | wpas_p2p_reconsider_moving_go, |
| 4021 | wpa_s, NULL); |
| 4022 | eloop_register_timeout( |
| 4023 | 0, 50000, |
| 4024 | wpas_p2p_reconsider_moving_go, |
| 4025 | wpa_s, NULL); |
| 4026 | } |
| 4027 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 4028 | } |
| 4029 | return; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4030 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4031 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 4032 | if (status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) { |
| 4033 | wpa_printf(MSG_DEBUG, "P2P: Waiting for peer to start another " |
| 4034 | "invitation exchange to indicate readiness for " |
| 4035 | "re-invocation"); |
| 4036 | } |
| 4037 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4038 | if (status != P2P_SC_SUCCESS) { |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4039 | if (status == P2P_SC_FAIL_UNKNOWN_GROUP) { |
| 4040 | ssid = wpa_config_get_network( |
| 4041 | wpa_s->conf, wpa_s->pending_invite_ssid_id); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 4042 | wpas_remove_persistent_peer(wpa_s, ssid, peer, 1); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4043 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4044 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 4045 | return; |
| 4046 | } |
| 4047 | |
| 4048 | ssid = wpa_config_get_network(wpa_s->conf, |
| 4049 | wpa_s->pending_invite_ssid_id); |
| 4050 | if (ssid == NULL) { |
| 4051 | wpa_printf(MSG_ERROR, "P2P: Could not find persistent group " |
| 4052 | "data matching with invitation"); |
| 4053 | return; |
| 4054 | } |
| 4055 | |
Jouni Malinen | 2c5b17d | 2012-10-13 21:52:46 -0700 | [diff] [blame] | 4056 | /* |
| 4057 | * The peer could have missed our ctrl::ack frame for Invitation |
| 4058 | * Response and continue retransmitting the frame. To reduce the |
| 4059 | * likelihood of the peer not getting successful TX status for the |
| 4060 | * Invitation Response frame, wait a short time here before starting |
| 4061 | * the persistent group so that we will remain on the current channel to |
| 4062 | * acknowledge any possible retransmission from the peer. |
| 4063 | */ |
| 4064 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: 50 ms wait on current channel before " |
| 4065 | "starting persistent group"); |
| 4066 | os_sleep(0, 50000); |
| 4067 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4068 | if (neg_freq > 0 && ssid->mode == WPAS_MODE_P2P_GO && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4069 | freq_included(wpa_s, channels, neg_freq)) |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4070 | freq = neg_freq; |
| 4071 | else if (peer_oper_freq > 0 && ssid->mode != WPAS_MODE_P2P_GO && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4072 | freq_included(wpa_s, channels, peer_oper_freq)) |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4073 | freq = peer_oper_freq; |
| 4074 | else |
| 4075 | freq = 0; |
| 4076 | |
| 4077 | wpa_printf(MSG_DEBUG, "P2P: Persistent group invitation success - op_freq=%d MHz SSID=%s", |
| 4078 | freq, wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4079 | wpas_p2p_group_add_persistent(wpa_s, ssid, |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 4080 | ssid->mode == WPAS_MODE_P2P_GO, |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4081 | wpa_s->p2p_persistent_go_freq, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4082 | freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4083 | wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4084 | wpa_s->p2p_go_ht40, wpa_s->p2p_go_vht, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4085 | wpa_s->p2p_go_max_oper_chwidth, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4086 | wpa_s->p2p_go_he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4087 | wpa_s->p2p_go_edmg, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4088 | channels, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4089 | ssid->mode == WPAS_MODE_P2P_GO ? |
| 4090 | P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4091 | 0, 1, |
Matthew Wang | 124e5f4 | 2022-12-29 07:23:06 +0000 | [diff] [blame] | 4092 | is_p2p_allow_6ghz(wpa_s->global->p2p), 0, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 4093 | bssid, peer, pmkid, pmk, pmk_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4094 | } |
| 4095 | |
| 4096 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4097 | static int wpas_p2p_disallowed_freq(struct wpa_global *global, |
| 4098 | unsigned int freq) |
| 4099 | { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 4100 | if (freq_range_list_includes(&global->p2p_go_avoid_freq, freq)) |
| 4101 | return 1; |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 4102 | return freq_range_list_includes(&global->p2p_disallow_freq, freq); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4103 | } |
| 4104 | |
| 4105 | |
| 4106 | static void wpas_p2p_add_chan(struct p2p_reg_class *reg, u8 chan) |
| 4107 | { |
| 4108 | reg->channel[reg->channels] = chan; |
| 4109 | reg->channels++; |
| 4110 | } |
| 4111 | |
| 4112 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4113 | static int wpas_p2p_default_channels(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4114 | struct p2p_channels *chan, |
| 4115 | struct p2p_channels *cli_chan) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4116 | { |
| 4117 | int i, cla = 0; |
| 4118 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4119 | wpa_s->global->p2p_24ghz_social_channels = 1; |
| 4120 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4121 | os_memset(cli_chan, 0, sizeof(*cli_chan)); |
| 4122 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4123 | wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for 2.4 GHz " |
| 4124 | "band"); |
| 4125 | |
| 4126 | /* Operating class 81 - 2.4 GHz band channels 1..13 */ |
| 4127 | chan->reg_class[cla].reg_class = 81; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4128 | chan->reg_class[cla].channels = 0; |
| 4129 | for (i = 0; i < 11; i++) { |
| 4130 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 2412 + i * 5)) |
| 4131 | wpas_p2p_add_chan(&chan->reg_class[cla], i + 1); |
| 4132 | } |
| 4133 | if (chan->reg_class[cla].channels) |
| 4134 | cla++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4135 | |
| 4136 | wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for lower 5 GHz " |
| 4137 | "band"); |
| 4138 | |
| 4139 | /* Operating class 115 - 5 GHz, channels 36-48 */ |
| 4140 | chan->reg_class[cla].reg_class = 115; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4141 | chan->reg_class[cla].channels = 0; |
| 4142 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 36 * 5)) |
| 4143 | wpas_p2p_add_chan(&chan->reg_class[cla], 36); |
| 4144 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 40 * 5)) |
| 4145 | wpas_p2p_add_chan(&chan->reg_class[cla], 40); |
| 4146 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 44 * 5)) |
| 4147 | wpas_p2p_add_chan(&chan->reg_class[cla], 44); |
| 4148 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 48 * 5)) |
| 4149 | wpas_p2p_add_chan(&chan->reg_class[cla], 48); |
| 4150 | if (chan->reg_class[cla].channels) |
| 4151 | cla++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4152 | |
| 4153 | wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for higher 5 GHz " |
| 4154 | "band"); |
| 4155 | |
| 4156 | /* Operating class 124 - 5 GHz, channels 149,153,157,161 */ |
| 4157 | chan->reg_class[cla].reg_class = 124; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4158 | chan->reg_class[cla].channels = 0; |
| 4159 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 149 * 5)) |
| 4160 | wpas_p2p_add_chan(&chan->reg_class[cla], 149); |
| 4161 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 153 * 5)) |
| 4162 | wpas_p2p_add_chan(&chan->reg_class[cla], 153); |
| 4163 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 156 * 5)) |
| 4164 | wpas_p2p_add_chan(&chan->reg_class[cla], 157); |
| 4165 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 161 * 5)) |
| 4166 | wpas_p2p_add_chan(&chan->reg_class[cla], 161); |
| 4167 | if (chan->reg_class[cla].channels) |
| 4168 | cla++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4169 | |
| 4170 | chan->reg_classes = cla; |
| 4171 | return 0; |
| 4172 | } |
| 4173 | |
| 4174 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4175 | static enum chan_allowed has_channel(struct wpa_global *global, |
| 4176 | struct hostapd_hw_modes *mode, u8 op_class, |
| 4177 | u8 chan, int *flags) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4178 | { |
| 4179 | int i; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4180 | unsigned int freq; |
| 4181 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4182 | freq = ieee80211_chan_to_freq(NULL, op_class, chan); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4183 | if (wpas_p2p_disallowed_freq(global, freq)) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4184 | return NOT_ALLOWED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4185 | |
| 4186 | for (i = 0; i < mode->num_channels; i++) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4187 | if ((unsigned int) mode->channels[i].freq == freq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4188 | if (flags) |
| 4189 | *flags = mode->channels[i].flag; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4190 | if (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4191 | return NOT_ALLOWED; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4192 | if (mode->channels[i].flag & HOSTAPD_CHAN_NO_IR) |
| 4193 | return NO_IR; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4194 | if (mode->channels[i].flag & HOSTAPD_CHAN_RADAR) |
| 4195 | return RADAR; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4196 | return ALLOWED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4197 | } |
| 4198 | } |
| 4199 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4200 | return NOT_ALLOWED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4201 | } |
| 4202 | |
| 4203 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4204 | static int wpas_p2p_get_center_80mhz(struct wpa_supplicant *wpa_s, |
| 4205 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4206 | u8 channel, const u8 *center_channels, |
| 4207 | size_t num_chan) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4208 | { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 4209 | size_t i; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4210 | |
| 4211 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 4212 | return 0; |
| 4213 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4214 | for (i = 0; i < num_chan; i++) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4215 | /* |
| 4216 | * In 80 MHz, the bandwidth "spans" 12 channels (e.g., 36-48), |
| 4217 | * so the center channel is 6 channels away from the start/end. |
| 4218 | */ |
| 4219 | if (channel >= center_channels[i] - 6 && |
| 4220 | channel <= center_channels[i] + 6) |
| 4221 | return center_channels[i]; |
| 4222 | |
| 4223 | return 0; |
| 4224 | } |
| 4225 | |
| 4226 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4227 | static const u8 center_channels_5ghz_80mhz[] = { 42, 58, 106, 122, 138, |
| 4228 | 155, 171 }; |
| 4229 | static const u8 center_channels_6ghz_80mhz[] = { 7, 23, 39, 55, 71, 87, 103, |
| 4230 | 119, 135, 151, 167, 183, 199, |
| 4231 | 215 }; |
| 4232 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4233 | static enum chan_allowed wpas_p2p_verify_80mhz(struct wpa_supplicant *wpa_s, |
| 4234 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4235 | u8 op_class, u8 channel, u8 bw) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4236 | { |
| 4237 | u8 center_chan; |
| 4238 | int i, flags; |
| 4239 | enum chan_allowed res, ret = ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4240 | const u8 *chans; |
| 4241 | size_t num_chans; |
| 4242 | bool is_6ghz = is_6ghz_op_class(op_class); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4243 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4244 | if (is_6ghz) { |
| 4245 | chans = center_channels_6ghz_80mhz; |
| 4246 | num_chans = ARRAY_SIZE(center_channels_6ghz_80mhz); |
| 4247 | } else { |
| 4248 | chans = center_channels_5ghz_80mhz; |
| 4249 | num_chans = ARRAY_SIZE(center_channels_5ghz_80mhz); |
| 4250 | } |
| 4251 | center_chan = wpas_p2p_get_center_80mhz(wpa_s, mode, channel, |
| 4252 | chans, num_chans); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4253 | if (!center_chan) |
| 4254 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4255 | if (!wpa_s->p2p_go_allow_dfs && |
| 4256 | !is_6ghz && center_chan >= 58 && center_chan <= 138) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4257 | return NOT_ALLOWED; /* Do not allow DFS channels for P2P */ |
| 4258 | |
| 4259 | /* check all the channels are available */ |
| 4260 | for (i = 0; i < 4; i++) { |
| 4261 | int adj_chan = center_chan - 6 + i * 4; |
| 4262 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4263 | res = has_channel(wpa_s->global, mode, op_class, adj_chan, |
| 4264 | &flags); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4265 | if (res == NOT_ALLOWED) |
| 4266 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4267 | if (res == RADAR) |
| 4268 | ret = RADAR; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4269 | if (res == NO_IR) |
| 4270 | ret = NO_IR; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4271 | if (!is_6ghz) { |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4272 | if (!(flags & HOSTAPD_CHAN_VHT_80MHZ_SUBCHANNEL)) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4273 | return NOT_ALLOWED; |
| 4274 | } else if (is_6ghz && |
| 4275 | (!(wpas_get_6ghz_he_chwidth_capab(mode) & |
| 4276 | HE_PHYCAP_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G))) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4277 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4278 | } |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4279 | } |
| 4280 | |
| 4281 | return ret; |
| 4282 | } |
| 4283 | |
| 4284 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4285 | static int wpas_p2p_get_center_160mhz(struct wpa_supplicant *wpa_s, |
| 4286 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4287 | u8 channel, const u8 *center_channels, |
| 4288 | size_t num_chan) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4289 | { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4290 | unsigned int i; |
| 4291 | |
| 4292 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 4293 | return 0; |
| 4294 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4295 | for (i = 0; i < num_chan; i++) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4296 | /* |
| 4297 | * In 160 MHz, the bandwidth "spans" 28 channels (e.g., 36-64), |
| 4298 | * so the center channel is 14 channels away from the start/end. |
| 4299 | */ |
| 4300 | if (channel >= center_channels[i] - 14 && |
| 4301 | channel <= center_channels[i] + 14) |
| 4302 | return center_channels[i]; |
| 4303 | |
| 4304 | return 0; |
| 4305 | } |
| 4306 | |
| 4307 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4308 | static const u8 center_channels_5ghz_160mhz[] = { 50, 114, 163 }; |
| 4309 | static const u8 center_channels_6ghz_160mhz[] = { 15, 47, 79, 111, 143, 175, |
| 4310 | 207 }; |
| 4311 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4312 | static enum chan_allowed wpas_p2p_verify_160mhz(struct wpa_supplicant *wpa_s, |
| 4313 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4314 | u8 op_class, u8 channel, u8 bw) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4315 | { |
| 4316 | u8 center_chan; |
| 4317 | int i, flags; |
| 4318 | enum chan_allowed res, ret = ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4319 | const u8 *chans; |
| 4320 | size_t num_chans; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4321 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4322 | if (is_6ghz_op_class(op_class)) { |
| 4323 | chans = center_channels_6ghz_160mhz; |
| 4324 | num_chans = ARRAY_SIZE(center_channels_6ghz_160mhz); |
| 4325 | } else { |
| 4326 | chans = center_channels_5ghz_160mhz; |
| 4327 | num_chans = ARRAY_SIZE(center_channels_5ghz_160mhz); |
| 4328 | } |
| 4329 | center_chan = wpas_p2p_get_center_160mhz(wpa_s, mode, channel, |
| 4330 | chans, num_chans); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4331 | if (!center_chan) |
| 4332 | return NOT_ALLOWED; |
| 4333 | /* VHT 160 MHz uses DFS channels in most countries. */ |
| 4334 | |
| 4335 | /* Check all the channels are available */ |
| 4336 | for (i = 0; i < 8; i++) { |
| 4337 | int adj_chan = center_chan - 14 + i * 4; |
| 4338 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4339 | res = has_channel(wpa_s->global, mode, op_class, adj_chan, |
| 4340 | &flags); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4341 | if (res == NOT_ALLOWED) |
| 4342 | return NOT_ALLOWED; |
| 4343 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4344 | if (res == RADAR) |
| 4345 | ret = RADAR; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4346 | if (res == NO_IR) |
| 4347 | ret = NO_IR; |
| 4348 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4349 | if (!is_6ghz_op_class(op_class)) { |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4350 | if (!(flags & HOSTAPD_CHAN_VHT_80MHZ_SUBCHANNEL) || |
| 4351 | !(flags & HOSTAPD_CHAN_VHT_160MHZ_SUBCHANNEL)) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4352 | return NOT_ALLOWED; |
| 4353 | } else if (is_6ghz_op_class(op_class) && |
| 4354 | (!(wpas_get_6ghz_he_chwidth_capab(mode) & |
| 4355 | HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G))) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4356 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4357 | } |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4358 | } |
| 4359 | |
| 4360 | return ret; |
| 4361 | } |
| 4362 | |
| 4363 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4364 | static enum chan_allowed wpas_p2p_verify_edmg(struct wpa_supplicant *wpa_s, |
| 4365 | struct hostapd_hw_modes *mode, |
| 4366 | u8 channel) |
| 4367 | { |
| 4368 | struct ieee80211_edmg_config edmg; |
| 4369 | |
| 4370 | hostapd_encode_edmg_chan(1, channel, 0, &edmg); |
| 4371 | if (edmg.channels && ieee802_edmg_is_allowed(mode->edmg, edmg)) |
| 4372 | return ALLOWED; |
| 4373 | |
| 4374 | return NOT_ALLOWED; |
| 4375 | } |
| 4376 | |
| 4377 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4378 | static enum chan_allowed wpas_p2p_verify_channel(struct wpa_supplicant *wpa_s, |
| 4379 | struct hostapd_hw_modes *mode, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4380 | u8 op_class, u8 channel, u8 bw) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4381 | { |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4382 | int flag = 0; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4383 | enum chan_allowed res, res2; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4384 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 4385 | if (is_6ghz_op_class(op_class) && !is_6ghz_psc_frequency( |
| 4386 | p2p_channel_to_freq(op_class, channel))) |
| 4387 | return NOT_ALLOWED; |
| 4388 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4389 | res2 = res = has_channel(wpa_s->global, mode, op_class, channel, &flag); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4390 | if (bw == BW40MINUS) { |
| 4391 | if (!(flag & HOSTAPD_CHAN_HT40MINUS)) |
| 4392 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4393 | res2 = has_channel(wpa_s->global, mode, op_class, channel - 4, |
| 4394 | NULL); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4395 | } else if (bw == BW40PLUS) { |
| 4396 | if (!(flag & HOSTAPD_CHAN_HT40PLUS)) |
| 4397 | return NOT_ALLOWED; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4398 | res2 = has_channel(wpa_s->global, mode, op_class, channel + 4, |
| 4399 | NULL); |
| 4400 | } else if (is_6ghz_op_class(op_class) && bw == BW40) { |
| 4401 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 4402 | return NOT_ALLOWED; |
| 4403 | if (get_6ghz_sec_channel(channel) < 0) |
| 4404 | res2 = has_channel(wpa_s->global, mode, op_class, |
| 4405 | channel - 4, NULL); |
| 4406 | else |
| 4407 | res2 = has_channel(wpa_s->global, mode, op_class, |
| 4408 | channel + 4, NULL); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4409 | } else if (bw == BW80) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4410 | res2 = wpas_p2p_verify_80mhz(wpa_s, mode, op_class, channel, |
| 4411 | bw); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4412 | } else if (bw == BW160) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4413 | res2 = wpas_p2p_verify_160mhz(wpa_s, mode, op_class, channel, |
| 4414 | bw); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4415 | } else if (bw == BW4320 || bw == BW6480 || bw == BW8640) { |
| 4416 | return wpas_p2p_verify_edmg(wpa_s, mode, channel); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4417 | } |
| 4418 | |
| 4419 | if (res == NOT_ALLOWED || res2 == NOT_ALLOWED) |
| 4420 | return NOT_ALLOWED; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4421 | if (res == NO_IR || res2 == NO_IR) |
| 4422 | return NO_IR; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4423 | if (res == RADAR || res2 == RADAR) |
| 4424 | return RADAR; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4425 | return res; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4426 | } |
| 4427 | |
| 4428 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4429 | static int wpas_p2p_setup_channels(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4430 | struct p2p_channels *chan, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4431 | struct p2p_channels *cli_chan, |
| 4432 | bool p2p_disable_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4433 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4434 | struct hostapd_hw_modes *mode; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4435 | int cla, op, cli_cla; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4436 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4437 | if (wpa_s->hw.modes == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4438 | wpa_printf(MSG_DEBUG, "P2P: Driver did not support fetching " |
| 4439 | "of all supported channels; assume dualband " |
| 4440 | "support"); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4441 | return wpas_p2p_default_channels(wpa_s, chan, cli_chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4442 | } |
| 4443 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4444 | cla = cli_cla = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4445 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4446 | for (op = 0; global_op_class[op].op_class; op++) { |
| 4447 | const struct oper_class_map *o = &global_op_class[op]; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4448 | unsigned int ch; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4449 | struct p2p_reg_class *reg = NULL, *cli_reg = NULL; |
Shuibing Dai | e2fad41 | 2023-05-05 14:08:11 -0700 | [diff] [blame] | 4450 | bool check_dfs_supported = (is_p2p_dfs_chan_enabled(wpa_s->global->p2p) |
Shuibing Dai | 64a8a89 | 2023-03-08 10:26:22 -0800 | [diff] [blame] | 4451 | && is_dfs_global_op_class(o->op_class)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4452 | |
Shuibing Dai | 64a8a89 | 2023-03-08 10:26:22 -0800 | [diff] [blame] | 4453 | if ((!check_dfs_supported && o->p2p == NO_P2P_SUPP) || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4454 | (is_6ghz_op_class(o->op_class) && p2p_disable_6ghz)) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4455 | continue; |
| 4456 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4457 | mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, o->mode, |
| 4458 | is_6ghz_op_class(o->op_class)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4459 | if (mode == NULL) |
| 4460 | continue; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4461 | if (mode->mode == HOSTAPD_MODE_IEEE80211G) |
| 4462 | wpa_s->global->p2p_24ghz_social_channels = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4463 | for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4464 | enum chan_allowed res; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4465 | |
| 4466 | /* Check for non-continuous jump in channel index |
| 4467 | * incrementation */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4468 | if ((o->op_class >= 128 && o->op_class <= 130) && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4469 | ch < 149 && ch + o->inc > 149) |
| 4470 | ch = 149; |
| 4471 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4472 | res = wpas_p2p_verify_channel(wpa_s, mode, o->op_class, |
| 4473 | ch, o->bw); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4474 | if (res == ALLOWED) { |
| 4475 | if (reg == NULL) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4476 | if (cla == P2P_MAX_REG_CLASSES) |
| 4477 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4478 | wpa_printf(MSG_DEBUG, "P2P: Add operating class %u", |
| 4479 | o->op_class); |
| 4480 | reg = &chan->reg_class[cla]; |
| 4481 | cla++; |
| 4482 | reg->reg_class = o->op_class; |
| 4483 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4484 | if (reg->channels == P2P_MAX_REG_CLASS_CHANNELS) |
| 4485 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4486 | reg->channel[reg->channels] = ch; |
| 4487 | reg->channels++; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4488 | } else if (res == NO_IR && |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4489 | wpa_s->conf->p2p_add_cli_chan) { |
| 4490 | if (cli_reg == NULL) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4491 | if (cli_cla == P2P_MAX_REG_CLASSES) |
| 4492 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4493 | wpa_printf(MSG_DEBUG, "P2P: Add operating class %u (client only)", |
| 4494 | o->op_class); |
| 4495 | cli_reg = &cli_chan->reg_class[cli_cla]; |
| 4496 | cli_cla++; |
| 4497 | cli_reg->reg_class = o->op_class; |
| 4498 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4499 | if (cli_reg->channels == |
| 4500 | P2P_MAX_REG_CLASS_CHANNELS) |
| 4501 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4502 | cli_reg->channel[cli_reg->channels] = ch; |
| 4503 | cli_reg->channels++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4504 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4505 | } |
| 4506 | if (reg) { |
| 4507 | wpa_hexdump(MSG_DEBUG, "P2P: Channels", |
| 4508 | reg->channel, reg->channels); |
| 4509 | } |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4510 | if (cli_reg) { |
| 4511 | wpa_hexdump(MSG_DEBUG, "P2P: Channels (client only)", |
| 4512 | cli_reg->channel, cli_reg->channels); |
| 4513 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4514 | } |
| 4515 | |
| 4516 | chan->reg_classes = cla; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4517 | cli_chan->reg_classes = cli_cla; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4518 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4519 | return 0; |
| 4520 | } |
| 4521 | |
| 4522 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4523 | int wpas_p2p_get_sec_channel_offset_40mhz(struct wpa_supplicant *wpa_s, |
| 4524 | struct hostapd_hw_modes *mode, |
| 4525 | u8 channel) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4526 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4527 | int op; |
| 4528 | enum chan_allowed ret; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4529 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4530 | for (op = 0; global_op_class[op].op_class; op++) { |
| 4531 | const struct oper_class_map *o = &global_op_class[op]; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4532 | u16 ch = 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4533 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4534 | /* Allow DFS channels marked as NO_P2P_SUPP to be used with |
| 4535 | * driver offloaded DFS. */ |
| 4536 | if ((o->p2p == NO_P2P_SUPP && |
| 4537 | (!is_dfs_global_op_class(o->op_class) || |
| 4538 | !wpa_s->p2p_go_allow_dfs)) || |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4539 | (is_6ghz_op_class(o->op_class) && |
| 4540 | wpa_s->conf->p2p_6ghz_disable)) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4541 | continue; |
| 4542 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4543 | /* IEEE Std 802.11ax-2021 26.17.2.3.2: "A 6 GHz-only AP should |
| 4544 | * set up the BSS with a primary 20 MHz channel that coincides |
| 4545 | * with a preferred scanning channel (PSC)." |
| 4546 | * 6 GHz BW40 operation class 132 in wpa_supplicant uses the |
| 4547 | * lowest 20 MHz channel for simplicity, so increase ch by 4 to |
| 4548 | * match the PSC. |
| 4549 | */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4550 | if (is_6ghz_op_class(o->op_class) && o->bw == BW40 && |
| 4551 | get_6ghz_sec_channel(channel) < 0) |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4552 | ch = 4; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4553 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4554 | for (ch += o->min_chan; ch <= o->max_chan; ch += o->inc) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4555 | if (o->mode != HOSTAPD_MODE_IEEE80211A || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4556 | (o->bw != BW40PLUS && o->bw != BW40MINUS && |
| 4557 | o->bw != BW40) || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4558 | ch != channel) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4559 | continue; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4560 | ret = wpas_p2p_verify_channel(wpa_s, mode, o->op_class, |
| 4561 | ch, o->bw); |
| 4562 | if (ret == ALLOWED) { |
| 4563 | if (is_6ghz_op_class(o->op_class) && |
| 4564 | o->bw == BW40) |
| 4565 | return get_6ghz_sec_channel(channel); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4566 | return (o->bw == BW40MINUS) ? -1 : 1; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4567 | } |
| 4568 | if (ret == RADAR && wpa_s->p2p_go_allow_dfs) { |
| 4569 | /* Allow RADAR channels used for driver |
| 4570 | * offloaded DFS */ |
| 4571 | return (o->bw == BW40MINUS) ? -1 : 1; |
| 4572 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4573 | } |
| 4574 | } |
| 4575 | return 0; |
| 4576 | } |
| 4577 | |
| 4578 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4579 | int wpas_p2p_get_vht80_center(struct wpa_supplicant *wpa_s, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4580 | struct hostapd_hw_modes *mode, u8 channel, |
| 4581 | u8 op_class) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4582 | { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4583 | const u8 *chans; |
| 4584 | size_t num_chans; |
| 4585 | enum chan_allowed ret; |
| 4586 | |
| 4587 | ret = wpas_p2p_verify_channel(wpa_s, mode, op_class, channel, BW80); |
| 4588 | if (!(ret == ALLOWED || (ret == RADAR && wpa_s->p2p_go_allow_dfs))) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4589 | return 0; |
| 4590 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4591 | if (is_6ghz_op_class(op_class)) { |
| 4592 | chans = center_channels_6ghz_80mhz; |
| 4593 | num_chans = ARRAY_SIZE(center_channels_6ghz_80mhz); |
| 4594 | } else { |
| 4595 | chans = center_channels_5ghz_80mhz; |
| 4596 | num_chans = ARRAY_SIZE(center_channels_5ghz_80mhz); |
| 4597 | } |
| 4598 | return wpas_p2p_get_center_80mhz(wpa_s, mode, channel, |
| 4599 | chans, num_chans); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4603 | int wpas_p2p_get_vht160_center(struct wpa_supplicant *wpa_s, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4604 | struct hostapd_hw_modes *mode, u8 channel, |
| 4605 | u8 op_class) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4606 | { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4607 | const u8 *chans; |
| 4608 | size_t num_chans; |
| 4609 | enum chan_allowed ret; |
| 4610 | |
| 4611 | ret = wpas_p2p_verify_channel(wpa_s, mode, op_class, channel, BW160); |
| 4612 | if (!(ret == ALLOWED || (ret == RADAR && wpa_s->p2p_go_allow_dfs))) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4613 | return 0; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4614 | if (is_6ghz_op_class(op_class)) { |
| 4615 | chans = center_channels_6ghz_160mhz; |
| 4616 | num_chans = ARRAY_SIZE(center_channels_6ghz_160mhz); |
| 4617 | } else { |
| 4618 | chans = center_channels_5ghz_160mhz; |
| 4619 | num_chans = ARRAY_SIZE(center_channels_5ghz_160mhz); |
| 4620 | } |
| 4621 | return wpas_p2p_get_center_160mhz(wpa_s, mode, channel, |
| 4622 | chans, num_chans); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4623 | } |
| 4624 | |
| 4625 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4626 | static int wpas_get_noa(void *ctx, const u8 *interface_addr, u8 *buf, |
| 4627 | size_t buf_len) |
| 4628 | { |
| 4629 | struct wpa_supplicant *wpa_s = ctx; |
| 4630 | |
| 4631 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4632 | if (ether_addr_equal(wpa_s->own_addr, interface_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4633 | break; |
| 4634 | } |
| 4635 | if (wpa_s == NULL) |
| 4636 | return -1; |
| 4637 | |
| 4638 | return wpa_drv_get_noa(wpa_s, buf, buf_len); |
| 4639 | } |
| 4640 | |
| 4641 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4642 | struct wpa_supplicant * wpas_get_p2p_go_iface(struct wpa_supplicant *wpa_s, |
| 4643 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4644 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4645 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 4646 | struct wpa_ssid *s = wpa_s->current_ssid; |
| 4647 | if (s == NULL) |
| 4648 | continue; |
| 4649 | if (s->mode != WPAS_MODE_P2P_GO && |
| 4650 | s->mode != WPAS_MODE_AP && |
| 4651 | s->mode != WPAS_MODE_P2P_GROUP_FORMATION) |
| 4652 | continue; |
| 4653 | if (s->ssid_len != ssid_len || |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 4654 | os_memcmp(ssid, s->ssid, ssid_len) != 0) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4655 | continue; |
| 4656 | return wpa_s; |
| 4657 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4658 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4659 | return NULL; |
| 4660 | |
| 4661 | } |
| 4662 | |
| 4663 | |
| 4664 | struct wpa_supplicant * wpas_get_p2p_client_iface(struct wpa_supplicant *wpa_s, |
| 4665 | const u8 *peer_dev_addr) |
| 4666 | { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4667 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 4668 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4669 | if (ssid && (ssid->mode != WPAS_MODE_INFRA || !ssid->p2p_group)) |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4670 | continue; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4671 | if (ether_addr_equal(wpa_s->go_dev_addr, peer_dev_addr)) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4672 | return wpa_s; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4673 | } |
| 4674 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4675 | return NULL; |
| 4676 | } |
| 4677 | |
| 4678 | |
| 4679 | static int wpas_go_connected(void *ctx, const u8 *dev_addr) |
| 4680 | { |
| 4681 | struct wpa_supplicant *wpa_s = ctx; |
| 4682 | |
| 4683 | return wpas_get_p2p_client_iface(wpa_s, dev_addr) != NULL; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4684 | } |
| 4685 | |
| 4686 | |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 4687 | static int wpas_is_concurrent_session_active(void *ctx) |
| 4688 | { |
| 4689 | struct wpa_supplicant *wpa_s = ctx; |
| 4690 | struct wpa_supplicant *ifs; |
| 4691 | |
| 4692 | for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) { |
| 4693 | if (ifs == wpa_s) |
| 4694 | continue; |
| 4695 | if (ifs->wpa_state > WPA_ASSOCIATED) |
| 4696 | return 1; |
| 4697 | } |
| 4698 | return 0; |
| 4699 | } |
| 4700 | |
| 4701 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 4702 | static void wpas_p2p_debug_print(void *ctx, int level, const char *msg) |
| 4703 | { |
| 4704 | struct wpa_supplicant *wpa_s = ctx; |
| 4705 | wpa_msg_global(wpa_s, level, "P2P: %s", msg); |
| 4706 | } |
| 4707 | |
| 4708 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4709 | int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s, |
| 4710 | const char *conf_p2p_dev) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4711 | { |
| 4712 | struct wpa_interface iface; |
| 4713 | struct wpa_supplicant *p2pdev_wpa_s; |
| 4714 | char ifname[100]; |
| 4715 | char force_name[100]; |
| 4716 | int ret; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4717 | const u8 *if_addr = NULL; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4718 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4719 | ret = os_snprintf(ifname, sizeof(ifname), P2P_MGMT_DEVICE_PREFIX "%s", |
| 4720 | wpa_s->ifname); |
| 4721 | if (os_snprintf_error(sizeof(ifname), ret)) |
| 4722 | return -1; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4723 | /* Cut length at the maximum size. Note that we don't need to ensure |
| 4724 | * collision free names here as the created interface is not a netdev. |
| 4725 | */ |
| 4726 | ifname[IFNAMSIZ - 1] = '\0'; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4727 | force_name[0] = '\0'; |
| 4728 | wpa_s->pending_interface_type = WPA_IF_P2P_DEVICE; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4729 | |
| 4730 | if (wpa_s->conf->p2p_device_random_mac_addr == 2 && |
| 4731 | !is_zero_ether_addr(wpa_s->conf->p2p_device_persistent_mac_addr)) |
| 4732 | if_addr = wpa_s->conf->p2p_device_persistent_mac_addr; |
| 4733 | |
| 4734 | 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] | 4735 | force_name, wpa_s->pending_interface_addr, NULL); |
| 4736 | if (ret < 0) { |
| 4737 | wpa_printf(MSG_DEBUG, "P2P: Failed to create P2P Device interface"); |
| 4738 | return ret; |
| 4739 | } |
| 4740 | os_strlcpy(wpa_s->pending_interface_name, ifname, |
| 4741 | sizeof(wpa_s->pending_interface_name)); |
| 4742 | |
| 4743 | os_memset(&iface, 0, sizeof(iface)); |
| 4744 | iface.p2p_mgmt = 1; |
| 4745 | iface.ifname = wpa_s->pending_interface_name; |
| 4746 | iface.driver = wpa_s->driver->name; |
| 4747 | iface.driver_param = wpa_s->conf->driver_param; |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4748 | |
| 4749 | /* |
| 4750 | * If a P2P Device configuration file was given, use it as the interface |
| 4751 | * configuration file (instead of using parent's configuration file. |
| 4752 | */ |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4753 | if (conf_p2p_dev) { |
| 4754 | iface.confname = conf_p2p_dev; |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4755 | iface.ctrl_interface = NULL; |
| 4756 | } else { |
| 4757 | iface.confname = wpa_s->confname; |
| 4758 | iface.ctrl_interface = wpa_s->conf->ctrl_interface; |
| 4759 | } |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4760 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4761 | 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] | 4762 | if (!p2pdev_wpa_s) { |
| 4763 | wpa_printf(MSG_DEBUG, "P2P: Failed to add P2P Device interface"); |
| 4764 | return -1; |
| 4765 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4766 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4767 | p2pdev_wpa_s->p2pdev = p2pdev_wpa_s; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4768 | wpa_s->pending_interface_name[0] = '\0'; |
| 4769 | return 0; |
| 4770 | } |
| 4771 | |
| 4772 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4773 | static void wpas_presence_resp(void *ctx, const u8 *src, u8 status, |
| 4774 | const u8 *noa, size_t noa_len) |
| 4775 | { |
| 4776 | struct wpa_supplicant *wpa_s, *intf = ctx; |
| 4777 | char hex[100]; |
| 4778 | |
| 4779 | for (wpa_s = intf->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 4780 | if (wpa_s->waiting_presence_resp) |
| 4781 | break; |
| 4782 | } |
| 4783 | if (!wpa_s) { |
| 4784 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No group interface was waiting for presence response"); |
| 4785 | return; |
| 4786 | } |
| 4787 | wpa_s->waiting_presence_resp = 0; |
| 4788 | |
| 4789 | wpa_snprintf_hex(hex, sizeof(hex), noa, noa_len); |
| 4790 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PRESENCE_RESPONSE "src=" MACSTR |
| 4791 | " status=%u noa=%s", MAC2STR(src), status, hex); |
| 4792 | } |
| 4793 | |
| 4794 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4795 | static int wpas_get_persistent_group(void *ctx, const u8 *addr, const u8 *ssid, |
| 4796 | size_t ssid_len, u8 *go_dev_addr, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4797 | u8 *ret_ssid, size_t *ret_ssid_len, |
| 4798 | u8 *intended_iface_addr) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4799 | { |
| 4800 | struct wpa_supplicant *wpa_s = ctx; |
| 4801 | struct wpa_ssid *s; |
| 4802 | |
| 4803 | s = wpas_p2p_get_persistent(wpa_s, addr, ssid, ssid_len); |
| 4804 | if (s) { |
| 4805 | os_memcpy(ret_ssid, s->ssid, s->ssid_len); |
| 4806 | *ret_ssid_len = s->ssid_len; |
| 4807 | os_memcpy(go_dev_addr, s->bssid, ETH_ALEN); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4808 | |
| 4809 | if (s->mode != WPAS_MODE_P2P_GO) { |
| 4810 | os_memset(intended_iface_addr, 0, ETH_ALEN); |
| 4811 | } else if (wpas_p2p_create_iface(wpa_s)) { |
| 4812 | if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO)) |
| 4813 | return 0; |
| 4814 | |
| 4815 | os_memcpy(intended_iface_addr, |
| 4816 | wpa_s->pending_interface_addr, ETH_ALEN); |
| 4817 | } else { |
| 4818 | os_memcpy(intended_iface_addr, wpa_s->own_addr, |
| 4819 | ETH_ALEN); |
| 4820 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4821 | return 1; |
| 4822 | } |
| 4823 | |
| 4824 | return 0; |
| 4825 | } |
| 4826 | |
| 4827 | |
| 4828 | static int wpas_get_go_info(void *ctx, u8 *intended_addr, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4829 | u8 *ssid, size_t *ssid_len, int *group_iface, |
| 4830 | unsigned int *freq) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4831 | { |
| 4832 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4833 | struct wpa_supplicant *go; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4834 | struct wpa_ssid *s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4835 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4836 | /* |
| 4837 | * group_iface will be set to 1 only if a dedicated interface for P2P |
| 4838 | * role is required. First, we try to reuse an active GO. However, |
| 4839 | * if it is not present, we will try to reactivate an existing |
| 4840 | * persistent group and set group_iface to 1, so the caller will know |
| 4841 | * that the pending interface should be used. |
| 4842 | */ |
| 4843 | *group_iface = 0; |
| 4844 | |
| 4845 | if (freq) |
| 4846 | *freq = 0; |
| 4847 | |
| 4848 | go = wpas_p2p_get_go_group(wpa_s); |
| 4849 | if (!go) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4850 | s = wpas_p2p_get_persistent_go(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4851 | *group_iface = wpas_p2p_create_iface(wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4852 | if (s) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4853 | os_memcpy(intended_addr, s->bssid, ETH_ALEN); |
| 4854 | else |
| 4855 | return 0; |
| 4856 | } else { |
| 4857 | s = go->current_ssid; |
| 4858 | os_memcpy(intended_addr, go->own_addr, ETH_ALEN); |
| 4859 | if (freq) |
| 4860 | *freq = go->assoc_freq; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4861 | } |
| 4862 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4863 | os_memcpy(ssid, s->ssid, s->ssid_len); |
| 4864 | *ssid_len = s->ssid_len; |
| 4865 | |
| 4866 | return 1; |
| 4867 | } |
| 4868 | |
| 4869 | |
| 4870 | static int wpas_remove_stale_groups(void *ctx, const u8 *peer, const u8 *go, |
| 4871 | const u8 *ssid, size_t ssid_len) |
| 4872 | { |
| 4873 | struct wpa_supplicant *wpa_s = ctx; |
| 4874 | struct wpa_ssid *s; |
| 4875 | int save_config = 0; |
| 4876 | size_t i; |
| 4877 | |
| 4878 | /* Start with our first choice of Persistent Groups */ |
| 4879 | while ((s = wpas_p2p_get_persistent(wpa_s, peer, NULL, 0))) { |
| 4880 | if (go && ssid && ssid_len && |
| 4881 | s->ssid_len == ssid_len && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4882 | ether_addr_equal(go, s->bssid) && |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4883 | os_memcmp(ssid, s->ssid, ssid_len) == 0) |
| 4884 | break; |
| 4885 | |
| 4886 | /* Remove stale persistent group */ |
| 4887 | if (s->mode != WPAS_MODE_P2P_GO || s->num_p2p_clients <= 1) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4888 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4889 | "P2P: Remove stale persistent group id=%d", |
| 4890 | s->id); |
| 4891 | wpas_notify_persistent_group_removed(wpa_s, s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4892 | wpa_config_remove_network(wpa_s->conf, s->id); |
| 4893 | save_config = 1; |
| 4894 | continue; |
| 4895 | } |
| 4896 | |
| 4897 | for (i = 0; i < s->num_p2p_clients; i++) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 4898 | if (!ether_addr_equal(s->p2p_client_list + |
| 4899 | i * 2 * ETH_ALEN, peer)) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4900 | continue; |
| 4901 | |
| 4902 | os_memmove(s->p2p_client_list + i * 2 * ETH_ALEN, |
| 4903 | s->p2p_client_list + (i + 1) * 2 * ETH_ALEN, |
| 4904 | (s->num_p2p_clients - i - 1) * 2 * ETH_ALEN); |
| 4905 | break; |
| 4906 | } |
| 4907 | s->num_p2p_clients--; |
| 4908 | save_config = 1; |
| 4909 | } |
| 4910 | |
| 4911 | if (save_config) |
| 4912 | p2p_config_write(wpa_s); |
| 4913 | |
| 4914 | /* Return TRUE if valid SSID remains */ |
| 4915 | return s != NULL; |
| 4916 | } |
| 4917 | |
| 4918 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4919 | static void wpas_p2ps_get_feat_cap_str(char *buf, size_t buf_len, |
| 4920 | const u8 *feat_cap, size_t feat_cap_len) |
| 4921 | { |
| 4922 | static const char pref[] = " feature_cap="; |
| 4923 | int ret; |
| 4924 | |
| 4925 | buf[0] = '\0'; |
| 4926 | |
| 4927 | /* |
| 4928 | * We expect a feature capability to contain at least one byte to be |
| 4929 | * reported. The string buffer provided by the caller function is |
| 4930 | * expected to be big enough to contain all bytes of the attribute for |
| 4931 | * known specifications. This function truncates the reported bytes if |
| 4932 | * the feature capability data exceeds the string buffer size. |
| 4933 | */ |
| 4934 | if (!feat_cap || !feat_cap_len || buf_len < sizeof(pref) + 2) |
| 4935 | return; |
| 4936 | |
| 4937 | os_memcpy(buf, pref, sizeof(pref)); |
| 4938 | ret = wpa_snprintf_hex(&buf[sizeof(pref) - 1], |
| 4939 | buf_len - sizeof(pref) + 1, |
| 4940 | feat_cap, feat_cap_len); |
| 4941 | |
| 4942 | if (ret != (2 * (int) feat_cap_len)) |
| 4943 | wpa_printf(MSG_WARNING, "P2PS feature_cap bytes truncated"); |
| 4944 | } |
| 4945 | |
| 4946 | |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 4947 | static void wpas_p2ps_prov_complete(void *ctx, enum p2p_status_code status, |
| 4948 | const u8 *dev, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4949 | const u8 *adv_mac, const u8 *ses_mac, |
| 4950 | const u8 *grp_mac, u32 adv_id, u32 ses_id, |
| 4951 | u8 conncap, int passwd_id, |
| 4952 | const u8 *persist_ssid, |
| 4953 | size_t persist_ssid_size, int response_done, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4954 | int prov_start, const char *session_info, |
| 4955 | const u8 *feat_cap, size_t feat_cap_len, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4956 | unsigned int freq, |
| 4957 | const u8 *group_ssid, size_t group_ssid_len) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4958 | { |
| 4959 | struct wpa_supplicant *wpa_s = ctx; |
| 4960 | u8 mac[ETH_ALEN]; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4961 | struct wpa_ssid *persistent_go, *stale, *s = NULL; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4962 | int save_config = 0; |
| 4963 | struct wpa_supplicant *go_wpa_s; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4964 | char feat_cap_str[256]; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4965 | |
| 4966 | if (!dev) |
| 4967 | return; |
| 4968 | |
| 4969 | os_memset(mac, 0, ETH_ALEN); |
| 4970 | if (!adv_mac) |
| 4971 | adv_mac = mac; |
| 4972 | if (!ses_mac) |
| 4973 | ses_mac = mac; |
| 4974 | if (!grp_mac) |
| 4975 | grp_mac = mac; |
| 4976 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4977 | wpas_p2ps_get_feat_cap_str(feat_cap_str, sizeof(feat_cap_str), |
| 4978 | feat_cap, feat_cap_len); |
| 4979 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4980 | if (prov_start) { |
| 4981 | if (session_info == NULL) { |
| 4982 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4983 | P2P_EVENT_P2PS_PROVISION_START MACSTR |
| 4984 | " adv_id=%x conncap=%x" |
| 4985 | " adv_mac=" MACSTR |
| 4986 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4987 | " dev_passwd_id=%d%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4988 | MAC2STR(dev), adv_id, conncap, |
| 4989 | MAC2STR(adv_mac), |
| 4990 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4991 | passwd_id, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4992 | } else { |
| 4993 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4994 | P2P_EVENT_P2PS_PROVISION_START MACSTR |
| 4995 | " adv_id=%x conncap=%x" |
| 4996 | " adv_mac=" MACSTR |
| 4997 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4998 | " dev_passwd_id=%d info='%s'%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4999 | MAC2STR(dev), adv_id, conncap, |
| 5000 | MAC2STR(adv_mac), |
| 5001 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5002 | passwd_id, session_info, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5003 | } |
| 5004 | return; |
| 5005 | } |
| 5006 | |
| 5007 | go_wpa_s = wpas_p2p_get_go_group(wpa_s); |
| 5008 | persistent_go = wpas_p2p_get_persistent_go(wpa_s); |
| 5009 | |
| 5010 | if (status && status != P2P_SC_SUCCESS_DEFERRED) { |
| 5011 | if (go_wpa_s && !p2p_group_go_member_count(wpa_s)) |
| 5012 | wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname); |
| 5013 | |
| 5014 | if (persistent_go && !persistent_go->num_p2p_clients) { |
| 5015 | /* remove empty persistent GO */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5016 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 5017 | "P2P: Remove empty persistent group id=%d", |
| 5018 | persistent_go->id); |
| 5019 | wpas_notify_persistent_group_removed(wpa_s, |
| 5020 | persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5021 | wpa_config_remove_network(wpa_s->conf, |
| 5022 | persistent_go->id); |
| 5023 | } |
| 5024 | |
| 5025 | wpa_msg_global(wpa_s, MSG_INFO, |
| 5026 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 5027 | " status=%d" |
| 5028 | " adv_id=%x adv_mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5029 | " session=%x mac=" MACSTR "%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5030 | MAC2STR(dev), status, |
| 5031 | adv_id, MAC2STR(adv_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5032 | ses_id, MAC2STR(ses_mac), feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5033 | return; |
| 5034 | } |
| 5035 | |
| 5036 | /* Clean up stale persistent groups with this device */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5037 | if (persist_ssid && persist_ssid_size) |
| 5038 | s = wpas_p2p_get_persistent(wpa_s, dev, persist_ssid, |
| 5039 | persist_ssid_size); |
| 5040 | |
| 5041 | if (persist_ssid && s && s->mode != WPAS_MODE_P2P_GO && |
| 5042 | is_zero_ether_addr(grp_mac)) { |
| 5043 | wpa_dbg(wpa_s, MSG_ERROR, |
| 5044 | "P2P: Peer device is a GO in a persistent group, but it did not provide the intended MAC address"); |
| 5045 | return; |
| 5046 | } |
| 5047 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5048 | for (;;) { |
| 5049 | stale = wpas_p2p_get_persistent(wpa_s, dev, NULL, 0); |
| 5050 | if (!stale) |
| 5051 | break; |
| 5052 | |
| 5053 | if (s && s->ssid_len == stale->ssid_len && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5054 | ether_addr_equal(stale->bssid, s->bssid) && |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5055 | os_memcmp(stale->ssid, s->ssid, s->ssid_len) == 0) |
| 5056 | break; |
| 5057 | |
| 5058 | /* Remove stale persistent group */ |
| 5059 | if (stale->mode != WPAS_MODE_P2P_GO || |
| 5060 | stale->num_p2p_clients <= 1) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5061 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 5062 | "P2P: Remove stale persistent group id=%d", |
| 5063 | stale->id); |
| 5064 | wpas_notify_persistent_group_removed(wpa_s, stale); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5065 | wpa_config_remove_network(wpa_s->conf, stale->id); |
| 5066 | } else { |
| 5067 | size_t i; |
| 5068 | |
| 5069 | for (i = 0; i < stale->num_p2p_clients; i++) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 5070 | if (ether_addr_equal(stale->p2p_client_list + |
| 5071 | i * ETH_ALEN, dev)) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5072 | os_memmove(stale->p2p_client_list + |
| 5073 | i * ETH_ALEN, |
| 5074 | stale->p2p_client_list + |
| 5075 | (i + 1) * ETH_ALEN, |
| 5076 | (stale->num_p2p_clients - |
| 5077 | i - 1) * ETH_ALEN); |
| 5078 | break; |
| 5079 | } |
| 5080 | } |
| 5081 | stale->num_p2p_clients--; |
| 5082 | } |
| 5083 | save_config = 1; |
| 5084 | } |
| 5085 | |
| 5086 | if (save_config) |
| 5087 | p2p_config_write(wpa_s); |
| 5088 | |
| 5089 | if (s) { |
| 5090 | if (go_wpa_s && !p2p_group_go_member_count(wpa_s)) |
| 5091 | wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname); |
| 5092 | |
| 5093 | if (persistent_go && s != persistent_go && |
| 5094 | !persistent_go->num_p2p_clients) { |
| 5095 | /* remove empty persistent GO */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5096 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 5097 | "P2P: Remove empty persistent group id=%d", |
| 5098 | persistent_go->id); |
| 5099 | wpas_notify_persistent_group_removed(wpa_s, |
| 5100 | persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5101 | wpa_config_remove_network(wpa_s->conf, |
| 5102 | persistent_go->id); |
| 5103 | /* Save config */ |
| 5104 | } |
| 5105 | |
| 5106 | wpa_msg_global(wpa_s, MSG_INFO, |
| 5107 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 5108 | " status=%d" |
| 5109 | " adv_id=%x adv_mac=" MACSTR |
| 5110 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5111 | " persist=%d%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5112 | MAC2STR(dev), status, |
| 5113 | adv_id, MAC2STR(adv_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5114 | ses_id, MAC2STR(ses_mac), s->id, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5115 | return; |
| 5116 | } |
| 5117 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 5118 | wpa_s->global->pending_p2ps_group = 0; |
| 5119 | wpa_s->global->pending_p2ps_group_freq = 0; |
| 5120 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5121 | if (conncap == P2PS_SETUP_GROUP_OWNER) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5122 | /* |
| 5123 | * We need to copy the interface name. Simply saving a |
| 5124 | * pointer isn't enough, since if we use pending_interface_name |
| 5125 | * it will be overwritten when the group is added. |
| 5126 | */ |
| 5127 | char go_ifname[100]; |
| 5128 | |
| 5129 | go_ifname[0] = '\0'; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5130 | if (!go_wpa_s) { |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 5131 | if (!response_done) { |
| 5132 | wpa_s->global->pending_p2ps_group = 1; |
| 5133 | wpa_s->global->pending_p2ps_group_freq = freq; |
| 5134 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5135 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5136 | if (!wpas_p2p_create_iface(wpa_s)) |
| 5137 | os_memcpy(go_ifname, wpa_s->ifname, |
| 5138 | sizeof(go_ifname)); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5139 | else if (wpa_s->pending_interface_name[0]) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5140 | os_memcpy(go_ifname, |
| 5141 | wpa_s->pending_interface_name, |
| 5142 | sizeof(go_ifname)); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5143 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5144 | if (!go_ifname[0]) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5145 | wpas_p2ps_prov_complete( |
| 5146 | wpa_s, P2P_SC_FAIL_UNKNOWN_GROUP, |
| 5147 | dev, adv_mac, ses_mac, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5148 | grp_mac, adv_id, ses_id, 0, 0, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5149 | NULL, 0, 0, 0, NULL, NULL, 0, 0, |
| 5150 | NULL, 0); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5151 | return; |
| 5152 | } |
| 5153 | |
| 5154 | /* If PD Resp complete, start up the GO */ |
| 5155 | if (response_done && persistent_go) { |
| 5156 | wpas_p2p_group_add_persistent( |
| 5157 | wpa_s, persistent_go, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 5158 | 0, 0, freq, 0, 0, 0, 0, 0, 0, NULL, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5159 | persistent_go->mode == |
| 5160 | WPAS_MODE_P2P_GO ? |
| 5161 | P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 5162 | 0, 0, false, 0, NULL, NULL, NULL, NULL, |
| 5163 | 0); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5164 | } else if (response_done) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5165 | wpas_p2p_group_add(wpa_s, 1, freq, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 5166 | 0, 0, 0, 0, 0, 0, false, |
| 5167 | wpa_s->p2p2, |
| 5168 | WPA_P2P_MODE_WFD_R1); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5169 | } |
| 5170 | |
| 5171 | if (passwd_id == DEV_PW_P2PS_DEFAULT) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5172 | os_memcpy(wpa_s->p2ps_join_addr, grp_mac, |
| 5173 | ETH_ALEN); |
| 5174 | wpa_s->p2ps_method_config_any = 1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5175 | } |
| 5176 | } else if (passwd_id == DEV_PW_P2PS_DEFAULT) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5177 | os_memcpy(go_ifname, go_wpa_s->ifname, |
| 5178 | sizeof(go_ifname)); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5179 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5180 | if (is_zero_ether_addr(grp_mac)) { |
| 5181 | wpa_dbg(go_wpa_s, MSG_DEBUG, |
| 5182 | "P2P: Setting PIN-1 for ANY"); |
| 5183 | wpa_supplicant_ap_wps_pin(go_wpa_s, NULL, |
| 5184 | "12345670", NULL, 0, |
| 5185 | 0); |
| 5186 | } else { |
| 5187 | wpa_dbg(go_wpa_s, MSG_DEBUG, |
| 5188 | "P2P: Setting PIN-1 for " MACSTR, |
| 5189 | MAC2STR(grp_mac)); |
| 5190 | wpa_supplicant_ap_wps_pin(go_wpa_s, grp_mac, |
| 5191 | "12345670", NULL, 0, |
| 5192 | 0); |
| 5193 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5194 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5195 | os_memcpy(wpa_s->p2ps_join_addr, grp_mac, ETH_ALEN); |
| 5196 | wpa_s->p2ps_method_config_any = 1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5197 | } |
| 5198 | |
| 5199 | wpa_msg_global(wpa_s, MSG_INFO, |
| 5200 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 5201 | " status=%d conncap=%x" |
| 5202 | " adv_id=%x adv_mac=" MACSTR |
| 5203 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5204 | " dev_passwd_id=%d go=%s%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5205 | MAC2STR(dev), status, conncap, |
| 5206 | adv_id, MAC2STR(adv_mac), |
| 5207 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5208 | passwd_id, go_ifname, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5209 | return; |
| 5210 | } |
| 5211 | |
| 5212 | if (go_wpa_s && !p2p_group_go_member_count(wpa_s)) |
| 5213 | wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname); |
| 5214 | |
| 5215 | if (persistent_go && !persistent_go->num_p2p_clients) { |
| 5216 | /* remove empty persistent GO */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5217 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 5218 | "P2P: Remove empty persistent group id=%d", |
| 5219 | persistent_go->id); |
| 5220 | wpas_notify_persistent_group_removed(wpa_s, persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5221 | wpa_config_remove_network(wpa_s->conf, persistent_go->id); |
| 5222 | } |
| 5223 | |
| 5224 | if (conncap == P2PS_SETUP_CLIENT) { |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5225 | char ssid_hex[32 * 2 + 1]; |
| 5226 | |
| 5227 | if (group_ssid) |
| 5228 | wpa_snprintf_hex(ssid_hex, sizeof(ssid_hex), |
| 5229 | group_ssid, group_ssid_len); |
| 5230 | else |
| 5231 | ssid_hex[0] = '\0'; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5232 | wpa_msg_global(wpa_s, MSG_INFO, |
| 5233 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 5234 | " status=%d conncap=%x" |
| 5235 | " adv_id=%x adv_mac=" MACSTR |
| 5236 | " session=%x mac=" MACSTR |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5237 | " dev_passwd_id=%d join=" MACSTR "%s%s%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5238 | MAC2STR(dev), status, conncap, |
| 5239 | adv_id, MAC2STR(adv_mac), |
| 5240 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5241 | passwd_id, MAC2STR(grp_mac), feat_cap_str, |
| 5242 | group_ssid ? " group_ssid=" : "", ssid_hex); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5243 | } else { |
| 5244 | wpa_msg_global(wpa_s, MSG_INFO, |
| 5245 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 5246 | " status=%d conncap=%x" |
| 5247 | " adv_id=%x adv_mac=" MACSTR |
| 5248 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5249 | " dev_passwd_id=%d%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5250 | MAC2STR(dev), status, conncap, |
| 5251 | adv_id, MAC2STR(adv_mac), |
| 5252 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5253 | passwd_id, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5254 | } |
| 5255 | } |
| 5256 | |
| 5257 | |
Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 5258 | static int _wpas_p2p_in_progress(void *ctx) |
| 5259 | { |
| 5260 | struct wpa_supplicant *wpa_s = ctx; |
| 5261 | return wpas_p2p_in_progress(wpa_s); |
| 5262 | } |
| 5263 | |
| 5264 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5265 | static int wpas_prov_disc_resp_cb(void *ctx) |
| 5266 | { |
| 5267 | struct wpa_supplicant *wpa_s = ctx; |
| 5268 | struct wpa_ssid *persistent_go; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5269 | unsigned int freq; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5270 | |
| 5271 | if (!wpa_s->global->pending_p2ps_group) |
| 5272 | return 0; |
| 5273 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5274 | freq = wpa_s->global->pending_p2ps_group_freq; |
| 5275 | wpa_s->global->pending_p2ps_group_freq = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5276 | wpa_s->global->pending_p2ps_group = 0; |
| 5277 | |
| 5278 | if (wpas_p2p_get_go_group(wpa_s)) |
| 5279 | return 0; |
| 5280 | persistent_go = wpas_p2p_get_persistent_go(wpa_s); |
| 5281 | |
| 5282 | if (persistent_go) { |
| 5283 | wpas_p2p_group_add_persistent( |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 5284 | wpa_s, persistent_go, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 5285 | NULL, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5286 | persistent_go->mode == WPAS_MODE_P2P_GO ? |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5287 | P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0, 0, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 5288 | is_p2p_allow_6ghz(wpa_s->global->p2p), 0, NULL, NULL, |
| 5289 | NULL, NULL, 0); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5290 | } else { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5291 | wpas_p2p_group_add(wpa_s, 1, freq, 0, 0, 0, 0, 0, 0, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 5292 | is_p2p_allow_6ghz(wpa_s->global->p2p), |
| 5293 | wpa_s->p2p2, WPA_P2P_MODE_WFD_R1); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5294 | } |
| 5295 | |
| 5296 | return 1; |
| 5297 | } |
| 5298 | |
| 5299 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5300 | static int wpas_p2p_get_pref_freq_list(void *ctx, int go, |
| 5301 | unsigned int *len, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5302 | struct weighted_pcl *freq_list) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5303 | { |
| 5304 | struct wpa_supplicant *wpa_s = ctx; |
| 5305 | |
| 5306 | return wpa_drv_get_pref_freq_list(wpa_s, go ? WPA_IF_P2P_GO : |
| 5307 | WPA_IF_P2P_CLIENT, len, freq_list); |
| 5308 | } |
| 5309 | |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 5310 | |
| 5311 | static void wpas_p2p_send_bootstrap_comeback(void *eloop_ctx, void *timeout_ctx) |
| 5312 | { |
| 5313 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 5314 | |
| 5315 | wpa_printf(MSG_DEBUG, "P2P2: Send bootstrapping comeback PD Request"); |
| 5316 | wpas_p2p_connect(wpa_s, wpa_s->p2p_bootstrap_dev_addr, wpa_s->p2p_pin, |
| 5317 | wpa_s->p2p_wps_method, wpa_s->p2p_persistent_group, 0, |
| 5318 | 0, 0, wpa_s->p2p_go_intent, wpa_s->p2p_connect_freq, |
| 5319 | wpa_s->p2p_go_vht_center_freq2, |
| 5320 | wpa_s->p2p_persistent_id, |
| 5321 | wpa_s->p2p_pd_before_go_neg, |
| 5322 | wpa_s->p2p_go_ht40, |
| 5323 | wpa_s->p2p_go_vht, |
| 5324 | wpa_s->p2p_go_max_oper_chwidth, |
| 5325 | wpa_s->p2p_go_he, |
| 5326 | wpa_s->p2p_go_edmg, |
| 5327 | NULL, 0, is_p2p_allow_6ghz(wpa_s->global->p2p), |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 5328 | wpa_s->p2p2, wpa_s->p2p_bootstrap, NULL, false); |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 5329 | } |
| 5330 | |
| 5331 | |
| 5332 | static void wpas_p2p_register_bootstrap_comeback(void *ctx, const u8 *addr, |
| 5333 | u16 comeback_after) |
| 5334 | { |
| 5335 | unsigned int timeout_us; |
| 5336 | struct wpa_supplicant *wpa_s = ctx; |
| 5337 | |
| 5338 | timeout_us = comeback_after * 1024; |
| 5339 | os_memcpy(wpa_s->p2p_bootstrap_dev_addr, addr, ETH_ALEN); |
| 5340 | |
| 5341 | eloop_cancel_timeout(wpas_p2p_send_bootstrap_comeback, wpa_s, NULL); |
| 5342 | eloop_register_timeout(0, timeout_us, wpas_p2p_send_bootstrap_comeback, |
| 5343 | wpa_s, NULL); |
| 5344 | } |
| 5345 | |
| 5346 | |
| 5347 | static void wpas_bootstrap_req_rx(void *ctx, const u8 *addr, |
| 5348 | u16 bootstrap_method) |
| 5349 | { |
| 5350 | struct wpa_supplicant *wpa_s = ctx; |
| 5351 | |
| 5352 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_BOOTSTRAP_REQUEST MACSTR |
| 5353 | " bootstrap_method=%u", MAC2STR(addr), bootstrap_method); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 5354 | |
| 5355 | wpas_notify_p2p_bootstrap_req(wpa_s, addr, bootstrap_method); |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 5356 | } |
| 5357 | |
| 5358 | |
| 5359 | static void wpas_bootstrap_completed(void *ctx, const u8 *addr, |
| 5360 | enum p2p_status_code status, int freq) |
| 5361 | { |
| 5362 | struct wpa_supplicant *wpa_s = ctx; |
| 5363 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 5364 | wpas_notify_p2p_bootstrap_completed(wpa_s, addr, status); |
| 5365 | |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 5366 | if (status) { |
| 5367 | wpa_msg_global(wpa_s, MSG_INFO, |
| 5368 | P2P_EVENT_BOOTSTRAP_FAILURE MACSTR " status=%d", |
| 5369 | MAC2STR(addr), status); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 5370 | return; |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 5371 | } |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 5372 | |
| 5373 | wpa_msg_global(wpa_s, MSG_INFO, |
| 5374 | P2P_EVENT_BOOTSTRAP_SUCCESS MACSTR " status=%d", |
| 5375 | MAC2STR(addr), status); |
| 5376 | |
| 5377 | #ifdef CONFIG_PASN |
| 5378 | wpas_p2p_initiate_pasn_auth(wpa_s, addr, freq); |
| 5379 | #endif /* CONFIG_PASN */ |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 5383 | static void wpas_validate_dira(void *ctx, const u8 *peer_addr, |
| 5384 | const u8 *dira, size_t dira_len) |
| 5385 | { |
| 5386 | struct wpa_supplicant *wpa_s = ctx; |
| 5387 | int ret; |
| 5388 | u8 tag[DEVICE_MAX_HASH_LEN]; |
| 5389 | struct wpa_dev_ik *ik; |
| 5390 | const u8 *addr[3]; |
| 5391 | size_t len[3]; |
| 5392 | const char *label = "DIR"; |
| 5393 | |
| 5394 | if (dira_len < 1 || dira[0] != DIRA_CIPHER_VERSION_128) { |
| 5395 | wpa_printf(MSG_ERROR, |
| 5396 | "P2P2: Unsupported DIRA cipher version %d", dira[0]); |
| 5397 | return; |
| 5398 | } |
| 5399 | |
| 5400 | if (dira_len < 1 + DEVICE_IDENTITY_NONCE_LEN + DEVICE_IDENTITY_TAG_LEN) |
| 5401 | { |
| 5402 | wpa_printf(MSG_INFO, "P2P2: Truncated DIRA (length %zu)", |
| 5403 | dira_len); |
| 5404 | return; |
| 5405 | } |
| 5406 | |
| 5407 | addr[0] = (const u8 *) label; |
| 5408 | len[0] = DIR_STR_LEN; |
| 5409 | addr[1] = peer_addr; |
| 5410 | len[1] = ETH_ALEN; |
| 5411 | addr[2] = &dira[1]; |
| 5412 | len[2] = DEVICE_IDENTITY_NONCE_LEN; |
| 5413 | |
| 5414 | for (ik = wpa_s->conf->identity; ik; ik = ik->next) { |
| 5415 | if (wpabuf_len(ik->dik) != DEVICE_IDENTITY_KEY_LEN || |
| 5416 | ik->dik_cipher != DIRA_CIPHER_VERSION_128) |
| 5417 | continue; |
| 5418 | |
| 5419 | ret = hmac_sha256_vector(wpabuf_head(ik->dik), |
| 5420 | DEVICE_IDENTITY_KEY_LEN, |
| 5421 | 3, addr, len, tag); |
| 5422 | if (ret < 0) { |
| 5423 | wpa_printf(MSG_ERROR, |
| 5424 | "P2P2: Failed to derive DIRA Tag"); |
| 5425 | return; |
| 5426 | } |
| 5427 | |
| 5428 | if (os_memcmp(tag, &dira[1 + DEVICE_IDENTITY_NONCE_LEN], |
| 5429 | DEVICE_IDENTITY_TAG_LEN) == 0) { |
| 5430 | wpa_printf(MSG_DEBUG, "P2P2: DIRA Tag matched"); |
| 5431 | break; |
| 5432 | } |
| 5433 | } |
| 5434 | |
| 5435 | if (!ik) |
| 5436 | return; |
| 5437 | |
| 5438 | #ifdef CONFIG_PASN |
| 5439 | p2p_pasn_pmksa_set_pmk(wpa_s->global->p2p, wpa_s->global->p2p_dev_addr, |
| 5440 | peer_addr, |
| 5441 | wpabuf_head(ik->pmk), wpabuf_len(ik->pmk), |
| 5442 | wpabuf_head(ik->pmkid)); |
| 5443 | #endif /* CONFIG_PASN */ |
| 5444 | } |
| 5445 | |
| 5446 | |
| 5447 | #ifdef CONFIG_PASN |
| 5448 | |
| 5449 | static int wpas_p2p_initiate_pasn_verify(struct wpa_supplicant *wpa_s, |
| 5450 | const u8 *peer, |
| 5451 | enum p2p_invite_role role, |
| 5452 | const u8 *bssid, const u8 *ssid, |
| 5453 | size_t ssid_len, |
| 5454 | unsigned int force_freq, |
| 5455 | const u8 *go_dev_addr, |
| 5456 | unsigned int pref_freq) |
| 5457 | { |
| 5458 | int freq; |
| 5459 | struct wpa_p2p_pasn_auth_work *awork; |
| 5460 | |
| 5461 | wpas_p2p_pasn_cancel_auth_work(wpa_s); |
| 5462 | wpa_s->p2p_pasn_auth_work = NULL; |
| 5463 | |
| 5464 | freq = p2p_get_listen_freq(wpa_s->global->p2p, peer); |
| 5465 | if (freq == -1) |
| 5466 | return -1; |
| 5467 | |
| 5468 | awork = os_zalloc(sizeof(*awork)); |
| 5469 | if (!awork) |
| 5470 | return -1; |
| 5471 | |
| 5472 | awork->verify = 1; |
| 5473 | awork->role = role; |
| 5474 | awork->freq = freq; |
| 5475 | awork->force_freq = force_freq; |
| 5476 | awork->pref_freq = pref_freq; |
| 5477 | os_memcpy(awork->peer_addr, peer, ETH_ALEN); |
| 5478 | if (go_dev_addr) |
| 5479 | os_memcpy(awork->go_dev_addr, go_dev_addr, ETH_ALEN); |
| 5480 | if (bssid) |
| 5481 | os_memcpy(awork->bssid, bssid, ETH_ALEN); |
| 5482 | if (ssid_len) { |
| 5483 | awork->ssid = os_zalloc(ssid_len); |
| 5484 | if (!awork->ssid) { |
| 5485 | os_free(awork); |
| 5486 | return -1; |
| 5487 | } |
| 5488 | os_memcpy(awork->ssid, ssid, ssid_len); |
| 5489 | awork->ssid_len = ssid_len; |
| 5490 | } |
| 5491 | |
| 5492 | if (radio_add_work(wpa_s, freq, "p2p-pasn-start-auth", 1, |
| 5493 | wpas_p2p_pasn_auth_start_cb, awork) < 0) { |
| 5494 | wpas_p2p_pasn_free_auth_work(awork); |
| 5495 | return -1; |
| 5496 | } |
| 5497 | |
| 5498 | wpa_printf(MSG_DEBUG, "P2P PASN: Auth work successfully added"); |
| 5499 | return 0; |
| 5500 | } |
| 5501 | |
| 5502 | |
| 5503 | static int wpas_p2p_pasn_send_mgmt(void *ctx, const u8 *data, size_t data_len, |
| 5504 | int noack, unsigned int freq, |
| 5505 | unsigned int wait) |
| 5506 | { |
| 5507 | struct wpa_supplicant *wpa_s = ctx; |
| 5508 | |
| 5509 | return wpa_drv_send_mlme(wpa_s, data, data_len, noack, freq, wait); |
| 5510 | } |
| 5511 | |
| 5512 | |
| 5513 | static int wpas_p2p_prepare_data_element(void *ctx, const u8 *peer_addr) |
| 5514 | { |
| 5515 | struct wpa_supplicant *wpa_s = ctx; |
| 5516 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 5517 | |
| 5518 | return p2p_prepare_data_element(p2p, peer_addr); |
| 5519 | } |
| 5520 | |
| 5521 | |
| 5522 | static int wpas_p2p_parse_data_element(void *ctx, const u8 *data, size_t len) |
| 5523 | { |
| 5524 | struct wpa_supplicant *wpa_s = ctx; |
| 5525 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 5526 | |
| 5527 | return p2p_parse_data_element(p2p, data, len); |
| 5528 | } |
| 5529 | |
| 5530 | #endif /* CONFIG_PASN */ |
| 5531 | |
| 5532 | |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 5533 | int wpas_p2p_mac_setup(struct wpa_supplicant *wpa_s) |
| 5534 | { |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 5535 | int ret = 0; |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 5536 | u8 addr[ETH_ALEN] = {0}; |
| 5537 | |
| 5538 | if (wpa_s->conf->p2p_device_random_mac_addr == 0) |
| 5539 | return 0; |
| 5540 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5541 | if (wpa_s->conf->p2p_device_random_mac_addr == 2) { |
| 5542 | if (is_zero_ether_addr( |
| 5543 | wpa_s->conf->p2p_device_persistent_mac_addr) && |
| 5544 | !is_zero_ether_addr(wpa_s->own_addr)) { |
| 5545 | os_memcpy(wpa_s->conf->p2p_device_persistent_mac_addr, |
| 5546 | wpa_s->own_addr, ETH_ALEN); |
| 5547 | } |
| 5548 | return 0; |
| 5549 | } |
| 5550 | |
| 5551 | if (!wpa_s->conf->ssid) { |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 5552 | if (random_mac_addr(addr) < 0) { |
| 5553 | wpa_msg(wpa_s, MSG_INFO, |
| 5554 | "Failed to generate random MAC address"); |
| 5555 | return -EINVAL; |
| 5556 | } |
| 5557 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 5558 | /* Store generated MAC address. */ |
| 5559 | os_memcpy(wpa_s->conf->p2p_device_persistent_mac_addr, addr, |
| 5560 | ETH_ALEN); |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 5561 | } else { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 5562 | /* If there are existing saved groups, restore last MAC address. |
| 5563 | * if there is no last used MAC address, the last one is |
| 5564 | * factory MAC. */ |
| 5565 | if (is_zero_ether_addr( |
| 5566 | wpa_s->conf->p2p_device_persistent_mac_addr)) |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 5567 | return 0; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 5568 | os_memcpy(addr, wpa_s->conf->p2p_device_persistent_mac_addr, |
| 5569 | ETH_ALEN); |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 5570 | wpa_msg(wpa_s, MSG_DEBUG, "Restore last used MAC address."); |
| 5571 | } |
| 5572 | |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 5573 | ret = wpa_drv_set_mac_addr(wpa_s, addr); |
| 5574 | |
| 5575 | if (ret < 0) { |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 5576 | wpa_msg(wpa_s, MSG_INFO, |
| 5577 | "Failed to set random MAC address"); |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 5578 | return ret; |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 5579 | } |
| 5580 | |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 5581 | ret = wpa_supplicant_update_mac_addr(wpa_s); |
| 5582 | |
| 5583 | if (ret < 0) { |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 5584 | wpa_msg(wpa_s, MSG_INFO, |
| 5585 | "Could not update MAC address information"); |
JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 5586 | return ret; |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 5587 | } |
| 5588 | |
| 5589 | wpa_msg(wpa_s, MSG_DEBUG, "Using random MAC address " MACSTR, |
| 5590 | MAC2STR(addr)); |
| 5591 | |
| 5592 | return 0; |
| 5593 | } |
| 5594 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5595 | /** |
| 5596 | * wpas_p2p_init - Initialize P2P module for %wpa_supplicant |
| 5597 | * @global: Pointer to global data from wpa_supplicant_init() |
| 5598 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 5599 | * Returns: 0 on success, -1 on failure |
| 5600 | */ |
| 5601 | int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s) |
| 5602 | { |
| 5603 | struct p2p_config p2p; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5604 | int i; |
| 5605 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 5606 | if (wpa_s->conf->p2p_disabled) |
| 5607 | return 0; |
| 5608 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5609 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE)) |
| 5610 | return 0; |
| 5611 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5612 | if (global->p2p) |
| 5613 | return 0; |
| 5614 | |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 5615 | if (wpas_p2p_mac_setup(wpa_s) < 0) { |
| 5616 | wpa_msg(wpa_s, MSG_ERROR, |
| 5617 | "Failed to initialize P2P random MAC address."); |
| 5618 | return -1; |
| 5619 | } |
| 5620 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5621 | os_memset(&p2p, 0, sizeof(p2p)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5622 | p2p.cb_ctx = wpa_s; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5623 | p2p.debug_print = wpas_p2p_debug_print; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5624 | p2p.p2p_scan = wpas_p2p_scan; |
| 5625 | p2p.send_action = wpas_send_action; |
| 5626 | p2p.send_action_done = wpas_send_action_done; |
| 5627 | p2p.go_neg_completed = wpas_go_neg_completed; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 5628 | p2p.set_go_security_config = wpas_set_go_security_config; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5629 | p2p.go_neg_req_rx = wpas_go_neg_req_rx; |
| 5630 | p2p.dev_found = wpas_dev_found; |
| 5631 | p2p.dev_lost = wpas_dev_lost; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5632 | p2p.find_stopped = wpas_find_stopped; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5633 | p2p.start_listen = wpas_start_listen; |
| 5634 | p2p.stop_listen = wpas_stop_listen; |
| 5635 | p2p.send_probe_resp = wpas_send_probe_resp; |
| 5636 | p2p.sd_request = wpas_sd_request; |
| 5637 | p2p.sd_response = wpas_sd_response; |
| 5638 | p2p.prov_disc_req = wpas_prov_disc_req; |
| 5639 | p2p.prov_disc_resp = wpas_prov_disc_resp; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5640 | p2p.prov_disc_fail = wpas_prov_disc_fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5641 | p2p.invitation_process = wpas_invitation_process; |
| 5642 | p2p.invitation_received = wpas_invitation_received; |
| 5643 | p2p.invitation_result = wpas_invitation_result; |
| 5644 | p2p.get_noa = wpas_get_noa; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5645 | p2p.go_connected = wpas_go_connected; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5646 | p2p.presence_resp = wpas_presence_resp; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 5647 | p2p.is_concurrent_session_active = wpas_is_concurrent_session_active; |
Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 5648 | p2p.is_p2p_in_progress = _wpas_p2p_in_progress; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5649 | p2p.get_persistent_group = wpas_get_persistent_group; |
| 5650 | p2p.get_go_info = wpas_get_go_info; |
| 5651 | p2p.remove_stale_groups = wpas_remove_stale_groups; |
| 5652 | p2p.p2ps_prov_complete = wpas_p2ps_prov_complete; |
| 5653 | p2p.prov_disc_resp_cb = wpas_prov_disc_resp_cb; |
| 5654 | p2p.p2ps_group_capability = p2ps_group_capability; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5655 | p2p.get_pref_freq_list = wpas_p2p_get_pref_freq_list; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5656 | p2p.p2p_6ghz_disable = wpa_s->conf->p2p_6ghz_disable; |
Shuibing Dai | e2fad41 | 2023-05-05 14:08:11 -0700 | [diff] [blame] | 5657 | p2p.p2p_dfs_chan_enable = wpa_s->conf->p2p_dfs_chan_enable; |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 5658 | p2p.register_bootstrap_comeback = wpas_p2p_register_bootstrap_comeback; |
| 5659 | p2p.bootstrap_req_rx = wpas_bootstrap_req_rx; |
| 5660 | p2p.bootstrap_completed = wpas_bootstrap_completed; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 5661 | p2p.validate_dira = wpas_validate_dira; |
| 5662 | #ifdef CONFIG_PASN |
| 5663 | p2p.pasn_send_mgmt = wpas_p2p_pasn_send_mgmt; |
| 5664 | p2p.prepare_data_element = wpas_p2p_prepare_data_element; |
| 5665 | p2p.parse_data_element = wpas_p2p_parse_data_element; |
| 5666 | #endif /* CONFIG_PASN */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5667 | |
| 5668 | 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] | 5669 | 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] | 5670 | p2p.dev_name = wpa_s->conf->device_name; |
| 5671 | p2p.manufacturer = wpa_s->conf->manufacturer; |
| 5672 | p2p.model_name = wpa_s->conf->model_name; |
| 5673 | p2p.model_number = wpa_s->conf->model_number; |
| 5674 | p2p.serial_number = wpa_s->conf->serial_number; |
| 5675 | if (wpa_s->wps) { |
| 5676 | os_memcpy(p2p.uuid, wpa_s->wps->uuid, 16); |
| 5677 | p2p.config_methods = wpa_s->wps->config_methods; |
| 5678 | } |
| 5679 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5680 | if (wpas_p2p_setup_channels(wpa_s, &p2p.channels, &p2p.cli_channels, |
| 5681 | p2p.p2p_6ghz_disable)) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5682 | wpa_printf(MSG_ERROR, |
| 5683 | "P2P: Failed to configure supported channel list"); |
| 5684 | return -1; |
| 5685 | } |
| 5686 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5687 | if (wpa_s->conf->p2p_listen_reg_class && |
| 5688 | wpa_s->conf->p2p_listen_channel) { |
| 5689 | p2p.reg_class = wpa_s->conf->p2p_listen_reg_class; |
| 5690 | p2p.channel = wpa_s->conf->p2p_listen_channel; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5691 | p2p.channel_forced = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5692 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5693 | /* |
| 5694 | * Pick one of the social channels randomly as the listen |
| 5695 | * channel. |
| 5696 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5697 | if (p2p_config_get_random_social(&p2p, &p2p.reg_class, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5698 | &p2p.channel, |
| 5699 | &global->p2p_go_avoid_freq, |
| 5700 | &global->p2p_disallow_freq) != |
| 5701 | 0) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 5702 | wpa_printf(MSG_INFO, |
| 5703 | "P2P: No social channels supported by the driver - do not enable P2P"); |
| 5704 | return 0; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5705 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5706 | p2p.channel_forced = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5707 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5708 | wpa_printf(MSG_DEBUG, "P2P: Own listen channel: %d:%d", |
| 5709 | p2p.reg_class, p2p.channel); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5710 | |
| 5711 | if (wpa_s->conf->p2p_oper_reg_class && |
| 5712 | wpa_s->conf->p2p_oper_channel) { |
| 5713 | p2p.op_reg_class = wpa_s->conf->p2p_oper_reg_class; |
| 5714 | p2p.op_channel = wpa_s->conf->p2p_oper_channel; |
| 5715 | p2p.cfg_op_channel = 1; |
| 5716 | wpa_printf(MSG_DEBUG, "P2P: Configured operating channel: " |
| 5717 | "%d:%d", p2p.op_reg_class, p2p.op_channel); |
| 5718 | |
| 5719 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5720 | /* |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5721 | * Use random operation channel from 2.4 GHz band social |
| 5722 | * channels (1, 6, 11) or band 60 GHz social channel (2) if no |
| 5723 | * other preference is indicated. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5724 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5725 | if (p2p_config_get_random_social(&p2p, &p2p.op_reg_class, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5726 | &p2p.op_channel, NULL, |
| 5727 | NULL) != 0) { |
| 5728 | wpa_printf(MSG_INFO, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5729 | "P2P: Failed to select random social channel as operation channel"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5730 | p2p.op_reg_class = 0; |
| 5731 | p2p.op_channel = 0; |
| 5732 | /* This will be overridden during group setup in |
| 5733 | * p2p_prepare_channel(), so allow setup to continue. */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5734 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5735 | p2p.cfg_op_channel = 0; |
| 5736 | wpa_printf(MSG_DEBUG, "P2P: Random operating channel: " |
| 5737 | "%d:%d", p2p.op_reg_class, p2p.op_channel); |
| 5738 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 5739 | |
| 5740 | if (wpa_s->conf->p2p_pref_chan && wpa_s->conf->num_p2p_pref_chan) { |
| 5741 | p2p.pref_chan = wpa_s->conf->p2p_pref_chan; |
| 5742 | p2p.num_pref_chan = wpa_s->conf->num_p2p_pref_chan; |
| 5743 | } |
| 5744 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5745 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) { |
| 5746 | os_memcpy(p2p.country, wpa_s->conf->country, 2); |
| 5747 | p2p.country[2] = 0x04; |
| 5748 | } else |
| 5749 | os_memcpy(p2p.country, "XX\x04", 3); |
| 5750 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5751 | os_memcpy(p2p.pri_dev_type, wpa_s->conf->device_type, |
| 5752 | WPS_DEV_TYPE_LEN); |
| 5753 | |
| 5754 | p2p.num_sec_dev_types = wpa_s->conf->num_sec_device_types; |
| 5755 | os_memcpy(p2p.sec_dev_type, wpa_s->conf->sec_device_type, |
| 5756 | p2p.num_sec_dev_types * WPS_DEV_TYPE_LEN); |
| 5757 | |
| 5758 | p2p.concurrent_operations = !!(wpa_s->drv_flags & |
| 5759 | WPA_DRIVER_FLAGS_P2P_CONCURRENT); |
| 5760 | |
| 5761 | p2p.max_peers = 100; |
| 5762 | |
| 5763 | if (wpa_s->conf->p2p_ssid_postfix) { |
| 5764 | p2p.ssid_postfix_len = |
| 5765 | os_strlen(wpa_s->conf->p2p_ssid_postfix); |
| 5766 | if (p2p.ssid_postfix_len > sizeof(p2p.ssid_postfix)) |
| 5767 | p2p.ssid_postfix_len = sizeof(p2p.ssid_postfix); |
| 5768 | os_memcpy(p2p.ssid_postfix, wpa_s->conf->p2p_ssid_postfix, |
| 5769 | p2p.ssid_postfix_len); |
| 5770 | } |
| 5771 | |
| 5772 | p2p.p2p_intra_bss = wpa_s->conf->p2p_intra_bss; |
| 5773 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5774 | p2p.max_listen = wpa_s->max_remain_on_chan; |
| 5775 | |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 5776 | if (wpa_s->conf->p2p_passphrase_len >= 8 && |
| 5777 | wpa_s->conf->p2p_passphrase_len <= 63) |
| 5778 | p2p.passphrase_len = wpa_s->conf->p2p_passphrase_len; |
| 5779 | else |
| 5780 | p2p.passphrase_len = 8; |
| 5781 | |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 5782 | if (wpa_s->conf->dik && |
| 5783 | wpabuf_len(wpa_s->conf->dik) <= DEVICE_IDENTITY_KEY_MAX_LEN) { |
| 5784 | p2p.pairing_config.dik_cipher = wpa_s->conf->dik_cipher; |
| 5785 | p2p.pairing_config.dik_len = wpabuf_len(wpa_s->conf->dik); |
| 5786 | os_memcpy(p2p.pairing_config.dik_data, |
| 5787 | wpabuf_head(wpa_s->conf->dik), |
| 5788 | p2p.pairing_config.dik_len); |
| 5789 | } else { |
| 5790 | p2p.pairing_config.dik_cipher = DIRA_CIPHER_VERSION_128; |
| 5791 | p2p.pairing_config.dik_len = DEVICE_IDENTITY_KEY_LEN; |
| 5792 | if (os_get_random(p2p.pairing_config.dik_data, |
| 5793 | p2p.pairing_config.dik_len) < 0) |
| 5794 | return -1; |
| 5795 | |
| 5796 | wpa_s->conf->dik = |
| 5797 | wpabuf_alloc_copy(p2p.pairing_config.dik_data, |
| 5798 | p2p.pairing_config.dik_len); |
| 5799 | if (!wpa_s->conf->dik) |
| 5800 | return -1; |
| 5801 | |
| 5802 | wpa_s->conf->dik_cipher = p2p.pairing_config.dik_cipher; |
| 5803 | |
| 5804 | if (wpa_s->conf->update_config && |
| 5805 | wpa_config_write(wpa_s->confname, wpa_s->conf)) |
| 5806 | wpa_printf(MSG_DEBUG, |
| 5807 | "P2P: Failed to update configuration"); |
| 5808 | } |
| 5809 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 5810 | p2p.pairing_config.enable_pairing_setup = |
| 5811 | wpa_s->conf->p2p_pairing_setup; |
| 5812 | p2p.pairing_config.enable_pairing_cache = |
| 5813 | wpa_s->conf->p2p_pairing_cache; |
| 5814 | p2p.pairing_config.bootstrap_methods = |
| 5815 | wpa_s->conf->p2p_bootstrap_methods; |
| 5816 | p2p.pairing_config.pasn_type = wpa_s->conf->p2p_pasn_type; |
| 5817 | p2p.comeback_after = wpa_s->conf->p2p_comeback_after; |
| 5818 | p2p.reg_info = wpa_s->conf->p2p_reg_info; |
| 5819 | p2p.twt_power_mgmt = wpa_s->conf->p2p_twt_power_mgmt; |
| 5820 | p2p.chan_switch_req_enable = wpa_s->conf->p2p_chan_switch_req_enable; |
| 5821 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5822 | global->p2p = p2p_init(&p2p); |
| 5823 | if (global->p2p == NULL) |
| 5824 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5825 | global->p2p_init_wpa_s = wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5826 | |
| 5827 | for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) { |
| 5828 | if (wpa_s->conf->wps_vendor_ext[i] == NULL) |
| 5829 | continue; |
| 5830 | p2p_add_wps_vendor_extension( |
| 5831 | global->p2p, wpa_s->conf->wps_vendor_ext[i]); |
| 5832 | } |
| 5833 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5834 | p2p_set_no_go_freq(global->p2p, &wpa_s->conf->p2p_no_go_freq); |
| 5835 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5836 | return 0; |
| 5837 | } |
| 5838 | |
| 5839 | |
| 5840 | /** |
| 5841 | * wpas_p2p_deinit - Deinitialize per-interface P2P data |
| 5842 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 5843 | * |
| 5844 | * This function deinitialize per-interface P2P data. |
| 5845 | */ |
| 5846 | void wpas_p2p_deinit(struct wpa_supplicant *wpa_s) |
| 5847 | { |
| 5848 | if (wpa_s->driver && wpa_s->drv_priv) |
| 5849 | wpa_drv_probe_req_report(wpa_s, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5850 | |
| 5851 | if (wpa_s->go_params) { |
| 5852 | /* Clear any stored provisioning info */ |
| 5853 | p2p_clear_provisioning_info( |
| 5854 | wpa_s->global->p2p, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5855 | wpa_s->go_params->peer_device_addr); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5856 | } |
| 5857 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5858 | os_free(wpa_s->go_params); |
| 5859 | wpa_s->go_params = NULL; |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 5860 | eloop_cancel_timeout(wpas_p2p_psk_failure_removal, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5861 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 5862 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5863 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5864 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
| 5865 | eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL); |
| 5866 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 5867 | eloop_cancel_timeout(wpas_p2p_group_freq_conflict, wpa_s, NULL); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5868 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, wpa_s, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5869 | wpas_p2p_listen_work_done(wpa_s); |
| 5870 | if (wpa_s->p2p_send_action_work) { |
| 5871 | os_free(wpa_s->p2p_send_action_work->ctx); |
| 5872 | radio_work_done(wpa_s->p2p_send_action_work); |
| 5873 | wpa_s->p2p_send_action_work = NULL; |
| 5874 | } |
| 5875 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, wpa_s, NULL); |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 5876 | eloop_cancel_timeout(wpas_p2p_send_bootstrap_comeback, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5877 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5878 | wpabuf_free(wpa_s->p2p_oob_dev_pw); |
| 5879 | wpa_s->p2p_oob_dev_pw = NULL; |
| 5880 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5881 | os_free(wpa_s->p2p_group_common_freqs); |
| 5882 | wpa_s->p2p_group_common_freqs = NULL; |
| 5883 | wpa_s->p2p_group_common_freqs_num = 0; |
| 5884 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5885 | /* TODO: remove group interface from the driver if this wpa_s instance |
| 5886 | * is on top of a P2P group interface */ |
| 5887 | } |
| 5888 | |
| 5889 | |
| 5890 | /** |
| 5891 | * wpas_p2p_deinit_global - Deinitialize global P2P module |
| 5892 | * @global: Pointer to global data from wpa_supplicant_init() |
| 5893 | * |
| 5894 | * This function deinitializes the global (per device) P2P module. |
| 5895 | */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5896 | static void wpas_p2p_deinit_global(struct wpa_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5897 | { |
| 5898 | struct wpa_supplicant *wpa_s, *tmp; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5899 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5900 | wpa_s = global->ifaces; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5901 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5902 | wpas_p2p_service_flush(global->p2p_init_wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5903 | |
| 5904 | /* Remove remaining P2P group interfaces */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5905 | while (wpa_s && wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) |
| 5906 | wpa_s = wpa_s->next; |
| 5907 | while (wpa_s) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5908 | tmp = global->ifaces; |
| 5909 | while (tmp && |
| 5910 | (tmp == wpa_s || |
| 5911 | tmp->p2p_group_interface == NOT_P2P_GROUP_INTERFACE)) { |
| 5912 | tmp = tmp->next; |
| 5913 | } |
| 5914 | if (tmp == NULL) |
| 5915 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5916 | /* Disconnect from the P2P group and deinit the interface */ |
| 5917 | wpas_p2p_disconnect(tmp); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5918 | } |
| 5919 | |
| 5920 | /* |
| 5921 | * Deinit GO data on any possibly remaining interface (if main |
| 5922 | * interface is used as GO). |
| 5923 | */ |
| 5924 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 5925 | if (wpa_s->ap_iface) |
| 5926 | wpas_p2p_group_deinit(wpa_s); |
| 5927 | } |
| 5928 | |
| 5929 | p2p_deinit(global->p2p); |
| 5930 | global->p2p = NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5931 | global->p2p_init_wpa_s = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5932 | } |
| 5933 | |
| 5934 | |
| 5935 | static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s) |
| 5936 | { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5937 | if (wpa_s->conf->p2p_no_group_iface) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5938 | return 0; /* separate interface disabled per configuration */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5939 | if (wpa_s->drv_flags & |
| 5940 | (WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE | |
| 5941 | WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P)) |
| 5942 | return 1; /* P2P group requires a new interface in every case |
| 5943 | */ |
| 5944 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CONCURRENT)) |
| 5945 | return 0; /* driver does not support concurrent operations */ |
| 5946 | if (wpa_s->global->ifaces->next) |
| 5947 | return 1; /* more that one interface already in use */ |
| 5948 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
| 5949 | return 1; /* this interface is already in use */ |
| 5950 | return 0; |
| 5951 | } |
| 5952 | |
| 5953 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 5954 | #ifdef CONFIG_PASN |
| 5955 | static int wpas_p2p_config_sae_password(struct wpa_supplicant *wpa_s, |
| 5956 | struct wpa_ssid *ssid) |
| 5957 | { |
| 5958 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 5959 | |
| 5960 | if (wpa_s->global->p2p_disabled || !p2p || !ssid->sae_password) |
| 5961 | return -2; |
| 5962 | |
| 5963 | return p2p_config_sae_password(p2p, ssid->sae_password); |
| 5964 | } |
| 5965 | #endif /* CONFIG_PASN */ |
| 5966 | |
| 5967 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5968 | static int wpas_p2p_start_go_neg(struct wpa_supplicant *wpa_s, |
| 5969 | const u8 *peer_addr, |
| 5970 | enum p2p_wps_method wps_method, |
| 5971 | int go_intent, const u8 *own_interface_addr, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5972 | unsigned int force_freq, int persistent_group, |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 5973 | struct wpa_ssid *ssid, unsigned int pref_freq, |
| 5974 | bool p2p2, u16 bootstrap, const char *password) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5975 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5976 | if (persistent_group && wpa_s->conf->persistent_reconnect) |
| 5977 | persistent_group = 2; |
| 5978 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5979 | /* |
| 5980 | * Increase GO config timeout if HT40 is used since it takes some time |
| 5981 | * to scan channels for coex purposes before the BSS can be started. |
| 5982 | */ |
| 5983 | p2p_set_config_timeout(wpa_s->global->p2p, |
| 5984 | wpa_s->p2p_go_ht40 ? 255 : 100, 20); |
| 5985 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5986 | return p2p_connect(wpa_s->global->p2p, peer_addr, wps_method, |
| 5987 | go_intent, own_interface_addr, force_freq, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5988 | persistent_group, ssid ? ssid->ssid : NULL, |
| 5989 | ssid ? ssid->ssid_len : 0, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5990 | wpa_s->p2p_pd_before_go_neg, pref_freq, |
| 5991 | wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id : |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 5992 | 0, p2p2, bootstrap, password); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5993 | } |
| 5994 | |
| 5995 | |
| 5996 | static int wpas_p2p_auth_go_neg(struct wpa_supplicant *wpa_s, |
| 5997 | const u8 *peer_addr, |
| 5998 | enum p2p_wps_method wps_method, |
| 5999 | int go_intent, const u8 *own_interface_addr, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6000 | unsigned int force_freq, int persistent_group, |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 6001 | struct wpa_ssid *ssid, unsigned int pref_freq, |
| 6002 | u16 bootstrap, const char *password) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6003 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6004 | if (persistent_group && wpa_s->conf->persistent_reconnect) |
| 6005 | persistent_group = 2; |
| 6006 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6007 | return p2p_authorize(wpa_s->global->p2p, peer_addr, wps_method, |
| 6008 | go_intent, own_interface_addr, force_freq, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6009 | persistent_group, ssid ? ssid->ssid : NULL, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 6010 | ssid ? ssid->ssid_len : 0, pref_freq, |
| 6011 | wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id : |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 6012 | 0, bootstrap, password); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6013 | } |
| 6014 | |
| 6015 | |
| 6016 | static void wpas_p2p_check_join_scan_limit(struct wpa_supplicant *wpa_s) |
| 6017 | { |
| 6018 | wpa_s->p2p_join_scan_count++; |
| 6019 | wpa_printf(MSG_DEBUG, "P2P: Join scan attempt %d", |
| 6020 | wpa_s->p2p_join_scan_count); |
| 6021 | if (wpa_s->p2p_join_scan_count > P2P_MAX_JOIN_SCAN_ATTEMPTS) { |
| 6022 | wpa_printf(MSG_DEBUG, "P2P: Failed to find GO " MACSTR |
| 6023 | " for join operationg - stop join attempt", |
| 6024 | MAC2STR(wpa_s->pending_join_iface_addr)); |
| 6025 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6026 | if (wpa_s->p2p_auto_pd) { |
| 6027 | wpa_s->p2p_auto_pd = 0; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6028 | wpa_msg_global(wpa_s, MSG_INFO, |
| 6029 | P2P_EVENT_PROV_DISC_FAILURE |
| 6030 | " p2p_dev_addr=" MACSTR " status=N/A", |
| 6031 | MAC2STR(wpa_s->pending_join_dev_addr)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6032 | return; |
| 6033 | } |
Jimmy Chen | b7b3f4d | 2020-09-02 16:50:11 +0800 | [diff] [blame] | 6034 | if (wpa_s->p2p_fallback_to_go_neg) { |
| 6035 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Join operating " |
| 6036 | "failed - fall back to GO Negotiation"); |
| 6037 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
| 6038 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 6039 | "reason=join-failed"); |
| 6040 | wpas_p2p_fallback_to_go_neg(wpa_s, 0); |
| 6041 | return; |
| 6042 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6043 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6044 | P2P_EVENT_GROUP_FORMATION_FAILURE); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6045 | wpas_notify_p2p_group_formation_failure(wpa_s, ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6046 | } |
| 6047 | } |
| 6048 | |
| 6049 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6050 | static int wpas_check_freq_conflict(struct wpa_supplicant *wpa_s, int freq) |
| 6051 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6052 | int res; |
| 6053 | unsigned int num, i; |
| 6054 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6055 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6056 | if (wpas_p2p_num_unused_channels(wpa_s) > 0) { |
| 6057 | /* Multiple channels are supported and not all are in use */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6058 | return 0; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6059 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6060 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6061 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 6062 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6063 | if (!freqs) |
| 6064 | return 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6065 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6066 | num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, |
| 6067 | wpa_s->num_multichan_concurrent); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6068 | |
| 6069 | for (i = 0; i < num; i++) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6070 | if (freqs[i].freq == freq) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6071 | wpa_printf(MSG_DEBUG, "P2P: Frequency %d MHz in use by another virtual interface and can be used", |
| 6072 | freq); |
| 6073 | res = 0; |
| 6074 | goto exit_free; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6075 | } |
| 6076 | } |
| 6077 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6078 | wpa_printf(MSG_DEBUG, "P2P: No valid operating frequencies"); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6079 | res = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6080 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6081 | exit_free: |
| 6082 | os_free(freqs); |
| 6083 | return res; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6084 | } |
| 6085 | |
| 6086 | |
| 6087 | static int wpas_p2p_peer_go(struct wpa_supplicant *wpa_s, |
| 6088 | const u8 *peer_dev_addr) |
| 6089 | { |
| 6090 | struct wpa_bss *bss; |
| 6091 | int updated; |
| 6092 | |
| 6093 | bss = wpa_bss_get_p2p_dev_addr(wpa_s, peer_dev_addr); |
| 6094 | if (bss == NULL) |
| 6095 | return -1; |
| 6096 | if (bss->last_update_idx < wpa_s->bss_update_idx) { |
| 6097 | wpa_printf(MSG_DEBUG, "P2P: Peer BSS entry not updated in the " |
| 6098 | "last scan"); |
| 6099 | return 0; |
| 6100 | } |
| 6101 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6102 | updated = os_reltime_before(&wpa_s->p2p_auto_started, |
| 6103 | &bss->last_update); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6104 | wpa_printf(MSG_DEBUG, "P2P: Current BSS entry for peer updated at " |
| 6105 | "%ld.%06ld (%supdated in last scan)", |
| 6106 | bss->last_update.sec, bss->last_update.usec, |
| 6107 | updated ? "": "not "); |
| 6108 | |
| 6109 | return updated; |
| 6110 | } |
| 6111 | |
| 6112 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6113 | static void wpas_p2p_scan_res_join(struct wpa_supplicant *wpa_s, |
| 6114 | struct wpa_scan_results *scan_res) |
| 6115 | { |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 6116 | struct wpa_bss *bss = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6117 | int freq; |
| 6118 | u8 iface_addr[ETH_ALEN]; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6119 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6120 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
| 6121 | |
| 6122 | if (wpa_s->global->p2p_disabled) |
| 6123 | return; |
| 6124 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6125 | wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS) for %sjoin", |
| 6126 | scan_res ? (int) scan_res->num : -1, |
| 6127 | wpa_s->p2p_auto_join ? "auto_" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6128 | |
| 6129 | if (scan_res) |
| 6130 | wpas_p2p_scan_res_handler(wpa_s, scan_res); |
| 6131 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6132 | if (!wpa_s->p2p2 && wpa_s->p2p_auto_pd) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6133 | int join = wpas_p2p_peer_go(wpa_s, |
| 6134 | wpa_s->pending_join_dev_addr); |
| 6135 | if (join == 0 && |
| 6136 | wpa_s->auto_pd_scan_retry < P2P_AUTO_PD_SCAN_ATTEMPTS) { |
| 6137 | wpa_s->auto_pd_scan_retry++; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 6138 | bss = wpa_bss_get_bssid_latest( |
| 6139 | wpa_s, wpa_s->pending_join_dev_addr); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6140 | if (bss) { |
| 6141 | freq = bss->freq; |
| 6142 | wpa_printf(MSG_DEBUG, "P2P: Scan retry %d for " |
| 6143 | "the peer " MACSTR " at %d MHz", |
| 6144 | wpa_s->auto_pd_scan_retry, |
| 6145 | MAC2STR(wpa_s-> |
| 6146 | pending_join_dev_addr), |
| 6147 | freq); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 6148 | wpas_p2p_join_scan_req(wpa_s, freq, NULL, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6149 | return; |
| 6150 | } |
| 6151 | } |
| 6152 | |
| 6153 | if (join < 0) |
| 6154 | join = 0; |
| 6155 | |
| 6156 | wpa_s->p2p_auto_pd = 0; |
| 6157 | wpa_s->pending_pd_use = join ? AUTO_PD_JOIN : AUTO_PD_GO_NEG; |
| 6158 | wpa_printf(MSG_DEBUG, "P2P: Auto PD with " MACSTR " join=%d", |
| 6159 | MAC2STR(wpa_s->pending_join_dev_addr), join); |
| 6160 | if (p2p_prov_disc_req(wpa_s->global->p2p, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6161 | wpa_s->pending_join_dev_addr, NULL, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6162 | wpa_s->pending_pd_config_methods, join, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6163 | 0, wpa_s->user_initiated_pd) < 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6164 | wpa_s->p2p_auto_pd = 0; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6165 | wpa_msg_global(wpa_s, MSG_INFO, |
| 6166 | P2P_EVENT_PROV_DISC_FAILURE |
| 6167 | " p2p_dev_addr=" MACSTR " status=N/A", |
| 6168 | MAC2STR(wpa_s->pending_join_dev_addr)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6169 | } |
| 6170 | return; |
| 6171 | } |
| 6172 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6173 | if (wpa_s->p2p2 || wpa_s->p2p_auto_join) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6174 | int join = wpas_p2p_peer_go(wpa_s, |
| 6175 | wpa_s->pending_join_dev_addr); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6176 | |
| 6177 | if (wpa_s->p2p2 || join < 0) { |
| 6178 | if (join < 0) { |
| 6179 | wpa_printf(MSG_DEBUG, |
| 6180 | "P2P: Peer was not found to be running a GO -> use GO Negotiation"); |
| 6181 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
| 6182 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 6183 | "reason=peer-not-running-GO"); |
| 6184 | } |
| 6185 | |
| 6186 | if (wpa_s->p2p2) |
| 6187 | wpa_printf(MSG_DEBUG, |
| 6188 | "P2P2: Initiate GO negotiation and provisioning using PASN Authentication"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6189 | wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr, |
| 6190 | wpa_s->p2p_pin, wpa_s->p2p_wps_method, |
| 6191 | wpa_s->p2p_persistent_group, 0, 0, 0, |
| 6192 | wpa_s->p2p_go_intent, |
| 6193 | wpa_s->p2p_connect_freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6194 | wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6195 | wpa_s->p2p_persistent_id, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6196 | wpa_s->p2p_pd_before_go_neg, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6197 | wpa_s->p2p_go_ht40, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6198 | wpa_s->p2p_go_vht, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 6199 | wpa_s->p2p_go_max_oper_chwidth, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6200 | wpa_s->p2p_go_he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6201 | wpa_s->p2p_go_edmg, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6202 | NULL, 0, |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 6203 | is_p2p_allow_6ghz(wpa_s->global->p2p), |
| 6204 | wpa_s->p2p2, wpa_s->p2p_bootstrap, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6205 | wpa_s->pending_join_password[0] ? |
| 6206 | wpa_s->pending_join_password : NULL, |
| 6207 | false); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6208 | return; |
| 6209 | } |
| 6210 | |
| 6211 | wpa_printf(MSG_DEBUG, "P2P: Peer was found running GO%s -> " |
| 6212 | "try to join the group", join ? "" : |
| 6213 | " in older scan"); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 6214 | if (!join) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6215 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 6216 | P2P_EVENT_FALLBACK_TO_GO_NEG_ENABLED); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6217 | wpa_s->p2p_fallback_to_go_neg = 1; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 6218 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6219 | } |
| 6220 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6221 | freq = p2p_get_oper_freq(wpa_s->global->p2p, |
| 6222 | wpa_s->pending_join_iface_addr); |
| 6223 | if (freq < 0 && |
| 6224 | p2p_get_interface_addr(wpa_s->global->p2p, |
| 6225 | wpa_s->pending_join_dev_addr, |
| 6226 | iface_addr) == 0 && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 6227 | !ether_addr_equal(iface_addr, wpa_s->pending_join_dev_addr) && |
| 6228 | !wpa_bss_get_bssid(wpa_s, wpa_s->pending_join_iface_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6229 | wpa_printf(MSG_DEBUG, "P2P: Overwrite pending interface " |
| 6230 | "address for join from " MACSTR " to " MACSTR |
| 6231 | " based on newly discovered P2P peer entry", |
| 6232 | MAC2STR(wpa_s->pending_join_iface_addr), |
| 6233 | MAC2STR(iface_addr)); |
| 6234 | os_memcpy(wpa_s->pending_join_iface_addr, iface_addr, |
| 6235 | ETH_ALEN); |
| 6236 | |
| 6237 | freq = p2p_get_oper_freq(wpa_s->global->p2p, |
| 6238 | wpa_s->pending_join_iface_addr); |
| 6239 | } |
| 6240 | if (freq >= 0) { |
| 6241 | wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency " |
| 6242 | "from P2P peer table: %d MHz", freq); |
| 6243 | } |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 6244 | if (wpa_s->p2p_join_ssid_len) { |
| 6245 | wpa_printf(MSG_DEBUG, "P2P: Trying to find target GO BSS entry based on BSSID " |
| 6246 | MACSTR " and SSID %s", |
| 6247 | MAC2STR(wpa_s->pending_join_iface_addr), |
| 6248 | wpa_ssid_txt(wpa_s->p2p_join_ssid, |
| 6249 | wpa_s->p2p_join_ssid_len)); |
| 6250 | bss = wpa_bss_get(wpa_s, wpa_s->pending_join_iface_addr, |
| 6251 | wpa_s->p2p_join_ssid, |
| 6252 | wpa_s->p2p_join_ssid_len); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 6253 | } else if (!bss) { |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 6254 | wpa_printf(MSG_DEBUG, "P2P: Trying to find target GO BSS entry based on BSSID " |
| 6255 | MACSTR, MAC2STR(wpa_s->pending_join_iface_addr)); |
| 6256 | bss = wpa_bss_get_bssid_latest(wpa_s, |
| 6257 | wpa_s->pending_join_iface_addr); |
| 6258 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6259 | if (bss) { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6260 | u8 dev_addr[ETH_ALEN]; |
| 6261 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6262 | freq = bss->freq; |
| 6263 | wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency " |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 6264 | "from BSS table: %d MHz (SSID %s)", freq, |
| 6265 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6266 | 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] | 6267 | dev_addr) == 0 && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 6268 | ether_addr_equal(wpa_s->pending_join_dev_addr, |
| 6269 | wpa_s->pending_join_iface_addr) && |
| 6270 | !ether_addr_equal(dev_addr, wpa_s->pending_join_dev_addr)) { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6271 | wpa_printf(MSG_DEBUG, |
| 6272 | "P2P: Update target GO device address based on BSS entry: " MACSTR " (was " MACSTR ")", |
| 6273 | MAC2STR(dev_addr), |
| 6274 | MAC2STR(wpa_s->pending_join_dev_addr)); |
| 6275 | os_memcpy(wpa_s->pending_join_dev_addr, dev_addr, |
| 6276 | ETH_ALEN); |
| 6277 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6278 | } |
| 6279 | if (freq > 0) { |
| 6280 | u16 method; |
| 6281 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6282 | if (wpas_check_freq_conflict(wpa_s, freq) > 0) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6283 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6284 | P2P_EVENT_GROUP_FORMATION_FAILURE |
| 6285 | "reason=FREQ_CONFLICT"); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6286 | wpas_notify_p2p_group_formation_failure( |
| 6287 | wpa_s, "FREQ_CONFLICT"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6288 | return; |
| 6289 | } |
| 6290 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6291 | wpa_printf(MSG_DEBUG, "P2P: Send Provision Discovery Request " |
| 6292 | "prior to joining an existing group (GO " MACSTR |
| 6293 | " freq=%u MHz)", |
| 6294 | MAC2STR(wpa_s->pending_join_dev_addr), freq); |
| 6295 | wpa_s->pending_pd_before_join = 1; |
| 6296 | |
| 6297 | switch (wpa_s->pending_join_wps_method) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6298 | case WPS_PIN_DISPLAY: |
| 6299 | method = WPS_CONFIG_KEYPAD; |
| 6300 | break; |
| 6301 | case WPS_PIN_KEYPAD: |
| 6302 | method = WPS_CONFIG_DISPLAY; |
| 6303 | break; |
| 6304 | case WPS_PBC: |
| 6305 | method = WPS_CONFIG_PUSHBUTTON; |
| 6306 | break; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6307 | case WPS_P2PS: |
| 6308 | method = WPS_CONFIG_P2PS; |
| 6309 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6310 | default: |
| 6311 | method = 0; |
| 6312 | break; |
| 6313 | } |
| 6314 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6315 | if ((p2p_get_provisioning_info(wpa_s->global->p2p, |
| 6316 | wpa_s->pending_join_dev_addr) == |
| 6317 | method)) { |
| 6318 | /* |
| 6319 | * We have already performed provision discovery for |
| 6320 | * joining the group. Proceed directly to join |
| 6321 | * operation without duplicated provision discovery. */ |
| 6322 | wpa_printf(MSG_DEBUG, "P2P: Provision discovery " |
| 6323 | "with " MACSTR " already done - proceed to " |
| 6324 | "join", |
| 6325 | MAC2STR(wpa_s->pending_join_dev_addr)); |
| 6326 | wpa_s->pending_pd_before_join = 0; |
| 6327 | goto start; |
| 6328 | } |
| 6329 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6330 | if (p2p_prov_disc_req(wpa_s->global->p2p, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6331 | wpa_s->pending_join_dev_addr, |
| 6332 | NULL, method, 1, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6333 | freq, wpa_s->user_initiated_pd) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6334 | wpa_printf(MSG_DEBUG, "P2P: Failed to send Provision " |
| 6335 | "Discovery Request before joining an " |
| 6336 | "existing group"); |
| 6337 | wpa_s->pending_pd_before_join = 0; |
| 6338 | goto start; |
| 6339 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6340 | return; |
| 6341 | } |
| 6342 | |
| 6343 | wpa_printf(MSG_DEBUG, "P2P: Failed to find BSS/GO - try again later"); |
| 6344 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
| 6345 | eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL); |
| 6346 | wpas_p2p_check_join_scan_limit(wpa_s); |
| 6347 | return; |
| 6348 | |
| 6349 | start: |
| 6350 | /* Start join operation immediately */ |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 6351 | wpas_p2p_join_start(wpa_s, 0, wpa_s->p2p_join_ssid, |
| 6352 | wpa_s->p2p_join_ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6353 | } |
| 6354 | |
| 6355 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 6356 | static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq, |
| 6357 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6358 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6359 | int ret; |
| 6360 | struct wpa_driver_scan_params params; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6361 | struct wpabuf *wps_ie = NULL, *ies; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6362 | size_t ielen; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6363 | int freqs[2] = { 0, 0 }; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6364 | unsigned int bands; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6365 | |
| 6366 | os_memset(¶ms, 0, sizeof(params)); |
| 6367 | |
| 6368 | /* P2P Wildcard SSID */ |
| 6369 | params.num_ssids = 1; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 6370 | if (ssid && ssid_len) { |
| 6371 | params.ssids[0].ssid = ssid; |
| 6372 | params.ssids[0].ssid_len = ssid_len; |
| 6373 | os_memcpy(wpa_s->p2p_join_ssid, ssid, ssid_len); |
| 6374 | wpa_s->p2p_join_ssid_len = ssid_len; |
| 6375 | } else { |
| 6376 | params.ssids[0].ssid = (u8 *) P2P_WILDCARD_SSID; |
| 6377 | params.ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN; |
| 6378 | wpa_s->p2p_join_ssid_len = 0; |
| 6379 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6380 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6381 | if (!wpa_s->p2p2) { |
| 6382 | wpa_s->wps->dev.p2p = 1; |
| 6383 | wps_ie = wps_build_probe_req_ie(DEV_PW_DEFAULT, |
| 6384 | &wpa_s->wps->dev, |
| 6385 | wpa_s->wps->uuid, |
| 6386 | WPS_REQ_ENROLLEE, 0, NULL); |
| 6387 | if (!wps_ie) { |
| 6388 | wpas_p2p_scan_res_join(wpa_s, NULL); |
| 6389 | return; |
| 6390 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6391 | } |
| 6392 | |
Dmitry Shmidt | 9e3f8ee | 2014-01-17 10:52:01 -0800 | [diff] [blame] | 6393 | if (!freq) { |
| 6394 | int oper_freq; |
| 6395 | /* |
| 6396 | * If freq is not provided, check the operating freq of the GO |
| 6397 | * and use a single channel scan on if possible. |
| 6398 | */ |
| 6399 | oper_freq = p2p_get_oper_freq(wpa_s->global->p2p, |
| 6400 | wpa_s->pending_join_iface_addr); |
| 6401 | if (oper_freq > 0) |
| 6402 | freq = oper_freq; |
| 6403 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6404 | if (freq > 0) { |
| 6405 | freqs[0] = freq; |
| 6406 | params.freqs = freqs; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6407 | } else { |
| 6408 | wpas_p2p_scan_freqs(wpa_s, ¶ms, true); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6409 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6410 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6411 | ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6412 | |
| 6413 | if (wps_ie) |
| 6414 | ielen += wpabuf_len(wps_ie); |
| 6415 | |
| 6416 | ies = wpabuf_alloc(ielen); |
| 6417 | if (!ies) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6418 | wpabuf_free(wps_ie); |
| 6419 | wpas_p2p_scan_res_join(wpa_s, NULL); |
| 6420 | return; |
| 6421 | } |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6422 | |
| 6423 | if (wps_ie) { |
| 6424 | wpabuf_put_buf(ies, wps_ie); |
| 6425 | wpabuf_free(wps_ie); |
| 6426 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6427 | |
| 6428 | bands = wpas_get_bands(wpa_s, freqs); |
| 6429 | p2p_scan_ie(wpa_s->global->p2p, ies, NULL, bands); |
| 6430 | |
| 6431 | params.p2p_probe = 1; |
| 6432 | params.extra_ies = wpabuf_head(ies); |
| 6433 | params.extra_ies_len = wpabuf_len(ies); |
| 6434 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 6435 | if (wpa_s->clear_driver_scan_cache) { |
| 6436 | wpa_printf(MSG_DEBUG, |
| 6437 | "Request driver to clear scan cache due to local BSS flush"); |
| 6438 | params.only_new_results = 1; |
| 6439 | } |
| 6440 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6441 | /* |
| 6442 | * Run a scan to update BSS table and start Provision Discovery once |
| 6443 | * the new scan results become available. |
| 6444 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6445 | ret = wpa_drv_scan(wpa_s, ¶ms); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6446 | if (params.freqs != freqs) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6447 | os_free(params.freqs); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 6448 | if (!ret) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6449 | os_get_reltime(&wpa_s->scan_trigger_time); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6450 | wpa_s->scan_res_handler = wpas_p2p_scan_res_join; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6451 | wpa_s->own_scan_requested = 1; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 6452 | wpa_s->clear_driver_scan_cache = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 6453 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6454 | |
| 6455 | wpabuf_free(ies); |
| 6456 | |
| 6457 | if (ret) { |
| 6458 | wpa_printf(MSG_DEBUG, "P2P: Failed to start scan for join - " |
| 6459 | "try again later"); |
| 6460 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
| 6461 | eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL); |
| 6462 | wpas_p2p_check_join_scan_limit(wpa_s); |
| 6463 | } |
| 6464 | } |
| 6465 | |
| 6466 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6467 | static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx) |
| 6468 | { |
| 6469 | struct wpa_supplicant *wpa_s = eloop_ctx; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 6470 | wpas_p2p_join_scan_req(wpa_s, 0, NULL, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6471 | } |
| 6472 | |
| 6473 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6474 | 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] | 6475 | const u8 *dev_addr, enum p2p_wps_method wps_method, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 6476 | int auto_join, int op_freq, |
| 6477 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6478 | { |
| 6479 | wpa_printf(MSG_DEBUG, "P2P: Request to join existing group (iface " |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 6480 | MACSTR " dev " MACSTR " op_freq=%d)%s", |
| 6481 | MAC2STR(iface_addr), MAC2STR(dev_addr), op_freq, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6482 | auto_join ? " (auto_join)" : ""); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 6483 | if (ssid && ssid_len) { |
| 6484 | wpa_printf(MSG_DEBUG, "P2P: Group SSID specified: %s", |
| 6485 | wpa_ssid_txt(ssid, ssid_len)); |
| 6486 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6487 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6488 | wpa_s->p2p_auto_pd = 0; |
| 6489 | wpa_s->p2p_auto_join = !!auto_join; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6490 | os_memcpy(wpa_s->pending_join_iface_addr, iface_addr, ETH_ALEN); |
| 6491 | os_memcpy(wpa_s->pending_join_dev_addr, dev_addr, ETH_ALEN); |
| 6492 | wpa_s->pending_join_wps_method = wps_method; |
| 6493 | |
| 6494 | /* Make sure we are not running find during connection establishment */ |
| 6495 | wpas_p2p_stop_find(wpa_s); |
| 6496 | |
| 6497 | wpa_s->p2p_join_scan_count = 0; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 6498 | wpas_p2p_join_scan_req(wpa_s, op_freq, ssid, ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6499 | return 0; |
| 6500 | } |
| 6501 | |
| 6502 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 6503 | static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s, int freq, |
| 6504 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6505 | { |
| 6506 | struct wpa_supplicant *group; |
| 6507 | struct p2p_go_neg_results res; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6508 | struct wpa_bss *bss; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6509 | const u8 *iface_addr = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6510 | |
| 6511 | group = wpas_p2p_get_group_iface(wpa_s, 0, 0); |
| 6512 | if (group == NULL) |
| 6513 | return -1; |
| 6514 | if (group != wpa_s) { |
| 6515 | os_memcpy(group->p2p_pin, wpa_s->p2p_pin, |
| 6516 | sizeof(group->p2p_pin)); |
| 6517 | group->p2p_wps_method = wpa_s->p2p_wps_method; |
| 6518 | } |
| 6519 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6520 | /* |
| 6521 | * Need to mark the current interface for p2p_group_formation |
| 6522 | * when a separate group interface is not used. This is needed |
| 6523 | * to allow p2p_cancel stop a pending p2p_connect-join. |
| 6524 | * wpas_p2p_init_group_interface() addresses this for the case |
| 6525 | * where a separate group interface is used. |
| 6526 | */ |
| 6527 | if (group == wpa_s->parent) |
| 6528 | wpa_s->global->p2p_group_formation = group; |
| 6529 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6530 | group->p2p_in_provisioning = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6531 | 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] | 6532 | |
| 6533 | os_memset(&res, 0, sizeof(res)); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 6534 | 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] | 6535 | os_memcpy(res.peer_interface_addr, wpa_s->pending_join_iface_addr, |
| 6536 | ETH_ALEN); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6537 | if (!is_zero_ether_addr(wpa_s->pending_join_iface_addr)) |
| 6538 | iface_addr = wpa_s->pending_join_iface_addr; |
| 6539 | |
| 6540 | if (wpa_s->pending_join_password[0]) { |
| 6541 | res.akmp = WPA_KEY_MGMT_SAE; |
| 6542 | os_strlcpy(res.sae_password, wpa_s->pending_join_password, |
| 6543 | sizeof(res.sae_password)); |
| 6544 | os_memset(wpa_s->pending_join_password, 0, |
| 6545 | sizeof(wpa_s->pending_join_password)); |
| 6546 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6547 | res.wps_method = wpa_s->pending_join_wps_method; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6548 | res.p2p2 = wpa_s->p2p2; |
| 6549 | res.cipher = WPA_CIPHER_CCMP; |
| 6550 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 6551 | if (freq && ssid && ssid_len) { |
| 6552 | res.freq = freq; |
| 6553 | res.ssid_len = ssid_len; |
| 6554 | os_memcpy(res.ssid, ssid, ssid_len); |
| 6555 | } else { |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 6556 | if (ssid && ssid_len) { |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6557 | bss = wpa_bss_get(wpa_s, iface_addr, ssid, ssid_len); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 6558 | } else { |
| 6559 | bss = wpa_bss_get_bssid_latest( |
| 6560 | wpa_s, wpa_s->pending_join_iface_addr); |
| 6561 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 6562 | if (bss) { |
| 6563 | res.freq = bss->freq; |
| 6564 | res.ssid_len = bss->ssid_len; |
| 6565 | os_memcpy(res.ssid, bss->ssid, bss->ssid_len); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6566 | os_memcpy(res.peer_interface_addr, bss->bssid, |
| 6567 | ETH_ALEN); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 6568 | wpa_printf(MSG_DEBUG, "P2P: Join target GO operating frequency from BSS table: %d MHz (SSID %s)", |
| 6569 | bss->freq, |
| 6570 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 6571 | } else if (ssid && ssid_len) { |
| 6572 | res.ssid_len = ssid_len; |
| 6573 | os_memcpy(res.ssid, ssid, ssid_len); |
| 6574 | wpa_printf(MSG_DEBUG, "P2P: Join target GO (SSID %s)", |
| 6575 | wpa_ssid_txt(ssid, ssid_len)); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 6576 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6577 | } |
| 6578 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6579 | if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) { |
| 6580 | wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel prior to " |
| 6581 | "starting client"); |
| 6582 | wpa_drv_cancel_remain_on_channel(wpa_s); |
| 6583 | wpa_s->off_channel_freq = 0; |
| 6584 | wpa_s->roc_waiting_drv_freq = 0; |
| 6585 | } |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6586 | if (res.p2p2) |
| 6587 | wpas_start_gc(group, &res); |
| 6588 | else |
| 6589 | wpas_start_wps_enrollee(group, &res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6590 | |
| 6591 | /* |
| 6592 | * Allow a longer timeout for join-a-running-group than normal 15 |
| 6593 | * second group formation timeout since the GO may not have authorized |
| 6594 | * our connection yet. |
| 6595 | */ |
| 6596 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 6597 | eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout, |
| 6598 | wpa_s, NULL); |
| 6599 | |
| 6600 | return 0; |
| 6601 | } |
| 6602 | |
| 6603 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6604 | 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] | 6605 | int *force_freq, int *pref_freq, int go, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6606 | struct weighted_pcl *pref_freq_list, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6607 | unsigned int *num_pref_freq) |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6608 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6609 | struct wpa_used_freq_data *freqs; |
| 6610 | int res, best_freq, num_unused; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6611 | unsigned int freq_in_use = 0, num, i, max_pref_freq; |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 6612 | int p2p_pref_freq; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6613 | |
| 6614 | max_pref_freq = *num_pref_freq; |
| 6615 | *num_pref_freq = 0; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6616 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6617 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 6618 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6619 | if (!freqs) |
| 6620 | return -1; |
| 6621 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6622 | num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, |
| 6623 | wpa_s->num_multichan_concurrent); |
| 6624 | |
| 6625 | /* |
| 6626 | * It is possible that the total number of used frequencies is bigger |
| 6627 | * than the number of frequencies used for P2P, so get the system wide |
| 6628 | * number of unused frequencies. |
| 6629 | */ |
| 6630 | num_unused = wpas_p2p_num_unused_channels(wpa_s); |
| 6631 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6632 | wpa_printf(MSG_DEBUG, |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6633 | "P2P: Setup freqs: freq=%d num_MCC=%d shared_freqs=%u num_unused=%d", |
| 6634 | freq, wpa_s->num_multichan_concurrent, num, num_unused); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6635 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6636 | if (freq > 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6637 | int ret; |
| 6638 | if (go) |
| 6639 | ret = p2p_supported_freq(wpa_s->global->p2p, freq); |
| 6640 | else |
| 6641 | ret = p2p_supported_freq_cli(wpa_s->global->p2p, freq); |
| 6642 | if (!ret) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6643 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6644 | ieee80211_is_dfs(freq, wpa_s->hw.modes, |
| 6645 | wpa_s->hw.num_modes)) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6646 | /* |
| 6647 | * If freq is a DFS channel and DFS is offloaded |
| 6648 | * to the driver, allow P2P GO to use it. |
| 6649 | */ |
| 6650 | wpa_printf(MSG_DEBUG, |
| 6651 | "P2P: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded to the driver", |
| 6652 | freq); |
| 6653 | } else { |
| 6654 | wpa_printf(MSG_DEBUG, |
| 6655 | "P2P: The forced channel (%u MHz) is not supported for P2P uses", |
| 6656 | freq); |
| 6657 | res = -3; |
| 6658 | goto exit_free; |
| 6659 | } |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6660 | } |
| 6661 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6662 | for (i = 0; i < num; i++) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6663 | if (freqs[i].freq == freq) |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6664 | freq_in_use = 1; |
| 6665 | } |
| 6666 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6667 | if (num_unused <= 0 && !freq_in_use) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6668 | wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group on %u MHz as there are no available channels", |
| 6669 | freq); |
| 6670 | res = -2; |
| 6671 | goto exit_free; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6672 | } |
| 6673 | wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the " |
| 6674 | "requested channel (%u MHz)", freq); |
| 6675 | *force_freq = freq; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6676 | goto exit_ok; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6677 | } |
| 6678 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6679 | best_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6680 | |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 6681 | if (*pref_freq == 0) { |
| 6682 | if (wpa_s->conf->num_p2p_pref_chan && IS_2GHZ(best_freq)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6683 | i = 0; |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 6684 | while (i < wpa_s->conf->num_p2p_pref_chan) { |
| 6685 | p2p_pref_freq = ieee80211_chan_to_freq(NULL, |
| 6686 | wpa_s->conf->p2p_pref_chan[i].op_class, |
| 6687 | wpa_s->conf->p2p_pref_chan[i].chan); |
| 6688 | |
| 6689 | if (p2p_supported_freq(wpa_s->global->p2p, p2p_pref_freq) && |
| 6690 | !wpas_p2p_disallowed_freq(wpa_s->global, p2p_pref_freq)) { |
| 6691 | best_freq = p2p_pref_freq; |
| 6692 | wpa_printf(MSG_DEBUG, "P2P: Using frequency (%u MHz) " |
| 6693 | "from P2P preferred channel list", best_freq); |
| 6694 | break; |
| 6695 | } else { |
| 6696 | wpa_printf(MSG_MSGDUMP, "P2P: Skipping preferred " |
| 6697 | "frequency (%u MHz) ", p2p_pref_freq); |
| 6698 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6699 | i++; |
| 6700 | } |
Sreeramya Soratkal | f928e8f | 2022-03-22 17:33:31 +0530 | [diff] [blame] | 6701 | } else if (!wpa_s->conf->num_p2p_pref_chan) { |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 6702 | wpa_printf(MSG_DEBUG, "P2P: best_freq=%d, go=%d", |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 6703 | best_freq, go); |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 6704 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 6705 | *num_pref_freq = max_pref_freq; |
| 6706 | res = wpas_p2p_pick_best_pref_freq(wpa_s, go, pref_freq_list, |
| 6707 | num_pref_freq); |
| 6708 | if (res > 0) |
| 6709 | best_freq = res; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6710 | } |
| 6711 | } |
| 6712 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6713 | /* We have a candidate frequency to use */ |
| 6714 | if (best_freq > 0) { |
| 6715 | if (*pref_freq == 0 && num_unused > 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 6716 | 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] | 6717 | best_freq); |
| 6718 | *pref_freq = best_freq; |
Dmitry Shmidt | 51a47d5 | 2013-09-10 10:52:57 -0700 | [diff] [blame] | 6719 | } else { |
| 6720 | 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] | 6721 | best_freq); |
| 6722 | *force_freq = best_freq; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6723 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6724 | } else if (num_unused > 0) { |
| 6725 | wpa_printf(MSG_DEBUG, |
| 6726 | "P2P: Current operating channels are not available for P2P. Try to use another channel"); |
| 6727 | *force_freq = 0; |
| 6728 | } else { |
| 6729 | wpa_printf(MSG_DEBUG, |
| 6730 | "P2P: All channels are in use and none of them are P2P enabled. Cannot start P2P group"); |
| 6731 | res = -2; |
| 6732 | goto exit_free; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6733 | } |
| 6734 | |
| 6735 | exit_ok: |
| 6736 | res = 0; |
| 6737 | exit_free: |
| 6738 | os_free(freqs); |
| 6739 | return res; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6740 | } |
| 6741 | |
| 6742 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6743 | static bool is_p2p_6ghz_supported(struct wpa_supplicant *wpa_s, |
| 6744 | const u8 *peer_addr) |
| 6745 | { |
| 6746 | if (wpa_s->conf->p2p_6ghz_disable || |
| 6747 | !get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
| 6748 | HOSTAPD_MODE_IEEE80211A, true)) |
| 6749 | return false; |
| 6750 | |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 6751 | if (wpa_s->p2p2) |
| 6752 | return true; |
| 6753 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6754 | if (!p2p_wfd_enabled(wpa_s->global->p2p)) |
| 6755 | return false; |
| 6756 | if (peer_addr && !p2p_peer_wfd_enabled(wpa_s->global->p2p, peer_addr)) |
| 6757 | return false; |
| 6758 | |
| 6759 | return true; |
| 6760 | } |
| 6761 | |
| 6762 | |
| 6763 | static int wpas_p2p_check_6ghz(struct wpa_supplicant *wpa_s, |
| 6764 | const u8 *peer_addr, bool allow_6ghz, int freq) |
| 6765 | { |
| 6766 | if (allow_6ghz && is_p2p_6ghz_supported(wpa_s, peer_addr)) { |
| 6767 | wpa_printf(MSG_DEBUG, |
| 6768 | "P2P: Allow connection on 6 GHz channels"); |
| 6769 | p2p_set_6ghz_dev_capab(wpa_s->global->p2p, true); |
| 6770 | } else { |
| 6771 | if (is_6ghz_freq(freq)) |
| 6772 | return -2; |
| 6773 | p2p_set_6ghz_dev_capab(wpa_s->global->p2p, false); |
| 6774 | } |
| 6775 | |
| 6776 | return 0; |
| 6777 | } |
| 6778 | |
| 6779 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6780 | /** |
| 6781 | * wpas_p2p_connect - Request P2P Group Formation to be started |
| 6782 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 6783 | * @peer_addr: Address of the peer P2P Device |
| 6784 | * @pin: PIN to use during provisioning or %NULL to indicate PBC mode |
| 6785 | * @persistent_group: Whether to create a persistent group |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6786 | * @auto_join: Whether to select join vs. GO Negotiation automatically |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6787 | * @join: Whether to join an existing group (as a client) instead of starting |
| 6788 | * Group Owner negotiation; @peer_addr is BSSID in that case |
| 6789 | * @auth: Whether to only authorize the connection instead of doing that and |
| 6790 | * initiating Group Owner negotiation |
| 6791 | * @go_intent: GO Intent or -1 to use default |
| 6792 | * @freq: Frequency for the group or 0 for auto-selection |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6793 | * @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] | 6794 | * @persistent_id: Persistent group credentials to use for forcing GO |
| 6795 | * parameters or -1 to generate new values (SSID/passphrase) |
| 6796 | * @pd: Whether to send Provision Discovery prior to GO Negotiation as an |
| 6797 | * interoperability workaround when initiating group formation |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6798 | * @ht40: Start GO with 40 MHz channel width |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6799 | * @vht: Start GO with VHT support |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6800 | * @vht_chwidth: Channel width supported by GO operating with VHT support |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6801 | * (CHANWIDTH_*). |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 6802 | * @group_ssid: Specific Group SSID for join or %NULL if not set |
| 6803 | * @group_ssid_len: Length of @group_ssid in octets |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6804 | * @allow_6ghz: Allow P2P connection on 6 GHz channels |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 6805 | * @p2p2: Whether device is in P2P R2 mode |
| 6806 | * @bootstrap: Requested bootstrap method for pairing in P2P2 |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6807 | * @password: Password for pairing setup or NULL for opportunistic method |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 6808 | * in P2P2 |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6809 | * @skip_prov: Connect without provisioning |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6810 | * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified |
| 6811 | * failure, -2 on failure due to channel not currently available, |
| 6812 | * -3 if forced channel is not supported |
| 6813 | */ |
| 6814 | int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr, |
| 6815 | const char *pin, enum p2p_wps_method wps_method, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6816 | int persistent_group, int auto_join, int join, int auth, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6817 | int go_intent, int freq, unsigned int vht_center_freq2, |
| 6818 | int persistent_id, int pd, int ht40, int vht, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6819 | unsigned int vht_chwidth, int he, int edmg, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6820 | const u8 *group_ssid, size_t group_ssid_len, |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 6821 | bool allow_6ghz, bool p2p2, u16 bootstrap, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6822 | const char *password, bool skip_prov) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6823 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6824 | int force_freq = 0, pref_freq = 0; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6825 | int ret = 0, res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6826 | enum wpa_driver_if_type iftype; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6827 | const u8 *if_addr; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6828 | struct wpa_ssid *ssid = NULL; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6829 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 6830 | unsigned int size; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6831 | |
| 6832 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 6833 | return -1; |
| 6834 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6835 | if (persistent_id >= 0) { |
| 6836 | ssid = wpa_config_get_network(wpa_s->conf, persistent_id); |
| 6837 | if (ssid == NULL || ssid->disabled != 2 || |
| 6838 | ssid->mode != WPAS_MODE_P2P_GO) |
| 6839 | return -1; |
| 6840 | } |
| 6841 | |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 6842 | wpa_s->p2p2 = p2p2; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6843 | wpa_s->p2p_mode = p2p2 ? WPA_P2P_MODE_WFD_R2 : WPA_P2P_MODE_WFD_R1; |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 6844 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6845 | if (wpas_p2p_check_6ghz(wpa_s, peer_addr, allow_6ghz, freq)) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6846 | return -2; |
| 6847 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6848 | os_free(wpa_s->global->add_psk); |
| 6849 | wpa_s->global->add_psk = NULL; |
| 6850 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6851 | p2p_set_go_role(wpa_s->global->p2p, false); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6852 | wpa_s->global->p2p_fail_on_wps_complete = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6853 | wpa_s->global->pending_p2ps_group = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6854 | wpa_s->global->pending_p2ps_group_freq = 0; |
| 6855 | wpa_s->p2ps_method_config_any = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6856 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6857 | if (go_intent < 0) |
| 6858 | go_intent = wpa_s->conf->p2p_go_intent; |
| 6859 | |
| 6860 | if (!auth) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6861 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6862 | |
| 6863 | wpa_s->p2p_wps_method = wps_method; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6864 | wpa_s->p2p_persistent_group = !!persistent_group; |
| 6865 | wpa_s->p2p_persistent_id = persistent_id; |
| 6866 | wpa_s->p2p_go_intent = go_intent; |
| 6867 | wpa_s->p2p_connect_freq = freq; |
| 6868 | wpa_s->p2p_fallback_to_go_neg = 0; |
| 6869 | wpa_s->p2p_pd_before_go_neg = !!pd; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6870 | wpa_s->p2p_go_ht40 = !!ht40; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6871 | wpa_s->p2p_go_vht = !!vht; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6872 | wpa_s->p2p_go_vht_center_freq2 = vht_center_freq2; |
| 6873 | wpa_s->p2p_go_max_oper_chwidth = vht_chwidth; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6874 | wpa_s->p2p_go_he = !!he; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6875 | wpa_s->p2p_go_edmg = !!edmg; |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 6876 | wpa_s->p2p_bootstrap = bootstrap; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6877 | |
| 6878 | if (pin) |
| 6879 | os_strlcpy(wpa_s->p2p_pin, pin, sizeof(wpa_s->p2p_pin)); |
| 6880 | else if (wps_method == WPS_PIN_DISPLAY) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6881 | if (wps_generate_pin((unsigned int *) &ret) < 0) |
| 6882 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6883 | res = os_snprintf(wpa_s->p2p_pin, sizeof(wpa_s->p2p_pin), |
| 6884 | "%08d", ret); |
| 6885 | if (os_snprintf_error(sizeof(wpa_s->p2p_pin), res)) |
| 6886 | wpa_s->p2p_pin[sizeof(wpa_s->p2p_pin) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6887 | wpa_printf(MSG_DEBUG, "P2P: Randomly generated PIN: %s", |
| 6888 | wpa_s->p2p_pin); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6889 | } else if (wps_method == WPS_P2PS) { |
| 6890 | /* Force the P2Ps default PIN to be used */ |
| 6891 | os_strlcpy(wpa_s->p2p_pin, "12345670", sizeof(wpa_s->p2p_pin)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6892 | } else |
| 6893 | wpa_s->p2p_pin[0] = '\0'; |
| 6894 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6895 | if (!password) |
| 6896 | os_memset(wpa_s->pending_join_password, 0, |
| 6897 | sizeof(wpa_s->pending_join_password)); |
| 6898 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6899 | if (join || auto_join) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6900 | u8 iface_addr[ETH_ALEN], dev_addr[ETH_ALEN]; |
| 6901 | if (auth) { |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6902 | #ifdef CONFIG_PASN |
| 6903 | struct wpa_supplicant *ifs; |
| 6904 | #endif /* CONFIG_PASN */ |
| 6905 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6906 | wpa_printf(MSG_DEBUG, "P2P: Authorize invitation to " |
| 6907 | "connect a running group from " MACSTR, |
| 6908 | MAC2STR(peer_addr)); |
| 6909 | os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6910 | |
| 6911 | #ifdef CONFIG_PASN |
| 6912 | if (!wpa_s->p2p2) |
| 6913 | return ret; |
| 6914 | |
| 6915 | wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s); |
| 6916 | if (wpa_s->create_p2p_iface) { |
| 6917 | if_addr = wpa_s->pending_interface_addr; |
| 6918 | } else { |
| 6919 | if (wpa_s->p2p_mgmt) |
| 6920 | if_addr = wpa_s->parent->own_addr; |
| 6921 | else |
| 6922 | if_addr = wpa_s->own_addr; |
| 6923 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
| 6924 | } |
| 6925 | |
| 6926 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, |
| 6927 | struct wpa_supplicant, radio_list) { |
| 6928 | if (!ifs->current_ssid || |
| 6929 | ifs->current_ssid->mode != WPAS_MODE_P2P_GO) |
| 6930 | continue; |
| 6931 | |
| 6932 | ssid = ifs->current_ssid; |
| 6933 | |
| 6934 | if (bootstrap == P2P_PBMA_OPPORTUNISTIC && |
| 6935 | wpas_p2p_config_sae_password(wpa_s, ssid)) { |
| 6936 | ssid = NULL; |
| 6937 | continue; |
| 6938 | } |
| 6939 | |
| 6940 | force_freq = ifs->ap_iface->freq; |
| 6941 | break; |
| 6942 | } |
| 6943 | p2p_set_go_role(wpa_s->global->p2p, true); |
| 6944 | return wpas_p2p_auth_go_neg(wpa_s, peer_addr, |
| 6945 | wps_method, 15, if_addr, |
| 6946 | force_freq, |
| 6947 | persistent_group, ssid, |
| 6948 | pref_freq, bootstrap, |
| 6949 | password); |
| 6950 | #else /* CONFIG_PASN */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6951 | return ret; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6952 | #endif /* CONFIG_PASN */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6953 | } |
| 6954 | os_memcpy(dev_addr, peer_addr, ETH_ALEN); |
| 6955 | if (p2p_get_interface_addr(wpa_s->global->p2p, peer_addr, |
| 6956 | iface_addr) < 0) { |
| 6957 | os_memcpy(iface_addr, peer_addr, ETH_ALEN); |
| 6958 | p2p_get_dev_addr(wpa_s->global->p2p, peer_addr, |
| 6959 | dev_addr); |
| 6960 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6961 | if (auto_join) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6962 | os_get_reltime(&wpa_s->p2p_auto_started); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6963 | wpa_printf(MSG_DEBUG, "P2P: Auto join started at " |
| 6964 | "%ld.%06ld", |
| 6965 | wpa_s->p2p_auto_started.sec, |
| 6966 | wpa_s->p2p_auto_started.usec); |
| 6967 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6968 | wpa_s->user_initiated_pd = 1; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 6969 | if (password) |
| 6970 | os_strlcpy(wpa_s->pending_join_password, password, |
| 6971 | sizeof(wpa_s->pending_join_password)); |
| 6972 | |
| 6973 | if (skip_prov) { |
| 6974 | if (!wpa_s->p2p2) { |
| 6975 | wpa_printf(MSG_DEBUG, |
| 6976 | "P2P: Join without provisioning not supported"); |
| 6977 | return -1; |
| 6978 | } |
| 6979 | /* Start join operation immediately */ |
| 6980 | return wpas_p2p_join_start(wpa_s, 0, group_ssid, |
| 6981 | group_ssid_len); |
| 6982 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6983 | if (wpas_p2p_join(wpa_s, iface_addr, dev_addr, wps_method, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 6984 | auto_join, freq, |
| 6985 | group_ssid, group_ssid_len) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6986 | return -1; |
| 6987 | return ret; |
| 6988 | } |
| 6989 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6990 | size = P2P_MAX_PREF_CHANNELS; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6991 | res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6992 | go_intent == 15, pref_freq_list, &size); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6993 | if (res) |
| 6994 | return res; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 6995 | wpas_p2p_set_own_freq_preference(wpa_s, |
| 6996 | force_freq ? force_freq : pref_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6997 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6998 | p2p_set_own_pref_freq_list(wpa_s->global->p2p, pref_freq_list, size); |
| 6999 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7000 | wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s); |
| 7001 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7002 | if (wpa_s->create_p2p_iface) { |
| 7003 | /* Prepare to add a new interface for the group */ |
| 7004 | iftype = WPA_IF_P2P_GROUP; |
| 7005 | if (go_intent == 15) |
| 7006 | iftype = WPA_IF_P2P_GO; |
| 7007 | if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) { |
| 7008 | wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " |
| 7009 | "interface for the group"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7010 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7011 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7012 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7013 | if_addr = wpa_s->pending_interface_addr; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7014 | } else { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7015 | if (wpa_s->p2p_mgmt) |
| 7016 | if_addr = wpa_s->parent->own_addr; |
| 7017 | else |
| 7018 | if_addr = wpa_s->own_addr; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7019 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
| 7020 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7021 | |
| 7022 | if (auth) { |
| 7023 | if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7024 | go_intent, if_addr, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7025 | force_freq, persistent_group, ssid, |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 7026 | pref_freq, bootstrap, password) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7027 | return -1; |
| 7028 | return ret; |
| 7029 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7030 | |
| 7031 | if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method, |
| 7032 | go_intent, if_addr, force_freq, |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 7033 | persistent_group, ssid, pref_freq, p2p2, |
| 7034 | bootstrap, password) < 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7035 | if (wpa_s->create_p2p_iface) |
| 7036 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7037 | return -1; |
| 7038 | } |
| 7039 | return ret; |
| 7040 | } |
| 7041 | |
| 7042 | |
| 7043 | /** |
| 7044 | * wpas_p2p_remain_on_channel_cb - Indication of remain-on-channel start |
| 7045 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 7046 | * @freq: Frequency of the channel in MHz |
| 7047 | * @duration: Duration of the stay on the channel in milliseconds |
| 7048 | * |
| 7049 | * This callback is called when the driver indicates that it has started the |
| 7050 | * requested remain-on-channel duration. |
| 7051 | */ |
| 7052 | void wpas_p2p_remain_on_channel_cb(struct wpa_supplicant *wpa_s, |
| 7053 | unsigned int freq, unsigned int duration) |
| 7054 | { |
| 7055 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7056 | return; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7057 | 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)", |
| 7058 | wpa_s->off_channel_freq, wpa_s->pending_listen_freq, |
| 7059 | wpa_s->roc_waiting_drv_freq, freq, duration); |
| 7060 | if (wpa_s->off_channel_freq && |
| 7061 | wpa_s->off_channel_freq == wpa_s->pending_listen_freq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7062 | p2p_listen_cb(wpa_s->global->p2p, wpa_s->pending_listen_freq, |
| 7063 | wpa_s->pending_listen_duration); |
| 7064 | wpa_s->pending_listen_freq = 0; |
Dmitry Shmidt | 7f93d6f | 2014-02-21 11:22:49 -0800 | [diff] [blame] | 7065 | } else { |
| 7066 | wpa_printf(MSG_DEBUG, "P2P: Ignore remain-on-channel callback (off_channel_freq=%u pending_listen_freq=%d freq=%u duration=%u)", |
| 7067 | wpa_s->off_channel_freq, wpa_s->pending_listen_freq, |
| 7068 | freq, duration); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7069 | } |
| 7070 | } |
| 7071 | |
| 7072 | |
Jithu Jance | 57cea1a | 2014-08-20 10:22:04 -0700 | [diff] [blame] | 7073 | 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] | 7074 | { |
| 7075 | /* Limit maximum Listen state time based on driver limitation. */ |
| 7076 | if (timeout > wpa_s->max_remain_on_chan) |
| 7077 | timeout = wpa_s->max_remain_on_chan; |
| 7078 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7079 | return p2p_listen(wpa_s->global->p2p, timeout); |
| 7080 | } |
| 7081 | |
| 7082 | |
| 7083 | /** |
| 7084 | * wpas_p2p_cancel_remain_on_channel_cb - Remain-on-channel timeout |
| 7085 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 7086 | * @freq: Frequency of the channel in MHz |
| 7087 | * |
| 7088 | * This callback is called when the driver indicates that a remain-on-channel |
| 7089 | * operation has been completed, i.e., the duration on the requested channel |
| 7090 | * has timed out. |
| 7091 | */ |
| 7092 | void wpas_p2p_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s, |
| 7093 | unsigned int freq) |
| 7094 | { |
| 7095 | wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel callback " |
| 7096 | "(p2p_long_listen=%d ms pending_action_tx=%p)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7097 | wpa_s->global->p2p_long_listen, |
| 7098 | offchannel_pending_action_tx(wpa_s)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7099 | wpas_p2p_listen_work_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7100 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7101 | return; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7102 | if (wpa_s->global->p2p_long_listen > 0) |
| 7103 | wpa_s->global->p2p_long_listen -= wpa_s->max_remain_on_chan; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7104 | if (p2p_listen_end(wpa_s->global->p2p, freq) > 0) |
| 7105 | return; /* P2P module started a new operation */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7106 | if (offchannel_pending_action_tx(wpa_s)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7107 | return; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7108 | if (wpa_s->global->p2p_long_listen > 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7109 | wpa_printf(MSG_DEBUG, "P2P: Continuing long Listen state"); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7110 | wpas_p2p_listen_start(wpa_s, wpa_s->global->p2p_long_listen); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 7111 | } else { |
| 7112 | /* |
| 7113 | * When listen duration is over, stop listen & update p2p_state |
| 7114 | * to IDLE. |
| 7115 | */ |
| 7116 | p2p_stop_listen(wpa_s->global->p2p); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7117 | } |
| 7118 | } |
| 7119 | |
| 7120 | |
| 7121 | /** |
| 7122 | * wpas_p2p_group_remove - Remove a P2P group |
| 7123 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 7124 | * @ifname: Network interface name of the group interface or "*" to remove all |
| 7125 | * groups |
| 7126 | * Returns: 0 on success, -1 on failure |
| 7127 | * |
| 7128 | * This function is used to remove a P2P group. This can be used to disconnect |
| 7129 | * from a group in which the local end is a P2P Client or to end a P2P Group in |
| 7130 | * case the local end is the Group Owner. If a virtual network interface was |
| 7131 | * created for this group, that interface will be removed. Otherwise, only the |
| 7132 | * configured P2P group network will be removed from the interface. |
| 7133 | */ |
| 7134 | int wpas_p2p_group_remove(struct wpa_supplicant *wpa_s, const char *ifname) |
| 7135 | { |
| 7136 | struct wpa_global *global = wpa_s->global; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7137 | struct wpa_supplicant *calling_wpa_s = wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7138 | |
| 7139 | if (os_strcmp(ifname, "*") == 0) { |
| 7140 | struct wpa_supplicant *prev; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7141 | bool calling_wpa_s_group_removed = false; |
| 7142 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7143 | wpa_s = global->ifaces; |
| 7144 | while (wpa_s) { |
| 7145 | prev = wpa_s; |
| 7146 | wpa_s = wpa_s->next; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7147 | if (prev->p2p_group_interface != |
| 7148 | NOT_P2P_GROUP_INTERFACE || |
| 7149 | (prev->current_ssid && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7150 | prev->current_ssid->p2p_group)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7151 | wpas_p2p_disconnect_safely(prev, calling_wpa_s); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7152 | if (prev == calling_wpa_s) |
| 7153 | calling_wpa_s_group_removed = true; |
| 7154 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7155 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7156 | |
| 7157 | if (!calling_wpa_s_group_removed && |
| 7158 | (calling_wpa_s->p2p_group_interface != |
| 7159 | NOT_P2P_GROUP_INTERFACE || |
| 7160 | (calling_wpa_s->current_ssid && |
| 7161 | calling_wpa_s->current_ssid->p2p_group))) { |
| 7162 | wpa_printf(MSG_DEBUG, "Remove calling_wpa_s P2P group"); |
| 7163 | wpas_p2p_disconnect_safely(calling_wpa_s, |
| 7164 | calling_wpa_s); |
| 7165 | } |
| 7166 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7167 | return 0; |
| 7168 | } |
| 7169 | |
| 7170 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 7171 | if (os_strcmp(wpa_s->ifname, ifname) == 0) |
| 7172 | break; |
| 7173 | } |
| 7174 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7175 | return wpas_p2p_disconnect_safely(wpa_s, calling_wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7176 | } |
| 7177 | |
| 7178 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7179 | static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq) |
| 7180 | { |
| 7181 | unsigned int r; |
| 7182 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7183 | if (!wpa_s->conf->num_p2p_pref_chan && !freq) { |
| 7184 | unsigned int i, size = P2P_MAX_PREF_CHANNELS; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 7185 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7186 | int res; |
| 7187 | |
| 7188 | res = wpa_drv_get_pref_freq_list(wpa_s, WPA_IF_P2P_GO, |
| 7189 | &size, pref_freq_list); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 7190 | if (!res && size > 0 && !is_p2p_allow_6ghz(wpa_s->global->p2p)) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7191 | size = p2p_remove_6ghz_channels(pref_freq_list, size); |
| 7192 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7193 | if (!res && size > 0) { |
| 7194 | i = 0; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 7195 | while (i < size && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7196 | (!p2p_supported_freq(wpa_s->global->p2p, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 7197 | pref_freq_list[i].freq) || |
| 7198 | wpas_p2p_disallowed_freq( |
| 7199 | wpa_s->global, |
| 7200 | pref_freq_list[i].freq) || |
| 7201 | !p2p_pref_freq_allowed(&pref_freq_list[i], |
| 7202 | true))) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7203 | wpa_printf(MSG_DEBUG, |
| 7204 | "P2P: preferred_freq_list[%d]=%d is disallowed", |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 7205 | i, pref_freq_list[i].freq); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7206 | i++; |
| 7207 | } |
| 7208 | if (i != size) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 7209 | freq = pref_freq_list[i].freq; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7210 | wpa_printf(MSG_DEBUG, |
| 7211 | "P2P: Using preferred_freq_list[%d]=%d", |
| 7212 | i, freq); |
| 7213 | } else { |
| 7214 | wpa_printf(MSG_DEBUG, |
| 7215 | "P2P: All driver preferred frequencies are disallowed for P2P use"); |
| 7216 | } |
| 7217 | } else { |
| 7218 | wpa_printf(MSG_DEBUG, |
| 7219 | "P2P: No preferred frequency list available"); |
| 7220 | } |
| 7221 | } |
| 7222 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7223 | if (freq == 2) { |
| 7224 | wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 2.4 GHz " |
| 7225 | "band"); |
| 7226 | if (wpa_s->best_24_freq > 0 && |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7227 | p2p_supported_freq_go(wpa_s->global->p2p, |
| 7228 | wpa_s->best_24_freq)) { |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7229 | freq = wpa_s->best_24_freq; |
| 7230 | wpa_printf(MSG_DEBUG, "P2P: Use best 2.4 GHz band " |
| 7231 | "channel: %d MHz", freq); |
| 7232 | } else { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7233 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 7234 | return -1; |
Jimmy Chen | 801bf46 | 2021-11-09 23:08:48 +0800 | [diff] [blame] | 7235 | int possible_2g_freqs[] = { |
| 7236 | /* operating class 81 */ |
| 7237 | 2412, 2437, 2462, |
| 7238 | }; |
| 7239 | int possible_2g_freqs_num = |
| 7240 | sizeof(possible_2g_freqs)/sizeof(possible_2g_freqs[0]); |
| 7241 | int i; |
| 7242 | for (i = 0; i < possible_2g_freqs_num; i++, r++) { |
| 7243 | freq = possible_2g_freqs[r % possible_2g_freqs_num]; |
| 7244 | if (p2p_supported_freq_go(wpa_s->global->p2p, freq)) { |
| 7245 | break; |
| 7246 | } |
| 7247 | } |
| 7248 | |
| 7249 | if (i >= possible_2g_freqs_num) { |
| 7250 | wpa_printf(MSG_DEBUG, "P2P: Could not select " |
| 7251 | "2.4 GHz channel for P2P group"); |
| 7252 | return -1; |
| 7253 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7254 | wpa_printf(MSG_DEBUG, "P2P: Use random 2.4 GHz band " |
| 7255 | "channel: %d MHz", freq); |
| 7256 | } |
| 7257 | } |
| 7258 | |
| 7259 | if (freq == 5) { |
| 7260 | wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 5 GHz " |
| 7261 | "band"); |
| 7262 | if (wpa_s->best_5_freq > 0 && |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7263 | p2p_supported_freq_go(wpa_s->global->p2p, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7264 | wpa_s->best_5_freq)) { |
| 7265 | freq = wpa_s->best_5_freq; |
| 7266 | wpa_printf(MSG_DEBUG, "P2P: Use best 5 GHz band " |
| 7267 | "channel: %d MHz", freq); |
| 7268 | } else { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7269 | const int freqs[] = { |
| 7270 | /* operating class 115 */ |
| 7271 | 5180, 5200, 5220, 5240, |
| 7272 | /* operating class 124 */ |
| 7273 | 5745, 5765, 5785, 5805, |
| 7274 | }; |
| 7275 | unsigned int i, num_freqs = ARRAY_SIZE(freqs); |
| 7276 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7277 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 7278 | return -1; |
Jimmy Chen | 64b9063 | 2020-09-29 17:27:34 +0800 | [diff] [blame] | 7279 | |
| 7280 | /* |
| 7281 | * most of 5G channels are DFS, only operating class 115 and 124 |
| 7282 | * are available possibly, randomly pick a start to check them. |
| 7283 | */ |
| 7284 | int possible_5g_freqs[] = { |
| 7285 | /* operating class 115 */ |
| 7286 | 5180, 5200, 5220, 5240, |
| 7287 | /* operating class 124 */ |
| 7288 | 5745, 5765, 5785, 5805, |
| 7289 | }; |
| 7290 | int possible_5g_freqs_num = |
| 7291 | sizeof(possible_5g_freqs)/sizeof(possible_5g_freqs[0]); |
| 7292 | |
Jimmy Chen | 64b9063 | 2020-09-29 17:27:34 +0800 | [diff] [blame] | 7293 | for (i = 0; i < possible_5g_freqs_num; i++, r++) { |
| 7294 | if (p2p_supported_freq_go( |
| 7295 | wpa_s->global->p2p, |
| 7296 | possible_5g_freqs[r % possible_5g_freqs_num])) { |
| 7297 | freq = possible_5g_freqs[r % possible_5g_freqs_num]; |
| 7298 | break; |
| 7299 | } |
| 7300 | } |
| 7301 | |
| 7302 | if (i >= possible_5g_freqs_num) { |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7303 | wpa_printf(MSG_DEBUG, "P2P: Could not select " |
| 7304 | "5 GHz channel for P2P group"); |
| 7305 | return -1; |
| 7306 | } |
| 7307 | wpa_printf(MSG_DEBUG, "P2P: Use random 5 GHz band " |
| 7308 | "channel: %d MHz", freq); |
| 7309 | } |
| 7310 | } |
| 7311 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7312 | if (freq > 0 && !p2p_supported_freq_go(wpa_s->global->p2p, freq)) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 7313 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7314 | ieee80211_is_dfs(freq, wpa_s->hw.modes, |
| 7315 | wpa_s->hw.num_modes)) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 7316 | /* |
| 7317 | * If freq is a DFS channel and DFS is offloaded to the |
| 7318 | * driver, allow P2P GO to use it. |
| 7319 | */ |
| 7320 | wpa_printf(MSG_DEBUG, "P2P: " |
| 7321 | "%s: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded", |
| 7322 | __func__, freq); |
| 7323 | return freq; |
| 7324 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7325 | wpa_printf(MSG_DEBUG, "P2P: The forced channel for GO " |
| 7326 | "(%u MHz) is not supported for P2P uses", |
| 7327 | freq); |
| 7328 | return -1; |
| 7329 | } |
| 7330 | |
| 7331 | return freq; |
| 7332 | } |
| 7333 | |
| 7334 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7335 | static int wpas_p2p_supported_freq_go(struct wpa_supplicant *wpa_s, |
| 7336 | const struct p2p_channels *channels, |
| 7337 | int freq) |
| 7338 | { |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 7339 | if (is_6ghz_freq(freq) && |
| 7340 | !is_p2p_6ghz_capable(wpa_s->global->p2p)) |
| 7341 | return 0; |
| 7342 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7343 | if (!wpas_p2p_disallowed_freq(wpa_s->global, freq) && |
| 7344 | p2p_supported_freq_go(wpa_s->global->p2p, freq) && |
| 7345 | freq_included(wpa_s, channels, freq)) |
| 7346 | return 1; |
| 7347 | return 0; |
| 7348 | } |
| 7349 | |
| 7350 | |
| 7351 | static void wpas_p2p_select_go_freq_no_pref(struct wpa_supplicant *wpa_s, |
| 7352 | struct p2p_go_neg_results *params, |
| 7353 | const struct p2p_channels *channels) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7354 | { |
| 7355 | unsigned int i, r; |
| 7356 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 7357 | /* try all channels in operating class 115 */ |
| 7358 | for (i = 0; i < 4; i++) { |
| 7359 | params->freq = 5180 + i * 20; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7360 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 7361 | goto out; |
| 7362 | } |
| 7363 | |
| 7364 | /* try all channels in operating class 124 */ |
| 7365 | for (i = 0; i < 4; i++) { |
| 7366 | params->freq = 5745 + i * 20; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7367 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 7368 | goto out; |
| 7369 | } |
| 7370 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7371 | /* try social channel class 180 channel 2 */ |
| 7372 | params->freq = 58320 + 1 * 2160; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7373 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7374 | goto out; |
| 7375 | |
| 7376 | /* try all channels in reg. class 180 */ |
| 7377 | for (i = 0; i < 4; i++) { |
| 7378 | params->freq = 58320 + i * 2160; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7379 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7380 | goto out; |
| 7381 | } |
| 7382 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7383 | /* try some random selection of the social channels */ |
| 7384 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 7385 | return; |
| 7386 | |
| 7387 | for (i = 0; i < 3; i++) { |
| 7388 | params->freq = 2412 + ((r + i) % 3) * 25; |
| 7389 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
| 7390 | goto out; |
| 7391 | } |
| 7392 | |
| 7393 | /* try all other channels in operating class 81 */ |
| 7394 | for (i = 0; i < 11; i++) { |
| 7395 | params->freq = 2412 + i * 5; |
| 7396 | |
| 7397 | /* skip social channels; covered in the previous loop */ |
| 7398 | if (params->freq == 2412 || |
| 7399 | params->freq == 2437 || |
| 7400 | params->freq == 2462) |
| 7401 | continue; |
| 7402 | |
| 7403 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
| 7404 | goto out; |
| 7405 | } |
| 7406 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7407 | params->freq = 0; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 7408 | 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] | 7409 | return; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7410 | out: |
| 7411 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz (no preference known)", |
| 7412 | params->freq); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7413 | } |
| 7414 | |
| 7415 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7416 | static int wpas_same_band(int freq1, int freq2) |
| 7417 | { |
| 7418 | enum hostapd_hw_mode mode1, mode2; |
| 7419 | u8 chan1, chan2; |
| 7420 | |
| 7421 | mode1 = ieee80211_freq_to_chan(freq1, &chan1); |
| 7422 | mode2 = ieee80211_freq_to_chan(freq2, &chan2); |
| 7423 | if (mode1 == NUM_HOSTAPD_MODES) |
| 7424 | return 0; |
| 7425 | return mode1 == mode2; |
| 7426 | } |
| 7427 | |
| 7428 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7429 | static int wpas_p2p_init_go_params(struct wpa_supplicant *wpa_s, |
| 7430 | struct p2p_go_neg_results *params, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7431 | int freq, int vht_center_freq2, int ht40, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7432 | int vht, int max_oper_chwidth, int he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7433 | int edmg, |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7434 | const struct p2p_channels *channels) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7435 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7436 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7437 | unsigned int cand; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7438 | unsigned int num, i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7439 | int ignore_no_freqs = 0; |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 7440 | int unused_channels = wpas_p2p_num_unused_channels(wpa_s) > 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7441 | |
| 7442 | os_memset(params, 0, sizeof(*params)); |
| 7443 | params->role_go = 1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7444 | params->ht40 = ht40; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7445 | params->vht = vht; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7446 | params->he = he; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7447 | params->max_oper_chwidth = max_oper_chwidth; |
| 7448 | params->vht_center_freq2 = vht_center_freq2; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7449 | params->edmg = edmg; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 7450 | params->p2p2 = wpa_s->p2p2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7451 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7452 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 7453 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7454 | if (!freqs) |
| 7455 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7456 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7457 | num = get_shared_radio_freqs_data(wpa_s, freqs, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 7458 | wpa_s->num_multichan_concurrent, |
| 7459 | false); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7460 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7461 | if (wpa_s->current_ssid && |
| 7462 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO && |
| 7463 | wpa_s->wpa_state == WPA_COMPLETED) { |
| 7464 | wpa_printf(MSG_DEBUG, "P2P: %s called for an active GO", |
| 7465 | __func__); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7466 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7467 | /* |
| 7468 | * If the frequency selection is done for an active P2P GO that |
| 7469 | * is not sharing a frequency, allow to select a new frequency |
| 7470 | * even if there are no unused frequencies as we are about to |
| 7471 | * move the P2P GO so its frequency can be re-used. |
| 7472 | */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7473 | for (i = 0; i < num; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7474 | if (freqs[i].freq == wpa_s->current_ssid->frequency && |
| 7475 | freqs[i].flags == 0) { |
| 7476 | ignore_no_freqs = 1; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7477 | break; |
| 7478 | } |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7479 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7480 | } |
| 7481 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7482 | /* Try to use EDMG channel */ |
| 7483 | if (params->edmg) { |
| 7484 | if (wpas_p2p_try_edmg_channel(wpa_s, params) == 0) |
| 7485 | goto success; |
| 7486 | params->edmg = 0; |
| 7487 | } |
| 7488 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7489 | /* try using the forced freq */ |
| 7490 | if (freq) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7491 | if (wpas_p2p_disallowed_freq(wpa_s->global, freq) || |
| 7492 | !freq_included(wpa_s, channels, freq)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7493 | wpa_printf(MSG_DEBUG, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7494 | "P2P: Forced GO freq %d MHz disallowed", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7495 | freq); |
| 7496 | goto fail; |
| 7497 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7498 | if (!p2p_supported_freq_go(wpa_s->global->p2p, freq)) { |
| 7499 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7500 | ieee80211_is_dfs(freq, wpa_s->hw.modes, |
| 7501 | wpa_s->hw.num_modes)) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7502 | /* |
| 7503 | * If freq is a DFS channel and DFS is offloaded |
| 7504 | * to the driver, allow P2P GO to use it. |
| 7505 | */ |
| 7506 | wpa_printf(MSG_DEBUG, |
| 7507 | "P2P: %s: The forced channel for GO (%u MHz) requires DFS and DFS is offloaded", |
| 7508 | __func__, freq); |
| 7509 | } else { |
| 7510 | wpa_printf(MSG_DEBUG, |
| 7511 | "P2P: The forced channel for GO (%u MHz) is not supported for P2P uses", |
| 7512 | freq); |
| 7513 | goto fail; |
| 7514 | } |
| 7515 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7516 | |
| 7517 | for (i = 0; i < num; i++) { |
| 7518 | if (freqs[i].freq == freq) { |
| 7519 | wpa_printf(MSG_DEBUG, |
| 7520 | "P2P: forced freq (%d MHz) is also shared", |
| 7521 | freq); |
| 7522 | params->freq = freq; |
| 7523 | goto success; |
| 7524 | } |
| 7525 | } |
| 7526 | |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 7527 | if (!ignore_no_freqs && !unused_channels) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7528 | wpa_printf(MSG_DEBUG, |
| 7529 | "P2P: Cannot force GO on freq (%d MHz) as all the channels are in use", |
| 7530 | freq); |
| 7531 | goto fail; |
| 7532 | } |
| 7533 | |
| 7534 | wpa_printf(MSG_DEBUG, |
| 7535 | "P2P: force GO freq (%d MHz) on a free channel", |
| 7536 | freq); |
| 7537 | params->freq = freq; |
| 7538 | goto success; |
| 7539 | } |
| 7540 | |
| 7541 | /* consider using one of the shared frequencies */ |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 7542 | if (num && |
| 7543 | (!wpa_s->conf->p2p_ignore_shared_freq || !unused_channels)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7544 | cand = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num); |
| 7545 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 7546 | wpa_printf(MSG_DEBUG, |
| 7547 | "P2P: Use shared freq (%d MHz) for GO", |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 7548 | cand); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7549 | params->freq = cand; |
| 7550 | goto success; |
| 7551 | } |
| 7552 | |
| 7553 | /* try using one of the shared freqs */ |
| 7554 | for (i = 0; i < num; i++) { |
| 7555 | if (wpas_p2p_supported_freq_go(wpa_s, channels, |
| 7556 | freqs[i].freq)) { |
| 7557 | wpa_printf(MSG_DEBUG, |
| 7558 | "P2P: Use shared freq (%d MHz) for GO", |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 7559 | freqs[i].freq); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7560 | params->freq = freqs[i].freq; |
| 7561 | goto success; |
| 7562 | } |
| 7563 | } |
| 7564 | } |
| 7565 | |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 7566 | if (!ignore_no_freqs && !unused_channels) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7567 | wpa_printf(MSG_DEBUG, |
| 7568 | "P2P: Cannot force GO on any of the channels we are already using"); |
| 7569 | goto fail; |
| 7570 | } |
| 7571 | |
| 7572 | /* try using the setting from the configuration file */ |
| 7573 | if (wpa_s->conf->p2p_oper_reg_class == 81 && |
| 7574 | wpa_s->conf->p2p_oper_channel >= 1 && |
| 7575 | wpa_s->conf->p2p_oper_channel <= 11 && |
| 7576 | wpas_p2p_supported_freq_go( |
| 7577 | wpa_s, channels, |
| 7578 | 2407 + 5 * wpa_s->conf->p2p_oper_channel)) { |
| 7579 | params->freq = 2407 + 5 * wpa_s->conf->p2p_oper_channel; |
| 7580 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured " |
| 7581 | "frequency %d MHz", params->freq); |
| 7582 | goto success; |
| 7583 | } |
| 7584 | |
| 7585 | if ((wpa_s->conf->p2p_oper_reg_class == 115 || |
| 7586 | wpa_s->conf->p2p_oper_reg_class == 116 || |
| 7587 | wpa_s->conf->p2p_oper_reg_class == 117 || |
| 7588 | wpa_s->conf->p2p_oper_reg_class == 124 || |
| 7589 | wpa_s->conf->p2p_oper_reg_class == 125 || |
| 7590 | wpa_s->conf->p2p_oper_reg_class == 126 || |
| 7591 | wpa_s->conf->p2p_oper_reg_class == 127) && |
| 7592 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 7593 | 5000 + |
| 7594 | 5 * wpa_s->conf->p2p_oper_channel)) { |
| 7595 | params->freq = 5000 + 5 * wpa_s->conf->p2p_oper_channel; |
| 7596 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured " |
| 7597 | "frequency %d MHz", params->freq); |
| 7598 | goto success; |
| 7599 | } |
| 7600 | |
| 7601 | /* Try using best channels */ |
| 7602 | if (wpa_s->conf->p2p_oper_channel == 0 && |
| 7603 | wpa_s->best_overall_freq > 0 && |
| 7604 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 7605 | wpa_s->best_overall_freq)) { |
| 7606 | params->freq = wpa_s->best_overall_freq; |
| 7607 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best overall " |
| 7608 | "channel %d MHz", params->freq); |
| 7609 | goto success; |
| 7610 | } |
| 7611 | |
| 7612 | if (wpa_s->conf->p2p_oper_channel == 0 && |
| 7613 | wpa_s->best_24_freq > 0 && |
| 7614 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 7615 | wpa_s->best_24_freq)) { |
| 7616 | params->freq = wpa_s->best_24_freq; |
| 7617 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 2.4 GHz " |
| 7618 | "channel %d MHz", params->freq); |
| 7619 | goto success; |
| 7620 | } |
| 7621 | |
| 7622 | if (wpa_s->conf->p2p_oper_channel == 0 && |
| 7623 | wpa_s->best_5_freq > 0 && |
| 7624 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 7625 | wpa_s->best_5_freq)) { |
| 7626 | params->freq = wpa_s->best_5_freq; |
| 7627 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 5 GHz " |
| 7628 | "channel %d MHz", params->freq); |
| 7629 | goto success; |
| 7630 | } |
| 7631 | |
| 7632 | /* try using preferred channels */ |
| 7633 | cand = p2p_get_pref_freq(wpa_s->global->p2p, channels); |
| 7634 | if (cand && wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 7635 | params->freq = cand; |
| 7636 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz from preferred " |
| 7637 | "channels", params->freq); |
| 7638 | goto success; |
| 7639 | } |
| 7640 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7641 | /* Try using a channel that allows VHT to be used with 80 MHz */ |
| 7642 | if (wpa_s->hw.modes && wpa_s->p2p_group_common_freqs) { |
| 7643 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 7644 | enum hostapd_hw_mode mode; |
| 7645 | struct hostapd_hw_modes *hwmode; |
| 7646 | u8 chan; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7647 | u8 op_class; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7648 | |
| 7649 | cand = wpa_s->p2p_group_common_freqs[i]; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7650 | op_class = is_6ghz_freq(cand) ? 133 : 128; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7651 | mode = ieee80211_freq_to_chan(cand, &chan); |
| 7652 | hwmode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7653 | mode, is_6ghz_freq(cand)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7654 | if (!hwmode || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7655 | wpas_p2p_verify_channel(wpa_s, hwmode, op_class, |
| 7656 | chan, BW80) != ALLOWED) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7657 | continue; |
| 7658 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 7659 | params->freq = cand; |
| 7660 | wpa_printf(MSG_DEBUG, |
| 7661 | "P2P: Use freq %d MHz common with the peer and allowing VHT80", |
| 7662 | params->freq); |
| 7663 | goto success; |
| 7664 | } |
| 7665 | } |
| 7666 | } |
| 7667 | |
| 7668 | /* Try using a channel that allows HT to be used with 40 MHz on the same |
| 7669 | * band so that CSA can be used */ |
| 7670 | if (wpa_s->current_ssid && wpa_s->hw.modes && |
| 7671 | wpa_s->p2p_group_common_freqs) { |
| 7672 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 7673 | enum hostapd_hw_mode mode; |
| 7674 | struct hostapd_hw_modes *hwmode; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7675 | u8 chan, op_class; |
| 7676 | bool is_6ghz, supported = false; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7677 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7678 | is_6ghz = is_6ghz_freq(cand); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7679 | cand = wpa_s->p2p_group_common_freqs[i]; |
| 7680 | mode = ieee80211_freq_to_chan(cand, &chan); |
| 7681 | hwmode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7682 | mode, is_6ghz); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7683 | if (!wpas_same_band(wpa_s->current_ssid->frequency, |
| 7684 | cand) || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7685 | !hwmode) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7686 | continue; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7687 | if (is_6ghz && |
| 7688 | wpas_p2p_verify_channel(wpa_s, hwmode, 132, chan, |
| 7689 | BW40) == ALLOWED) |
| 7690 | supported = true; |
| 7691 | |
| 7692 | if (!is_6ghz && |
| 7693 | ieee80211_freq_to_channel_ext( |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 7694 | cand, -1, CONF_OPER_CHWIDTH_USE_HT, |
| 7695 | &op_class, &chan) != NUM_HOSTAPD_MODES && |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7696 | wpas_p2p_verify_channel( |
| 7697 | wpa_s, hwmode, op_class, chan, |
| 7698 | BW40MINUS) == ALLOWED) |
| 7699 | supported = true; |
| 7700 | |
| 7701 | if (!supported && !is_6ghz && |
| 7702 | ieee80211_freq_to_channel_ext( |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 7703 | cand, 1, CONF_OPER_CHWIDTH_USE_HT, |
| 7704 | &op_class, &chan) != NUM_HOSTAPD_MODES && |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7705 | wpas_p2p_verify_channel( |
| 7706 | wpa_s, hwmode, op_class, chan, |
| 7707 | BW40PLUS) == ALLOWED) |
| 7708 | supported = true; |
| 7709 | |
| 7710 | if (!supported) |
| 7711 | continue; |
| 7712 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7713 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 7714 | params->freq = cand; |
| 7715 | wpa_printf(MSG_DEBUG, |
| 7716 | "P2P: Use freq %d MHz common with the peer, allowing HT40, and maintaining same band", |
| 7717 | params->freq); |
| 7718 | goto success; |
| 7719 | } |
| 7720 | } |
| 7721 | } |
| 7722 | |
| 7723 | /* Try using one of the group common freqs on the same band so that CSA |
| 7724 | * can be used */ |
| 7725 | if (wpa_s->current_ssid && wpa_s->p2p_group_common_freqs) { |
| 7726 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 7727 | cand = wpa_s->p2p_group_common_freqs[i]; |
| 7728 | if (!wpas_same_band(wpa_s->current_ssid->frequency, |
| 7729 | cand)) |
| 7730 | continue; |
| 7731 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 7732 | params->freq = cand; |
| 7733 | wpa_printf(MSG_DEBUG, |
| 7734 | "P2P: Use freq %d MHz common with the peer and maintaining same band", |
| 7735 | params->freq); |
| 7736 | goto success; |
| 7737 | } |
| 7738 | } |
| 7739 | } |
| 7740 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7741 | /* Try using one of the group common freqs */ |
| 7742 | if (wpa_s->p2p_group_common_freqs) { |
| 7743 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 7744 | cand = wpa_s->p2p_group_common_freqs[i]; |
| 7745 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 7746 | params->freq = cand; |
| 7747 | wpa_printf(MSG_DEBUG, |
| 7748 | "P2P: Use freq %d MHz common with the peer", |
| 7749 | params->freq); |
| 7750 | goto success; |
| 7751 | } |
| 7752 | } |
| 7753 | } |
| 7754 | |
| 7755 | /* no preference, select some channel */ |
| 7756 | wpas_p2p_select_go_freq_no_pref(wpa_s, params, channels); |
| 7757 | |
| 7758 | if (params->freq == 0) { |
| 7759 | wpa_printf(MSG_DEBUG, "P2P: did not find a freq for GO use"); |
| 7760 | goto fail; |
| 7761 | } |
| 7762 | |
| 7763 | success: |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7764 | os_free(freqs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7765 | return 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7766 | fail: |
| 7767 | os_free(freqs); |
| 7768 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7769 | } |
| 7770 | |
| 7771 | |
| 7772 | static struct wpa_supplicant * |
| 7773 | wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated, |
| 7774 | int go) |
| 7775 | { |
| 7776 | struct wpa_supplicant *group_wpa_s; |
| 7777 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7778 | if (!wpas_p2p_create_iface(wpa_s)) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7779 | if (wpa_s->p2p_mgmt) { |
| 7780 | /* |
| 7781 | * We may be called on the p2p_dev interface which |
| 7782 | * cannot be used for group operations, so always use |
| 7783 | * the primary interface. |
| 7784 | */ |
| 7785 | wpa_s->parent->p2pdev = wpa_s; |
| 7786 | wpa_s = wpa_s->parent; |
| 7787 | } |
| 7788 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 7789 | "P2P: Use primary interface for group operations"); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7790 | wpa_s->p2p_first_connection_timeout = 0; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7791 | if (wpa_s != wpa_s->p2pdev) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 7792 | wpas_p2p_clone_config(wpa_s, wpa_s->p2pdev); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7793 | return wpa_s; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7794 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7795 | |
| 7796 | 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] | 7797 | WPA_IF_P2P_CLIENT) < 0) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 7798 | wpa_msg_global(wpa_s, MSG_ERROR, |
| 7799 | "P2P: Failed to add group interface"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7800 | return NULL; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7801 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7802 | group_wpa_s = wpas_p2p_init_group_interface(wpa_s, go); |
| 7803 | if (group_wpa_s == NULL) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 7804 | wpa_msg_global(wpa_s, MSG_ERROR, |
| 7805 | "P2P: Failed to initialize group interface"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7806 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 7807 | return NULL; |
| 7808 | } |
| 7809 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7810 | if (go && wpa_s->p2p_go_do_acs) { |
| 7811 | group_wpa_s->p2p_go_do_acs = wpa_s->p2p_go_do_acs; |
| 7812 | group_wpa_s->p2p_go_acs_band = wpa_s->p2p_go_acs_band; |
| 7813 | wpa_s->p2p_go_do_acs = 0; |
| 7814 | } |
| 7815 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7816 | if (go && wpa_s->p2p_go_allow_dfs) { |
| 7817 | group_wpa_s->p2p_go_allow_dfs = wpa_s->p2p_go_allow_dfs; |
| 7818 | wpa_s->p2p_go_allow_dfs = 0; |
| 7819 | } |
| 7820 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7821 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use separate group interface %s", |
| 7822 | group_wpa_s->ifname); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7823 | group_wpa_s->p2p_first_connection_timeout = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7824 | return group_wpa_s; |
| 7825 | } |
| 7826 | |
| 7827 | |
| 7828 | /** |
| 7829 | * wpas_p2p_group_add - Add a new P2P group with local end as Group Owner |
| 7830 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 7831 | * @persistent_group: Whether to create a persistent group |
| 7832 | * @freq: Frequency for the group or 0 to indicate no hardcoding |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7833 | * @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] | 7834 | * @ht40: Start GO with 40 MHz channel width |
| 7835 | * @vht: Start GO with VHT support |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7836 | * @vht_chwidth: channel bandwidth for GO operating with VHT support |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7837 | * @edmg: Start GO with EDMG support |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7838 | * @allow_6ghz: Allow P2P group creation on a 6 GHz channel |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 7839 | * @p2p_mode: Operation mode for GO (R1/R2/PCC) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7840 | * Returns: 0 on success, -1 on failure |
| 7841 | * |
| 7842 | * This function creates a new P2P group with the local end as the Group Owner, |
| 7843 | * i.e., without using Group Owner Negotiation. |
| 7844 | */ |
| 7845 | 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] | 7846 | int freq, int vht_center_freq2, int ht40, int vht, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7847 | int max_oper_chwidth, int he, int edmg, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 7848 | bool allow_6ghz, bool p2p2, enum wpa_p2p_mode p2p_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7849 | { |
| 7850 | struct p2p_go_neg_results params; |
Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 7851 | int selected_freq = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7852 | |
| 7853 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7854 | return -1; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7855 | if (wpas_p2p_check_6ghz(wpa_s, NULL, allow_6ghz, freq)) |
| 7856 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7857 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 7858 | os_free(wpa_s->global->add_psk); |
| 7859 | wpa_s->global->add_psk = NULL; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 7860 | wpa_s->p2p2 = p2p2; |
| 7861 | wpa_s->p2p_mode = p2p_mode; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 7862 | |
Dmitry Shmidt | dca3979 | 2011-09-06 11:17:33 -0700 | [diff] [blame] | 7863 | /* Make sure we are not running find during connection establishment */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7864 | wpa_printf(MSG_DEBUG, "P2P: Stop any on-going P2P FIND"); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7865 | wpas_p2p_stop_find_oper(wpa_s); |
Dmitry Shmidt | dca3979 | 2011-09-06 11:17:33 -0700 | [diff] [blame] | 7866 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7867 | if (!wpa_s->p2p_go_do_acs) { |
Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 7868 | selected_freq = wpas_p2p_select_go_freq(wpa_s, freq); |
| 7869 | if (selected_freq < 0) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7870 | return -1; |
| 7871 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7872 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 7873 | if (wpas_p2p_init_go_params(wpa_s, ¶ms, selected_freq, |
| 7874 | vht_center_freq2, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7875 | ht40, vht, max_oper_chwidth, he, edmg, |
| 7876 | NULL)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7877 | return -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7878 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7879 | p2p_go_params(wpa_s->global->p2p, ¶ms); |
| 7880 | params.persistent_group = persistent_group; |
| 7881 | |
| 7882 | wpa_s = wpas_p2p_get_group_iface(wpa_s, 0, 1); |
| 7883 | if (wpa_s == NULL) |
| 7884 | return -1; |
Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 7885 | if (freq > 0) |
| 7886 | wpa_s->p2p_go_no_pri_sec_switch = 1; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 7887 | params.p2p2 = wpa_s->p2p2; |
| 7888 | wpas_start_go(wpa_s, ¶ms, 0, p2p_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7889 | |
| 7890 | return 0; |
| 7891 | } |
| 7892 | |
| 7893 | |
| 7894 | static int wpas_start_p2p_client(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7895 | struct wpa_ssid *params, int addr_allocated, |
Matthew Wang | 124e5f4 | 2022-12-29 07:23:06 +0000 | [diff] [blame] | 7896 | int freq, int force_scan, int retry_limit, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 7897 | const u8 *go_bssid, bool p2p2, const u8 *pmkid, |
| 7898 | const u8 *pmk, size_t pmk_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7899 | { |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 7900 | struct os_reltime now; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7901 | struct wpa_ssid *ssid; |
Matthew Wang | 9ae940b | 2022-09-14 21:25:34 -0700 | [diff] [blame] | 7902 | int other_iface_found = 0; |
| 7903 | struct wpa_supplicant *ifs; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 7904 | struct rsn_pmksa_cache_entry *entry; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7905 | |
| 7906 | wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 0); |
| 7907 | if (wpa_s == NULL) |
| 7908 | return -1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7909 | if (force_scan) |
| 7910 | os_get_reltime(&wpa_s->scan_min_time); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 7911 | wpa_s->p2p_last_4way_hs_fail = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7912 | |
| 7913 | wpa_supplicant_ap_deinit(wpa_s); |
| 7914 | |
| 7915 | ssid = wpa_config_add_network(wpa_s->conf); |
| 7916 | if (ssid == NULL) |
| 7917 | return -1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7918 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7919 | wpa_config_set_network_defaults(ssid); |
| 7920 | ssid->temporary = 1; |
| 7921 | ssid->proto = WPA_PROTO_RSN; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7922 | ssid->pbss = params->pbss; |
| 7923 | ssid->pairwise_cipher = params->pbss ? WPA_CIPHER_GCMP : |
| 7924 | WPA_CIPHER_CCMP; |
| 7925 | ssid->group_cipher = params->pbss ? WPA_CIPHER_GCMP : WPA_CIPHER_CCMP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7926 | ssid->key_mgmt = WPA_KEY_MGMT_PSK; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 7927 | if (is_6ghz_freq(freq) && |
| 7928 | is_p2p_6ghz_capable(wpa_s->global->p2p)) { |
| 7929 | ssid->auth_alg |= WPA_AUTH_ALG_SAE; |
| 7930 | ssid->key_mgmt |= WPA_KEY_MGMT_SAE; |
| 7931 | ssid->ieee80211w = MGMT_FRAME_PROTECTION_OPTIONAL; |
| 7932 | ssid->sae_pwe = SAE_PWE_HASH_TO_ELEMENT; |
| 7933 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 7934 | "P2P: Enable SAE auth_alg and key_mgmt"); |
| 7935 | } |
| 7936 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7937 | ssid->ssid = os_malloc(params->ssid_len); |
| 7938 | if (ssid->ssid == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7939 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 7940 | return -1; |
| 7941 | } |
| 7942 | os_memcpy(ssid->ssid, params->ssid, params->ssid_len); |
| 7943 | ssid->ssid_len = params->ssid_len; |
| 7944 | ssid->p2p_group = 1; |
| 7945 | ssid->export_keys = 1; |
| 7946 | if (params->psk_set) { |
| 7947 | os_memcpy(ssid->psk, params->psk, 32); |
| 7948 | ssid->psk_set = 1; |
| 7949 | } |
| 7950 | if (params->passphrase) |
| 7951 | ssid->passphrase = os_strdup(params->passphrase); |
| 7952 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 7953 | if (go_bssid) { |
Matthew Wang | dcf1945 | 2022-11-07 20:42:52 -0800 | [diff] [blame] | 7954 | ssid->bssid_set = 1; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 7955 | os_memcpy(ssid->bssid, go_bssid, ETH_ALEN); |
Matthew Wang | dcf1945 | 2022-11-07 20:42:52 -0800 | [diff] [blame] | 7956 | } |
| 7957 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 7958 | if (p2p2) { |
| 7959 | ssid->key_mgmt = WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_PASN; |
| 7960 | ssid->auth_alg = WPA_AUTH_ALG_OPEN; |
| 7961 | ssid->sae_pwe = SAE_PWE_HASH_TO_ELEMENT; |
| 7962 | ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED; |
| 7963 | ssid->disabled = 0; |
| 7964 | |
| 7965 | if (pmk && pmk_len && pmkid) { |
| 7966 | entry = os_zalloc(sizeof(*entry)); |
| 7967 | if (!entry) |
| 7968 | return -1; |
| 7969 | os_memcpy(entry->aa, ssid->bssid, ETH_ALEN); |
| 7970 | os_memcpy(entry->pmkid, pmkid, PMKID_LEN); |
| 7971 | entry->pmk_len = pmk_len; |
| 7972 | os_memcpy(entry->pmk, pmk, pmk_len); |
| 7973 | entry->akmp = WPA_KEY_MGMT_SAE; |
| 7974 | os_get_reltime(&now); |
| 7975 | entry->expiration = now.sec + 43200; |
| 7976 | entry->reauth_time = now.sec + 43200 * 70 / 100; |
| 7977 | entry->network_ctx = ssid; |
| 7978 | os_memcpy(entry->spa, wpa_s->own_addr, ETH_ALEN); |
| 7979 | |
| 7980 | wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry); |
| 7981 | ssid->pmk_valid = true; |
| 7982 | } |
| 7983 | wpa_s->current_ssid = ssid; |
| 7984 | } |
| 7985 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7986 | wpa_s->show_group_started = 1; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7987 | wpa_s->p2p_in_invitation = 1; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 7988 | wpa_s->p2p_retry_limit = retry_limit; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7989 | wpa_s->p2p_invite_go_freq = freq; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7990 | wpa_s->p2p_go_group_formation_completed = 0; |
| 7991 | wpa_s->global->p2p_group_formation = wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7992 | |
Matthew Wang | 9ae940b | 2022-09-14 21:25:34 -0700 | [diff] [blame] | 7993 | /* |
| 7994 | * Get latest scan results from driver in case cached scan results from |
| 7995 | * interfaces on the same wiphy allow us to skip the next scan by fast |
| 7996 | * associating. Also update the scan time to the most recent scan result |
| 7997 | * fetch time on the same radio so it reflects the actual time the last |
| 7998 | * scan result event occurred. |
| 7999 | */ |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 8000 | wpa_supplicant_update_scan_results(wpa_s, go_bssid); |
Matthew Wang | 9ae940b | 2022-09-14 21:25:34 -0700 | [diff] [blame] | 8001 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 8002 | radio_list) { |
| 8003 | if (ifs == wpa_s) |
| 8004 | continue; |
| 8005 | if (!other_iface_found || os_reltime_before(&wpa_s->last_scan, |
| 8006 | &ifs->last_scan)) { |
| 8007 | other_iface_found = 1; |
| 8008 | wpa_s->last_scan.sec = ifs->last_scan.sec; |
| 8009 | wpa_s->last_scan.usec = ifs->last_scan.usec; |
| 8010 | } |
| 8011 | } |
| 8012 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8013 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->p2pdev, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 8014 | NULL); |
| 8015 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, |
| 8016 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8017 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 8018 | wpa_supplicant_select_network(wpa_s, ssid); |
| 8019 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8020 | return 0; |
| 8021 | } |
| 8022 | |
| 8023 | |
| 8024 | int wpas_p2p_group_add_persistent(struct wpa_supplicant *wpa_s, |
| 8025 | struct wpa_ssid *ssid, int addr_allocated, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8026 | int force_freq, int neg_freq, |
| 8027 | int vht_center_freq2, int ht40, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8028 | int vht, int max_oper_chwidth, int he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8029 | int edmg, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8030 | const struct p2p_channels *channels, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 8031 | int connection_timeout, int force_scan, |
Matthew Wang | 124e5f4 | 2022-12-29 07:23:06 +0000 | [diff] [blame] | 8032 | bool allow_6ghz, int retry_limit, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 8033 | const u8 *go_bssid, const u8 *dev_addr, |
| 8034 | const u8 *pmkid, const u8 *pmk, |
| 8035 | size_t pmk_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8036 | { |
| 8037 | struct p2p_go_neg_results params; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 8038 | int go = 0, freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8039 | |
| 8040 | if (ssid->disabled != 2 || ssid->ssid == NULL) |
| 8041 | return -1; |
| 8042 | |
| 8043 | if (wpas_get_p2p_group(wpa_s, ssid->ssid, ssid->ssid_len, &go) && |
| 8044 | go == (ssid->mode == WPAS_MODE_P2P_GO)) { |
| 8045 | wpa_printf(MSG_DEBUG, "P2P: Requested persistent group is " |
| 8046 | "already running"); |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 8047 | if (go == 0 && |
| 8048 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8049 | wpa_s->p2pdev, NULL)) { |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 8050 | /* |
| 8051 | * This can happen if Invitation Response frame was lost |
| 8052 | * and the peer (GO of a persistent group) tries to |
| 8053 | * invite us again. Reschedule the timeout to avoid |
| 8054 | * terminating the wait for the connection too early |
| 8055 | * since we now know that the peer is still trying to |
| 8056 | * invite us instead of having already started the GO. |
| 8057 | */ |
| 8058 | wpa_printf(MSG_DEBUG, |
| 8059 | "P2P: Reschedule group formation timeout since peer is still trying to invite us"); |
| 8060 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, |
| 8061 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8062 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 8063 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8064 | return 0; |
| 8065 | } |
| 8066 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8067 | os_free(wpa_s->global->add_psk); |
| 8068 | wpa_s->global->add_psk = NULL; |
| 8069 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8070 | /* Make sure we are not running find during connection establishment */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 8071 | wpas_p2p_stop_find_oper(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8072 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8073 | wpa_s->p2p_fallback_to_go_neg = 0; |
| 8074 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8075 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 8076 | if (force_freq > 0) { |
| 8077 | freq = wpas_p2p_select_go_freq(wpa_s, force_freq); |
| 8078 | if (freq < 0) |
| 8079 | return -1; |
Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 8080 | wpa_s->p2p_go_no_pri_sec_switch = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8081 | } else { |
| 8082 | freq = wpas_p2p_select_go_freq(wpa_s, neg_freq); |
| 8083 | if (freq < 0 || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8084 | (freq > 0 && !freq_included(wpa_s, channels, freq))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8085 | freq = 0; |
| 8086 | } |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 8087 | } else if (ssid->mode == WPAS_MODE_INFRA) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8088 | freq = neg_freq; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8089 | if (freq <= 0 || !freq_included(wpa_s, channels, freq)) { |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 8090 | struct os_reltime now; |
| 8091 | struct wpa_bss *bss = |
| 8092 | wpa_bss_get_p2p_dev_addr(wpa_s, ssid->bssid); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 8093 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 8094 | os_get_reltime(&now); |
| 8095 | if (bss && |
| 8096 | !os_reltime_expired(&now, &bss->last_update, 5) && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8097 | freq_included(wpa_s, channels, bss->freq)) |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 8098 | freq = bss->freq; |
| 8099 | else |
| 8100 | freq = 0; |
| 8101 | } |
| 8102 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8103 | return wpas_start_p2p_client(wpa_s, ssid, addr_allocated, freq, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 8104 | force_scan, retry_limit, go_bssid, |
| 8105 | wpa_s->p2p2, pmkid, pmk, pmk_len); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 8106 | } else { |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 8107 | return -1; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 8108 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 8109 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8110 | 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] | 8111 | ht40, vht, max_oper_chwidth, he, edmg, |
| 8112 | channels)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8113 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8114 | |
| 8115 | params.role_go = 1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 8116 | params.psk_set = ssid->psk_set; |
| 8117 | if (params.psk_set) |
| 8118 | os_memcpy(params.psk, ssid->psk, sizeof(params.psk)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8119 | if (ssid->passphrase) { |
| 8120 | if (os_strlen(ssid->passphrase) >= sizeof(params.passphrase)) { |
| 8121 | wpa_printf(MSG_ERROR, "P2P: Invalid passphrase in " |
| 8122 | "persistent group"); |
| 8123 | return -1; |
| 8124 | } |
| 8125 | os_strlcpy(params.passphrase, ssid->passphrase, |
| 8126 | sizeof(params.passphrase)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8127 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8128 | os_memcpy(params.ssid, ssid->ssid, ssid->ssid_len); |
| 8129 | params.ssid_len = ssid->ssid_len; |
| 8130 | params.persistent_group = 1; |
| 8131 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 8132 | if (wpa_s->p2p2 && pmk_len && pmk && pmkid) { |
| 8133 | os_memcpy(params.peer_device_addr, dev_addr, ETH_ALEN); |
| 8134 | os_memcpy(params.pmkid, pmkid, PMKID_LEN); |
| 8135 | os_memcpy(params.pmk, pmk, pmk_len); |
| 8136 | params.pmk_len = pmk_len; |
| 8137 | params.akmp = WPA_KEY_MGMT_SAE; |
| 8138 | params.p2p2 = true; |
| 8139 | } |
| 8140 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8141 | wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 1); |
| 8142 | if (wpa_s == NULL) |
| 8143 | return -1; |
| 8144 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8145 | p2p_channels_to_freqs(channels, params.freq_list, P2P_MAX_CHANNELS); |
| 8146 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8147 | wpa_s->p2p_first_connection_timeout = connection_timeout; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 8148 | params.p2p2 = wpa_s->p2p2; |
| 8149 | wpas_start_go(wpa_s, ¶ms, 0, wpa_s->p2p_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8150 | |
| 8151 | return 0; |
| 8152 | } |
| 8153 | |
| 8154 | |
| 8155 | static void wpas_p2p_ie_update(void *ctx, struct wpabuf *beacon_ies, |
| 8156 | struct wpabuf *proberesp_ies) |
| 8157 | { |
| 8158 | struct wpa_supplicant *wpa_s = ctx; |
| 8159 | if (wpa_s->ap_iface) { |
| 8160 | struct hostapd_data *hapd = wpa_s->ap_iface->bss[0]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8161 | if (!(hapd->conf->p2p & P2P_GROUP_OWNER)) { |
| 8162 | wpabuf_free(beacon_ies); |
| 8163 | wpabuf_free(proberesp_ies); |
| 8164 | return; |
| 8165 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8166 | if (beacon_ies) { |
| 8167 | wpabuf_free(hapd->p2p_beacon_ie); |
| 8168 | hapd->p2p_beacon_ie = beacon_ies; |
| 8169 | } |
| 8170 | wpabuf_free(hapd->p2p_probe_resp_ie); |
| 8171 | hapd->p2p_probe_resp_ie = proberesp_ies; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 8172 | |
| 8173 | if (wpa_s->p2p2) { |
| 8174 | hapd->iconf->peer_to_peer_twt = true; |
| 8175 | hapd->iconf->channel_usage = true; |
| 8176 | } |
| 8177 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8178 | } else { |
| 8179 | wpabuf_free(beacon_ies); |
| 8180 | wpabuf_free(proberesp_ies); |
| 8181 | } |
| 8182 | wpa_supplicant_ap_update_beacon(wpa_s); |
| 8183 | } |
| 8184 | |
| 8185 | |
| 8186 | static void wpas_p2p_idle_update(void *ctx, int idle) |
| 8187 | { |
| 8188 | struct wpa_supplicant *wpa_s = ctx; |
| 8189 | if (!wpa_s->ap_iface) |
| 8190 | return; |
| 8191 | wpa_printf(MSG_DEBUG, "P2P: GO - group %sidle", idle ? "" : "not "); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8192 | if (idle) { |
| 8193 | if (wpa_s->global->p2p_fail_on_wps_complete && |
| 8194 | wpa_s->p2p_in_provisioning) { |
| 8195 | wpas_p2p_grpform_fail_after_wps(wpa_s); |
| 8196 | return; |
| 8197 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8198 | wpas_p2p_set_group_idle_timeout(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8199 | } else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8200 | eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL); |
| 8201 | } |
| 8202 | |
| 8203 | |
| 8204 | struct p2p_group * wpas_p2p_group_init(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8205 | struct wpa_ssid *ssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8206 | { |
| 8207 | struct p2p_group *group; |
| 8208 | struct p2p_group_config *cfg; |
| 8209 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 8210 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL || |
| 8211 | !ssid->p2p_group) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8212 | return NULL; |
| 8213 | |
| 8214 | cfg = os_zalloc(sizeof(*cfg)); |
| 8215 | if (cfg == NULL) |
| 8216 | return NULL; |
| 8217 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8218 | if (ssid->p2p_persistent_group && wpa_s->conf->persistent_reconnect) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8219 | cfg->persistent_group = 2; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8220 | else if (ssid->p2p_persistent_group) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8221 | cfg->persistent_group = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8222 | os_memcpy(cfg->interface_addr, wpa_s->own_addr, ETH_ALEN); |
| 8223 | if (wpa_s->max_stations && |
| 8224 | wpa_s->max_stations < wpa_s->conf->max_num_sta) |
| 8225 | cfg->max_clients = wpa_s->max_stations; |
| 8226 | else |
| 8227 | cfg->max_clients = wpa_s->conf->max_num_sta; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8228 | os_memcpy(cfg->ssid, ssid->ssid, ssid->ssid_len); |
| 8229 | cfg->ssid_len = ssid->ssid_len; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 8230 | cfg->freq = ssid->frequency; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8231 | cfg->cb_ctx = wpa_s; |
| 8232 | cfg->ie_update = wpas_p2p_ie_update; |
| 8233 | cfg->idle_update = wpas_p2p_idle_update; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 8234 | cfg->ip_addr_alloc = WPA_GET_BE32(wpa_s->p2pdev->conf->ip_addr_start) |
| 8235 | != 0; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 8236 | cfg->p2p2 = wpa_s->p2p2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8237 | |
| 8238 | group = p2p_group_init(wpa_s->global->p2p, cfg); |
| 8239 | if (group == NULL) |
| 8240 | os_free(cfg); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8241 | if (ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8242 | p2p_group_notif_formation_done(group); |
| 8243 | wpa_s->p2p_group = group; |
| 8244 | return group; |
| 8245 | } |
| 8246 | |
| 8247 | |
| 8248 | void wpas_p2p_wps_success(struct wpa_supplicant *wpa_s, const u8 *peer_addr, |
| 8249 | int registrar) |
| 8250 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8251 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 8252 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8253 | if (!wpa_s->p2p_in_provisioning) { |
| 8254 | wpa_printf(MSG_DEBUG, "P2P: Ignore WPS success event - P2P " |
| 8255 | "provisioning not in progress"); |
| 8256 | return; |
| 8257 | } |
| 8258 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8259 | if (ssid && ssid->mode == WPAS_MODE_INFRA) { |
| 8260 | u8 go_dev_addr[ETH_ALEN]; |
| 8261 | os_memcpy(go_dev_addr, wpa_s->bssid, ETH_ALEN); |
| 8262 | wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid, |
| 8263 | ssid->ssid_len); |
| 8264 | /* Clear any stored provisioning info */ |
| 8265 | p2p_clear_provisioning_info(wpa_s->global->p2p, go_dev_addr); |
| 8266 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8267 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8268 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->p2pdev, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8269 | NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8270 | wpa_s->p2p_go_group_formation_completed = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8271 | if (ssid && ssid->mode == WPAS_MODE_INFRA) { |
| 8272 | /* |
| 8273 | * Use a separate timeout for initial data connection to |
| 8274 | * complete to allow the group to be removed automatically if |
| 8275 | * something goes wrong in this step before the P2P group idle |
| 8276 | * timeout mechanism is taken into use. |
| 8277 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8278 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 8279 | "P2P: Re-start group formation timeout (%d seconds) as client for initial connection", |
| 8280 | P2P_MAX_INITIAL_CONN_WAIT); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8281 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, |
| 8282 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8283 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8284 | /* Complete group formation on successful data connection. */ |
| 8285 | wpa_s->p2p_go_group_formation_completed = 0; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8286 | } else if (ssid) { |
| 8287 | /* |
| 8288 | * Use a separate timeout for initial data connection to |
| 8289 | * complete to allow the group to be removed automatically if |
| 8290 | * the client does not complete data connection successfully. |
| 8291 | */ |
| 8292 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 8293 | "P2P: Re-start group formation timeout (%d seconds) as GO for initial connection", |
| 8294 | P2P_MAX_INITIAL_CONN_WAIT_GO); |
| 8295 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT_GO, 0, |
| 8296 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8297 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8298 | /* |
| 8299 | * Complete group formation on first successful data connection |
| 8300 | */ |
| 8301 | wpa_s->p2p_go_group_formation_completed = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8302 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8303 | if (wpa_s->global->p2p) |
| 8304 | p2p_wps_success_cb(wpa_s->global->p2p, peer_addr); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8305 | wpas_group_formation_completed(wpa_s, 1, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8306 | } |
| 8307 | |
| 8308 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8309 | void wpas_p2p_wps_failed(struct wpa_supplicant *wpa_s, |
| 8310 | struct wps_event_fail *fail) |
| 8311 | { |
| 8312 | if (!wpa_s->p2p_in_provisioning) { |
| 8313 | wpa_printf(MSG_DEBUG, "P2P: Ignore WPS fail event - P2P " |
| 8314 | "provisioning not in progress"); |
| 8315 | return; |
| 8316 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8317 | |
| 8318 | if (wpa_s->go_params) { |
| 8319 | p2p_clear_provisioning_info( |
| 8320 | wpa_s->global->p2p, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8321 | wpa_s->go_params->peer_device_addr); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8322 | } |
| 8323 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8324 | wpas_notify_p2p_wps_failed(wpa_s, fail); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8325 | |
| 8326 | if (wpa_s == wpa_s->global->p2p_group_formation) { |
| 8327 | /* |
| 8328 | * Allow some time for the failed WPS negotiation exchange to |
| 8329 | * complete, but remove the group since group formation cannot |
| 8330 | * succeed after provisioning failure. |
| 8331 | */ |
| 8332 | wpa_printf(MSG_DEBUG, "P2P: WPS step failed during group formation - reject connection from timeout"); |
| 8333 | wpa_s->global->p2p_fail_on_wps_complete = 1; |
| 8334 | eloop_deplete_timeout(0, 50000, |
| 8335 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8336 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8337 | } |
| 8338 | } |
| 8339 | |
| 8340 | |
| 8341 | int wpas_p2p_wps_eapol_cb(struct wpa_supplicant *wpa_s) |
| 8342 | { |
| 8343 | if (!wpa_s->global->p2p_fail_on_wps_complete || |
| 8344 | !wpa_s->p2p_in_provisioning) |
| 8345 | return 0; |
| 8346 | |
| 8347 | wpas_p2p_grpform_fail_after_wps(wpa_s); |
| 8348 | |
| 8349 | return 1; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8350 | } |
| 8351 | |
| 8352 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8353 | 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] | 8354 | const char *config_method, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 8355 | enum wpas_p2p_prov_disc_use use, |
| 8356 | struct p2ps_provision *p2ps_prov) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8357 | { |
| 8358 | u16 config_methods; |
| 8359 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 8360 | wpa_s->global->pending_p2ps_group = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8361 | wpa_s->global->pending_p2ps_group_freq = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8362 | wpa_s->p2p_fallback_to_go_neg = 0; |
| 8363 | wpa_s->pending_pd_use = NORMAL_PD; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 8364 | if (p2ps_prov && use == WPAS_P2P_PD_FOR_ASP) { |
| 8365 | p2ps_prov->conncap = p2ps_group_capability( |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8366 | wpa_s, P2PS_SETUP_NONE, p2ps_prov->role, |
| 8367 | &p2ps_prov->force_freq, &p2ps_prov->pref_freq); |
| 8368 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 8369 | wpa_printf(MSG_DEBUG, |
| 8370 | "P2P: %s conncap: %d - ASP parsed: %x %x %d %s", |
| 8371 | __func__, p2ps_prov->conncap, |
| 8372 | p2ps_prov->adv_id, p2ps_prov->conncap, |
| 8373 | p2ps_prov->status, p2ps_prov->info); |
| 8374 | |
| 8375 | config_methods = 0; |
| 8376 | } else if (os_strncmp(config_method, "display", 7) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8377 | config_methods = WPS_CONFIG_DISPLAY; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8378 | else if (os_strncmp(config_method, "keypad", 6) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8379 | config_methods = WPS_CONFIG_KEYPAD; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8380 | else if (os_strncmp(config_method, "pbc", 3) == 0 || |
| 8381 | os_strncmp(config_method, "pushbutton", 10) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8382 | config_methods = WPS_CONFIG_PUSHBUTTON; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8383 | else { |
| 8384 | wpa_printf(MSG_DEBUG, "P2P: Unknown config method"); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 8385 | os_free(p2ps_prov); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8386 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8387 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8388 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8389 | if (use == WPAS_P2P_PD_AUTO) { |
| 8390 | os_memcpy(wpa_s->pending_join_dev_addr, peer_addr, ETH_ALEN); |
| 8391 | wpa_s->pending_pd_config_methods = config_methods; |
| 8392 | wpa_s->p2p_auto_pd = 1; |
| 8393 | wpa_s->p2p_auto_join = 0; |
| 8394 | wpa_s->pending_pd_before_join = 0; |
| 8395 | wpa_s->auto_pd_scan_retry = 0; |
| 8396 | wpas_p2p_stop_find(wpa_s); |
| 8397 | wpa_s->p2p_join_scan_count = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8398 | os_get_reltime(&wpa_s->p2p_auto_started); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8399 | wpa_printf(MSG_DEBUG, "P2P: Auto PD started at %ld.%06ld", |
| 8400 | wpa_s->p2p_auto_started.sec, |
| 8401 | wpa_s->p2p_auto_started.usec); |
| 8402 | wpas_p2p_join_scan(wpa_s, NULL); |
| 8403 | return 0; |
| 8404 | } |
| 8405 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 8406 | if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) { |
| 8407 | os_free(p2ps_prov); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8408 | return -1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 8409 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8410 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 8411 | 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] | 8412 | config_methods, use == WPAS_P2P_PD_FOR_JOIN, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 8413 | 0, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8414 | } |
| 8415 | |
| 8416 | |
| 8417 | int wpas_p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf, |
| 8418 | char *end) |
| 8419 | { |
| 8420 | return p2p_scan_result_text(ies, ies_len, buf, end); |
| 8421 | } |
| 8422 | |
| 8423 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 8424 | static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant *wpa_s, |
| 8425 | bool force) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8426 | { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 8427 | if (!offchannel_pending_action_tx(wpa_s) && !force) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8428 | return; |
| 8429 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 8430 | if (wpa_s->p2p_send_action_work) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8431 | wpas_p2p_free_send_action_work(wpa_s); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 8432 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 8433 | wpa_s, NULL); |
| 8434 | offchannel_send_action_done(wpa_s); |
| 8435 | } |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 8436 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 8437 | if (!offchannel_pending_action_tx(wpa_s)) |
| 8438 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8439 | wpa_printf(MSG_DEBUG, "P2P: Drop pending Action TX due to new " |
| 8440 | "operation request"); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8441 | offchannel_clear_pending_action_tx(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8442 | } |
| 8443 | |
| 8444 | |
| 8445 | int wpas_p2p_find(struct wpa_supplicant *wpa_s, unsigned int timeout, |
| 8446 | enum p2p_discovery_type type, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8447 | unsigned int num_req_dev_types, const u8 *req_dev_types, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 8448 | const u8 *dev_id, unsigned int search_delay, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 8449 | u8 seek_cnt, const char **seek_string, int freq, |
| 8450 | bool include_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8451 | { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 8452 | wpas_p2p_clear_pending_action_tx(wpa_s, false); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8453 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8454 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8455 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8456 | wpa_s->p2p_in_provisioning) { |
| 8457 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Reject p2p_find operation%s%s", |
| 8458 | (wpa_s->global->p2p_disabled || !wpa_s->global->p2p) ? |
| 8459 | " (P2P disabled)" : "", |
| 8460 | wpa_s->p2p_in_provisioning ? |
| 8461 | " (p2p_in_provisioning)" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8462 | return -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8463 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8464 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8465 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 8466 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8467 | return p2p_find(wpa_s->global->p2p, timeout, type, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8468 | num_req_dev_types, req_dev_types, dev_id, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 8469 | search_delay, seek_cnt, seek_string, freq, |
| 8470 | include_6ghz); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8471 | } |
| 8472 | |
| 8473 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8474 | static void wpas_p2p_scan_res_ignore_search(struct wpa_supplicant *wpa_s, |
| 8475 | struct wpa_scan_results *scan_res) |
| 8476 | { |
| 8477 | wpa_printf(MSG_DEBUG, "P2P: Ignore scan results"); |
| 8478 | |
| 8479 | if (wpa_s->p2p_scan_work) { |
| 8480 | struct wpa_radio_work *work = wpa_s->p2p_scan_work; |
| 8481 | wpa_s->p2p_scan_work = NULL; |
| 8482 | radio_work_done(work); |
| 8483 | } |
| 8484 | |
| 8485 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8486 | return; |
| 8487 | |
| 8488 | /* |
| 8489 | * Indicate that results have been processed so that the P2P module can |
| 8490 | * continue pending tasks. |
| 8491 | */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8492 | wpas_p2p_scan_res_handled(wpa_s); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8493 | } |
| 8494 | |
| 8495 | |
| 8496 | static void wpas_p2p_stop_find_oper(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8497 | { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 8498 | wpas_p2p_clear_pending_action_tx(wpa_s, true); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8499 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8500 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
| 8501 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8502 | |
| 8503 | if (wpa_s->global->p2p) |
| 8504 | p2p_stop_find(wpa_s->global->p2p); |
| 8505 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8506 | if (wpa_s->scan_res_handler == wpas_p2p_scan_res_handler) { |
| 8507 | wpa_printf(MSG_DEBUG, |
| 8508 | "P2P: Do not consider the scan results after stop_find"); |
| 8509 | wpa_s->scan_res_handler = wpas_p2p_scan_res_ignore_search; |
| 8510 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 8511 | } |
| 8512 | |
| 8513 | |
| 8514 | void wpas_p2p_stop_find(struct wpa_supplicant *wpa_s) |
| 8515 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8516 | wpas_p2p_stop_find_oper(wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 8517 | if (!wpa_s->global->pending_group_iface_for_p2ps) |
| 8518 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8519 | } |
| 8520 | |
| 8521 | |
| 8522 | static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx) |
| 8523 | { |
| 8524 | struct wpa_supplicant *wpa_s = eloop_ctx; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8525 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8526 | } |
| 8527 | |
| 8528 | |
| 8529 | int wpas_p2p_listen(struct wpa_supplicant *wpa_s, unsigned int timeout) |
| 8530 | { |
| 8531 | int res; |
| 8532 | |
| 8533 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8534 | return -1; |
| 8535 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 8536 | if (wpa_s->p2p_lo_started) { |
| 8537 | wpa_printf(MSG_DEBUG, |
| 8538 | "P2P: Cannot start P2P listen, it is offloaded"); |
| 8539 | return -1; |
| 8540 | } |
| 8541 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8542 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 8543 | wpas_p2p_clear_pending_action_tx(wpa_s, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8544 | |
| 8545 | if (timeout == 0) { |
| 8546 | /* |
| 8547 | * This is a request for unlimited Listen state. However, at |
| 8548 | * least for now, this is mapped to a Listen state for one |
| 8549 | * hour. |
| 8550 | */ |
| 8551 | timeout = 3600; |
| 8552 | } |
| 8553 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8554 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8555 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8556 | /* |
| 8557 | * Stop previous find/listen operation to avoid trying to request a new |
| 8558 | * remain-on-channel operation while the driver is still running the |
| 8559 | * previous one. |
| 8560 | */ |
| 8561 | if (wpa_s->global->p2p) |
| 8562 | p2p_stop_find(wpa_s->global->p2p); |
| 8563 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8564 | res = wpas_p2p_listen_start(wpa_s, timeout * 1000); |
| 8565 | if (res == 0 && timeout * 1000 > wpa_s->max_remain_on_chan) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8566 | wpa_s->global->p2p_long_listen = timeout * 1000; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8567 | eloop_register_timeout(timeout, 0, |
| 8568 | wpas_p2p_long_listen_timeout, |
| 8569 | wpa_s, NULL); |
| 8570 | } |
| 8571 | |
| 8572 | return res; |
| 8573 | } |
| 8574 | |
| 8575 | |
| 8576 | int wpas_p2p_assoc_req_ie(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
| 8577 | u8 *buf, size_t len, int p2p_group) |
| 8578 | { |
| 8579 | struct wpabuf *p2p_ie; |
| 8580 | int ret; |
| 8581 | |
| 8582 | if (wpa_s->global->p2p_disabled) |
| 8583 | return -1; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 8584 | /* |
| 8585 | * Advertize mandatory cross connection capability even on |
| 8586 | * p2p_disabled=1 interface when associating with a P2P Manager WLAN AP. |
| 8587 | */ |
| 8588 | if (wpa_s->conf->p2p_disabled && p2p_group) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8589 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8590 | if (wpa_s->global->p2p == NULL) |
| 8591 | return -1; |
| 8592 | if (bss == NULL) |
| 8593 | return -1; |
| 8594 | |
| 8595 | p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE); |
| 8596 | ret = p2p_assoc_req_ie(wpa_s->global->p2p, bss->bssid, buf, len, |
| 8597 | p2p_group, p2p_ie); |
| 8598 | wpabuf_free(p2p_ie); |
| 8599 | |
| 8600 | return ret; |
| 8601 | } |
| 8602 | |
| 8603 | |
| 8604 | 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] | 8605 | const u8 *dst, const u8 *bssid, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8606 | const u8 *ie, size_t ie_len, |
| 8607 | unsigned int rx_freq, int ssi_signal) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8608 | { |
| 8609 | if (wpa_s->global->p2p_disabled) |
| 8610 | return 0; |
| 8611 | if (wpa_s->global->p2p == NULL) |
| 8612 | return 0; |
| 8613 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8614 | switch (p2p_probe_req_rx(wpa_s->global->p2p, addr, dst, bssid, |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 8615 | ie, ie_len, rx_freq, wpa_s->p2p_lo_started)) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8616 | case P2P_PREQ_NOT_P2P: |
| 8617 | wpas_notify_preq(wpa_s, addr, dst, bssid, ie, ie_len, |
| 8618 | ssi_signal); |
| 8619 | /* fall through */ |
| 8620 | case P2P_PREQ_MALFORMED: |
| 8621 | case P2P_PREQ_NOT_LISTEN: |
| 8622 | case P2P_PREQ_NOT_PROCESSED: |
| 8623 | default: /* make gcc happy */ |
| 8624 | return 0; |
| 8625 | case P2P_PREQ_PROCESSED: |
| 8626 | return 1; |
| 8627 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8628 | } |
| 8629 | |
| 8630 | |
| 8631 | void wpas_p2p_rx_action(struct wpa_supplicant *wpa_s, const u8 *da, |
| 8632 | const u8 *sa, const u8 *bssid, |
| 8633 | u8 category, const u8 *data, size_t len, int freq) |
| 8634 | { |
| 8635 | if (wpa_s->global->p2p_disabled) |
| 8636 | return; |
| 8637 | if (wpa_s->global->p2p == NULL) |
| 8638 | return; |
| 8639 | |
| 8640 | p2p_rx_action(wpa_s->global->p2p, da, sa, bssid, category, data, len, |
| 8641 | freq); |
| 8642 | } |
| 8643 | |
| 8644 | |
| 8645 | void wpas_p2p_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ies) |
| 8646 | { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8647 | unsigned int bands; |
| 8648 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8649 | if (wpa_s->global->p2p_disabled) |
| 8650 | return; |
| 8651 | if (wpa_s->global->p2p == NULL) |
| 8652 | return; |
| 8653 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8654 | bands = wpas_get_bands(wpa_s, NULL); |
| 8655 | p2p_scan_ie(wpa_s->global->p2p, ies, NULL, bands); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8656 | } |
| 8657 | |
| 8658 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8659 | static void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8660 | { |
| 8661 | p2p_group_deinit(wpa_s->p2p_group); |
| 8662 | wpa_s->p2p_group = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8663 | |
| 8664 | wpa_s->ap_configured_cb = NULL; |
| 8665 | wpa_s->ap_configured_cb_ctx = NULL; |
| 8666 | wpa_s->ap_configured_cb_data = NULL; |
| 8667 | wpa_s->connect_without_scan = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8668 | } |
| 8669 | |
| 8670 | |
| 8671 | int wpas_p2p_reject(struct wpa_supplicant *wpa_s, const u8 *addr) |
| 8672 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8673 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8674 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8675 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8676 | return -1; |
| 8677 | |
| 8678 | return p2p_reject(wpa_s->global->p2p, addr); |
| 8679 | } |
| 8680 | |
| 8681 | |
| 8682 | /* Invite to reinvoke a persistent group */ |
| 8683 | 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] | 8684 | struct wpa_ssid *ssid, const u8 *go_dev_addr, int freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8685 | int vht_center_freq2, int ht40, int vht, int max_chwidth, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 8686 | int pref_freq, int he, int edmg, bool allow_6ghz, bool p2p2) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8687 | { |
| 8688 | enum p2p_invite_role role; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 8689 | u8 *bssid = NULL; |
| 8690 | int force_freq = 0; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 8691 | int res; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 8692 | int no_pref_freq_given = pref_freq == 0; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 8693 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 8694 | unsigned int size; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 8695 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 8696 | if (wpas_p2p_check_6ghz(wpa_s, NULL, allow_6ghz, freq)) |
| 8697 | return -1; |
| 8698 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8699 | wpa_s->global->p2p_invite_group = NULL; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 8700 | if (peer_addr) |
| 8701 | os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN); |
| 8702 | else |
| 8703 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8704 | |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 8705 | wpa_s->p2p_persistent_go_freq = freq; |
| 8706 | wpa_s->p2p_go_ht40 = !!ht40; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8707 | wpa_s->p2p_go_vht = !!vht; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8708 | wpa_s->p2p_go_he = !!he; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8709 | wpa_s->p2p_go_max_oper_chwidth = max_chwidth; |
| 8710 | wpa_s->p2p_go_vht_center_freq2 = vht_center_freq2; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8711 | wpa_s->p2p_go_edmg = !!edmg; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 8712 | wpa_s->p2p2 = p2p2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8713 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 8714 | role = P2P_INVITE_ROLE_GO; |
| 8715 | if (peer_addr == NULL) { |
| 8716 | wpa_printf(MSG_DEBUG, "P2P: Missing peer " |
| 8717 | "address in invitation command"); |
| 8718 | return -1; |
| 8719 | } |
| 8720 | if (wpas_p2p_create_iface(wpa_s)) { |
| 8721 | if (wpas_p2p_add_group_interface(wpa_s, |
| 8722 | WPA_IF_P2P_GO) < 0) { |
| 8723 | wpa_printf(MSG_ERROR, "P2P: Failed to " |
| 8724 | "allocate a new interface for the " |
| 8725 | "group"); |
| 8726 | return -1; |
| 8727 | } |
| 8728 | bssid = wpa_s->pending_interface_addr; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8729 | } else if (wpa_s->p2p_mgmt) |
| 8730 | bssid = wpa_s->parent->own_addr; |
| 8731 | else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8732 | bssid = wpa_s->own_addr; |
| 8733 | } else { |
| 8734 | role = P2P_INVITE_ROLE_CLIENT; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 8735 | if (!wpa_s->p2p2) |
| 8736 | peer_addr = ssid->bssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8737 | } |
| 8738 | wpa_s->pending_invite_ssid_id = ssid->id; |
| 8739 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8740 | size = P2P_MAX_PREF_CHANNELS; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8741 | res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8742 | role == P2P_INVITE_ROLE_GO, |
| 8743 | pref_freq_list, &size); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 8744 | if (res) |
| 8745 | return res; |
Irfan Sheriff | af84a57 | 2012-09-22 16:59:30 -0700 | [diff] [blame] | 8746 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8747 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8748 | return -1; |
| 8749 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 8750 | p2p_set_own_pref_freq_list(wpa_s->global->p2p, pref_freq_list, size); |
| 8751 | |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 8752 | if (wpa_s->parent->conf->p2p_ignore_shared_freq && |
| 8753 | no_pref_freq_given && pref_freq > 0 && |
| 8754 | wpa_s->num_multichan_concurrent > 1 && |
| 8755 | wpas_p2p_num_unused_channels(wpa_s) > 0) { |
| 8756 | wpa_printf(MSG_DEBUG, "P2P: Ignore own channel preference %d MHz for invitation due to p2p_ignore_shared_freq=1 configuration", |
| 8757 | pref_freq); |
| 8758 | pref_freq = 0; |
| 8759 | } |
| 8760 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8761 | /* |
| 8762 | * Stop any find/listen operations before invitation and possibly |
| 8763 | * connection establishment. |
| 8764 | */ |
| 8765 | wpas_p2p_stop_find_oper(wpa_s); |
| 8766 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 8767 | #ifdef CONFIG_PASN |
| 8768 | if (p2p2) { |
| 8769 | if (wpas_p2p_initiate_pasn_verify(wpa_s, peer_addr, role, bssid, |
| 8770 | ssid->ssid, ssid->ssid_len, |
| 8771 | force_freq, go_dev_addr, |
| 8772 | pref_freq) < 0) { |
| 8773 | if (wpa_s->create_p2p_iface) |
| 8774 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 8775 | return -1; |
| 8776 | } |
| 8777 | return 0; |
| 8778 | } |
| 8779 | #endif /* CONFIG_PASN */ |
| 8780 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8781 | return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid, |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 8782 | ssid->ssid, ssid->ssid_len, force_freq, go_dev_addr, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 8783 | 1, pref_freq, -1, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8784 | } |
| 8785 | |
| 8786 | |
| 8787 | /* Invite to join an active group */ |
| 8788 | 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] | 8789 | const u8 *peer_addr, const u8 *go_dev_addr, |
| 8790 | bool allow_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8791 | { |
| 8792 | struct wpa_global *global = wpa_s->global; |
| 8793 | enum p2p_invite_role role; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 8794 | u8 *bssid = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8795 | struct wpa_ssid *ssid; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8796 | int persistent; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8797 | int freq = 0, force_freq = 0, pref_freq = 0; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 8798 | int res; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 8799 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 8800 | unsigned int size; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8801 | |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 8802 | wpa_s->p2p_persistent_go_freq = 0; |
| 8803 | wpa_s->p2p_go_ht40 = 0; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8804 | wpa_s->p2p_go_vht = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8805 | wpa_s->p2p_go_vht_center_freq2 = 0; |
| 8806 | wpa_s->p2p_go_max_oper_chwidth = 0; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8807 | wpa_s->p2p_go_edmg = 0; |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 8808 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8809 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 8810 | if (os_strcmp(wpa_s->ifname, ifname) == 0) |
| 8811 | break; |
| 8812 | } |
| 8813 | if (wpa_s == NULL) { |
| 8814 | wpa_printf(MSG_DEBUG, "P2P: Interface '%s' not found", ifname); |
| 8815 | return -1; |
| 8816 | } |
| 8817 | |
| 8818 | ssid = wpa_s->current_ssid; |
| 8819 | if (ssid == NULL) { |
| 8820 | wpa_printf(MSG_DEBUG, "P2P: No current SSID to use for " |
| 8821 | "invitation"); |
| 8822 | return -1; |
| 8823 | } |
| 8824 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8825 | wpa_s->global->p2p_invite_group = wpa_s; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8826 | persistent = ssid->p2p_persistent_group && |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8827 | wpas_p2p_get_persistent(wpa_s->p2pdev, peer_addr, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8828 | ssid->ssid, ssid->ssid_len); |
| 8829 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8830 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 8831 | role = P2P_INVITE_ROLE_ACTIVE_GO; |
| 8832 | bssid = wpa_s->own_addr; |
| 8833 | if (go_dev_addr == NULL) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8834 | go_dev_addr = wpa_s->global->p2p_dev_addr; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8835 | freq = ssid->frequency; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8836 | } else { |
| 8837 | role = P2P_INVITE_ROLE_CLIENT; |
| 8838 | if (wpa_s->wpa_state < WPA_ASSOCIATED) { |
| 8839 | wpa_printf(MSG_DEBUG, "P2P: Not associated - cannot " |
| 8840 | "invite to current group"); |
| 8841 | return -1; |
| 8842 | } |
| 8843 | bssid = wpa_s->bssid; |
| 8844 | if (go_dev_addr == NULL && |
| 8845 | !is_zero_ether_addr(wpa_s->go_dev_addr)) |
| 8846 | go_dev_addr = wpa_s->go_dev_addr; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8847 | freq = wpa_s->current_bss ? wpa_s->current_bss->freq : |
| 8848 | (int) wpa_s->assoc_freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8849 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8850 | wpa_s->p2pdev->pending_invite_ssid_id = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8851 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8852 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8853 | return -1; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 8854 | if (wpas_p2p_check_6ghz(wpa_s, peer_addr, allow_6ghz, freq)) |
| 8855 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8856 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8857 | size = P2P_MAX_PREF_CHANNELS; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8858 | res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8859 | role == P2P_INVITE_ROLE_ACTIVE_GO, |
| 8860 | pref_freq_list, &size); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 8861 | if (res) |
| 8862 | return res; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 8863 | wpas_p2p_set_own_freq_preference(wpa_s, force_freq); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 8864 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8865 | return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid, |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 8866 | ssid->ssid, ssid->ssid_len, force_freq, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 8867 | go_dev_addr, persistent, pref_freq, -1, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8868 | } |
| 8869 | |
| 8870 | |
| 8871 | void wpas_p2p_completed(struct wpa_supplicant *wpa_s) |
| 8872 | { |
| 8873 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 8874 | const u8 *bssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8875 | u8 go_dev_addr[ETH_ALEN]; |
| 8876 | int persistent; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8877 | int freq; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 8878 | u8 ip[3 * 4], *ip_ptr = NULL; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 8879 | char ip_addr[100]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8880 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8881 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION) { |
| 8882 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8883 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8884 | } |
| 8885 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8886 | if (!wpa_s->show_group_started || !ssid) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8887 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8888 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 8889 | if (wpa_s->go_params) |
| 8890 | bssid = wpa_s->go_params->peer_interface_addr; |
| 8891 | else |
| 8892 | bssid = wpa_s->bssid; |
| 8893 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8894 | wpa_s->show_group_started = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8895 | if (!wpa_s->p2p_go_group_formation_completed && |
| 8896 | wpa_s->global->p2p_group_formation == wpa_s) { |
| 8897 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 8898 | "P2P: Marking group formation completed on client on data connection"); |
| 8899 | wpa_s->p2p_go_group_formation_completed = 1; |
| 8900 | wpa_s->global->p2p_group_formation = NULL; |
| 8901 | wpa_s->p2p_in_provisioning = 0; |
| 8902 | wpa_s->p2p_in_invitation = 0; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 8903 | wpa_s->p2p_retry_limit = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8904 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8905 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8906 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 8907 | if (ssid->bssid_set) |
| 8908 | os_memcpy(go_dev_addr, ssid->bssid, ETH_ALEN); |
| 8909 | persistent = wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid, |
| 8910 | ssid->ssid_len); |
| 8911 | os_memcpy(wpa_s->go_dev_addr, go_dev_addr, ETH_ALEN); |
| 8912 | |
| 8913 | if (wpa_s->global->p2p_group_formation == wpa_s) |
| 8914 | wpa_s->global->p2p_group_formation = NULL; |
| 8915 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8916 | freq = wpa_s->current_bss ? wpa_s->current_bss->freq : |
| 8917 | (int) wpa_s->assoc_freq; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 8918 | |
| 8919 | ip_addr[0] = '\0'; |
| 8920 | if (wpa_sm_get_p2p_ip_addr(wpa_s->wpa, ip) == 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8921 | int res; |
| 8922 | |
| 8923 | res = os_snprintf(ip_addr, sizeof(ip_addr), |
| 8924 | " ip_addr=%u.%u.%u.%u " |
| 8925 | "ip_mask=%u.%u.%u.%u go_ip_addr=%u.%u.%u.%u", |
| 8926 | ip[0], ip[1], ip[2], ip[3], |
| 8927 | ip[4], ip[5], ip[6], ip[7], |
| 8928 | ip[8], ip[9], ip[10], ip[11]); |
| 8929 | if (os_snprintf_error(sizeof(ip_addr), res)) |
| 8930 | ip_addr[0] = '\0'; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 8931 | ip_ptr = ip; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 8932 | } |
| 8933 | |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 8934 | wpas_p2p_group_started(wpa_s, 0, ssid, freq, |
| 8935 | ssid->passphrase == NULL && ssid->psk_set ? |
| 8936 | ssid->psk : NULL, |
| 8937 | ssid->passphrase, go_dev_addr, persistent, |
| 8938 | ip_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8939 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 8940 | if (persistent) { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 8941 | wpas_p2p_store_persistent_group(wpa_s->p2pdev, |
| 8942 | ssid, go_dev_addr); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 8943 | wpas_p2p_store_go_identity(wpa_s, go_dev_addr, bssid); |
| 8944 | } |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 8945 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 8946 | wpas_notify_p2p_group_started(wpa_s, ssid, persistent, 1, ip_ptr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8947 | } |
| 8948 | |
| 8949 | |
| 8950 | int wpas_p2p_presence_req(struct wpa_supplicant *wpa_s, u32 duration1, |
| 8951 | u32 interval1, u32 duration2, u32 interval2) |
| 8952 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8953 | int ret; |
| 8954 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8955 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8956 | return -1; |
| 8957 | |
| 8958 | if (wpa_s->wpa_state < WPA_ASSOCIATED || |
| 8959 | wpa_s->current_ssid == NULL || |
| 8960 | wpa_s->current_ssid->mode != WPAS_MODE_INFRA) |
| 8961 | return -1; |
| 8962 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8963 | ret = p2p_presence_req(wpa_s->global->p2p, wpa_s->bssid, |
| 8964 | wpa_s->own_addr, wpa_s->assoc_freq, |
| 8965 | duration1, interval1, duration2, interval2); |
| 8966 | if (ret == 0) |
| 8967 | wpa_s->waiting_presence_resp = 1; |
| 8968 | |
| 8969 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8970 | } |
| 8971 | |
| 8972 | |
| 8973 | int wpas_p2p_ext_listen(struct wpa_supplicant *wpa_s, unsigned int period, |
| 8974 | unsigned int interval) |
| 8975 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8976 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8977 | return -1; |
| 8978 | |
| 8979 | return p2p_ext_listen(wpa_s->global->p2p, period, interval); |
| 8980 | } |
| 8981 | |
| 8982 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8983 | static int wpas_p2p_is_client(struct wpa_supplicant *wpa_s) |
| 8984 | { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 8985 | if (wpa_s->current_ssid == NULL) { |
| 8986 | /* |
| 8987 | * current_ssid can be cleared when P2P client interface gets |
| 8988 | * disconnected, so assume this interface was used as P2P |
| 8989 | * client. |
| 8990 | */ |
| 8991 | return 1; |
| 8992 | } |
| 8993 | return wpa_s->current_ssid->p2p_group && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8994 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA; |
| 8995 | } |
| 8996 | |
| 8997 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8998 | static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx) |
| 8999 | { |
| 9000 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 9001 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9002 | 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] | 9003 | wpa_printf(MSG_DEBUG, "P2P: Ignore group idle timeout - " |
| 9004 | "disabled"); |
| 9005 | return; |
| 9006 | } |
| 9007 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9008 | wpa_printf(MSG_DEBUG, "P2P: Group idle timeout reached - terminate " |
| 9009 | "group"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9010 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_IDLE_TIMEOUT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9011 | } |
| 9012 | |
| 9013 | |
| 9014 | static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s) |
| 9015 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9016 | int timeout; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9017 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9018 | if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0) |
| 9019 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout"); |
| 9020 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9021 | if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group) |
| 9022 | return; |
| 9023 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9024 | timeout = wpa_s->conf->p2p_group_idle; |
| 9025 | if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA && |
| 9026 | (timeout == 0 || timeout > P2P_MAX_CLIENT_IDLE)) |
| 9027 | timeout = P2P_MAX_CLIENT_IDLE; |
| 9028 | |
| 9029 | if (timeout == 0) |
| 9030 | return; |
| 9031 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9032 | if (timeout < 0) { |
| 9033 | if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA) |
| 9034 | timeout = 0; /* special client mode no-timeout */ |
| 9035 | else |
| 9036 | return; |
| 9037 | } |
| 9038 | |
| 9039 | if (wpa_s->p2p_in_provisioning) { |
| 9040 | /* |
| 9041 | * Use the normal group formation timeout during the |
| 9042 | * provisioning phase to avoid terminating this process too |
| 9043 | * early due to group idle timeout. |
| 9044 | */ |
| 9045 | wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout " |
| 9046 | "during provisioning"); |
| 9047 | return; |
| 9048 | } |
Deepthi Gowri | 9e4e8ac | 2013-04-16 11:57:05 +0530 | [diff] [blame] | 9049 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9050 | if (wpa_s->show_group_started) { |
| 9051 | /* |
| 9052 | * Use the normal group formation timeout between the end of |
| 9053 | * the provisioning phase and completion of 4-way handshake to |
| 9054 | * avoid terminating this process too early due to group idle |
| 9055 | * timeout. |
| 9056 | */ |
| 9057 | wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout " |
| 9058 | "while waiting for initial 4-way handshake to " |
| 9059 | "complete"); |
| 9060 | return; |
| 9061 | } |
| 9062 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9063 | 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] | 9064 | timeout); |
| 9065 | eloop_register_timeout(timeout, 0, wpas_p2p_group_idle_timeout, |
| 9066 | wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9067 | } |
| 9068 | |
| 9069 | |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 9070 | /* Returns 1 if the interface was removed */ |
| 9071 | int wpas_p2p_deauth_notif(struct wpa_supplicant *wpa_s, const u8 *bssid, |
| 9072 | u16 reason_code, const u8 *ie, size_t ie_len, |
| 9073 | int locally_generated) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9074 | { |
| 9075 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 9076 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9077 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9078 | if (!locally_generated) |
| 9079 | p2p_deauth_notif(wpa_s->global->p2p, bssid, reason_code, ie, |
| 9080 | ie_len); |
| 9081 | |
| 9082 | if (reason_code == WLAN_REASON_DEAUTH_LEAVING && !locally_generated && |
| 9083 | wpa_s->current_ssid && |
| 9084 | wpa_s->current_ssid->p2p_group && |
| 9085 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA) { |
| 9086 | wpa_printf(MSG_DEBUG, "P2P: GO indicated that the P2P Group " |
| 9087 | "session is ending"); |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 9088 | if (wpas_p2p_group_delete(wpa_s, |
| 9089 | P2P_GROUP_REMOVAL_GO_ENDING_SESSION) |
| 9090 | > 0) |
| 9091 | return 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9092 | } |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 9093 | |
| 9094 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9095 | } |
| 9096 | |
| 9097 | |
| 9098 | 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] | 9099 | u16 reason_code, const u8 *ie, size_t ie_len, |
| 9100 | int locally_generated) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9101 | { |
| 9102 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 9103 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9104 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9105 | if (!locally_generated) |
| 9106 | p2p_disassoc_notif(wpa_s->global->p2p, bssid, reason_code, ie, |
| 9107 | ie_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9108 | } |
| 9109 | |
| 9110 | |
| 9111 | void wpas_p2p_update_config(struct wpa_supplicant *wpa_s) |
| 9112 | { |
| 9113 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 9114 | |
| 9115 | if (p2p == NULL) |
| 9116 | return; |
| 9117 | |
| 9118 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE)) |
| 9119 | return; |
| 9120 | |
| 9121 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_NAME) |
| 9122 | p2p_set_dev_name(p2p, wpa_s->conf->device_name); |
| 9123 | |
| 9124 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_TYPE) |
| 9125 | p2p_set_pri_dev_type(p2p, wpa_s->conf->device_type); |
| 9126 | |
| 9127 | if (wpa_s->wps && |
| 9128 | (wpa_s->conf->changed_parameters & CFG_CHANGED_CONFIG_METHODS)) |
| 9129 | p2p_set_config_methods(p2p, wpa_s->wps->config_methods); |
| 9130 | |
| 9131 | if (wpa_s->wps && (wpa_s->conf->changed_parameters & CFG_CHANGED_UUID)) |
| 9132 | p2p_set_uuid(p2p, wpa_s->wps->uuid); |
| 9133 | |
| 9134 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_WPS_STRING) { |
| 9135 | p2p_set_manufacturer(p2p, wpa_s->conf->manufacturer); |
| 9136 | p2p_set_model_name(p2p, wpa_s->conf->model_name); |
| 9137 | p2p_set_model_number(p2p, wpa_s->conf->model_number); |
| 9138 | p2p_set_serial_number(p2p, wpa_s->conf->serial_number); |
| 9139 | } |
| 9140 | |
| 9141 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_SEC_DEVICE_TYPE) |
| 9142 | p2p_set_sec_dev_types(p2p, |
| 9143 | (void *) wpa_s->conf->sec_device_type, |
| 9144 | wpa_s->conf->num_sec_device_types); |
| 9145 | |
| 9146 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_VENDOR_EXTENSION) { |
| 9147 | int i; |
| 9148 | p2p_remove_wps_vendor_extensions(p2p); |
| 9149 | for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) { |
| 9150 | if (wpa_s->conf->wps_vendor_ext[i] == NULL) |
| 9151 | continue; |
| 9152 | p2p_add_wps_vendor_extension( |
| 9153 | p2p, wpa_s->conf->wps_vendor_ext[i]); |
| 9154 | } |
| 9155 | } |
| 9156 | |
| 9157 | if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) && |
| 9158 | wpa_s->conf->country[0] && wpa_s->conf->country[1]) { |
| 9159 | char country[3]; |
| 9160 | country[0] = wpa_s->conf->country[0]; |
| 9161 | country[1] = wpa_s->conf->country[1]; |
| 9162 | country[2] = 0x04; |
| 9163 | p2p_set_country(p2p, country); |
| 9164 | } |
| 9165 | |
| 9166 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_SSID_POSTFIX) { |
| 9167 | p2p_set_ssid_postfix(p2p, (u8 *) wpa_s->conf->p2p_ssid_postfix, |
| 9168 | wpa_s->conf->p2p_ssid_postfix ? |
| 9169 | os_strlen(wpa_s->conf->p2p_ssid_postfix) : |
| 9170 | 0); |
| 9171 | } |
| 9172 | |
| 9173 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_INTRA_BSS) |
| 9174 | p2p_set_intra_bss_dist(p2p, wpa_s->conf->p2p_intra_bss); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9175 | |
| 9176 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_LISTEN_CHANNEL) { |
| 9177 | u8 reg_class, channel; |
| 9178 | int ret; |
| 9179 | unsigned int r; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9180 | u8 channel_forced; |
| 9181 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9182 | if (wpa_s->conf->p2p_listen_reg_class && |
| 9183 | wpa_s->conf->p2p_listen_channel) { |
| 9184 | reg_class = wpa_s->conf->p2p_listen_reg_class; |
| 9185 | channel = wpa_s->conf->p2p_listen_channel; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9186 | channel_forced = 1; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9187 | } else { |
| 9188 | reg_class = 81; |
| 9189 | /* |
| 9190 | * Pick one of the social channels randomly as the |
| 9191 | * listen channel. |
| 9192 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9193 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 9194 | channel = 1; |
| 9195 | else |
| 9196 | channel = 1 + (r % 3) * 5; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9197 | channel_forced = 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9198 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9199 | ret = p2p_set_listen_channel(p2p, reg_class, channel, |
| 9200 | channel_forced); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9201 | if (ret) |
| 9202 | wpa_printf(MSG_ERROR, "P2P: Own listen channel update " |
| 9203 | "failed: %d", ret); |
| 9204 | } |
| 9205 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_OPER_CHANNEL) { |
| 9206 | u8 op_reg_class, op_channel, cfg_op_channel; |
| 9207 | int ret = 0; |
| 9208 | unsigned int r; |
| 9209 | if (wpa_s->conf->p2p_oper_reg_class && |
| 9210 | wpa_s->conf->p2p_oper_channel) { |
| 9211 | op_reg_class = wpa_s->conf->p2p_oper_reg_class; |
| 9212 | op_channel = wpa_s->conf->p2p_oper_channel; |
| 9213 | cfg_op_channel = 1; |
| 9214 | } else { |
| 9215 | op_reg_class = 81; |
| 9216 | /* |
| 9217 | * Use random operation channel from (1, 6, 11) |
| 9218 | *if no other preference is indicated. |
| 9219 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9220 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 9221 | op_channel = 1; |
| 9222 | else |
| 9223 | op_channel = 1 + (r % 3) * 5; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9224 | cfg_op_channel = 0; |
| 9225 | } |
| 9226 | ret = p2p_set_oper_channel(p2p, op_reg_class, op_channel, |
| 9227 | cfg_op_channel); |
| 9228 | if (ret) |
| 9229 | wpa_printf(MSG_ERROR, "P2P: Own oper channel update " |
| 9230 | "failed: %d", ret); |
| 9231 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9232 | |
| 9233 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PREF_CHAN) { |
| 9234 | if (p2p_set_pref_chan(p2p, wpa_s->conf->num_p2p_pref_chan, |
| 9235 | wpa_s->conf->p2p_pref_chan) < 0) { |
| 9236 | wpa_printf(MSG_ERROR, "P2P: Preferred channel list " |
| 9237 | "update failed"); |
| 9238 | } |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9239 | |
| 9240 | if (p2p_set_no_go_freq(p2p, &wpa_s->conf->p2p_no_go_freq) < 0) { |
| 9241 | wpa_printf(MSG_ERROR, "P2P: No GO channel list " |
| 9242 | "update failed"); |
| 9243 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9244 | } |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 9245 | |
| 9246 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PASSPHRASE_LEN) |
| 9247 | p2p_set_passphrase_len(p2p, wpa_s->conf->p2p_passphrase_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9248 | } |
| 9249 | |
| 9250 | |
| 9251 | int wpas_p2p_set_noa(struct wpa_supplicant *wpa_s, u8 count, int start, |
| 9252 | int duration) |
| 9253 | { |
| 9254 | if (!wpa_s->ap_iface) |
| 9255 | return -1; |
| 9256 | return hostapd_p2p_set_noa(wpa_s->ap_iface->bss[0], count, start, |
| 9257 | duration); |
| 9258 | } |
| 9259 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9260 | |
| 9261 | int wpas_p2p_set_cross_connect(struct wpa_supplicant *wpa_s, int enabled) |
| 9262 | { |
| 9263 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 9264 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9265 | |
| 9266 | wpa_s->global->cross_connection = enabled; |
| 9267 | p2p_set_cross_connect(wpa_s->global->p2p, enabled); |
| 9268 | |
| 9269 | if (!enabled) { |
| 9270 | struct wpa_supplicant *iface; |
| 9271 | |
| 9272 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) |
| 9273 | { |
| 9274 | if (iface->cross_connect_enabled == 0) |
| 9275 | continue; |
| 9276 | |
| 9277 | iface->cross_connect_enabled = 0; |
| 9278 | iface->cross_connect_in_use = 0; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9279 | wpa_msg_global(iface->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 9280 | P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s", |
| 9281 | iface->ifname, |
| 9282 | iface->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9283 | } |
| 9284 | } |
| 9285 | |
| 9286 | return 0; |
| 9287 | } |
| 9288 | |
| 9289 | |
| 9290 | static void wpas_p2p_enable_cross_connect(struct wpa_supplicant *uplink) |
| 9291 | { |
| 9292 | struct wpa_supplicant *iface; |
| 9293 | |
| 9294 | if (!uplink->global->cross_connection) |
| 9295 | return; |
| 9296 | |
| 9297 | for (iface = uplink->global->ifaces; iface; iface = iface->next) { |
| 9298 | if (!iface->cross_connect_enabled) |
| 9299 | continue; |
| 9300 | if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) != |
| 9301 | 0) |
| 9302 | continue; |
| 9303 | if (iface->ap_iface == NULL) |
| 9304 | continue; |
| 9305 | if (iface->cross_connect_in_use) |
| 9306 | continue; |
| 9307 | |
| 9308 | iface->cross_connect_in_use = 1; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9309 | wpa_msg_global(iface->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 9310 | P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s", |
| 9311 | iface->ifname, iface->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9312 | } |
| 9313 | } |
| 9314 | |
| 9315 | |
| 9316 | static void wpas_p2p_disable_cross_connect(struct wpa_supplicant *uplink) |
| 9317 | { |
| 9318 | struct wpa_supplicant *iface; |
| 9319 | |
| 9320 | for (iface = uplink->global->ifaces; iface; iface = iface->next) { |
| 9321 | if (!iface->cross_connect_enabled) |
| 9322 | continue; |
| 9323 | if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) != |
| 9324 | 0) |
| 9325 | continue; |
| 9326 | if (!iface->cross_connect_in_use) |
| 9327 | continue; |
| 9328 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9329 | wpa_msg_global(iface->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 9330 | P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s", |
| 9331 | iface->ifname, iface->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9332 | iface->cross_connect_in_use = 0; |
| 9333 | } |
| 9334 | } |
| 9335 | |
| 9336 | |
| 9337 | void wpas_p2p_notif_connected(struct wpa_supplicant *wpa_s) |
| 9338 | { |
| 9339 | if (wpa_s->ap_iface || wpa_s->current_ssid == NULL || |
| 9340 | wpa_s->current_ssid->mode != WPAS_MODE_INFRA || |
| 9341 | wpa_s->cross_connect_disallowed) |
| 9342 | wpas_p2p_disable_cross_connect(wpa_s); |
| 9343 | else |
| 9344 | wpas_p2p_enable_cross_connect(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9345 | if (!wpa_s->ap_iface && |
| 9346 | eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0) |
| 9347 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9348 | } |
| 9349 | |
| 9350 | |
| 9351 | void wpas_p2p_notif_disconnected(struct wpa_supplicant *wpa_s) |
| 9352 | { |
| 9353 | wpas_p2p_disable_cross_connect(wpa_s); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9354 | if (!wpa_s->ap_iface && |
| 9355 | !eloop_is_timeout_registered(wpas_p2p_group_idle_timeout, |
| 9356 | wpa_s, NULL)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9357 | wpas_p2p_set_group_idle_timeout(wpa_s); |
| 9358 | } |
| 9359 | |
| 9360 | |
| 9361 | static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s) |
| 9362 | { |
| 9363 | struct wpa_supplicant *iface; |
| 9364 | |
| 9365 | if (!wpa_s->global->cross_connection) |
| 9366 | return; |
| 9367 | |
| 9368 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 9369 | if (iface == wpa_s) |
| 9370 | continue; |
| 9371 | if (iface->drv_flags & |
| 9372 | WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE) |
| 9373 | continue; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9374 | if ((iface->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) && |
| 9375 | iface != wpa_s->parent) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9376 | continue; |
| 9377 | |
| 9378 | wpa_s->cross_connect_enabled = 1; |
| 9379 | os_strlcpy(wpa_s->cross_connect_uplink, iface->ifname, |
| 9380 | sizeof(wpa_s->cross_connect_uplink)); |
| 9381 | wpa_printf(MSG_DEBUG, "P2P: Enable cross connection from " |
| 9382 | "%s to %s whenever uplink is available", |
| 9383 | wpa_s->ifname, wpa_s->cross_connect_uplink); |
| 9384 | |
| 9385 | if (iface->ap_iface || iface->current_ssid == NULL || |
| 9386 | iface->current_ssid->mode != WPAS_MODE_INFRA || |
| 9387 | iface->cross_connect_disallowed || |
| 9388 | iface->wpa_state != WPA_COMPLETED) |
| 9389 | break; |
| 9390 | |
| 9391 | wpa_s->cross_connect_in_use = 1; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9392 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 9393 | P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s", |
| 9394 | wpa_s->ifname, wpa_s->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9395 | break; |
| 9396 | } |
| 9397 | } |
| 9398 | |
| 9399 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 9400 | static int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9401 | { |
| 9402 | if (wpa_s->p2p_group_interface != P2P_GROUP_INTERFACE_CLIENT && |
| 9403 | !wpa_s->p2p_in_provisioning) |
| 9404 | return 0; /* not P2P client operation */ |
| 9405 | |
| 9406 | wpa_printf(MSG_DEBUG, "P2P: Terminate connection due to WPS PBC " |
| 9407 | "session overlap"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9408 | if (wpa_s != wpa_s->p2pdev) |
| 9409 | wpa_msg_ctrl(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_OVERLAP); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 9410 | wpas_p2p_group_formation_failed(wpa_s, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9411 | return 1; |
| 9412 | } |
| 9413 | |
| 9414 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 9415 | void wpas_p2p_pbc_overlap_cb(void *eloop_ctx, void *timeout_ctx) |
| 9416 | { |
| 9417 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 9418 | wpas_p2p_notif_pbc_overlap(wpa_s); |
| 9419 | } |
| 9420 | |
| 9421 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9422 | void wpas_p2p_update_channel_list(struct wpa_supplicant *wpa_s, |
| 9423 | enum wpas_p2p_channel_update_trig trig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9424 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9425 | struct p2p_channels chan, cli_chan; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9426 | struct wpa_used_freq_data *freqs = NULL; |
| 9427 | unsigned int num = wpa_s->num_multichan_concurrent; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9428 | |
| 9429 | if (wpa_s->global == NULL || wpa_s->global->p2p == NULL) |
| 9430 | return; |
| 9431 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9432 | freqs = os_calloc(num, sizeof(struct wpa_used_freq_data)); |
| 9433 | if (!freqs) |
| 9434 | return; |
| 9435 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 9436 | num = get_shared_radio_freqs_data(wpa_s, freqs, num, false); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9437 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9438 | os_memset(&chan, 0, sizeof(chan)); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9439 | os_memset(&cli_chan, 0, sizeof(cli_chan)); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 9440 | if (wpas_p2p_setup_channels(wpa_s, &chan, &cli_chan, |
| 9441 | is_p2p_6ghz_disabled(wpa_s->global->p2p))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9442 | wpa_printf(MSG_ERROR, "P2P: Failed to update supported " |
| 9443 | "channel list"); |
| 9444 | return; |
| 9445 | } |
| 9446 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9447 | p2p_update_channel_list(wpa_s->global->p2p, &chan, &cli_chan); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 9448 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9449 | wpas_p2p_optimize_listen_channel(wpa_s, freqs, num); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 9450 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9451 | /* |
| 9452 | * The used frequencies map changed, so it is possible that a GO is |
| 9453 | * using a channel that is no longer valid for P2P use. It is also |
| 9454 | * possible that due to policy consideration, it would be preferable to |
| 9455 | * move it to a frequency already used by other station interfaces. |
| 9456 | */ |
| 9457 | wpas_p2p_consider_moving_gos(wpa_s, freqs, num, trig); |
| 9458 | |
| 9459 | os_free(freqs); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9460 | } |
| 9461 | |
| 9462 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 9463 | static void wpas_p2p_scan_res_ignore(struct wpa_supplicant *wpa_s, |
| 9464 | struct wpa_scan_results *scan_res) |
| 9465 | { |
| 9466 | wpa_printf(MSG_DEBUG, "P2P: Ignore scan results"); |
| 9467 | } |
| 9468 | |
| 9469 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9470 | int wpas_p2p_cancel(struct wpa_supplicant *wpa_s) |
| 9471 | { |
| 9472 | struct wpa_global *global = wpa_s->global; |
| 9473 | int found = 0; |
| 9474 | const u8 *peer; |
| 9475 | |
| 9476 | if (global->p2p == NULL) |
| 9477 | return -1; |
| 9478 | |
| 9479 | wpa_printf(MSG_DEBUG, "P2P: Request to cancel group formation"); |
| 9480 | |
| 9481 | if (wpa_s->pending_interface_name[0] && |
| 9482 | !is_zero_ether_addr(wpa_s->pending_interface_addr)) |
| 9483 | found = 1; |
| 9484 | |
| 9485 | peer = p2p_get_go_neg_peer(global->p2p); |
| 9486 | if (peer) { |
| 9487 | wpa_printf(MSG_DEBUG, "P2P: Unauthorize pending GO Neg peer " |
| 9488 | MACSTR, MAC2STR(peer)); |
| 9489 | p2p_unauthorize(global->p2p, peer); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9490 | found = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9491 | } |
| 9492 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 9493 | if (wpa_s->scan_res_handler == wpas_p2p_scan_res_join) { |
| 9494 | wpa_printf(MSG_DEBUG, "P2P: Stop pending scan for join"); |
| 9495 | wpa_s->scan_res_handler = wpas_p2p_scan_res_ignore; |
| 9496 | found = 1; |
| 9497 | } |
| 9498 | |
| 9499 | if (wpa_s->pending_pd_before_join) { |
| 9500 | wpa_printf(MSG_DEBUG, "P2P: Stop pending PD before join"); |
| 9501 | wpa_s->pending_pd_before_join = 0; |
| 9502 | found = 1; |
| 9503 | } |
| 9504 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9505 | wpas_p2p_stop_find(wpa_s); |
| 9506 | |
| 9507 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 9508 | if (wpa_s == global->p2p_group_formation && |
| 9509 | (wpa_s->p2p_in_provisioning || |
| 9510 | wpa_s->parent->pending_interface_type == |
| 9511 | WPA_IF_P2P_CLIENT)) { |
| 9512 | wpa_printf(MSG_DEBUG, "P2P: Interface %s in group " |
| 9513 | "formation found - cancelling", |
| 9514 | wpa_s->ifname); |
| 9515 | found = 1; |
| 9516 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9517 | wpa_s->p2pdev, NULL); |
Jouni Malinen | adddfc4 | 2012-10-03 14:31:41 -0700 | [diff] [blame] | 9518 | if (wpa_s->p2p_in_provisioning) { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 9519 | wpas_group_formation_completed(wpa_s, 0, 0); |
Jouni Malinen | adddfc4 | 2012-10-03 14:31:41 -0700 | [diff] [blame] | 9520 | break; |
| 9521 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9522 | wpas_p2p_group_delete(wpa_s, |
| 9523 | P2P_GROUP_REMOVAL_REQUESTED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9524 | break; |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 9525 | } else if (wpa_s->p2p_in_invitation) { |
| 9526 | wpa_printf(MSG_DEBUG, "P2P: Interface %s in invitation found - cancelling", |
| 9527 | wpa_s->ifname); |
| 9528 | found = 1; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 9529 | wpas_p2p_group_formation_failed(wpa_s, 0); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9530 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9531 | } |
| 9532 | } |
| 9533 | |
| 9534 | if (!found) { |
| 9535 | wpa_printf(MSG_DEBUG, "P2P: No ongoing group formation found"); |
| 9536 | return -1; |
| 9537 | } |
| 9538 | |
| 9539 | return 0; |
| 9540 | } |
| 9541 | |
| 9542 | |
| 9543 | void wpas_p2p_interface_unavailable(struct wpa_supplicant *wpa_s) |
| 9544 | { |
| 9545 | if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group) |
| 9546 | return; |
| 9547 | |
| 9548 | wpa_printf(MSG_DEBUG, "P2P: Remove group due to driver resource not " |
| 9549 | "being available anymore"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9550 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_UNAVAILABLE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9551 | } |
| 9552 | |
| 9553 | |
| 9554 | void wpas_p2p_update_best_channels(struct wpa_supplicant *wpa_s, |
| 9555 | int freq_24, int freq_5, int freq_overall) |
| 9556 | { |
| 9557 | struct p2p_data *p2p = wpa_s->global->p2p; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9558 | if (p2p == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9559 | return; |
| 9560 | p2p_set_best_channels(p2p, freq_24, freq_5, freq_overall); |
| 9561 | } |
| 9562 | |
| 9563 | |
| 9564 | int wpas_p2p_unauthorize(struct wpa_supplicant *wpa_s, const char *addr) |
| 9565 | { |
| 9566 | u8 peer[ETH_ALEN]; |
| 9567 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 9568 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9569 | if (p2p == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9570 | return -1; |
| 9571 | |
| 9572 | if (hwaddr_aton(addr, peer)) |
| 9573 | return -1; |
| 9574 | |
| 9575 | return p2p_unauthorize(p2p, peer); |
| 9576 | } |
| 9577 | |
| 9578 | |
| 9579 | /** |
| 9580 | * wpas_p2p_disconnect - Disconnect from a P2P Group |
| 9581 | * @wpa_s: Pointer to wpa_supplicant data |
| 9582 | * Returns: 0 on success, -1 on failure |
| 9583 | * |
| 9584 | * This can be used to disconnect from a group in which the local end is a P2P |
| 9585 | * Client or to end a P2P Group in case the local end is the Group Owner. If a |
| 9586 | * virtual network interface was created for this group, that interface will be |
| 9587 | * removed. Otherwise, only the configured P2P group network will be removed |
| 9588 | * from the interface. |
| 9589 | */ |
| 9590 | int wpas_p2p_disconnect(struct wpa_supplicant *wpa_s) |
| 9591 | { |
| 9592 | |
| 9593 | if (wpa_s == NULL) |
| 9594 | return -1; |
| 9595 | |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 9596 | return wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_REQUESTED) < 0 ? |
| 9597 | -1 : 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9598 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9599 | |
| 9600 | |
| 9601 | int wpas_p2p_in_progress(struct wpa_supplicant *wpa_s) |
| 9602 | { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 9603 | int ret; |
| 9604 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9605 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 9606 | return 0; |
| 9607 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 9608 | ret = p2p_in_progress(wpa_s->global->p2p); |
| 9609 | if (ret == 0) { |
| 9610 | /* |
| 9611 | * Check whether there is an ongoing WPS provisioning step (or |
| 9612 | * other parts of group formation) on another interface since |
| 9613 | * p2p_in_progress() does not report this to avoid issues for |
| 9614 | * scans during such provisioning step. |
| 9615 | */ |
| 9616 | if (wpa_s->global->p2p_group_formation && |
| 9617 | wpa_s->global->p2p_group_formation != wpa_s) { |
| 9618 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Another interface (%s) " |
| 9619 | "in group formation", |
| 9620 | wpa_s->global->p2p_group_formation->ifname); |
| 9621 | ret = 1; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 9622 | } else if (wpa_s->global->p2p_group_formation == wpa_s) { |
| 9623 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9624 | "P2P: Skip Extended Listen timeout and allow scans on current interface for group formation"); |
| 9625 | ret = 2; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 9626 | } |
| 9627 | } |
| 9628 | |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 9629 | if (!ret && wpa_s->global->p2p_go_wait_client.sec) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9630 | struct os_reltime now; |
| 9631 | os_get_reltime(&now); |
| 9632 | if (os_reltime_expired(&now, &wpa_s->global->p2p_go_wait_client, |
| 9633 | P2P_MAX_INITIAL_CONN_WAIT_GO)) { |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 9634 | /* Wait for the first client has expired */ |
| 9635 | wpa_s->global->p2p_go_wait_client.sec = 0; |
| 9636 | } else { |
| 9637 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Waiting for initial client connection during group formation"); |
| 9638 | ret = 1; |
| 9639 | } |
| 9640 | } |
| 9641 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 9642 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9643 | } |
| 9644 | |
| 9645 | |
| 9646 | void wpas_p2p_network_removed(struct wpa_supplicant *wpa_s, |
| 9647 | struct wpa_ssid *ssid) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9648 | { |
| 9649 | if (wpa_s->p2p_in_provisioning && ssid->p2p_group && |
| 9650 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9651 | wpa_s->p2pdev, NULL) > 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9652 | /** |
| 9653 | * Remove the network by scheduling the group formation |
| 9654 | * timeout to happen immediately. The teardown code |
| 9655 | * needs to be scheduled to run asynch later so that we |
| 9656 | * don't delete data from under ourselves unexpectedly. |
| 9657 | * Calling wpas_p2p_group_formation_timeout directly |
| 9658 | * causes a series of crashes in WPS failure scenarios. |
| 9659 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9660 | wpa_printf(MSG_DEBUG, "P2P: Canceled group formation due to " |
| 9661 | "P2P group network getting removed"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9662 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9663 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9664 | } |
| 9665 | } |
| 9666 | |
| 9667 | |
| 9668 | struct wpa_ssid * wpas_p2p_get_persistent(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9669 | const u8 *addr, const u8 *ssid, |
| 9670 | size_t ssid_len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9671 | { |
| 9672 | struct wpa_ssid *s; |
| 9673 | size_t i; |
| 9674 | |
| 9675 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 9676 | if (s->disabled != 2) |
| 9677 | continue; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9678 | if (ssid && |
| 9679 | (ssid_len != s->ssid_len || |
| 9680 | os_memcmp(ssid, s->ssid, ssid_len) != 0)) |
| 9681 | continue; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9682 | if (addr == NULL) { |
| 9683 | if (s->mode == WPAS_MODE_P2P_GO) |
| 9684 | return s; |
| 9685 | continue; |
| 9686 | } |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9687 | if (ether_addr_equal(s->bssid, addr)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9688 | return s; /* peer is GO in the persistent group */ |
| 9689 | if (s->mode != WPAS_MODE_P2P_GO || s->p2p_client_list == NULL) |
| 9690 | continue; |
| 9691 | for (i = 0; i < s->num_p2p_clients; i++) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9692 | if (ether_addr_equal(s->p2p_client_list + |
| 9693 | i * 2 * ETH_ALEN, addr)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9694 | return s; /* peer is P2P client in persistent |
| 9695 | * group */ |
| 9696 | } |
| 9697 | } |
| 9698 | |
| 9699 | return NULL; |
| 9700 | } |
| 9701 | |
| 9702 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 9703 | static void wpas_p2p_store_client_identity(struct wpa_supplicant *wpa_s, |
| 9704 | const u8 *addr) |
| 9705 | { |
| 9706 | u8 cipher; |
| 9707 | size_t dik_len; |
| 9708 | const u8 *dik_data; |
| 9709 | const u8 *pmk, *pmkid; |
| 9710 | size_t pmk_len; |
| 9711 | u8 iface_addr[ETH_ALEN]; |
| 9712 | struct hostapd_data *hapd; |
| 9713 | struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s; |
| 9714 | |
| 9715 | if (!wpa_s->p2p2 || !wpa_s->ap_iface) |
| 9716 | return; |
| 9717 | |
| 9718 | hapd = wpa_s->ap_iface->bss[0]; |
| 9719 | if (!hapd) |
| 9720 | return; |
| 9721 | |
| 9722 | if (p2p_get_dev_identity_key(p2p_wpa_s->global->p2p, addr, |
| 9723 | &dik_data, &dik_len, &cipher)) |
| 9724 | return; |
| 9725 | |
| 9726 | wpa_printf(MSG_DEBUG, "P2P: Fetch PMK from client (Device Addr " MACSTR |
| 9727 | ")", MAC2STR(addr)); |
| 9728 | if (wpa_auth_pmksa_get_pmk(hapd->wpa_auth, addr, &pmk, &pmk_len, |
| 9729 | &pmkid)) { |
| 9730 | if (p2p_get_interface_addr(p2p_wpa_s->global->p2p, addr, |
| 9731 | iface_addr)) |
| 9732 | return; |
| 9733 | wpa_printf(MSG_DEBUG, |
| 9734 | "P2P: Fetch PMK from client (Interface Addr " MACSTR |
| 9735 | ")", MAC2STR(iface_addr)); |
| 9736 | if (wpa_auth_pmksa_get_pmk(hapd->wpa_auth, iface_addr, &pmk, |
| 9737 | &pmk_len, &pmkid)) |
| 9738 | return; |
| 9739 | } |
| 9740 | |
| 9741 | wpa_printf(MSG_DEBUG, |
| 9742 | "P2P: Storing device identity of client (Device Addr " |
| 9743 | MACSTR ")", MAC2STR(addr)); |
| 9744 | wpas_p2p_store_identity(p2p_wpa_s, cipher, dik_data, dik_len, pmk, |
| 9745 | pmk_len, pmkid); |
| 9746 | } |
| 9747 | |
| 9748 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9749 | void wpas_p2p_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s, |
| 9750 | const u8 *addr) |
| 9751 | { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9752 | if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9753 | wpa_s->p2pdev, NULL) > 0) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9754 | /* |
| 9755 | * This can happen if WPS provisioning step is not terminated |
| 9756 | * cleanly (e.g., P2P Client does not send WSC_Done). Since the |
| 9757 | * peer was able to connect, there is no need to time out group |
| 9758 | * formation after this, though. In addition, this is used with |
| 9759 | * the initial connection wait on the GO as a separate formation |
| 9760 | * timeout and as such, expected to be hit after the initial WPS |
| 9761 | * provisioning step. |
| 9762 | */ |
| 9763 | 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] | 9764 | |
| 9765 | if (!wpa_s->p2p_go_group_formation_completed && |
| 9766 | !wpa_s->group_formation_reported) { |
| 9767 | /* |
| 9768 | * GO has not yet notified group formation success since |
| 9769 | * the WPS step was not completed cleanly. Do that |
| 9770 | * notification now since the P2P Client was able to |
| 9771 | * connect and as such, must have received the |
| 9772 | * credential from the WPS step. |
| 9773 | */ |
| 9774 | if (wpa_s->global->p2p) |
| 9775 | p2p_wps_success_cb(wpa_s->global->p2p, addr); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 9776 | wpas_group_formation_completed(wpa_s, 1, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9777 | } |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9778 | } |
| 9779 | if (!wpa_s->p2p_go_group_formation_completed) { |
| 9780 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Marking group formation completed on GO on first data connection"); |
| 9781 | wpa_s->p2p_go_group_formation_completed = 1; |
| 9782 | wpa_s->global->p2p_group_formation = NULL; |
| 9783 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 9784 | wpa_s->p2p_in_invitation = 0; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 9785 | wpa_s->p2p_retry_limit = 0; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9786 | } |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 9787 | wpa_s->global->p2p_go_wait_client.sec = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9788 | if (addr == NULL) |
| 9789 | return; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 9790 | |
| 9791 | wpas_p2p_store_client_identity(wpa_s, addr); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9792 | wpas_p2p_add_persistent_group_client(wpa_s, addr); |
| 9793 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9794 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9795 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9796 | static int wpas_p2p_fallback_to_go_neg(struct wpa_supplicant *wpa_s, |
| 9797 | int group_added) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9798 | { |
| 9799 | struct wpa_supplicant *group = wpa_s; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9800 | int ret = 0; |
| 9801 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9802 | if (wpa_s->global->p2p_group_formation) |
| 9803 | group = wpa_s->global->p2p_group_formation; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 9804 | wpa_s = wpa_s->global->p2p_init_wpa_s; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9805 | offchannel_send_action_done(wpa_s); |
| 9806 | if (group_added) |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9807 | ret = wpas_p2p_group_delete(group, P2P_GROUP_REMOVAL_SILENT); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9808 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Fall back to GO Negotiation"); |
| 9809 | wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr, wpa_s->p2p_pin, |
| 9810 | wpa_s->p2p_wps_method, wpa_s->p2p_persistent_group, 0, |
| 9811 | 0, 0, wpa_s->p2p_go_intent, wpa_s->p2p_connect_freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9812 | wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9813 | wpa_s->p2p_persistent_id, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9814 | wpa_s->p2p_pd_before_go_neg, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 9815 | wpa_s->p2p_go_ht40, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9816 | wpa_s->p2p_go_vht, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9817 | wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9818 | wpa_s->p2p_go_he, |
| 9819 | wpa_s->p2p_go_edmg, |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 9820 | NULL, 0, is_p2p_allow_6ghz(wpa_s->global->p2p), |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 9821 | wpa_s->p2p2, wpa_s->p2p_bootstrap, NULL, false); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9822 | return ret; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9823 | } |
| 9824 | |
| 9825 | |
| 9826 | int wpas_p2p_scan_no_go_seen(struct wpa_supplicant *wpa_s) |
| 9827 | { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9828 | int res; |
| 9829 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9830 | if (!wpa_s->p2p_fallback_to_go_neg || |
| 9831 | wpa_s->p2p_in_provisioning <= 5) |
| 9832 | return 0; |
| 9833 | |
| 9834 | if (wpas_p2p_peer_go(wpa_s, wpa_s->pending_join_dev_addr) > 0) |
| 9835 | return 0; /* peer operating as a GO */ |
| 9836 | |
| 9837 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: GO not found for p2p_connect-auto - " |
| 9838 | "fallback to GO Negotiation"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9839 | 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] | 9840 | "reason=GO-not-found"); |
| 9841 | res = wpas_p2p_fallback_to_go_neg(wpa_s, 1); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9842 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9843 | return res == 1 ? 2 : 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9844 | } |
| 9845 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9846 | |
| 9847 | unsigned int wpas_p2p_search_delay(struct wpa_supplicant *wpa_s) |
| 9848 | { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9849 | struct wpa_supplicant *ifs; |
| 9850 | |
| 9851 | if (wpa_s->wpa_state > WPA_SCANNING) { |
| 9852 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search delay due to " |
| 9853 | "concurrent operation", |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 9854 | wpa_s->conf->p2p_search_delay); |
| 9855 | return wpa_s->conf->p2p_search_delay; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9856 | } |
| 9857 | |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 9858 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 9859 | radio_list) { |
| 9860 | if (ifs != wpa_s && ifs->wpa_state > WPA_SCANNING) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9861 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search " |
| 9862 | "delay due to concurrent operation on " |
| 9863 | "interface %s", |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 9864 | wpa_s->conf->p2p_search_delay, |
| 9865 | ifs->ifname); |
| 9866 | return wpa_s->conf->p2p_search_delay; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 9867 | } |
| 9868 | } |
| 9869 | |
| 9870 | return 0; |
| 9871 | } |
| 9872 | |
Dmitry Shmidt | 37d4d6a | 2013-03-18 13:09:42 -0700 | [diff] [blame] | 9873 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9874 | static int wpas_p2p_remove_psk_entry(struct wpa_supplicant *wpa_s, |
| 9875 | struct wpa_ssid *s, const u8 *addr, |
| 9876 | int iface_addr) |
| 9877 | { |
| 9878 | struct psk_list_entry *psk, *tmp; |
| 9879 | int changed = 0; |
| 9880 | |
| 9881 | dl_list_for_each_safe(psk, tmp, &s->psk_list, struct psk_list_entry, |
| 9882 | list) { |
| 9883 | if ((iface_addr && !psk->p2p && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9884 | ether_addr_equal(addr, psk->addr)) || |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9885 | (!iface_addr && psk->p2p && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 9886 | ether_addr_equal(addr, psk->addr))) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9887 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9888 | "P2P: Remove persistent group PSK list entry for " |
| 9889 | MACSTR " p2p=%u", |
| 9890 | MAC2STR(psk->addr), psk->p2p); |
| 9891 | dl_list_del(&psk->list); |
| 9892 | os_free(psk); |
| 9893 | changed++; |
| 9894 | } |
| 9895 | } |
| 9896 | |
| 9897 | return changed; |
| 9898 | } |
| 9899 | |
| 9900 | |
| 9901 | void wpas_p2p_new_psk_cb(struct wpa_supplicant *wpa_s, const u8 *mac_addr, |
| 9902 | const u8 *p2p_dev_addr, |
| 9903 | const u8 *psk, size_t psk_len) |
| 9904 | { |
| 9905 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 9906 | struct wpa_ssid *persistent; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 9907 | struct psk_list_entry *p, *last; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9908 | |
| 9909 | if (psk_len != sizeof(p->psk)) |
| 9910 | return; |
| 9911 | |
| 9912 | if (p2p_dev_addr) { |
| 9913 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New PSK for addr=" MACSTR |
| 9914 | " p2p_dev_addr=" MACSTR, |
| 9915 | MAC2STR(mac_addr), MAC2STR(p2p_dev_addr)); |
| 9916 | if (is_zero_ether_addr(p2p_dev_addr)) |
| 9917 | p2p_dev_addr = NULL; |
| 9918 | } else { |
| 9919 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New PSK for addr=" MACSTR, |
| 9920 | MAC2STR(mac_addr)); |
| 9921 | } |
| 9922 | |
| 9923 | if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) { |
| 9924 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: new_psk_cb during group formation"); |
| 9925 | /* To be added to persistent group once created */ |
| 9926 | if (wpa_s->global->add_psk == NULL) { |
| 9927 | wpa_s->global->add_psk = os_zalloc(sizeof(*p)); |
| 9928 | if (wpa_s->global->add_psk == NULL) |
| 9929 | return; |
| 9930 | } |
| 9931 | p = wpa_s->global->add_psk; |
| 9932 | if (p2p_dev_addr) { |
| 9933 | p->p2p = 1; |
| 9934 | os_memcpy(p->addr, p2p_dev_addr, ETH_ALEN); |
| 9935 | } else { |
| 9936 | p->p2p = 0; |
| 9937 | os_memcpy(p->addr, mac_addr, ETH_ALEN); |
| 9938 | } |
| 9939 | os_memcpy(p->psk, psk, psk_len); |
| 9940 | return; |
| 9941 | } |
| 9942 | |
| 9943 | if (ssid->mode != WPAS_MODE_P2P_GO || !ssid->p2p_persistent_group) { |
| 9944 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Ignore new_psk_cb on not-persistent GO"); |
| 9945 | return; |
| 9946 | } |
| 9947 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9948 | persistent = wpas_p2p_get_persistent(wpa_s->p2pdev, NULL, ssid->ssid, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9949 | ssid->ssid_len); |
| 9950 | if (!persistent) { |
| 9951 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not find persistent group information to store the new PSK"); |
| 9952 | return; |
| 9953 | } |
| 9954 | |
| 9955 | p = os_zalloc(sizeof(*p)); |
| 9956 | if (p == NULL) |
| 9957 | return; |
| 9958 | if (p2p_dev_addr) { |
| 9959 | p->p2p = 1; |
| 9960 | os_memcpy(p->addr, p2p_dev_addr, ETH_ALEN); |
| 9961 | } else { |
| 9962 | p->p2p = 0; |
| 9963 | os_memcpy(p->addr, mac_addr, ETH_ALEN); |
| 9964 | } |
| 9965 | os_memcpy(p->psk, psk, psk_len); |
| 9966 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 9967 | if (dl_list_len(&persistent->psk_list) > P2P_MAX_STORED_CLIENTS && |
| 9968 | (last = dl_list_last(&persistent->psk_list, |
| 9969 | struct psk_list_entry, list))) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9970 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove oldest PSK entry for " |
| 9971 | MACSTR " (p2p=%u) to make room for a new one", |
| 9972 | MAC2STR(last->addr), last->p2p); |
| 9973 | dl_list_del(&last->list); |
| 9974 | os_free(last); |
| 9975 | } |
| 9976 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9977 | wpas_p2p_remove_psk_entry(wpa_s->p2pdev, persistent, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9978 | p2p_dev_addr ? p2p_dev_addr : mac_addr, |
| 9979 | p2p_dev_addr == NULL); |
| 9980 | if (p2p_dev_addr) { |
| 9981 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for p2p_dev_addr=" |
| 9982 | MACSTR, MAC2STR(p2p_dev_addr)); |
| 9983 | } else { |
| 9984 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for addr=" MACSTR, |
| 9985 | MAC2STR(mac_addr)); |
| 9986 | } |
| 9987 | dl_list_add(&persistent->psk_list, &p->list); |
| 9988 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9989 | if (wpa_s->p2pdev->conf->update_config && |
| 9990 | wpa_config_write(wpa_s->p2pdev->confname, wpa_s->p2pdev->conf)) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9991 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9992 | } |
| 9993 | |
| 9994 | |
| 9995 | static void wpas_p2p_remove_psk(struct wpa_supplicant *wpa_s, |
| 9996 | struct wpa_ssid *s, const u8 *addr, |
| 9997 | int iface_addr) |
| 9998 | { |
| 9999 | int res; |
| 10000 | |
| 10001 | res = wpas_p2p_remove_psk_entry(wpa_s, s, addr, iface_addr); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 10002 | if (res > 0 && wpa_s->conf->update_config && |
| 10003 | wpa_config_write(wpa_s->confname, wpa_s->conf)) |
| 10004 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10005 | "P2P: Failed to update configuration"); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 10006 | } |
| 10007 | |
| 10008 | |
| 10009 | static void wpas_p2p_remove_client_go(struct wpa_supplicant *wpa_s, |
| 10010 | const u8 *peer, int iface_addr) |
| 10011 | { |
| 10012 | struct hostapd_data *hapd; |
| 10013 | struct hostapd_wpa_psk *psk, *prev, *rem; |
| 10014 | struct sta_info *sta; |
| 10015 | |
| 10016 | if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL || |
| 10017 | wpa_s->current_ssid->mode != WPAS_MODE_P2P_GO) |
| 10018 | return; |
| 10019 | |
| 10020 | /* Remove per-station PSK entry */ |
| 10021 | hapd = wpa_s->ap_iface->bss[0]; |
| 10022 | prev = NULL; |
| 10023 | psk = hapd->conf->ssid.wpa_psk; |
| 10024 | while (psk) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10025 | if ((iface_addr && ether_addr_equal(peer, psk->addr)) || |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 10026 | (!iface_addr && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10027 | ether_addr_equal(peer, psk->p2p_dev_addr))) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 10028 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove operating group PSK entry for " |
| 10029 | MACSTR " iface_addr=%d", |
| 10030 | MAC2STR(peer), iface_addr); |
| 10031 | if (prev) |
| 10032 | prev->next = psk->next; |
| 10033 | else |
| 10034 | hapd->conf->ssid.wpa_psk = psk->next; |
| 10035 | rem = psk; |
| 10036 | psk = psk->next; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 10037 | bin_clear_free(rem, sizeof(*rem)); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 10038 | } else { |
| 10039 | prev = psk; |
| 10040 | psk = psk->next; |
| 10041 | } |
| 10042 | } |
| 10043 | |
| 10044 | /* Disconnect from group */ |
| 10045 | if (iface_addr) |
| 10046 | sta = ap_get_sta(hapd, peer); |
| 10047 | else |
| 10048 | sta = ap_get_sta_p2p(hapd, peer); |
| 10049 | if (sta) { |
| 10050 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disconnect peer " MACSTR |
| 10051 | " (iface_addr=%d) from group", |
| 10052 | MAC2STR(peer), iface_addr); |
| 10053 | hostapd_drv_sta_deauth(hapd, sta->addr, |
| 10054 | WLAN_REASON_DEAUTH_LEAVING); |
| 10055 | ap_sta_deauthenticate(hapd, sta, WLAN_REASON_DEAUTH_LEAVING); |
| 10056 | } |
| 10057 | } |
| 10058 | |
| 10059 | |
| 10060 | void wpas_p2p_remove_client(struct wpa_supplicant *wpa_s, const u8 *peer, |
| 10061 | int iface_addr) |
| 10062 | { |
| 10063 | struct wpa_ssid *s; |
| 10064 | struct wpa_supplicant *w; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 10065 | 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] | 10066 | |
| 10067 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove client " MACSTR, MAC2STR(peer)); |
| 10068 | |
| 10069 | /* Remove from any persistent group */ |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 10070 | for (s = p2p_wpa_s->conf->ssid; s; s = s->next) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 10071 | if (s->disabled != 2 || s->mode != WPAS_MODE_P2P_GO) |
| 10072 | continue; |
| 10073 | if (!iface_addr) |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 10074 | wpas_remove_persistent_peer(p2p_wpa_s, s, peer, 0); |
| 10075 | wpas_p2p_remove_psk(p2p_wpa_s, s, peer, iface_addr); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 10076 | } |
| 10077 | |
| 10078 | /* Remove from any operating group */ |
| 10079 | for (w = wpa_s->global->ifaces; w; w = w->next) |
| 10080 | wpas_p2p_remove_client_go(w, peer, iface_addr); |
| 10081 | } |
| 10082 | |
| 10083 | |
| 10084 | static void wpas_p2p_psk_failure_removal(void *eloop_ctx, void *timeout_ctx) |
| 10085 | { |
| 10086 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 10087 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_PSK_FAILURE); |
| 10088 | } |
| 10089 | |
| 10090 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 10091 | static void wpas_p2p_group_freq_conflict(void *eloop_ctx, void *timeout_ctx) |
| 10092 | { |
| 10093 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 10094 | |
| 10095 | wpa_printf(MSG_DEBUG, "P2P: Frequency conflict - terminate group"); |
| 10096 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_FREQ_CONFLICT); |
| 10097 | } |
| 10098 | |
| 10099 | |
| 10100 | int wpas_p2p_handle_frequency_conflicts(struct wpa_supplicant *wpa_s, int freq, |
| 10101 | struct wpa_ssid *ssid) |
| 10102 | { |
| 10103 | struct wpa_supplicant *iface; |
| 10104 | |
| 10105 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 10106 | if (!iface->current_ssid || |
| 10107 | iface->current_ssid->frequency == freq || |
| 10108 | (iface->p2p_group_interface == NOT_P2P_GROUP_INTERFACE && |
| 10109 | !iface->current_ssid->p2p_group)) |
| 10110 | continue; |
| 10111 | |
| 10112 | /* Remove the connection with least priority */ |
| 10113 | if (!wpas_is_p2p_prioritized(iface)) { |
| 10114 | /* STA connection has priority over existing |
| 10115 | * P2P connection, so remove the interface. */ |
| 10116 | wpa_printf(MSG_DEBUG, "P2P: Removing P2P connection due to single channel concurrent mode frequency conflict"); |
| 10117 | eloop_register_timeout(0, 0, |
| 10118 | wpas_p2p_group_freq_conflict, |
| 10119 | iface, NULL); |
| 10120 | /* If connection in progress is P2P connection, do not |
| 10121 | * proceed for the connection. */ |
| 10122 | if (wpa_s == iface) |
| 10123 | return -1; |
| 10124 | else |
| 10125 | return 0; |
| 10126 | } else { |
| 10127 | /* P2P connection has priority, disable the STA network |
| 10128 | */ |
| 10129 | wpa_supplicant_disable_network(wpa_s->global->ifaces, |
| 10130 | ssid); |
| 10131 | wpa_msg(wpa_s->global->ifaces, MSG_INFO, |
| 10132 | WPA_EVENT_FREQ_CONFLICT " id=%d", ssid->id); |
| 10133 | os_memset(wpa_s->global->ifaces->pending_bssid, 0, |
| 10134 | ETH_ALEN); |
| 10135 | /* If P2P connection is in progress, continue |
| 10136 | * connecting...*/ |
| 10137 | if (wpa_s == iface) |
| 10138 | return 0; |
| 10139 | else |
| 10140 | return -1; |
| 10141 | } |
| 10142 | } |
| 10143 | |
| 10144 | return 0; |
| 10145 | } |
| 10146 | |
| 10147 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 10148 | int wpas_p2p_4way_hs_failed(struct wpa_supplicant *wpa_s) |
| 10149 | { |
| 10150 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 10151 | |
| 10152 | if (ssid == NULL || !ssid->p2p_group) |
| 10153 | return 0; |
| 10154 | |
| 10155 | if (wpa_s->p2p_last_4way_hs_fail && |
| 10156 | wpa_s->p2p_last_4way_hs_fail == ssid) { |
| 10157 | u8 go_dev_addr[ETH_ALEN]; |
| 10158 | struct wpa_ssid *persistent; |
| 10159 | |
| 10160 | if (wpas_p2p_persistent_group(wpa_s, go_dev_addr, |
| 10161 | ssid->ssid, |
| 10162 | ssid->ssid_len) <= 0) { |
| 10163 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not determine whether 4-way handshake failures were for a persistent group"); |
| 10164 | goto disconnect; |
| 10165 | } |
| 10166 | |
| 10167 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Two 4-way handshake failures for a P2P group - go_dev_addr=" |
| 10168 | MACSTR, MAC2STR(go_dev_addr)); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 10169 | persistent = wpas_p2p_get_persistent(wpa_s->p2pdev, go_dev_addr, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 10170 | ssid->ssid, |
| 10171 | ssid->ssid_len); |
| 10172 | if (persistent == NULL || persistent->mode != WPAS_MODE_INFRA) { |
| 10173 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No matching persistent group stored"); |
| 10174 | goto disconnect; |
| 10175 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 10176 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 10177 | P2P_EVENT_PERSISTENT_PSK_FAIL "%d", |
| 10178 | persistent->id); |
| 10179 | disconnect: |
| 10180 | wpa_s->p2p_last_4way_hs_fail = NULL; |
| 10181 | /* |
| 10182 | * Remove the group from a timeout to avoid issues with caller |
| 10183 | * continuing to use the interface if this is on a P2P group |
| 10184 | * interface. |
| 10185 | */ |
| 10186 | eloop_register_timeout(0, 0, wpas_p2p_psk_failure_removal, |
| 10187 | wpa_s, NULL); |
| 10188 | return 1; |
| 10189 | } |
| 10190 | |
| 10191 | wpa_s->p2p_last_4way_hs_fail = ssid; |
| 10192 | return 0; |
| 10193 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 10194 | |
| 10195 | |
| 10196 | #ifdef CONFIG_WPS_NFC |
| 10197 | |
| 10198 | static struct wpabuf * wpas_p2p_nfc_handover(int ndef, struct wpabuf *wsc, |
| 10199 | struct wpabuf *p2p) |
| 10200 | { |
| 10201 | struct wpabuf *ret; |
| 10202 | size_t wsc_len; |
| 10203 | |
| 10204 | if (p2p == NULL) { |
| 10205 | wpabuf_free(wsc); |
| 10206 | wpa_printf(MSG_DEBUG, "P2P: No p2p buffer for handover"); |
| 10207 | return NULL; |
| 10208 | } |
| 10209 | |
| 10210 | wsc_len = wsc ? wpabuf_len(wsc) : 0; |
| 10211 | ret = wpabuf_alloc(2 + wsc_len + 2 + wpabuf_len(p2p)); |
| 10212 | if (ret == NULL) { |
| 10213 | wpabuf_free(wsc); |
| 10214 | wpabuf_free(p2p); |
| 10215 | return NULL; |
| 10216 | } |
| 10217 | |
| 10218 | wpabuf_put_be16(ret, wsc_len); |
| 10219 | if (wsc) |
| 10220 | wpabuf_put_buf(ret, wsc); |
| 10221 | wpabuf_put_be16(ret, wpabuf_len(p2p)); |
| 10222 | wpabuf_put_buf(ret, p2p); |
| 10223 | |
| 10224 | wpabuf_free(wsc); |
| 10225 | wpabuf_free(p2p); |
| 10226 | wpa_hexdump_buf(MSG_DEBUG, |
| 10227 | "P2P: Generated NFC connection handover message", ret); |
| 10228 | |
| 10229 | if (ndef && ret) { |
| 10230 | struct wpabuf *tmp; |
| 10231 | tmp = ndef_build_p2p(ret); |
| 10232 | wpabuf_free(ret); |
| 10233 | if (tmp == NULL) { |
| 10234 | wpa_printf(MSG_DEBUG, "P2P: Failed to NDEF encapsulate handover request"); |
| 10235 | return NULL; |
| 10236 | } |
| 10237 | ret = tmp; |
| 10238 | } |
| 10239 | |
| 10240 | return ret; |
| 10241 | } |
| 10242 | |
| 10243 | |
| 10244 | static int wpas_p2p_cli_freq(struct wpa_supplicant *wpa_s, |
| 10245 | struct wpa_ssid **ssid, u8 *go_dev_addr) |
| 10246 | { |
| 10247 | struct wpa_supplicant *iface; |
| 10248 | |
| 10249 | if (go_dev_addr) |
| 10250 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 10251 | if (ssid) |
| 10252 | *ssid = NULL; |
| 10253 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 10254 | if (iface->wpa_state < WPA_ASSOCIATING || |
| 10255 | iface->current_ssid == NULL || iface->assoc_freq == 0 || |
| 10256 | !iface->current_ssid->p2p_group || |
| 10257 | iface->current_ssid->mode != WPAS_MODE_INFRA) |
| 10258 | continue; |
| 10259 | if (ssid) |
| 10260 | *ssid = iface->current_ssid; |
| 10261 | if (go_dev_addr) |
| 10262 | os_memcpy(go_dev_addr, iface->go_dev_addr, ETH_ALEN); |
| 10263 | return iface->assoc_freq; |
| 10264 | } |
| 10265 | return 0; |
| 10266 | } |
| 10267 | |
| 10268 | |
| 10269 | struct wpabuf * wpas_p2p_nfc_handover_req(struct wpa_supplicant *wpa_s, |
| 10270 | int ndef) |
| 10271 | { |
| 10272 | struct wpabuf *wsc, *p2p; |
| 10273 | struct wpa_ssid *ssid; |
| 10274 | u8 go_dev_addr[ETH_ALEN]; |
| 10275 | int cli_freq = wpas_p2p_cli_freq(wpa_s, &ssid, go_dev_addr); |
| 10276 | |
| 10277 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) { |
| 10278 | wpa_printf(MSG_DEBUG, "P2P: P2P disabled - cannot build handover request"); |
| 10279 | return NULL; |
| 10280 | } |
| 10281 | |
| 10282 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL && |
| 10283 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, |
| 10284 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) { |
| 10285 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No DH key available for handover request"); |
| 10286 | return NULL; |
| 10287 | } |
| 10288 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 10289 | wpa_s->p2p2 = false; |
| 10290 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 10291 | if (cli_freq == 0) { |
| 10292 | wsc = wps_build_nfc_handover_req_p2p( |
| 10293 | wpa_s->parent->wps, wpa_s->conf->wps_nfc_dh_pubkey); |
| 10294 | } else |
| 10295 | wsc = NULL; |
| 10296 | p2p = p2p_build_nfc_handover_req(wpa_s->global->p2p, cli_freq, |
| 10297 | go_dev_addr, ssid ? ssid->ssid : NULL, |
| 10298 | ssid ? ssid->ssid_len : 0); |
| 10299 | |
| 10300 | return wpas_p2p_nfc_handover(ndef, wsc, p2p); |
| 10301 | } |
| 10302 | |
| 10303 | |
| 10304 | struct wpabuf * wpas_p2p_nfc_handover_sel(struct wpa_supplicant *wpa_s, |
| 10305 | int ndef, int tag) |
| 10306 | { |
| 10307 | struct wpabuf *wsc, *p2p; |
| 10308 | struct wpa_ssid *ssid; |
| 10309 | u8 go_dev_addr[ETH_ALEN]; |
| 10310 | int cli_freq = wpas_p2p_cli_freq(wpa_s, &ssid, go_dev_addr); |
| 10311 | |
| 10312 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 10313 | return NULL; |
| 10314 | |
| 10315 | if (!tag && wpa_s->conf->wps_nfc_dh_pubkey == NULL && |
| 10316 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, |
| 10317 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) |
| 10318 | return NULL; |
| 10319 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 10320 | wpa_s->p2p2 = false; |
| 10321 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 10322 | if (cli_freq == 0) { |
| 10323 | wsc = wps_build_nfc_handover_sel_p2p( |
| 10324 | wpa_s->parent->wps, |
| 10325 | tag ? wpa_s->conf->wps_nfc_dev_pw_id : |
| 10326 | DEV_PW_NFC_CONNECTION_HANDOVER, |
| 10327 | wpa_s->conf->wps_nfc_dh_pubkey, |
| 10328 | tag ? wpa_s->conf->wps_nfc_dev_pw : NULL); |
| 10329 | } else |
| 10330 | wsc = NULL; |
| 10331 | p2p = p2p_build_nfc_handover_sel(wpa_s->global->p2p, cli_freq, |
| 10332 | go_dev_addr, ssid ? ssid->ssid : NULL, |
| 10333 | ssid ? ssid->ssid_len : 0); |
| 10334 | |
| 10335 | return wpas_p2p_nfc_handover(ndef, wsc, p2p); |
| 10336 | } |
| 10337 | |
| 10338 | |
| 10339 | static int wpas_p2p_nfc_join_group(struct wpa_supplicant *wpa_s, |
| 10340 | struct p2p_nfc_params *params) |
| 10341 | { |
| 10342 | wpa_printf(MSG_DEBUG, "P2P: Initiate join-group based on NFC " |
| 10343 | "connection handover (freq=%d)", |
| 10344 | params->go_freq); |
| 10345 | |
| 10346 | if (params->go_freq && params->go_ssid_len) { |
| 10347 | wpa_s->p2p_wps_method = WPS_NFC; |
| 10348 | wpa_s->pending_join_wps_method = WPS_NFC; |
| 10349 | os_memset(wpa_s->pending_join_iface_addr, 0, ETH_ALEN); |
| 10350 | os_memcpy(wpa_s->pending_join_dev_addr, params->go_dev_addr, |
| 10351 | ETH_ALEN); |
| 10352 | return wpas_p2p_join_start(wpa_s, params->go_freq, |
| 10353 | params->go_ssid, |
| 10354 | params->go_ssid_len); |
| 10355 | } |
| 10356 | |
| 10357 | return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL, |
| 10358 | WPS_NFC, 0, 0, 1, 0, wpa_s->conf->p2p_go_intent, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 10359 | params->go_freq, wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 10360 | -1, 0, 1, 1, wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 10361 | wpa_s->p2p_go_he, wpa_s->p2p_go_edmg, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 10362 | params->go_ssid_len ? params->go_ssid : NULL, |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 10363 | params->go_ssid_len, false, wpa_s->p2p2, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 10364 | wpa_s->p2p_bootstrap, NULL, false); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 10365 | } |
| 10366 | |
| 10367 | |
| 10368 | static int wpas_p2p_nfc_auth_join(struct wpa_supplicant *wpa_s, |
| 10369 | struct p2p_nfc_params *params, int tag) |
| 10370 | { |
| 10371 | int res, persistent; |
| 10372 | struct wpa_ssid *ssid; |
| 10373 | |
| 10374 | wpa_printf(MSG_DEBUG, "P2P: Authorize join-group based on NFC " |
| 10375 | "connection handover"); |
| 10376 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 10377 | ssid = wpa_s->current_ssid; |
| 10378 | if (ssid == NULL) |
| 10379 | continue; |
| 10380 | if (ssid->mode != WPAS_MODE_P2P_GO) |
| 10381 | continue; |
| 10382 | if (wpa_s->ap_iface == NULL) |
| 10383 | continue; |
| 10384 | break; |
| 10385 | } |
| 10386 | if (wpa_s == NULL) { |
| 10387 | wpa_printf(MSG_DEBUG, "P2P: Could not find GO interface"); |
| 10388 | return -1; |
| 10389 | } |
| 10390 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10391 | if (wpa_s->p2pdev->p2p_oob_dev_pw_id != |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 10392 | DEV_PW_NFC_CONNECTION_HANDOVER && |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10393 | !wpa_s->p2pdev->p2p_oob_dev_pw) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 10394 | wpa_printf(MSG_DEBUG, "P2P: No NFC Dev Pw known"); |
| 10395 | return -1; |
| 10396 | } |
| 10397 | res = wpas_ap_wps_add_nfc_pw( |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10398 | wpa_s, wpa_s->p2pdev->p2p_oob_dev_pw_id, |
| 10399 | wpa_s->p2pdev->p2p_oob_dev_pw, |
| 10400 | wpa_s->p2pdev->p2p_peer_oob_pk_hash_known ? |
| 10401 | wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : NULL); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 10402 | if (res) |
| 10403 | return res; |
| 10404 | |
| 10405 | if (!tag) { |
| 10406 | wpa_printf(MSG_DEBUG, "P2P: Negotiated handover - wait for peer to join without invitation"); |
| 10407 | return 0; |
| 10408 | } |
| 10409 | |
| 10410 | if (!params->peer || |
| 10411 | !(params->peer->dev_capab & P2P_DEV_CAPAB_INVITATION_PROCEDURE)) |
| 10412 | return 0; |
| 10413 | |
| 10414 | wpa_printf(MSG_DEBUG, "P2P: Static handover - invite peer " MACSTR |
| 10415 | " to join", MAC2STR(params->peer->p2p_device_addr)); |
| 10416 | |
| 10417 | wpa_s->global->p2p_invite_group = wpa_s; |
| 10418 | persistent = ssid->p2p_persistent_group && |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10419 | wpas_p2p_get_persistent(wpa_s->p2pdev, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 10420 | params->peer->p2p_device_addr, |
| 10421 | ssid->ssid, ssid->ssid_len); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10422 | wpa_s->p2pdev->pending_invite_ssid_id = -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 10423 | |
| 10424 | return p2p_invite(wpa_s->global->p2p, params->peer->p2p_device_addr, |
| 10425 | P2P_INVITE_ROLE_ACTIVE_GO, wpa_s->own_addr, |
| 10426 | ssid->ssid, ssid->ssid_len, ssid->frequency, |
| 10427 | wpa_s->global->p2p_dev_addr, persistent, 0, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 10428 | wpa_s->p2pdev->p2p_oob_dev_pw_id, false); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 10429 | } |
| 10430 | |
| 10431 | |
| 10432 | static int wpas_p2p_nfc_init_go_neg(struct wpa_supplicant *wpa_s, |
| 10433 | struct p2p_nfc_params *params, |
| 10434 | int forced_freq) |
| 10435 | { |
| 10436 | wpa_printf(MSG_DEBUG, "P2P: Initiate GO Negotiation based on NFC " |
| 10437 | "connection handover"); |
| 10438 | return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL, |
| 10439 | WPS_NFC, 0, 0, 0, 0, wpa_s->conf->p2p_go_intent, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 10440 | forced_freq, wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 10441 | -1, 0, 1, 1, wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 10442 | wpa_s->p2p_go_he, wpa_s->p2p_go_edmg, |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 10443 | NULL, 0, false, wpa_s->p2p2, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 10444 | wpa_s->p2p_bootstrap, NULL, false); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 10445 | } |
| 10446 | |
| 10447 | |
| 10448 | static int wpas_p2p_nfc_resp_go_neg(struct wpa_supplicant *wpa_s, |
| 10449 | struct p2p_nfc_params *params, |
| 10450 | int forced_freq) |
| 10451 | { |
| 10452 | int res; |
| 10453 | |
| 10454 | wpa_printf(MSG_DEBUG, "P2P: Authorize GO Negotiation based on NFC " |
| 10455 | "connection handover"); |
| 10456 | res = wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL, |
| 10457 | WPS_NFC, 0, 0, 0, 1, wpa_s->conf->p2p_go_intent, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 10458 | forced_freq, wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 10459 | -1, 0, 1, 1, wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 10460 | wpa_s->p2p_go_he, wpa_s->p2p_go_edmg, |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 10461 | NULL, 0, false, wpa_s->p2p2, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 10462 | wpa_s->p2p_bootstrap, NULL, false); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 10463 | if (res) |
| 10464 | return res; |
| 10465 | |
| 10466 | res = wpas_p2p_listen(wpa_s, 60); |
| 10467 | if (res) { |
| 10468 | p2p_unauthorize(wpa_s->global->p2p, |
| 10469 | params->peer->p2p_device_addr); |
| 10470 | } |
| 10471 | |
| 10472 | return res; |
| 10473 | } |
| 10474 | |
| 10475 | |
| 10476 | static int wpas_p2p_nfc_connection_handover(struct wpa_supplicant *wpa_s, |
| 10477 | const struct wpabuf *data, |
| 10478 | int sel, int tag, int forced_freq) |
| 10479 | { |
| 10480 | const u8 *pos, *end; |
| 10481 | u16 len, id; |
| 10482 | struct p2p_nfc_params params; |
| 10483 | int res; |
| 10484 | |
| 10485 | os_memset(¶ms, 0, sizeof(params)); |
| 10486 | params.sel = sel; |
| 10487 | |
| 10488 | wpa_hexdump_buf(MSG_DEBUG, "P2P: Received NFC tag payload", data); |
| 10489 | |
| 10490 | pos = wpabuf_head(data); |
| 10491 | end = pos + wpabuf_len(data); |
| 10492 | |
| 10493 | if (end - pos < 2) { |
| 10494 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for Length of WSC " |
| 10495 | "attributes"); |
| 10496 | return -1; |
| 10497 | } |
| 10498 | len = WPA_GET_BE16(pos); |
| 10499 | pos += 2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10500 | if (len > end - pos) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 10501 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for WSC " |
| 10502 | "attributes"); |
| 10503 | return -1; |
| 10504 | } |
| 10505 | params.wsc_attr = pos; |
| 10506 | params.wsc_len = len; |
| 10507 | pos += len; |
| 10508 | |
| 10509 | if (end - pos < 2) { |
| 10510 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for Length of P2P " |
| 10511 | "attributes"); |
| 10512 | return -1; |
| 10513 | } |
| 10514 | len = WPA_GET_BE16(pos); |
| 10515 | pos += 2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10516 | if (len > end - pos) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 10517 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for P2P " |
| 10518 | "attributes"); |
| 10519 | return -1; |
| 10520 | } |
| 10521 | params.p2p_attr = pos; |
| 10522 | params.p2p_len = len; |
| 10523 | pos += len; |
| 10524 | |
| 10525 | wpa_hexdump(MSG_DEBUG, "P2P: WSC attributes", |
| 10526 | params.wsc_attr, params.wsc_len); |
| 10527 | wpa_hexdump(MSG_DEBUG, "P2P: P2P attributes", |
| 10528 | params.p2p_attr, params.p2p_len); |
| 10529 | if (pos < end) { |
| 10530 | wpa_hexdump(MSG_DEBUG, |
| 10531 | "P2P: Ignored extra data after P2P attributes", |
| 10532 | pos, end - pos); |
| 10533 | } |
| 10534 | |
| 10535 | res = p2p_process_nfc_connection_handover(wpa_s->global->p2p, ¶ms); |
| 10536 | if (res) |
| 10537 | return res; |
| 10538 | |
| 10539 | if (params.next_step == NO_ACTION) |
| 10540 | return 0; |
| 10541 | |
| 10542 | if (params.next_step == BOTH_GO) { |
| 10543 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_BOTH_GO "peer=" MACSTR, |
| 10544 | MAC2STR(params.peer->p2p_device_addr)); |
| 10545 | return 0; |
| 10546 | } |
| 10547 | |
| 10548 | if (params.next_step == PEER_CLIENT) { |
| 10549 | if (!is_zero_ether_addr(params.go_dev_addr)) { |
| 10550 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_PEER_CLIENT |
| 10551 | "peer=" MACSTR " freq=%d go_dev_addr=" MACSTR |
| 10552 | " ssid=\"%s\"", |
| 10553 | MAC2STR(params.peer->p2p_device_addr), |
| 10554 | params.go_freq, |
| 10555 | MAC2STR(params.go_dev_addr), |
| 10556 | wpa_ssid_txt(params.go_ssid, |
| 10557 | params.go_ssid_len)); |
| 10558 | } else { |
| 10559 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_PEER_CLIENT |
| 10560 | "peer=" MACSTR " freq=%d", |
| 10561 | MAC2STR(params.peer->p2p_device_addr), |
| 10562 | params.go_freq); |
| 10563 | } |
| 10564 | return 0; |
| 10565 | } |
| 10566 | |
| 10567 | if (wpas_p2p_cli_freq(wpa_s, NULL, NULL)) { |
| 10568 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_WHILE_CLIENT "peer=" |
| 10569 | MACSTR, MAC2STR(params.peer->p2p_device_addr)); |
| 10570 | return 0; |
| 10571 | } |
| 10572 | |
| 10573 | wpabuf_free(wpa_s->p2p_oob_dev_pw); |
| 10574 | wpa_s->p2p_oob_dev_pw = NULL; |
| 10575 | |
| 10576 | if (params.oob_dev_pw_len < WPS_OOB_PUBKEY_HASH_LEN + 2) { |
| 10577 | wpa_printf(MSG_DEBUG, "P2P: No peer OOB Dev Pw " |
| 10578 | "received"); |
| 10579 | return -1; |
| 10580 | } |
| 10581 | |
| 10582 | id = WPA_GET_BE16(params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN); |
| 10583 | wpa_printf(MSG_DEBUG, "P2P: Peer OOB Dev Pw %u", id); |
| 10584 | wpa_hexdump(MSG_DEBUG, "P2P: Peer OOB Public Key hash", |
| 10585 | params.oob_dev_pw, WPS_OOB_PUBKEY_HASH_LEN); |
| 10586 | os_memcpy(wpa_s->p2p_peer_oob_pubkey_hash, |
| 10587 | params.oob_dev_pw, WPS_OOB_PUBKEY_HASH_LEN); |
| 10588 | wpa_s->p2p_peer_oob_pk_hash_known = 1; |
| 10589 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 10590 | wpa_s->p2p2 = false; |
| 10591 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 10592 | if (tag) { |
| 10593 | if (id < 0x10) { |
| 10594 | wpa_printf(MSG_DEBUG, "P2P: Static handover - invalid " |
| 10595 | "peer OOB Device Password Id %u", id); |
| 10596 | return -1; |
| 10597 | } |
| 10598 | wpa_printf(MSG_DEBUG, "P2P: Static handover - use peer OOB " |
| 10599 | "Device Password Id %u", id); |
| 10600 | wpa_hexdump_key(MSG_DEBUG, "P2P: Peer OOB Device Password", |
| 10601 | params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN + 2, |
| 10602 | params.oob_dev_pw_len - |
| 10603 | WPS_OOB_PUBKEY_HASH_LEN - 2); |
| 10604 | wpa_s->p2p_oob_dev_pw_id = id; |
| 10605 | wpa_s->p2p_oob_dev_pw = wpabuf_alloc_copy( |
| 10606 | params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN + 2, |
| 10607 | params.oob_dev_pw_len - |
| 10608 | WPS_OOB_PUBKEY_HASH_LEN - 2); |
| 10609 | if (wpa_s->p2p_oob_dev_pw == NULL) |
| 10610 | return -1; |
| 10611 | |
| 10612 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL && |
| 10613 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, |
| 10614 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) |
| 10615 | return -1; |
| 10616 | } else { |
| 10617 | wpa_printf(MSG_DEBUG, "P2P: Using abbreviated WPS handshake " |
| 10618 | "without Device Password"); |
| 10619 | wpa_s->p2p_oob_dev_pw_id = DEV_PW_NFC_CONNECTION_HANDOVER; |
| 10620 | } |
| 10621 | |
| 10622 | switch (params.next_step) { |
| 10623 | case NO_ACTION: |
| 10624 | case BOTH_GO: |
| 10625 | case PEER_CLIENT: |
| 10626 | /* already covered above */ |
| 10627 | return 0; |
| 10628 | case JOIN_GROUP: |
| 10629 | return wpas_p2p_nfc_join_group(wpa_s, ¶ms); |
| 10630 | case AUTH_JOIN: |
| 10631 | return wpas_p2p_nfc_auth_join(wpa_s, ¶ms, tag); |
| 10632 | case INIT_GO_NEG: |
| 10633 | return wpas_p2p_nfc_init_go_neg(wpa_s, ¶ms, forced_freq); |
| 10634 | case RESP_GO_NEG: |
| 10635 | /* TODO: use own OOB Dev Pw */ |
| 10636 | return wpas_p2p_nfc_resp_go_neg(wpa_s, ¶ms, forced_freq); |
| 10637 | } |
| 10638 | |
| 10639 | return -1; |
| 10640 | } |
| 10641 | |
| 10642 | |
| 10643 | int wpas_p2p_nfc_tag_process(struct wpa_supplicant *wpa_s, |
| 10644 | const struct wpabuf *data, int forced_freq) |
| 10645 | { |
| 10646 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 10647 | return -1; |
| 10648 | |
| 10649 | return wpas_p2p_nfc_connection_handover(wpa_s, data, 1, 1, forced_freq); |
| 10650 | } |
| 10651 | |
| 10652 | |
| 10653 | int wpas_p2p_nfc_report_handover(struct wpa_supplicant *wpa_s, int init, |
| 10654 | const struct wpabuf *req, |
| 10655 | const struct wpabuf *sel, int forced_freq) |
| 10656 | { |
| 10657 | struct wpabuf *tmp; |
| 10658 | int ret; |
| 10659 | |
| 10660 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 10661 | return -1; |
| 10662 | |
| 10663 | wpa_printf(MSG_DEBUG, "NFC: P2P connection handover reported"); |
| 10664 | |
| 10665 | wpa_hexdump_ascii(MSG_DEBUG, "NFC: Req", |
| 10666 | wpabuf_head(req), wpabuf_len(req)); |
| 10667 | wpa_hexdump_ascii(MSG_DEBUG, "NFC: Sel", |
| 10668 | wpabuf_head(sel), wpabuf_len(sel)); |
| 10669 | if (forced_freq) |
| 10670 | wpa_printf(MSG_DEBUG, "NFC: Forced freq %d", forced_freq); |
| 10671 | tmp = ndef_parse_p2p(init ? sel : req); |
| 10672 | if (tmp == NULL) { |
| 10673 | wpa_printf(MSG_DEBUG, "P2P: Could not parse NDEF"); |
| 10674 | return -1; |
| 10675 | } |
| 10676 | |
| 10677 | ret = wpas_p2p_nfc_connection_handover(wpa_s, tmp, init, 0, |
| 10678 | forced_freq); |
| 10679 | wpabuf_free(tmp); |
| 10680 | |
| 10681 | return ret; |
| 10682 | } |
| 10683 | |
| 10684 | |
| 10685 | int wpas_p2p_nfc_tag_enabled(struct wpa_supplicant *wpa_s, int enabled) |
| 10686 | { |
| 10687 | const u8 *if_addr; |
| 10688 | int go_intent = wpa_s->conf->p2p_go_intent; |
| 10689 | struct wpa_supplicant *iface; |
| 10690 | |
| 10691 | if (wpa_s->global->p2p == NULL) |
| 10692 | return -1; |
| 10693 | |
| 10694 | if (!enabled) { |
| 10695 | wpa_printf(MSG_DEBUG, "P2P: Disable use of own NFC Tag"); |
| 10696 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) |
| 10697 | { |
| 10698 | if (!iface->ap_iface) |
| 10699 | continue; |
| 10700 | hostapd_wps_nfc_token_disable(iface->ap_iface->bss[0]); |
| 10701 | } |
| 10702 | p2p_set_authorized_oob_dev_pw_id(wpa_s->global->p2p, 0, |
| 10703 | 0, NULL); |
| 10704 | if (wpa_s->p2p_nfc_tag_enabled) |
| 10705 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 10706 | wpa_s->p2p_nfc_tag_enabled = 0; |
| 10707 | return 0; |
| 10708 | } |
| 10709 | |
| 10710 | if (wpa_s->global->p2p_disabled) |
| 10711 | return -1; |
| 10712 | |
| 10713 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL || |
| 10714 | wpa_s->conf->wps_nfc_dh_privkey == NULL || |
| 10715 | wpa_s->conf->wps_nfc_dev_pw == NULL || |
| 10716 | wpa_s->conf->wps_nfc_dev_pw_id < 0x10) { |
| 10717 | wpa_printf(MSG_DEBUG, "P2P: NFC password token not configured " |
| 10718 | "to allow static handover cases"); |
| 10719 | return -1; |
| 10720 | } |
| 10721 | |
| 10722 | wpa_printf(MSG_DEBUG, "P2P: Enable use of own NFC Tag"); |
| 10723 | |
| 10724 | wpa_s->p2p_oob_dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id; |
| 10725 | wpabuf_free(wpa_s->p2p_oob_dev_pw); |
| 10726 | wpa_s->p2p_oob_dev_pw = wpabuf_dup(wpa_s->conf->wps_nfc_dev_pw); |
| 10727 | if (wpa_s->p2p_oob_dev_pw == NULL) |
| 10728 | return -1; |
| 10729 | wpa_s->p2p_peer_oob_pk_hash_known = 0; |
| 10730 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 10731 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO || |
| 10732 | wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT) { |
| 10733 | /* |
| 10734 | * P2P Group Interface present and the command came on group |
| 10735 | * interface, so enable the token for the current interface. |
| 10736 | */ |
| 10737 | wpa_s->create_p2p_iface = 0; |
| 10738 | } else { |
| 10739 | wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s); |
| 10740 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 10741 | |
| 10742 | if (wpa_s->create_p2p_iface) { |
| 10743 | enum wpa_driver_if_type iftype; |
| 10744 | /* Prepare to add a new interface for the group */ |
| 10745 | iftype = WPA_IF_P2P_GROUP; |
| 10746 | if (go_intent == 15) |
| 10747 | iftype = WPA_IF_P2P_GO; |
| 10748 | if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) { |
| 10749 | wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " |
| 10750 | "interface for the group"); |
| 10751 | return -1; |
| 10752 | } |
| 10753 | |
| 10754 | if_addr = wpa_s->pending_interface_addr; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 10755 | } else if (wpa_s->p2p_mgmt) |
| 10756 | if_addr = wpa_s->parent->own_addr; |
| 10757 | else |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 10758 | if_addr = wpa_s->own_addr; |
| 10759 | |
| 10760 | wpa_s->p2p_nfc_tag_enabled = enabled; |
| 10761 | |
| 10762 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 10763 | struct hostapd_data *hapd; |
| 10764 | if (iface->ap_iface == NULL) |
| 10765 | continue; |
| 10766 | hapd = iface->ap_iface->bss[0]; |
| 10767 | wpabuf_free(hapd->conf->wps_nfc_dh_pubkey); |
| 10768 | hapd->conf->wps_nfc_dh_pubkey = |
| 10769 | wpabuf_dup(wpa_s->conf->wps_nfc_dh_pubkey); |
| 10770 | wpabuf_free(hapd->conf->wps_nfc_dh_privkey); |
| 10771 | hapd->conf->wps_nfc_dh_privkey = |
| 10772 | wpabuf_dup(wpa_s->conf->wps_nfc_dh_privkey); |
| 10773 | wpabuf_free(hapd->conf->wps_nfc_dev_pw); |
| 10774 | hapd->conf->wps_nfc_dev_pw = |
| 10775 | wpabuf_dup(wpa_s->conf->wps_nfc_dev_pw); |
| 10776 | hapd->conf->wps_nfc_dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id; |
| 10777 | |
| 10778 | if (hostapd_wps_nfc_token_enable(iface->ap_iface->bss[0]) < 0) { |
| 10779 | wpa_dbg(iface, MSG_DEBUG, |
| 10780 | "P2P: Failed to enable NFC Tag for GO"); |
| 10781 | } |
| 10782 | } |
| 10783 | p2p_set_authorized_oob_dev_pw_id( |
| 10784 | wpa_s->global->p2p, wpa_s->conf->wps_nfc_dev_pw_id, go_intent, |
| 10785 | if_addr); |
| 10786 | |
| 10787 | return 0; |
| 10788 | } |
| 10789 | |
| 10790 | #endif /* CONFIG_WPS_NFC */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10791 | |
| 10792 | |
| 10793 | static void wpas_p2p_optimize_listen_channel(struct wpa_supplicant *wpa_s, |
| 10794 | struct wpa_used_freq_data *freqs, |
| 10795 | unsigned int num) |
| 10796 | { |
| 10797 | u8 curr_chan, cand, chan; |
| 10798 | unsigned int i; |
| 10799 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10800 | /* |
| 10801 | * If possible, optimize the Listen channel to be a channel that is |
| 10802 | * already used by one of the other interfaces. |
| 10803 | */ |
| 10804 | if (!wpa_s->conf->p2p_optimize_listen_chan) |
| 10805 | return; |
| 10806 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10807 | curr_chan = p2p_get_listen_channel(wpa_s->global->p2p); |
| 10808 | for (i = 0, cand = 0; i < num; i++) { |
| 10809 | ieee80211_freq_to_chan(freqs[i].freq, &chan); |
| 10810 | if (curr_chan == chan) { |
| 10811 | cand = 0; |
| 10812 | break; |
| 10813 | } |
| 10814 | |
| 10815 | if (chan == 1 || chan == 6 || chan == 11) |
| 10816 | cand = chan; |
| 10817 | } |
| 10818 | |
| 10819 | if (cand) { |
| 10820 | wpa_dbg(wpa_s, MSG_DEBUG, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 10821 | "P2P: Update Listen channel to %u based on operating channel", |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10822 | cand); |
| 10823 | p2p_set_listen_channel(wpa_s->global->p2p, 81, cand, 0); |
| 10824 | } |
| 10825 | } |
| 10826 | |
| 10827 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10828 | static int wpas_p2p_move_go_csa(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10829 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10830 | struct hostapd_config *conf; |
| 10831 | struct p2p_go_neg_results params; |
| 10832 | struct csa_settings csa_settings; |
| 10833 | struct wpa_ssid *current_ssid = wpa_s->current_ssid; |
| 10834 | int old_freq = current_ssid->frequency; |
| 10835 | int ret; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10836 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10837 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
| 10838 | wpa_dbg(wpa_s, MSG_DEBUG, "CSA is not enabled"); |
| 10839 | return -1; |
| 10840 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10841 | |
| 10842 | /* |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10843 | * TODO: This function may not always work correctly. For example, |
| 10844 | * 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] | 10845 | */ |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 10846 | if (wpas_p2p_init_go_params(wpa_s, ¶ms, 0, 0, 0, 0, 0, 0, 0, |
| 10847 | NULL)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10848 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10849 | "P2P CSA: Failed to select new frequency for GO"); |
| 10850 | return -1; |
| 10851 | } |
| 10852 | |
| 10853 | if (current_ssid->frequency == params.freq) { |
| 10854 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10855 | "P2P CSA: Selected same frequency - not moving GO"); |
| 10856 | return 0; |
| 10857 | } |
| 10858 | |
| 10859 | conf = hostapd_config_defaults(); |
| 10860 | if (!conf) { |
| 10861 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10862 | "P2P CSA: Failed to allocate default config"); |
| 10863 | return -1; |
| 10864 | } |
| 10865 | |
| 10866 | current_ssid->frequency = params.freq; |
| 10867 | if (wpa_supplicant_conf_ap_ht(wpa_s, current_ssid, conf)) { |
| 10868 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10869 | "P2P CSA: Failed to create new GO config"); |
| 10870 | ret = -1; |
| 10871 | goto out; |
| 10872 | } |
| 10873 | |
Sunil | 4a3f9f5 | 2022-07-19 22:04:39 +0000 | [diff] [blame] | 10874 | if (conf->hw_mode != wpa_s->ap_iface->current_mode->mode && |
| 10875 | (wpa_s->ap_iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A || |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 10876 | is_6ghz_freq(wpa_s->ap_iface->freq) || |
Sunil | 4a3f9f5 | 2022-07-19 22:04:39 +0000 | [diff] [blame] | 10877 | conf->hw_mode != HOSTAPD_MODE_IEEE80211G)) { |
| 10878 | wpa_dbg(wpa_s, MSG_INFO, |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 10879 | "P2P CSA: CSA from hardware mode %d%s to %d is not supported", |
| 10880 | wpa_s->ap_iface->current_mode->mode, |
| 10881 | is_6ghz_freq(wpa_s->ap_iface->freq) ? " (6 GHz)" : "", |
| 10882 | conf->hw_mode); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10883 | ret = -1; |
| 10884 | goto out; |
| 10885 | } |
| 10886 | |
| 10887 | os_memset(&csa_settings, 0, sizeof(csa_settings)); |
| 10888 | csa_settings.cs_count = P2P_GO_CSA_COUNT; |
| 10889 | csa_settings.block_tx = P2P_GO_CSA_BLOCK_TX; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 10890 | csa_settings.link_id = -1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10891 | csa_settings.freq_params.freq = params.freq; |
| 10892 | csa_settings.freq_params.sec_channel_offset = conf->secondary_channel; |
| 10893 | csa_settings.freq_params.ht_enabled = conf->ieee80211n; |
| 10894 | csa_settings.freq_params.bandwidth = conf->secondary_channel ? 40 : 20; |
| 10895 | |
| 10896 | if (conf->ieee80211ac) { |
| 10897 | int freq1 = 0, freq2 = 0; |
| 10898 | u8 chan, opclass; |
| 10899 | |
| 10900 | if (ieee80211_freq_to_channel_ext(params.freq, |
| 10901 | conf->secondary_channel, |
| 10902 | conf->vht_oper_chwidth, |
| 10903 | &opclass, &chan) == |
| 10904 | NUM_HOSTAPD_MODES) { |
| 10905 | wpa_printf(MSG_ERROR, "P2P CSA: Bad freq"); |
| 10906 | ret = -1; |
| 10907 | goto out; |
| 10908 | } |
| 10909 | |
| 10910 | if (conf->vht_oper_centr_freq_seg0_idx) |
| 10911 | freq1 = ieee80211_chan_to_freq( |
| 10912 | NULL, opclass, |
| 10913 | conf->vht_oper_centr_freq_seg0_idx); |
| 10914 | |
| 10915 | if (conf->vht_oper_centr_freq_seg1_idx) |
| 10916 | freq2 = ieee80211_chan_to_freq( |
| 10917 | NULL, opclass, |
| 10918 | conf->vht_oper_centr_freq_seg1_idx); |
| 10919 | |
| 10920 | if (freq1 < 0 || freq2 < 0) { |
| 10921 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 10922 | "P2P CSA: Selected invalid VHT center freqs"); |
| 10923 | ret = -1; |
| 10924 | goto out; |
| 10925 | } |
| 10926 | |
| 10927 | csa_settings.freq_params.vht_enabled = conf->ieee80211ac; |
| 10928 | csa_settings.freq_params.center_freq1 = freq1; |
| 10929 | csa_settings.freq_params.center_freq2 = freq2; |
| 10930 | |
| 10931 | switch (conf->vht_oper_chwidth) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 10932 | case CONF_OPER_CHWIDTH_80MHZ: |
| 10933 | case CONF_OPER_CHWIDTH_80P80MHZ: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10934 | csa_settings.freq_params.bandwidth = 80; |
| 10935 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 10936 | case CONF_OPER_CHWIDTH_160MHZ: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10937 | csa_settings.freq_params.bandwidth = 160; |
| 10938 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 10939 | default: |
| 10940 | break; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10941 | } |
| 10942 | } |
| 10943 | |
| 10944 | ret = ap_switch_channel(wpa_s, &csa_settings); |
| 10945 | out: |
| 10946 | current_ssid->frequency = old_freq; |
| 10947 | hostapd_config_free(conf); |
| 10948 | return ret; |
| 10949 | } |
| 10950 | |
| 10951 | |
| 10952 | static void wpas_p2p_move_go_no_csa(struct wpa_supplicant *wpa_s) |
| 10953 | { |
| 10954 | struct p2p_go_neg_results params; |
| 10955 | struct wpa_ssid *current_ssid = wpa_s->current_ssid; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10956 | void (*ap_configured_cb)(void *ctx, void *data); |
| 10957 | void *ap_configured_cb_ctx, *ap_configured_cb_data; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10958 | |
| 10959 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP); |
| 10960 | |
| 10961 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Move GO from freq=%d MHz", |
| 10962 | current_ssid->frequency); |
| 10963 | |
| 10964 | /* Stop the AP functionality */ |
| 10965 | /* TODO: Should do this in a way that does not indicated to possible |
| 10966 | * P2P Clients in the group that the group is terminated. */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10967 | /* If this action occurs before a group is started, the callback should |
| 10968 | * be preserved, or GROUP-STARTED event would be lost. If this action |
| 10969 | * occurs after a group is started, these pointers are all NULL and |
| 10970 | * harmless. */ |
| 10971 | ap_configured_cb = wpa_s->ap_configured_cb; |
| 10972 | ap_configured_cb_ctx = wpa_s->ap_configured_cb_ctx; |
| 10973 | ap_configured_cb_data = wpa_s->ap_configured_cb_data; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10974 | wpa_supplicant_ap_deinit(wpa_s); |
| 10975 | |
| 10976 | /* Reselect the GO frequency */ |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 10977 | if (wpas_p2p_init_go_params(wpa_s, ¶ms, 0, 0, 0, 0, 0, 0, 0, |
| 10978 | NULL)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10979 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Failed to reselect freq"); |
| 10980 | wpas_p2p_group_delete(wpa_s, |
| 10981 | P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL); |
| 10982 | return; |
| 10983 | } |
| 10984 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New freq selected for the GO (%u MHz)", |
| 10985 | params.freq); |
| 10986 | |
| 10987 | if (params.freq && |
| 10988 | !p2p_supported_freq_go(wpa_s->global->p2p, params.freq)) { |
| 10989 | wpa_printf(MSG_DEBUG, |
| 10990 | "P2P: Selected freq (%u MHz) is not valid for P2P", |
| 10991 | params.freq); |
| 10992 | wpas_p2p_group_delete(wpa_s, |
| 10993 | P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL); |
| 10994 | return; |
| 10995 | } |
| 10996 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10997 | /* Restore preserved callback parameters */ |
Jimmy Chen | 4b2a502 | 2020-08-26 18:55:45 +0800 | [diff] [blame] | 10998 | wpa_s->ap_configured_cb = ap_configured_cb; |
| 10999 | wpa_s->ap_configured_cb_ctx = ap_configured_cb_ctx; |
| 11000 | wpa_s->ap_configured_cb_data = ap_configured_cb_data; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11001 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11002 | /* Update the frequency */ |
| 11003 | current_ssid->frequency = params.freq; |
| 11004 | wpa_s->connect_without_scan = current_ssid; |
| 11005 | wpa_s->reassociate = 1; |
| 11006 | wpa_s->disconnected = 0; |
| 11007 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 11008 | } |
| 11009 | |
| 11010 | |
| 11011 | static void wpas_p2p_move_go(void *eloop_ctx, void *timeout_ctx) |
| 11012 | { |
| 11013 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 11014 | |
| 11015 | if (!wpa_s->ap_iface || !wpa_s->current_ssid) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 11016 | return; |
| 11017 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11018 | wpas_p2p_go_update_common_freqs(wpa_s); |
| 11019 | |
| 11020 | /* Do not move GO in the middle of a CSA */ |
| 11021 | if (hostapd_csa_in_progress(wpa_s->ap_iface)) { |
| 11022 | wpa_printf(MSG_DEBUG, |
| 11023 | "P2P: CSA is in progress - not moving GO"); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 11024 | return; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11025 | } |
| 11026 | |
| 11027 | /* |
| 11028 | * First, try a channel switch flow. If it is not supported or fails, |
| 11029 | * take down the GO and bring it up again. |
| 11030 | */ |
| 11031 | if (wpas_p2p_move_go_csa(wpa_s) < 0) |
| 11032 | wpas_p2p_move_go_no_csa(wpa_s); |
| 11033 | } |
| 11034 | |
| 11035 | |
| 11036 | static void wpas_p2p_reconsider_moving_go(void *eloop_ctx, void *timeout_ctx) |
| 11037 | { |
| 11038 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 11039 | struct wpa_used_freq_data *freqs = NULL; |
| 11040 | unsigned int num = wpa_s->num_multichan_concurrent; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 11041 | |
| 11042 | freqs = os_calloc(num, sizeof(struct wpa_used_freq_data)); |
| 11043 | if (!freqs) |
| 11044 | return; |
| 11045 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 11046 | num = get_shared_radio_freqs_data(wpa_s, freqs, num, false); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 11047 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11048 | /* Previous attempt to move a GO was not possible -- try again. */ |
| 11049 | wpas_p2p_consider_moving_gos(wpa_s, freqs, num, |
| 11050 | WPAS_P2P_CHANNEL_UPDATE_ANY); |
| 11051 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 11052 | os_free(freqs); |
| 11053 | } |
| 11054 | |
| 11055 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11056 | /* |
| 11057 | * Consider moving a GO from its currently used frequency: |
| 11058 | * 1. It is possible that due to regulatory consideration the frequency |
| 11059 | * can no longer be used and there is a need to evacuate the GO. |
| 11060 | * 2. It is possible that due to MCC considerations, it would be preferable |
| 11061 | * to move the GO to a channel that is currently used by some other |
| 11062 | * station interface. |
| 11063 | * |
| 11064 | * In case a frequency that became invalid is once again valid, cancel a |
| 11065 | * previously initiated GO frequency change. |
| 11066 | */ |
| 11067 | static void wpas_p2p_consider_moving_one_go(struct wpa_supplicant *wpa_s, |
| 11068 | struct wpa_used_freq_data *freqs, |
| 11069 | unsigned int num) |
| 11070 | { |
| 11071 | unsigned int i, invalid_freq = 0, policy_move = 0, flags = 0; |
| 11072 | unsigned int timeout; |
| 11073 | int freq; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11074 | int dfs_offload; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11075 | |
| 11076 | wpas_p2p_go_update_common_freqs(wpa_s); |
| 11077 | |
| 11078 | freq = wpa_s->current_ssid->frequency; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11079 | dfs_offload = (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11080 | 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] | 11081 | for (i = 0, invalid_freq = 0; i < num; i++) { |
| 11082 | if (freqs[i].freq == freq) { |
| 11083 | flags = freqs[i].flags; |
| 11084 | |
| 11085 | /* The channel is invalid, must change it */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11086 | if (!p2p_supported_freq_go(wpa_s->global->p2p, freq) && |
| 11087 | !dfs_offload) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11088 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 11089 | "P2P: Freq=%d MHz no longer valid for GO", |
| 11090 | freq); |
| 11091 | invalid_freq = 1; |
| 11092 | } |
| 11093 | } else if (freqs[i].flags == 0) { |
| 11094 | /* Freq is not used by any other station interface */ |
| 11095 | continue; |
| 11096 | } else if (!p2p_supported_freq(wpa_s->global->p2p, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11097 | freqs[i].freq) && !dfs_offload) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11098 | /* Freq is not valid for P2P use cases */ |
| 11099 | continue; |
| 11100 | } else if (wpa_s->conf->p2p_go_freq_change_policy == |
| 11101 | P2P_GO_FREQ_MOVE_SCM) { |
| 11102 | policy_move = 1; |
| 11103 | } else if (wpa_s->conf->p2p_go_freq_change_policy == |
| 11104 | P2P_GO_FREQ_MOVE_SCM_PEER_SUPPORTS && |
| 11105 | wpas_p2p_go_is_peer_freq(wpa_s, freqs[i].freq)) { |
| 11106 | policy_move = 1; |
| 11107 | } else if ((wpa_s->conf->p2p_go_freq_change_policy == |
| 11108 | P2P_GO_FREQ_MOVE_SCM_ECSA) && |
| 11109 | wpas_p2p_go_is_peer_freq(wpa_s, freqs[i].freq)) { |
| 11110 | if (!p2p_get_group_num_members(wpa_s->p2p_group)) { |
| 11111 | policy_move = 1; |
| 11112 | } else if ((wpa_s->drv_flags & |
| 11113 | WPA_DRIVER_FLAGS_AP_CSA) && |
| 11114 | wpas_p2p_go_clients_support_ecsa(wpa_s)) { |
| 11115 | u8 chan; |
| 11116 | |
| 11117 | /* |
| 11118 | * We do not support CSA between bands, so move |
| 11119 | * GO only within the same band. |
| 11120 | */ |
| 11121 | if (wpa_s->ap_iface->current_mode->mode == |
| 11122 | ieee80211_freq_to_chan(freqs[i].freq, |
| 11123 | &chan)) |
| 11124 | policy_move = 1; |
| 11125 | } |
| 11126 | } |
| 11127 | } |
| 11128 | |
| 11129 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 11130 | "P2P: GO move: invalid_freq=%u, policy_move=%u, flags=0x%X", |
| 11131 | invalid_freq, policy_move, flags); |
| 11132 | |
| 11133 | /* |
| 11134 | * The channel is valid, or we are going to have a policy move, so |
| 11135 | * cancel timeout. |
| 11136 | */ |
| 11137 | if (!invalid_freq || policy_move) { |
| 11138 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 11139 | "P2P: Cancel a GO move from freq=%d MHz", freq); |
| 11140 | eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL); |
| 11141 | |
| 11142 | if (wpas_p2p_in_progress(wpa_s)) { |
| 11143 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 11144 | "P2P: GO move: policy CS is not allowed - setting timeout to re-consider GO move"); |
| 11145 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, |
| 11146 | wpa_s, NULL); |
| 11147 | eloop_register_timeout(P2P_RECONSIDER_GO_MOVE_DELAY, 0, |
| 11148 | wpas_p2p_reconsider_moving_go, |
| 11149 | wpa_s, NULL); |
| 11150 | return; |
| 11151 | } |
| 11152 | } |
| 11153 | |
| 11154 | if (!invalid_freq && (!policy_move || flags != 0)) { |
| 11155 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 11156 | "P2P: Not initiating a GO frequency change"); |
| 11157 | return; |
| 11158 | } |
| 11159 | |
| 11160 | /* |
| 11161 | * Do not consider moving GO if it is in the middle of a CSA. When the |
| 11162 | * CSA is finished this flow should be retriggered. |
| 11163 | */ |
| 11164 | if (hostapd_csa_in_progress(wpa_s->ap_iface)) { |
| 11165 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 11166 | "P2P: Not initiating a GO frequency change - CSA is in progress"); |
| 11167 | return; |
| 11168 | } |
| 11169 | |
| 11170 | if (invalid_freq && !wpas_p2p_disallowed_freq(wpa_s->global, freq)) |
| 11171 | timeout = P2P_GO_FREQ_CHANGE_TIME; |
| 11172 | else |
| 11173 | timeout = 0; |
| 11174 | |
| 11175 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Move GO from freq=%d MHz in %d secs", |
| 11176 | freq, timeout); |
| 11177 | eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL); |
| 11178 | eloop_register_timeout(timeout, 0, wpas_p2p_move_go, wpa_s, NULL); |
| 11179 | } |
| 11180 | |
| 11181 | |
| 11182 | static void wpas_p2p_consider_moving_gos(struct wpa_supplicant *wpa_s, |
| 11183 | struct wpa_used_freq_data *freqs, |
| 11184 | unsigned int num, |
| 11185 | enum wpas_p2p_channel_update_trig trig) |
| 11186 | { |
| 11187 | struct wpa_supplicant *ifs; |
| 11188 | |
| 11189 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, ELOOP_ALL_CTX, |
| 11190 | NULL); |
| 11191 | |
| 11192 | /* |
| 11193 | * Travers all the radio interfaces, and for each GO interface, check |
| 11194 | * if there is a need to move the GO from the frequency it is using, |
| 11195 | * or in case the frequency is valid again, cancel the evacuation flow. |
| 11196 | */ |
| 11197 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 11198 | radio_list) { |
| 11199 | if (ifs->current_ssid == NULL || |
| 11200 | ifs->current_ssid->mode != WPAS_MODE_P2P_GO) |
| 11201 | continue; |
| 11202 | |
| 11203 | /* |
| 11204 | * The GO was just started or completed channel switch, no need |
| 11205 | * to move it. |
| 11206 | */ |
| 11207 | if (wpa_s == ifs && |
| 11208 | (trig == WPAS_P2P_CHANNEL_UPDATE_STATE_CHANGE || |
| 11209 | trig == WPAS_P2P_CHANNEL_UPDATE_CS)) { |
| 11210 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 11211 | "P2P: GO move - schedule re-consideration"); |
| 11212 | eloop_register_timeout(P2P_RECONSIDER_GO_MOVE_DELAY, 0, |
| 11213 | wpas_p2p_reconsider_moving_go, |
| 11214 | wpa_s, NULL); |
| 11215 | continue; |
| 11216 | } |
| 11217 | |
| 11218 | wpas_p2p_consider_moving_one_go(ifs, freqs, num); |
| 11219 | } |
| 11220 | } |
| 11221 | |
| 11222 | |
| 11223 | void wpas_p2p_indicate_state_change(struct wpa_supplicant *wpa_s) |
| 11224 | { |
| 11225 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 11226 | return; |
| 11227 | |
| 11228 | wpas_p2p_update_channel_list(wpa_s, |
| 11229 | WPAS_P2P_CHANNEL_UPDATE_STATE_CHANGE); |
| 11230 | } |
| 11231 | |
| 11232 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 11233 | void wpas_p2p_deinit_iface(struct wpa_supplicant *wpa_s) |
| 11234 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 11235 | if (wpa_s == wpa_s->global->p2p_init_wpa_s && wpa_s->global->p2p) { |
| 11236 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disable P2P since removing " |
| 11237 | "the management interface is being removed"); |
| 11238 | wpas_p2p_deinit_global(wpa_s->global); |
| 11239 | } |
| 11240 | } |
| 11241 | |
| 11242 | |
| 11243 | void wpas_p2p_ap_deinit(struct wpa_supplicant *wpa_s) |
| 11244 | { |
| 11245 | if (wpa_s->ap_iface->bss) |
| 11246 | wpa_s->ap_iface->bss[0]->p2p_group = NULL; |
| 11247 | wpas_p2p_group_deinit(wpa_s); |
| 11248 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11249 | |
| 11250 | |
| 11251 | int wpas_p2p_lo_start(struct wpa_supplicant *wpa_s, unsigned int freq, |
| 11252 | unsigned int period, unsigned int interval, |
| 11253 | unsigned int count) |
| 11254 | { |
| 11255 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 11256 | u8 *device_types; |
| 11257 | size_t dev_types_len; |
| 11258 | struct wpabuf *buf; |
| 11259 | int ret; |
| 11260 | |
| 11261 | if (wpa_s->p2p_lo_started) { |
| 11262 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 11263 | "P2P Listen offload is already started"); |
| 11264 | return 0; |
| 11265 | } |
| 11266 | |
| 11267 | if (wpa_s->global->p2p == NULL || |
| 11268 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) { |
| 11269 | wpa_printf(MSG_DEBUG, "P2P: Listen offload not supported"); |
| 11270 | return -1; |
| 11271 | } |
| 11272 | |
| 11273 | if (!p2p_supported_freq(wpa_s->global->p2p, freq)) { |
| 11274 | wpa_printf(MSG_ERROR, "P2P: Input channel not supported: %u", |
| 11275 | freq); |
| 11276 | return -1; |
| 11277 | } |
| 11278 | |
| 11279 | /* Get device type */ |
| 11280 | dev_types_len = (wpa_s->conf->num_sec_device_types + 1) * |
| 11281 | WPS_DEV_TYPE_LEN; |
| 11282 | device_types = os_malloc(dev_types_len); |
| 11283 | if (!device_types) |
| 11284 | return -1; |
| 11285 | os_memcpy(device_types, wpa_s->conf->device_type, WPS_DEV_TYPE_LEN); |
| 11286 | os_memcpy(&device_types[WPS_DEV_TYPE_LEN], wpa_s->conf->sec_device_type, |
| 11287 | wpa_s->conf->num_sec_device_types * WPS_DEV_TYPE_LEN); |
| 11288 | |
| 11289 | /* Get Probe Response IE(s) */ |
| 11290 | buf = p2p_build_probe_resp_template(p2p, freq); |
| 11291 | if (!buf) { |
| 11292 | os_free(device_types); |
| 11293 | return -1; |
| 11294 | } |
| 11295 | |
| 11296 | ret = wpa_drv_p2p_lo_start(wpa_s, freq, period, interval, count, |
| 11297 | device_types, dev_types_len, |
| 11298 | wpabuf_mhead_u8(buf), wpabuf_len(buf)); |
| 11299 | if (ret < 0) |
| 11300 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 11301 | "P2P: Failed to start P2P listen offload"); |
| 11302 | |
| 11303 | os_free(device_types); |
| 11304 | wpabuf_free(buf); |
| 11305 | |
| 11306 | if (ret == 0) { |
| 11307 | wpa_s->p2p_lo_started = 1; |
| 11308 | |
| 11309 | /* Stop current P2P listen if any */ |
| 11310 | wpas_stop_listen(wpa_s); |
| 11311 | } |
| 11312 | |
| 11313 | return ret; |
| 11314 | } |
| 11315 | |
| 11316 | |
| 11317 | int wpas_p2p_lo_stop(struct wpa_supplicant *wpa_s) |
| 11318 | { |
| 11319 | int ret; |
| 11320 | |
| 11321 | if (!wpa_s->p2p_lo_started) |
| 11322 | return 0; |
| 11323 | |
| 11324 | ret = wpa_drv_p2p_lo_stop(wpa_s); |
| 11325 | if (ret < 0) |
| 11326 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 11327 | "P2P: Failed to stop P2P listen offload"); |
| 11328 | |
| 11329 | wpa_s->p2p_lo_started = 0; |
| 11330 | return ret; |
| 11331 | } |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 11332 | |
| 11333 | |
| 11334 | struct wpabuf * wpas_p2p_usd_elems(struct wpa_supplicant *wpa_s) |
| 11335 | { |
| 11336 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 11337 | |
| 11338 | if (wpa_s->global->p2p_disabled || !p2p) |
| 11339 | return NULL; |
| 11340 | return p2p_usd_elems(p2p); |
| 11341 | } |
| 11342 | |
| 11343 | |
| 11344 | void wpas_p2p_process_usd_elems(struct wpa_supplicant *wpa_s, const u8 *buf, |
| 11345 | u16 buf_len, const u8 *peer_addr, |
| 11346 | unsigned int freq) |
| 11347 | { |
| 11348 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 11349 | |
| 11350 | if (wpa_s->global->p2p_disabled || !p2p) |
| 11351 | return; |
| 11352 | p2p_process_usd_elems(p2p, buf, buf_len, peer_addr, freq); |
| 11353 | } |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame^] | 11354 | |
| 11355 | |
| 11356 | #ifdef CONFIG_PASN |
| 11357 | |
| 11358 | int wpas_p2p_pasn_auth_rx(struct wpa_supplicant *wpa_s, |
| 11359 | const struct ieee80211_mgmt *mgmt, size_t len, |
| 11360 | int freq) |
| 11361 | { |
| 11362 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 11363 | |
| 11364 | if (wpa_s->global->p2p_disabled || !p2p) |
| 11365 | return -2; |
| 11366 | return p2p_pasn_auth_rx(p2p, mgmt, len, freq); |
| 11367 | } |
| 11368 | |
| 11369 | |
| 11370 | int wpas_p2p_pasn_auth_tx_status(struct wpa_supplicant *wpa_s, const u8 *data, |
| 11371 | size_t data_len, bool acked) |
| 11372 | { |
| 11373 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 11374 | struct wpa_p2p_pasn_auth_work *awork; |
| 11375 | |
| 11376 | if (!wpa_s->p2p_pasn_auth_work) |
| 11377 | return -1; |
| 11378 | awork = wpa_s->p2p_pasn_auth_work->ctx; |
| 11379 | |
| 11380 | return p2p_pasn_auth_tx_status(p2p, data, data_len, acked, |
| 11381 | awork->verify); |
| 11382 | } |
| 11383 | |
| 11384 | |
| 11385 | #ifdef CONFIG_TESTING_OPTIONS |
| 11386 | int wpas_p2p_get_pasn_ptk(struct wpa_supplicant *wpa_s, const u8 **ptk, |
| 11387 | size_t *ptk_len) |
| 11388 | { |
| 11389 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 11390 | |
| 11391 | if (wpa_s->global->p2p_disabled || !p2p) |
| 11392 | return -2; |
| 11393 | return p2p_pasn_get_ptk(p2p, ptk, ptk_len); |
| 11394 | } |
| 11395 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 11396 | |
| 11397 | #endif /* CONFIG_PASN */ |
| 11398 | |
| 11399 | |
| 11400 | void wpas_p2p_update_dev_addr(struct wpa_supplicant *wpa_s) |
| 11401 | { |
| 11402 | os_memcpy(wpa_s->global->p2p_dev_addr, wpa_s->own_addr, ETH_ALEN); |
| 11403 | p2p_set_dev_addr(wpa_s->global->p2p, wpa_s->own_addr); |
| 11404 | } |