Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * wpa_supplicant - P2P |
| 3 | * Copyright (c) 2009-2010, Atheros Communications |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4 | * Copyright (c) 2010-2014, Jouni Malinen <j@w1.fi> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6 | * This software may be distributed under the terms of the BSD license. |
| 7 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include "includes.h" |
| 11 | |
| 12 | #include "common.h" |
| 13 | #include "eloop.h" |
| 14 | #include "common/ieee802_11_common.h" |
| 15 | #include "common/ieee802_11_defs.h" |
| 16 | #include "common/wpa_ctrl.h" |
| 17 | #include "wps/wps_i.h" |
| 18 | #include "p2p/p2p.h" |
| 19 | #include "ap/hostapd.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 20 | #include "ap/ap_config.h" |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 21 | #include "ap/sta_info.h" |
| 22 | #include "ap/ap_drv_ops.h" |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 23 | #include "ap/wps_hostapd.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 24 | #include "ap/p2p_hostapd.h" |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 25 | #include "ap/dfs.h" |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 26 | #include "eapol_supp/eapol_supp_sm.h" |
| 27 | #include "rsn_supp/wpa.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 28 | #include "wpa_supplicant_i.h" |
| 29 | #include "driver_i.h" |
| 30 | #include "ap.h" |
| 31 | #include "config_ssid.h" |
| 32 | #include "config.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 33 | #include "notify.h" |
| 34 | #include "scan.h" |
| 35 | #include "bss.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 36 | #include "offchannel.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 37 | #include "wps_supplicant.h" |
| 38 | #include "p2p_supplicant.h" |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 39 | #include "wifi_display.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 40 | |
| 41 | |
| 42 | /* |
| 43 | * How many times to try to scan to find the GO before giving up on join |
| 44 | * request. |
| 45 | */ |
| 46 | #define P2P_MAX_JOIN_SCAN_ATTEMPTS 10 |
| 47 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 48 | #define P2P_AUTO_PD_SCAN_ATTEMPTS 5 |
| 49 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 50 | /** |
| 51 | * Defines time interval in seconds when a GO needs to evacuate a frequency that |
| 52 | * it is currently using, but is no longer valid for P2P use cases. |
| 53 | */ |
| 54 | #define P2P_GO_FREQ_CHANGE_TIME 5 |
| 55 | |
| 56 | /** |
| 57 | * Defines CSA parameters which are used when GO evacuates the no longer valid |
| 58 | * channel (and if the driver supports channel switch). |
| 59 | */ |
| 60 | #define P2P_GO_CSA_COUNT 7 |
| 61 | #define P2P_GO_CSA_BLOCK_TX 0 |
| 62 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 63 | #ifndef P2P_MAX_CLIENT_IDLE |
| 64 | /* |
| 65 | * How many seconds to try to reconnect to the GO when connection in P2P client |
| 66 | * role has been lost. |
| 67 | */ |
| 68 | #define P2P_MAX_CLIENT_IDLE 10 |
| 69 | #endif /* P2P_MAX_CLIENT_IDLE */ |
| 70 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 71 | #ifndef P2P_MAX_INITIAL_CONN_WAIT |
| 72 | /* |
| 73 | * How many seconds to wait for initial 4-way handshake to get completed after |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 74 | * WPS provisioning step or after the re-invocation of a persistent group on a |
| 75 | * P2P Client. |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 76 | */ |
| 77 | #define P2P_MAX_INITIAL_CONN_WAIT 10 |
| 78 | #endif /* P2P_MAX_INITIAL_CONN_WAIT */ |
| 79 | |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 80 | #ifndef P2P_MAX_INITIAL_CONN_WAIT_GO |
| 81 | /* |
| 82 | * How many seconds to wait for initial 4-way handshake to get completed after |
| 83 | * WPS provisioning step on the GO. This controls the extra time the P2P |
| 84 | * operation is considered to be in progress (e.g., to delay other scans) after |
| 85 | * WPS provisioning has been completed on the GO during group formation. |
| 86 | */ |
| 87 | #define P2P_MAX_INITIAL_CONN_WAIT_GO 10 |
| 88 | #endif /* P2P_MAX_INITIAL_CONN_WAIT_GO */ |
| 89 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 90 | #ifndef P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE |
| 91 | /* |
| 92 | * How many seconds to wait for initial 4-way handshake to get completed after |
| 93 | * re-invocation of a persistent group on the GO when the client is expected |
| 94 | * to connect automatically (no user interaction). |
| 95 | */ |
| 96 | #define P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE 15 |
| 97 | #endif /* P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE */ |
| 98 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 99 | #define P2P_MGMT_DEVICE_PREFIX "p2p-dev-" |
| 100 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 101 | /* |
| 102 | * How many seconds to wait to re-attempt to move GOs, in case previous attempt |
| 103 | * was not possible. |
| 104 | */ |
| 105 | #define P2P_RECONSIDER_GO_MOVE_DELAY 30 |
| 106 | |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 107 | /* Check if frequency is 2GHz */ |
| 108 | #define IS_2GHZ(n) (n >= 2412 && n <= 2484) |
| 109 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 110 | enum p2p_group_removal_reason { |
| 111 | P2P_GROUP_REMOVAL_UNKNOWN, |
| 112 | P2P_GROUP_REMOVAL_SILENT, |
| 113 | P2P_GROUP_REMOVAL_FORMATION_FAILED, |
| 114 | P2P_GROUP_REMOVAL_REQUESTED, |
| 115 | P2P_GROUP_REMOVAL_IDLE_TIMEOUT, |
| 116 | P2P_GROUP_REMOVAL_UNAVAILABLE, |
| 117 | P2P_GROUP_REMOVAL_GO_ENDING_SESSION, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 118 | P2P_GROUP_REMOVAL_PSK_FAILURE, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 119 | P2P_GROUP_REMOVAL_FREQ_CONFLICT, |
| 120 | P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
Jouni Malinen | dc7b713 | 2012-09-14 12:53:47 -0700 | [diff] [blame] | 123 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 124 | static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx); |
| 125 | static struct wpa_supplicant * |
| 126 | wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated, |
| 127 | int go); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 128 | static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s, int freq, |
| 129 | const u8 *ssid, size_t ssid_len); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 130 | static int wpas_p2p_setup_freqs(struct wpa_supplicant *wpa_s, int freq, |
| 131 | int *force_freq, int *pref_freq, int go, |
| 132 | unsigned int *pref_freq_list, |
| 133 | unsigned int *num_pref_freq); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 134 | static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq, |
| 135 | const u8 *ssid, size_t ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 136 | static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx); |
| 137 | static int wpas_p2p_join(struct wpa_supplicant *wpa_s, const u8 *iface_addr, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 138 | const u8 *dev_addr, enum p2p_wps_method wps_method, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 139 | int auto_join, int freq, |
| 140 | const u8 *ssid, size_t ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 141 | static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s); |
| 142 | static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s); |
| 143 | static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx); |
| 144 | static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 145 | static void wpas_p2p_group_formation_timeout(void *eloop_ctx, |
| 146 | void *timeout_ctx); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 147 | static void wpas_p2p_group_freq_conflict(void *eloop_ctx, void *timeout_ctx); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 148 | static int wpas_p2p_fallback_to_go_neg(struct wpa_supplicant *wpa_s, |
| 149 | int group_added); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 150 | static void wpas_p2p_stop_find_oper(struct wpa_supplicant *wpa_s); |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 151 | static void wpas_stop_listen(void *ctx); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 152 | static void wpas_p2p_psk_failure_removal(void *eloop_ctx, void *timeout_ctx); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 153 | static void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 154 | static int wpas_p2p_add_group_interface(struct wpa_supplicant *wpa_s, |
| 155 | enum wpa_driver_if_type type); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 156 | static void wpas_p2p_group_formation_failed(struct wpa_supplicant *wpa_s, |
| 157 | int already_deleted); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 158 | static void wpas_p2p_optimize_listen_channel(struct wpa_supplicant *wpa_s, |
| 159 | struct wpa_used_freq_data *freqs, |
| 160 | unsigned int num); |
| 161 | static void wpas_p2p_move_go(void *eloop_ctx, void *timeout_ctx); |
| 162 | static int wpas_p2p_go_is_peer_freq(struct wpa_supplicant *wpa_s, int freq); |
| 163 | static void |
| 164 | wpas_p2p_consider_moving_gos(struct wpa_supplicant *wpa_s, |
| 165 | struct wpa_used_freq_data *freqs, unsigned int num, |
| 166 | enum wpas_p2p_channel_update_trig trig); |
| 167 | static void wpas_p2p_reconsider_moving_go(void *eloop_ctx, void *timeout_ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 168 | |
| 169 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 170 | /* |
| 171 | * Get the number of concurrent channels that the HW can operate, but that are |
| 172 | * currently not in use by any of the wpa_supplicant interfaces. |
| 173 | */ |
| 174 | static int wpas_p2p_num_unused_channels(struct wpa_supplicant *wpa_s) |
| 175 | { |
| 176 | int *freqs; |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 177 | int num, unused; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 178 | |
| 179 | freqs = os_calloc(wpa_s->num_multichan_concurrent, sizeof(int)); |
| 180 | if (!freqs) |
| 181 | return -1; |
| 182 | |
| 183 | num = get_shared_radio_freqs(wpa_s, freqs, |
| 184 | wpa_s->num_multichan_concurrent); |
| 185 | os_free(freqs); |
| 186 | |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 187 | unused = wpa_s->num_multichan_concurrent - num; |
| 188 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: num_unused_channels: %d", unused); |
| 189 | return unused; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | |
| 193 | /* |
| 194 | * Get the frequencies that are currently in use by one or more of the virtual |
| 195 | * interfaces, and that are also valid for P2P operation. |
| 196 | */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 197 | static unsigned int |
| 198 | wpas_p2p_valid_oper_freqs(struct wpa_supplicant *wpa_s, |
| 199 | struct wpa_used_freq_data *p2p_freqs, |
| 200 | unsigned int len) |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 201 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 202 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 203 | unsigned int num, i, j; |
| 204 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 205 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 206 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 207 | if (!freqs) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 208 | return 0; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 209 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 210 | num = get_shared_radio_freqs_data(wpa_s, freqs, |
| 211 | wpa_s->num_multichan_concurrent); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 212 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 213 | os_memset(p2p_freqs, 0, sizeof(struct wpa_used_freq_data) * len); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 214 | |
| 215 | for (i = 0, j = 0; i < num && j < len; i++) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 216 | if (p2p_supported_freq(wpa_s->global->p2p, freqs[i].freq)) |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 217 | p2p_freqs[j++] = freqs[i]; |
| 218 | } |
| 219 | |
| 220 | os_free(freqs); |
| 221 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 222 | dump_freq_data(wpa_s, "valid for P2P", p2p_freqs, j); |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 223 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 224 | return j; |
| 225 | } |
| 226 | |
| 227 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 228 | static void wpas_p2p_set_own_freq_preference(struct wpa_supplicant *wpa_s, |
| 229 | int freq) |
| 230 | { |
| 231 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 232 | return; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 233 | |
| 234 | /* Use the wpa_s used to control the P2P Device operation */ |
| 235 | wpa_s = wpa_s->global->p2p_init_wpa_s; |
| 236 | |
| 237 | if (wpa_s->conf->p2p_ignore_shared_freq && |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 238 | freq > 0 && wpa_s->num_multichan_concurrent > 1 && |
| 239 | wpas_p2p_num_unused_channels(wpa_s) > 0) { |
| 240 | wpa_printf(MSG_DEBUG, "P2P: Ignore own channel preference %d MHz due to p2p_ignore_shared_freq=1 configuration", |
| 241 | freq); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 242 | freq = 0; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 243 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 244 | p2p_set_own_freq_preference(wpa_s->global->p2p, freq); |
| 245 | } |
| 246 | |
| 247 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 248 | static void wpas_p2p_scan_res_handled(struct wpa_supplicant *wpa_s) |
| 249 | { |
| 250 | unsigned int delay = wpas_p2p_search_delay(wpa_s); |
| 251 | |
| 252 | /* In case of concurrent P2P and external scans, delay P2P search. */ |
| 253 | if (external_scan_running(wpa_s->radio)) { |
| 254 | delay = wpa_s->conf->p2p_search_delay; |
| 255 | wpa_printf(MSG_DEBUG, |
| 256 | "P2P: Delay next P2P search by %d ms to let externally triggered scan complete", |
| 257 | delay); |
| 258 | } |
| 259 | |
| 260 | p2p_scan_res_handled(wpa_s->global->p2p, delay); |
| 261 | } |
| 262 | |
| 263 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 264 | static void wpas_p2p_scan_res_handler(struct wpa_supplicant *wpa_s, |
| 265 | struct wpa_scan_results *scan_res) |
| 266 | { |
| 267 | size_t i; |
| 268 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 269 | if (wpa_s->p2p_scan_work) { |
| 270 | struct wpa_radio_work *work = wpa_s->p2p_scan_work; |
| 271 | wpa_s->p2p_scan_work = NULL; |
| 272 | radio_work_done(work); |
| 273 | } |
| 274 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 275 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 276 | return; |
| 277 | |
| 278 | wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS)", |
| 279 | (int) scan_res->num); |
| 280 | |
| 281 | for (i = 0; i < scan_res->num; i++) { |
| 282 | struct wpa_scan_res *bss = scan_res->res[i]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 283 | struct os_reltime time_tmp_age, entry_ts; |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 284 | const u8 *ies; |
| 285 | size_t ies_len; |
| 286 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 287 | time_tmp_age.sec = bss->age / 1000; |
| 288 | time_tmp_age.usec = (bss->age % 1000) * 1000; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 289 | os_reltime_sub(&scan_res->fetch_time, &time_tmp_age, &entry_ts); |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 290 | |
| 291 | ies = (const u8 *) (bss + 1); |
| 292 | ies_len = bss->ie_len; |
| 293 | if (bss->beacon_ie_len > 0 && |
| 294 | !wpa_scan_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) && |
| 295 | wpa_scan_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { |
| 296 | wpa_printf(MSG_DEBUG, "P2P: Use P2P IE(s) from Beacon frame since no P2P IE(s) in Probe Response frames received for " |
| 297 | MACSTR, MAC2STR(bss->bssid)); |
| 298 | ies = ies + ies_len; |
| 299 | ies_len = bss->beacon_ie_len; |
| 300 | } |
| 301 | |
| 302 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 303 | if (p2p_scan_res_handler(wpa_s->global->p2p, bss->bssid, |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 304 | bss->freq, &entry_ts, bss->level, |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 305 | ies, ies_len) > 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 306 | break; |
| 307 | } |
| 308 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 309 | wpas_p2p_scan_res_handled(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 313 | 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] | 314 | { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 315 | if (wpa_s->p2p_scan_work) { |
| 316 | struct wpa_radio_work *work = wpa_s->p2p_scan_work; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 317 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 318 | wpa_s->p2p_scan_work = NULL; |
| 319 | radio_work_done(work); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 322 | if (wpa_s->global->p2p_disabled || !wpa_s->global->p2p) |
| 323 | return; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 324 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 325 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 326 | "P2P: Failed to get scan results - try to continue"); |
| 327 | wpas_p2p_scan_res_handled(wpa_s); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 331 | static void wpas_p2p_trigger_scan_cb(struct wpa_radio_work *work, int deinit) |
| 332 | { |
| 333 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 334 | struct wpa_driver_scan_params *params = work->ctx; |
| 335 | int ret; |
| 336 | |
| 337 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 338 | if (!work->started) { |
| 339 | wpa_scan_free_params(params); |
| 340 | return; |
| 341 | } |
| 342 | |
| 343 | wpa_s->p2p_scan_work = NULL; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 344 | return; |
| 345 | } |
| 346 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 347 | if (wpa_s->clear_driver_scan_cache) { |
| 348 | wpa_printf(MSG_DEBUG, |
| 349 | "Request driver to clear scan cache due to local BSS flush"); |
| 350 | params->only_new_results = 1; |
| 351 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 352 | |
| 353 | if (wpa_s->conf->p2p_6ghz_disable && !params->freqs) { |
| 354 | wpa_printf(MSG_DEBUG, |
| 355 | "P2P: 6 GHz disabled - update the scan frequency list"); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 356 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211G, params, |
| 357 | 0); |
| 358 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, params, |
| 359 | 0); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 360 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 361 | ret = wpa_drv_scan(wpa_s, params); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 362 | if (ret == 0) |
| 363 | wpa_s->curr_scan_cookie = params->scan_cookie; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 364 | wpa_scan_free_params(params); |
| 365 | work->ctx = NULL; |
| 366 | if (ret) { |
| 367 | radio_work_done(work); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 368 | p2p_notify_scan_trigger_status(wpa_s->global->p2p, ret); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 369 | return; |
| 370 | } |
| 371 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 372 | p2p_notify_scan_trigger_status(wpa_s->global->p2p, ret); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 373 | os_get_reltime(&wpa_s->scan_trigger_time); |
| 374 | wpa_s->scan_res_handler = wpas_p2p_scan_res_handler; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 375 | wpa_s->scan_res_fail_handler = wpas_p2p_scan_res_fail_handler; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 376 | wpa_s->own_scan_requested = 1; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 377 | wpa_s->clear_driver_scan_cache = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 378 | wpa_s->p2p_scan_work = work; |
| 379 | } |
| 380 | |
| 381 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 382 | static int wpas_p2p_search_social_channel(struct wpa_supplicant *wpa_s, |
| 383 | int freq) |
| 384 | { |
| 385 | if (wpa_s->global->p2p_24ghz_social_channels && |
| 386 | (freq == 2412 || freq == 2437 || freq == 2462)) { |
| 387 | /* |
| 388 | * Search all social channels regardless of whether these have |
| 389 | * been disabled for P2P operating channel use to avoid missing |
| 390 | * peers. |
| 391 | */ |
| 392 | return 1; |
| 393 | } |
| 394 | return p2p_supported_freq(wpa_s->global->p2p, freq); |
| 395 | } |
| 396 | |
| 397 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 398 | static int wpas_p2p_scan(void *ctx, enum p2p_scan_type type, int freq, |
| 399 | unsigned int num_req_dev_types, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 400 | const u8 *req_dev_types, const u8 *dev_id, u16 pw_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 401 | { |
| 402 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 403 | struct wpa_driver_scan_params *params = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 404 | struct wpabuf *wps_ie, *ies; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 405 | unsigned int num_channels = 0; |
| 406 | int social_channels_freq[] = { 2412, 2437, 2462, 60480 }; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 407 | size_t ielen; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 408 | u8 *n, i; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 409 | unsigned int bands; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 410 | |
| 411 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 412 | return -1; |
| 413 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 414 | if (wpa_s->p2p_scan_work) { |
| 415 | wpa_dbg(wpa_s, MSG_INFO, "P2P: Reject scan trigger since one is already pending"); |
| 416 | return -1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 419 | params = os_zalloc(sizeof(*params)); |
| 420 | if (params == NULL) |
| 421 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 422 | |
| 423 | /* P2P Wildcard SSID */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 424 | params->num_ssids = 1; |
| 425 | n = os_malloc(P2P_WILDCARD_SSID_LEN); |
| 426 | if (n == NULL) |
| 427 | goto fail; |
| 428 | os_memcpy(n, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN); |
| 429 | params->ssids[0].ssid = n; |
| 430 | params->ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 431 | |
| 432 | wpa_s->wps->dev.p2p = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 433 | wps_ie = wps_build_probe_req_ie(pw_id, &wpa_s->wps->dev, |
| 434 | wpa_s->wps->uuid, WPS_REQ_ENROLLEE, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 435 | num_req_dev_types, req_dev_types); |
| 436 | if (wps_ie == NULL) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 437 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 438 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 439 | switch (type) { |
| 440 | case P2P_SCAN_SOCIAL: |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 441 | params->freqs = os_calloc(ARRAY_SIZE(social_channels_freq) + 1, |
| 442 | sizeof(int)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 443 | if (params->freqs == NULL) |
| 444 | goto fail; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 445 | for (i = 0; i < ARRAY_SIZE(social_channels_freq); i++) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 446 | if (wpas_p2p_search_social_channel( |
| 447 | wpa_s, social_channels_freq[i])) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 448 | params->freqs[num_channels++] = |
| 449 | social_channels_freq[i]; |
| 450 | } |
| 451 | params->freqs[num_channels++] = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 452 | break; |
| 453 | case P2P_SCAN_FULL: |
| 454 | break; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 455 | case P2P_SCAN_SPECIFIC: |
| 456 | params->freqs = os_calloc(2, sizeof(int)); |
| 457 | if (params->freqs == NULL) |
| 458 | goto fail; |
| 459 | params->freqs[0] = freq; |
| 460 | params->freqs[1] = 0; |
| 461 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 462 | case P2P_SCAN_SOCIAL_PLUS_ONE: |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 463 | params->freqs = os_calloc(ARRAY_SIZE(social_channels_freq) + 2, |
| 464 | sizeof(int)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 465 | if (params->freqs == NULL) |
| 466 | goto fail; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 467 | for (i = 0; i < ARRAY_SIZE(social_channels_freq); i++) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 468 | if (wpas_p2p_search_social_channel( |
| 469 | wpa_s, social_channels_freq[i])) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 470 | params->freqs[num_channels++] = |
| 471 | social_channels_freq[i]; |
| 472 | } |
| 473 | if (p2p_supported_freq(wpa_s->global->p2p, freq)) |
| 474 | params->freqs[num_channels++] = freq; |
| 475 | params->freqs[num_channels++] = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 476 | break; |
| 477 | } |
| 478 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 479 | ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p); |
| 480 | ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen); |
| 481 | if (ies == NULL) { |
| 482 | wpabuf_free(wps_ie); |
| 483 | goto fail; |
| 484 | } |
| 485 | wpabuf_put_buf(ies, wps_ie); |
| 486 | wpabuf_free(wps_ie); |
| 487 | |
| 488 | bands = wpas_get_bands(wpa_s, params->freqs); |
| 489 | p2p_scan_ie(wpa_s->global->p2p, ies, dev_id, bands); |
| 490 | |
| 491 | params->p2p_probe = 1; |
| 492 | n = os_malloc(wpabuf_len(ies)); |
| 493 | if (n == NULL) { |
| 494 | wpabuf_free(ies); |
| 495 | goto fail; |
| 496 | } |
| 497 | os_memcpy(n, wpabuf_head(ies), wpabuf_len(ies)); |
| 498 | params->extra_ies = n; |
| 499 | params->extra_ies_len = wpabuf_len(ies); |
| 500 | wpabuf_free(ies); |
| 501 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 502 | radio_remove_works(wpa_s, "p2p-scan", 0); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 503 | if (radio_add_work(wpa_s, 0, "p2p-scan", 0, wpas_p2p_trigger_scan_cb, |
| 504 | params) < 0) |
| 505 | goto fail; |
| 506 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 507 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 508 | fail: |
| 509 | wpa_scan_free_params(params); |
| 510 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 514 | static enum wpa_driver_if_type wpas_p2p_if_type(int p2p_group_interface) |
| 515 | { |
| 516 | switch (p2p_group_interface) { |
| 517 | case P2P_GROUP_INTERFACE_PENDING: |
| 518 | return WPA_IF_P2P_GROUP; |
| 519 | case P2P_GROUP_INTERFACE_GO: |
| 520 | return WPA_IF_P2P_GO; |
| 521 | case P2P_GROUP_INTERFACE_CLIENT: |
| 522 | return WPA_IF_P2P_CLIENT; |
| 523 | } |
| 524 | |
| 525 | return WPA_IF_P2P_GROUP; |
| 526 | } |
| 527 | |
| 528 | |
| 529 | static struct wpa_supplicant * wpas_get_p2p_group(struct wpa_supplicant *wpa_s, |
| 530 | const u8 *ssid, |
| 531 | size_t ssid_len, int *go) |
| 532 | { |
| 533 | struct wpa_ssid *s; |
| 534 | |
| 535 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 536 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 537 | if (s->disabled != 0 || !s->p2p_group || |
| 538 | s->ssid_len != ssid_len || |
| 539 | os_memcmp(ssid, s->ssid, ssid_len) != 0) |
| 540 | continue; |
| 541 | if (s->mode == WPAS_MODE_P2P_GO && |
| 542 | s != wpa_s->current_ssid) |
| 543 | continue; |
| 544 | if (go) |
| 545 | *go = s->mode == WPAS_MODE_P2P_GO; |
| 546 | return wpa_s; |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | return NULL; |
| 551 | } |
| 552 | |
| 553 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 554 | static void run_wpas_p2p_disconnect(void *eloop_ctx, void *timeout_ctx) |
| 555 | { |
| 556 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 557 | wpa_printf(MSG_DEBUG, |
| 558 | "P2P: Complete previously requested removal of %s", |
| 559 | wpa_s->ifname); |
| 560 | wpas_p2p_disconnect(wpa_s); |
| 561 | } |
| 562 | |
| 563 | |
| 564 | static int wpas_p2p_disconnect_safely(struct wpa_supplicant *wpa_s, |
| 565 | struct wpa_supplicant *calling_wpa_s) |
| 566 | { |
| 567 | if (calling_wpa_s == wpa_s && wpa_s && |
| 568 | wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) { |
| 569 | /* |
| 570 | * The calling wpa_s instance is going to be removed. Do that |
| 571 | * from an eloop callback to keep the instance available until |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 572 | * the caller has returned. This may be needed, e.g., to provide |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 573 | * control interface responses on the per-interface socket. |
| 574 | */ |
| 575 | if (eloop_register_timeout(0, 0, run_wpas_p2p_disconnect, |
| 576 | wpa_s, NULL) < 0) |
| 577 | return -1; |
| 578 | return 0; |
| 579 | } |
| 580 | |
| 581 | return wpas_p2p_disconnect(wpa_s); |
| 582 | } |
| 583 | |
| 584 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 585 | /* Determine total number of clients in active groups where we are the GO */ |
| 586 | static unsigned int p2p_group_go_member_count(struct wpa_supplicant *wpa_s) |
| 587 | { |
| 588 | unsigned int count = 0; |
| 589 | struct wpa_ssid *s; |
| 590 | |
| 591 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 592 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 593 | wpa_printf(MSG_DEBUG, |
| 594 | "P2P: sup:%p ssid:%p disabled:%d p2p:%d mode:%d", |
| 595 | wpa_s, s, s->disabled, s->p2p_group, |
| 596 | s->mode); |
| 597 | if (!s->disabled && s->p2p_group && |
| 598 | s->mode == WPAS_MODE_P2P_GO) { |
| 599 | count += p2p_get_group_num_members( |
| 600 | wpa_s->p2p_group); |
| 601 | } |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | return count; |
| 606 | } |
| 607 | |
| 608 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 609 | static unsigned int p2p_is_active_persistent_group(struct wpa_supplicant *wpa_s) |
| 610 | { |
| 611 | return !wpa_s->p2p_mgmt && wpa_s->current_ssid && |
| 612 | !wpa_s->current_ssid->disabled && |
| 613 | wpa_s->current_ssid->p2p_group && |
| 614 | wpa_s->current_ssid->p2p_persistent_group; |
| 615 | } |
| 616 | |
| 617 | |
| 618 | static unsigned int p2p_is_active_persistent_go(struct wpa_supplicant *wpa_s) |
| 619 | { |
| 620 | return p2p_is_active_persistent_group(wpa_s) && |
| 621 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO; |
| 622 | } |
| 623 | |
| 624 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 625 | /* Find an interface for a P2P group where we are the GO */ |
| 626 | static struct wpa_supplicant * |
| 627 | wpas_p2p_get_go_group(struct wpa_supplicant *wpa_s) |
| 628 | { |
| 629 | struct wpa_supplicant *save = NULL; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 630 | |
| 631 | if (!wpa_s) |
| 632 | return NULL; |
| 633 | |
| 634 | 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] | 635 | if (!p2p_is_active_persistent_go(wpa_s)) |
| 636 | continue; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 637 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 638 | /* Prefer a group with connected clients */ |
| 639 | if (p2p_get_group_num_members(wpa_s->p2p_group)) |
| 640 | return wpa_s; |
| 641 | save = wpa_s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | /* No group with connected clients, so pick the one without (if any) */ |
| 645 | return save; |
| 646 | } |
| 647 | |
| 648 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 649 | 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] | 650 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 651 | return p2p_is_active_persistent_group(wpa_s) && |
| 652 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA; |
| 653 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 654 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 655 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 656 | /* Find an interface for a P2P group where we are the P2P Client */ |
| 657 | static struct wpa_supplicant * |
| 658 | wpas_p2p_get_cli_group(struct wpa_supplicant *wpa_s) |
| 659 | { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 660 | 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] | 661 | if (p2p_is_active_persistent_cli(wpa_s)) |
| 662 | return wpa_s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 663 | } |
| 664 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 665 | return NULL; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | |
| 669 | /* Find a persistent group where we are the GO */ |
| 670 | static struct wpa_ssid * |
| 671 | wpas_p2p_get_persistent_go(struct wpa_supplicant *wpa_s) |
| 672 | { |
| 673 | struct wpa_ssid *s; |
| 674 | |
| 675 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 676 | if (s->disabled == 2 && s->mode == WPAS_MODE_P2P_GO) |
| 677 | return s; |
| 678 | } |
| 679 | |
| 680 | return NULL; |
| 681 | } |
| 682 | |
| 683 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 684 | static u8 p2ps_group_capability(void *ctx, u8 incoming, u8 role, |
| 685 | unsigned int *force_freq, |
| 686 | unsigned int *pref_freq) |
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 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 689 | struct wpa_ssid *s; |
| 690 | u8 conncap = P2PS_SETUP_NONE; |
| 691 | unsigned int owned_members = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 692 | struct wpa_supplicant *go_wpa_s, *cli_wpa_s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 693 | struct wpa_ssid *persistent_go; |
| 694 | int p2p_no_group_iface; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 695 | unsigned int pref_freq_list[P2P_MAX_PREF_CHANNELS], size; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 696 | |
| 697 | wpa_printf(MSG_DEBUG, "P2P: Conncap - in:%d role:%d", incoming, role); |
| 698 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 699 | if (force_freq) |
| 700 | *force_freq = 0; |
| 701 | if (pref_freq) |
| 702 | *pref_freq = 0; |
| 703 | |
| 704 | size = P2P_MAX_PREF_CHANNELS; |
| 705 | if (force_freq && pref_freq && |
| 706 | !wpas_p2p_setup_freqs(wpa_s, 0, (int *) force_freq, |
| 707 | (int *) pref_freq, 0, pref_freq_list, &size)) |
| 708 | wpas_p2p_set_own_freq_preference(wpa_s, |
| 709 | *force_freq ? *force_freq : |
| 710 | *pref_freq); |
| 711 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 712 | /* |
| 713 | * For non-concurrent capable devices: |
| 714 | * If persistent_go, then no new. |
| 715 | * If GO, then no client. |
| 716 | * If client, then no GO. |
| 717 | */ |
| 718 | go_wpa_s = wpas_p2p_get_go_group(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 719 | if (go_wpa_s) |
| 720 | owned_members = p2p_get_group_num_members(go_wpa_s->p2p_group); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 721 | persistent_go = wpas_p2p_get_persistent_go(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 722 | p2p_no_group_iface = !wpas_p2p_create_iface(wpa_s); |
| 723 | cli_wpa_s = wpas_p2p_get_cli_group(wpa_s); |
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 | wpa_printf(MSG_DEBUG, |
| 726 | "P2P: GO(iface)=%p members=%u CLI(iface)=%p persistent(ssid)=%p", |
| 727 | go_wpa_s, owned_members, cli_wpa_s, persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 728 | |
| 729 | /* If not concurrent, restrict our choices */ |
| 730 | if (p2p_no_group_iface) { |
| 731 | wpa_printf(MSG_DEBUG, "P2P: p2p_no_group_iface"); |
| 732 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 733 | if (cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 734 | return P2PS_SETUP_NONE; |
| 735 | |
| 736 | if (go_wpa_s) { |
| 737 | if (role == P2PS_SETUP_CLIENT || |
| 738 | incoming == P2PS_SETUP_GROUP_OWNER || |
| 739 | p2p_client_limit_reached(go_wpa_s->p2p_group)) |
| 740 | return P2PS_SETUP_NONE; |
| 741 | |
| 742 | return P2PS_SETUP_GROUP_OWNER; |
| 743 | } |
| 744 | |
| 745 | if (persistent_go) { |
| 746 | if (role == P2PS_SETUP_NONE || role == P2PS_SETUP_NEW) { |
| 747 | if (!incoming) |
| 748 | return P2PS_SETUP_GROUP_OWNER | |
| 749 | P2PS_SETUP_CLIENT; |
| 750 | if (incoming == P2PS_SETUP_NEW) { |
| 751 | u8 r; |
| 752 | |
| 753 | if (os_get_random(&r, sizeof(r)) < 0 || |
| 754 | (r & 1)) |
| 755 | return P2PS_SETUP_CLIENT; |
| 756 | return P2PS_SETUP_GROUP_OWNER; |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | /* If a required role has been specified, handle it here */ |
| 763 | if (role && role != P2PS_SETUP_NEW) { |
| 764 | switch (incoming) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 765 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_NEW: |
| 766 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT: |
| 767 | /* |
| 768 | * Peer has an active GO, so if the role allows it and |
| 769 | * we do not have any active roles, become client. |
| 770 | */ |
| 771 | if ((role & P2PS_SETUP_CLIENT) && !go_wpa_s && |
| 772 | !cli_wpa_s) |
| 773 | return P2PS_SETUP_CLIENT; |
| 774 | |
| 775 | /* fall through */ |
| 776 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 777 | case P2PS_SETUP_NONE: |
| 778 | case P2PS_SETUP_NEW: |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 779 | conncap = role; |
| 780 | goto grp_owner; |
| 781 | |
| 782 | case P2PS_SETUP_GROUP_OWNER: |
| 783 | /* |
| 784 | * Must be a complimentary role - cannot be a client to |
| 785 | * more than one peer. |
| 786 | */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 787 | if (incoming == role || cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 788 | return P2PS_SETUP_NONE; |
| 789 | |
| 790 | return P2PS_SETUP_CLIENT; |
| 791 | |
| 792 | case P2PS_SETUP_CLIENT: |
| 793 | /* Must be a complimentary role */ |
| 794 | if (incoming != role) { |
| 795 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 796 | goto grp_owner; |
| 797 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 798 | /* fall through */ |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 799 | |
| 800 | default: |
| 801 | return P2PS_SETUP_NONE; |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | /* |
| 806 | * For now, we only will support ownership of one group, and being a |
| 807 | * client of one group. Therefore, if we have either an existing GO |
| 808 | * group, or an existing client group, we will not do a new GO |
| 809 | * negotiation, but rather try to re-use the existing groups. |
| 810 | */ |
| 811 | switch (incoming) { |
| 812 | case P2PS_SETUP_NONE: |
| 813 | case P2PS_SETUP_NEW: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 814 | if (cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 815 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 816 | else if (!owned_members) |
| 817 | conncap = P2PS_SETUP_NEW; |
| 818 | else if (incoming == P2PS_SETUP_NONE) |
| 819 | conncap = P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT; |
| 820 | else |
| 821 | conncap = P2PS_SETUP_CLIENT; |
| 822 | break; |
| 823 | |
| 824 | case P2PS_SETUP_CLIENT: |
| 825 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 826 | break; |
| 827 | |
| 828 | case P2PS_SETUP_GROUP_OWNER: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 829 | if (!cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 830 | conncap = P2PS_SETUP_CLIENT; |
| 831 | break; |
| 832 | |
| 833 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_NEW: |
| 834 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 835 | if (cli_wpa_s) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 836 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 837 | else { |
| 838 | u8 r; |
| 839 | |
| 840 | if (os_get_random(&r, sizeof(r)) < 0 || |
| 841 | (r & 1)) |
| 842 | conncap = P2PS_SETUP_CLIENT; |
| 843 | else |
| 844 | conncap = P2PS_SETUP_GROUP_OWNER; |
| 845 | } |
| 846 | break; |
| 847 | |
| 848 | default: |
| 849 | return P2PS_SETUP_NONE; |
| 850 | } |
| 851 | |
| 852 | grp_owner: |
| 853 | if ((conncap & P2PS_SETUP_GROUP_OWNER) || |
| 854 | (!incoming && (conncap & P2PS_SETUP_NEW))) { |
| 855 | if (go_wpa_s && p2p_client_limit_reached(go_wpa_s->p2p_group)) |
| 856 | conncap &= ~P2PS_SETUP_GROUP_OWNER; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 857 | |
| 858 | s = wpas_p2p_get_persistent_go(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 859 | if (!s && !go_wpa_s && p2p_no_group_iface) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 860 | p2p_set_intended_addr(wpa_s->global->p2p, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 861 | wpa_s->p2p_mgmt ? |
| 862 | wpa_s->parent->own_addr : |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 863 | wpa_s->own_addr); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 864 | } else if (!s && !go_wpa_s) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 865 | if (wpas_p2p_add_group_interface(wpa_s, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 866 | WPA_IF_P2P_GROUP) < 0) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 867 | wpa_printf(MSG_ERROR, |
| 868 | "P2P: Failed to allocate a new interface for the group"); |
| 869 | return P2PS_SETUP_NONE; |
| 870 | } |
| 871 | wpa_s->global->pending_group_iface_for_p2ps = 1; |
| 872 | p2p_set_intended_addr(wpa_s->global->p2p, |
| 873 | wpa_s->pending_interface_addr); |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | return conncap; |
| 878 | } |
| 879 | |
| 880 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 881 | static int wpas_p2p_group_delete(struct wpa_supplicant *wpa_s, |
| 882 | enum p2p_group_removal_reason removal_reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 883 | { |
| 884 | struct wpa_ssid *ssid; |
| 885 | char *gtype; |
| 886 | const char *reason; |
| 887 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 888 | ssid = wpa_s->current_ssid; |
| 889 | if (ssid == NULL) { |
| 890 | /* |
| 891 | * The current SSID was not known, but there may still be a |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 892 | * pending P2P group interface waiting for provisioning or a |
| 893 | * P2P group that is trying to reconnect. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 894 | */ |
| 895 | ssid = wpa_s->conf->ssid; |
| 896 | while (ssid) { |
Jouni Malinen | 9d71283 | 2012-10-05 11:01:57 -0700 | [diff] [blame] | 897 | if (ssid->p2p_group && ssid->disabled != 2) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 898 | break; |
| 899 | ssid = ssid->next; |
| 900 | } |
Jouni Malinen | 5c44edb | 2012-08-31 21:35:32 +0300 | [diff] [blame] | 901 | if (ssid == NULL && |
| 902 | wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE) |
| 903 | { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 904 | wpa_printf(MSG_ERROR, "P2P: P2P group interface " |
| 905 | "not found"); |
| 906 | return -1; |
| 907 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 908 | } |
| 909 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO) |
| 910 | gtype = "GO"; |
| 911 | else if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT || |
| 912 | (ssid && ssid->mode == WPAS_MODE_INFRA)) { |
| 913 | wpa_s->reassociate = 0; |
| 914 | wpa_s->disconnected = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 915 | gtype = "client"; |
| 916 | } else |
| 917 | gtype = "GO"; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 918 | |
| 919 | if (removal_reason != P2P_GROUP_REMOVAL_SILENT && ssid) |
| 920 | wpas_notify_p2p_group_removed(wpa_s, ssid, gtype); |
| 921 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 922 | if (os_strcmp(gtype, "client") == 0) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 923 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 924 | if (eloop_is_timeout_registered(wpas_p2p_psk_failure_removal, |
| 925 | wpa_s, NULL)) { |
| 926 | wpa_printf(MSG_DEBUG, |
| 927 | "P2P: PSK failure removal was scheduled, so use PSK failure as reason for group removal"); |
| 928 | removal_reason = P2P_GROUP_REMOVAL_PSK_FAILURE; |
| 929 | eloop_cancel_timeout(wpas_p2p_psk_failure_removal, |
| 930 | wpa_s, NULL); |
| 931 | } |
| 932 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 933 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 934 | if (wpa_s->cross_connect_in_use) { |
| 935 | wpa_s->cross_connect_in_use = 0; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 936 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 937 | P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s", |
| 938 | wpa_s->ifname, wpa_s->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 939 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 940 | switch (removal_reason) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 941 | case P2P_GROUP_REMOVAL_REQUESTED: |
| 942 | reason = " reason=REQUESTED"; |
| 943 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 944 | case P2P_GROUP_REMOVAL_FORMATION_FAILED: |
| 945 | reason = " reason=FORMATION_FAILED"; |
| 946 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 947 | case P2P_GROUP_REMOVAL_IDLE_TIMEOUT: |
| 948 | reason = " reason=IDLE"; |
| 949 | break; |
| 950 | case P2P_GROUP_REMOVAL_UNAVAILABLE: |
| 951 | reason = " reason=UNAVAILABLE"; |
| 952 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 953 | case P2P_GROUP_REMOVAL_GO_ENDING_SESSION: |
| 954 | reason = " reason=GO_ENDING_SESSION"; |
| 955 | break; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 956 | case P2P_GROUP_REMOVAL_PSK_FAILURE: |
| 957 | reason = " reason=PSK_FAILURE"; |
| 958 | break; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 959 | case P2P_GROUP_REMOVAL_FREQ_CONFLICT: |
| 960 | reason = " reason=FREQ_CONFLICT"; |
| 961 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 962 | default: |
| 963 | reason = ""; |
| 964 | break; |
| 965 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 966 | if (removal_reason != P2P_GROUP_REMOVAL_SILENT) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 967 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 968 | P2P_EVENT_GROUP_REMOVED "%s %s%s", |
| 969 | wpa_s->ifname, gtype, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 970 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 971 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 972 | if (eloop_cancel_timeout(wpas_p2p_group_freq_conflict, wpa_s, NULL) > 0) |
| 973 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group freq_conflict timeout"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 974 | if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0) |
| 975 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout"); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 976 | if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 977 | wpa_s->p2pdev, NULL) > 0) { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 978 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group formation " |
| 979 | "timeout"); |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 980 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 981 | wpas_p2p_group_formation_failed(wpa_s, 1); |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 982 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 983 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 984 | wpa_s->p2p_in_invitation = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 985 | eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL); |
| 986 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, wpa_s, NULL); |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 987 | |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 988 | /* |
| 989 | * Make sure wait for the first client does not remain active after the |
| 990 | * group has been removed. |
| 991 | */ |
| 992 | wpa_s->global->p2p_go_wait_client.sec = 0; |
| 993 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 994 | if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) { |
| 995 | struct wpa_global *global; |
| 996 | char *ifname; |
| 997 | enum wpa_driver_if_type type; |
| 998 | wpa_printf(MSG_DEBUG, "P2P: Remove group interface %s", |
| 999 | wpa_s->ifname); |
| 1000 | global = wpa_s->global; |
| 1001 | ifname = os_strdup(wpa_s->ifname); |
| 1002 | type = wpas_p2p_if_type(wpa_s->p2p_group_interface); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1003 | eloop_cancel_timeout(run_wpas_p2p_disconnect, wpa_s, NULL); |
Dmitry Shmidt | e15c7b5 | 2011-08-03 15:04:35 -0700 | [diff] [blame] | 1004 | wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1005 | wpa_s = global->ifaces; |
| 1006 | if (wpa_s && ifname) |
| 1007 | wpa_drv_if_remove(wpa_s, type, ifname); |
| 1008 | os_free(ifname); |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 1009 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1012 | /* |
| 1013 | * The primary interface was used for P2P group operations, so |
| 1014 | * need to reset its p2pdev. |
| 1015 | */ |
| 1016 | wpa_s->p2pdev = wpa_s->parent; |
| 1017 | |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1018 | if (!wpa_s->p2p_go_group_formation_completed) { |
| 1019 | wpa_s->global->p2p_group_formation = NULL; |
| 1020 | wpa_s->p2p_in_provisioning = 0; |
| 1021 | } |
| 1022 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1023 | wpa_s->show_group_started = 0; |
| 1024 | os_free(wpa_s->go_params); |
| 1025 | wpa_s->go_params = NULL; |
| 1026 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1027 | os_free(wpa_s->p2p_group_common_freqs); |
| 1028 | wpa_s->p2p_group_common_freqs = NULL; |
| 1029 | wpa_s->p2p_group_common_freqs_num = 0; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1030 | wpa_s->p2p_go_do_acs = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1031 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1032 | wpa_s->waiting_presence_resp = 0; |
| 1033 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1034 | wpa_printf(MSG_DEBUG, "P2P: Remove temporary group network"); |
| 1035 | if (ssid && (ssid->p2p_group || |
| 1036 | ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION || |
| 1037 | (ssid->key_mgmt & WPA_KEY_MGMT_WPS))) { |
| 1038 | int id = ssid->id; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1039 | if (ssid == wpa_s->current_ssid) { |
| 1040 | wpa_sm_set_config(wpa_s->wpa, NULL); |
| 1041 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1042 | wpa_s->current_ssid = NULL; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1043 | } |
| 1044 | /* |
| 1045 | * Networks objects created during any P2P activities are not |
| 1046 | * exposed out as they might/will confuse certain non-P2P aware |
| 1047 | * applications since these network objects won't behave like |
| 1048 | * regular ones. |
| 1049 | * |
| 1050 | * Likewise, we don't send out network removed signals for such |
| 1051 | * network objects. |
| 1052 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1053 | wpa_config_remove_network(wpa_s->conf, id); |
| 1054 | wpa_supplicant_clear_status(wpa_s); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1055 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1056 | } else { |
| 1057 | wpa_printf(MSG_DEBUG, "P2P: Temporary group network not " |
| 1058 | "found"); |
| 1059 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1060 | if (wpa_s->ap_iface) |
| 1061 | wpa_supplicant_ap_deinit(wpa_s); |
| 1062 | else |
| 1063 | wpa_drv_deinit_p2p_cli(wpa_s); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1064 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1065 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
| 1066 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1067 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | |
| 1071 | static int wpas_p2p_persistent_group(struct wpa_supplicant *wpa_s, |
| 1072 | u8 *go_dev_addr, |
| 1073 | const u8 *ssid, size_t ssid_len) |
| 1074 | { |
| 1075 | struct wpa_bss *bss; |
| 1076 | const u8 *bssid; |
| 1077 | struct wpabuf *p2p; |
| 1078 | u8 group_capab; |
| 1079 | const u8 *addr; |
| 1080 | |
| 1081 | if (wpa_s->go_params) |
| 1082 | bssid = wpa_s->go_params->peer_interface_addr; |
| 1083 | else |
| 1084 | bssid = wpa_s->bssid; |
| 1085 | |
| 1086 | bss = wpa_bss_get(wpa_s, bssid, ssid, ssid_len); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1087 | if (bss == NULL && wpa_s->go_params && |
| 1088 | !is_zero_ether_addr(wpa_s->go_params->peer_device_addr)) |
| 1089 | bss = wpa_bss_get_p2p_dev_addr( |
| 1090 | wpa_s, wpa_s->go_params->peer_device_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1091 | if (bss == NULL) { |
| 1092 | u8 iface_addr[ETH_ALEN]; |
| 1093 | if (p2p_get_interface_addr(wpa_s->global->p2p, bssid, |
| 1094 | iface_addr) == 0) |
| 1095 | bss = wpa_bss_get(wpa_s, iface_addr, ssid, ssid_len); |
| 1096 | } |
| 1097 | if (bss == NULL) { |
| 1098 | wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether " |
| 1099 | "group is persistent - BSS " MACSTR " not found", |
| 1100 | MAC2STR(bssid)); |
| 1101 | return 0; |
| 1102 | } |
| 1103 | |
| 1104 | p2p = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE); |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1105 | if (p2p == NULL) |
| 1106 | p2p = wpa_bss_get_vendor_ie_multi_beacon(bss, |
| 1107 | P2P_IE_VENDOR_TYPE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1108 | if (p2p == NULL) { |
| 1109 | wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether " |
| 1110 | "group is persistent - BSS " MACSTR |
| 1111 | " did not include P2P IE", MAC2STR(bssid)); |
| 1112 | wpa_hexdump(MSG_DEBUG, "P2P: Probe Response IEs", |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1113 | wpa_bss_ie_ptr(bss), bss->ie_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1114 | wpa_hexdump(MSG_DEBUG, "P2P: Beacon IEs", |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1115 | wpa_bss_ie_ptr(bss) + bss->ie_len, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1116 | bss->beacon_ie_len); |
| 1117 | return 0; |
| 1118 | } |
| 1119 | |
| 1120 | group_capab = p2p_get_group_capab(p2p); |
| 1121 | addr = p2p_get_go_dev_addr(p2p); |
| 1122 | wpa_printf(MSG_DEBUG, "P2P: Checking whether group is persistent: " |
| 1123 | "group_capab=0x%x", group_capab); |
| 1124 | if (addr) { |
| 1125 | os_memcpy(go_dev_addr, addr, ETH_ALEN); |
| 1126 | wpa_printf(MSG_DEBUG, "P2P: GO Device Address " MACSTR, |
| 1127 | MAC2STR(addr)); |
| 1128 | } else |
| 1129 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 1130 | wpabuf_free(p2p); |
| 1131 | |
| 1132 | wpa_printf(MSG_DEBUG, "P2P: BSS " MACSTR " group_capab=0x%x " |
| 1133 | "go_dev_addr=" MACSTR, |
| 1134 | MAC2STR(bssid), group_capab, MAC2STR(go_dev_addr)); |
| 1135 | |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 1136 | return !!(group_capab & P2P_GROUP_CAPAB_PERSISTENT_GROUP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1140 | static int wpas_p2p_store_persistent_group(struct wpa_supplicant *wpa_s, |
| 1141 | struct wpa_ssid *ssid, |
| 1142 | const u8 *go_dev_addr) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1143 | { |
| 1144 | struct wpa_ssid *s; |
| 1145 | int changed = 0; |
| 1146 | |
| 1147 | wpa_printf(MSG_DEBUG, "P2P: Storing credentials for a persistent " |
| 1148 | "group (GO Dev Addr " MACSTR ")", MAC2STR(go_dev_addr)); |
| 1149 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 1150 | if (s->disabled == 2 && |
| 1151 | os_memcmp(go_dev_addr, s->bssid, ETH_ALEN) == 0 && |
| 1152 | s->ssid_len == ssid->ssid_len && |
| 1153 | os_memcmp(ssid->ssid, s->ssid, ssid->ssid_len) == 0) |
| 1154 | break; |
| 1155 | } |
| 1156 | |
| 1157 | if (s) { |
| 1158 | wpa_printf(MSG_DEBUG, "P2P: Update existing persistent group " |
| 1159 | "entry"); |
| 1160 | if (ssid->passphrase && !s->passphrase) |
| 1161 | changed = 1; |
| 1162 | else if (ssid->passphrase && s->passphrase && |
| 1163 | os_strcmp(ssid->passphrase, s->passphrase) != 0) |
| 1164 | changed = 1; |
| 1165 | } else { |
| 1166 | wpa_printf(MSG_DEBUG, "P2P: Create a new persistent group " |
| 1167 | "entry"); |
| 1168 | changed = 1; |
| 1169 | s = wpa_config_add_network(wpa_s->conf); |
| 1170 | if (s == NULL) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1171 | return -1; |
| 1172 | |
| 1173 | /* |
| 1174 | * Instead of network_added we emit persistent_group_added |
| 1175 | * notification. Also to keep the defense checks in |
| 1176 | * persistent_group obj registration method, we set the |
| 1177 | * relevant flags in s to designate it as a persistent group. |
| 1178 | */ |
| 1179 | s->p2p_group = 1; |
| 1180 | s->p2p_persistent_group = 1; |
| 1181 | wpas_notify_persistent_group_added(wpa_s, s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1182 | wpa_config_set_network_defaults(s); |
| 1183 | } |
| 1184 | |
| 1185 | s->p2p_group = 1; |
| 1186 | s->p2p_persistent_group = 1; |
| 1187 | s->disabled = 2; |
| 1188 | s->bssid_set = 1; |
| 1189 | os_memcpy(s->bssid, go_dev_addr, ETH_ALEN); |
| 1190 | s->mode = ssid->mode; |
| 1191 | s->auth_alg = WPA_AUTH_ALG_OPEN; |
| 1192 | s->key_mgmt = WPA_KEY_MGMT_PSK; |
| 1193 | s->proto = WPA_PROTO_RSN; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1194 | s->pbss = ssid->pbss; |
| 1195 | s->pairwise_cipher = ssid->pbss ? WPA_CIPHER_GCMP : WPA_CIPHER_CCMP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1196 | s->export_keys = 1; |
| 1197 | if (ssid->passphrase) { |
| 1198 | os_free(s->passphrase); |
| 1199 | s->passphrase = os_strdup(ssid->passphrase); |
| 1200 | } |
| 1201 | if (ssid->psk_set) { |
| 1202 | s->psk_set = 1; |
| 1203 | os_memcpy(s->psk, ssid->psk, 32); |
| 1204 | } |
| 1205 | if (s->passphrase && !s->psk_set) |
| 1206 | wpa_config_update_psk(s); |
| 1207 | if (s->ssid == NULL || s->ssid_len < ssid->ssid_len) { |
| 1208 | os_free(s->ssid); |
| 1209 | s->ssid = os_malloc(ssid->ssid_len); |
| 1210 | } |
| 1211 | if (s->ssid) { |
| 1212 | s->ssid_len = ssid->ssid_len; |
| 1213 | os_memcpy(s->ssid, ssid->ssid, s->ssid_len); |
| 1214 | } |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1215 | if (ssid->mode == WPAS_MODE_P2P_GO && wpa_s->global->add_psk) { |
| 1216 | dl_list_add(&s->psk_list, &wpa_s->global->add_psk->list); |
| 1217 | wpa_s->global->add_psk = NULL; |
| 1218 | changed = 1; |
| 1219 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1220 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1221 | if (changed && wpa_s->conf->update_config && |
| 1222 | wpa_config_write(wpa_s->confname, wpa_s->conf)) { |
| 1223 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
| 1224 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1225 | |
| 1226 | return s->id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1230 | static void wpas_p2p_add_persistent_group_client(struct wpa_supplicant *wpa_s, |
| 1231 | const u8 *addr) |
| 1232 | { |
| 1233 | struct wpa_ssid *ssid, *s; |
| 1234 | u8 *n; |
| 1235 | size_t i; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1236 | int found = 0; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1237 | 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] | 1238 | |
| 1239 | ssid = wpa_s->current_ssid; |
| 1240 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || |
| 1241 | !ssid->p2p_persistent_group) |
| 1242 | return; |
| 1243 | |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1244 | for (s = p2p_wpa_s->conf->ssid; s; s = s->next) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1245 | if (s->disabled != 2 || s->mode != WPAS_MODE_P2P_GO) |
| 1246 | continue; |
| 1247 | |
| 1248 | if (s->ssid_len == ssid->ssid_len && |
| 1249 | os_memcmp(s->ssid, ssid->ssid, s->ssid_len) == 0) |
| 1250 | break; |
| 1251 | } |
| 1252 | |
| 1253 | if (s == NULL) |
| 1254 | return; |
| 1255 | |
| 1256 | for (i = 0; s->p2p_client_list && i < s->num_p2p_clients; i++) { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1257 | if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN, addr, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1258 | ETH_ALEN) != 0) |
| 1259 | continue; |
| 1260 | |
| 1261 | if (i == s->num_p2p_clients - 1) |
| 1262 | return; /* already the most recent entry */ |
| 1263 | |
| 1264 | /* move the entry to mark it most recent */ |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1265 | os_memmove(s->p2p_client_list + i * 2 * ETH_ALEN, |
| 1266 | s->p2p_client_list + (i + 1) * 2 * ETH_ALEN, |
| 1267 | (s->num_p2p_clients - i - 1) * 2 * ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1268 | os_memcpy(s->p2p_client_list + |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1269 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN, addr, |
| 1270 | ETH_ALEN); |
| 1271 | os_memset(s->p2p_client_list + |
| 1272 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN + ETH_ALEN, |
| 1273 | 0xff, ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1274 | found = 1; |
| 1275 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1276 | } |
| 1277 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1278 | if (!found && s->num_p2p_clients < P2P_MAX_STORED_CLIENTS) { |
| 1279 | n = os_realloc_array(s->p2p_client_list, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1280 | s->num_p2p_clients + 1, 2 * ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1281 | if (n == NULL) |
| 1282 | return; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1283 | os_memcpy(n + s->num_p2p_clients * 2 * ETH_ALEN, addr, |
| 1284 | ETH_ALEN); |
| 1285 | os_memset(n + s->num_p2p_clients * 2 * ETH_ALEN + ETH_ALEN, |
| 1286 | 0xff, ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1287 | s->p2p_client_list = n; |
| 1288 | s->num_p2p_clients++; |
Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 1289 | } else if (!found && s->p2p_client_list) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1290 | /* Not enough room for an additional entry - drop the oldest |
| 1291 | * entry */ |
| 1292 | os_memmove(s->p2p_client_list, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1293 | s->p2p_client_list + 2 * ETH_ALEN, |
| 1294 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1295 | os_memcpy(s->p2p_client_list + |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1296 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1297 | addr, ETH_ALEN); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1298 | os_memset(s->p2p_client_list + |
| 1299 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN + ETH_ALEN, |
| 1300 | 0xff, ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1301 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1302 | |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1303 | if (p2p_wpa_s->conf->update_config && |
| 1304 | wpa_config_write(p2p_wpa_s->confname, p2p_wpa_s->conf)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1305 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1309 | static void wpas_p2p_group_started(struct wpa_supplicant *wpa_s, |
| 1310 | int go, struct wpa_ssid *ssid, int freq, |
| 1311 | const u8 *psk, const char *passphrase, |
| 1312 | const u8 *go_dev_addr, int persistent, |
| 1313 | const char *extra) |
| 1314 | { |
| 1315 | const char *ssid_txt; |
| 1316 | char psk_txt[65]; |
| 1317 | |
| 1318 | if (psk) |
| 1319 | wpa_snprintf_hex(psk_txt, sizeof(psk_txt), psk, 32); |
| 1320 | else |
| 1321 | psk_txt[0] = '\0'; |
| 1322 | |
| 1323 | if (ssid) |
| 1324 | ssid_txt = wpa_ssid_txt(ssid->ssid, ssid->ssid_len); |
| 1325 | else |
| 1326 | ssid_txt = ""; |
| 1327 | |
| 1328 | if (passphrase && passphrase[0] == '\0') |
| 1329 | passphrase = NULL; |
| 1330 | |
| 1331 | /* |
| 1332 | * Include PSK/passphrase only in the control interface message and |
| 1333 | * leave it out from the debug log entry. |
| 1334 | */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1335 | wpa_msg_global_ctrl(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1336 | P2P_EVENT_GROUP_STARTED |
| 1337 | "%s %s ssid=\"%s\" freq=%d%s%s%s%s%s go_dev_addr=" |
| 1338 | MACSTR "%s%s", |
| 1339 | wpa_s->ifname, go ? "GO" : "client", ssid_txt, freq, |
| 1340 | psk ? " psk=" : "", psk_txt, |
| 1341 | passphrase ? " passphrase=\"" : "", |
| 1342 | passphrase ? passphrase : "", |
| 1343 | passphrase ? "\"" : "", |
| 1344 | MAC2STR(go_dev_addr), |
| 1345 | persistent ? " [PERSISTENT]" : "", extra); |
| 1346 | wpa_printf(MSG_INFO, P2P_EVENT_GROUP_STARTED |
| 1347 | "%s %s ssid=\"%s\" freq=%d go_dev_addr=" MACSTR "%s%s", |
| 1348 | wpa_s->ifname, go ? "GO" : "client", ssid_txt, freq, |
| 1349 | MAC2STR(go_dev_addr), persistent ? " [PERSISTENT]" : "", |
| 1350 | extra); |
| 1351 | } |
| 1352 | |
| 1353 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1354 | static void wpas_group_formation_completed(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 1355 | int success, int already_deleted) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1356 | { |
| 1357 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1358 | int client; |
| 1359 | int persistent; |
| 1360 | u8 go_dev_addr[ETH_ALEN]; |
| 1361 | |
| 1362 | /* |
| 1363 | * This callback is likely called for the main interface. Update wpa_s |
| 1364 | * to use the group interface if a new interface was created for the |
| 1365 | * group. |
| 1366 | */ |
| 1367 | if (wpa_s->global->p2p_group_formation) |
| 1368 | wpa_s = wpa_s->global->p2p_group_formation; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1369 | if (wpa_s->p2p_go_group_formation_completed) { |
| 1370 | wpa_s->global->p2p_group_formation = NULL; |
| 1371 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1372 | } else if (wpa_s->p2p_in_provisioning && !success) { |
| 1373 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1374 | "P2P: Stop provisioning state due to failure"); |
| 1375 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1376 | } |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 1377 | wpa_s->p2p_in_invitation = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1378 | wpa_s->group_formation_reported = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1379 | |
| 1380 | if (!success) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1381 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1382 | P2P_EVENT_GROUP_FORMATION_FAILURE); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1383 | wpas_notify_p2p_group_formation_failure(wpa_s, ""); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 1384 | if (already_deleted) |
| 1385 | return; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1386 | wpas_p2p_group_delete(wpa_s, |
| 1387 | P2P_GROUP_REMOVAL_FORMATION_FAILED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1388 | return; |
| 1389 | } |
| 1390 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1391 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1392 | P2P_EVENT_GROUP_FORMATION_SUCCESS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1393 | |
| 1394 | ssid = wpa_s->current_ssid; |
| 1395 | if (ssid && ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) { |
| 1396 | ssid->mode = WPAS_MODE_P2P_GO; |
| 1397 | p2p_group_notif_formation_done(wpa_s->p2p_group); |
| 1398 | wpa_supplicant_ap_mac_addr_filter(wpa_s, NULL); |
| 1399 | } |
| 1400 | |
| 1401 | persistent = 0; |
| 1402 | if (ssid) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1403 | client = ssid->mode == WPAS_MODE_INFRA; |
| 1404 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 1405 | persistent = ssid->p2p_persistent_group; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 1406 | os_memcpy(go_dev_addr, wpa_s->global->p2p_dev_addr, |
| 1407 | ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1408 | } else |
| 1409 | persistent = wpas_p2p_persistent_group(wpa_s, |
| 1410 | go_dev_addr, |
| 1411 | ssid->ssid, |
| 1412 | ssid->ssid_len); |
| 1413 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1414 | client = wpa_s->p2p_group_interface == |
| 1415 | P2P_GROUP_INTERFACE_CLIENT; |
| 1416 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 1417 | } |
| 1418 | |
| 1419 | wpa_s->show_group_started = 0; |
| 1420 | if (client) { |
| 1421 | /* |
| 1422 | * Indicate event only after successfully completed 4-way |
| 1423 | * handshake, i.e., when the interface is ready for data |
| 1424 | * packets. |
| 1425 | */ |
| 1426 | wpa_s->show_group_started = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1427 | } else { |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1428 | wpas_p2p_group_started(wpa_s, 1, ssid, |
| 1429 | ssid ? ssid->frequency : 0, |
| 1430 | ssid && ssid->passphrase == NULL && |
| 1431 | ssid->psk_set ? ssid->psk : NULL, |
| 1432 | ssid ? ssid->passphrase : NULL, |
| 1433 | go_dev_addr, persistent, ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1434 | wpas_p2p_cross_connect_setup(wpa_s); |
| 1435 | wpas_p2p_set_group_idle_timeout(wpa_s); |
| 1436 | } |
| 1437 | |
| 1438 | if (persistent) |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1439 | wpas_p2p_store_persistent_group(wpa_s->p2pdev, |
| 1440 | ssid, go_dev_addr); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1441 | else { |
| 1442 | os_free(wpa_s->global->add_psk); |
| 1443 | wpa_s->global->add_psk = NULL; |
| 1444 | } |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1445 | |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 1446 | if (!client) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1447 | wpas_notify_p2p_group_started(wpa_s, ssid, persistent, 0, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1448 | os_get_reltime(&wpa_s->global->p2p_go_wait_client); |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 1449 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1453 | struct send_action_work { |
| 1454 | unsigned int freq; |
| 1455 | u8 dst[ETH_ALEN]; |
| 1456 | u8 src[ETH_ALEN]; |
| 1457 | u8 bssid[ETH_ALEN]; |
| 1458 | size_t len; |
| 1459 | unsigned int wait_time; |
| 1460 | u8 buf[0]; |
| 1461 | }; |
| 1462 | |
| 1463 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1464 | static void wpas_p2p_free_send_action_work(struct wpa_supplicant *wpa_s) |
| 1465 | { |
| 1466 | struct send_action_work *awork = wpa_s->p2p_send_action_work->ctx; |
| 1467 | |
| 1468 | wpa_printf(MSG_DEBUG, |
| 1469 | "P2P: Free Action frame radio work @%p (freq=%u dst=" |
| 1470 | MACSTR " src=" MACSTR " bssid=" MACSTR " wait_time=%u)", |
| 1471 | wpa_s->p2p_send_action_work, awork->freq, |
| 1472 | MAC2STR(awork->dst), MAC2STR(awork->src), |
| 1473 | MAC2STR(awork->bssid), awork->wait_time); |
| 1474 | wpa_hexdump(MSG_DEBUG, "P2P: Freeing pending Action frame", |
| 1475 | awork->buf, awork->len); |
| 1476 | os_free(awork); |
| 1477 | wpa_s->p2p_send_action_work->ctx = NULL; |
| 1478 | radio_work_done(wpa_s->p2p_send_action_work); |
| 1479 | wpa_s->p2p_send_action_work = NULL; |
| 1480 | } |
| 1481 | |
| 1482 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1483 | static void wpas_p2p_send_action_work_timeout(void *eloop_ctx, |
| 1484 | void *timeout_ctx) |
| 1485 | { |
| 1486 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 1487 | |
| 1488 | if (!wpa_s->p2p_send_action_work) |
| 1489 | return; |
| 1490 | |
| 1491 | wpa_printf(MSG_DEBUG, "P2P: Send Action frame radio work timed out"); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1492 | wpas_p2p_free_send_action_work(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 1496 | static void wpas_p2p_action_tx_clear(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1497 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1498 | if (wpa_s->p2p_send_action_work) { |
| 1499 | struct send_action_work *awork; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1500 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1501 | awork = wpa_s->p2p_send_action_work->ctx; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1502 | wpa_printf(MSG_DEBUG, |
| 1503 | "P2P: Clear Action TX work @%p (wait_time=%u)", |
| 1504 | wpa_s->p2p_send_action_work, awork->wait_time); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1505 | if (awork->wait_time == 0) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1506 | wpas_p2p_free_send_action_work(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1507 | } else { |
| 1508 | /* |
| 1509 | * In theory, this should not be needed, but number of |
| 1510 | * places in the P2P code is still using non-zero wait |
| 1511 | * time for the last Action frame in the sequence and |
| 1512 | * some of these do not call send_action_done(). |
| 1513 | */ |
| 1514 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 1515 | wpa_s, NULL); |
| 1516 | eloop_register_timeout( |
| 1517 | 0, awork->wait_time * 1000, |
| 1518 | wpas_p2p_send_action_work_timeout, |
| 1519 | wpa_s, NULL); |
| 1520 | } |
| 1521 | } |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | |
| 1525 | static void wpas_p2p_send_action_tx_status(struct wpa_supplicant *wpa_s, |
| 1526 | unsigned int freq, |
| 1527 | const u8 *dst, const u8 *src, |
| 1528 | const u8 *bssid, |
| 1529 | const u8 *data, size_t data_len, |
| 1530 | enum offchannel_send_action_result |
| 1531 | result) |
| 1532 | { |
| 1533 | enum p2p_send_action_result res = P2P_SEND_ACTION_SUCCESS; |
| 1534 | |
| 1535 | wpas_p2p_action_tx_clear(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1536 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1537 | if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) |
| 1538 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1539 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1540 | switch (result) { |
| 1541 | case OFFCHANNEL_SEND_ACTION_SUCCESS: |
| 1542 | res = P2P_SEND_ACTION_SUCCESS; |
| 1543 | break; |
| 1544 | case OFFCHANNEL_SEND_ACTION_NO_ACK: |
| 1545 | res = P2P_SEND_ACTION_NO_ACK; |
| 1546 | break; |
| 1547 | case OFFCHANNEL_SEND_ACTION_FAILED: |
| 1548 | res = P2P_SEND_ACTION_FAILED; |
| 1549 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1552 | 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] | 1553 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1554 | if (result != OFFCHANNEL_SEND_ACTION_SUCCESS && |
| 1555 | wpa_s->pending_pd_before_join && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1556 | (os_memcmp(dst, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 || |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1557 | os_memcmp(dst, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0) && |
| 1558 | wpa_s->p2p_fallback_to_go_neg) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1559 | wpa_s->pending_pd_before_join = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1560 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No ACK for PD Req " |
| 1561 | "during p2p_connect-auto"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1562 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1563 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 1564 | "reason=no-ACK-to-PD-Req"); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1565 | wpas_p2p_fallback_to_go_neg(wpa_s, 0); |
| 1566 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1567 | } |
| 1568 | } |
| 1569 | |
| 1570 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1571 | static void wpas_send_action_cb(struct wpa_radio_work *work, int deinit) |
| 1572 | { |
| 1573 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 1574 | struct send_action_work *awork = work->ctx; |
| 1575 | |
| 1576 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 1577 | if (work->started) { |
| 1578 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 1579 | wpa_s, NULL); |
| 1580 | wpa_s->p2p_send_action_work = NULL; |
| 1581 | offchannel_send_action_done(wpa_s); |
| 1582 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1583 | os_free(awork); |
| 1584 | return; |
| 1585 | } |
| 1586 | |
| 1587 | if (offchannel_send_action(wpa_s, awork->freq, awork->dst, awork->src, |
| 1588 | awork->bssid, awork->buf, awork->len, |
| 1589 | awork->wait_time, |
| 1590 | wpas_p2p_send_action_tx_status, 1) < 0) { |
| 1591 | os_free(awork); |
| 1592 | radio_work_done(work); |
| 1593 | return; |
| 1594 | } |
| 1595 | wpa_s->p2p_send_action_work = work; |
| 1596 | } |
| 1597 | |
| 1598 | |
| 1599 | static int wpas_send_action_work(struct wpa_supplicant *wpa_s, |
| 1600 | unsigned int freq, const u8 *dst, |
| 1601 | const u8 *src, const u8 *bssid, const u8 *buf, |
| 1602 | size_t len, unsigned int wait_time) |
| 1603 | { |
| 1604 | struct send_action_work *awork; |
| 1605 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1606 | if (radio_work_pending(wpa_s, "p2p-send-action")) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1607 | wpa_printf(MSG_DEBUG, "P2P: Cannot schedule new p2p-send-action work since one is already pending"); |
| 1608 | return -1; |
| 1609 | } |
| 1610 | |
| 1611 | awork = os_zalloc(sizeof(*awork) + len); |
| 1612 | if (awork == NULL) |
| 1613 | return -1; |
| 1614 | |
| 1615 | awork->freq = freq; |
| 1616 | os_memcpy(awork->dst, dst, ETH_ALEN); |
| 1617 | os_memcpy(awork->src, src, ETH_ALEN); |
| 1618 | os_memcpy(awork->bssid, bssid, ETH_ALEN); |
| 1619 | awork->len = len; |
| 1620 | awork->wait_time = wait_time; |
| 1621 | os_memcpy(awork->buf, buf, len); |
| 1622 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1623 | if (radio_add_work(wpa_s, freq, "p2p-send-action", 1, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1624 | wpas_send_action_cb, awork) < 0) { |
| 1625 | os_free(awork); |
| 1626 | return -1; |
| 1627 | } |
| 1628 | |
| 1629 | return 0; |
| 1630 | } |
| 1631 | |
| 1632 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1633 | static int wpas_send_action(void *ctx, unsigned int freq, const u8 *dst, |
| 1634 | const u8 *src, const u8 *bssid, const u8 *buf, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1635 | size_t len, unsigned int wait_time, int *scheduled) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1636 | { |
| 1637 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1638 | int listen_freq = -1, send_freq = -1; |
| 1639 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1640 | if (scheduled) |
| 1641 | *scheduled = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1642 | if (wpa_s->p2p_listen_work) |
| 1643 | listen_freq = wpa_s->p2p_listen_work->freq; |
| 1644 | if (wpa_s->p2p_send_action_work) |
| 1645 | send_freq = wpa_s->p2p_send_action_work->freq; |
| 1646 | if (listen_freq != (int) freq && send_freq != (int) freq) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1647 | int res; |
| 1648 | |
| 1649 | wpa_printf(MSG_DEBUG, "P2P: Schedule new radio work for Action frame TX (listen_freq=%d send_freq=%d freq=%u)", |
| 1650 | listen_freq, send_freq, freq); |
| 1651 | res = wpas_send_action_work(wpa_s, freq, dst, src, bssid, buf, |
| 1652 | len, wait_time); |
| 1653 | if (res == 0 && scheduled) |
| 1654 | *scheduled = 1; |
| 1655 | return res; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | 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] | 1659 | return offchannel_send_action(wpa_s, freq, dst, src, bssid, buf, len, |
| 1660 | wait_time, |
| 1661 | wpas_p2p_send_action_tx_status, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1662 | } |
| 1663 | |
| 1664 | |
| 1665 | static void wpas_send_action_done(void *ctx) |
| 1666 | { |
| 1667 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1668 | |
| 1669 | if (wpa_s->p2p_send_action_work) { |
| 1670 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 1671 | wpa_s, NULL); |
| 1672 | os_free(wpa_s->p2p_send_action_work->ctx); |
| 1673 | radio_work_done(wpa_s->p2p_send_action_work); |
| 1674 | wpa_s->p2p_send_action_work = NULL; |
| 1675 | } |
| 1676 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1677 | offchannel_send_action_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | |
| 1681 | static int wpas_copy_go_neg_results(struct wpa_supplicant *wpa_s, |
| 1682 | struct p2p_go_neg_results *params) |
| 1683 | { |
| 1684 | if (wpa_s->go_params == NULL) { |
| 1685 | wpa_s->go_params = os_malloc(sizeof(*params)); |
| 1686 | if (wpa_s->go_params == NULL) |
| 1687 | return -1; |
| 1688 | } |
| 1689 | os_memcpy(wpa_s->go_params, params, sizeof(*params)); |
| 1690 | return 0; |
| 1691 | } |
| 1692 | |
| 1693 | |
| 1694 | static void wpas_start_wps_enrollee(struct wpa_supplicant *wpa_s, |
| 1695 | struct p2p_go_neg_results *res) |
| 1696 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1697 | wpa_s->group_formation_reported = 0; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1698 | wpa_printf(MSG_DEBUG, "P2P: Start WPS Enrollee for peer " MACSTR |
| 1699 | " dev_addr " MACSTR " wps_method %d", |
| 1700 | MAC2STR(res->peer_interface_addr), |
| 1701 | MAC2STR(res->peer_device_addr), res->wps_method); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1702 | wpa_hexdump_ascii(MSG_DEBUG, "P2P: Start WPS Enrollee for SSID", |
| 1703 | res->ssid, res->ssid_len); |
| 1704 | wpa_supplicant_ap_deinit(wpa_s); |
| 1705 | wpas_copy_go_neg_results(wpa_s, res); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1706 | if (res->wps_method == WPS_PBC) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1707 | wpas_wps_start_pbc(wpa_s, res->peer_interface_addr, 1, 0); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1708 | #ifdef CONFIG_WPS_NFC |
| 1709 | } else if (res->wps_method == WPS_NFC) { |
| 1710 | wpas_wps_start_nfc(wpa_s, res->peer_device_addr, |
| 1711 | res->peer_interface_addr, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1712 | wpa_s->p2pdev->p2p_oob_dev_pw, |
| 1713 | wpa_s->p2pdev->p2p_oob_dev_pw_id, 1, |
| 1714 | wpa_s->p2pdev->p2p_oob_dev_pw_id == |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1715 | DEV_PW_NFC_CONNECTION_HANDOVER ? |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1716 | wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1717 | NULL, |
| 1718 | NULL, 0, 0); |
| 1719 | #endif /* CONFIG_WPS_NFC */ |
| 1720 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1721 | u16 dev_pw_id = DEV_PW_DEFAULT; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1722 | if (wpa_s->p2p_wps_method == WPS_P2PS) |
| 1723 | dev_pw_id = DEV_PW_P2PS_DEFAULT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1724 | if (wpa_s->p2p_wps_method == WPS_PIN_KEYPAD) |
| 1725 | dev_pw_id = DEV_PW_REGISTRAR_SPECIFIED; |
| 1726 | wpas_wps_start_pin(wpa_s, res->peer_interface_addr, |
| 1727 | wpa_s->p2p_pin, 1, dev_pw_id); |
| 1728 | } |
| 1729 | } |
| 1730 | |
| 1731 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1732 | static void wpas_p2p_add_psk_list(struct wpa_supplicant *wpa_s, |
| 1733 | struct wpa_ssid *ssid) |
| 1734 | { |
| 1735 | struct wpa_ssid *persistent; |
| 1736 | struct psk_list_entry *psk; |
| 1737 | struct hostapd_data *hapd; |
| 1738 | |
| 1739 | if (!wpa_s->ap_iface) |
| 1740 | return; |
| 1741 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1742 | persistent = wpas_p2p_get_persistent(wpa_s->p2pdev, NULL, ssid->ssid, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1743 | ssid->ssid_len); |
| 1744 | if (persistent == NULL) |
| 1745 | return; |
| 1746 | |
| 1747 | hapd = wpa_s->ap_iface->bss[0]; |
| 1748 | |
| 1749 | dl_list_for_each(psk, &persistent->psk_list, struct psk_list_entry, |
| 1750 | list) { |
| 1751 | struct hostapd_wpa_psk *hpsk; |
| 1752 | |
| 1753 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add persistent group PSK entry for " |
| 1754 | MACSTR " psk=%d", |
| 1755 | MAC2STR(psk->addr), psk->p2p); |
| 1756 | hpsk = os_zalloc(sizeof(*hpsk)); |
| 1757 | if (hpsk == NULL) |
| 1758 | break; |
| 1759 | os_memcpy(hpsk->psk, psk->psk, PMK_LEN); |
| 1760 | if (psk->p2p) |
| 1761 | os_memcpy(hpsk->p2p_dev_addr, psk->addr, ETH_ALEN); |
| 1762 | else |
| 1763 | os_memcpy(hpsk->addr, psk->addr, ETH_ALEN); |
| 1764 | hpsk->next = hapd->conf->ssid.wpa_psk; |
| 1765 | hapd->conf->ssid.wpa_psk = hpsk; |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1770 | static void p2p_go_dump_common_freqs(struct wpa_supplicant *wpa_s) |
| 1771 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1772 | char buf[20 + P2P_MAX_CHANNELS * 6]; |
| 1773 | char *pos, *end; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1774 | unsigned int i; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1775 | int res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1776 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1777 | pos = buf; |
| 1778 | end = pos + sizeof(buf); |
| 1779 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 1780 | res = os_snprintf(pos, end - pos, " %d", |
| 1781 | wpa_s->p2p_group_common_freqs[i]); |
| 1782 | if (os_snprintf_error(end - pos, res)) |
| 1783 | break; |
| 1784 | pos += res; |
| 1785 | } |
| 1786 | *pos = '\0'; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1787 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1788 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Common group frequencies:%s", buf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | |
| 1792 | static void p2p_go_save_group_common_freqs(struct wpa_supplicant *wpa_s, |
| 1793 | struct p2p_go_neg_results *params) |
| 1794 | { |
| 1795 | unsigned int i, len = int_array_len(wpa_s->go_params->freq_list); |
| 1796 | |
| 1797 | wpa_s->p2p_group_common_freqs_num = 0; |
| 1798 | os_free(wpa_s->p2p_group_common_freqs); |
| 1799 | wpa_s->p2p_group_common_freqs = os_calloc(len, sizeof(int)); |
| 1800 | if (!wpa_s->p2p_group_common_freqs) |
| 1801 | return; |
| 1802 | |
| 1803 | for (i = 0; i < len; i++) { |
| 1804 | if (!wpa_s->go_params->freq_list[i]) |
| 1805 | break; |
| 1806 | wpa_s->p2p_group_common_freqs[i] = |
| 1807 | wpa_s->go_params->freq_list[i]; |
| 1808 | } |
| 1809 | wpa_s->p2p_group_common_freqs_num = i; |
| 1810 | } |
| 1811 | |
| 1812 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1813 | static void p2p_config_write(struct wpa_supplicant *wpa_s) |
| 1814 | { |
| 1815 | #ifndef CONFIG_NO_CONFIG_WRITE |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1816 | if (wpa_s->p2pdev->conf->update_config && |
| 1817 | wpa_config_write(wpa_s->p2pdev->confname, wpa_s->p2pdev->conf)) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1818 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
| 1819 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 1820 | } |
| 1821 | |
| 1822 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1823 | static void p2p_go_configured(void *ctx, void *data) |
| 1824 | { |
| 1825 | struct wpa_supplicant *wpa_s = ctx; |
| 1826 | struct p2p_go_neg_results *params = data; |
| 1827 | struct wpa_ssid *ssid; |
| 1828 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 1829 | wpa_s->ap_configured_cb = NULL; |
| 1830 | wpa_s->ap_configured_cb_ctx = NULL; |
| 1831 | wpa_s->ap_configured_cb_data = NULL; |
| 1832 | if (!wpa_s->go_params) { |
| 1833 | wpa_printf(MSG_ERROR, |
| 1834 | "P2P: p2p_go_configured() called with wpa_s->go_params == NULL"); |
| 1835 | return; |
| 1836 | } |
| 1837 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1838 | p2p_go_save_group_common_freqs(wpa_s, params); |
| 1839 | p2p_go_dump_common_freqs(wpa_s); |
| 1840 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1841 | ssid = wpa_s->current_ssid; |
| 1842 | if (ssid && ssid->mode == WPAS_MODE_P2P_GO) { |
| 1843 | wpa_printf(MSG_DEBUG, "P2P: Group setup without provisioning"); |
| 1844 | if (wpa_s->global->p2p_group_formation == wpa_s) |
| 1845 | wpa_s->global->p2p_group_formation = NULL; |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1846 | wpas_p2p_group_started(wpa_s, 1, ssid, ssid->frequency, |
| 1847 | params->passphrase[0] == '\0' ? |
| 1848 | params->psk : NULL, |
| 1849 | params->passphrase, |
| 1850 | wpa_s->global->p2p_dev_addr, |
| 1851 | params->persistent_group, ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1852 | wpa_s->group_formation_reported = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1853 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1854 | if (wpa_s->p2pdev->p2ps_method_config_any) { |
| 1855 | if (is_zero_ether_addr(wpa_s->p2pdev->p2ps_join_addr)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1856 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1857 | "P2PS: Setting default PIN for ANY"); |
| 1858 | wpa_supplicant_ap_wps_pin(wpa_s, NULL, |
| 1859 | "12345670", NULL, 0, |
| 1860 | 0); |
| 1861 | } else { |
| 1862 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1863 | "P2PS: Setting default PIN for " MACSTR, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1864 | MAC2STR(wpa_s->p2pdev->p2ps_join_addr)); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1865 | wpa_supplicant_ap_wps_pin( |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1866 | wpa_s, wpa_s->p2pdev->p2ps_join_addr, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1867 | "12345670", NULL, 0, 0); |
| 1868 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1869 | wpa_s->p2pdev->p2ps_method_config_any = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1870 | } |
| 1871 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1872 | os_get_reltime(&wpa_s->global->p2p_go_wait_client); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1873 | if (params->persistent_group) { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1874 | wpas_p2p_store_persistent_group( |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1875 | wpa_s->p2pdev, ssid, |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 1876 | wpa_s->global->p2p_dev_addr); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1877 | wpas_p2p_add_psk_list(wpa_s, ssid); |
| 1878 | } |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1879 | |
| 1880 | wpas_notify_p2p_group_started(wpa_s, ssid, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1881 | params->persistent_group, 0, |
| 1882 | NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1883 | wpas_p2p_cross_connect_setup(wpa_s); |
| 1884 | wpas_p2p_set_group_idle_timeout(wpa_s); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1885 | |
| 1886 | if (wpa_s->p2p_first_connection_timeout) { |
| 1887 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1888 | "P2P: Start group formation timeout of %d seconds until first data connection on GO", |
| 1889 | wpa_s->p2p_first_connection_timeout); |
| 1890 | wpa_s->p2p_go_group_formation_completed = 0; |
| 1891 | wpa_s->global->p2p_group_formation = wpa_s; |
| 1892 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1893 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1894 | eloop_register_timeout( |
| 1895 | wpa_s->p2p_first_connection_timeout, 0, |
| 1896 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1897 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1898 | } |
| 1899 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1900 | return; |
| 1901 | } |
| 1902 | |
| 1903 | wpa_printf(MSG_DEBUG, "P2P: Setting up WPS for GO provisioning"); |
| 1904 | if (wpa_supplicant_ap_mac_addr_filter(wpa_s, |
| 1905 | params->peer_interface_addr)) { |
| 1906 | wpa_printf(MSG_DEBUG, "P2P: Failed to setup MAC address " |
| 1907 | "filtering"); |
| 1908 | return; |
| 1909 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1910 | if (params->wps_method == WPS_PBC) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1911 | wpa_supplicant_ap_wps_pbc(wpa_s, params->peer_interface_addr, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1912 | params->peer_device_addr); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1913 | #ifdef CONFIG_WPS_NFC |
| 1914 | } else if (params->wps_method == WPS_NFC) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1915 | if (wpa_s->p2pdev->p2p_oob_dev_pw_id != |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1916 | DEV_PW_NFC_CONNECTION_HANDOVER && |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1917 | !wpa_s->p2pdev->p2p_oob_dev_pw) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1918 | wpa_printf(MSG_DEBUG, "P2P: No NFC Dev Pw known"); |
| 1919 | return; |
| 1920 | } |
| 1921 | wpas_ap_wps_add_nfc_pw( |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1922 | wpa_s, wpa_s->p2pdev->p2p_oob_dev_pw_id, |
| 1923 | wpa_s->p2pdev->p2p_oob_dev_pw, |
| 1924 | wpa_s->p2pdev->p2p_peer_oob_pk_hash_known ? |
| 1925 | wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : NULL); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1926 | #endif /* CONFIG_WPS_NFC */ |
| 1927 | } else if (wpa_s->p2p_pin[0]) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1928 | wpa_supplicant_ap_wps_pin(wpa_s, params->peer_interface_addr, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1929 | wpa_s->p2p_pin, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1930 | os_free(wpa_s->go_params); |
| 1931 | wpa_s->go_params = NULL; |
| 1932 | } |
| 1933 | |
| 1934 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1935 | /** |
| 1936 | * wpas_p2p_freq_to_edmg_channel - Convert frequency into EDMG channel |
| 1937 | * @freq: Frequency (MHz) to convert |
| 1938 | * @op_class: Buffer for returning operating class |
| 1939 | * @op_edmg_channel: Buffer for returning channel number |
| 1940 | * Returns: 0 on success, -1 on failure |
| 1941 | * |
| 1942 | * This can be used to find the highest channel bonding which includes the |
| 1943 | * specified frequency. |
| 1944 | */ |
| 1945 | static int wpas_p2p_freq_to_edmg_channel(struct wpa_supplicant *wpa_s, |
| 1946 | unsigned int freq, |
| 1947 | u8 *op_class, u8 *op_edmg_channel) |
| 1948 | { |
| 1949 | struct hostapd_hw_modes *hwmode; |
| 1950 | struct ieee80211_edmg_config edmg; |
| 1951 | unsigned int i; |
| 1952 | enum chan_width chanwidth[] = { |
| 1953 | CHAN_WIDTH_8640, |
| 1954 | CHAN_WIDTH_6480, |
| 1955 | CHAN_WIDTH_4320, |
| 1956 | }; |
| 1957 | |
| 1958 | if (!wpa_s->hw.modes) |
| 1959 | return -1; |
| 1960 | |
| 1961 | hwmode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1962 | HOSTAPD_MODE_IEEE80211AD, false); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1963 | if (!hwmode) { |
| 1964 | wpa_printf(MSG_ERROR, |
| 1965 | "Unsupported AP mode: HOSTAPD_MODE_IEEE80211AD"); |
| 1966 | return -1; |
| 1967 | } |
| 1968 | |
| 1969 | /* Find the highest EDMG channel bandwidth to start the P2P GO */ |
| 1970 | for (i = 0; i < ARRAY_SIZE(chanwidth); i++) { |
| 1971 | if (ieee80211_chaninfo_to_channel(freq, chanwidth[i], 0, |
| 1972 | op_class, |
| 1973 | op_edmg_channel) < 0) |
| 1974 | continue; |
| 1975 | |
| 1976 | hostapd_encode_edmg_chan(1, *op_edmg_channel, 0, &edmg); |
| 1977 | if (edmg.channels && |
| 1978 | ieee802_edmg_is_allowed(hwmode->edmg, edmg)) { |
| 1979 | wpa_printf(MSG_DEBUG, |
| 1980 | "Freq %u to EDMG channel %u at opclass %u", |
| 1981 | freq, *op_edmg_channel, *op_class); |
| 1982 | return 0; |
| 1983 | } |
| 1984 | } |
| 1985 | |
| 1986 | return -1; |
| 1987 | } |
| 1988 | |
| 1989 | |
| 1990 | int wpas_p2p_try_edmg_channel(struct wpa_supplicant *wpa_s, |
| 1991 | struct p2p_go_neg_results *params) |
| 1992 | { |
| 1993 | u8 op_channel, op_class; |
| 1994 | int freq; |
| 1995 | |
| 1996 | /* Try social channel as primary channel frequency */ |
| 1997 | freq = (!params->freq) ? 58320 + 1 * 2160 : params->freq; |
| 1998 | |
| 1999 | if (wpas_p2p_freq_to_edmg_channel(wpa_s, freq, &op_class, |
| 2000 | &op_channel) == 0) { |
| 2001 | wpa_printf(MSG_DEBUG, |
| 2002 | "Freq %d will be used to set an EDMG connection (channel=%u opclass=%u)", |
| 2003 | freq, op_channel, op_class); |
| 2004 | params->freq = freq; |
| 2005 | return 0; |
| 2006 | } |
| 2007 | |
| 2008 | return -1; |
| 2009 | } |
| 2010 | |
| 2011 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2012 | static void wpas_start_wps_go(struct wpa_supplicant *wpa_s, |
| 2013 | struct p2p_go_neg_results *params, |
| 2014 | int group_formation) |
| 2015 | { |
| 2016 | struct wpa_ssid *ssid; |
| 2017 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2018 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Starting GO"); |
| 2019 | if (wpas_copy_go_neg_results(wpa_s, params) < 0) { |
| 2020 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not copy GO Negotiation " |
| 2021 | "results"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2022 | return; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2023 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2024 | |
| 2025 | ssid = wpa_config_add_network(wpa_s->conf); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2026 | if (ssid == NULL) { |
| 2027 | 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] | 2028 | return; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2029 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2030 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2031 | wpa_s->show_group_started = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2032 | wpa_s->p2p_go_group_formation_completed = 0; |
| 2033 | wpa_s->group_formation_reported = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2034 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2035 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2036 | wpa_config_set_network_defaults(ssid); |
| 2037 | ssid->temporary = 1; |
| 2038 | ssid->p2p_group = 1; |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 2039 | ssid->p2p_persistent_group = !!params->persistent_group; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2040 | ssid->mode = group_formation ? WPAS_MODE_P2P_GROUP_FORMATION : |
| 2041 | WPAS_MODE_P2P_GO; |
| 2042 | ssid->frequency = params->freq; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2043 | ssid->ht40 = params->ht40; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2044 | ssid->vht = params->vht; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 2045 | ssid->max_oper_chwidth = params->max_oper_chwidth; |
| 2046 | ssid->vht_center_freq2 = params->vht_center_freq2; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2047 | ssid->he = params->he; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2048 | if (params->edmg) { |
| 2049 | u8 op_channel, op_class; |
| 2050 | |
| 2051 | if (!wpas_p2p_freq_to_edmg_channel(wpa_s, params->freq, |
| 2052 | &op_class, &op_channel)) { |
| 2053 | ssid->edmg_channel = op_channel; |
| 2054 | ssid->enable_edmg = params->edmg; |
| 2055 | } else { |
| 2056 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2057 | "P2P: Could not match EDMG channel, freq %d, for GO", |
| 2058 | params->freq); |
| 2059 | } |
| 2060 | } |
| 2061 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2062 | ssid->ssid = os_zalloc(params->ssid_len + 1); |
| 2063 | if (ssid->ssid) { |
| 2064 | os_memcpy(ssid->ssid, params->ssid, params->ssid_len); |
| 2065 | ssid->ssid_len = params->ssid_len; |
| 2066 | } |
| 2067 | ssid->auth_alg = WPA_AUTH_ALG_OPEN; |
| 2068 | ssid->key_mgmt = WPA_KEY_MGMT_PSK; |
| 2069 | ssid->proto = WPA_PROTO_RSN; |
| 2070 | ssid->pairwise_cipher = WPA_CIPHER_CCMP; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2071 | ssid->group_cipher = WPA_CIPHER_CCMP; |
| 2072 | if (params->freq > 56160) { |
| 2073 | /* |
| 2074 | * Enable GCMP instead of CCMP as pairwise_cipher and |
| 2075 | * group_cipher in 60 GHz. |
| 2076 | */ |
| 2077 | ssid->pairwise_cipher = WPA_CIPHER_GCMP; |
| 2078 | ssid->group_cipher = WPA_CIPHER_GCMP; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2079 | /* P2P GO in 60 GHz is always a PCP (PBSS) */ |
| 2080 | ssid->pbss = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2081 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2082 | if (os_strlen(params->passphrase) > 0) { |
| 2083 | ssid->passphrase = os_strdup(params->passphrase); |
| 2084 | if (ssid->passphrase == NULL) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2085 | wpa_msg_global(wpa_s, MSG_ERROR, |
| 2086 | "P2P: Failed to copy passphrase for GO"); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2087 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 2088 | return; |
| 2089 | } |
| 2090 | } else |
| 2091 | ssid->passphrase = NULL; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2092 | ssid->psk_set = params->psk_set; |
| 2093 | if (ssid->psk_set) |
| 2094 | os_memcpy(ssid->psk, params->psk, sizeof(ssid->psk)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2095 | else if (ssid->passphrase) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2096 | wpa_config_update_psk(ssid); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2097 | ssid->ap_max_inactivity = wpa_s->p2pdev->conf->p2p_go_max_inactivity; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2098 | |
| 2099 | wpa_s->ap_configured_cb = p2p_go_configured; |
| 2100 | wpa_s->ap_configured_cb_ctx = wpa_s; |
| 2101 | wpa_s->ap_configured_cb_data = wpa_s->go_params; |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 2102 | wpa_s->scan_req = NORMAL_SCAN_REQ; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2103 | wpa_s->connect_without_scan = ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2104 | wpa_s->reassociate = 1; |
| 2105 | wpa_s->disconnected = 0; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2106 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Request scan (that will be skipped) to " |
| 2107 | "start GO)"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2108 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 2109 | } |
| 2110 | |
| 2111 | |
| 2112 | static void wpas_p2p_clone_config(struct wpa_supplicant *dst, |
| 2113 | const struct wpa_supplicant *src) |
| 2114 | { |
| 2115 | struct wpa_config *d; |
| 2116 | const struct wpa_config *s; |
| 2117 | |
| 2118 | d = dst->conf; |
| 2119 | s = src->conf; |
| 2120 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2121 | #define C(n) \ |
| 2122 | do { \ |
| 2123 | if (s->n && !d->n) \ |
| 2124 | d->n = os_strdup(s->n); \ |
| 2125 | } while (0) |
| 2126 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2127 | C(device_name); |
| 2128 | C(manufacturer); |
| 2129 | C(model_name); |
| 2130 | C(model_number); |
| 2131 | C(serial_number); |
| 2132 | C(config_methods); |
| 2133 | #undef C |
| 2134 | |
| 2135 | os_memcpy(d->device_type, s->device_type, WPS_DEV_TYPE_LEN); |
| 2136 | os_memcpy(d->sec_device_type, s->sec_device_type, |
| 2137 | sizeof(d->sec_device_type)); |
| 2138 | d->num_sec_device_types = s->num_sec_device_types; |
| 2139 | |
| 2140 | d->p2p_group_idle = s->p2p_group_idle; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2141 | d->p2p_go_freq_change_policy = s->p2p_go_freq_change_policy; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2142 | d->p2p_intra_bss = s->p2p_intra_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2143 | d->persistent_reconnect = s->persistent_reconnect; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2144 | d->max_num_sta = s->max_num_sta; |
| 2145 | d->pbc_in_m1 = s->pbc_in_m1; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2146 | d->ignore_old_scan_res = s->ignore_old_scan_res; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 2147 | d->beacon_int = s->beacon_int; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2148 | d->dtim_period = s->dtim_period; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2149 | d->p2p_go_ctwindow = s->p2p_go_ctwindow; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2150 | d->disassoc_low_ack = s->disassoc_low_ack; |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 2151 | d->disable_scan_offload = s->disable_scan_offload; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2152 | d->passive_scan = s->passive_scan; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2153 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2154 | if (s->wps_nfc_dh_privkey && s->wps_nfc_dh_pubkey && |
| 2155 | !d->wps_nfc_pw_from_config) { |
| 2156 | wpabuf_free(d->wps_nfc_dh_privkey); |
| 2157 | wpabuf_free(d->wps_nfc_dh_pubkey); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2158 | d->wps_nfc_dh_privkey = wpabuf_dup(s->wps_nfc_dh_privkey); |
| 2159 | d->wps_nfc_dh_pubkey = wpabuf_dup(s->wps_nfc_dh_pubkey); |
| 2160 | } |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2161 | d->p2p_cli_probe = s->p2p_cli_probe; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2162 | d->go_interworking = s->go_interworking; |
| 2163 | d->go_access_network_type = s->go_access_network_type; |
| 2164 | d->go_internet = s->go_internet; |
| 2165 | d->go_venue_group = s->go_venue_group; |
| 2166 | d->go_venue_type = s->go_venue_type; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2167 | d->p2p_add_cli_chan = s->p2p_add_cli_chan; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2168 | } |
| 2169 | |
| 2170 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2171 | static void wpas_p2p_get_group_ifname(struct wpa_supplicant *wpa_s, |
| 2172 | char *ifname, size_t len) |
| 2173 | { |
| 2174 | char *ifname_ptr = wpa_s->ifname; |
| 2175 | |
| 2176 | if (os_strncmp(wpa_s->ifname, P2P_MGMT_DEVICE_PREFIX, |
| 2177 | os_strlen(P2P_MGMT_DEVICE_PREFIX)) == 0) { |
| 2178 | ifname_ptr = os_strrchr(wpa_s->ifname, '-') + 1; |
| 2179 | } |
| 2180 | |
| 2181 | os_snprintf(ifname, len, "p2p-%s-%d", ifname_ptr, wpa_s->p2p_group_idx); |
| 2182 | if (os_strlen(ifname) >= IFNAMSIZ && |
| 2183 | os_strlen(wpa_s->ifname) < IFNAMSIZ) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2184 | int res; |
| 2185 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2186 | /* Try to avoid going over the IFNAMSIZ length limit */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2187 | res = os_snprintf(ifname, len, "p2p-%d", wpa_s->p2p_group_idx); |
| 2188 | if (os_snprintf_error(len, res) && len) |
| 2189 | ifname[len - 1] = '\0'; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2190 | } |
| 2191 | } |
| 2192 | |
| 2193 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2194 | static int wpas_p2p_add_group_interface(struct wpa_supplicant *wpa_s, |
| 2195 | enum wpa_driver_if_type type) |
| 2196 | { |
| 2197 | char ifname[120], force_ifname[120]; |
| 2198 | |
| 2199 | if (wpa_s->pending_interface_name[0]) { |
| 2200 | wpa_printf(MSG_DEBUG, "P2P: Pending virtual interface exists " |
| 2201 | "- skip creation of a new one"); |
| 2202 | if (is_zero_ether_addr(wpa_s->pending_interface_addr)) { |
| 2203 | wpa_printf(MSG_DEBUG, "P2P: Pending virtual address " |
| 2204 | "unknown?! ifname='%s'", |
| 2205 | wpa_s->pending_interface_name); |
| 2206 | return -1; |
| 2207 | } |
| 2208 | return 0; |
| 2209 | } |
| 2210 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2211 | wpas_p2p_get_group_ifname(wpa_s, ifname, sizeof(ifname)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2212 | force_ifname[0] = '\0'; |
| 2213 | |
| 2214 | wpa_printf(MSG_DEBUG, "P2P: Create a new interface %s for the group", |
| 2215 | ifname); |
| 2216 | wpa_s->p2p_group_idx++; |
| 2217 | |
| 2218 | wpa_s->pending_interface_type = type; |
| 2219 | if (wpa_drv_if_add(wpa_s, type, ifname, NULL, NULL, force_ifname, |
| 2220 | wpa_s->pending_interface_addr, NULL) < 0) { |
| 2221 | wpa_printf(MSG_ERROR, "P2P: Failed to create new group " |
| 2222 | "interface"); |
| 2223 | return -1; |
| 2224 | } |
| 2225 | |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2226 | if (wpa_s->conf->p2p_interface_random_mac_addr) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2227 | random_mac_addr(wpa_s->pending_interface_addr); |
| 2228 | wpa_printf(MSG_DEBUG, "P2P: Generate random MAC address " MACSTR |
| 2229 | " for the group", |
| 2230 | MAC2STR(wpa_s->pending_interface_addr)); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2231 | } |
| 2232 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2233 | if (force_ifname[0]) { |
| 2234 | wpa_printf(MSG_DEBUG, "P2P: Driver forced interface name %s", |
| 2235 | force_ifname); |
| 2236 | os_strlcpy(wpa_s->pending_interface_name, force_ifname, |
| 2237 | sizeof(wpa_s->pending_interface_name)); |
| 2238 | } else |
| 2239 | os_strlcpy(wpa_s->pending_interface_name, ifname, |
| 2240 | sizeof(wpa_s->pending_interface_name)); |
| 2241 | wpa_printf(MSG_DEBUG, "P2P: Created pending virtual interface %s addr " |
| 2242 | MACSTR, wpa_s->pending_interface_name, |
| 2243 | MAC2STR(wpa_s->pending_interface_addr)); |
| 2244 | |
| 2245 | return 0; |
| 2246 | } |
| 2247 | |
| 2248 | |
| 2249 | static void wpas_p2p_remove_pending_group_interface( |
| 2250 | struct wpa_supplicant *wpa_s) |
| 2251 | { |
| 2252 | if (!wpa_s->pending_interface_name[0] || |
| 2253 | is_zero_ether_addr(wpa_s->pending_interface_addr)) |
| 2254 | return; /* No pending virtual interface */ |
| 2255 | |
| 2256 | wpa_printf(MSG_DEBUG, "P2P: Removing pending group interface %s", |
| 2257 | wpa_s->pending_interface_name); |
| 2258 | wpa_drv_if_remove(wpa_s, wpa_s->pending_interface_type, |
| 2259 | wpa_s->pending_interface_name); |
| 2260 | os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN); |
| 2261 | wpa_s->pending_interface_name[0] = '\0'; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2262 | wpa_s->global->pending_group_iface_for_p2ps = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
| 2265 | |
| 2266 | static struct wpa_supplicant * |
| 2267 | wpas_p2p_init_group_interface(struct wpa_supplicant *wpa_s, int go) |
| 2268 | { |
| 2269 | struct wpa_interface iface; |
| 2270 | struct wpa_supplicant *group_wpa_s; |
| 2271 | |
| 2272 | if (!wpa_s->pending_interface_name[0]) { |
| 2273 | wpa_printf(MSG_ERROR, "P2P: No pending group interface"); |
| 2274 | if (!wpas_p2p_create_iface(wpa_s)) |
| 2275 | return NULL; |
| 2276 | /* |
| 2277 | * Something has forced us to remove the pending interface; try |
| 2278 | * to create a new one and hope for the best that we will get |
| 2279 | * the same local address. |
| 2280 | */ |
| 2281 | if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO : |
| 2282 | WPA_IF_P2P_CLIENT) < 0) |
| 2283 | return NULL; |
| 2284 | } |
| 2285 | |
| 2286 | os_memset(&iface, 0, sizeof(iface)); |
| 2287 | iface.ifname = wpa_s->pending_interface_name; |
| 2288 | iface.driver = wpa_s->driver->name; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2289 | if (wpa_s->conf->ctrl_interface == NULL && |
| 2290 | wpa_s->parent != wpa_s && |
| 2291 | wpa_s->p2p_mgmt && |
| 2292 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) |
| 2293 | iface.ctrl_interface = wpa_s->parent->conf->ctrl_interface; |
| 2294 | else |
| 2295 | iface.ctrl_interface = wpa_s->conf->ctrl_interface; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2296 | iface.driver_param = wpa_s->conf->driver_param; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 2297 | 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] | 2298 | if (group_wpa_s == NULL) { |
| 2299 | wpa_printf(MSG_ERROR, "P2P: Failed to create new " |
| 2300 | "wpa_supplicant interface"); |
| 2301 | return NULL; |
| 2302 | } |
| 2303 | wpa_s->pending_interface_name[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2304 | group_wpa_s->p2p_group_interface = go ? P2P_GROUP_INTERFACE_GO : |
| 2305 | P2P_GROUP_INTERFACE_CLIENT; |
| 2306 | wpa_s->global->p2p_group_formation = group_wpa_s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2307 | wpa_s->global->pending_group_iface_for_p2ps = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2308 | |
| 2309 | wpas_p2p_clone_config(group_wpa_s, wpa_s); |
| 2310 | |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2311 | if (wpa_s->conf->p2p_interface_random_mac_addr) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2312 | if (wpa_drv_set_mac_addr(group_wpa_s, |
| 2313 | wpa_s->pending_interface_addr) < 0) { |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2314 | wpa_msg(group_wpa_s, MSG_INFO, |
| 2315 | "Failed to set random MAC address"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2316 | wpa_supplicant_remove_iface(wpa_s->global, group_wpa_s, |
| 2317 | 0); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2318 | return NULL; |
| 2319 | } |
| 2320 | |
| 2321 | if (wpa_supplicant_update_mac_addr(group_wpa_s) < 0) { |
| 2322 | wpa_msg(group_wpa_s, MSG_INFO, |
| 2323 | "Could not update MAC address information"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2324 | wpa_supplicant_remove_iface(wpa_s->global, group_wpa_s, |
| 2325 | 0); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2326 | return NULL; |
| 2327 | } |
| 2328 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2329 | wpa_printf(MSG_DEBUG, "P2P: Using random MAC address " MACSTR |
| 2330 | " for the group", |
| 2331 | MAC2STR(wpa_s->pending_interface_addr)); |
Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2332 | } |
| 2333 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2334 | return group_wpa_s; |
| 2335 | } |
| 2336 | |
| 2337 | |
| 2338 | static void wpas_p2p_group_formation_timeout(void *eloop_ctx, |
| 2339 | void *timeout_ctx) |
| 2340 | { |
| 2341 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 2342 | wpa_printf(MSG_DEBUG, "P2P: Group Formation timed out"); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2343 | wpas_p2p_group_formation_failed(wpa_s, 0); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2347 | static void wpas_p2p_group_formation_failed(struct wpa_supplicant *wpa_s, |
| 2348 | int already_deleted) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2349 | { |
| 2350 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2351 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2352 | if (wpa_s->global->p2p) |
| 2353 | p2p_group_formation_failed(wpa_s->global->p2p); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2354 | wpas_group_formation_completed(wpa_s, 0, already_deleted); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2358 | static void wpas_p2p_grpform_fail_after_wps(struct wpa_supplicant *wpa_s) |
| 2359 | { |
| 2360 | wpa_printf(MSG_DEBUG, "P2P: Reject group formation due to WPS provisioning failure"); |
| 2361 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2362 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2363 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2364 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2365 | wpa_s->global->p2p_fail_on_wps_complete = 0; |
| 2366 | } |
| 2367 | |
| 2368 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2369 | void wpas_p2p_ap_setup_failed(struct wpa_supplicant *wpa_s) |
| 2370 | { |
| 2371 | if (wpa_s->global->p2p_group_formation != wpa_s) |
| 2372 | return; |
| 2373 | /* Speed up group formation timeout since this cannot succeed */ |
| 2374 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2375 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2376 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2377 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2381 | 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] | 2382 | { |
| 2383 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2384 | struct wpa_supplicant *group_wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2385 | |
| 2386 | if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) { |
| 2387 | wpa_drv_cancel_remain_on_channel(wpa_s); |
| 2388 | wpa_s->off_channel_freq = 0; |
| 2389 | wpa_s->roc_waiting_drv_freq = 0; |
| 2390 | } |
| 2391 | |
| 2392 | if (res->status) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2393 | wpa_msg_global(wpa_s, MSG_INFO, |
| 2394 | P2P_EVENT_GO_NEG_FAILURE "status=%d", |
| 2395 | res->status); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2396 | wpas_notify_p2p_go_neg_completed(wpa_s, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2397 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 2398 | return; |
| 2399 | } |
| 2400 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2401 | if (!res->role_go) { |
| 2402 | /* Inform driver of the operating channel of GO. */ |
| 2403 | wpa_drv_set_prob_oper_freq(wpa_s, res->freq); |
| 2404 | } |
| 2405 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2406 | if (wpa_s->p2p_go_ht40) |
| 2407 | res->ht40 = 1; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2408 | if (wpa_s->p2p_go_vht) |
| 2409 | res->vht = 1; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2410 | if (wpa_s->p2p_go_he) |
| 2411 | res->he = 1; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2412 | if (wpa_s->p2p_go_edmg) |
| 2413 | res->edmg = 1; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 2414 | res->max_oper_chwidth = wpa_s->p2p_go_max_oper_chwidth; |
| 2415 | res->vht_center_freq2 = wpa_s->p2p_go_vht_center_freq2; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2416 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2417 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_SUCCESS "role=%s " |
| 2418 | "freq=%d ht40=%d peer_dev=" MACSTR " peer_iface=" MACSTR |
| 2419 | " wps_method=%s", |
| 2420 | res->role_go ? "GO" : "client", res->freq, res->ht40, |
| 2421 | MAC2STR(res->peer_device_addr), |
| 2422 | MAC2STR(res->peer_interface_addr), |
| 2423 | p2p_wps_method_text(res->wps_method)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2424 | wpas_notify_p2p_go_neg_completed(wpa_s, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2425 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2426 | if (res->role_go && wpa_s->p2p_persistent_id >= 0) { |
| 2427 | struct wpa_ssid *ssid; |
| 2428 | ssid = wpa_config_get_network(wpa_s->conf, |
| 2429 | wpa_s->p2p_persistent_id); |
| 2430 | if (ssid && ssid->disabled == 2 && |
| 2431 | ssid->mode == WPAS_MODE_P2P_GO && ssid->passphrase) { |
| 2432 | size_t len = os_strlen(ssid->passphrase); |
| 2433 | wpa_printf(MSG_DEBUG, "P2P: Override passphrase based " |
| 2434 | "on requested persistent group"); |
| 2435 | os_memcpy(res->passphrase, ssid->passphrase, len); |
| 2436 | res->passphrase[len] = '\0'; |
| 2437 | } |
| 2438 | } |
| 2439 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2440 | if (wpa_s->create_p2p_iface) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2441 | group_wpa_s = |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2442 | wpas_p2p_init_group_interface(wpa_s, res->role_go); |
| 2443 | if (group_wpa_s == NULL) { |
| 2444 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 2445 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, |
| 2446 | wpa_s, NULL); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2447 | wpas_p2p_group_formation_failed(wpa_s, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2448 | return; |
| 2449 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2450 | os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN); |
| 2451 | wpa_s->pending_interface_name[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2452 | } else { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2453 | group_wpa_s = wpa_s->parent; |
| 2454 | wpa_s->global->p2p_group_formation = group_wpa_s; |
| 2455 | if (group_wpa_s != wpa_s) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2456 | wpas_p2p_clone_config(group_wpa_s, wpa_s); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2457 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2458 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2459 | group_wpa_s->p2p_in_provisioning = 1; |
| 2460 | group_wpa_s->p2pdev = wpa_s; |
| 2461 | if (group_wpa_s != wpa_s) { |
| 2462 | os_memcpy(group_wpa_s->p2p_pin, wpa_s->p2p_pin, |
| 2463 | sizeof(group_wpa_s->p2p_pin)); |
| 2464 | group_wpa_s->p2p_wps_method = wpa_s->p2p_wps_method; |
| 2465 | } |
| 2466 | if (res->role_go) { |
| 2467 | wpas_start_wps_go(group_wpa_s, res, 1); |
| 2468 | } else { |
| 2469 | os_get_reltime(&group_wpa_s->scan_min_time); |
| 2470 | wpas_start_wps_enrollee(group_wpa_s, res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2471 | } |
| 2472 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2473 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2474 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
| 2475 | |
| 2476 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 2477 | eloop_register_timeout(15 + res->peer_config_timeout / 100, |
| 2478 | (res->peer_config_timeout % 100) * 10000, |
| 2479 | wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 2480 | } |
| 2481 | |
| 2482 | |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 2483 | static void wpas_go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id, |
| 2484 | u8 go_intent) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2485 | { |
| 2486 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2487 | 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] | 2488 | " dev_passwd_id=%u go_intent=%u", MAC2STR(src), |
| 2489 | dev_passwd_id, go_intent); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2490 | |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 2491 | 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] | 2492 | } |
| 2493 | |
| 2494 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2495 | static void wpas_dev_found(void *ctx, const u8 *addr, |
| 2496 | const struct p2p_peer_info *info, |
| 2497 | int new_device) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2498 | { |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2499 | u8 *wfd_dev_info = NULL; |
| 2500 | u8 wfd_dev_info_len = 0; |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2501 | u8 *wfd_r2_dev_info = NULL; |
Jimmy Chen | 57e19f5 | 2021-03-04 14:19:52 +0800 | [diff] [blame] | 2502 | u8 wfd_r2_dev_info_len = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2503 | #ifndef CONFIG_NO_STDOUT_DEBUG |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2504 | struct wpa_supplicant *wpa_s = ctx; |
| 2505 | char devtype[WPS_DEV_TYPE_BUFSIZE]; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2506 | char *wfd_dev_info_hex = NULL; |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2507 | char *wfd_r2_dev_info_hex = NULL; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2508 | |
Irfan Sheriff | 8367dc9 | 2012-09-09 17:08:19 -0700 | [diff] [blame] | 2509 | #ifdef CONFIG_WIFI_DISPLAY |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2510 | wfd_dev_info_hex = wifi_display_subelem_hex(info->wfd_subelems, |
| 2511 | WFD_SUBELEM_DEVICE_INFO); |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2512 | if (wfd_dev_info_hex) { |
| 2513 | wfd_dev_info_len = strlen(wfd_dev_info_hex) / 2; |
| 2514 | wfd_dev_info = os_zalloc(wfd_dev_info_len); |
| 2515 | // Only used for notification, so not handling error. |
| 2516 | hexstr2bin(wfd_dev_info_hex, wfd_dev_info, wfd_dev_info_len); |
| 2517 | } |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2518 | |
| 2519 | wfd_r2_dev_info_hex = wifi_display_subelem_hex(info->wfd_subelems, |
| 2520 | WFD_SUBELEM_R2_DEVICE_INFO); |
| 2521 | if (wfd_r2_dev_info_hex) { |
| 2522 | wfd_r2_dev_info_len = strlen(wfd_r2_dev_info_hex) / 2; |
| 2523 | wfd_r2_dev_info = os_zalloc(wfd_r2_dev_info_len); |
| 2524 | // Only used for notification, so not handling error. |
| 2525 | hexstr2bin(wfd_r2_dev_info_hex, wfd_r2_dev_info, wfd_r2_dev_info_len); |
| 2526 | } |
Irfan Sheriff | 8367dc9 | 2012-09-09 17:08:19 -0700 | [diff] [blame] | 2527 | #endif /* CONFIG_WIFI_DISPLAY */ |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2528 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2529 | if (info->p2ps_instance) { |
| 2530 | char str[256]; |
| 2531 | const u8 *buf = wpabuf_head(info->p2ps_instance); |
| 2532 | size_t len = wpabuf_len(info->p2ps_instance); |
| 2533 | |
| 2534 | while (len) { |
| 2535 | u32 id; |
| 2536 | u16 methods; |
| 2537 | u8 str_len; |
| 2538 | |
| 2539 | if (len < 4 + 2 + 1) |
| 2540 | break; |
| 2541 | id = WPA_GET_LE32(buf); |
| 2542 | buf += sizeof(u32); |
| 2543 | methods = WPA_GET_BE16(buf); |
| 2544 | buf += sizeof(u16); |
| 2545 | str_len = *buf++; |
| 2546 | if (str_len > len - 4 - 2 - 1) |
| 2547 | break; |
| 2548 | os_memcpy(str, buf, str_len); |
| 2549 | str[str_len] = '\0'; |
| 2550 | buf += str_len; |
| 2551 | len -= str_len + sizeof(u32) + sizeof(u16) + sizeof(u8); |
| 2552 | |
| 2553 | wpa_msg_global(wpa_s, MSG_INFO, |
| 2554 | P2P_EVENT_DEVICE_FOUND MACSTR |
| 2555 | " p2p_dev_addr=" MACSTR |
| 2556 | " pri_dev_type=%s name='%s'" |
| 2557 | " config_methods=0x%x" |
| 2558 | " dev_capab=0x%x" |
| 2559 | " group_capab=0x%x" |
| 2560 | " adv_id=%x asp_svc=%s%s", |
| 2561 | MAC2STR(addr), |
| 2562 | MAC2STR(info->p2p_device_addr), |
| 2563 | wps_dev_type_bin2str( |
| 2564 | info->pri_dev_type, |
| 2565 | devtype, sizeof(devtype)), |
| 2566 | info->device_name, methods, |
| 2567 | info->dev_capab, info->group_capab, |
| 2568 | id, str, |
| 2569 | info->vendor_elems ? |
| 2570 | " vendor_elems=1" : ""); |
| 2571 | } |
| 2572 | goto done; |
| 2573 | } |
| 2574 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2575 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_FOUND MACSTR |
| 2576 | " p2p_dev_addr=" MACSTR |
| 2577 | " pri_dev_type=%s name='%s' config_methods=0x%x " |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2578 | "dev_capab=0x%x group_capab=0x%x%s%s%s%s%s new=%d", |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2579 | MAC2STR(addr), MAC2STR(info->p2p_device_addr), |
| 2580 | wps_dev_type_bin2str(info->pri_dev_type, devtype, |
| 2581 | sizeof(devtype)), |
| 2582 | info->device_name, info->config_methods, |
| 2583 | info->dev_capab, info->group_capab, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2584 | wfd_dev_info_hex ? " wfd_dev_info=0x" : "", |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 2585 | wfd_dev_info_hex ? wfd_dev_info_hex : "", |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2586 | wfd_r2_dev_info_hex ? " wfd_r2_dev_info=0x" : "", |
| 2587 | wfd_r2_dev_info_hex ? wfd_r2_dev_info_hex : "", |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2588 | info->vendor_elems ? " vendor_elems=1" : "", |
| 2589 | new_device); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2590 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2591 | done: |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2592 | os_free(wfd_dev_info_hex); |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2593 | os_free(wfd_r2_dev_info_hex); |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 2594 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2595 | |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2596 | wpas_notify_p2p_device_found(ctx, addr, info, wfd_dev_info, |
Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2597 | wfd_dev_info_len, wfd_r2_dev_info, |
| 2598 | wfd_r2_dev_info_len, new_device); |
Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2599 | os_free(wfd_dev_info); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | |
| 2603 | static void wpas_dev_lost(void *ctx, const u8 *dev_addr) |
| 2604 | { |
| 2605 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2606 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2607 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_LOST |
| 2608 | "p2p_dev_addr=" MACSTR, MAC2STR(dev_addr)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2609 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2610 | wpas_notify_p2p_device_lost(wpa_s, dev_addr); |
| 2611 | } |
| 2612 | |
| 2613 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2614 | static void wpas_find_stopped(void *ctx) |
| 2615 | { |
| 2616 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2617 | |
| 2618 | if (wpa_s->p2p_scan_work && wpas_abort_ongoing_scan(wpa_s) < 0) |
| 2619 | wpa_printf(MSG_DEBUG, "P2P: Abort ongoing scan failed"); |
| 2620 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2621 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_FIND_STOPPED); |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 2622 | wpas_notify_p2p_find_stopped(wpa_s); |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2626 | struct wpas_p2p_listen_work { |
| 2627 | unsigned int freq; |
| 2628 | unsigned int duration; |
| 2629 | struct wpabuf *probe_resp_ie; |
| 2630 | }; |
| 2631 | |
| 2632 | |
| 2633 | static void wpas_p2p_listen_work_free(struct wpas_p2p_listen_work *lwork) |
| 2634 | { |
| 2635 | if (lwork == NULL) |
| 2636 | return; |
| 2637 | wpabuf_free(lwork->probe_resp_ie); |
| 2638 | os_free(lwork); |
| 2639 | } |
| 2640 | |
| 2641 | |
| 2642 | static void wpas_p2p_listen_work_done(struct wpa_supplicant *wpa_s) |
| 2643 | { |
| 2644 | struct wpas_p2p_listen_work *lwork; |
| 2645 | |
| 2646 | if (!wpa_s->p2p_listen_work) |
| 2647 | return; |
| 2648 | |
| 2649 | lwork = wpa_s->p2p_listen_work->ctx; |
| 2650 | wpas_p2p_listen_work_free(lwork); |
| 2651 | radio_work_done(wpa_s->p2p_listen_work); |
| 2652 | wpa_s->p2p_listen_work = NULL; |
| 2653 | } |
| 2654 | |
| 2655 | |
| 2656 | static void wpas_start_listen_cb(struct wpa_radio_work *work, int deinit) |
| 2657 | { |
| 2658 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 2659 | struct wpas_p2p_listen_work *lwork = work->ctx; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2660 | unsigned int duration; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2661 | |
| 2662 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 2663 | if (work->started) { |
| 2664 | wpa_s->p2p_listen_work = NULL; |
| 2665 | wpas_stop_listen(wpa_s); |
| 2666 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2667 | wpas_p2p_listen_work_free(lwork); |
| 2668 | return; |
| 2669 | } |
| 2670 | |
| 2671 | wpa_s->p2p_listen_work = work; |
| 2672 | |
| 2673 | wpa_drv_set_ap_wps_ie(wpa_s, NULL, lwork->probe_resp_ie, NULL); |
| 2674 | |
| 2675 | if (wpa_drv_probe_req_report(wpa_s, 1) < 0) { |
| 2676 | wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver to " |
| 2677 | "report received Probe Request frames"); |
| 2678 | wpas_p2p_listen_work_done(wpa_s); |
| 2679 | return; |
| 2680 | } |
| 2681 | |
| 2682 | wpa_s->pending_listen_freq = lwork->freq; |
| 2683 | wpa_s->pending_listen_duration = lwork->duration; |
| 2684 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2685 | duration = lwork->duration; |
| 2686 | #ifdef CONFIG_TESTING_OPTIONS |
| 2687 | if (wpa_s->extra_roc_dur) { |
| 2688 | wpa_printf(MSG_DEBUG, "TESTING: Increase ROC duration %u -> %u", |
| 2689 | duration, duration + wpa_s->extra_roc_dur); |
| 2690 | duration += wpa_s->extra_roc_dur; |
| 2691 | } |
| 2692 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2693 | |
| 2694 | if (wpa_drv_remain_on_channel(wpa_s, lwork->freq, duration) < 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2695 | wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver " |
| 2696 | "to remain on channel (%u MHz) for Listen " |
| 2697 | "state", lwork->freq); |
| 2698 | wpas_p2p_listen_work_done(wpa_s); |
| 2699 | wpa_s->pending_listen_freq = 0; |
| 2700 | return; |
| 2701 | } |
| 2702 | wpa_s->off_channel_freq = 0; |
| 2703 | wpa_s->roc_waiting_drv_freq = lwork->freq; |
| 2704 | } |
| 2705 | |
| 2706 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2707 | static int wpas_start_listen(void *ctx, unsigned int freq, |
| 2708 | unsigned int duration, |
| 2709 | const struct wpabuf *probe_resp_ie) |
| 2710 | { |
| 2711 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2712 | struct wpas_p2p_listen_work *lwork; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2713 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2714 | if (wpa_s->p2p_listen_work) { |
| 2715 | 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] | 2716 | return -1; |
| 2717 | } |
| 2718 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2719 | lwork = os_zalloc(sizeof(*lwork)); |
| 2720 | if (lwork == NULL) |
| 2721 | return -1; |
| 2722 | lwork->freq = freq; |
| 2723 | lwork->duration = duration; |
| 2724 | if (probe_resp_ie) { |
| 2725 | lwork->probe_resp_ie = wpabuf_dup(probe_resp_ie); |
| 2726 | if (lwork->probe_resp_ie == NULL) { |
| 2727 | wpas_p2p_listen_work_free(lwork); |
| 2728 | return -1; |
| 2729 | } |
| 2730 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2731 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2732 | if (radio_add_work(wpa_s, freq, "p2p-listen", 0, wpas_start_listen_cb, |
| 2733 | lwork) < 0) { |
| 2734 | wpas_p2p_listen_work_free(lwork); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2735 | return -1; |
| 2736 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2737 | |
| 2738 | return 0; |
| 2739 | } |
| 2740 | |
| 2741 | |
| 2742 | static void wpas_stop_listen(void *ctx) |
| 2743 | { |
| 2744 | struct wpa_supplicant *wpa_s = ctx; |
| 2745 | if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) { |
| 2746 | wpa_drv_cancel_remain_on_channel(wpa_s); |
| 2747 | wpa_s->off_channel_freq = 0; |
| 2748 | wpa_s->roc_waiting_drv_freq = 0; |
| 2749 | } |
| 2750 | wpa_drv_set_ap_wps_ie(wpa_s, NULL, NULL, NULL); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2751 | |
| 2752 | /* |
| 2753 | * Don't cancel Probe Request RX reporting for a connected P2P Client |
| 2754 | * handling Probe Request frames. |
| 2755 | */ |
| 2756 | if (!wpa_s->p2p_cli_probe) |
| 2757 | wpa_drv_probe_req_report(wpa_s, 0); |
| 2758 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2759 | wpas_p2p_listen_work_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2763 | static int wpas_send_probe_resp(void *ctx, const struct wpabuf *buf, |
| 2764 | unsigned int freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2765 | { |
| 2766 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2767 | 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] | 2768 | freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2769 | } |
| 2770 | |
| 2771 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2772 | static void wpas_prov_disc_local_display(struct wpa_supplicant *wpa_s, |
| 2773 | const u8 *peer, const char *params, |
| 2774 | unsigned int generated_pin) |
| 2775 | { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2776 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR |
| 2777 | " %08d%s", MAC2STR(peer), generated_pin, params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2778 | } |
| 2779 | |
| 2780 | |
| 2781 | static void wpas_prov_disc_local_keypad(struct wpa_supplicant *wpa_s, |
| 2782 | const u8 *peer, const char *params) |
| 2783 | { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2784 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR |
| 2785 | "%s", MAC2STR(peer), params); |
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_prov_disc_req(void *ctx, const u8 *peer, u16 config_methods, |
| 2790 | const u8 *dev_addr, const u8 *pri_dev_type, |
| 2791 | const char *dev_name, u16 supp_config_methods, |
| 2792 | u8 dev_capab, u8 group_capab, const u8 *group_id, |
| 2793 | size_t group_id_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2794 | { |
| 2795 | struct wpa_supplicant *wpa_s = ctx; |
| 2796 | char devtype[WPS_DEV_TYPE_BUFSIZE]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2797 | char params[300]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2798 | u8 empty_dev_type[8]; |
| 2799 | unsigned int generated_pin = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2800 | struct wpa_supplicant *group = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2801 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2802 | |
| 2803 | if (group_id) { |
| 2804 | for (group = wpa_s->global->ifaces; group; group = group->next) |
| 2805 | { |
| 2806 | struct wpa_ssid *s = group->current_ssid; |
| 2807 | if (s != NULL && |
| 2808 | s->mode == WPAS_MODE_P2P_GO && |
| 2809 | group_id_len - ETH_ALEN == s->ssid_len && |
| 2810 | os_memcmp(group_id + ETH_ALEN, s->ssid, |
| 2811 | s->ssid_len) == 0) |
| 2812 | break; |
| 2813 | } |
| 2814 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2815 | |
| 2816 | if (pri_dev_type == NULL) { |
| 2817 | os_memset(empty_dev_type, 0, sizeof(empty_dev_type)); |
| 2818 | pri_dev_type = empty_dev_type; |
| 2819 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2820 | res = os_snprintf(params, sizeof(params), " p2p_dev_addr=" MACSTR |
| 2821 | " pri_dev_type=%s name='%s' config_methods=0x%x " |
| 2822 | "dev_capab=0x%x group_capab=0x%x%s%s", |
| 2823 | MAC2STR(dev_addr), |
| 2824 | wps_dev_type_bin2str(pri_dev_type, devtype, |
| 2825 | sizeof(devtype)), |
| 2826 | dev_name, supp_config_methods, dev_capab, group_capab, |
| 2827 | group ? " group=" : "", |
| 2828 | group ? group->ifname : ""); |
| 2829 | if (os_snprintf_error(sizeof(params), res)) |
| 2830 | wpa_printf(MSG_DEBUG, "P2P: PD Request event truncated"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2831 | params[sizeof(params) - 1] = '\0'; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2832 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2833 | if (config_methods & WPS_CONFIG_DISPLAY) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2834 | if (wps_generate_pin(&generated_pin) < 0) { |
| 2835 | wpa_printf(MSG_DEBUG, "P2P: Could not generate PIN"); |
| 2836 | wpas_notify_p2p_provision_discovery( |
| 2837 | wpa_s, peer, 0 /* response */, |
| 2838 | P2P_PROV_DISC_INFO_UNAVAILABLE, 0, 0); |
| 2839 | return; |
| 2840 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2841 | wpas_prov_disc_local_display(wpa_s, peer, params, |
| 2842 | generated_pin); |
| 2843 | } else if (config_methods & WPS_CONFIG_KEYPAD) |
| 2844 | wpas_prov_disc_local_keypad(wpa_s, peer, params); |
| 2845 | else if (config_methods & WPS_CONFIG_PUSHBUTTON) |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2846 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_REQ |
| 2847 | MACSTR "%s", MAC2STR(peer), params); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2848 | |
| 2849 | wpas_notify_p2p_provision_discovery(wpa_s, peer, 1 /* request */, |
| 2850 | P2P_PROV_DISC_SUCCESS, |
| 2851 | config_methods, generated_pin); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2855 | 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] | 2856 | { |
| 2857 | struct wpa_supplicant *wpa_s = ctx; |
| 2858 | unsigned int generated_pin = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2859 | char params[20]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2860 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2861 | if (wpa_s->pending_pd_before_join && |
| 2862 | (os_memcmp(peer, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 || |
| 2863 | os_memcmp(peer, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0)) { |
| 2864 | wpa_s->pending_pd_before_join = 0; |
| 2865 | wpa_printf(MSG_DEBUG, "P2P: Starting pending " |
| 2866 | "join-existing-group operation"); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2867 | wpas_p2p_join_start(wpa_s, 0, NULL, 0); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2868 | return; |
| 2869 | } |
| 2870 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2871 | if (wpa_s->pending_pd_use == AUTO_PD_JOIN || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2872 | wpa_s->pending_pd_use == AUTO_PD_GO_NEG) { |
| 2873 | int res; |
| 2874 | |
| 2875 | res = os_snprintf(params, sizeof(params), " peer_go=%d", |
| 2876 | wpa_s->pending_pd_use == AUTO_PD_JOIN); |
| 2877 | if (os_snprintf_error(sizeof(params), res)) |
| 2878 | params[sizeof(params) - 1] = '\0'; |
| 2879 | } else |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2880 | params[0] = '\0'; |
| 2881 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2882 | if (config_methods & WPS_CONFIG_DISPLAY) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2883 | wpas_prov_disc_local_keypad(wpa_s, peer, params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2884 | else if (config_methods & WPS_CONFIG_KEYPAD) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2885 | if (wps_generate_pin(&generated_pin) < 0) { |
| 2886 | wpa_printf(MSG_DEBUG, "P2P: Could not generate PIN"); |
| 2887 | wpas_notify_p2p_provision_discovery( |
| 2888 | wpa_s, peer, 0 /* response */, |
| 2889 | P2P_PROV_DISC_INFO_UNAVAILABLE, 0, 0); |
| 2890 | return; |
| 2891 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2892 | wpas_prov_disc_local_display(wpa_s, peer, params, |
| 2893 | generated_pin); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2894 | } else if (config_methods & WPS_CONFIG_PUSHBUTTON) |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2895 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_RESP |
| 2896 | MACSTR "%s", MAC2STR(peer), params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2897 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2898 | wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */, |
| 2899 | P2P_PROV_DISC_SUCCESS, |
| 2900 | config_methods, generated_pin); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2904 | static void wpas_prov_disc_fail(void *ctx, const u8 *peer, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2905 | enum p2p_prov_disc_status status, |
| 2906 | u32 adv_id, const u8 *adv_mac, |
| 2907 | const char *deferred_session_resp) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2908 | { |
| 2909 | struct wpa_supplicant *wpa_s = ctx; |
| 2910 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2911 | if (wpa_s->p2p_fallback_to_go_neg) { |
| 2912 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: PD for p2p_connect-auto " |
| 2913 | "failed - fall back to GO Negotiation"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2914 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2915 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 2916 | "reason=PD-failed"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2917 | wpas_p2p_fallback_to_go_neg(wpa_s, 0); |
| 2918 | return; |
| 2919 | } |
| 2920 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2921 | if (status == P2P_PROV_DISC_TIMEOUT_JOIN) { |
Dmitry Shmidt | 2b38048 | 2012-09-13 10:52:13 -0700 | [diff] [blame] | 2922 | wpa_s->pending_pd_before_join = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2923 | wpa_printf(MSG_DEBUG, "P2P: Starting pending " |
| 2924 | "join-existing-group operation (no ACK for PD " |
| 2925 | "Req attempts)"); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2926 | wpas_p2p_join_start(wpa_s, 0, NULL, 0); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2927 | return; |
Dmitry Shmidt | 2b38048 | 2012-09-13 10:52:13 -0700 | [diff] [blame] | 2928 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2929 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2930 | if (adv_id && adv_mac && deferred_session_resp) { |
| 2931 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE |
| 2932 | " p2p_dev_addr=" MACSTR " status=%d adv_id=%x" |
| 2933 | " deferred_session_resp='%s'", |
| 2934 | MAC2STR(peer), status, adv_id, |
| 2935 | deferred_session_resp); |
| 2936 | } else if (adv_id && adv_mac) { |
| 2937 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE |
| 2938 | " p2p_dev_addr=" MACSTR " status=%d adv_id=%x", |
| 2939 | MAC2STR(peer), status, adv_id); |
| 2940 | } else { |
| 2941 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE |
| 2942 | " p2p_dev_addr=" MACSTR " status=%d", |
| 2943 | MAC2STR(peer), status); |
| 2944 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2945 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2946 | wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */, |
| 2947 | status, 0, 0); |
| 2948 | } |
| 2949 | |
| 2950 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2951 | static int freq_included(struct wpa_supplicant *wpa_s, |
| 2952 | const struct p2p_channels *channels, |
| 2953 | unsigned int freq) |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 2954 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2955 | if ((channels == NULL || p2p_channels_includes_freq(channels, freq)) && |
| 2956 | wpas_p2p_go_is_peer_freq(wpa_s, freq)) |
| 2957 | return 1; |
| 2958 | return 0; |
| 2959 | } |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 2960 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2961 | |
| 2962 | static void wpas_p2p_go_update_common_freqs(struct wpa_supplicant *wpa_s) |
| 2963 | { |
| 2964 | unsigned int num = P2P_MAX_CHANNELS; |
| 2965 | int *common_freqs; |
| 2966 | int ret; |
| 2967 | |
| 2968 | p2p_go_dump_common_freqs(wpa_s); |
| 2969 | common_freqs = os_calloc(num, sizeof(int)); |
| 2970 | if (!common_freqs) |
| 2971 | return; |
| 2972 | |
| 2973 | ret = p2p_group_get_common_freqs(wpa_s->p2p_group, common_freqs, &num); |
| 2974 | if (ret < 0) { |
| 2975 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2976 | "P2P: Failed to get group common freqs"); |
| 2977 | os_free(common_freqs); |
| 2978 | return; |
| 2979 | } |
| 2980 | |
| 2981 | os_free(wpa_s->p2p_group_common_freqs); |
| 2982 | wpa_s->p2p_group_common_freqs = common_freqs; |
| 2983 | wpa_s->p2p_group_common_freqs_num = num; |
| 2984 | p2p_go_dump_common_freqs(wpa_s); |
| 2985 | } |
| 2986 | |
| 2987 | |
| 2988 | /* |
| 2989 | * Check if the given frequency is one of the possible operating frequencies |
| 2990 | * set after the completion of the GO Negotiation. |
| 2991 | */ |
| 2992 | static int wpas_p2p_go_is_peer_freq(struct wpa_supplicant *wpa_s, int freq) |
| 2993 | { |
| 2994 | unsigned int i; |
| 2995 | |
| 2996 | p2p_go_dump_common_freqs(wpa_s); |
| 2997 | |
| 2998 | /* assume no restrictions */ |
| 2999 | if (!wpa_s->p2p_group_common_freqs_num) |
| 3000 | return 1; |
| 3001 | |
| 3002 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 3003 | if (wpa_s->p2p_group_common_freqs[i] == freq) |
| 3004 | return 1; |
| 3005 | } |
| 3006 | return 0; |
| 3007 | } |
| 3008 | |
| 3009 | |
| 3010 | static int wpas_sta_check_ecsa(struct hostapd_data *hapd, |
| 3011 | struct sta_info *sta, void *ctx) |
| 3012 | { |
| 3013 | int *ecsa_support = ctx; |
| 3014 | |
| 3015 | *ecsa_support &= sta->ecsa_supported; |
| 3016 | |
| 3017 | return 0; |
| 3018 | } |
| 3019 | |
| 3020 | |
| 3021 | /* Check if all the peers support eCSA */ |
| 3022 | static int wpas_p2p_go_clients_support_ecsa(struct wpa_supplicant *wpa_s) |
| 3023 | { |
| 3024 | int ecsa_support = 1; |
| 3025 | |
| 3026 | ap_for_each_sta(wpa_s->ap_iface->bss[0], wpas_sta_check_ecsa, |
| 3027 | &ecsa_support); |
| 3028 | |
| 3029 | return ecsa_support; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3030 | } |
| 3031 | |
| 3032 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3033 | /** |
| 3034 | * Pick the best frequency to use from all the currently used frequencies. |
| 3035 | */ |
| 3036 | static int wpas_p2p_pick_best_used_freq(struct wpa_supplicant *wpa_s, |
| 3037 | struct wpa_used_freq_data *freqs, |
| 3038 | unsigned int num) |
| 3039 | { |
| 3040 | unsigned int i, c; |
| 3041 | |
| 3042 | /* find a candidate freq that is supported by P2P */ |
| 3043 | for (c = 0; c < num; c++) |
| 3044 | if (p2p_supported_freq(wpa_s->global->p2p, freqs[c].freq)) |
| 3045 | break; |
| 3046 | |
| 3047 | if (c == num) |
| 3048 | return 0; |
| 3049 | |
| 3050 | /* once we have a candidate, try to find a 'better' one */ |
| 3051 | for (i = c + 1; i < num; i++) { |
| 3052 | if (!p2p_supported_freq(wpa_s->global->p2p, freqs[i].freq)) |
| 3053 | continue; |
| 3054 | |
| 3055 | /* |
| 3056 | * 1. Infrastructure station interfaces have higher preference. |
| 3057 | * 2. P2P Clients have higher preference. |
| 3058 | * 3. All others. |
| 3059 | */ |
| 3060 | if (freqs[i].flags & WPA_FREQ_USED_BY_INFRA_STATION) { |
| 3061 | c = i; |
| 3062 | break; |
| 3063 | } |
| 3064 | |
| 3065 | if ((freqs[i].flags & WPA_FREQ_USED_BY_P2P_CLIENT)) |
| 3066 | c = i; |
| 3067 | } |
| 3068 | return freqs[c].freq; |
| 3069 | } |
| 3070 | |
| 3071 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3072 | static u8 wpas_invitation_process(void *ctx, const u8 *sa, const u8 *bssid, |
| 3073 | const u8 *go_dev_addr, const u8 *ssid, |
| 3074 | size_t ssid_len, int *go, u8 *group_bssid, |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3075 | int *force_freq, int persistent_group, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3076 | const struct p2p_channels *channels, |
| 3077 | int dev_pw_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3078 | { |
| 3079 | struct wpa_supplicant *wpa_s = ctx; |
| 3080 | struct wpa_ssid *s; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3081 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3082 | struct wpa_supplicant *grp; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3083 | int best_freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3084 | |
| 3085 | if (!persistent_group) { |
| 3086 | wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3087 | " to join an active group (SSID: %s)", |
| 3088 | MAC2STR(sa), wpa_ssid_txt(ssid, ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3089 | if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) && |
| 3090 | (os_memcmp(go_dev_addr, wpa_s->p2p_auth_invite, ETH_ALEN) |
| 3091 | == 0 || |
| 3092 | os_memcmp(sa, wpa_s->p2p_auth_invite, ETH_ALEN) == 0)) { |
| 3093 | wpa_printf(MSG_DEBUG, "P2P: Accept previously " |
| 3094 | "authorized invitation"); |
| 3095 | goto accept_inv; |
| 3096 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3097 | |
| 3098 | #ifdef CONFIG_WPS_NFC |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3099 | if (dev_pw_id >= 0 && wpa_s->p2p_nfc_tag_enabled && |
| 3100 | dev_pw_id == wpa_s->p2p_oob_dev_pw_id) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3101 | 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] | 3102 | wpa_s->p2p_wps_method = WPS_NFC; |
| 3103 | wpa_s->pending_join_wps_method = WPS_NFC; |
| 3104 | os_memcpy(wpa_s->pending_join_dev_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3105 | go_dev_addr, ETH_ALEN); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3106 | os_memcpy(wpa_s->pending_join_iface_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3107 | bssid, ETH_ALEN); |
| 3108 | goto accept_inv; |
| 3109 | } |
| 3110 | #endif /* CONFIG_WPS_NFC */ |
| 3111 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3112 | /* |
| 3113 | * Do not accept the invitation automatically; notify user and |
| 3114 | * request approval. |
| 3115 | */ |
| 3116 | return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; |
| 3117 | } |
| 3118 | |
| 3119 | grp = wpas_get_p2p_group(wpa_s, ssid, ssid_len, go); |
| 3120 | if (grp) { |
| 3121 | wpa_printf(MSG_DEBUG, "P2P: Accept invitation to already " |
| 3122 | "running persistent group"); |
| 3123 | if (*go) |
| 3124 | os_memcpy(group_bssid, grp->own_addr, ETH_ALEN); |
| 3125 | goto accept_inv; |
| 3126 | } |
| 3127 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3128 | if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) && |
| 3129 | os_memcmp(sa, wpa_s->p2p_auth_invite, ETH_ALEN) == 0) { |
| 3130 | wpa_printf(MSG_DEBUG, "P2P: Accept previously initiated " |
| 3131 | "invitation to re-invoke a persistent group"); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3132 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3133 | } else if (!wpa_s->conf->persistent_reconnect) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3134 | return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; |
| 3135 | |
| 3136 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 3137 | if (s->disabled == 2 && |
| 3138 | os_memcmp(s->bssid, go_dev_addr, ETH_ALEN) == 0 && |
| 3139 | s->ssid_len == ssid_len && |
| 3140 | os_memcmp(ssid, s->ssid, ssid_len) == 0) |
| 3141 | break; |
| 3142 | } |
| 3143 | |
| 3144 | if (!s) { |
| 3145 | wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR |
| 3146 | " requested reinvocation of an unknown group", |
| 3147 | MAC2STR(sa)); |
| 3148 | return P2P_SC_FAIL_UNKNOWN_GROUP; |
| 3149 | } |
| 3150 | |
| 3151 | if (s->mode == WPAS_MODE_P2P_GO && !wpas_p2p_create_iface(wpa_s)) { |
| 3152 | *go = 1; |
| 3153 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
| 3154 | wpa_printf(MSG_DEBUG, "P2P: The only available " |
| 3155 | "interface is already in use - reject " |
| 3156 | "invitation"); |
| 3157 | return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; |
| 3158 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3159 | if (wpa_s->p2p_mgmt) |
| 3160 | os_memcpy(group_bssid, wpa_s->parent->own_addr, |
| 3161 | ETH_ALEN); |
| 3162 | else |
| 3163 | os_memcpy(group_bssid, wpa_s->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3164 | } else if (s->mode == WPAS_MODE_P2P_GO) { |
| 3165 | *go = 1; |
| 3166 | if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO) < 0) |
| 3167 | { |
| 3168 | wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " |
| 3169 | "interface address for the group"); |
| 3170 | return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; |
| 3171 | } |
| 3172 | os_memcpy(group_bssid, wpa_s->pending_interface_addr, |
| 3173 | ETH_ALEN); |
| 3174 | } |
| 3175 | |
| 3176 | accept_inv: |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3177 | wpas_p2p_set_own_freq_preference(wpa_s, 0); |
| 3178 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3179 | best_freq = 0; |
| 3180 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 3181 | sizeof(struct wpa_used_freq_data)); |
| 3182 | if (freqs) { |
| 3183 | int num_channels = wpa_s->num_multichan_concurrent; |
| 3184 | int num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, num_channels); |
| 3185 | best_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num); |
| 3186 | os_free(freqs); |
| 3187 | } |
| 3188 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3189 | /* Get one of the frequencies currently in use */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3190 | if (best_freq > 0) { |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 3191 | 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] | 3192 | wpas_p2p_set_own_freq_preference(wpa_s, best_freq); |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 3193 | |
| 3194 | if (wpa_s->num_multichan_concurrent < 2 || |
| 3195 | wpas_p2p_num_unused_channels(wpa_s) < 1) { |
| 3196 | 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] | 3197 | *force_freq = best_freq; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 3198 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3199 | } |
| 3200 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3201 | if (*force_freq > 0 && wpa_s->num_multichan_concurrent > 1 && |
| 3202 | wpas_p2p_num_unused_channels(wpa_s) > 0) { |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3203 | if (*go == 0) { |
| 3204 | /* We are the client */ |
| 3205 | wpa_printf(MSG_DEBUG, "P2P: Peer was found to be " |
| 3206 | "running a GO but we are capable of MCC, " |
| 3207 | "figure out the best channel to use"); |
| 3208 | *force_freq = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3209 | } else if (!freq_included(wpa_s, channels, *force_freq)) { |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3210 | /* We are the GO, and *force_freq is not in the |
| 3211 | * intersection */ |
| 3212 | wpa_printf(MSG_DEBUG, "P2P: Forced GO freq %d MHz not " |
| 3213 | "in intersection but we are capable of MCC, " |
| 3214 | "figure out the best channel to use", |
| 3215 | *force_freq); |
| 3216 | *force_freq = 0; |
| 3217 | } |
| 3218 | } |
| 3219 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3220 | return P2P_SC_SUCCESS; |
| 3221 | } |
| 3222 | |
| 3223 | |
| 3224 | static void wpas_invitation_received(void *ctx, const u8 *sa, const u8 *bssid, |
| 3225 | const u8 *ssid, size_t ssid_len, |
| 3226 | const u8 *go_dev_addr, u8 status, |
| 3227 | int op_freq) |
| 3228 | { |
| 3229 | struct wpa_supplicant *wpa_s = ctx; |
| 3230 | struct wpa_ssid *s; |
| 3231 | |
| 3232 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 3233 | if (s->disabled == 2 && |
| 3234 | s->ssid_len == ssid_len && |
| 3235 | os_memcmp(ssid, s->ssid, ssid_len) == 0) |
| 3236 | break; |
| 3237 | } |
| 3238 | |
| 3239 | if (status == P2P_SC_SUCCESS) { |
| 3240 | wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3241 | " was accepted; op_freq=%d MHz, SSID=%s", |
| 3242 | MAC2STR(sa), op_freq, wpa_ssid_txt(ssid, ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3243 | if (s) { |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 3244 | int go = s->mode == WPAS_MODE_P2P_GO; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 3245 | if (go) { |
| 3246 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3247 | P2P_EVENT_INVITATION_ACCEPTED |
| 3248 | "sa=" MACSTR |
| 3249 | " persistent=%d freq=%d", |
| 3250 | MAC2STR(sa), s->id, op_freq); |
| 3251 | } else { |
| 3252 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3253 | P2P_EVENT_INVITATION_ACCEPTED |
| 3254 | "sa=" MACSTR |
| 3255 | " persistent=%d", |
| 3256 | MAC2STR(sa), s->id); |
| 3257 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3258 | wpas_p2p_group_add_persistent( |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3259 | wpa_s, s, go, 0, op_freq, 0, |
| 3260 | wpa_s->conf->p2p_go_ht40, |
| 3261 | wpa_s->conf->p2p_go_vht, |
| 3262 | 0, |
| 3263 | wpa_s->conf->p2p_go_he, |
| 3264 | wpa_s->conf->p2p_go_edmg, NULL, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3265 | go ? P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0, |
| 3266 | 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3267 | } else if (bssid) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3268 | wpa_s->user_initiated_pd = 0; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 3269 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3270 | P2P_EVENT_INVITATION_ACCEPTED |
| 3271 | "sa=" MACSTR " go_dev_addr=" MACSTR |
| 3272 | " bssid=" MACSTR " unknown-network", |
| 3273 | MAC2STR(sa), MAC2STR(go_dev_addr), |
| 3274 | MAC2STR(bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3275 | wpas_p2p_join(wpa_s, bssid, go_dev_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3276 | wpa_s->p2p_wps_method, 0, op_freq, |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3277 | ssid, ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3278 | } |
| 3279 | return; |
| 3280 | } |
| 3281 | |
| 3282 | if (status != P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) { |
| 3283 | wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR |
| 3284 | " was rejected (status %u)", MAC2STR(sa), status); |
| 3285 | return; |
| 3286 | } |
| 3287 | |
| 3288 | if (!s) { |
| 3289 | if (bssid) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3290 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3291 | P2P_EVENT_INVITATION_RECEIVED |
| 3292 | "sa=" MACSTR " go_dev_addr=" MACSTR |
| 3293 | " bssid=" MACSTR " unknown-network", |
| 3294 | MAC2STR(sa), MAC2STR(go_dev_addr), |
| 3295 | MAC2STR(bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3296 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3297 | wpa_msg_global(wpa_s, MSG_INFO, |
| 3298 | P2P_EVENT_INVITATION_RECEIVED |
| 3299 | "sa=" MACSTR " go_dev_addr=" MACSTR |
| 3300 | " unknown-network", |
| 3301 | MAC2STR(sa), MAC2STR(go_dev_addr)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3302 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3303 | wpas_notify_p2p_invitation_received(wpa_s, sa, go_dev_addr, |
| 3304 | bssid, 0, op_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3305 | return; |
| 3306 | } |
| 3307 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3308 | if (s->mode == WPAS_MODE_P2P_GO && op_freq) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3309 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED |
| 3310 | "sa=" MACSTR " persistent=%d freq=%d", |
| 3311 | MAC2STR(sa), s->id, op_freq); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3312 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3313 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED |
| 3314 | "sa=" MACSTR " persistent=%d", |
| 3315 | MAC2STR(sa), s->id); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3316 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3317 | wpas_notify_p2p_invitation_received(wpa_s, sa, go_dev_addr, bssid, |
| 3318 | s->id, op_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3319 | } |
| 3320 | |
| 3321 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3322 | static void wpas_remove_persistent_peer(struct wpa_supplicant *wpa_s, |
| 3323 | struct wpa_ssid *ssid, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3324 | const u8 *peer, int inv) |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3325 | { |
| 3326 | size_t i; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 3327 | 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] | 3328 | |
| 3329 | if (ssid == NULL) |
| 3330 | return; |
| 3331 | |
| 3332 | for (i = 0; ssid->p2p_client_list && i < ssid->num_p2p_clients; i++) { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3333 | if (os_memcmp(ssid->p2p_client_list + i * 2 * ETH_ALEN, peer, |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3334 | ETH_ALEN) == 0) |
| 3335 | break; |
| 3336 | } |
Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 3337 | if (i >= ssid->num_p2p_clients || !ssid->p2p_client_list) { |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3338 | if (ssid->mode != WPAS_MODE_P2P_GO && |
| 3339 | os_memcmp(ssid->bssid, peer, ETH_ALEN) == 0) { |
| 3340 | wpa_printf(MSG_DEBUG, "P2P: Remove persistent group %d " |
| 3341 | "due to invitation result", ssid->id); |
| 3342 | wpas_notify_network_removed(wpa_s, ssid); |
| 3343 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 3344 | return; |
| 3345 | } |
| 3346 | return; /* Peer not found in client list */ |
| 3347 | } |
| 3348 | |
| 3349 | wpa_printf(MSG_DEBUG, "P2P: Remove peer " MACSTR " from persistent " |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3350 | "group %d client list%s", |
| 3351 | MAC2STR(peer), ssid->id, |
| 3352 | inv ? " due to invitation result" : ""); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3353 | os_memmove(ssid->p2p_client_list + i * 2 * ETH_ALEN, |
| 3354 | ssid->p2p_client_list + (i + 1) * 2 * ETH_ALEN, |
| 3355 | (ssid->num_p2p_clients - i - 1) * 2 * ETH_ALEN); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3356 | ssid->num_p2p_clients--; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 3357 | if (p2p_wpa_s->conf->update_config && |
| 3358 | wpa_config_write(p2p_wpa_s->confname, p2p_wpa_s->conf)) |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3359 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3360 | } |
| 3361 | |
| 3362 | |
| 3363 | static void wpas_remove_persistent_client(struct wpa_supplicant *wpa_s, |
| 3364 | const u8 *peer) |
| 3365 | { |
| 3366 | struct wpa_ssid *ssid; |
| 3367 | |
| 3368 | wpa_s = wpa_s->global->p2p_invite_group; |
| 3369 | if (wpa_s == NULL) |
| 3370 | return; /* No known invitation group */ |
| 3371 | ssid = wpa_s->current_ssid; |
| 3372 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || |
| 3373 | !ssid->p2p_persistent_group) |
| 3374 | return; /* Not operating as a GO in persistent group */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3375 | ssid = wpas_p2p_get_persistent(wpa_s->p2pdev, peer, |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3376 | ssid->ssid, ssid->ssid_len); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3377 | wpas_remove_persistent_peer(wpa_s, ssid, peer, 1); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3378 | } |
| 3379 | |
| 3380 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3381 | static void wpas_invitation_result(void *ctx, int status, const u8 *bssid, |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3382 | const struct p2p_channels *channels, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3383 | const u8 *peer, int neg_freq, |
| 3384 | int peer_oper_freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3385 | { |
| 3386 | struct wpa_supplicant *wpa_s = ctx; |
| 3387 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3388 | int freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3389 | |
| 3390 | if (bssid) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3391 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT |
| 3392 | "status=%d " MACSTR, |
| 3393 | status, MAC2STR(bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3394 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3395 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT |
| 3396 | "status=%d ", status); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3397 | } |
| 3398 | wpas_notify_p2p_invitation_result(wpa_s, status, bssid); |
| 3399 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3400 | wpa_printf(MSG_DEBUG, "P2P: Invitation result - status=%d peer=" MACSTR, |
| 3401 | status, MAC2STR(peer)); |
| 3402 | if (wpa_s->pending_invite_ssid_id == -1) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3403 | struct wpa_supplicant *group_if = |
| 3404 | wpa_s->global->p2p_invite_group; |
| 3405 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3406 | if (status == P2P_SC_FAIL_UNKNOWN_GROUP) |
| 3407 | wpas_remove_persistent_client(wpa_s, peer); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3408 | |
| 3409 | /* |
| 3410 | * Invitation to an active group. If this is successful and we |
| 3411 | * are the GO, set the client wait to postpone some concurrent |
| 3412 | * operations and to allow provisioning and connection to happen |
| 3413 | * more quickly. |
| 3414 | */ |
| 3415 | if (status == P2P_SC_SUCCESS && |
| 3416 | group_if && group_if->current_ssid && |
| 3417 | group_if->current_ssid->mode == WPAS_MODE_P2P_GO) { |
| 3418 | os_get_reltime(&wpa_s->global->p2p_go_wait_client); |
| 3419 | #ifdef CONFIG_TESTING_OPTIONS |
| 3420 | if (group_if->p2p_go_csa_on_inv) { |
| 3421 | wpa_printf(MSG_DEBUG, |
| 3422 | "Testing: force P2P GO CSA after invitation"); |
| 3423 | eloop_cancel_timeout( |
| 3424 | wpas_p2p_reconsider_moving_go, |
| 3425 | wpa_s, NULL); |
| 3426 | eloop_register_timeout( |
| 3427 | 0, 50000, |
| 3428 | wpas_p2p_reconsider_moving_go, |
| 3429 | wpa_s, NULL); |
| 3430 | } |
| 3431 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 3432 | } |
| 3433 | return; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3434 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3435 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3436 | if (status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) { |
| 3437 | wpa_printf(MSG_DEBUG, "P2P: Waiting for peer to start another " |
| 3438 | "invitation exchange to indicate readiness for " |
| 3439 | "re-invocation"); |
| 3440 | } |
| 3441 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3442 | if (status != P2P_SC_SUCCESS) { |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3443 | if (status == P2P_SC_FAIL_UNKNOWN_GROUP) { |
| 3444 | ssid = wpa_config_get_network( |
| 3445 | wpa_s->conf, wpa_s->pending_invite_ssid_id); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3446 | wpas_remove_persistent_peer(wpa_s, ssid, peer, 1); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3447 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3448 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 3449 | return; |
| 3450 | } |
| 3451 | |
| 3452 | ssid = wpa_config_get_network(wpa_s->conf, |
| 3453 | wpa_s->pending_invite_ssid_id); |
| 3454 | if (ssid == NULL) { |
| 3455 | wpa_printf(MSG_ERROR, "P2P: Could not find persistent group " |
| 3456 | "data matching with invitation"); |
| 3457 | return; |
| 3458 | } |
| 3459 | |
Jouni Malinen | 2c5b17d | 2012-10-13 21:52:46 -0700 | [diff] [blame] | 3460 | /* |
| 3461 | * The peer could have missed our ctrl::ack frame for Invitation |
| 3462 | * Response and continue retransmitting the frame. To reduce the |
| 3463 | * likelihood of the peer not getting successful TX status for the |
| 3464 | * Invitation Response frame, wait a short time here before starting |
| 3465 | * the persistent group so that we will remain on the current channel to |
| 3466 | * acknowledge any possible retransmission from the peer. |
| 3467 | */ |
| 3468 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: 50 ms wait on current channel before " |
| 3469 | "starting persistent group"); |
| 3470 | os_sleep(0, 50000); |
| 3471 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3472 | if (neg_freq > 0 && ssid->mode == WPAS_MODE_P2P_GO && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3473 | freq_included(wpa_s, channels, neg_freq)) |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3474 | freq = neg_freq; |
| 3475 | else if (peer_oper_freq > 0 && ssid->mode != WPAS_MODE_P2P_GO && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3476 | freq_included(wpa_s, channels, peer_oper_freq)) |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3477 | freq = peer_oper_freq; |
| 3478 | else |
| 3479 | freq = 0; |
| 3480 | |
| 3481 | wpa_printf(MSG_DEBUG, "P2P: Persistent group invitation success - op_freq=%d MHz SSID=%s", |
| 3482 | freq, wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3483 | wpas_p2p_group_add_persistent(wpa_s, ssid, |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 3484 | ssid->mode == WPAS_MODE_P2P_GO, |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 3485 | wpa_s->p2p_persistent_go_freq, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3486 | freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3487 | wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3488 | wpa_s->p2p_go_ht40, wpa_s->p2p_go_vht, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3489 | wpa_s->p2p_go_max_oper_chwidth, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3490 | wpa_s->p2p_go_he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3491 | wpa_s->p2p_go_edmg, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3492 | channels, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3493 | ssid->mode == WPAS_MODE_P2P_GO ? |
| 3494 | P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3495 | 0, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3496 | } |
| 3497 | |
| 3498 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3499 | static int wpas_p2p_disallowed_freq(struct wpa_global *global, |
| 3500 | unsigned int freq) |
| 3501 | { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3502 | if (freq_range_list_includes(&global->p2p_go_avoid_freq, freq)) |
| 3503 | return 1; |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 3504 | return freq_range_list_includes(&global->p2p_disallow_freq, freq); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3505 | } |
| 3506 | |
| 3507 | |
| 3508 | static void wpas_p2p_add_chan(struct p2p_reg_class *reg, u8 chan) |
| 3509 | { |
| 3510 | reg->channel[reg->channels] = chan; |
| 3511 | reg->channels++; |
| 3512 | } |
| 3513 | |
| 3514 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3515 | static int wpas_p2p_default_channels(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3516 | struct p2p_channels *chan, |
| 3517 | struct p2p_channels *cli_chan) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3518 | { |
| 3519 | int i, cla = 0; |
| 3520 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3521 | wpa_s->global->p2p_24ghz_social_channels = 1; |
| 3522 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3523 | os_memset(cli_chan, 0, sizeof(*cli_chan)); |
| 3524 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3525 | wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for 2.4 GHz " |
| 3526 | "band"); |
| 3527 | |
| 3528 | /* Operating class 81 - 2.4 GHz band channels 1..13 */ |
| 3529 | chan->reg_class[cla].reg_class = 81; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3530 | chan->reg_class[cla].channels = 0; |
| 3531 | for (i = 0; i < 11; i++) { |
| 3532 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 2412 + i * 5)) |
| 3533 | wpas_p2p_add_chan(&chan->reg_class[cla], i + 1); |
| 3534 | } |
| 3535 | if (chan->reg_class[cla].channels) |
| 3536 | cla++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3537 | |
| 3538 | wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for lower 5 GHz " |
| 3539 | "band"); |
| 3540 | |
| 3541 | /* Operating class 115 - 5 GHz, channels 36-48 */ |
| 3542 | chan->reg_class[cla].reg_class = 115; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3543 | chan->reg_class[cla].channels = 0; |
| 3544 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 36 * 5)) |
| 3545 | wpas_p2p_add_chan(&chan->reg_class[cla], 36); |
| 3546 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 40 * 5)) |
| 3547 | wpas_p2p_add_chan(&chan->reg_class[cla], 40); |
| 3548 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 44 * 5)) |
| 3549 | wpas_p2p_add_chan(&chan->reg_class[cla], 44); |
| 3550 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 48 * 5)) |
| 3551 | wpas_p2p_add_chan(&chan->reg_class[cla], 48); |
| 3552 | if (chan->reg_class[cla].channels) |
| 3553 | cla++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3554 | |
| 3555 | wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for higher 5 GHz " |
| 3556 | "band"); |
| 3557 | |
| 3558 | /* Operating class 124 - 5 GHz, channels 149,153,157,161 */ |
| 3559 | chan->reg_class[cla].reg_class = 124; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3560 | chan->reg_class[cla].channels = 0; |
| 3561 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 149 * 5)) |
| 3562 | wpas_p2p_add_chan(&chan->reg_class[cla], 149); |
| 3563 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 153 * 5)) |
| 3564 | wpas_p2p_add_chan(&chan->reg_class[cla], 153); |
| 3565 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 156 * 5)) |
| 3566 | wpas_p2p_add_chan(&chan->reg_class[cla], 157); |
| 3567 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 161 * 5)) |
| 3568 | wpas_p2p_add_chan(&chan->reg_class[cla], 161); |
| 3569 | if (chan->reg_class[cla].channels) |
| 3570 | cla++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3571 | |
| 3572 | chan->reg_classes = cla; |
| 3573 | return 0; |
| 3574 | } |
| 3575 | |
| 3576 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3577 | static int has_channel(struct wpa_global *global, |
| 3578 | struct hostapd_hw_modes *mode, u8 chan, int *flags) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3579 | { |
| 3580 | int i; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3581 | unsigned int freq; |
| 3582 | |
| 3583 | freq = (mode->mode == HOSTAPD_MODE_IEEE80211A ? 5000 : 2407) + |
| 3584 | chan * 5; |
| 3585 | if (wpas_p2p_disallowed_freq(global, freq)) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3586 | return NOT_ALLOWED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3587 | |
| 3588 | for (i = 0; i < mode->num_channels; i++) { |
| 3589 | if (mode->channels[i].chan == chan) { |
| 3590 | if (flags) |
| 3591 | *flags = mode->channels[i].flag; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3592 | if (mode->channels[i].flag & |
| 3593 | (HOSTAPD_CHAN_DISABLED | |
| 3594 | HOSTAPD_CHAN_RADAR)) |
| 3595 | return NOT_ALLOWED; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3596 | if (mode->channels[i].flag & HOSTAPD_CHAN_NO_IR) |
| 3597 | return NO_IR; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3598 | return ALLOWED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3599 | } |
| 3600 | } |
| 3601 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3602 | return NOT_ALLOWED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3603 | } |
| 3604 | |
| 3605 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3606 | static int wpas_p2p_get_center_80mhz(struct wpa_supplicant *wpa_s, |
| 3607 | struct hostapd_hw_modes *mode, |
| 3608 | u8 channel) |
| 3609 | { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3610 | u8 center_channels[] = { 42, 58, 106, 122, 138, 155, 171 }; |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 3611 | size_t i; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3612 | |
| 3613 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 3614 | return 0; |
| 3615 | |
| 3616 | for (i = 0; i < ARRAY_SIZE(center_channels); i++) |
| 3617 | /* |
| 3618 | * In 80 MHz, the bandwidth "spans" 12 channels (e.g., 36-48), |
| 3619 | * so the center channel is 6 channels away from the start/end. |
| 3620 | */ |
| 3621 | if (channel >= center_channels[i] - 6 && |
| 3622 | channel <= center_channels[i] + 6) |
| 3623 | return center_channels[i]; |
| 3624 | |
| 3625 | return 0; |
| 3626 | } |
| 3627 | |
| 3628 | |
| 3629 | static enum chan_allowed wpas_p2p_verify_80mhz(struct wpa_supplicant *wpa_s, |
| 3630 | struct hostapd_hw_modes *mode, |
| 3631 | u8 channel, u8 bw) |
| 3632 | { |
| 3633 | u8 center_chan; |
| 3634 | int i, flags; |
| 3635 | enum chan_allowed res, ret = ALLOWED; |
| 3636 | |
| 3637 | center_chan = wpas_p2p_get_center_80mhz(wpa_s, mode, channel); |
| 3638 | if (!center_chan) |
| 3639 | return NOT_ALLOWED; |
| 3640 | if (center_chan >= 58 && center_chan <= 138) |
| 3641 | return NOT_ALLOWED; /* Do not allow DFS channels for P2P */ |
| 3642 | |
| 3643 | /* check all the channels are available */ |
| 3644 | for (i = 0; i < 4; i++) { |
| 3645 | int adj_chan = center_chan - 6 + i * 4; |
| 3646 | |
| 3647 | res = has_channel(wpa_s->global, mode, adj_chan, &flags); |
| 3648 | if (res == NOT_ALLOWED) |
| 3649 | return NOT_ALLOWED; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3650 | if (res == NO_IR) |
| 3651 | ret = NO_IR; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3652 | |
| 3653 | if (i == 0 && !(flags & HOSTAPD_CHAN_VHT_10_70)) |
| 3654 | return NOT_ALLOWED; |
| 3655 | if (i == 1 && !(flags & HOSTAPD_CHAN_VHT_30_50)) |
| 3656 | return NOT_ALLOWED; |
| 3657 | if (i == 2 && !(flags & HOSTAPD_CHAN_VHT_50_30)) |
| 3658 | return NOT_ALLOWED; |
| 3659 | if (i == 3 && !(flags & HOSTAPD_CHAN_VHT_70_10)) |
| 3660 | return NOT_ALLOWED; |
| 3661 | } |
| 3662 | |
| 3663 | return ret; |
| 3664 | } |
| 3665 | |
| 3666 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3667 | static int wpas_p2p_get_center_160mhz(struct wpa_supplicant *wpa_s, |
| 3668 | struct hostapd_hw_modes *mode, |
| 3669 | u8 channel) |
| 3670 | { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3671 | u8 center_channels[] = { 50, 114, 163 }; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3672 | unsigned int i; |
| 3673 | |
| 3674 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 3675 | return 0; |
| 3676 | |
| 3677 | for (i = 0; i < ARRAY_SIZE(center_channels); i++) |
| 3678 | /* |
| 3679 | * In 160 MHz, the bandwidth "spans" 28 channels (e.g., 36-64), |
| 3680 | * so the center channel is 14 channels away from the start/end. |
| 3681 | */ |
| 3682 | if (channel >= center_channels[i] - 14 && |
| 3683 | channel <= center_channels[i] + 14) |
| 3684 | return center_channels[i]; |
| 3685 | |
| 3686 | return 0; |
| 3687 | } |
| 3688 | |
| 3689 | |
| 3690 | static enum chan_allowed wpas_p2p_verify_160mhz(struct wpa_supplicant *wpa_s, |
| 3691 | struct hostapd_hw_modes *mode, |
| 3692 | u8 channel, u8 bw) |
| 3693 | { |
| 3694 | u8 center_chan; |
| 3695 | int i, flags; |
| 3696 | enum chan_allowed res, ret = ALLOWED; |
| 3697 | |
| 3698 | center_chan = wpas_p2p_get_center_160mhz(wpa_s, mode, channel); |
| 3699 | if (!center_chan) |
| 3700 | return NOT_ALLOWED; |
| 3701 | /* VHT 160 MHz uses DFS channels in most countries. */ |
| 3702 | |
| 3703 | /* Check all the channels are available */ |
| 3704 | for (i = 0; i < 8; i++) { |
| 3705 | int adj_chan = center_chan - 14 + i * 4; |
| 3706 | |
| 3707 | res = has_channel(wpa_s->global, mode, adj_chan, &flags); |
| 3708 | if (res == NOT_ALLOWED) |
| 3709 | return NOT_ALLOWED; |
| 3710 | |
| 3711 | if (res == NO_IR) |
| 3712 | ret = NO_IR; |
| 3713 | |
| 3714 | if (i == 0 && !(flags & HOSTAPD_CHAN_VHT_10_150)) |
| 3715 | return NOT_ALLOWED; |
| 3716 | if (i == 1 && !(flags & HOSTAPD_CHAN_VHT_30_130)) |
| 3717 | return NOT_ALLOWED; |
| 3718 | if (i == 2 && !(flags & HOSTAPD_CHAN_VHT_50_110)) |
| 3719 | return NOT_ALLOWED; |
| 3720 | if (i == 3 && !(flags & HOSTAPD_CHAN_VHT_70_90)) |
| 3721 | return NOT_ALLOWED; |
| 3722 | if (i == 4 && !(flags & HOSTAPD_CHAN_VHT_90_70)) |
| 3723 | return NOT_ALLOWED; |
| 3724 | if (i == 5 && !(flags & HOSTAPD_CHAN_VHT_110_50)) |
| 3725 | return NOT_ALLOWED; |
| 3726 | if (i == 6 && !(flags & HOSTAPD_CHAN_VHT_130_30)) |
| 3727 | return NOT_ALLOWED; |
| 3728 | if (i == 7 && !(flags & HOSTAPD_CHAN_VHT_150_10)) |
| 3729 | return NOT_ALLOWED; |
| 3730 | } |
| 3731 | |
| 3732 | return ret; |
| 3733 | } |
| 3734 | |
| 3735 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3736 | static enum chan_allowed wpas_p2p_verify_edmg(struct wpa_supplicant *wpa_s, |
| 3737 | struct hostapd_hw_modes *mode, |
| 3738 | u8 channel) |
| 3739 | { |
| 3740 | struct ieee80211_edmg_config edmg; |
| 3741 | |
| 3742 | hostapd_encode_edmg_chan(1, channel, 0, &edmg); |
| 3743 | if (edmg.channels && ieee802_edmg_is_allowed(mode->edmg, edmg)) |
| 3744 | return ALLOWED; |
| 3745 | |
| 3746 | return NOT_ALLOWED; |
| 3747 | } |
| 3748 | |
| 3749 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3750 | static enum chan_allowed wpas_p2p_verify_channel(struct wpa_supplicant *wpa_s, |
| 3751 | struct hostapd_hw_modes *mode, |
| 3752 | u8 channel, u8 bw) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3753 | { |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 3754 | int flag = 0; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3755 | enum chan_allowed res, res2; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3756 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3757 | res2 = res = has_channel(wpa_s->global, mode, channel, &flag); |
| 3758 | if (bw == BW40MINUS) { |
| 3759 | if (!(flag & HOSTAPD_CHAN_HT40MINUS)) |
| 3760 | return NOT_ALLOWED; |
| 3761 | res2 = has_channel(wpa_s->global, mode, channel - 4, NULL); |
| 3762 | } else if (bw == BW40PLUS) { |
| 3763 | if (!(flag & HOSTAPD_CHAN_HT40PLUS)) |
| 3764 | return NOT_ALLOWED; |
| 3765 | res2 = has_channel(wpa_s->global, mode, channel + 4, NULL); |
| 3766 | } else if (bw == BW80) { |
| 3767 | res2 = wpas_p2p_verify_80mhz(wpa_s, mode, channel, bw); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3768 | } else if (bw == BW160) { |
| 3769 | res2 = wpas_p2p_verify_160mhz(wpa_s, mode, channel, bw); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3770 | } else if (bw == BW4320 || bw == BW6480 || bw == BW8640) { |
| 3771 | return wpas_p2p_verify_edmg(wpa_s, mode, channel); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3772 | } |
| 3773 | |
| 3774 | if (res == NOT_ALLOWED || res2 == NOT_ALLOWED) |
| 3775 | return NOT_ALLOWED; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3776 | if (res == NO_IR || res2 == NO_IR) |
| 3777 | return NO_IR; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3778 | return res; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3779 | } |
| 3780 | |
| 3781 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3782 | static int wpas_p2p_setup_channels(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3783 | struct p2p_channels *chan, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3784 | struct p2p_channels *cli_chan, |
| 3785 | bool p2p_disable_6ghz) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3786 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3787 | struct hostapd_hw_modes *mode; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3788 | int cla, op, cli_cla; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3789 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3790 | if (wpa_s->hw.modes == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3791 | wpa_printf(MSG_DEBUG, "P2P: Driver did not support fetching " |
| 3792 | "of all supported channels; assume dualband " |
| 3793 | "support"); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3794 | return wpas_p2p_default_channels(wpa_s, chan, cli_chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3795 | } |
| 3796 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3797 | cla = cli_cla = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3798 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3799 | for (op = 0; global_op_class[op].op_class; op++) { |
| 3800 | const struct oper_class_map *o = &global_op_class[op]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3801 | u8 ch; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3802 | struct p2p_reg_class *reg = NULL, *cli_reg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3803 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3804 | if (o->p2p == NO_P2P_SUPP || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3805 | (is_6ghz_op_class(o->op_class) && p2p_disable_6ghz)) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3806 | continue; |
| 3807 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3808 | mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, o->mode, |
| 3809 | is_6ghz_op_class(o->op_class)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3810 | if (mode == NULL) |
| 3811 | continue; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3812 | if (mode->mode == HOSTAPD_MODE_IEEE80211G) |
| 3813 | wpa_s->global->p2p_24ghz_social_channels = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3814 | for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3815 | enum chan_allowed res; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3816 | |
| 3817 | /* Check for non-continuous jump in channel index |
| 3818 | * incrementation */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3819 | if ((o->op_class >= 128 && o->op_class <= 130) && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3820 | ch < 149 && ch + o->inc > 149) |
| 3821 | ch = 149; |
| 3822 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3823 | res = wpas_p2p_verify_channel(wpa_s, mode, ch, o->bw); |
| 3824 | if (res == ALLOWED) { |
| 3825 | if (reg == NULL) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3826 | if (cla == P2P_MAX_REG_CLASSES) |
| 3827 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3828 | wpa_printf(MSG_DEBUG, "P2P: Add operating class %u", |
| 3829 | o->op_class); |
| 3830 | reg = &chan->reg_class[cla]; |
| 3831 | cla++; |
| 3832 | reg->reg_class = o->op_class; |
| 3833 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3834 | if (reg->channels == P2P_MAX_REG_CLASS_CHANNELS) |
| 3835 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3836 | reg->channel[reg->channels] = ch; |
| 3837 | reg->channels++; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3838 | } else if (res == NO_IR && |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3839 | wpa_s->conf->p2p_add_cli_chan) { |
| 3840 | if (cli_reg == NULL) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3841 | if (cli_cla == P2P_MAX_REG_CLASSES) |
| 3842 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3843 | wpa_printf(MSG_DEBUG, "P2P: Add operating class %u (client only)", |
| 3844 | o->op_class); |
| 3845 | cli_reg = &cli_chan->reg_class[cli_cla]; |
| 3846 | cli_cla++; |
| 3847 | cli_reg->reg_class = o->op_class; |
| 3848 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3849 | if (cli_reg->channels == |
| 3850 | P2P_MAX_REG_CLASS_CHANNELS) |
| 3851 | continue; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3852 | cli_reg->channel[cli_reg->channels] = ch; |
| 3853 | cli_reg->channels++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3854 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3855 | } |
| 3856 | if (reg) { |
| 3857 | wpa_hexdump(MSG_DEBUG, "P2P: Channels", |
| 3858 | reg->channel, reg->channels); |
| 3859 | } |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3860 | if (cli_reg) { |
| 3861 | wpa_hexdump(MSG_DEBUG, "P2P: Channels (client only)", |
| 3862 | cli_reg->channel, cli_reg->channels); |
| 3863 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3864 | } |
| 3865 | |
| 3866 | chan->reg_classes = cla; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3867 | cli_chan->reg_classes = cli_cla; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3868 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3869 | return 0; |
| 3870 | } |
| 3871 | |
| 3872 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3873 | int wpas_p2p_get_ht40_mode(struct wpa_supplicant *wpa_s, |
| 3874 | struct hostapd_hw_modes *mode, u8 channel) |
| 3875 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3876 | int op; |
| 3877 | enum chan_allowed ret; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3878 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3879 | for (op = 0; global_op_class[op].op_class; op++) { |
| 3880 | const struct oper_class_map *o = &global_op_class[op]; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3881 | u8 ch; |
| 3882 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3883 | if (o->p2p == NO_P2P_SUPP || |
| 3884 | (is_6ghz_op_class(o->op_class) && |
| 3885 | wpa_s->conf->p2p_6ghz_disable)) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3886 | continue; |
| 3887 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3888 | for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) { |
| 3889 | if (o->mode != HOSTAPD_MODE_IEEE80211A || |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 3890 | (o->bw != BW40PLUS && o->bw != BW40MINUS) || |
| 3891 | ch != channel) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3892 | continue; |
| 3893 | ret = wpas_p2p_verify_channel(wpa_s, mode, ch, o->bw); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3894 | if (ret == ALLOWED) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3895 | return (o->bw == BW40MINUS) ? -1 : 1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3896 | } |
| 3897 | } |
| 3898 | return 0; |
| 3899 | } |
| 3900 | |
| 3901 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3902 | int wpas_p2p_get_vht80_center(struct wpa_supplicant *wpa_s, |
| 3903 | struct hostapd_hw_modes *mode, u8 channel) |
| 3904 | { |
| 3905 | if (!wpas_p2p_verify_channel(wpa_s, mode, channel, BW80)) |
| 3906 | return 0; |
| 3907 | |
| 3908 | return wpas_p2p_get_center_80mhz(wpa_s, mode, channel); |
| 3909 | } |
| 3910 | |
| 3911 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3912 | int wpas_p2p_get_vht160_center(struct wpa_supplicant *wpa_s, |
| 3913 | struct hostapd_hw_modes *mode, u8 channel) |
| 3914 | { |
| 3915 | if (!wpas_p2p_verify_channel(wpa_s, mode, channel, BW160)) |
| 3916 | return 0; |
| 3917 | return wpas_p2p_get_center_160mhz(wpa_s, mode, channel); |
| 3918 | } |
| 3919 | |
| 3920 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3921 | static int wpas_get_noa(void *ctx, const u8 *interface_addr, u8 *buf, |
| 3922 | size_t buf_len) |
| 3923 | { |
| 3924 | struct wpa_supplicant *wpa_s = ctx; |
| 3925 | |
| 3926 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 3927 | if (os_memcmp(wpa_s->own_addr, interface_addr, ETH_ALEN) == 0) |
| 3928 | break; |
| 3929 | } |
| 3930 | if (wpa_s == NULL) |
| 3931 | return -1; |
| 3932 | |
| 3933 | return wpa_drv_get_noa(wpa_s, buf, buf_len); |
| 3934 | } |
| 3935 | |
| 3936 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 3937 | struct wpa_supplicant * wpas_get_p2p_go_iface(struct wpa_supplicant *wpa_s, |
| 3938 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3939 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 3940 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 3941 | struct wpa_ssid *s = wpa_s->current_ssid; |
| 3942 | if (s == NULL) |
| 3943 | continue; |
| 3944 | if (s->mode != WPAS_MODE_P2P_GO && |
| 3945 | s->mode != WPAS_MODE_AP && |
| 3946 | s->mode != WPAS_MODE_P2P_GROUP_FORMATION) |
| 3947 | continue; |
| 3948 | if (s->ssid_len != ssid_len || |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 3949 | os_memcmp(ssid, s->ssid, ssid_len) != 0) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 3950 | continue; |
| 3951 | return wpa_s; |
| 3952 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3953 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 3954 | return NULL; |
| 3955 | |
| 3956 | } |
| 3957 | |
| 3958 | |
| 3959 | struct wpa_supplicant * wpas_get_p2p_client_iface(struct wpa_supplicant *wpa_s, |
| 3960 | const u8 *peer_dev_addr) |
| 3961 | { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3962 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 3963 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3964 | if (ssid && (ssid->mode != WPAS_MODE_INFRA || !ssid->p2p_group)) |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3965 | continue; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 3966 | if (os_memcmp(wpa_s->go_dev_addr, peer_dev_addr, ETH_ALEN) == 0) |
| 3967 | return wpa_s; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3968 | } |
| 3969 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 3970 | return NULL; |
| 3971 | } |
| 3972 | |
| 3973 | |
| 3974 | static int wpas_go_connected(void *ctx, const u8 *dev_addr) |
| 3975 | { |
| 3976 | struct wpa_supplicant *wpa_s = ctx; |
| 3977 | |
| 3978 | return wpas_get_p2p_client_iface(wpa_s, dev_addr) != NULL; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3979 | } |
| 3980 | |
| 3981 | |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 3982 | static int wpas_is_concurrent_session_active(void *ctx) |
| 3983 | { |
| 3984 | struct wpa_supplicant *wpa_s = ctx; |
| 3985 | struct wpa_supplicant *ifs; |
| 3986 | |
| 3987 | for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) { |
| 3988 | if (ifs == wpa_s) |
| 3989 | continue; |
| 3990 | if (ifs->wpa_state > WPA_ASSOCIATED) |
| 3991 | return 1; |
| 3992 | } |
| 3993 | return 0; |
| 3994 | } |
| 3995 | |
| 3996 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3997 | static void wpas_p2p_debug_print(void *ctx, int level, const char *msg) |
| 3998 | { |
| 3999 | struct wpa_supplicant *wpa_s = ctx; |
| 4000 | wpa_msg_global(wpa_s, level, "P2P: %s", msg); |
| 4001 | } |
| 4002 | |
| 4003 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4004 | int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s, |
| 4005 | const char *conf_p2p_dev) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4006 | { |
| 4007 | struct wpa_interface iface; |
| 4008 | struct wpa_supplicant *p2pdev_wpa_s; |
| 4009 | char ifname[100]; |
| 4010 | char force_name[100]; |
| 4011 | int ret; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4012 | const u8 *if_addr = NULL; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4013 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4014 | ret = os_snprintf(ifname, sizeof(ifname), P2P_MGMT_DEVICE_PREFIX "%s", |
| 4015 | wpa_s->ifname); |
| 4016 | if (os_snprintf_error(sizeof(ifname), ret)) |
| 4017 | return -1; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4018 | /* Cut length at the maximum size. Note that we don't need to ensure |
| 4019 | * collision free names here as the created interface is not a netdev. |
| 4020 | */ |
| 4021 | ifname[IFNAMSIZ - 1] = '\0'; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4022 | force_name[0] = '\0'; |
| 4023 | wpa_s->pending_interface_type = WPA_IF_P2P_DEVICE; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4024 | |
| 4025 | if (wpa_s->conf->p2p_device_random_mac_addr == 2 && |
| 4026 | !is_zero_ether_addr(wpa_s->conf->p2p_device_persistent_mac_addr)) |
| 4027 | if_addr = wpa_s->conf->p2p_device_persistent_mac_addr; |
| 4028 | |
| 4029 | 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] | 4030 | force_name, wpa_s->pending_interface_addr, NULL); |
| 4031 | if (ret < 0) { |
| 4032 | wpa_printf(MSG_DEBUG, "P2P: Failed to create P2P Device interface"); |
| 4033 | return ret; |
| 4034 | } |
| 4035 | os_strlcpy(wpa_s->pending_interface_name, ifname, |
| 4036 | sizeof(wpa_s->pending_interface_name)); |
| 4037 | |
| 4038 | os_memset(&iface, 0, sizeof(iface)); |
| 4039 | iface.p2p_mgmt = 1; |
| 4040 | iface.ifname = wpa_s->pending_interface_name; |
| 4041 | iface.driver = wpa_s->driver->name; |
| 4042 | iface.driver_param = wpa_s->conf->driver_param; |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4043 | |
| 4044 | /* |
| 4045 | * If a P2P Device configuration file was given, use it as the interface |
| 4046 | * configuration file (instead of using parent's configuration file. |
| 4047 | */ |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4048 | if (conf_p2p_dev) { |
| 4049 | iface.confname = conf_p2p_dev; |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4050 | iface.ctrl_interface = NULL; |
| 4051 | } else { |
| 4052 | iface.confname = wpa_s->confname; |
| 4053 | iface.ctrl_interface = wpa_s->conf->ctrl_interface; |
| 4054 | } |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4055 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4056 | 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] | 4057 | if (!p2pdev_wpa_s) { |
| 4058 | wpa_printf(MSG_DEBUG, "P2P: Failed to add P2P Device interface"); |
| 4059 | return -1; |
| 4060 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4061 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4062 | p2pdev_wpa_s->p2pdev = p2pdev_wpa_s; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4063 | wpa_s->pending_interface_name[0] = '\0'; |
| 4064 | return 0; |
| 4065 | } |
| 4066 | |
| 4067 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4068 | static void wpas_presence_resp(void *ctx, const u8 *src, u8 status, |
| 4069 | const u8 *noa, size_t noa_len) |
| 4070 | { |
| 4071 | struct wpa_supplicant *wpa_s, *intf = ctx; |
| 4072 | char hex[100]; |
| 4073 | |
| 4074 | for (wpa_s = intf->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 4075 | if (wpa_s->waiting_presence_resp) |
| 4076 | break; |
| 4077 | } |
| 4078 | if (!wpa_s) { |
| 4079 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No group interface was waiting for presence response"); |
| 4080 | return; |
| 4081 | } |
| 4082 | wpa_s->waiting_presence_resp = 0; |
| 4083 | |
| 4084 | wpa_snprintf_hex(hex, sizeof(hex), noa, noa_len); |
| 4085 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PRESENCE_RESPONSE "src=" MACSTR |
| 4086 | " status=%u noa=%s", MAC2STR(src), status, hex); |
| 4087 | } |
| 4088 | |
| 4089 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4090 | static int wpas_get_persistent_group(void *ctx, const u8 *addr, const u8 *ssid, |
| 4091 | size_t ssid_len, u8 *go_dev_addr, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4092 | u8 *ret_ssid, size_t *ret_ssid_len, |
| 4093 | u8 *intended_iface_addr) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4094 | { |
| 4095 | struct wpa_supplicant *wpa_s = ctx; |
| 4096 | struct wpa_ssid *s; |
| 4097 | |
| 4098 | s = wpas_p2p_get_persistent(wpa_s, addr, ssid, ssid_len); |
| 4099 | if (s) { |
| 4100 | os_memcpy(ret_ssid, s->ssid, s->ssid_len); |
| 4101 | *ret_ssid_len = s->ssid_len; |
| 4102 | os_memcpy(go_dev_addr, s->bssid, ETH_ALEN); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4103 | |
| 4104 | if (s->mode != WPAS_MODE_P2P_GO) { |
| 4105 | os_memset(intended_iface_addr, 0, ETH_ALEN); |
| 4106 | } else if (wpas_p2p_create_iface(wpa_s)) { |
| 4107 | if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO)) |
| 4108 | return 0; |
| 4109 | |
| 4110 | os_memcpy(intended_iface_addr, |
| 4111 | wpa_s->pending_interface_addr, ETH_ALEN); |
| 4112 | } else { |
| 4113 | os_memcpy(intended_iface_addr, wpa_s->own_addr, |
| 4114 | ETH_ALEN); |
| 4115 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4116 | return 1; |
| 4117 | } |
| 4118 | |
| 4119 | return 0; |
| 4120 | } |
| 4121 | |
| 4122 | |
| 4123 | static int wpas_get_go_info(void *ctx, u8 *intended_addr, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4124 | u8 *ssid, size_t *ssid_len, int *group_iface, |
| 4125 | unsigned int *freq) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4126 | { |
| 4127 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4128 | struct wpa_supplicant *go; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4129 | struct wpa_ssid *s; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4130 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4131 | /* |
| 4132 | * group_iface will be set to 1 only if a dedicated interface for P2P |
| 4133 | * role is required. First, we try to reuse an active GO. However, |
| 4134 | * if it is not present, we will try to reactivate an existing |
| 4135 | * persistent group and set group_iface to 1, so the caller will know |
| 4136 | * that the pending interface should be used. |
| 4137 | */ |
| 4138 | *group_iface = 0; |
| 4139 | |
| 4140 | if (freq) |
| 4141 | *freq = 0; |
| 4142 | |
| 4143 | go = wpas_p2p_get_go_group(wpa_s); |
| 4144 | if (!go) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4145 | s = wpas_p2p_get_persistent_go(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4146 | *group_iface = wpas_p2p_create_iface(wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4147 | if (s) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4148 | os_memcpy(intended_addr, s->bssid, ETH_ALEN); |
| 4149 | else |
| 4150 | return 0; |
| 4151 | } else { |
| 4152 | s = go->current_ssid; |
| 4153 | os_memcpy(intended_addr, go->own_addr, ETH_ALEN); |
| 4154 | if (freq) |
| 4155 | *freq = go->assoc_freq; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4156 | } |
| 4157 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4158 | os_memcpy(ssid, s->ssid, s->ssid_len); |
| 4159 | *ssid_len = s->ssid_len; |
| 4160 | |
| 4161 | return 1; |
| 4162 | } |
| 4163 | |
| 4164 | |
| 4165 | static int wpas_remove_stale_groups(void *ctx, const u8 *peer, const u8 *go, |
| 4166 | const u8 *ssid, size_t ssid_len) |
| 4167 | { |
| 4168 | struct wpa_supplicant *wpa_s = ctx; |
| 4169 | struct wpa_ssid *s; |
| 4170 | int save_config = 0; |
| 4171 | size_t i; |
| 4172 | |
| 4173 | /* Start with our first choice of Persistent Groups */ |
| 4174 | while ((s = wpas_p2p_get_persistent(wpa_s, peer, NULL, 0))) { |
| 4175 | if (go && ssid && ssid_len && |
| 4176 | s->ssid_len == ssid_len && |
| 4177 | os_memcmp(go, s->bssid, ETH_ALEN) == 0 && |
| 4178 | os_memcmp(ssid, s->ssid, ssid_len) == 0) |
| 4179 | break; |
| 4180 | |
| 4181 | /* Remove stale persistent group */ |
| 4182 | if (s->mode != WPAS_MODE_P2P_GO || s->num_p2p_clients <= 1) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4183 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4184 | "P2P: Remove stale persistent group id=%d", |
| 4185 | s->id); |
| 4186 | wpas_notify_persistent_group_removed(wpa_s, s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4187 | wpa_config_remove_network(wpa_s->conf, s->id); |
| 4188 | save_config = 1; |
| 4189 | continue; |
| 4190 | } |
| 4191 | |
| 4192 | for (i = 0; i < s->num_p2p_clients; i++) { |
| 4193 | if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN, |
| 4194 | peer, ETH_ALEN) != 0) |
| 4195 | continue; |
| 4196 | |
| 4197 | os_memmove(s->p2p_client_list + i * 2 * ETH_ALEN, |
| 4198 | s->p2p_client_list + (i + 1) * 2 * ETH_ALEN, |
| 4199 | (s->num_p2p_clients - i - 1) * 2 * ETH_ALEN); |
| 4200 | break; |
| 4201 | } |
| 4202 | s->num_p2p_clients--; |
| 4203 | save_config = 1; |
| 4204 | } |
| 4205 | |
| 4206 | if (save_config) |
| 4207 | p2p_config_write(wpa_s); |
| 4208 | |
| 4209 | /* Return TRUE if valid SSID remains */ |
| 4210 | return s != NULL; |
| 4211 | } |
| 4212 | |
| 4213 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4214 | static void wpas_p2ps_get_feat_cap_str(char *buf, size_t buf_len, |
| 4215 | const u8 *feat_cap, size_t feat_cap_len) |
| 4216 | { |
| 4217 | static const char pref[] = " feature_cap="; |
| 4218 | int ret; |
| 4219 | |
| 4220 | buf[0] = '\0'; |
| 4221 | |
| 4222 | /* |
| 4223 | * We expect a feature capability to contain at least one byte to be |
| 4224 | * reported. The string buffer provided by the caller function is |
| 4225 | * expected to be big enough to contain all bytes of the attribute for |
| 4226 | * known specifications. This function truncates the reported bytes if |
| 4227 | * the feature capability data exceeds the string buffer size. |
| 4228 | */ |
| 4229 | if (!feat_cap || !feat_cap_len || buf_len < sizeof(pref) + 2) |
| 4230 | return; |
| 4231 | |
| 4232 | os_memcpy(buf, pref, sizeof(pref)); |
| 4233 | ret = wpa_snprintf_hex(&buf[sizeof(pref) - 1], |
| 4234 | buf_len - sizeof(pref) + 1, |
| 4235 | feat_cap, feat_cap_len); |
| 4236 | |
| 4237 | if (ret != (2 * (int) feat_cap_len)) |
| 4238 | wpa_printf(MSG_WARNING, "P2PS feature_cap bytes truncated"); |
| 4239 | } |
| 4240 | |
| 4241 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4242 | static void wpas_p2ps_prov_complete(void *ctx, u8 status, const u8 *dev, |
| 4243 | const u8 *adv_mac, const u8 *ses_mac, |
| 4244 | const u8 *grp_mac, u32 adv_id, u32 ses_id, |
| 4245 | u8 conncap, int passwd_id, |
| 4246 | const u8 *persist_ssid, |
| 4247 | size_t persist_ssid_size, int response_done, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4248 | int prov_start, const char *session_info, |
| 4249 | const u8 *feat_cap, size_t feat_cap_len, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4250 | unsigned int freq, |
| 4251 | const u8 *group_ssid, size_t group_ssid_len) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4252 | { |
| 4253 | struct wpa_supplicant *wpa_s = ctx; |
| 4254 | u8 mac[ETH_ALEN]; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4255 | struct wpa_ssid *persistent_go, *stale, *s = NULL; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4256 | int save_config = 0; |
| 4257 | struct wpa_supplicant *go_wpa_s; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4258 | char feat_cap_str[256]; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4259 | |
| 4260 | if (!dev) |
| 4261 | return; |
| 4262 | |
| 4263 | os_memset(mac, 0, ETH_ALEN); |
| 4264 | if (!adv_mac) |
| 4265 | adv_mac = mac; |
| 4266 | if (!ses_mac) |
| 4267 | ses_mac = mac; |
| 4268 | if (!grp_mac) |
| 4269 | grp_mac = mac; |
| 4270 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4271 | wpas_p2ps_get_feat_cap_str(feat_cap_str, sizeof(feat_cap_str), |
| 4272 | feat_cap, feat_cap_len); |
| 4273 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4274 | if (prov_start) { |
| 4275 | if (session_info == NULL) { |
| 4276 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4277 | P2P_EVENT_P2PS_PROVISION_START MACSTR |
| 4278 | " adv_id=%x conncap=%x" |
| 4279 | " adv_mac=" MACSTR |
| 4280 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4281 | " dev_passwd_id=%d%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4282 | MAC2STR(dev), adv_id, conncap, |
| 4283 | MAC2STR(adv_mac), |
| 4284 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4285 | passwd_id, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4286 | } else { |
| 4287 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4288 | P2P_EVENT_P2PS_PROVISION_START MACSTR |
| 4289 | " adv_id=%x conncap=%x" |
| 4290 | " adv_mac=" MACSTR |
| 4291 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4292 | " dev_passwd_id=%d info='%s'%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4293 | MAC2STR(dev), adv_id, conncap, |
| 4294 | MAC2STR(adv_mac), |
| 4295 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4296 | passwd_id, session_info, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4297 | } |
| 4298 | return; |
| 4299 | } |
| 4300 | |
| 4301 | go_wpa_s = wpas_p2p_get_go_group(wpa_s); |
| 4302 | persistent_go = wpas_p2p_get_persistent_go(wpa_s); |
| 4303 | |
| 4304 | if (status && status != P2P_SC_SUCCESS_DEFERRED) { |
| 4305 | if (go_wpa_s && !p2p_group_go_member_count(wpa_s)) |
| 4306 | wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname); |
| 4307 | |
| 4308 | if (persistent_go && !persistent_go->num_p2p_clients) { |
| 4309 | /* remove empty persistent GO */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4310 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4311 | "P2P: Remove empty persistent group id=%d", |
| 4312 | persistent_go->id); |
| 4313 | wpas_notify_persistent_group_removed(wpa_s, |
| 4314 | persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4315 | wpa_config_remove_network(wpa_s->conf, |
| 4316 | persistent_go->id); |
| 4317 | } |
| 4318 | |
| 4319 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4320 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4321 | " status=%d" |
| 4322 | " adv_id=%x adv_mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4323 | " session=%x mac=" MACSTR "%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4324 | MAC2STR(dev), status, |
| 4325 | adv_id, MAC2STR(adv_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4326 | ses_id, MAC2STR(ses_mac), feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4327 | return; |
| 4328 | } |
| 4329 | |
| 4330 | /* Clean up stale persistent groups with this device */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4331 | if (persist_ssid && persist_ssid_size) |
| 4332 | s = wpas_p2p_get_persistent(wpa_s, dev, persist_ssid, |
| 4333 | persist_ssid_size); |
| 4334 | |
| 4335 | if (persist_ssid && s && s->mode != WPAS_MODE_P2P_GO && |
| 4336 | is_zero_ether_addr(grp_mac)) { |
| 4337 | wpa_dbg(wpa_s, MSG_ERROR, |
| 4338 | "P2P: Peer device is a GO in a persistent group, but it did not provide the intended MAC address"); |
| 4339 | return; |
| 4340 | } |
| 4341 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4342 | for (;;) { |
| 4343 | stale = wpas_p2p_get_persistent(wpa_s, dev, NULL, 0); |
| 4344 | if (!stale) |
| 4345 | break; |
| 4346 | |
| 4347 | if (s && s->ssid_len == stale->ssid_len && |
| 4348 | os_memcmp(stale->bssid, s->bssid, ETH_ALEN) == 0 && |
| 4349 | os_memcmp(stale->ssid, s->ssid, s->ssid_len) == 0) |
| 4350 | break; |
| 4351 | |
| 4352 | /* Remove stale persistent group */ |
| 4353 | if (stale->mode != WPAS_MODE_P2P_GO || |
| 4354 | stale->num_p2p_clients <= 1) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4355 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4356 | "P2P: Remove stale persistent group id=%d", |
| 4357 | stale->id); |
| 4358 | wpas_notify_persistent_group_removed(wpa_s, stale); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4359 | wpa_config_remove_network(wpa_s->conf, stale->id); |
| 4360 | } else { |
| 4361 | size_t i; |
| 4362 | |
| 4363 | for (i = 0; i < stale->num_p2p_clients; i++) { |
| 4364 | if (os_memcmp(stale->p2p_client_list + |
| 4365 | i * ETH_ALEN, |
| 4366 | dev, ETH_ALEN) == 0) { |
| 4367 | os_memmove(stale->p2p_client_list + |
| 4368 | i * ETH_ALEN, |
| 4369 | stale->p2p_client_list + |
| 4370 | (i + 1) * ETH_ALEN, |
| 4371 | (stale->num_p2p_clients - |
| 4372 | i - 1) * ETH_ALEN); |
| 4373 | break; |
| 4374 | } |
| 4375 | } |
| 4376 | stale->num_p2p_clients--; |
| 4377 | } |
| 4378 | save_config = 1; |
| 4379 | } |
| 4380 | |
| 4381 | if (save_config) |
| 4382 | p2p_config_write(wpa_s); |
| 4383 | |
| 4384 | if (s) { |
| 4385 | if (go_wpa_s && !p2p_group_go_member_count(wpa_s)) |
| 4386 | wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname); |
| 4387 | |
| 4388 | if (persistent_go && s != persistent_go && |
| 4389 | !persistent_go->num_p2p_clients) { |
| 4390 | /* remove empty persistent GO */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4391 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4392 | "P2P: Remove empty persistent group id=%d", |
| 4393 | persistent_go->id); |
| 4394 | wpas_notify_persistent_group_removed(wpa_s, |
| 4395 | persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4396 | wpa_config_remove_network(wpa_s->conf, |
| 4397 | persistent_go->id); |
| 4398 | /* Save config */ |
| 4399 | } |
| 4400 | |
| 4401 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4402 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4403 | " status=%d" |
| 4404 | " adv_id=%x adv_mac=" MACSTR |
| 4405 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4406 | " persist=%d%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4407 | MAC2STR(dev), status, |
| 4408 | adv_id, MAC2STR(adv_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4409 | ses_id, MAC2STR(ses_mac), s->id, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4410 | return; |
| 4411 | } |
| 4412 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4413 | wpa_s->global->pending_p2ps_group = 0; |
| 4414 | wpa_s->global->pending_p2ps_group_freq = 0; |
| 4415 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4416 | if (conncap == P2PS_SETUP_GROUP_OWNER) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4417 | /* |
| 4418 | * We need to copy the interface name. Simply saving a |
| 4419 | * pointer isn't enough, since if we use pending_interface_name |
| 4420 | * it will be overwritten when the group is added. |
| 4421 | */ |
| 4422 | char go_ifname[100]; |
| 4423 | |
| 4424 | go_ifname[0] = '\0'; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4425 | if (!go_wpa_s) { |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4426 | if (!response_done) { |
| 4427 | wpa_s->global->pending_p2ps_group = 1; |
| 4428 | wpa_s->global->pending_p2ps_group_freq = freq; |
| 4429 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4430 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4431 | if (!wpas_p2p_create_iface(wpa_s)) |
| 4432 | os_memcpy(go_ifname, wpa_s->ifname, |
| 4433 | sizeof(go_ifname)); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4434 | else if (wpa_s->pending_interface_name[0]) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4435 | os_memcpy(go_ifname, |
| 4436 | wpa_s->pending_interface_name, |
| 4437 | sizeof(go_ifname)); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4438 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4439 | if (!go_ifname[0]) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4440 | wpas_p2ps_prov_complete( |
| 4441 | wpa_s, P2P_SC_FAIL_UNKNOWN_GROUP, |
| 4442 | dev, adv_mac, ses_mac, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4443 | grp_mac, adv_id, ses_id, 0, 0, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4444 | NULL, 0, 0, 0, NULL, NULL, 0, 0, |
| 4445 | NULL, 0); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4446 | return; |
| 4447 | } |
| 4448 | |
| 4449 | /* If PD Resp complete, start up the GO */ |
| 4450 | if (response_done && persistent_go) { |
| 4451 | wpas_p2p_group_add_persistent( |
| 4452 | wpa_s, persistent_go, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4453 | 0, 0, freq, 0, 0, 0, 0, 0, 0, NULL, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4454 | persistent_go->mode == |
| 4455 | WPAS_MODE_P2P_GO ? |
| 4456 | P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4457 | 0, 0); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4458 | } else if (response_done) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4459 | wpas_p2p_group_add(wpa_s, 1, freq, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4460 | 0, 0, 0, 0, 0, 0); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4461 | } |
| 4462 | |
| 4463 | if (passwd_id == DEV_PW_P2PS_DEFAULT) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4464 | os_memcpy(wpa_s->p2ps_join_addr, grp_mac, |
| 4465 | ETH_ALEN); |
| 4466 | wpa_s->p2ps_method_config_any = 1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4467 | } |
| 4468 | } else if (passwd_id == DEV_PW_P2PS_DEFAULT) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4469 | os_memcpy(go_ifname, go_wpa_s->ifname, |
| 4470 | sizeof(go_ifname)); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4471 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4472 | if (is_zero_ether_addr(grp_mac)) { |
| 4473 | wpa_dbg(go_wpa_s, MSG_DEBUG, |
| 4474 | "P2P: Setting PIN-1 for ANY"); |
| 4475 | wpa_supplicant_ap_wps_pin(go_wpa_s, NULL, |
| 4476 | "12345670", NULL, 0, |
| 4477 | 0); |
| 4478 | } else { |
| 4479 | wpa_dbg(go_wpa_s, MSG_DEBUG, |
| 4480 | "P2P: Setting PIN-1 for " MACSTR, |
| 4481 | MAC2STR(grp_mac)); |
| 4482 | wpa_supplicant_ap_wps_pin(go_wpa_s, grp_mac, |
| 4483 | "12345670", NULL, 0, |
| 4484 | 0); |
| 4485 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4486 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4487 | os_memcpy(wpa_s->p2ps_join_addr, grp_mac, ETH_ALEN); |
| 4488 | wpa_s->p2ps_method_config_any = 1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4489 | } |
| 4490 | |
| 4491 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4492 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4493 | " status=%d conncap=%x" |
| 4494 | " adv_id=%x adv_mac=" MACSTR |
| 4495 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4496 | " dev_passwd_id=%d go=%s%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4497 | MAC2STR(dev), status, conncap, |
| 4498 | adv_id, MAC2STR(adv_mac), |
| 4499 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4500 | passwd_id, go_ifname, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4501 | return; |
| 4502 | } |
| 4503 | |
| 4504 | if (go_wpa_s && !p2p_group_go_member_count(wpa_s)) |
| 4505 | wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname); |
| 4506 | |
| 4507 | if (persistent_go && !persistent_go->num_p2p_clients) { |
| 4508 | /* remove empty persistent GO */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4509 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4510 | "P2P: Remove empty persistent group id=%d", |
| 4511 | persistent_go->id); |
| 4512 | wpas_notify_persistent_group_removed(wpa_s, persistent_go); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4513 | wpa_config_remove_network(wpa_s->conf, persistent_go->id); |
| 4514 | } |
| 4515 | |
| 4516 | if (conncap == P2PS_SETUP_CLIENT) { |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4517 | char ssid_hex[32 * 2 + 1]; |
| 4518 | |
| 4519 | if (group_ssid) |
| 4520 | wpa_snprintf_hex(ssid_hex, sizeof(ssid_hex), |
| 4521 | group_ssid, group_ssid_len); |
| 4522 | else |
| 4523 | ssid_hex[0] = '\0'; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4524 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4525 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4526 | " status=%d conncap=%x" |
| 4527 | " adv_id=%x adv_mac=" MACSTR |
| 4528 | " session=%x mac=" MACSTR |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4529 | " dev_passwd_id=%d join=" MACSTR "%s%s%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4530 | MAC2STR(dev), status, conncap, |
| 4531 | adv_id, MAC2STR(adv_mac), |
| 4532 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4533 | passwd_id, MAC2STR(grp_mac), feat_cap_str, |
| 4534 | group_ssid ? " group_ssid=" : "", ssid_hex); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4535 | } else { |
| 4536 | wpa_msg_global(wpa_s, MSG_INFO, |
| 4537 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR |
| 4538 | " status=%d conncap=%x" |
| 4539 | " adv_id=%x adv_mac=" MACSTR |
| 4540 | " session=%x mac=" MACSTR |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4541 | " dev_passwd_id=%d%s", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4542 | MAC2STR(dev), status, conncap, |
| 4543 | adv_id, MAC2STR(adv_mac), |
| 4544 | ses_id, MAC2STR(ses_mac), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4545 | passwd_id, feat_cap_str); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4546 | } |
| 4547 | } |
| 4548 | |
| 4549 | |
Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 4550 | static int _wpas_p2p_in_progress(void *ctx) |
| 4551 | { |
| 4552 | struct wpa_supplicant *wpa_s = ctx; |
| 4553 | return wpas_p2p_in_progress(wpa_s); |
| 4554 | } |
| 4555 | |
| 4556 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4557 | static int wpas_prov_disc_resp_cb(void *ctx) |
| 4558 | { |
| 4559 | struct wpa_supplicant *wpa_s = ctx; |
| 4560 | struct wpa_ssid *persistent_go; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4561 | unsigned int freq; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4562 | |
| 4563 | if (!wpa_s->global->pending_p2ps_group) |
| 4564 | return 0; |
| 4565 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4566 | freq = wpa_s->global->pending_p2ps_group_freq; |
| 4567 | wpa_s->global->pending_p2ps_group_freq = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4568 | wpa_s->global->pending_p2ps_group = 0; |
| 4569 | |
| 4570 | if (wpas_p2p_get_go_group(wpa_s)) |
| 4571 | return 0; |
| 4572 | persistent_go = wpas_p2p_get_persistent_go(wpa_s); |
| 4573 | |
| 4574 | if (persistent_go) { |
| 4575 | wpas_p2p_group_add_persistent( |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4576 | wpa_s, persistent_go, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 4577 | NULL, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4578 | persistent_go->mode == WPAS_MODE_P2P_GO ? |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4579 | P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0, 0); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4580 | } else { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4581 | wpas_p2p_group_add(wpa_s, 1, freq, 0, 0, 0, 0, 0, 0); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4582 | } |
| 4583 | |
| 4584 | return 1; |
| 4585 | } |
| 4586 | |
| 4587 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4588 | static int wpas_p2p_get_pref_freq_list(void *ctx, int go, |
| 4589 | unsigned int *len, |
| 4590 | unsigned int *freq_list) |
| 4591 | { |
| 4592 | struct wpa_supplicant *wpa_s = ctx; |
| 4593 | |
| 4594 | return wpa_drv_get_pref_freq_list(wpa_s, go ? WPA_IF_P2P_GO : |
| 4595 | WPA_IF_P2P_CLIENT, len, freq_list); |
| 4596 | } |
| 4597 | |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4598 | int wpas_p2p_mac_setup(struct wpa_supplicant *wpa_s) |
| 4599 | { |
| 4600 | u8 addr[ETH_ALEN] = {0}; |
| 4601 | |
| 4602 | if (wpa_s->conf->p2p_device_random_mac_addr == 0) |
| 4603 | return 0; |
| 4604 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4605 | if (wpa_s->conf->p2p_device_random_mac_addr == 2) { |
| 4606 | if (is_zero_ether_addr( |
| 4607 | wpa_s->conf->p2p_device_persistent_mac_addr) && |
| 4608 | !is_zero_ether_addr(wpa_s->own_addr)) { |
| 4609 | os_memcpy(wpa_s->conf->p2p_device_persistent_mac_addr, |
| 4610 | wpa_s->own_addr, ETH_ALEN); |
| 4611 | } |
| 4612 | return 0; |
| 4613 | } |
| 4614 | |
| 4615 | if (!wpa_s->conf->ssid) { |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4616 | if (random_mac_addr(addr) < 0) { |
| 4617 | wpa_msg(wpa_s, MSG_INFO, |
| 4618 | "Failed to generate random MAC address"); |
| 4619 | return -EINVAL; |
| 4620 | } |
| 4621 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 4622 | /* Store generated MAC address. */ |
| 4623 | os_memcpy(wpa_s->conf->p2p_device_persistent_mac_addr, addr, |
| 4624 | ETH_ALEN); |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4625 | } else { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 4626 | /* If there are existing saved groups, restore last MAC address. |
| 4627 | * if there is no last used MAC address, the last one is |
| 4628 | * factory MAC. */ |
| 4629 | if (is_zero_ether_addr( |
| 4630 | wpa_s->conf->p2p_device_persistent_mac_addr)) |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4631 | return 0; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 4632 | os_memcpy(addr, wpa_s->conf->p2p_device_persistent_mac_addr, |
| 4633 | ETH_ALEN); |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4634 | wpa_msg(wpa_s, MSG_DEBUG, "Restore last used MAC address."); |
| 4635 | } |
| 4636 | |
| 4637 | if (wpa_drv_set_mac_addr(wpa_s, addr) < 0) { |
| 4638 | wpa_msg(wpa_s, MSG_INFO, |
| 4639 | "Failed to set random MAC address"); |
| 4640 | return -EINVAL; |
| 4641 | } |
| 4642 | |
| 4643 | if (wpa_supplicant_update_mac_addr(wpa_s) < 0) { |
| 4644 | wpa_msg(wpa_s, MSG_INFO, |
| 4645 | "Could not update MAC address information"); |
| 4646 | return -EINVAL; |
| 4647 | } |
| 4648 | |
| 4649 | wpa_msg(wpa_s, MSG_DEBUG, "Using random MAC address " MACSTR, |
| 4650 | MAC2STR(addr)); |
| 4651 | |
| 4652 | return 0; |
| 4653 | } |
| 4654 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4655 | /** |
| 4656 | * wpas_p2p_init - Initialize P2P module for %wpa_supplicant |
| 4657 | * @global: Pointer to global data from wpa_supplicant_init() |
| 4658 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 4659 | * Returns: 0 on success, -1 on failure |
| 4660 | */ |
| 4661 | int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s) |
| 4662 | { |
| 4663 | struct p2p_config p2p; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4664 | int i; |
| 4665 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 4666 | if (wpa_s->conf->p2p_disabled) |
| 4667 | return 0; |
| 4668 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4669 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE)) |
| 4670 | return 0; |
| 4671 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4672 | if (global->p2p) |
| 4673 | return 0; |
| 4674 | |
Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4675 | if (wpas_p2p_mac_setup(wpa_s) < 0) { |
| 4676 | wpa_msg(wpa_s, MSG_ERROR, |
| 4677 | "Failed to initialize P2P random MAC address."); |
| 4678 | return -1; |
| 4679 | } |
| 4680 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4681 | os_memset(&p2p, 0, sizeof(p2p)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4682 | p2p.cb_ctx = wpa_s; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 4683 | p2p.debug_print = wpas_p2p_debug_print; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4684 | p2p.p2p_scan = wpas_p2p_scan; |
| 4685 | p2p.send_action = wpas_send_action; |
| 4686 | p2p.send_action_done = wpas_send_action_done; |
| 4687 | p2p.go_neg_completed = wpas_go_neg_completed; |
| 4688 | p2p.go_neg_req_rx = wpas_go_neg_req_rx; |
| 4689 | p2p.dev_found = wpas_dev_found; |
| 4690 | p2p.dev_lost = wpas_dev_lost; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 4691 | p2p.find_stopped = wpas_find_stopped; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4692 | p2p.start_listen = wpas_start_listen; |
| 4693 | p2p.stop_listen = wpas_stop_listen; |
| 4694 | p2p.send_probe_resp = wpas_send_probe_resp; |
| 4695 | p2p.sd_request = wpas_sd_request; |
| 4696 | p2p.sd_response = wpas_sd_response; |
| 4697 | p2p.prov_disc_req = wpas_prov_disc_req; |
| 4698 | p2p.prov_disc_resp = wpas_prov_disc_resp; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 4699 | p2p.prov_disc_fail = wpas_prov_disc_fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4700 | p2p.invitation_process = wpas_invitation_process; |
| 4701 | p2p.invitation_received = wpas_invitation_received; |
| 4702 | p2p.invitation_result = wpas_invitation_result; |
| 4703 | p2p.get_noa = wpas_get_noa; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4704 | p2p.go_connected = wpas_go_connected; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4705 | p2p.presence_resp = wpas_presence_resp; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 4706 | p2p.is_concurrent_session_active = wpas_is_concurrent_session_active; |
Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 4707 | p2p.is_p2p_in_progress = _wpas_p2p_in_progress; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4708 | p2p.get_persistent_group = wpas_get_persistent_group; |
| 4709 | p2p.get_go_info = wpas_get_go_info; |
| 4710 | p2p.remove_stale_groups = wpas_remove_stale_groups; |
| 4711 | p2p.p2ps_prov_complete = wpas_p2ps_prov_complete; |
| 4712 | p2p.prov_disc_resp_cb = wpas_prov_disc_resp_cb; |
| 4713 | p2p.p2ps_group_capability = p2ps_group_capability; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4714 | p2p.get_pref_freq_list = wpas_p2p_get_pref_freq_list; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4715 | p2p.p2p_6ghz_disable = wpa_s->conf->p2p_6ghz_disable; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4716 | |
| 4717 | 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] | 4718 | 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] | 4719 | p2p.dev_name = wpa_s->conf->device_name; |
| 4720 | p2p.manufacturer = wpa_s->conf->manufacturer; |
| 4721 | p2p.model_name = wpa_s->conf->model_name; |
| 4722 | p2p.model_number = wpa_s->conf->model_number; |
| 4723 | p2p.serial_number = wpa_s->conf->serial_number; |
| 4724 | if (wpa_s->wps) { |
| 4725 | os_memcpy(p2p.uuid, wpa_s->wps->uuid, 16); |
| 4726 | p2p.config_methods = wpa_s->wps->config_methods; |
| 4727 | } |
| 4728 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4729 | if (wpas_p2p_setup_channels(wpa_s, &p2p.channels, &p2p.cli_channels, |
| 4730 | p2p.p2p_6ghz_disable)) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4731 | wpa_printf(MSG_ERROR, |
| 4732 | "P2P: Failed to configure supported channel list"); |
| 4733 | return -1; |
| 4734 | } |
| 4735 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4736 | if (wpa_s->conf->p2p_listen_reg_class && |
| 4737 | wpa_s->conf->p2p_listen_channel) { |
| 4738 | p2p.reg_class = wpa_s->conf->p2p_listen_reg_class; |
| 4739 | p2p.channel = wpa_s->conf->p2p_listen_channel; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 4740 | p2p.channel_forced = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4741 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4742 | /* |
| 4743 | * Pick one of the social channels randomly as the listen |
| 4744 | * channel. |
| 4745 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4746 | if (p2p_config_get_random_social(&p2p, &p2p.reg_class, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4747 | &p2p.channel, |
| 4748 | &global->p2p_go_avoid_freq, |
| 4749 | &global->p2p_disallow_freq) != |
| 4750 | 0) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 4751 | wpa_printf(MSG_INFO, |
| 4752 | "P2P: No social channels supported by the driver - do not enable P2P"); |
| 4753 | return 0; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4754 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 4755 | p2p.channel_forced = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4756 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4757 | wpa_printf(MSG_DEBUG, "P2P: Own listen channel: %d:%d", |
| 4758 | p2p.reg_class, p2p.channel); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4759 | |
| 4760 | if (wpa_s->conf->p2p_oper_reg_class && |
| 4761 | wpa_s->conf->p2p_oper_channel) { |
| 4762 | p2p.op_reg_class = wpa_s->conf->p2p_oper_reg_class; |
| 4763 | p2p.op_channel = wpa_s->conf->p2p_oper_channel; |
| 4764 | p2p.cfg_op_channel = 1; |
| 4765 | wpa_printf(MSG_DEBUG, "P2P: Configured operating channel: " |
| 4766 | "%d:%d", p2p.op_reg_class, p2p.op_channel); |
| 4767 | |
| 4768 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4769 | /* |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4770 | * Use random operation channel from 2.4 GHz band social |
| 4771 | * channels (1, 6, 11) or band 60 GHz social channel (2) if no |
| 4772 | * other preference is indicated. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4773 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4774 | if (p2p_config_get_random_social(&p2p, &p2p.op_reg_class, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4775 | &p2p.op_channel, NULL, |
| 4776 | NULL) != 0) { |
| 4777 | wpa_printf(MSG_INFO, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4778 | "P2P: Failed to select random social channel as operation channel"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4779 | p2p.op_reg_class = 0; |
| 4780 | p2p.op_channel = 0; |
| 4781 | /* This will be overridden during group setup in |
| 4782 | * p2p_prepare_channel(), so allow setup to continue. */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4783 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4784 | p2p.cfg_op_channel = 0; |
| 4785 | wpa_printf(MSG_DEBUG, "P2P: Random operating channel: " |
| 4786 | "%d:%d", p2p.op_reg_class, p2p.op_channel); |
| 4787 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 4788 | |
| 4789 | if (wpa_s->conf->p2p_pref_chan && wpa_s->conf->num_p2p_pref_chan) { |
| 4790 | p2p.pref_chan = wpa_s->conf->p2p_pref_chan; |
| 4791 | p2p.num_pref_chan = wpa_s->conf->num_p2p_pref_chan; |
| 4792 | } |
| 4793 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4794 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) { |
| 4795 | os_memcpy(p2p.country, wpa_s->conf->country, 2); |
| 4796 | p2p.country[2] = 0x04; |
| 4797 | } else |
| 4798 | os_memcpy(p2p.country, "XX\x04", 3); |
| 4799 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4800 | os_memcpy(p2p.pri_dev_type, wpa_s->conf->device_type, |
| 4801 | WPS_DEV_TYPE_LEN); |
| 4802 | |
| 4803 | p2p.num_sec_dev_types = wpa_s->conf->num_sec_device_types; |
| 4804 | os_memcpy(p2p.sec_dev_type, wpa_s->conf->sec_device_type, |
| 4805 | p2p.num_sec_dev_types * WPS_DEV_TYPE_LEN); |
| 4806 | |
| 4807 | p2p.concurrent_operations = !!(wpa_s->drv_flags & |
| 4808 | WPA_DRIVER_FLAGS_P2P_CONCURRENT); |
| 4809 | |
| 4810 | p2p.max_peers = 100; |
| 4811 | |
| 4812 | if (wpa_s->conf->p2p_ssid_postfix) { |
| 4813 | p2p.ssid_postfix_len = |
| 4814 | os_strlen(wpa_s->conf->p2p_ssid_postfix); |
| 4815 | if (p2p.ssid_postfix_len > sizeof(p2p.ssid_postfix)) |
| 4816 | p2p.ssid_postfix_len = sizeof(p2p.ssid_postfix); |
| 4817 | os_memcpy(p2p.ssid_postfix, wpa_s->conf->p2p_ssid_postfix, |
| 4818 | p2p.ssid_postfix_len); |
| 4819 | } |
| 4820 | |
| 4821 | p2p.p2p_intra_bss = wpa_s->conf->p2p_intra_bss; |
| 4822 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4823 | p2p.max_listen = wpa_s->max_remain_on_chan; |
| 4824 | |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 4825 | if (wpa_s->conf->p2p_passphrase_len >= 8 && |
| 4826 | wpa_s->conf->p2p_passphrase_len <= 63) |
| 4827 | p2p.passphrase_len = wpa_s->conf->p2p_passphrase_len; |
| 4828 | else |
| 4829 | p2p.passphrase_len = 8; |
| 4830 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4831 | global->p2p = p2p_init(&p2p); |
| 4832 | if (global->p2p == NULL) |
| 4833 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4834 | global->p2p_init_wpa_s = wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4835 | |
| 4836 | for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) { |
| 4837 | if (wpa_s->conf->wps_vendor_ext[i] == NULL) |
| 4838 | continue; |
| 4839 | p2p_add_wps_vendor_extension( |
| 4840 | global->p2p, wpa_s->conf->wps_vendor_ext[i]); |
| 4841 | } |
| 4842 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4843 | p2p_set_no_go_freq(global->p2p, &wpa_s->conf->p2p_no_go_freq); |
| 4844 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4845 | return 0; |
| 4846 | } |
| 4847 | |
| 4848 | |
| 4849 | /** |
| 4850 | * wpas_p2p_deinit - Deinitialize per-interface P2P data |
| 4851 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 4852 | * |
| 4853 | * This function deinitialize per-interface P2P data. |
| 4854 | */ |
| 4855 | void wpas_p2p_deinit(struct wpa_supplicant *wpa_s) |
| 4856 | { |
| 4857 | if (wpa_s->driver && wpa_s->drv_priv) |
| 4858 | wpa_drv_probe_req_report(wpa_s, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4859 | |
| 4860 | if (wpa_s->go_params) { |
| 4861 | /* Clear any stored provisioning info */ |
| 4862 | p2p_clear_provisioning_info( |
| 4863 | wpa_s->global->p2p, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4864 | wpa_s->go_params->peer_device_addr); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4865 | } |
| 4866 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4867 | os_free(wpa_s->go_params); |
| 4868 | wpa_s->go_params = NULL; |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 4869 | eloop_cancel_timeout(wpas_p2p_psk_failure_removal, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4870 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 4871 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4872 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4873 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
| 4874 | eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL); |
| 4875 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 4876 | eloop_cancel_timeout(wpas_p2p_group_freq_conflict, wpa_s, NULL); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4877 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, wpa_s, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4878 | wpas_p2p_listen_work_done(wpa_s); |
| 4879 | if (wpa_s->p2p_send_action_work) { |
| 4880 | os_free(wpa_s->p2p_send_action_work->ctx); |
| 4881 | radio_work_done(wpa_s->p2p_send_action_work); |
| 4882 | wpa_s->p2p_send_action_work = NULL; |
| 4883 | } |
| 4884 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4885 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 4886 | wpabuf_free(wpa_s->p2p_oob_dev_pw); |
| 4887 | wpa_s->p2p_oob_dev_pw = NULL; |
| 4888 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4889 | os_free(wpa_s->p2p_group_common_freqs); |
| 4890 | wpa_s->p2p_group_common_freqs = NULL; |
| 4891 | wpa_s->p2p_group_common_freqs_num = 0; |
| 4892 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4893 | /* TODO: remove group interface from the driver if this wpa_s instance |
| 4894 | * is on top of a P2P group interface */ |
| 4895 | } |
| 4896 | |
| 4897 | |
| 4898 | /** |
| 4899 | * wpas_p2p_deinit_global - Deinitialize global P2P module |
| 4900 | * @global: Pointer to global data from wpa_supplicant_init() |
| 4901 | * |
| 4902 | * This function deinitializes the global (per device) P2P module. |
| 4903 | */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 4904 | static void wpas_p2p_deinit_global(struct wpa_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4905 | { |
| 4906 | struct wpa_supplicant *wpa_s, *tmp; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4907 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4908 | wpa_s = global->ifaces; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4909 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4910 | wpas_p2p_service_flush(global->p2p_init_wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4911 | |
| 4912 | /* Remove remaining P2P group interfaces */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4913 | while (wpa_s && wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) |
| 4914 | wpa_s = wpa_s->next; |
| 4915 | while (wpa_s) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4916 | tmp = global->ifaces; |
| 4917 | while (tmp && |
| 4918 | (tmp == wpa_s || |
| 4919 | tmp->p2p_group_interface == NOT_P2P_GROUP_INTERFACE)) { |
| 4920 | tmp = tmp->next; |
| 4921 | } |
| 4922 | if (tmp == NULL) |
| 4923 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4924 | /* Disconnect from the P2P group and deinit the interface */ |
| 4925 | wpas_p2p_disconnect(tmp); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4926 | } |
| 4927 | |
| 4928 | /* |
| 4929 | * Deinit GO data on any possibly remaining interface (if main |
| 4930 | * interface is used as GO). |
| 4931 | */ |
| 4932 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 4933 | if (wpa_s->ap_iface) |
| 4934 | wpas_p2p_group_deinit(wpa_s); |
| 4935 | } |
| 4936 | |
| 4937 | p2p_deinit(global->p2p); |
| 4938 | global->p2p = NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4939 | global->p2p_init_wpa_s = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4940 | } |
| 4941 | |
| 4942 | |
| 4943 | static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s) |
| 4944 | { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4945 | if (wpa_s->conf->p2p_no_group_iface) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4946 | return 0; /* separate interface disabled per configuration */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4947 | if (wpa_s->drv_flags & |
| 4948 | (WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE | |
| 4949 | WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P)) |
| 4950 | return 1; /* P2P group requires a new interface in every case |
| 4951 | */ |
| 4952 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CONCURRENT)) |
| 4953 | return 0; /* driver does not support concurrent operations */ |
| 4954 | if (wpa_s->global->ifaces->next) |
| 4955 | return 1; /* more that one interface already in use */ |
| 4956 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
| 4957 | return 1; /* this interface is already in use */ |
| 4958 | return 0; |
| 4959 | } |
| 4960 | |
| 4961 | |
| 4962 | static int wpas_p2p_start_go_neg(struct wpa_supplicant *wpa_s, |
| 4963 | const u8 *peer_addr, |
| 4964 | enum p2p_wps_method wps_method, |
| 4965 | int go_intent, const u8 *own_interface_addr, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4966 | unsigned int force_freq, int persistent_group, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4967 | struct wpa_ssid *ssid, unsigned int pref_freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4968 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4969 | if (persistent_group && wpa_s->conf->persistent_reconnect) |
| 4970 | persistent_group = 2; |
| 4971 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4972 | /* |
| 4973 | * Increase GO config timeout if HT40 is used since it takes some time |
| 4974 | * to scan channels for coex purposes before the BSS can be started. |
| 4975 | */ |
| 4976 | p2p_set_config_timeout(wpa_s->global->p2p, |
| 4977 | wpa_s->p2p_go_ht40 ? 255 : 100, 20); |
| 4978 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4979 | return p2p_connect(wpa_s->global->p2p, peer_addr, wps_method, |
| 4980 | go_intent, own_interface_addr, force_freq, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4981 | persistent_group, ssid ? ssid->ssid : NULL, |
| 4982 | ssid ? ssid->ssid_len : 0, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 4983 | wpa_s->p2p_pd_before_go_neg, pref_freq, |
| 4984 | wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id : |
| 4985 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4986 | } |
| 4987 | |
| 4988 | |
| 4989 | static int wpas_p2p_auth_go_neg(struct wpa_supplicant *wpa_s, |
| 4990 | const u8 *peer_addr, |
| 4991 | enum p2p_wps_method wps_method, |
| 4992 | int go_intent, const u8 *own_interface_addr, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4993 | unsigned int force_freq, int persistent_group, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4994 | struct wpa_ssid *ssid, unsigned int pref_freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4995 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4996 | if (persistent_group && wpa_s->conf->persistent_reconnect) |
| 4997 | persistent_group = 2; |
| 4998 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4999 | return p2p_authorize(wpa_s->global->p2p, peer_addr, wps_method, |
| 5000 | go_intent, own_interface_addr, force_freq, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5001 | persistent_group, ssid ? ssid->ssid : NULL, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5002 | ssid ? ssid->ssid_len : 0, pref_freq, |
| 5003 | wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id : |
| 5004 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5005 | } |
| 5006 | |
| 5007 | |
| 5008 | static void wpas_p2p_check_join_scan_limit(struct wpa_supplicant *wpa_s) |
| 5009 | { |
| 5010 | wpa_s->p2p_join_scan_count++; |
| 5011 | wpa_printf(MSG_DEBUG, "P2P: Join scan attempt %d", |
| 5012 | wpa_s->p2p_join_scan_count); |
| 5013 | if (wpa_s->p2p_join_scan_count > P2P_MAX_JOIN_SCAN_ATTEMPTS) { |
| 5014 | wpa_printf(MSG_DEBUG, "P2P: Failed to find GO " MACSTR |
| 5015 | " for join operationg - stop join attempt", |
| 5016 | MAC2STR(wpa_s->pending_join_iface_addr)); |
| 5017 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5018 | if (wpa_s->p2p_auto_pd) { |
| 5019 | wpa_s->p2p_auto_pd = 0; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5020 | wpa_msg_global(wpa_s, MSG_INFO, |
| 5021 | P2P_EVENT_PROV_DISC_FAILURE |
| 5022 | " p2p_dev_addr=" MACSTR " status=N/A", |
| 5023 | MAC2STR(wpa_s->pending_join_dev_addr)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5024 | return; |
| 5025 | } |
Jimmy Chen | b7b3f4d | 2020-09-02 16:50:11 +0800 | [diff] [blame] | 5026 | if (wpa_s->p2p_fallback_to_go_neg) { |
| 5027 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Join operating " |
| 5028 | "failed - fall back to GO Negotiation"); |
| 5029 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
| 5030 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 5031 | "reason=join-failed"); |
| 5032 | wpas_p2p_fallback_to_go_neg(wpa_s, 0); |
| 5033 | return; |
| 5034 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5035 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5036 | P2P_EVENT_GROUP_FORMATION_FAILURE); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5037 | wpas_notify_p2p_group_formation_failure(wpa_s, ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5038 | } |
| 5039 | } |
| 5040 | |
| 5041 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5042 | static int wpas_check_freq_conflict(struct wpa_supplicant *wpa_s, int freq) |
| 5043 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5044 | int res; |
| 5045 | unsigned int num, i; |
| 5046 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5047 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5048 | if (wpas_p2p_num_unused_channels(wpa_s) > 0) { |
| 5049 | /* Multiple channels are supported and not all are in use */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5050 | return 0; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5051 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5052 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5053 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 5054 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5055 | if (!freqs) |
| 5056 | return 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5057 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5058 | num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, |
| 5059 | wpa_s->num_multichan_concurrent); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5060 | |
| 5061 | for (i = 0; i < num; i++) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5062 | if (freqs[i].freq == freq) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5063 | wpa_printf(MSG_DEBUG, "P2P: Frequency %d MHz in use by another virtual interface and can be used", |
| 5064 | freq); |
| 5065 | res = 0; |
| 5066 | goto exit_free; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5067 | } |
| 5068 | } |
| 5069 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5070 | wpa_printf(MSG_DEBUG, "P2P: No valid operating frequencies"); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5071 | res = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5072 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5073 | exit_free: |
| 5074 | os_free(freqs); |
| 5075 | return res; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5076 | } |
| 5077 | |
| 5078 | |
| 5079 | static int wpas_p2p_peer_go(struct wpa_supplicant *wpa_s, |
| 5080 | const u8 *peer_dev_addr) |
| 5081 | { |
| 5082 | struct wpa_bss *bss; |
| 5083 | int updated; |
| 5084 | |
| 5085 | bss = wpa_bss_get_p2p_dev_addr(wpa_s, peer_dev_addr); |
| 5086 | if (bss == NULL) |
| 5087 | return -1; |
| 5088 | if (bss->last_update_idx < wpa_s->bss_update_idx) { |
| 5089 | wpa_printf(MSG_DEBUG, "P2P: Peer BSS entry not updated in the " |
| 5090 | "last scan"); |
| 5091 | return 0; |
| 5092 | } |
| 5093 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5094 | updated = os_reltime_before(&wpa_s->p2p_auto_started, |
| 5095 | &bss->last_update); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5096 | wpa_printf(MSG_DEBUG, "P2P: Current BSS entry for peer updated at " |
| 5097 | "%ld.%06ld (%supdated in last scan)", |
| 5098 | bss->last_update.sec, bss->last_update.usec, |
| 5099 | updated ? "": "not "); |
| 5100 | |
| 5101 | return updated; |
| 5102 | } |
| 5103 | |
| 5104 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5105 | static void wpas_p2p_scan_res_join(struct wpa_supplicant *wpa_s, |
| 5106 | struct wpa_scan_results *scan_res) |
| 5107 | { |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5108 | struct wpa_bss *bss = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5109 | int freq; |
| 5110 | u8 iface_addr[ETH_ALEN]; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5111 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5112 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
| 5113 | |
| 5114 | if (wpa_s->global->p2p_disabled) |
| 5115 | return; |
| 5116 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5117 | wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS) for %sjoin", |
| 5118 | scan_res ? (int) scan_res->num : -1, |
| 5119 | wpa_s->p2p_auto_join ? "auto_" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5120 | |
| 5121 | if (scan_res) |
| 5122 | wpas_p2p_scan_res_handler(wpa_s, scan_res); |
| 5123 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5124 | if (wpa_s->p2p_auto_pd) { |
| 5125 | int join = wpas_p2p_peer_go(wpa_s, |
| 5126 | wpa_s->pending_join_dev_addr); |
| 5127 | if (join == 0 && |
| 5128 | wpa_s->auto_pd_scan_retry < P2P_AUTO_PD_SCAN_ATTEMPTS) { |
| 5129 | wpa_s->auto_pd_scan_retry++; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5130 | bss = wpa_bss_get_bssid_latest( |
| 5131 | wpa_s, wpa_s->pending_join_dev_addr); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5132 | if (bss) { |
| 5133 | freq = bss->freq; |
| 5134 | wpa_printf(MSG_DEBUG, "P2P: Scan retry %d for " |
| 5135 | "the peer " MACSTR " at %d MHz", |
| 5136 | wpa_s->auto_pd_scan_retry, |
| 5137 | MAC2STR(wpa_s-> |
| 5138 | pending_join_dev_addr), |
| 5139 | freq); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5140 | wpas_p2p_join_scan_req(wpa_s, freq, NULL, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5141 | return; |
| 5142 | } |
| 5143 | } |
| 5144 | |
| 5145 | if (join < 0) |
| 5146 | join = 0; |
| 5147 | |
| 5148 | wpa_s->p2p_auto_pd = 0; |
| 5149 | wpa_s->pending_pd_use = join ? AUTO_PD_JOIN : AUTO_PD_GO_NEG; |
| 5150 | wpa_printf(MSG_DEBUG, "P2P: Auto PD with " MACSTR " join=%d", |
| 5151 | MAC2STR(wpa_s->pending_join_dev_addr), join); |
| 5152 | if (p2p_prov_disc_req(wpa_s->global->p2p, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5153 | wpa_s->pending_join_dev_addr, NULL, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5154 | wpa_s->pending_pd_config_methods, join, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5155 | 0, wpa_s->user_initiated_pd) < 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5156 | wpa_s->p2p_auto_pd = 0; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5157 | wpa_msg_global(wpa_s, MSG_INFO, |
| 5158 | P2P_EVENT_PROV_DISC_FAILURE |
| 5159 | " p2p_dev_addr=" MACSTR " status=N/A", |
| 5160 | MAC2STR(wpa_s->pending_join_dev_addr)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5161 | } |
| 5162 | return; |
| 5163 | } |
| 5164 | |
| 5165 | if (wpa_s->p2p_auto_join) { |
| 5166 | int join = wpas_p2p_peer_go(wpa_s, |
| 5167 | wpa_s->pending_join_dev_addr); |
| 5168 | if (join < 0) { |
| 5169 | wpa_printf(MSG_DEBUG, "P2P: Peer was not found to be " |
| 5170 | "running a GO -> use GO Negotiation"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5171 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5172 | P2P_EVENT_FALLBACK_TO_GO_NEG |
| 5173 | "reason=peer-not-running-GO"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5174 | wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr, |
| 5175 | wpa_s->p2p_pin, wpa_s->p2p_wps_method, |
| 5176 | wpa_s->p2p_persistent_group, 0, 0, 0, |
| 5177 | wpa_s->p2p_go_intent, |
| 5178 | wpa_s->p2p_connect_freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5179 | wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5180 | wpa_s->p2p_persistent_id, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5181 | wpa_s->p2p_pd_before_go_neg, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5182 | wpa_s->p2p_go_ht40, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5183 | wpa_s->p2p_go_vht, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5184 | wpa_s->p2p_go_max_oper_chwidth, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5185 | wpa_s->p2p_go_he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 5186 | wpa_s->p2p_go_edmg, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5187 | NULL, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5188 | return; |
| 5189 | } |
| 5190 | |
| 5191 | wpa_printf(MSG_DEBUG, "P2P: Peer was found running GO%s -> " |
| 5192 | "try to join the group", join ? "" : |
| 5193 | " in older scan"); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5194 | if (!join) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5195 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5196 | P2P_EVENT_FALLBACK_TO_GO_NEG_ENABLED); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5197 | wpa_s->p2p_fallback_to_go_neg = 1; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5198 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5199 | } |
| 5200 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5201 | freq = p2p_get_oper_freq(wpa_s->global->p2p, |
| 5202 | wpa_s->pending_join_iface_addr); |
| 5203 | if (freq < 0 && |
| 5204 | p2p_get_interface_addr(wpa_s->global->p2p, |
| 5205 | wpa_s->pending_join_dev_addr, |
| 5206 | iface_addr) == 0 && |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5207 | os_memcmp(iface_addr, wpa_s->pending_join_dev_addr, ETH_ALEN) != 0 |
| 5208 | && !wpa_bss_get_bssid(wpa_s, wpa_s->pending_join_iface_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5209 | wpa_printf(MSG_DEBUG, "P2P: Overwrite pending interface " |
| 5210 | "address for join from " MACSTR " to " MACSTR |
| 5211 | " based on newly discovered P2P peer entry", |
| 5212 | MAC2STR(wpa_s->pending_join_iface_addr), |
| 5213 | MAC2STR(iface_addr)); |
| 5214 | os_memcpy(wpa_s->pending_join_iface_addr, iface_addr, |
| 5215 | ETH_ALEN); |
| 5216 | |
| 5217 | freq = p2p_get_oper_freq(wpa_s->global->p2p, |
| 5218 | wpa_s->pending_join_iface_addr); |
| 5219 | } |
| 5220 | if (freq >= 0) { |
| 5221 | wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency " |
| 5222 | "from P2P peer table: %d MHz", freq); |
| 5223 | } |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5224 | if (wpa_s->p2p_join_ssid_len) { |
| 5225 | wpa_printf(MSG_DEBUG, "P2P: Trying to find target GO BSS entry based on BSSID " |
| 5226 | MACSTR " and SSID %s", |
| 5227 | MAC2STR(wpa_s->pending_join_iface_addr), |
| 5228 | wpa_ssid_txt(wpa_s->p2p_join_ssid, |
| 5229 | wpa_s->p2p_join_ssid_len)); |
| 5230 | bss = wpa_bss_get(wpa_s, wpa_s->pending_join_iface_addr, |
| 5231 | wpa_s->p2p_join_ssid, |
| 5232 | wpa_s->p2p_join_ssid_len); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5233 | } else if (!bss) { |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5234 | wpa_printf(MSG_DEBUG, "P2P: Trying to find target GO BSS entry based on BSSID " |
| 5235 | MACSTR, MAC2STR(wpa_s->pending_join_iface_addr)); |
| 5236 | bss = wpa_bss_get_bssid_latest(wpa_s, |
| 5237 | wpa_s->pending_join_iface_addr); |
| 5238 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5239 | if (bss) { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5240 | u8 dev_addr[ETH_ALEN]; |
| 5241 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5242 | freq = bss->freq; |
| 5243 | wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency " |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 5244 | "from BSS table: %d MHz (SSID %s)", freq, |
| 5245 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5246 | 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] | 5247 | dev_addr) == 0 && |
| 5248 | os_memcmp(wpa_s->pending_join_dev_addr, |
| 5249 | wpa_s->pending_join_iface_addr, ETH_ALEN) == 0 && |
| 5250 | os_memcmp(dev_addr, wpa_s->pending_join_dev_addr, |
| 5251 | ETH_ALEN) != 0) { |
| 5252 | wpa_printf(MSG_DEBUG, |
| 5253 | "P2P: Update target GO device address based on BSS entry: " MACSTR " (was " MACSTR ")", |
| 5254 | MAC2STR(dev_addr), |
| 5255 | MAC2STR(wpa_s->pending_join_dev_addr)); |
| 5256 | os_memcpy(wpa_s->pending_join_dev_addr, dev_addr, |
| 5257 | ETH_ALEN); |
| 5258 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5259 | } |
| 5260 | if (freq > 0) { |
| 5261 | u16 method; |
| 5262 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5263 | if (wpas_check_freq_conflict(wpa_s, freq) > 0) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5264 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5265 | P2P_EVENT_GROUP_FORMATION_FAILURE |
| 5266 | "reason=FREQ_CONFLICT"); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5267 | wpas_notify_p2p_group_formation_failure( |
| 5268 | wpa_s, "FREQ_CONFLICT"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5269 | return; |
| 5270 | } |
| 5271 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5272 | wpa_printf(MSG_DEBUG, "P2P: Send Provision Discovery Request " |
| 5273 | "prior to joining an existing group (GO " MACSTR |
| 5274 | " freq=%u MHz)", |
| 5275 | MAC2STR(wpa_s->pending_join_dev_addr), freq); |
| 5276 | wpa_s->pending_pd_before_join = 1; |
| 5277 | |
| 5278 | switch (wpa_s->pending_join_wps_method) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5279 | case WPS_PIN_DISPLAY: |
| 5280 | method = WPS_CONFIG_KEYPAD; |
| 5281 | break; |
| 5282 | case WPS_PIN_KEYPAD: |
| 5283 | method = WPS_CONFIG_DISPLAY; |
| 5284 | break; |
| 5285 | case WPS_PBC: |
| 5286 | method = WPS_CONFIG_PUSHBUTTON; |
| 5287 | break; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5288 | case WPS_P2PS: |
| 5289 | method = WPS_CONFIG_P2PS; |
| 5290 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5291 | default: |
| 5292 | method = 0; |
| 5293 | break; |
| 5294 | } |
| 5295 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5296 | if ((p2p_get_provisioning_info(wpa_s->global->p2p, |
| 5297 | wpa_s->pending_join_dev_addr) == |
| 5298 | method)) { |
| 5299 | /* |
| 5300 | * We have already performed provision discovery for |
| 5301 | * joining the group. Proceed directly to join |
| 5302 | * operation without duplicated provision discovery. */ |
| 5303 | wpa_printf(MSG_DEBUG, "P2P: Provision discovery " |
| 5304 | "with " MACSTR " already done - proceed to " |
| 5305 | "join", |
| 5306 | MAC2STR(wpa_s->pending_join_dev_addr)); |
| 5307 | wpa_s->pending_pd_before_join = 0; |
| 5308 | goto start; |
| 5309 | } |
| 5310 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5311 | if (p2p_prov_disc_req(wpa_s->global->p2p, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5312 | wpa_s->pending_join_dev_addr, |
| 5313 | NULL, method, 1, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5314 | freq, wpa_s->user_initiated_pd) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5315 | wpa_printf(MSG_DEBUG, "P2P: Failed to send Provision " |
| 5316 | "Discovery Request before joining an " |
| 5317 | "existing group"); |
| 5318 | wpa_s->pending_pd_before_join = 0; |
| 5319 | goto start; |
| 5320 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5321 | return; |
| 5322 | } |
| 5323 | |
| 5324 | wpa_printf(MSG_DEBUG, "P2P: Failed to find BSS/GO - try again later"); |
| 5325 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
| 5326 | eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL); |
| 5327 | wpas_p2p_check_join_scan_limit(wpa_s); |
| 5328 | return; |
| 5329 | |
| 5330 | start: |
| 5331 | /* Start join operation immediately */ |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5332 | wpas_p2p_join_start(wpa_s, 0, wpa_s->p2p_join_ssid, |
| 5333 | wpa_s->p2p_join_ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5334 | } |
| 5335 | |
| 5336 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5337 | static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq, |
| 5338 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5339 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5340 | int ret; |
| 5341 | struct wpa_driver_scan_params params; |
| 5342 | struct wpabuf *wps_ie, *ies; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5343 | size_t ielen; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5344 | int freqs[2] = { 0, 0 }; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5345 | unsigned int bands; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5346 | |
| 5347 | os_memset(¶ms, 0, sizeof(params)); |
| 5348 | |
| 5349 | /* P2P Wildcard SSID */ |
| 5350 | params.num_ssids = 1; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5351 | if (ssid && ssid_len) { |
| 5352 | params.ssids[0].ssid = ssid; |
| 5353 | params.ssids[0].ssid_len = ssid_len; |
| 5354 | os_memcpy(wpa_s->p2p_join_ssid, ssid, ssid_len); |
| 5355 | wpa_s->p2p_join_ssid_len = ssid_len; |
| 5356 | } else { |
| 5357 | params.ssids[0].ssid = (u8 *) P2P_WILDCARD_SSID; |
| 5358 | params.ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN; |
| 5359 | wpa_s->p2p_join_ssid_len = 0; |
| 5360 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5361 | |
| 5362 | wpa_s->wps->dev.p2p = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5363 | wps_ie = wps_build_probe_req_ie(DEV_PW_DEFAULT, &wpa_s->wps->dev, |
| 5364 | wpa_s->wps->uuid, WPS_REQ_ENROLLEE, 0, |
| 5365 | NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5366 | if (wps_ie == NULL) { |
| 5367 | wpas_p2p_scan_res_join(wpa_s, NULL); |
| 5368 | return; |
| 5369 | } |
| 5370 | |
Dmitry Shmidt | 9e3f8ee | 2014-01-17 10:52:01 -0800 | [diff] [blame] | 5371 | if (!freq) { |
| 5372 | int oper_freq; |
| 5373 | /* |
| 5374 | * If freq is not provided, check the operating freq of the GO |
| 5375 | * and use a single channel scan on if possible. |
| 5376 | */ |
| 5377 | oper_freq = p2p_get_oper_freq(wpa_s->global->p2p, |
| 5378 | wpa_s->pending_join_iface_addr); |
| 5379 | if (oper_freq > 0) |
| 5380 | freq = oper_freq; |
| 5381 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5382 | if (freq > 0) { |
| 5383 | freqs[0] = freq; |
| 5384 | params.freqs = freqs; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5385 | } else if (wpa_s->conf->p2p_6ghz_disable) { |
| 5386 | wpa_printf(MSG_DEBUG, |
| 5387 | "P2P: 6 GHz disabled - update the scan frequency list"); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5388 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211G, ¶ms, |
| 5389 | 0); |
| 5390 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, ¶ms, |
| 5391 | 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5392 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5393 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5394 | ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p); |
| 5395 | ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen); |
| 5396 | if (ies == NULL) { |
| 5397 | wpabuf_free(wps_ie); |
| 5398 | wpas_p2p_scan_res_join(wpa_s, NULL); |
| 5399 | return; |
| 5400 | } |
| 5401 | wpabuf_put_buf(ies, wps_ie); |
| 5402 | wpabuf_free(wps_ie); |
| 5403 | |
| 5404 | bands = wpas_get_bands(wpa_s, freqs); |
| 5405 | p2p_scan_ie(wpa_s->global->p2p, ies, NULL, bands); |
| 5406 | |
| 5407 | params.p2p_probe = 1; |
| 5408 | params.extra_ies = wpabuf_head(ies); |
| 5409 | params.extra_ies_len = wpabuf_len(ies); |
| 5410 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 5411 | if (wpa_s->clear_driver_scan_cache) { |
| 5412 | wpa_printf(MSG_DEBUG, |
| 5413 | "Request driver to clear scan cache due to local BSS flush"); |
| 5414 | params.only_new_results = 1; |
| 5415 | } |
| 5416 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5417 | /* |
| 5418 | * Run a scan to update BSS table and start Provision Discovery once |
| 5419 | * the new scan results become available. |
| 5420 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5421 | ret = wpa_drv_scan(wpa_s, ¶ms); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5422 | if (wpa_s->conf->p2p_6ghz_disable && params.freqs != freqs) |
| 5423 | os_free(params.freqs); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5424 | if (!ret) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5425 | os_get_reltime(&wpa_s->scan_trigger_time); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5426 | wpa_s->scan_res_handler = wpas_p2p_scan_res_join; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5427 | wpa_s->own_scan_requested = 1; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 5428 | wpa_s->clear_driver_scan_cache = 0; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5429 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5430 | |
| 5431 | wpabuf_free(ies); |
| 5432 | |
| 5433 | if (ret) { |
| 5434 | wpa_printf(MSG_DEBUG, "P2P: Failed to start scan for join - " |
| 5435 | "try again later"); |
| 5436 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
| 5437 | eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL); |
| 5438 | wpas_p2p_check_join_scan_limit(wpa_s); |
| 5439 | } |
| 5440 | } |
| 5441 | |
| 5442 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5443 | static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx) |
| 5444 | { |
| 5445 | struct wpa_supplicant *wpa_s = eloop_ctx; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5446 | wpas_p2p_join_scan_req(wpa_s, 0, NULL, 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5447 | } |
| 5448 | |
| 5449 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5450 | 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] | 5451 | const u8 *dev_addr, enum p2p_wps_method wps_method, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5452 | int auto_join, int op_freq, |
| 5453 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5454 | { |
| 5455 | wpa_printf(MSG_DEBUG, "P2P: Request to join existing group (iface " |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5456 | MACSTR " dev " MACSTR " op_freq=%d)%s", |
| 5457 | MAC2STR(iface_addr), MAC2STR(dev_addr), op_freq, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5458 | auto_join ? " (auto_join)" : ""); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5459 | if (ssid && ssid_len) { |
| 5460 | wpa_printf(MSG_DEBUG, "P2P: Group SSID specified: %s", |
| 5461 | wpa_ssid_txt(ssid, ssid_len)); |
| 5462 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5463 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5464 | wpa_s->p2p_auto_pd = 0; |
| 5465 | wpa_s->p2p_auto_join = !!auto_join; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5466 | os_memcpy(wpa_s->pending_join_iface_addr, iface_addr, ETH_ALEN); |
| 5467 | os_memcpy(wpa_s->pending_join_dev_addr, dev_addr, ETH_ALEN); |
| 5468 | wpa_s->pending_join_wps_method = wps_method; |
| 5469 | |
| 5470 | /* Make sure we are not running find during connection establishment */ |
| 5471 | wpas_p2p_stop_find(wpa_s); |
| 5472 | |
| 5473 | wpa_s->p2p_join_scan_count = 0; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5474 | wpas_p2p_join_scan_req(wpa_s, op_freq, ssid, ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5475 | return 0; |
| 5476 | } |
| 5477 | |
| 5478 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5479 | static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s, int freq, |
| 5480 | const u8 *ssid, size_t ssid_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5481 | { |
| 5482 | struct wpa_supplicant *group; |
| 5483 | struct p2p_go_neg_results res; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5484 | struct wpa_bss *bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5485 | |
| 5486 | group = wpas_p2p_get_group_iface(wpa_s, 0, 0); |
| 5487 | if (group == NULL) |
| 5488 | return -1; |
| 5489 | if (group != wpa_s) { |
| 5490 | os_memcpy(group->p2p_pin, wpa_s->p2p_pin, |
| 5491 | sizeof(group->p2p_pin)); |
| 5492 | group->p2p_wps_method = wpa_s->p2p_wps_method; |
| 5493 | } |
| 5494 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5495 | /* |
| 5496 | * Need to mark the current interface for p2p_group_formation |
| 5497 | * when a separate group interface is not used. This is needed |
| 5498 | * to allow p2p_cancel stop a pending p2p_connect-join. |
| 5499 | * wpas_p2p_init_group_interface() addresses this for the case |
| 5500 | * where a separate group interface is used. |
| 5501 | */ |
| 5502 | if (group == wpa_s->parent) |
| 5503 | wpa_s->global->p2p_group_formation = group; |
| 5504 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5505 | group->p2p_in_provisioning = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5506 | 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] | 5507 | |
| 5508 | os_memset(&res, 0, sizeof(res)); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5509 | 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] | 5510 | os_memcpy(res.peer_interface_addr, wpa_s->pending_join_iface_addr, |
| 5511 | ETH_ALEN); |
| 5512 | res.wps_method = wpa_s->pending_join_wps_method; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5513 | if (freq && ssid && ssid_len) { |
| 5514 | res.freq = freq; |
| 5515 | res.ssid_len = ssid_len; |
| 5516 | os_memcpy(res.ssid, ssid, ssid_len); |
| 5517 | } else { |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5518 | if (ssid && ssid_len) { |
| 5519 | bss = wpa_bss_get(wpa_s, wpa_s->pending_join_iface_addr, |
| 5520 | ssid, ssid_len); |
| 5521 | } else { |
| 5522 | bss = wpa_bss_get_bssid_latest( |
| 5523 | wpa_s, wpa_s->pending_join_iface_addr); |
| 5524 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5525 | if (bss) { |
| 5526 | res.freq = bss->freq; |
| 5527 | res.ssid_len = bss->ssid_len; |
| 5528 | os_memcpy(res.ssid, bss->ssid, bss->ssid_len); |
| 5529 | wpa_printf(MSG_DEBUG, "P2P: Join target GO operating frequency from BSS table: %d MHz (SSID %s)", |
| 5530 | bss->freq, |
| 5531 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5532 | } else if (ssid && ssid_len) { |
| 5533 | res.ssid_len = ssid_len; |
| 5534 | os_memcpy(res.ssid, ssid, ssid_len); |
| 5535 | wpa_printf(MSG_DEBUG, "P2P: Join target GO (SSID %s)", |
| 5536 | wpa_ssid_txt(ssid, ssid_len)); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5537 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5538 | } |
| 5539 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5540 | if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) { |
| 5541 | wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel prior to " |
| 5542 | "starting client"); |
| 5543 | wpa_drv_cancel_remain_on_channel(wpa_s); |
| 5544 | wpa_s->off_channel_freq = 0; |
| 5545 | wpa_s->roc_waiting_drv_freq = 0; |
| 5546 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5547 | wpas_start_wps_enrollee(group, &res); |
| 5548 | |
| 5549 | /* |
| 5550 | * Allow a longer timeout for join-a-running-group than normal 15 |
| 5551 | * second group formation timeout since the GO may not have authorized |
| 5552 | * our connection yet. |
| 5553 | */ |
| 5554 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL); |
| 5555 | eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout, |
| 5556 | wpa_s, NULL); |
| 5557 | |
| 5558 | return 0; |
| 5559 | } |
| 5560 | |
| 5561 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5562 | 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] | 5563 | int *force_freq, int *pref_freq, int go, |
| 5564 | unsigned int *pref_freq_list, |
| 5565 | unsigned int *num_pref_freq) |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5566 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5567 | struct wpa_used_freq_data *freqs; |
| 5568 | int res, best_freq, num_unused; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5569 | unsigned int freq_in_use = 0, num, i, max_pref_freq; |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5570 | int p2p_pref_freq; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5571 | |
| 5572 | max_pref_freq = *num_pref_freq; |
| 5573 | *num_pref_freq = 0; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5574 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5575 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 5576 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5577 | if (!freqs) |
| 5578 | return -1; |
| 5579 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5580 | num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, |
| 5581 | wpa_s->num_multichan_concurrent); |
| 5582 | |
| 5583 | /* |
| 5584 | * It is possible that the total number of used frequencies is bigger |
| 5585 | * than the number of frequencies used for P2P, so get the system wide |
| 5586 | * number of unused frequencies. |
| 5587 | */ |
| 5588 | num_unused = wpas_p2p_num_unused_channels(wpa_s); |
| 5589 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5590 | wpa_printf(MSG_DEBUG, |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5591 | "P2P: Setup freqs: freq=%d num_MCC=%d shared_freqs=%u num_unused=%d", |
| 5592 | freq, wpa_s->num_multichan_concurrent, num, num_unused); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5593 | |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5594 | if (freq > 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5595 | int ret; |
| 5596 | if (go) |
| 5597 | ret = p2p_supported_freq(wpa_s->global->p2p, freq); |
| 5598 | else |
| 5599 | ret = p2p_supported_freq_cli(wpa_s->global->p2p, freq); |
| 5600 | if (!ret) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5601 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5602 | ieee80211_is_dfs(freq, wpa_s->hw.modes, |
| 5603 | wpa_s->hw.num_modes)) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5604 | /* |
| 5605 | * If freq is a DFS channel and DFS is offloaded |
| 5606 | * to the driver, allow P2P GO to use it. |
| 5607 | */ |
| 5608 | wpa_printf(MSG_DEBUG, |
| 5609 | "P2P: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded to the driver", |
| 5610 | freq); |
| 5611 | } else { |
| 5612 | wpa_printf(MSG_DEBUG, |
| 5613 | "P2P: The forced channel (%u MHz) is not supported for P2P uses", |
| 5614 | freq); |
| 5615 | res = -3; |
| 5616 | goto exit_free; |
| 5617 | } |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5618 | } |
| 5619 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5620 | for (i = 0; i < num; i++) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5621 | if (freqs[i].freq == freq) |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5622 | freq_in_use = 1; |
| 5623 | } |
| 5624 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5625 | if (num_unused <= 0 && !freq_in_use) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5626 | wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group on %u MHz as there are no available channels", |
| 5627 | freq); |
| 5628 | res = -2; |
| 5629 | goto exit_free; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5630 | } |
| 5631 | wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the " |
| 5632 | "requested channel (%u MHz)", freq); |
| 5633 | *force_freq = freq; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5634 | goto exit_ok; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5635 | } |
| 5636 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5637 | best_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5638 | |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5639 | if (*pref_freq == 0) { |
| 5640 | if (wpa_s->conf->num_p2p_pref_chan && IS_2GHZ(best_freq)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5641 | i = 0; |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5642 | while (i < wpa_s->conf->num_p2p_pref_chan) { |
| 5643 | p2p_pref_freq = ieee80211_chan_to_freq(NULL, |
| 5644 | wpa_s->conf->p2p_pref_chan[i].op_class, |
| 5645 | wpa_s->conf->p2p_pref_chan[i].chan); |
| 5646 | |
| 5647 | if (p2p_supported_freq(wpa_s->global->p2p, p2p_pref_freq) && |
| 5648 | !wpas_p2p_disallowed_freq(wpa_s->global, p2p_pref_freq)) { |
| 5649 | best_freq = p2p_pref_freq; |
| 5650 | wpa_printf(MSG_DEBUG, "P2P: Using frequency (%u MHz) " |
| 5651 | "from P2P preferred channel list", best_freq); |
| 5652 | break; |
| 5653 | } else { |
| 5654 | wpa_printf(MSG_MSGDUMP, "P2P: Skipping preferred " |
| 5655 | "frequency (%u MHz) ", p2p_pref_freq); |
| 5656 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5657 | i++; |
| 5658 | } |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5659 | } else { |
| 5660 | enum wpa_driver_if_type iface_type; |
| 5661 | |
| 5662 | if (go) |
| 5663 | iface_type = WPA_IF_P2P_GO; |
| 5664 | else |
| 5665 | iface_type = WPA_IF_P2P_CLIENT; |
| 5666 | |
| 5667 | wpa_printf(MSG_DEBUG, "P2P: best_freq=%d, go=%d", |
| 5668 | best_freq, go); |
| 5669 | |
| 5670 | res = wpa_drv_get_pref_freq_list(wpa_s, iface_type, |
| 5671 | &max_pref_freq, |
| 5672 | pref_freq_list); |
| 5673 | if (!res && max_pref_freq > 0) { |
| 5674 | *num_pref_freq = max_pref_freq; |
| 5675 | i = 0; |
| 5676 | while (i < *num_pref_freq && |
| 5677 | (!p2p_supported_freq(wpa_s->global->p2p, |
| 5678 | pref_freq_list[i]) || |
| 5679 | wpas_p2p_disallowed_freq(wpa_s->global, |
| 5680 | pref_freq_list[i]))) { |
| 5681 | wpa_printf(MSG_DEBUG, |
| 5682 | "P2P: preferred_freq_list[%d]=%d is disallowed", |
| 5683 | i, pref_freq_list[i]); |
| 5684 | i++; |
| 5685 | } |
| 5686 | if (i != *num_pref_freq) { |
| 5687 | best_freq = pref_freq_list[i]; |
| 5688 | wpa_printf(MSG_DEBUG, |
| 5689 | "P2P: Using preferred_freq_list[%d]=%d", |
| 5690 | i, best_freq); |
| 5691 | } else { |
| 5692 | wpa_printf(MSG_DEBUG, |
| 5693 | "P2P: All driver preferred frequencies are " |
| 5694 | "disallowed for P2P use"); |
| 5695 | *num_pref_freq = 0; |
| 5696 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5697 | } else { |
| 5698 | wpa_printf(MSG_DEBUG, |
Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5699 | "P2P: No preferred frequency list available"); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5700 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5701 | } |
| 5702 | } |
| 5703 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5704 | /* We have a candidate frequency to use */ |
| 5705 | if (best_freq > 0) { |
| 5706 | if (*pref_freq == 0 && num_unused > 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5707 | 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] | 5708 | best_freq); |
| 5709 | *pref_freq = best_freq; |
Dmitry Shmidt | 51a47d5 | 2013-09-10 10:52:57 -0700 | [diff] [blame] | 5710 | } else { |
| 5711 | 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] | 5712 | best_freq); |
| 5713 | *force_freq = best_freq; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5714 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5715 | } else if (num_unused > 0) { |
| 5716 | wpa_printf(MSG_DEBUG, |
| 5717 | "P2P: Current operating channels are not available for P2P. Try to use another channel"); |
| 5718 | *force_freq = 0; |
| 5719 | } else { |
| 5720 | wpa_printf(MSG_DEBUG, |
| 5721 | "P2P: All channels are in use and none of them are P2P enabled. Cannot start P2P group"); |
| 5722 | res = -2; |
| 5723 | goto exit_free; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5724 | } |
| 5725 | |
| 5726 | exit_ok: |
| 5727 | res = 0; |
| 5728 | exit_free: |
| 5729 | os_free(freqs); |
| 5730 | return res; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5731 | } |
| 5732 | |
| 5733 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5734 | /** |
| 5735 | * wpas_p2p_connect - Request P2P Group Formation to be started |
| 5736 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 5737 | * @peer_addr: Address of the peer P2P Device |
| 5738 | * @pin: PIN to use during provisioning or %NULL to indicate PBC mode |
| 5739 | * @persistent_group: Whether to create a persistent group |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5740 | * @auto_join: Whether to select join vs. GO Negotiation automatically |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5741 | * @join: Whether to join an existing group (as a client) instead of starting |
| 5742 | * Group Owner negotiation; @peer_addr is BSSID in that case |
| 5743 | * @auth: Whether to only authorize the connection instead of doing that and |
| 5744 | * initiating Group Owner negotiation |
| 5745 | * @go_intent: GO Intent or -1 to use default |
| 5746 | * @freq: Frequency for the group or 0 for auto-selection |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5747 | * @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] | 5748 | * @persistent_id: Persistent group credentials to use for forcing GO |
| 5749 | * parameters or -1 to generate new values (SSID/passphrase) |
| 5750 | * @pd: Whether to send Provision Discovery prior to GO Negotiation as an |
| 5751 | * interoperability workaround when initiating group formation |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5752 | * @ht40: Start GO with 40 MHz channel width |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5753 | * @vht: Start GO with VHT support |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5754 | * @vht_chwidth: Channel width supported by GO operating with VHT support |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5755 | * (CHANWIDTH_*). |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5756 | * @group_ssid: Specific Group SSID for join or %NULL if not set |
| 5757 | * @group_ssid_len: Length of @group_ssid in octets |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5758 | * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified |
| 5759 | * failure, -2 on failure due to channel not currently available, |
| 5760 | * -3 if forced channel is not supported |
| 5761 | */ |
| 5762 | int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr, |
| 5763 | const char *pin, enum p2p_wps_method wps_method, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5764 | int persistent_group, int auto_join, int join, int auth, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5765 | int go_intent, int freq, unsigned int vht_center_freq2, |
| 5766 | int persistent_id, int pd, int ht40, int vht, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 5767 | unsigned int vht_chwidth, int he, int edmg, |
| 5768 | const u8 *group_ssid, size_t group_ssid_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5769 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5770 | int force_freq = 0, pref_freq = 0; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5771 | int ret = 0, res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5772 | enum wpa_driver_if_type iftype; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5773 | const u8 *if_addr; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5774 | struct wpa_ssid *ssid = NULL; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5775 | unsigned int pref_freq_list[P2P_MAX_PREF_CHANNELS], size; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5776 | |
| 5777 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 5778 | return -1; |
| 5779 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5780 | if (persistent_id >= 0) { |
| 5781 | ssid = wpa_config_get_network(wpa_s->conf, persistent_id); |
| 5782 | if (ssid == NULL || ssid->disabled != 2 || |
| 5783 | ssid->mode != WPAS_MODE_P2P_GO) |
| 5784 | return -1; |
| 5785 | } |
| 5786 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5787 | if (is_6ghz_freq(freq) && wpa_s->conf->p2p_6ghz_disable) |
| 5788 | return -2; |
| 5789 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 5790 | os_free(wpa_s->global->add_psk); |
| 5791 | wpa_s->global->add_psk = NULL; |
| 5792 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5793 | wpa_s->global->p2p_fail_on_wps_complete = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5794 | wpa_s->global->pending_p2ps_group = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5795 | wpa_s->global->pending_p2ps_group_freq = 0; |
| 5796 | wpa_s->p2ps_method_config_any = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5797 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5798 | if (go_intent < 0) |
| 5799 | go_intent = wpa_s->conf->p2p_go_intent; |
| 5800 | |
| 5801 | if (!auth) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5802 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5803 | |
| 5804 | wpa_s->p2p_wps_method = wps_method; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5805 | wpa_s->p2p_persistent_group = !!persistent_group; |
| 5806 | wpa_s->p2p_persistent_id = persistent_id; |
| 5807 | wpa_s->p2p_go_intent = go_intent; |
| 5808 | wpa_s->p2p_connect_freq = freq; |
| 5809 | wpa_s->p2p_fallback_to_go_neg = 0; |
| 5810 | wpa_s->p2p_pd_before_go_neg = !!pd; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5811 | wpa_s->p2p_go_ht40 = !!ht40; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5812 | wpa_s->p2p_go_vht = !!vht; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5813 | wpa_s->p2p_go_vht_center_freq2 = vht_center_freq2; |
| 5814 | wpa_s->p2p_go_max_oper_chwidth = vht_chwidth; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5815 | wpa_s->p2p_go_he = !!he; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 5816 | wpa_s->p2p_go_edmg = !!edmg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5817 | |
| 5818 | if (pin) |
| 5819 | os_strlcpy(wpa_s->p2p_pin, pin, sizeof(wpa_s->p2p_pin)); |
| 5820 | else if (wps_method == WPS_PIN_DISPLAY) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5821 | if (wps_generate_pin((unsigned int *) &ret) < 0) |
| 5822 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5823 | res = os_snprintf(wpa_s->p2p_pin, sizeof(wpa_s->p2p_pin), |
| 5824 | "%08d", ret); |
| 5825 | if (os_snprintf_error(sizeof(wpa_s->p2p_pin), res)) |
| 5826 | wpa_s->p2p_pin[sizeof(wpa_s->p2p_pin) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5827 | wpa_printf(MSG_DEBUG, "P2P: Randomly generated PIN: %s", |
| 5828 | wpa_s->p2p_pin); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5829 | } else if (wps_method == WPS_P2PS) { |
| 5830 | /* Force the P2Ps default PIN to be used */ |
| 5831 | os_strlcpy(wpa_s->p2p_pin, "12345670", sizeof(wpa_s->p2p_pin)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5832 | } else |
| 5833 | wpa_s->p2p_pin[0] = '\0'; |
| 5834 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5835 | if (join || auto_join) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5836 | u8 iface_addr[ETH_ALEN], dev_addr[ETH_ALEN]; |
| 5837 | if (auth) { |
| 5838 | wpa_printf(MSG_DEBUG, "P2P: Authorize invitation to " |
| 5839 | "connect a running group from " MACSTR, |
| 5840 | MAC2STR(peer_addr)); |
| 5841 | os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN); |
| 5842 | return ret; |
| 5843 | } |
| 5844 | os_memcpy(dev_addr, peer_addr, ETH_ALEN); |
| 5845 | if (p2p_get_interface_addr(wpa_s->global->p2p, peer_addr, |
| 5846 | iface_addr) < 0) { |
| 5847 | os_memcpy(iface_addr, peer_addr, ETH_ALEN); |
| 5848 | p2p_get_dev_addr(wpa_s->global->p2p, peer_addr, |
| 5849 | dev_addr); |
| 5850 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5851 | if (auto_join) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5852 | os_get_reltime(&wpa_s->p2p_auto_started); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5853 | wpa_printf(MSG_DEBUG, "P2P: Auto join started at " |
| 5854 | "%ld.%06ld", |
| 5855 | wpa_s->p2p_auto_started.sec, |
| 5856 | wpa_s->p2p_auto_started.usec); |
| 5857 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5858 | wpa_s->user_initiated_pd = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5859 | if (wpas_p2p_join(wpa_s, iface_addr, dev_addr, wps_method, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5860 | auto_join, freq, |
| 5861 | group_ssid, group_ssid_len) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5862 | return -1; |
| 5863 | return ret; |
| 5864 | } |
| 5865 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5866 | size = P2P_MAX_PREF_CHANNELS; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5867 | res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5868 | go_intent == 15, pref_freq_list, &size); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5869 | if (res) |
| 5870 | return res; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 5871 | wpas_p2p_set_own_freq_preference(wpa_s, |
| 5872 | force_freq ? force_freq : pref_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5873 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5874 | p2p_set_own_pref_freq_list(wpa_s->global->p2p, pref_freq_list, size); |
| 5875 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5876 | wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s); |
| 5877 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5878 | if (wpa_s->create_p2p_iface) { |
| 5879 | /* Prepare to add a new interface for the group */ |
| 5880 | iftype = WPA_IF_P2P_GROUP; |
| 5881 | if (go_intent == 15) |
| 5882 | iftype = WPA_IF_P2P_GO; |
| 5883 | if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) { |
| 5884 | wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " |
| 5885 | "interface for the group"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5886 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5887 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5888 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5889 | if_addr = wpa_s->pending_interface_addr; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5890 | } else { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5891 | if (wpa_s->p2p_mgmt) |
| 5892 | if_addr = wpa_s->parent->own_addr; |
| 5893 | else |
| 5894 | if_addr = wpa_s->own_addr; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5895 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
| 5896 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5897 | |
| 5898 | if (auth) { |
| 5899 | if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5900 | go_intent, if_addr, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5901 | force_freq, persistent_group, ssid, |
| 5902 | pref_freq) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5903 | return -1; |
| 5904 | return ret; |
| 5905 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5906 | |
| 5907 | if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method, |
| 5908 | go_intent, if_addr, force_freq, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5909 | persistent_group, ssid, pref_freq) < 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5910 | if (wpa_s->create_p2p_iface) |
| 5911 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5912 | return -1; |
| 5913 | } |
| 5914 | return ret; |
| 5915 | } |
| 5916 | |
| 5917 | |
| 5918 | /** |
| 5919 | * wpas_p2p_remain_on_channel_cb - Indication of remain-on-channel start |
| 5920 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 5921 | * @freq: Frequency of the channel in MHz |
| 5922 | * @duration: Duration of the stay on the channel in milliseconds |
| 5923 | * |
| 5924 | * This callback is called when the driver indicates that it has started the |
| 5925 | * requested remain-on-channel duration. |
| 5926 | */ |
| 5927 | void wpas_p2p_remain_on_channel_cb(struct wpa_supplicant *wpa_s, |
| 5928 | unsigned int freq, unsigned int duration) |
| 5929 | { |
| 5930 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 5931 | return; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5932 | 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)", |
| 5933 | wpa_s->off_channel_freq, wpa_s->pending_listen_freq, |
| 5934 | wpa_s->roc_waiting_drv_freq, freq, duration); |
| 5935 | if (wpa_s->off_channel_freq && |
| 5936 | wpa_s->off_channel_freq == wpa_s->pending_listen_freq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5937 | p2p_listen_cb(wpa_s->global->p2p, wpa_s->pending_listen_freq, |
| 5938 | wpa_s->pending_listen_duration); |
| 5939 | wpa_s->pending_listen_freq = 0; |
Dmitry Shmidt | 7f93d6f | 2014-02-21 11:22:49 -0800 | [diff] [blame] | 5940 | } else { |
| 5941 | wpa_printf(MSG_DEBUG, "P2P: Ignore remain-on-channel callback (off_channel_freq=%u pending_listen_freq=%d freq=%u duration=%u)", |
| 5942 | wpa_s->off_channel_freq, wpa_s->pending_listen_freq, |
| 5943 | freq, duration); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5944 | } |
| 5945 | } |
| 5946 | |
| 5947 | |
Jithu Jance | 57cea1a | 2014-08-20 10:22:04 -0700 | [diff] [blame] | 5948 | 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] | 5949 | { |
| 5950 | /* Limit maximum Listen state time based on driver limitation. */ |
| 5951 | if (timeout > wpa_s->max_remain_on_chan) |
| 5952 | timeout = wpa_s->max_remain_on_chan; |
| 5953 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5954 | return p2p_listen(wpa_s->global->p2p, timeout); |
| 5955 | } |
| 5956 | |
| 5957 | |
| 5958 | /** |
| 5959 | * wpas_p2p_cancel_remain_on_channel_cb - Remain-on-channel timeout |
| 5960 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 5961 | * @freq: Frequency of the channel in MHz |
| 5962 | * |
| 5963 | * This callback is called when the driver indicates that a remain-on-channel |
| 5964 | * operation has been completed, i.e., the duration on the requested channel |
| 5965 | * has timed out. |
| 5966 | */ |
| 5967 | void wpas_p2p_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s, |
| 5968 | unsigned int freq) |
| 5969 | { |
| 5970 | wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel callback " |
| 5971 | "(p2p_long_listen=%d ms pending_action_tx=%p)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5972 | wpa_s->global->p2p_long_listen, |
| 5973 | offchannel_pending_action_tx(wpa_s)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5974 | wpas_p2p_listen_work_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5975 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 5976 | return; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5977 | if (wpa_s->global->p2p_long_listen > 0) |
| 5978 | wpa_s->global->p2p_long_listen -= wpa_s->max_remain_on_chan; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5979 | if (p2p_listen_end(wpa_s->global->p2p, freq) > 0) |
| 5980 | return; /* P2P module started a new operation */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5981 | if (offchannel_pending_action_tx(wpa_s)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5982 | return; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5983 | if (wpa_s->global->p2p_long_listen > 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5984 | wpa_printf(MSG_DEBUG, "P2P: Continuing long Listen state"); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5985 | wpas_p2p_listen_start(wpa_s, wpa_s->global->p2p_long_listen); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 5986 | } else { |
| 5987 | /* |
| 5988 | * When listen duration is over, stop listen & update p2p_state |
| 5989 | * to IDLE. |
| 5990 | */ |
| 5991 | p2p_stop_listen(wpa_s->global->p2p); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5992 | } |
| 5993 | } |
| 5994 | |
| 5995 | |
| 5996 | /** |
| 5997 | * wpas_p2p_group_remove - Remove a P2P group |
| 5998 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 5999 | * @ifname: Network interface name of the group interface or "*" to remove all |
| 6000 | * groups |
| 6001 | * Returns: 0 on success, -1 on failure |
| 6002 | * |
| 6003 | * This function is used to remove a P2P group. This can be used to disconnect |
| 6004 | * from a group in which the local end is a P2P Client or to end a P2P Group in |
| 6005 | * case the local end is the Group Owner. If a virtual network interface was |
| 6006 | * created for this group, that interface will be removed. Otherwise, only the |
| 6007 | * configured P2P group network will be removed from the interface. |
| 6008 | */ |
| 6009 | int wpas_p2p_group_remove(struct wpa_supplicant *wpa_s, const char *ifname) |
| 6010 | { |
| 6011 | struct wpa_global *global = wpa_s->global; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6012 | struct wpa_supplicant *calling_wpa_s = wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6013 | |
| 6014 | if (os_strcmp(ifname, "*") == 0) { |
| 6015 | struct wpa_supplicant *prev; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6016 | bool calling_wpa_s_group_removed = false; |
| 6017 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6018 | wpa_s = global->ifaces; |
| 6019 | while (wpa_s) { |
| 6020 | prev = wpa_s; |
| 6021 | wpa_s = wpa_s->next; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6022 | if (prev->p2p_group_interface != |
| 6023 | NOT_P2P_GROUP_INTERFACE || |
| 6024 | (prev->current_ssid && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6025 | prev->current_ssid->p2p_group)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6026 | wpas_p2p_disconnect_safely(prev, calling_wpa_s); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6027 | if (prev == calling_wpa_s) |
| 6028 | calling_wpa_s_group_removed = true; |
| 6029 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6030 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6031 | |
| 6032 | if (!calling_wpa_s_group_removed && |
| 6033 | (calling_wpa_s->p2p_group_interface != |
| 6034 | NOT_P2P_GROUP_INTERFACE || |
| 6035 | (calling_wpa_s->current_ssid && |
| 6036 | calling_wpa_s->current_ssid->p2p_group))) { |
| 6037 | wpa_printf(MSG_DEBUG, "Remove calling_wpa_s P2P group"); |
| 6038 | wpas_p2p_disconnect_safely(calling_wpa_s, |
| 6039 | calling_wpa_s); |
| 6040 | } |
| 6041 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6042 | return 0; |
| 6043 | } |
| 6044 | |
| 6045 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 6046 | if (os_strcmp(wpa_s->ifname, ifname) == 0) |
| 6047 | break; |
| 6048 | } |
| 6049 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6050 | return wpas_p2p_disconnect_safely(wpa_s, calling_wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6051 | } |
| 6052 | |
| 6053 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6054 | static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq) |
| 6055 | { |
| 6056 | unsigned int r; |
| 6057 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6058 | if (!wpa_s->conf->num_p2p_pref_chan && !freq) { |
| 6059 | unsigned int i, size = P2P_MAX_PREF_CHANNELS; |
| 6060 | unsigned int pref_freq_list[P2P_MAX_PREF_CHANNELS]; |
| 6061 | int res; |
| 6062 | |
| 6063 | res = wpa_drv_get_pref_freq_list(wpa_s, WPA_IF_P2P_GO, |
| 6064 | &size, pref_freq_list); |
| 6065 | if (!res && size > 0) { |
| 6066 | i = 0; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 6067 | while (i < size && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6068 | (!p2p_supported_freq(wpa_s->global->p2p, |
| 6069 | pref_freq_list[i]) || |
| 6070 | wpas_p2p_disallowed_freq(wpa_s->global, |
| 6071 | pref_freq_list[i]))) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6072 | wpa_printf(MSG_DEBUG, |
| 6073 | "P2P: preferred_freq_list[%d]=%d is disallowed", |
| 6074 | i, pref_freq_list[i]); |
| 6075 | i++; |
| 6076 | } |
| 6077 | if (i != size) { |
| 6078 | freq = pref_freq_list[i]; |
| 6079 | wpa_printf(MSG_DEBUG, |
| 6080 | "P2P: Using preferred_freq_list[%d]=%d", |
| 6081 | i, freq); |
| 6082 | } else { |
| 6083 | wpa_printf(MSG_DEBUG, |
| 6084 | "P2P: All driver preferred frequencies are disallowed for P2P use"); |
| 6085 | } |
| 6086 | } else { |
| 6087 | wpa_printf(MSG_DEBUG, |
| 6088 | "P2P: No preferred frequency list available"); |
| 6089 | } |
| 6090 | } |
| 6091 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6092 | if (freq == 2) { |
| 6093 | wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 2.4 GHz " |
| 6094 | "band"); |
| 6095 | if (wpa_s->best_24_freq > 0 && |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6096 | p2p_supported_freq_go(wpa_s->global->p2p, |
| 6097 | wpa_s->best_24_freq)) { |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6098 | freq = wpa_s->best_24_freq; |
| 6099 | wpa_printf(MSG_DEBUG, "P2P: Use best 2.4 GHz band " |
| 6100 | "channel: %d MHz", freq); |
| 6101 | } else { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6102 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 6103 | return -1; |
Jimmy Chen | 801bf46 | 2021-11-09 23:08:48 +0800 | [diff] [blame^] | 6104 | int possible_2g_freqs[] = { |
| 6105 | /* operating class 81 */ |
| 6106 | 2412, 2437, 2462, |
| 6107 | }; |
| 6108 | int possible_2g_freqs_num = |
| 6109 | sizeof(possible_2g_freqs)/sizeof(possible_2g_freqs[0]); |
| 6110 | int i; |
| 6111 | for (i = 0; i < possible_2g_freqs_num; i++, r++) { |
| 6112 | freq = possible_2g_freqs[r % possible_2g_freqs_num]; |
| 6113 | if (p2p_supported_freq_go(wpa_s->global->p2p, freq)) { |
| 6114 | break; |
| 6115 | } |
| 6116 | } |
| 6117 | |
| 6118 | if (i >= possible_2g_freqs_num) { |
| 6119 | wpa_printf(MSG_DEBUG, "P2P: Could not select " |
| 6120 | "2.4 GHz channel for P2P group"); |
| 6121 | return -1; |
| 6122 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6123 | wpa_printf(MSG_DEBUG, "P2P: Use random 2.4 GHz band " |
| 6124 | "channel: %d MHz", freq); |
| 6125 | } |
| 6126 | } |
| 6127 | |
| 6128 | if (freq == 5) { |
| 6129 | wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 5 GHz " |
| 6130 | "band"); |
| 6131 | if (wpa_s->best_5_freq > 0 && |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6132 | p2p_supported_freq_go(wpa_s->global->p2p, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6133 | wpa_s->best_5_freq)) { |
| 6134 | freq = wpa_s->best_5_freq; |
| 6135 | wpa_printf(MSG_DEBUG, "P2P: Use best 5 GHz band " |
| 6136 | "channel: %d MHz", freq); |
| 6137 | } else { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6138 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 6139 | return -1; |
Jimmy Chen | 64b9063 | 2020-09-29 17:27:34 +0800 | [diff] [blame] | 6140 | |
| 6141 | /* |
| 6142 | * most of 5G channels are DFS, only operating class 115 and 124 |
| 6143 | * are available possibly, randomly pick a start to check them. |
| 6144 | */ |
| 6145 | int possible_5g_freqs[] = { |
| 6146 | /* operating class 115 */ |
| 6147 | 5180, 5200, 5220, 5240, |
| 6148 | /* operating class 124 */ |
| 6149 | 5745, 5765, 5785, 5805, |
| 6150 | }; |
| 6151 | int possible_5g_freqs_num = |
| 6152 | sizeof(possible_5g_freqs)/sizeof(possible_5g_freqs[0]); |
| 6153 | |
| 6154 | int i; |
| 6155 | for (i = 0; i < possible_5g_freqs_num; i++, r++) { |
| 6156 | if (p2p_supported_freq_go( |
| 6157 | wpa_s->global->p2p, |
| 6158 | possible_5g_freqs[r % possible_5g_freqs_num])) { |
| 6159 | freq = possible_5g_freqs[r % possible_5g_freqs_num]; |
| 6160 | break; |
| 6161 | } |
| 6162 | } |
| 6163 | |
| 6164 | if (i >= possible_5g_freqs_num) { |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6165 | wpa_printf(MSG_DEBUG, "P2P: Could not select " |
| 6166 | "5 GHz channel for P2P group"); |
| 6167 | return -1; |
| 6168 | } |
| 6169 | wpa_printf(MSG_DEBUG, "P2P: Use random 5 GHz band " |
| 6170 | "channel: %d MHz", freq); |
| 6171 | } |
| 6172 | } |
| 6173 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6174 | if (freq > 0 && !p2p_supported_freq_go(wpa_s->global->p2p, freq)) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6175 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6176 | ieee80211_is_dfs(freq, wpa_s->hw.modes, |
| 6177 | wpa_s->hw.num_modes)) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6178 | /* |
| 6179 | * If freq is a DFS channel and DFS is offloaded to the |
| 6180 | * driver, allow P2P GO to use it. |
| 6181 | */ |
| 6182 | wpa_printf(MSG_DEBUG, "P2P: " |
| 6183 | "%s: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded", |
| 6184 | __func__, freq); |
| 6185 | return freq; |
| 6186 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6187 | wpa_printf(MSG_DEBUG, "P2P: The forced channel for GO " |
| 6188 | "(%u MHz) is not supported for P2P uses", |
| 6189 | freq); |
| 6190 | return -1; |
| 6191 | } |
| 6192 | |
| 6193 | return freq; |
| 6194 | } |
| 6195 | |
| 6196 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6197 | static int wpas_p2p_supported_freq_go(struct wpa_supplicant *wpa_s, |
| 6198 | const struct p2p_channels *channels, |
| 6199 | int freq) |
| 6200 | { |
| 6201 | if (!wpas_p2p_disallowed_freq(wpa_s->global, freq) && |
| 6202 | p2p_supported_freq_go(wpa_s->global->p2p, freq) && |
| 6203 | freq_included(wpa_s, channels, freq)) |
| 6204 | return 1; |
| 6205 | return 0; |
| 6206 | } |
| 6207 | |
| 6208 | |
| 6209 | static void wpas_p2p_select_go_freq_no_pref(struct wpa_supplicant *wpa_s, |
| 6210 | struct p2p_go_neg_results *params, |
| 6211 | const struct p2p_channels *channels) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6212 | { |
| 6213 | unsigned int i, r; |
| 6214 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6215 | /* try all channels in operating class 115 */ |
| 6216 | for (i = 0; i < 4; i++) { |
| 6217 | params->freq = 5180 + i * 20; |
| 6218 | if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6219 | freq_included(wpa_s, channels, params->freq) && |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6220 | p2p_supported_freq(wpa_s->global->p2p, params->freq)) |
| 6221 | goto out; |
| 6222 | } |
| 6223 | |
| 6224 | /* try all channels in operating class 124 */ |
| 6225 | for (i = 0; i < 4; i++) { |
| 6226 | params->freq = 5745 + i * 20; |
| 6227 | if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6228 | freq_included(wpa_s, channels, params->freq) && |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6229 | p2p_supported_freq(wpa_s->global->p2p, params->freq)) |
| 6230 | goto out; |
| 6231 | } |
| 6232 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6233 | /* try social channel class 180 channel 2 */ |
| 6234 | params->freq = 58320 + 1 * 2160; |
| 6235 | if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6236 | freq_included(wpa_s, channels, params->freq) && |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6237 | p2p_supported_freq(wpa_s->global->p2p, params->freq)) |
| 6238 | goto out; |
| 6239 | |
| 6240 | /* try all channels in reg. class 180 */ |
| 6241 | for (i = 0; i < 4; i++) { |
| 6242 | params->freq = 58320 + i * 2160; |
| 6243 | if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6244 | freq_included(wpa_s, channels, params->freq) && |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6245 | p2p_supported_freq(wpa_s->global->p2p, params->freq)) |
| 6246 | goto out; |
| 6247 | } |
| 6248 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6249 | /* try some random selection of the social channels */ |
| 6250 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 6251 | return; |
| 6252 | |
| 6253 | for (i = 0; i < 3; i++) { |
| 6254 | params->freq = 2412 + ((r + i) % 3) * 25; |
| 6255 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
| 6256 | goto out; |
| 6257 | } |
| 6258 | |
| 6259 | /* try all other channels in operating class 81 */ |
| 6260 | for (i = 0; i < 11; i++) { |
| 6261 | params->freq = 2412 + i * 5; |
| 6262 | |
| 6263 | /* skip social channels; covered in the previous loop */ |
| 6264 | if (params->freq == 2412 || |
| 6265 | params->freq == 2437 || |
| 6266 | params->freq == 2462) |
| 6267 | continue; |
| 6268 | |
| 6269 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) |
| 6270 | goto out; |
| 6271 | } |
| 6272 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6273 | params->freq = 0; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6274 | 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] | 6275 | return; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6276 | out: |
| 6277 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz (no preference known)", |
| 6278 | params->freq); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6279 | } |
| 6280 | |
| 6281 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6282 | static int wpas_same_band(int freq1, int freq2) |
| 6283 | { |
| 6284 | enum hostapd_hw_mode mode1, mode2; |
| 6285 | u8 chan1, chan2; |
| 6286 | |
| 6287 | mode1 = ieee80211_freq_to_chan(freq1, &chan1); |
| 6288 | mode2 = ieee80211_freq_to_chan(freq2, &chan2); |
| 6289 | if (mode1 == NUM_HOSTAPD_MODES) |
| 6290 | return 0; |
| 6291 | return mode1 == mode2; |
| 6292 | } |
| 6293 | |
| 6294 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6295 | static int wpas_p2p_init_go_params(struct wpa_supplicant *wpa_s, |
| 6296 | struct p2p_go_neg_results *params, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6297 | int freq, int vht_center_freq2, int ht40, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6298 | int vht, int max_oper_chwidth, int he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6299 | int edmg, |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6300 | const struct p2p_channels *channels) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6301 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6302 | struct wpa_used_freq_data *freqs; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6303 | unsigned int cand; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6304 | unsigned int num, i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6305 | int ignore_no_freqs = 0; |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6306 | int unused_channels = wpas_p2p_num_unused_channels(wpa_s) > 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6307 | |
| 6308 | os_memset(params, 0, sizeof(*params)); |
| 6309 | params->role_go = 1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6310 | params->ht40 = ht40; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6311 | params->vht = vht; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6312 | params->he = he; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6313 | params->max_oper_chwidth = max_oper_chwidth; |
| 6314 | params->vht_center_freq2 = vht_center_freq2; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6315 | params->edmg = edmg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6316 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6317 | freqs = os_calloc(wpa_s->num_multichan_concurrent, |
| 6318 | sizeof(struct wpa_used_freq_data)); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6319 | if (!freqs) |
| 6320 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6321 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6322 | num = get_shared_radio_freqs_data(wpa_s, freqs, |
| 6323 | wpa_s->num_multichan_concurrent); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6324 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6325 | if (wpa_s->current_ssid && |
| 6326 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO && |
| 6327 | wpa_s->wpa_state == WPA_COMPLETED) { |
| 6328 | wpa_printf(MSG_DEBUG, "P2P: %s called for an active GO", |
| 6329 | __func__); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6330 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6331 | /* |
| 6332 | * If the frequency selection is done for an active P2P GO that |
| 6333 | * is not sharing a frequency, allow to select a new frequency |
| 6334 | * even if there are no unused frequencies as we are about to |
| 6335 | * move the P2P GO so its frequency can be re-used. |
| 6336 | */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6337 | for (i = 0; i < num; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6338 | if (freqs[i].freq == wpa_s->current_ssid->frequency && |
| 6339 | freqs[i].flags == 0) { |
| 6340 | ignore_no_freqs = 1; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6341 | break; |
| 6342 | } |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6343 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 6344 | } |
| 6345 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6346 | /* Try to use EDMG channel */ |
| 6347 | if (params->edmg) { |
| 6348 | if (wpas_p2p_try_edmg_channel(wpa_s, params) == 0) |
| 6349 | goto success; |
| 6350 | params->edmg = 0; |
| 6351 | } |
| 6352 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6353 | /* try using the forced freq */ |
| 6354 | if (freq) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6355 | if (wpas_p2p_disallowed_freq(wpa_s->global, freq) || |
| 6356 | !freq_included(wpa_s, channels, freq)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6357 | wpa_printf(MSG_DEBUG, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6358 | "P2P: Forced GO freq %d MHz disallowed", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6359 | freq); |
| 6360 | goto fail; |
| 6361 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6362 | if (!p2p_supported_freq_go(wpa_s->global->p2p, freq)) { |
| 6363 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6364 | ieee80211_is_dfs(freq, wpa_s->hw.modes, |
| 6365 | wpa_s->hw.num_modes)) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6366 | /* |
| 6367 | * If freq is a DFS channel and DFS is offloaded |
| 6368 | * to the driver, allow P2P GO to use it. |
| 6369 | */ |
| 6370 | wpa_printf(MSG_DEBUG, |
| 6371 | "P2P: %s: The forced channel for GO (%u MHz) requires DFS and DFS is offloaded", |
| 6372 | __func__, freq); |
| 6373 | } else { |
| 6374 | wpa_printf(MSG_DEBUG, |
| 6375 | "P2P: The forced channel for GO (%u MHz) is not supported for P2P uses", |
| 6376 | freq); |
| 6377 | goto fail; |
| 6378 | } |
| 6379 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6380 | |
| 6381 | for (i = 0; i < num; i++) { |
| 6382 | if (freqs[i].freq == freq) { |
| 6383 | wpa_printf(MSG_DEBUG, |
| 6384 | "P2P: forced freq (%d MHz) is also shared", |
| 6385 | freq); |
| 6386 | params->freq = freq; |
| 6387 | goto success; |
| 6388 | } |
| 6389 | } |
| 6390 | |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6391 | if (!ignore_no_freqs && !unused_channels) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6392 | wpa_printf(MSG_DEBUG, |
| 6393 | "P2P: Cannot force GO on freq (%d MHz) as all the channels are in use", |
| 6394 | freq); |
| 6395 | goto fail; |
| 6396 | } |
| 6397 | |
| 6398 | wpa_printf(MSG_DEBUG, |
| 6399 | "P2P: force GO freq (%d MHz) on a free channel", |
| 6400 | freq); |
| 6401 | params->freq = freq; |
| 6402 | goto success; |
| 6403 | } |
| 6404 | |
| 6405 | /* consider using one of the shared frequencies */ |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6406 | if (num && |
| 6407 | (!wpa_s->conf->p2p_ignore_shared_freq || !unused_channels)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6408 | cand = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num); |
| 6409 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6410 | wpa_printf(MSG_DEBUG, |
| 6411 | "P2P: Use shared freq (%d MHz) for GO", |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6412 | cand); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6413 | params->freq = cand; |
| 6414 | goto success; |
| 6415 | } |
| 6416 | |
| 6417 | /* try using one of the shared freqs */ |
| 6418 | for (i = 0; i < num; i++) { |
| 6419 | if (wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6420 | freqs[i].freq)) { |
| 6421 | wpa_printf(MSG_DEBUG, |
| 6422 | "P2P: Use shared freq (%d MHz) for GO", |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6423 | freqs[i].freq); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6424 | params->freq = freqs[i].freq; |
| 6425 | goto success; |
| 6426 | } |
| 6427 | } |
| 6428 | } |
| 6429 | |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6430 | if (!ignore_no_freqs && !unused_channels) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6431 | wpa_printf(MSG_DEBUG, |
| 6432 | "P2P: Cannot force GO on any of the channels we are already using"); |
| 6433 | goto fail; |
| 6434 | } |
| 6435 | |
| 6436 | /* try using the setting from the configuration file */ |
| 6437 | if (wpa_s->conf->p2p_oper_reg_class == 81 && |
| 6438 | wpa_s->conf->p2p_oper_channel >= 1 && |
| 6439 | wpa_s->conf->p2p_oper_channel <= 11 && |
| 6440 | wpas_p2p_supported_freq_go( |
| 6441 | wpa_s, channels, |
| 6442 | 2407 + 5 * wpa_s->conf->p2p_oper_channel)) { |
| 6443 | params->freq = 2407 + 5 * wpa_s->conf->p2p_oper_channel; |
| 6444 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured " |
| 6445 | "frequency %d MHz", params->freq); |
| 6446 | goto success; |
| 6447 | } |
| 6448 | |
| 6449 | if ((wpa_s->conf->p2p_oper_reg_class == 115 || |
| 6450 | wpa_s->conf->p2p_oper_reg_class == 116 || |
| 6451 | wpa_s->conf->p2p_oper_reg_class == 117 || |
| 6452 | wpa_s->conf->p2p_oper_reg_class == 124 || |
| 6453 | wpa_s->conf->p2p_oper_reg_class == 125 || |
| 6454 | wpa_s->conf->p2p_oper_reg_class == 126 || |
| 6455 | wpa_s->conf->p2p_oper_reg_class == 127) && |
| 6456 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6457 | 5000 + |
| 6458 | 5 * wpa_s->conf->p2p_oper_channel)) { |
| 6459 | params->freq = 5000 + 5 * wpa_s->conf->p2p_oper_channel; |
| 6460 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured " |
| 6461 | "frequency %d MHz", params->freq); |
| 6462 | goto success; |
| 6463 | } |
| 6464 | |
| 6465 | /* Try using best channels */ |
| 6466 | if (wpa_s->conf->p2p_oper_channel == 0 && |
| 6467 | wpa_s->best_overall_freq > 0 && |
| 6468 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6469 | wpa_s->best_overall_freq)) { |
| 6470 | params->freq = wpa_s->best_overall_freq; |
| 6471 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best overall " |
| 6472 | "channel %d MHz", params->freq); |
| 6473 | goto success; |
| 6474 | } |
| 6475 | |
| 6476 | if (wpa_s->conf->p2p_oper_channel == 0 && |
| 6477 | wpa_s->best_24_freq > 0 && |
| 6478 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6479 | wpa_s->best_24_freq)) { |
| 6480 | params->freq = wpa_s->best_24_freq; |
| 6481 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 2.4 GHz " |
| 6482 | "channel %d MHz", params->freq); |
| 6483 | goto success; |
| 6484 | } |
| 6485 | |
| 6486 | if (wpa_s->conf->p2p_oper_channel == 0 && |
| 6487 | wpa_s->best_5_freq > 0 && |
| 6488 | wpas_p2p_supported_freq_go(wpa_s, channels, |
| 6489 | wpa_s->best_5_freq)) { |
| 6490 | params->freq = wpa_s->best_5_freq; |
| 6491 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 5 GHz " |
| 6492 | "channel %d MHz", params->freq); |
| 6493 | goto success; |
| 6494 | } |
| 6495 | |
| 6496 | /* try using preferred channels */ |
| 6497 | cand = p2p_get_pref_freq(wpa_s->global->p2p, channels); |
| 6498 | if (cand && wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6499 | params->freq = cand; |
| 6500 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz from preferred " |
| 6501 | "channels", params->freq); |
| 6502 | goto success; |
| 6503 | } |
| 6504 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6505 | /* Try using a channel that allows VHT to be used with 80 MHz */ |
| 6506 | if (wpa_s->hw.modes && wpa_s->p2p_group_common_freqs) { |
| 6507 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 6508 | enum hostapd_hw_mode mode; |
| 6509 | struct hostapd_hw_modes *hwmode; |
| 6510 | u8 chan; |
| 6511 | |
| 6512 | cand = wpa_s->p2p_group_common_freqs[i]; |
| 6513 | mode = ieee80211_freq_to_chan(cand, &chan); |
| 6514 | hwmode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6515 | mode, is_6ghz_freq(cand)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6516 | if (!hwmode || |
| 6517 | wpas_p2p_verify_channel(wpa_s, hwmode, chan, |
| 6518 | BW80) != ALLOWED) |
| 6519 | continue; |
| 6520 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6521 | params->freq = cand; |
| 6522 | wpa_printf(MSG_DEBUG, |
| 6523 | "P2P: Use freq %d MHz common with the peer and allowing VHT80", |
| 6524 | params->freq); |
| 6525 | goto success; |
| 6526 | } |
| 6527 | } |
| 6528 | } |
| 6529 | |
| 6530 | /* Try using a channel that allows HT to be used with 40 MHz on the same |
| 6531 | * band so that CSA can be used */ |
| 6532 | if (wpa_s->current_ssid && wpa_s->hw.modes && |
| 6533 | wpa_s->p2p_group_common_freqs) { |
| 6534 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 6535 | enum hostapd_hw_mode mode; |
| 6536 | struct hostapd_hw_modes *hwmode; |
| 6537 | u8 chan; |
| 6538 | |
| 6539 | cand = wpa_s->p2p_group_common_freqs[i]; |
| 6540 | mode = ieee80211_freq_to_chan(cand, &chan); |
| 6541 | hwmode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6542 | mode, is_6ghz_freq(cand)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6543 | if (!wpas_same_band(wpa_s->current_ssid->frequency, |
| 6544 | cand) || |
| 6545 | !hwmode || |
| 6546 | (wpas_p2p_verify_channel(wpa_s, hwmode, chan, |
| 6547 | BW40MINUS) != ALLOWED && |
| 6548 | wpas_p2p_verify_channel(wpa_s, hwmode, chan, |
| 6549 | BW40PLUS) != ALLOWED)) |
| 6550 | continue; |
| 6551 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6552 | params->freq = cand; |
| 6553 | wpa_printf(MSG_DEBUG, |
| 6554 | "P2P: Use freq %d MHz common with the peer, allowing HT40, and maintaining same band", |
| 6555 | params->freq); |
| 6556 | goto success; |
| 6557 | } |
| 6558 | } |
| 6559 | } |
| 6560 | |
| 6561 | /* Try using one of the group common freqs on the same band so that CSA |
| 6562 | * can be used */ |
| 6563 | if (wpa_s->current_ssid && wpa_s->p2p_group_common_freqs) { |
| 6564 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 6565 | cand = wpa_s->p2p_group_common_freqs[i]; |
| 6566 | if (!wpas_same_band(wpa_s->current_ssid->frequency, |
| 6567 | cand)) |
| 6568 | continue; |
| 6569 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6570 | params->freq = cand; |
| 6571 | wpa_printf(MSG_DEBUG, |
| 6572 | "P2P: Use freq %d MHz common with the peer and maintaining same band", |
| 6573 | params->freq); |
| 6574 | goto success; |
| 6575 | } |
| 6576 | } |
| 6577 | } |
| 6578 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6579 | /* Try using one of the group common freqs */ |
| 6580 | if (wpa_s->p2p_group_common_freqs) { |
| 6581 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { |
| 6582 | cand = wpa_s->p2p_group_common_freqs[i]; |
| 6583 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { |
| 6584 | params->freq = cand; |
| 6585 | wpa_printf(MSG_DEBUG, |
| 6586 | "P2P: Use freq %d MHz common with the peer", |
| 6587 | params->freq); |
| 6588 | goto success; |
| 6589 | } |
| 6590 | } |
| 6591 | } |
| 6592 | |
| 6593 | /* no preference, select some channel */ |
| 6594 | wpas_p2p_select_go_freq_no_pref(wpa_s, params, channels); |
| 6595 | |
| 6596 | if (params->freq == 0) { |
| 6597 | wpa_printf(MSG_DEBUG, "P2P: did not find a freq for GO use"); |
| 6598 | goto fail; |
| 6599 | } |
| 6600 | |
| 6601 | success: |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6602 | os_free(freqs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6603 | return 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6604 | fail: |
| 6605 | os_free(freqs); |
| 6606 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6607 | } |
| 6608 | |
| 6609 | |
| 6610 | static struct wpa_supplicant * |
| 6611 | wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated, |
| 6612 | int go) |
| 6613 | { |
| 6614 | struct wpa_supplicant *group_wpa_s; |
| 6615 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6616 | if (!wpas_p2p_create_iface(wpa_s)) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6617 | if (wpa_s->p2p_mgmt) { |
| 6618 | /* |
| 6619 | * We may be called on the p2p_dev interface which |
| 6620 | * cannot be used for group operations, so always use |
| 6621 | * the primary interface. |
| 6622 | */ |
| 6623 | wpa_s->parent->p2pdev = wpa_s; |
| 6624 | wpa_s = wpa_s->parent; |
| 6625 | } |
| 6626 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 6627 | "P2P: Use primary interface for group operations"); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6628 | wpa_s->p2p_first_connection_timeout = 0; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6629 | if (wpa_s != wpa_s->p2pdev) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6630 | wpas_p2p_clone_config(wpa_s, wpa_s->p2pdev); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6631 | return wpa_s; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6632 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6633 | |
| 6634 | 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] | 6635 | WPA_IF_P2P_CLIENT) < 0) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6636 | wpa_msg_global(wpa_s, MSG_ERROR, |
| 6637 | "P2P: Failed to add group interface"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6638 | return NULL; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6639 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6640 | group_wpa_s = wpas_p2p_init_group_interface(wpa_s, go); |
| 6641 | if (group_wpa_s == NULL) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6642 | wpa_msg_global(wpa_s, MSG_ERROR, |
| 6643 | "P2P: Failed to initialize group interface"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6644 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 6645 | return NULL; |
| 6646 | } |
| 6647 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6648 | if (go && wpa_s->p2p_go_do_acs) { |
| 6649 | group_wpa_s->p2p_go_do_acs = wpa_s->p2p_go_do_acs; |
| 6650 | group_wpa_s->p2p_go_acs_band = wpa_s->p2p_go_acs_band; |
| 6651 | wpa_s->p2p_go_do_acs = 0; |
| 6652 | } |
| 6653 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6654 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use separate group interface %s", |
| 6655 | group_wpa_s->ifname); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6656 | group_wpa_s->p2p_first_connection_timeout = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6657 | return group_wpa_s; |
| 6658 | } |
| 6659 | |
| 6660 | |
| 6661 | /** |
| 6662 | * wpas_p2p_group_add - Add a new P2P group with local end as Group Owner |
| 6663 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() |
| 6664 | * @persistent_group: Whether to create a persistent group |
| 6665 | * @freq: Frequency for the group or 0 to indicate no hardcoding |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6666 | * @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] | 6667 | * @ht40: Start GO with 40 MHz channel width |
| 6668 | * @vht: Start GO with VHT support |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6669 | * @vht_chwidth: channel bandwidth for GO operating with VHT support |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6670 | * @edmg: Start GO with EDMG support |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6671 | * Returns: 0 on success, -1 on failure |
| 6672 | * |
| 6673 | * This function creates a new P2P group with the local end as the Group Owner, |
| 6674 | * i.e., without using Group Owner Negotiation. |
| 6675 | */ |
| 6676 | 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] | 6677 | int freq, int vht_center_freq2, int ht40, int vht, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6678 | int max_oper_chwidth, int he, int edmg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6679 | { |
| 6680 | struct p2p_go_neg_results params; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6681 | |
| 6682 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 6683 | return -1; |
| 6684 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6685 | os_free(wpa_s->global->add_psk); |
| 6686 | wpa_s->global->add_psk = NULL; |
| 6687 | |
Dmitry Shmidt | dca3979 | 2011-09-06 11:17:33 -0700 | [diff] [blame] | 6688 | /* Make sure we are not running find during connection establishment */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6689 | wpa_printf(MSG_DEBUG, "P2P: Stop any on-going P2P FIND"); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6690 | wpas_p2p_stop_find_oper(wpa_s); |
Dmitry Shmidt | dca3979 | 2011-09-06 11:17:33 -0700 | [diff] [blame] | 6691 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6692 | if (!wpa_s->p2p_go_do_acs) { |
| 6693 | freq = wpas_p2p_select_go_freq(wpa_s, freq); |
| 6694 | if (freq < 0) |
| 6695 | return -1; |
| 6696 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6697 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6698 | 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] | 6699 | ht40, vht, max_oper_chwidth, he, edmg, |
| 6700 | NULL)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6701 | return -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6702 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6703 | p2p_go_params(wpa_s->global->p2p, ¶ms); |
| 6704 | params.persistent_group = persistent_group; |
| 6705 | |
| 6706 | wpa_s = wpas_p2p_get_group_iface(wpa_s, 0, 1); |
| 6707 | if (wpa_s == NULL) |
| 6708 | return -1; |
| 6709 | wpas_start_wps_go(wpa_s, ¶ms, 0); |
| 6710 | |
| 6711 | return 0; |
| 6712 | } |
| 6713 | |
| 6714 | |
| 6715 | static int wpas_start_p2p_client(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6716 | struct wpa_ssid *params, int addr_allocated, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6717 | int freq, int force_scan) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6718 | { |
| 6719 | struct wpa_ssid *ssid; |
| 6720 | |
| 6721 | wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 0); |
| 6722 | if (wpa_s == NULL) |
| 6723 | return -1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6724 | if (force_scan) |
| 6725 | os_get_reltime(&wpa_s->scan_min_time); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6726 | wpa_s->p2p_last_4way_hs_fail = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6727 | |
| 6728 | wpa_supplicant_ap_deinit(wpa_s); |
| 6729 | |
| 6730 | ssid = wpa_config_add_network(wpa_s->conf); |
| 6731 | if (ssid == NULL) |
| 6732 | return -1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6733 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6734 | wpa_config_set_network_defaults(ssid); |
| 6735 | ssid->temporary = 1; |
| 6736 | ssid->proto = WPA_PROTO_RSN; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 6737 | ssid->pbss = params->pbss; |
| 6738 | ssid->pairwise_cipher = params->pbss ? WPA_CIPHER_GCMP : |
| 6739 | WPA_CIPHER_CCMP; |
| 6740 | ssid->group_cipher = params->pbss ? WPA_CIPHER_GCMP : WPA_CIPHER_CCMP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6741 | ssid->key_mgmt = WPA_KEY_MGMT_PSK; |
| 6742 | ssid->ssid = os_malloc(params->ssid_len); |
| 6743 | if (ssid->ssid == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6744 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 6745 | return -1; |
| 6746 | } |
| 6747 | os_memcpy(ssid->ssid, params->ssid, params->ssid_len); |
| 6748 | ssid->ssid_len = params->ssid_len; |
| 6749 | ssid->p2p_group = 1; |
| 6750 | ssid->export_keys = 1; |
| 6751 | if (params->psk_set) { |
| 6752 | os_memcpy(ssid->psk, params->psk, 32); |
| 6753 | ssid->psk_set = 1; |
| 6754 | } |
| 6755 | if (params->passphrase) |
| 6756 | ssid->passphrase = os_strdup(params->passphrase); |
| 6757 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6758 | wpa_s->show_group_started = 1; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6759 | wpa_s->p2p_in_invitation = 1; |
| 6760 | wpa_s->p2p_invite_go_freq = freq; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6761 | wpa_s->p2p_go_group_formation_completed = 0; |
| 6762 | wpa_s->global->p2p_group_formation = wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6763 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6764 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->p2pdev, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6765 | NULL); |
| 6766 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, |
| 6767 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6768 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 6769 | wpa_supplicant_select_network(wpa_s, ssid); |
| 6770 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6771 | return 0; |
| 6772 | } |
| 6773 | |
| 6774 | |
| 6775 | int wpas_p2p_group_add_persistent(struct wpa_supplicant *wpa_s, |
| 6776 | struct wpa_ssid *ssid, int addr_allocated, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6777 | int force_freq, int neg_freq, |
| 6778 | int vht_center_freq2, int ht40, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6779 | int vht, int max_oper_chwidth, int he, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6780 | int edmg, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6781 | const struct p2p_channels *channels, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6782 | int connection_timeout, int force_scan) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6783 | { |
| 6784 | struct p2p_go_neg_results params; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 6785 | int go = 0, freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6786 | |
| 6787 | if (ssid->disabled != 2 || ssid->ssid == NULL) |
| 6788 | return -1; |
| 6789 | |
| 6790 | if (wpas_get_p2p_group(wpa_s, ssid->ssid, ssid->ssid_len, &go) && |
| 6791 | go == (ssid->mode == WPAS_MODE_P2P_GO)) { |
| 6792 | wpa_printf(MSG_DEBUG, "P2P: Requested persistent group is " |
| 6793 | "already running"); |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 6794 | if (go == 0 && |
| 6795 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6796 | wpa_s->p2pdev, NULL)) { |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 6797 | /* |
| 6798 | * This can happen if Invitation Response frame was lost |
| 6799 | * and the peer (GO of a persistent group) tries to |
| 6800 | * invite us again. Reschedule the timeout to avoid |
| 6801 | * terminating the wait for the connection too early |
| 6802 | * since we now know that the peer is still trying to |
| 6803 | * invite us instead of having already started the GO. |
| 6804 | */ |
| 6805 | wpa_printf(MSG_DEBUG, |
| 6806 | "P2P: Reschedule group formation timeout since peer is still trying to invite us"); |
| 6807 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, |
| 6808 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6809 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 6810 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6811 | return 0; |
| 6812 | } |
| 6813 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6814 | os_free(wpa_s->global->add_psk); |
| 6815 | wpa_s->global->add_psk = NULL; |
| 6816 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6817 | /* Make sure we are not running find during connection establishment */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6818 | wpas_p2p_stop_find_oper(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6819 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6820 | wpa_s->p2p_fallback_to_go_neg = 0; |
| 6821 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6822 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 6823 | if (force_freq > 0) { |
| 6824 | freq = wpas_p2p_select_go_freq(wpa_s, force_freq); |
| 6825 | if (freq < 0) |
| 6826 | return -1; |
| 6827 | } else { |
| 6828 | freq = wpas_p2p_select_go_freq(wpa_s, neg_freq); |
| 6829 | if (freq < 0 || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6830 | (freq > 0 && !freq_included(wpa_s, channels, freq))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6831 | freq = 0; |
| 6832 | } |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 6833 | } else if (ssid->mode == WPAS_MODE_INFRA) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6834 | freq = neg_freq; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6835 | if (freq <= 0 || !freq_included(wpa_s, channels, freq)) { |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 6836 | struct os_reltime now; |
| 6837 | struct wpa_bss *bss = |
| 6838 | wpa_bss_get_p2p_dev_addr(wpa_s, ssid->bssid); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6839 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 6840 | os_get_reltime(&now); |
| 6841 | if (bss && |
| 6842 | !os_reltime_expired(&now, &bss->last_update, 5) && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6843 | freq_included(wpa_s, channels, bss->freq)) |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 6844 | freq = bss->freq; |
| 6845 | else |
| 6846 | freq = 0; |
| 6847 | } |
| 6848 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6849 | return wpas_start_p2p_client(wpa_s, ssid, addr_allocated, freq, |
| 6850 | force_scan); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 6851 | } else { |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6852 | return -1; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 6853 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6854 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6855 | 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] | 6856 | ht40, vht, max_oper_chwidth, he, edmg, |
| 6857 | channels)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6858 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6859 | |
| 6860 | params.role_go = 1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6861 | params.psk_set = ssid->psk_set; |
| 6862 | if (params.psk_set) |
| 6863 | os_memcpy(params.psk, ssid->psk, sizeof(params.psk)); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6864 | if (ssid->passphrase) { |
| 6865 | if (os_strlen(ssid->passphrase) >= sizeof(params.passphrase)) { |
| 6866 | wpa_printf(MSG_ERROR, "P2P: Invalid passphrase in " |
| 6867 | "persistent group"); |
| 6868 | return -1; |
| 6869 | } |
| 6870 | os_strlcpy(params.passphrase, ssid->passphrase, |
| 6871 | sizeof(params.passphrase)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6872 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6873 | os_memcpy(params.ssid, ssid->ssid, ssid->ssid_len); |
| 6874 | params.ssid_len = ssid->ssid_len; |
| 6875 | params.persistent_group = 1; |
| 6876 | |
| 6877 | wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 1); |
| 6878 | if (wpa_s == NULL) |
| 6879 | return -1; |
| 6880 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6881 | p2p_channels_to_freqs(channels, params.freq_list, P2P_MAX_CHANNELS); |
| 6882 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6883 | wpa_s->p2p_first_connection_timeout = connection_timeout; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6884 | wpas_start_wps_go(wpa_s, ¶ms, 0); |
| 6885 | |
| 6886 | return 0; |
| 6887 | } |
| 6888 | |
| 6889 | |
| 6890 | static void wpas_p2p_ie_update(void *ctx, struct wpabuf *beacon_ies, |
| 6891 | struct wpabuf *proberesp_ies) |
| 6892 | { |
| 6893 | struct wpa_supplicant *wpa_s = ctx; |
| 6894 | if (wpa_s->ap_iface) { |
| 6895 | struct hostapd_data *hapd = wpa_s->ap_iface->bss[0]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6896 | if (!(hapd->conf->p2p & P2P_GROUP_OWNER)) { |
| 6897 | wpabuf_free(beacon_ies); |
| 6898 | wpabuf_free(proberesp_ies); |
| 6899 | return; |
| 6900 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6901 | if (beacon_ies) { |
| 6902 | wpabuf_free(hapd->p2p_beacon_ie); |
| 6903 | hapd->p2p_beacon_ie = beacon_ies; |
| 6904 | } |
| 6905 | wpabuf_free(hapd->p2p_probe_resp_ie); |
| 6906 | hapd->p2p_probe_resp_ie = proberesp_ies; |
| 6907 | } else { |
| 6908 | wpabuf_free(beacon_ies); |
| 6909 | wpabuf_free(proberesp_ies); |
| 6910 | } |
| 6911 | wpa_supplicant_ap_update_beacon(wpa_s); |
| 6912 | } |
| 6913 | |
| 6914 | |
| 6915 | static void wpas_p2p_idle_update(void *ctx, int idle) |
| 6916 | { |
| 6917 | struct wpa_supplicant *wpa_s = ctx; |
| 6918 | if (!wpa_s->ap_iface) |
| 6919 | return; |
| 6920 | wpa_printf(MSG_DEBUG, "P2P: GO - group %sidle", idle ? "" : "not "); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6921 | if (idle) { |
| 6922 | if (wpa_s->global->p2p_fail_on_wps_complete && |
| 6923 | wpa_s->p2p_in_provisioning) { |
| 6924 | wpas_p2p_grpform_fail_after_wps(wpa_s); |
| 6925 | return; |
| 6926 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6927 | wpas_p2p_set_group_idle_timeout(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6928 | } else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6929 | eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL); |
| 6930 | } |
| 6931 | |
| 6932 | |
| 6933 | struct p2p_group * wpas_p2p_group_init(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6934 | struct wpa_ssid *ssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6935 | { |
| 6936 | struct p2p_group *group; |
| 6937 | struct p2p_group_config *cfg; |
| 6938 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6939 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL || |
| 6940 | !ssid->p2p_group) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6941 | return NULL; |
| 6942 | |
| 6943 | cfg = os_zalloc(sizeof(*cfg)); |
| 6944 | if (cfg == NULL) |
| 6945 | return NULL; |
| 6946 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6947 | if (ssid->p2p_persistent_group && wpa_s->conf->persistent_reconnect) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6948 | cfg->persistent_group = 2; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6949 | else if (ssid->p2p_persistent_group) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6950 | cfg->persistent_group = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6951 | os_memcpy(cfg->interface_addr, wpa_s->own_addr, ETH_ALEN); |
| 6952 | if (wpa_s->max_stations && |
| 6953 | wpa_s->max_stations < wpa_s->conf->max_num_sta) |
| 6954 | cfg->max_clients = wpa_s->max_stations; |
| 6955 | else |
| 6956 | cfg->max_clients = wpa_s->conf->max_num_sta; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6957 | os_memcpy(cfg->ssid, ssid->ssid, ssid->ssid_len); |
| 6958 | cfg->ssid_len = ssid->ssid_len; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 6959 | cfg->freq = ssid->frequency; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6960 | cfg->cb_ctx = wpa_s; |
| 6961 | cfg->ie_update = wpas_p2p_ie_update; |
| 6962 | cfg->idle_update = wpas_p2p_idle_update; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 6963 | cfg->ip_addr_alloc = WPA_GET_BE32(wpa_s->p2pdev->conf->ip_addr_start) |
| 6964 | != 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6965 | |
| 6966 | group = p2p_group_init(wpa_s->global->p2p, cfg); |
| 6967 | if (group == NULL) |
| 6968 | os_free(cfg); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6969 | if (ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6970 | p2p_group_notif_formation_done(group); |
| 6971 | wpa_s->p2p_group = group; |
| 6972 | return group; |
| 6973 | } |
| 6974 | |
| 6975 | |
| 6976 | void wpas_p2p_wps_success(struct wpa_supplicant *wpa_s, const u8 *peer_addr, |
| 6977 | int registrar) |
| 6978 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6979 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 6980 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6981 | if (!wpa_s->p2p_in_provisioning) { |
| 6982 | wpa_printf(MSG_DEBUG, "P2P: Ignore WPS success event - P2P " |
| 6983 | "provisioning not in progress"); |
| 6984 | return; |
| 6985 | } |
| 6986 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6987 | if (ssid && ssid->mode == WPAS_MODE_INFRA) { |
| 6988 | u8 go_dev_addr[ETH_ALEN]; |
| 6989 | os_memcpy(go_dev_addr, wpa_s->bssid, ETH_ALEN); |
| 6990 | wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid, |
| 6991 | ssid->ssid_len); |
| 6992 | /* Clear any stored provisioning info */ |
| 6993 | p2p_clear_provisioning_info(wpa_s->global->p2p, go_dev_addr); |
| 6994 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6995 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6996 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->p2pdev, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6997 | NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6998 | wpa_s->p2p_go_group_formation_completed = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6999 | if (ssid && ssid->mode == WPAS_MODE_INFRA) { |
| 7000 | /* |
| 7001 | * Use a separate timeout for initial data connection to |
| 7002 | * complete to allow the group to be removed automatically if |
| 7003 | * something goes wrong in this step before the P2P group idle |
| 7004 | * timeout mechanism is taken into use. |
| 7005 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7006 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 7007 | "P2P: Re-start group formation timeout (%d seconds) as client for initial connection", |
| 7008 | P2P_MAX_INITIAL_CONN_WAIT); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7009 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, |
| 7010 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7011 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7012 | /* Complete group formation on successful data connection. */ |
| 7013 | wpa_s->p2p_go_group_formation_completed = 0; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7014 | } else if (ssid) { |
| 7015 | /* |
| 7016 | * Use a separate timeout for initial data connection to |
| 7017 | * complete to allow the group to be removed automatically if |
| 7018 | * the client does not complete data connection successfully. |
| 7019 | */ |
| 7020 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 7021 | "P2P: Re-start group formation timeout (%d seconds) as GO for initial connection", |
| 7022 | P2P_MAX_INITIAL_CONN_WAIT_GO); |
| 7023 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT_GO, 0, |
| 7024 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7025 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7026 | /* |
| 7027 | * Complete group formation on first successful data connection |
| 7028 | */ |
| 7029 | wpa_s->p2p_go_group_formation_completed = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7030 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7031 | if (wpa_s->global->p2p) |
| 7032 | p2p_wps_success_cb(wpa_s->global->p2p, peer_addr); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 7033 | wpas_group_formation_completed(wpa_s, 1, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7034 | } |
| 7035 | |
| 7036 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7037 | void wpas_p2p_wps_failed(struct wpa_supplicant *wpa_s, |
| 7038 | struct wps_event_fail *fail) |
| 7039 | { |
| 7040 | if (!wpa_s->p2p_in_provisioning) { |
| 7041 | wpa_printf(MSG_DEBUG, "P2P: Ignore WPS fail event - P2P " |
| 7042 | "provisioning not in progress"); |
| 7043 | return; |
| 7044 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7045 | |
| 7046 | if (wpa_s->go_params) { |
| 7047 | p2p_clear_provisioning_info( |
| 7048 | wpa_s->global->p2p, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7049 | wpa_s->go_params->peer_device_addr); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7050 | } |
| 7051 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7052 | wpas_notify_p2p_wps_failed(wpa_s, fail); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7053 | |
| 7054 | if (wpa_s == wpa_s->global->p2p_group_formation) { |
| 7055 | /* |
| 7056 | * Allow some time for the failed WPS negotiation exchange to |
| 7057 | * complete, but remove the group since group formation cannot |
| 7058 | * succeed after provisioning failure. |
| 7059 | */ |
| 7060 | wpa_printf(MSG_DEBUG, "P2P: WPS step failed during group formation - reject connection from timeout"); |
| 7061 | wpa_s->global->p2p_fail_on_wps_complete = 1; |
| 7062 | eloop_deplete_timeout(0, 50000, |
| 7063 | wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7064 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7065 | } |
| 7066 | } |
| 7067 | |
| 7068 | |
| 7069 | int wpas_p2p_wps_eapol_cb(struct wpa_supplicant *wpa_s) |
| 7070 | { |
| 7071 | if (!wpa_s->global->p2p_fail_on_wps_complete || |
| 7072 | !wpa_s->p2p_in_provisioning) |
| 7073 | return 0; |
| 7074 | |
| 7075 | wpas_p2p_grpform_fail_after_wps(wpa_s); |
| 7076 | |
| 7077 | return 1; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7078 | } |
| 7079 | |
| 7080 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7081 | 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] | 7082 | const char *config_method, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7083 | enum wpas_p2p_prov_disc_use use, |
| 7084 | struct p2ps_provision *p2ps_prov) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7085 | { |
| 7086 | u16 config_methods; |
| 7087 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7088 | wpa_s->global->pending_p2ps_group = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7089 | wpa_s->global->pending_p2ps_group_freq = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7090 | wpa_s->p2p_fallback_to_go_neg = 0; |
| 7091 | wpa_s->pending_pd_use = NORMAL_PD; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7092 | if (p2ps_prov && use == WPAS_P2P_PD_FOR_ASP) { |
| 7093 | p2ps_prov->conncap = p2ps_group_capability( |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7094 | wpa_s, P2PS_SETUP_NONE, p2ps_prov->role, |
| 7095 | &p2ps_prov->force_freq, &p2ps_prov->pref_freq); |
| 7096 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7097 | wpa_printf(MSG_DEBUG, |
| 7098 | "P2P: %s conncap: %d - ASP parsed: %x %x %d %s", |
| 7099 | __func__, p2ps_prov->conncap, |
| 7100 | p2ps_prov->adv_id, p2ps_prov->conncap, |
| 7101 | p2ps_prov->status, p2ps_prov->info); |
| 7102 | |
| 7103 | config_methods = 0; |
| 7104 | } else if (os_strncmp(config_method, "display", 7) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7105 | config_methods = WPS_CONFIG_DISPLAY; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7106 | else if (os_strncmp(config_method, "keypad", 6) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7107 | config_methods = WPS_CONFIG_KEYPAD; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7108 | else if (os_strncmp(config_method, "pbc", 3) == 0 || |
| 7109 | os_strncmp(config_method, "pushbutton", 10) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7110 | config_methods = WPS_CONFIG_PUSHBUTTON; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7111 | else { |
| 7112 | wpa_printf(MSG_DEBUG, "P2P: Unknown config method"); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7113 | os_free(p2ps_prov); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7114 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7115 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7116 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7117 | if (use == WPAS_P2P_PD_AUTO) { |
| 7118 | os_memcpy(wpa_s->pending_join_dev_addr, peer_addr, ETH_ALEN); |
| 7119 | wpa_s->pending_pd_config_methods = config_methods; |
| 7120 | wpa_s->p2p_auto_pd = 1; |
| 7121 | wpa_s->p2p_auto_join = 0; |
| 7122 | wpa_s->pending_pd_before_join = 0; |
| 7123 | wpa_s->auto_pd_scan_retry = 0; |
| 7124 | wpas_p2p_stop_find(wpa_s); |
| 7125 | wpa_s->p2p_join_scan_count = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7126 | os_get_reltime(&wpa_s->p2p_auto_started); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7127 | wpa_printf(MSG_DEBUG, "P2P: Auto PD started at %ld.%06ld", |
| 7128 | wpa_s->p2p_auto_started.sec, |
| 7129 | wpa_s->p2p_auto_started.usec); |
| 7130 | wpas_p2p_join_scan(wpa_s, NULL); |
| 7131 | return 0; |
| 7132 | } |
| 7133 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7134 | if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) { |
| 7135 | os_free(p2ps_prov); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7136 | return -1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7137 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7138 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7139 | 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] | 7140 | config_methods, use == WPAS_P2P_PD_FOR_JOIN, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7141 | 0, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7142 | } |
| 7143 | |
| 7144 | |
| 7145 | int wpas_p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf, |
| 7146 | char *end) |
| 7147 | { |
| 7148 | return p2p_scan_result_text(ies, ies_len, buf, end); |
| 7149 | } |
| 7150 | |
| 7151 | |
| 7152 | static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant *wpa_s) |
| 7153 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7154 | if (!offchannel_pending_action_tx(wpa_s)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7155 | return; |
| 7156 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 7157 | if (wpa_s->p2p_send_action_work) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7158 | wpas_p2p_free_send_action_work(wpa_s); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 7159 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, |
| 7160 | wpa_s, NULL); |
| 7161 | offchannel_send_action_done(wpa_s); |
| 7162 | } |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 7163 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7164 | wpa_printf(MSG_DEBUG, "P2P: Drop pending Action TX due to new " |
| 7165 | "operation request"); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7166 | offchannel_clear_pending_action_tx(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7167 | } |
| 7168 | |
| 7169 | |
| 7170 | int wpas_p2p_find(struct wpa_supplicant *wpa_s, unsigned int timeout, |
| 7171 | enum p2p_discovery_type type, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7172 | unsigned int num_req_dev_types, const u8 *req_dev_types, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7173 | const u8 *dev_id, unsigned int search_delay, |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 7174 | u8 seek_cnt, const char **seek_string, int freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7175 | { |
| 7176 | wpas_p2p_clear_pending_action_tx(wpa_s); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7177 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7178 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7179 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7180 | wpa_s->p2p_in_provisioning) { |
| 7181 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Reject p2p_find operation%s%s", |
| 7182 | (wpa_s->global->p2p_disabled || !wpa_s->global->p2p) ? |
| 7183 | " (P2P disabled)" : "", |
| 7184 | wpa_s->p2p_in_provisioning ? |
| 7185 | " (p2p_in_provisioning)" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7186 | return -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7187 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7188 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7189 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 7190 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7191 | return p2p_find(wpa_s->global->p2p, timeout, type, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7192 | num_req_dev_types, req_dev_types, dev_id, |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 7193 | search_delay, seek_cnt, seek_string, freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7194 | } |
| 7195 | |
| 7196 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7197 | static void wpas_p2p_scan_res_ignore_search(struct wpa_supplicant *wpa_s, |
| 7198 | struct wpa_scan_results *scan_res) |
| 7199 | { |
| 7200 | wpa_printf(MSG_DEBUG, "P2P: Ignore scan results"); |
| 7201 | |
| 7202 | if (wpa_s->p2p_scan_work) { |
| 7203 | struct wpa_radio_work *work = wpa_s->p2p_scan_work; |
| 7204 | wpa_s->p2p_scan_work = NULL; |
| 7205 | radio_work_done(work); |
| 7206 | } |
| 7207 | |
| 7208 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7209 | return; |
| 7210 | |
| 7211 | /* |
| 7212 | * Indicate that results have been processed so that the P2P module can |
| 7213 | * continue pending tasks. |
| 7214 | */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 7215 | wpas_p2p_scan_res_handled(wpa_s); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7216 | } |
| 7217 | |
| 7218 | |
| 7219 | static void wpas_p2p_stop_find_oper(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7220 | { |
| 7221 | wpas_p2p_clear_pending_action_tx(wpa_s); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7222 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7223 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
| 7224 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7225 | |
| 7226 | if (wpa_s->global->p2p) |
| 7227 | p2p_stop_find(wpa_s->global->p2p); |
| 7228 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7229 | if (wpa_s->scan_res_handler == wpas_p2p_scan_res_handler) { |
| 7230 | wpa_printf(MSG_DEBUG, |
| 7231 | "P2P: Do not consider the scan results after stop_find"); |
| 7232 | wpa_s->scan_res_handler = wpas_p2p_scan_res_ignore_search; |
| 7233 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7234 | } |
| 7235 | |
| 7236 | |
| 7237 | void wpas_p2p_stop_find(struct wpa_supplicant *wpa_s) |
| 7238 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7239 | wpas_p2p_stop_find_oper(wpa_s); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7240 | if (!wpa_s->global->pending_group_iface_for_p2ps) |
| 7241 | wpas_p2p_remove_pending_group_interface(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7242 | } |
| 7243 | |
| 7244 | |
| 7245 | static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx) |
| 7246 | { |
| 7247 | struct wpa_supplicant *wpa_s = eloop_ctx; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7248 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7249 | } |
| 7250 | |
| 7251 | |
| 7252 | int wpas_p2p_listen(struct wpa_supplicant *wpa_s, unsigned int timeout) |
| 7253 | { |
| 7254 | int res; |
| 7255 | |
| 7256 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7257 | return -1; |
| 7258 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 7259 | if (wpa_s->p2p_lo_started) { |
| 7260 | wpa_printf(MSG_DEBUG, |
| 7261 | "P2P: Cannot start P2P listen, it is offloaded"); |
| 7262 | return -1; |
| 7263 | } |
| 7264 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7265 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7266 | wpas_p2p_clear_pending_action_tx(wpa_s); |
| 7267 | |
| 7268 | if (timeout == 0) { |
| 7269 | /* |
| 7270 | * This is a request for unlimited Listen state. However, at |
| 7271 | * least for now, this is mapped to a Listen state for one |
| 7272 | * hour. |
| 7273 | */ |
| 7274 | timeout = 3600; |
| 7275 | } |
| 7276 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7277 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7278 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7279 | /* |
| 7280 | * Stop previous find/listen operation to avoid trying to request a new |
| 7281 | * remain-on-channel operation while the driver is still running the |
| 7282 | * previous one. |
| 7283 | */ |
| 7284 | if (wpa_s->global->p2p) |
| 7285 | p2p_stop_find(wpa_s->global->p2p); |
| 7286 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7287 | res = wpas_p2p_listen_start(wpa_s, timeout * 1000); |
| 7288 | if (res == 0 && timeout * 1000 > wpa_s->max_remain_on_chan) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7289 | wpa_s->global->p2p_long_listen = timeout * 1000; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7290 | eloop_register_timeout(timeout, 0, |
| 7291 | wpas_p2p_long_listen_timeout, |
| 7292 | wpa_s, NULL); |
| 7293 | } |
| 7294 | |
| 7295 | return res; |
| 7296 | } |
| 7297 | |
| 7298 | |
| 7299 | int wpas_p2p_assoc_req_ie(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
| 7300 | u8 *buf, size_t len, int p2p_group) |
| 7301 | { |
| 7302 | struct wpabuf *p2p_ie; |
| 7303 | int ret; |
| 7304 | |
| 7305 | if (wpa_s->global->p2p_disabled) |
| 7306 | return -1; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 7307 | /* |
| 7308 | * Advertize mandatory cross connection capability even on |
| 7309 | * p2p_disabled=1 interface when associating with a P2P Manager WLAN AP. |
| 7310 | */ |
| 7311 | if (wpa_s->conf->p2p_disabled && p2p_group) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7312 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7313 | if (wpa_s->global->p2p == NULL) |
| 7314 | return -1; |
| 7315 | if (bss == NULL) |
| 7316 | return -1; |
| 7317 | |
| 7318 | p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE); |
| 7319 | ret = p2p_assoc_req_ie(wpa_s->global->p2p, bss->bssid, buf, len, |
| 7320 | p2p_group, p2p_ie); |
| 7321 | wpabuf_free(p2p_ie); |
| 7322 | |
| 7323 | return ret; |
| 7324 | } |
| 7325 | |
| 7326 | |
| 7327 | 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] | 7328 | const u8 *dst, const u8 *bssid, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 7329 | const u8 *ie, size_t ie_len, |
| 7330 | unsigned int rx_freq, int ssi_signal) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7331 | { |
| 7332 | if (wpa_s->global->p2p_disabled) |
| 7333 | return 0; |
| 7334 | if (wpa_s->global->p2p == NULL) |
| 7335 | return 0; |
| 7336 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7337 | switch (p2p_probe_req_rx(wpa_s->global->p2p, addr, dst, bssid, |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 7338 | ie, ie_len, rx_freq, wpa_s->p2p_lo_started)) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7339 | case P2P_PREQ_NOT_P2P: |
| 7340 | wpas_notify_preq(wpa_s, addr, dst, bssid, ie, ie_len, |
| 7341 | ssi_signal); |
| 7342 | /* fall through */ |
| 7343 | case P2P_PREQ_MALFORMED: |
| 7344 | case P2P_PREQ_NOT_LISTEN: |
| 7345 | case P2P_PREQ_NOT_PROCESSED: |
| 7346 | default: /* make gcc happy */ |
| 7347 | return 0; |
| 7348 | case P2P_PREQ_PROCESSED: |
| 7349 | return 1; |
| 7350 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7351 | } |
| 7352 | |
| 7353 | |
| 7354 | void wpas_p2p_rx_action(struct wpa_supplicant *wpa_s, const u8 *da, |
| 7355 | const u8 *sa, const u8 *bssid, |
| 7356 | u8 category, const u8 *data, size_t len, int freq) |
| 7357 | { |
| 7358 | if (wpa_s->global->p2p_disabled) |
| 7359 | return; |
| 7360 | if (wpa_s->global->p2p == NULL) |
| 7361 | return; |
| 7362 | |
| 7363 | p2p_rx_action(wpa_s->global->p2p, da, sa, bssid, category, data, len, |
| 7364 | freq); |
| 7365 | } |
| 7366 | |
| 7367 | |
| 7368 | void wpas_p2p_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ies) |
| 7369 | { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7370 | unsigned int bands; |
| 7371 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7372 | if (wpa_s->global->p2p_disabled) |
| 7373 | return; |
| 7374 | if (wpa_s->global->p2p == NULL) |
| 7375 | return; |
| 7376 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7377 | bands = wpas_get_bands(wpa_s, NULL); |
| 7378 | p2p_scan_ie(wpa_s->global->p2p, ies, NULL, bands); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7379 | } |
| 7380 | |
| 7381 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7382 | static void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7383 | { |
| 7384 | p2p_group_deinit(wpa_s->p2p_group); |
| 7385 | wpa_s->p2p_group = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7386 | |
| 7387 | wpa_s->ap_configured_cb = NULL; |
| 7388 | wpa_s->ap_configured_cb_ctx = NULL; |
| 7389 | wpa_s->ap_configured_cb_data = NULL; |
| 7390 | wpa_s->connect_without_scan = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7391 | } |
| 7392 | |
| 7393 | |
| 7394 | int wpas_p2p_reject(struct wpa_supplicant *wpa_s, const u8 *addr) |
| 7395 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7396 | wpa_s->global->p2p_long_listen = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7397 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7398 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7399 | return -1; |
| 7400 | |
| 7401 | return p2p_reject(wpa_s->global->p2p, addr); |
| 7402 | } |
| 7403 | |
| 7404 | |
| 7405 | /* Invite to reinvoke a persistent group */ |
| 7406 | 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] | 7407 | struct wpa_ssid *ssid, const u8 *go_dev_addr, int freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7408 | int vht_center_freq2, int ht40, int vht, int max_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7409 | int pref_freq, int he, int edmg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7410 | { |
| 7411 | enum p2p_invite_role role; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7412 | u8 *bssid = NULL; |
| 7413 | int force_freq = 0; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7414 | int res; |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 7415 | int no_pref_freq_given = pref_freq == 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7416 | unsigned int pref_freq_list[P2P_MAX_PREF_CHANNELS], size; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7417 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7418 | wpa_s->global->p2p_invite_group = NULL; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7419 | if (peer_addr) |
| 7420 | os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN); |
| 7421 | else |
| 7422 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7423 | |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 7424 | wpa_s->p2p_persistent_go_freq = freq; |
| 7425 | wpa_s->p2p_go_ht40 = !!ht40; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7426 | wpa_s->p2p_go_vht = !!vht; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7427 | wpa_s->p2p_go_he = !!he; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7428 | wpa_s->p2p_go_max_oper_chwidth = max_chwidth; |
| 7429 | wpa_s->p2p_go_vht_center_freq2 = vht_center_freq2; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7430 | wpa_s->p2p_go_edmg = !!edmg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7431 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 7432 | role = P2P_INVITE_ROLE_GO; |
| 7433 | if (peer_addr == NULL) { |
| 7434 | wpa_printf(MSG_DEBUG, "P2P: Missing peer " |
| 7435 | "address in invitation command"); |
| 7436 | return -1; |
| 7437 | } |
| 7438 | if (wpas_p2p_create_iface(wpa_s)) { |
| 7439 | if (wpas_p2p_add_group_interface(wpa_s, |
| 7440 | WPA_IF_P2P_GO) < 0) { |
| 7441 | wpa_printf(MSG_ERROR, "P2P: Failed to " |
| 7442 | "allocate a new interface for the " |
| 7443 | "group"); |
| 7444 | return -1; |
| 7445 | } |
| 7446 | bssid = wpa_s->pending_interface_addr; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7447 | } else if (wpa_s->p2p_mgmt) |
| 7448 | bssid = wpa_s->parent->own_addr; |
| 7449 | else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7450 | bssid = wpa_s->own_addr; |
| 7451 | } else { |
| 7452 | role = P2P_INVITE_ROLE_CLIENT; |
| 7453 | peer_addr = ssid->bssid; |
| 7454 | } |
| 7455 | wpa_s->pending_invite_ssid_id = ssid->id; |
| 7456 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7457 | size = P2P_MAX_PREF_CHANNELS; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7458 | res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7459 | role == P2P_INVITE_ROLE_GO, |
| 7460 | pref_freq_list, &size); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7461 | if (res) |
| 7462 | return res; |
Irfan Sheriff | af84a57 | 2012-09-22 16:59:30 -0700 | [diff] [blame] | 7463 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7464 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7465 | return -1; |
| 7466 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7467 | p2p_set_own_pref_freq_list(wpa_s->global->p2p, pref_freq_list, size); |
| 7468 | |
Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 7469 | if (wpa_s->parent->conf->p2p_ignore_shared_freq && |
| 7470 | no_pref_freq_given && pref_freq > 0 && |
| 7471 | wpa_s->num_multichan_concurrent > 1 && |
| 7472 | wpas_p2p_num_unused_channels(wpa_s) > 0) { |
| 7473 | wpa_printf(MSG_DEBUG, "P2P: Ignore own channel preference %d MHz for invitation due to p2p_ignore_shared_freq=1 configuration", |
| 7474 | pref_freq); |
| 7475 | pref_freq = 0; |
| 7476 | } |
| 7477 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7478 | /* |
| 7479 | * Stop any find/listen operations before invitation and possibly |
| 7480 | * connection establishment. |
| 7481 | */ |
| 7482 | wpas_p2p_stop_find_oper(wpa_s); |
| 7483 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7484 | return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid, |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7485 | ssid->ssid, ssid->ssid_len, force_freq, go_dev_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7486 | 1, pref_freq, -1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7487 | } |
| 7488 | |
| 7489 | |
| 7490 | /* Invite to join an active group */ |
| 7491 | int wpas_p2p_invite_group(struct wpa_supplicant *wpa_s, const char *ifname, |
| 7492 | const u8 *peer_addr, const u8 *go_dev_addr) |
| 7493 | { |
| 7494 | struct wpa_global *global = wpa_s->global; |
| 7495 | enum p2p_invite_role role; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7496 | u8 *bssid = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7497 | struct wpa_ssid *ssid; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7498 | int persistent; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7499 | int freq = 0, force_freq = 0, pref_freq = 0; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7500 | int res; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7501 | unsigned int pref_freq_list[P2P_MAX_PREF_CHANNELS], size; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7502 | |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 7503 | wpa_s->p2p_persistent_go_freq = 0; |
| 7504 | wpa_s->p2p_go_ht40 = 0; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7505 | wpa_s->p2p_go_vht = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7506 | wpa_s->p2p_go_vht_center_freq2 = 0; |
| 7507 | wpa_s->p2p_go_max_oper_chwidth = 0; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7508 | wpa_s->p2p_go_edmg = 0; |
Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 7509 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7510 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 7511 | if (os_strcmp(wpa_s->ifname, ifname) == 0) |
| 7512 | break; |
| 7513 | } |
| 7514 | if (wpa_s == NULL) { |
| 7515 | wpa_printf(MSG_DEBUG, "P2P: Interface '%s' not found", ifname); |
| 7516 | return -1; |
| 7517 | } |
| 7518 | |
| 7519 | ssid = wpa_s->current_ssid; |
| 7520 | if (ssid == NULL) { |
| 7521 | wpa_printf(MSG_DEBUG, "P2P: No current SSID to use for " |
| 7522 | "invitation"); |
| 7523 | return -1; |
| 7524 | } |
| 7525 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7526 | wpa_s->global->p2p_invite_group = wpa_s; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7527 | persistent = ssid->p2p_persistent_group && |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7528 | wpas_p2p_get_persistent(wpa_s->p2pdev, peer_addr, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7529 | ssid->ssid, ssid->ssid_len); |
| 7530 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7531 | if (ssid->mode == WPAS_MODE_P2P_GO) { |
| 7532 | role = P2P_INVITE_ROLE_ACTIVE_GO; |
| 7533 | bssid = wpa_s->own_addr; |
| 7534 | if (go_dev_addr == NULL) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7535 | go_dev_addr = wpa_s->global->p2p_dev_addr; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7536 | freq = ssid->frequency; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7537 | } else { |
| 7538 | role = P2P_INVITE_ROLE_CLIENT; |
| 7539 | if (wpa_s->wpa_state < WPA_ASSOCIATED) { |
| 7540 | wpa_printf(MSG_DEBUG, "P2P: Not associated - cannot " |
| 7541 | "invite to current group"); |
| 7542 | return -1; |
| 7543 | } |
| 7544 | bssid = wpa_s->bssid; |
| 7545 | if (go_dev_addr == NULL && |
| 7546 | !is_zero_ether_addr(wpa_s->go_dev_addr)) |
| 7547 | go_dev_addr = wpa_s->go_dev_addr; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7548 | freq = wpa_s->current_bss ? wpa_s->current_bss->freq : |
| 7549 | (int) wpa_s->assoc_freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7550 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7551 | wpa_s->p2pdev->pending_invite_ssid_id = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7552 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7553 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7554 | return -1; |
| 7555 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7556 | size = P2P_MAX_PREF_CHANNELS; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7557 | res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7558 | role == P2P_INVITE_ROLE_ACTIVE_GO, |
| 7559 | pref_freq_list, &size); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7560 | if (res) |
| 7561 | return res; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7562 | wpas_p2p_set_own_freq_preference(wpa_s, force_freq); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7563 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7564 | return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid, |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7565 | ssid->ssid, ssid->ssid_len, force_freq, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7566 | go_dev_addr, persistent, pref_freq, -1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7567 | } |
| 7568 | |
| 7569 | |
| 7570 | void wpas_p2p_completed(struct wpa_supplicant *wpa_s) |
| 7571 | { |
| 7572 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7573 | u8 go_dev_addr[ETH_ALEN]; |
| 7574 | int persistent; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7575 | int freq; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 7576 | u8 ip[3 * 4], *ip_ptr = NULL; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7577 | char ip_addr[100]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7578 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7579 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION) { |
| 7580 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7581 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7582 | } |
| 7583 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7584 | if (!wpa_s->show_group_started || !ssid) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7585 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7586 | |
| 7587 | wpa_s->show_group_started = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7588 | if (!wpa_s->p2p_go_group_formation_completed && |
| 7589 | wpa_s->global->p2p_group_formation == wpa_s) { |
| 7590 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 7591 | "P2P: Marking group formation completed on client on data connection"); |
| 7592 | wpa_s->p2p_go_group_formation_completed = 1; |
| 7593 | wpa_s->global->p2p_group_formation = NULL; |
| 7594 | wpa_s->p2p_in_provisioning = 0; |
| 7595 | wpa_s->p2p_in_invitation = 0; |
| 7596 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7597 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7598 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 7599 | if (ssid->bssid_set) |
| 7600 | os_memcpy(go_dev_addr, ssid->bssid, ETH_ALEN); |
| 7601 | persistent = wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid, |
| 7602 | ssid->ssid_len); |
| 7603 | os_memcpy(wpa_s->go_dev_addr, go_dev_addr, ETH_ALEN); |
| 7604 | |
| 7605 | if (wpa_s->global->p2p_group_formation == wpa_s) |
| 7606 | wpa_s->global->p2p_group_formation = NULL; |
| 7607 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7608 | freq = wpa_s->current_bss ? wpa_s->current_bss->freq : |
| 7609 | (int) wpa_s->assoc_freq; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7610 | |
| 7611 | ip_addr[0] = '\0'; |
| 7612 | if (wpa_sm_get_p2p_ip_addr(wpa_s->wpa, ip) == 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7613 | int res; |
| 7614 | |
| 7615 | res = os_snprintf(ip_addr, sizeof(ip_addr), |
| 7616 | " ip_addr=%u.%u.%u.%u " |
| 7617 | "ip_mask=%u.%u.%u.%u go_ip_addr=%u.%u.%u.%u", |
| 7618 | ip[0], ip[1], ip[2], ip[3], |
| 7619 | ip[4], ip[5], ip[6], ip[7], |
| 7620 | ip[8], ip[9], ip[10], ip[11]); |
| 7621 | if (os_snprintf_error(sizeof(ip_addr), res)) |
| 7622 | ip_addr[0] = '\0'; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 7623 | ip_ptr = ip; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7624 | } |
| 7625 | |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 7626 | wpas_p2p_group_started(wpa_s, 0, ssid, freq, |
| 7627 | ssid->passphrase == NULL && ssid->psk_set ? |
| 7628 | ssid->psk : NULL, |
| 7629 | ssid->passphrase, go_dev_addr, persistent, |
| 7630 | ip_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7631 | |
| 7632 | if (persistent) |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 7633 | wpas_p2p_store_persistent_group(wpa_s->p2pdev, |
| 7634 | ssid, go_dev_addr); |
| 7635 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 7636 | wpas_notify_p2p_group_started(wpa_s, ssid, persistent, 1, ip_ptr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7637 | } |
| 7638 | |
| 7639 | |
| 7640 | int wpas_p2p_presence_req(struct wpa_supplicant *wpa_s, u32 duration1, |
| 7641 | u32 interval1, u32 duration2, u32 interval2) |
| 7642 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7643 | int ret; |
| 7644 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7645 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7646 | return -1; |
| 7647 | |
| 7648 | if (wpa_s->wpa_state < WPA_ASSOCIATED || |
| 7649 | wpa_s->current_ssid == NULL || |
| 7650 | wpa_s->current_ssid->mode != WPAS_MODE_INFRA) |
| 7651 | return -1; |
| 7652 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7653 | ret = p2p_presence_req(wpa_s->global->p2p, wpa_s->bssid, |
| 7654 | wpa_s->own_addr, wpa_s->assoc_freq, |
| 7655 | duration1, interval1, duration2, interval2); |
| 7656 | if (ret == 0) |
| 7657 | wpa_s->waiting_presence_resp = 1; |
| 7658 | |
| 7659 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7660 | } |
| 7661 | |
| 7662 | |
| 7663 | int wpas_p2p_ext_listen(struct wpa_supplicant *wpa_s, unsigned int period, |
| 7664 | unsigned int interval) |
| 7665 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7666 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7667 | return -1; |
| 7668 | |
| 7669 | return p2p_ext_listen(wpa_s->global->p2p, period, interval); |
| 7670 | } |
| 7671 | |
| 7672 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7673 | static int wpas_p2p_is_client(struct wpa_supplicant *wpa_s) |
| 7674 | { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7675 | if (wpa_s->current_ssid == NULL) { |
| 7676 | /* |
| 7677 | * current_ssid can be cleared when P2P client interface gets |
| 7678 | * disconnected, so assume this interface was used as P2P |
| 7679 | * client. |
| 7680 | */ |
| 7681 | return 1; |
| 7682 | } |
| 7683 | return wpa_s->current_ssid->p2p_group && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7684 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA; |
| 7685 | } |
| 7686 | |
| 7687 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7688 | static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx) |
| 7689 | { |
| 7690 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 7691 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7692 | 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] | 7693 | wpa_printf(MSG_DEBUG, "P2P: Ignore group idle timeout - " |
| 7694 | "disabled"); |
| 7695 | return; |
| 7696 | } |
| 7697 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7698 | wpa_printf(MSG_DEBUG, "P2P: Group idle timeout reached - terminate " |
| 7699 | "group"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7700 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_IDLE_TIMEOUT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7701 | } |
| 7702 | |
| 7703 | |
| 7704 | static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s) |
| 7705 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7706 | int timeout; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7707 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7708 | if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0) |
| 7709 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout"); |
| 7710 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7711 | if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group) |
| 7712 | return; |
| 7713 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7714 | timeout = wpa_s->conf->p2p_group_idle; |
| 7715 | if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA && |
| 7716 | (timeout == 0 || timeout > P2P_MAX_CLIENT_IDLE)) |
| 7717 | timeout = P2P_MAX_CLIENT_IDLE; |
| 7718 | |
| 7719 | if (timeout == 0) |
| 7720 | return; |
| 7721 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7722 | if (timeout < 0) { |
| 7723 | if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA) |
| 7724 | timeout = 0; /* special client mode no-timeout */ |
| 7725 | else |
| 7726 | return; |
| 7727 | } |
| 7728 | |
| 7729 | if (wpa_s->p2p_in_provisioning) { |
| 7730 | /* |
| 7731 | * Use the normal group formation timeout during the |
| 7732 | * provisioning phase to avoid terminating this process too |
| 7733 | * early due to group idle timeout. |
| 7734 | */ |
| 7735 | wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout " |
| 7736 | "during provisioning"); |
| 7737 | return; |
| 7738 | } |
Deepthi Gowri | 9e4e8ac | 2013-04-16 11:57:05 +0530 | [diff] [blame] | 7739 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7740 | if (wpa_s->show_group_started) { |
| 7741 | /* |
| 7742 | * Use the normal group formation timeout between the end of |
| 7743 | * the provisioning phase and completion of 4-way handshake to |
| 7744 | * avoid terminating this process too early due to group idle |
| 7745 | * timeout. |
| 7746 | */ |
| 7747 | wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout " |
| 7748 | "while waiting for initial 4-way handshake to " |
| 7749 | "complete"); |
| 7750 | return; |
| 7751 | } |
| 7752 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7753 | 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] | 7754 | timeout); |
| 7755 | eloop_register_timeout(timeout, 0, wpas_p2p_group_idle_timeout, |
| 7756 | wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7757 | } |
| 7758 | |
| 7759 | |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 7760 | /* Returns 1 if the interface was removed */ |
| 7761 | int wpas_p2p_deauth_notif(struct wpa_supplicant *wpa_s, const u8 *bssid, |
| 7762 | u16 reason_code, const u8 *ie, size_t ie_len, |
| 7763 | int locally_generated) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7764 | { |
| 7765 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 7766 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7767 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7768 | if (!locally_generated) |
| 7769 | p2p_deauth_notif(wpa_s->global->p2p, bssid, reason_code, ie, |
| 7770 | ie_len); |
| 7771 | |
| 7772 | if (reason_code == WLAN_REASON_DEAUTH_LEAVING && !locally_generated && |
| 7773 | wpa_s->current_ssid && |
| 7774 | wpa_s->current_ssid->p2p_group && |
| 7775 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA) { |
| 7776 | wpa_printf(MSG_DEBUG, "P2P: GO indicated that the P2P Group " |
| 7777 | "session is ending"); |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 7778 | if (wpas_p2p_group_delete(wpa_s, |
| 7779 | P2P_GROUP_REMOVAL_GO_ENDING_SESSION) |
| 7780 | > 0) |
| 7781 | return 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7782 | } |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 7783 | |
| 7784 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7785 | } |
| 7786 | |
| 7787 | |
| 7788 | 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] | 7789 | u16 reason_code, const u8 *ie, size_t ie_len, |
| 7790 | int locally_generated) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7791 | { |
| 7792 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7793 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7794 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7795 | if (!locally_generated) |
| 7796 | p2p_disassoc_notif(wpa_s->global->p2p, bssid, reason_code, ie, |
| 7797 | ie_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7798 | } |
| 7799 | |
| 7800 | |
| 7801 | void wpas_p2p_update_config(struct wpa_supplicant *wpa_s) |
| 7802 | { |
| 7803 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 7804 | |
| 7805 | if (p2p == NULL) |
| 7806 | return; |
| 7807 | |
| 7808 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE)) |
| 7809 | return; |
| 7810 | |
| 7811 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_NAME) |
| 7812 | p2p_set_dev_name(p2p, wpa_s->conf->device_name); |
| 7813 | |
| 7814 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_TYPE) |
| 7815 | p2p_set_pri_dev_type(p2p, wpa_s->conf->device_type); |
| 7816 | |
| 7817 | if (wpa_s->wps && |
| 7818 | (wpa_s->conf->changed_parameters & CFG_CHANGED_CONFIG_METHODS)) |
| 7819 | p2p_set_config_methods(p2p, wpa_s->wps->config_methods); |
| 7820 | |
| 7821 | if (wpa_s->wps && (wpa_s->conf->changed_parameters & CFG_CHANGED_UUID)) |
| 7822 | p2p_set_uuid(p2p, wpa_s->wps->uuid); |
| 7823 | |
| 7824 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_WPS_STRING) { |
| 7825 | p2p_set_manufacturer(p2p, wpa_s->conf->manufacturer); |
| 7826 | p2p_set_model_name(p2p, wpa_s->conf->model_name); |
| 7827 | p2p_set_model_number(p2p, wpa_s->conf->model_number); |
| 7828 | p2p_set_serial_number(p2p, wpa_s->conf->serial_number); |
| 7829 | } |
| 7830 | |
| 7831 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_SEC_DEVICE_TYPE) |
| 7832 | p2p_set_sec_dev_types(p2p, |
| 7833 | (void *) wpa_s->conf->sec_device_type, |
| 7834 | wpa_s->conf->num_sec_device_types); |
| 7835 | |
| 7836 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_VENDOR_EXTENSION) { |
| 7837 | int i; |
| 7838 | p2p_remove_wps_vendor_extensions(p2p); |
| 7839 | for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) { |
| 7840 | if (wpa_s->conf->wps_vendor_ext[i] == NULL) |
| 7841 | continue; |
| 7842 | p2p_add_wps_vendor_extension( |
| 7843 | p2p, wpa_s->conf->wps_vendor_ext[i]); |
| 7844 | } |
| 7845 | } |
| 7846 | |
| 7847 | if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) && |
| 7848 | wpa_s->conf->country[0] && wpa_s->conf->country[1]) { |
| 7849 | char country[3]; |
| 7850 | country[0] = wpa_s->conf->country[0]; |
| 7851 | country[1] = wpa_s->conf->country[1]; |
| 7852 | country[2] = 0x04; |
| 7853 | p2p_set_country(p2p, country); |
| 7854 | } |
| 7855 | |
| 7856 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_SSID_POSTFIX) { |
| 7857 | p2p_set_ssid_postfix(p2p, (u8 *) wpa_s->conf->p2p_ssid_postfix, |
| 7858 | wpa_s->conf->p2p_ssid_postfix ? |
| 7859 | os_strlen(wpa_s->conf->p2p_ssid_postfix) : |
| 7860 | 0); |
| 7861 | } |
| 7862 | |
| 7863 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_INTRA_BSS) |
| 7864 | p2p_set_intra_bss_dist(p2p, wpa_s->conf->p2p_intra_bss); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7865 | |
| 7866 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_LISTEN_CHANNEL) { |
| 7867 | u8 reg_class, channel; |
| 7868 | int ret; |
| 7869 | unsigned int r; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7870 | u8 channel_forced; |
| 7871 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7872 | if (wpa_s->conf->p2p_listen_reg_class && |
| 7873 | wpa_s->conf->p2p_listen_channel) { |
| 7874 | reg_class = wpa_s->conf->p2p_listen_reg_class; |
| 7875 | channel = wpa_s->conf->p2p_listen_channel; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7876 | channel_forced = 1; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7877 | } else { |
| 7878 | reg_class = 81; |
| 7879 | /* |
| 7880 | * Pick one of the social channels randomly as the |
| 7881 | * listen channel. |
| 7882 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7883 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 7884 | channel = 1; |
| 7885 | else |
| 7886 | channel = 1 + (r % 3) * 5; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7887 | channel_forced = 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7888 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7889 | ret = p2p_set_listen_channel(p2p, reg_class, channel, |
| 7890 | channel_forced); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7891 | if (ret) |
| 7892 | wpa_printf(MSG_ERROR, "P2P: Own listen channel update " |
| 7893 | "failed: %d", ret); |
| 7894 | } |
| 7895 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_OPER_CHANNEL) { |
| 7896 | u8 op_reg_class, op_channel, cfg_op_channel; |
| 7897 | int ret = 0; |
| 7898 | unsigned int r; |
| 7899 | if (wpa_s->conf->p2p_oper_reg_class && |
| 7900 | wpa_s->conf->p2p_oper_channel) { |
| 7901 | op_reg_class = wpa_s->conf->p2p_oper_reg_class; |
| 7902 | op_channel = wpa_s->conf->p2p_oper_channel; |
| 7903 | cfg_op_channel = 1; |
| 7904 | } else { |
| 7905 | op_reg_class = 81; |
| 7906 | /* |
| 7907 | * Use random operation channel from (1, 6, 11) |
| 7908 | *if no other preference is indicated. |
| 7909 | */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7910 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) |
| 7911 | op_channel = 1; |
| 7912 | else |
| 7913 | op_channel = 1 + (r % 3) * 5; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7914 | cfg_op_channel = 0; |
| 7915 | } |
| 7916 | ret = p2p_set_oper_channel(p2p, op_reg_class, op_channel, |
| 7917 | cfg_op_channel); |
| 7918 | if (ret) |
| 7919 | wpa_printf(MSG_ERROR, "P2P: Own oper channel update " |
| 7920 | "failed: %d", ret); |
| 7921 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7922 | |
| 7923 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PREF_CHAN) { |
| 7924 | if (p2p_set_pref_chan(p2p, wpa_s->conf->num_p2p_pref_chan, |
| 7925 | wpa_s->conf->p2p_pref_chan) < 0) { |
| 7926 | wpa_printf(MSG_ERROR, "P2P: Preferred channel list " |
| 7927 | "update failed"); |
| 7928 | } |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7929 | |
| 7930 | if (p2p_set_no_go_freq(p2p, &wpa_s->conf->p2p_no_go_freq) < 0) { |
| 7931 | wpa_printf(MSG_ERROR, "P2P: No GO channel list " |
| 7932 | "update failed"); |
| 7933 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7934 | } |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 7935 | |
| 7936 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PASSPHRASE_LEN) |
| 7937 | p2p_set_passphrase_len(p2p, wpa_s->conf->p2p_passphrase_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7938 | } |
| 7939 | |
| 7940 | |
| 7941 | int wpas_p2p_set_noa(struct wpa_supplicant *wpa_s, u8 count, int start, |
| 7942 | int duration) |
| 7943 | { |
| 7944 | if (!wpa_s->ap_iface) |
| 7945 | return -1; |
| 7946 | return hostapd_p2p_set_noa(wpa_s->ap_iface->bss[0], count, start, |
| 7947 | duration); |
| 7948 | } |
| 7949 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7950 | |
| 7951 | int wpas_p2p_set_cross_connect(struct wpa_supplicant *wpa_s, int enabled) |
| 7952 | { |
| 7953 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 7954 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7955 | |
| 7956 | wpa_s->global->cross_connection = enabled; |
| 7957 | p2p_set_cross_connect(wpa_s->global->p2p, enabled); |
| 7958 | |
| 7959 | if (!enabled) { |
| 7960 | struct wpa_supplicant *iface; |
| 7961 | |
| 7962 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) |
| 7963 | { |
| 7964 | if (iface->cross_connect_enabled == 0) |
| 7965 | continue; |
| 7966 | |
| 7967 | iface->cross_connect_enabled = 0; |
| 7968 | iface->cross_connect_in_use = 0; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7969 | wpa_msg_global(iface->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 7970 | P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s", |
| 7971 | iface->ifname, |
| 7972 | iface->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7973 | } |
| 7974 | } |
| 7975 | |
| 7976 | return 0; |
| 7977 | } |
| 7978 | |
| 7979 | |
| 7980 | static void wpas_p2p_enable_cross_connect(struct wpa_supplicant *uplink) |
| 7981 | { |
| 7982 | struct wpa_supplicant *iface; |
| 7983 | |
| 7984 | if (!uplink->global->cross_connection) |
| 7985 | return; |
| 7986 | |
| 7987 | for (iface = uplink->global->ifaces; iface; iface = iface->next) { |
| 7988 | if (!iface->cross_connect_enabled) |
| 7989 | continue; |
| 7990 | if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) != |
| 7991 | 0) |
| 7992 | continue; |
| 7993 | if (iface->ap_iface == NULL) |
| 7994 | continue; |
| 7995 | if (iface->cross_connect_in_use) |
| 7996 | continue; |
| 7997 | |
| 7998 | iface->cross_connect_in_use = 1; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7999 | wpa_msg_global(iface->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8000 | P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s", |
| 8001 | iface->ifname, iface->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8002 | } |
| 8003 | } |
| 8004 | |
| 8005 | |
| 8006 | static void wpas_p2p_disable_cross_connect(struct wpa_supplicant *uplink) |
| 8007 | { |
| 8008 | struct wpa_supplicant *iface; |
| 8009 | |
| 8010 | for (iface = uplink->global->ifaces; iface; iface = iface->next) { |
| 8011 | if (!iface->cross_connect_enabled) |
| 8012 | continue; |
| 8013 | if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) != |
| 8014 | 0) |
| 8015 | continue; |
| 8016 | if (!iface->cross_connect_in_use) |
| 8017 | continue; |
| 8018 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8019 | wpa_msg_global(iface->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8020 | P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s", |
| 8021 | iface->ifname, iface->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8022 | iface->cross_connect_in_use = 0; |
| 8023 | } |
| 8024 | } |
| 8025 | |
| 8026 | |
| 8027 | void wpas_p2p_notif_connected(struct wpa_supplicant *wpa_s) |
| 8028 | { |
| 8029 | if (wpa_s->ap_iface || wpa_s->current_ssid == NULL || |
| 8030 | wpa_s->current_ssid->mode != WPAS_MODE_INFRA || |
| 8031 | wpa_s->cross_connect_disallowed) |
| 8032 | wpas_p2p_disable_cross_connect(wpa_s); |
| 8033 | else |
| 8034 | wpas_p2p_enable_cross_connect(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8035 | if (!wpa_s->ap_iface && |
| 8036 | eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0) |
| 8037 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8038 | } |
| 8039 | |
| 8040 | |
| 8041 | void wpas_p2p_notif_disconnected(struct wpa_supplicant *wpa_s) |
| 8042 | { |
| 8043 | wpas_p2p_disable_cross_connect(wpa_s); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8044 | if (!wpa_s->ap_iface && |
| 8045 | !eloop_is_timeout_registered(wpas_p2p_group_idle_timeout, |
| 8046 | wpa_s, NULL)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8047 | wpas_p2p_set_group_idle_timeout(wpa_s); |
| 8048 | } |
| 8049 | |
| 8050 | |
| 8051 | static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s) |
| 8052 | { |
| 8053 | struct wpa_supplicant *iface; |
| 8054 | |
| 8055 | if (!wpa_s->global->cross_connection) |
| 8056 | return; |
| 8057 | |
| 8058 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 8059 | if (iface == wpa_s) |
| 8060 | continue; |
| 8061 | if (iface->drv_flags & |
| 8062 | WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE) |
| 8063 | continue; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8064 | if ((iface->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) && |
| 8065 | iface != wpa_s->parent) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8066 | continue; |
| 8067 | |
| 8068 | wpa_s->cross_connect_enabled = 1; |
| 8069 | os_strlcpy(wpa_s->cross_connect_uplink, iface->ifname, |
| 8070 | sizeof(wpa_s->cross_connect_uplink)); |
| 8071 | wpa_printf(MSG_DEBUG, "P2P: Enable cross connection from " |
| 8072 | "%s to %s whenever uplink is available", |
| 8073 | wpa_s->ifname, wpa_s->cross_connect_uplink); |
| 8074 | |
| 8075 | if (iface->ap_iface || iface->current_ssid == NULL || |
| 8076 | iface->current_ssid->mode != WPAS_MODE_INFRA || |
| 8077 | iface->cross_connect_disallowed || |
| 8078 | iface->wpa_state != WPA_COMPLETED) |
| 8079 | break; |
| 8080 | |
| 8081 | wpa_s->cross_connect_in_use = 1; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8082 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8083 | P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s", |
| 8084 | wpa_s->ifname, wpa_s->cross_connect_uplink); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8085 | break; |
| 8086 | } |
| 8087 | } |
| 8088 | |
| 8089 | |
| 8090 | int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant *wpa_s) |
| 8091 | { |
| 8092 | if (wpa_s->p2p_group_interface != P2P_GROUP_INTERFACE_CLIENT && |
| 8093 | !wpa_s->p2p_in_provisioning) |
| 8094 | return 0; /* not P2P client operation */ |
| 8095 | |
| 8096 | wpa_printf(MSG_DEBUG, "P2P: Terminate connection due to WPS PBC " |
| 8097 | "session overlap"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8098 | if (wpa_s != wpa_s->p2pdev) |
| 8099 | wpa_msg_ctrl(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_OVERLAP); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8100 | wpas_p2p_group_formation_failed(wpa_s, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8101 | return 1; |
| 8102 | } |
| 8103 | |
| 8104 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8105 | void wpas_p2p_pbc_overlap_cb(void *eloop_ctx, void *timeout_ctx) |
| 8106 | { |
| 8107 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 8108 | wpas_p2p_notif_pbc_overlap(wpa_s); |
| 8109 | } |
| 8110 | |
| 8111 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8112 | void wpas_p2p_update_channel_list(struct wpa_supplicant *wpa_s, |
| 8113 | enum wpas_p2p_channel_update_trig trig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8114 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8115 | struct p2p_channels chan, cli_chan; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8116 | struct wpa_used_freq_data *freqs = NULL; |
| 8117 | unsigned int num = wpa_s->num_multichan_concurrent; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8118 | |
| 8119 | if (wpa_s->global == NULL || wpa_s->global->p2p == NULL) |
| 8120 | return; |
| 8121 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8122 | freqs = os_calloc(num, sizeof(struct wpa_used_freq_data)); |
| 8123 | if (!freqs) |
| 8124 | return; |
| 8125 | |
| 8126 | num = get_shared_radio_freqs_data(wpa_s, freqs, num); |
| 8127 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8128 | os_memset(&chan, 0, sizeof(chan)); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8129 | os_memset(&cli_chan, 0, sizeof(cli_chan)); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8130 | if (wpas_p2p_setup_channels(wpa_s, &chan, &cli_chan, |
| 8131 | is_p2p_6ghz_disabled(wpa_s->global->p2p))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8132 | wpa_printf(MSG_ERROR, "P2P: Failed to update supported " |
| 8133 | "channel list"); |
| 8134 | return; |
| 8135 | } |
| 8136 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8137 | p2p_update_channel_list(wpa_s->global->p2p, &chan, &cli_chan); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 8138 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8139 | wpas_p2p_optimize_listen_channel(wpa_s, freqs, num); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 8140 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8141 | /* |
| 8142 | * The used frequencies map changed, so it is possible that a GO is |
| 8143 | * using a channel that is no longer valid for P2P use. It is also |
| 8144 | * possible that due to policy consideration, it would be preferable to |
| 8145 | * move it to a frequency already used by other station interfaces. |
| 8146 | */ |
| 8147 | wpas_p2p_consider_moving_gos(wpa_s, freqs, num, trig); |
| 8148 | |
| 8149 | os_free(freqs); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8150 | } |
| 8151 | |
| 8152 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8153 | static void wpas_p2p_scan_res_ignore(struct wpa_supplicant *wpa_s, |
| 8154 | struct wpa_scan_results *scan_res) |
| 8155 | { |
| 8156 | wpa_printf(MSG_DEBUG, "P2P: Ignore scan results"); |
| 8157 | } |
| 8158 | |
| 8159 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8160 | int wpas_p2p_cancel(struct wpa_supplicant *wpa_s) |
| 8161 | { |
| 8162 | struct wpa_global *global = wpa_s->global; |
| 8163 | int found = 0; |
| 8164 | const u8 *peer; |
| 8165 | |
| 8166 | if (global->p2p == NULL) |
| 8167 | return -1; |
| 8168 | |
| 8169 | wpa_printf(MSG_DEBUG, "P2P: Request to cancel group formation"); |
| 8170 | |
| 8171 | if (wpa_s->pending_interface_name[0] && |
| 8172 | !is_zero_ether_addr(wpa_s->pending_interface_addr)) |
| 8173 | found = 1; |
| 8174 | |
| 8175 | peer = p2p_get_go_neg_peer(global->p2p); |
| 8176 | if (peer) { |
| 8177 | wpa_printf(MSG_DEBUG, "P2P: Unauthorize pending GO Neg peer " |
| 8178 | MACSTR, MAC2STR(peer)); |
| 8179 | p2p_unauthorize(global->p2p, peer); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8180 | found = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8181 | } |
| 8182 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8183 | if (wpa_s->scan_res_handler == wpas_p2p_scan_res_join) { |
| 8184 | wpa_printf(MSG_DEBUG, "P2P: Stop pending scan for join"); |
| 8185 | wpa_s->scan_res_handler = wpas_p2p_scan_res_ignore; |
| 8186 | found = 1; |
| 8187 | } |
| 8188 | |
| 8189 | if (wpa_s->pending_pd_before_join) { |
| 8190 | wpa_printf(MSG_DEBUG, "P2P: Stop pending PD before join"); |
| 8191 | wpa_s->pending_pd_before_join = 0; |
| 8192 | found = 1; |
| 8193 | } |
| 8194 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8195 | wpas_p2p_stop_find(wpa_s); |
| 8196 | |
| 8197 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 8198 | if (wpa_s == global->p2p_group_formation && |
| 8199 | (wpa_s->p2p_in_provisioning || |
| 8200 | wpa_s->parent->pending_interface_type == |
| 8201 | WPA_IF_P2P_CLIENT)) { |
| 8202 | wpa_printf(MSG_DEBUG, "P2P: Interface %s in group " |
| 8203 | "formation found - cancelling", |
| 8204 | wpa_s->ifname); |
| 8205 | found = 1; |
| 8206 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8207 | wpa_s->p2pdev, NULL); |
Jouni Malinen | adddfc4 | 2012-10-03 14:31:41 -0700 | [diff] [blame] | 8208 | if (wpa_s->p2p_in_provisioning) { |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8209 | wpas_group_formation_completed(wpa_s, 0, 0); |
Jouni Malinen | adddfc4 | 2012-10-03 14:31:41 -0700 | [diff] [blame] | 8210 | break; |
| 8211 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8212 | wpas_p2p_group_delete(wpa_s, |
| 8213 | P2P_GROUP_REMOVAL_REQUESTED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8214 | break; |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 8215 | } else if (wpa_s->p2p_in_invitation) { |
| 8216 | wpa_printf(MSG_DEBUG, "P2P: Interface %s in invitation found - cancelling", |
| 8217 | wpa_s->ifname); |
| 8218 | found = 1; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8219 | wpas_p2p_group_formation_failed(wpa_s, 0); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8220 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8221 | } |
| 8222 | } |
| 8223 | |
| 8224 | if (!found) { |
| 8225 | wpa_printf(MSG_DEBUG, "P2P: No ongoing group formation found"); |
| 8226 | return -1; |
| 8227 | } |
| 8228 | |
| 8229 | return 0; |
| 8230 | } |
| 8231 | |
| 8232 | |
| 8233 | void wpas_p2p_interface_unavailable(struct wpa_supplicant *wpa_s) |
| 8234 | { |
| 8235 | if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group) |
| 8236 | return; |
| 8237 | |
| 8238 | wpa_printf(MSG_DEBUG, "P2P: Remove group due to driver resource not " |
| 8239 | "being available anymore"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8240 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_UNAVAILABLE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8241 | } |
| 8242 | |
| 8243 | |
| 8244 | void wpas_p2p_update_best_channels(struct wpa_supplicant *wpa_s, |
| 8245 | int freq_24, int freq_5, int freq_overall) |
| 8246 | { |
| 8247 | struct p2p_data *p2p = wpa_s->global->p2p; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8248 | if (p2p == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8249 | return; |
| 8250 | p2p_set_best_channels(p2p, freq_24, freq_5, freq_overall); |
| 8251 | } |
| 8252 | |
| 8253 | |
| 8254 | int wpas_p2p_unauthorize(struct wpa_supplicant *wpa_s, const char *addr) |
| 8255 | { |
| 8256 | u8 peer[ETH_ALEN]; |
| 8257 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 8258 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8259 | if (p2p == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8260 | return -1; |
| 8261 | |
| 8262 | if (hwaddr_aton(addr, peer)) |
| 8263 | return -1; |
| 8264 | |
| 8265 | return p2p_unauthorize(p2p, peer); |
| 8266 | } |
| 8267 | |
| 8268 | |
| 8269 | /** |
| 8270 | * wpas_p2p_disconnect - Disconnect from a P2P Group |
| 8271 | * @wpa_s: Pointer to wpa_supplicant data |
| 8272 | * Returns: 0 on success, -1 on failure |
| 8273 | * |
| 8274 | * This can be used to disconnect from a group in which the local end is a P2P |
| 8275 | * Client or to end a P2P Group in case the local end is the Group Owner. If a |
| 8276 | * virtual network interface was created for this group, that interface will be |
| 8277 | * removed. Otherwise, only the configured P2P group network will be removed |
| 8278 | * from the interface. |
| 8279 | */ |
| 8280 | int wpas_p2p_disconnect(struct wpa_supplicant *wpa_s) |
| 8281 | { |
| 8282 | |
| 8283 | if (wpa_s == NULL) |
| 8284 | return -1; |
| 8285 | |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8286 | return wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_REQUESTED) < 0 ? |
| 8287 | -1 : 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8288 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8289 | |
| 8290 | |
| 8291 | int wpas_p2p_in_progress(struct wpa_supplicant *wpa_s) |
| 8292 | { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8293 | int ret; |
| 8294 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8295 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8296 | return 0; |
| 8297 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8298 | ret = p2p_in_progress(wpa_s->global->p2p); |
| 8299 | if (ret == 0) { |
| 8300 | /* |
| 8301 | * Check whether there is an ongoing WPS provisioning step (or |
| 8302 | * other parts of group formation) on another interface since |
| 8303 | * p2p_in_progress() does not report this to avoid issues for |
| 8304 | * scans during such provisioning step. |
| 8305 | */ |
| 8306 | if (wpa_s->global->p2p_group_formation && |
| 8307 | wpa_s->global->p2p_group_formation != wpa_s) { |
| 8308 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Another interface (%s) " |
| 8309 | "in group formation", |
| 8310 | wpa_s->global->p2p_group_formation->ifname); |
| 8311 | ret = 1; |
| 8312 | } |
| 8313 | } |
| 8314 | |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 8315 | if (!ret && wpa_s->global->p2p_go_wait_client.sec) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8316 | struct os_reltime now; |
| 8317 | os_get_reltime(&now); |
| 8318 | if (os_reltime_expired(&now, &wpa_s->global->p2p_go_wait_client, |
| 8319 | P2P_MAX_INITIAL_CONN_WAIT_GO)) { |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 8320 | /* Wait for the first client has expired */ |
| 8321 | wpa_s->global->p2p_go_wait_client.sec = 0; |
| 8322 | } else { |
| 8323 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Waiting for initial client connection during group formation"); |
| 8324 | ret = 1; |
| 8325 | } |
| 8326 | } |
| 8327 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8328 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8329 | } |
| 8330 | |
| 8331 | |
| 8332 | void wpas_p2p_network_removed(struct wpa_supplicant *wpa_s, |
| 8333 | struct wpa_ssid *ssid) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8334 | { |
| 8335 | if (wpa_s->p2p_in_provisioning && ssid->p2p_group && |
| 8336 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8337 | wpa_s->p2pdev, NULL) > 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8338 | /** |
| 8339 | * Remove the network by scheduling the group formation |
| 8340 | * timeout to happen immediately. The teardown code |
| 8341 | * needs to be scheduled to run asynch later so that we |
| 8342 | * don't delete data from under ourselves unexpectedly. |
| 8343 | * Calling wpas_p2p_group_formation_timeout directly |
| 8344 | * causes a series of crashes in WPS failure scenarios. |
| 8345 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8346 | wpa_printf(MSG_DEBUG, "P2P: Canceled group formation due to " |
| 8347 | "P2P group network getting removed"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8348 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8349 | wpa_s->p2pdev, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8350 | } |
| 8351 | } |
| 8352 | |
| 8353 | |
| 8354 | struct wpa_ssid * wpas_p2p_get_persistent(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8355 | const u8 *addr, const u8 *ssid, |
| 8356 | size_t ssid_len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8357 | { |
| 8358 | struct wpa_ssid *s; |
| 8359 | size_t i; |
| 8360 | |
| 8361 | for (s = wpa_s->conf->ssid; s; s = s->next) { |
| 8362 | if (s->disabled != 2) |
| 8363 | continue; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8364 | if (ssid && |
| 8365 | (ssid_len != s->ssid_len || |
| 8366 | os_memcmp(ssid, s->ssid, ssid_len) != 0)) |
| 8367 | continue; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8368 | if (addr == NULL) { |
| 8369 | if (s->mode == WPAS_MODE_P2P_GO) |
| 8370 | return s; |
| 8371 | continue; |
| 8372 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8373 | if (os_memcmp(s->bssid, addr, ETH_ALEN) == 0) |
| 8374 | return s; /* peer is GO in the persistent group */ |
| 8375 | if (s->mode != WPAS_MODE_P2P_GO || s->p2p_client_list == NULL) |
| 8376 | continue; |
| 8377 | for (i = 0; i < s->num_p2p_clients; i++) { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8378 | if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8379 | addr, ETH_ALEN) == 0) |
| 8380 | return s; /* peer is P2P client in persistent |
| 8381 | * group */ |
| 8382 | } |
| 8383 | } |
| 8384 | |
| 8385 | return NULL; |
| 8386 | } |
| 8387 | |
| 8388 | |
| 8389 | void wpas_p2p_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s, |
| 8390 | const u8 *addr) |
| 8391 | { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8392 | if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8393 | wpa_s->p2pdev, NULL) > 0) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8394 | /* |
| 8395 | * This can happen if WPS provisioning step is not terminated |
| 8396 | * cleanly (e.g., P2P Client does not send WSC_Done). Since the |
| 8397 | * peer was able to connect, there is no need to time out group |
| 8398 | * formation after this, though. In addition, this is used with |
| 8399 | * the initial connection wait on the GO as a separate formation |
| 8400 | * timeout and as such, expected to be hit after the initial WPS |
| 8401 | * provisioning step. |
| 8402 | */ |
| 8403 | 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] | 8404 | |
| 8405 | if (!wpa_s->p2p_go_group_formation_completed && |
| 8406 | !wpa_s->group_formation_reported) { |
| 8407 | /* |
| 8408 | * GO has not yet notified group formation success since |
| 8409 | * the WPS step was not completed cleanly. Do that |
| 8410 | * notification now since the P2P Client was able to |
| 8411 | * connect and as such, must have received the |
| 8412 | * credential from the WPS step. |
| 8413 | */ |
| 8414 | if (wpa_s->global->p2p) |
| 8415 | p2p_wps_success_cb(wpa_s->global->p2p, addr); |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8416 | wpas_group_formation_completed(wpa_s, 1, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8417 | } |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8418 | } |
| 8419 | if (!wpa_s->p2p_go_group_formation_completed) { |
| 8420 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Marking group formation completed on GO on first data connection"); |
| 8421 | wpa_s->p2p_go_group_formation_completed = 1; |
| 8422 | wpa_s->global->p2p_group_formation = NULL; |
| 8423 | wpa_s->p2p_in_provisioning = 0; |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 8424 | wpa_s->p2p_in_invitation = 0; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8425 | } |
Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 8426 | wpa_s->global->p2p_go_wait_client.sec = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8427 | if (addr == NULL) |
| 8428 | return; |
| 8429 | wpas_p2p_add_persistent_group_client(wpa_s, addr); |
| 8430 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8431 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8432 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8433 | static int wpas_p2p_fallback_to_go_neg(struct wpa_supplicant *wpa_s, |
| 8434 | int group_added) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8435 | { |
| 8436 | struct wpa_supplicant *group = wpa_s; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8437 | int ret = 0; |
| 8438 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8439 | if (wpa_s->global->p2p_group_formation) |
| 8440 | group = wpa_s->global->p2p_group_formation; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8441 | wpa_s = wpa_s->global->p2p_init_wpa_s; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8442 | offchannel_send_action_done(wpa_s); |
| 8443 | if (group_added) |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8444 | ret = wpas_p2p_group_delete(group, P2P_GROUP_REMOVAL_SILENT); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8445 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Fall back to GO Negotiation"); |
| 8446 | wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr, wpa_s->p2p_pin, |
| 8447 | wpa_s->p2p_wps_method, wpa_s->p2p_persistent_group, 0, |
| 8448 | 0, 0, wpa_s->p2p_go_intent, wpa_s->p2p_connect_freq, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8449 | wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8450 | wpa_s->p2p_persistent_id, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8451 | wpa_s->p2p_pd_before_go_neg, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8452 | wpa_s->p2p_go_ht40, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8453 | wpa_s->p2p_go_vht, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8454 | wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8455 | wpa_s->p2p_go_he, |
| 8456 | wpa_s->p2p_go_edmg, |
| 8457 | NULL, 0); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8458 | return ret; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8459 | } |
| 8460 | |
| 8461 | |
| 8462 | int wpas_p2p_scan_no_go_seen(struct wpa_supplicant *wpa_s) |
| 8463 | { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8464 | int res; |
| 8465 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8466 | if (!wpa_s->p2p_fallback_to_go_neg || |
| 8467 | wpa_s->p2p_in_provisioning <= 5) |
| 8468 | return 0; |
| 8469 | |
| 8470 | if (wpas_p2p_peer_go(wpa_s, wpa_s->pending_join_dev_addr) > 0) |
| 8471 | return 0; /* peer operating as a GO */ |
| 8472 | |
| 8473 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: GO not found for p2p_connect-auto - " |
| 8474 | "fallback to GO Negotiation"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8475 | 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] | 8476 | "reason=GO-not-found"); |
| 8477 | res = wpas_p2p_fallback_to_go_neg(wpa_s, 1); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8478 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8479 | return res == 1 ? 2 : 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8480 | } |
| 8481 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8482 | |
| 8483 | unsigned int wpas_p2p_search_delay(struct wpa_supplicant *wpa_s) |
| 8484 | { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8485 | struct wpa_supplicant *ifs; |
| 8486 | |
| 8487 | if (wpa_s->wpa_state > WPA_SCANNING) { |
| 8488 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search delay due to " |
| 8489 | "concurrent operation", |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 8490 | wpa_s->conf->p2p_search_delay); |
| 8491 | return wpa_s->conf->p2p_search_delay; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8492 | } |
| 8493 | |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 8494 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 8495 | radio_list) { |
| 8496 | if (ifs != wpa_s && ifs->wpa_state > WPA_SCANNING) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8497 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search " |
| 8498 | "delay due to concurrent operation on " |
| 8499 | "interface %s", |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 8500 | wpa_s->conf->p2p_search_delay, |
| 8501 | ifs->ifname); |
| 8502 | return wpa_s->conf->p2p_search_delay; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8503 | } |
| 8504 | } |
| 8505 | |
| 8506 | return 0; |
| 8507 | } |
| 8508 | |
Dmitry Shmidt | 37d4d6a | 2013-03-18 13:09:42 -0700 | [diff] [blame] | 8509 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8510 | static int wpas_p2p_remove_psk_entry(struct wpa_supplicant *wpa_s, |
| 8511 | struct wpa_ssid *s, const u8 *addr, |
| 8512 | int iface_addr) |
| 8513 | { |
| 8514 | struct psk_list_entry *psk, *tmp; |
| 8515 | int changed = 0; |
| 8516 | |
| 8517 | dl_list_for_each_safe(psk, tmp, &s->psk_list, struct psk_list_entry, |
| 8518 | list) { |
| 8519 | if ((iface_addr && !psk->p2p && |
| 8520 | os_memcmp(addr, psk->addr, ETH_ALEN) == 0) || |
| 8521 | (!iface_addr && psk->p2p && |
| 8522 | os_memcmp(addr, psk->addr, ETH_ALEN) == 0)) { |
| 8523 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 8524 | "P2P: Remove persistent group PSK list entry for " |
| 8525 | MACSTR " p2p=%u", |
| 8526 | MAC2STR(psk->addr), psk->p2p); |
| 8527 | dl_list_del(&psk->list); |
| 8528 | os_free(psk); |
| 8529 | changed++; |
| 8530 | } |
| 8531 | } |
| 8532 | |
| 8533 | return changed; |
| 8534 | } |
| 8535 | |
| 8536 | |
| 8537 | void wpas_p2p_new_psk_cb(struct wpa_supplicant *wpa_s, const u8 *mac_addr, |
| 8538 | const u8 *p2p_dev_addr, |
| 8539 | const u8 *psk, size_t psk_len) |
| 8540 | { |
| 8541 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 8542 | struct wpa_ssid *persistent; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 8543 | struct psk_list_entry *p, *last; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8544 | |
| 8545 | if (psk_len != sizeof(p->psk)) |
| 8546 | return; |
| 8547 | |
| 8548 | if (p2p_dev_addr) { |
| 8549 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New PSK for addr=" MACSTR |
| 8550 | " p2p_dev_addr=" MACSTR, |
| 8551 | MAC2STR(mac_addr), MAC2STR(p2p_dev_addr)); |
| 8552 | if (is_zero_ether_addr(p2p_dev_addr)) |
| 8553 | p2p_dev_addr = NULL; |
| 8554 | } else { |
| 8555 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New PSK for addr=" MACSTR, |
| 8556 | MAC2STR(mac_addr)); |
| 8557 | } |
| 8558 | |
| 8559 | if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) { |
| 8560 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: new_psk_cb during group formation"); |
| 8561 | /* To be added to persistent group once created */ |
| 8562 | if (wpa_s->global->add_psk == NULL) { |
| 8563 | wpa_s->global->add_psk = os_zalloc(sizeof(*p)); |
| 8564 | if (wpa_s->global->add_psk == NULL) |
| 8565 | return; |
| 8566 | } |
| 8567 | p = wpa_s->global->add_psk; |
| 8568 | if (p2p_dev_addr) { |
| 8569 | p->p2p = 1; |
| 8570 | os_memcpy(p->addr, p2p_dev_addr, ETH_ALEN); |
| 8571 | } else { |
| 8572 | p->p2p = 0; |
| 8573 | os_memcpy(p->addr, mac_addr, ETH_ALEN); |
| 8574 | } |
| 8575 | os_memcpy(p->psk, psk, psk_len); |
| 8576 | return; |
| 8577 | } |
| 8578 | |
| 8579 | if (ssid->mode != WPAS_MODE_P2P_GO || !ssid->p2p_persistent_group) { |
| 8580 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Ignore new_psk_cb on not-persistent GO"); |
| 8581 | return; |
| 8582 | } |
| 8583 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8584 | persistent = wpas_p2p_get_persistent(wpa_s->p2pdev, NULL, ssid->ssid, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8585 | ssid->ssid_len); |
| 8586 | if (!persistent) { |
| 8587 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not find persistent group information to store the new PSK"); |
| 8588 | return; |
| 8589 | } |
| 8590 | |
| 8591 | p = os_zalloc(sizeof(*p)); |
| 8592 | if (p == NULL) |
| 8593 | return; |
| 8594 | if (p2p_dev_addr) { |
| 8595 | p->p2p = 1; |
| 8596 | os_memcpy(p->addr, p2p_dev_addr, ETH_ALEN); |
| 8597 | } else { |
| 8598 | p->p2p = 0; |
| 8599 | os_memcpy(p->addr, mac_addr, ETH_ALEN); |
| 8600 | } |
| 8601 | os_memcpy(p->psk, psk, psk_len); |
| 8602 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 8603 | if (dl_list_len(&persistent->psk_list) > P2P_MAX_STORED_CLIENTS && |
| 8604 | (last = dl_list_last(&persistent->psk_list, |
| 8605 | struct psk_list_entry, list))) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8606 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove oldest PSK entry for " |
| 8607 | MACSTR " (p2p=%u) to make room for a new one", |
| 8608 | MAC2STR(last->addr), last->p2p); |
| 8609 | dl_list_del(&last->list); |
| 8610 | os_free(last); |
| 8611 | } |
| 8612 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8613 | wpas_p2p_remove_psk_entry(wpa_s->p2pdev, persistent, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8614 | p2p_dev_addr ? p2p_dev_addr : mac_addr, |
| 8615 | p2p_dev_addr == NULL); |
| 8616 | if (p2p_dev_addr) { |
| 8617 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for p2p_dev_addr=" |
| 8618 | MACSTR, MAC2STR(p2p_dev_addr)); |
| 8619 | } else { |
| 8620 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for addr=" MACSTR, |
| 8621 | MAC2STR(mac_addr)); |
| 8622 | } |
| 8623 | dl_list_add(&persistent->psk_list, &p->list); |
| 8624 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8625 | if (wpa_s->p2pdev->conf->update_config && |
| 8626 | wpa_config_write(wpa_s->p2pdev->confname, wpa_s->p2pdev->conf)) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8627 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8628 | } |
| 8629 | |
| 8630 | |
| 8631 | static void wpas_p2p_remove_psk(struct wpa_supplicant *wpa_s, |
| 8632 | struct wpa_ssid *s, const u8 *addr, |
| 8633 | int iface_addr) |
| 8634 | { |
| 8635 | int res; |
| 8636 | |
| 8637 | res = wpas_p2p_remove_psk_entry(wpa_s, s, addr, iface_addr); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 8638 | if (res > 0 && wpa_s->conf->update_config && |
| 8639 | wpa_config_write(wpa_s->confname, wpa_s->conf)) |
| 8640 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 8641 | "P2P: Failed to update configuration"); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8642 | } |
| 8643 | |
| 8644 | |
| 8645 | static void wpas_p2p_remove_client_go(struct wpa_supplicant *wpa_s, |
| 8646 | const u8 *peer, int iface_addr) |
| 8647 | { |
| 8648 | struct hostapd_data *hapd; |
| 8649 | struct hostapd_wpa_psk *psk, *prev, *rem; |
| 8650 | struct sta_info *sta; |
| 8651 | |
| 8652 | if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL || |
| 8653 | wpa_s->current_ssid->mode != WPAS_MODE_P2P_GO) |
| 8654 | return; |
| 8655 | |
| 8656 | /* Remove per-station PSK entry */ |
| 8657 | hapd = wpa_s->ap_iface->bss[0]; |
| 8658 | prev = NULL; |
| 8659 | psk = hapd->conf->ssid.wpa_psk; |
| 8660 | while (psk) { |
| 8661 | if ((iface_addr && os_memcmp(peer, psk->addr, ETH_ALEN) == 0) || |
| 8662 | (!iface_addr && |
| 8663 | os_memcmp(peer, psk->p2p_dev_addr, ETH_ALEN) == 0)) { |
| 8664 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove operating group PSK entry for " |
| 8665 | MACSTR " iface_addr=%d", |
| 8666 | MAC2STR(peer), iface_addr); |
| 8667 | if (prev) |
| 8668 | prev->next = psk->next; |
| 8669 | else |
| 8670 | hapd->conf->ssid.wpa_psk = psk->next; |
| 8671 | rem = psk; |
| 8672 | psk = psk->next; |
| 8673 | os_free(rem); |
| 8674 | } else { |
| 8675 | prev = psk; |
| 8676 | psk = psk->next; |
| 8677 | } |
| 8678 | } |
| 8679 | |
| 8680 | /* Disconnect from group */ |
| 8681 | if (iface_addr) |
| 8682 | sta = ap_get_sta(hapd, peer); |
| 8683 | else |
| 8684 | sta = ap_get_sta_p2p(hapd, peer); |
| 8685 | if (sta) { |
| 8686 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disconnect peer " MACSTR |
| 8687 | " (iface_addr=%d) from group", |
| 8688 | MAC2STR(peer), iface_addr); |
| 8689 | hostapd_drv_sta_deauth(hapd, sta->addr, |
| 8690 | WLAN_REASON_DEAUTH_LEAVING); |
| 8691 | ap_sta_deauthenticate(hapd, sta, WLAN_REASON_DEAUTH_LEAVING); |
| 8692 | } |
| 8693 | } |
| 8694 | |
| 8695 | |
| 8696 | void wpas_p2p_remove_client(struct wpa_supplicant *wpa_s, const u8 *peer, |
| 8697 | int iface_addr) |
| 8698 | { |
| 8699 | struct wpa_ssid *s; |
| 8700 | struct wpa_supplicant *w; |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 8701 | 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] | 8702 | |
| 8703 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove client " MACSTR, MAC2STR(peer)); |
| 8704 | |
| 8705 | /* Remove from any persistent group */ |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 8706 | for (s = p2p_wpa_s->conf->ssid; s; s = s->next) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8707 | if (s->disabled != 2 || s->mode != WPAS_MODE_P2P_GO) |
| 8708 | continue; |
| 8709 | if (!iface_addr) |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 8710 | wpas_remove_persistent_peer(p2p_wpa_s, s, peer, 0); |
| 8711 | wpas_p2p_remove_psk(p2p_wpa_s, s, peer, iface_addr); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8712 | } |
| 8713 | |
| 8714 | /* Remove from any operating group */ |
| 8715 | for (w = wpa_s->global->ifaces; w; w = w->next) |
| 8716 | wpas_p2p_remove_client_go(w, peer, iface_addr); |
| 8717 | } |
| 8718 | |
| 8719 | |
| 8720 | static void wpas_p2p_psk_failure_removal(void *eloop_ctx, void *timeout_ctx) |
| 8721 | { |
| 8722 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 8723 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_PSK_FAILURE); |
| 8724 | } |
| 8725 | |
| 8726 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 8727 | static void wpas_p2p_group_freq_conflict(void *eloop_ctx, void *timeout_ctx) |
| 8728 | { |
| 8729 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 8730 | |
| 8731 | wpa_printf(MSG_DEBUG, "P2P: Frequency conflict - terminate group"); |
| 8732 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_FREQ_CONFLICT); |
| 8733 | } |
| 8734 | |
| 8735 | |
| 8736 | int wpas_p2p_handle_frequency_conflicts(struct wpa_supplicant *wpa_s, int freq, |
| 8737 | struct wpa_ssid *ssid) |
| 8738 | { |
| 8739 | struct wpa_supplicant *iface; |
| 8740 | |
| 8741 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 8742 | if (!iface->current_ssid || |
| 8743 | iface->current_ssid->frequency == freq || |
| 8744 | (iface->p2p_group_interface == NOT_P2P_GROUP_INTERFACE && |
| 8745 | !iface->current_ssid->p2p_group)) |
| 8746 | continue; |
| 8747 | |
| 8748 | /* Remove the connection with least priority */ |
| 8749 | if (!wpas_is_p2p_prioritized(iface)) { |
| 8750 | /* STA connection has priority over existing |
| 8751 | * P2P connection, so remove the interface. */ |
| 8752 | wpa_printf(MSG_DEBUG, "P2P: Removing P2P connection due to single channel concurrent mode frequency conflict"); |
| 8753 | eloop_register_timeout(0, 0, |
| 8754 | wpas_p2p_group_freq_conflict, |
| 8755 | iface, NULL); |
| 8756 | /* If connection in progress is P2P connection, do not |
| 8757 | * proceed for the connection. */ |
| 8758 | if (wpa_s == iface) |
| 8759 | return -1; |
| 8760 | else |
| 8761 | return 0; |
| 8762 | } else { |
| 8763 | /* P2P connection has priority, disable the STA network |
| 8764 | */ |
| 8765 | wpa_supplicant_disable_network(wpa_s->global->ifaces, |
| 8766 | ssid); |
| 8767 | wpa_msg(wpa_s->global->ifaces, MSG_INFO, |
| 8768 | WPA_EVENT_FREQ_CONFLICT " id=%d", ssid->id); |
| 8769 | os_memset(wpa_s->global->ifaces->pending_bssid, 0, |
| 8770 | ETH_ALEN); |
| 8771 | /* If P2P connection is in progress, continue |
| 8772 | * connecting...*/ |
| 8773 | if (wpa_s == iface) |
| 8774 | return 0; |
| 8775 | else |
| 8776 | return -1; |
| 8777 | } |
| 8778 | } |
| 8779 | |
| 8780 | return 0; |
| 8781 | } |
| 8782 | |
| 8783 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8784 | int wpas_p2p_4way_hs_failed(struct wpa_supplicant *wpa_s) |
| 8785 | { |
| 8786 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 8787 | |
| 8788 | if (ssid == NULL || !ssid->p2p_group) |
| 8789 | return 0; |
| 8790 | |
| 8791 | if (wpa_s->p2p_last_4way_hs_fail && |
| 8792 | wpa_s->p2p_last_4way_hs_fail == ssid) { |
| 8793 | u8 go_dev_addr[ETH_ALEN]; |
| 8794 | struct wpa_ssid *persistent; |
| 8795 | |
| 8796 | if (wpas_p2p_persistent_group(wpa_s, go_dev_addr, |
| 8797 | ssid->ssid, |
| 8798 | ssid->ssid_len) <= 0) { |
| 8799 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not determine whether 4-way handshake failures were for a persistent group"); |
| 8800 | goto disconnect; |
| 8801 | } |
| 8802 | |
| 8803 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Two 4-way handshake failures for a P2P group - go_dev_addr=" |
| 8804 | MACSTR, MAC2STR(go_dev_addr)); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8805 | persistent = wpas_p2p_get_persistent(wpa_s->p2pdev, go_dev_addr, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8806 | ssid->ssid, |
| 8807 | ssid->ssid_len); |
| 8808 | if (persistent == NULL || persistent->mode != WPAS_MODE_INFRA) { |
| 8809 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No matching persistent group stored"); |
| 8810 | goto disconnect; |
| 8811 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8812 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8813 | P2P_EVENT_PERSISTENT_PSK_FAIL "%d", |
| 8814 | persistent->id); |
| 8815 | disconnect: |
| 8816 | wpa_s->p2p_last_4way_hs_fail = NULL; |
| 8817 | /* |
| 8818 | * Remove the group from a timeout to avoid issues with caller |
| 8819 | * continuing to use the interface if this is on a P2P group |
| 8820 | * interface. |
| 8821 | */ |
| 8822 | eloop_register_timeout(0, 0, wpas_p2p_psk_failure_removal, |
| 8823 | wpa_s, NULL); |
| 8824 | return 1; |
| 8825 | } |
| 8826 | |
| 8827 | wpa_s->p2p_last_4way_hs_fail = ssid; |
| 8828 | return 0; |
| 8829 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 8830 | |
| 8831 | |
| 8832 | #ifdef CONFIG_WPS_NFC |
| 8833 | |
| 8834 | static struct wpabuf * wpas_p2p_nfc_handover(int ndef, struct wpabuf *wsc, |
| 8835 | struct wpabuf *p2p) |
| 8836 | { |
| 8837 | struct wpabuf *ret; |
| 8838 | size_t wsc_len; |
| 8839 | |
| 8840 | if (p2p == NULL) { |
| 8841 | wpabuf_free(wsc); |
| 8842 | wpa_printf(MSG_DEBUG, "P2P: No p2p buffer for handover"); |
| 8843 | return NULL; |
| 8844 | } |
| 8845 | |
| 8846 | wsc_len = wsc ? wpabuf_len(wsc) : 0; |
| 8847 | ret = wpabuf_alloc(2 + wsc_len + 2 + wpabuf_len(p2p)); |
| 8848 | if (ret == NULL) { |
| 8849 | wpabuf_free(wsc); |
| 8850 | wpabuf_free(p2p); |
| 8851 | return NULL; |
| 8852 | } |
| 8853 | |
| 8854 | wpabuf_put_be16(ret, wsc_len); |
| 8855 | if (wsc) |
| 8856 | wpabuf_put_buf(ret, wsc); |
| 8857 | wpabuf_put_be16(ret, wpabuf_len(p2p)); |
| 8858 | wpabuf_put_buf(ret, p2p); |
| 8859 | |
| 8860 | wpabuf_free(wsc); |
| 8861 | wpabuf_free(p2p); |
| 8862 | wpa_hexdump_buf(MSG_DEBUG, |
| 8863 | "P2P: Generated NFC connection handover message", ret); |
| 8864 | |
| 8865 | if (ndef && ret) { |
| 8866 | struct wpabuf *tmp; |
| 8867 | tmp = ndef_build_p2p(ret); |
| 8868 | wpabuf_free(ret); |
| 8869 | if (tmp == NULL) { |
| 8870 | wpa_printf(MSG_DEBUG, "P2P: Failed to NDEF encapsulate handover request"); |
| 8871 | return NULL; |
| 8872 | } |
| 8873 | ret = tmp; |
| 8874 | } |
| 8875 | |
| 8876 | return ret; |
| 8877 | } |
| 8878 | |
| 8879 | |
| 8880 | static int wpas_p2p_cli_freq(struct wpa_supplicant *wpa_s, |
| 8881 | struct wpa_ssid **ssid, u8 *go_dev_addr) |
| 8882 | { |
| 8883 | struct wpa_supplicant *iface; |
| 8884 | |
| 8885 | if (go_dev_addr) |
| 8886 | os_memset(go_dev_addr, 0, ETH_ALEN); |
| 8887 | if (ssid) |
| 8888 | *ssid = NULL; |
| 8889 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 8890 | if (iface->wpa_state < WPA_ASSOCIATING || |
| 8891 | iface->current_ssid == NULL || iface->assoc_freq == 0 || |
| 8892 | !iface->current_ssid->p2p_group || |
| 8893 | iface->current_ssid->mode != WPAS_MODE_INFRA) |
| 8894 | continue; |
| 8895 | if (ssid) |
| 8896 | *ssid = iface->current_ssid; |
| 8897 | if (go_dev_addr) |
| 8898 | os_memcpy(go_dev_addr, iface->go_dev_addr, ETH_ALEN); |
| 8899 | return iface->assoc_freq; |
| 8900 | } |
| 8901 | return 0; |
| 8902 | } |
| 8903 | |
| 8904 | |
| 8905 | struct wpabuf * wpas_p2p_nfc_handover_req(struct wpa_supplicant *wpa_s, |
| 8906 | int ndef) |
| 8907 | { |
| 8908 | struct wpabuf *wsc, *p2p; |
| 8909 | struct wpa_ssid *ssid; |
| 8910 | u8 go_dev_addr[ETH_ALEN]; |
| 8911 | int cli_freq = wpas_p2p_cli_freq(wpa_s, &ssid, go_dev_addr); |
| 8912 | |
| 8913 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) { |
| 8914 | wpa_printf(MSG_DEBUG, "P2P: P2P disabled - cannot build handover request"); |
| 8915 | return NULL; |
| 8916 | } |
| 8917 | |
| 8918 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL && |
| 8919 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, |
| 8920 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) { |
| 8921 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No DH key available for handover request"); |
| 8922 | return NULL; |
| 8923 | } |
| 8924 | |
| 8925 | if (cli_freq == 0) { |
| 8926 | wsc = wps_build_nfc_handover_req_p2p( |
| 8927 | wpa_s->parent->wps, wpa_s->conf->wps_nfc_dh_pubkey); |
| 8928 | } else |
| 8929 | wsc = NULL; |
| 8930 | p2p = p2p_build_nfc_handover_req(wpa_s->global->p2p, cli_freq, |
| 8931 | go_dev_addr, ssid ? ssid->ssid : NULL, |
| 8932 | ssid ? ssid->ssid_len : 0); |
| 8933 | |
| 8934 | return wpas_p2p_nfc_handover(ndef, wsc, p2p); |
| 8935 | } |
| 8936 | |
| 8937 | |
| 8938 | struct wpabuf * wpas_p2p_nfc_handover_sel(struct wpa_supplicant *wpa_s, |
| 8939 | int ndef, int tag) |
| 8940 | { |
| 8941 | struct wpabuf *wsc, *p2p; |
| 8942 | struct wpa_ssid *ssid; |
| 8943 | u8 go_dev_addr[ETH_ALEN]; |
| 8944 | int cli_freq = wpas_p2p_cli_freq(wpa_s, &ssid, go_dev_addr); |
| 8945 | |
| 8946 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 8947 | return NULL; |
| 8948 | |
| 8949 | if (!tag && wpa_s->conf->wps_nfc_dh_pubkey == NULL && |
| 8950 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, |
| 8951 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) |
| 8952 | return NULL; |
| 8953 | |
| 8954 | if (cli_freq == 0) { |
| 8955 | wsc = wps_build_nfc_handover_sel_p2p( |
| 8956 | wpa_s->parent->wps, |
| 8957 | tag ? wpa_s->conf->wps_nfc_dev_pw_id : |
| 8958 | DEV_PW_NFC_CONNECTION_HANDOVER, |
| 8959 | wpa_s->conf->wps_nfc_dh_pubkey, |
| 8960 | tag ? wpa_s->conf->wps_nfc_dev_pw : NULL); |
| 8961 | } else |
| 8962 | wsc = NULL; |
| 8963 | p2p = p2p_build_nfc_handover_sel(wpa_s->global->p2p, cli_freq, |
| 8964 | go_dev_addr, ssid ? ssid->ssid : NULL, |
| 8965 | ssid ? ssid->ssid_len : 0); |
| 8966 | |
| 8967 | return wpas_p2p_nfc_handover(ndef, wsc, p2p); |
| 8968 | } |
| 8969 | |
| 8970 | |
| 8971 | static int wpas_p2p_nfc_join_group(struct wpa_supplicant *wpa_s, |
| 8972 | struct p2p_nfc_params *params) |
| 8973 | { |
| 8974 | wpa_printf(MSG_DEBUG, "P2P: Initiate join-group based on NFC " |
| 8975 | "connection handover (freq=%d)", |
| 8976 | params->go_freq); |
| 8977 | |
| 8978 | if (params->go_freq && params->go_ssid_len) { |
| 8979 | wpa_s->p2p_wps_method = WPS_NFC; |
| 8980 | wpa_s->pending_join_wps_method = WPS_NFC; |
| 8981 | os_memset(wpa_s->pending_join_iface_addr, 0, ETH_ALEN); |
| 8982 | os_memcpy(wpa_s->pending_join_dev_addr, params->go_dev_addr, |
| 8983 | ETH_ALEN); |
| 8984 | return wpas_p2p_join_start(wpa_s, params->go_freq, |
| 8985 | params->go_ssid, |
| 8986 | params->go_ssid_len); |
| 8987 | } |
| 8988 | |
| 8989 | return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL, |
| 8990 | WPS_NFC, 0, 0, 1, 0, wpa_s->conf->p2p_go_intent, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8991 | params->go_freq, wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 8992 | -1, 0, 1, 1, wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8993 | wpa_s->p2p_go_he, wpa_s->p2p_go_edmg, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 8994 | params->go_ssid_len ? params->go_ssid : NULL, |
| 8995 | params->go_ssid_len); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 8996 | } |
| 8997 | |
| 8998 | |
| 8999 | static int wpas_p2p_nfc_auth_join(struct wpa_supplicant *wpa_s, |
| 9000 | struct p2p_nfc_params *params, int tag) |
| 9001 | { |
| 9002 | int res, persistent; |
| 9003 | struct wpa_ssid *ssid; |
| 9004 | |
| 9005 | wpa_printf(MSG_DEBUG, "P2P: Authorize join-group based on NFC " |
| 9006 | "connection handover"); |
| 9007 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 9008 | ssid = wpa_s->current_ssid; |
| 9009 | if (ssid == NULL) |
| 9010 | continue; |
| 9011 | if (ssid->mode != WPAS_MODE_P2P_GO) |
| 9012 | continue; |
| 9013 | if (wpa_s->ap_iface == NULL) |
| 9014 | continue; |
| 9015 | break; |
| 9016 | } |
| 9017 | if (wpa_s == NULL) { |
| 9018 | wpa_printf(MSG_DEBUG, "P2P: Could not find GO interface"); |
| 9019 | return -1; |
| 9020 | } |
| 9021 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9022 | if (wpa_s->p2pdev->p2p_oob_dev_pw_id != |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9023 | DEV_PW_NFC_CONNECTION_HANDOVER && |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9024 | !wpa_s->p2pdev->p2p_oob_dev_pw) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9025 | wpa_printf(MSG_DEBUG, "P2P: No NFC Dev Pw known"); |
| 9026 | return -1; |
| 9027 | } |
| 9028 | res = wpas_ap_wps_add_nfc_pw( |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9029 | wpa_s, wpa_s->p2pdev->p2p_oob_dev_pw_id, |
| 9030 | wpa_s->p2pdev->p2p_oob_dev_pw, |
| 9031 | wpa_s->p2pdev->p2p_peer_oob_pk_hash_known ? |
| 9032 | wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : NULL); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9033 | if (res) |
| 9034 | return res; |
| 9035 | |
| 9036 | if (!tag) { |
| 9037 | wpa_printf(MSG_DEBUG, "P2P: Negotiated handover - wait for peer to join without invitation"); |
| 9038 | return 0; |
| 9039 | } |
| 9040 | |
| 9041 | if (!params->peer || |
| 9042 | !(params->peer->dev_capab & P2P_DEV_CAPAB_INVITATION_PROCEDURE)) |
| 9043 | return 0; |
| 9044 | |
| 9045 | wpa_printf(MSG_DEBUG, "P2P: Static handover - invite peer " MACSTR |
| 9046 | " to join", MAC2STR(params->peer->p2p_device_addr)); |
| 9047 | |
| 9048 | wpa_s->global->p2p_invite_group = wpa_s; |
| 9049 | persistent = ssid->p2p_persistent_group && |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9050 | wpas_p2p_get_persistent(wpa_s->p2pdev, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9051 | params->peer->p2p_device_addr, |
| 9052 | ssid->ssid, ssid->ssid_len); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9053 | wpa_s->p2pdev->pending_invite_ssid_id = -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9054 | |
| 9055 | return p2p_invite(wpa_s->global->p2p, params->peer->p2p_device_addr, |
| 9056 | P2P_INVITE_ROLE_ACTIVE_GO, wpa_s->own_addr, |
| 9057 | ssid->ssid, ssid->ssid_len, ssid->frequency, |
| 9058 | wpa_s->global->p2p_dev_addr, persistent, 0, |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9059 | wpa_s->p2pdev->p2p_oob_dev_pw_id); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9060 | } |
| 9061 | |
| 9062 | |
| 9063 | static int wpas_p2p_nfc_init_go_neg(struct wpa_supplicant *wpa_s, |
| 9064 | struct p2p_nfc_params *params, |
| 9065 | int forced_freq) |
| 9066 | { |
| 9067 | wpa_printf(MSG_DEBUG, "P2P: Initiate GO Negotiation based on NFC " |
| 9068 | "connection handover"); |
| 9069 | return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL, |
| 9070 | WPS_NFC, 0, 0, 0, 0, wpa_s->conf->p2p_go_intent, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9071 | forced_freq, wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 9072 | -1, 0, 1, 1, wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9073 | wpa_s->p2p_go_he, wpa_s->p2p_go_edmg, |
| 9074 | NULL, 0); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9075 | } |
| 9076 | |
| 9077 | |
| 9078 | static int wpas_p2p_nfc_resp_go_neg(struct wpa_supplicant *wpa_s, |
| 9079 | struct p2p_nfc_params *params, |
| 9080 | int forced_freq) |
| 9081 | { |
| 9082 | int res; |
| 9083 | |
| 9084 | wpa_printf(MSG_DEBUG, "P2P: Authorize GO Negotiation based on NFC " |
| 9085 | "connection handover"); |
| 9086 | res = wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL, |
| 9087 | WPS_NFC, 0, 0, 0, 1, wpa_s->conf->p2p_go_intent, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9088 | forced_freq, wpa_s->p2p_go_vht_center_freq2, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 9089 | -1, 0, 1, 1, wpa_s->p2p_go_max_oper_chwidth, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9090 | wpa_s->p2p_go_he, wpa_s->p2p_go_edmg, |
| 9091 | NULL, 0); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9092 | if (res) |
| 9093 | return res; |
| 9094 | |
| 9095 | res = wpas_p2p_listen(wpa_s, 60); |
| 9096 | if (res) { |
| 9097 | p2p_unauthorize(wpa_s->global->p2p, |
| 9098 | params->peer->p2p_device_addr); |
| 9099 | } |
| 9100 | |
| 9101 | return res; |
| 9102 | } |
| 9103 | |
| 9104 | |
| 9105 | static int wpas_p2p_nfc_connection_handover(struct wpa_supplicant *wpa_s, |
| 9106 | const struct wpabuf *data, |
| 9107 | int sel, int tag, int forced_freq) |
| 9108 | { |
| 9109 | const u8 *pos, *end; |
| 9110 | u16 len, id; |
| 9111 | struct p2p_nfc_params params; |
| 9112 | int res; |
| 9113 | |
| 9114 | os_memset(¶ms, 0, sizeof(params)); |
| 9115 | params.sel = sel; |
| 9116 | |
| 9117 | wpa_hexdump_buf(MSG_DEBUG, "P2P: Received NFC tag payload", data); |
| 9118 | |
| 9119 | pos = wpabuf_head(data); |
| 9120 | end = pos + wpabuf_len(data); |
| 9121 | |
| 9122 | if (end - pos < 2) { |
| 9123 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for Length of WSC " |
| 9124 | "attributes"); |
| 9125 | return -1; |
| 9126 | } |
| 9127 | len = WPA_GET_BE16(pos); |
| 9128 | pos += 2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9129 | if (len > end - pos) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9130 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for WSC " |
| 9131 | "attributes"); |
| 9132 | return -1; |
| 9133 | } |
| 9134 | params.wsc_attr = pos; |
| 9135 | params.wsc_len = len; |
| 9136 | pos += len; |
| 9137 | |
| 9138 | if (end - pos < 2) { |
| 9139 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for Length of P2P " |
| 9140 | "attributes"); |
| 9141 | return -1; |
| 9142 | } |
| 9143 | len = WPA_GET_BE16(pos); |
| 9144 | pos += 2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9145 | if (len > end - pos) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9146 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for P2P " |
| 9147 | "attributes"); |
| 9148 | return -1; |
| 9149 | } |
| 9150 | params.p2p_attr = pos; |
| 9151 | params.p2p_len = len; |
| 9152 | pos += len; |
| 9153 | |
| 9154 | wpa_hexdump(MSG_DEBUG, "P2P: WSC attributes", |
| 9155 | params.wsc_attr, params.wsc_len); |
| 9156 | wpa_hexdump(MSG_DEBUG, "P2P: P2P attributes", |
| 9157 | params.p2p_attr, params.p2p_len); |
| 9158 | if (pos < end) { |
| 9159 | wpa_hexdump(MSG_DEBUG, |
| 9160 | "P2P: Ignored extra data after P2P attributes", |
| 9161 | pos, end - pos); |
| 9162 | } |
| 9163 | |
| 9164 | res = p2p_process_nfc_connection_handover(wpa_s->global->p2p, ¶ms); |
| 9165 | if (res) |
| 9166 | return res; |
| 9167 | |
| 9168 | if (params.next_step == NO_ACTION) |
| 9169 | return 0; |
| 9170 | |
| 9171 | if (params.next_step == BOTH_GO) { |
| 9172 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_BOTH_GO "peer=" MACSTR, |
| 9173 | MAC2STR(params.peer->p2p_device_addr)); |
| 9174 | return 0; |
| 9175 | } |
| 9176 | |
| 9177 | if (params.next_step == PEER_CLIENT) { |
| 9178 | if (!is_zero_ether_addr(params.go_dev_addr)) { |
| 9179 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_PEER_CLIENT |
| 9180 | "peer=" MACSTR " freq=%d go_dev_addr=" MACSTR |
| 9181 | " ssid=\"%s\"", |
| 9182 | MAC2STR(params.peer->p2p_device_addr), |
| 9183 | params.go_freq, |
| 9184 | MAC2STR(params.go_dev_addr), |
| 9185 | wpa_ssid_txt(params.go_ssid, |
| 9186 | params.go_ssid_len)); |
| 9187 | } else { |
| 9188 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_PEER_CLIENT |
| 9189 | "peer=" MACSTR " freq=%d", |
| 9190 | MAC2STR(params.peer->p2p_device_addr), |
| 9191 | params.go_freq); |
| 9192 | } |
| 9193 | return 0; |
| 9194 | } |
| 9195 | |
| 9196 | if (wpas_p2p_cli_freq(wpa_s, NULL, NULL)) { |
| 9197 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_WHILE_CLIENT "peer=" |
| 9198 | MACSTR, MAC2STR(params.peer->p2p_device_addr)); |
| 9199 | return 0; |
| 9200 | } |
| 9201 | |
| 9202 | wpabuf_free(wpa_s->p2p_oob_dev_pw); |
| 9203 | wpa_s->p2p_oob_dev_pw = NULL; |
| 9204 | |
| 9205 | if (params.oob_dev_pw_len < WPS_OOB_PUBKEY_HASH_LEN + 2) { |
| 9206 | wpa_printf(MSG_DEBUG, "P2P: No peer OOB Dev Pw " |
| 9207 | "received"); |
| 9208 | return -1; |
| 9209 | } |
| 9210 | |
| 9211 | id = WPA_GET_BE16(params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN); |
| 9212 | wpa_printf(MSG_DEBUG, "P2P: Peer OOB Dev Pw %u", id); |
| 9213 | wpa_hexdump(MSG_DEBUG, "P2P: Peer OOB Public Key hash", |
| 9214 | params.oob_dev_pw, WPS_OOB_PUBKEY_HASH_LEN); |
| 9215 | os_memcpy(wpa_s->p2p_peer_oob_pubkey_hash, |
| 9216 | params.oob_dev_pw, WPS_OOB_PUBKEY_HASH_LEN); |
| 9217 | wpa_s->p2p_peer_oob_pk_hash_known = 1; |
| 9218 | |
| 9219 | if (tag) { |
| 9220 | if (id < 0x10) { |
| 9221 | wpa_printf(MSG_DEBUG, "P2P: Static handover - invalid " |
| 9222 | "peer OOB Device Password Id %u", id); |
| 9223 | return -1; |
| 9224 | } |
| 9225 | wpa_printf(MSG_DEBUG, "P2P: Static handover - use peer OOB " |
| 9226 | "Device Password Id %u", id); |
| 9227 | wpa_hexdump_key(MSG_DEBUG, "P2P: Peer OOB Device Password", |
| 9228 | params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN + 2, |
| 9229 | params.oob_dev_pw_len - |
| 9230 | WPS_OOB_PUBKEY_HASH_LEN - 2); |
| 9231 | wpa_s->p2p_oob_dev_pw_id = id; |
| 9232 | wpa_s->p2p_oob_dev_pw = wpabuf_alloc_copy( |
| 9233 | params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN + 2, |
| 9234 | params.oob_dev_pw_len - |
| 9235 | WPS_OOB_PUBKEY_HASH_LEN - 2); |
| 9236 | if (wpa_s->p2p_oob_dev_pw == NULL) |
| 9237 | return -1; |
| 9238 | |
| 9239 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL && |
| 9240 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, |
| 9241 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) |
| 9242 | return -1; |
| 9243 | } else { |
| 9244 | wpa_printf(MSG_DEBUG, "P2P: Using abbreviated WPS handshake " |
| 9245 | "without Device Password"); |
| 9246 | wpa_s->p2p_oob_dev_pw_id = DEV_PW_NFC_CONNECTION_HANDOVER; |
| 9247 | } |
| 9248 | |
| 9249 | switch (params.next_step) { |
| 9250 | case NO_ACTION: |
| 9251 | case BOTH_GO: |
| 9252 | case PEER_CLIENT: |
| 9253 | /* already covered above */ |
| 9254 | return 0; |
| 9255 | case JOIN_GROUP: |
| 9256 | return wpas_p2p_nfc_join_group(wpa_s, ¶ms); |
| 9257 | case AUTH_JOIN: |
| 9258 | return wpas_p2p_nfc_auth_join(wpa_s, ¶ms, tag); |
| 9259 | case INIT_GO_NEG: |
| 9260 | return wpas_p2p_nfc_init_go_neg(wpa_s, ¶ms, forced_freq); |
| 9261 | case RESP_GO_NEG: |
| 9262 | /* TODO: use own OOB Dev Pw */ |
| 9263 | return wpas_p2p_nfc_resp_go_neg(wpa_s, ¶ms, forced_freq); |
| 9264 | } |
| 9265 | |
| 9266 | return -1; |
| 9267 | } |
| 9268 | |
| 9269 | |
| 9270 | int wpas_p2p_nfc_tag_process(struct wpa_supplicant *wpa_s, |
| 9271 | const struct wpabuf *data, int forced_freq) |
| 9272 | { |
| 9273 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 9274 | return -1; |
| 9275 | |
| 9276 | return wpas_p2p_nfc_connection_handover(wpa_s, data, 1, 1, forced_freq); |
| 9277 | } |
| 9278 | |
| 9279 | |
| 9280 | int wpas_p2p_nfc_report_handover(struct wpa_supplicant *wpa_s, int init, |
| 9281 | const struct wpabuf *req, |
| 9282 | const struct wpabuf *sel, int forced_freq) |
| 9283 | { |
| 9284 | struct wpabuf *tmp; |
| 9285 | int ret; |
| 9286 | |
| 9287 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 9288 | return -1; |
| 9289 | |
| 9290 | wpa_printf(MSG_DEBUG, "NFC: P2P connection handover reported"); |
| 9291 | |
| 9292 | wpa_hexdump_ascii(MSG_DEBUG, "NFC: Req", |
| 9293 | wpabuf_head(req), wpabuf_len(req)); |
| 9294 | wpa_hexdump_ascii(MSG_DEBUG, "NFC: Sel", |
| 9295 | wpabuf_head(sel), wpabuf_len(sel)); |
| 9296 | if (forced_freq) |
| 9297 | wpa_printf(MSG_DEBUG, "NFC: Forced freq %d", forced_freq); |
| 9298 | tmp = ndef_parse_p2p(init ? sel : req); |
| 9299 | if (tmp == NULL) { |
| 9300 | wpa_printf(MSG_DEBUG, "P2P: Could not parse NDEF"); |
| 9301 | return -1; |
| 9302 | } |
| 9303 | |
| 9304 | ret = wpas_p2p_nfc_connection_handover(wpa_s, tmp, init, 0, |
| 9305 | forced_freq); |
| 9306 | wpabuf_free(tmp); |
| 9307 | |
| 9308 | return ret; |
| 9309 | } |
| 9310 | |
| 9311 | |
| 9312 | int wpas_p2p_nfc_tag_enabled(struct wpa_supplicant *wpa_s, int enabled) |
| 9313 | { |
| 9314 | const u8 *if_addr; |
| 9315 | int go_intent = wpa_s->conf->p2p_go_intent; |
| 9316 | struct wpa_supplicant *iface; |
| 9317 | |
| 9318 | if (wpa_s->global->p2p == NULL) |
| 9319 | return -1; |
| 9320 | |
| 9321 | if (!enabled) { |
| 9322 | wpa_printf(MSG_DEBUG, "P2P: Disable use of own NFC Tag"); |
| 9323 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) |
| 9324 | { |
| 9325 | if (!iface->ap_iface) |
| 9326 | continue; |
| 9327 | hostapd_wps_nfc_token_disable(iface->ap_iface->bss[0]); |
| 9328 | } |
| 9329 | p2p_set_authorized_oob_dev_pw_id(wpa_s->global->p2p, 0, |
| 9330 | 0, NULL); |
| 9331 | if (wpa_s->p2p_nfc_tag_enabled) |
| 9332 | wpas_p2p_remove_pending_group_interface(wpa_s); |
| 9333 | wpa_s->p2p_nfc_tag_enabled = 0; |
| 9334 | return 0; |
| 9335 | } |
| 9336 | |
| 9337 | if (wpa_s->global->p2p_disabled) |
| 9338 | return -1; |
| 9339 | |
| 9340 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL || |
| 9341 | wpa_s->conf->wps_nfc_dh_privkey == NULL || |
| 9342 | wpa_s->conf->wps_nfc_dev_pw == NULL || |
| 9343 | wpa_s->conf->wps_nfc_dev_pw_id < 0x10) { |
| 9344 | wpa_printf(MSG_DEBUG, "P2P: NFC password token not configured " |
| 9345 | "to allow static handover cases"); |
| 9346 | return -1; |
| 9347 | } |
| 9348 | |
| 9349 | wpa_printf(MSG_DEBUG, "P2P: Enable use of own NFC Tag"); |
| 9350 | |
| 9351 | wpa_s->p2p_oob_dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id; |
| 9352 | wpabuf_free(wpa_s->p2p_oob_dev_pw); |
| 9353 | wpa_s->p2p_oob_dev_pw = wpabuf_dup(wpa_s->conf->wps_nfc_dev_pw); |
| 9354 | if (wpa_s->p2p_oob_dev_pw == NULL) |
| 9355 | return -1; |
| 9356 | wpa_s->p2p_peer_oob_pk_hash_known = 0; |
| 9357 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 9358 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO || |
| 9359 | wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT) { |
| 9360 | /* |
| 9361 | * P2P Group Interface present and the command came on group |
| 9362 | * interface, so enable the token for the current interface. |
| 9363 | */ |
| 9364 | wpa_s->create_p2p_iface = 0; |
| 9365 | } else { |
| 9366 | wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s); |
| 9367 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9368 | |
| 9369 | if (wpa_s->create_p2p_iface) { |
| 9370 | enum wpa_driver_if_type iftype; |
| 9371 | /* Prepare to add a new interface for the group */ |
| 9372 | iftype = WPA_IF_P2P_GROUP; |
| 9373 | if (go_intent == 15) |
| 9374 | iftype = WPA_IF_P2P_GO; |
| 9375 | if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) { |
| 9376 | wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " |
| 9377 | "interface for the group"); |
| 9378 | return -1; |
| 9379 | } |
| 9380 | |
| 9381 | if_addr = wpa_s->pending_interface_addr; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9382 | } else if (wpa_s->p2p_mgmt) |
| 9383 | if_addr = wpa_s->parent->own_addr; |
| 9384 | else |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9385 | if_addr = wpa_s->own_addr; |
| 9386 | |
| 9387 | wpa_s->p2p_nfc_tag_enabled = enabled; |
| 9388 | |
| 9389 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { |
| 9390 | struct hostapd_data *hapd; |
| 9391 | if (iface->ap_iface == NULL) |
| 9392 | continue; |
| 9393 | hapd = iface->ap_iface->bss[0]; |
| 9394 | wpabuf_free(hapd->conf->wps_nfc_dh_pubkey); |
| 9395 | hapd->conf->wps_nfc_dh_pubkey = |
| 9396 | wpabuf_dup(wpa_s->conf->wps_nfc_dh_pubkey); |
| 9397 | wpabuf_free(hapd->conf->wps_nfc_dh_privkey); |
| 9398 | hapd->conf->wps_nfc_dh_privkey = |
| 9399 | wpabuf_dup(wpa_s->conf->wps_nfc_dh_privkey); |
| 9400 | wpabuf_free(hapd->conf->wps_nfc_dev_pw); |
| 9401 | hapd->conf->wps_nfc_dev_pw = |
| 9402 | wpabuf_dup(wpa_s->conf->wps_nfc_dev_pw); |
| 9403 | hapd->conf->wps_nfc_dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id; |
| 9404 | |
| 9405 | if (hostapd_wps_nfc_token_enable(iface->ap_iface->bss[0]) < 0) { |
| 9406 | wpa_dbg(iface, MSG_DEBUG, |
| 9407 | "P2P: Failed to enable NFC Tag for GO"); |
| 9408 | } |
| 9409 | } |
| 9410 | p2p_set_authorized_oob_dev_pw_id( |
| 9411 | wpa_s->global->p2p, wpa_s->conf->wps_nfc_dev_pw_id, go_intent, |
| 9412 | if_addr); |
| 9413 | |
| 9414 | return 0; |
| 9415 | } |
| 9416 | |
| 9417 | #endif /* CONFIG_WPS_NFC */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9418 | |
| 9419 | |
| 9420 | static void wpas_p2p_optimize_listen_channel(struct wpa_supplicant *wpa_s, |
| 9421 | struct wpa_used_freq_data *freqs, |
| 9422 | unsigned int num) |
| 9423 | { |
| 9424 | u8 curr_chan, cand, chan; |
| 9425 | unsigned int i; |
| 9426 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9427 | /* |
| 9428 | * If possible, optimize the Listen channel to be a channel that is |
| 9429 | * already used by one of the other interfaces. |
| 9430 | */ |
| 9431 | if (!wpa_s->conf->p2p_optimize_listen_chan) |
| 9432 | return; |
| 9433 | |
| 9434 | if (!wpa_s->current_ssid || wpa_s->wpa_state != WPA_COMPLETED) |
| 9435 | return; |
| 9436 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9437 | curr_chan = p2p_get_listen_channel(wpa_s->global->p2p); |
| 9438 | for (i = 0, cand = 0; i < num; i++) { |
| 9439 | ieee80211_freq_to_chan(freqs[i].freq, &chan); |
| 9440 | if (curr_chan == chan) { |
| 9441 | cand = 0; |
| 9442 | break; |
| 9443 | } |
| 9444 | |
| 9445 | if (chan == 1 || chan == 6 || chan == 11) |
| 9446 | cand = chan; |
| 9447 | } |
| 9448 | |
| 9449 | if (cand) { |
| 9450 | wpa_dbg(wpa_s, MSG_DEBUG, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 9451 | "P2P: Update Listen channel to %u based on operating channel", |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9452 | cand); |
| 9453 | p2p_set_listen_channel(wpa_s->global->p2p, 81, cand, 0); |
| 9454 | } |
| 9455 | } |
| 9456 | |
| 9457 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9458 | static int wpas_p2p_move_go_csa(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9459 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9460 | struct hostapd_config *conf; |
| 9461 | struct p2p_go_neg_results params; |
| 9462 | struct csa_settings csa_settings; |
| 9463 | struct wpa_ssid *current_ssid = wpa_s->current_ssid; |
| 9464 | int old_freq = current_ssid->frequency; |
| 9465 | int ret; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9466 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9467 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
| 9468 | wpa_dbg(wpa_s, MSG_DEBUG, "CSA is not enabled"); |
| 9469 | return -1; |
| 9470 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9471 | |
| 9472 | /* |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9473 | * TODO: This function may not always work correctly. For example, |
| 9474 | * 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] | 9475 | */ |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9476 | if (wpas_p2p_init_go_params(wpa_s, ¶ms, 0, 0, 0, 0, 0, 0, 0, |
| 9477 | NULL)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9478 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9479 | "P2P CSA: Failed to select new frequency for GO"); |
| 9480 | return -1; |
| 9481 | } |
| 9482 | |
| 9483 | if (current_ssid->frequency == params.freq) { |
| 9484 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9485 | "P2P CSA: Selected same frequency - not moving GO"); |
| 9486 | return 0; |
| 9487 | } |
| 9488 | |
| 9489 | conf = hostapd_config_defaults(); |
| 9490 | if (!conf) { |
| 9491 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9492 | "P2P CSA: Failed to allocate default config"); |
| 9493 | return -1; |
| 9494 | } |
| 9495 | |
| 9496 | current_ssid->frequency = params.freq; |
| 9497 | if (wpa_supplicant_conf_ap_ht(wpa_s, current_ssid, conf)) { |
| 9498 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9499 | "P2P CSA: Failed to create new GO config"); |
| 9500 | ret = -1; |
| 9501 | goto out; |
| 9502 | } |
| 9503 | |
| 9504 | if (conf->hw_mode != wpa_s->ap_iface->current_mode->mode) { |
| 9505 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9506 | "P2P CSA: CSA to a different band is not supported"); |
| 9507 | ret = -1; |
| 9508 | goto out; |
| 9509 | } |
| 9510 | |
| 9511 | os_memset(&csa_settings, 0, sizeof(csa_settings)); |
| 9512 | csa_settings.cs_count = P2P_GO_CSA_COUNT; |
| 9513 | csa_settings.block_tx = P2P_GO_CSA_BLOCK_TX; |
| 9514 | csa_settings.freq_params.freq = params.freq; |
| 9515 | csa_settings.freq_params.sec_channel_offset = conf->secondary_channel; |
| 9516 | csa_settings.freq_params.ht_enabled = conf->ieee80211n; |
| 9517 | csa_settings.freq_params.bandwidth = conf->secondary_channel ? 40 : 20; |
| 9518 | |
| 9519 | if (conf->ieee80211ac) { |
| 9520 | int freq1 = 0, freq2 = 0; |
| 9521 | u8 chan, opclass; |
| 9522 | |
| 9523 | if (ieee80211_freq_to_channel_ext(params.freq, |
| 9524 | conf->secondary_channel, |
| 9525 | conf->vht_oper_chwidth, |
| 9526 | &opclass, &chan) == |
| 9527 | NUM_HOSTAPD_MODES) { |
| 9528 | wpa_printf(MSG_ERROR, "P2P CSA: Bad freq"); |
| 9529 | ret = -1; |
| 9530 | goto out; |
| 9531 | } |
| 9532 | |
| 9533 | if (conf->vht_oper_centr_freq_seg0_idx) |
| 9534 | freq1 = ieee80211_chan_to_freq( |
| 9535 | NULL, opclass, |
| 9536 | conf->vht_oper_centr_freq_seg0_idx); |
| 9537 | |
| 9538 | if (conf->vht_oper_centr_freq_seg1_idx) |
| 9539 | freq2 = ieee80211_chan_to_freq( |
| 9540 | NULL, opclass, |
| 9541 | conf->vht_oper_centr_freq_seg1_idx); |
| 9542 | |
| 9543 | if (freq1 < 0 || freq2 < 0) { |
| 9544 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9545 | "P2P CSA: Selected invalid VHT center freqs"); |
| 9546 | ret = -1; |
| 9547 | goto out; |
| 9548 | } |
| 9549 | |
| 9550 | csa_settings.freq_params.vht_enabled = conf->ieee80211ac; |
| 9551 | csa_settings.freq_params.center_freq1 = freq1; |
| 9552 | csa_settings.freq_params.center_freq2 = freq2; |
| 9553 | |
| 9554 | switch (conf->vht_oper_chwidth) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 9555 | case CHANWIDTH_80MHZ: |
| 9556 | case CHANWIDTH_80P80MHZ: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9557 | csa_settings.freq_params.bandwidth = 80; |
| 9558 | break; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 9559 | case CHANWIDTH_160MHZ: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9560 | csa_settings.freq_params.bandwidth = 160; |
| 9561 | break; |
| 9562 | } |
| 9563 | } |
| 9564 | |
| 9565 | ret = ap_switch_channel(wpa_s, &csa_settings); |
| 9566 | out: |
| 9567 | current_ssid->frequency = old_freq; |
| 9568 | hostapd_config_free(conf); |
| 9569 | return ret; |
| 9570 | } |
| 9571 | |
| 9572 | |
| 9573 | static void wpas_p2p_move_go_no_csa(struct wpa_supplicant *wpa_s) |
| 9574 | { |
| 9575 | struct p2p_go_neg_results params; |
| 9576 | struct wpa_ssid *current_ssid = wpa_s->current_ssid; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9577 | void (*ap_configured_cb)(void *ctx, void *data); |
| 9578 | void *ap_configured_cb_ctx, *ap_configured_cb_data; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9579 | |
| 9580 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP); |
| 9581 | |
| 9582 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Move GO from freq=%d MHz", |
| 9583 | current_ssid->frequency); |
| 9584 | |
| 9585 | /* Stop the AP functionality */ |
| 9586 | /* TODO: Should do this in a way that does not indicated to possible |
| 9587 | * P2P Clients in the group that the group is terminated. */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9588 | /* If this action occurs before a group is started, the callback should |
| 9589 | * be preserved, or GROUP-STARTED event would be lost. If this action |
| 9590 | * occurs after a group is started, these pointers are all NULL and |
| 9591 | * harmless. */ |
| 9592 | ap_configured_cb = wpa_s->ap_configured_cb; |
| 9593 | ap_configured_cb_ctx = wpa_s->ap_configured_cb_ctx; |
| 9594 | ap_configured_cb_data = wpa_s->ap_configured_cb_data; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9595 | wpa_supplicant_ap_deinit(wpa_s); |
| 9596 | |
| 9597 | /* Reselect the GO frequency */ |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9598 | if (wpas_p2p_init_go_params(wpa_s, ¶ms, 0, 0, 0, 0, 0, 0, 0, |
| 9599 | NULL)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9600 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Failed to reselect freq"); |
| 9601 | wpas_p2p_group_delete(wpa_s, |
| 9602 | P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL); |
| 9603 | return; |
| 9604 | } |
| 9605 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New freq selected for the GO (%u MHz)", |
| 9606 | params.freq); |
| 9607 | |
| 9608 | if (params.freq && |
| 9609 | !p2p_supported_freq_go(wpa_s->global->p2p, params.freq)) { |
| 9610 | wpa_printf(MSG_DEBUG, |
| 9611 | "P2P: Selected freq (%u MHz) is not valid for P2P", |
| 9612 | params.freq); |
| 9613 | wpas_p2p_group_delete(wpa_s, |
| 9614 | P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL); |
| 9615 | return; |
| 9616 | } |
| 9617 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9618 | /* Restore preserved callback parameters */ |
Jimmy Chen | 4b2a502 | 2020-08-26 18:55:45 +0800 | [diff] [blame] | 9619 | wpa_s->ap_configured_cb = ap_configured_cb; |
| 9620 | wpa_s->ap_configured_cb_ctx = ap_configured_cb_ctx; |
| 9621 | wpa_s->ap_configured_cb_data = ap_configured_cb_data; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9622 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9623 | /* Update the frequency */ |
| 9624 | current_ssid->frequency = params.freq; |
| 9625 | wpa_s->connect_without_scan = current_ssid; |
| 9626 | wpa_s->reassociate = 1; |
| 9627 | wpa_s->disconnected = 0; |
| 9628 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 9629 | } |
| 9630 | |
| 9631 | |
| 9632 | static void wpas_p2p_move_go(void *eloop_ctx, void *timeout_ctx) |
| 9633 | { |
| 9634 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 9635 | |
| 9636 | if (!wpa_s->ap_iface || !wpa_s->current_ssid) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9637 | return; |
| 9638 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9639 | wpas_p2p_go_update_common_freqs(wpa_s); |
| 9640 | |
| 9641 | /* Do not move GO in the middle of a CSA */ |
| 9642 | if (hostapd_csa_in_progress(wpa_s->ap_iface)) { |
| 9643 | wpa_printf(MSG_DEBUG, |
| 9644 | "P2P: CSA is in progress - not moving GO"); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9645 | return; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9646 | } |
| 9647 | |
| 9648 | /* |
| 9649 | * First, try a channel switch flow. If it is not supported or fails, |
| 9650 | * take down the GO and bring it up again. |
| 9651 | */ |
| 9652 | if (wpas_p2p_move_go_csa(wpa_s) < 0) |
| 9653 | wpas_p2p_move_go_no_csa(wpa_s); |
| 9654 | } |
| 9655 | |
| 9656 | |
| 9657 | static void wpas_p2p_reconsider_moving_go(void *eloop_ctx, void *timeout_ctx) |
| 9658 | { |
| 9659 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 9660 | struct wpa_used_freq_data *freqs = NULL; |
| 9661 | unsigned int num = wpa_s->num_multichan_concurrent; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9662 | |
| 9663 | freqs = os_calloc(num, sizeof(struct wpa_used_freq_data)); |
| 9664 | if (!freqs) |
| 9665 | return; |
| 9666 | |
| 9667 | num = get_shared_radio_freqs_data(wpa_s, freqs, num); |
| 9668 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9669 | /* Previous attempt to move a GO was not possible -- try again. */ |
| 9670 | wpas_p2p_consider_moving_gos(wpa_s, freqs, num, |
| 9671 | WPAS_P2P_CHANNEL_UPDATE_ANY); |
| 9672 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9673 | os_free(freqs); |
| 9674 | } |
| 9675 | |
| 9676 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9677 | /* |
| 9678 | * Consider moving a GO from its currently used frequency: |
| 9679 | * 1. It is possible that due to regulatory consideration the frequency |
| 9680 | * can no longer be used and there is a need to evacuate the GO. |
| 9681 | * 2. It is possible that due to MCC considerations, it would be preferable |
| 9682 | * to move the GO to a channel that is currently used by some other |
| 9683 | * station interface. |
| 9684 | * |
| 9685 | * In case a frequency that became invalid is once again valid, cancel a |
| 9686 | * previously initiated GO frequency change. |
| 9687 | */ |
| 9688 | static void wpas_p2p_consider_moving_one_go(struct wpa_supplicant *wpa_s, |
| 9689 | struct wpa_used_freq_data *freqs, |
| 9690 | unsigned int num) |
| 9691 | { |
| 9692 | unsigned int i, invalid_freq = 0, policy_move = 0, flags = 0; |
| 9693 | unsigned int timeout; |
| 9694 | int freq; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9695 | int dfs_offload; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9696 | |
| 9697 | wpas_p2p_go_update_common_freqs(wpa_s); |
| 9698 | |
| 9699 | freq = wpa_s->current_ssid->frequency; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9700 | dfs_offload = (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9701 | 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] | 9702 | for (i = 0, invalid_freq = 0; i < num; i++) { |
| 9703 | if (freqs[i].freq == freq) { |
| 9704 | flags = freqs[i].flags; |
| 9705 | |
| 9706 | /* The channel is invalid, must change it */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9707 | if (!p2p_supported_freq_go(wpa_s->global->p2p, freq) && |
| 9708 | !dfs_offload) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9709 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9710 | "P2P: Freq=%d MHz no longer valid for GO", |
| 9711 | freq); |
| 9712 | invalid_freq = 1; |
| 9713 | } |
| 9714 | } else if (freqs[i].flags == 0) { |
| 9715 | /* Freq is not used by any other station interface */ |
| 9716 | continue; |
| 9717 | } else if (!p2p_supported_freq(wpa_s->global->p2p, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9718 | freqs[i].freq) && !dfs_offload) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9719 | /* Freq is not valid for P2P use cases */ |
| 9720 | continue; |
| 9721 | } else if (wpa_s->conf->p2p_go_freq_change_policy == |
| 9722 | P2P_GO_FREQ_MOVE_SCM) { |
| 9723 | policy_move = 1; |
| 9724 | } else if (wpa_s->conf->p2p_go_freq_change_policy == |
| 9725 | P2P_GO_FREQ_MOVE_SCM_PEER_SUPPORTS && |
| 9726 | wpas_p2p_go_is_peer_freq(wpa_s, freqs[i].freq)) { |
| 9727 | policy_move = 1; |
| 9728 | } else if ((wpa_s->conf->p2p_go_freq_change_policy == |
| 9729 | P2P_GO_FREQ_MOVE_SCM_ECSA) && |
| 9730 | wpas_p2p_go_is_peer_freq(wpa_s, freqs[i].freq)) { |
| 9731 | if (!p2p_get_group_num_members(wpa_s->p2p_group)) { |
| 9732 | policy_move = 1; |
| 9733 | } else if ((wpa_s->drv_flags & |
| 9734 | WPA_DRIVER_FLAGS_AP_CSA) && |
| 9735 | wpas_p2p_go_clients_support_ecsa(wpa_s)) { |
| 9736 | u8 chan; |
| 9737 | |
| 9738 | /* |
| 9739 | * We do not support CSA between bands, so move |
| 9740 | * GO only within the same band. |
| 9741 | */ |
| 9742 | if (wpa_s->ap_iface->current_mode->mode == |
| 9743 | ieee80211_freq_to_chan(freqs[i].freq, |
| 9744 | &chan)) |
| 9745 | policy_move = 1; |
| 9746 | } |
| 9747 | } |
| 9748 | } |
| 9749 | |
| 9750 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9751 | "P2P: GO move: invalid_freq=%u, policy_move=%u, flags=0x%X", |
| 9752 | invalid_freq, policy_move, flags); |
| 9753 | |
| 9754 | /* |
| 9755 | * The channel is valid, or we are going to have a policy move, so |
| 9756 | * cancel timeout. |
| 9757 | */ |
| 9758 | if (!invalid_freq || policy_move) { |
| 9759 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9760 | "P2P: Cancel a GO move from freq=%d MHz", freq); |
| 9761 | eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL); |
| 9762 | |
| 9763 | if (wpas_p2p_in_progress(wpa_s)) { |
| 9764 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9765 | "P2P: GO move: policy CS is not allowed - setting timeout to re-consider GO move"); |
| 9766 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, |
| 9767 | wpa_s, NULL); |
| 9768 | eloop_register_timeout(P2P_RECONSIDER_GO_MOVE_DELAY, 0, |
| 9769 | wpas_p2p_reconsider_moving_go, |
| 9770 | wpa_s, NULL); |
| 9771 | return; |
| 9772 | } |
| 9773 | } |
| 9774 | |
| 9775 | if (!invalid_freq && (!policy_move || flags != 0)) { |
| 9776 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9777 | "P2P: Not initiating a GO frequency change"); |
| 9778 | return; |
| 9779 | } |
| 9780 | |
| 9781 | /* |
| 9782 | * Do not consider moving GO if it is in the middle of a CSA. When the |
| 9783 | * CSA is finished this flow should be retriggered. |
| 9784 | */ |
| 9785 | if (hostapd_csa_in_progress(wpa_s->ap_iface)) { |
| 9786 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9787 | "P2P: Not initiating a GO frequency change - CSA is in progress"); |
| 9788 | return; |
| 9789 | } |
| 9790 | |
| 9791 | if (invalid_freq && !wpas_p2p_disallowed_freq(wpa_s->global, freq)) |
| 9792 | timeout = P2P_GO_FREQ_CHANGE_TIME; |
| 9793 | else |
| 9794 | timeout = 0; |
| 9795 | |
| 9796 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Move GO from freq=%d MHz in %d secs", |
| 9797 | freq, timeout); |
| 9798 | eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL); |
| 9799 | eloop_register_timeout(timeout, 0, wpas_p2p_move_go, wpa_s, NULL); |
| 9800 | } |
| 9801 | |
| 9802 | |
| 9803 | static void wpas_p2p_consider_moving_gos(struct wpa_supplicant *wpa_s, |
| 9804 | struct wpa_used_freq_data *freqs, |
| 9805 | unsigned int num, |
| 9806 | enum wpas_p2p_channel_update_trig trig) |
| 9807 | { |
| 9808 | struct wpa_supplicant *ifs; |
| 9809 | |
| 9810 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, ELOOP_ALL_CTX, |
| 9811 | NULL); |
| 9812 | |
| 9813 | /* |
| 9814 | * Travers all the radio interfaces, and for each GO interface, check |
| 9815 | * if there is a need to move the GO from the frequency it is using, |
| 9816 | * or in case the frequency is valid again, cancel the evacuation flow. |
| 9817 | */ |
| 9818 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 9819 | radio_list) { |
| 9820 | if (ifs->current_ssid == NULL || |
| 9821 | ifs->current_ssid->mode != WPAS_MODE_P2P_GO) |
| 9822 | continue; |
| 9823 | |
| 9824 | /* |
| 9825 | * The GO was just started or completed channel switch, no need |
| 9826 | * to move it. |
| 9827 | */ |
| 9828 | if (wpa_s == ifs && |
| 9829 | (trig == WPAS_P2P_CHANNEL_UPDATE_STATE_CHANGE || |
| 9830 | trig == WPAS_P2P_CHANNEL_UPDATE_CS)) { |
| 9831 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9832 | "P2P: GO move - schedule re-consideration"); |
| 9833 | eloop_register_timeout(P2P_RECONSIDER_GO_MOVE_DELAY, 0, |
| 9834 | wpas_p2p_reconsider_moving_go, |
| 9835 | wpa_s, NULL); |
| 9836 | continue; |
| 9837 | } |
| 9838 | |
| 9839 | wpas_p2p_consider_moving_one_go(ifs, freqs, num); |
| 9840 | } |
| 9841 | } |
| 9842 | |
| 9843 | |
| 9844 | void wpas_p2p_indicate_state_change(struct wpa_supplicant *wpa_s) |
| 9845 | { |
| 9846 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) |
| 9847 | return; |
| 9848 | |
| 9849 | wpas_p2p_update_channel_list(wpa_s, |
| 9850 | WPAS_P2P_CHANNEL_UPDATE_STATE_CHANGE); |
| 9851 | } |
| 9852 | |
| 9853 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9854 | void wpas_p2p_deinit_iface(struct wpa_supplicant *wpa_s) |
| 9855 | { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9856 | if (wpa_s == wpa_s->global->p2p_init_wpa_s && wpa_s->global->p2p) { |
| 9857 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disable P2P since removing " |
| 9858 | "the management interface is being removed"); |
| 9859 | wpas_p2p_deinit_global(wpa_s->global); |
| 9860 | } |
| 9861 | } |
| 9862 | |
| 9863 | |
| 9864 | void wpas_p2p_ap_deinit(struct wpa_supplicant *wpa_s) |
| 9865 | { |
| 9866 | if (wpa_s->ap_iface->bss) |
| 9867 | wpa_s->ap_iface->bss[0]->p2p_group = NULL; |
| 9868 | wpas_p2p_group_deinit(wpa_s); |
| 9869 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 9870 | |
| 9871 | |
| 9872 | int wpas_p2p_lo_start(struct wpa_supplicant *wpa_s, unsigned int freq, |
| 9873 | unsigned int period, unsigned int interval, |
| 9874 | unsigned int count) |
| 9875 | { |
| 9876 | struct p2p_data *p2p = wpa_s->global->p2p; |
| 9877 | u8 *device_types; |
| 9878 | size_t dev_types_len; |
| 9879 | struct wpabuf *buf; |
| 9880 | int ret; |
| 9881 | |
| 9882 | if (wpa_s->p2p_lo_started) { |
| 9883 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9884 | "P2P Listen offload is already started"); |
| 9885 | return 0; |
| 9886 | } |
| 9887 | |
| 9888 | if (wpa_s->global->p2p == NULL || |
| 9889 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) { |
| 9890 | wpa_printf(MSG_DEBUG, "P2P: Listen offload not supported"); |
| 9891 | return -1; |
| 9892 | } |
| 9893 | |
| 9894 | if (!p2p_supported_freq(wpa_s->global->p2p, freq)) { |
| 9895 | wpa_printf(MSG_ERROR, "P2P: Input channel not supported: %u", |
| 9896 | freq); |
| 9897 | return -1; |
| 9898 | } |
| 9899 | |
| 9900 | /* Get device type */ |
| 9901 | dev_types_len = (wpa_s->conf->num_sec_device_types + 1) * |
| 9902 | WPS_DEV_TYPE_LEN; |
| 9903 | device_types = os_malloc(dev_types_len); |
| 9904 | if (!device_types) |
| 9905 | return -1; |
| 9906 | os_memcpy(device_types, wpa_s->conf->device_type, WPS_DEV_TYPE_LEN); |
| 9907 | os_memcpy(&device_types[WPS_DEV_TYPE_LEN], wpa_s->conf->sec_device_type, |
| 9908 | wpa_s->conf->num_sec_device_types * WPS_DEV_TYPE_LEN); |
| 9909 | |
| 9910 | /* Get Probe Response IE(s) */ |
| 9911 | buf = p2p_build_probe_resp_template(p2p, freq); |
| 9912 | if (!buf) { |
| 9913 | os_free(device_types); |
| 9914 | return -1; |
| 9915 | } |
| 9916 | |
| 9917 | ret = wpa_drv_p2p_lo_start(wpa_s, freq, period, interval, count, |
| 9918 | device_types, dev_types_len, |
| 9919 | wpabuf_mhead_u8(buf), wpabuf_len(buf)); |
| 9920 | if (ret < 0) |
| 9921 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9922 | "P2P: Failed to start P2P listen offload"); |
| 9923 | |
| 9924 | os_free(device_types); |
| 9925 | wpabuf_free(buf); |
| 9926 | |
| 9927 | if (ret == 0) { |
| 9928 | wpa_s->p2p_lo_started = 1; |
| 9929 | |
| 9930 | /* Stop current P2P listen if any */ |
| 9931 | wpas_stop_listen(wpa_s); |
| 9932 | } |
| 9933 | |
| 9934 | return ret; |
| 9935 | } |
| 9936 | |
| 9937 | |
| 9938 | int wpas_p2p_lo_stop(struct wpa_supplicant *wpa_s) |
| 9939 | { |
| 9940 | int ret; |
| 9941 | |
| 9942 | if (!wpa_s->p2p_lo_started) |
| 9943 | return 0; |
| 9944 | |
| 9945 | ret = wpa_drv_p2p_lo_stop(wpa_s); |
| 9946 | if (ret < 0) |
| 9947 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 9948 | "P2P: Failed to stop P2P listen offload"); |
| 9949 | |
| 9950 | wpa_s->p2p_lo_started = 0; |
| 9951 | return ret; |
| 9952 | } |