| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * wpa_supplicant - P2P | 
|  | 3 | * Copyright (c) 2009-2010, Atheros Communications | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4 | * Copyright (c) 2010-2014, Jouni Malinen <j@w1.fi> | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5 | * | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6 | * This software may be distributed under the terms of the BSD license. | 
|  | 7 | * See README for more details. | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8 | */ | 
|  | 9 |  | 
|  | 10 | #include "includes.h" | 
|  | 11 |  | 
|  | 12 | #include "common.h" | 
|  | 13 | #include "eloop.h" | 
|  | 14 | #include "common/ieee802_11_common.h" | 
|  | 15 | #include "common/ieee802_11_defs.h" | 
|  | 16 | #include "common/wpa_ctrl.h" | 
|  | 17 | #include "wps/wps_i.h" | 
|  | 18 | #include "p2p/p2p.h" | 
|  | 19 | #include "ap/hostapd.h" | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 20 | #include "ap/ap_config.h" | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 21 | #include "ap/sta_info.h" | 
|  | 22 | #include "ap/ap_drv_ops.h" | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 23 | #include "ap/wps_hostapd.h" | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 24 | #include "ap/p2p_hostapd.h" | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 25 | #include "ap/dfs.h" | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 26 | #include "eapol_supp/eapol_supp_sm.h" | 
|  | 27 | #include "rsn_supp/wpa.h" | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 28 | #include "wpa_supplicant_i.h" | 
|  | 29 | #include "driver_i.h" | 
|  | 30 | #include "ap.h" | 
|  | 31 | #include "config_ssid.h" | 
|  | 32 | #include "config.h" | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 33 | #include "notify.h" | 
|  | 34 | #include "scan.h" | 
|  | 35 | #include "bss.h" | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 36 | #include "offchannel.h" | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 37 | #include "wps_supplicant.h" | 
|  | 38 | #include "p2p_supplicant.h" | 
| Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 39 | #include "wifi_display.h" | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 40 |  | 
|  | 41 |  | 
|  | 42 | /* | 
|  | 43 | * How many times to try to scan to find the GO before giving up on join | 
|  | 44 | * request. | 
|  | 45 | */ | 
|  | 46 | #define P2P_MAX_JOIN_SCAN_ATTEMPTS 10 | 
|  | 47 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 48 | #define P2P_AUTO_PD_SCAN_ATTEMPTS 5 | 
|  | 49 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 50 | /** | 
|  | 51 | * Defines time interval in seconds when a GO needs to evacuate a frequency that | 
|  | 52 | * it is currently using, but is no longer valid for P2P use cases. | 
|  | 53 | */ | 
|  | 54 | #define P2P_GO_FREQ_CHANGE_TIME 5 | 
|  | 55 |  | 
|  | 56 | /** | 
|  | 57 | * Defines CSA parameters which are used when GO evacuates the no longer valid | 
|  | 58 | * channel (and if the driver supports channel switch). | 
|  | 59 | */ | 
|  | 60 | #define P2P_GO_CSA_COUNT 7 | 
|  | 61 | #define P2P_GO_CSA_BLOCK_TX 0 | 
|  | 62 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 63 | #ifndef P2P_MAX_CLIENT_IDLE | 
|  | 64 | /* | 
|  | 65 | * How many seconds to try to reconnect to the GO when connection in P2P client | 
|  | 66 | * role has been lost. | 
|  | 67 | */ | 
|  | 68 | #define P2P_MAX_CLIENT_IDLE 10 | 
|  | 69 | #endif /* P2P_MAX_CLIENT_IDLE */ | 
|  | 70 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 71 | #ifndef P2P_MAX_INITIAL_CONN_WAIT | 
|  | 72 | /* | 
|  | 73 | * How many seconds to wait for initial 4-way handshake to get completed after | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 74 | * WPS provisioning step or after the re-invocation of a persistent group on a | 
|  | 75 | * P2P Client. | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 76 | */ | 
|  | 77 | #define P2P_MAX_INITIAL_CONN_WAIT 10 | 
|  | 78 | #endif /* P2P_MAX_INITIAL_CONN_WAIT */ | 
|  | 79 |  | 
| Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 80 | #ifndef P2P_MAX_INITIAL_CONN_WAIT_GO | 
|  | 81 | /* | 
|  | 82 | * How many seconds to wait for initial 4-way handshake to get completed after | 
|  | 83 | * WPS provisioning step on the GO. This controls the extra time the P2P | 
|  | 84 | * operation is considered to be in progress (e.g., to delay other scans) after | 
|  | 85 | * WPS provisioning has been completed on the GO during group formation. | 
|  | 86 | */ | 
|  | 87 | #define P2P_MAX_INITIAL_CONN_WAIT_GO 10 | 
|  | 88 | #endif /* P2P_MAX_INITIAL_CONN_WAIT_GO */ | 
|  | 89 |  | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 90 | #ifndef P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE | 
|  | 91 | /* | 
|  | 92 | * How many seconds to wait for initial 4-way handshake to get completed after | 
|  | 93 | * re-invocation of a persistent group on the GO when the client is expected | 
|  | 94 | * to connect automatically (no user interaction). | 
|  | 95 | */ | 
|  | 96 | #define P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE 15 | 
|  | 97 | #endif /* P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE */ | 
|  | 98 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 99 | #define P2P_MGMT_DEVICE_PREFIX		"p2p-dev-" | 
|  | 100 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 101 | /* | 
|  | 102 | * How many seconds to wait to re-attempt to move GOs, in case previous attempt | 
|  | 103 | * was not possible. | 
|  | 104 | */ | 
|  | 105 | #define P2P_RECONSIDER_GO_MOVE_DELAY 30 | 
|  | 106 |  | 
| Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 107 | /* Check if frequency is 2GHz */ | 
|  | 108 | #define	IS_2GHZ(n)	(n >= 2412 && n <= 2484) | 
|  | 109 |  | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 110 | enum p2p_group_removal_reason { | 
|  | 111 | P2P_GROUP_REMOVAL_UNKNOWN, | 
|  | 112 | P2P_GROUP_REMOVAL_SILENT, | 
|  | 113 | P2P_GROUP_REMOVAL_FORMATION_FAILED, | 
|  | 114 | P2P_GROUP_REMOVAL_REQUESTED, | 
|  | 115 | P2P_GROUP_REMOVAL_IDLE_TIMEOUT, | 
|  | 116 | P2P_GROUP_REMOVAL_UNAVAILABLE, | 
|  | 117 | P2P_GROUP_REMOVAL_GO_ENDING_SESSION, | 
| Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 118 | P2P_GROUP_REMOVAL_PSK_FAILURE, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 119 | P2P_GROUP_REMOVAL_FREQ_CONFLICT, | 
|  | 120 | P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 121 | }; | 
|  | 122 |  | 
| Jouni Malinen | dc7b713 | 2012-09-14 12:53:47 -0700 | [diff] [blame] | 123 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 124 | static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx); | 
|  | 125 | static struct wpa_supplicant * | 
|  | 126 | wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated, | 
|  | 127 | int go); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 128 | static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s, int freq, | 
|  | 129 | const u8 *ssid, size_t ssid_len); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 130 | static int wpas_p2p_setup_freqs(struct wpa_supplicant *wpa_s, int freq, | 
|  | 131 | int *force_freq, int *pref_freq, int go, | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 132 | struct weighted_pcl *pref_freq_list, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 133 | unsigned int *num_pref_freq); | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 134 | static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq, | 
|  | 135 | const u8 *ssid, size_t ssid_len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 136 | static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx); | 
|  | 137 | static int wpas_p2p_join(struct wpa_supplicant *wpa_s, const u8 *iface_addr, | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 138 | const u8 *dev_addr, enum p2p_wps_method wps_method, | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 139 | int auto_join, int freq, | 
|  | 140 | const u8 *ssid, size_t ssid_len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 141 | static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s); | 
|  | 142 | static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s); | 
|  | 143 | static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx); | 
|  | 144 | static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s); | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 145 | static void wpas_p2p_group_formation_timeout(void *eloop_ctx, | 
|  | 146 | void *timeout_ctx); | 
| Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 147 | static void wpas_p2p_group_freq_conflict(void *eloop_ctx, void *timeout_ctx); | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 148 | static int wpas_p2p_fallback_to_go_neg(struct wpa_supplicant *wpa_s, | 
|  | 149 | int group_added); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 150 | static void wpas_p2p_stop_find_oper(struct wpa_supplicant *wpa_s); | 
| Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 151 | static void wpas_stop_listen(void *ctx); | 
| Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 152 | static void wpas_p2p_psk_failure_removal(void *eloop_ctx, void *timeout_ctx); | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 153 | static void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 154 | static int wpas_p2p_add_group_interface(struct wpa_supplicant *wpa_s, | 
|  | 155 | enum wpa_driver_if_type type); | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 156 | static void wpas_p2p_group_formation_failed(struct wpa_supplicant *wpa_s, | 
|  | 157 | int already_deleted); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 158 | static void wpas_p2p_optimize_listen_channel(struct wpa_supplicant *wpa_s, | 
|  | 159 | struct wpa_used_freq_data *freqs, | 
|  | 160 | unsigned int num); | 
|  | 161 | static void wpas_p2p_move_go(void *eloop_ctx, void *timeout_ctx); | 
|  | 162 | static int wpas_p2p_go_is_peer_freq(struct wpa_supplicant *wpa_s, int freq); | 
|  | 163 | static void | 
|  | 164 | wpas_p2p_consider_moving_gos(struct wpa_supplicant *wpa_s, | 
|  | 165 | struct wpa_used_freq_data *freqs, unsigned int num, | 
|  | 166 | enum wpas_p2p_channel_update_trig trig); | 
|  | 167 | static void wpas_p2p_reconsider_moving_go(void *eloop_ctx, void *timeout_ctx); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 168 |  | 
|  | 169 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 170 | static int wpas_get_6ghz_he_chwidth_capab(struct hostapd_hw_modes *mode) | 
|  | 171 | { | 
|  | 172 | int he_capab = 0; | 
|  | 173 |  | 
|  | 174 | if (mode) | 
|  | 175 | he_capab = mode->he_capab[WPAS_MODE_INFRA].phy_cap[ | 
|  | 176 | HE_PHYCAP_CHANNEL_WIDTH_SET_IDX]; | 
|  | 177 | return he_capab; | 
|  | 178 | } | 
|  | 179 |  | 
|  | 180 |  | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 181 | /* | 
|  | 182 | * Get the number of concurrent channels that the HW can operate, but that are | 
|  | 183 | * currently not in use by any of the wpa_supplicant interfaces. | 
|  | 184 | */ | 
|  | 185 | static int wpas_p2p_num_unused_channels(struct wpa_supplicant *wpa_s) | 
|  | 186 | { | 
|  | 187 | int *freqs; | 
| Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 188 | int num, unused; | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 189 |  | 
|  | 190 | freqs = os_calloc(wpa_s->num_multichan_concurrent, sizeof(int)); | 
|  | 191 | if (!freqs) | 
|  | 192 | return -1; | 
|  | 193 |  | 
|  | 194 | num = get_shared_radio_freqs(wpa_s, freqs, | 
|  | 195 | wpa_s->num_multichan_concurrent); | 
|  | 196 | os_free(freqs); | 
|  | 197 |  | 
| Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 198 | unused = wpa_s->num_multichan_concurrent - num; | 
|  | 199 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: num_unused_channels: %d", unused); | 
|  | 200 | return unused; | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 201 | } | 
|  | 202 |  | 
|  | 203 |  | 
|  | 204 | /* | 
|  | 205 | * Get the frequencies that are currently in use by one or more of the virtual | 
|  | 206 | * interfaces, and that are also valid for P2P operation. | 
|  | 207 | */ | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 208 | static unsigned int | 
|  | 209 | wpas_p2p_valid_oper_freqs(struct wpa_supplicant *wpa_s, | 
|  | 210 | struct wpa_used_freq_data *p2p_freqs, | 
|  | 211 | unsigned int len) | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 212 | { | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 213 | struct wpa_used_freq_data *freqs; | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 214 | unsigned int num, i, j; | 
|  | 215 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 216 | freqs = os_calloc(wpa_s->num_multichan_concurrent, | 
|  | 217 | sizeof(struct wpa_used_freq_data)); | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 218 | if (!freqs) | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 219 | return 0; | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 220 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 221 | num = get_shared_radio_freqs_data(wpa_s, freqs, | 
|  | 222 | wpa_s->num_multichan_concurrent); | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 223 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 224 | os_memset(p2p_freqs, 0, sizeof(struct wpa_used_freq_data) * len); | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 225 |  | 
|  | 226 | for (i = 0, j = 0; i < num && j < len; i++) { | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 227 | if (p2p_supported_freq(wpa_s->global->p2p, freqs[i].freq)) | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 228 | p2p_freqs[j++] = freqs[i]; | 
|  | 229 | } | 
|  | 230 |  | 
|  | 231 | os_free(freqs); | 
|  | 232 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 233 | dump_freq_data(wpa_s, "valid for P2P", p2p_freqs, j); | 
| Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 234 |  | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 235 | return j; | 
|  | 236 | } | 
|  | 237 |  | 
|  | 238 |  | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 239 | static void wpas_p2p_set_own_freq_preference(struct wpa_supplicant *wpa_s, | 
|  | 240 | int freq) | 
|  | 241 | { | 
|  | 242 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 243 | return; | 
| Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 244 |  | 
|  | 245 | /* Use the wpa_s used to control the P2P Device operation */ | 
|  | 246 | wpa_s = wpa_s->global->p2p_init_wpa_s; | 
|  | 247 |  | 
|  | 248 | if (wpa_s->conf->p2p_ignore_shared_freq && | 
| Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 249 | freq > 0 && wpa_s->num_multichan_concurrent > 1 && | 
|  | 250 | wpas_p2p_num_unused_channels(wpa_s) > 0) { | 
|  | 251 | wpa_printf(MSG_DEBUG, "P2P: Ignore own channel preference %d MHz due to p2p_ignore_shared_freq=1 configuration", | 
|  | 252 | freq); | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 253 | freq = 0; | 
| Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 254 | } | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 255 | p2p_set_own_freq_preference(wpa_s->global->p2p, freq); | 
|  | 256 | } | 
|  | 257 |  | 
|  | 258 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 259 | static void wpas_p2p_scan_res_handled(struct wpa_supplicant *wpa_s) | 
|  | 260 | { | 
|  | 261 | unsigned int delay = wpas_p2p_search_delay(wpa_s); | 
|  | 262 |  | 
|  | 263 | /* In case of concurrent P2P and external scans, delay P2P search. */ | 
|  | 264 | if (external_scan_running(wpa_s->radio)) { | 
|  | 265 | delay = wpa_s->conf->p2p_search_delay; | 
|  | 266 | wpa_printf(MSG_DEBUG, | 
|  | 267 | "P2P: Delay next P2P search by %d ms to let externally triggered scan complete", | 
|  | 268 | delay); | 
|  | 269 | } | 
|  | 270 |  | 
|  | 271 | p2p_scan_res_handled(wpa_s->global->p2p, delay); | 
|  | 272 | } | 
|  | 273 |  | 
|  | 274 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 275 | static void wpas_p2p_scan_res_handler(struct wpa_supplicant *wpa_s, | 
|  | 276 | struct wpa_scan_results *scan_res) | 
|  | 277 | { | 
|  | 278 | size_t i; | 
|  | 279 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 280 | if (wpa_s->p2p_scan_work) { | 
|  | 281 | struct wpa_radio_work *work = wpa_s->p2p_scan_work; | 
|  | 282 | wpa_s->p2p_scan_work = NULL; | 
|  | 283 | radio_work_done(work); | 
|  | 284 | } | 
|  | 285 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 286 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 287 | return; | 
|  | 288 |  | 
|  | 289 | wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS)", | 
|  | 290 | (int) scan_res->num); | 
|  | 291 |  | 
|  | 292 | for (i = 0; i < scan_res->num; i++) { | 
|  | 293 | struct wpa_scan_res *bss = scan_res->res[i]; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 294 | struct os_reltime time_tmp_age, entry_ts; | 
| Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 295 | const u8 *ies; | 
|  | 296 | size_t ies_len; | 
|  | 297 |  | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 298 | time_tmp_age.sec = bss->age / 1000; | 
|  | 299 | time_tmp_age.usec = (bss->age % 1000) * 1000; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 300 | os_reltime_sub(&scan_res->fetch_time, &time_tmp_age, &entry_ts); | 
| Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 301 |  | 
|  | 302 | ies = (const u8 *) (bss + 1); | 
|  | 303 | ies_len = bss->ie_len; | 
|  | 304 | if (bss->beacon_ie_len > 0 && | 
|  | 305 | !wpa_scan_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) && | 
|  | 306 | wpa_scan_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { | 
|  | 307 | wpa_printf(MSG_DEBUG, "P2P: Use P2P IE(s) from Beacon frame since no P2P IE(s) in Probe Response frames received for " | 
|  | 308 | MACSTR, MAC2STR(bss->bssid)); | 
|  | 309 | ies = ies + ies_len; | 
|  | 310 | ies_len = bss->beacon_ie_len; | 
|  | 311 | } | 
|  | 312 |  | 
|  | 313 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 314 | if (p2p_scan_res_handler(wpa_s->global->p2p, bss->bssid, | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 315 | bss->freq, &entry_ts, bss->level, | 
| Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 316 | ies, ies_len) > 0) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 317 | break; | 
|  | 318 | } | 
|  | 319 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 320 | wpas_p2p_scan_res_handled(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 321 | } | 
|  | 322 |  | 
|  | 323 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 324 | static void wpas_p2p_scan_res_fail_handler(struct wpa_supplicant *wpa_s) | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 325 | { | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 326 | if (wpa_s->p2p_scan_work) { | 
|  | 327 | struct wpa_radio_work *work = wpa_s->p2p_scan_work; | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 328 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 329 | wpa_s->p2p_scan_work = NULL; | 
|  | 330 | radio_work_done(work); | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 331 | } | 
|  | 332 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 333 | if (wpa_s->global->p2p_disabled || !wpa_s->global->p2p) | 
|  | 334 | return; | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 335 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 336 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 337 | "P2P: Failed to get scan results - try to continue"); | 
|  | 338 | wpas_p2p_scan_res_handled(wpa_s); | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 339 | } | 
|  | 340 |  | 
|  | 341 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 342 | static void wpas_p2p_trigger_scan_cb(struct wpa_radio_work *work, int deinit) | 
|  | 343 | { | 
|  | 344 | struct wpa_supplicant *wpa_s = work->wpa_s; | 
|  | 345 | struct wpa_driver_scan_params *params = work->ctx; | 
|  | 346 | int ret; | 
|  | 347 |  | 
|  | 348 | if (deinit) { | 
| Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 349 | if (!work->started) { | 
|  | 350 | wpa_scan_free_params(params); | 
|  | 351 | return; | 
|  | 352 | } | 
|  | 353 |  | 
|  | 354 | wpa_s->p2p_scan_work = NULL; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 355 | return; | 
|  | 356 | } | 
|  | 357 |  | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 358 | if (wpa_s->clear_driver_scan_cache) { | 
|  | 359 | wpa_printf(MSG_DEBUG, | 
|  | 360 | "Request driver to clear scan cache due to local BSS flush"); | 
|  | 361 | params->only_new_results = 1; | 
|  | 362 | } | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 363 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 364 | if (!params->p2p_include_6ghz && !params->freqs) { | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 365 | wpa_printf(MSG_DEBUG, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 366 | "P2P: Exclude 6 GHz channels - update the scan frequency list"); | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 367 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211G, params, | 
|  | 368 | 0); | 
|  | 369 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, params, | 
|  | 370 | 0); | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 371 | } | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 372 | ret = wpa_drv_scan(wpa_s, params); | 
| Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 373 | if (ret == 0) | 
|  | 374 | wpa_s->curr_scan_cookie = params->scan_cookie; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 375 | wpa_scan_free_params(params); | 
|  | 376 | work->ctx = NULL; | 
|  | 377 | if (ret) { | 
|  | 378 | radio_work_done(work); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 379 | p2p_notify_scan_trigger_status(wpa_s->global->p2p, ret); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 380 | return; | 
|  | 381 | } | 
|  | 382 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 383 | p2p_notify_scan_trigger_status(wpa_s->global->p2p, ret); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 384 | os_get_reltime(&wpa_s->scan_trigger_time); | 
|  | 385 | wpa_s->scan_res_handler = wpas_p2p_scan_res_handler; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 386 | wpa_s->scan_res_fail_handler = wpas_p2p_scan_res_fail_handler; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 387 | wpa_s->own_scan_requested = 1; | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 388 | wpa_s->clear_driver_scan_cache = 0; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 389 | wpa_s->p2p_scan_work = work; | 
|  | 390 | } | 
|  | 391 |  | 
|  | 392 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 393 | static int wpas_p2p_search_social_channel(struct wpa_supplicant *wpa_s, | 
|  | 394 | int freq) | 
|  | 395 | { | 
|  | 396 | if (wpa_s->global->p2p_24ghz_social_channels && | 
|  | 397 | (freq == 2412 || freq == 2437 || freq == 2462)) { | 
|  | 398 | /* | 
|  | 399 | * Search all social channels regardless of whether these have | 
|  | 400 | * been disabled for P2P operating channel use to avoid missing | 
|  | 401 | * peers. | 
|  | 402 | */ | 
|  | 403 | return 1; | 
|  | 404 | } | 
|  | 405 | return p2p_supported_freq(wpa_s->global->p2p, freq); | 
|  | 406 | } | 
|  | 407 |  | 
|  | 408 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 409 | static int wpas_p2p_scan(void *ctx, enum p2p_scan_type type, int freq, | 
|  | 410 | unsigned int num_req_dev_types, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 411 | const u8 *req_dev_types, const u8 *dev_id, u16 pw_id, | 
|  | 412 | bool include_6ghz) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 413 | { | 
|  | 414 | struct wpa_supplicant *wpa_s = ctx; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 415 | struct wpa_driver_scan_params *params = NULL; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 416 | struct wpabuf *wps_ie, *ies; | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 417 | unsigned int num_channels = 0; | 
|  | 418 | int social_channels_freq[] = { 2412, 2437, 2462, 60480 }; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 419 | size_t ielen; | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 420 | u8 *n, i; | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 421 | unsigned int bands; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 422 |  | 
|  | 423 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 424 | return -1; | 
|  | 425 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 426 | if (wpa_s->p2p_scan_work) { | 
|  | 427 | wpa_dbg(wpa_s, MSG_INFO, "P2P: Reject scan trigger since one is already pending"); | 
|  | 428 | return -1; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 429 | } | 
|  | 430 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 431 | params = os_zalloc(sizeof(*params)); | 
|  | 432 | if (params == NULL) | 
|  | 433 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 434 |  | 
|  | 435 | /* P2P Wildcard SSID */ | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 436 | params->num_ssids = 1; | 
|  | 437 | n = os_malloc(P2P_WILDCARD_SSID_LEN); | 
|  | 438 | if (n == NULL) | 
|  | 439 | goto fail; | 
|  | 440 | os_memcpy(n, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN); | 
|  | 441 | params->ssids[0].ssid = n; | 
|  | 442 | params->ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 443 |  | 
|  | 444 | wpa_s->wps->dev.p2p = 1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 445 | wps_ie = wps_build_probe_req_ie(pw_id, &wpa_s->wps->dev, | 
|  | 446 | wpa_s->wps->uuid, WPS_REQ_ENROLLEE, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 447 | num_req_dev_types, req_dev_types); | 
|  | 448 | if (wps_ie == NULL) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 449 | goto fail; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 450 | if (!wpa_s->conf->p2p_6ghz_disable) | 
|  | 451 | params->p2p_include_6ghz = include_6ghz; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 452 | switch (type) { | 
|  | 453 | case P2P_SCAN_SOCIAL: | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 454 | params->freqs = os_calloc(ARRAY_SIZE(social_channels_freq) + 1, | 
|  | 455 | sizeof(int)); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 456 | if (params->freqs == NULL) | 
|  | 457 | goto fail; | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 458 | for (i = 0; i < ARRAY_SIZE(social_channels_freq); i++) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 459 | if (wpas_p2p_search_social_channel( | 
|  | 460 | wpa_s, social_channels_freq[i])) | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 461 | params->freqs[num_channels++] = | 
|  | 462 | social_channels_freq[i]; | 
|  | 463 | } | 
|  | 464 | params->freqs[num_channels++] = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 465 | break; | 
|  | 466 | case P2P_SCAN_FULL: | 
|  | 467 | break; | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 468 | case P2P_SCAN_SPECIFIC: | 
|  | 469 | params->freqs = os_calloc(2, sizeof(int)); | 
|  | 470 | if (params->freqs == NULL) | 
|  | 471 | goto fail; | 
|  | 472 | params->freqs[0] = freq; | 
|  | 473 | params->freqs[1] = 0; | 
|  | 474 | break; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 475 | case P2P_SCAN_SOCIAL_PLUS_ONE: | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 476 | params->freqs = os_calloc(ARRAY_SIZE(social_channels_freq) + 2, | 
|  | 477 | sizeof(int)); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 478 | if (params->freqs == NULL) | 
|  | 479 | goto fail; | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 480 | for (i = 0; i < ARRAY_SIZE(social_channels_freq); i++) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 481 | if (wpas_p2p_search_social_channel( | 
|  | 482 | wpa_s, social_channels_freq[i])) | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 483 | params->freqs[num_channels++] = | 
|  | 484 | social_channels_freq[i]; | 
|  | 485 | } | 
|  | 486 | if (p2p_supported_freq(wpa_s->global->p2p, freq)) | 
|  | 487 | params->freqs[num_channels++] = freq; | 
|  | 488 | params->freqs[num_channels++] = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 489 | break; | 
|  | 490 | } | 
|  | 491 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 492 | ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p); | 
|  | 493 | ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen); | 
|  | 494 | if (ies == NULL) { | 
|  | 495 | wpabuf_free(wps_ie); | 
|  | 496 | goto fail; | 
|  | 497 | } | 
|  | 498 | wpabuf_put_buf(ies, wps_ie); | 
|  | 499 | wpabuf_free(wps_ie); | 
|  | 500 |  | 
|  | 501 | bands = wpas_get_bands(wpa_s, params->freqs); | 
|  | 502 | p2p_scan_ie(wpa_s->global->p2p, ies, dev_id, bands); | 
|  | 503 |  | 
|  | 504 | params->p2p_probe = 1; | 
|  | 505 | n = os_malloc(wpabuf_len(ies)); | 
|  | 506 | if (n == NULL) { | 
|  | 507 | wpabuf_free(ies); | 
|  | 508 | goto fail; | 
|  | 509 | } | 
|  | 510 | os_memcpy(n, wpabuf_head(ies), wpabuf_len(ies)); | 
|  | 511 | params->extra_ies = n; | 
|  | 512 | params->extra_ies_len = wpabuf_len(ies); | 
|  | 513 | wpabuf_free(ies); | 
|  | 514 |  | 
| Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 515 | radio_remove_works(wpa_s, "p2p-scan", 0); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 516 | if (radio_add_work(wpa_s, 0, "p2p-scan", 0, wpas_p2p_trigger_scan_cb, | 
|  | 517 | params) < 0) | 
|  | 518 | goto fail; | 
|  | 519 | return 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 520 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 521 | fail: | 
|  | 522 | wpa_scan_free_params(params); | 
|  | 523 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 524 | } | 
|  | 525 |  | 
|  | 526 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 527 | static enum wpa_driver_if_type wpas_p2p_if_type(int p2p_group_interface) | 
|  | 528 | { | 
|  | 529 | switch (p2p_group_interface) { | 
|  | 530 | case P2P_GROUP_INTERFACE_PENDING: | 
|  | 531 | return WPA_IF_P2P_GROUP; | 
|  | 532 | case P2P_GROUP_INTERFACE_GO: | 
|  | 533 | return WPA_IF_P2P_GO; | 
|  | 534 | case P2P_GROUP_INTERFACE_CLIENT: | 
|  | 535 | return WPA_IF_P2P_CLIENT; | 
|  | 536 | } | 
|  | 537 |  | 
|  | 538 | return WPA_IF_P2P_GROUP; | 
|  | 539 | } | 
|  | 540 |  | 
|  | 541 |  | 
|  | 542 | static struct wpa_supplicant * wpas_get_p2p_group(struct wpa_supplicant *wpa_s, | 
|  | 543 | const u8 *ssid, | 
|  | 544 | size_t ssid_len, int *go) | 
|  | 545 | { | 
|  | 546 | struct wpa_ssid *s; | 
|  | 547 |  | 
|  | 548 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 549 | for (s = wpa_s->conf->ssid; s; s = s->next) { | 
|  | 550 | if (s->disabled != 0 || !s->p2p_group || | 
|  | 551 | s->ssid_len != ssid_len || | 
|  | 552 | os_memcmp(ssid, s->ssid, ssid_len) != 0) | 
|  | 553 | continue; | 
|  | 554 | if (s->mode == WPAS_MODE_P2P_GO && | 
|  | 555 | s != wpa_s->current_ssid) | 
|  | 556 | continue; | 
|  | 557 | if (go) | 
|  | 558 | *go = s->mode == WPAS_MODE_P2P_GO; | 
|  | 559 | return wpa_s; | 
|  | 560 | } | 
|  | 561 | } | 
|  | 562 |  | 
|  | 563 | return NULL; | 
|  | 564 | } | 
|  | 565 |  | 
|  | 566 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 567 | static void run_wpas_p2p_disconnect(void *eloop_ctx, void *timeout_ctx) | 
|  | 568 | { | 
|  | 569 | struct wpa_supplicant *wpa_s = eloop_ctx; | 
|  | 570 | wpa_printf(MSG_DEBUG, | 
|  | 571 | "P2P: Complete previously requested removal of %s", | 
|  | 572 | wpa_s->ifname); | 
|  | 573 | wpas_p2p_disconnect(wpa_s); | 
|  | 574 | } | 
|  | 575 |  | 
|  | 576 |  | 
|  | 577 | static int wpas_p2p_disconnect_safely(struct wpa_supplicant *wpa_s, | 
|  | 578 | struct wpa_supplicant *calling_wpa_s) | 
|  | 579 | { | 
|  | 580 | if (calling_wpa_s == wpa_s && wpa_s && | 
|  | 581 | wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) { | 
|  | 582 | /* | 
|  | 583 | * The calling wpa_s instance is going to be removed. Do that | 
|  | 584 | * from an eloop callback to keep the instance available until | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 585 | * the caller has returned. This may be needed, e.g., to provide | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 586 | * control interface responses on the per-interface socket. | 
|  | 587 | */ | 
|  | 588 | if (eloop_register_timeout(0, 0, run_wpas_p2p_disconnect, | 
|  | 589 | wpa_s, NULL) < 0) | 
|  | 590 | return -1; | 
|  | 591 | return 0; | 
|  | 592 | } | 
|  | 593 |  | 
|  | 594 | return wpas_p2p_disconnect(wpa_s); | 
|  | 595 | } | 
|  | 596 |  | 
|  | 597 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 598 | /* Determine total number of clients in active groups where we are the GO */ | 
|  | 599 | static unsigned int p2p_group_go_member_count(struct wpa_supplicant *wpa_s) | 
|  | 600 | { | 
|  | 601 | unsigned int count = 0; | 
|  | 602 | struct wpa_ssid *s; | 
|  | 603 |  | 
|  | 604 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 605 | for (s = wpa_s->conf->ssid; s; s = s->next) { | 
|  | 606 | wpa_printf(MSG_DEBUG, | 
|  | 607 | "P2P: sup:%p ssid:%p disabled:%d p2p:%d mode:%d", | 
|  | 608 | wpa_s, s, s->disabled, s->p2p_group, | 
|  | 609 | s->mode); | 
|  | 610 | if (!s->disabled && s->p2p_group && | 
|  | 611 | s->mode == WPAS_MODE_P2P_GO) { | 
|  | 612 | count += p2p_get_group_num_members( | 
|  | 613 | wpa_s->p2p_group); | 
|  | 614 | } | 
|  | 615 | } | 
|  | 616 | } | 
|  | 617 |  | 
|  | 618 | return count; | 
|  | 619 | } | 
|  | 620 |  | 
|  | 621 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 622 | static unsigned int p2p_is_active_persistent_group(struct wpa_supplicant *wpa_s) | 
|  | 623 | { | 
|  | 624 | return !wpa_s->p2p_mgmt && wpa_s->current_ssid && | 
|  | 625 | !wpa_s->current_ssid->disabled && | 
|  | 626 | wpa_s->current_ssid->p2p_group && | 
|  | 627 | wpa_s->current_ssid->p2p_persistent_group; | 
|  | 628 | } | 
|  | 629 |  | 
|  | 630 |  | 
|  | 631 | static unsigned int p2p_is_active_persistent_go(struct wpa_supplicant *wpa_s) | 
|  | 632 | { | 
|  | 633 | return p2p_is_active_persistent_group(wpa_s) && | 
|  | 634 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO; | 
|  | 635 | } | 
|  | 636 |  | 
|  | 637 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 638 | /* Find an interface for a P2P group where we are the GO */ | 
|  | 639 | static struct wpa_supplicant * | 
|  | 640 | wpas_p2p_get_go_group(struct wpa_supplicant *wpa_s) | 
|  | 641 | { | 
|  | 642 | struct wpa_supplicant *save = NULL; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 643 |  | 
|  | 644 | if (!wpa_s) | 
|  | 645 | return NULL; | 
|  | 646 |  | 
|  | 647 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 648 | if (!p2p_is_active_persistent_go(wpa_s)) | 
|  | 649 | continue; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 650 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 651 | /* Prefer a group with connected clients */ | 
|  | 652 | if (p2p_get_group_num_members(wpa_s->p2p_group)) | 
|  | 653 | return wpa_s; | 
|  | 654 | save = wpa_s; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 655 | } | 
|  | 656 |  | 
|  | 657 | /* No group with connected clients, so pick the one without (if any) */ | 
|  | 658 | return save; | 
|  | 659 | } | 
|  | 660 |  | 
|  | 661 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 662 | static unsigned int p2p_is_active_persistent_cli(struct wpa_supplicant *wpa_s) | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 663 | { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 664 | return p2p_is_active_persistent_group(wpa_s) && | 
|  | 665 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA; | 
|  | 666 | } | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 667 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 668 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 669 | /* Find an interface for a P2P group where we are the P2P Client */ | 
|  | 670 | static struct wpa_supplicant * | 
|  | 671 | wpas_p2p_get_cli_group(struct wpa_supplicant *wpa_s) | 
|  | 672 | { | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 673 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 674 | if (p2p_is_active_persistent_cli(wpa_s)) | 
|  | 675 | return wpa_s; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 676 | } | 
|  | 677 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 678 | return NULL; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 679 | } | 
|  | 680 |  | 
|  | 681 |  | 
|  | 682 | /* Find a persistent group where we are the GO */ | 
|  | 683 | static struct wpa_ssid * | 
|  | 684 | wpas_p2p_get_persistent_go(struct wpa_supplicant *wpa_s) | 
|  | 685 | { | 
|  | 686 | struct wpa_ssid *s; | 
|  | 687 |  | 
|  | 688 | for (s = wpa_s->conf->ssid; s; s = s->next) { | 
|  | 689 | if (s->disabled == 2 && s->mode == WPAS_MODE_P2P_GO) | 
|  | 690 | return s; | 
|  | 691 | } | 
|  | 692 |  | 
|  | 693 | return NULL; | 
|  | 694 | } | 
|  | 695 |  | 
|  | 696 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 697 | static u8 p2ps_group_capability(void *ctx, u8 incoming, u8 role, | 
|  | 698 | unsigned int *force_freq, | 
|  | 699 | unsigned int *pref_freq) | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 700 | { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 701 | struct wpa_supplicant *wpa_s = ctx; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 702 | struct wpa_ssid *s; | 
|  | 703 | u8 conncap = P2PS_SETUP_NONE; | 
|  | 704 | unsigned int owned_members = 0; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 705 | struct wpa_supplicant *go_wpa_s, *cli_wpa_s; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 706 | struct wpa_ssid *persistent_go; | 
|  | 707 | int p2p_no_group_iface; | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 708 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; | 
|  | 709 | unsigned int size; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 710 |  | 
|  | 711 | wpa_printf(MSG_DEBUG, "P2P: Conncap - in:%d role:%d", incoming, role); | 
|  | 712 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 713 | if (force_freq) | 
|  | 714 | *force_freq = 0; | 
|  | 715 | if (pref_freq) | 
|  | 716 | *pref_freq = 0; | 
|  | 717 |  | 
|  | 718 | size = P2P_MAX_PREF_CHANNELS; | 
|  | 719 | if (force_freq && pref_freq && | 
|  | 720 | !wpas_p2p_setup_freqs(wpa_s, 0, (int *) force_freq, | 
|  | 721 | (int *) pref_freq, 0, pref_freq_list, &size)) | 
|  | 722 | wpas_p2p_set_own_freq_preference(wpa_s, | 
|  | 723 | *force_freq ? *force_freq : | 
|  | 724 | *pref_freq); | 
|  | 725 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 726 | /* | 
|  | 727 | * For non-concurrent capable devices: | 
|  | 728 | * If persistent_go, then no new. | 
|  | 729 | * If GO, then no client. | 
|  | 730 | * If client, then no GO. | 
|  | 731 | */ | 
|  | 732 | go_wpa_s = wpas_p2p_get_go_group(wpa_s); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 733 | if (go_wpa_s) | 
|  | 734 | owned_members = p2p_get_group_num_members(go_wpa_s->p2p_group); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 735 | persistent_go = wpas_p2p_get_persistent_go(wpa_s); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 736 | p2p_no_group_iface = !wpas_p2p_create_iface(wpa_s); | 
|  | 737 | cli_wpa_s = wpas_p2p_get_cli_group(wpa_s); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 738 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 739 | wpa_printf(MSG_DEBUG, | 
|  | 740 | "P2P: GO(iface)=%p members=%u CLI(iface)=%p persistent(ssid)=%p", | 
|  | 741 | go_wpa_s, owned_members, cli_wpa_s, persistent_go); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 742 |  | 
|  | 743 | /* If not concurrent, restrict our choices */ | 
|  | 744 | if (p2p_no_group_iface) { | 
|  | 745 | wpa_printf(MSG_DEBUG, "P2P: p2p_no_group_iface"); | 
|  | 746 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 747 | if (cli_wpa_s) | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 748 | return P2PS_SETUP_NONE; | 
|  | 749 |  | 
|  | 750 | if (go_wpa_s) { | 
|  | 751 | if (role == P2PS_SETUP_CLIENT || | 
|  | 752 | incoming == P2PS_SETUP_GROUP_OWNER || | 
|  | 753 | p2p_client_limit_reached(go_wpa_s->p2p_group)) | 
|  | 754 | return P2PS_SETUP_NONE; | 
|  | 755 |  | 
|  | 756 | return P2PS_SETUP_GROUP_OWNER; | 
|  | 757 | } | 
|  | 758 |  | 
|  | 759 | if (persistent_go) { | 
|  | 760 | if (role == P2PS_SETUP_NONE || role == P2PS_SETUP_NEW) { | 
|  | 761 | if (!incoming) | 
|  | 762 | return P2PS_SETUP_GROUP_OWNER | | 
|  | 763 | P2PS_SETUP_CLIENT; | 
|  | 764 | if (incoming == P2PS_SETUP_NEW) { | 
|  | 765 | u8 r; | 
|  | 766 |  | 
|  | 767 | if (os_get_random(&r, sizeof(r)) < 0 || | 
|  | 768 | (r & 1)) | 
|  | 769 | return P2PS_SETUP_CLIENT; | 
|  | 770 | return P2PS_SETUP_GROUP_OWNER; | 
|  | 771 | } | 
|  | 772 | } | 
|  | 773 | } | 
|  | 774 | } | 
|  | 775 |  | 
|  | 776 | /* If a required role has been specified, handle it here */ | 
|  | 777 | if (role && role != P2PS_SETUP_NEW) { | 
|  | 778 | switch (incoming) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 779 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_NEW: | 
|  | 780 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT: | 
|  | 781 | /* | 
|  | 782 | * Peer has an active GO, so if the role allows it and | 
|  | 783 | * we do not have any active roles, become client. | 
|  | 784 | */ | 
|  | 785 | if ((role & P2PS_SETUP_CLIENT) && !go_wpa_s && | 
|  | 786 | !cli_wpa_s) | 
|  | 787 | return P2PS_SETUP_CLIENT; | 
|  | 788 |  | 
|  | 789 | /* fall through */ | 
|  | 790 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 791 | case P2PS_SETUP_NONE: | 
|  | 792 | case P2PS_SETUP_NEW: | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 793 | conncap = role; | 
|  | 794 | goto grp_owner; | 
|  | 795 |  | 
|  | 796 | case P2PS_SETUP_GROUP_OWNER: | 
|  | 797 | /* | 
|  | 798 | * Must be a complimentary role - cannot be a client to | 
|  | 799 | * more than one peer. | 
|  | 800 | */ | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 801 | if (incoming == role || cli_wpa_s) | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 802 | return P2PS_SETUP_NONE; | 
|  | 803 |  | 
|  | 804 | return P2PS_SETUP_CLIENT; | 
|  | 805 |  | 
|  | 806 | case P2PS_SETUP_CLIENT: | 
|  | 807 | /* Must be a complimentary role */ | 
|  | 808 | if (incoming != role) { | 
|  | 809 | conncap = P2PS_SETUP_GROUP_OWNER; | 
|  | 810 | goto grp_owner; | 
|  | 811 | } | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 812 | /* fall through */ | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 813 |  | 
|  | 814 | default: | 
|  | 815 | return P2PS_SETUP_NONE; | 
|  | 816 | } | 
|  | 817 | } | 
|  | 818 |  | 
|  | 819 | /* | 
|  | 820 | * For now, we only will support ownership of one group, and being a | 
|  | 821 | * client of one group. Therefore, if we have either an existing GO | 
|  | 822 | * group, or an existing client group, we will not do a new GO | 
|  | 823 | * negotiation, but rather try to re-use the existing groups. | 
|  | 824 | */ | 
|  | 825 | switch (incoming) { | 
|  | 826 | case P2PS_SETUP_NONE: | 
|  | 827 | case P2PS_SETUP_NEW: | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 828 | if (cli_wpa_s) | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 829 | conncap = P2PS_SETUP_GROUP_OWNER; | 
|  | 830 | else if (!owned_members) | 
|  | 831 | conncap = P2PS_SETUP_NEW; | 
|  | 832 | else if (incoming == P2PS_SETUP_NONE) | 
|  | 833 | conncap = P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT; | 
|  | 834 | else | 
|  | 835 | conncap = P2PS_SETUP_CLIENT; | 
|  | 836 | break; | 
|  | 837 |  | 
|  | 838 | case P2PS_SETUP_CLIENT: | 
|  | 839 | conncap = P2PS_SETUP_GROUP_OWNER; | 
|  | 840 | break; | 
|  | 841 |  | 
|  | 842 | case P2PS_SETUP_GROUP_OWNER: | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 843 | if (!cli_wpa_s) | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 844 | conncap = P2PS_SETUP_CLIENT; | 
|  | 845 | break; | 
|  | 846 |  | 
|  | 847 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_NEW: | 
|  | 848 | case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT: | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 849 | if (cli_wpa_s) | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 850 | conncap = P2PS_SETUP_GROUP_OWNER; | 
|  | 851 | else { | 
|  | 852 | u8 r; | 
|  | 853 |  | 
|  | 854 | if (os_get_random(&r, sizeof(r)) < 0 || | 
|  | 855 | (r & 1)) | 
|  | 856 | conncap = P2PS_SETUP_CLIENT; | 
|  | 857 | else | 
|  | 858 | conncap = P2PS_SETUP_GROUP_OWNER; | 
|  | 859 | } | 
|  | 860 | break; | 
|  | 861 |  | 
|  | 862 | default: | 
|  | 863 | return P2PS_SETUP_NONE; | 
|  | 864 | } | 
|  | 865 |  | 
|  | 866 | grp_owner: | 
|  | 867 | if ((conncap & P2PS_SETUP_GROUP_OWNER) || | 
|  | 868 | (!incoming && (conncap & P2PS_SETUP_NEW))) { | 
|  | 869 | if (go_wpa_s && p2p_client_limit_reached(go_wpa_s->p2p_group)) | 
|  | 870 | conncap &= ~P2PS_SETUP_GROUP_OWNER; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 871 |  | 
|  | 872 | s = wpas_p2p_get_persistent_go(wpa_s); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 873 | if (!s && !go_wpa_s && p2p_no_group_iface) { | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 874 | p2p_set_intended_addr(wpa_s->global->p2p, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 875 | wpa_s->p2p_mgmt ? | 
|  | 876 | wpa_s->parent->own_addr : | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 877 | wpa_s->own_addr); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 878 | } else if (!s && !go_wpa_s) { | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 879 | if (wpas_p2p_add_group_interface(wpa_s, | 
| Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 880 | WPA_IF_P2P_GROUP) < 0) { | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 881 | wpa_printf(MSG_ERROR, | 
|  | 882 | "P2P: Failed to allocate a new interface for the group"); | 
|  | 883 | return P2PS_SETUP_NONE; | 
|  | 884 | } | 
|  | 885 | wpa_s->global->pending_group_iface_for_p2ps = 1; | 
|  | 886 | p2p_set_intended_addr(wpa_s->global->p2p, | 
|  | 887 | wpa_s->pending_interface_addr); | 
|  | 888 | } | 
|  | 889 | } | 
|  | 890 |  | 
|  | 891 | return conncap; | 
|  | 892 | } | 
|  | 893 |  | 
|  | 894 |  | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 895 | static int wpas_p2p_group_delete(struct wpa_supplicant *wpa_s, | 
|  | 896 | enum p2p_group_removal_reason removal_reason) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 897 | { | 
|  | 898 | struct wpa_ssid *ssid; | 
|  | 899 | char *gtype; | 
|  | 900 | const char *reason; | 
|  | 901 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 902 | ssid = wpa_s->current_ssid; | 
|  | 903 | if (ssid == NULL) { | 
|  | 904 | /* | 
|  | 905 | * The current SSID was not known, but there may still be a | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 906 | * pending P2P group interface waiting for provisioning or a | 
|  | 907 | * P2P group that is trying to reconnect. | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 908 | */ | 
|  | 909 | ssid = wpa_s->conf->ssid; | 
|  | 910 | while (ssid) { | 
| Jouni Malinen | 9d71283 | 2012-10-05 11:01:57 -0700 | [diff] [blame] | 911 | if (ssid->p2p_group && ssid->disabled != 2) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 912 | break; | 
|  | 913 | ssid = ssid->next; | 
|  | 914 | } | 
| Jouni Malinen | 5c44edb | 2012-08-31 21:35:32 +0300 | [diff] [blame] | 915 | if (ssid == NULL && | 
|  | 916 | wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE) | 
|  | 917 | { | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 918 | wpa_printf(MSG_ERROR, "P2P: P2P group interface " | 
|  | 919 | "not found"); | 
|  | 920 | return -1; | 
|  | 921 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 922 | } | 
|  | 923 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO) | 
|  | 924 | gtype = "GO"; | 
|  | 925 | else if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT || | 
|  | 926 | (ssid && ssid->mode == WPAS_MODE_INFRA)) { | 
|  | 927 | wpa_s->reassociate = 0; | 
|  | 928 | wpa_s->disconnected = 1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 929 | gtype = "client"; | 
|  | 930 | } else | 
|  | 931 | gtype = "GO"; | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 932 |  | 
|  | 933 | if (removal_reason != P2P_GROUP_REMOVAL_SILENT && ssid) | 
|  | 934 | wpas_notify_p2p_group_removed(wpa_s, ssid, gtype); | 
|  | 935 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 936 | if (os_strcmp(gtype, "client") == 0) { | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 937 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 938 | if (eloop_is_timeout_registered(wpas_p2p_psk_failure_removal, | 
|  | 939 | wpa_s, NULL)) { | 
|  | 940 | wpa_printf(MSG_DEBUG, | 
|  | 941 | "P2P: PSK failure removal was scheduled, so use PSK failure as reason for group removal"); | 
|  | 942 | removal_reason = P2P_GROUP_REMOVAL_PSK_FAILURE; | 
|  | 943 | eloop_cancel_timeout(wpas_p2p_psk_failure_removal, | 
|  | 944 | wpa_s, NULL); | 
|  | 945 | } | 
|  | 946 | } | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 947 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 948 | if (wpa_s->cross_connect_in_use) { | 
|  | 949 | wpa_s->cross_connect_in_use = 0; | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 950 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 951 | P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s", | 
|  | 952 | wpa_s->ifname, wpa_s->cross_connect_uplink); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 953 | } | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 954 | switch (removal_reason) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 955 | case P2P_GROUP_REMOVAL_REQUESTED: | 
|  | 956 | reason = " reason=REQUESTED"; | 
|  | 957 | break; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 958 | case P2P_GROUP_REMOVAL_FORMATION_FAILED: | 
|  | 959 | reason = " reason=FORMATION_FAILED"; | 
|  | 960 | break; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 961 | case P2P_GROUP_REMOVAL_IDLE_TIMEOUT: | 
|  | 962 | reason = " reason=IDLE"; | 
|  | 963 | break; | 
|  | 964 | case P2P_GROUP_REMOVAL_UNAVAILABLE: | 
|  | 965 | reason = " reason=UNAVAILABLE"; | 
|  | 966 | break; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 967 | case P2P_GROUP_REMOVAL_GO_ENDING_SESSION: | 
|  | 968 | reason = " reason=GO_ENDING_SESSION"; | 
|  | 969 | break; | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 970 | case P2P_GROUP_REMOVAL_PSK_FAILURE: | 
|  | 971 | reason = " reason=PSK_FAILURE"; | 
|  | 972 | break; | 
| Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 973 | case P2P_GROUP_REMOVAL_FREQ_CONFLICT: | 
|  | 974 | reason = " reason=FREQ_CONFLICT"; | 
|  | 975 | break; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 976 | default: | 
|  | 977 | reason = ""; | 
|  | 978 | break; | 
|  | 979 | } | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 980 | if (removal_reason != P2P_GROUP_REMOVAL_SILENT) { | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 981 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 982 | P2P_EVENT_GROUP_REMOVED "%s %s%s", | 
|  | 983 | wpa_s->ifname, gtype, reason); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 984 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 985 |  | 
| Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 986 | if (eloop_cancel_timeout(wpas_p2p_group_freq_conflict, wpa_s, NULL) > 0) | 
|  | 987 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group freq_conflict timeout"); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 988 | if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0) | 
|  | 989 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout"); | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 990 | if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 991 | wpa_s->p2pdev, NULL) > 0) { | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 992 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group formation " | 
|  | 993 | "timeout"); | 
| Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 994 | wpa_s->p2p_in_provisioning = 0; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 995 | wpas_p2p_group_formation_failed(wpa_s, 1); | 
| Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 996 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 997 |  | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 998 | wpa_s->p2p_in_invitation = 0; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 999 | eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL); | 
|  | 1000 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, wpa_s, NULL); | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 1001 |  | 
| Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1002 | /* | 
|  | 1003 | * Make sure wait for the first client does not remain active after the | 
|  | 1004 | * group has been removed. | 
|  | 1005 | */ | 
|  | 1006 | wpa_s->global->p2p_go_wait_client.sec = 0; | 
|  | 1007 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1008 | if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) { | 
|  | 1009 | struct wpa_global *global; | 
|  | 1010 | char *ifname; | 
|  | 1011 | enum wpa_driver_if_type type; | 
|  | 1012 | wpa_printf(MSG_DEBUG, "P2P: Remove group interface %s", | 
|  | 1013 | wpa_s->ifname); | 
|  | 1014 | global = wpa_s->global; | 
|  | 1015 | ifname = os_strdup(wpa_s->ifname); | 
|  | 1016 | type = wpas_p2p_if_type(wpa_s->p2p_group_interface); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1017 | eloop_cancel_timeout(run_wpas_p2p_disconnect, wpa_s, NULL); | 
| Dmitry Shmidt | e15c7b5 | 2011-08-03 15:04:35 -0700 | [diff] [blame] | 1018 | wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1019 | wpa_s = global->ifaces; | 
|  | 1020 | if (wpa_s && ifname) | 
|  | 1021 | wpa_drv_if_remove(wpa_s, type, ifname); | 
|  | 1022 | os_free(ifname); | 
| Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 1023 | return 1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1024 | } | 
|  | 1025 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1026 | /* | 
|  | 1027 | * The primary interface was used for P2P group operations, so | 
|  | 1028 | * need to reset its p2pdev. | 
|  | 1029 | */ | 
|  | 1030 | wpa_s->p2pdev = wpa_s->parent; | 
|  | 1031 |  | 
| Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1032 | if (!wpa_s->p2p_go_group_formation_completed) { | 
|  | 1033 | wpa_s->global->p2p_group_formation = NULL; | 
|  | 1034 | wpa_s->p2p_in_provisioning = 0; | 
|  | 1035 | } | 
|  | 1036 |  | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1037 | wpa_s->show_group_started = 0; | 
|  | 1038 | os_free(wpa_s->go_params); | 
|  | 1039 | wpa_s->go_params = NULL; | 
|  | 1040 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1041 | os_free(wpa_s->p2p_group_common_freqs); | 
|  | 1042 | wpa_s->p2p_group_common_freqs = NULL; | 
|  | 1043 | wpa_s->p2p_group_common_freqs_num = 0; | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1044 | wpa_s->p2p_go_do_acs = 0; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1045 | wpa_s->p2p_go_allow_dfs = 0; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1046 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1047 | wpa_s->waiting_presence_resp = 0; | 
|  | 1048 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1049 | wpa_printf(MSG_DEBUG, "P2P: Remove temporary group network"); | 
|  | 1050 | if (ssid && (ssid->p2p_group || | 
|  | 1051 | ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION || | 
|  | 1052 | (ssid->key_mgmt & WPA_KEY_MGMT_WPS))) { | 
|  | 1053 | int id = ssid->id; | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1054 | if (ssid == wpa_s->current_ssid) { | 
|  | 1055 | wpa_sm_set_config(wpa_s->wpa, NULL); | 
|  | 1056 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1057 | wpa_s->current_ssid = NULL; | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1058 | } | 
|  | 1059 | /* | 
|  | 1060 | * Networks objects created during any P2P activities are not | 
|  | 1061 | * exposed out as they might/will confuse certain non-P2P aware | 
|  | 1062 | * applications since these network objects won't behave like | 
|  | 1063 | * regular ones. | 
|  | 1064 | * | 
|  | 1065 | * Likewise, we don't send out network removed signals for such | 
|  | 1066 | * network objects. | 
|  | 1067 | */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1068 | wpa_config_remove_network(wpa_s->conf, id); | 
|  | 1069 | wpa_supplicant_clear_status(wpa_s); | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1070 | wpa_supplicant_cancel_sched_scan(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1071 | } else { | 
|  | 1072 | wpa_printf(MSG_DEBUG, "P2P: Temporary group network not " | 
|  | 1073 | "found"); | 
|  | 1074 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1075 | if (wpa_s->ap_iface) | 
|  | 1076 | wpa_supplicant_ap_deinit(wpa_s); | 
|  | 1077 | else | 
|  | 1078 | wpa_drv_deinit_p2p_cli(wpa_s); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1079 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1080 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); | 
|  | 1081 |  | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1082 | return 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1083 | } | 
|  | 1084 |  | 
|  | 1085 |  | 
|  | 1086 | static int wpas_p2p_persistent_group(struct wpa_supplicant *wpa_s, | 
|  | 1087 | u8 *go_dev_addr, | 
|  | 1088 | const u8 *ssid, size_t ssid_len) | 
|  | 1089 | { | 
|  | 1090 | struct wpa_bss *bss; | 
|  | 1091 | const u8 *bssid; | 
|  | 1092 | struct wpabuf *p2p; | 
|  | 1093 | u8 group_capab; | 
|  | 1094 | const u8 *addr; | 
|  | 1095 |  | 
|  | 1096 | if (wpa_s->go_params) | 
|  | 1097 | bssid = wpa_s->go_params->peer_interface_addr; | 
|  | 1098 | else | 
|  | 1099 | bssid = wpa_s->bssid; | 
|  | 1100 |  | 
|  | 1101 | bss = wpa_bss_get(wpa_s, bssid, ssid, ssid_len); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1102 | if (bss == NULL && wpa_s->go_params && | 
|  | 1103 | !is_zero_ether_addr(wpa_s->go_params->peer_device_addr)) | 
|  | 1104 | bss = wpa_bss_get_p2p_dev_addr( | 
|  | 1105 | wpa_s, wpa_s->go_params->peer_device_addr); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1106 | if (bss == NULL) { | 
|  | 1107 | u8 iface_addr[ETH_ALEN]; | 
|  | 1108 | if (p2p_get_interface_addr(wpa_s->global->p2p, bssid, | 
|  | 1109 | iface_addr) == 0) | 
|  | 1110 | bss = wpa_bss_get(wpa_s, iface_addr, ssid, ssid_len); | 
|  | 1111 | } | 
|  | 1112 | if (bss == NULL) { | 
|  | 1113 | wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether " | 
|  | 1114 | "group is persistent - BSS " MACSTR " not found", | 
|  | 1115 | MAC2STR(bssid)); | 
|  | 1116 | return 0; | 
|  | 1117 | } | 
|  | 1118 |  | 
|  | 1119 | p2p = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE); | 
| Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 1120 | if (p2p == NULL) | 
|  | 1121 | p2p = wpa_bss_get_vendor_ie_multi_beacon(bss, | 
|  | 1122 | P2P_IE_VENDOR_TYPE); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1123 | if (p2p == NULL) { | 
|  | 1124 | wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether " | 
|  | 1125 | "group is persistent - BSS " MACSTR | 
|  | 1126 | " did not include P2P IE", MAC2STR(bssid)); | 
|  | 1127 | wpa_hexdump(MSG_DEBUG, "P2P: Probe Response IEs", | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1128 | wpa_bss_ie_ptr(bss), bss->ie_len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1129 | wpa_hexdump(MSG_DEBUG, "P2P: Beacon IEs", | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1130 | wpa_bss_ie_ptr(bss) + bss->ie_len, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1131 | bss->beacon_ie_len); | 
|  | 1132 | return 0; | 
|  | 1133 | } | 
|  | 1134 |  | 
|  | 1135 | group_capab = p2p_get_group_capab(p2p); | 
|  | 1136 | addr = p2p_get_go_dev_addr(p2p); | 
|  | 1137 | wpa_printf(MSG_DEBUG, "P2P: Checking whether group is persistent: " | 
|  | 1138 | "group_capab=0x%x", group_capab); | 
|  | 1139 | if (addr) { | 
|  | 1140 | os_memcpy(go_dev_addr, addr, ETH_ALEN); | 
|  | 1141 | wpa_printf(MSG_DEBUG, "P2P: GO Device Address " MACSTR, | 
|  | 1142 | MAC2STR(addr)); | 
|  | 1143 | } else | 
|  | 1144 | os_memset(go_dev_addr, 0, ETH_ALEN); | 
|  | 1145 | wpabuf_free(p2p); | 
|  | 1146 |  | 
|  | 1147 | wpa_printf(MSG_DEBUG, "P2P: BSS " MACSTR " group_capab=0x%x " | 
|  | 1148 | "go_dev_addr=" MACSTR, | 
|  | 1149 | MAC2STR(bssid), group_capab, MAC2STR(go_dev_addr)); | 
|  | 1150 |  | 
| Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 1151 | return !!(group_capab & P2P_GROUP_CAPAB_PERSISTENT_GROUP); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1152 | } | 
|  | 1153 |  | 
|  | 1154 |  | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1155 | static int wpas_p2p_store_persistent_group(struct wpa_supplicant *wpa_s, | 
|  | 1156 | struct wpa_ssid *ssid, | 
|  | 1157 | const u8 *go_dev_addr) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1158 | { | 
|  | 1159 | struct wpa_ssid *s; | 
|  | 1160 | int changed = 0; | 
|  | 1161 |  | 
|  | 1162 | wpa_printf(MSG_DEBUG, "P2P: Storing credentials for a persistent " | 
|  | 1163 | "group (GO Dev Addr " MACSTR ")", MAC2STR(go_dev_addr)); | 
|  | 1164 | for (s = wpa_s->conf->ssid; s; s = s->next) { | 
|  | 1165 | if (s->disabled == 2 && | 
|  | 1166 | os_memcmp(go_dev_addr, s->bssid, ETH_ALEN) == 0 && | 
|  | 1167 | s->ssid_len == ssid->ssid_len && | 
|  | 1168 | os_memcmp(ssid->ssid, s->ssid, ssid->ssid_len) == 0) | 
|  | 1169 | break; | 
|  | 1170 | } | 
|  | 1171 |  | 
|  | 1172 | if (s) { | 
|  | 1173 | wpa_printf(MSG_DEBUG, "P2P: Update existing persistent group " | 
|  | 1174 | "entry"); | 
|  | 1175 | if (ssid->passphrase && !s->passphrase) | 
|  | 1176 | changed = 1; | 
|  | 1177 | else if (ssid->passphrase && s->passphrase && | 
|  | 1178 | os_strcmp(ssid->passphrase, s->passphrase) != 0) | 
|  | 1179 | changed = 1; | 
|  | 1180 | } else { | 
|  | 1181 | wpa_printf(MSG_DEBUG, "P2P: Create a new persistent group " | 
|  | 1182 | "entry"); | 
|  | 1183 | changed = 1; | 
|  | 1184 | s = wpa_config_add_network(wpa_s->conf); | 
|  | 1185 | if (s == NULL) | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1186 | return -1; | 
|  | 1187 |  | 
|  | 1188 | /* | 
|  | 1189 | * Instead of network_added we emit persistent_group_added | 
|  | 1190 | * notification. Also to keep the defense checks in | 
|  | 1191 | * persistent_group obj registration method, we set the | 
|  | 1192 | * relevant flags in s to designate it as a persistent group. | 
|  | 1193 | */ | 
|  | 1194 | s->p2p_group = 1; | 
|  | 1195 | s->p2p_persistent_group = 1; | 
|  | 1196 | wpas_notify_persistent_group_added(wpa_s, s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1197 | wpa_config_set_network_defaults(s); | 
|  | 1198 | } | 
|  | 1199 |  | 
|  | 1200 | s->p2p_group = 1; | 
|  | 1201 | s->p2p_persistent_group = 1; | 
|  | 1202 | s->disabled = 2; | 
|  | 1203 | s->bssid_set = 1; | 
|  | 1204 | os_memcpy(s->bssid, go_dev_addr, ETH_ALEN); | 
|  | 1205 | s->mode = ssid->mode; | 
|  | 1206 | s->auth_alg = WPA_AUTH_ALG_OPEN; | 
|  | 1207 | s->key_mgmt = WPA_KEY_MGMT_PSK; | 
|  | 1208 | s->proto = WPA_PROTO_RSN; | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1209 | s->pbss = ssid->pbss; | 
|  | 1210 | s->pairwise_cipher = ssid->pbss ? WPA_CIPHER_GCMP : WPA_CIPHER_CCMP; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1211 | s->export_keys = 1; | 
|  | 1212 | if (ssid->passphrase) { | 
|  | 1213 | os_free(s->passphrase); | 
|  | 1214 | s->passphrase = os_strdup(ssid->passphrase); | 
|  | 1215 | } | 
|  | 1216 | if (ssid->psk_set) { | 
|  | 1217 | s->psk_set = 1; | 
|  | 1218 | os_memcpy(s->psk, ssid->psk, 32); | 
|  | 1219 | } | 
|  | 1220 | if (s->passphrase && !s->psk_set) | 
|  | 1221 | wpa_config_update_psk(s); | 
|  | 1222 | if (s->ssid == NULL || s->ssid_len < ssid->ssid_len) { | 
|  | 1223 | os_free(s->ssid); | 
|  | 1224 | s->ssid = os_malloc(ssid->ssid_len); | 
|  | 1225 | } | 
|  | 1226 | if (s->ssid) { | 
|  | 1227 | s->ssid_len = ssid->ssid_len; | 
|  | 1228 | os_memcpy(s->ssid, ssid->ssid, s->ssid_len); | 
|  | 1229 | } | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1230 | if (ssid->mode == WPAS_MODE_P2P_GO && wpa_s->global->add_psk) { | 
|  | 1231 | dl_list_add(&s->psk_list, &wpa_s->global->add_psk->list); | 
|  | 1232 | wpa_s->global->add_psk = NULL; | 
|  | 1233 | changed = 1; | 
|  | 1234 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1235 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1236 | if (changed && wpa_s->conf->update_config && | 
|  | 1237 | wpa_config_write(wpa_s->confname, wpa_s->conf)) { | 
|  | 1238 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); | 
|  | 1239 | } | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1240 |  | 
|  | 1241 | return s->id; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1242 | } | 
|  | 1243 |  | 
|  | 1244 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1245 | static void wpas_p2p_add_persistent_group_client(struct wpa_supplicant *wpa_s, | 
|  | 1246 | const u8 *addr) | 
|  | 1247 | { | 
|  | 1248 | struct wpa_ssid *ssid, *s; | 
|  | 1249 | u8 *n; | 
|  | 1250 | size_t i; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1251 | int found = 0; | 
| Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1252 | 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] | 1253 |  | 
|  | 1254 | ssid = wpa_s->current_ssid; | 
|  | 1255 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || | 
|  | 1256 | !ssid->p2p_persistent_group) | 
|  | 1257 | return; | 
|  | 1258 |  | 
| Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1259 | for (s = p2p_wpa_s->conf->ssid; s; s = s->next) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1260 | if (s->disabled != 2 || s->mode != WPAS_MODE_P2P_GO) | 
|  | 1261 | continue; | 
|  | 1262 |  | 
|  | 1263 | if (s->ssid_len == ssid->ssid_len && | 
|  | 1264 | os_memcmp(s->ssid, ssid->ssid, s->ssid_len) == 0) | 
|  | 1265 | break; | 
|  | 1266 | } | 
|  | 1267 |  | 
|  | 1268 | if (s == NULL) | 
|  | 1269 | return; | 
|  | 1270 |  | 
|  | 1271 | 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] | 1272 | if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN, addr, | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1273 | ETH_ALEN) != 0) | 
|  | 1274 | continue; | 
|  | 1275 |  | 
|  | 1276 | if (i == s->num_p2p_clients - 1) | 
|  | 1277 | return; /* already the most recent entry */ | 
|  | 1278 |  | 
|  | 1279 | /* move the entry to mark it most recent */ | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1280 | os_memmove(s->p2p_client_list + i * 2 * ETH_ALEN, | 
|  | 1281 | s->p2p_client_list + (i + 1) * 2 * ETH_ALEN, | 
|  | 1282 | (s->num_p2p_clients - i - 1) * 2 * ETH_ALEN); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1283 | os_memcpy(s->p2p_client_list + | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1284 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN, addr, | 
|  | 1285 | ETH_ALEN); | 
|  | 1286 | os_memset(s->p2p_client_list + | 
|  | 1287 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN + ETH_ALEN, | 
|  | 1288 | 0xff, ETH_ALEN); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1289 | found = 1; | 
|  | 1290 | break; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1291 | } | 
|  | 1292 |  | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1293 | if (!found && s->num_p2p_clients < P2P_MAX_STORED_CLIENTS) { | 
|  | 1294 | n = os_realloc_array(s->p2p_client_list, | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1295 | s->num_p2p_clients + 1, 2 * ETH_ALEN); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1296 | if (n == NULL) | 
|  | 1297 | return; | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1298 | os_memcpy(n + s->num_p2p_clients * 2 * ETH_ALEN, addr, | 
|  | 1299 | ETH_ALEN); | 
|  | 1300 | os_memset(n + s->num_p2p_clients * 2 * ETH_ALEN + ETH_ALEN, | 
|  | 1301 | 0xff, ETH_ALEN); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1302 | s->p2p_client_list = n; | 
|  | 1303 | s->num_p2p_clients++; | 
| Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 1304 | } else if (!found && s->p2p_client_list) { | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1305 | /* Not enough room for an additional entry - drop the oldest | 
|  | 1306 | * entry */ | 
|  | 1307 | os_memmove(s->p2p_client_list, | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1308 | s->p2p_client_list + 2 * ETH_ALEN, | 
|  | 1309 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1310 | os_memcpy(s->p2p_client_list + | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1311 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN, | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1312 | addr, ETH_ALEN); | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1313 | os_memset(s->p2p_client_list + | 
|  | 1314 | (s->num_p2p_clients - 1) * 2 * ETH_ALEN + ETH_ALEN, | 
|  | 1315 | 0xff, ETH_ALEN); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1316 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1317 |  | 
| Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1318 | if (p2p_wpa_s->conf->update_config && | 
|  | 1319 | wpa_config_write(p2p_wpa_s->confname, p2p_wpa_s->conf)) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1320 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1321 | } | 
|  | 1322 |  | 
|  | 1323 |  | 
| Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1324 | static void wpas_p2p_group_started(struct wpa_supplicant *wpa_s, | 
|  | 1325 | int go, struct wpa_ssid *ssid, int freq, | 
|  | 1326 | const u8 *psk, const char *passphrase, | 
|  | 1327 | const u8 *go_dev_addr, int persistent, | 
|  | 1328 | const char *extra) | 
|  | 1329 | { | 
|  | 1330 | const char *ssid_txt; | 
|  | 1331 | char psk_txt[65]; | 
|  | 1332 |  | 
|  | 1333 | if (psk) | 
|  | 1334 | wpa_snprintf_hex(psk_txt, sizeof(psk_txt), psk, 32); | 
|  | 1335 | else | 
|  | 1336 | psk_txt[0] = '\0'; | 
|  | 1337 |  | 
|  | 1338 | if (ssid) | 
|  | 1339 | ssid_txt = wpa_ssid_txt(ssid->ssid, ssid->ssid_len); | 
|  | 1340 | else | 
|  | 1341 | ssid_txt = ""; | 
|  | 1342 |  | 
|  | 1343 | if (passphrase && passphrase[0] == '\0') | 
|  | 1344 | passphrase = NULL; | 
|  | 1345 |  | 
|  | 1346 | /* | 
|  | 1347 | * Include PSK/passphrase only in the control interface message and | 
|  | 1348 | * leave it out from the debug log entry. | 
|  | 1349 | */ | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1350 | wpa_msg_global_ctrl(wpa_s->p2pdev, MSG_INFO, | 
| Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1351 | P2P_EVENT_GROUP_STARTED | 
|  | 1352 | "%s %s ssid=\"%s\" freq=%d%s%s%s%s%s go_dev_addr=" | 
|  | 1353 | MACSTR "%s%s", | 
|  | 1354 | wpa_s->ifname, go ? "GO" : "client", ssid_txt, freq, | 
|  | 1355 | psk ? " psk=" : "", psk_txt, | 
|  | 1356 | passphrase ? " passphrase=\"" : "", | 
|  | 1357 | passphrase ? passphrase : "", | 
|  | 1358 | passphrase ? "\"" : "", | 
|  | 1359 | MAC2STR(go_dev_addr), | 
|  | 1360 | persistent ? " [PERSISTENT]" : "", extra); | 
|  | 1361 | wpa_printf(MSG_INFO, P2P_EVENT_GROUP_STARTED | 
|  | 1362 | "%s %s ssid=\"%s\" freq=%d go_dev_addr=" MACSTR "%s%s", | 
|  | 1363 | wpa_s->ifname, go ? "GO" : "client", ssid_txt, freq, | 
|  | 1364 | MAC2STR(go_dev_addr), persistent ? " [PERSISTENT]" : "", | 
|  | 1365 | extra); | 
|  | 1366 | } | 
|  | 1367 |  | 
|  | 1368 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1369 | static void wpas_group_formation_completed(struct wpa_supplicant *wpa_s, | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 1370 | int success, int already_deleted) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1371 | { | 
|  | 1372 | struct wpa_ssid *ssid; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1373 | int client; | 
|  | 1374 | int persistent; | 
|  | 1375 | u8 go_dev_addr[ETH_ALEN]; | 
|  | 1376 |  | 
|  | 1377 | /* | 
|  | 1378 | * This callback is likely called for the main interface. Update wpa_s | 
|  | 1379 | * to use the group interface if a new interface was created for the | 
|  | 1380 | * group. | 
|  | 1381 | */ | 
|  | 1382 | if (wpa_s->global->p2p_group_formation) | 
|  | 1383 | wpa_s = wpa_s->global->p2p_group_formation; | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1384 | if (wpa_s->p2p_go_group_formation_completed) { | 
|  | 1385 | wpa_s->global->p2p_group_formation = NULL; | 
|  | 1386 | wpa_s->p2p_in_provisioning = 0; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1387 | } else if (wpa_s->p2p_in_provisioning && !success) { | 
|  | 1388 | wpa_msg(wpa_s, MSG_DEBUG, | 
|  | 1389 | "P2P: Stop provisioning state due to failure"); | 
|  | 1390 | wpa_s->p2p_in_provisioning = 0; | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1391 | } | 
| Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 1392 | wpa_s->p2p_in_invitation = 0; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1393 | wpa_s->group_formation_reported = 1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1394 |  | 
|  | 1395 | if (!success) { | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1396 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1397 | P2P_EVENT_GROUP_FORMATION_FAILURE); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1398 | wpas_notify_p2p_group_formation_failure(wpa_s, ""); | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 1399 | if (already_deleted) | 
|  | 1400 | return; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1401 | wpas_p2p_group_delete(wpa_s, | 
|  | 1402 | P2P_GROUP_REMOVAL_FORMATION_FAILED); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1403 | return; | 
|  | 1404 | } | 
|  | 1405 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1406 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1407 | P2P_EVENT_GROUP_FORMATION_SUCCESS); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1408 |  | 
|  | 1409 | ssid = wpa_s->current_ssid; | 
|  | 1410 | if (ssid && ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) { | 
|  | 1411 | ssid->mode = WPAS_MODE_P2P_GO; | 
|  | 1412 | p2p_group_notif_formation_done(wpa_s->p2p_group); | 
|  | 1413 | wpa_supplicant_ap_mac_addr_filter(wpa_s, NULL); | 
|  | 1414 | } | 
|  | 1415 |  | 
|  | 1416 | persistent = 0; | 
|  | 1417 | if (ssid) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1418 | client = ssid->mode == WPAS_MODE_INFRA; | 
|  | 1419 | if (ssid->mode == WPAS_MODE_P2P_GO) { | 
|  | 1420 | persistent = ssid->p2p_persistent_group; | 
| Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 1421 | os_memcpy(go_dev_addr, wpa_s->global->p2p_dev_addr, | 
|  | 1422 | ETH_ALEN); | 
| George Burgess IV | 0d2d1bf | 2021-11-01 03:08:33 -0700 | [diff] [blame] | 1423 | } else { | 
|  | 1424 | os_memset(go_dev_addr, 0, ETH_ALEN); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1425 | persistent = wpas_p2p_persistent_group(wpa_s, | 
|  | 1426 | go_dev_addr, | 
|  | 1427 | ssid->ssid, | 
|  | 1428 | ssid->ssid_len); | 
| George Burgess IV | 0d2d1bf | 2021-11-01 03:08:33 -0700 | [diff] [blame] | 1429 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1430 | } else { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1431 | client = wpa_s->p2p_group_interface == | 
|  | 1432 | P2P_GROUP_INTERFACE_CLIENT; | 
|  | 1433 | os_memset(go_dev_addr, 0, ETH_ALEN); | 
|  | 1434 | } | 
|  | 1435 |  | 
|  | 1436 | wpa_s->show_group_started = 0; | 
|  | 1437 | if (client) { | 
|  | 1438 | /* | 
|  | 1439 | * Indicate event only after successfully completed 4-way | 
|  | 1440 | * handshake, i.e., when the interface is ready for data | 
|  | 1441 | * packets. | 
|  | 1442 | */ | 
|  | 1443 | wpa_s->show_group_started = 1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1444 | } else { | 
| Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1445 | wpas_p2p_group_started(wpa_s, 1, ssid, | 
|  | 1446 | ssid ? ssid->frequency : 0, | 
|  | 1447 | ssid && ssid->passphrase == NULL && | 
|  | 1448 | ssid->psk_set ? ssid->psk : NULL, | 
|  | 1449 | ssid ? ssid->passphrase : NULL, | 
|  | 1450 | go_dev_addr, persistent, ""); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1451 | wpas_p2p_cross_connect_setup(wpa_s); | 
|  | 1452 | wpas_p2p_set_group_idle_timeout(wpa_s); | 
|  | 1453 | } | 
|  | 1454 |  | 
|  | 1455 | if (persistent) | 
| Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1456 | wpas_p2p_store_persistent_group(wpa_s->p2pdev, | 
|  | 1457 | ssid, go_dev_addr); | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1458 | else { | 
|  | 1459 | os_free(wpa_s->global->add_psk); | 
|  | 1460 | wpa_s->global->add_psk = NULL; | 
|  | 1461 | } | 
| Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1462 |  | 
| Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 1463 | if (!client) { | 
| Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1464 | wpas_notify_p2p_group_started(wpa_s, ssid, persistent, 0, NULL); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1465 | os_get_reltime(&wpa_s->global->p2p_go_wait_client); | 
| Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 1466 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1467 | } | 
|  | 1468 |  | 
|  | 1469 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1470 | struct send_action_work { | 
|  | 1471 | unsigned int freq; | 
|  | 1472 | u8 dst[ETH_ALEN]; | 
|  | 1473 | u8 src[ETH_ALEN]; | 
|  | 1474 | u8 bssid[ETH_ALEN]; | 
|  | 1475 | size_t len; | 
|  | 1476 | unsigned int wait_time; | 
|  | 1477 | u8 buf[0]; | 
|  | 1478 | }; | 
|  | 1479 |  | 
|  | 1480 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1481 | static void wpas_p2p_free_send_action_work(struct wpa_supplicant *wpa_s) | 
|  | 1482 | { | 
|  | 1483 | struct send_action_work *awork = wpa_s->p2p_send_action_work->ctx; | 
|  | 1484 |  | 
|  | 1485 | wpa_printf(MSG_DEBUG, | 
|  | 1486 | "P2P: Free Action frame radio work @%p (freq=%u dst=" | 
|  | 1487 | MACSTR " src=" MACSTR " bssid=" MACSTR " wait_time=%u)", | 
|  | 1488 | wpa_s->p2p_send_action_work, awork->freq, | 
|  | 1489 | MAC2STR(awork->dst), MAC2STR(awork->src), | 
|  | 1490 | MAC2STR(awork->bssid), awork->wait_time); | 
|  | 1491 | wpa_hexdump(MSG_DEBUG, "P2P: Freeing pending Action frame", | 
|  | 1492 | awork->buf, awork->len); | 
|  | 1493 | os_free(awork); | 
|  | 1494 | wpa_s->p2p_send_action_work->ctx = NULL; | 
|  | 1495 | radio_work_done(wpa_s->p2p_send_action_work); | 
|  | 1496 | wpa_s->p2p_send_action_work = NULL; | 
|  | 1497 | } | 
|  | 1498 |  | 
|  | 1499 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1500 | static void wpas_p2p_send_action_work_timeout(void *eloop_ctx, | 
|  | 1501 | void *timeout_ctx) | 
|  | 1502 | { | 
|  | 1503 | struct wpa_supplicant *wpa_s = eloop_ctx; | 
|  | 1504 |  | 
|  | 1505 | if (!wpa_s->p2p_send_action_work) | 
|  | 1506 | return; | 
|  | 1507 |  | 
|  | 1508 | wpa_printf(MSG_DEBUG, "P2P: Send Action frame radio work timed out"); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1509 | wpas_p2p_free_send_action_work(wpa_s); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1510 | } | 
|  | 1511 |  | 
|  | 1512 |  | 
| Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 1513 | static void wpas_p2p_action_tx_clear(struct wpa_supplicant *wpa_s) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1514 | { | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1515 | if (wpa_s->p2p_send_action_work) { | 
|  | 1516 | struct send_action_work *awork; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1517 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1518 | awork = wpa_s->p2p_send_action_work->ctx; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1519 | wpa_printf(MSG_DEBUG, | 
|  | 1520 | "P2P: Clear Action TX work @%p (wait_time=%u)", | 
|  | 1521 | wpa_s->p2p_send_action_work, awork->wait_time); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1522 | if (awork->wait_time == 0) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1523 | wpas_p2p_free_send_action_work(wpa_s); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1524 | } else { | 
|  | 1525 | /* | 
|  | 1526 | * In theory, this should not be needed, but number of | 
|  | 1527 | * places in the P2P code is still using non-zero wait | 
|  | 1528 | * time for the last Action frame in the sequence and | 
|  | 1529 | * some of these do not call send_action_done(). | 
|  | 1530 | */ | 
|  | 1531 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, | 
|  | 1532 | wpa_s, NULL); | 
|  | 1533 | eloop_register_timeout( | 
|  | 1534 | 0, awork->wait_time * 1000, | 
|  | 1535 | wpas_p2p_send_action_work_timeout, | 
|  | 1536 | wpa_s, NULL); | 
|  | 1537 | } | 
|  | 1538 | } | 
| Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 1539 | } | 
|  | 1540 |  | 
|  | 1541 |  | 
|  | 1542 | static void wpas_p2p_send_action_tx_status(struct wpa_supplicant *wpa_s, | 
|  | 1543 | unsigned int freq, | 
|  | 1544 | const u8 *dst, const u8 *src, | 
|  | 1545 | const u8 *bssid, | 
|  | 1546 | const u8 *data, size_t data_len, | 
|  | 1547 | enum offchannel_send_action_result | 
|  | 1548 | result) | 
|  | 1549 | { | 
|  | 1550 | enum p2p_send_action_result res = P2P_SEND_ACTION_SUCCESS; | 
|  | 1551 |  | 
|  | 1552 | wpas_p2p_action_tx_clear(wpa_s); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1553 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1554 | if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) | 
|  | 1555 | return; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1556 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1557 | switch (result) { | 
|  | 1558 | case OFFCHANNEL_SEND_ACTION_SUCCESS: | 
|  | 1559 | res = P2P_SEND_ACTION_SUCCESS; | 
|  | 1560 | break; | 
|  | 1561 | case OFFCHANNEL_SEND_ACTION_NO_ACK: | 
|  | 1562 | res = P2P_SEND_ACTION_NO_ACK; | 
|  | 1563 | break; | 
|  | 1564 | case OFFCHANNEL_SEND_ACTION_FAILED: | 
|  | 1565 | res = P2P_SEND_ACTION_FAILED; | 
|  | 1566 | break; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1567 | } | 
|  | 1568 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1569 | 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] | 1570 |  | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1571 | if (result != OFFCHANNEL_SEND_ACTION_SUCCESS && | 
|  | 1572 | wpa_s->pending_pd_before_join && | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1573 | (os_memcmp(dst, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 || | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1574 | os_memcmp(dst, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0) && | 
|  | 1575 | wpa_s->p2p_fallback_to_go_neg) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1576 | wpa_s->pending_pd_before_join = 0; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1577 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No ACK for PD Req " | 
|  | 1578 | "during p2p_connect-auto"); | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1579 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1580 | P2P_EVENT_FALLBACK_TO_GO_NEG | 
|  | 1581 | "reason=no-ACK-to-PD-Req"); | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1582 | wpas_p2p_fallback_to_go_neg(wpa_s, 0); | 
|  | 1583 | return; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1584 | } | 
|  | 1585 | } | 
|  | 1586 |  | 
|  | 1587 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1588 | static void wpas_send_action_cb(struct wpa_radio_work *work, int deinit) | 
|  | 1589 | { | 
|  | 1590 | struct wpa_supplicant *wpa_s = work->wpa_s; | 
|  | 1591 | struct send_action_work *awork = work->ctx; | 
|  | 1592 |  | 
|  | 1593 | if (deinit) { | 
| Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 1594 | if (work->started) { | 
|  | 1595 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, | 
|  | 1596 | wpa_s, NULL); | 
|  | 1597 | wpa_s->p2p_send_action_work = NULL; | 
|  | 1598 | offchannel_send_action_done(wpa_s); | 
|  | 1599 | } | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1600 | os_free(awork); | 
|  | 1601 | return; | 
|  | 1602 | } | 
|  | 1603 |  | 
|  | 1604 | if (offchannel_send_action(wpa_s, awork->freq, awork->dst, awork->src, | 
|  | 1605 | awork->bssid, awork->buf, awork->len, | 
|  | 1606 | awork->wait_time, | 
|  | 1607 | wpas_p2p_send_action_tx_status, 1) < 0) { | 
|  | 1608 | os_free(awork); | 
|  | 1609 | radio_work_done(work); | 
|  | 1610 | return; | 
|  | 1611 | } | 
|  | 1612 | wpa_s->p2p_send_action_work = work; | 
|  | 1613 | } | 
|  | 1614 |  | 
|  | 1615 |  | 
|  | 1616 | static int wpas_send_action_work(struct wpa_supplicant *wpa_s, | 
|  | 1617 | unsigned int freq, const u8 *dst, | 
|  | 1618 | const u8 *src, const u8 *bssid, const u8 *buf, | 
|  | 1619 | size_t len, unsigned int wait_time) | 
|  | 1620 | { | 
|  | 1621 | struct send_action_work *awork; | 
|  | 1622 |  | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1623 | if (radio_work_pending(wpa_s, "p2p-send-action")) { | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1624 | wpa_printf(MSG_DEBUG, "P2P: Cannot schedule new p2p-send-action work since one is already pending"); | 
|  | 1625 | return -1; | 
|  | 1626 | } | 
|  | 1627 |  | 
|  | 1628 | awork = os_zalloc(sizeof(*awork) + len); | 
|  | 1629 | if (awork == NULL) | 
|  | 1630 | return -1; | 
|  | 1631 |  | 
|  | 1632 | awork->freq = freq; | 
|  | 1633 | os_memcpy(awork->dst, dst, ETH_ALEN); | 
|  | 1634 | os_memcpy(awork->src, src, ETH_ALEN); | 
|  | 1635 | os_memcpy(awork->bssid, bssid, ETH_ALEN); | 
|  | 1636 | awork->len = len; | 
|  | 1637 | awork->wait_time = wait_time; | 
|  | 1638 | os_memcpy(awork->buf, buf, len); | 
|  | 1639 |  | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1640 | if (radio_add_work(wpa_s, freq, "p2p-send-action", 1, | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1641 | wpas_send_action_cb, awork) < 0) { | 
|  | 1642 | os_free(awork); | 
|  | 1643 | return -1; | 
|  | 1644 | } | 
|  | 1645 |  | 
|  | 1646 | return 0; | 
|  | 1647 | } | 
|  | 1648 |  | 
|  | 1649 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1650 | static int wpas_send_action(void *ctx, unsigned int freq, const u8 *dst, | 
|  | 1651 | const u8 *src, const u8 *bssid, const u8 *buf, | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1652 | size_t len, unsigned int wait_time, int *scheduled) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1653 | { | 
|  | 1654 | struct wpa_supplicant *wpa_s = ctx; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1655 | int listen_freq = -1, send_freq = -1; | 
|  | 1656 |  | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1657 | if (scheduled) | 
|  | 1658 | *scheduled = 0; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1659 | if (wpa_s->p2p_listen_work) | 
|  | 1660 | listen_freq = wpa_s->p2p_listen_work->freq; | 
|  | 1661 | if (wpa_s->p2p_send_action_work) | 
|  | 1662 | send_freq = wpa_s->p2p_send_action_work->freq; | 
|  | 1663 | if (listen_freq != (int) freq && send_freq != (int) freq) { | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1664 | int res; | 
|  | 1665 |  | 
|  | 1666 | wpa_printf(MSG_DEBUG, "P2P: Schedule new radio work for Action frame TX (listen_freq=%d send_freq=%d freq=%u)", | 
|  | 1667 | listen_freq, send_freq, freq); | 
|  | 1668 | res = wpas_send_action_work(wpa_s, freq, dst, src, bssid, buf, | 
|  | 1669 | len, wait_time); | 
|  | 1670 | if (res == 0 && scheduled) | 
|  | 1671 | *scheduled = 1; | 
|  | 1672 | return res; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1673 | } | 
|  | 1674 |  | 
|  | 1675 | 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] | 1676 | return offchannel_send_action(wpa_s, freq, dst, src, bssid, buf, len, | 
|  | 1677 | wait_time, | 
|  | 1678 | wpas_p2p_send_action_tx_status, 1); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1679 | } | 
|  | 1680 |  | 
|  | 1681 |  | 
|  | 1682 | static void wpas_send_action_done(void *ctx) | 
|  | 1683 | { | 
|  | 1684 | struct wpa_supplicant *wpa_s = ctx; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1685 |  | 
|  | 1686 | if (wpa_s->p2p_send_action_work) { | 
|  | 1687 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, | 
|  | 1688 | wpa_s, NULL); | 
|  | 1689 | os_free(wpa_s->p2p_send_action_work->ctx); | 
|  | 1690 | radio_work_done(wpa_s->p2p_send_action_work); | 
|  | 1691 | wpa_s->p2p_send_action_work = NULL; | 
|  | 1692 | } | 
|  | 1693 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1694 | offchannel_send_action_done(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1695 | } | 
|  | 1696 |  | 
|  | 1697 |  | 
|  | 1698 | static int wpas_copy_go_neg_results(struct wpa_supplicant *wpa_s, | 
|  | 1699 | struct p2p_go_neg_results *params) | 
|  | 1700 | { | 
|  | 1701 | if (wpa_s->go_params == NULL) { | 
|  | 1702 | wpa_s->go_params = os_malloc(sizeof(*params)); | 
|  | 1703 | if (wpa_s->go_params == NULL) | 
|  | 1704 | return -1; | 
|  | 1705 | } | 
|  | 1706 | os_memcpy(wpa_s->go_params, params, sizeof(*params)); | 
|  | 1707 | return 0; | 
|  | 1708 | } | 
|  | 1709 |  | 
|  | 1710 |  | 
|  | 1711 | static void wpas_start_wps_enrollee(struct wpa_supplicant *wpa_s, | 
|  | 1712 | struct p2p_go_neg_results *res) | 
|  | 1713 | { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1714 | wpa_s->group_formation_reported = 0; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1715 | wpa_printf(MSG_DEBUG, "P2P: Start WPS Enrollee for peer " MACSTR | 
|  | 1716 | " dev_addr " MACSTR " wps_method %d", | 
|  | 1717 | MAC2STR(res->peer_interface_addr), | 
|  | 1718 | MAC2STR(res->peer_device_addr), res->wps_method); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1719 | wpa_hexdump_ascii(MSG_DEBUG, "P2P: Start WPS Enrollee for SSID", | 
|  | 1720 | res->ssid, res->ssid_len); | 
|  | 1721 | wpa_supplicant_ap_deinit(wpa_s); | 
|  | 1722 | wpas_copy_go_neg_results(wpa_s, res); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1723 | if (res->wps_method == WPS_PBC) { | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1724 | wpas_wps_start_pbc(wpa_s, res->peer_interface_addr, 1, 0); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1725 | #ifdef CONFIG_WPS_NFC | 
|  | 1726 | } else if (res->wps_method == WPS_NFC) { | 
|  | 1727 | wpas_wps_start_nfc(wpa_s, res->peer_device_addr, | 
|  | 1728 | res->peer_interface_addr, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1729 | wpa_s->p2pdev->p2p_oob_dev_pw, | 
|  | 1730 | wpa_s->p2pdev->p2p_oob_dev_pw_id, 1, | 
|  | 1731 | wpa_s->p2pdev->p2p_oob_dev_pw_id == | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1732 | DEV_PW_NFC_CONNECTION_HANDOVER ? | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1733 | wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1734 | NULL, | 
|  | 1735 | NULL, 0, 0); | 
|  | 1736 | #endif /* CONFIG_WPS_NFC */ | 
|  | 1737 | } else { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1738 | u16 dev_pw_id = DEV_PW_DEFAULT; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1739 | if (wpa_s->p2p_wps_method == WPS_P2PS) | 
|  | 1740 | dev_pw_id = DEV_PW_P2PS_DEFAULT; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1741 | if (wpa_s->p2p_wps_method == WPS_PIN_KEYPAD) | 
|  | 1742 | dev_pw_id = DEV_PW_REGISTRAR_SPECIFIED; | 
|  | 1743 | wpas_wps_start_pin(wpa_s, res->peer_interface_addr, | 
|  | 1744 | wpa_s->p2p_pin, 1, dev_pw_id); | 
|  | 1745 | } | 
|  | 1746 | } | 
|  | 1747 |  | 
|  | 1748 |  | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1749 | static void wpas_p2p_add_psk_list(struct wpa_supplicant *wpa_s, | 
|  | 1750 | struct wpa_ssid *ssid) | 
|  | 1751 | { | 
|  | 1752 | struct wpa_ssid *persistent; | 
|  | 1753 | struct psk_list_entry *psk; | 
|  | 1754 | struct hostapd_data *hapd; | 
|  | 1755 |  | 
|  | 1756 | if (!wpa_s->ap_iface) | 
|  | 1757 | return; | 
|  | 1758 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1759 | persistent = wpas_p2p_get_persistent(wpa_s->p2pdev, NULL, ssid->ssid, | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1760 | ssid->ssid_len); | 
|  | 1761 | if (persistent == NULL) | 
|  | 1762 | return; | 
|  | 1763 |  | 
|  | 1764 | hapd = wpa_s->ap_iface->bss[0]; | 
|  | 1765 |  | 
|  | 1766 | dl_list_for_each(psk, &persistent->psk_list, struct psk_list_entry, | 
|  | 1767 | list) { | 
|  | 1768 | struct hostapd_wpa_psk *hpsk; | 
|  | 1769 |  | 
|  | 1770 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add persistent group PSK entry for " | 
|  | 1771 | MACSTR " psk=%d", | 
|  | 1772 | MAC2STR(psk->addr), psk->p2p); | 
|  | 1773 | hpsk = os_zalloc(sizeof(*hpsk)); | 
|  | 1774 | if (hpsk == NULL) | 
|  | 1775 | break; | 
|  | 1776 | os_memcpy(hpsk->psk, psk->psk, PMK_LEN); | 
|  | 1777 | if (psk->p2p) | 
|  | 1778 | os_memcpy(hpsk->p2p_dev_addr, psk->addr, ETH_ALEN); | 
|  | 1779 | else | 
|  | 1780 | os_memcpy(hpsk->addr, psk->addr, ETH_ALEN); | 
|  | 1781 | hpsk->next = hapd->conf->ssid.wpa_psk; | 
|  | 1782 | hapd->conf->ssid.wpa_psk = hpsk; | 
|  | 1783 | } | 
|  | 1784 | } | 
|  | 1785 |  | 
|  | 1786 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1787 | static void p2p_go_dump_common_freqs(struct wpa_supplicant *wpa_s) | 
|  | 1788 | { | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1789 | char buf[20 + P2P_MAX_CHANNELS * 6]; | 
|  | 1790 | char *pos, *end; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1791 | unsigned int i; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1792 | int res; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1793 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1794 | pos = buf; | 
|  | 1795 | end = pos + sizeof(buf); | 
|  | 1796 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { | 
|  | 1797 | res = os_snprintf(pos, end - pos, " %d", | 
|  | 1798 | wpa_s->p2p_group_common_freqs[i]); | 
|  | 1799 | if (os_snprintf_error(end - pos, res)) | 
|  | 1800 | break; | 
|  | 1801 | pos += res; | 
|  | 1802 | } | 
|  | 1803 | *pos = '\0'; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1804 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1805 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Common group frequencies:%s", buf); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1806 | } | 
|  | 1807 |  | 
|  | 1808 |  | 
|  | 1809 | static void p2p_go_save_group_common_freqs(struct wpa_supplicant *wpa_s, | 
|  | 1810 | struct p2p_go_neg_results *params) | 
|  | 1811 | { | 
|  | 1812 | unsigned int i, len = int_array_len(wpa_s->go_params->freq_list); | 
|  | 1813 |  | 
|  | 1814 | wpa_s->p2p_group_common_freqs_num = 0; | 
|  | 1815 | os_free(wpa_s->p2p_group_common_freqs); | 
|  | 1816 | wpa_s->p2p_group_common_freqs = os_calloc(len, sizeof(int)); | 
|  | 1817 | if (!wpa_s->p2p_group_common_freqs) | 
|  | 1818 | return; | 
|  | 1819 |  | 
|  | 1820 | for (i = 0; i < len; i++) { | 
|  | 1821 | if (!wpa_s->go_params->freq_list[i]) | 
|  | 1822 | break; | 
|  | 1823 | wpa_s->p2p_group_common_freqs[i] = | 
|  | 1824 | wpa_s->go_params->freq_list[i]; | 
|  | 1825 | } | 
|  | 1826 | wpa_s->p2p_group_common_freqs_num = i; | 
|  | 1827 | } | 
|  | 1828 |  | 
|  | 1829 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1830 | static void p2p_config_write(struct wpa_supplicant *wpa_s) | 
|  | 1831 | { | 
|  | 1832 | #ifndef CONFIG_NO_CONFIG_WRITE | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1833 | if (wpa_s->p2pdev->conf->update_config && | 
|  | 1834 | wpa_config_write(wpa_s->p2pdev->confname, wpa_s->p2pdev->conf)) | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1835 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); | 
|  | 1836 | #endif /* CONFIG_NO_CONFIG_WRITE */ | 
|  | 1837 | } | 
|  | 1838 |  | 
|  | 1839 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1840 | static void p2p_go_configured(void *ctx, void *data) | 
|  | 1841 | { | 
|  | 1842 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 1843 | struct p2p_go_neg_results *params = data; | 
|  | 1844 | struct wpa_ssid *ssid; | 
|  | 1845 |  | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 1846 | wpa_s->ap_configured_cb = NULL; | 
|  | 1847 | wpa_s->ap_configured_cb_ctx = NULL; | 
|  | 1848 | wpa_s->ap_configured_cb_data = NULL; | 
|  | 1849 | if (!wpa_s->go_params) { | 
|  | 1850 | wpa_printf(MSG_ERROR, | 
|  | 1851 | "P2P: p2p_go_configured() called with wpa_s->go_params == NULL"); | 
|  | 1852 | return; | 
|  | 1853 | } | 
|  | 1854 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1855 | p2p_go_save_group_common_freqs(wpa_s, params); | 
|  | 1856 | p2p_go_dump_common_freqs(wpa_s); | 
|  | 1857 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1858 | ssid = wpa_s->current_ssid; | 
|  | 1859 | if (ssid && ssid->mode == WPAS_MODE_P2P_GO) { | 
|  | 1860 | wpa_printf(MSG_DEBUG, "P2P: Group setup without provisioning"); | 
|  | 1861 | if (wpa_s->global->p2p_group_formation == wpa_s) | 
|  | 1862 | wpa_s->global->p2p_group_formation = NULL; | 
| Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 1863 | wpas_p2p_group_started(wpa_s, 1, ssid, ssid->frequency, | 
|  | 1864 | params->passphrase[0] == '\0' ? | 
|  | 1865 | params->psk : NULL, | 
|  | 1866 | params->passphrase, | 
|  | 1867 | wpa_s->global->p2p_dev_addr, | 
|  | 1868 | params->persistent_group, ""); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1869 | wpa_s->group_formation_reported = 1; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1870 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1871 | if (wpa_s->p2pdev->p2ps_method_config_any) { | 
|  | 1872 | if (is_zero_ether_addr(wpa_s->p2pdev->p2ps_join_addr)) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1873 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 1874 | "P2PS: Setting default PIN for ANY"); | 
|  | 1875 | wpa_supplicant_ap_wps_pin(wpa_s, NULL, | 
|  | 1876 | "12345670", NULL, 0, | 
|  | 1877 | 0); | 
|  | 1878 | } else { | 
|  | 1879 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 1880 | "P2PS: Setting default PIN for " MACSTR, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1881 | MAC2STR(wpa_s->p2pdev->p2ps_join_addr)); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1882 | wpa_supplicant_ap_wps_pin( | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1883 | wpa_s, wpa_s->p2pdev->p2ps_join_addr, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1884 | "12345670", NULL, 0, 0); | 
|  | 1885 | } | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1886 | wpa_s->p2pdev->p2ps_method_config_any = 0; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1887 | } | 
|  | 1888 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1889 | os_get_reltime(&wpa_s->global->p2p_go_wait_client); | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1890 | if (params->persistent_group) { | 
| Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1891 | wpas_p2p_store_persistent_group( | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1892 | wpa_s->p2pdev, ssid, | 
| Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 1893 | wpa_s->global->p2p_dev_addr); | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1894 | wpas_p2p_add_psk_list(wpa_s, ssid); | 
|  | 1895 | } | 
| Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1896 |  | 
|  | 1897 | wpas_notify_p2p_group_started(wpa_s, ssid, | 
| Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1898 | params->persistent_group, 0, | 
|  | 1899 | NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1900 | wpas_p2p_cross_connect_setup(wpa_s); | 
|  | 1901 | wpas_p2p_set_group_idle_timeout(wpa_s); | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1902 |  | 
|  | 1903 | if (wpa_s->p2p_first_connection_timeout) { | 
|  | 1904 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 1905 | "P2P: Start group formation timeout of %d seconds until first data connection on GO", | 
|  | 1906 | wpa_s->p2p_first_connection_timeout); | 
|  | 1907 | wpa_s->p2p_go_group_formation_completed = 0; | 
|  | 1908 | wpa_s->global->p2p_group_formation = wpa_s; | 
|  | 1909 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1910 | wpa_s->p2pdev, NULL); | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1911 | eloop_register_timeout( | 
|  | 1912 | wpa_s->p2p_first_connection_timeout, 0, | 
|  | 1913 | wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1914 | wpa_s->p2pdev, NULL); | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1915 | } | 
|  | 1916 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1917 | return; | 
|  | 1918 | } | 
|  | 1919 |  | 
|  | 1920 | wpa_printf(MSG_DEBUG, "P2P: Setting up WPS for GO provisioning"); | 
|  | 1921 | if (wpa_supplicant_ap_mac_addr_filter(wpa_s, | 
|  | 1922 | params->peer_interface_addr)) { | 
|  | 1923 | wpa_printf(MSG_DEBUG, "P2P: Failed to setup MAC address " | 
|  | 1924 | "filtering"); | 
|  | 1925 | return; | 
|  | 1926 | } | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1927 | if (params->wps_method == WPS_PBC) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1928 | wpa_supplicant_ap_wps_pbc(wpa_s, params->peer_interface_addr, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1929 | params->peer_device_addr); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1930 | #ifdef CONFIG_WPS_NFC | 
|  | 1931 | } else if (params->wps_method == WPS_NFC) { | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1932 | if (wpa_s->p2pdev->p2p_oob_dev_pw_id != | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1933 | DEV_PW_NFC_CONNECTION_HANDOVER && | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1934 | !wpa_s->p2pdev->p2p_oob_dev_pw) { | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1935 | wpa_printf(MSG_DEBUG, "P2P: No NFC Dev Pw known"); | 
|  | 1936 | return; | 
|  | 1937 | } | 
|  | 1938 | wpas_ap_wps_add_nfc_pw( | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1939 | wpa_s, wpa_s->p2pdev->p2p_oob_dev_pw_id, | 
|  | 1940 | wpa_s->p2pdev->p2p_oob_dev_pw, | 
|  | 1941 | wpa_s->p2pdev->p2p_peer_oob_pk_hash_known ? | 
|  | 1942 | wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : NULL); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1943 | #endif /* CONFIG_WPS_NFC */ | 
|  | 1944 | } else if (wpa_s->p2p_pin[0]) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1945 | wpa_supplicant_ap_wps_pin(wpa_s, params->peer_interface_addr, | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1946 | wpa_s->p2p_pin, NULL, 0, 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1947 | os_free(wpa_s->go_params); | 
|  | 1948 | wpa_s->go_params = NULL; | 
|  | 1949 | } | 
|  | 1950 |  | 
|  | 1951 |  | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1952 | /** | 
|  | 1953 | * wpas_p2p_freq_to_edmg_channel - Convert frequency into EDMG channel | 
|  | 1954 | * @freq: Frequency (MHz) to convert | 
|  | 1955 | * @op_class: Buffer for returning operating class | 
|  | 1956 | * @op_edmg_channel: Buffer for returning channel number | 
|  | 1957 | * Returns: 0 on success, -1 on failure | 
|  | 1958 | * | 
|  | 1959 | * This can be used to find the highest channel bonding which includes the | 
|  | 1960 | * specified frequency. | 
|  | 1961 | */ | 
|  | 1962 | static int wpas_p2p_freq_to_edmg_channel(struct wpa_supplicant *wpa_s, | 
|  | 1963 | unsigned int freq, | 
|  | 1964 | u8 *op_class, u8 *op_edmg_channel) | 
|  | 1965 | { | 
|  | 1966 | struct hostapd_hw_modes *hwmode; | 
|  | 1967 | struct ieee80211_edmg_config edmg; | 
|  | 1968 | unsigned int i; | 
|  | 1969 | enum chan_width chanwidth[] = { | 
|  | 1970 | CHAN_WIDTH_8640, | 
|  | 1971 | CHAN_WIDTH_6480, | 
|  | 1972 | CHAN_WIDTH_4320, | 
|  | 1973 | }; | 
|  | 1974 |  | 
|  | 1975 | if (!wpa_s->hw.modes) | 
|  | 1976 | return -1; | 
|  | 1977 |  | 
|  | 1978 | hwmode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1979 | HOSTAPD_MODE_IEEE80211AD, false); | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1980 | if (!hwmode) { | 
|  | 1981 | wpa_printf(MSG_ERROR, | 
|  | 1982 | "Unsupported AP mode: HOSTAPD_MODE_IEEE80211AD"); | 
|  | 1983 | return -1; | 
|  | 1984 | } | 
|  | 1985 |  | 
|  | 1986 | /* Find the highest EDMG channel bandwidth to start the P2P GO */ | 
|  | 1987 | for (i = 0; i < ARRAY_SIZE(chanwidth); i++) { | 
|  | 1988 | if (ieee80211_chaninfo_to_channel(freq, chanwidth[i], 0, | 
|  | 1989 | op_class, | 
|  | 1990 | op_edmg_channel) < 0) | 
|  | 1991 | continue; | 
|  | 1992 |  | 
|  | 1993 | hostapd_encode_edmg_chan(1, *op_edmg_channel, 0, &edmg); | 
|  | 1994 | if (edmg.channels && | 
|  | 1995 | ieee802_edmg_is_allowed(hwmode->edmg, edmg)) { | 
|  | 1996 | wpa_printf(MSG_DEBUG, | 
|  | 1997 | "Freq %u to EDMG channel %u at opclass %u", | 
|  | 1998 | freq, *op_edmg_channel, *op_class); | 
|  | 1999 | return 0; | 
|  | 2000 | } | 
|  | 2001 | } | 
|  | 2002 |  | 
|  | 2003 | return -1; | 
|  | 2004 | } | 
|  | 2005 |  | 
|  | 2006 |  | 
|  | 2007 | int wpas_p2p_try_edmg_channel(struct wpa_supplicant *wpa_s, | 
|  | 2008 | struct p2p_go_neg_results *params) | 
|  | 2009 | { | 
|  | 2010 | u8 op_channel, op_class; | 
|  | 2011 | int freq; | 
|  | 2012 |  | 
|  | 2013 | /* Try social channel as primary channel frequency */ | 
|  | 2014 | freq = (!params->freq) ? 58320 + 1 * 2160 : params->freq; | 
|  | 2015 |  | 
|  | 2016 | if (wpas_p2p_freq_to_edmg_channel(wpa_s, freq, &op_class, | 
|  | 2017 | &op_channel) == 0) { | 
|  | 2018 | wpa_printf(MSG_DEBUG, | 
|  | 2019 | "Freq %d will be used to set an EDMG connection (channel=%u opclass=%u)", | 
|  | 2020 | freq, op_channel, op_class); | 
|  | 2021 | params->freq = freq; | 
|  | 2022 | return 0; | 
|  | 2023 | } | 
|  | 2024 |  | 
|  | 2025 | return -1; | 
|  | 2026 | } | 
|  | 2027 |  | 
|  | 2028 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2029 | static void wpas_start_wps_go(struct wpa_supplicant *wpa_s, | 
|  | 2030 | struct p2p_go_neg_results *params, | 
|  | 2031 | int group_formation) | 
|  | 2032 | { | 
|  | 2033 | struct wpa_ssid *ssid; | 
|  | 2034 |  | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2035 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Starting GO"); | 
|  | 2036 | if (wpas_copy_go_neg_results(wpa_s, params) < 0) { | 
|  | 2037 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not copy GO Negotiation " | 
|  | 2038 | "results"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2039 | return; | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2040 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2041 |  | 
|  | 2042 | ssid = wpa_config_add_network(wpa_s->conf); | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2043 | if (ssid == NULL) { | 
|  | 2044 | 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] | 2045 | return; | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2046 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2047 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2048 | wpa_s->show_group_started = 0; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2049 | wpa_s->p2p_go_group_formation_completed = 0; | 
|  | 2050 | wpa_s->group_formation_reported = 0; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2051 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2052 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2053 | wpa_config_set_network_defaults(ssid); | 
|  | 2054 | ssid->temporary = 1; | 
|  | 2055 | ssid->p2p_group = 1; | 
| Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 2056 | ssid->p2p_persistent_group = !!params->persistent_group; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2057 | ssid->mode = group_formation ? WPAS_MODE_P2P_GROUP_FORMATION : | 
|  | 2058 | WPAS_MODE_P2P_GO; | 
|  | 2059 | ssid->frequency = params->freq; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2060 | ssid->ht40 = params->ht40; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2061 | ssid->vht = params->vht; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 2062 | ssid->max_oper_chwidth = params->max_oper_chwidth; | 
|  | 2063 | ssid->vht_center_freq2 = params->vht_center_freq2; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2064 | ssid->he = params->he; | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2065 | if (params->edmg) { | 
|  | 2066 | u8 op_channel, op_class; | 
|  | 2067 |  | 
|  | 2068 | if (!wpas_p2p_freq_to_edmg_channel(wpa_s, params->freq, | 
|  | 2069 | &op_class, &op_channel)) { | 
|  | 2070 | ssid->edmg_channel = op_channel; | 
|  | 2071 | ssid->enable_edmg = params->edmg; | 
|  | 2072 | } else { | 
|  | 2073 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 2074 | "P2P: Could not match EDMG channel, freq %d, for GO", | 
|  | 2075 | params->freq); | 
|  | 2076 | } | 
|  | 2077 | } | 
|  | 2078 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2079 | ssid->ssid = os_zalloc(params->ssid_len + 1); | 
|  | 2080 | if (ssid->ssid) { | 
|  | 2081 | os_memcpy(ssid->ssid, params->ssid, params->ssid_len); | 
|  | 2082 | ssid->ssid_len = params->ssid_len; | 
|  | 2083 | } | 
|  | 2084 | ssid->auth_alg = WPA_AUTH_ALG_OPEN; | 
|  | 2085 | ssid->key_mgmt = WPA_KEY_MGMT_PSK; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2086 | if (is_6ghz_freq(ssid->frequency) && | 
|  | 2087 | is_p2p_6ghz_capable(wpa_s->global->p2p)) { | 
|  | 2088 | ssid->auth_alg |= WPA_AUTH_ALG_SAE; | 
|  | 2089 | ssid->key_mgmt = WPA_KEY_MGMT_SAE; | 
|  | 2090 | ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED; | 
|  | 2091 | ssid->sae_pwe = 1; | 
|  | 2092 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use SAE auth_alg and key_mgmt"); | 
|  | 2093 | } else { | 
|  | 2094 | p2p_set_6ghz_dev_capab(wpa_s->global->p2p, false); | 
|  | 2095 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2096 | ssid->proto = WPA_PROTO_RSN; | 
|  | 2097 | ssid->pairwise_cipher = WPA_CIPHER_CCMP; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2098 | ssid->group_cipher = WPA_CIPHER_CCMP; | 
|  | 2099 | if (params->freq > 56160) { | 
|  | 2100 | /* | 
|  | 2101 | * Enable GCMP instead of CCMP as pairwise_cipher and | 
|  | 2102 | * group_cipher in 60 GHz. | 
|  | 2103 | */ | 
|  | 2104 | ssid->pairwise_cipher = WPA_CIPHER_GCMP; | 
|  | 2105 | ssid->group_cipher = WPA_CIPHER_GCMP; | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2106 | /* P2P GO in 60 GHz is always a PCP (PBSS) */ | 
|  | 2107 | ssid->pbss = 1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2108 | } | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2109 | if (os_strlen(params->passphrase) > 0) { | 
|  | 2110 | ssid->passphrase = os_strdup(params->passphrase); | 
|  | 2111 | if (ssid->passphrase == NULL) { | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2112 | wpa_msg_global(wpa_s, MSG_ERROR, | 
|  | 2113 | "P2P: Failed to copy passphrase for GO"); | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2114 | wpa_config_remove_network(wpa_s->conf, ssid->id); | 
|  | 2115 | return; | 
|  | 2116 | } | 
|  | 2117 | } else | 
|  | 2118 | ssid->passphrase = NULL; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2119 | ssid->psk_set = params->psk_set; | 
|  | 2120 | if (ssid->psk_set) | 
|  | 2121 | os_memcpy(ssid->psk, params->psk, sizeof(ssid->psk)); | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2122 | else if (ssid->passphrase) | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2123 | wpa_config_update_psk(ssid); | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2124 | ssid->ap_max_inactivity = wpa_s->p2pdev->conf->p2p_go_max_inactivity; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2125 |  | 
|  | 2126 | wpa_s->ap_configured_cb = p2p_go_configured; | 
|  | 2127 | wpa_s->ap_configured_cb_ctx = wpa_s; | 
|  | 2128 | wpa_s->ap_configured_cb_data = wpa_s->go_params; | 
| Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 2129 | wpa_s->scan_req = NORMAL_SCAN_REQ; | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2130 | wpa_s->connect_without_scan = ssid; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2131 | wpa_s->reassociate = 1; | 
|  | 2132 | wpa_s->disconnected = 0; | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2133 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Request scan (that will be skipped) to " | 
|  | 2134 | "start GO)"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2135 | wpa_supplicant_req_scan(wpa_s, 0, 0); | 
|  | 2136 | } | 
|  | 2137 |  | 
|  | 2138 |  | 
|  | 2139 | static void wpas_p2p_clone_config(struct wpa_supplicant *dst, | 
|  | 2140 | const struct wpa_supplicant *src) | 
|  | 2141 | { | 
|  | 2142 | struct wpa_config *d; | 
|  | 2143 | const struct wpa_config *s; | 
|  | 2144 |  | 
|  | 2145 | d = dst->conf; | 
|  | 2146 | s = src->conf; | 
|  | 2147 |  | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2148 | #define C(n)                            \ | 
|  | 2149 | do {                                    \ | 
|  | 2150 | if (s->n && !d->n)              \ | 
|  | 2151 | d->n = os_strdup(s->n); \ | 
|  | 2152 | } while (0) | 
|  | 2153 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2154 | C(device_name); | 
|  | 2155 | C(manufacturer); | 
|  | 2156 | C(model_name); | 
|  | 2157 | C(model_number); | 
|  | 2158 | C(serial_number); | 
|  | 2159 | C(config_methods); | 
|  | 2160 | #undef C | 
|  | 2161 |  | 
|  | 2162 | os_memcpy(d->device_type, s->device_type, WPS_DEV_TYPE_LEN); | 
|  | 2163 | os_memcpy(d->sec_device_type, s->sec_device_type, | 
|  | 2164 | sizeof(d->sec_device_type)); | 
|  | 2165 | d->num_sec_device_types = s->num_sec_device_types; | 
|  | 2166 |  | 
|  | 2167 | d->p2p_group_idle = s->p2p_group_idle; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2168 | d->p2p_go_freq_change_policy = s->p2p_go_freq_change_policy; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2169 | d->p2p_intra_bss = s->p2p_intra_bss; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2170 | d->persistent_reconnect = s->persistent_reconnect; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2171 | d->max_num_sta = s->max_num_sta; | 
|  | 2172 | d->pbc_in_m1 = s->pbc_in_m1; | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2173 | d->ignore_old_scan_res = s->ignore_old_scan_res; | 
| Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 2174 | d->beacon_int = s->beacon_int; | 
| Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2175 | d->dtim_period = s->dtim_period; | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2176 | d->p2p_go_ctwindow = s->p2p_go_ctwindow; | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2177 | d->disassoc_low_ack = s->disassoc_low_ack; | 
| Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 2178 | d->disable_scan_offload = s->disable_scan_offload; | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2179 | d->passive_scan = s->passive_scan; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2180 | d->pmf = s->pmf; | 
|  | 2181 | d->p2p_6ghz_disable = s->p2p_6ghz_disable; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2182 |  | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2183 | if (s->wps_nfc_dh_privkey && s->wps_nfc_dh_pubkey && | 
|  | 2184 | !d->wps_nfc_pw_from_config) { | 
|  | 2185 | wpabuf_free(d->wps_nfc_dh_privkey); | 
|  | 2186 | wpabuf_free(d->wps_nfc_dh_pubkey); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2187 | d->wps_nfc_dh_privkey = wpabuf_dup(s->wps_nfc_dh_privkey); | 
|  | 2188 | d->wps_nfc_dh_pubkey = wpabuf_dup(s->wps_nfc_dh_pubkey); | 
|  | 2189 | } | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2190 | d->p2p_cli_probe = s->p2p_cli_probe; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2191 | d->go_interworking = s->go_interworking; | 
|  | 2192 | d->go_access_network_type = s->go_access_network_type; | 
|  | 2193 | d->go_internet = s->go_internet; | 
|  | 2194 | d->go_venue_group = s->go_venue_group; | 
|  | 2195 | d->go_venue_type = s->go_venue_type; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2196 | d->p2p_add_cli_chan = s->p2p_add_cli_chan; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2197 | } | 
|  | 2198 |  | 
|  | 2199 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2200 | static void wpas_p2p_get_group_ifname(struct wpa_supplicant *wpa_s, | 
|  | 2201 | char *ifname, size_t len) | 
|  | 2202 | { | 
|  | 2203 | char *ifname_ptr = wpa_s->ifname; | 
|  | 2204 |  | 
|  | 2205 | if (os_strncmp(wpa_s->ifname, P2P_MGMT_DEVICE_PREFIX, | 
|  | 2206 | os_strlen(P2P_MGMT_DEVICE_PREFIX)) == 0) { | 
|  | 2207 | ifname_ptr = os_strrchr(wpa_s->ifname, '-') + 1; | 
|  | 2208 | } | 
|  | 2209 |  | 
|  | 2210 | os_snprintf(ifname, len, "p2p-%s-%d", ifname_ptr, wpa_s->p2p_group_idx); | 
|  | 2211 | if (os_strlen(ifname) >= IFNAMSIZ && | 
|  | 2212 | os_strlen(wpa_s->ifname) < IFNAMSIZ) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2213 | int res; | 
|  | 2214 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2215 | /* Try to avoid going over the IFNAMSIZ length limit */ | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2216 | res = os_snprintf(ifname, len, "p2p-%d", wpa_s->p2p_group_idx); | 
|  | 2217 | if (os_snprintf_error(len, res) && len) | 
|  | 2218 | ifname[len - 1] = '\0'; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2219 | } | 
|  | 2220 | } | 
|  | 2221 |  | 
|  | 2222 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2223 | static int wpas_p2p_add_group_interface(struct wpa_supplicant *wpa_s, | 
|  | 2224 | enum wpa_driver_if_type type) | 
|  | 2225 | { | 
|  | 2226 | char ifname[120], force_ifname[120]; | 
|  | 2227 |  | 
|  | 2228 | if (wpa_s->pending_interface_name[0]) { | 
|  | 2229 | wpa_printf(MSG_DEBUG, "P2P: Pending virtual interface exists " | 
|  | 2230 | "- skip creation of a new one"); | 
|  | 2231 | if (is_zero_ether_addr(wpa_s->pending_interface_addr)) { | 
|  | 2232 | wpa_printf(MSG_DEBUG, "P2P: Pending virtual address " | 
|  | 2233 | "unknown?! ifname='%s'", | 
|  | 2234 | wpa_s->pending_interface_name); | 
|  | 2235 | return -1; | 
|  | 2236 | } | 
|  | 2237 | return 0; | 
|  | 2238 | } | 
|  | 2239 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2240 | wpas_p2p_get_group_ifname(wpa_s, ifname, sizeof(ifname)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2241 | force_ifname[0] = '\0'; | 
|  | 2242 |  | 
|  | 2243 | wpa_printf(MSG_DEBUG, "P2P: Create a new interface %s for the group", | 
|  | 2244 | ifname); | 
|  | 2245 | wpa_s->p2p_group_idx++; | 
|  | 2246 |  | 
|  | 2247 | wpa_s->pending_interface_type = type; | 
|  | 2248 | if (wpa_drv_if_add(wpa_s, type, ifname, NULL, NULL, force_ifname, | 
|  | 2249 | wpa_s->pending_interface_addr, NULL) < 0) { | 
|  | 2250 | wpa_printf(MSG_ERROR, "P2P: Failed to create new group " | 
|  | 2251 | "interface"); | 
|  | 2252 | return -1; | 
|  | 2253 | } | 
|  | 2254 |  | 
| Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2255 | if (wpa_s->conf->p2p_interface_random_mac_addr) { | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2256 | random_mac_addr(wpa_s->pending_interface_addr); | 
|  | 2257 | wpa_printf(MSG_DEBUG, "P2P: Generate random MAC address " MACSTR | 
|  | 2258 | " for the group", | 
|  | 2259 | MAC2STR(wpa_s->pending_interface_addr)); | 
| Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2260 | } | 
|  | 2261 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2262 | if (force_ifname[0]) { | 
|  | 2263 | wpa_printf(MSG_DEBUG, "P2P: Driver forced interface name %s", | 
|  | 2264 | force_ifname); | 
|  | 2265 | os_strlcpy(wpa_s->pending_interface_name, force_ifname, | 
|  | 2266 | sizeof(wpa_s->pending_interface_name)); | 
|  | 2267 | } else | 
|  | 2268 | os_strlcpy(wpa_s->pending_interface_name, ifname, | 
|  | 2269 | sizeof(wpa_s->pending_interface_name)); | 
|  | 2270 | wpa_printf(MSG_DEBUG, "P2P: Created pending virtual interface %s addr " | 
|  | 2271 | MACSTR, wpa_s->pending_interface_name, | 
|  | 2272 | MAC2STR(wpa_s->pending_interface_addr)); | 
|  | 2273 |  | 
|  | 2274 | return 0; | 
|  | 2275 | } | 
|  | 2276 |  | 
|  | 2277 |  | 
|  | 2278 | static void wpas_p2p_remove_pending_group_interface( | 
|  | 2279 | struct wpa_supplicant *wpa_s) | 
|  | 2280 | { | 
|  | 2281 | if (!wpa_s->pending_interface_name[0] || | 
|  | 2282 | is_zero_ether_addr(wpa_s->pending_interface_addr)) | 
|  | 2283 | return; /* No pending virtual interface */ | 
|  | 2284 |  | 
|  | 2285 | wpa_printf(MSG_DEBUG, "P2P: Removing pending group interface %s", | 
|  | 2286 | wpa_s->pending_interface_name); | 
|  | 2287 | wpa_drv_if_remove(wpa_s, wpa_s->pending_interface_type, | 
|  | 2288 | wpa_s->pending_interface_name); | 
|  | 2289 | os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN); | 
|  | 2290 | wpa_s->pending_interface_name[0] = '\0'; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2291 | wpa_s->global->pending_group_iface_for_p2ps = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2292 | } | 
|  | 2293 |  | 
|  | 2294 |  | 
|  | 2295 | static struct wpa_supplicant * | 
|  | 2296 | wpas_p2p_init_group_interface(struct wpa_supplicant *wpa_s, int go) | 
|  | 2297 | { | 
|  | 2298 | struct wpa_interface iface; | 
|  | 2299 | struct wpa_supplicant *group_wpa_s; | 
|  | 2300 |  | 
|  | 2301 | if (!wpa_s->pending_interface_name[0]) { | 
|  | 2302 | wpa_printf(MSG_ERROR, "P2P: No pending group interface"); | 
|  | 2303 | if (!wpas_p2p_create_iface(wpa_s)) | 
|  | 2304 | return NULL; | 
|  | 2305 | /* | 
|  | 2306 | * Something has forced us to remove the pending interface; try | 
|  | 2307 | * to create a new one and hope for the best that we will get | 
|  | 2308 | * the same local address. | 
|  | 2309 | */ | 
|  | 2310 | if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO : | 
|  | 2311 | WPA_IF_P2P_CLIENT) < 0) | 
|  | 2312 | return NULL; | 
|  | 2313 | } | 
|  | 2314 |  | 
|  | 2315 | os_memset(&iface, 0, sizeof(iface)); | 
|  | 2316 | iface.ifname = wpa_s->pending_interface_name; | 
|  | 2317 | iface.driver = wpa_s->driver->name; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2318 | if (wpa_s->conf->ctrl_interface == NULL && | 
|  | 2319 | wpa_s->parent != wpa_s && | 
|  | 2320 | wpa_s->p2p_mgmt && | 
|  | 2321 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) | 
|  | 2322 | iface.ctrl_interface = wpa_s->parent->conf->ctrl_interface; | 
|  | 2323 | else | 
|  | 2324 | iface.ctrl_interface = wpa_s->conf->ctrl_interface; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2325 | iface.driver_param = wpa_s->conf->driver_param; | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 2326 | 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] | 2327 | if (group_wpa_s == NULL) { | 
|  | 2328 | wpa_printf(MSG_ERROR, "P2P: Failed to create new " | 
|  | 2329 | "wpa_supplicant interface"); | 
|  | 2330 | return NULL; | 
|  | 2331 | } | 
|  | 2332 | wpa_s->pending_interface_name[0] = '\0'; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2333 | group_wpa_s->p2p_group_interface = go ? P2P_GROUP_INTERFACE_GO : | 
|  | 2334 | P2P_GROUP_INTERFACE_CLIENT; | 
|  | 2335 | wpa_s->global->p2p_group_formation = group_wpa_s; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2336 | wpa_s->global->pending_group_iface_for_p2ps = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2337 |  | 
|  | 2338 | wpas_p2p_clone_config(group_wpa_s, wpa_s); | 
|  | 2339 |  | 
| Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2340 | if (wpa_s->conf->p2p_interface_random_mac_addr) { | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2341 | if (wpa_drv_set_mac_addr(group_wpa_s, | 
|  | 2342 | wpa_s->pending_interface_addr) < 0) { | 
| Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2343 | wpa_msg(group_wpa_s, MSG_INFO, | 
|  | 2344 | "Failed to set random MAC address"); | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2345 | wpa_supplicant_remove_iface(wpa_s->global, group_wpa_s, | 
|  | 2346 | 0); | 
| Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2347 | return NULL; | 
|  | 2348 | } | 
|  | 2349 |  | 
|  | 2350 | if (wpa_supplicant_update_mac_addr(group_wpa_s) < 0) { | 
|  | 2351 | wpa_msg(group_wpa_s, MSG_INFO, | 
|  | 2352 | "Could not update MAC address information"); | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2353 | wpa_supplicant_remove_iface(wpa_s->global, group_wpa_s, | 
|  | 2354 | 0); | 
| Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2355 | return NULL; | 
|  | 2356 | } | 
|  | 2357 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2358 | wpa_printf(MSG_DEBUG, "P2P: Using random MAC address " MACSTR | 
|  | 2359 | " for the group", | 
|  | 2360 | MAC2STR(wpa_s->pending_interface_addr)); | 
| Jimmy Chen | 36c2199 | 2018-11-29 16:46:43 +0800 | [diff] [blame] | 2361 | } | 
|  | 2362 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2363 | return group_wpa_s; | 
|  | 2364 | } | 
|  | 2365 |  | 
|  | 2366 |  | 
|  | 2367 | static void wpas_p2p_group_formation_timeout(void *eloop_ctx, | 
|  | 2368 | void *timeout_ctx) | 
|  | 2369 | { | 
|  | 2370 | struct wpa_supplicant *wpa_s = eloop_ctx; | 
|  | 2371 | wpa_printf(MSG_DEBUG, "P2P: Group Formation timed out"); | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2372 | wpas_p2p_group_formation_failed(wpa_s, 0); | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2373 | } | 
|  | 2374 |  | 
|  | 2375 |  | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2376 | static void wpas_p2p_group_formation_failed(struct wpa_supplicant *wpa_s, | 
|  | 2377 | int already_deleted) | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2378 | { | 
|  | 2379 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2380 | wpa_s->p2pdev, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2381 | if (wpa_s->global->p2p) | 
|  | 2382 | p2p_group_formation_failed(wpa_s->global->p2p); | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2383 | wpas_group_formation_completed(wpa_s, 0, already_deleted); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2384 | } | 
|  | 2385 |  | 
|  | 2386 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2387 | static void wpas_p2p_grpform_fail_after_wps(struct wpa_supplicant *wpa_s) | 
|  | 2388 | { | 
|  | 2389 | wpa_printf(MSG_DEBUG, "P2P: Reject group formation due to WPS provisioning failure"); | 
|  | 2390 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2391 | wpa_s->p2pdev, NULL); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2392 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2393 | wpa_s->p2pdev, NULL); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2394 | wpa_s->global->p2p_fail_on_wps_complete = 0; | 
|  | 2395 | } | 
|  | 2396 |  | 
|  | 2397 |  | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2398 | void wpas_p2p_ap_setup_failed(struct wpa_supplicant *wpa_s) | 
|  | 2399 | { | 
|  | 2400 | if (wpa_s->global->p2p_group_formation != wpa_s) | 
|  | 2401 | return; | 
|  | 2402 | /* Speed up group formation timeout since this cannot succeed */ | 
|  | 2403 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2404 | wpa_s->p2pdev, NULL); | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2405 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2406 | wpa_s->p2pdev, NULL); | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2407 | } | 
|  | 2408 |  | 
|  | 2409 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2410 | 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] | 2411 | { | 
|  | 2412 | struct wpa_supplicant *wpa_s = ctx; | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2413 | struct wpa_supplicant *group_wpa_s; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2414 |  | 
|  | 2415 | if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) { | 
|  | 2416 | wpa_drv_cancel_remain_on_channel(wpa_s); | 
|  | 2417 | wpa_s->off_channel_freq = 0; | 
|  | 2418 | wpa_s->roc_waiting_drv_freq = 0; | 
|  | 2419 | } | 
|  | 2420 |  | 
|  | 2421 | if (res->status) { | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2422 | wpa_msg_global(wpa_s, MSG_INFO, | 
|  | 2423 | P2P_EVENT_GO_NEG_FAILURE "status=%d", | 
|  | 2424 | res->status); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2425 | wpas_notify_p2p_go_neg_completed(wpa_s, res); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2426 | wpas_p2p_remove_pending_group_interface(wpa_s); | 
|  | 2427 | return; | 
|  | 2428 | } | 
|  | 2429 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2430 | if (!res->role_go) { | 
|  | 2431 | /* Inform driver of the operating channel of GO. */ | 
|  | 2432 | wpa_drv_set_prob_oper_freq(wpa_s, res->freq); | 
|  | 2433 | } | 
|  | 2434 |  | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2435 | if (wpa_s->p2p_go_ht40) | 
|  | 2436 | res->ht40 = 1; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2437 | if (wpa_s->p2p_go_vht) | 
|  | 2438 | res->vht = 1; | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2439 | if (wpa_s->p2p_go_he) | 
|  | 2440 | res->he = 1; | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2441 | if (wpa_s->p2p_go_edmg) | 
|  | 2442 | res->edmg = 1; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 2443 | res->max_oper_chwidth = wpa_s->p2p_go_max_oper_chwidth; | 
|  | 2444 | res->vht_center_freq2 = wpa_s->p2p_go_vht_center_freq2; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2445 |  | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2446 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_SUCCESS "role=%s " | 
|  | 2447 | "freq=%d ht40=%d peer_dev=" MACSTR " peer_iface=" MACSTR | 
|  | 2448 | " wps_method=%s", | 
|  | 2449 | res->role_go ? "GO" : "client", res->freq, res->ht40, | 
|  | 2450 | MAC2STR(res->peer_device_addr), | 
|  | 2451 | MAC2STR(res->peer_interface_addr), | 
|  | 2452 | p2p_wps_method_text(res->wps_method)); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2453 | wpas_notify_p2p_go_neg_completed(wpa_s, res); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2454 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2455 | if (res->role_go && wpa_s->p2p_persistent_id >= 0) { | 
|  | 2456 | struct wpa_ssid *ssid; | 
|  | 2457 | ssid = wpa_config_get_network(wpa_s->conf, | 
|  | 2458 | wpa_s->p2p_persistent_id); | 
|  | 2459 | if (ssid && ssid->disabled == 2 && | 
|  | 2460 | ssid->mode == WPAS_MODE_P2P_GO && ssid->passphrase) { | 
|  | 2461 | size_t len = os_strlen(ssid->passphrase); | 
|  | 2462 | wpa_printf(MSG_DEBUG, "P2P: Override passphrase based " | 
|  | 2463 | "on requested persistent group"); | 
|  | 2464 | os_memcpy(res->passphrase, ssid->passphrase, len); | 
|  | 2465 | res->passphrase[len] = '\0'; | 
|  | 2466 | } | 
|  | 2467 | } | 
|  | 2468 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2469 | if (wpa_s->create_p2p_iface) { | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2470 | group_wpa_s = | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2471 | wpas_p2p_init_group_interface(wpa_s, res->role_go); | 
|  | 2472 | if (group_wpa_s == NULL) { | 
|  | 2473 | wpas_p2p_remove_pending_group_interface(wpa_s); | 
| Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 2474 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, | 
|  | 2475 | wpa_s, NULL); | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2476 | wpas_p2p_group_formation_failed(wpa_s, 1); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2477 | return; | 
|  | 2478 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2479 | os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN); | 
|  | 2480 | wpa_s->pending_interface_name[0] = '\0'; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2481 | } else { | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2482 | group_wpa_s = wpa_s->parent; | 
|  | 2483 | wpa_s->global->p2p_group_formation = group_wpa_s; | 
|  | 2484 | if (group_wpa_s != wpa_s) | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2485 | wpas_p2p_clone_config(group_wpa_s, wpa_s); | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2486 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2487 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2488 | group_wpa_s->p2p_in_provisioning = 1; | 
|  | 2489 | group_wpa_s->p2pdev = wpa_s; | 
|  | 2490 | if (group_wpa_s != wpa_s) { | 
|  | 2491 | os_memcpy(group_wpa_s->p2p_pin, wpa_s->p2p_pin, | 
|  | 2492 | sizeof(group_wpa_s->p2p_pin)); | 
|  | 2493 | group_wpa_s->p2p_wps_method = wpa_s->p2p_wps_method; | 
|  | 2494 | } | 
|  | 2495 | if (res->role_go) { | 
|  | 2496 | wpas_start_wps_go(group_wpa_s, res, 1); | 
|  | 2497 | } else { | 
|  | 2498 | os_get_reltime(&group_wpa_s->scan_min_time); | 
|  | 2499 | wpas_start_wps_enrollee(group_wpa_s, res); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2500 | } | 
|  | 2501 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2502 | wpa_s->global->p2p_long_listen = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2503 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); | 
|  | 2504 |  | 
|  | 2505 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL); | 
|  | 2506 | eloop_register_timeout(15 + res->peer_config_timeout / 100, | 
|  | 2507 | (res->peer_config_timeout % 100) * 10000, | 
|  | 2508 | wpas_p2p_group_formation_timeout, wpa_s, NULL); | 
|  | 2509 | } | 
|  | 2510 |  | 
|  | 2511 |  | 
| Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 2512 | static void wpas_go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id, | 
|  | 2513 | u8 go_intent) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2514 | { | 
|  | 2515 | struct wpa_supplicant *wpa_s = ctx; | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2516 | 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] | 2517 | " dev_passwd_id=%u go_intent=%u", MAC2STR(src), | 
|  | 2518 | dev_passwd_id, go_intent); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2519 |  | 
| Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 2520 | 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] | 2521 | } | 
|  | 2522 |  | 
|  | 2523 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2524 | static void wpas_dev_found(void *ctx, const u8 *addr, | 
|  | 2525 | const struct p2p_peer_info *info, | 
|  | 2526 | int new_device) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2527 | { | 
| Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2528 | u8 *wfd_dev_info = NULL; | 
|  | 2529 | u8 wfd_dev_info_len = 0; | 
| Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2530 | u8 *wfd_r2_dev_info = NULL; | 
| Jimmy Chen | 57e19f5 | 2021-03-04 14:19:52 +0800 | [diff] [blame] | 2531 | u8 wfd_r2_dev_info_len = 0; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2532 | #ifndef CONFIG_NO_STDOUT_DEBUG | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2533 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 2534 | char devtype[WPS_DEV_TYPE_BUFSIZE]; | 
| Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2535 | char *wfd_dev_info_hex = NULL; | 
| Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2536 | char *wfd_r2_dev_info_hex = NULL; | 
| Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2537 |  | 
| Irfan Sheriff | 8367dc9 | 2012-09-09 17:08:19 -0700 | [diff] [blame] | 2538 | #ifdef CONFIG_WIFI_DISPLAY | 
| Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2539 | wfd_dev_info_hex = wifi_display_subelem_hex(info->wfd_subelems, | 
|  | 2540 | WFD_SUBELEM_DEVICE_INFO); | 
| Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2541 | if (wfd_dev_info_hex) { | 
|  | 2542 | wfd_dev_info_len = strlen(wfd_dev_info_hex) / 2; | 
|  | 2543 | wfd_dev_info = os_zalloc(wfd_dev_info_len); | 
|  | 2544 | // Only used for notification, so not handling error. | 
|  | 2545 | hexstr2bin(wfd_dev_info_hex, wfd_dev_info, wfd_dev_info_len); | 
|  | 2546 | } | 
| Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2547 |  | 
|  | 2548 | wfd_r2_dev_info_hex = wifi_display_subelem_hex(info->wfd_subelems, | 
|  | 2549 | WFD_SUBELEM_R2_DEVICE_INFO); | 
|  | 2550 | if (wfd_r2_dev_info_hex) { | 
|  | 2551 | wfd_r2_dev_info_len = strlen(wfd_r2_dev_info_hex) / 2; | 
|  | 2552 | wfd_r2_dev_info = os_zalloc(wfd_r2_dev_info_len); | 
|  | 2553 | // Only used for notification, so not handling error. | 
|  | 2554 | hexstr2bin(wfd_r2_dev_info_hex, wfd_r2_dev_info, wfd_r2_dev_info_len); | 
|  | 2555 | } | 
| Irfan Sheriff | 8367dc9 | 2012-09-09 17:08:19 -0700 | [diff] [blame] | 2556 | #endif /* CONFIG_WIFI_DISPLAY */ | 
| Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2557 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2558 | if (info->p2ps_instance) { | 
|  | 2559 | char str[256]; | 
|  | 2560 | const u8 *buf = wpabuf_head(info->p2ps_instance); | 
|  | 2561 | size_t len = wpabuf_len(info->p2ps_instance); | 
|  | 2562 |  | 
|  | 2563 | while (len) { | 
|  | 2564 | u32 id; | 
|  | 2565 | u16 methods; | 
|  | 2566 | u8 str_len; | 
|  | 2567 |  | 
|  | 2568 | if (len < 4 + 2 + 1) | 
|  | 2569 | break; | 
|  | 2570 | id = WPA_GET_LE32(buf); | 
|  | 2571 | buf += sizeof(u32); | 
|  | 2572 | methods = WPA_GET_BE16(buf); | 
|  | 2573 | buf += sizeof(u16); | 
|  | 2574 | str_len = *buf++; | 
|  | 2575 | if (str_len > len - 4 - 2 - 1) | 
|  | 2576 | break; | 
|  | 2577 | os_memcpy(str, buf, str_len); | 
|  | 2578 | str[str_len] = '\0'; | 
|  | 2579 | buf += str_len; | 
|  | 2580 | len -= str_len + sizeof(u32) + sizeof(u16) + sizeof(u8); | 
|  | 2581 |  | 
|  | 2582 | wpa_msg_global(wpa_s, MSG_INFO, | 
|  | 2583 | P2P_EVENT_DEVICE_FOUND MACSTR | 
|  | 2584 | " p2p_dev_addr=" MACSTR | 
|  | 2585 | " pri_dev_type=%s name='%s'" | 
|  | 2586 | " config_methods=0x%x" | 
|  | 2587 | " dev_capab=0x%x" | 
|  | 2588 | " group_capab=0x%x" | 
|  | 2589 | " adv_id=%x asp_svc=%s%s", | 
|  | 2590 | MAC2STR(addr), | 
|  | 2591 | MAC2STR(info->p2p_device_addr), | 
|  | 2592 | wps_dev_type_bin2str( | 
|  | 2593 | info->pri_dev_type, | 
|  | 2594 | devtype, sizeof(devtype)), | 
|  | 2595 | info->device_name, methods, | 
|  | 2596 | info->dev_capab, info->group_capab, | 
|  | 2597 | id, str, | 
|  | 2598 | info->vendor_elems ? | 
|  | 2599 | " vendor_elems=1" : ""); | 
|  | 2600 | } | 
|  | 2601 | goto done; | 
|  | 2602 | } | 
|  | 2603 |  | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2604 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_FOUND MACSTR | 
|  | 2605 | " p2p_dev_addr=" MACSTR | 
|  | 2606 | " pri_dev_type=%s name='%s' config_methods=0x%x " | 
| Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2607 | "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] | 2608 | MAC2STR(addr), MAC2STR(info->p2p_device_addr), | 
|  | 2609 | wps_dev_type_bin2str(info->pri_dev_type, devtype, | 
|  | 2610 | sizeof(devtype)), | 
|  | 2611 | info->device_name, info->config_methods, | 
|  | 2612 | info->dev_capab, info->group_capab, | 
| Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2613 | wfd_dev_info_hex ? " wfd_dev_info=0x" : "", | 
| Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 2614 | wfd_dev_info_hex ? wfd_dev_info_hex : "", | 
| Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2615 | wfd_r2_dev_info_hex ? " wfd_r2_dev_info=0x" : "", | 
|  | 2616 | wfd_r2_dev_info_hex ? wfd_r2_dev_info_hex : "", | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2617 | info->vendor_elems ? " vendor_elems=1" : "", | 
|  | 2618 | new_device); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2619 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2620 | done: | 
| Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2621 | os_free(wfd_dev_info_hex); | 
| Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2622 | os_free(wfd_r2_dev_info_hex); | 
| Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 2623 | #endif /* CONFIG_NO_STDOUT_DEBUG */ | 
| Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2624 |  | 
| Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2625 | wpas_notify_p2p_device_found(ctx, addr, info, wfd_dev_info, | 
| Jimmy Chen | 0133fc1 | 2021-03-04 13:56:11 +0800 | [diff] [blame] | 2626 | wfd_dev_info_len, wfd_r2_dev_info, | 
|  | 2627 | wfd_r2_dev_info_len, new_device); | 
| Roshan Pius | fd2fd66 | 2017-01-23 13:41:57 -0800 | [diff] [blame] | 2628 | os_free(wfd_dev_info); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2629 | } | 
|  | 2630 |  | 
|  | 2631 |  | 
|  | 2632 | static void wpas_dev_lost(void *ctx, const u8 *dev_addr) | 
|  | 2633 | { | 
|  | 2634 | struct wpa_supplicant *wpa_s = ctx; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2635 |  | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2636 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_LOST | 
|  | 2637 | "p2p_dev_addr=" MACSTR, MAC2STR(dev_addr)); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2638 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2639 | wpas_notify_p2p_device_lost(wpa_s, dev_addr); | 
|  | 2640 | } | 
|  | 2641 |  | 
|  | 2642 |  | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2643 | static void wpas_find_stopped(void *ctx) | 
|  | 2644 | { | 
|  | 2645 | struct wpa_supplicant *wpa_s = ctx; | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2646 |  | 
|  | 2647 | if (wpa_s->p2p_scan_work && wpas_abort_ongoing_scan(wpa_s) < 0) | 
|  | 2648 | wpa_printf(MSG_DEBUG, "P2P: Abort ongoing scan failed"); | 
|  | 2649 |  | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2650 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_FIND_STOPPED); | 
| Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 2651 | wpas_notify_p2p_find_stopped(wpa_s); | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2652 | } | 
|  | 2653 |  | 
|  | 2654 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2655 | struct wpas_p2p_listen_work { | 
|  | 2656 | unsigned int freq; | 
|  | 2657 | unsigned int duration; | 
|  | 2658 | struct wpabuf *probe_resp_ie; | 
|  | 2659 | }; | 
|  | 2660 |  | 
|  | 2661 |  | 
|  | 2662 | static void wpas_p2p_listen_work_free(struct wpas_p2p_listen_work *lwork) | 
|  | 2663 | { | 
|  | 2664 | if (lwork == NULL) | 
|  | 2665 | return; | 
|  | 2666 | wpabuf_free(lwork->probe_resp_ie); | 
|  | 2667 | os_free(lwork); | 
|  | 2668 | } | 
|  | 2669 |  | 
|  | 2670 |  | 
|  | 2671 | static void wpas_p2p_listen_work_done(struct wpa_supplicant *wpa_s) | 
|  | 2672 | { | 
|  | 2673 | struct wpas_p2p_listen_work *lwork; | 
|  | 2674 |  | 
|  | 2675 | if (!wpa_s->p2p_listen_work) | 
|  | 2676 | return; | 
|  | 2677 |  | 
|  | 2678 | lwork = wpa_s->p2p_listen_work->ctx; | 
|  | 2679 | wpas_p2p_listen_work_free(lwork); | 
|  | 2680 | radio_work_done(wpa_s->p2p_listen_work); | 
|  | 2681 | wpa_s->p2p_listen_work = NULL; | 
|  | 2682 | } | 
|  | 2683 |  | 
|  | 2684 |  | 
|  | 2685 | static void wpas_start_listen_cb(struct wpa_radio_work *work, int deinit) | 
|  | 2686 | { | 
|  | 2687 | struct wpa_supplicant *wpa_s = work->wpa_s; | 
|  | 2688 | struct wpas_p2p_listen_work *lwork = work->ctx; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2689 | unsigned int duration; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2690 |  | 
|  | 2691 | if (deinit) { | 
| Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 2692 | if (work->started) { | 
|  | 2693 | wpa_s->p2p_listen_work = NULL; | 
|  | 2694 | wpas_stop_listen(wpa_s); | 
|  | 2695 | } | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2696 | wpas_p2p_listen_work_free(lwork); | 
|  | 2697 | return; | 
|  | 2698 | } | 
|  | 2699 |  | 
|  | 2700 | wpa_s->p2p_listen_work = work; | 
|  | 2701 |  | 
|  | 2702 | wpa_drv_set_ap_wps_ie(wpa_s, NULL, lwork->probe_resp_ie, NULL); | 
|  | 2703 |  | 
|  | 2704 | if (wpa_drv_probe_req_report(wpa_s, 1) < 0) { | 
|  | 2705 | wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver to " | 
|  | 2706 | "report received Probe Request frames"); | 
|  | 2707 | wpas_p2p_listen_work_done(wpa_s); | 
|  | 2708 | return; | 
|  | 2709 | } | 
|  | 2710 |  | 
|  | 2711 | wpa_s->pending_listen_freq = lwork->freq; | 
|  | 2712 | wpa_s->pending_listen_duration = lwork->duration; | 
|  | 2713 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2714 | duration = lwork->duration; | 
|  | 2715 | #ifdef CONFIG_TESTING_OPTIONS | 
|  | 2716 | if (wpa_s->extra_roc_dur) { | 
|  | 2717 | wpa_printf(MSG_DEBUG, "TESTING: Increase ROC duration %u -> %u", | 
|  | 2718 | duration, duration + wpa_s->extra_roc_dur); | 
|  | 2719 | duration += wpa_s->extra_roc_dur; | 
|  | 2720 | } | 
|  | 2721 | #endif /* CONFIG_TESTING_OPTIONS */ | 
|  | 2722 |  | 
|  | 2723 | if (wpa_drv_remain_on_channel(wpa_s, lwork->freq, duration) < 0) { | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2724 | wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver " | 
|  | 2725 | "to remain on channel (%u MHz) for Listen " | 
|  | 2726 | "state", lwork->freq); | 
|  | 2727 | wpas_p2p_listen_work_done(wpa_s); | 
|  | 2728 | wpa_s->pending_listen_freq = 0; | 
|  | 2729 | return; | 
|  | 2730 | } | 
|  | 2731 | wpa_s->off_channel_freq = 0; | 
|  | 2732 | wpa_s->roc_waiting_drv_freq = lwork->freq; | 
|  | 2733 | } | 
|  | 2734 |  | 
|  | 2735 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2736 | static int wpas_start_listen(void *ctx, unsigned int freq, | 
|  | 2737 | unsigned int duration, | 
|  | 2738 | const struct wpabuf *probe_resp_ie) | 
|  | 2739 | { | 
|  | 2740 | struct wpa_supplicant *wpa_s = ctx; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2741 | struct wpas_p2p_listen_work *lwork; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2742 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2743 | if (wpa_s->p2p_listen_work) { | 
|  | 2744 | 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] | 2745 | return -1; | 
|  | 2746 | } | 
|  | 2747 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2748 | lwork = os_zalloc(sizeof(*lwork)); | 
|  | 2749 | if (lwork == NULL) | 
|  | 2750 | return -1; | 
|  | 2751 | lwork->freq = freq; | 
|  | 2752 | lwork->duration = duration; | 
|  | 2753 | if (probe_resp_ie) { | 
|  | 2754 | lwork->probe_resp_ie = wpabuf_dup(probe_resp_ie); | 
|  | 2755 | if (lwork->probe_resp_ie == NULL) { | 
|  | 2756 | wpas_p2p_listen_work_free(lwork); | 
|  | 2757 | return -1; | 
|  | 2758 | } | 
|  | 2759 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2760 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2761 | if (radio_add_work(wpa_s, freq, "p2p-listen", 0, wpas_start_listen_cb, | 
|  | 2762 | lwork) < 0) { | 
|  | 2763 | wpas_p2p_listen_work_free(lwork); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2764 | return -1; | 
|  | 2765 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2766 |  | 
|  | 2767 | return 0; | 
|  | 2768 | } | 
|  | 2769 |  | 
|  | 2770 |  | 
|  | 2771 | static void wpas_stop_listen(void *ctx) | 
|  | 2772 | { | 
|  | 2773 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 2774 | if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) { | 
|  | 2775 | wpa_drv_cancel_remain_on_channel(wpa_s); | 
|  | 2776 | wpa_s->off_channel_freq = 0; | 
|  | 2777 | wpa_s->roc_waiting_drv_freq = 0; | 
|  | 2778 | } | 
|  | 2779 | wpa_drv_set_ap_wps_ie(wpa_s, NULL, NULL, NULL); | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2780 |  | 
|  | 2781 | /* | 
|  | 2782 | * Don't cancel Probe Request RX reporting for a connected P2P Client | 
|  | 2783 | * handling Probe Request frames. | 
|  | 2784 | */ | 
|  | 2785 | if (!wpa_s->p2p_cli_probe) | 
|  | 2786 | wpa_drv_probe_req_report(wpa_s, 0); | 
|  | 2787 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2788 | wpas_p2p_listen_work_done(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2789 | } | 
|  | 2790 |  | 
|  | 2791 |  | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2792 | static int wpas_send_probe_resp(void *ctx, const struct wpabuf *buf, | 
|  | 2793 | unsigned int freq) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2794 | { | 
|  | 2795 | struct wpa_supplicant *wpa_s = ctx; | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 2796 | 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] | 2797 | freq, 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2798 | } | 
|  | 2799 |  | 
|  | 2800 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2801 | static void wpas_prov_disc_local_display(struct wpa_supplicant *wpa_s, | 
|  | 2802 | const u8 *peer, const char *params, | 
|  | 2803 | unsigned int generated_pin) | 
|  | 2804 | { | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2805 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR | 
|  | 2806 | " %08d%s", MAC2STR(peer), generated_pin, params); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2807 | } | 
|  | 2808 |  | 
|  | 2809 |  | 
|  | 2810 | static void wpas_prov_disc_local_keypad(struct wpa_supplicant *wpa_s, | 
|  | 2811 | const u8 *peer, const char *params) | 
|  | 2812 | { | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2813 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR | 
|  | 2814 | "%s", MAC2STR(peer), params); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2815 | } | 
|  | 2816 |  | 
|  | 2817 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2818 | static void wpas_prov_disc_req(void *ctx, const u8 *peer, u16 config_methods, | 
|  | 2819 | const u8 *dev_addr, const u8 *pri_dev_type, | 
|  | 2820 | const char *dev_name, u16 supp_config_methods, | 
|  | 2821 | u8 dev_capab, u8 group_capab, const u8 *group_id, | 
|  | 2822 | size_t group_id_len) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2823 | { | 
|  | 2824 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 2825 | char devtype[WPS_DEV_TYPE_BUFSIZE]; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2826 | char params[300]; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2827 | u8 empty_dev_type[8]; | 
|  | 2828 | unsigned int generated_pin = 0; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2829 | struct wpa_supplicant *group = NULL; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2830 | int res; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2831 |  | 
|  | 2832 | if (group_id) { | 
|  | 2833 | for (group = wpa_s->global->ifaces; group; group = group->next) | 
|  | 2834 | { | 
|  | 2835 | struct wpa_ssid *s = group->current_ssid; | 
|  | 2836 | if (s != NULL && | 
|  | 2837 | s->mode == WPAS_MODE_P2P_GO && | 
|  | 2838 | group_id_len - ETH_ALEN == s->ssid_len && | 
|  | 2839 | os_memcmp(group_id + ETH_ALEN, s->ssid, | 
|  | 2840 | s->ssid_len) == 0) | 
|  | 2841 | break; | 
|  | 2842 | } | 
|  | 2843 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2844 |  | 
|  | 2845 | if (pri_dev_type == NULL) { | 
|  | 2846 | os_memset(empty_dev_type, 0, sizeof(empty_dev_type)); | 
|  | 2847 | pri_dev_type = empty_dev_type; | 
|  | 2848 | } | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2849 | res = os_snprintf(params, sizeof(params), " p2p_dev_addr=" MACSTR | 
|  | 2850 | " pri_dev_type=%s name='%s' config_methods=0x%x " | 
|  | 2851 | "dev_capab=0x%x group_capab=0x%x%s%s", | 
|  | 2852 | MAC2STR(dev_addr), | 
|  | 2853 | wps_dev_type_bin2str(pri_dev_type, devtype, | 
|  | 2854 | sizeof(devtype)), | 
|  | 2855 | dev_name, supp_config_methods, dev_capab, group_capab, | 
|  | 2856 | group ? " group=" : "", | 
|  | 2857 | group ? group->ifname : ""); | 
|  | 2858 | if (os_snprintf_error(sizeof(params), res)) | 
|  | 2859 | wpa_printf(MSG_DEBUG, "P2P: PD Request event truncated"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2860 | params[sizeof(params) - 1] = '\0'; | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2861 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2862 | if (config_methods & WPS_CONFIG_DISPLAY) { | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2863 | if (wps_generate_pin(&generated_pin) < 0) { | 
|  | 2864 | wpa_printf(MSG_DEBUG, "P2P: Could not generate PIN"); | 
|  | 2865 | wpas_notify_p2p_provision_discovery( | 
|  | 2866 | wpa_s, peer, 0 /* response */, | 
|  | 2867 | P2P_PROV_DISC_INFO_UNAVAILABLE, 0, 0); | 
|  | 2868 | return; | 
|  | 2869 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2870 | wpas_prov_disc_local_display(wpa_s, peer, params, | 
|  | 2871 | generated_pin); | 
|  | 2872 | } else if (config_methods & WPS_CONFIG_KEYPAD) | 
|  | 2873 | wpas_prov_disc_local_keypad(wpa_s, peer, params); | 
|  | 2874 | else if (config_methods & WPS_CONFIG_PUSHBUTTON) | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2875 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_REQ | 
|  | 2876 | MACSTR "%s", MAC2STR(peer), params); | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2877 |  | 
|  | 2878 | wpas_notify_p2p_provision_discovery(wpa_s, peer, 1 /* request */, | 
|  | 2879 | P2P_PROV_DISC_SUCCESS, | 
|  | 2880 | config_methods, generated_pin); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2881 | } | 
|  | 2882 |  | 
|  | 2883 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2884 | 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] | 2885 | { | 
|  | 2886 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 2887 | unsigned int generated_pin = 0; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2888 | char params[20]; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2889 |  | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2890 | if (wpa_s->pending_pd_before_join && | 
|  | 2891 | (os_memcmp(peer, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 || | 
|  | 2892 | os_memcmp(peer, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0)) { | 
|  | 2893 | wpa_s->pending_pd_before_join = 0; | 
|  | 2894 | wpa_printf(MSG_DEBUG, "P2P: Starting pending " | 
|  | 2895 | "join-existing-group operation"); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2896 | wpas_p2p_join_start(wpa_s, 0, NULL, 0); | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2897 | return; | 
|  | 2898 | } | 
|  | 2899 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2900 | if (wpa_s->pending_pd_use == AUTO_PD_JOIN || | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2901 | wpa_s->pending_pd_use == AUTO_PD_GO_NEG) { | 
|  | 2902 | int res; | 
|  | 2903 |  | 
|  | 2904 | res = os_snprintf(params, sizeof(params), " peer_go=%d", | 
|  | 2905 | wpa_s->pending_pd_use == AUTO_PD_JOIN); | 
|  | 2906 | if (os_snprintf_error(sizeof(params), res)) | 
|  | 2907 | params[sizeof(params) - 1] = '\0'; | 
|  | 2908 | } else | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2909 | params[0] = '\0'; | 
|  | 2910 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2911 | if (config_methods & WPS_CONFIG_DISPLAY) | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2912 | wpas_prov_disc_local_keypad(wpa_s, peer, params); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2913 | else if (config_methods & WPS_CONFIG_KEYPAD) { | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2914 | if (wps_generate_pin(&generated_pin) < 0) { | 
|  | 2915 | wpa_printf(MSG_DEBUG, "P2P: Could not generate PIN"); | 
|  | 2916 | wpas_notify_p2p_provision_discovery( | 
|  | 2917 | wpa_s, peer, 0 /* response */, | 
|  | 2918 | P2P_PROV_DISC_INFO_UNAVAILABLE, 0, 0); | 
|  | 2919 | return; | 
|  | 2920 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2921 | wpas_prov_disc_local_display(wpa_s, peer, params, | 
|  | 2922 | generated_pin); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2923 | } else if (config_methods & WPS_CONFIG_PUSHBUTTON) | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 2924 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_RESP | 
|  | 2925 | MACSTR "%s", MAC2STR(peer), params); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2926 |  | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2927 | wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */, | 
|  | 2928 | P2P_PROV_DISC_SUCCESS, | 
|  | 2929 | config_methods, generated_pin); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2930 | } | 
|  | 2931 |  | 
|  | 2932 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2933 | static void wpas_prov_disc_fail(void *ctx, const u8 *peer, | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2934 | enum p2p_prov_disc_status status, | 
|  | 2935 | u32 adv_id, const u8 *adv_mac, | 
|  | 2936 | const char *deferred_session_resp) | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2937 | { | 
|  | 2938 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 2939 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2940 | if (wpa_s->p2p_fallback_to_go_neg) { | 
|  | 2941 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: PD for p2p_connect-auto " | 
|  | 2942 | "failed - fall back to GO Negotiation"); | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2943 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2944 | P2P_EVENT_FALLBACK_TO_GO_NEG | 
|  | 2945 | "reason=PD-failed"); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2946 | wpas_p2p_fallback_to_go_neg(wpa_s, 0); | 
|  | 2947 | return; | 
|  | 2948 | } | 
|  | 2949 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2950 | if (status == P2P_PROV_DISC_TIMEOUT_JOIN) { | 
| Dmitry Shmidt | 2b38048 | 2012-09-13 10:52:13 -0700 | [diff] [blame] | 2951 | wpa_s->pending_pd_before_join = 0; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2952 | wpa_printf(MSG_DEBUG, "P2P: Starting pending " | 
|  | 2953 | "join-existing-group operation (no ACK for PD " | 
|  | 2954 | "Req attempts)"); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2955 | wpas_p2p_join_start(wpa_s, 0, NULL, 0); | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2956 | return; | 
| Dmitry Shmidt | 2b38048 | 2012-09-13 10:52:13 -0700 | [diff] [blame] | 2957 | } | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2958 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2959 | if (adv_id && adv_mac && deferred_session_resp) { | 
|  | 2960 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE | 
|  | 2961 | " p2p_dev_addr=" MACSTR " status=%d adv_id=%x" | 
|  | 2962 | " deferred_session_resp='%s'", | 
|  | 2963 | MAC2STR(peer), status, adv_id, | 
|  | 2964 | deferred_session_resp); | 
|  | 2965 | } else if (adv_id && adv_mac) { | 
|  | 2966 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE | 
|  | 2967 | " p2p_dev_addr=" MACSTR " status=%d adv_id=%x", | 
|  | 2968 | MAC2STR(peer), status, adv_id); | 
|  | 2969 | } else { | 
|  | 2970 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE | 
|  | 2971 | " p2p_dev_addr=" MACSTR " status=%d", | 
|  | 2972 | MAC2STR(peer), status); | 
|  | 2973 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2974 |  | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2975 | wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */, | 
|  | 2976 | status, 0, 0); | 
|  | 2977 | } | 
|  | 2978 |  | 
|  | 2979 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2980 | static int freq_included(struct wpa_supplicant *wpa_s, | 
|  | 2981 | const struct p2p_channels *channels, | 
|  | 2982 | unsigned int freq) | 
| Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 2983 | { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2984 | if ((channels == NULL || p2p_channels_includes_freq(channels, freq)) && | 
|  | 2985 | wpas_p2p_go_is_peer_freq(wpa_s, freq)) | 
|  | 2986 | return 1; | 
|  | 2987 | return 0; | 
|  | 2988 | } | 
| Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 2989 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2990 |  | 
|  | 2991 | static void wpas_p2p_go_update_common_freqs(struct wpa_supplicant *wpa_s) | 
|  | 2992 | { | 
|  | 2993 | unsigned int num = P2P_MAX_CHANNELS; | 
|  | 2994 | int *common_freqs; | 
|  | 2995 | int ret; | 
|  | 2996 |  | 
|  | 2997 | p2p_go_dump_common_freqs(wpa_s); | 
|  | 2998 | common_freqs = os_calloc(num, sizeof(int)); | 
|  | 2999 | if (!common_freqs) | 
|  | 3000 | return; | 
|  | 3001 |  | 
|  | 3002 | ret = p2p_group_get_common_freqs(wpa_s->p2p_group, common_freqs, &num); | 
|  | 3003 | if (ret < 0) { | 
|  | 3004 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 3005 | "P2P: Failed to get group common freqs"); | 
|  | 3006 | os_free(common_freqs); | 
|  | 3007 | return; | 
|  | 3008 | } | 
|  | 3009 |  | 
|  | 3010 | os_free(wpa_s->p2p_group_common_freqs); | 
|  | 3011 | wpa_s->p2p_group_common_freqs = common_freqs; | 
|  | 3012 | wpa_s->p2p_group_common_freqs_num = num; | 
|  | 3013 | p2p_go_dump_common_freqs(wpa_s); | 
|  | 3014 | } | 
|  | 3015 |  | 
|  | 3016 |  | 
|  | 3017 | /* | 
|  | 3018 | * Check if the given frequency is one of the possible operating frequencies | 
|  | 3019 | * set after the completion of the GO Negotiation. | 
|  | 3020 | */ | 
|  | 3021 | static int wpas_p2p_go_is_peer_freq(struct wpa_supplicant *wpa_s, int freq) | 
|  | 3022 | { | 
|  | 3023 | unsigned int i; | 
|  | 3024 |  | 
|  | 3025 | p2p_go_dump_common_freqs(wpa_s); | 
|  | 3026 |  | 
|  | 3027 | /* assume no restrictions */ | 
|  | 3028 | if (!wpa_s->p2p_group_common_freqs_num) | 
|  | 3029 | return 1; | 
|  | 3030 |  | 
|  | 3031 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { | 
|  | 3032 | if (wpa_s->p2p_group_common_freqs[i] == freq) | 
|  | 3033 | return 1; | 
|  | 3034 | } | 
|  | 3035 | return 0; | 
|  | 3036 | } | 
|  | 3037 |  | 
|  | 3038 |  | 
|  | 3039 | static int wpas_sta_check_ecsa(struct hostapd_data *hapd, | 
|  | 3040 | struct sta_info *sta, void *ctx) | 
|  | 3041 | { | 
|  | 3042 | int *ecsa_support = ctx; | 
|  | 3043 |  | 
|  | 3044 | *ecsa_support &= sta->ecsa_supported; | 
|  | 3045 |  | 
|  | 3046 | return 0; | 
|  | 3047 | } | 
|  | 3048 |  | 
|  | 3049 |  | 
|  | 3050 | /* Check if all the peers support eCSA */ | 
|  | 3051 | static int wpas_p2p_go_clients_support_ecsa(struct wpa_supplicant *wpa_s) | 
|  | 3052 | { | 
|  | 3053 | int ecsa_support = 1; | 
|  | 3054 |  | 
|  | 3055 | ap_for_each_sta(wpa_s->ap_iface->bss[0], wpas_sta_check_ecsa, | 
|  | 3056 | &ecsa_support); | 
|  | 3057 |  | 
|  | 3058 | return ecsa_support; | 
| Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3059 | } | 
|  | 3060 |  | 
|  | 3061 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3062 | /** | 
|  | 3063 | * Pick the best frequency to use from all the currently used frequencies. | 
|  | 3064 | */ | 
|  | 3065 | static int wpas_p2p_pick_best_used_freq(struct wpa_supplicant *wpa_s, | 
|  | 3066 | struct wpa_used_freq_data *freqs, | 
|  | 3067 | unsigned int num) | 
|  | 3068 | { | 
|  | 3069 | unsigned int i, c; | 
|  | 3070 |  | 
|  | 3071 | /* find a candidate freq that is supported by P2P */ | 
|  | 3072 | for (c = 0; c < num; c++) | 
|  | 3073 | if (p2p_supported_freq(wpa_s->global->p2p, freqs[c].freq)) | 
|  | 3074 | break; | 
|  | 3075 |  | 
|  | 3076 | if (c == num) | 
|  | 3077 | return 0; | 
|  | 3078 |  | 
|  | 3079 | /* once we have a candidate, try to find a 'better' one */ | 
|  | 3080 | for (i = c + 1; i < num; i++) { | 
|  | 3081 | if (!p2p_supported_freq(wpa_s->global->p2p, freqs[i].freq)) | 
|  | 3082 | continue; | 
|  | 3083 |  | 
|  | 3084 | /* | 
|  | 3085 | * 1. Infrastructure station interfaces have higher preference. | 
|  | 3086 | * 2. P2P Clients have higher preference. | 
|  | 3087 | * 3. All others. | 
|  | 3088 | */ | 
|  | 3089 | if (freqs[i].flags & WPA_FREQ_USED_BY_INFRA_STATION) { | 
|  | 3090 | c = i; | 
|  | 3091 | break; | 
|  | 3092 | } | 
|  | 3093 |  | 
|  | 3094 | if ((freqs[i].flags & WPA_FREQ_USED_BY_P2P_CLIENT)) | 
|  | 3095 | c = i; | 
|  | 3096 | } | 
|  | 3097 | return freqs[c].freq; | 
|  | 3098 | } | 
|  | 3099 |  | 
|  | 3100 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3101 | static u8 wpas_invitation_process(void *ctx, const u8 *sa, const u8 *bssid, | 
|  | 3102 | const u8 *go_dev_addr, const u8 *ssid, | 
|  | 3103 | size_t ssid_len, int *go, u8 *group_bssid, | 
| Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3104 | int *force_freq, int persistent_group, | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3105 | const struct p2p_channels *channels, | 
|  | 3106 | int dev_pw_id) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3107 | { | 
|  | 3108 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 3109 | struct wpa_ssid *s; | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3110 | struct wpa_used_freq_data *freqs; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3111 | struct wpa_supplicant *grp; | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3112 | int best_freq; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3113 |  | 
|  | 3114 | if (!persistent_group) { | 
|  | 3115 | wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3116 | " to join an active group (SSID: %s)", | 
|  | 3117 | MAC2STR(sa), wpa_ssid_txt(ssid, ssid_len)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3118 | if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) && | 
|  | 3119 | (os_memcmp(go_dev_addr, wpa_s->p2p_auth_invite, ETH_ALEN) | 
|  | 3120 | == 0 || | 
|  | 3121 | os_memcmp(sa, wpa_s->p2p_auth_invite, ETH_ALEN) == 0)) { | 
|  | 3122 | wpa_printf(MSG_DEBUG, "P2P: Accept previously " | 
|  | 3123 | "authorized invitation"); | 
|  | 3124 | goto accept_inv; | 
|  | 3125 | } | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3126 |  | 
|  | 3127 | #ifdef CONFIG_WPS_NFC | 
| Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3128 | if (dev_pw_id >= 0 && wpa_s->p2p_nfc_tag_enabled && | 
|  | 3129 | dev_pw_id == wpa_s->p2p_oob_dev_pw_id) { | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3130 | 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] | 3131 | wpa_s->p2p_wps_method = WPS_NFC; | 
|  | 3132 | wpa_s->pending_join_wps_method = WPS_NFC; | 
|  | 3133 | os_memcpy(wpa_s->pending_join_dev_addr, | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3134 | go_dev_addr, ETH_ALEN); | 
| Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3135 | os_memcpy(wpa_s->pending_join_iface_addr, | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3136 | bssid, ETH_ALEN); | 
|  | 3137 | goto accept_inv; | 
|  | 3138 | } | 
|  | 3139 | #endif /* CONFIG_WPS_NFC */ | 
|  | 3140 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3141 | /* | 
|  | 3142 | * Do not accept the invitation automatically; notify user and | 
|  | 3143 | * request approval. | 
|  | 3144 | */ | 
|  | 3145 | return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; | 
|  | 3146 | } | 
|  | 3147 |  | 
|  | 3148 | grp = wpas_get_p2p_group(wpa_s, ssid, ssid_len, go); | 
|  | 3149 | if (grp) { | 
|  | 3150 | wpa_printf(MSG_DEBUG, "P2P: Accept invitation to already " | 
|  | 3151 | "running persistent group"); | 
|  | 3152 | if (*go) | 
|  | 3153 | os_memcpy(group_bssid, grp->own_addr, ETH_ALEN); | 
|  | 3154 | goto accept_inv; | 
|  | 3155 | } | 
|  | 3156 |  | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3157 | if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) && | 
|  | 3158 | os_memcmp(sa, wpa_s->p2p_auth_invite, ETH_ALEN) == 0) { | 
|  | 3159 | wpa_printf(MSG_DEBUG, "P2P: Accept previously initiated " | 
|  | 3160 | "invitation to re-invoke a persistent group"); | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3161 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3162 | } else if (!wpa_s->conf->persistent_reconnect) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3163 | return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; | 
|  | 3164 |  | 
|  | 3165 | for (s = wpa_s->conf->ssid; s; s = s->next) { | 
|  | 3166 | if (s->disabled == 2 && | 
|  | 3167 | os_memcmp(s->bssid, go_dev_addr, ETH_ALEN) == 0 && | 
|  | 3168 | s->ssid_len == ssid_len && | 
|  | 3169 | os_memcmp(ssid, s->ssid, ssid_len) == 0) | 
|  | 3170 | break; | 
|  | 3171 | } | 
|  | 3172 |  | 
|  | 3173 | if (!s) { | 
|  | 3174 | wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR | 
|  | 3175 | " requested reinvocation of an unknown group", | 
|  | 3176 | MAC2STR(sa)); | 
|  | 3177 | return P2P_SC_FAIL_UNKNOWN_GROUP; | 
|  | 3178 | } | 
|  | 3179 |  | 
|  | 3180 | if (s->mode == WPAS_MODE_P2P_GO && !wpas_p2p_create_iface(wpa_s)) { | 
|  | 3181 | *go = 1; | 
|  | 3182 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { | 
|  | 3183 | wpa_printf(MSG_DEBUG, "P2P: The only available " | 
|  | 3184 | "interface is already in use - reject " | 
|  | 3185 | "invitation"); | 
|  | 3186 | return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; | 
|  | 3187 | } | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3188 | if (wpa_s->p2p_mgmt) | 
|  | 3189 | os_memcpy(group_bssid, wpa_s->parent->own_addr, | 
|  | 3190 | ETH_ALEN); | 
|  | 3191 | else | 
|  | 3192 | os_memcpy(group_bssid, wpa_s->own_addr, ETH_ALEN); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3193 | } else if (s->mode == WPAS_MODE_P2P_GO) { | 
|  | 3194 | *go = 1; | 
|  | 3195 | if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO) < 0) | 
|  | 3196 | { | 
|  | 3197 | wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " | 
|  | 3198 | "interface address for the group"); | 
|  | 3199 | return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; | 
|  | 3200 | } | 
|  | 3201 | os_memcpy(group_bssid, wpa_s->pending_interface_addr, | 
|  | 3202 | ETH_ALEN); | 
|  | 3203 | } | 
|  | 3204 |  | 
|  | 3205 | accept_inv: | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3206 | wpas_p2p_set_own_freq_preference(wpa_s, 0); | 
|  | 3207 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3208 | best_freq = 0; | 
|  | 3209 | freqs = os_calloc(wpa_s->num_multichan_concurrent, | 
|  | 3210 | sizeof(struct wpa_used_freq_data)); | 
|  | 3211 | if (freqs) { | 
|  | 3212 | int num_channels = wpa_s->num_multichan_concurrent; | 
|  | 3213 | int num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, num_channels); | 
|  | 3214 | best_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num); | 
|  | 3215 | os_free(freqs); | 
|  | 3216 | } | 
|  | 3217 |  | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3218 | /* Get one of the frequencies currently in use */ | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 3219 | if (best_freq > 0) { | 
| Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 3220 | 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] | 3221 | wpas_p2p_set_own_freq_preference(wpa_s, best_freq); | 
| Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 3222 |  | 
|  | 3223 | if (wpa_s->num_multichan_concurrent < 2 || | 
|  | 3224 | wpas_p2p_num_unused_channels(wpa_s) < 1) { | 
|  | 3225 | 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] | 3226 | *force_freq = best_freq; | 
| Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 3227 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3228 | } | 
|  | 3229 |  | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3230 | if (*force_freq > 0 && wpa_s->num_multichan_concurrent > 1 && | 
|  | 3231 | wpas_p2p_num_unused_channels(wpa_s) > 0) { | 
| Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3232 | if (*go == 0) { | 
|  | 3233 | /* We are the client */ | 
|  | 3234 | wpa_printf(MSG_DEBUG, "P2P: Peer was found to be " | 
|  | 3235 | "running a GO but we are capable of MCC, " | 
|  | 3236 | "figure out the best channel to use"); | 
|  | 3237 | *force_freq = 0; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3238 | } else if (!freq_included(wpa_s, channels, *force_freq)) { | 
| Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3239 | /* We are the GO, and *force_freq is not in the | 
|  | 3240 | * intersection */ | 
|  | 3241 | wpa_printf(MSG_DEBUG, "P2P: Forced GO freq %d MHz not " | 
|  | 3242 | "in intersection but we are capable of MCC, " | 
|  | 3243 | "figure out the best channel to use", | 
|  | 3244 | *force_freq); | 
|  | 3245 | *force_freq = 0; | 
|  | 3246 | } | 
|  | 3247 | } | 
|  | 3248 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3249 | return P2P_SC_SUCCESS; | 
|  | 3250 | } | 
|  | 3251 |  | 
|  | 3252 |  | 
|  | 3253 | static void wpas_invitation_received(void *ctx, const u8 *sa, const u8 *bssid, | 
|  | 3254 | const u8 *ssid, size_t ssid_len, | 
|  | 3255 | const u8 *go_dev_addr, u8 status, | 
|  | 3256 | int op_freq) | 
|  | 3257 | { | 
|  | 3258 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 3259 | struct wpa_ssid *s; | 
|  | 3260 |  | 
|  | 3261 | for (s = wpa_s->conf->ssid; s; s = s->next) { | 
|  | 3262 | if (s->disabled == 2 && | 
|  | 3263 | s->ssid_len == ssid_len && | 
|  | 3264 | os_memcmp(ssid, s->ssid, ssid_len) == 0) | 
|  | 3265 | break; | 
|  | 3266 | } | 
|  | 3267 |  | 
|  | 3268 | if (status == P2P_SC_SUCCESS) { | 
|  | 3269 | wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3270 | " was accepted; op_freq=%d MHz, SSID=%s", | 
|  | 3271 | MAC2STR(sa), op_freq, wpa_ssid_txt(ssid, ssid_len)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3272 | if (s) { | 
| Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 3273 | int go = s->mode == WPAS_MODE_P2P_GO; | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 3274 | if (go) { | 
|  | 3275 | wpa_msg_global(wpa_s, MSG_INFO, | 
|  | 3276 | P2P_EVENT_INVITATION_ACCEPTED | 
|  | 3277 | "sa=" MACSTR | 
|  | 3278 | " persistent=%d freq=%d", | 
|  | 3279 | MAC2STR(sa), s->id, op_freq); | 
|  | 3280 | } else { | 
|  | 3281 | wpa_msg_global(wpa_s, MSG_INFO, | 
|  | 3282 | P2P_EVENT_INVITATION_ACCEPTED | 
|  | 3283 | "sa=" MACSTR | 
|  | 3284 | " persistent=%d", | 
|  | 3285 | MAC2STR(sa), s->id); | 
|  | 3286 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3287 | wpas_p2p_group_add_persistent( | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3288 | wpa_s, s, go, 0, op_freq, 0, | 
|  | 3289 | wpa_s->conf->p2p_go_ht40, | 
|  | 3290 | wpa_s->conf->p2p_go_vht, | 
|  | 3291 | 0, | 
|  | 3292 | wpa_s->conf->p2p_go_he, | 
|  | 3293 | wpa_s->conf->p2p_go_edmg, NULL, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3294 | go ? P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3295 | 1, is_p2p_allow_6ghz(wpa_s->global->p2p)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3296 | } else if (bssid) { | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3297 | wpa_s->user_initiated_pd = 0; | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 3298 | wpa_msg_global(wpa_s, MSG_INFO, | 
|  | 3299 | P2P_EVENT_INVITATION_ACCEPTED | 
|  | 3300 | "sa=" MACSTR " go_dev_addr=" MACSTR | 
|  | 3301 | " bssid=" MACSTR " unknown-network", | 
|  | 3302 | MAC2STR(sa), MAC2STR(go_dev_addr), | 
|  | 3303 | MAC2STR(bssid)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3304 | wpas_p2p_join(wpa_s, bssid, go_dev_addr, | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3305 | wpa_s->p2p_wps_method, 0, op_freq, | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3306 | ssid, ssid_len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3307 | } | 
|  | 3308 | return; | 
|  | 3309 | } | 
|  | 3310 |  | 
|  | 3311 | if (status != P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) { | 
|  | 3312 | wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR | 
|  | 3313 | " was rejected (status %u)", MAC2STR(sa), status); | 
|  | 3314 | return; | 
|  | 3315 | } | 
|  | 3316 |  | 
|  | 3317 | if (!s) { | 
|  | 3318 | if (bssid) { | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3319 | wpa_msg_global(wpa_s, MSG_INFO, | 
|  | 3320 | P2P_EVENT_INVITATION_RECEIVED | 
|  | 3321 | "sa=" MACSTR " go_dev_addr=" MACSTR | 
|  | 3322 | " bssid=" MACSTR " unknown-network", | 
|  | 3323 | MAC2STR(sa), MAC2STR(go_dev_addr), | 
|  | 3324 | MAC2STR(bssid)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3325 | } else { | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3326 | wpa_msg_global(wpa_s, MSG_INFO, | 
|  | 3327 | P2P_EVENT_INVITATION_RECEIVED | 
|  | 3328 | "sa=" MACSTR " go_dev_addr=" MACSTR | 
|  | 3329 | " unknown-network", | 
|  | 3330 | MAC2STR(sa), MAC2STR(go_dev_addr)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3331 | } | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3332 | wpas_notify_p2p_invitation_received(wpa_s, sa, go_dev_addr, | 
|  | 3333 | bssid, 0, op_freq); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3334 | return; | 
|  | 3335 | } | 
|  | 3336 |  | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3337 | if (s->mode == WPAS_MODE_P2P_GO && op_freq) { | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3338 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED | 
|  | 3339 | "sa=" MACSTR " persistent=%d freq=%d", | 
|  | 3340 | MAC2STR(sa), s->id, op_freq); | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3341 | } else { | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3342 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED | 
|  | 3343 | "sa=" MACSTR " persistent=%d", | 
|  | 3344 | MAC2STR(sa), s->id); | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3345 | } | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3346 | wpas_notify_p2p_invitation_received(wpa_s, sa, go_dev_addr, bssid, | 
|  | 3347 | s->id, op_freq); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3348 | } | 
|  | 3349 |  | 
|  | 3350 |  | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3351 | static void wpas_remove_persistent_peer(struct wpa_supplicant *wpa_s, | 
|  | 3352 | struct wpa_ssid *ssid, | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3353 | const u8 *peer, int inv) | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3354 | { | 
|  | 3355 | size_t i; | 
| Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 3356 | 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] | 3357 |  | 
|  | 3358 | if (ssid == NULL) | 
|  | 3359 | return; | 
|  | 3360 |  | 
|  | 3361 | 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] | 3362 | if (os_memcmp(ssid->p2p_client_list + i * 2 * ETH_ALEN, peer, | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3363 | ETH_ALEN) == 0) | 
|  | 3364 | break; | 
|  | 3365 | } | 
| Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 3366 | if (i >= ssid->num_p2p_clients || !ssid->p2p_client_list) { | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3367 | if (ssid->mode != WPAS_MODE_P2P_GO && | 
|  | 3368 | os_memcmp(ssid->bssid, peer, ETH_ALEN) == 0) { | 
|  | 3369 | wpa_printf(MSG_DEBUG, "P2P: Remove persistent group %d " | 
|  | 3370 | "due to invitation result", ssid->id); | 
|  | 3371 | wpas_notify_network_removed(wpa_s, ssid); | 
|  | 3372 | wpa_config_remove_network(wpa_s->conf, ssid->id); | 
|  | 3373 | return; | 
|  | 3374 | } | 
|  | 3375 | return; /* Peer not found in client list */ | 
|  | 3376 | } | 
|  | 3377 |  | 
|  | 3378 | wpa_printf(MSG_DEBUG, "P2P: Remove peer " MACSTR " from persistent " | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3379 | "group %d client list%s", | 
|  | 3380 | MAC2STR(peer), ssid->id, | 
|  | 3381 | inv ? " due to invitation result" : ""); | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3382 | os_memmove(ssid->p2p_client_list + i * 2 * ETH_ALEN, | 
|  | 3383 | ssid->p2p_client_list + (i + 1) * 2 * ETH_ALEN, | 
|  | 3384 | (ssid->num_p2p_clients - i - 1) * 2 * ETH_ALEN); | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3385 | ssid->num_p2p_clients--; | 
| Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 3386 | if (p2p_wpa_s->conf->update_config && | 
|  | 3387 | wpa_config_write(p2p_wpa_s->confname, p2p_wpa_s->conf)) | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3388 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3389 | } | 
|  | 3390 |  | 
|  | 3391 |  | 
|  | 3392 | static void wpas_remove_persistent_client(struct wpa_supplicant *wpa_s, | 
|  | 3393 | const u8 *peer) | 
|  | 3394 | { | 
|  | 3395 | struct wpa_ssid *ssid; | 
|  | 3396 |  | 
|  | 3397 | wpa_s = wpa_s->global->p2p_invite_group; | 
|  | 3398 | if (wpa_s == NULL) | 
|  | 3399 | return; /* No known invitation group */ | 
|  | 3400 | ssid = wpa_s->current_ssid; | 
|  | 3401 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO || | 
|  | 3402 | !ssid->p2p_persistent_group) | 
|  | 3403 | return; /* Not operating as a GO in persistent group */ | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3404 | ssid = wpas_p2p_get_persistent(wpa_s->p2pdev, peer, | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3405 | ssid->ssid, ssid->ssid_len); | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3406 | wpas_remove_persistent_peer(wpa_s, ssid, peer, 1); | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3407 | } | 
|  | 3408 |  | 
|  | 3409 |  | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3410 | static void wpas_invitation_result(void *ctx, int status, const u8 *bssid, | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3411 | const struct p2p_channels *channels, | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3412 | const u8 *peer, int neg_freq, | 
|  | 3413 | int peer_oper_freq) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3414 | { | 
|  | 3415 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 3416 | struct wpa_ssid *ssid; | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3417 | int freq; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3418 |  | 
|  | 3419 | if (bssid) { | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3420 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT | 
|  | 3421 | "status=%d " MACSTR, | 
|  | 3422 | status, MAC2STR(bssid)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3423 | } else { | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 3424 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT | 
|  | 3425 | "status=%d ", status); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3426 | } | 
|  | 3427 | wpas_notify_p2p_invitation_result(wpa_s, status, bssid); | 
|  | 3428 |  | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3429 | wpa_printf(MSG_DEBUG, "P2P: Invitation result - status=%d peer=" MACSTR, | 
|  | 3430 | status, MAC2STR(peer)); | 
|  | 3431 | if (wpa_s->pending_invite_ssid_id == -1) { | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3432 | struct wpa_supplicant *group_if = | 
|  | 3433 | wpa_s->global->p2p_invite_group; | 
|  | 3434 |  | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3435 | if (status == P2P_SC_FAIL_UNKNOWN_GROUP) | 
|  | 3436 | wpas_remove_persistent_client(wpa_s, peer); | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3437 |  | 
|  | 3438 | /* | 
|  | 3439 | * Invitation to an active group. If this is successful and we | 
|  | 3440 | * are the GO, set the client wait to postpone some concurrent | 
|  | 3441 | * operations and to allow provisioning and connection to happen | 
|  | 3442 | * more quickly. | 
|  | 3443 | */ | 
|  | 3444 | if (status == P2P_SC_SUCCESS && | 
|  | 3445 | group_if && group_if->current_ssid && | 
|  | 3446 | group_if->current_ssid->mode == WPAS_MODE_P2P_GO) { | 
|  | 3447 | os_get_reltime(&wpa_s->global->p2p_go_wait_client); | 
|  | 3448 | #ifdef CONFIG_TESTING_OPTIONS | 
|  | 3449 | if (group_if->p2p_go_csa_on_inv) { | 
|  | 3450 | wpa_printf(MSG_DEBUG, | 
|  | 3451 | "Testing: force P2P GO CSA after invitation"); | 
|  | 3452 | eloop_cancel_timeout( | 
|  | 3453 | wpas_p2p_reconsider_moving_go, | 
|  | 3454 | wpa_s, NULL); | 
|  | 3455 | eloop_register_timeout( | 
|  | 3456 | 0, 50000, | 
|  | 3457 | wpas_p2p_reconsider_moving_go, | 
|  | 3458 | wpa_s, NULL); | 
|  | 3459 | } | 
|  | 3460 | #endif /* CONFIG_TESTING_OPTIONS */ | 
|  | 3461 | } | 
|  | 3462 | return; | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3463 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3464 |  | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 3465 | if (status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) { | 
|  | 3466 | wpa_printf(MSG_DEBUG, "P2P: Waiting for peer to start another " | 
|  | 3467 | "invitation exchange to indicate readiness for " | 
|  | 3468 | "re-invocation"); | 
|  | 3469 | } | 
|  | 3470 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3471 | if (status != P2P_SC_SUCCESS) { | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3472 | if (status == P2P_SC_FAIL_UNKNOWN_GROUP) { | 
|  | 3473 | ssid = wpa_config_get_network( | 
|  | 3474 | wpa_s->conf, wpa_s->pending_invite_ssid_id); | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3475 | wpas_remove_persistent_peer(wpa_s, ssid, peer, 1); | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3476 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3477 | wpas_p2p_remove_pending_group_interface(wpa_s); | 
|  | 3478 | return; | 
|  | 3479 | } | 
|  | 3480 |  | 
|  | 3481 | ssid = wpa_config_get_network(wpa_s->conf, | 
|  | 3482 | wpa_s->pending_invite_ssid_id); | 
|  | 3483 | if (ssid == NULL) { | 
|  | 3484 | wpa_printf(MSG_ERROR, "P2P: Could not find persistent group " | 
|  | 3485 | "data matching with invitation"); | 
|  | 3486 | return; | 
|  | 3487 | } | 
|  | 3488 |  | 
| Jouni Malinen | 2c5b17d | 2012-10-13 21:52:46 -0700 | [diff] [blame] | 3489 | /* | 
|  | 3490 | * The peer could have missed our ctrl::ack frame for Invitation | 
|  | 3491 | * Response and continue retransmitting the frame. To reduce the | 
|  | 3492 | * likelihood of the peer not getting successful TX status for the | 
|  | 3493 | * Invitation Response frame, wait a short time here before starting | 
|  | 3494 | * the persistent group so that we will remain on the current channel to | 
|  | 3495 | * acknowledge any possible retransmission from the peer. | 
|  | 3496 | */ | 
|  | 3497 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: 50 ms wait on current channel before " | 
|  | 3498 | "starting persistent group"); | 
|  | 3499 | os_sleep(0, 50000); | 
|  | 3500 |  | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3501 | if (neg_freq > 0 && ssid->mode == WPAS_MODE_P2P_GO && | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3502 | freq_included(wpa_s, channels, neg_freq)) | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3503 | freq = neg_freq; | 
|  | 3504 | else if (peer_oper_freq > 0 && ssid->mode != WPAS_MODE_P2P_GO && | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3505 | freq_included(wpa_s, channels, peer_oper_freq)) | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3506 | freq = peer_oper_freq; | 
|  | 3507 | else | 
|  | 3508 | freq = 0; | 
|  | 3509 |  | 
|  | 3510 | wpa_printf(MSG_DEBUG, "P2P: Persistent group invitation success - op_freq=%d MHz SSID=%s", | 
|  | 3511 | freq, wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3512 | wpas_p2p_group_add_persistent(wpa_s, ssid, | 
| Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 3513 | ssid->mode == WPAS_MODE_P2P_GO, | 
| Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 3514 | wpa_s->p2p_persistent_go_freq, | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3515 | freq, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3516 | wpa_s->p2p_go_vht_center_freq2, | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3517 | wpa_s->p2p_go_ht40, wpa_s->p2p_go_vht, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3518 | wpa_s->p2p_go_max_oper_chwidth, | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3519 | wpa_s->p2p_go_he, | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3520 | wpa_s->p2p_go_edmg, | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3521 | channels, | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3522 | ssid->mode == WPAS_MODE_P2P_GO ? | 
|  | 3523 | P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3524 | 0, 1, | 
|  | 3525 | is_p2p_allow_6ghz(wpa_s->global->p2p)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3526 | } | 
|  | 3527 |  | 
|  | 3528 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3529 | static int wpas_p2p_disallowed_freq(struct wpa_global *global, | 
|  | 3530 | unsigned int freq) | 
|  | 3531 | { | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3532 | if (freq_range_list_includes(&global->p2p_go_avoid_freq, freq)) | 
|  | 3533 | return 1; | 
| Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 3534 | return freq_range_list_includes(&global->p2p_disallow_freq, freq); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3535 | } | 
|  | 3536 |  | 
|  | 3537 |  | 
|  | 3538 | static void wpas_p2p_add_chan(struct p2p_reg_class *reg, u8 chan) | 
|  | 3539 | { | 
|  | 3540 | reg->channel[reg->channels] = chan; | 
|  | 3541 | reg->channels++; | 
|  | 3542 | } | 
|  | 3543 |  | 
|  | 3544 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3545 | static int wpas_p2p_default_channels(struct wpa_supplicant *wpa_s, | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3546 | struct p2p_channels *chan, | 
|  | 3547 | struct p2p_channels *cli_chan) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3548 | { | 
|  | 3549 | int i, cla = 0; | 
|  | 3550 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3551 | wpa_s->global->p2p_24ghz_social_channels = 1; | 
|  | 3552 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3553 | os_memset(cli_chan, 0, sizeof(*cli_chan)); | 
|  | 3554 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3555 | wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for 2.4 GHz " | 
|  | 3556 | "band"); | 
|  | 3557 |  | 
|  | 3558 | /* Operating class 81 - 2.4 GHz band channels 1..13 */ | 
|  | 3559 | chan->reg_class[cla].reg_class = 81; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3560 | chan->reg_class[cla].channels = 0; | 
|  | 3561 | for (i = 0; i < 11; i++) { | 
|  | 3562 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 2412 + i * 5)) | 
|  | 3563 | wpas_p2p_add_chan(&chan->reg_class[cla], i + 1); | 
|  | 3564 | } | 
|  | 3565 | if (chan->reg_class[cla].channels) | 
|  | 3566 | cla++; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3567 |  | 
|  | 3568 | wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for lower 5 GHz " | 
|  | 3569 | "band"); | 
|  | 3570 |  | 
|  | 3571 | /* Operating class 115 - 5 GHz, channels 36-48 */ | 
|  | 3572 | chan->reg_class[cla].reg_class = 115; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3573 | chan->reg_class[cla].channels = 0; | 
|  | 3574 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 36 * 5)) | 
|  | 3575 | wpas_p2p_add_chan(&chan->reg_class[cla], 36); | 
|  | 3576 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 40 * 5)) | 
|  | 3577 | wpas_p2p_add_chan(&chan->reg_class[cla], 40); | 
|  | 3578 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 44 * 5)) | 
|  | 3579 | wpas_p2p_add_chan(&chan->reg_class[cla], 44); | 
|  | 3580 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 48 * 5)) | 
|  | 3581 | wpas_p2p_add_chan(&chan->reg_class[cla], 48); | 
|  | 3582 | if (chan->reg_class[cla].channels) | 
|  | 3583 | cla++; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3584 |  | 
|  | 3585 | wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for higher 5 GHz " | 
|  | 3586 | "band"); | 
|  | 3587 |  | 
|  | 3588 | /* Operating class 124 - 5 GHz, channels 149,153,157,161 */ | 
|  | 3589 | chan->reg_class[cla].reg_class = 124; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3590 | chan->reg_class[cla].channels = 0; | 
|  | 3591 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 149 * 5)) | 
|  | 3592 | wpas_p2p_add_chan(&chan->reg_class[cla], 149); | 
|  | 3593 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 153 * 5)) | 
|  | 3594 | wpas_p2p_add_chan(&chan->reg_class[cla], 153); | 
|  | 3595 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 156 * 5)) | 
|  | 3596 | wpas_p2p_add_chan(&chan->reg_class[cla], 157); | 
|  | 3597 | if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 161 * 5)) | 
|  | 3598 | wpas_p2p_add_chan(&chan->reg_class[cla], 161); | 
|  | 3599 | if (chan->reg_class[cla].channels) | 
|  | 3600 | cla++; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3601 |  | 
|  | 3602 | chan->reg_classes = cla; | 
|  | 3603 | return 0; | 
|  | 3604 | } | 
|  | 3605 |  | 
|  | 3606 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3607 | static enum chan_allowed has_channel(struct wpa_global *global, | 
|  | 3608 | struct hostapd_hw_modes *mode, u8 op_class, | 
|  | 3609 | u8 chan, int *flags) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3610 | { | 
|  | 3611 | int i; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3612 | unsigned int freq; | 
|  | 3613 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3614 | freq = ieee80211_chan_to_freq(NULL, op_class, chan); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3615 | if (wpas_p2p_disallowed_freq(global, freq)) | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3616 | return NOT_ALLOWED; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3617 |  | 
|  | 3618 | for (i = 0; i < mode->num_channels; i++) { | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3619 | if ((unsigned int) mode->channels[i].freq == freq) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3620 | if (flags) | 
|  | 3621 | *flags = mode->channels[i].flag; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3622 | if (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED) | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3623 | return NOT_ALLOWED; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3624 | if (mode->channels[i].flag & HOSTAPD_CHAN_NO_IR) | 
|  | 3625 | return NO_IR; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3626 | if (mode->channels[i].flag & HOSTAPD_CHAN_RADAR) | 
|  | 3627 | return RADAR; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3628 | return ALLOWED; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3629 | } | 
|  | 3630 | } | 
|  | 3631 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3632 | return NOT_ALLOWED; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3633 | } | 
|  | 3634 |  | 
|  | 3635 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3636 | static int wpas_p2p_get_center_80mhz(struct wpa_supplicant *wpa_s, | 
|  | 3637 | struct hostapd_hw_modes *mode, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3638 | u8 channel, const u8 *center_channels, | 
|  | 3639 | size_t num_chan) | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3640 | { | 
| Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 3641 | size_t i; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3642 |  | 
|  | 3643 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) | 
|  | 3644 | return 0; | 
|  | 3645 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3646 | for (i = 0; i < num_chan; i++) | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3647 | /* | 
|  | 3648 | * In 80 MHz, the bandwidth "spans" 12 channels (e.g., 36-48), | 
|  | 3649 | * so the center channel is 6 channels away from the start/end. | 
|  | 3650 | */ | 
|  | 3651 | if (channel >= center_channels[i] - 6 && | 
|  | 3652 | channel <= center_channels[i] + 6) | 
|  | 3653 | return center_channels[i]; | 
|  | 3654 |  | 
|  | 3655 | return 0; | 
|  | 3656 | } | 
|  | 3657 |  | 
|  | 3658 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3659 | static const u8 center_channels_5ghz_80mhz[] = { 42, 58, 106, 122, 138, | 
|  | 3660 | 155, 171 }; | 
|  | 3661 | static const u8 center_channels_6ghz_80mhz[] = { 7, 23, 39, 55, 71, 87, 103, | 
|  | 3662 | 119, 135, 151, 167, 183, 199, | 
|  | 3663 | 215 }; | 
|  | 3664 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3665 | static enum chan_allowed wpas_p2p_verify_80mhz(struct wpa_supplicant *wpa_s, | 
|  | 3666 | struct hostapd_hw_modes *mode, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3667 | u8 op_class, u8 channel, u8 bw) | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3668 | { | 
|  | 3669 | u8 center_chan; | 
|  | 3670 | int i, flags; | 
|  | 3671 | enum chan_allowed res, ret = ALLOWED; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3672 | const u8 *chans; | 
|  | 3673 | size_t num_chans; | 
|  | 3674 | bool is_6ghz = is_6ghz_op_class(op_class); | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3675 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3676 | if (is_6ghz) { | 
|  | 3677 | chans = center_channels_6ghz_80mhz; | 
|  | 3678 | num_chans = ARRAY_SIZE(center_channels_6ghz_80mhz); | 
|  | 3679 | } else { | 
|  | 3680 | chans = center_channels_5ghz_80mhz; | 
|  | 3681 | num_chans = ARRAY_SIZE(center_channels_5ghz_80mhz); | 
|  | 3682 | } | 
|  | 3683 | center_chan = wpas_p2p_get_center_80mhz(wpa_s, mode, channel, | 
|  | 3684 | chans, num_chans); | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3685 | if (!center_chan) | 
|  | 3686 | return NOT_ALLOWED; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3687 | if (!wpa_s->p2p_go_allow_dfs && | 
|  | 3688 | !is_6ghz && center_chan >= 58 && center_chan <= 138) | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3689 | return NOT_ALLOWED; /* Do not allow DFS channels for P2P */ | 
|  | 3690 |  | 
|  | 3691 | /* check all the channels are available */ | 
|  | 3692 | for (i = 0; i < 4; i++) { | 
|  | 3693 | int adj_chan = center_chan - 6 + i * 4; | 
|  | 3694 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3695 | res = has_channel(wpa_s->global, mode, op_class, adj_chan, | 
|  | 3696 | &flags); | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3697 | if (res == NOT_ALLOWED) | 
|  | 3698 | return NOT_ALLOWED; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3699 | if (res == RADAR) | 
|  | 3700 | ret = RADAR; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3701 | if (res == NO_IR) | 
|  | 3702 | ret = NO_IR; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3703 | if (!is_6ghz) { | 
|  | 3704 | if (i == 0 && !(flags & HOSTAPD_CHAN_VHT_10_70)) | 
|  | 3705 | return NOT_ALLOWED; | 
|  | 3706 | if (i == 1 && !(flags & HOSTAPD_CHAN_VHT_30_50)) | 
|  | 3707 | return NOT_ALLOWED; | 
|  | 3708 | if (i == 2 && !(flags & HOSTAPD_CHAN_VHT_50_30)) | 
|  | 3709 | return NOT_ALLOWED; | 
|  | 3710 | if (i == 3 && !(flags & HOSTAPD_CHAN_VHT_70_10)) | 
|  | 3711 | return NOT_ALLOWED; | 
|  | 3712 | } else if (is_6ghz && | 
|  | 3713 | (!(wpas_get_6ghz_he_chwidth_capab(mode) & | 
|  | 3714 | HE_PHYCAP_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G))) { | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3715 | return NOT_ALLOWED; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3716 | } | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3717 | } | 
|  | 3718 |  | 
|  | 3719 | return ret; | 
|  | 3720 | } | 
|  | 3721 |  | 
|  | 3722 |  | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3723 | static int wpas_p2p_get_center_160mhz(struct wpa_supplicant *wpa_s, | 
|  | 3724 | struct hostapd_hw_modes *mode, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3725 | u8 channel, const u8 *center_channels, | 
|  | 3726 | size_t num_chan) | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3727 | { | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3728 | unsigned int i; | 
|  | 3729 |  | 
|  | 3730 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) | 
|  | 3731 | return 0; | 
|  | 3732 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3733 | for (i = 0; i < num_chan; i++) | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3734 | /* | 
|  | 3735 | * In 160 MHz, the bandwidth "spans" 28 channels (e.g., 36-64), | 
|  | 3736 | * so the center channel is 14 channels away from the start/end. | 
|  | 3737 | */ | 
|  | 3738 | if (channel >= center_channels[i] - 14 && | 
|  | 3739 | channel <= center_channels[i] + 14) | 
|  | 3740 | return center_channels[i]; | 
|  | 3741 |  | 
|  | 3742 | return 0; | 
|  | 3743 | } | 
|  | 3744 |  | 
|  | 3745 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3746 | static const u8 center_channels_5ghz_160mhz[] = { 50, 114, 163 }; | 
|  | 3747 | static const u8 center_channels_6ghz_160mhz[] = { 15, 47, 79, 111, 143, 175, | 
|  | 3748 | 207 }; | 
|  | 3749 |  | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3750 | static enum chan_allowed wpas_p2p_verify_160mhz(struct wpa_supplicant *wpa_s, | 
|  | 3751 | struct hostapd_hw_modes *mode, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3752 | u8 op_class, u8 channel, u8 bw) | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3753 | { | 
|  | 3754 | u8 center_chan; | 
|  | 3755 | int i, flags; | 
|  | 3756 | enum chan_allowed res, ret = ALLOWED; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3757 | const u8 *chans; | 
|  | 3758 | size_t num_chans; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3759 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3760 | if (is_6ghz_op_class(op_class)) { | 
|  | 3761 | chans = center_channels_6ghz_160mhz; | 
|  | 3762 | num_chans = ARRAY_SIZE(center_channels_6ghz_160mhz); | 
|  | 3763 | } else { | 
|  | 3764 | chans = center_channels_5ghz_160mhz; | 
|  | 3765 | num_chans = ARRAY_SIZE(center_channels_5ghz_160mhz); | 
|  | 3766 | } | 
|  | 3767 | center_chan = wpas_p2p_get_center_160mhz(wpa_s, mode, channel, | 
|  | 3768 | chans, num_chans); | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3769 | if (!center_chan) | 
|  | 3770 | return NOT_ALLOWED; | 
|  | 3771 | /* VHT 160 MHz uses DFS channels in most countries. */ | 
|  | 3772 |  | 
|  | 3773 | /* Check all the channels are available */ | 
|  | 3774 | for (i = 0; i < 8; i++) { | 
|  | 3775 | int adj_chan = center_chan - 14 + i * 4; | 
|  | 3776 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3777 | res = has_channel(wpa_s->global, mode, op_class, adj_chan, | 
|  | 3778 | &flags); | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3779 | if (res == NOT_ALLOWED) | 
|  | 3780 | return NOT_ALLOWED; | 
|  | 3781 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3782 | if (res == RADAR) | 
|  | 3783 | ret = RADAR; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3784 | if (res == NO_IR) | 
|  | 3785 | ret = NO_IR; | 
|  | 3786 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3787 | if (!is_6ghz_op_class(op_class)) { | 
|  | 3788 | if (i == 0 && !(flags & HOSTAPD_CHAN_VHT_10_150)) | 
|  | 3789 | return NOT_ALLOWED; | 
|  | 3790 | if (i == 1 && !(flags & HOSTAPD_CHAN_VHT_30_130)) | 
|  | 3791 | return NOT_ALLOWED; | 
|  | 3792 | if (i == 2 && !(flags & HOSTAPD_CHAN_VHT_50_110)) | 
|  | 3793 | return NOT_ALLOWED; | 
|  | 3794 | if (i == 3 && !(flags & HOSTAPD_CHAN_VHT_70_90)) | 
|  | 3795 | return NOT_ALLOWED; | 
|  | 3796 | if (i == 4 && !(flags & HOSTAPD_CHAN_VHT_90_70)) | 
|  | 3797 | return NOT_ALLOWED; | 
|  | 3798 | if (i == 5 && !(flags & HOSTAPD_CHAN_VHT_110_50)) | 
|  | 3799 | return NOT_ALLOWED; | 
|  | 3800 | if (i == 6 && !(flags & HOSTAPD_CHAN_VHT_130_30)) | 
|  | 3801 | return NOT_ALLOWED; | 
|  | 3802 | if (i == 7 && !(flags & HOSTAPD_CHAN_VHT_150_10)) | 
|  | 3803 | return NOT_ALLOWED; | 
|  | 3804 | } else if (is_6ghz_op_class(op_class) && | 
|  | 3805 | (!(wpas_get_6ghz_he_chwidth_capab(mode) & | 
|  | 3806 | HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G))) { | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3807 | return NOT_ALLOWED; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3808 | } | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3809 | } | 
|  | 3810 |  | 
|  | 3811 | return ret; | 
|  | 3812 | } | 
|  | 3813 |  | 
|  | 3814 |  | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3815 | static enum chan_allowed wpas_p2p_verify_edmg(struct wpa_supplicant *wpa_s, | 
|  | 3816 | struct hostapd_hw_modes *mode, | 
|  | 3817 | u8 channel) | 
|  | 3818 | { | 
|  | 3819 | struct ieee80211_edmg_config edmg; | 
|  | 3820 |  | 
|  | 3821 | hostapd_encode_edmg_chan(1, channel, 0, &edmg); | 
|  | 3822 | if (edmg.channels && ieee802_edmg_is_allowed(mode->edmg, edmg)) | 
|  | 3823 | return ALLOWED; | 
|  | 3824 |  | 
|  | 3825 | return NOT_ALLOWED; | 
|  | 3826 | } | 
|  | 3827 |  | 
|  | 3828 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3829 | static enum chan_allowed wpas_p2p_verify_channel(struct wpa_supplicant *wpa_s, | 
|  | 3830 | struct hostapd_hw_modes *mode, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3831 | u8 op_class, u8 channel, u8 bw) | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3832 | { | 
| Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 3833 | int flag = 0; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3834 | enum chan_allowed res, res2; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3835 |  | 
| Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3836 | if (is_6ghz_op_class(op_class) && !is_6ghz_psc_frequency( | 
|  | 3837 | p2p_channel_to_freq(op_class, channel))) | 
|  | 3838 | return NOT_ALLOWED; | 
|  | 3839 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3840 | res2 = res = has_channel(wpa_s->global, mode, op_class, channel, &flag); | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3841 | if (bw == BW40MINUS) { | 
|  | 3842 | if (!(flag & HOSTAPD_CHAN_HT40MINUS)) | 
|  | 3843 | return NOT_ALLOWED; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3844 | res2 = has_channel(wpa_s->global, mode, op_class, channel - 4, | 
|  | 3845 | NULL); | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3846 | } else if (bw == BW40PLUS) { | 
|  | 3847 | if (!(flag & HOSTAPD_CHAN_HT40PLUS)) | 
|  | 3848 | return NOT_ALLOWED; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3849 | res2 = has_channel(wpa_s->global, mode, op_class, channel + 4, | 
|  | 3850 | NULL); | 
|  | 3851 | } else if (is_6ghz_op_class(op_class) && bw == BW40) { | 
|  | 3852 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) | 
|  | 3853 | return NOT_ALLOWED; | 
|  | 3854 | if (get_6ghz_sec_channel(channel) < 0) | 
|  | 3855 | res2 = has_channel(wpa_s->global, mode, op_class, | 
|  | 3856 | channel - 4, NULL); | 
|  | 3857 | else | 
|  | 3858 | res2 = has_channel(wpa_s->global, mode, op_class, | 
|  | 3859 | channel + 4, NULL); | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3860 | } else if (bw == BW80) { | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3861 | res2 = wpas_p2p_verify_80mhz(wpa_s, mode, op_class, channel, | 
|  | 3862 | bw); | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3863 | } else if (bw == BW160) { | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3864 | res2 = wpas_p2p_verify_160mhz(wpa_s, mode, op_class, channel, | 
|  | 3865 | bw); | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3866 | } else if (bw == BW4320 || bw == BW6480 || bw == BW8640) { | 
|  | 3867 | return wpas_p2p_verify_edmg(wpa_s, mode, channel); | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3868 | } | 
|  | 3869 |  | 
|  | 3870 | if (res == NOT_ALLOWED || res2 == NOT_ALLOWED) | 
|  | 3871 | return NOT_ALLOWED; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3872 | if (res == NO_IR || res2 == NO_IR) | 
|  | 3873 | return NO_IR; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3874 | if (res == RADAR || res2 == RADAR) | 
|  | 3875 | return RADAR; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3876 | return res; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3877 | } | 
|  | 3878 |  | 
|  | 3879 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3880 | static int wpas_p2p_setup_channels(struct wpa_supplicant *wpa_s, | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3881 | struct p2p_channels *chan, | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3882 | struct p2p_channels *cli_chan, | 
|  | 3883 | bool p2p_disable_6ghz) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3884 | { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3885 | struct hostapd_hw_modes *mode; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3886 | int cla, op, cli_cla; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3887 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3888 | if (wpa_s->hw.modes == NULL) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3889 | wpa_printf(MSG_DEBUG, "P2P: Driver did not support fetching " | 
|  | 3890 | "of all supported channels; assume dualband " | 
|  | 3891 | "support"); | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3892 | return wpas_p2p_default_channels(wpa_s, chan, cli_chan); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3893 | } | 
|  | 3894 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3895 | cla = cli_cla = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3896 |  | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3897 | for (op = 0; global_op_class[op].op_class; op++) { | 
|  | 3898 | const struct oper_class_map *o = &global_op_class[op]; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3899 | unsigned int ch; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3900 | struct p2p_reg_class *reg = NULL, *cli_reg = NULL; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3901 |  | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3902 | if (o->p2p == NO_P2P_SUPP || | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3903 | (is_6ghz_op_class(o->op_class) && p2p_disable_6ghz)) | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3904 | continue; | 
|  | 3905 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3906 | mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, o->mode, | 
|  | 3907 | is_6ghz_op_class(o->op_class)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3908 | if (mode == NULL) | 
|  | 3909 | continue; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3910 | if (mode->mode == HOSTAPD_MODE_IEEE80211G) | 
|  | 3911 | wpa_s->global->p2p_24ghz_social_channels = 1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3912 | for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) { | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3913 | enum chan_allowed res; | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3914 |  | 
|  | 3915 | /* Check for non-continuous jump in channel index | 
|  | 3916 | * incrementation */ | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3917 | if ((o->op_class >= 128 && o->op_class <= 130) && | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3918 | ch < 149 && ch + o->inc > 149) | 
|  | 3919 | ch = 149; | 
|  | 3920 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3921 | res = wpas_p2p_verify_channel(wpa_s, mode, o->op_class, | 
|  | 3922 | ch, o->bw); | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3923 | if (res == ALLOWED) { | 
|  | 3924 | if (reg == NULL) { | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3925 | if (cla == P2P_MAX_REG_CLASSES) | 
|  | 3926 | continue; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3927 | wpa_printf(MSG_DEBUG, "P2P: Add operating class %u", | 
|  | 3928 | o->op_class); | 
|  | 3929 | reg = &chan->reg_class[cla]; | 
|  | 3930 | cla++; | 
|  | 3931 | reg->reg_class = o->op_class; | 
|  | 3932 | } | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3933 | if (reg->channels == P2P_MAX_REG_CLASS_CHANNELS) | 
|  | 3934 | continue; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3935 | reg->channel[reg->channels] = ch; | 
|  | 3936 | reg->channels++; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3937 | } else if (res == NO_IR && | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3938 | wpa_s->conf->p2p_add_cli_chan) { | 
|  | 3939 | if (cli_reg == NULL) { | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3940 | if (cli_cla == P2P_MAX_REG_CLASSES) | 
|  | 3941 | continue; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3942 | wpa_printf(MSG_DEBUG, "P2P: Add operating class %u (client only)", | 
|  | 3943 | o->op_class); | 
|  | 3944 | cli_reg = &cli_chan->reg_class[cli_cla]; | 
|  | 3945 | cli_cla++; | 
|  | 3946 | cli_reg->reg_class = o->op_class; | 
|  | 3947 | } | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3948 | if (cli_reg->channels == | 
|  | 3949 | P2P_MAX_REG_CLASS_CHANNELS) | 
|  | 3950 | continue; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3951 | cli_reg->channel[cli_reg->channels] = ch; | 
|  | 3952 | cli_reg->channels++; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3953 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3954 | } | 
|  | 3955 | if (reg) { | 
|  | 3956 | wpa_hexdump(MSG_DEBUG, "P2P: Channels", | 
|  | 3957 | reg->channel, reg->channels); | 
|  | 3958 | } | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3959 | if (cli_reg) { | 
|  | 3960 | wpa_hexdump(MSG_DEBUG, "P2P: Channels (client only)", | 
|  | 3961 | cli_reg->channel, cli_reg->channels); | 
|  | 3962 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3963 | } | 
|  | 3964 |  | 
|  | 3965 | chan->reg_classes = cla; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3966 | cli_chan->reg_classes = cli_cla; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3967 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3968 | return 0; | 
|  | 3969 | } | 
|  | 3970 |  | 
|  | 3971 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3972 | int wpas_p2p_get_sec_channel_offset_40mhz(struct wpa_supplicant *wpa_s, | 
|  | 3973 | struct hostapd_hw_modes *mode, | 
|  | 3974 | u8 channel) | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3975 | { | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3976 | int op; | 
|  | 3977 | enum chan_allowed ret; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3978 |  | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3979 | for (op = 0; global_op_class[op].op_class; op++) { | 
|  | 3980 | const struct oper_class_map *o = &global_op_class[op]; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3981 | u16 ch; | 
|  | 3982 | int chan = channel; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3983 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3984 | /* Allow DFS channels marked as NO_P2P_SUPP to be used with | 
|  | 3985 | * driver offloaded DFS. */ | 
|  | 3986 | if ((o->p2p == NO_P2P_SUPP && | 
|  | 3987 | (!is_dfs_global_op_class(o->op_class) || | 
|  | 3988 | !wpa_s->p2p_go_allow_dfs)) || | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3989 | (is_6ghz_op_class(o->op_class) && | 
|  | 3990 | wpa_s->conf->p2p_6ghz_disable)) | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3991 | continue; | 
|  | 3992 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3993 | if (is_6ghz_op_class(o->op_class) && o->bw == BW40 && | 
|  | 3994 | get_6ghz_sec_channel(channel) < 0) | 
|  | 3995 | chan = channel - 4; | 
|  | 3996 |  | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3997 | for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) { | 
|  | 3998 | if (o->mode != HOSTAPD_MODE_IEEE80211A || | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3999 | (o->bw != BW40PLUS && o->bw != BW40MINUS && | 
|  | 4000 | o->bw != BW40) || | 
|  | 4001 | ch != chan) | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4002 | continue; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4003 | ret = wpas_p2p_verify_channel(wpa_s, mode, o->op_class, | 
|  | 4004 | ch, o->bw); | 
|  | 4005 | if (ret == ALLOWED) { | 
|  | 4006 | if (is_6ghz_op_class(o->op_class) && | 
|  | 4007 | o->bw == BW40) | 
|  | 4008 | return get_6ghz_sec_channel(channel); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4009 | return (o->bw == BW40MINUS) ? -1 : 1; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4010 | } | 
|  | 4011 | if (ret == RADAR && wpa_s->p2p_go_allow_dfs) { | 
|  | 4012 | /* Allow RADAR channels used for driver | 
|  | 4013 | * offloaded DFS */ | 
|  | 4014 | return (o->bw == BW40MINUS) ? -1 : 1; | 
|  | 4015 | } | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4016 | } | 
|  | 4017 | } | 
|  | 4018 | return 0; | 
|  | 4019 | } | 
|  | 4020 |  | 
|  | 4021 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4022 | int wpas_p2p_get_vht80_center(struct wpa_supplicant *wpa_s, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4023 | struct hostapd_hw_modes *mode, u8 channel, | 
|  | 4024 | u8 op_class) | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4025 | { | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4026 | const u8 *chans; | 
|  | 4027 | size_t num_chans; | 
|  | 4028 | enum chan_allowed ret; | 
|  | 4029 |  | 
|  | 4030 | ret = wpas_p2p_verify_channel(wpa_s, mode, op_class, channel, BW80); | 
|  | 4031 | if (!(ret == ALLOWED || (ret == RADAR && wpa_s->p2p_go_allow_dfs))) | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4032 | return 0; | 
|  | 4033 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4034 | if (is_6ghz_op_class(op_class)) { | 
|  | 4035 | chans = center_channels_6ghz_80mhz; | 
|  | 4036 | num_chans = ARRAY_SIZE(center_channels_6ghz_80mhz); | 
|  | 4037 | } else { | 
|  | 4038 | chans = center_channels_5ghz_80mhz; | 
|  | 4039 | num_chans = ARRAY_SIZE(center_channels_5ghz_80mhz); | 
|  | 4040 | } | 
|  | 4041 | return wpas_p2p_get_center_80mhz(wpa_s, mode, channel, | 
|  | 4042 | chans, num_chans); | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4043 | } | 
|  | 4044 |  | 
|  | 4045 |  | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4046 | int wpas_p2p_get_vht160_center(struct wpa_supplicant *wpa_s, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4047 | struct hostapd_hw_modes *mode, u8 channel, | 
|  | 4048 | u8 op_class) | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4049 | { | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4050 | const u8 *chans; | 
|  | 4051 | size_t num_chans; | 
|  | 4052 | enum chan_allowed ret; | 
|  | 4053 |  | 
|  | 4054 | ret = wpas_p2p_verify_channel(wpa_s, mode, op_class, channel, BW160); | 
|  | 4055 | if (!(ret == ALLOWED || (ret == RADAR && wpa_s->p2p_go_allow_dfs))) | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4056 | return 0; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4057 | if (is_6ghz_op_class(op_class)) { | 
|  | 4058 | chans = center_channels_6ghz_160mhz; | 
|  | 4059 | num_chans = ARRAY_SIZE(center_channels_6ghz_160mhz); | 
|  | 4060 | } else { | 
|  | 4061 | chans = center_channels_5ghz_160mhz; | 
|  | 4062 | num_chans = ARRAY_SIZE(center_channels_5ghz_160mhz); | 
|  | 4063 | } | 
|  | 4064 | return wpas_p2p_get_center_160mhz(wpa_s, mode, channel, | 
|  | 4065 | chans, num_chans); | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4066 | } | 
|  | 4067 |  | 
|  | 4068 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4069 | static int wpas_get_noa(void *ctx, const u8 *interface_addr, u8 *buf, | 
|  | 4070 | size_t buf_len) | 
|  | 4071 | { | 
|  | 4072 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 4073 |  | 
|  | 4074 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 4075 | if (os_memcmp(wpa_s->own_addr, interface_addr, ETH_ALEN) == 0) | 
|  | 4076 | break; | 
|  | 4077 | } | 
|  | 4078 | if (wpa_s == NULL) | 
|  | 4079 | return -1; | 
|  | 4080 |  | 
|  | 4081 | return wpa_drv_get_noa(wpa_s, buf, buf_len); | 
|  | 4082 | } | 
|  | 4083 |  | 
|  | 4084 |  | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4085 | struct wpa_supplicant * wpas_get_p2p_go_iface(struct wpa_supplicant *wpa_s, | 
|  | 4086 | const u8 *ssid, size_t ssid_len) | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4087 | { | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4088 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 4089 | struct wpa_ssid *s = wpa_s->current_ssid; | 
|  | 4090 | if (s == NULL) | 
|  | 4091 | continue; | 
|  | 4092 | if (s->mode != WPAS_MODE_P2P_GO && | 
|  | 4093 | s->mode != WPAS_MODE_AP && | 
|  | 4094 | s->mode != WPAS_MODE_P2P_GROUP_FORMATION) | 
|  | 4095 | continue; | 
|  | 4096 | if (s->ssid_len != ssid_len || | 
| Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 4097 | os_memcmp(ssid, s->ssid, ssid_len) != 0) | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4098 | continue; | 
|  | 4099 | return wpa_s; | 
|  | 4100 | } | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4101 |  | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4102 | return NULL; | 
|  | 4103 |  | 
|  | 4104 | } | 
|  | 4105 |  | 
|  | 4106 |  | 
|  | 4107 | struct wpa_supplicant * wpas_get_p2p_client_iface(struct wpa_supplicant *wpa_s, | 
|  | 4108 | const u8 *peer_dev_addr) | 
|  | 4109 | { | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4110 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 4111 | struct wpa_ssid *ssid = wpa_s->current_ssid; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4112 | if (ssid && (ssid->mode != WPAS_MODE_INFRA || !ssid->p2p_group)) | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4113 | continue; | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4114 | if (os_memcmp(wpa_s->go_dev_addr, peer_dev_addr, ETH_ALEN) == 0) | 
|  | 4115 | return wpa_s; | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4116 | } | 
|  | 4117 |  | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4118 | return NULL; | 
|  | 4119 | } | 
|  | 4120 |  | 
|  | 4121 |  | 
|  | 4122 | static int wpas_go_connected(void *ctx, const u8 *dev_addr) | 
|  | 4123 | { | 
|  | 4124 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 4125 |  | 
|  | 4126 | return wpas_get_p2p_client_iface(wpa_s, dev_addr) != NULL; | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4127 | } | 
|  | 4128 |  | 
|  | 4129 |  | 
| Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 4130 | static int wpas_is_concurrent_session_active(void *ctx) | 
|  | 4131 | { | 
|  | 4132 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 4133 | struct wpa_supplicant *ifs; | 
|  | 4134 |  | 
|  | 4135 | for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) { | 
|  | 4136 | if (ifs == wpa_s) | 
|  | 4137 | continue; | 
|  | 4138 | if (ifs->wpa_state > WPA_ASSOCIATED) | 
|  | 4139 | return 1; | 
|  | 4140 | } | 
|  | 4141 | return 0; | 
|  | 4142 | } | 
|  | 4143 |  | 
|  | 4144 |  | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 4145 | static void wpas_p2p_debug_print(void *ctx, int level, const char *msg) | 
|  | 4146 | { | 
|  | 4147 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 4148 | wpa_msg_global(wpa_s, level, "P2P: %s", msg); | 
|  | 4149 | } | 
|  | 4150 |  | 
|  | 4151 |  | 
| Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4152 | int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s, | 
|  | 4153 | const char *conf_p2p_dev) | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4154 | { | 
|  | 4155 | struct wpa_interface iface; | 
|  | 4156 | struct wpa_supplicant *p2pdev_wpa_s; | 
|  | 4157 | char ifname[100]; | 
|  | 4158 | char force_name[100]; | 
|  | 4159 | int ret; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4160 | const u8 *if_addr = NULL; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4161 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4162 | ret = os_snprintf(ifname, sizeof(ifname), P2P_MGMT_DEVICE_PREFIX "%s", | 
|  | 4163 | wpa_s->ifname); | 
|  | 4164 | if (os_snprintf_error(sizeof(ifname), ret)) | 
|  | 4165 | return -1; | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4166 | /* Cut length at the maximum size. Note that we don't need to ensure | 
|  | 4167 | * collision free names here as the created interface is not a netdev. | 
|  | 4168 | */ | 
|  | 4169 | ifname[IFNAMSIZ - 1] = '\0'; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4170 | force_name[0] = '\0'; | 
|  | 4171 | wpa_s->pending_interface_type = WPA_IF_P2P_DEVICE; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4172 |  | 
|  | 4173 | if (wpa_s->conf->p2p_device_random_mac_addr == 2 && | 
|  | 4174 | !is_zero_ether_addr(wpa_s->conf->p2p_device_persistent_mac_addr)) | 
|  | 4175 | if_addr = wpa_s->conf->p2p_device_persistent_mac_addr; | 
|  | 4176 |  | 
|  | 4177 | 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] | 4178 | force_name, wpa_s->pending_interface_addr, NULL); | 
|  | 4179 | if (ret < 0) { | 
|  | 4180 | wpa_printf(MSG_DEBUG, "P2P: Failed to create P2P Device interface"); | 
|  | 4181 | return ret; | 
|  | 4182 | } | 
|  | 4183 | os_strlcpy(wpa_s->pending_interface_name, ifname, | 
|  | 4184 | sizeof(wpa_s->pending_interface_name)); | 
|  | 4185 |  | 
|  | 4186 | os_memset(&iface, 0, sizeof(iface)); | 
|  | 4187 | iface.p2p_mgmt = 1; | 
|  | 4188 | iface.ifname = wpa_s->pending_interface_name; | 
|  | 4189 | iface.driver = wpa_s->driver->name; | 
|  | 4190 | iface.driver_param = wpa_s->conf->driver_param; | 
| Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4191 |  | 
|  | 4192 | /* | 
|  | 4193 | * If a P2P Device configuration file was given, use it as the interface | 
|  | 4194 | * configuration file (instead of using parent's configuration file. | 
|  | 4195 | */ | 
| Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4196 | if (conf_p2p_dev) { | 
|  | 4197 | iface.confname = conf_p2p_dev; | 
| Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4198 | iface.ctrl_interface = NULL; | 
|  | 4199 | } else { | 
|  | 4200 | iface.confname = wpa_s->confname; | 
|  | 4201 | iface.ctrl_interface = wpa_s->conf->ctrl_interface; | 
|  | 4202 | } | 
| Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4203 |  | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4204 | 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] | 4205 | if (!p2pdev_wpa_s) { | 
|  | 4206 | wpa_printf(MSG_DEBUG, "P2P: Failed to add P2P Device interface"); | 
|  | 4207 | return -1; | 
|  | 4208 | } | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4209 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4210 | p2pdev_wpa_s->p2pdev = p2pdev_wpa_s; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4211 | wpa_s->pending_interface_name[0] = '\0'; | 
|  | 4212 | return 0; | 
|  | 4213 | } | 
|  | 4214 |  | 
|  | 4215 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4216 | static void wpas_presence_resp(void *ctx, const u8 *src, u8 status, | 
|  | 4217 | const u8 *noa, size_t noa_len) | 
|  | 4218 | { | 
|  | 4219 | struct wpa_supplicant *wpa_s, *intf = ctx; | 
|  | 4220 | char hex[100]; | 
|  | 4221 |  | 
|  | 4222 | for (wpa_s = intf->global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 4223 | if (wpa_s->waiting_presence_resp) | 
|  | 4224 | break; | 
|  | 4225 | } | 
|  | 4226 | if (!wpa_s) { | 
|  | 4227 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No group interface was waiting for presence response"); | 
|  | 4228 | return; | 
|  | 4229 | } | 
|  | 4230 | wpa_s->waiting_presence_resp = 0; | 
|  | 4231 |  | 
|  | 4232 | wpa_snprintf_hex(hex, sizeof(hex), noa, noa_len); | 
|  | 4233 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PRESENCE_RESPONSE "src=" MACSTR | 
|  | 4234 | " status=%u noa=%s", MAC2STR(src), status, hex); | 
|  | 4235 | } | 
|  | 4236 |  | 
|  | 4237 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4238 | static int wpas_get_persistent_group(void *ctx, const u8 *addr, const u8 *ssid, | 
|  | 4239 | size_t ssid_len, u8 *go_dev_addr, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4240 | u8 *ret_ssid, size_t *ret_ssid_len, | 
|  | 4241 | u8 *intended_iface_addr) | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4242 | { | 
|  | 4243 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 4244 | struct wpa_ssid *s; | 
|  | 4245 |  | 
|  | 4246 | s = wpas_p2p_get_persistent(wpa_s, addr, ssid, ssid_len); | 
|  | 4247 | if (s) { | 
|  | 4248 | os_memcpy(ret_ssid, s->ssid, s->ssid_len); | 
|  | 4249 | *ret_ssid_len = s->ssid_len; | 
|  | 4250 | os_memcpy(go_dev_addr, s->bssid, ETH_ALEN); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4251 |  | 
|  | 4252 | if (s->mode != WPAS_MODE_P2P_GO) { | 
|  | 4253 | os_memset(intended_iface_addr, 0, ETH_ALEN); | 
|  | 4254 | } else if (wpas_p2p_create_iface(wpa_s)) { | 
|  | 4255 | if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO)) | 
|  | 4256 | return 0; | 
|  | 4257 |  | 
|  | 4258 | os_memcpy(intended_iface_addr, | 
|  | 4259 | wpa_s->pending_interface_addr, ETH_ALEN); | 
|  | 4260 | } else { | 
|  | 4261 | os_memcpy(intended_iface_addr, wpa_s->own_addr, | 
|  | 4262 | ETH_ALEN); | 
|  | 4263 | } | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4264 | return 1; | 
|  | 4265 | } | 
|  | 4266 |  | 
|  | 4267 | return 0; | 
|  | 4268 | } | 
|  | 4269 |  | 
|  | 4270 |  | 
|  | 4271 | static int wpas_get_go_info(void *ctx, u8 *intended_addr, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4272 | u8 *ssid, size_t *ssid_len, int *group_iface, | 
|  | 4273 | unsigned int *freq) | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4274 | { | 
|  | 4275 | struct wpa_supplicant *wpa_s = ctx; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4276 | struct wpa_supplicant *go; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4277 | struct wpa_ssid *s; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4278 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4279 | /* | 
|  | 4280 | * group_iface will be set to 1 only if a dedicated interface for P2P | 
|  | 4281 | * role is required. First, we try to reuse an active GO. However, | 
|  | 4282 | * if it is not present, we will try to reactivate an existing | 
|  | 4283 | * persistent group and set group_iface to 1, so the caller will know | 
|  | 4284 | * that the pending interface should be used. | 
|  | 4285 | */ | 
|  | 4286 | *group_iface = 0; | 
|  | 4287 |  | 
|  | 4288 | if (freq) | 
|  | 4289 | *freq = 0; | 
|  | 4290 |  | 
|  | 4291 | go = wpas_p2p_get_go_group(wpa_s); | 
|  | 4292 | if (!go) { | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4293 | s = wpas_p2p_get_persistent_go(wpa_s); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4294 | *group_iface = wpas_p2p_create_iface(wpa_s); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4295 | if (s) | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4296 | os_memcpy(intended_addr, s->bssid, ETH_ALEN); | 
|  | 4297 | else | 
|  | 4298 | return 0; | 
|  | 4299 | } else { | 
|  | 4300 | s = go->current_ssid; | 
|  | 4301 | os_memcpy(intended_addr, go->own_addr, ETH_ALEN); | 
|  | 4302 | if (freq) | 
|  | 4303 | *freq = go->assoc_freq; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4304 | } | 
|  | 4305 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4306 | os_memcpy(ssid, s->ssid, s->ssid_len); | 
|  | 4307 | *ssid_len = s->ssid_len; | 
|  | 4308 |  | 
|  | 4309 | return 1; | 
|  | 4310 | } | 
|  | 4311 |  | 
|  | 4312 |  | 
|  | 4313 | static int wpas_remove_stale_groups(void *ctx, const u8 *peer, const u8 *go, | 
|  | 4314 | const u8 *ssid, size_t ssid_len) | 
|  | 4315 | { | 
|  | 4316 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 4317 | struct wpa_ssid *s; | 
|  | 4318 | int save_config = 0; | 
|  | 4319 | size_t i; | 
|  | 4320 |  | 
|  | 4321 | /* Start with our first choice of Persistent Groups */ | 
|  | 4322 | while ((s = wpas_p2p_get_persistent(wpa_s, peer, NULL, 0))) { | 
|  | 4323 | if (go && ssid && ssid_len && | 
|  | 4324 | s->ssid_len == ssid_len && | 
|  | 4325 | os_memcmp(go, s->bssid, ETH_ALEN) == 0 && | 
|  | 4326 | os_memcmp(ssid, s->ssid, ssid_len) == 0) | 
|  | 4327 | break; | 
|  | 4328 |  | 
|  | 4329 | /* Remove stale persistent group */ | 
|  | 4330 | if (s->mode != WPAS_MODE_P2P_GO || s->num_p2p_clients <= 1) { | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4331 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 4332 | "P2P: Remove stale persistent group id=%d", | 
|  | 4333 | s->id); | 
|  | 4334 | wpas_notify_persistent_group_removed(wpa_s, s); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4335 | wpa_config_remove_network(wpa_s->conf, s->id); | 
|  | 4336 | save_config = 1; | 
|  | 4337 | continue; | 
|  | 4338 | } | 
|  | 4339 |  | 
|  | 4340 | for (i = 0; i < s->num_p2p_clients; i++) { | 
|  | 4341 | if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN, | 
|  | 4342 | peer, ETH_ALEN) != 0) | 
|  | 4343 | continue; | 
|  | 4344 |  | 
|  | 4345 | os_memmove(s->p2p_client_list + i * 2 * ETH_ALEN, | 
|  | 4346 | s->p2p_client_list + (i + 1) * 2 * ETH_ALEN, | 
|  | 4347 | (s->num_p2p_clients - i - 1) * 2 * ETH_ALEN); | 
|  | 4348 | break; | 
|  | 4349 | } | 
|  | 4350 | s->num_p2p_clients--; | 
|  | 4351 | save_config = 1; | 
|  | 4352 | } | 
|  | 4353 |  | 
|  | 4354 | if (save_config) | 
|  | 4355 | p2p_config_write(wpa_s); | 
|  | 4356 |  | 
|  | 4357 | /* Return TRUE if valid SSID remains */ | 
|  | 4358 | return s != NULL; | 
|  | 4359 | } | 
|  | 4360 |  | 
|  | 4361 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4362 | static void wpas_p2ps_get_feat_cap_str(char *buf, size_t buf_len, | 
|  | 4363 | const u8 *feat_cap, size_t feat_cap_len) | 
|  | 4364 | { | 
|  | 4365 | static const char pref[] = " feature_cap="; | 
|  | 4366 | int ret; | 
|  | 4367 |  | 
|  | 4368 | buf[0] = '\0'; | 
|  | 4369 |  | 
|  | 4370 | /* | 
|  | 4371 | * We expect a feature capability to contain at least one byte to be | 
|  | 4372 | * reported. The string buffer provided by the caller function is | 
|  | 4373 | * expected to be big enough to contain all bytes of the attribute for | 
|  | 4374 | * known specifications. This function truncates the reported bytes if | 
|  | 4375 | * the feature capability data exceeds the string buffer size. | 
|  | 4376 | */ | 
|  | 4377 | if (!feat_cap || !feat_cap_len || buf_len < sizeof(pref) + 2) | 
|  | 4378 | return; | 
|  | 4379 |  | 
|  | 4380 | os_memcpy(buf, pref, sizeof(pref)); | 
|  | 4381 | ret = wpa_snprintf_hex(&buf[sizeof(pref) - 1], | 
|  | 4382 | buf_len - sizeof(pref) + 1, | 
|  | 4383 | feat_cap, feat_cap_len); | 
|  | 4384 |  | 
|  | 4385 | if (ret != (2 * (int) feat_cap_len)) | 
|  | 4386 | wpa_printf(MSG_WARNING, "P2PS feature_cap bytes truncated"); | 
|  | 4387 | } | 
|  | 4388 |  | 
|  | 4389 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4390 | static void wpas_p2ps_prov_complete(void *ctx, u8 status, const u8 *dev, | 
|  | 4391 | const u8 *adv_mac, const u8 *ses_mac, | 
|  | 4392 | const u8 *grp_mac, u32 adv_id, u32 ses_id, | 
|  | 4393 | u8 conncap, int passwd_id, | 
|  | 4394 | const u8 *persist_ssid, | 
|  | 4395 | size_t persist_ssid_size, int response_done, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4396 | int prov_start, const char *session_info, | 
|  | 4397 | const u8 *feat_cap, size_t feat_cap_len, | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4398 | unsigned int freq, | 
|  | 4399 | const u8 *group_ssid, size_t group_ssid_len) | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4400 | { | 
|  | 4401 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 4402 | u8 mac[ETH_ALEN]; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4403 | struct wpa_ssid *persistent_go, *stale, *s = NULL; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4404 | int save_config = 0; | 
|  | 4405 | struct wpa_supplicant *go_wpa_s; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4406 | char feat_cap_str[256]; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4407 |  | 
|  | 4408 | if (!dev) | 
|  | 4409 | return; | 
|  | 4410 |  | 
|  | 4411 | os_memset(mac, 0, ETH_ALEN); | 
|  | 4412 | if (!adv_mac) | 
|  | 4413 | adv_mac = mac; | 
|  | 4414 | if (!ses_mac) | 
|  | 4415 | ses_mac = mac; | 
|  | 4416 | if (!grp_mac) | 
|  | 4417 | grp_mac = mac; | 
|  | 4418 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4419 | wpas_p2ps_get_feat_cap_str(feat_cap_str, sizeof(feat_cap_str), | 
|  | 4420 | feat_cap, feat_cap_len); | 
|  | 4421 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4422 | if (prov_start) { | 
|  | 4423 | if (session_info == NULL) { | 
|  | 4424 | wpa_msg_global(wpa_s, MSG_INFO, | 
|  | 4425 | P2P_EVENT_P2PS_PROVISION_START MACSTR | 
|  | 4426 | " adv_id=%x conncap=%x" | 
|  | 4427 | " adv_mac=" MACSTR | 
|  | 4428 | " session=%x mac=" MACSTR | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4429 | " dev_passwd_id=%d%s", | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4430 | MAC2STR(dev), adv_id, conncap, | 
|  | 4431 | MAC2STR(adv_mac), | 
|  | 4432 | ses_id, MAC2STR(ses_mac), | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4433 | passwd_id, feat_cap_str); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4434 | } else { | 
|  | 4435 | wpa_msg_global(wpa_s, MSG_INFO, | 
|  | 4436 | P2P_EVENT_P2PS_PROVISION_START MACSTR | 
|  | 4437 | " adv_id=%x conncap=%x" | 
|  | 4438 | " adv_mac=" MACSTR | 
|  | 4439 | " session=%x mac=" MACSTR | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4440 | " dev_passwd_id=%d info='%s'%s", | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4441 | MAC2STR(dev), adv_id, conncap, | 
|  | 4442 | MAC2STR(adv_mac), | 
|  | 4443 | ses_id, MAC2STR(ses_mac), | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4444 | passwd_id, session_info, feat_cap_str); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4445 | } | 
|  | 4446 | return; | 
|  | 4447 | } | 
|  | 4448 |  | 
|  | 4449 | go_wpa_s = wpas_p2p_get_go_group(wpa_s); | 
|  | 4450 | persistent_go = wpas_p2p_get_persistent_go(wpa_s); | 
|  | 4451 |  | 
|  | 4452 | if (status && status != P2P_SC_SUCCESS_DEFERRED) { | 
|  | 4453 | if (go_wpa_s && !p2p_group_go_member_count(wpa_s)) | 
|  | 4454 | wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname); | 
|  | 4455 |  | 
|  | 4456 | if (persistent_go && !persistent_go->num_p2p_clients) { | 
|  | 4457 | /* remove empty persistent GO */ | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4458 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 4459 | "P2P: Remove empty persistent group id=%d", | 
|  | 4460 | persistent_go->id); | 
|  | 4461 | wpas_notify_persistent_group_removed(wpa_s, | 
|  | 4462 | persistent_go); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4463 | wpa_config_remove_network(wpa_s->conf, | 
|  | 4464 | persistent_go->id); | 
|  | 4465 | } | 
|  | 4466 |  | 
|  | 4467 | wpa_msg_global(wpa_s, MSG_INFO, | 
|  | 4468 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR | 
|  | 4469 | " status=%d" | 
|  | 4470 | " adv_id=%x adv_mac=" MACSTR | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4471 | " session=%x mac=" MACSTR "%s", | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4472 | MAC2STR(dev), status, | 
|  | 4473 | adv_id, MAC2STR(adv_mac), | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4474 | ses_id, MAC2STR(ses_mac), feat_cap_str); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4475 | return; | 
|  | 4476 | } | 
|  | 4477 |  | 
|  | 4478 | /* Clean up stale persistent groups with this device */ | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4479 | if (persist_ssid && persist_ssid_size) | 
|  | 4480 | s = wpas_p2p_get_persistent(wpa_s, dev, persist_ssid, | 
|  | 4481 | persist_ssid_size); | 
|  | 4482 |  | 
|  | 4483 | if (persist_ssid && s && s->mode != WPAS_MODE_P2P_GO && | 
|  | 4484 | is_zero_ether_addr(grp_mac)) { | 
|  | 4485 | wpa_dbg(wpa_s, MSG_ERROR, | 
|  | 4486 | "P2P: Peer device is a GO in a persistent group, but it did not provide the intended MAC address"); | 
|  | 4487 | return; | 
|  | 4488 | } | 
|  | 4489 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4490 | for (;;) { | 
|  | 4491 | stale = wpas_p2p_get_persistent(wpa_s, dev, NULL, 0); | 
|  | 4492 | if (!stale) | 
|  | 4493 | break; | 
|  | 4494 |  | 
|  | 4495 | if (s && s->ssid_len == stale->ssid_len && | 
|  | 4496 | os_memcmp(stale->bssid, s->bssid, ETH_ALEN) == 0 && | 
|  | 4497 | os_memcmp(stale->ssid, s->ssid, s->ssid_len) == 0) | 
|  | 4498 | break; | 
|  | 4499 |  | 
|  | 4500 | /* Remove stale persistent group */ | 
|  | 4501 | if (stale->mode != WPAS_MODE_P2P_GO || | 
|  | 4502 | stale->num_p2p_clients <= 1) { | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4503 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 4504 | "P2P: Remove stale persistent group id=%d", | 
|  | 4505 | stale->id); | 
|  | 4506 | wpas_notify_persistent_group_removed(wpa_s, stale); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4507 | wpa_config_remove_network(wpa_s->conf, stale->id); | 
|  | 4508 | } else { | 
|  | 4509 | size_t i; | 
|  | 4510 |  | 
|  | 4511 | for (i = 0; i < stale->num_p2p_clients; i++) { | 
|  | 4512 | if (os_memcmp(stale->p2p_client_list + | 
|  | 4513 | i * ETH_ALEN, | 
|  | 4514 | dev, ETH_ALEN) == 0) { | 
|  | 4515 | os_memmove(stale->p2p_client_list + | 
|  | 4516 | i * ETH_ALEN, | 
|  | 4517 | stale->p2p_client_list + | 
|  | 4518 | (i + 1) * ETH_ALEN, | 
|  | 4519 | (stale->num_p2p_clients - | 
|  | 4520 | i - 1) * ETH_ALEN); | 
|  | 4521 | break; | 
|  | 4522 | } | 
|  | 4523 | } | 
|  | 4524 | stale->num_p2p_clients--; | 
|  | 4525 | } | 
|  | 4526 | save_config = 1; | 
|  | 4527 | } | 
|  | 4528 |  | 
|  | 4529 | if (save_config) | 
|  | 4530 | p2p_config_write(wpa_s); | 
|  | 4531 |  | 
|  | 4532 | if (s) { | 
|  | 4533 | if (go_wpa_s && !p2p_group_go_member_count(wpa_s)) | 
|  | 4534 | wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname); | 
|  | 4535 |  | 
|  | 4536 | if (persistent_go && s != persistent_go && | 
|  | 4537 | !persistent_go->num_p2p_clients) { | 
|  | 4538 | /* remove empty persistent GO */ | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4539 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 4540 | "P2P: Remove empty persistent group id=%d", | 
|  | 4541 | persistent_go->id); | 
|  | 4542 | wpas_notify_persistent_group_removed(wpa_s, | 
|  | 4543 | persistent_go); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4544 | wpa_config_remove_network(wpa_s->conf, | 
|  | 4545 | persistent_go->id); | 
|  | 4546 | /* Save config */ | 
|  | 4547 | } | 
|  | 4548 |  | 
|  | 4549 | wpa_msg_global(wpa_s, MSG_INFO, | 
|  | 4550 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR | 
|  | 4551 | " status=%d" | 
|  | 4552 | " adv_id=%x adv_mac=" MACSTR | 
|  | 4553 | " session=%x mac=" MACSTR | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4554 | " persist=%d%s", | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4555 | MAC2STR(dev), status, | 
|  | 4556 | adv_id, MAC2STR(adv_mac), | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4557 | ses_id, MAC2STR(ses_mac), s->id, feat_cap_str); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4558 | return; | 
|  | 4559 | } | 
|  | 4560 |  | 
| Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4561 | wpa_s->global->pending_p2ps_group = 0; | 
|  | 4562 | wpa_s->global->pending_p2ps_group_freq = 0; | 
|  | 4563 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4564 | if (conncap == P2PS_SETUP_GROUP_OWNER) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4565 | /* | 
|  | 4566 | * We need to copy the interface name. Simply saving a | 
|  | 4567 | * pointer isn't enough, since if we use pending_interface_name | 
|  | 4568 | * it will be overwritten when the group is added. | 
|  | 4569 | */ | 
|  | 4570 | char go_ifname[100]; | 
|  | 4571 |  | 
|  | 4572 | go_ifname[0] = '\0'; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4573 | if (!go_wpa_s) { | 
| Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4574 | if (!response_done) { | 
|  | 4575 | wpa_s->global->pending_p2ps_group = 1; | 
|  | 4576 | wpa_s->global->pending_p2ps_group_freq = freq; | 
|  | 4577 | } | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4578 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4579 | if (!wpas_p2p_create_iface(wpa_s)) | 
|  | 4580 | os_memcpy(go_ifname, wpa_s->ifname, | 
|  | 4581 | sizeof(go_ifname)); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4582 | else if (wpa_s->pending_interface_name[0]) | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4583 | os_memcpy(go_ifname, | 
|  | 4584 | wpa_s->pending_interface_name, | 
|  | 4585 | sizeof(go_ifname)); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4586 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4587 | if (!go_ifname[0]) { | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4588 | wpas_p2ps_prov_complete( | 
|  | 4589 | wpa_s, P2P_SC_FAIL_UNKNOWN_GROUP, | 
|  | 4590 | dev, adv_mac, ses_mac, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4591 | grp_mac, adv_id, ses_id, 0, 0, | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4592 | NULL, 0, 0, 0, NULL, NULL, 0, 0, | 
|  | 4593 | NULL, 0); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4594 | return; | 
|  | 4595 | } | 
|  | 4596 |  | 
|  | 4597 | /* If PD Resp complete, start up the GO */ | 
|  | 4598 | if (response_done && persistent_go) { | 
|  | 4599 | wpas_p2p_group_add_persistent( | 
|  | 4600 | wpa_s, persistent_go, | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4601 | 0, 0, freq, 0, 0, 0, 0, 0, 0, NULL, | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4602 | persistent_go->mode == | 
|  | 4603 | WPAS_MODE_P2P_GO ? | 
|  | 4604 | P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4605 | 0, 0, false); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4606 | } else if (response_done) { | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4607 | wpas_p2p_group_add(wpa_s, 1, freq, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4608 | 0, 0, 0, 0, 0, 0, false); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4609 | } | 
|  | 4610 |  | 
|  | 4611 | if (passwd_id == DEV_PW_P2PS_DEFAULT) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4612 | os_memcpy(wpa_s->p2ps_join_addr, grp_mac, | 
|  | 4613 | ETH_ALEN); | 
|  | 4614 | wpa_s->p2ps_method_config_any = 1; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4615 | } | 
|  | 4616 | } else if (passwd_id == DEV_PW_P2PS_DEFAULT) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4617 | os_memcpy(go_ifname, go_wpa_s->ifname, | 
|  | 4618 | sizeof(go_ifname)); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4619 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4620 | if (is_zero_ether_addr(grp_mac)) { | 
|  | 4621 | wpa_dbg(go_wpa_s, MSG_DEBUG, | 
|  | 4622 | "P2P: Setting PIN-1 for ANY"); | 
|  | 4623 | wpa_supplicant_ap_wps_pin(go_wpa_s, NULL, | 
|  | 4624 | "12345670", NULL, 0, | 
|  | 4625 | 0); | 
|  | 4626 | } else { | 
|  | 4627 | wpa_dbg(go_wpa_s, MSG_DEBUG, | 
|  | 4628 | "P2P: Setting PIN-1 for " MACSTR, | 
|  | 4629 | MAC2STR(grp_mac)); | 
|  | 4630 | wpa_supplicant_ap_wps_pin(go_wpa_s, grp_mac, | 
|  | 4631 | "12345670", NULL, 0, | 
|  | 4632 | 0); | 
|  | 4633 | } | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4634 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4635 | os_memcpy(wpa_s->p2ps_join_addr, grp_mac, ETH_ALEN); | 
|  | 4636 | wpa_s->p2ps_method_config_any = 1; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4637 | } | 
|  | 4638 |  | 
|  | 4639 | wpa_msg_global(wpa_s, MSG_INFO, | 
|  | 4640 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR | 
|  | 4641 | " status=%d conncap=%x" | 
|  | 4642 | " adv_id=%x adv_mac=" MACSTR | 
|  | 4643 | " session=%x mac=" MACSTR | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4644 | " dev_passwd_id=%d go=%s%s", | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4645 | MAC2STR(dev), status, conncap, | 
|  | 4646 | adv_id, MAC2STR(adv_mac), | 
|  | 4647 | ses_id, MAC2STR(ses_mac), | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4648 | passwd_id, go_ifname, feat_cap_str); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4649 | return; | 
|  | 4650 | } | 
|  | 4651 |  | 
|  | 4652 | if (go_wpa_s && !p2p_group_go_member_count(wpa_s)) | 
|  | 4653 | wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname); | 
|  | 4654 |  | 
|  | 4655 | if (persistent_go && !persistent_go->num_p2p_clients) { | 
|  | 4656 | /* remove empty persistent GO */ | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4657 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 4658 | "P2P: Remove empty persistent group id=%d", | 
|  | 4659 | persistent_go->id); | 
|  | 4660 | wpas_notify_persistent_group_removed(wpa_s, persistent_go); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4661 | wpa_config_remove_network(wpa_s->conf, persistent_go->id); | 
|  | 4662 | } | 
|  | 4663 |  | 
|  | 4664 | if (conncap == P2PS_SETUP_CLIENT) { | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4665 | char ssid_hex[32 * 2 + 1]; | 
|  | 4666 |  | 
|  | 4667 | if (group_ssid) | 
|  | 4668 | wpa_snprintf_hex(ssid_hex, sizeof(ssid_hex), | 
|  | 4669 | group_ssid, group_ssid_len); | 
|  | 4670 | else | 
|  | 4671 | ssid_hex[0] = '\0'; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4672 | wpa_msg_global(wpa_s, MSG_INFO, | 
|  | 4673 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR | 
|  | 4674 | " status=%d conncap=%x" | 
|  | 4675 | " adv_id=%x adv_mac=" MACSTR | 
|  | 4676 | " session=%x mac=" MACSTR | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4677 | " dev_passwd_id=%d join=" MACSTR "%s%s%s", | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4678 | MAC2STR(dev), status, conncap, | 
|  | 4679 | adv_id, MAC2STR(adv_mac), | 
|  | 4680 | ses_id, MAC2STR(ses_mac), | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 4681 | passwd_id, MAC2STR(grp_mac), feat_cap_str, | 
|  | 4682 | group_ssid ? " group_ssid=" : "", ssid_hex); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4683 | } else { | 
|  | 4684 | wpa_msg_global(wpa_s, MSG_INFO, | 
|  | 4685 | P2P_EVENT_P2PS_PROVISION_DONE MACSTR | 
|  | 4686 | " status=%d conncap=%x" | 
|  | 4687 | " adv_id=%x adv_mac=" MACSTR | 
|  | 4688 | " session=%x mac=" MACSTR | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4689 | " dev_passwd_id=%d%s", | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4690 | MAC2STR(dev), status, conncap, | 
|  | 4691 | adv_id, MAC2STR(adv_mac), | 
|  | 4692 | ses_id, MAC2STR(ses_mac), | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4693 | passwd_id, feat_cap_str); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4694 | } | 
|  | 4695 | } | 
|  | 4696 |  | 
|  | 4697 |  | 
| Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 4698 | static int _wpas_p2p_in_progress(void *ctx) | 
|  | 4699 | { | 
|  | 4700 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 4701 | return wpas_p2p_in_progress(wpa_s); | 
|  | 4702 | } | 
|  | 4703 |  | 
|  | 4704 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4705 | static int wpas_prov_disc_resp_cb(void *ctx) | 
|  | 4706 | { | 
|  | 4707 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 4708 | struct wpa_ssid *persistent_go; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4709 | unsigned int freq; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4710 |  | 
|  | 4711 | if (!wpa_s->global->pending_p2ps_group) | 
|  | 4712 | return 0; | 
|  | 4713 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4714 | freq = wpa_s->global->pending_p2ps_group_freq; | 
|  | 4715 | wpa_s->global->pending_p2ps_group_freq = 0; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4716 | wpa_s->global->pending_p2ps_group = 0; | 
|  | 4717 |  | 
|  | 4718 | if (wpas_p2p_get_go_group(wpa_s)) | 
|  | 4719 | return 0; | 
|  | 4720 | persistent_go = wpas_p2p_get_persistent_go(wpa_s); | 
|  | 4721 |  | 
|  | 4722 | if (persistent_go) { | 
|  | 4723 | wpas_p2p_group_add_persistent( | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4724 | wpa_s, persistent_go, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 
|  | 4725 | NULL, | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4726 | persistent_go->mode == WPAS_MODE_P2P_GO ? | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4727 | P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0, 0, | 
|  | 4728 | is_p2p_allow_6ghz(wpa_s->global->p2p)); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4729 | } else { | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4730 | wpas_p2p_group_add(wpa_s, 1, freq, 0, 0, 0, 0, 0, 0, | 
|  | 4731 | is_p2p_allow_6ghz(wpa_s->global->p2p)); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4732 | } | 
|  | 4733 |  | 
|  | 4734 | return 1; | 
|  | 4735 | } | 
|  | 4736 |  | 
|  | 4737 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4738 | static int wpas_p2p_get_pref_freq_list(void *ctx, int go, | 
|  | 4739 | unsigned int *len, | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4740 | struct weighted_pcl *freq_list) | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4741 | { | 
|  | 4742 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 4743 |  | 
|  | 4744 | return wpa_drv_get_pref_freq_list(wpa_s, go ? WPA_IF_P2P_GO : | 
|  | 4745 | WPA_IF_P2P_CLIENT, len, freq_list); | 
|  | 4746 | } | 
|  | 4747 |  | 
| Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4748 | int wpas_p2p_mac_setup(struct wpa_supplicant *wpa_s) | 
|  | 4749 | { | 
| JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4750 | int ret = 0; | 
| Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4751 | u8 addr[ETH_ALEN] = {0}; | 
|  | 4752 |  | 
|  | 4753 | if (wpa_s->conf->p2p_device_random_mac_addr == 0) | 
|  | 4754 | return 0; | 
|  | 4755 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4756 | if (wpa_s->conf->p2p_device_random_mac_addr == 2) { | 
|  | 4757 | if (is_zero_ether_addr( | 
|  | 4758 | wpa_s->conf->p2p_device_persistent_mac_addr) && | 
|  | 4759 | !is_zero_ether_addr(wpa_s->own_addr)) { | 
|  | 4760 | os_memcpy(wpa_s->conf->p2p_device_persistent_mac_addr, | 
|  | 4761 | wpa_s->own_addr, ETH_ALEN); | 
|  | 4762 | } | 
|  | 4763 | return 0; | 
|  | 4764 | } | 
|  | 4765 |  | 
|  | 4766 | if (!wpa_s->conf->ssid) { | 
| Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4767 | if (random_mac_addr(addr) < 0) { | 
|  | 4768 | wpa_msg(wpa_s, MSG_INFO, | 
|  | 4769 | "Failed to generate random MAC address"); | 
|  | 4770 | return -EINVAL; | 
|  | 4771 | } | 
|  | 4772 |  | 
| Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 4773 | /* Store generated MAC address. */ | 
|  | 4774 | os_memcpy(wpa_s->conf->p2p_device_persistent_mac_addr, addr, | 
|  | 4775 | ETH_ALEN); | 
| Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4776 | } else { | 
| Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 4777 | /* If there are existing saved groups, restore last MAC address. | 
|  | 4778 | * if there is no last used MAC address, the last one is | 
|  | 4779 | * factory MAC. */ | 
|  | 4780 | if (is_zero_ether_addr( | 
|  | 4781 | wpa_s->conf->p2p_device_persistent_mac_addr)) | 
| Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4782 | return 0; | 
| Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 4783 | os_memcpy(addr, wpa_s->conf->p2p_device_persistent_mac_addr, | 
|  | 4784 | ETH_ALEN); | 
| Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4785 | wpa_msg(wpa_s, MSG_DEBUG, "Restore last used MAC address."); | 
|  | 4786 | } | 
|  | 4787 |  | 
| JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4788 | ret = wpa_drv_set_mac_addr(wpa_s, addr); | 
|  | 4789 |  | 
|  | 4790 | if (ret < 0) { | 
| Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4791 | wpa_msg(wpa_s, MSG_INFO, | 
|  | 4792 | "Failed to set random MAC address"); | 
| JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4793 | return ret; | 
| Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4794 | } | 
|  | 4795 |  | 
| JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4796 | ret = wpa_supplicant_update_mac_addr(wpa_s); | 
|  | 4797 |  | 
|  | 4798 | if (ret < 0) { | 
| Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4799 | wpa_msg(wpa_s, MSG_INFO, | 
|  | 4800 | "Could not update MAC address information"); | 
| JaeMan Park | 9de9732 | 2022-07-11 15:36:43 +0900 | [diff] [blame] | 4801 | return ret; | 
| Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4802 | } | 
|  | 4803 |  | 
|  | 4804 | wpa_msg(wpa_s, MSG_DEBUG, "Using random MAC address " MACSTR, | 
|  | 4805 | MAC2STR(addr)); | 
|  | 4806 |  | 
|  | 4807 | return 0; | 
|  | 4808 | } | 
|  | 4809 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4810 | /** | 
|  | 4811 | * wpas_p2p_init - Initialize P2P module for %wpa_supplicant | 
|  | 4812 | * @global: Pointer to global data from wpa_supplicant_init() | 
|  | 4813 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() | 
|  | 4814 | * Returns: 0 on success, -1 on failure | 
|  | 4815 | */ | 
|  | 4816 | int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s) | 
|  | 4817 | { | 
|  | 4818 | struct p2p_config p2p; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4819 | int i; | 
|  | 4820 |  | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 4821 | if (wpa_s->conf->p2p_disabled) | 
|  | 4822 | return 0; | 
|  | 4823 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4824 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE)) | 
|  | 4825 | return 0; | 
|  | 4826 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4827 | if (global->p2p) | 
|  | 4828 | return 0; | 
|  | 4829 |  | 
| Jimmy Chen | f887c7b | 2018-11-13 15:19:57 +0800 | [diff] [blame] | 4830 | if (wpas_p2p_mac_setup(wpa_s) < 0) { | 
|  | 4831 | wpa_msg(wpa_s, MSG_ERROR, | 
|  | 4832 | "Failed to initialize P2P random MAC address."); | 
|  | 4833 | return -1; | 
|  | 4834 | } | 
|  | 4835 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4836 | os_memset(&p2p, 0, sizeof(p2p)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4837 | p2p.cb_ctx = wpa_s; | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 4838 | p2p.debug_print = wpas_p2p_debug_print; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4839 | p2p.p2p_scan = wpas_p2p_scan; | 
|  | 4840 | p2p.send_action = wpas_send_action; | 
|  | 4841 | p2p.send_action_done = wpas_send_action_done; | 
|  | 4842 | p2p.go_neg_completed = wpas_go_neg_completed; | 
|  | 4843 | p2p.go_neg_req_rx = wpas_go_neg_req_rx; | 
|  | 4844 | p2p.dev_found = wpas_dev_found; | 
|  | 4845 | p2p.dev_lost = wpas_dev_lost; | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 4846 | p2p.find_stopped = wpas_find_stopped; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4847 | p2p.start_listen = wpas_start_listen; | 
|  | 4848 | p2p.stop_listen = wpas_stop_listen; | 
|  | 4849 | p2p.send_probe_resp = wpas_send_probe_resp; | 
|  | 4850 | p2p.sd_request = wpas_sd_request; | 
|  | 4851 | p2p.sd_response = wpas_sd_response; | 
|  | 4852 | p2p.prov_disc_req = wpas_prov_disc_req; | 
|  | 4853 | p2p.prov_disc_resp = wpas_prov_disc_resp; | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 4854 | p2p.prov_disc_fail = wpas_prov_disc_fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4855 | p2p.invitation_process = wpas_invitation_process; | 
|  | 4856 | p2p.invitation_received = wpas_invitation_received; | 
|  | 4857 | p2p.invitation_result = wpas_invitation_result; | 
|  | 4858 | p2p.get_noa = wpas_get_noa; | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4859 | p2p.go_connected = wpas_go_connected; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4860 | p2p.presence_resp = wpas_presence_resp; | 
| Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 4861 | p2p.is_concurrent_session_active = wpas_is_concurrent_session_active; | 
| Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 4862 | p2p.is_p2p_in_progress = _wpas_p2p_in_progress; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 4863 | p2p.get_persistent_group = wpas_get_persistent_group; | 
|  | 4864 | p2p.get_go_info = wpas_get_go_info; | 
|  | 4865 | p2p.remove_stale_groups = wpas_remove_stale_groups; | 
|  | 4866 | p2p.p2ps_prov_complete = wpas_p2ps_prov_complete; | 
|  | 4867 | p2p.prov_disc_resp_cb = wpas_prov_disc_resp_cb; | 
|  | 4868 | p2p.p2ps_group_capability = p2ps_group_capability; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4869 | p2p.get_pref_freq_list = wpas_p2p_get_pref_freq_list; | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4870 | p2p.p2p_6ghz_disable = wpa_s->conf->p2p_6ghz_disable; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4871 |  | 
|  | 4872 | 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] | 4873 | 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] | 4874 | p2p.dev_name = wpa_s->conf->device_name; | 
|  | 4875 | p2p.manufacturer = wpa_s->conf->manufacturer; | 
|  | 4876 | p2p.model_name = wpa_s->conf->model_name; | 
|  | 4877 | p2p.model_number = wpa_s->conf->model_number; | 
|  | 4878 | p2p.serial_number = wpa_s->conf->serial_number; | 
|  | 4879 | if (wpa_s->wps) { | 
|  | 4880 | os_memcpy(p2p.uuid, wpa_s->wps->uuid, 16); | 
|  | 4881 | p2p.config_methods = wpa_s->wps->config_methods; | 
|  | 4882 | } | 
|  | 4883 |  | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4884 | if (wpas_p2p_setup_channels(wpa_s, &p2p.channels, &p2p.cli_channels, | 
|  | 4885 | p2p.p2p_6ghz_disable)) { | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4886 | wpa_printf(MSG_ERROR, | 
|  | 4887 | "P2P: Failed to configure supported channel list"); | 
|  | 4888 | return -1; | 
|  | 4889 | } | 
|  | 4890 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4891 | if (wpa_s->conf->p2p_listen_reg_class && | 
|  | 4892 | wpa_s->conf->p2p_listen_channel) { | 
|  | 4893 | p2p.reg_class = wpa_s->conf->p2p_listen_reg_class; | 
|  | 4894 | p2p.channel = wpa_s->conf->p2p_listen_channel; | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 4895 | p2p.channel_forced = 1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4896 | } else { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4897 | /* | 
|  | 4898 | * Pick one of the social channels randomly as the listen | 
|  | 4899 | * channel. | 
|  | 4900 | */ | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4901 | if (p2p_config_get_random_social(&p2p, &p2p.reg_class, | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4902 | &p2p.channel, | 
|  | 4903 | &global->p2p_go_avoid_freq, | 
|  | 4904 | &global->p2p_disallow_freq) != | 
|  | 4905 | 0) { | 
| Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 4906 | wpa_printf(MSG_INFO, | 
|  | 4907 | "P2P: No social channels supported by the driver - do not enable P2P"); | 
|  | 4908 | return 0; | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4909 | } | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 4910 | p2p.channel_forced = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4911 | } | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4912 | wpa_printf(MSG_DEBUG, "P2P: Own listen channel: %d:%d", | 
|  | 4913 | p2p.reg_class, p2p.channel); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4914 |  | 
|  | 4915 | if (wpa_s->conf->p2p_oper_reg_class && | 
|  | 4916 | wpa_s->conf->p2p_oper_channel) { | 
|  | 4917 | p2p.op_reg_class = wpa_s->conf->p2p_oper_reg_class; | 
|  | 4918 | p2p.op_channel = wpa_s->conf->p2p_oper_channel; | 
|  | 4919 | p2p.cfg_op_channel = 1; | 
|  | 4920 | wpa_printf(MSG_DEBUG, "P2P: Configured operating channel: " | 
|  | 4921 | "%d:%d", p2p.op_reg_class, p2p.op_channel); | 
|  | 4922 |  | 
|  | 4923 | } else { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4924 | /* | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4925 | * Use random operation channel from 2.4 GHz band social | 
|  | 4926 | * channels (1, 6, 11) or band 60 GHz social channel (2) if no | 
|  | 4927 | * other preference is indicated. | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4928 | */ | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4929 | if (p2p_config_get_random_social(&p2p, &p2p.op_reg_class, | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4930 | &p2p.op_channel, NULL, | 
|  | 4931 | NULL) != 0) { | 
|  | 4932 | wpa_printf(MSG_INFO, | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4933 | "P2P: Failed to select random social channel as operation channel"); | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4934 | p2p.op_reg_class = 0; | 
|  | 4935 | p2p.op_channel = 0; | 
|  | 4936 | /* This will be overridden during group setup in | 
|  | 4937 | * p2p_prepare_channel(), so allow setup to continue. */ | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4938 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4939 | p2p.cfg_op_channel = 0; | 
|  | 4940 | wpa_printf(MSG_DEBUG, "P2P: Random operating channel: " | 
|  | 4941 | "%d:%d", p2p.op_reg_class, p2p.op_channel); | 
|  | 4942 | } | 
| Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 4943 |  | 
|  | 4944 | if (wpa_s->conf->p2p_pref_chan && wpa_s->conf->num_p2p_pref_chan) { | 
|  | 4945 | p2p.pref_chan = wpa_s->conf->p2p_pref_chan; | 
|  | 4946 | p2p.num_pref_chan = wpa_s->conf->num_p2p_pref_chan; | 
|  | 4947 | } | 
|  | 4948 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4949 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) { | 
|  | 4950 | os_memcpy(p2p.country, wpa_s->conf->country, 2); | 
|  | 4951 | p2p.country[2] = 0x04; | 
|  | 4952 | } else | 
|  | 4953 | os_memcpy(p2p.country, "XX\x04", 3); | 
|  | 4954 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4955 | os_memcpy(p2p.pri_dev_type, wpa_s->conf->device_type, | 
|  | 4956 | WPS_DEV_TYPE_LEN); | 
|  | 4957 |  | 
|  | 4958 | p2p.num_sec_dev_types = wpa_s->conf->num_sec_device_types; | 
|  | 4959 | os_memcpy(p2p.sec_dev_type, wpa_s->conf->sec_device_type, | 
|  | 4960 | p2p.num_sec_dev_types * WPS_DEV_TYPE_LEN); | 
|  | 4961 |  | 
|  | 4962 | p2p.concurrent_operations = !!(wpa_s->drv_flags & | 
|  | 4963 | WPA_DRIVER_FLAGS_P2P_CONCURRENT); | 
|  | 4964 |  | 
|  | 4965 | p2p.max_peers = 100; | 
|  | 4966 |  | 
|  | 4967 | if (wpa_s->conf->p2p_ssid_postfix) { | 
|  | 4968 | p2p.ssid_postfix_len = | 
|  | 4969 | os_strlen(wpa_s->conf->p2p_ssid_postfix); | 
|  | 4970 | if (p2p.ssid_postfix_len > sizeof(p2p.ssid_postfix)) | 
|  | 4971 | p2p.ssid_postfix_len = sizeof(p2p.ssid_postfix); | 
|  | 4972 | os_memcpy(p2p.ssid_postfix, wpa_s->conf->p2p_ssid_postfix, | 
|  | 4973 | p2p.ssid_postfix_len); | 
|  | 4974 | } | 
|  | 4975 |  | 
|  | 4976 | p2p.p2p_intra_bss = wpa_s->conf->p2p_intra_bss; | 
|  | 4977 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4978 | p2p.max_listen = wpa_s->max_remain_on_chan; | 
|  | 4979 |  | 
| Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 4980 | if (wpa_s->conf->p2p_passphrase_len >= 8 && | 
|  | 4981 | wpa_s->conf->p2p_passphrase_len <= 63) | 
|  | 4982 | p2p.passphrase_len = wpa_s->conf->p2p_passphrase_len; | 
|  | 4983 | else | 
|  | 4984 | p2p.passphrase_len = 8; | 
|  | 4985 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4986 | global->p2p = p2p_init(&p2p); | 
|  | 4987 | if (global->p2p == NULL) | 
|  | 4988 | return -1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4989 | global->p2p_init_wpa_s = wpa_s; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4990 |  | 
|  | 4991 | for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) { | 
|  | 4992 | if (wpa_s->conf->wps_vendor_ext[i] == NULL) | 
|  | 4993 | continue; | 
|  | 4994 | p2p_add_wps_vendor_extension( | 
|  | 4995 | global->p2p, wpa_s->conf->wps_vendor_ext[i]); | 
|  | 4996 | } | 
|  | 4997 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4998 | p2p_set_no_go_freq(global->p2p, &wpa_s->conf->p2p_no_go_freq); | 
|  | 4999 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5000 | return 0; | 
|  | 5001 | } | 
|  | 5002 |  | 
|  | 5003 |  | 
|  | 5004 | /** | 
|  | 5005 | * wpas_p2p_deinit - Deinitialize per-interface P2P data | 
|  | 5006 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() | 
|  | 5007 | * | 
|  | 5008 | * This function deinitialize per-interface P2P data. | 
|  | 5009 | */ | 
|  | 5010 | void wpas_p2p_deinit(struct wpa_supplicant *wpa_s) | 
|  | 5011 | { | 
|  | 5012 | if (wpa_s->driver && wpa_s->drv_priv) | 
|  | 5013 | wpa_drv_probe_req_report(wpa_s, 0); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5014 |  | 
|  | 5015 | if (wpa_s->go_params) { | 
|  | 5016 | /* Clear any stored provisioning info */ | 
|  | 5017 | p2p_clear_provisioning_info( | 
|  | 5018 | wpa_s->global->p2p, | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5019 | wpa_s->go_params->peer_device_addr); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5020 | } | 
|  | 5021 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5022 | os_free(wpa_s->go_params); | 
|  | 5023 | wpa_s->go_params = NULL; | 
| Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 5024 | eloop_cancel_timeout(wpas_p2p_psk_failure_removal, wpa_s, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5025 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL); | 
|  | 5026 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5027 | wpa_s->global->p2p_long_listen = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5028 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); | 
|  | 5029 | eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL); | 
|  | 5030 | wpas_p2p_remove_pending_group_interface(wpa_s); | 
| Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 5031 | eloop_cancel_timeout(wpas_p2p_group_freq_conflict, wpa_s, NULL); | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5032 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, wpa_s, NULL); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5033 | wpas_p2p_listen_work_done(wpa_s); | 
|  | 5034 | if (wpa_s->p2p_send_action_work) { | 
|  | 5035 | os_free(wpa_s->p2p_send_action_work->ctx); | 
|  | 5036 | radio_work_done(wpa_s->p2p_send_action_work); | 
|  | 5037 | wpa_s->p2p_send_action_work = NULL; | 
|  | 5038 | } | 
|  | 5039 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, wpa_s, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5040 |  | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5041 | wpabuf_free(wpa_s->p2p_oob_dev_pw); | 
|  | 5042 | wpa_s->p2p_oob_dev_pw = NULL; | 
|  | 5043 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5044 | os_free(wpa_s->p2p_group_common_freqs); | 
|  | 5045 | wpa_s->p2p_group_common_freqs = NULL; | 
|  | 5046 | wpa_s->p2p_group_common_freqs_num = 0; | 
|  | 5047 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5048 | /* TODO: remove group interface from the driver if this wpa_s instance | 
|  | 5049 | * is on top of a P2P group interface */ | 
|  | 5050 | } | 
|  | 5051 |  | 
|  | 5052 |  | 
|  | 5053 | /** | 
|  | 5054 | * wpas_p2p_deinit_global - Deinitialize global P2P module | 
|  | 5055 | * @global: Pointer to global data from wpa_supplicant_init() | 
|  | 5056 | * | 
|  | 5057 | * This function deinitializes the global (per device) P2P module. | 
|  | 5058 | */ | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5059 | static void wpas_p2p_deinit_global(struct wpa_global *global) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5060 | { | 
|  | 5061 | struct wpa_supplicant *wpa_s, *tmp; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5062 |  | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5063 | wpa_s = global->ifaces; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5064 |  | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5065 | wpas_p2p_service_flush(global->p2p_init_wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5066 |  | 
|  | 5067 | /* Remove remaining P2P group interfaces */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5068 | while (wpa_s && wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) | 
|  | 5069 | wpa_s = wpa_s->next; | 
|  | 5070 | while (wpa_s) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5071 | tmp = global->ifaces; | 
|  | 5072 | while (tmp && | 
|  | 5073 | (tmp == wpa_s || | 
|  | 5074 | tmp->p2p_group_interface == NOT_P2P_GROUP_INTERFACE)) { | 
|  | 5075 | tmp = tmp->next; | 
|  | 5076 | } | 
|  | 5077 | if (tmp == NULL) | 
|  | 5078 | break; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5079 | /* Disconnect from the P2P group and deinit the interface */ | 
|  | 5080 | wpas_p2p_disconnect(tmp); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5081 | } | 
|  | 5082 |  | 
|  | 5083 | /* | 
|  | 5084 | * Deinit GO data on any possibly remaining interface (if main | 
|  | 5085 | * interface is used as GO). | 
|  | 5086 | */ | 
|  | 5087 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 5088 | if (wpa_s->ap_iface) | 
|  | 5089 | wpas_p2p_group_deinit(wpa_s); | 
|  | 5090 | } | 
|  | 5091 |  | 
|  | 5092 | p2p_deinit(global->p2p); | 
|  | 5093 | global->p2p = NULL; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5094 | global->p2p_init_wpa_s = NULL; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5095 | } | 
|  | 5096 |  | 
|  | 5097 |  | 
|  | 5098 | static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s) | 
|  | 5099 | { | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5100 | if (wpa_s->conf->p2p_no_group_iface) | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5101 | return 0; /* separate interface disabled per configuration */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5102 | if (wpa_s->drv_flags & | 
|  | 5103 | (WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE | | 
|  | 5104 | WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P)) | 
|  | 5105 | return 1; /* P2P group requires a new interface in every case | 
|  | 5106 | */ | 
|  | 5107 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CONCURRENT)) | 
|  | 5108 | return 0; /* driver does not support concurrent operations */ | 
|  | 5109 | if (wpa_s->global->ifaces->next) | 
|  | 5110 | return 1; /* more that one interface already in use */ | 
|  | 5111 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) | 
|  | 5112 | return 1; /* this interface is already in use */ | 
|  | 5113 | return 0; | 
|  | 5114 | } | 
|  | 5115 |  | 
|  | 5116 |  | 
|  | 5117 | static int wpas_p2p_start_go_neg(struct wpa_supplicant *wpa_s, | 
|  | 5118 | const u8 *peer_addr, | 
|  | 5119 | enum p2p_wps_method wps_method, | 
|  | 5120 | int go_intent, const u8 *own_interface_addr, | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5121 | unsigned int force_freq, int persistent_group, | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5122 | struct wpa_ssid *ssid, unsigned int pref_freq) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5123 | { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5124 | if (persistent_group && wpa_s->conf->persistent_reconnect) | 
|  | 5125 | persistent_group = 2; | 
|  | 5126 |  | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5127 | /* | 
|  | 5128 | * Increase GO config timeout if HT40 is used since it takes some time | 
|  | 5129 | * to scan channels for coex purposes before the BSS can be started. | 
|  | 5130 | */ | 
|  | 5131 | p2p_set_config_timeout(wpa_s->global->p2p, | 
|  | 5132 | wpa_s->p2p_go_ht40 ? 255 : 100, 20); | 
|  | 5133 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5134 | return p2p_connect(wpa_s->global->p2p, peer_addr, wps_method, | 
|  | 5135 | go_intent, own_interface_addr, force_freq, | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5136 | persistent_group, ssid ? ssid->ssid : NULL, | 
|  | 5137 | ssid ? ssid->ssid_len : 0, | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5138 | wpa_s->p2p_pd_before_go_neg, pref_freq, | 
|  | 5139 | wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id : | 
|  | 5140 | 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5141 | } | 
|  | 5142 |  | 
|  | 5143 |  | 
|  | 5144 | static int wpas_p2p_auth_go_neg(struct wpa_supplicant *wpa_s, | 
|  | 5145 | const u8 *peer_addr, | 
|  | 5146 | enum p2p_wps_method wps_method, | 
|  | 5147 | int go_intent, const u8 *own_interface_addr, | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5148 | unsigned int force_freq, int persistent_group, | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5149 | struct wpa_ssid *ssid, unsigned int pref_freq) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5150 | { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5151 | if (persistent_group && wpa_s->conf->persistent_reconnect) | 
|  | 5152 | persistent_group = 2; | 
|  | 5153 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5154 | return p2p_authorize(wpa_s->global->p2p, peer_addr, wps_method, | 
|  | 5155 | go_intent, own_interface_addr, force_freq, | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5156 | persistent_group, ssid ? ssid->ssid : NULL, | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5157 | ssid ? ssid->ssid_len : 0, pref_freq, | 
|  | 5158 | wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id : | 
|  | 5159 | 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5160 | } | 
|  | 5161 |  | 
|  | 5162 |  | 
|  | 5163 | static void wpas_p2p_check_join_scan_limit(struct wpa_supplicant *wpa_s) | 
|  | 5164 | { | 
|  | 5165 | wpa_s->p2p_join_scan_count++; | 
|  | 5166 | wpa_printf(MSG_DEBUG, "P2P: Join scan attempt %d", | 
|  | 5167 | wpa_s->p2p_join_scan_count); | 
|  | 5168 | if (wpa_s->p2p_join_scan_count > P2P_MAX_JOIN_SCAN_ATTEMPTS) { | 
|  | 5169 | wpa_printf(MSG_DEBUG, "P2P: Failed to find GO " MACSTR | 
|  | 5170 | " for join operationg - stop join attempt", | 
|  | 5171 | MAC2STR(wpa_s->pending_join_iface_addr)); | 
|  | 5172 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5173 | if (wpa_s->p2p_auto_pd) { | 
|  | 5174 | wpa_s->p2p_auto_pd = 0; | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5175 | wpa_msg_global(wpa_s, MSG_INFO, | 
|  | 5176 | P2P_EVENT_PROV_DISC_FAILURE | 
|  | 5177 | " p2p_dev_addr=" MACSTR " status=N/A", | 
|  | 5178 | MAC2STR(wpa_s->pending_join_dev_addr)); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5179 | return; | 
|  | 5180 | } | 
| Jimmy Chen | b7b3f4d | 2020-09-02 16:50:11 +0800 | [diff] [blame] | 5181 | if (wpa_s->p2p_fallback_to_go_neg) { | 
|  | 5182 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Join operating " | 
|  | 5183 | "failed - fall back to GO Negotiation"); | 
|  | 5184 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, | 
|  | 5185 | P2P_EVENT_FALLBACK_TO_GO_NEG | 
|  | 5186 | "reason=join-failed"); | 
|  | 5187 | wpas_p2p_fallback_to_go_neg(wpa_s, 0); | 
|  | 5188 | return; | 
|  | 5189 | } | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5190 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5191 | P2P_EVENT_GROUP_FORMATION_FAILURE); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5192 | wpas_notify_p2p_group_formation_failure(wpa_s, ""); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5193 | } | 
|  | 5194 | } | 
|  | 5195 |  | 
|  | 5196 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5197 | static int wpas_check_freq_conflict(struct wpa_supplicant *wpa_s, int freq) | 
|  | 5198 | { | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5199 | int res; | 
|  | 5200 | unsigned int num, i; | 
|  | 5201 | struct wpa_used_freq_data *freqs; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5202 |  | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5203 | if (wpas_p2p_num_unused_channels(wpa_s) > 0) { | 
|  | 5204 | /* Multiple channels are supported and not all are in use */ | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5205 | return 0; | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5206 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5207 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5208 | freqs = os_calloc(wpa_s->num_multichan_concurrent, | 
|  | 5209 | sizeof(struct wpa_used_freq_data)); | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5210 | if (!freqs) | 
|  | 5211 | return 1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5212 |  | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5213 | num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, | 
|  | 5214 | wpa_s->num_multichan_concurrent); | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5215 |  | 
|  | 5216 | for (i = 0; i < num; i++) { | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5217 | if (freqs[i].freq == freq) { | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5218 | wpa_printf(MSG_DEBUG, "P2P: Frequency %d MHz in use by another virtual interface and can be used", | 
|  | 5219 | freq); | 
|  | 5220 | res = 0; | 
|  | 5221 | goto exit_free; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5222 | } | 
|  | 5223 | } | 
|  | 5224 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5225 | wpa_printf(MSG_DEBUG, "P2P: No valid operating frequencies"); | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5226 | res = 1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5227 |  | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5228 | exit_free: | 
|  | 5229 | os_free(freqs); | 
|  | 5230 | return res; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5231 | } | 
|  | 5232 |  | 
|  | 5233 |  | 
|  | 5234 | static int wpas_p2p_peer_go(struct wpa_supplicant *wpa_s, | 
|  | 5235 | const u8 *peer_dev_addr) | 
|  | 5236 | { | 
|  | 5237 | struct wpa_bss *bss; | 
|  | 5238 | int updated; | 
|  | 5239 |  | 
|  | 5240 | bss = wpa_bss_get_p2p_dev_addr(wpa_s, peer_dev_addr); | 
|  | 5241 | if (bss == NULL) | 
|  | 5242 | return -1; | 
|  | 5243 | if (bss->last_update_idx < wpa_s->bss_update_idx) { | 
|  | 5244 | wpa_printf(MSG_DEBUG, "P2P: Peer BSS entry not updated in the " | 
|  | 5245 | "last scan"); | 
|  | 5246 | return 0; | 
|  | 5247 | } | 
|  | 5248 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5249 | updated = os_reltime_before(&wpa_s->p2p_auto_started, | 
|  | 5250 | &bss->last_update); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5251 | wpa_printf(MSG_DEBUG, "P2P: Current BSS entry for peer updated at " | 
|  | 5252 | "%ld.%06ld (%supdated in last scan)", | 
|  | 5253 | bss->last_update.sec, bss->last_update.usec, | 
|  | 5254 | updated ? "": "not "); | 
|  | 5255 |  | 
|  | 5256 | return updated; | 
|  | 5257 | } | 
|  | 5258 |  | 
|  | 5259 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5260 | static void wpas_p2p_scan_res_join(struct wpa_supplicant *wpa_s, | 
|  | 5261 | struct wpa_scan_results *scan_res) | 
|  | 5262 | { | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5263 | struct wpa_bss *bss = NULL; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5264 | int freq; | 
|  | 5265 | u8 iface_addr[ETH_ALEN]; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5266 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5267 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); | 
|  | 5268 |  | 
|  | 5269 | if (wpa_s->global->p2p_disabled) | 
|  | 5270 | return; | 
|  | 5271 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5272 | wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS) for %sjoin", | 
|  | 5273 | scan_res ? (int) scan_res->num : -1, | 
|  | 5274 | wpa_s->p2p_auto_join ? "auto_" : ""); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5275 |  | 
|  | 5276 | if (scan_res) | 
|  | 5277 | wpas_p2p_scan_res_handler(wpa_s, scan_res); | 
|  | 5278 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5279 | if (wpa_s->p2p_auto_pd) { | 
|  | 5280 | int join = wpas_p2p_peer_go(wpa_s, | 
|  | 5281 | wpa_s->pending_join_dev_addr); | 
|  | 5282 | if (join == 0 && | 
|  | 5283 | wpa_s->auto_pd_scan_retry < P2P_AUTO_PD_SCAN_ATTEMPTS) { | 
|  | 5284 | wpa_s->auto_pd_scan_retry++; | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5285 | bss = wpa_bss_get_bssid_latest( | 
|  | 5286 | wpa_s, wpa_s->pending_join_dev_addr); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5287 | if (bss) { | 
|  | 5288 | freq = bss->freq; | 
|  | 5289 | wpa_printf(MSG_DEBUG, "P2P: Scan retry %d for " | 
|  | 5290 | "the peer " MACSTR " at %d MHz", | 
|  | 5291 | wpa_s->auto_pd_scan_retry, | 
|  | 5292 | MAC2STR(wpa_s-> | 
|  | 5293 | pending_join_dev_addr), | 
|  | 5294 | freq); | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5295 | wpas_p2p_join_scan_req(wpa_s, freq, NULL, 0); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5296 | return; | 
|  | 5297 | } | 
|  | 5298 | } | 
|  | 5299 |  | 
|  | 5300 | if (join < 0) | 
|  | 5301 | join = 0; | 
|  | 5302 |  | 
|  | 5303 | wpa_s->p2p_auto_pd = 0; | 
|  | 5304 | wpa_s->pending_pd_use = join ? AUTO_PD_JOIN : AUTO_PD_GO_NEG; | 
|  | 5305 | wpa_printf(MSG_DEBUG, "P2P: Auto PD with " MACSTR " join=%d", | 
|  | 5306 | MAC2STR(wpa_s->pending_join_dev_addr), join); | 
|  | 5307 | if (p2p_prov_disc_req(wpa_s->global->p2p, | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5308 | wpa_s->pending_join_dev_addr, NULL, | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5309 | wpa_s->pending_pd_config_methods, join, | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5310 | 0, wpa_s->user_initiated_pd) < 0) { | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5311 | wpa_s->p2p_auto_pd = 0; | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5312 | wpa_msg_global(wpa_s, MSG_INFO, | 
|  | 5313 | P2P_EVENT_PROV_DISC_FAILURE | 
|  | 5314 | " p2p_dev_addr=" MACSTR " status=N/A", | 
|  | 5315 | MAC2STR(wpa_s->pending_join_dev_addr)); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5316 | } | 
|  | 5317 | return; | 
|  | 5318 | } | 
|  | 5319 |  | 
|  | 5320 | if (wpa_s->p2p_auto_join) { | 
|  | 5321 | int join = wpas_p2p_peer_go(wpa_s, | 
|  | 5322 | wpa_s->pending_join_dev_addr); | 
|  | 5323 | if (join < 0) { | 
|  | 5324 | wpa_printf(MSG_DEBUG, "P2P: Peer was not found to be " | 
|  | 5325 | "running a GO -> use GO Negotiation"); | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5326 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5327 | P2P_EVENT_FALLBACK_TO_GO_NEG | 
|  | 5328 | "reason=peer-not-running-GO"); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5329 | wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr, | 
|  | 5330 | wpa_s->p2p_pin, wpa_s->p2p_wps_method, | 
|  | 5331 | wpa_s->p2p_persistent_group, 0, 0, 0, | 
|  | 5332 | wpa_s->p2p_go_intent, | 
|  | 5333 | wpa_s->p2p_connect_freq, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5334 | wpa_s->p2p_go_vht_center_freq2, | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5335 | wpa_s->p2p_persistent_id, | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5336 | wpa_s->p2p_pd_before_go_neg, | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5337 | wpa_s->p2p_go_ht40, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5338 | wpa_s->p2p_go_vht, | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5339 | wpa_s->p2p_go_max_oper_chwidth, | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5340 | wpa_s->p2p_go_he, | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 5341 | wpa_s->p2p_go_edmg, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5342 | NULL, 0, | 
|  | 5343 | is_p2p_allow_6ghz(wpa_s->global->p2p)); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5344 | return; | 
|  | 5345 | } | 
|  | 5346 |  | 
|  | 5347 | wpa_printf(MSG_DEBUG, "P2P: Peer was found running GO%s -> " | 
|  | 5348 | "try to join the group", join ? "" : | 
|  | 5349 | " in older scan"); | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5350 | if (!join) { | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5351 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5352 | P2P_EVENT_FALLBACK_TO_GO_NEG_ENABLED); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5353 | wpa_s->p2p_fallback_to_go_neg = 1; | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5354 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5355 | } | 
|  | 5356 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5357 | freq = p2p_get_oper_freq(wpa_s->global->p2p, | 
|  | 5358 | wpa_s->pending_join_iface_addr); | 
|  | 5359 | if (freq < 0 && | 
|  | 5360 | p2p_get_interface_addr(wpa_s->global->p2p, | 
|  | 5361 | wpa_s->pending_join_dev_addr, | 
|  | 5362 | iface_addr) == 0 && | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5363 | os_memcmp(iface_addr, wpa_s->pending_join_dev_addr, ETH_ALEN) != 0 | 
|  | 5364 | && !wpa_bss_get_bssid(wpa_s, wpa_s->pending_join_iface_addr)) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5365 | wpa_printf(MSG_DEBUG, "P2P: Overwrite pending interface " | 
|  | 5366 | "address for join from " MACSTR " to " MACSTR | 
|  | 5367 | " based on newly discovered P2P peer entry", | 
|  | 5368 | MAC2STR(wpa_s->pending_join_iface_addr), | 
|  | 5369 | MAC2STR(iface_addr)); | 
|  | 5370 | os_memcpy(wpa_s->pending_join_iface_addr, iface_addr, | 
|  | 5371 | ETH_ALEN); | 
|  | 5372 |  | 
|  | 5373 | freq = p2p_get_oper_freq(wpa_s->global->p2p, | 
|  | 5374 | wpa_s->pending_join_iface_addr); | 
|  | 5375 | } | 
|  | 5376 | if (freq >= 0) { | 
|  | 5377 | wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency " | 
|  | 5378 | "from P2P peer table: %d MHz", freq); | 
|  | 5379 | } | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5380 | if (wpa_s->p2p_join_ssid_len) { | 
|  | 5381 | wpa_printf(MSG_DEBUG, "P2P: Trying to find target GO BSS entry based on BSSID " | 
|  | 5382 | MACSTR " and SSID %s", | 
|  | 5383 | MAC2STR(wpa_s->pending_join_iface_addr), | 
|  | 5384 | wpa_ssid_txt(wpa_s->p2p_join_ssid, | 
|  | 5385 | wpa_s->p2p_join_ssid_len)); | 
|  | 5386 | bss = wpa_bss_get(wpa_s, wpa_s->pending_join_iface_addr, | 
|  | 5387 | wpa_s->p2p_join_ssid, | 
|  | 5388 | wpa_s->p2p_join_ssid_len); | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5389 | } else if (!bss) { | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5390 | wpa_printf(MSG_DEBUG, "P2P: Trying to find target GO BSS entry based on BSSID " | 
|  | 5391 | MACSTR, MAC2STR(wpa_s->pending_join_iface_addr)); | 
|  | 5392 | bss = wpa_bss_get_bssid_latest(wpa_s, | 
|  | 5393 | wpa_s->pending_join_iface_addr); | 
|  | 5394 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5395 | if (bss) { | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5396 | u8 dev_addr[ETH_ALEN]; | 
|  | 5397 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5398 | freq = bss->freq; | 
|  | 5399 | wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency " | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 5400 | "from BSS table: %d MHz (SSID %s)", freq, | 
|  | 5401 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5402 | 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] | 5403 | dev_addr) == 0 && | 
|  | 5404 | os_memcmp(wpa_s->pending_join_dev_addr, | 
|  | 5405 | wpa_s->pending_join_iface_addr, ETH_ALEN) == 0 && | 
|  | 5406 | os_memcmp(dev_addr, wpa_s->pending_join_dev_addr, | 
|  | 5407 | ETH_ALEN) != 0) { | 
|  | 5408 | wpa_printf(MSG_DEBUG, | 
|  | 5409 | "P2P: Update target GO device address based on BSS entry: " MACSTR " (was " MACSTR ")", | 
|  | 5410 | MAC2STR(dev_addr), | 
|  | 5411 | MAC2STR(wpa_s->pending_join_dev_addr)); | 
|  | 5412 | os_memcpy(wpa_s->pending_join_dev_addr, dev_addr, | 
|  | 5413 | ETH_ALEN); | 
|  | 5414 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5415 | } | 
|  | 5416 | if (freq > 0) { | 
|  | 5417 | u16 method; | 
|  | 5418 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5419 | if (wpas_check_freq_conflict(wpa_s, freq) > 0) { | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5420 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 5421 | P2P_EVENT_GROUP_FORMATION_FAILURE | 
|  | 5422 | "reason=FREQ_CONFLICT"); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5423 | wpas_notify_p2p_group_formation_failure( | 
|  | 5424 | wpa_s, "FREQ_CONFLICT"); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5425 | return; | 
|  | 5426 | } | 
|  | 5427 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5428 | wpa_printf(MSG_DEBUG, "P2P: Send Provision Discovery Request " | 
|  | 5429 | "prior to joining an existing group (GO " MACSTR | 
|  | 5430 | " freq=%u MHz)", | 
|  | 5431 | MAC2STR(wpa_s->pending_join_dev_addr), freq); | 
|  | 5432 | wpa_s->pending_pd_before_join = 1; | 
|  | 5433 |  | 
|  | 5434 | switch (wpa_s->pending_join_wps_method) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5435 | case WPS_PIN_DISPLAY: | 
|  | 5436 | method = WPS_CONFIG_KEYPAD; | 
|  | 5437 | break; | 
|  | 5438 | case WPS_PIN_KEYPAD: | 
|  | 5439 | method = WPS_CONFIG_DISPLAY; | 
|  | 5440 | break; | 
|  | 5441 | case WPS_PBC: | 
|  | 5442 | method = WPS_CONFIG_PUSHBUTTON; | 
|  | 5443 | break; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5444 | case WPS_P2PS: | 
|  | 5445 | method = WPS_CONFIG_P2PS; | 
|  | 5446 | break; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5447 | default: | 
|  | 5448 | method = 0; | 
|  | 5449 | break; | 
|  | 5450 | } | 
|  | 5451 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5452 | if ((p2p_get_provisioning_info(wpa_s->global->p2p, | 
|  | 5453 | wpa_s->pending_join_dev_addr) == | 
|  | 5454 | method)) { | 
|  | 5455 | /* | 
|  | 5456 | * We have already performed provision discovery for | 
|  | 5457 | * joining the group. Proceed directly to join | 
|  | 5458 | * operation without duplicated provision discovery. */ | 
|  | 5459 | wpa_printf(MSG_DEBUG, "P2P: Provision discovery " | 
|  | 5460 | "with " MACSTR " already done - proceed to " | 
|  | 5461 | "join", | 
|  | 5462 | MAC2STR(wpa_s->pending_join_dev_addr)); | 
|  | 5463 | wpa_s->pending_pd_before_join = 0; | 
|  | 5464 | goto start; | 
|  | 5465 | } | 
|  | 5466 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5467 | if (p2p_prov_disc_req(wpa_s->global->p2p, | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5468 | wpa_s->pending_join_dev_addr, | 
|  | 5469 | NULL, method, 1, | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5470 | freq, wpa_s->user_initiated_pd) < 0) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5471 | wpa_printf(MSG_DEBUG, "P2P: Failed to send Provision " | 
|  | 5472 | "Discovery Request before joining an " | 
|  | 5473 | "existing group"); | 
|  | 5474 | wpa_s->pending_pd_before_join = 0; | 
|  | 5475 | goto start; | 
|  | 5476 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5477 | return; | 
|  | 5478 | } | 
|  | 5479 |  | 
|  | 5480 | wpa_printf(MSG_DEBUG, "P2P: Failed to find BSS/GO - try again later"); | 
|  | 5481 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); | 
|  | 5482 | eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL); | 
|  | 5483 | wpas_p2p_check_join_scan_limit(wpa_s); | 
|  | 5484 | return; | 
|  | 5485 |  | 
|  | 5486 | start: | 
|  | 5487 | /* Start join operation immediately */ | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5488 | wpas_p2p_join_start(wpa_s, 0, wpa_s->p2p_join_ssid, | 
|  | 5489 | wpa_s->p2p_join_ssid_len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5490 | } | 
|  | 5491 |  | 
|  | 5492 |  | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5493 | static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq, | 
|  | 5494 | const u8 *ssid, size_t ssid_len) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5495 | { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5496 | int ret; | 
|  | 5497 | struct wpa_driver_scan_params params; | 
|  | 5498 | struct wpabuf *wps_ie, *ies; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5499 | size_t ielen; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5500 | int freqs[2] = { 0, 0 }; | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5501 | unsigned int bands; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5502 |  | 
|  | 5503 | os_memset(¶ms, 0, sizeof(params)); | 
|  | 5504 |  | 
|  | 5505 | /* P2P Wildcard SSID */ | 
|  | 5506 | params.num_ssids = 1; | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5507 | if (ssid && ssid_len) { | 
|  | 5508 | params.ssids[0].ssid = ssid; | 
|  | 5509 | params.ssids[0].ssid_len = ssid_len; | 
|  | 5510 | os_memcpy(wpa_s->p2p_join_ssid, ssid, ssid_len); | 
|  | 5511 | wpa_s->p2p_join_ssid_len = ssid_len; | 
|  | 5512 | } else { | 
|  | 5513 | params.ssids[0].ssid = (u8 *) P2P_WILDCARD_SSID; | 
|  | 5514 | params.ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN; | 
|  | 5515 | wpa_s->p2p_join_ssid_len = 0; | 
|  | 5516 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5517 |  | 
|  | 5518 | wpa_s->wps->dev.p2p = 1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5519 | wps_ie = wps_build_probe_req_ie(DEV_PW_DEFAULT, &wpa_s->wps->dev, | 
|  | 5520 | wpa_s->wps->uuid, WPS_REQ_ENROLLEE, 0, | 
|  | 5521 | NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5522 | if (wps_ie == NULL) { | 
|  | 5523 | wpas_p2p_scan_res_join(wpa_s, NULL); | 
|  | 5524 | return; | 
|  | 5525 | } | 
|  | 5526 |  | 
| Dmitry Shmidt | 9e3f8ee | 2014-01-17 10:52:01 -0800 | [diff] [blame] | 5527 | if (!freq) { | 
|  | 5528 | int oper_freq; | 
|  | 5529 | /* | 
|  | 5530 | * If freq is not provided, check the operating freq of the GO | 
|  | 5531 | * and use a single channel scan on if possible. | 
|  | 5532 | */ | 
|  | 5533 | oper_freq = p2p_get_oper_freq(wpa_s->global->p2p, | 
|  | 5534 | wpa_s->pending_join_iface_addr); | 
|  | 5535 | if (oper_freq > 0) | 
|  | 5536 | freq = oper_freq; | 
|  | 5537 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5538 | if (freq > 0) { | 
|  | 5539 | freqs[0] = freq; | 
|  | 5540 | params.freqs = freqs; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5541 | } else if (wpa_s->conf->p2p_6ghz_disable || | 
|  | 5542 | !is_p2p_allow_6ghz(wpa_s->global->p2p)) { | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5543 | wpa_printf(MSG_DEBUG, | 
|  | 5544 | "P2P: 6 GHz disabled - update the scan frequency list"); | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5545 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211G, ¶ms, | 
|  | 5546 | 0); | 
|  | 5547 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, ¶ms, | 
|  | 5548 | 0); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5549 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5550 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5551 | ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p); | 
|  | 5552 | ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen); | 
|  | 5553 | if (ies == NULL) { | 
|  | 5554 | wpabuf_free(wps_ie); | 
|  | 5555 | wpas_p2p_scan_res_join(wpa_s, NULL); | 
|  | 5556 | return; | 
|  | 5557 | } | 
|  | 5558 | wpabuf_put_buf(ies, wps_ie); | 
|  | 5559 | wpabuf_free(wps_ie); | 
|  | 5560 |  | 
|  | 5561 | bands = wpas_get_bands(wpa_s, freqs); | 
|  | 5562 | p2p_scan_ie(wpa_s->global->p2p, ies, NULL, bands); | 
|  | 5563 |  | 
|  | 5564 | params.p2p_probe = 1; | 
|  | 5565 | params.extra_ies = wpabuf_head(ies); | 
|  | 5566 | params.extra_ies_len = wpabuf_len(ies); | 
|  | 5567 |  | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 5568 | if (wpa_s->clear_driver_scan_cache) { | 
|  | 5569 | wpa_printf(MSG_DEBUG, | 
|  | 5570 | "Request driver to clear scan cache due to local BSS flush"); | 
|  | 5571 | params.only_new_results = 1; | 
|  | 5572 | } | 
|  | 5573 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5574 | /* | 
|  | 5575 | * Run a scan to update BSS table and start Provision Discovery once | 
|  | 5576 | * the new scan results become available. | 
|  | 5577 | */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5578 | ret = wpa_drv_scan(wpa_s, ¶ms); | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5579 | if (params.freqs != freqs) | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5580 | os_free(params.freqs); | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5581 | if (!ret) { | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5582 | os_get_reltime(&wpa_s->scan_trigger_time); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5583 | wpa_s->scan_res_handler = wpas_p2p_scan_res_join; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5584 | wpa_s->own_scan_requested = 1; | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 5585 | wpa_s->clear_driver_scan_cache = 0; | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5586 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5587 |  | 
|  | 5588 | wpabuf_free(ies); | 
|  | 5589 |  | 
|  | 5590 | if (ret) { | 
|  | 5591 | wpa_printf(MSG_DEBUG, "P2P: Failed to start scan for join - " | 
|  | 5592 | "try again later"); | 
|  | 5593 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); | 
|  | 5594 | eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL); | 
|  | 5595 | wpas_p2p_check_join_scan_limit(wpa_s); | 
|  | 5596 | } | 
|  | 5597 | } | 
|  | 5598 |  | 
|  | 5599 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5600 | static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx) | 
|  | 5601 | { | 
|  | 5602 | struct wpa_supplicant *wpa_s = eloop_ctx; | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5603 | wpas_p2p_join_scan_req(wpa_s, 0, NULL, 0); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5604 | } | 
|  | 5605 |  | 
|  | 5606 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5607 | 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] | 5608 | const u8 *dev_addr, enum p2p_wps_method wps_method, | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5609 | int auto_join, int op_freq, | 
|  | 5610 | const u8 *ssid, size_t ssid_len) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5611 | { | 
|  | 5612 | wpa_printf(MSG_DEBUG, "P2P: Request to join existing group (iface " | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5613 | MACSTR " dev " MACSTR " op_freq=%d)%s", | 
|  | 5614 | MAC2STR(iface_addr), MAC2STR(dev_addr), op_freq, | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5615 | auto_join ? " (auto_join)" : ""); | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5616 | if (ssid && ssid_len) { | 
|  | 5617 | wpa_printf(MSG_DEBUG, "P2P: Group SSID specified: %s", | 
|  | 5618 | wpa_ssid_txt(ssid, ssid_len)); | 
|  | 5619 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5620 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5621 | wpa_s->p2p_auto_pd = 0; | 
|  | 5622 | wpa_s->p2p_auto_join = !!auto_join; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5623 | os_memcpy(wpa_s->pending_join_iface_addr, iface_addr, ETH_ALEN); | 
|  | 5624 | os_memcpy(wpa_s->pending_join_dev_addr, dev_addr, ETH_ALEN); | 
|  | 5625 | wpa_s->pending_join_wps_method = wps_method; | 
|  | 5626 |  | 
|  | 5627 | /* Make sure we are not running find during connection establishment */ | 
|  | 5628 | wpas_p2p_stop_find(wpa_s); | 
|  | 5629 |  | 
|  | 5630 | wpa_s->p2p_join_scan_count = 0; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5631 | wpas_p2p_join_scan_req(wpa_s, op_freq, ssid, ssid_len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5632 | return 0; | 
|  | 5633 | } | 
|  | 5634 |  | 
|  | 5635 |  | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5636 | static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s, int freq, | 
|  | 5637 | const u8 *ssid, size_t ssid_len) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5638 | { | 
|  | 5639 | struct wpa_supplicant *group; | 
|  | 5640 | struct p2p_go_neg_results res; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5641 | struct wpa_bss *bss; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5642 |  | 
|  | 5643 | group = wpas_p2p_get_group_iface(wpa_s, 0, 0); | 
|  | 5644 | if (group == NULL) | 
|  | 5645 | return -1; | 
|  | 5646 | if (group != wpa_s) { | 
|  | 5647 | os_memcpy(group->p2p_pin, wpa_s->p2p_pin, | 
|  | 5648 | sizeof(group->p2p_pin)); | 
|  | 5649 | group->p2p_wps_method = wpa_s->p2p_wps_method; | 
|  | 5650 | } | 
|  | 5651 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5652 | /* | 
|  | 5653 | * Need to mark the current interface for p2p_group_formation | 
|  | 5654 | * when a separate group interface is not used. This is needed | 
|  | 5655 | * to allow p2p_cancel stop a pending p2p_connect-join. | 
|  | 5656 | * wpas_p2p_init_group_interface() addresses this for the case | 
|  | 5657 | * where a separate group interface is used. | 
|  | 5658 | */ | 
|  | 5659 | if (group == wpa_s->parent) | 
|  | 5660 | wpa_s->global->p2p_group_formation = group; | 
|  | 5661 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5662 | group->p2p_in_provisioning = 1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5663 | 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] | 5664 |  | 
|  | 5665 | os_memset(&res, 0, sizeof(res)); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5666 | 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] | 5667 | os_memcpy(res.peer_interface_addr, wpa_s->pending_join_iface_addr, | 
|  | 5668 | ETH_ALEN); | 
|  | 5669 | res.wps_method = wpa_s->pending_join_wps_method; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5670 | if (freq && ssid && ssid_len) { | 
|  | 5671 | res.freq = freq; | 
|  | 5672 | res.ssid_len = ssid_len; | 
|  | 5673 | os_memcpy(res.ssid, ssid, ssid_len); | 
|  | 5674 | } else { | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5675 | if (ssid && ssid_len) { | 
|  | 5676 | bss = wpa_bss_get(wpa_s, wpa_s->pending_join_iface_addr, | 
|  | 5677 | ssid, ssid_len); | 
|  | 5678 | } else { | 
|  | 5679 | bss = wpa_bss_get_bssid_latest( | 
|  | 5680 | wpa_s, wpa_s->pending_join_iface_addr); | 
|  | 5681 | } | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5682 | if (bss) { | 
|  | 5683 | res.freq = bss->freq; | 
|  | 5684 | res.ssid_len = bss->ssid_len; | 
|  | 5685 | os_memcpy(res.ssid, bss->ssid, bss->ssid_len); | 
|  | 5686 | wpa_printf(MSG_DEBUG, "P2P: Join target GO operating frequency from BSS table: %d MHz (SSID %s)", | 
|  | 5687 | bss->freq, | 
|  | 5688 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5689 | } else if (ssid && ssid_len) { | 
|  | 5690 | res.ssid_len = ssid_len; | 
|  | 5691 | os_memcpy(res.ssid, ssid, ssid_len); | 
|  | 5692 | wpa_printf(MSG_DEBUG, "P2P: Join target GO (SSID %s)", | 
|  | 5693 | wpa_ssid_txt(ssid, ssid_len)); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5694 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5695 | } | 
|  | 5696 |  | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5697 | if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) { | 
|  | 5698 | wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel prior to " | 
|  | 5699 | "starting client"); | 
|  | 5700 | wpa_drv_cancel_remain_on_channel(wpa_s); | 
|  | 5701 | wpa_s->off_channel_freq = 0; | 
|  | 5702 | wpa_s->roc_waiting_drv_freq = 0; | 
|  | 5703 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5704 | wpas_start_wps_enrollee(group, &res); | 
|  | 5705 |  | 
|  | 5706 | /* | 
|  | 5707 | * Allow a longer timeout for join-a-running-group than normal 15 | 
|  | 5708 | * second group formation timeout since the GO may not have authorized | 
|  | 5709 | * our connection yet. | 
|  | 5710 | */ | 
|  | 5711 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL); | 
|  | 5712 | eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout, | 
|  | 5713 | wpa_s, NULL); | 
|  | 5714 |  | 
|  | 5715 | return 0; | 
|  | 5716 | } | 
|  | 5717 |  | 
|  | 5718 |  | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5719 | 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] | 5720 | int *force_freq, int *pref_freq, int go, | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5721 | struct weighted_pcl *pref_freq_list, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5722 | unsigned int *num_pref_freq) | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5723 | { | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5724 | struct wpa_used_freq_data *freqs; | 
|  | 5725 | int res, best_freq, num_unused; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5726 | unsigned int freq_in_use = 0, num, i, max_pref_freq; | 
| Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5727 | int p2p_pref_freq; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5728 |  | 
|  | 5729 | max_pref_freq = *num_pref_freq; | 
|  | 5730 | *num_pref_freq = 0; | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5731 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5732 | freqs = os_calloc(wpa_s->num_multichan_concurrent, | 
|  | 5733 | sizeof(struct wpa_used_freq_data)); | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5734 | if (!freqs) | 
|  | 5735 | return -1; | 
|  | 5736 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5737 | num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, | 
|  | 5738 | wpa_s->num_multichan_concurrent); | 
|  | 5739 |  | 
|  | 5740 | /* | 
|  | 5741 | * It is possible that the total number of used frequencies is bigger | 
|  | 5742 | * than the number of frequencies used for P2P, so get the system wide | 
|  | 5743 | * number of unused frequencies. | 
|  | 5744 | */ | 
|  | 5745 | num_unused = wpas_p2p_num_unused_channels(wpa_s); | 
|  | 5746 |  | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5747 | wpa_printf(MSG_DEBUG, | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5748 | "P2P: Setup freqs: freq=%d num_MCC=%d shared_freqs=%u num_unused=%d", | 
|  | 5749 | freq, wpa_s->num_multichan_concurrent, num, num_unused); | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5750 |  | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5751 | if (freq > 0) { | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5752 | int ret; | 
|  | 5753 | if (go) | 
|  | 5754 | ret = p2p_supported_freq(wpa_s->global->p2p, freq); | 
|  | 5755 | else | 
|  | 5756 | ret = p2p_supported_freq_cli(wpa_s->global->p2p, freq); | 
|  | 5757 | if (!ret) { | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5758 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5759 | ieee80211_is_dfs(freq, wpa_s->hw.modes, | 
|  | 5760 | wpa_s->hw.num_modes)) { | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5761 | /* | 
|  | 5762 | * If freq is a DFS channel and DFS is offloaded | 
|  | 5763 | * to the driver, allow P2P GO to use it. | 
|  | 5764 | */ | 
|  | 5765 | wpa_printf(MSG_DEBUG, | 
|  | 5766 | "P2P: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded to the driver", | 
|  | 5767 | freq); | 
|  | 5768 | } else { | 
|  | 5769 | wpa_printf(MSG_DEBUG, | 
|  | 5770 | "P2P: The forced channel (%u MHz) is not supported for P2P uses", | 
|  | 5771 | freq); | 
|  | 5772 | res = -3; | 
|  | 5773 | goto exit_free; | 
|  | 5774 | } | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5775 | } | 
|  | 5776 |  | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5777 | for (i = 0; i < num; i++) { | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5778 | if (freqs[i].freq == freq) | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5779 | freq_in_use = 1; | 
|  | 5780 | } | 
|  | 5781 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5782 | if (num_unused <= 0 && !freq_in_use) { | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5783 | wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group on %u MHz as there are no available channels", | 
|  | 5784 | freq); | 
|  | 5785 | res = -2; | 
|  | 5786 | goto exit_free; | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5787 | } | 
|  | 5788 | wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the " | 
|  | 5789 | "requested channel (%u MHz)", freq); | 
|  | 5790 | *force_freq = freq; | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5791 | goto exit_ok; | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5792 | } | 
|  | 5793 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5794 | best_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num); | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5795 |  | 
| Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5796 | if (*pref_freq == 0) { | 
|  | 5797 | if (wpa_s->conf->num_p2p_pref_chan && IS_2GHZ(best_freq)) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5798 | i = 0; | 
| Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5799 | while (i < wpa_s->conf->num_p2p_pref_chan) { | 
|  | 5800 | p2p_pref_freq = ieee80211_chan_to_freq(NULL, | 
|  | 5801 | wpa_s->conf->p2p_pref_chan[i].op_class, | 
|  | 5802 | wpa_s->conf->p2p_pref_chan[i].chan); | 
|  | 5803 |  | 
|  | 5804 | if (p2p_supported_freq(wpa_s->global->p2p, p2p_pref_freq) && | 
|  | 5805 | !wpas_p2p_disallowed_freq(wpa_s->global, p2p_pref_freq)) { | 
|  | 5806 | best_freq = p2p_pref_freq; | 
|  | 5807 | wpa_printf(MSG_DEBUG, "P2P: Using frequency (%u MHz) " | 
|  | 5808 | "from P2P preferred channel list", best_freq); | 
|  | 5809 | break; | 
|  | 5810 | } else { | 
|  | 5811 | wpa_printf(MSG_MSGDUMP, "P2P: Skipping preferred " | 
|  | 5812 | "frequency (%u MHz) ", p2p_pref_freq); | 
|  | 5813 | } | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5814 | i++; | 
|  | 5815 | } | 
| Sreeramya Soratkal | f928e8f | 2022-03-22 17:33:31 +0530 | [diff] [blame] | 5816 | } else if (!wpa_s->conf->num_p2p_pref_chan) { | 
| Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5817 | enum wpa_driver_if_type iface_type; | 
|  | 5818 |  | 
|  | 5819 | if (go) | 
|  | 5820 | iface_type = WPA_IF_P2P_GO; | 
|  | 5821 | else | 
|  | 5822 | iface_type = WPA_IF_P2P_CLIENT; | 
|  | 5823 |  | 
|  | 5824 | wpa_printf(MSG_DEBUG, "P2P: best_freq=%d, go=%d", | 
|  | 5825 | best_freq, go); | 
|  | 5826 |  | 
|  | 5827 | res = wpa_drv_get_pref_freq_list(wpa_s, iface_type, | 
|  | 5828 | &max_pref_freq, | 
|  | 5829 | pref_freq_list); | 
|  | 5830 | if (!res && max_pref_freq > 0) { | 
|  | 5831 | *num_pref_freq = max_pref_freq; | 
|  | 5832 | i = 0; | 
|  | 5833 | while (i < *num_pref_freq && | 
|  | 5834 | (!p2p_supported_freq(wpa_s->global->p2p, | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5835 | pref_freq_list[i].freq) || | 
|  | 5836 | wpas_p2p_disallowed_freq( | 
|  | 5837 | wpa_s->global, | 
|  | 5838 | pref_freq_list[i].freq) || | 
|  | 5839 | !p2p_pref_freq_allowed(&pref_freq_list[i], | 
|  | 5840 | go))) { | 
| Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5841 | wpa_printf(MSG_DEBUG, | 
|  | 5842 | "P2P: preferred_freq_list[%d]=%d is disallowed", | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5843 | i, pref_freq_list[i].freq); | 
| Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5844 | i++; | 
|  | 5845 | } | 
|  | 5846 | if (i != *num_pref_freq) { | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5847 | best_freq = pref_freq_list[i].freq; | 
| Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5848 | wpa_printf(MSG_DEBUG, | 
|  | 5849 | "P2P: Using preferred_freq_list[%d]=%d", | 
|  | 5850 | i, best_freq); | 
|  | 5851 | } else { | 
|  | 5852 | wpa_printf(MSG_DEBUG, | 
|  | 5853 | "P2P: All driver preferred frequencies are " | 
|  | 5854 | "disallowed for P2P use"); | 
|  | 5855 | *num_pref_freq = 0; | 
|  | 5856 | } | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5857 | } else { | 
|  | 5858 | wpa_printf(MSG_DEBUG, | 
| Vinayak Yadawad | 8db3457 | 2021-08-30 21:28:05 +0530 | [diff] [blame] | 5859 | "P2P: No preferred frequency list available"); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5860 | } | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5861 | } | 
|  | 5862 | } | 
|  | 5863 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5864 | /* We have a candidate frequency to use */ | 
|  | 5865 | if (best_freq > 0) { | 
|  | 5866 | if (*pref_freq == 0 && num_unused > 0) { | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5867 | 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] | 5868 | best_freq); | 
|  | 5869 | *pref_freq = best_freq; | 
| Dmitry Shmidt | 51a47d5 | 2013-09-10 10:52:57 -0700 | [diff] [blame] | 5870 | } else { | 
|  | 5871 | 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] | 5872 | best_freq); | 
|  | 5873 | *force_freq = best_freq; | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5874 | } | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5875 | } else if (num_unused > 0) { | 
|  | 5876 | wpa_printf(MSG_DEBUG, | 
|  | 5877 | "P2P: Current operating channels are not available for P2P. Try to use another channel"); | 
|  | 5878 | *force_freq = 0; | 
|  | 5879 | } else { | 
|  | 5880 | wpa_printf(MSG_DEBUG, | 
|  | 5881 | "P2P: All channels are in use and none of them are P2P enabled. Cannot start P2P group"); | 
|  | 5882 | res = -2; | 
|  | 5883 | goto exit_free; | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5884 | } | 
|  | 5885 |  | 
|  | 5886 | exit_ok: | 
|  | 5887 | res = 0; | 
|  | 5888 | exit_free: | 
|  | 5889 | os_free(freqs); | 
|  | 5890 | return res; | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5891 | } | 
|  | 5892 |  | 
|  | 5893 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5894 | static bool is_p2p_6ghz_supported(struct wpa_supplicant *wpa_s, | 
|  | 5895 | const u8 *peer_addr) | 
|  | 5896 | { | 
|  | 5897 | if (wpa_s->conf->p2p_6ghz_disable || | 
|  | 5898 | !get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, | 
|  | 5899 | HOSTAPD_MODE_IEEE80211A, true)) | 
|  | 5900 | return false; | 
|  | 5901 |  | 
|  | 5902 | if (!p2p_wfd_enabled(wpa_s->global->p2p)) | 
|  | 5903 | return false; | 
|  | 5904 | if (peer_addr && !p2p_peer_wfd_enabled(wpa_s->global->p2p, peer_addr)) | 
|  | 5905 | return false; | 
|  | 5906 |  | 
|  | 5907 | return true; | 
|  | 5908 | } | 
|  | 5909 |  | 
|  | 5910 |  | 
|  | 5911 | static int wpas_p2p_check_6ghz(struct wpa_supplicant *wpa_s, | 
|  | 5912 | const u8 *peer_addr, bool allow_6ghz, int freq) | 
|  | 5913 | { | 
|  | 5914 | if (allow_6ghz && is_p2p_6ghz_supported(wpa_s, peer_addr)) { | 
|  | 5915 | wpa_printf(MSG_DEBUG, | 
|  | 5916 | "P2P: Allow connection on 6 GHz channels"); | 
|  | 5917 | p2p_set_6ghz_dev_capab(wpa_s->global->p2p, true); | 
|  | 5918 | } else { | 
|  | 5919 | if (is_6ghz_freq(freq)) | 
|  | 5920 | return -2; | 
|  | 5921 | p2p_set_6ghz_dev_capab(wpa_s->global->p2p, false); | 
|  | 5922 | } | 
|  | 5923 |  | 
|  | 5924 | return 0; | 
|  | 5925 | } | 
|  | 5926 |  | 
|  | 5927 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5928 | /** | 
|  | 5929 | * wpas_p2p_connect - Request P2P Group Formation to be started | 
|  | 5930 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() | 
|  | 5931 | * @peer_addr: Address of the peer P2P Device | 
|  | 5932 | * @pin: PIN to use during provisioning or %NULL to indicate PBC mode | 
|  | 5933 | * @persistent_group: Whether to create a persistent group | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5934 | * @auto_join: Whether to select join vs. GO Negotiation automatically | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5935 | * @join: Whether to join an existing group (as a client) instead of starting | 
|  | 5936 | *	Group Owner negotiation; @peer_addr is BSSID in that case | 
|  | 5937 | * @auth: Whether to only authorize the connection instead of doing that and | 
|  | 5938 | *	initiating Group Owner negotiation | 
|  | 5939 | * @go_intent: GO Intent or -1 to use default | 
|  | 5940 | * @freq: Frequency for the group or 0 for auto-selection | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5941 | * @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] | 5942 | * @persistent_id: Persistent group credentials to use for forcing GO | 
|  | 5943 | *	parameters or -1 to generate new values (SSID/passphrase) | 
|  | 5944 | * @pd: Whether to send Provision Discovery prior to GO Negotiation as an | 
|  | 5945 | *	interoperability workaround when initiating group formation | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5946 | * @ht40: Start GO with 40 MHz channel width | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5947 | * @vht:  Start GO with VHT support | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5948 | * @vht_chwidth: Channel width supported by GO operating with VHT support | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5949 | *	(CHANWIDTH_*). | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5950 | * @group_ssid: Specific Group SSID for join or %NULL if not set | 
|  | 5951 | * @group_ssid_len: Length of @group_ssid in octets | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5952 | * @allow_6ghz: Allow P2P connection on 6 GHz channels | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5953 | * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified | 
|  | 5954 | *	failure, -2 on failure due to channel not currently available, | 
|  | 5955 | *	-3 if forced channel is not supported | 
|  | 5956 | */ | 
|  | 5957 | int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr, | 
|  | 5958 | const char *pin, enum p2p_wps_method wps_method, | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5959 | int persistent_group, int auto_join, int join, int auth, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5960 | int go_intent, int freq, unsigned int vht_center_freq2, | 
|  | 5961 | int persistent_id, int pd, int ht40, int vht, | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 5962 | unsigned int vht_chwidth, int he, int edmg, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5963 | const u8 *group_ssid, size_t group_ssid_len, | 
|  | 5964 | bool allow_6ghz) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5965 | { | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5966 | int force_freq = 0, pref_freq = 0; | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 5967 | int ret = 0, res; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5968 | enum wpa_driver_if_type iftype; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5969 | const u8 *if_addr; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5970 | struct wpa_ssid *ssid = NULL; | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5971 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; | 
|  | 5972 | unsigned int size; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5973 |  | 
|  | 5974 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 5975 | return -1; | 
|  | 5976 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5977 | if (persistent_id >= 0) { | 
|  | 5978 | ssid = wpa_config_get_network(wpa_s->conf, persistent_id); | 
|  | 5979 | if (ssid == NULL || ssid->disabled != 2 || | 
|  | 5980 | ssid->mode != WPAS_MODE_P2P_GO) | 
|  | 5981 | return -1; | 
|  | 5982 | } | 
|  | 5983 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5984 | if (wpas_p2p_check_6ghz(wpa_s, peer_addr, allow_6ghz, freq)) | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5985 | return -2; | 
|  | 5986 |  | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 5987 | os_free(wpa_s->global->add_psk); | 
|  | 5988 | wpa_s->global->add_psk = NULL; | 
|  | 5989 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5990 | wpa_s->global->p2p_fail_on_wps_complete = 0; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 5991 | wpa_s->global->pending_p2ps_group = 0; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5992 | wpa_s->global->pending_p2ps_group_freq = 0; | 
|  | 5993 | wpa_s->p2ps_method_config_any = 0; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5994 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5995 | if (go_intent < 0) | 
|  | 5996 | go_intent = wpa_s->conf->p2p_go_intent; | 
|  | 5997 |  | 
|  | 5998 | if (!auth) | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5999 | wpa_s->global->p2p_long_listen = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6000 |  | 
|  | 6001 | wpa_s->p2p_wps_method = wps_method; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6002 | wpa_s->p2p_persistent_group = !!persistent_group; | 
|  | 6003 | wpa_s->p2p_persistent_id = persistent_id; | 
|  | 6004 | wpa_s->p2p_go_intent = go_intent; | 
|  | 6005 | wpa_s->p2p_connect_freq = freq; | 
|  | 6006 | wpa_s->p2p_fallback_to_go_neg = 0; | 
|  | 6007 | wpa_s->p2p_pd_before_go_neg = !!pd; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6008 | wpa_s->p2p_go_ht40 = !!ht40; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6009 | wpa_s->p2p_go_vht = !!vht; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6010 | wpa_s->p2p_go_vht_center_freq2 = vht_center_freq2; | 
|  | 6011 | wpa_s->p2p_go_max_oper_chwidth = vht_chwidth; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6012 | wpa_s->p2p_go_he = !!he; | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6013 | wpa_s->p2p_go_edmg = !!edmg; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6014 |  | 
|  | 6015 | if (pin) | 
|  | 6016 | os_strlcpy(wpa_s->p2p_pin, pin, sizeof(wpa_s->p2p_pin)); | 
|  | 6017 | else if (wps_method == WPS_PIN_DISPLAY) { | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6018 | if (wps_generate_pin((unsigned int *) &ret) < 0) | 
|  | 6019 | return -1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6020 | res = os_snprintf(wpa_s->p2p_pin, sizeof(wpa_s->p2p_pin), | 
|  | 6021 | "%08d", ret); | 
|  | 6022 | if (os_snprintf_error(sizeof(wpa_s->p2p_pin), res)) | 
|  | 6023 | wpa_s->p2p_pin[sizeof(wpa_s->p2p_pin) - 1] = '\0'; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6024 | wpa_printf(MSG_DEBUG, "P2P: Randomly generated PIN: %s", | 
|  | 6025 | wpa_s->p2p_pin); | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6026 | } else if (wps_method == WPS_P2PS) { | 
|  | 6027 | /* Force the P2Ps default PIN to be used */ | 
|  | 6028 | os_strlcpy(wpa_s->p2p_pin, "12345670", sizeof(wpa_s->p2p_pin)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6029 | } else | 
|  | 6030 | wpa_s->p2p_pin[0] = '\0'; | 
|  | 6031 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6032 | if (join || auto_join) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6033 | u8 iface_addr[ETH_ALEN], dev_addr[ETH_ALEN]; | 
|  | 6034 | if (auth) { | 
|  | 6035 | wpa_printf(MSG_DEBUG, "P2P: Authorize invitation to " | 
|  | 6036 | "connect a running group from " MACSTR, | 
|  | 6037 | MAC2STR(peer_addr)); | 
|  | 6038 | os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN); | 
|  | 6039 | return ret; | 
|  | 6040 | } | 
|  | 6041 | os_memcpy(dev_addr, peer_addr, ETH_ALEN); | 
|  | 6042 | if (p2p_get_interface_addr(wpa_s->global->p2p, peer_addr, | 
|  | 6043 | iface_addr) < 0) { | 
|  | 6044 | os_memcpy(iface_addr, peer_addr, ETH_ALEN); | 
|  | 6045 | p2p_get_dev_addr(wpa_s->global->p2p, peer_addr, | 
|  | 6046 | dev_addr); | 
|  | 6047 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6048 | if (auto_join) { | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6049 | os_get_reltime(&wpa_s->p2p_auto_started); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6050 | wpa_printf(MSG_DEBUG, "P2P: Auto join started at " | 
|  | 6051 | "%ld.%06ld", | 
|  | 6052 | wpa_s->p2p_auto_started.sec, | 
|  | 6053 | wpa_s->p2p_auto_started.usec); | 
|  | 6054 | } | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6055 | wpa_s->user_initiated_pd = 1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6056 | if (wpas_p2p_join(wpa_s, iface_addr, dev_addr, wps_method, | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 6057 | auto_join, freq, | 
|  | 6058 | group_ssid, group_ssid_len) < 0) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6059 | return -1; | 
|  | 6060 | return ret; | 
|  | 6061 | } | 
|  | 6062 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6063 | size = P2P_MAX_PREF_CHANNELS; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6064 | res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6065 | go_intent == 15, pref_freq_list, &size); | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6066 | if (res) | 
|  | 6067 | return res; | 
| Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 6068 | wpas_p2p_set_own_freq_preference(wpa_s, | 
|  | 6069 | force_freq ? force_freq : pref_freq); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6070 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6071 | p2p_set_own_pref_freq_list(wpa_s->global->p2p, pref_freq_list, size); | 
|  | 6072 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6073 | wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s); | 
|  | 6074 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6075 | if (wpa_s->create_p2p_iface) { | 
|  | 6076 | /* Prepare to add a new interface for the group */ | 
|  | 6077 | iftype = WPA_IF_P2P_GROUP; | 
|  | 6078 | if (go_intent == 15) | 
|  | 6079 | iftype = WPA_IF_P2P_GO; | 
|  | 6080 | if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) { | 
|  | 6081 | wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " | 
|  | 6082 | "interface for the group"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6083 | return -1; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6084 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6085 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6086 | if_addr = wpa_s->pending_interface_addr; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6087 | } else { | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6088 | if (wpa_s->p2p_mgmt) | 
|  | 6089 | if_addr = wpa_s->parent->own_addr; | 
|  | 6090 | else | 
|  | 6091 | if_addr = wpa_s->own_addr; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6092 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); | 
|  | 6093 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6094 |  | 
|  | 6095 | if (auth) { | 
|  | 6096 | if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6097 | go_intent, if_addr, | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6098 | force_freq, persistent_group, ssid, | 
|  | 6099 | pref_freq) < 0) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6100 | return -1; | 
|  | 6101 | return ret; | 
|  | 6102 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6103 |  | 
|  | 6104 | if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method, | 
|  | 6105 | go_intent, if_addr, force_freq, | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6106 | persistent_group, ssid, pref_freq) < 0) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6107 | if (wpa_s->create_p2p_iface) | 
|  | 6108 | wpas_p2p_remove_pending_group_interface(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6109 | return -1; | 
|  | 6110 | } | 
|  | 6111 | return ret; | 
|  | 6112 | } | 
|  | 6113 |  | 
|  | 6114 |  | 
|  | 6115 | /** | 
|  | 6116 | * wpas_p2p_remain_on_channel_cb - Indication of remain-on-channel start | 
|  | 6117 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() | 
|  | 6118 | * @freq: Frequency of the channel in MHz | 
|  | 6119 | * @duration: Duration of the stay on the channel in milliseconds | 
|  | 6120 | * | 
|  | 6121 | * This callback is called when the driver indicates that it has started the | 
|  | 6122 | * requested remain-on-channel duration. | 
|  | 6123 | */ | 
|  | 6124 | void wpas_p2p_remain_on_channel_cb(struct wpa_supplicant *wpa_s, | 
|  | 6125 | unsigned int freq, unsigned int duration) | 
|  | 6126 | { | 
|  | 6127 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 6128 | return; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 6129 | 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)", | 
|  | 6130 | wpa_s->off_channel_freq, wpa_s->pending_listen_freq, | 
|  | 6131 | wpa_s->roc_waiting_drv_freq, freq, duration); | 
|  | 6132 | if (wpa_s->off_channel_freq && | 
|  | 6133 | wpa_s->off_channel_freq == wpa_s->pending_listen_freq) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6134 | p2p_listen_cb(wpa_s->global->p2p, wpa_s->pending_listen_freq, | 
|  | 6135 | wpa_s->pending_listen_duration); | 
|  | 6136 | wpa_s->pending_listen_freq = 0; | 
| Dmitry Shmidt | 7f93d6f | 2014-02-21 11:22:49 -0800 | [diff] [blame] | 6137 | } else { | 
|  | 6138 | wpa_printf(MSG_DEBUG, "P2P: Ignore remain-on-channel callback (off_channel_freq=%u pending_listen_freq=%d freq=%u duration=%u)", | 
|  | 6139 | wpa_s->off_channel_freq, wpa_s->pending_listen_freq, | 
|  | 6140 | freq, duration); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6141 | } | 
|  | 6142 | } | 
|  | 6143 |  | 
|  | 6144 |  | 
| Jithu Jance | 57cea1a | 2014-08-20 10:22:04 -0700 | [diff] [blame] | 6145 | 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] | 6146 | { | 
|  | 6147 | /* Limit maximum Listen state time based on driver limitation. */ | 
|  | 6148 | if (timeout > wpa_s->max_remain_on_chan) | 
|  | 6149 | timeout = wpa_s->max_remain_on_chan; | 
|  | 6150 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6151 | return p2p_listen(wpa_s->global->p2p, timeout); | 
|  | 6152 | } | 
|  | 6153 |  | 
|  | 6154 |  | 
|  | 6155 | /** | 
|  | 6156 | * wpas_p2p_cancel_remain_on_channel_cb - Remain-on-channel timeout | 
|  | 6157 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() | 
|  | 6158 | * @freq: Frequency of the channel in MHz | 
|  | 6159 | * | 
|  | 6160 | * This callback is called when the driver indicates that a remain-on-channel | 
|  | 6161 | * operation has been completed, i.e., the duration on the requested channel | 
|  | 6162 | * has timed out. | 
|  | 6163 | */ | 
|  | 6164 | void wpas_p2p_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s, | 
|  | 6165 | unsigned int freq) | 
|  | 6166 | { | 
|  | 6167 | wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel callback " | 
|  | 6168 | "(p2p_long_listen=%d ms pending_action_tx=%p)", | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6169 | wpa_s->global->p2p_long_listen, | 
|  | 6170 | offchannel_pending_action_tx(wpa_s)); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6171 | wpas_p2p_listen_work_done(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6172 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 6173 | return; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6174 | if (wpa_s->global->p2p_long_listen > 0) | 
|  | 6175 | wpa_s->global->p2p_long_listen -= wpa_s->max_remain_on_chan; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6176 | if (p2p_listen_end(wpa_s->global->p2p, freq) > 0) | 
|  | 6177 | return; /* P2P module started a new operation */ | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6178 | if (offchannel_pending_action_tx(wpa_s)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6179 | return; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6180 | if (wpa_s->global->p2p_long_listen > 0) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6181 | wpa_printf(MSG_DEBUG, "P2P: Continuing long Listen state"); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6182 | wpas_p2p_listen_start(wpa_s, wpa_s->global->p2p_long_listen); | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6183 | } else { | 
|  | 6184 | /* | 
|  | 6185 | * When listen duration is over, stop listen & update p2p_state | 
|  | 6186 | * to IDLE. | 
|  | 6187 | */ | 
|  | 6188 | p2p_stop_listen(wpa_s->global->p2p); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6189 | } | 
|  | 6190 | } | 
|  | 6191 |  | 
|  | 6192 |  | 
|  | 6193 | /** | 
|  | 6194 | * wpas_p2p_group_remove - Remove a P2P group | 
|  | 6195 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() | 
|  | 6196 | * @ifname: Network interface name of the group interface or "*" to remove all | 
|  | 6197 | *	groups | 
|  | 6198 | * Returns: 0 on success, -1 on failure | 
|  | 6199 | * | 
|  | 6200 | * This function is used to remove a P2P group. This can be used to disconnect | 
|  | 6201 | * from a group in which the local end is a P2P Client or to end a P2P Group in | 
|  | 6202 | * case the local end is the Group Owner. If a virtual network interface was | 
|  | 6203 | * created for this group, that interface will be removed. Otherwise, only the | 
|  | 6204 | * configured P2P group network will be removed from the interface. | 
|  | 6205 | */ | 
|  | 6206 | int wpas_p2p_group_remove(struct wpa_supplicant *wpa_s, const char *ifname) | 
|  | 6207 | { | 
|  | 6208 | struct wpa_global *global = wpa_s->global; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6209 | struct wpa_supplicant *calling_wpa_s = wpa_s; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6210 |  | 
|  | 6211 | if (os_strcmp(ifname, "*") == 0) { | 
|  | 6212 | struct wpa_supplicant *prev; | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6213 | bool calling_wpa_s_group_removed = false; | 
|  | 6214 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6215 | wpa_s = global->ifaces; | 
|  | 6216 | while (wpa_s) { | 
|  | 6217 | prev = wpa_s; | 
|  | 6218 | wpa_s = wpa_s->next; | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6219 | if (prev->p2p_group_interface != | 
|  | 6220 | NOT_P2P_GROUP_INTERFACE || | 
|  | 6221 | (prev->current_ssid && | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6222 | prev->current_ssid->p2p_group)) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6223 | wpas_p2p_disconnect_safely(prev, calling_wpa_s); | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6224 | if (prev == calling_wpa_s) | 
|  | 6225 | calling_wpa_s_group_removed = true; | 
|  | 6226 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6227 | } | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6228 |  | 
|  | 6229 | if (!calling_wpa_s_group_removed && | 
|  | 6230 | (calling_wpa_s->p2p_group_interface != | 
|  | 6231 | NOT_P2P_GROUP_INTERFACE || | 
|  | 6232 | (calling_wpa_s->current_ssid && | 
|  | 6233 | calling_wpa_s->current_ssid->p2p_group))) { | 
|  | 6234 | wpa_printf(MSG_DEBUG, "Remove calling_wpa_s P2P group"); | 
|  | 6235 | wpas_p2p_disconnect_safely(calling_wpa_s, | 
|  | 6236 | calling_wpa_s); | 
|  | 6237 | } | 
|  | 6238 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6239 | return 0; | 
|  | 6240 | } | 
|  | 6241 |  | 
|  | 6242 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 6243 | if (os_strcmp(wpa_s->ifname, ifname) == 0) | 
|  | 6244 | break; | 
|  | 6245 | } | 
|  | 6246 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6247 | return wpas_p2p_disconnect_safely(wpa_s, calling_wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6248 | } | 
|  | 6249 |  | 
|  | 6250 |  | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6251 | static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq) | 
|  | 6252 | { | 
|  | 6253 | unsigned int r; | 
|  | 6254 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6255 | if (!wpa_s->conf->num_p2p_pref_chan && !freq) { | 
|  | 6256 | unsigned int i, size = P2P_MAX_PREF_CHANNELS; | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6257 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6258 | int res; | 
|  | 6259 |  | 
|  | 6260 | res = wpa_drv_get_pref_freq_list(wpa_s, WPA_IF_P2P_GO, | 
|  | 6261 | &size, pref_freq_list); | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6262 | if (!is_p2p_allow_6ghz(wpa_s->global->p2p)) | 
|  | 6263 | size = p2p_remove_6ghz_channels(pref_freq_list, size); | 
|  | 6264 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6265 | if (!res && size > 0) { | 
|  | 6266 | i = 0; | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 6267 | while (i < size && | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6268 | (!p2p_supported_freq(wpa_s->global->p2p, | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6269 | pref_freq_list[i].freq) || | 
|  | 6270 | wpas_p2p_disallowed_freq( | 
|  | 6271 | wpa_s->global, | 
|  | 6272 | pref_freq_list[i].freq) || | 
|  | 6273 | !p2p_pref_freq_allowed(&pref_freq_list[i], | 
|  | 6274 | true))) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6275 | wpa_printf(MSG_DEBUG, | 
|  | 6276 | "P2P: preferred_freq_list[%d]=%d is disallowed", | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6277 | i, pref_freq_list[i].freq); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6278 | i++; | 
|  | 6279 | } | 
|  | 6280 | if (i != size) { | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6281 | freq = pref_freq_list[i].freq; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6282 | wpa_printf(MSG_DEBUG, | 
|  | 6283 | "P2P: Using preferred_freq_list[%d]=%d", | 
|  | 6284 | i, freq); | 
|  | 6285 | } else { | 
|  | 6286 | wpa_printf(MSG_DEBUG, | 
|  | 6287 | "P2P: All driver preferred frequencies are disallowed for P2P use"); | 
|  | 6288 | } | 
|  | 6289 | } else { | 
|  | 6290 | wpa_printf(MSG_DEBUG, | 
|  | 6291 | "P2P: No preferred frequency list available"); | 
|  | 6292 | } | 
|  | 6293 | } | 
|  | 6294 |  | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6295 | if (freq == 2) { | 
|  | 6296 | wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 2.4 GHz " | 
|  | 6297 | "band"); | 
|  | 6298 | if (wpa_s->best_24_freq > 0 && | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6299 | p2p_supported_freq_go(wpa_s->global->p2p, | 
|  | 6300 | wpa_s->best_24_freq)) { | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6301 | freq = wpa_s->best_24_freq; | 
|  | 6302 | wpa_printf(MSG_DEBUG, "P2P: Use best 2.4 GHz band " | 
|  | 6303 | "channel: %d MHz", freq); | 
|  | 6304 | } else { | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6305 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) | 
|  | 6306 | return -1; | 
| Jimmy Chen | 801bf46 | 2021-11-09 23:08:48 +0800 | [diff] [blame] | 6307 | int possible_2g_freqs[] = { | 
|  | 6308 | /* operating class 81 */ | 
|  | 6309 | 2412, 2437, 2462, | 
|  | 6310 | }; | 
|  | 6311 | int possible_2g_freqs_num = | 
|  | 6312 | sizeof(possible_2g_freqs)/sizeof(possible_2g_freqs[0]); | 
|  | 6313 | int i; | 
|  | 6314 | for (i = 0; i < possible_2g_freqs_num; i++, r++) { | 
|  | 6315 | freq = possible_2g_freqs[r % possible_2g_freqs_num]; | 
|  | 6316 | if (p2p_supported_freq_go(wpa_s->global->p2p, freq)) { | 
|  | 6317 | break; | 
|  | 6318 | } | 
|  | 6319 | } | 
|  | 6320 |  | 
|  | 6321 | if (i >= possible_2g_freqs_num) { | 
|  | 6322 | wpa_printf(MSG_DEBUG, "P2P: Could not select " | 
|  | 6323 | "2.4 GHz channel for P2P group"); | 
|  | 6324 | return -1; | 
|  | 6325 | } | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6326 | wpa_printf(MSG_DEBUG, "P2P: Use random 2.4 GHz band " | 
|  | 6327 | "channel: %d MHz", freq); | 
|  | 6328 | } | 
|  | 6329 | } | 
|  | 6330 |  | 
|  | 6331 | if (freq == 5) { | 
|  | 6332 | wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 5 GHz " | 
|  | 6333 | "band"); | 
|  | 6334 | if (wpa_s->best_5_freq > 0 && | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6335 | p2p_supported_freq_go(wpa_s->global->p2p, | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6336 | wpa_s->best_5_freq)) { | 
|  | 6337 | freq = wpa_s->best_5_freq; | 
|  | 6338 | wpa_printf(MSG_DEBUG, "P2P: Use best 5 GHz band " | 
|  | 6339 | "channel: %d MHz", freq); | 
|  | 6340 | } else { | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6341 | const int freqs[] = { | 
|  | 6342 | /* operating class 115 */ | 
|  | 6343 | 5180, 5200, 5220, 5240, | 
|  | 6344 | /* operating class 124 */ | 
|  | 6345 | 5745, 5765, 5785, 5805, | 
|  | 6346 | }; | 
|  | 6347 | unsigned int i, num_freqs = ARRAY_SIZE(freqs); | 
|  | 6348 |  | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6349 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) | 
|  | 6350 | return -1; | 
| Jimmy Chen | 64b9063 | 2020-09-29 17:27:34 +0800 | [diff] [blame] | 6351 |  | 
|  | 6352 | /* | 
|  | 6353 | * most of 5G channels are DFS, only operating class 115 and 124 | 
|  | 6354 | * are available possibly, randomly pick a start to check them. | 
|  | 6355 | */ | 
|  | 6356 | int possible_5g_freqs[] = { | 
|  | 6357 | /* operating class 115 */ | 
|  | 6358 | 5180, 5200, 5220, 5240, | 
|  | 6359 | /* operating class 124 */ | 
|  | 6360 | 5745, 5765, 5785, 5805, | 
|  | 6361 | }; | 
|  | 6362 | int possible_5g_freqs_num = | 
|  | 6363 | sizeof(possible_5g_freqs)/sizeof(possible_5g_freqs[0]); | 
|  | 6364 |  | 
| Jimmy Chen | 64b9063 | 2020-09-29 17:27:34 +0800 | [diff] [blame] | 6365 | for (i = 0; i < possible_5g_freqs_num; i++, r++) { | 
|  | 6366 | if (p2p_supported_freq_go( | 
|  | 6367 | wpa_s->global->p2p, | 
|  | 6368 | possible_5g_freqs[r % possible_5g_freqs_num])) { | 
|  | 6369 | freq = possible_5g_freqs[r % possible_5g_freqs_num]; | 
|  | 6370 | break; | 
|  | 6371 | } | 
|  | 6372 | } | 
|  | 6373 |  | 
|  | 6374 | if (i >= possible_5g_freqs_num) { | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6375 | wpa_printf(MSG_DEBUG, "P2P: Could not select " | 
|  | 6376 | "5 GHz channel for P2P group"); | 
|  | 6377 | return -1; | 
|  | 6378 | } | 
|  | 6379 | wpa_printf(MSG_DEBUG, "P2P: Use random 5 GHz band " | 
|  | 6380 | "channel: %d MHz", freq); | 
|  | 6381 | } | 
|  | 6382 | } | 
|  | 6383 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6384 | if (freq > 0 && !p2p_supported_freq_go(wpa_s->global->p2p, freq)) { | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6385 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6386 | ieee80211_is_dfs(freq, wpa_s->hw.modes, | 
|  | 6387 | wpa_s->hw.num_modes)) { | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6388 | /* | 
|  | 6389 | * If freq is a DFS channel and DFS is offloaded to the | 
|  | 6390 | * driver, allow P2P GO to use it. | 
|  | 6391 | */ | 
|  | 6392 | wpa_printf(MSG_DEBUG, "P2P: " | 
|  | 6393 | "%s: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded", | 
|  | 6394 | __func__, freq); | 
|  | 6395 | return freq; | 
|  | 6396 | } | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6397 | wpa_printf(MSG_DEBUG, "P2P: The forced channel for GO " | 
|  | 6398 | "(%u MHz) is not supported for P2P uses", | 
|  | 6399 | freq); | 
|  | 6400 | return -1; | 
|  | 6401 | } | 
|  | 6402 |  | 
|  | 6403 | return freq; | 
|  | 6404 | } | 
|  | 6405 |  | 
|  | 6406 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6407 | static int wpas_p2p_supported_freq_go(struct wpa_supplicant *wpa_s, | 
|  | 6408 | const struct p2p_channels *channels, | 
|  | 6409 | int freq) | 
|  | 6410 | { | 
|  | 6411 | if (!wpas_p2p_disallowed_freq(wpa_s->global, freq) && | 
|  | 6412 | p2p_supported_freq_go(wpa_s->global->p2p, freq) && | 
|  | 6413 | freq_included(wpa_s, channels, freq)) | 
|  | 6414 | return 1; | 
|  | 6415 | return 0; | 
|  | 6416 | } | 
|  | 6417 |  | 
|  | 6418 |  | 
|  | 6419 | static void wpas_p2p_select_go_freq_no_pref(struct wpa_supplicant *wpa_s, | 
|  | 6420 | struct p2p_go_neg_results *params, | 
|  | 6421 | const struct p2p_channels *channels) | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6422 | { | 
|  | 6423 | unsigned int i, r; | 
|  | 6424 |  | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6425 | /* try all channels in operating class 115 */ | 
|  | 6426 | for (i = 0; i < 4; i++) { | 
|  | 6427 | params->freq = 5180 + i * 20; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6428 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6429 | goto out; | 
|  | 6430 | } | 
|  | 6431 |  | 
|  | 6432 | /* try all channels in operating class 124 */ | 
|  | 6433 | for (i = 0; i < 4; i++) { | 
|  | 6434 | params->freq = 5745 + i * 20; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6435 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6436 | goto out; | 
|  | 6437 | } | 
|  | 6438 |  | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6439 | /* try social channel class 180 channel 2 */ | 
|  | 6440 | params->freq = 58320 + 1 * 2160; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6441 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6442 | goto out; | 
|  | 6443 |  | 
|  | 6444 | /* try all channels in reg. class 180 */ | 
|  | 6445 | for (i = 0; i < 4; i++) { | 
|  | 6446 | params->freq = 58320 + i * 2160; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6447 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6448 | goto out; | 
|  | 6449 | } | 
|  | 6450 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6451 | /* try some random selection of the social channels */ | 
|  | 6452 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) | 
|  | 6453 | return; | 
|  | 6454 |  | 
|  | 6455 | for (i = 0; i < 3; i++) { | 
|  | 6456 | params->freq = 2412 + ((r + i) % 3) * 25; | 
|  | 6457 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) | 
|  | 6458 | goto out; | 
|  | 6459 | } | 
|  | 6460 |  | 
|  | 6461 | /* try all other channels in operating class 81 */ | 
|  | 6462 | for (i = 0; i < 11; i++) { | 
|  | 6463 | params->freq = 2412 + i * 5; | 
|  | 6464 |  | 
|  | 6465 | /* skip social channels; covered in the previous loop */ | 
|  | 6466 | if (params->freq == 2412 || | 
|  | 6467 | params->freq == 2437 || | 
|  | 6468 | params->freq == 2462) | 
|  | 6469 | continue; | 
|  | 6470 |  | 
|  | 6471 | if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq)) | 
|  | 6472 | goto out; | 
|  | 6473 | } | 
|  | 6474 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6475 | params->freq = 0; | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6476 | 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] | 6477 | return; | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6478 | out: | 
|  | 6479 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz (no preference known)", | 
|  | 6480 | params->freq); | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6481 | } | 
|  | 6482 |  | 
|  | 6483 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6484 | static int wpas_same_band(int freq1, int freq2) | 
|  | 6485 | { | 
|  | 6486 | enum hostapd_hw_mode mode1, mode2; | 
|  | 6487 | u8 chan1, chan2; | 
|  | 6488 |  | 
|  | 6489 | mode1 = ieee80211_freq_to_chan(freq1, &chan1); | 
|  | 6490 | mode2 = ieee80211_freq_to_chan(freq2, &chan2); | 
|  | 6491 | if (mode1 == NUM_HOSTAPD_MODES) | 
|  | 6492 | return 0; | 
|  | 6493 | return mode1 == mode2; | 
|  | 6494 | } | 
|  | 6495 |  | 
|  | 6496 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6497 | static int wpas_p2p_init_go_params(struct wpa_supplicant *wpa_s, | 
|  | 6498 | struct p2p_go_neg_results *params, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6499 | int freq, int vht_center_freq2, int ht40, | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6500 | int vht, int max_oper_chwidth, int he, | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6501 | int edmg, | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 6502 | const struct p2p_channels *channels) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6503 | { | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6504 | struct wpa_used_freq_data *freqs; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6505 | unsigned int cand; | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6506 | unsigned int num, i; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6507 | int ignore_no_freqs = 0; | 
| Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6508 | int unused_channels = wpas_p2p_num_unused_channels(wpa_s) > 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6509 |  | 
|  | 6510 | os_memset(params, 0, sizeof(*params)); | 
|  | 6511 | params->role_go = 1; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6512 | params->ht40 = ht40; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6513 | params->vht = vht; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6514 | params->he = he; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6515 | params->max_oper_chwidth = max_oper_chwidth; | 
|  | 6516 | params->vht_center_freq2 = vht_center_freq2; | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6517 | params->edmg = edmg; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6518 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6519 | freqs = os_calloc(wpa_s->num_multichan_concurrent, | 
|  | 6520 | sizeof(struct wpa_used_freq_data)); | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6521 | if (!freqs) | 
|  | 6522 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6523 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6524 | num = get_shared_radio_freqs_data(wpa_s, freqs, | 
|  | 6525 | wpa_s->num_multichan_concurrent); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6526 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6527 | if (wpa_s->current_ssid && | 
|  | 6528 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO && | 
|  | 6529 | wpa_s->wpa_state == WPA_COMPLETED) { | 
|  | 6530 | wpa_printf(MSG_DEBUG, "P2P: %s called for an active GO", | 
|  | 6531 | __func__); | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6532 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6533 | /* | 
|  | 6534 | * If the frequency selection is done for an active P2P GO that | 
|  | 6535 | * is not sharing a frequency, allow to select a new frequency | 
|  | 6536 | * even if there are no unused frequencies as we are about to | 
|  | 6537 | * move the P2P GO so its frequency can be re-used. | 
|  | 6538 | */ | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6539 | for (i = 0; i < num; i++) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6540 | if (freqs[i].freq == wpa_s->current_ssid->frequency && | 
|  | 6541 | freqs[i].flags == 0) { | 
|  | 6542 | ignore_no_freqs = 1; | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6543 | break; | 
|  | 6544 | } | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6545 | } | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 6546 | } | 
|  | 6547 |  | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6548 | /* Try to use EDMG channel */ | 
|  | 6549 | if (params->edmg) { | 
|  | 6550 | if (wpas_p2p_try_edmg_channel(wpa_s, params) == 0) | 
|  | 6551 | goto success; | 
|  | 6552 | params->edmg = 0; | 
|  | 6553 | } | 
|  | 6554 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6555 | /* try using the forced freq */ | 
|  | 6556 | if (freq) { | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6557 | if (wpas_p2p_disallowed_freq(wpa_s->global, freq) || | 
|  | 6558 | !freq_included(wpa_s, channels, freq)) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6559 | wpa_printf(MSG_DEBUG, | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6560 | "P2P: Forced GO freq %d MHz disallowed", | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6561 | freq); | 
|  | 6562 | goto fail; | 
|  | 6563 | } | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6564 | if (!p2p_supported_freq_go(wpa_s->global->p2p, freq)) { | 
|  | 6565 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6566 | ieee80211_is_dfs(freq, wpa_s->hw.modes, | 
|  | 6567 | wpa_s->hw.num_modes)) { | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6568 | /* | 
|  | 6569 | * If freq is a DFS channel and DFS is offloaded | 
|  | 6570 | * to the driver, allow P2P GO to use it. | 
|  | 6571 | */ | 
|  | 6572 | wpa_printf(MSG_DEBUG, | 
|  | 6573 | "P2P: %s: The forced channel for GO (%u MHz) requires DFS and DFS is offloaded", | 
|  | 6574 | __func__, freq); | 
|  | 6575 | } else { | 
|  | 6576 | wpa_printf(MSG_DEBUG, | 
|  | 6577 | "P2P: The forced channel for GO (%u MHz) is not supported for P2P uses", | 
|  | 6578 | freq); | 
|  | 6579 | goto fail; | 
|  | 6580 | } | 
|  | 6581 | } | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6582 |  | 
|  | 6583 | for (i = 0; i < num; i++) { | 
|  | 6584 | if (freqs[i].freq == freq) { | 
|  | 6585 | wpa_printf(MSG_DEBUG, | 
|  | 6586 | "P2P: forced freq (%d MHz) is also shared", | 
|  | 6587 | freq); | 
|  | 6588 | params->freq = freq; | 
|  | 6589 | goto success; | 
|  | 6590 | } | 
|  | 6591 | } | 
|  | 6592 |  | 
| Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6593 | if (!ignore_no_freqs && !unused_channels) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6594 | wpa_printf(MSG_DEBUG, | 
|  | 6595 | "P2P: Cannot force GO on freq (%d MHz) as all the channels are in use", | 
|  | 6596 | freq); | 
|  | 6597 | goto fail; | 
|  | 6598 | } | 
|  | 6599 |  | 
|  | 6600 | wpa_printf(MSG_DEBUG, | 
|  | 6601 | "P2P: force GO freq (%d MHz) on a free channel", | 
|  | 6602 | freq); | 
|  | 6603 | params->freq = freq; | 
|  | 6604 | goto success; | 
|  | 6605 | } | 
|  | 6606 |  | 
|  | 6607 | /* consider using one of the shared frequencies */ | 
| Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6608 | if (num && | 
|  | 6609 | (!wpa_s->conf->p2p_ignore_shared_freq || !unused_channels)) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6610 | cand = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num); | 
|  | 6611 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { | 
|  | 6612 | wpa_printf(MSG_DEBUG, | 
|  | 6613 | "P2P: Use shared freq (%d MHz) for GO", | 
| Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6614 | cand); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6615 | params->freq = cand; | 
|  | 6616 | goto success; | 
|  | 6617 | } | 
|  | 6618 |  | 
|  | 6619 | /* try using one of the shared freqs */ | 
|  | 6620 | for (i = 0; i < num; i++) { | 
|  | 6621 | if (wpas_p2p_supported_freq_go(wpa_s, channels, | 
|  | 6622 | freqs[i].freq)) { | 
|  | 6623 | wpa_printf(MSG_DEBUG, | 
|  | 6624 | "P2P: Use shared freq (%d MHz) for GO", | 
| Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6625 | freqs[i].freq); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6626 | params->freq = freqs[i].freq; | 
|  | 6627 | goto success; | 
|  | 6628 | } | 
|  | 6629 | } | 
|  | 6630 | } | 
|  | 6631 |  | 
| Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6632 | if (!ignore_no_freqs && !unused_channels) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6633 | wpa_printf(MSG_DEBUG, | 
|  | 6634 | "P2P: Cannot force GO on any of the channels we are already using"); | 
|  | 6635 | goto fail; | 
|  | 6636 | } | 
|  | 6637 |  | 
|  | 6638 | /* try using the setting from the configuration file */ | 
|  | 6639 | if (wpa_s->conf->p2p_oper_reg_class == 81 && | 
|  | 6640 | wpa_s->conf->p2p_oper_channel >= 1 && | 
|  | 6641 | wpa_s->conf->p2p_oper_channel <= 11 && | 
|  | 6642 | wpas_p2p_supported_freq_go( | 
|  | 6643 | wpa_s, channels, | 
|  | 6644 | 2407 + 5 * wpa_s->conf->p2p_oper_channel)) { | 
|  | 6645 | params->freq = 2407 + 5 * wpa_s->conf->p2p_oper_channel; | 
|  | 6646 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured " | 
|  | 6647 | "frequency %d MHz", params->freq); | 
|  | 6648 | goto success; | 
|  | 6649 | } | 
|  | 6650 |  | 
|  | 6651 | if ((wpa_s->conf->p2p_oper_reg_class == 115 || | 
|  | 6652 | wpa_s->conf->p2p_oper_reg_class == 116 || | 
|  | 6653 | wpa_s->conf->p2p_oper_reg_class == 117 || | 
|  | 6654 | wpa_s->conf->p2p_oper_reg_class == 124 || | 
|  | 6655 | wpa_s->conf->p2p_oper_reg_class == 125 || | 
|  | 6656 | wpa_s->conf->p2p_oper_reg_class == 126 || | 
|  | 6657 | wpa_s->conf->p2p_oper_reg_class == 127) && | 
|  | 6658 | wpas_p2p_supported_freq_go(wpa_s, channels, | 
|  | 6659 | 5000 + | 
|  | 6660 | 5 * wpa_s->conf->p2p_oper_channel)) { | 
|  | 6661 | params->freq = 5000 + 5 * wpa_s->conf->p2p_oper_channel; | 
|  | 6662 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured " | 
|  | 6663 | "frequency %d MHz", params->freq); | 
|  | 6664 | goto success; | 
|  | 6665 | } | 
|  | 6666 |  | 
|  | 6667 | /* Try using best channels */ | 
|  | 6668 | if (wpa_s->conf->p2p_oper_channel == 0 && | 
|  | 6669 | wpa_s->best_overall_freq > 0 && | 
|  | 6670 | wpas_p2p_supported_freq_go(wpa_s, channels, | 
|  | 6671 | wpa_s->best_overall_freq)) { | 
|  | 6672 | params->freq = wpa_s->best_overall_freq; | 
|  | 6673 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best overall " | 
|  | 6674 | "channel %d MHz", params->freq); | 
|  | 6675 | goto success; | 
|  | 6676 | } | 
|  | 6677 |  | 
|  | 6678 | if (wpa_s->conf->p2p_oper_channel == 0 && | 
|  | 6679 | wpa_s->best_24_freq > 0 && | 
|  | 6680 | wpas_p2p_supported_freq_go(wpa_s, channels, | 
|  | 6681 | wpa_s->best_24_freq)) { | 
|  | 6682 | params->freq = wpa_s->best_24_freq; | 
|  | 6683 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 2.4 GHz " | 
|  | 6684 | "channel %d MHz", params->freq); | 
|  | 6685 | goto success; | 
|  | 6686 | } | 
|  | 6687 |  | 
|  | 6688 | if (wpa_s->conf->p2p_oper_channel == 0 && | 
|  | 6689 | wpa_s->best_5_freq > 0 && | 
|  | 6690 | wpas_p2p_supported_freq_go(wpa_s, channels, | 
|  | 6691 | wpa_s->best_5_freq)) { | 
|  | 6692 | params->freq = wpa_s->best_5_freq; | 
|  | 6693 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 5 GHz " | 
|  | 6694 | "channel %d MHz", params->freq); | 
|  | 6695 | goto success; | 
|  | 6696 | } | 
|  | 6697 |  | 
|  | 6698 | /* try using preferred channels */ | 
|  | 6699 | cand = p2p_get_pref_freq(wpa_s->global->p2p, channels); | 
|  | 6700 | if (cand && wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { | 
|  | 6701 | params->freq = cand; | 
|  | 6702 | wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz from preferred " | 
|  | 6703 | "channels", params->freq); | 
|  | 6704 | goto success; | 
|  | 6705 | } | 
|  | 6706 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6707 | /* Try using a channel that allows VHT to be used with 80 MHz */ | 
|  | 6708 | if (wpa_s->hw.modes && wpa_s->p2p_group_common_freqs) { | 
|  | 6709 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { | 
|  | 6710 | enum hostapd_hw_mode mode; | 
|  | 6711 | struct hostapd_hw_modes *hwmode; | 
|  | 6712 | u8 chan; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6713 | u8 op_class; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6714 |  | 
|  | 6715 | cand = wpa_s->p2p_group_common_freqs[i]; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6716 | op_class = is_6ghz_freq(cand) ? 133 : 128; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6717 | mode = ieee80211_freq_to_chan(cand, &chan); | 
|  | 6718 | hwmode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6719 | mode, is_6ghz_freq(cand)); | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6720 | if (!hwmode || | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6721 | wpas_p2p_verify_channel(wpa_s, hwmode, op_class, | 
|  | 6722 | chan, BW80) != ALLOWED) | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6723 | continue; | 
|  | 6724 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { | 
|  | 6725 | params->freq = cand; | 
|  | 6726 | wpa_printf(MSG_DEBUG, | 
|  | 6727 | "P2P: Use freq %d MHz common with the peer and allowing VHT80", | 
|  | 6728 | params->freq); | 
|  | 6729 | goto success; | 
|  | 6730 | } | 
|  | 6731 | } | 
|  | 6732 | } | 
|  | 6733 |  | 
|  | 6734 | /* Try using a channel that allows HT to be used with 40 MHz on the same | 
|  | 6735 | * band so that CSA can be used */ | 
|  | 6736 | if (wpa_s->current_ssid && wpa_s->hw.modes && | 
|  | 6737 | wpa_s->p2p_group_common_freqs) { | 
|  | 6738 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { | 
|  | 6739 | enum hostapd_hw_mode mode; | 
|  | 6740 | struct hostapd_hw_modes *hwmode; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6741 | u8 chan, op_class; | 
|  | 6742 | bool is_6ghz, supported = false; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6743 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6744 | is_6ghz = is_6ghz_freq(cand); | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6745 | cand = wpa_s->p2p_group_common_freqs[i]; | 
|  | 6746 | mode = ieee80211_freq_to_chan(cand, &chan); | 
|  | 6747 | hwmode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6748 | mode, is_6ghz); | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6749 | if (!wpas_same_band(wpa_s->current_ssid->frequency, | 
|  | 6750 | cand) || | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6751 | !hwmode) | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6752 | continue; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6753 | if (is_6ghz && | 
|  | 6754 | wpas_p2p_verify_channel(wpa_s, hwmode, 132, chan, | 
|  | 6755 | BW40) == ALLOWED) | 
|  | 6756 | supported = true; | 
|  | 6757 |  | 
|  | 6758 | if (!is_6ghz && | 
|  | 6759 | ieee80211_freq_to_channel_ext( | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6760 | cand, -1, CONF_OPER_CHWIDTH_USE_HT, | 
|  | 6761 | &op_class, &chan) != NUM_HOSTAPD_MODES && | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6762 | wpas_p2p_verify_channel( | 
|  | 6763 | wpa_s, hwmode, op_class, chan, | 
|  | 6764 | BW40MINUS) == ALLOWED) | 
|  | 6765 | supported = true; | 
|  | 6766 |  | 
|  | 6767 | if (!supported && !is_6ghz && | 
|  | 6768 | ieee80211_freq_to_channel_ext( | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6769 | cand, 1, CONF_OPER_CHWIDTH_USE_HT, | 
|  | 6770 | &op_class, &chan) != NUM_HOSTAPD_MODES && | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6771 | wpas_p2p_verify_channel( | 
|  | 6772 | wpa_s, hwmode, op_class, chan, | 
|  | 6773 | BW40PLUS) == ALLOWED) | 
|  | 6774 | supported = true; | 
|  | 6775 |  | 
|  | 6776 | if (!supported) | 
|  | 6777 | continue; | 
|  | 6778 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6779 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { | 
|  | 6780 | params->freq = cand; | 
|  | 6781 | wpa_printf(MSG_DEBUG, | 
|  | 6782 | "P2P: Use freq %d MHz common with the peer, allowing HT40, and maintaining same band", | 
|  | 6783 | params->freq); | 
|  | 6784 | goto success; | 
|  | 6785 | } | 
|  | 6786 | } | 
|  | 6787 | } | 
|  | 6788 |  | 
|  | 6789 | /* Try using one of the group common freqs on the same band so that CSA | 
|  | 6790 | * can be used */ | 
|  | 6791 | if (wpa_s->current_ssid && wpa_s->p2p_group_common_freqs) { | 
|  | 6792 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { | 
|  | 6793 | cand = wpa_s->p2p_group_common_freqs[i]; | 
|  | 6794 | if (!wpas_same_band(wpa_s->current_ssid->frequency, | 
|  | 6795 | cand)) | 
|  | 6796 | continue; | 
|  | 6797 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { | 
|  | 6798 | params->freq = cand; | 
|  | 6799 | wpa_printf(MSG_DEBUG, | 
|  | 6800 | "P2P: Use freq %d MHz common with the peer and maintaining same band", | 
|  | 6801 | params->freq); | 
|  | 6802 | goto success; | 
|  | 6803 | } | 
|  | 6804 | } | 
|  | 6805 | } | 
|  | 6806 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6807 | /* Try using one of the group common freqs */ | 
|  | 6808 | if (wpa_s->p2p_group_common_freqs) { | 
|  | 6809 | for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) { | 
|  | 6810 | cand = wpa_s->p2p_group_common_freqs[i]; | 
|  | 6811 | if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) { | 
|  | 6812 | params->freq = cand; | 
|  | 6813 | wpa_printf(MSG_DEBUG, | 
|  | 6814 | "P2P: Use freq %d MHz common with the peer", | 
|  | 6815 | params->freq); | 
|  | 6816 | goto success; | 
|  | 6817 | } | 
|  | 6818 | } | 
|  | 6819 | } | 
|  | 6820 |  | 
|  | 6821 | /* no preference, select some channel */ | 
|  | 6822 | wpas_p2p_select_go_freq_no_pref(wpa_s, params, channels); | 
|  | 6823 |  | 
|  | 6824 | if (params->freq == 0) { | 
|  | 6825 | wpa_printf(MSG_DEBUG, "P2P: did not find a freq for GO use"); | 
|  | 6826 | goto fail; | 
|  | 6827 | } | 
|  | 6828 |  | 
|  | 6829 | success: | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6830 | os_free(freqs); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6831 | return 0; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6832 | fail: | 
|  | 6833 | os_free(freqs); | 
|  | 6834 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6835 | } | 
|  | 6836 |  | 
|  | 6837 |  | 
|  | 6838 | static struct wpa_supplicant * | 
|  | 6839 | wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated, | 
|  | 6840 | int go) | 
|  | 6841 | { | 
|  | 6842 | struct wpa_supplicant *group_wpa_s; | 
|  | 6843 |  | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6844 | if (!wpas_p2p_create_iface(wpa_s)) { | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6845 | if (wpa_s->p2p_mgmt) { | 
|  | 6846 | /* | 
|  | 6847 | * We may be called on the p2p_dev interface which | 
|  | 6848 | * cannot be used for group operations, so always use | 
|  | 6849 | * the primary interface. | 
|  | 6850 | */ | 
|  | 6851 | wpa_s->parent->p2pdev = wpa_s; | 
|  | 6852 | wpa_s = wpa_s->parent; | 
|  | 6853 | } | 
|  | 6854 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 6855 | "P2P: Use primary interface for group operations"); | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6856 | wpa_s->p2p_first_connection_timeout = 0; | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6857 | if (wpa_s != wpa_s->p2pdev) | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6858 | wpas_p2p_clone_config(wpa_s, wpa_s->p2pdev); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6859 | return wpa_s; | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6860 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6861 |  | 
|  | 6862 | 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] | 6863 | WPA_IF_P2P_CLIENT) < 0) { | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6864 | wpa_msg_global(wpa_s, MSG_ERROR, | 
|  | 6865 | "P2P: Failed to add group interface"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6866 | return NULL; | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6867 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6868 | group_wpa_s = wpas_p2p_init_group_interface(wpa_s, go); | 
|  | 6869 | if (group_wpa_s == NULL) { | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 6870 | wpa_msg_global(wpa_s, MSG_ERROR, | 
|  | 6871 | "P2P: Failed to initialize group interface"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6872 | wpas_p2p_remove_pending_group_interface(wpa_s); | 
|  | 6873 | return NULL; | 
|  | 6874 | } | 
|  | 6875 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6876 | if (go && wpa_s->p2p_go_do_acs) { | 
|  | 6877 | group_wpa_s->p2p_go_do_acs = wpa_s->p2p_go_do_acs; | 
|  | 6878 | group_wpa_s->p2p_go_acs_band = wpa_s->p2p_go_acs_band; | 
|  | 6879 | wpa_s->p2p_go_do_acs = 0; | 
|  | 6880 | } | 
|  | 6881 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6882 | if (go && wpa_s->p2p_go_allow_dfs) { | 
|  | 6883 | group_wpa_s->p2p_go_allow_dfs = wpa_s->p2p_go_allow_dfs; | 
|  | 6884 | wpa_s->p2p_go_allow_dfs = 0; | 
|  | 6885 | } | 
|  | 6886 |  | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6887 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use separate group interface %s", | 
|  | 6888 | group_wpa_s->ifname); | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6889 | group_wpa_s->p2p_first_connection_timeout = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6890 | return group_wpa_s; | 
|  | 6891 | } | 
|  | 6892 |  | 
|  | 6893 |  | 
|  | 6894 | /** | 
|  | 6895 | * wpas_p2p_group_add - Add a new P2P group with local end as Group Owner | 
|  | 6896 | * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface() | 
|  | 6897 | * @persistent_group: Whether to create a persistent group | 
|  | 6898 | * @freq: Frequency for the group or 0 to indicate no hardcoding | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6899 | * @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] | 6900 | * @ht40: Start GO with 40 MHz channel width | 
|  | 6901 | * @vht:  Start GO with VHT support | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6902 | * @vht_chwidth: channel bandwidth for GO operating with VHT support | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6903 | * @edmg: Start GO with EDMG support | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6904 | * @allow_6ghz: Allow P2P group creation on a 6 GHz channel | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6905 | * Returns: 0 on success, -1 on failure | 
|  | 6906 | * | 
|  | 6907 | * This function creates a new P2P group with the local end as the Group Owner, | 
|  | 6908 | * i.e., without using Group Owner Negotiation. | 
|  | 6909 | */ | 
|  | 6910 | 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] | 6911 | int freq, int vht_center_freq2, int ht40, int vht, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6912 | int max_oper_chwidth, int he, int edmg, | 
|  | 6913 | bool allow_6ghz) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6914 | { | 
|  | 6915 | struct p2p_go_neg_results params; | 
| Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 6916 | int selected_freq = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6917 |  | 
|  | 6918 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 6919 | return -1; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6920 | if (wpas_p2p_check_6ghz(wpa_s, NULL, allow_6ghz, freq)) | 
|  | 6921 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6922 |  | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6923 | os_free(wpa_s->global->add_psk); | 
|  | 6924 | wpa_s->global->add_psk = NULL; | 
|  | 6925 |  | 
| Dmitry Shmidt | dca3979 | 2011-09-06 11:17:33 -0700 | [diff] [blame] | 6926 | /* Make sure we are not running find during connection establishment */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6927 | wpa_printf(MSG_DEBUG, "P2P: Stop any on-going P2P FIND"); | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6928 | wpas_p2p_stop_find_oper(wpa_s); | 
| Dmitry Shmidt | dca3979 | 2011-09-06 11:17:33 -0700 | [diff] [blame] | 6929 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6930 | if (!wpa_s->p2p_go_do_acs) { | 
| Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 6931 | selected_freq = wpas_p2p_select_go_freq(wpa_s, freq); | 
|  | 6932 | if (selected_freq < 0) | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6933 | return -1; | 
|  | 6934 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6935 |  | 
| Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 6936 | if (wpas_p2p_init_go_params(wpa_s, ¶ms, selected_freq, vht_center_freq2, | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 6937 | ht40, vht, max_oper_chwidth, he, edmg, | 
|  | 6938 | NULL)) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6939 | return -1; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6940 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6941 | p2p_go_params(wpa_s->global->p2p, ¶ms); | 
|  | 6942 | params.persistent_group = persistent_group; | 
|  | 6943 |  | 
|  | 6944 | wpa_s = wpas_p2p_get_group_iface(wpa_s, 0, 1); | 
|  | 6945 | if (wpa_s == NULL) | 
|  | 6946 | return -1; | 
| Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 6947 | if (freq > 0) | 
|  | 6948 | wpa_s->p2p_go_no_pri_sec_switch = 1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6949 | wpas_start_wps_go(wpa_s, ¶ms, 0); | 
|  | 6950 |  | 
|  | 6951 | return 0; | 
|  | 6952 | } | 
|  | 6953 |  | 
|  | 6954 |  | 
|  | 6955 | static int wpas_start_p2p_client(struct wpa_supplicant *wpa_s, | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6956 | struct wpa_ssid *params, int addr_allocated, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6957 | int freq, int force_scan) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6958 | { | 
|  | 6959 | struct wpa_ssid *ssid; | 
| Matthew Wang | 9ae940b | 2022-09-14 21:25:34 -0700 | [diff] [blame] | 6960 | int other_iface_found = 0; | 
|  | 6961 | struct wpa_supplicant *ifs; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6962 |  | 
|  | 6963 | wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 0); | 
|  | 6964 | if (wpa_s == NULL) | 
|  | 6965 | return -1; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6966 | if (force_scan) | 
|  | 6967 | os_get_reltime(&wpa_s->scan_min_time); | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 6968 | wpa_s->p2p_last_4way_hs_fail = NULL; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6969 |  | 
|  | 6970 | wpa_supplicant_ap_deinit(wpa_s); | 
|  | 6971 |  | 
|  | 6972 | ssid = wpa_config_add_network(wpa_s->conf); | 
|  | 6973 | if (ssid == NULL) | 
|  | 6974 | return -1; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6975 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6976 | wpa_config_set_network_defaults(ssid); | 
|  | 6977 | ssid->temporary = 1; | 
|  | 6978 | ssid->proto = WPA_PROTO_RSN; | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 6979 | ssid->pbss = params->pbss; | 
|  | 6980 | ssid->pairwise_cipher = params->pbss ? WPA_CIPHER_GCMP : | 
|  | 6981 | WPA_CIPHER_CCMP; | 
|  | 6982 | ssid->group_cipher = params->pbss ? WPA_CIPHER_GCMP : WPA_CIPHER_CCMP; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6983 | ssid->key_mgmt = WPA_KEY_MGMT_PSK; | 
|  | 6984 | ssid->ssid = os_malloc(params->ssid_len); | 
|  | 6985 | if (ssid->ssid == NULL) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6986 | wpa_config_remove_network(wpa_s->conf, ssid->id); | 
|  | 6987 | return -1; | 
|  | 6988 | } | 
|  | 6989 | os_memcpy(ssid->ssid, params->ssid, params->ssid_len); | 
|  | 6990 | ssid->ssid_len = params->ssid_len; | 
|  | 6991 | ssid->p2p_group = 1; | 
|  | 6992 | ssid->export_keys = 1; | 
|  | 6993 | if (params->psk_set) { | 
|  | 6994 | os_memcpy(ssid->psk, params->psk, 32); | 
|  | 6995 | ssid->psk_set = 1; | 
|  | 6996 | } | 
|  | 6997 | if (params->passphrase) | 
|  | 6998 | ssid->passphrase = os_strdup(params->passphrase); | 
|  | 6999 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7000 | wpa_s->show_group_started = 1; | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7001 | wpa_s->p2p_in_invitation = 1; | 
|  | 7002 | wpa_s->p2p_invite_go_freq = freq; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7003 | wpa_s->p2p_go_group_formation_completed = 0; | 
|  | 7004 | wpa_s->global->p2p_group_formation = wpa_s; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7005 |  | 
| Matthew Wang | 9ae940b | 2022-09-14 21:25:34 -0700 | [diff] [blame] | 7006 | /* | 
|  | 7007 | * Get latest scan results from driver in case cached scan results from | 
|  | 7008 | * interfaces on the same wiphy allow us to skip the next scan by fast | 
|  | 7009 | * associating. Also update the scan time to the most recent scan result | 
|  | 7010 | * fetch time on the same radio so it reflects the actual time the last | 
|  | 7011 | * scan result event occurred. | 
|  | 7012 | */ | 
|  | 7013 | wpa_supplicant_update_scan_results(wpa_s); | 
|  | 7014 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, | 
|  | 7015 | radio_list) { | 
|  | 7016 | if (ifs == wpa_s) | 
|  | 7017 | continue; | 
|  | 7018 | if (!other_iface_found || os_reltime_before(&wpa_s->last_scan, | 
|  | 7019 | &ifs->last_scan)) { | 
|  | 7020 | other_iface_found = 1; | 
|  | 7021 | wpa_s->last_scan.sec = ifs->last_scan.sec; | 
|  | 7022 | wpa_s->last_scan.usec = ifs->last_scan.usec; | 
|  | 7023 | } | 
|  | 7024 | } | 
|  | 7025 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7026 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->p2pdev, | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7027 | NULL); | 
|  | 7028 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, | 
|  | 7029 | wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7030 | wpa_s->p2pdev, NULL); | 
| Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 7031 | wpa_supplicant_select_network(wpa_s, ssid); | 
|  | 7032 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7033 | return 0; | 
|  | 7034 | } | 
|  | 7035 |  | 
|  | 7036 |  | 
|  | 7037 | int wpas_p2p_group_add_persistent(struct wpa_supplicant *wpa_s, | 
|  | 7038 | struct wpa_ssid *ssid, int addr_allocated, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7039 | int force_freq, int neg_freq, | 
|  | 7040 | int vht_center_freq2, int ht40, | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7041 | int vht, int max_oper_chwidth, int he, | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7042 | int edmg, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7043 | const struct p2p_channels *channels, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7044 | int connection_timeout, int force_scan, | 
|  | 7045 | bool allow_6ghz) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7046 | { | 
|  | 7047 | struct p2p_go_neg_results params; | 
| Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 7048 | int go = 0, freq; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7049 |  | 
|  | 7050 | if (ssid->disabled != 2 || ssid->ssid == NULL) | 
|  | 7051 | return -1; | 
|  | 7052 |  | 
|  | 7053 | if (wpas_get_p2p_group(wpa_s, ssid->ssid, ssid->ssid_len, &go) && | 
|  | 7054 | go == (ssid->mode == WPAS_MODE_P2P_GO)) { | 
|  | 7055 | wpa_printf(MSG_DEBUG, "P2P: Requested persistent group is " | 
|  | 7056 | "already running"); | 
| Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 7057 | if (go == 0 && | 
|  | 7058 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7059 | wpa_s->p2pdev, NULL)) { | 
| Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 7060 | /* | 
|  | 7061 | * This can happen if Invitation Response frame was lost | 
|  | 7062 | * and the peer (GO of a persistent group) tries to | 
|  | 7063 | * invite us again. Reschedule the timeout to avoid | 
|  | 7064 | * terminating the wait for the connection too early | 
|  | 7065 | * since we now know that the peer is still trying to | 
|  | 7066 | * invite us instead of having already started the GO. | 
|  | 7067 | */ | 
|  | 7068 | wpa_printf(MSG_DEBUG, | 
|  | 7069 | "P2P: Reschedule group formation timeout since peer is still trying to invite us"); | 
|  | 7070 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, | 
|  | 7071 | wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7072 | wpa_s->p2pdev, NULL); | 
| Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 7073 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7074 | return 0; | 
|  | 7075 | } | 
|  | 7076 |  | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 7077 | os_free(wpa_s->global->add_psk); | 
|  | 7078 | wpa_s->global->add_psk = NULL; | 
|  | 7079 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7080 | /* Make sure we are not running find during connection establishment */ | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7081 | wpas_p2p_stop_find_oper(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7082 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7083 | wpa_s->p2p_fallback_to_go_neg = 0; | 
|  | 7084 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7085 | if (ssid->mode == WPAS_MODE_P2P_GO) { | 
|  | 7086 | if (force_freq > 0) { | 
|  | 7087 | freq = wpas_p2p_select_go_freq(wpa_s, force_freq); | 
|  | 7088 | if (freq < 0) | 
|  | 7089 | return -1; | 
| Sunil Ravi | 77a0f09 | 2022-10-03 00:53:41 +0000 | [diff] [blame] | 7090 | wpa_s->p2p_go_no_pri_sec_switch = 1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7091 | } else { | 
|  | 7092 | freq = wpas_p2p_select_go_freq(wpa_s, neg_freq); | 
|  | 7093 | if (freq < 0 || | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7094 | (freq > 0 && !freq_included(wpa_s, channels, freq))) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7095 | freq = 0; | 
|  | 7096 | } | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7097 | } else if (ssid->mode == WPAS_MODE_INFRA) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7098 | freq = neg_freq; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7099 | if (freq <= 0 || !freq_included(wpa_s, channels, freq)) { | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7100 | struct os_reltime now; | 
|  | 7101 | struct wpa_bss *bss = | 
|  | 7102 | wpa_bss_get_p2p_dev_addr(wpa_s, ssid->bssid); | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 7103 |  | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7104 | os_get_reltime(&now); | 
|  | 7105 | if (bss && | 
|  | 7106 | !os_reltime_expired(&now, &bss->last_update, 5) && | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7107 | freq_included(wpa_s, channels, bss->freq)) | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7108 | freq = bss->freq; | 
|  | 7109 | else | 
|  | 7110 | freq = 0; | 
|  | 7111 | } | 
|  | 7112 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7113 | return wpas_start_p2p_client(wpa_s, ssid, addr_allocated, freq, | 
|  | 7114 | force_scan); | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7115 | } else { | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7116 | return -1; | 
| Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 7117 | } | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 7118 |  | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7119 | 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] | 7120 | ht40, vht, max_oper_chwidth, he, edmg, | 
|  | 7121 | channels)) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7122 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7123 |  | 
|  | 7124 | params.role_go = 1; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7125 | params.psk_set = ssid->psk_set; | 
|  | 7126 | if (params.psk_set) | 
|  | 7127 | os_memcpy(params.psk, ssid->psk, sizeof(params.psk)); | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7128 | if (ssid->passphrase) { | 
|  | 7129 | if (os_strlen(ssid->passphrase) >= sizeof(params.passphrase)) { | 
|  | 7130 | wpa_printf(MSG_ERROR, "P2P: Invalid passphrase in " | 
|  | 7131 | "persistent group"); | 
|  | 7132 | return -1; | 
|  | 7133 | } | 
|  | 7134 | os_strlcpy(params.passphrase, ssid->passphrase, | 
|  | 7135 | sizeof(params.passphrase)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7136 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7137 | os_memcpy(params.ssid, ssid->ssid, ssid->ssid_len); | 
|  | 7138 | params.ssid_len = ssid->ssid_len; | 
|  | 7139 | params.persistent_group = 1; | 
|  | 7140 |  | 
|  | 7141 | wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 1); | 
|  | 7142 | if (wpa_s == NULL) | 
|  | 7143 | return -1; | 
|  | 7144 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7145 | p2p_channels_to_freqs(channels, params.freq_list, P2P_MAX_CHANNELS); | 
|  | 7146 |  | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7147 | wpa_s->p2p_first_connection_timeout = connection_timeout; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7148 | wpas_start_wps_go(wpa_s, ¶ms, 0); | 
|  | 7149 |  | 
|  | 7150 | return 0; | 
|  | 7151 | } | 
|  | 7152 |  | 
|  | 7153 |  | 
|  | 7154 | static void wpas_p2p_ie_update(void *ctx, struct wpabuf *beacon_ies, | 
|  | 7155 | struct wpabuf *proberesp_ies) | 
|  | 7156 | { | 
|  | 7157 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 7158 | if (wpa_s->ap_iface) { | 
|  | 7159 | struct hostapd_data *hapd = wpa_s->ap_iface->bss[0]; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7160 | if (!(hapd->conf->p2p & P2P_GROUP_OWNER)) { | 
|  | 7161 | wpabuf_free(beacon_ies); | 
|  | 7162 | wpabuf_free(proberesp_ies); | 
|  | 7163 | return; | 
|  | 7164 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7165 | if (beacon_ies) { | 
|  | 7166 | wpabuf_free(hapd->p2p_beacon_ie); | 
|  | 7167 | hapd->p2p_beacon_ie = beacon_ies; | 
|  | 7168 | } | 
|  | 7169 | wpabuf_free(hapd->p2p_probe_resp_ie); | 
|  | 7170 | hapd->p2p_probe_resp_ie = proberesp_ies; | 
|  | 7171 | } else { | 
|  | 7172 | wpabuf_free(beacon_ies); | 
|  | 7173 | wpabuf_free(proberesp_ies); | 
|  | 7174 | } | 
|  | 7175 | wpa_supplicant_ap_update_beacon(wpa_s); | 
|  | 7176 | } | 
|  | 7177 |  | 
|  | 7178 |  | 
|  | 7179 | static void wpas_p2p_idle_update(void *ctx, int idle) | 
|  | 7180 | { | 
|  | 7181 | struct wpa_supplicant *wpa_s = ctx; | 
|  | 7182 | if (!wpa_s->ap_iface) | 
|  | 7183 | return; | 
|  | 7184 | wpa_printf(MSG_DEBUG, "P2P: GO - group %sidle", idle ? "" : "not "); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7185 | if (idle) { | 
|  | 7186 | if (wpa_s->global->p2p_fail_on_wps_complete && | 
|  | 7187 | wpa_s->p2p_in_provisioning) { | 
|  | 7188 | wpas_p2p_grpform_fail_after_wps(wpa_s); | 
|  | 7189 | return; | 
|  | 7190 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7191 | wpas_p2p_set_group_idle_timeout(wpa_s); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7192 | } else | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7193 | eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL); | 
|  | 7194 | } | 
|  | 7195 |  | 
|  | 7196 |  | 
|  | 7197 | struct p2p_group * wpas_p2p_group_init(struct wpa_supplicant *wpa_s, | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7198 | struct wpa_ssid *ssid) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7199 | { | 
|  | 7200 | struct p2p_group *group; | 
|  | 7201 | struct p2p_group_config *cfg; | 
|  | 7202 |  | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 7203 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL || | 
|  | 7204 | !ssid->p2p_group) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7205 | return NULL; | 
|  | 7206 |  | 
|  | 7207 | cfg = os_zalloc(sizeof(*cfg)); | 
|  | 7208 | if (cfg == NULL) | 
|  | 7209 | return NULL; | 
|  | 7210 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7211 | if (ssid->p2p_persistent_group && wpa_s->conf->persistent_reconnect) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7212 | cfg->persistent_group = 2; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7213 | else if (ssid->p2p_persistent_group) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7214 | cfg->persistent_group = 1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7215 | os_memcpy(cfg->interface_addr, wpa_s->own_addr, ETH_ALEN); | 
|  | 7216 | if (wpa_s->max_stations && | 
|  | 7217 | wpa_s->max_stations < wpa_s->conf->max_num_sta) | 
|  | 7218 | cfg->max_clients = wpa_s->max_stations; | 
|  | 7219 | else | 
|  | 7220 | cfg->max_clients = wpa_s->conf->max_num_sta; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7221 | os_memcpy(cfg->ssid, ssid->ssid, ssid->ssid_len); | 
|  | 7222 | cfg->ssid_len = ssid->ssid_len; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7223 | cfg->freq = ssid->frequency; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7224 | cfg->cb_ctx = wpa_s; | 
|  | 7225 | cfg->ie_update = wpas_p2p_ie_update; | 
|  | 7226 | cfg->idle_update = wpas_p2p_idle_update; | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7227 | cfg->ip_addr_alloc = WPA_GET_BE32(wpa_s->p2pdev->conf->ip_addr_start) | 
|  | 7228 | != 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7229 |  | 
|  | 7230 | group = p2p_group_init(wpa_s->global->p2p, cfg); | 
|  | 7231 | if (group == NULL) | 
|  | 7232 | os_free(cfg); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7233 | if (ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7234 | p2p_group_notif_formation_done(group); | 
|  | 7235 | wpa_s->p2p_group = group; | 
|  | 7236 | return group; | 
|  | 7237 | } | 
|  | 7238 |  | 
|  | 7239 |  | 
|  | 7240 | void wpas_p2p_wps_success(struct wpa_supplicant *wpa_s, const u8 *peer_addr, | 
|  | 7241 | int registrar) | 
|  | 7242 | { | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7243 | struct wpa_ssid *ssid = wpa_s->current_ssid; | 
|  | 7244 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7245 | if (!wpa_s->p2p_in_provisioning) { | 
|  | 7246 | wpa_printf(MSG_DEBUG, "P2P: Ignore WPS success event - P2P " | 
|  | 7247 | "provisioning not in progress"); | 
|  | 7248 | return; | 
|  | 7249 | } | 
|  | 7250 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7251 | if (ssid && ssid->mode == WPAS_MODE_INFRA) { | 
|  | 7252 | u8 go_dev_addr[ETH_ALEN]; | 
|  | 7253 | os_memcpy(go_dev_addr, wpa_s->bssid, ETH_ALEN); | 
|  | 7254 | wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid, | 
|  | 7255 | ssid->ssid_len); | 
|  | 7256 | /* Clear any stored provisioning info */ | 
|  | 7257 | p2p_clear_provisioning_info(wpa_s->global->p2p, go_dev_addr); | 
|  | 7258 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7259 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7260 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->p2pdev, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7261 | NULL); | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7262 | wpa_s->p2p_go_group_formation_completed = 1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7263 | if (ssid && ssid->mode == WPAS_MODE_INFRA) { | 
|  | 7264 | /* | 
|  | 7265 | * Use a separate timeout for initial data connection to | 
|  | 7266 | * complete to allow the group to be removed automatically if | 
|  | 7267 | * something goes wrong in this step before the P2P group idle | 
|  | 7268 | * timeout mechanism is taken into use. | 
|  | 7269 | */ | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7270 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 7271 | "P2P: Re-start group formation timeout (%d seconds) as client for initial connection", | 
|  | 7272 | P2P_MAX_INITIAL_CONN_WAIT); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7273 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0, | 
|  | 7274 | wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7275 | wpa_s->p2pdev, NULL); | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7276 | /* Complete group formation on successful data connection. */ | 
|  | 7277 | wpa_s->p2p_go_group_formation_completed = 0; | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7278 | } else if (ssid) { | 
|  | 7279 | /* | 
|  | 7280 | * Use a separate timeout for initial data connection to | 
|  | 7281 | * complete to allow the group to be removed automatically if | 
|  | 7282 | * the client does not complete data connection successfully. | 
|  | 7283 | */ | 
|  | 7284 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 7285 | "P2P: Re-start group formation timeout (%d seconds) as GO for initial connection", | 
|  | 7286 | P2P_MAX_INITIAL_CONN_WAIT_GO); | 
|  | 7287 | eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT_GO, 0, | 
|  | 7288 | wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7289 | wpa_s->p2pdev, NULL); | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7290 | /* | 
|  | 7291 | * Complete group formation on first successful data connection | 
|  | 7292 | */ | 
|  | 7293 | wpa_s->p2p_go_group_formation_completed = 0; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7294 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7295 | if (wpa_s->global->p2p) | 
|  | 7296 | p2p_wps_success_cb(wpa_s->global->p2p, peer_addr); | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 7297 | wpas_group_formation_completed(wpa_s, 1, 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7298 | } | 
|  | 7299 |  | 
|  | 7300 |  | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7301 | void wpas_p2p_wps_failed(struct wpa_supplicant *wpa_s, | 
|  | 7302 | struct wps_event_fail *fail) | 
|  | 7303 | { | 
|  | 7304 | if (!wpa_s->p2p_in_provisioning) { | 
|  | 7305 | wpa_printf(MSG_DEBUG, "P2P: Ignore WPS fail event - P2P " | 
|  | 7306 | "provisioning not in progress"); | 
|  | 7307 | return; | 
|  | 7308 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7309 |  | 
|  | 7310 | if (wpa_s->go_params) { | 
|  | 7311 | p2p_clear_provisioning_info( | 
|  | 7312 | wpa_s->global->p2p, | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7313 | wpa_s->go_params->peer_device_addr); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7314 | } | 
|  | 7315 |  | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7316 | wpas_notify_p2p_wps_failed(wpa_s, fail); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7317 |  | 
|  | 7318 | if (wpa_s == wpa_s->global->p2p_group_formation) { | 
|  | 7319 | /* | 
|  | 7320 | * Allow some time for the failed WPS negotiation exchange to | 
|  | 7321 | * complete, but remove the group since group formation cannot | 
|  | 7322 | * succeed after provisioning failure. | 
|  | 7323 | */ | 
|  | 7324 | wpa_printf(MSG_DEBUG, "P2P: WPS step failed during group formation - reject connection from timeout"); | 
|  | 7325 | wpa_s->global->p2p_fail_on_wps_complete = 1; | 
|  | 7326 | eloop_deplete_timeout(0, 50000, | 
|  | 7327 | wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7328 | wpa_s->p2pdev, NULL); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7329 | } | 
|  | 7330 | } | 
|  | 7331 |  | 
|  | 7332 |  | 
|  | 7333 | int wpas_p2p_wps_eapol_cb(struct wpa_supplicant *wpa_s) | 
|  | 7334 | { | 
|  | 7335 | if (!wpa_s->global->p2p_fail_on_wps_complete || | 
|  | 7336 | !wpa_s->p2p_in_provisioning) | 
|  | 7337 | return 0; | 
|  | 7338 |  | 
|  | 7339 | wpas_p2p_grpform_fail_after_wps(wpa_s); | 
|  | 7340 |  | 
|  | 7341 | return 1; | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7342 | } | 
|  | 7343 |  | 
|  | 7344 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7345 | 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] | 7346 | const char *config_method, | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7347 | enum wpas_p2p_prov_disc_use use, | 
|  | 7348 | struct p2ps_provision *p2ps_prov) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7349 | { | 
|  | 7350 | u16 config_methods; | 
|  | 7351 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7352 | wpa_s->global->pending_p2ps_group = 0; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7353 | wpa_s->global->pending_p2ps_group_freq = 0; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7354 | wpa_s->p2p_fallback_to_go_neg = 0; | 
|  | 7355 | wpa_s->pending_pd_use = NORMAL_PD; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7356 | if (p2ps_prov && use == WPAS_P2P_PD_FOR_ASP) { | 
|  | 7357 | p2ps_prov->conncap = p2ps_group_capability( | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7358 | wpa_s, P2PS_SETUP_NONE, p2ps_prov->role, | 
|  | 7359 | &p2ps_prov->force_freq, &p2ps_prov->pref_freq); | 
|  | 7360 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7361 | wpa_printf(MSG_DEBUG, | 
|  | 7362 | "P2P: %s conncap: %d - ASP parsed: %x %x %d %s", | 
|  | 7363 | __func__, p2ps_prov->conncap, | 
|  | 7364 | p2ps_prov->adv_id, p2ps_prov->conncap, | 
|  | 7365 | p2ps_prov->status, p2ps_prov->info); | 
|  | 7366 |  | 
|  | 7367 | config_methods = 0; | 
|  | 7368 | } else if (os_strncmp(config_method, "display", 7) == 0) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7369 | config_methods = WPS_CONFIG_DISPLAY; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7370 | else if (os_strncmp(config_method, "keypad", 6) == 0) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7371 | config_methods = WPS_CONFIG_KEYPAD; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7372 | else if (os_strncmp(config_method, "pbc", 3) == 0 || | 
|  | 7373 | os_strncmp(config_method, "pushbutton", 10) == 0) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7374 | config_methods = WPS_CONFIG_PUSHBUTTON; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7375 | else { | 
|  | 7376 | wpa_printf(MSG_DEBUG, "P2P: Unknown config method"); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7377 | os_free(p2ps_prov); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7378 | return -1; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7379 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7380 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7381 | if (use == WPAS_P2P_PD_AUTO) { | 
|  | 7382 | os_memcpy(wpa_s->pending_join_dev_addr, peer_addr, ETH_ALEN); | 
|  | 7383 | wpa_s->pending_pd_config_methods = config_methods; | 
|  | 7384 | wpa_s->p2p_auto_pd = 1; | 
|  | 7385 | wpa_s->p2p_auto_join = 0; | 
|  | 7386 | wpa_s->pending_pd_before_join = 0; | 
|  | 7387 | wpa_s->auto_pd_scan_retry = 0; | 
|  | 7388 | wpas_p2p_stop_find(wpa_s); | 
|  | 7389 | wpa_s->p2p_join_scan_count = 0; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7390 | os_get_reltime(&wpa_s->p2p_auto_started); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7391 | wpa_printf(MSG_DEBUG, "P2P: Auto PD started at %ld.%06ld", | 
|  | 7392 | wpa_s->p2p_auto_started.sec, | 
|  | 7393 | wpa_s->p2p_auto_started.usec); | 
|  | 7394 | wpas_p2p_join_scan(wpa_s, NULL); | 
|  | 7395 | return 0; | 
|  | 7396 | } | 
|  | 7397 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7398 | if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) { | 
|  | 7399 | os_free(p2ps_prov); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7400 | return -1; | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7401 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7402 |  | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7403 | 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] | 7404 | config_methods, use == WPAS_P2P_PD_FOR_JOIN, | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7405 | 0, 1); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7406 | } | 
|  | 7407 |  | 
|  | 7408 |  | 
|  | 7409 | int wpas_p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf, | 
|  | 7410 | char *end) | 
|  | 7411 | { | 
|  | 7412 | return p2p_scan_result_text(ies, ies_len, buf, end); | 
|  | 7413 | } | 
|  | 7414 |  | 
|  | 7415 |  | 
|  | 7416 | static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant *wpa_s) | 
|  | 7417 | { | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7418 | if (!offchannel_pending_action_tx(wpa_s)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7419 | return; | 
|  | 7420 |  | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 7421 | if (wpa_s->p2p_send_action_work) { | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7422 | wpas_p2p_free_send_action_work(wpa_s); | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 7423 | eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, | 
|  | 7424 | wpa_s, NULL); | 
|  | 7425 | offchannel_send_action_done(wpa_s); | 
|  | 7426 | } | 
| Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 7427 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7428 | wpa_printf(MSG_DEBUG, "P2P: Drop pending Action TX due to new " | 
|  | 7429 | "operation request"); | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7430 | offchannel_clear_pending_action_tx(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7431 | } | 
|  | 7432 |  | 
|  | 7433 |  | 
|  | 7434 | int wpas_p2p_find(struct wpa_supplicant *wpa_s, unsigned int timeout, | 
|  | 7435 | enum p2p_discovery_type type, | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7436 | unsigned int num_req_dev_types, const u8 *req_dev_types, | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7437 | const u8 *dev_id, unsigned int search_delay, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7438 | u8 seek_cnt, const char **seek_string, int freq, | 
|  | 7439 | bool include_6ghz) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7440 | { | 
|  | 7441 | wpas_p2p_clear_pending_action_tx(wpa_s); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7442 | wpa_s->global->p2p_long_listen = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7443 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7444 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL || | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7445 | wpa_s->p2p_in_provisioning) { | 
|  | 7446 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Reject p2p_find operation%s%s", | 
|  | 7447 | (wpa_s->global->p2p_disabled || !wpa_s->global->p2p) ? | 
|  | 7448 | " (P2P disabled)" : "", | 
|  | 7449 | wpa_s->p2p_in_provisioning ? | 
|  | 7450 | " (p2p_in_provisioning)" : ""); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7451 | return -1; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7452 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7453 |  | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7454 | wpa_supplicant_cancel_sched_scan(wpa_s); | 
|  | 7455 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7456 | return p2p_find(wpa_s->global->p2p, timeout, type, | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7457 | num_req_dev_types, req_dev_types, dev_id, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7458 | search_delay, seek_cnt, seek_string, freq, | 
|  | 7459 | include_6ghz); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7460 | } | 
|  | 7461 |  | 
|  | 7462 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7463 | static void wpas_p2p_scan_res_ignore_search(struct wpa_supplicant *wpa_s, | 
|  | 7464 | struct wpa_scan_results *scan_res) | 
|  | 7465 | { | 
|  | 7466 | wpa_printf(MSG_DEBUG, "P2P: Ignore scan results"); | 
|  | 7467 |  | 
|  | 7468 | if (wpa_s->p2p_scan_work) { | 
|  | 7469 | struct wpa_radio_work *work = wpa_s->p2p_scan_work; | 
|  | 7470 | wpa_s->p2p_scan_work = NULL; | 
|  | 7471 | radio_work_done(work); | 
|  | 7472 | } | 
|  | 7473 |  | 
|  | 7474 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 7475 | return; | 
|  | 7476 |  | 
|  | 7477 | /* | 
|  | 7478 | * Indicate that results have been processed so that the P2P module can | 
|  | 7479 | * continue pending tasks. | 
|  | 7480 | */ | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 7481 | wpas_p2p_scan_res_handled(wpa_s); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7482 | } | 
|  | 7483 |  | 
|  | 7484 |  | 
|  | 7485 | static void wpas_p2p_stop_find_oper(struct wpa_supplicant *wpa_s) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7486 | { | 
|  | 7487 | wpas_p2p_clear_pending_action_tx(wpa_s); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7488 | wpa_s->global->p2p_long_listen = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7489 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); | 
|  | 7490 | eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7491 |  | 
|  | 7492 | if (wpa_s->global->p2p) | 
|  | 7493 | p2p_stop_find(wpa_s->global->p2p); | 
|  | 7494 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7495 | if (wpa_s->scan_res_handler == wpas_p2p_scan_res_handler) { | 
|  | 7496 | wpa_printf(MSG_DEBUG, | 
|  | 7497 | "P2P: Do not consider the scan results after stop_find"); | 
|  | 7498 | wpa_s->scan_res_handler = wpas_p2p_scan_res_ignore_search; | 
|  | 7499 | } | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7500 | } | 
|  | 7501 |  | 
|  | 7502 |  | 
|  | 7503 | void wpas_p2p_stop_find(struct wpa_supplicant *wpa_s) | 
|  | 7504 | { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7505 | wpas_p2p_stop_find_oper(wpa_s); | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 7506 | if (!wpa_s->global->pending_group_iface_for_p2ps) | 
|  | 7507 | wpas_p2p_remove_pending_group_interface(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7508 | } | 
|  | 7509 |  | 
|  | 7510 |  | 
|  | 7511 | static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx) | 
|  | 7512 | { | 
|  | 7513 | struct wpa_supplicant *wpa_s = eloop_ctx; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7514 | wpa_s->global->p2p_long_listen = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7515 | } | 
|  | 7516 |  | 
|  | 7517 |  | 
|  | 7518 | int wpas_p2p_listen(struct wpa_supplicant *wpa_s, unsigned int timeout) | 
|  | 7519 | { | 
|  | 7520 | int res; | 
|  | 7521 |  | 
|  | 7522 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 7523 | return -1; | 
|  | 7524 |  | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 7525 | if (wpa_s->p2p_lo_started) { | 
|  | 7526 | wpa_printf(MSG_DEBUG, | 
|  | 7527 | "P2P: Cannot start P2P listen, it is offloaded"); | 
|  | 7528 | return -1; | 
|  | 7529 | } | 
|  | 7530 |  | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7531 | wpa_supplicant_cancel_sched_scan(wpa_s); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7532 | wpas_p2p_clear_pending_action_tx(wpa_s); | 
|  | 7533 |  | 
|  | 7534 | if (timeout == 0) { | 
|  | 7535 | /* | 
|  | 7536 | * This is a request for unlimited Listen state. However, at | 
|  | 7537 | * least for now, this is mapped to a Listen state for one | 
|  | 7538 | * hour. | 
|  | 7539 | */ | 
|  | 7540 | timeout = 3600; | 
|  | 7541 | } | 
|  | 7542 | eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7543 | wpa_s->global->p2p_long_listen = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7544 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7545 | /* | 
|  | 7546 | * Stop previous find/listen operation to avoid trying to request a new | 
|  | 7547 | * remain-on-channel operation while the driver is still running the | 
|  | 7548 | * previous one. | 
|  | 7549 | */ | 
|  | 7550 | if (wpa_s->global->p2p) | 
|  | 7551 | p2p_stop_find(wpa_s->global->p2p); | 
|  | 7552 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7553 | res = wpas_p2p_listen_start(wpa_s, timeout * 1000); | 
|  | 7554 | if (res == 0 && timeout * 1000 > wpa_s->max_remain_on_chan) { | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7555 | wpa_s->global->p2p_long_listen = timeout * 1000; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7556 | eloop_register_timeout(timeout, 0, | 
|  | 7557 | wpas_p2p_long_listen_timeout, | 
|  | 7558 | wpa_s, NULL); | 
|  | 7559 | } | 
|  | 7560 |  | 
|  | 7561 | return res; | 
|  | 7562 | } | 
|  | 7563 |  | 
|  | 7564 |  | 
|  | 7565 | int wpas_p2p_assoc_req_ie(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, | 
|  | 7566 | u8 *buf, size_t len, int p2p_group) | 
|  | 7567 | { | 
|  | 7568 | struct wpabuf *p2p_ie; | 
|  | 7569 | int ret; | 
|  | 7570 |  | 
|  | 7571 | if (wpa_s->global->p2p_disabled) | 
|  | 7572 | return -1; | 
| Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 7573 | /* | 
|  | 7574 | * Advertize mandatory cross connection capability even on | 
|  | 7575 | * p2p_disabled=1 interface when associating with a P2P Manager WLAN AP. | 
|  | 7576 | */ | 
|  | 7577 | if (wpa_s->conf->p2p_disabled && p2p_group) | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7578 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7579 | if (wpa_s->global->p2p == NULL) | 
|  | 7580 | return -1; | 
|  | 7581 | if (bss == NULL) | 
|  | 7582 | return -1; | 
|  | 7583 |  | 
|  | 7584 | p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE); | 
|  | 7585 | ret = p2p_assoc_req_ie(wpa_s->global->p2p, bss->bssid, buf, len, | 
|  | 7586 | p2p_group, p2p_ie); | 
|  | 7587 | wpabuf_free(p2p_ie); | 
|  | 7588 |  | 
|  | 7589 | return ret; | 
|  | 7590 | } | 
|  | 7591 |  | 
|  | 7592 |  | 
|  | 7593 | 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] | 7594 | const u8 *dst, const u8 *bssid, | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 7595 | const u8 *ie, size_t ie_len, | 
|  | 7596 | unsigned int rx_freq, int ssi_signal) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7597 | { | 
|  | 7598 | if (wpa_s->global->p2p_disabled) | 
|  | 7599 | return 0; | 
|  | 7600 | if (wpa_s->global->p2p == NULL) | 
|  | 7601 | return 0; | 
|  | 7602 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7603 | switch (p2p_probe_req_rx(wpa_s->global->p2p, addr, dst, bssid, | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 7604 | ie, ie_len, rx_freq, wpa_s->p2p_lo_started)) { | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7605 | case P2P_PREQ_NOT_P2P: | 
|  | 7606 | wpas_notify_preq(wpa_s, addr, dst, bssid, ie, ie_len, | 
|  | 7607 | ssi_signal); | 
|  | 7608 | /* fall through */ | 
|  | 7609 | case P2P_PREQ_MALFORMED: | 
|  | 7610 | case P2P_PREQ_NOT_LISTEN: | 
|  | 7611 | case P2P_PREQ_NOT_PROCESSED: | 
|  | 7612 | default: /* make gcc happy */ | 
|  | 7613 | return 0; | 
|  | 7614 | case P2P_PREQ_PROCESSED: | 
|  | 7615 | return 1; | 
|  | 7616 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7617 | } | 
|  | 7618 |  | 
|  | 7619 |  | 
|  | 7620 | void wpas_p2p_rx_action(struct wpa_supplicant *wpa_s, const u8 *da, | 
|  | 7621 | const u8 *sa, const u8 *bssid, | 
|  | 7622 | u8 category, const u8 *data, size_t len, int freq) | 
|  | 7623 | { | 
|  | 7624 | if (wpa_s->global->p2p_disabled) | 
|  | 7625 | return; | 
|  | 7626 | if (wpa_s->global->p2p == NULL) | 
|  | 7627 | return; | 
|  | 7628 |  | 
|  | 7629 | p2p_rx_action(wpa_s->global->p2p, da, sa, bssid, category, data, len, | 
|  | 7630 | freq); | 
|  | 7631 | } | 
|  | 7632 |  | 
|  | 7633 |  | 
|  | 7634 | void wpas_p2p_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ies) | 
|  | 7635 | { | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7636 | unsigned int bands; | 
|  | 7637 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7638 | if (wpa_s->global->p2p_disabled) | 
|  | 7639 | return; | 
|  | 7640 | if (wpa_s->global->p2p == NULL) | 
|  | 7641 | return; | 
|  | 7642 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7643 | bands = wpas_get_bands(wpa_s, NULL); | 
|  | 7644 | p2p_scan_ie(wpa_s->global->p2p, ies, NULL, bands); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7645 | } | 
|  | 7646 |  | 
|  | 7647 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7648 | static void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7649 | { | 
|  | 7650 | p2p_group_deinit(wpa_s->p2p_group); | 
|  | 7651 | wpa_s->p2p_group = NULL; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7652 |  | 
|  | 7653 | wpa_s->ap_configured_cb = NULL; | 
|  | 7654 | wpa_s->ap_configured_cb_ctx = NULL; | 
|  | 7655 | wpa_s->ap_configured_cb_data = NULL; | 
|  | 7656 | wpa_s->connect_without_scan = NULL; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7657 | } | 
|  | 7658 |  | 
|  | 7659 |  | 
|  | 7660 | int wpas_p2p_reject(struct wpa_supplicant *wpa_s, const u8 *addr) | 
|  | 7661 | { | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7662 | wpa_s->global->p2p_long_listen = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7663 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7664 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 7665 | return -1; | 
|  | 7666 |  | 
|  | 7667 | return p2p_reject(wpa_s->global->p2p, addr); | 
|  | 7668 | } | 
|  | 7669 |  | 
|  | 7670 |  | 
|  | 7671 | /* Invite to reinvoke a persistent group */ | 
|  | 7672 | 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] | 7673 | struct wpa_ssid *ssid, const u8 *go_dev_addr, int freq, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7674 | int vht_center_freq2, int ht40, int vht, int max_chwidth, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7675 | int pref_freq, int he, int edmg, bool allow_6ghz) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7676 | { | 
|  | 7677 | enum p2p_invite_role role; | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7678 | u8 *bssid = NULL; | 
|  | 7679 | int force_freq = 0; | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7680 | int res; | 
| Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 7681 | int no_pref_freq_given = pref_freq == 0; | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 7682 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; | 
|  | 7683 | unsigned int size; | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7684 |  | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7685 | if (wpas_p2p_check_6ghz(wpa_s, NULL, allow_6ghz, freq)) | 
|  | 7686 | return -1; | 
|  | 7687 |  | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7688 | wpa_s->global->p2p_invite_group = NULL; | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7689 | if (peer_addr) | 
|  | 7690 | os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN); | 
|  | 7691 | else | 
|  | 7692 | os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7693 |  | 
| Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 7694 | wpa_s->p2p_persistent_go_freq = freq; | 
|  | 7695 | wpa_s->p2p_go_ht40 = !!ht40; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7696 | wpa_s->p2p_go_vht = !!vht; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7697 | wpa_s->p2p_go_he = !!he; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7698 | wpa_s->p2p_go_max_oper_chwidth = max_chwidth; | 
|  | 7699 | wpa_s->p2p_go_vht_center_freq2 = vht_center_freq2; | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7700 | wpa_s->p2p_go_edmg = !!edmg; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7701 | if (ssid->mode == WPAS_MODE_P2P_GO) { | 
|  | 7702 | role = P2P_INVITE_ROLE_GO; | 
|  | 7703 | if (peer_addr == NULL) { | 
|  | 7704 | wpa_printf(MSG_DEBUG, "P2P: Missing peer " | 
|  | 7705 | "address in invitation command"); | 
|  | 7706 | return -1; | 
|  | 7707 | } | 
|  | 7708 | if (wpas_p2p_create_iface(wpa_s)) { | 
|  | 7709 | if (wpas_p2p_add_group_interface(wpa_s, | 
|  | 7710 | WPA_IF_P2P_GO) < 0) { | 
|  | 7711 | wpa_printf(MSG_ERROR, "P2P: Failed to " | 
|  | 7712 | "allocate a new interface for the " | 
|  | 7713 | "group"); | 
|  | 7714 | return -1; | 
|  | 7715 | } | 
|  | 7716 | bssid = wpa_s->pending_interface_addr; | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7717 | } else if (wpa_s->p2p_mgmt) | 
|  | 7718 | bssid = wpa_s->parent->own_addr; | 
|  | 7719 | else | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7720 | bssid = wpa_s->own_addr; | 
|  | 7721 | } else { | 
|  | 7722 | role = P2P_INVITE_ROLE_CLIENT; | 
|  | 7723 | peer_addr = ssid->bssid; | 
|  | 7724 | } | 
|  | 7725 | wpa_s->pending_invite_ssid_id = ssid->id; | 
|  | 7726 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7727 | size = P2P_MAX_PREF_CHANNELS; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7728 | res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7729 | role == P2P_INVITE_ROLE_GO, | 
|  | 7730 | pref_freq_list, &size); | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7731 | if (res) | 
|  | 7732 | return res; | 
| Irfan Sheriff | af84a57 | 2012-09-22 16:59:30 -0700 | [diff] [blame] | 7733 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7734 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 7735 | return -1; | 
|  | 7736 |  | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 7737 | p2p_set_own_pref_freq_list(wpa_s->global->p2p, pref_freq_list, size); | 
|  | 7738 |  | 
| Dmitry Shmidt | a0d265f | 2013-11-19 13:13:41 -0800 | [diff] [blame] | 7739 | if (wpa_s->parent->conf->p2p_ignore_shared_freq && | 
|  | 7740 | no_pref_freq_given && pref_freq > 0 && | 
|  | 7741 | wpa_s->num_multichan_concurrent > 1 && | 
|  | 7742 | wpas_p2p_num_unused_channels(wpa_s) > 0) { | 
|  | 7743 | wpa_printf(MSG_DEBUG, "P2P: Ignore own channel preference %d MHz for invitation due to p2p_ignore_shared_freq=1 configuration", | 
|  | 7744 | pref_freq); | 
|  | 7745 | pref_freq = 0; | 
|  | 7746 | } | 
|  | 7747 |  | 
| Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7748 | /* | 
|  | 7749 | * Stop any find/listen operations before invitation and possibly | 
|  | 7750 | * connection establishment. | 
|  | 7751 | */ | 
|  | 7752 | wpas_p2p_stop_find_oper(wpa_s); | 
|  | 7753 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7754 | return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid, | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7755 | ssid->ssid, ssid->ssid_len, force_freq, go_dev_addr, | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7756 | 1, pref_freq, -1); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7757 | } | 
|  | 7758 |  | 
|  | 7759 |  | 
|  | 7760 | /* Invite to join an active group */ | 
|  | 7761 | int wpas_p2p_invite_group(struct wpa_supplicant *wpa_s, const char *ifname, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7762 | const u8 *peer_addr, const u8 *go_dev_addr, | 
|  | 7763 | bool allow_6ghz) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7764 | { | 
|  | 7765 | struct wpa_global *global = wpa_s->global; | 
|  | 7766 | enum p2p_invite_role role; | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7767 | u8 *bssid = NULL; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7768 | struct wpa_ssid *ssid; | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7769 | int persistent; | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7770 | int freq = 0, force_freq = 0, pref_freq = 0; | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7771 | int res; | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 7772 | struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS]; | 
|  | 7773 | unsigned int size; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7774 |  | 
| Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 7775 | wpa_s->p2p_persistent_go_freq = 0; | 
|  | 7776 | wpa_s->p2p_go_ht40 = 0; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7777 | wpa_s->p2p_go_vht = 0; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7778 | wpa_s->p2p_go_vht_center_freq2 = 0; | 
|  | 7779 | wpa_s->p2p_go_max_oper_chwidth = 0; | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7780 | wpa_s->p2p_go_edmg = 0; | 
| Jouni Malinen | 31be0a4 | 2012-08-31 21:20:51 +0300 | [diff] [blame] | 7781 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7782 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 7783 | if (os_strcmp(wpa_s->ifname, ifname) == 0) | 
|  | 7784 | break; | 
|  | 7785 | } | 
|  | 7786 | if (wpa_s == NULL) { | 
|  | 7787 | wpa_printf(MSG_DEBUG, "P2P: Interface '%s' not found", ifname); | 
|  | 7788 | return -1; | 
|  | 7789 | } | 
|  | 7790 |  | 
|  | 7791 | ssid = wpa_s->current_ssid; | 
|  | 7792 | if (ssid == NULL) { | 
|  | 7793 | wpa_printf(MSG_DEBUG, "P2P: No current SSID to use for " | 
|  | 7794 | "invitation"); | 
|  | 7795 | return -1; | 
|  | 7796 | } | 
|  | 7797 |  | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7798 | wpa_s->global->p2p_invite_group = wpa_s; | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7799 | persistent = ssid->p2p_persistent_group && | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7800 | wpas_p2p_get_persistent(wpa_s->p2pdev, peer_addr, | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7801 | ssid->ssid, ssid->ssid_len); | 
|  | 7802 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7803 | if (ssid->mode == WPAS_MODE_P2P_GO) { | 
|  | 7804 | role = P2P_INVITE_ROLE_ACTIVE_GO; | 
|  | 7805 | bssid = wpa_s->own_addr; | 
|  | 7806 | if (go_dev_addr == NULL) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7807 | go_dev_addr = wpa_s->global->p2p_dev_addr; | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7808 | freq = ssid->frequency; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7809 | } else { | 
|  | 7810 | role = P2P_INVITE_ROLE_CLIENT; | 
|  | 7811 | if (wpa_s->wpa_state < WPA_ASSOCIATED) { | 
|  | 7812 | wpa_printf(MSG_DEBUG, "P2P: Not associated - cannot " | 
|  | 7813 | "invite to current group"); | 
|  | 7814 | return -1; | 
|  | 7815 | } | 
|  | 7816 | bssid = wpa_s->bssid; | 
|  | 7817 | if (go_dev_addr == NULL && | 
|  | 7818 | !is_zero_ether_addr(wpa_s->go_dev_addr)) | 
|  | 7819 | go_dev_addr = wpa_s->go_dev_addr; | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7820 | freq = wpa_s->current_bss ? wpa_s->current_bss->freq : | 
|  | 7821 | (int) wpa_s->assoc_freq; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7822 | } | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7823 | wpa_s->p2pdev->pending_invite_ssid_id = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7824 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7825 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 7826 | return -1; | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7827 | if (wpas_p2p_check_6ghz(wpa_s, peer_addr, allow_6ghz, freq)) | 
|  | 7828 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7829 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7830 | size = P2P_MAX_PREF_CHANNELS; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7831 | res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7832 | role == P2P_INVITE_ROLE_ACTIVE_GO, | 
|  | 7833 | pref_freq_list, &size); | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7834 | if (res) | 
|  | 7835 | return res; | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7836 | wpas_p2p_set_own_freq_preference(wpa_s, force_freq); | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7837 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7838 | return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid, | 
| Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 7839 | ssid->ssid, ssid->ssid_len, force_freq, | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7840 | go_dev_addr, persistent, pref_freq, -1); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7841 | } | 
|  | 7842 |  | 
|  | 7843 |  | 
|  | 7844 | void wpas_p2p_completed(struct wpa_supplicant *wpa_s) | 
|  | 7845 | { | 
|  | 7846 | struct wpa_ssid *ssid = wpa_s->current_ssid; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7847 | u8 go_dev_addr[ETH_ALEN]; | 
|  | 7848 | int persistent; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7849 | int freq; | 
| Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 7850 | u8 ip[3 * 4], *ip_ptr = NULL; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7851 | char ip_addr[100]; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7852 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7853 | if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION) { | 
|  | 7854 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7855 | wpa_s->p2pdev, NULL); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7856 | } | 
|  | 7857 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7858 | if (!wpa_s->show_group_started || !ssid) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7859 | return; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7860 |  | 
|  | 7861 | wpa_s->show_group_started = 0; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7862 | if (!wpa_s->p2p_go_group_formation_completed && | 
|  | 7863 | wpa_s->global->p2p_group_formation == wpa_s) { | 
|  | 7864 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 7865 | "P2P: Marking group formation completed on client on data connection"); | 
|  | 7866 | wpa_s->p2p_go_group_formation_completed = 1; | 
|  | 7867 | wpa_s->global->p2p_group_formation = NULL; | 
|  | 7868 | wpa_s->p2p_in_provisioning = 0; | 
|  | 7869 | wpa_s->p2p_in_invitation = 0; | 
|  | 7870 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7871 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7872 | os_memset(go_dev_addr, 0, ETH_ALEN); | 
|  | 7873 | if (ssid->bssid_set) | 
|  | 7874 | os_memcpy(go_dev_addr, ssid->bssid, ETH_ALEN); | 
|  | 7875 | persistent = wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid, | 
|  | 7876 | ssid->ssid_len); | 
|  | 7877 | os_memcpy(wpa_s->go_dev_addr, go_dev_addr, ETH_ALEN); | 
|  | 7878 |  | 
|  | 7879 | if (wpa_s->global->p2p_group_formation == wpa_s) | 
|  | 7880 | wpa_s->global->p2p_group_formation = NULL; | 
|  | 7881 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7882 | freq = wpa_s->current_bss ? wpa_s->current_bss->freq : | 
|  | 7883 | (int) wpa_s->assoc_freq; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7884 |  | 
|  | 7885 | ip_addr[0] = '\0'; | 
|  | 7886 | if (wpa_sm_get_p2p_ip_addr(wpa_s->wpa, ip) == 0) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7887 | int res; | 
|  | 7888 |  | 
|  | 7889 | res = os_snprintf(ip_addr, sizeof(ip_addr), | 
|  | 7890 | " ip_addr=%u.%u.%u.%u " | 
|  | 7891 | "ip_mask=%u.%u.%u.%u go_ip_addr=%u.%u.%u.%u", | 
|  | 7892 | ip[0], ip[1], ip[2], ip[3], | 
|  | 7893 | ip[4], ip[5], ip[6], ip[7], | 
|  | 7894 | ip[8], ip[9], ip[10], ip[11]); | 
|  | 7895 | if (os_snprintf_error(sizeof(ip_addr), res)) | 
|  | 7896 | ip_addr[0] = '\0'; | 
| Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 7897 | ip_ptr = ip; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 7898 | } | 
|  | 7899 |  | 
| Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 7900 | wpas_p2p_group_started(wpa_s, 0, ssid, freq, | 
|  | 7901 | ssid->passphrase == NULL && ssid->psk_set ? | 
|  | 7902 | ssid->psk : NULL, | 
|  | 7903 | ssid->passphrase, go_dev_addr, persistent, | 
|  | 7904 | ip_addr); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7905 |  | 
|  | 7906 | if (persistent) | 
| Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 7907 | wpas_p2p_store_persistent_group(wpa_s->p2pdev, | 
|  | 7908 | ssid, go_dev_addr); | 
|  | 7909 |  | 
| Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 7910 | wpas_notify_p2p_group_started(wpa_s, ssid, persistent, 1, ip_ptr); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7911 | } | 
|  | 7912 |  | 
|  | 7913 |  | 
|  | 7914 | int wpas_p2p_presence_req(struct wpa_supplicant *wpa_s, u32 duration1, | 
|  | 7915 | u32 interval1, u32 duration2, u32 interval2) | 
|  | 7916 | { | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7917 | int ret; | 
|  | 7918 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7919 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 7920 | return -1; | 
|  | 7921 |  | 
|  | 7922 | if (wpa_s->wpa_state < WPA_ASSOCIATED || | 
|  | 7923 | wpa_s->current_ssid == NULL || | 
|  | 7924 | wpa_s->current_ssid->mode != WPAS_MODE_INFRA) | 
|  | 7925 | return -1; | 
|  | 7926 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7927 | ret = p2p_presence_req(wpa_s->global->p2p, wpa_s->bssid, | 
|  | 7928 | wpa_s->own_addr, wpa_s->assoc_freq, | 
|  | 7929 | duration1, interval1, duration2, interval2); | 
|  | 7930 | if (ret == 0) | 
|  | 7931 | wpa_s->waiting_presence_resp = 1; | 
|  | 7932 |  | 
|  | 7933 | return ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7934 | } | 
|  | 7935 |  | 
|  | 7936 |  | 
|  | 7937 | int wpas_p2p_ext_listen(struct wpa_supplicant *wpa_s, unsigned int period, | 
|  | 7938 | unsigned int interval) | 
|  | 7939 | { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7940 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 7941 | return -1; | 
|  | 7942 |  | 
|  | 7943 | return p2p_ext_listen(wpa_s->global->p2p, period, interval); | 
|  | 7944 | } | 
|  | 7945 |  | 
|  | 7946 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7947 | static int wpas_p2p_is_client(struct wpa_supplicant *wpa_s) | 
|  | 7948 | { | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 7949 | if (wpa_s->current_ssid == NULL) { | 
|  | 7950 | /* | 
|  | 7951 | * current_ssid can be cleared when P2P client interface gets | 
|  | 7952 | * disconnected, so assume this interface was used as P2P | 
|  | 7953 | * client. | 
|  | 7954 | */ | 
|  | 7955 | return 1; | 
|  | 7956 | } | 
|  | 7957 | return wpa_s->current_ssid->p2p_group && | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7958 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA; | 
|  | 7959 | } | 
|  | 7960 |  | 
|  | 7961 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7962 | static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx) | 
|  | 7963 | { | 
|  | 7964 | struct wpa_supplicant *wpa_s = eloop_ctx; | 
|  | 7965 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7966 | 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] | 7967 | wpa_printf(MSG_DEBUG, "P2P: Ignore group idle timeout - " | 
|  | 7968 | "disabled"); | 
|  | 7969 | return; | 
|  | 7970 | } | 
|  | 7971 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7972 | wpa_printf(MSG_DEBUG, "P2P: Group idle timeout reached - terminate " | 
|  | 7973 | "group"); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7974 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_IDLE_TIMEOUT); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7975 | } | 
|  | 7976 |  | 
|  | 7977 |  | 
|  | 7978 | static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s) | 
|  | 7979 | { | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7980 | int timeout; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7981 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7982 | if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0) | 
|  | 7983 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout"); | 
|  | 7984 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7985 | if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group) | 
|  | 7986 | return; | 
|  | 7987 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7988 | timeout = wpa_s->conf->p2p_group_idle; | 
|  | 7989 | if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA && | 
|  | 7990 | (timeout == 0 || timeout > P2P_MAX_CLIENT_IDLE)) | 
|  | 7991 | timeout = P2P_MAX_CLIENT_IDLE; | 
|  | 7992 |  | 
|  | 7993 | if (timeout == 0) | 
|  | 7994 | return; | 
|  | 7995 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7996 | if (timeout < 0) { | 
|  | 7997 | if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA) | 
|  | 7998 | timeout = 0; /* special client mode no-timeout */ | 
|  | 7999 | else | 
|  | 8000 | return; | 
|  | 8001 | } | 
|  | 8002 |  | 
|  | 8003 | if (wpa_s->p2p_in_provisioning) { | 
|  | 8004 | /* | 
|  | 8005 | * Use the normal group formation timeout during the | 
|  | 8006 | * provisioning phase to avoid terminating this process too | 
|  | 8007 | * early due to group idle timeout. | 
|  | 8008 | */ | 
|  | 8009 | wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout " | 
|  | 8010 | "during provisioning"); | 
|  | 8011 | return; | 
|  | 8012 | } | 
| Deepthi Gowri | 9e4e8ac | 2013-04-16 11:57:05 +0530 | [diff] [blame] | 8013 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8014 | if (wpa_s->show_group_started) { | 
|  | 8015 | /* | 
|  | 8016 | * Use the normal group formation timeout between the end of | 
|  | 8017 | * the provisioning phase and completion of 4-way handshake to | 
|  | 8018 | * avoid terminating this process too early due to group idle | 
|  | 8019 | * timeout. | 
|  | 8020 | */ | 
|  | 8021 | wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout " | 
|  | 8022 | "while waiting for initial 4-way handshake to " | 
|  | 8023 | "complete"); | 
|  | 8024 | return; | 
|  | 8025 | } | 
|  | 8026 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8027 | 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] | 8028 | timeout); | 
|  | 8029 | eloop_register_timeout(timeout, 0, wpas_p2p_group_idle_timeout, | 
|  | 8030 | wpa_s, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8031 | } | 
|  | 8032 |  | 
|  | 8033 |  | 
| Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8034 | /* Returns 1 if the interface was removed */ | 
|  | 8035 | int wpas_p2p_deauth_notif(struct wpa_supplicant *wpa_s, const u8 *bssid, | 
|  | 8036 | u16 reason_code, const u8 *ie, size_t ie_len, | 
|  | 8037 | int locally_generated) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8038 | { | 
|  | 8039 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
| Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8040 | return 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8041 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8042 | if (!locally_generated) | 
|  | 8043 | p2p_deauth_notif(wpa_s->global->p2p, bssid, reason_code, ie, | 
|  | 8044 | ie_len); | 
|  | 8045 |  | 
|  | 8046 | if (reason_code == WLAN_REASON_DEAUTH_LEAVING && !locally_generated && | 
|  | 8047 | wpa_s->current_ssid && | 
|  | 8048 | wpa_s->current_ssid->p2p_group && | 
|  | 8049 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA) { | 
|  | 8050 | wpa_printf(MSG_DEBUG, "P2P: GO indicated that the P2P Group " | 
|  | 8051 | "session is ending"); | 
| Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8052 | if (wpas_p2p_group_delete(wpa_s, | 
|  | 8053 | P2P_GROUP_REMOVAL_GO_ENDING_SESSION) | 
|  | 8054 | > 0) | 
|  | 8055 | return 1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8056 | } | 
| Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8057 |  | 
|  | 8058 | return 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8059 | } | 
|  | 8060 |  | 
|  | 8061 |  | 
|  | 8062 | 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] | 8063 | u16 reason_code, const u8 *ie, size_t ie_len, | 
|  | 8064 | int locally_generated) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8065 | { | 
|  | 8066 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 8067 | return; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8068 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8069 | if (!locally_generated) | 
|  | 8070 | p2p_disassoc_notif(wpa_s->global->p2p, bssid, reason_code, ie, | 
|  | 8071 | ie_len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8072 | } | 
|  | 8073 |  | 
|  | 8074 |  | 
|  | 8075 | void wpas_p2p_update_config(struct wpa_supplicant *wpa_s) | 
|  | 8076 | { | 
|  | 8077 | struct p2p_data *p2p = wpa_s->global->p2p; | 
|  | 8078 |  | 
|  | 8079 | if (p2p == NULL) | 
|  | 8080 | return; | 
|  | 8081 |  | 
|  | 8082 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE)) | 
|  | 8083 | return; | 
|  | 8084 |  | 
|  | 8085 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_NAME) | 
|  | 8086 | p2p_set_dev_name(p2p, wpa_s->conf->device_name); | 
|  | 8087 |  | 
|  | 8088 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_TYPE) | 
|  | 8089 | p2p_set_pri_dev_type(p2p, wpa_s->conf->device_type); | 
|  | 8090 |  | 
|  | 8091 | if (wpa_s->wps && | 
|  | 8092 | (wpa_s->conf->changed_parameters & CFG_CHANGED_CONFIG_METHODS)) | 
|  | 8093 | p2p_set_config_methods(p2p, wpa_s->wps->config_methods); | 
|  | 8094 |  | 
|  | 8095 | if (wpa_s->wps && (wpa_s->conf->changed_parameters & CFG_CHANGED_UUID)) | 
|  | 8096 | p2p_set_uuid(p2p, wpa_s->wps->uuid); | 
|  | 8097 |  | 
|  | 8098 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_WPS_STRING) { | 
|  | 8099 | p2p_set_manufacturer(p2p, wpa_s->conf->manufacturer); | 
|  | 8100 | p2p_set_model_name(p2p, wpa_s->conf->model_name); | 
|  | 8101 | p2p_set_model_number(p2p, wpa_s->conf->model_number); | 
|  | 8102 | p2p_set_serial_number(p2p, wpa_s->conf->serial_number); | 
|  | 8103 | } | 
|  | 8104 |  | 
|  | 8105 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_SEC_DEVICE_TYPE) | 
|  | 8106 | p2p_set_sec_dev_types(p2p, | 
|  | 8107 | (void *) wpa_s->conf->sec_device_type, | 
|  | 8108 | wpa_s->conf->num_sec_device_types); | 
|  | 8109 |  | 
|  | 8110 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_VENDOR_EXTENSION) { | 
|  | 8111 | int i; | 
|  | 8112 | p2p_remove_wps_vendor_extensions(p2p); | 
|  | 8113 | for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) { | 
|  | 8114 | if (wpa_s->conf->wps_vendor_ext[i] == NULL) | 
|  | 8115 | continue; | 
|  | 8116 | p2p_add_wps_vendor_extension( | 
|  | 8117 | p2p, wpa_s->conf->wps_vendor_ext[i]); | 
|  | 8118 | } | 
|  | 8119 | } | 
|  | 8120 |  | 
|  | 8121 | if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) && | 
|  | 8122 | wpa_s->conf->country[0] && wpa_s->conf->country[1]) { | 
|  | 8123 | char country[3]; | 
|  | 8124 | country[0] = wpa_s->conf->country[0]; | 
|  | 8125 | country[1] = wpa_s->conf->country[1]; | 
|  | 8126 | country[2] = 0x04; | 
|  | 8127 | p2p_set_country(p2p, country); | 
|  | 8128 | } | 
|  | 8129 |  | 
|  | 8130 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_SSID_POSTFIX) { | 
|  | 8131 | p2p_set_ssid_postfix(p2p, (u8 *) wpa_s->conf->p2p_ssid_postfix, | 
|  | 8132 | wpa_s->conf->p2p_ssid_postfix ? | 
|  | 8133 | os_strlen(wpa_s->conf->p2p_ssid_postfix) : | 
|  | 8134 | 0); | 
|  | 8135 | } | 
|  | 8136 |  | 
|  | 8137 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_INTRA_BSS) | 
|  | 8138 | p2p_set_intra_bss_dist(p2p, wpa_s->conf->p2p_intra_bss); | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8139 |  | 
|  | 8140 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_LISTEN_CHANNEL) { | 
|  | 8141 | u8 reg_class, channel; | 
|  | 8142 | int ret; | 
|  | 8143 | unsigned int r; | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8144 | u8 channel_forced; | 
|  | 8145 |  | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8146 | if (wpa_s->conf->p2p_listen_reg_class && | 
|  | 8147 | wpa_s->conf->p2p_listen_channel) { | 
|  | 8148 | reg_class = wpa_s->conf->p2p_listen_reg_class; | 
|  | 8149 | channel = wpa_s->conf->p2p_listen_channel; | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8150 | channel_forced = 1; | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8151 | } else { | 
|  | 8152 | reg_class = 81; | 
|  | 8153 | /* | 
|  | 8154 | * Pick one of the social channels randomly as the | 
|  | 8155 | * listen channel. | 
|  | 8156 | */ | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8157 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) | 
|  | 8158 | channel = 1; | 
|  | 8159 | else | 
|  | 8160 | channel = 1 + (r % 3) * 5; | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8161 | channel_forced = 0; | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8162 | } | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8163 | ret = p2p_set_listen_channel(p2p, reg_class, channel, | 
|  | 8164 | channel_forced); | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8165 | if (ret) | 
|  | 8166 | wpa_printf(MSG_ERROR, "P2P: Own listen channel update " | 
|  | 8167 | "failed: %d", ret); | 
|  | 8168 | } | 
|  | 8169 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_OPER_CHANNEL) { | 
|  | 8170 | u8 op_reg_class, op_channel, cfg_op_channel; | 
|  | 8171 | int ret = 0; | 
|  | 8172 | unsigned int r; | 
|  | 8173 | if (wpa_s->conf->p2p_oper_reg_class && | 
|  | 8174 | wpa_s->conf->p2p_oper_channel) { | 
|  | 8175 | op_reg_class = wpa_s->conf->p2p_oper_reg_class; | 
|  | 8176 | op_channel = wpa_s->conf->p2p_oper_channel; | 
|  | 8177 | cfg_op_channel = 1; | 
|  | 8178 | } else { | 
|  | 8179 | op_reg_class = 81; | 
|  | 8180 | /* | 
|  | 8181 | * Use random operation channel from (1, 6, 11) | 
|  | 8182 | *if no other preference is indicated. | 
|  | 8183 | */ | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8184 | if (os_get_random((u8 *) &r, sizeof(r)) < 0) | 
|  | 8185 | op_channel = 1; | 
|  | 8186 | else | 
|  | 8187 | op_channel = 1 + (r % 3) * 5; | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8188 | cfg_op_channel = 0; | 
|  | 8189 | } | 
|  | 8190 | ret = p2p_set_oper_channel(p2p, op_reg_class, op_channel, | 
|  | 8191 | cfg_op_channel); | 
|  | 8192 | if (ret) | 
|  | 8193 | wpa_printf(MSG_ERROR, "P2P: Own oper channel update " | 
|  | 8194 | "failed: %d", ret); | 
|  | 8195 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8196 |  | 
|  | 8197 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PREF_CHAN) { | 
|  | 8198 | if (p2p_set_pref_chan(p2p, wpa_s->conf->num_p2p_pref_chan, | 
|  | 8199 | wpa_s->conf->p2p_pref_chan) < 0) { | 
|  | 8200 | wpa_printf(MSG_ERROR, "P2P: Preferred channel list " | 
|  | 8201 | "update failed"); | 
|  | 8202 | } | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8203 |  | 
|  | 8204 | if (p2p_set_no_go_freq(p2p, &wpa_s->conf->p2p_no_go_freq) < 0) { | 
|  | 8205 | wpa_printf(MSG_ERROR, "P2P: No GO channel list " | 
|  | 8206 | "update failed"); | 
|  | 8207 | } | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8208 | } | 
| Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 8209 |  | 
|  | 8210 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PASSPHRASE_LEN) | 
|  | 8211 | p2p_set_passphrase_len(p2p, wpa_s->conf->p2p_passphrase_len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8212 | } | 
|  | 8213 |  | 
|  | 8214 |  | 
|  | 8215 | int wpas_p2p_set_noa(struct wpa_supplicant *wpa_s, u8 count, int start, | 
|  | 8216 | int duration) | 
|  | 8217 | { | 
|  | 8218 | if (!wpa_s->ap_iface) | 
|  | 8219 | return -1; | 
|  | 8220 | return hostapd_p2p_set_noa(wpa_s->ap_iface->bss[0], count, start, | 
|  | 8221 | duration); | 
|  | 8222 | } | 
|  | 8223 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8224 |  | 
|  | 8225 | int wpas_p2p_set_cross_connect(struct wpa_supplicant *wpa_s, int enabled) | 
|  | 8226 | { | 
|  | 8227 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 8228 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8229 |  | 
|  | 8230 | wpa_s->global->cross_connection = enabled; | 
|  | 8231 | p2p_set_cross_connect(wpa_s->global->p2p, enabled); | 
|  | 8232 |  | 
|  | 8233 | if (!enabled) { | 
|  | 8234 | struct wpa_supplicant *iface; | 
|  | 8235 |  | 
|  | 8236 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) | 
|  | 8237 | { | 
|  | 8238 | if (iface->cross_connect_enabled == 0) | 
|  | 8239 | continue; | 
|  | 8240 |  | 
|  | 8241 | iface->cross_connect_enabled = 0; | 
|  | 8242 | iface->cross_connect_in_use = 0; | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8243 | wpa_msg_global(iface->p2pdev, MSG_INFO, | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8244 | P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s", | 
|  | 8245 | iface->ifname, | 
|  | 8246 | iface->cross_connect_uplink); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8247 | } | 
|  | 8248 | } | 
|  | 8249 |  | 
|  | 8250 | return 0; | 
|  | 8251 | } | 
|  | 8252 |  | 
|  | 8253 |  | 
|  | 8254 | static void wpas_p2p_enable_cross_connect(struct wpa_supplicant *uplink) | 
|  | 8255 | { | 
|  | 8256 | struct wpa_supplicant *iface; | 
|  | 8257 |  | 
|  | 8258 | if (!uplink->global->cross_connection) | 
|  | 8259 | return; | 
|  | 8260 |  | 
|  | 8261 | for (iface = uplink->global->ifaces; iface; iface = iface->next) { | 
|  | 8262 | if (!iface->cross_connect_enabled) | 
|  | 8263 | continue; | 
|  | 8264 | if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) != | 
|  | 8265 | 0) | 
|  | 8266 | continue; | 
|  | 8267 | if (iface->ap_iface == NULL) | 
|  | 8268 | continue; | 
|  | 8269 | if (iface->cross_connect_in_use) | 
|  | 8270 | continue; | 
|  | 8271 |  | 
|  | 8272 | iface->cross_connect_in_use = 1; | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8273 | wpa_msg_global(iface->p2pdev, MSG_INFO, | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8274 | P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s", | 
|  | 8275 | iface->ifname, iface->cross_connect_uplink); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8276 | } | 
|  | 8277 | } | 
|  | 8278 |  | 
|  | 8279 |  | 
|  | 8280 | static void wpas_p2p_disable_cross_connect(struct wpa_supplicant *uplink) | 
|  | 8281 | { | 
|  | 8282 | struct wpa_supplicant *iface; | 
|  | 8283 |  | 
|  | 8284 | for (iface = uplink->global->ifaces; iface; iface = iface->next) { | 
|  | 8285 | if (!iface->cross_connect_enabled) | 
|  | 8286 | continue; | 
|  | 8287 | if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) != | 
|  | 8288 | 0) | 
|  | 8289 | continue; | 
|  | 8290 | if (!iface->cross_connect_in_use) | 
|  | 8291 | continue; | 
|  | 8292 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8293 | wpa_msg_global(iface->p2pdev, MSG_INFO, | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8294 | P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s", | 
|  | 8295 | iface->ifname, iface->cross_connect_uplink); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8296 | iface->cross_connect_in_use = 0; | 
|  | 8297 | } | 
|  | 8298 | } | 
|  | 8299 |  | 
|  | 8300 |  | 
|  | 8301 | void wpas_p2p_notif_connected(struct wpa_supplicant *wpa_s) | 
|  | 8302 | { | 
|  | 8303 | if (wpa_s->ap_iface || wpa_s->current_ssid == NULL || | 
|  | 8304 | wpa_s->current_ssid->mode != WPAS_MODE_INFRA || | 
|  | 8305 | wpa_s->cross_connect_disallowed) | 
|  | 8306 | wpas_p2p_disable_cross_connect(wpa_s); | 
|  | 8307 | else | 
|  | 8308 | wpas_p2p_enable_cross_connect(wpa_s); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8309 | if (!wpa_s->ap_iface && | 
|  | 8310 | eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0) | 
|  | 8311 | wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8312 | } | 
|  | 8313 |  | 
|  | 8314 |  | 
|  | 8315 | void wpas_p2p_notif_disconnected(struct wpa_supplicant *wpa_s) | 
|  | 8316 | { | 
|  | 8317 | wpas_p2p_disable_cross_connect(wpa_s); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8318 | if (!wpa_s->ap_iface && | 
|  | 8319 | !eloop_is_timeout_registered(wpas_p2p_group_idle_timeout, | 
|  | 8320 | wpa_s, NULL)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8321 | wpas_p2p_set_group_idle_timeout(wpa_s); | 
|  | 8322 | } | 
|  | 8323 |  | 
|  | 8324 |  | 
|  | 8325 | static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s) | 
|  | 8326 | { | 
|  | 8327 | struct wpa_supplicant *iface; | 
|  | 8328 |  | 
|  | 8329 | if (!wpa_s->global->cross_connection) | 
|  | 8330 | return; | 
|  | 8331 |  | 
|  | 8332 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { | 
|  | 8333 | if (iface == wpa_s) | 
|  | 8334 | continue; | 
|  | 8335 | if (iface->drv_flags & | 
|  | 8336 | WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE) | 
|  | 8337 | continue; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8338 | if ((iface->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) && | 
|  | 8339 | iface != wpa_s->parent) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8340 | continue; | 
|  | 8341 |  | 
|  | 8342 | wpa_s->cross_connect_enabled = 1; | 
|  | 8343 | os_strlcpy(wpa_s->cross_connect_uplink, iface->ifname, | 
|  | 8344 | sizeof(wpa_s->cross_connect_uplink)); | 
|  | 8345 | wpa_printf(MSG_DEBUG, "P2P: Enable cross connection from " | 
|  | 8346 | "%s to %s whenever uplink is available", | 
|  | 8347 | wpa_s->ifname, wpa_s->cross_connect_uplink); | 
|  | 8348 |  | 
|  | 8349 | if (iface->ap_iface || iface->current_ssid == NULL || | 
|  | 8350 | iface->current_ssid->mode != WPAS_MODE_INFRA || | 
|  | 8351 | iface->cross_connect_disallowed || | 
|  | 8352 | iface->wpa_state != WPA_COMPLETED) | 
|  | 8353 | break; | 
|  | 8354 |  | 
|  | 8355 | wpa_s->cross_connect_in_use = 1; | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8356 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, | 
| Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 8357 | P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s", | 
|  | 8358 | wpa_s->ifname, wpa_s->cross_connect_uplink); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8359 | break; | 
|  | 8360 | } | 
|  | 8361 | } | 
|  | 8362 |  | 
|  | 8363 |  | 
|  | 8364 | int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant *wpa_s) | 
|  | 8365 | { | 
|  | 8366 | if (wpa_s->p2p_group_interface != P2P_GROUP_INTERFACE_CLIENT && | 
|  | 8367 | !wpa_s->p2p_in_provisioning) | 
|  | 8368 | return 0; /* not P2P client operation */ | 
|  | 8369 |  | 
|  | 8370 | wpa_printf(MSG_DEBUG, "P2P: Terminate connection due to WPS PBC " | 
|  | 8371 | "session overlap"); | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8372 | if (wpa_s != wpa_s->p2pdev) | 
|  | 8373 | wpa_msg_ctrl(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_OVERLAP); | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8374 | wpas_p2p_group_formation_failed(wpa_s, 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8375 | return 1; | 
|  | 8376 | } | 
|  | 8377 |  | 
|  | 8378 |  | 
| Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8379 | void wpas_p2p_pbc_overlap_cb(void *eloop_ctx, void *timeout_ctx) | 
|  | 8380 | { | 
|  | 8381 | struct wpa_supplicant *wpa_s = eloop_ctx; | 
|  | 8382 | wpas_p2p_notif_pbc_overlap(wpa_s); | 
|  | 8383 | } | 
|  | 8384 |  | 
|  | 8385 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8386 | void wpas_p2p_update_channel_list(struct wpa_supplicant *wpa_s, | 
|  | 8387 | enum wpas_p2p_channel_update_trig trig) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8388 | { | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8389 | struct p2p_channels chan, cli_chan; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8390 | struct wpa_used_freq_data *freqs = NULL; | 
|  | 8391 | unsigned int num = wpa_s->num_multichan_concurrent; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8392 |  | 
|  | 8393 | if (wpa_s->global == NULL || wpa_s->global->p2p == NULL) | 
|  | 8394 | return; | 
|  | 8395 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8396 | freqs = os_calloc(num, sizeof(struct wpa_used_freq_data)); | 
|  | 8397 | if (!freqs) | 
|  | 8398 | return; | 
|  | 8399 |  | 
|  | 8400 | num = get_shared_radio_freqs_data(wpa_s, freqs, num); | 
|  | 8401 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8402 | os_memset(&chan, 0, sizeof(chan)); | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8403 | os_memset(&cli_chan, 0, sizeof(cli_chan)); | 
| Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8404 | if (wpas_p2p_setup_channels(wpa_s, &chan, &cli_chan, | 
|  | 8405 | is_p2p_6ghz_disabled(wpa_s->global->p2p))) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8406 | wpa_printf(MSG_ERROR, "P2P: Failed to update supported " | 
|  | 8407 | "channel list"); | 
|  | 8408 | return; | 
|  | 8409 | } | 
|  | 8410 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8411 | p2p_update_channel_list(wpa_s->global->p2p, &chan, &cli_chan); | 
| Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 8412 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8413 | wpas_p2p_optimize_listen_channel(wpa_s, freqs, num); | 
| Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 8414 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8415 | /* | 
|  | 8416 | * The used frequencies map changed, so it is possible that a GO is | 
|  | 8417 | * using a channel that is no longer valid for P2P use. It is also | 
|  | 8418 | * possible that due to policy consideration, it would be preferable to | 
|  | 8419 | * move it to a frequency already used by other station interfaces. | 
|  | 8420 | */ | 
|  | 8421 | wpas_p2p_consider_moving_gos(wpa_s, freqs, num, trig); | 
|  | 8422 |  | 
|  | 8423 | os_free(freqs); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8424 | } | 
|  | 8425 |  | 
|  | 8426 |  | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8427 | static void wpas_p2p_scan_res_ignore(struct wpa_supplicant *wpa_s, | 
|  | 8428 | struct wpa_scan_results *scan_res) | 
|  | 8429 | { | 
|  | 8430 | wpa_printf(MSG_DEBUG, "P2P: Ignore scan results"); | 
|  | 8431 | } | 
|  | 8432 |  | 
|  | 8433 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8434 | int wpas_p2p_cancel(struct wpa_supplicant *wpa_s) | 
|  | 8435 | { | 
|  | 8436 | struct wpa_global *global = wpa_s->global; | 
|  | 8437 | int found = 0; | 
|  | 8438 | const u8 *peer; | 
|  | 8439 |  | 
|  | 8440 | if (global->p2p == NULL) | 
|  | 8441 | return -1; | 
|  | 8442 |  | 
|  | 8443 | wpa_printf(MSG_DEBUG, "P2P: Request to cancel group formation"); | 
|  | 8444 |  | 
|  | 8445 | if (wpa_s->pending_interface_name[0] && | 
|  | 8446 | !is_zero_ether_addr(wpa_s->pending_interface_addr)) | 
|  | 8447 | found = 1; | 
|  | 8448 |  | 
|  | 8449 | peer = p2p_get_go_neg_peer(global->p2p); | 
|  | 8450 | if (peer) { | 
|  | 8451 | wpa_printf(MSG_DEBUG, "P2P: Unauthorize pending GO Neg peer " | 
|  | 8452 | MACSTR, MAC2STR(peer)); | 
|  | 8453 | p2p_unauthorize(global->p2p, peer); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8454 | found = 1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8455 | } | 
|  | 8456 |  | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8457 | if (wpa_s->scan_res_handler == wpas_p2p_scan_res_join) { | 
|  | 8458 | wpa_printf(MSG_DEBUG, "P2P: Stop pending scan for join"); | 
|  | 8459 | wpa_s->scan_res_handler = wpas_p2p_scan_res_ignore; | 
|  | 8460 | found = 1; | 
|  | 8461 | } | 
|  | 8462 |  | 
|  | 8463 | if (wpa_s->pending_pd_before_join) { | 
|  | 8464 | wpa_printf(MSG_DEBUG, "P2P: Stop pending PD before join"); | 
|  | 8465 | wpa_s->pending_pd_before_join = 0; | 
|  | 8466 | found = 1; | 
|  | 8467 | } | 
|  | 8468 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8469 | wpas_p2p_stop_find(wpa_s); | 
|  | 8470 |  | 
|  | 8471 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 8472 | if (wpa_s == global->p2p_group_formation && | 
|  | 8473 | (wpa_s->p2p_in_provisioning || | 
|  | 8474 | wpa_s->parent->pending_interface_type == | 
|  | 8475 | WPA_IF_P2P_CLIENT)) { | 
|  | 8476 | wpa_printf(MSG_DEBUG, "P2P: Interface %s in group " | 
|  | 8477 | "formation found - cancelling", | 
|  | 8478 | wpa_s->ifname); | 
|  | 8479 | found = 1; | 
|  | 8480 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8481 | wpa_s->p2pdev, NULL); | 
| Jouni Malinen | adddfc4 | 2012-10-03 14:31:41 -0700 | [diff] [blame] | 8482 | if (wpa_s->p2p_in_provisioning) { | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8483 | wpas_group_formation_completed(wpa_s, 0, 0); | 
| Jouni Malinen | adddfc4 | 2012-10-03 14:31:41 -0700 | [diff] [blame] | 8484 | break; | 
|  | 8485 | } | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8486 | wpas_p2p_group_delete(wpa_s, | 
|  | 8487 | P2P_GROUP_REMOVAL_REQUESTED); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8488 | break; | 
| Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 8489 | } else if (wpa_s->p2p_in_invitation) { | 
|  | 8490 | wpa_printf(MSG_DEBUG, "P2P: Interface %s in invitation found - cancelling", | 
|  | 8491 | wpa_s->ifname); | 
|  | 8492 | found = 1; | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8493 | wpas_p2p_group_formation_failed(wpa_s, 0); | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8494 | break; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8495 | } | 
|  | 8496 | } | 
|  | 8497 |  | 
|  | 8498 | if (!found) { | 
|  | 8499 | wpa_printf(MSG_DEBUG, "P2P: No ongoing group formation found"); | 
|  | 8500 | return -1; | 
|  | 8501 | } | 
|  | 8502 |  | 
|  | 8503 | return 0; | 
|  | 8504 | } | 
|  | 8505 |  | 
|  | 8506 |  | 
|  | 8507 | void wpas_p2p_interface_unavailable(struct wpa_supplicant *wpa_s) | 
|  | 8508 | { | 
|  | 8509 | if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group) | 
|  | 8510 | return; | 
|  | 8511 |  | 
|  | 8512 | wpa_printf(MSG_DEBUG, "P2P: Remove group due to driver resource not " | 
|  | 8513 | "being available anymore"); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8514 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_UNAVAILABLE); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8515 | } | 
|  | 8516 |  | 
|  | 8517 |  | 
|  | 8518 | void wpas_p2p_update_best_channels(struct wpa_supplicant *wpa_s, | 
|  | 8519 | int freq_24, int freq_5, int freq_overall) | 
|  | 8520 | { | 
|  | 8521 | struct p2p_data *p2p = wpa_s->global->p2p; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8522 | if (p2p == NULL) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8523 | return; | 
|  | 8524 | p2p_set_best_channels(p2p, freq_24, freq_5, freq_overall); | 
|  | 8525 | } | 
|  | 8526 |  | 
|  | 8527 |  | 
|  | 8528 | int wpas_p2p_unauthorize(struct wpa_supplicant *wpa_s, const char *addr) | 
|  | 8529 | { | 
|  | 8530 | u8 peer[ETH_ALEN]; | 
|  | 8531 | struct p2p_data *p2p = wpa_s->global->p2p; | 
|  | 8532 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8533 | if (p2p == NULL) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8534 | return -1; | 
|  | 8535 |  | 
|  | 8536 | if (hwaddr_aton(addr, peer)) | 
|  | 8537 | return -1; | 
|  | 8538 |  | 
|  | 8539 | return p2p_unauthorize(p2p, peer); | 
|  | 8540 | } | 
|  | 8541 |  | 
|  | 8542 |  | 
|  | 8543 | /** | 
|  | 8544 | * wpas_p2p_disconnect - Disconnect from a P2P Group | 
|  | 8545 | * @wpa_s: Pointer to wpa_supplicant data | 
|  | 8546 | * Returns: 0 on success, -1 on failure | 
|  | 8547 | * | 
|  | 8548 | * This can be used to disconnect from a group in which the local end is a P2P | 
|  | 8549 | * Client or to end a P2P Group in case the local end is the Group Owner. If a | 
|  | 8550 | * virtual network interface was created for this group, that interface will be | 
|  | 8551 | * removed. Otherwise, only the configured P2P group network will be removed | 
|  | 8552 | * from the interface. | 
|  | 8553 | */ | 
|  | 8554 | int wpas_p2p_disconnect(struct wpa_supplicant *wpa_s) | 
|  | 8555 | { | 
|  | 8556 |  | 
|  | 8557 | if (wpa_s == NULL) | 
|  | 8558 | return -1; | 
|  | 8559 |  | 
| Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 8560 | return wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_REQUESTED) < 0 ? | 
|  | 8561 | -1 : 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8562 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8563 |  | 
|  | 8564 |  | 
|  | 8565 | int wpas_p2p_in_progress(struct wpa_supplicant *wpa_s) | 
|  | 8566 | { | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8567 | int ret; | 
|  | 8568 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8569 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 8570 | return 0; | 
|  | 8571 |  | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8572 | ret = p2p_in_progress(wpa_s->global->p2p); | 
|  | 8573 | if (ret == 0) { | 
|  | 8574 | /* | 
|  | 8575 | * Check whether there is an ongoing WPS provisioning step (or | 
|  | 8576 | * other parts of group formation) on another interface since | 
|  | 8577 | * p2p_in_progress() does not report this to avoid issues for | 
|  | 8578 | * scans during such provisioning step. | 
|  | 8579 | */ | 
|  | 8580 | if (wpa_s->global->p2p_group_formation && | 
|  | 8581 | wpa_s->global->p2p_group_formation != wpa_s) { | 
|  | 8582 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Another interface (%s) " | 
|  | 8583 | "in group formation", | 
|  | 8584 | wpa_s->global->p2p_group_formation->ifname); | 
|  | 8585 | ret = 1; | 
|  | 8586 | } | 
|  | 8587 | } | 
|  | 8588 |  | 
| Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 8589 | if (!ret && wpa_s->global->p2p_go_wait_client.sec) { | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8590 | struct os_reltime now; | 
|  | 8591 | os_get_reltime(&now); | 
|  | 8592 | if (os_reltime_expired(&now, &wpa_s->global->p2p_go_wait_client, | 
|  | 8593 | P2P_MAX_INITIAL_CONN_WAIT_GO)) { | 
| Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 8594 | /* Wait for the first client has expired */ | 
|  | 8595 | wpa_s->global->p2p_go_wait_client.sec = 0; | 
|  | 8596 | } else { | 
|  | 8597 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Waiting for initial client connection during group formation"); | 
|  | 8598 | ret = 1; | 
|  | 8599 | } | 
|  | 8600 | } | 
|  | 8601 |  | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 8602 | return ret; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8603 | } | 
|  | 8604 |  | 
|  | 8605 |  | 
|  | 8606 | void wpas_p2p_network_removed(struct wpa_supplicant *wpa_s, | 
|  | 8607 | struct wpa_ssid *ssid) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8608 | { | 
|  | 8609 | if (wpa_s->p2p_in_provisioning && ssid->p2p_group && | 
|  | 8610 | eloop_cancel_timeout(wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8611 | wpa_s->p2pdev, NULL) > 0) { | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8612 | /** | 
|  | 8613 | * Remove the network by scheduling the group formation | 
|  | 8614 | * timeout to happen immediately. The teardown code | 
|  | 8615 | * needs to be scheduled to run asynch later so that we | 
|  | 8616 | * don't delete data from under ourselves unexpectedly. | 
|  | 8617 | * Calling wpas_p2p_group_formation_timeout directly | 
|  | 8618 | * causes a series of crashes in WPS failure scenarios. | 
|  | 8619 | */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8620 | wpa_printf(MSG_DEBUG, "P2P: Canceled group formation due to " | 
|  | 8621 | "P2P group network getting removed"); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8622 | eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8623 | wpa_s->p2pdev, NULL); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8624 | } | 
|  | 8625 | } | 
|  | 8626 |  | 
|  | 8627 |  | 
|  | 8628 | struct wpa_ssid * wpas_p2p_get_persistent(struct wpa_supplicant *wpa_s, | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8629 | const u8 *addr, const u8 *ssid, | 
|  | 8630 | size_t ssid_len) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8631 | { | 
|  | 8632 | struct wpa_ssid *s; | 
|  | 8633 | size_t i; | 
|  | 8634 |  | 
|  | 8635 | for (s = wpa_s->conf->ssid; s; s = s->next) { | 
|  | 8636 | if (s->disabled != 2) | 
|  | 8637 | continue; | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8638 | if (ssid && | 
|  | 8639 | (ssid_len != s->ssid_len || | 
|  | 8640 | os_memcmp(ssid, s->ssid, ssid_len) != 0)) | 
|  | 8641 | continue; | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8642 | if (addr == NULL) { | 
|  | 8643 | if (s->mode == WPAS_MODE_P2P_GO) | 
|  | 8644 | return s; | 
|  | 8645 | continue; | 
|  | 8646 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8647 | if (os_memcmp(s->bssid, addr, ETH_ALEN) == 0) | 
|  | 8648 | return s; /* peer is GO in the persistent group */ | 
|  | 8649 | if (s->mode != WPAS_MODE_P2P_GO || s->p2p_client_list == NULL) | 
|  | 8650 | continue; | 
|  | 8651 | for (i = 0; i < s->num_p2p_clients; i++) { | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8652 | if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8653 | addr, ETH_ALEN) == 0) | 
|  | 8654 | return s; /* peer is P2P client in persistent | 
|  | 8655 | * group */ | 
|  | 8656 | } | 
|  | 8657 | } | 
|  | 8658 |  | 
|  | 8659 | return NULL; | 
|  | 8660 | } | 
|  | 8661 |  | 
|  | 8662 |  | 
|  | 8663 | void wpas_p2p_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s, | 
|  | 8664 | const u8 *addr) | 
|  | 8665 | { | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8666 | if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8667 | wpa_s->p2pdev, NULL) > 0) { | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8668 | /* | 
|  | 8669 | * This can happen if WPS provisioning step is not terminated | 
|  | 8670 | * cleanly (e.g., P2P Client does not send WSC_Done). Since the | 
|  | 8671 | * peer was able to connect, there is no need to time out group | 
|  | 8672 | * formation after this, though. In addition, this is used with | 
|  | 8673 | * the initial connection wait on the GO as a separate formation | 
|  | 8674 | * timeout and as such, expected to be hit after the initial WPS | 
|  | 8675 | * provisioning step. | 
|  | 8676 | */ | 
|  | 8677 | 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] | 8678 |  | 
|  | 8679 | if (!wpa_s->p2p_go_group_formation_completed && | 
|  | 8680 | !wpa_s->group_formation_reported) { | 
|  | 8681 | /* | 
|  | 8682 | * GO has not yet notified group formation success since | 
|  | 8683 | * the WPS step was not completed cleanly. Do that | 
|  | 8684 | * notification now since the P2P Client was able to | 
|  | 8685 | * connect and as such, must have received the | 
|  | 8686 | * credential from the WPS step. | 
|  | 8687 | */ | 
|  | 8688 | if (wpa_s->global->p2p) | 
|  | 8689 | p2p_wps_success_cb(wpa_s->global->p2p, addr); | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8690 | wpas_group_formation_completed(wpa_s, 1, 0); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8691 | } | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8692 | } | 
|  | 8693 | if (!wpa_s->p2p_go_group_formation_completed) { | 
|  | 8694 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Marking group formation completed on GO on first data connection"); | 
|  | 8695 | wpa_s->p2p_go_group_formation_completed = 1; | 
|  | 8696 | wpa_s->global->p2p_group_formation = NULL; | 
|  | 8697 | wpa_s->p2p_in_provisioning = 0; | 
| Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 8698 | wpa_s->p2p_in_invitation = 0; | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8699 | } | 
| Dmitry Shmidt | 92c368d | 2013-08-29 12:37:21 -0700 | [diff] [blame] | 8700 | wpa_s->global->p2p_go_wait_client.sec = 0; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8701 | if (addr == NULL) | 
|  | 8702 | return; | 
|  | 8703 | wpas_p2p_add_persistent_group_client(wpa_s, addr); | 
|  | 8704 | } | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8705 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8706 |  | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8707 | static int wpas_p2p_fallback_to_go_neg(struct wpa_supplicant *wpa_s, | 
|  | 8708 | int group_added) | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8709 | { | 
|  | 8710 | struct wpa_supplicant *group = wpa_s; | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8711 | int ret = 0; | 
|  | 8712 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8713 | if (wpa_s->global->p2p_group_formation) | 
|  | 8714 | group = wpa_s->global->p2p_group_formation; | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8715 | wpa_s = wpa_s->global->p2p_init_wpa_s; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8716 | offchannel_send_action_done(wpa_s); | 
|  | 8717 | if (group_added) | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8718 | ret = wpas_p2p_group_delete(group, P2P_GROUP_REMOVAL_SILENT); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8719 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Fall back to GO Negotiation"); | 
|  | 8720 | wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr, wpa_s->p2p_pin, | 
|  | 8721 | wpa_s->p2p_wps_method, wpa_s->p2p_persistent_group, 0, | 
|  | 8722 | 0, 0, wpa_s->p2p_go_intent, wpa_s->p2p_connect_freq, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8723 | wpa_s->p2p_go_vht_center_freq2, | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8724 | wpa_s->p2p_persistent_id, | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8725 | wpa_s->p2p_pd_before_go_neg, | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8726 | wpa_s->p2p_go_ht40, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8727 | wpa_s->p2p_go_vht, | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8728 | wpa_s->p2p_go_max_oper_chwidth, | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 8729 | wpa_s->p2p_go_he, | 
|  | 8730 | wpa_s->p2p_go_edmg, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 8731 | NULL, 0, is_p2p_allow_6ghz(wpa_s->global->p2p)); | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8732 | return ret; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8733 | } | 
|  | 8734 |  | 
|  | 8735 |  | 
|  | 8736 | int wpas_p2p_scan_no_go_seen(struct wpa_supplicant *wpa_s) | 
|  | 8737 | { | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8738 | int res; | 
|  | 8739 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8740 | if (!wpa_s->p2p_fallback_to_go_neg || | 
|  | 8741 | wpa_s->p2p_in_provisioning <= 5) | 
|  | 8742 | return 0; | 
|  | 8743 |  | 
|  | 8744 | if (wpas_p2p_peer_go(wpa_s, wpa_s->pending_join_dev_addr) > 0) | 
|  | 8745 | return 0; /* peer operating as a GO */ | 
|  | 8746 |  | 
|  | 8747 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: GO not found for p2p_connect-auto - " | 
|  | 8748 | "fallback to GO Negotiation"); | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8749 | 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] | 8750 | "reason=GO-not-found"); | 
|  | 8751 | res = wpas_p2p_fallback_to_go_neg(wpa_s, 1); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8752 |  | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8753 | return res == 1 ? 2 : 1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8754 | } | 
|  | 8755 |  | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8756 |  | 
|  | 8757 | unsigned int wpas_p2p_search_delay(struct wpa_supplicant *wpa_s) | 
|  | 8758 | { | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8759 | struct wpa_supplicant *ifs; | 
|  | 8760 |  | 
|  | 8761 | if (wpa_s->wpa_state > WPA_SCANNING) { | 
|  | 8762 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search delay due to " | 
|  | 8763 | "concurrent operation", | 
| Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 8764 | wpa_s->conf->p2p_search_delay); | 
|  | 8765 | return wpa_s->conf->p2p_search_delay; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8766 | } | 
|  | 8767 |  | 
| Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 8768 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, | 
|  | 8769 | radio_list) { | 
|  | 8770 | if (ifs != wpa_s && ifs->wpa_state > WPA_SCANNING) { | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8771 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search " | 
|  | 8772 | "delay due to concurrent operation on " | 
|  | 8773 | "interface %s", | 
| Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 8774 | wpa_s->conf->p2p_search_delay, | 
|  | 8775 | ifs->ifname); | 
|  | 8776 | return wpa_s->conf->p2p_search_delay; | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8777 | } | 
|  | 8778 | } | 
|  | 8779 |  | 
|  | 8780 | return 0; | 
|  | 8781 | } | 
|  | 8782 |  | 
| Dmitry Shmidt | 37d4d6a | 2013-03-18 13:09:42 -0700 | [diff] [blame] | 8783 |  | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8784 | static int wpas_p2p_remove_psk_entry(struct wpa_supplicant *wpa_s, | 
|  | 8785 | struct wpa_ssid *s, const u8 *addr, | 
|  | 8786 | int iface_addr) | 
|  | 8787 | { | 
|  | 8788 | struct psk_list_entry *psk, *tmp; | 
|  | 8789 | int changed = 0; | 
|  | 8790 |  | 
|  | 8791 | dl_list_for_each_safe(psk, tmp, &s->psk_list, struct psk_list_entry, | 
|  | 8792 | list) { | 
|  | 8793 | if ((iface_addr && !psk->p2p && | 
|  | 8794 | os_memcmp(addr, psk->addr, ETH_ALEN) == 0) || | 
|  | 8795 | (!iface_addr && psk->p2p && | 
|  | 8796 | os_memcmp(addr, psk->addr, ETH_ALEN) == 0)) { | 
|  | 8797 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 8798 | "P2P: Remove persistent group PSK list entry for " | 
|  | 8799 | MACSTR " p2p=%u", | 
|  | 8800 | MAC2STR(psk->addr), psk->p2p); | 
|  | 8801 | dl_list_del(&psk->list); | 
|  | 8802 | os_free(psk); | 
|  | 8803 | changed++; | 
|  | 8804 | } | 
|  | 8805 | } | 
|  | 8806 |  | 
|  | 8807 | return changed; | 
|  | 8808 | } | 
|  | 8809 |  | 
|  | 8810 |  | 
|  | 8811 | void wpas_p2p_new_psk_cb(struct wpa_supplicant *wpa_s, const u8 *mac_addr, | 
|  | 8812 | const u8 *p2p_dev_addr, | 
|  | 8813 | const u8 *psk, size_t psk_len) | 
|  | 8814 | { | 
|  | 8815 | struct wpa_ssid *ssid = wpa_s->current_ssid; | 
|  | 8816 | struct wpa_ssid *persistent; | 
| Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 8817 | struct psk_list_entry *p, *last; | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8818 |  | 
|  | 8819 | if (psk_len != sizeof(p->psk)) | 
|  | 8820 | return; | 
|  | 8821 |  | 
|  | 8822 | if (p2p_dev_addr) { | 
|  | 8823 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New PSK for addr=" MACSTR | 
|  | 8824 | " p2p_dev_addr=" MACSTR, | 
|  | 8825 | MAC2STR(mac_addr), MAC2STR(p2p_dev_addr)); | 
|  | 8826 | if (is_zero_ether_addr(p2p_dev_addr)) | 
|  | 8827 | p2p_dev_addr = NULL; | 
|  | 8828 | } else { | 
|  | 8829 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New PSK for addr=" MACSTR, | 
|  | 8830 | MAC2STR(mac_addr)); | 
|  | 8831 | } | 
|  | 8832 |  | 
|  | 8833 | if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) { | 
|  | 8834 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: new_psk_cb during group formation"); | 
|  | 8835 | /* To be added to persistent group once created */ | 
|  | 8836 | if (wpa_s->global->add_psk == NULL) { | 
|  | 8837 | wpa_s->global->add_psk = os_zalloc(sizeof(*p)); | 
|  | 8838 | if (wpa_s->global->add_psk == NULL) | 
|  | 8839 | return; | 
|  | 8840 | } | 
|  | 8841 | p = wpa_s->global->add_psk; | 
|  | 8842 | if (p2p_dev_addr) { | 
|  | 8843 | p->p2p = 1; | 
|  | 8844 | os_memcpy(p->addr, p2p_dev_addr, ETH_ALEN); | 
|  | 8845 | } else { | 
|  | 8846 | p->p2p = 0; | 
|  | 8847 | os_memcpy(p->addr, mac_addr, ETH_ALEN); | 
|  | 8848 | } | 
|  | 8849 | os_memcpy(p->psk, psk, psk_len); | 
|  | 8850 | return; | 
|  | 8851 | } | 
|  | 8852 |  | 
|  | 8853 | if (ssid->mode != WPAS_MODE_P2P_GO || !ssid->p2p_persistent_group) { | 
|  | 8854 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Ignore new_psk_cb on not-persistent GO"); | 
|  | 8855 | return; | 
|  | 8856 | } | 
|  | 8857 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8858 | persistent = wpas_p2p_get_persistent(wpa_s->p2pdev, NULL, ssid->ssid, | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8859 | ssid->ssid_len); | 
|  | 8860 | if (!persistent) { | 
|  | 8861 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not find persistent group information to store the new PSK"); | 
|  | 8862 | return; | 
|  | 8863 | } | 
|  | 8864 |  | 
|  | 8865 | p = os_zalloc(sizeof(*p)); | 
|  | 8866 | if (p == NULL) | 
|  | 8867 | return; | 
|  | 8868 | if (p2p_dev_addr) { | 
|  | 8869 | p->p2p = 1; | 
|  | 8870 | os_memcpy(p->addr, p2p_dev_addr, ETH_ALEN); | 
|  | 8871 | } else { | 
|  | 8872 | p->p2p = 0; | 
|  | 8873 | os_memcpy(p->addr, mac_addr, ETH_ALEN); | 
|  | 8874 | } | 
|  | 8875 | os_memcpy(p->psk, psk, psk_len); | 
|  | 8876 |  | 
| Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 8877 | if (dl_list_len(&persistent->psk_list) > P2P_MAX_STORED_CLIENTS && | 
|  | 8878 | (last = dl_list_last(&persistent->psk_list, | 
|  | 8879 | struct psk_list_entry, list))) { | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8880 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove oldest PSK entry for " | 
|  | 8881 | MACSTR " (p2p=%u) to make room for a new one", | 
|  | 8882 | MAC2STR(last->addr), last->p2p); | 
|  | 8883 | dl_list_del(&last->list); | 
|  | 8884 | os_free(last); | 
|  | 8885 | } | 
|  | 8886 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8887 | wpas_p2p_remove_psk_entry(wpa_s->p2pdev, persistent, | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8888 | p2p_dev_addr ? p2p_dev_addr : mac_addr, | 
|  | 8889 | p2p_dev_addr == NULL); | 
|  | 8890 | if (p2p_dev_addr) { | 
|  | 8891 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for p2p_dev_addr=" | 
|  | 8892 | MACSTR, MAC2STR(p2p_dev_addr)); | 
|  | 8893 | } else { | 
|  | 8894 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for addr=" MACSTR, | 
|  | 8895 | MAC2STR(mac_addr)); | 
|  | 8896 | } | 
|  | 8897 | dl_list_add(&persistent->psk_list, &p->list); | 
|  | 8898 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8899 | if (wpa_s->p2pdev->conf->update_config && | 
|  | 8900 | wpa_config_write(wpa_s->p2pdev->confname, wpa_s->p2pdev->conf)) | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8901 | wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration"); | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8902 | } | 
|  | 8903 |  | 
|  | 8904 |  | 
|  | 8905 | static void wpas_p2p_remove_psk(struct wpa_supplicant *wpa_s, | 
|  | 8906 | struct wpa_ssid *s, const u8 *addr, | 
|  | 8907 | int iface_addr) | 
|  | 8908 | { | 
|  | 8909 | int res; | 
|  | 8910 |  | 
|  | 8911 | res = wpas_p2p_remove_psk_entry(wpa_s, s, addr, iface_addr); | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 8912 | if (res > 0 && wpa_s->conf->update_config && | 
|  | 8913 | wpa_config_write(wpa_s->confname, wpa_s->conf)) | 
|  | 8914 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 8915 | "P2P: Failed to update configuration"); | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8916 | } | 
|  | 8917 |  | 
|  | 8918 |  | 
|  | 8919 | static void wpas_p2p_remove_client_go(struct wpa_supplicant *wpa_s, | 
|  | 8920 | const u8 *peer, int iface_addr) | 
|  | 8921 | { | 
|  | 8922 | struct hostapd_data *hapd; | 
|  | 8923 | struct hostapd_wpa_psk *psk, *prev, *rem; | 
|  | 8924 | struct sta_info *sta; | 
|  | 8925 |  | 
|  | 8926 | if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL || | 
|  | 8927 | wpa_s->current_ssid->mode != WPAS_MODE_P2P_GO) | 
|  | 8928 | return; | 
|  | 8929 |  | 
|  | 8930 | /* Remove per-station PSK entry */ | 
|  | 8931 | hapd = wpa_s->ap_iface->bss[0]; | 
|  | 8932 | prev = NULL; | 
|  | 8933 | psk = hapd->conf->ssid.wpa_psk; | 
|  | 8934 | while (psk) { | 
|  | 8935 | if ((iface_addr && os_memcmp(peer, psk->addr, ETH_ALEN) == 0) || | 
|  | 8936 | (!iface_addr && | 
|  | 8937 | os_memcmp(peer, psk->p2p_dev_addr, ETH_ALEN) == 0)) { | 
|  | 8938 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove operating group PSK entry for " | 
|  | 8939 | MACSTR " iface_addr=%d", | 
|  | 8940 | MAC2STR(peer), iface_addr); | 
|  | 8941 | if (prev) | 
|  | 8942 | prev->next = psk->next; | 
|  | 8943 | else | 
|  | 8944 | hapd->conf->ssid.wpa_psk = psk->next; | 
|  | 8945 | rem = psk; | 
|  | 8946 | psk = psk->next; | 
| Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 8947 | bin_clear_free(rem, sizeof(*rem)); | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8948 | } else { | 
|  | 8949 | prev = psk; | 
|  | 8950 | psk = psk->next; | 
|  | 8951 | } | 
|  | 8952 | } | 
|  | 8953 |  | 
|  | 8954 | /* Disconnect from group */ | 
|  | 8955 | if (iface_addr) | 
|  | 8956 | sta = ap_get_sta(hapd, peer); | 
|  | 8957 | else | 
|  | 8958 | sta = ap_get_sta_p2p(hapd, peer); | 
|  | 8959 | if (sta) { | 
|  | 8960 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disconnect peer " MACSTR | 
|  | 8961 | " (iface_addr=%d) from group", | 
|  | 8962 | MAC2STR(peer), iface_addr); | 
|  | 8963 | hostapd_drv_sta_deauth(hapd, sta->addr, | 
|  | 8964 | WLAN_REASON_DEAUTH_LEAVING); | 
|  | 8965 | ap_sta_deauthenticate(hapd, sta, WLAN_REASON_DEAUTH_LEAVING); | 
|  | 8966 | } | 
|  | 8967 | } | 
|  | 8968 |  | 
|  | 8969 |  | 
|  | 8970 | void wpas_p2p_remove_client(struct wpa_supplicant *wpa_s, const u8 *peer, | 
|  | 8971 | int iface_addr) | 
|  | 8972 | { | 
|  | 8973 | struct wpa_ssid *s; | 
|  | 8974 | struct wpa_supplicant *w; | 
| Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 8975 | 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] | 8976 |  | 
|  | 8977 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove client " MACSTR, MAC2STR(peer)); | 
|  | 8978 |  | 
|  | 8979 | /* Remove from any persistent group */ | 
| Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 8980 | for (s = p2p_wpa_s->conf->ssid; s; s = s->next) { | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8981 | if (s->disabled != 2 || s->mode != WPAS_MODE_P2P_GO) | 
|  | 8982 | continue; | 
|  | 8983 | if (!iface_addr) | 
| Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 8984 | wpas_remove_persistent_peer(p2p_wpa_s, s, peer, 0); | 
|  | 8985 | wpas_p2p_remove_psk(p2p_wpa_s, s, peer, iface_addr); | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 8986 | } | 
|  | 8987 |  | 
|  | 8988 | /* Remove from any operating group */ | 
|  | 8989 | for (w = wpa_s->global->ifaces; w; w = w->next) | 
|  | 8990 | wpas_p2p_remove_client_go(w, peer, iface_addr); | 
|  | 8991 | } | 
|  | 8992 |  | 
|  | 8993 |  | 
|  | 8994 | static void wpas_p2p_psk_failure_removal(void *eloop_ctx, void *timeout_ctx) | 
|  | 8995 | { | 
|  | 8996 | struct wpa_supplicant *wpa_s = eloop_ctx; | 
|  | 8997 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_PSK_FAILURE); | 
|  | 8998 | } | 
|  | 8999 |  | 
|  | 9000 |  | 
| Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 9001 | static void wpas_p2p_group_freq_conflict(void *eloop_ctx, void *timeout_ctx) | 
|  | 9002 | { | 
|  | 9003 | struct wpa_supplicant *wpa_s = eloop_ctx; | 
|  | 9004 |  | 
|  | 9005 | wpa_printf(MSG_DEBUG, "P2P: Frequency conflict - terminate group"); | 
|  | 9006 | wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_FREQ_CONFLICT); | 
|  | 9007 | } | 
|  | 9008 |  | 
|  | 9009 |  | 
|  | 9010 | int wpas_p2p_handle_frequency_conflicts(struct wpa_supplicant *wpa_s, int freq, | 
|  | 9011 | struct wpa_ssid *ssid) | 
|  | 9012 | { | 
|  | 9013 | struct wpa_supplicant *iface; | 
|  | 9014 |  | 
|  | 9015 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { | 
|  | 9016 | if (!iface->current_ssid || | 
|  | 9017 | iface->current_ssid->frequency == freq || | 
|  | 9018 | (iface->p2p_group_interface == NOT_P2P_GROUP_INTERFACE && | 
|  | 9019 | !iface->current_ssid->p2p_group)) | 
|  | 9020 | continue; | 
|  | 9021 |  | 
|  | 9022 | /* Remove the connection with least priority */ | 
|  | 9023 | if (!wpas_is_p2p_prioritized(iface)) { | 
|  | 9024 | /* STA connection has priority over existing | 
|  | 9025 | * P2P connection, so remove the interface. */ | 
|  | 9026 | wpa_printf(MSG_DEBUG, "P2P: Removing P2P connection due to single channel concurrent mode frequency conflict"); | 
|  | 9027 | eloop_register_timeout(0, 0, | 
|  | 9028 | wpas_p2p_group_freq_conflict, | 
|  | 9029 | iface, NULL); | 
|  | 9030 | /* If connection in progress is P2P connection, do not | 
|  | 9031 | * proceed for the connection. */ | 
|  | 9032 | if (wpa_s == iface) | 
|  | 9033 | return -1; | 
|  | 9034 | else | 
|  | 9035 | return 0; | 
|  | 9036 | } else { | 
|  | 9037 | /* P2P connection has priority, disable the STA network | 
|  | 9038 | */ | 
|  | 9039 | wpa_supplicant_disable_network(wpa_s->global->ifaces, | 
|  | 9040 | ssid); | 
|  | 9041 | wpa_msg(wpa_s->global->ifaces, MSG_INFO, | 
|  | 9042 | WPA_EVENT_FREQ_CONFLICT " id=%d", ssid->id); | 
|  | 9043 | os_memset(wpa_s->global->ifaces->pending_bssid, 0, | 
|  | 9044 | ETH_ALEN); | 
|  | 9045 | /* If P2P connection is in progress, continue | 
|  | 9046 | * connecting...*/ | 
|  | 9047 | if (wpa_s == iface) | 
|  | 9048 | return 0; | 
|  | 9049 | else | 
|  | 9050 | return -1; | 
|  | 9051 | } | 
|  | 9052 | } | 
|  | 9053 |  | 
|  | 9054 | return 0; | 
|  | 9055 | } | 
|  | 9056 |  | 
|  | 9057 |  | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9058 | int wpas_p2p_4way_hs_failed(struct wpa_supplicant *wpa_s) | 
|  | 9059 | { | 
|  | 9060 | struct wpa_ssid *ssid = wpa_s->current_ssid; | 
|  | 9061 |  | 
|  | 9062 | if (ssid == NULL || !ssid->p2p_group) | 
|  | 9063 | return 0; | 
|  | 9064 |  | 
|  | 9065 | if (wpa_s->p2p_last_4way_hs_fail && | 
|  | 9066 | wpa_s->p2p_last_4way_hs_fail == ssid) { | 
|  | 9067 | u8 go_dev_addr[ETH_ALEN]; | 
|  | 9068 | struct wpa_ssid *persistent; | 
|  | 9069 |  | 
|  | 9070 | if (wpas_p2p_persistent_group(wpa_s, go_dev_addr, | 
|  | 9071 | ssid->ssid, | 
|  | 9072 | ssid->ssid_len) <= 0) { | 
|  | 9073 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not determine whether 4-way handshake failures were for a persistent group"); | 
|  | 9074 | goto disconnect; | 
|  | 9075 | } | 
|  | 9076 |  | 
|  | 9077 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Two 4-way handshake failures for a P2P group - go_dev_addr=" | 
|  | 9078 | MACSTR, MAC2STR(go_dev_addr)); | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9079 | persistent = wpas_p2p_get_persistent(wpa_s->p2pdev, go_dev_addr, | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9080 | ssid->ssid, | 
|  | 9081 | ssid->ssid_len); | 
|  | 9082 | if (persistent == NULL || persistent->mode != WPAS_MODE_INFRA) { | 
|  | 9083 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No matching persistent group stored"); | 
|  | 9084 | goto disconnect; | 
|  | 9085 | } | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9086 | wpa_msg_global(wpa_s->p2pdev, MSG_INFO, | 
| Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 9087 | P2P_EVENT_PERSISTENT_PSK_FAIL "%d", | 
|  | 9088 | persistent->id); | 
|  | 9089 | disconnect: | 
|  | 9090 | wpa_s->p2p_last_4way_hs_fail = NULL; | 
|  | 9091 | /* | 
|  | 9092 | * Remove the group from a timeout to avoid issues with caller | 
|  | 9093 | * continuing to use the interface if this is on a P2P group | 
|  | 9094 | * interface. | 
|  | 9095 | */ | 
|  | 9096 | eloop_register_timeout(0, 0, wpas_p2p_psk_failure_removal, | 
|  | 9097 | wpa_s, NULL); | 
|  | 9098 | return 1; | 
|  | 9099 | } | 
|  | 9100 |  | 
|  | 9101 | wpa_s->p2p_last_4way_hs_fail = ssid; | 
|  | 9102 | return 0; | 
|  | 9103 | } | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9104 |  | 
|  | 9105 |  | 
|  | 9106 | #ifdef CONFIG_WPS_NFC | 
|  | 9107 |  | 
|  | 9108 | static struct wpabuf * wpas_p2p_nfc_handover(int ndef, struct wpabuf *wsc, | 
|  | 9109 | struct wpabuf *p2p) | 
|  | 9110 | { | 
|  | 9111 | struct wpabuf *ret; | 
|  | 9112 | size_t wsc_len; | 
|  | 9113 |  | 
|  | 9114 | if (p2p == NULL) { | 
|  | 9115 | wpabuf_free(wsc); | 
|  | 9116 | wpa_printf(MSG_DEBUG, "P2P: No p2p buffer for handover"); | 
|  | 9117 | return NULL; | 
|  | 9118 | } | 
|  | 9119 |  | 
|  | 9120 | wsc_len = wsc ? wpabuf_len(wsc) : 0; | 
|  | 9121 | ret = wpabuf_alloc(2 + wsc_len + 2 + wpabuf_len(p2p)); | 
|  | 9122 | if (ret == NULL) { | 
|  | 9123 | wpabuf_free(wsc); | 
|  | 9124 | wpabuf_free(p2p); | 
|  | 9125 | return NULL; | 
|  | 9126 | } | 
|  | 9127 |  | 
|  | 9128 | wpabuf_put_be16(ret, wsc_len); | 
|  | 9129 | if (wsc) | 
|  | 9130 | wpabuf_put_buf(ret, wsc); | 
|  | 9131 | wpabuf_put_be16(ret, wpabuf_len(p2p)); | 
|  | 9132 | wpabuf_put_buf(ret, p2p); | 
|  | 9133 |  | 
|  | 9134 | wpabuf_free(wsc); | 
|  | 9135 | wpabuf_free(p2p); | 
|  | 9136 | wpa_hexdump_buf(MSG_DEBUG, | 
|  | 9137 | "P2P: Generated NFC connection handover message", ret); | 
|  | 9138 |  | 
|  | 9139 | if (ndef && ret) { | 
|  | 9140 | struct wpabuf *tmp; | 
|  | 9141 | tmp = ndef_build_p2p(ret); | 
|  | 9142 | wpabuf_free(ret); | 
|  | 9143 | if (tmp == NULL) { | 
|  | 9144 | wpa_printf(MSG_DEBUG, "P2P: Failed to NDEF encapsulate handover request"); | 
|  | 9145 | return NULL; | 
|  | 9146 | } | 
|  | 9147 | ret = tmp; | 
|  | 9148 | } | 
|  | 9149 |  | 
|  | 9150 | return ret; | 
|  | 9151 | } | 
|  | 9152 |  | 
|  | 9153 |  | 
|  | 9154 | static int wpas_p2p_cli_freq(struct wpa_supplicant *wpa_s, | 
|  | 9155 | struct wpa_ssid **ssid, u8 *go_dev_addr) | 
|  | 9156 | { | 
|  | 9157 | struct wpa_supplicant *iface; | 
|  | 9158 |  | 
|  | 9159 | if (go_dev_addr) | 
|  | 9160 | os_memset(go_dev_addr, 0, ETH_ALEN); | 
|  | 9161 | if (ssid) | 
|  | 9162 | *ssid = NULL; | 
|  | 9163 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { | 
|  | 9164 | if (iface->wpa_state < WPA_ASSOCIATING || | 
|  | 9165 | iface->current_ssid == NULL || iface->assoc_freq == 0 || | 
|  | 9166 | !iface->current_ssid->p2p_group || | 
|  | 9167 | iface->current_ssid->mode != WPAS_MODE_INFRA) | 
|  | 9168 | continue; | 
|  | 9169 | if (ssid) | 
|  | 9170 | *ssid = iface->current_ssid; | 
|  | 9171 | if (go_dev_addr) | 
|  | 9172 | os_memcpy(go_dev_addr, iface->go_dev_addr, ETH_ALEN); | 
|  | 9173 | return iface->assoc_freq; | 
|  | 9174 | } | 
|  | 9175 | return 0; | 
|  | 9176 | } | 
|  | 9177 |  | 
|  | 9178 |  | 
|  | 9179 | struct wpabuf * wpas_p2p_nfc_handover_req(struct wpa_supplicant *wpa_s, | 
|  | 9180 | int ndef) | 
|  | 9181 | { | 
|  | 9182 | struct wpabuf *wsc, *p2p; | 
|  | 9183 | struct wpa_ssid *ssid; | 
|  | 9184 | u8 go_dev_addr[ETH_ALEN]; | 
|  | 9185 | int cli_freq = wpas_p2p_cli_freq(wpa_s, &ssid, go_dev_addr); | 
|  | 9186 |  | 
|  | 9187 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) { | 
|  | 9188 | wpa_printf(MSG_DEBUG, "P2P: P2P disabled - cannot build handover request"); | 
|  | 9189 | return NULL; | 
|  | 9190 | } | 
|  | 9191 |  | 
|  | 9192 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL && | 
|  | 9193 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, | 
|  | 9194 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) { | 
|  | 9195 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No DH key available for handover request"); | 
|  | 9196 | return NULL; | 
|  | 9197 | } | 
|  | 9198 |  | 
|  | 9199 | if (cli_freq == 0) { | 
|  | 9200 | wsc = wps_build_nfc_handover_req_p2p( | 
|  | 9201 | wpa_s->parent->wps, wpa_s->conf->wps_nfc_dh_pubkey); | 
|  | 9202 | } else | 
|  | 9203 | wsc = NULL; | 
|  | 9204 | p2p = p2p_build_nfc_handover_req(wpa_s->global->p2p, cli_freq, | 
|  | 9205 | go_dev_addr, ssid ? ssid->ssid : NULL, | 
|  | 9206 | ssid ? ssid->ssid_len : 0); | 
|  | 9207 |  | 
|  | 9208 | return wpas_p2p_nfc_handover(ndef, wsc, p2p); | 
|  | 9209 | } | 
|  | 9210 |  | 
|  | 9211 |  | 
|  | 9212 | struct wpabuf * wpas_p2p_nfc_handover_sel(struct wpa_supplicant *wpa_s, | 
|  | 9213 | int ndef, int tag) | 
|  | 9214 | { | 
|  | 9215 | struct wpabuf *wsc, *p2p; | 
|  | 9216 | struct wpa_ssid *ssid; | 
|  | 9217 | u8 go_dev_addr[ETH_ALEN]; | 
|  | 9218 | int cli_freq = wpas_p2p_cli_freq(wpa_s, &ssid, go_dev_addr); | 
|  | 9219 |  | 
|  | 9220 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 9221 | return NULL; | 
|  | 9222 |  | 
|  | 9223 | if (!tag && wpa_s->conf->wps_nfc_dh_pubkey == NULL && | 
|  | 9224 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, | 
|  | 9225 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) | 
|  | 9226 | return NULL; | 
|  | 9227 |  | 
|  | 9228 | if (cli_freq == 0) { | 
|  | 9229 | wsc = wps_build_nfc_handover_sel_p2p( | 
|  | 9230 | wpa_s->parent->wps, | 
|  | 9231 | tag ? wpa_s->conf->wps_nfc_dev_pw_id : | 
|  | 9232 | DEV_PW_NFC_CONNECTION_HANDOVER, | 
|  | 9233 | wpa_s->conf->wps_nfc_dh_pubkey, | 
|  | 9234 | tag ? wpa_s->conf->wps_nfc_dev_pw : NULL); | 
|  | 9235 | } else | 
|  | 9236 | wsc = NULL; | 
|  | 9237 | p2p = p2p_build_nfc_handover_sel(wpa_s->global->p2p, cli_freq, | 
|  | 9238 | go_dev_addr, ssid ? ssid->ssid : NULL, | 
|  | 9239 | ssid ? ssid->ssid_len : 0); | 
|  | 9240 |  | 
|  | 9241 | return wpas_p2p_nfc_handover(ndef, wsc, p2p); | 
|  | 9242 | } | 
|  | 9243 |  | 
|  | 9244 |  | 
|  | 9245 | static int wpas_p2p_nfc_join_group(struct wpa_supplicant *wpa_s, | 
|  | 9246 | struct p2p_nfc_params *params) | 
|  | 9247 | { | 
|  | 9248 | wpa_printf(MSG_DEBUG, "P2P: Initiate join-group based on NFC " | 
|  | 9249 | "connection handover (freq=%d)", | 
|  | 9250 | params->go_freq); | 
|  | 9251 |  | 
|  | 9252 | if (params->go_freq && params->go_ssid_len) { | 
|  | 9253 | wpa_s->p2p_wps_method = WPS_NFC; | 
|  | 9254 | wpa_s->pending_join_wps_method = WPS_NFC; | 
|  | 9255 | os_memset(wpa_s->pending_join_iface_addr, 0, ETH_ALEN); | 
|  | 9256 | os_memcpy(wpa_s->pending_join_dev_addr, params->go_dev_addr, | 
|  | 9257 | ETH_ALEN); | 
|  | 9258 | return wpas_p2p_join_start(wpa_s, params->go_freq, | 
|  | 9259 | params->go_ssid, | 
|  | 9260 | params->go_ssid_len); | 
|  | 9261 | } | 
|  | 9262 |  | 
|  | 9263 | return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL, | 
|  | 9264 | WPS_NFC, 0, 0, 1, 0, wpa_s->conf->p2p_go_intent, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9265 | params->go_freq, wpa_s->p2p_go_vht_center_freq2, | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 9266 | -1, 0, 1, 1, wpa_s->p2p_go_max_oper_chwidth, | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9267 | wpa_s->p2p_go_he, wpa_s->p2p_go_edmg, | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 9268 | params->go_ssid_len ? params->go_ssid : NULL, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9269 | params->go_ssid_len, false); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9270 | } | 
|  | 9271 |  | 
|  | 9272 |  | 
|  | 9273 | static int wpas_p2p_nfc_auth_join(struct wpa_supplicant *wpa_s, | 
|  | 9274 | struct p2p_nfc_params *params, int tag) | 
|  | 9275 | { | 
|  | 9276 | int res, persistent; | 
|  | 9277 | struct wpa_ssid *ssid; | 
|  | 9278 |  | 
|  | 9279 | wpa_printf(MSG_DEBUG, "P2P: Authorize join-group based on NFC " | 
|  | 9280 | "connection handover"); | 
|  | 9281 | for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
|  | 9282 | ssid = wpa_s->current_ssid; | 
|  | 9283 | if (ssid == NULL) | 
|  | 9284 | continue; | 
|  | 9285 | if (ssid->mode != WPAS_MODE_P2P_GO) | 
|  | 9286 | continue; | 
|  | 9287 | if (wpa_s->ap_iface == NULL) | 
|  | 9288 | continue; | 
|  | 9289 | break; | 
|  | 9290 | } | 
|  | 9291 | if (wpa_s == NULL) { | 
|  | 9292 | wpa_printf(MSG_DEBUG, "P2P: Could not find GO interface"); | 
|  | 9293 | return -1; | 
|  | 9294 | } | 
|  | 9295 |  | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9296 | if (wpa_s->p2pdev->p2p_oob_dev_pw_id != | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9297 | DEV_PW_NFC_CONNECTION_HANDOVER && | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9298 | !wpa_s->p2pdev->p2p_oob_dev_pw) { | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9299 | wpa_printf(MSG_DEBUG, "P2P: No NFC Dev Pw known"); | 
|  | 9300 | return -1; | 
|  | 9301 | } | 
|  | 9302 | res = wpas_ap_wps_add_nfc_pw( | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9303 | wpa_s, wpa_s->p2pdev->p2p_oob_dev_pw_id, | 
|  | 9304 | wpa_s->p2pdev->p2p_oob_dev_pw, | 
|  | 9305 | wpa_s->p2pdev->p2p_peer_oob_pk_hash_known ? | 
|  | 9306 | wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : NULL); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9307 | if (res) | 
|  | 9308 | return res; | 
|  | 9309 |  | 
|  | 9310 | if (!tag) { | 
|  | 9311 | wpa_printf(MSG_DEBUG, "P2P: Negotiated handover - wait for peer to join without invitation"); | 
|  | 9312 | return 0; | 
|  | 9313 | } | 
|  | 9314 |  | 
|  | 9315 | if (!params->peer || | 
|  | 9316 | !(params->peer->dev_capab & P2P_DEV_CAPAB_INVITATION_PROCEDURE)) | 
|  | 9317 | return 0; | 
|  | 9318 |  | 
|  | 9319 | wpa_printf(MSG_DEBUG, "P2P: Static handover - invite peer " MACSTR | 
|  | 9320 | " to join", MAC2STR(params->peer->p2p_device_addr)); | 
|  | 9321 |  | 
|  | 9322 | wpa_s->global->p2p_invite_group = wpa_s; | 
|  | 9323 | persistent = ssid->p2p_persistent_group && | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9324 | wpas_p2p_get_persistent(wpa_s->p2pdev, | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9325 | params->peer->p2p_device_addr, | 
|  | 9326 | ssid->ssid, ssid->ssid_len); | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9327 | wpa_s->p2pdev->pending_invite_ssid_id = -1; | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9328 |  | 
|  | 9329 | return p2p_invite(wpa_s->global->p2p, params->peer->p2p_device_addr, | 
|  | 9330 | P2P_INVITE_ROLE_ACTIVE_GO, wpa_s->own_addr, | 
|  | 9331 | ssid->ssid, ssid->ssid_len, ssid->frequency, | 
|  | 9332 | wpa_s->global->p2p_dev_addr, persistent, 0, | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9333 | wpa_s->p2pdev->p2p_oob_dev_pw_id); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9334 | } | 
|  | 9335 |  | 
|  | 9336 |  | 
|  | 9337 | static int wpas_p2p_nfc_init_go_neg(struct wpa_supplicant *wpa_s, | 
|  | 9338 | struct p2p_nfc_params *params, | 
|  | 9339 | int forced_freq) | 
|  | 9340 | { | 
|  | 9341 | wpa_printf(MSG_DEBUG, "P2P: Initiate GO Negotiation based on NFC " | 
|  | 9342 | "connection handover"); | 
|  | 9343 | return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL, | 
|  | 9344 | WPS_NFC, 0, 0, 0, 0, wpa_s->conf->p2p_go_intent, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9345 | forced_freq, wpa_s->p2p_go_vht_center_freq2, | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 9346 | -1, 0, 1, 1, wpa_s->p2p_go_max_oper_chwidth, | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9347 | wpa_s->p2p_go_he, wpa_s->p2p_go_edmg, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9348 | NULL, 0, false); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9349 | } | 
|  | 9350 |  | 
|  | 9351 |  | 
|  | 9352 | static int wpas_p2p_nfc_resp_go_neg(struct wpa_supplicant *wpa_s, | 
|  | 9353 | struct p2p_nfc_params *params, | 
|  | 9354 | int forced_freq) | 
|  | 9355 | { | 
|  | 9356 | int res; | 
|  | 9357 |  | 
|  | 9358 | wpa_printf(MSG_DEBUG, "P2P: Authorize GO Negotiation based on NFC " | 
|  | 9359 | "connection handover"); | 
|  | 9360 | res = wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL, | 
|  | 9361 | WPS_NFC, 0, 0, 0, 1, wpa_s->conf->p2p_go_intent, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9362 | forced_freq, wpa_s->p2p_go_vht_center_freq2, | 
| Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 9363 | -1, 0, 1, 1, wpa_s->p2p_go_max_oper_chwidth, | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9364 | wpa_s->p2p_go_he, wpa_s->p2p_go_edmg, | 
| Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9365 | NULL, 0, false); | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9366 | if (res) | 
|  | 9367 | return res; | 
|  | 9368 |  | 
|  | 9369 | res = wpas_p2p_listen(wpa_s, 60); | 
|  | 9370 | if (res) { | 
|  | 9371 | p2p_unauthorize(wpa_s->global->p2p, | 
|  | 9372 | params->peer->p2p_device_addr); | 
|  | 9373 | } | 
|  | 9374 |  | 
|  | 9375 | return res; | 
|  | 9376 | } | 
|  | 9377 |  | 
|  | 9378 |  | 
|  | 9379 | static int wpas_p2p_nfc_connection_handover(struct wpa_supplicant *wpa_s, | 
|  | 9380 | const struct wpabuf *data, | 
|  | 9381 | int sel, int tag, int forced_freq) | 
|  | 9382 | { | 
|  | 9383 | const u8 *pos, *end; | 
|  | 9384 | u16 len, id; | 
|  | 9385 | struct p2p_nfc_params params; | 
|  | 9386 | int res; | 
|  | 9387 |  | 
|  | 9388 | os_memset(¶ms, 0, sizeof(params)); | 
|  | 9389 | params.sel = sel; | 
|  | 9390 |  | 
|  | 9391 | wpa_hexdump_buf(MSG_DEBUG, "P2P: Received NFC tag payload", data); | 
|  | 9392 |  | 
|  | 9393 | pos = wpabuf_head(data); | 
|  | 9394 | end = pos + wpabuf_len(data); | 
|  | 9395 |  | 
|  | 9396 | if (end - pos < 2) { | 
|  | 9397 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for Length of WSC " | 
|  | 9398 | "attributes"); | 
|  | 9399 | return -1; | 
|  | 9400 | } | 
|  | 9401 | len = WPA_GET_BE16(pos); | 
|  | 9402 | pos += 2; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9403 | if (len > end - pos) { | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9404 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for WSC " | 
|  | 9405 | "attributes"); | 
|  | 9406 | return -1; | 
|  | 9407 | } | 
|  | 9408 | params.wsc_attr = pos; | 
|  | 9409 | params.wsc_len = len; | 
|  | 9410 | pos += len; | 
|  | 9411 |  | 
|  | 9412 | if (end - pos < 2) { | 
|  | 9413 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for Length of P2P " | 
|  | 9414 | "attributes"); | 
|  | 9415 | return -1; | 
|  | 9416 | } | 
|  | 9417 | len = WPA_GET_BE16(pos); | 
|  | 9418 | pos += 2; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9419 | if (len > end - pos) { | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9420 | wpa_printf(MSG_DEBUG, "P2P: Not enough data for P2P " | 
|  | 9421 | "attributes"); | 
|  | 9422 | return -1; | 
|  | 9423 | } | 
|  | 9424 | params.p2p_attr = pos; | 
|  | 9425 | params.p2p_len = len; | 
|  | 9426 | pos += len; | 
|  | 9427 |  | 
|  | 9428 | wpa_hexdump(MSG_DEBUG, "P2P: WSC attributes", | 
|  | 9429 | params.wsc_attr, params.wsc_len); | 
|  | 9430 | wpa_hexdump(MSG_DEBUG, "P2P: P2P attributes", | 
|  | 9431 | params.p2p_attr, params.p2p_len); | 
|  | 9432 | if (pos < end) { | 
|  | 9433 | wpa_hexdump(MSG_DEBUG, | 
|  | 9434 | "P2P: Ignored extra data after P2P attributes", | 
|  | 9435 | pos, end - pos); | 
|  | 9436 | } | 
|  | 9437 |  | 
|  | 9438 | res = p2p_process_nfc_connection_handover(wpa_s->global->p2p, ¶ms); | 
|  | 9439 | if (res) | 
|  | 9440 | return res; | 
|  | 9441 |  | 
|  | 9442 | if (params.next_step == NO_ACTION) | 
|  | 9443 | return 0; | 
|  | 9444 |  | 
|  | 9445 | if (params.next_step == BOTH_GO) { | 
|  | 9446 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_BOTH_GO "peer=" MACSTR, | 
|  | 9447 | MAC2STR(params.peer->p2p_device_addr)); | 
|  | 9448 | return 0; | 
|  | 9449 | } | 
|  | 9450 |  | 
|  | 9451 | if (params.next_step == PEER_CLIENT) { | 
|  | 9452 | if (!is_zero_ether_addr(params.go_dev_addr)) { | 
|  | 9453 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_PEER_CLIENT | 
|  | 9454 | "peer=" MACSTR " freq=%d go_dev_addr=" MACSTR | 
|  | 9455 | " ssid=\"%s\"", | 
|  | 9456 | MAC2STR(params.peer->p2p_device_addr), | 
|  | 9457 | params.go_freq, | 
|  | 9458 | MAC2STR(params.go_dev_addr), | 
|  | 9459 | wpa_ssid_txt(params.go_ssid, | 
|  | 9460 | params.go_ssid_len)); | 
|  | 9461 | } else { | 
|  | 9462 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_PEER_CLIENT | 
|  | 9463 | "peer=" MACSTR " freq=%d", | 
|  | 9464 | MAC2STR(params.peer->p2p_device_addr), | 
|  | 9465 | params.go_freq); | 
|  | 9466 | } | 
|  | 9467 | return 0; | 
|  | 9468 | } | 
|  | 9469 |  | 
|  | 9470 | if (wpas_p2p_cli_freq(wpa_s, NULL, NULL)) { | 
|  | 9471 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_WHILE_CLIENT "peer=" | 
|  | 9472 | MACSTR, MAC2STR(params.peer->p2p_device_addr)); | 
|  | 9473 | return 0; | 
|  | 9474 | } | 
|  | 9475 |  | 
|  | 9476 | wpabuf_free(wpa_s->p2p_oob_dev_pw); | 
|  | 9477 | wpa_s->p2p_oob_dev_pw = NULL; | 
|  | 9478 |  | 
|  | 9479 | if (params.oob_dev_pw_len < WPS_OOB_PUBKEY_HASH_LEN + 2) { | 
|  | 9480 | wpa_printf(MSG_DEBUG, "P2P: No peer OOB Dev Pw " | 
|  | 9481 | "received"); | 
|  | 9482 | return -1; | 
|  | 9483 | } | 
|  | 9484 |  | 
|  | 9485 | id = WPA_GET_BE16(params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN); | 
|  | 9486 | wpa_printf(MSG_DEBUG, "P2P: Peer OOB Dev Pw %u", id); | 
|  | 9487 | wpa_hexdump(MSG_DEBUG, "P2P: Peer OOB Public Key hash", | 
|  | 9488 | params.oob_dev_pw, WPS_OOB_PUBKEY_HASH_LEN); | 
|  | 9489 | os_memcpy(wpa_s->p2p_peer_oob_pubkey_hash, | 
|  | 9490 | params.oob_dev_pw, WPS_OOB_PUBKEY_HASH_LEN); | 
|  | 9491 | wpa_s->p2p_peer_oob_pk_hash_known = 1; | 
|  | 9492 |  | 
|  | 9493 | if (tag) { | 
|  | 9494 | if (id < 0x10) { | 
|  | 9495 | wpa_printf(MSG_DEBUG, "P2P: Static handover - invalid " | 
|  | 9496 | "peer OOB Device Password Id %u", id); | 
|  | 9497 | return -1; | 
|  | 9498 | } | 
|  | 9499 | wpa_printf(MSG_DEBUG, "P2P: Static handover - use peer OOB " | 
|  | 9500 | "Device Password Id %u", id); | 
|  | 9501 | wpa_hexdump_key(MSG_DEBUG, "P2P: Peer OOB Device Password", | 
|  | 9502 | params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN + 2, | 
|  | 9503 | params.oob_dev_pw_len - | 
|  | 9504 | WPS_OOB_PUBKEY_HASH_LEN - 2); | 
|  | 9505 | wpa_s->p2p_oob_dev_pw_id = id; | 
|  | 9506 | wpa_s->p2p_oob_dev_pw = wpabuf_alloc_copy( | 
|  | 9507 | params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN + 2, | 
|  | 9508 | params.oob_dev_pw_len - | 
|  | 9509 | WPS_OOB_PUBKEY_HASH_LEN - 2); | 
|  | 9510 | if (wpa_s->p2p_oob_dev_pw == NULL) | 
|  | 9511 | return -1; | 
|  | 9512 |  | 
|  | 9513 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL && | 
|  | 9514 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, | 
|  | 9515 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) | 
|  | 9516 | return -1; | 
|  | 9517 | } else { | 
|  | 9518 | wpa_printf(MSG_DEBUG, "P2P: Using abbreviated WPS handshake " | 
|  | 9519 | "without Device Password"); | 
|  | 9520 | wpa_s->p2p_oob_dev_pw_id = DEV_PW_NFC_CONNECTION_HANDOVER; | 
|  | 9521 | } | 
|  | 9522 |  | 
|  | 9523 | switch (params.next_step) { | 
|  | 9524 | case NO_ACTION: | 
|  | 9525 | case BOTH_GO: | 
|  | 9526 | case PEER_CLIENT: | 
|  | 9527 | /* already covered above */ | 
|  | 9528 | return 0; | 
|  | 9529 | case JOIN_GROUP: | 
|  | 9530 | return wpas_p2p_nfc_join_group(wpa_s, ¶ms); | 
|  | 9531 | case AUTH_JOIN: | 
|  | 9532 | return wpas_p2p_nfc_auth_join(wpa_s, ¶ms, tag); | 
|  | 9533 | case INIT_GO_NEG: | 
|  | 9534 | return wpas_p2p_nfc_init_go_neg(wpa_s, ¶ms, forced_freq); | 
|  | 9535 | case RESP_GO_NEG: | 
|  | 9536 | /* TODO: use own OOB Dev Pw */ | 
|  | 9537 | return wpas_p2p_nfc_resp_go_neg(wpa_s, ¶ms, forced_freq); | 
|  | 9538 | } | 
|  | 9539 |  | 
|  | 9540 | return -1; | 
|  | 9541 | } | 
|  | 9542 |  | 
|  | 9543 |  | 
|  | 9544 | int wpas_p2p_nfc_tag_process(struct wpa_supplicant *wpa_s, | 
|  | 9545 | const struct wpabuf *data, int forced_freq) | 
|  | 9546 | { | 
|  | 9547 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 9548 | return -1; | 
|  | 9549 |  | 
|  | 9550 | return wpas_p2p_nfc_connection_handover(wpa_s, data, 1, 1, forced_freq); | 
|  | 9551 | } | 
|  | 9552 |  | 
|  | 9553 |  | 
|  | 9554 | int wpas_p2p_nfc_report_handover(struct wpa_supplicant *wpa_s, int init, | 
|  | 9555 | const struct wpabuf *req, | 
|  | 9556 | const struct wpabuf *sel, int forced_freq) | 
|  | 9557 | { | 
|  | 9558 | struct wpabuf *tmp; | 
|  | 9559 | int ret; | 
|  | 9560 |  | 
|  | 9561 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 9562 | return -1; | 
|  | 9563 |  | 
|  | 9564 | wpa_printf(MSG_DEBUG, "NFC: P2P connection handover reported"); | 
|  | 9565 |  | 
|  | 9566 | wpa_hexdump_ascii(MSG_DEBUG, "NFC: Req", | 
|  | 9567 | wpabuf_head(req), wpabuf_len(req)); | 
|  | 9568 | wpa_hexdump_ascii(MSG_DEBUG, "NFC: Sel", | 
|  | 9569 | wpabuf_head(sel), wpabuf_len(sel)); | 
|  | 9570 | if (forced_freq) | 
|  | 9571 | wpa_printf(MSG_DEBUG, "NFC: Forced freq %d", forced_freq); | 
|  | 9572 | tmp = ndef_parse_p2p(init ? sel : req); | 
|  | 9573 | if (tmp == NULL) { | 
|  | 9574 | wpa_printf(MSG_DEBUG, "P2P: Could not parse NDEF"); | 
|  | 9575 | return -1; | 
|  | 9576 | } | 
|  | 9577 |  | 
|  | 9578 | ret = wpas_p2p_nfc_connection_handover(wpa_s, tmp, init, 0, | 
|  | 9579 | forced_freq); | 
|  | 9580 | wpabuf_free(tmp); | 
|  | 9581 |  | 
|  | 9582 | return ret; | 
|  | 9583 | } | 
|  | 9584 |  | 
|  | 9585 |  | 
|  | 9586 | int wpas_p2p_nfc_tag_enabled(struct wpa_supplicant *wpa_s, int enabled) | 
|  | 9587 | { | 
|  | 9588 | const u8 *if_addr; | 
|  | 9589 | int go_intent = wpa_s->conf->p2p_go_intent; | 
|  | 9590 | struct wpa_supplicant *iface; | 
|  | 9591 |  | 
|  | 9592 | if (wpa_s->global->p2p == NULL) | 
|  | 9593 | return -1; | 
|  | 9594 |  | 
|  | 9595 | if (!enabled) { | 
|  | 9596 | wpa_printf(MSG_DEBUG, "P2P: Disable use of own NFC Tag"); | 
|  | 9597 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) | 
|  | 9598 | { | 
|  | 9599 | if (!iface->ap_iface) | 
|  | 9600 | continue; | 
|  | 9601 | hostapd_wps_nfc_token_disable(iface->ap_iface->bss[0]); | 
|  | 9602 | } | 
|  | 9603 | p2p_set_authorized_oob_dev_pw_id(wpa_s->global->p2p, 0, | 
|  | 9604 | 0, NULL); | 
|  | 9605 | if (wpa_s->p2p_nfc_tag_enabled) | 
|  | 9606 | wpas_p2p_remove_pending_group_interface(wpa_s); | 
|  | 9607 | wpa_s->p2p_nfc_tag_enabled = 0; | 
|  | 9608 | return 0; | 
|  | 9609 | } | 
|  | 9610 |  | 
|  | 9611 | if (wpa_s->global->p2p_disabled) | 
|  | 9612 | return -1; | 
|  | 9613 |  | 
|  | 9614 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL || | 
|  | 9615 | wpa_s->conf->wps_nfc_dh_privkey == NULL || | 
|  | 9616 | wpa_s->conf->wps_nfc_dev_pw == NULL || | 
|  | 9617 | wpa_s->conf->wps_nfc_dev_pw_id < 0x10) { | 
|  | 9618 | wpa_printf(MSG_DEBUG, "P2P: NFC password token not configured " | 
|  | 9619 | "to allow static handover cases"); | 
|  | 9620 | return -1; | 
|  | 9621 | } | 
|  | 9622 |  | 
|  | 9623 | wpa_printf(MSG_DEBUG, "P2P: Enable use of own NFC Tag"); | 
|  | 9624 |  | 
|  | 9625 | wpa_s->p2p_oob_dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id; | 
|  | 9626 | wpabuf_free(wpa_s->p2p_oob_dev_pw); | 
|  | 9627 | wpa_s->p2p_oob_dev_pw = wpabuf_dup(wpa_s->conf->wps_nfc_dev_pw); | 
|  | 9628 | if (wpa_s->p2p_oob_dev_pw == NULL) | 
|  | 9629 | return -1; | 
|  | 9630 | wpa_s->p2p_peer_oob_pk_hash_known = 0; | 
|  | 9631 |  | 
| Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 9632 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO || | 
|  | 9633 | wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT) { | 
|  | 9634 | /* | 
|  | 9635 | * P2P Group Interface present and the command came on group | 
|  | 9636 | * interface, so enable the token for the current interface. | 
|  | 9637 | */ | 
|  | 9638 | wpa_s->create_p2p_iface = 0; | 
|  | 9639 | } else { | 
|  | 9640 | wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s); | 
|  | 9641 | } | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9642 |  | 
|  | 9643 | if (wpa_s->create_p2p_iface) { | 
|  | 9644 | enum wpa_driver_if_type iftype; | 
|  | 9645 | /* Prepare to add a new interface for the group */ | 
|  | 9646 | iftype = WPA_IF_P2P_GROUP; | 
|  | 9647 | if (go_intent == 15) | 
|  | 9648 | iftype = WPA_IF_P2P_GO; | 
|  | 9649 | if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) { | 
|  | 9650 | wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new " | 
|  | 9651 | "interface for the group"); | 
|  | 9652 | return -1; | 
|  | 9653 | } | 
|  | 9654 |  | 
|  | 9655 | if_addr = wpa_s->pending_interface_addr; | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 9656 | } else if (wpa_s->p2p_mgmt) | 
|  | 9657 | if_addr = wpa_s->parent->own_addr; | 
|  | 9658 | else | 
| Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 9659 | if_addr = wpa_s->own_addr; | 
|  | 9660 |  | 
|  | 9661 | wpa_s->p2p_nfc_tag_enabled = enabled; | 
|  | 9662 |  | 
|  | 9663 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { | 
|  | 9664 | struct hostapd_data *hapd; | 
|  | 9665 | if (iface->ap_iface == NULL) | 
|  | 9666 | continue; | 
|  | 9667 | hapd = iface->ap_iface->bss[0]; | 
|  | 9668 | wpabuf_free(hapd->conf->wps_nfc_dh_pubkey); | 
|  | 9669 | hapd->conf->wps_nfc_dh_pubkey = | 
|  | 9670 | wpabuf_dup(wpa_s->conf->wps_nfc_dh_pubkey); | 
|  | 9671 | wpabuf_free(hapd->conf->wps_nfc_dh_privkey); | 
|  | 9672 | hapd->conf->wps_nfc_dh_privkey = | 
|  | 9673 | wpabuf_dup(wpa_s->conf->wps_nfc_dh_privkey); | 
|  | 9674 | wpabuf_free(hapd->conf->wps_nfc_dev_pw); | 
|  | 9675 | hapd->conf->wps_nfc_dev_pw = | 
|  | 9676 | wpabuf_dup(wpa_s->conf->wps_nfc_dev_pw); | 
|  | 9677 | hapd->conf->wps_nfc_dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id; | 
|  | 9678 |  | 
|  | 9679 | if (hostapd_wps_nfc_token_enable(iface->ap_iface->bss[0]) < 0) { | 
|  | 9680 | wpa_dbg(iface, MSG_DEBUG, | 
|  | 9681 | "P2P: Failed to enable NFC Tag for GO"); | 
|  | 9682 | } | 
|  | 9683 | } | 
|  | 9684 | p2p_set_authorized_oob_dev_pw_id( | 
|  | 9685 | wpa_s->global->p2p, wpa_s->conf->wps_nfc_dev_pw_id, go_intent, | 
|  | 9686 | if_addr); | 
|  | 9687 |  | 
|  | 9688 | return 0; | 
|  | 9689 | } | 
|  | 9690 |  | 
|  | 9691 | #endif /* CONFIG_WPS_NFC */ | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9692 |  | 
|  | 9693 |  | 
|  | 9694 | static void wpas_p2p_optimize_listen_channel(struct wpa_supplicant *wpa_s, | 
|  | 9695 | struct wpa_used_freq_data *freqs, | 
|  | 9696 | unsigned int num) | 
|  | 9697 | { | 
|  | 9698 | u8 curr_chan, cand, chan; | 
|  | 9699 | unsigned int i; | 
|  | 9700 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9701 | /* | 
|  | 9702 | * If possible, optimize the Listen channel to be a channel that is | 
|  | 9703 | * already used by one of the other interfaces. | 
|  | 9704 | */ | 
|  | 9705 | if (!wpa_s->conf->p2p_optimize_listen_chan) | 
|  | 9706 | return; | 
|  | 9707 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9708 | curr_chan = p2p_get_listen_channel(wpa_s->global->p2p); | 
|  | 9709 | for (i = 0, cand = 0; i < num; i++) { | 
|  | 9710 | ieee80211_freq_to_chan(freqs[i].freq, &chan); | 
|  | 9711 | if (curr_chan == chan) { | 
|  | 9712 | cand = 0; | 
|  | 9713 | break; | 
|  | 9714 | } | 
|  | 9715 |  | 
|  | 9716 | if (chan == 1 || chan == 6 || chan == 11) | 
|  | 9717 | cand = chan; | 
|  | 9718 | } | 
|  | 9719 |  | 
|  | 9720 | if (cand) { | 
|  | 9721 | wpa_dbg(wpa_s, MSG_DEBUG, | 
| Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 9722 | "P2P: Update Listen channel to %u based on operating channel", | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9723 | cand); | 
|  | 9724 | p2p_set_listen_channel(wpa_s->global->p2p, 81, cand, 0); | 
|  | 9725 | } | 
|  | 9726 | } | 
|  | 9727 |  | 
|  | 9728 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9729 | static int wpas_p2p_move_go_csa(struct wpa_supplicant *wpa_s) | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9730 | { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9731 | struct hostapd_config *conf; | 
|  | 9732 | struct p2p_go_neg_results params; | 
|  | 9733 | struct csa_settings csa_settings; | 
|  | 9734 | struct wpa_ssid *current_ssid = wpa_s->current_ssid; | 
|  | 9735 | int old_freq = current_ssid->frequency; | 
|  | 9736 | int ret; | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9737 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9738 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)) { | 
|  | 9739 | wpa_dbg(wpa_s, MSG_DEBUG, "CSA is not enabled"); | 
|  | 9740 | return -1; | 
|  | 9741 | } | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9742 |  | 
|  | 9743 | /* | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9744 | * TODO: This function may not always work correctly. For example, | 
|  | 9745 | * 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] | 9746 | */ | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9747 | if (wpas_p2p_init_go_params(wpa_s, ¶ms, 0, 0, 0, 0, 0, 0, 0, | 
|  | 9748 | NULL)) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9749 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 9750 | "P2P CSA: Failed to select new frequency for GO"); | 
|  | 9751 | return -1; | 
|  | 9752 | } | 
|  | 9753 |  | 
|  | 9754 | if (current_ssid->frequency == params.freq) { | 
|  | 9755 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 9756 | "P2P CSA: Selected same frequency - not moving GO"); | 
|  | 9757 | return 0; | 
|  | 9758 | } | 
|  | 9759 |  | 
|  | 9760 | conf = hostapd_config_defaults(); | 
|  | 9761 | if (!conf) { | 
|  | 9762 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 9763 | "P2P CSA: Failed to allocate default config"); | 
|  | 9764 | return -1; | 
|  | 9765 | } | 
|  | 9766 |  | 
|  | 9767 | current_ssid->frequency = params.freq; | 
|  | 9768 | if (wpa_supplicant_conf_ap_ht(wpa_s, current_ssid, conf)) { | 
|  | 9769 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 9770 | "P2P CSA: Failed to create new GO config"); | 
|  | 9771 | ret = -1; | 
|  | 9772 | goto out; | 
|  | 9773 | } | 
|  | 9774 |  | 
| Sunil | 4a3f9f5 | 2022-07-19 22:04:39 +0000 | [diff] [blame] | 9775 | if (conf->hw_mode != wpa_s->ap_iface->current_mode->mode && | 
|  | 9776 | (wpa_s->ap_iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A || | 
| Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 9777 | is_6ghz_freq(wpa_s->ap_iface->freq) || | 
| Sunil | 4a3f9f5 | 2022-07-19 22:04:39 +0000 | [diff] [blame] | 9778 | conf->hw_mode != HOSTAPD_MODE_IEEE80211G)) { | 
|  | 9779 | wpa_dbg(wpa_s, MSG_INFO, | 
| Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 9780 | "P2P CSA: CSA from hardware mode %d%s to %d is not supported", | 
|  | 9781 | wpa_s->ap_iface->current_mode->mode, | 
|  | 9782 | is_6ghz_freq(wpa_s->ap_iface->freq) ? " (6 GHz)" : "", | 
|  | 9783 | conf->hw_mode); | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9784 | ret = -1; | 
|  | 9785 | goto out; | 
|  | 9786 | } | 
|  | 9787 |  | 
|  | 9788 | os_memset(&csa_settings, 0, sizeof(csa_settings)); | 
|  | 9789 | csa_settings.cs_count = P2P_GO_CSA_COUNT; | 
|  | 9790 | csa_settings.block_tx = P2P_GO_CSA_BLOCK_TX; | 
|  | 9791 | csa_settings.freq_params.freq = params.freq; | 
|  | 9792 | csa_settings.freq_params.sec_channel_offset = conf->secondary_channel; | 
|  | 9793 | csa_settings.freq_params.ht_enabled = conf->ieee80211n; | 
|  | 9794 | csa_settings.freq_params.bandwidth = conf->secondary_channel ? 40 : 20; | 
|  | 9795 |  | 
|  | 9796 | if (conf->ieee80211ac) { | 
|  | 9797 | int freq1 = 0, freq2 = 0; | 
|  | 9798 | u8 chan, opclass; | 
|  | 9799 |  | 
|  | 9800 | if (ieee80211_freq_to_channel_ext(params.freq, | 
|  | 9801 | conf->secondary_channel, | 
|  | 9802 | conf->vht_oper_chwidth, | 
|  | 9803 | &opclass, &chan) == | 
|  | 9804 | NUM_HOSTAPD_MODES) { | 
|  | 9805 | wpa_printf(MSG_ERROR, "P2P CSA: Bad freq"); | 
|  | 9806 | ret = -1; | 
|  | 9807 | goto out; | 
|  | 9808 | } | 
|  | 9809 |  | 
|  | 9810 | if (conf->vht_oper_centr_freq_seg0_idx) | 
|  | 9811 | freq1 = ieee80211_chan_to_freq( | 
|  | 9812 | NULL, opclass, | 
|  | 9813 | conf->vht_oper_centr_freq_seg0_idx); | 
|  | 9814 |  | 
|  | 9815 | if (conf->vht_oper_centr_freq_seg1_idx) | 
|  | 9816 | freq2 = ieee80211_chan_to_freq( | 
|  | 9817 | NULL, opclass, | 
|  | 9818 | conf->vht_oper_centr_freq_seg1_idx); | 
|  | 9819 |  | 
|  | 9820 | if (freq1 < 0 || freq2 < 0) { | 
|  | 9821 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 9822 | "P2P CSA: Selected invalid VHT center freqs"); | 
|  | 9823 | ret = -1; | 
|  | 9824 | goto out; | 
|  | 9825 | } | 
|  | 9826 |  | 
|  | 9827 | csa_settings.freq_params.vht_enabled = conf->ieee80211ac; | 
|  | 9828 | csa_settings.freq_params.center_freq1 = freq1; | 
|  | 9829 | csa_settings.freq_params.center_freq2 = freq2; | 
|  | 9830 |  | 
|  | 9831 | switch (conf->vht_oper_chwidth) { | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 9832 | case CONF_OPER_CHWIDTH_80MHZ: | 
|  | 9833 | case CONF_OPER_CHWIDTH_80P80MHZ: | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9834 | csa_settings.freq_params.bandwidth = 80; | 
|  | 9835 | break; | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 9836 | case CONF_OPER_CHWIDTH_160MHZ: | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9837 | csa_settings.freq_params.bandwidth = 160; | 
|  | 9838 | break; | 
| Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 9839 | default: | 
|  | 9840 | break; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9841 | } | 
|  | 9842 | } | 
|  | 9843 |  | 
|  | 9844 | ret = ap_switch_channel(wpa_s, &csa_settings); | 
|  | 9845 | out: | 
|  | 9846 | current_ssid->frequency = old_freq; | 
|  | 9847 | hostapd_config_free(conf); | 
|  | 9848 | return ret; | 
|  | 9849 | } | 
|  | 9850 |  | 
|  | 9851 |  | 
|  | 9852 | static void wpas_p2p_move_go_no_csa(struct wpa_supplicant *wpa_s) | 
|  | 9853 | { | 
|  | 9854 | struct p2p_go_neg_results params; | 
|  | 9855 | struct wpa_ssid *current_ssid = wpa_s->current_ssid; | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9856 | void (*ap_configured_cb)(void *ctx, void *data); | 
|  | 9857 | void *ap_configured_cb_ctx, *ap_configured_cb_data; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9858 |  | 
|  | 9859 | wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP); | 
|  | 9860 |  | 
|  | 9861 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Move GO from freq=%d MHz", | 
|  | 9862 | current_ssid->frequency); | 
|  | 9863 |  | 
|  | 9864 | /* Stop the AP functionality */ | 
|  | 9865 | /* TODO: Should do this in a way that does not indicated to possible | 
|  | 9866 | * P2P Clients in the group that the group is terminated. */ | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9867 | /* If this action occurs before a group is started, the callback should | 
|  | 9868 | * be preserved, or GROUP-STARTED event would be lost. If this action | 
|  | 9869 | * occurs after a group is started, these pointers are all NULL and | 
|  | 9870 | * harmless. */ | 
|  | 9871 | ap_configured_cb = wpa_s->ap_configured_cb; | 
|  | 9872 | ap_configured_cb_ctx = wpa_s->ap_configured_cb_ctx; | 
|  | 9873 | ap_configured_cb_data = wpa_s->ap_configured_cb_data; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9874 | wpa_supplicant_ap_deinit(wpa_s); | 
|  | 9875 |  | 
|  | 9876 | /* Reselect the GO frequency */ | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 9877 | if (wpas_p2p_init_go_params(wpa_s, ¶ms, 0, 0, 0, 0, 0, 0, 0, | 
|  | 9878 | NULL)) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9879 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Failed to reselect freq"); | 
|  | 9880 | wpas_p2p_group_delete(wpa_s, | 
|  | 9881 | P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL); | 
|  | 9882 | return; | 
|  | 9883 | } | 
|  | 9884 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New freq selected for the GO (%u MHz)", | 
|  | 9885 | params.freq); | 
|  | 9886 |  | 
|  | 9887 | if (params.freq && | 
|  | 9888 | !p2p_supported_freq_go(wpa_s->global->p2p, params.freq)) { | 
|  | 9889 | wpa_printf(MSG_DEBUG, | 
|  | 9890 | "P2P: Selected freq (%u MHz) is not valid for P2P", | 
|  | 9891 | params.freq); | 
|  | 9892 | wpas_p2p_group_delete(wpa_s, | 
|  | 9893 | P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL); | 
|  | 9894 | return; | 
|  | 9895 | } | 
|  | 9896 |  | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9897 | /* Restore preserved callback parameters */ | 
| Jimmy Chen | 4b2a502 | 2020-08-26 18:55:45 +0800 | [diff] [blame] | 9898 | wpa_s->ap_configured_cb = ap_configured_cb; | 
|  | 9899 | wpa_s->ap_configured_cb_ctx = ap_configured_cb_ctx; | 
|  | 9900 | wpa_s->ap_configured_cb_data = ap_configured_cb_data; | 
| Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9901 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9902 | /* Update the frequency */ | 
|  | 9903 | current_ssid->frequency = params.freq; | 
|  | 9904 | wpa_s->connect_without_scan = current_ssid; | 
|  | 9905 | wpa_s->reassociate = 1; | 
|  | 9906 | wpa_s->disconnected = 0; | 
|  | 9907 | wpa_supplicant_req_scan(wpa_s, 0, 0); | 
|  | 9908 | } | 
|  | 9909 |  | 
|  | 9910 |  | 
|  | 9911 | static void wpas_p2p_move_go(void *eloop_ctx, void *timeout_ctx) | 
|  | 9912 | { | 
|  | 9913 | struct wpa_supplicant *wpa_s = eloop_ctx; | 
|  | 9914 |  | 
|  | 9915 | if (!wpa_s->ap_iface || !wpa_s->current_ssid) | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9916 | return; | 
|  | 9917 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9918 | wpas_p2p_go_update_common_freqs(wpa_s); | 
|  | 9919 |  | 
|  | 9920 | /* Do not move GO in the middle of a CSA */ | 
|  | 9921 | if (hostapd_csa_in_progress(wpa_s->ap_iface)) { | 
|  | 9922 | wpa_printf(MSG_DEBUG, | 
|  | 9923 | "P2P: CSA is in progress - not moving GO"); | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9924 | return; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9925 | } | 
|  | 9926 |  | 
|  | 9927 | /* | 
|  | 9928 | * First, try a channel switch flow. If it is not supported or fails, | 
|  | 9929 | * take down the GO and bring it up again. | 
|  | 9930 | */ | 
|  | 9931 | if (wpas_p2p_move_go_csa(wpa_s) < 0) | 
|  | 9932 | wpas_p2p_move_go_no_csa(wpa_s); | 
|  | 9933 | } | 
|  | 9934 |  | 
|  | 9935 |  | 
|  | 9936 | static void wpas_p2p_reconsider_moving_go(void *eloop_ctx, void *timeout_ctx) | 
|  | 9937 | { | 
|  | 9938 | struct wpa_supplicant *wpa_s = eloop_ctx; | 
|  | 9939 | struct wpa_used_freq_data *freqs = NULL; | 
|  | 9940 | unsigned int num = wpa_s->num_multichan_concurrent; | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9941 |  | 
|  | 9942 | freqs = os_calloc(num, sizeof(struct wpa_used_freq_data)); | 
|  | 9943 | if (!freqs) | 
|  | 9944 | return; | 
|  | 9945 |  | 
|  | 9946 | num = get_shared_radio_freqs_data(wpa_s, freqs, num); | 
|  | 9947 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9948 | /* Previous attempt to move a GO was not possible -- try again. */ | 
|  | 9949 | wpas_p2p_consider_moving_gos(wpa_s, freqs, num, | 
|  | 9950 | WPAS_P2P_CHANNEL_UPDATE_ANY); | 
|  | 9951 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 9952 | os_free(freqs); | 
|  | 9953 | } | 
|  | 9954 |  | 
|  | 9955 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9956 | /* | 
|  | 9957 | * Consider moving a GO from its currently used frequency: | 
|  | 9958 | * 1. It is possible that due to regulatory consideration the frequency | 
|  | 9959 | *    can no longer be used and there is a need to evacuate the GO. | 
|  | 9960 | * 2. It is possible that due to MCC considerations, it would be preferable | 
|  | 9961 | *    to move the GO to a channel that is currently used by some other | 
|  | 9962 | *    station interface. | 
|  | 9963 | * | 
|  | 9964 | * In case a frequency that became invalid is once again valid, cancel a | 
|  | 9965 | * previously initiated GO frequency change. | 
|  | 9966 | */ | 
|  | 9967 | static void wpas_p2p_consider_moving_one_go(struct wpa_supplicant *wpa_s, | 
|  | 9968 | struct wpa_used_freq_data *freqs, | 
|  | 9969 | unsigned int num) | 
|  | 9970 | { | 
|  | 9971 | unsigned int i, invalid_freq = 0, policy_move = 0, flags = 0; | 
|  | 9972 | unsigned int timeout; | 
|  | 9973 | int freq; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9974 | int dfs_offload; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9975 |  | 
|  | 9976 | wpas_p2p_go_update_common_freqs(wpa_s); | 
|  | 9977 |  | 
|  | 9978 | freq = wpa_s->current_ssid->frequency; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9979 | dfs_offload = (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9980 | 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] | 9981 | for (i = 0, invalid_freq = 0; i < num; i++) { | 
|  | 9982 | if (freqs[i].freq == freq) { | 
|  | 9983 | flags = freqs[i].flags; | 
|  | 9984 |  | 
|  | 9985 | /* The channel is invalid, must change it */ | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9986 | if (!p2p_supported_freq_go(wpa_s->global->p2p, freq) && | 
|  | 9987 | !dfs_offload) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9988 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 9989 | "P2P: Freq=%d MHz no longer valid for GO", | 
|  | 9990 | freq); | 
|  | 9991 | invalid_freq = 1; | 
|  | 9992 | } | 
|  | 9993 | } else if (freqs[i].flags == 0) { | 
|  | 9994 | /* Freq is not used by any other station interface */ | 
|  | 9995 | continue; | 
|  | 9996 | } else if (!p2p_supported_freq(wpa_s->global->p2p, | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9997 | freqs[i].freq) && !dfs_offload) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9998 | /* Freq is not valid for P2P use cases */ | 
|  | 9999 | continue; | 
|  | 10000 | } else if (wpa_s->conf->p2p_go_freq_change_policy == | 
|  | 10001 | P2P_GO_FREQ_MOVE_SCM) { | 
|  | 10002 | policy_move = 1; | 
|  | 10003 | } else if (wpa_s->conf->p2p_go_freq_change_policy == | 
|  | 10004 | P2P_GO_FREQ_MOVE_SCM_PEER_SUPPORTS && | 
|  | 10005 | wpas_p2p_go_is_peer_freq(wpa_s, freqs[i].freq)) { | 
|  | 10006 | policy_move = 1; | 
|  | 10007 | } else if ((wpa_s->conf->p2p_go_freq_change_policy == | 
|  | 10008 | P2P_GO_FREQ_MOVE_SCM_ECSA) && | 
|  | 10009 | wpas_p2p_go_is_peer_freq(wpa_s, freqs[i].freq)) { | 
|  | 10010 | if (!p2p_get_group_num_members(wpa_s->p2p_group)) { | 
|  | 10011 | policy_move = 1; | 
|  | 10012 | } else if ((wpa_s->drv_flags & | 
|  | 10013 | WPA_DRIVER_FLAGS_AP_CSA) && | 
|  | 10014 | wpas_p2p_go_clients_support_ecsa(wpa_s)) { | 
|  | 10015 | u8 chan; | 
|  | 10016 |  | 
|  | 10017 | /* | 
|  | 10018 | * We do not support CSA between bands, so move | 
|  | 10019 | * GO only within the same band. | 
|  | 10020 | */ | 
|  | 10021 | if (wpa_s->ap_iface->current_mode->mode == | 
|  | 10022 | ieee80211_freq_to_chan(freqs[i].freq, | 
|  | 10023 | &chan)) | 
|  | 10024 | policy_move = 1; | 
|  | 10025 | } | 
|  | 10026 | } | 
|  | 10027 | } | 
|  | 10028 |  | 
|  | 10029 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 10030 | "P2P: GO move: invalid_freq=%u, policy_move=%u, flags=0x%X", | 
|  | 10031 | invalid_freq, policy_move, flags); | 
|  | 10032 |  | 
|  | 10033 | /* | 
|  | 10034 | * The channel is valid, or we are going to have a policy move, so | 
|  | 10035 | * cancel timeout. | 
|  | 10036 | */ | 
|  | 10037 | if (!invalid_freq || policy_move) { | 
|  | 10038 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 10039 | "P2P: Cancel a GO move from freq=%d MHz", freq); | 
|  | 10040 | eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL); | 
|  | 10041 |  | 
|  | 10042 | if (wpas_p2p_in_progress(wpa_s)) { | 
|  | 10043 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 10044 | "P2P: GO move: policy CS is not allowed - setting timeout to re-consider GO move"); | 
|  | 10045 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, | 
|  | 10046 | wpa_s, NULL); | 
|  | 10047 | eloop_register_timeout(P2P_RECONSIDER_GO_MOVE_DELAY, 0, | 
|  | 10048 | wpas_p2p_reconsider_moving_go, | 
|  | 10049 | wpa_s, NULL); | 
|  | 10050 | return; | 
|  | 10051 | } | 
|  | 10052 | } | 
|  | 10053 |  | 
|  | 10054 | if (!invalid_freq && (!policy_move || flags != 0)) { | 
|  | 10055 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 10056 | "P2P: Not initiating a GO frequency change"); | 
|  | 10057 | return; | 
|  | 10058 | } | 
|  | 10059 |  | 
|  | 10060 | /* | 
|  | 10061 | * Do not consider moving GO if it is in the middle of a CSA. When the | 
|  | 10062 | * CSA is finished this flow should be retriggered. | 
|  | 10063 | */ | 
|  | 10064 | if (hostapd_csa_in_progress(wpa_s->ap_iface)) { | 
|  | 10065 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 10066 | "P2P: Not initiating a GO frequency change - CSA is in progress"); | 
|  | 10067 | return; | 
|  | 10068 | } | 
|  | 10069 |  | 
|  | 10070 | if (invalid_freq && !wpas_p2p_disallowed_freq(wpa_s->global, freq)) | 
|  | 10071 | timeout = P2P_GO_FREQ_CHANGE_TIME; | 
|  | 10072 | else | 
|  | 10073 | timeout = 0; | 
|  | 10074 |  | 
|  | 10075 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Move GO from freq=%d MHz in %d secs", | 
|  | 10076 | freq, timeout); | 
|  | 10077 | eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL); | 
|  | 10078 | eloop_register_timeout(timeout, 0, wpas_p2p_move_go, wpa_s, NULL); | 
|  | 10079 | } | 
|  | 10080 |  | 
|  | 10081 |  | 
|  | 10082 | static void wpas_p2p_consider_moving_gos(struct wpa_supplicant *wpa_s, | 
|  | 10083 | struct wpa_used_freq_data *freqs, | 
|  | 10084 | unsigned int num, | 
|  | 10085 | enum wpas_p2p_channel_update_trig trig) | 
|  | 10086 | { | 
|  | 10087 | struct wpa_supplicant *ifs; | 
|  | 10088 |  | 
|  | 10089 | eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, ELOOP_ALL_CTX, | 
|  | 10090 | NULL); | 
|  | 10091 |  | 
|  | 10092 | /* | 
|  | 10093 | * Travers all the radio interfaces, and for each GO interface, check | 
|  | 10094 | * if there is a need to move the GO from the frequency it is using, | 
|  | 10095 | * or in case the frequency is valid again, cancel the evacuation flow. | 
|  | 10096 | */ | 
|  | 10097 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, | 
|  | 10098 | radio_list) { | 
|  | 10099 | if (ifs->current_ssid == NULL || | 
|  | 10100 | ifs->current_ssid->mode != WPAS_MODE_P2P_GO) | 
|  | 10101 | continue; | 
|  | 10102 |  | 
|  | 10103 | /* | 
|  | 10104 | * The GO was just started or completed channel switch, no need | 
|  | 10105 | * to move it. | 
|  | 10106 | */ | 
|  | 10107 | if (wpa_s == ifs && | 
|  | 10108 | (trig == WPAS_P2P_CHANNEL_UPDATE_STATE_CHANGE || | 
|  | 10109 | trig == WPAS_P2P_CHANNEL_UPDATE_CS)) { | 
|  | 10110 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 10111 | "P2P: GO move - schedule re-consideration"); | 
|  | 10112 | eloop_register_timeout(P2P_RECONSIDER_GO_MOVE_DELAY, 0, | 
|  | 10113 | wpas_p2p_reconsider_moving_go, | 
|  | 10114 | wpa_s, NULL); | 
|  | 10115 | continue; | 
|  | 10116 | } | 
|  | 10117 |  | 
|  | 10118 | wpas_p2p_consider_moving_one_go(ifs, freqs, num); | 
|  | 10119 | } | 
|  | 10120 | } | 
|  | 10121 |  | 
|  | 10122 |  | 
|  | 10123 | void wpas_p2p_indicate_state_change(struct wpa_supplicant *wpa_s) | 
|  | 10124 | { | 
|  | 10125 | if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) | 
|  | 10126 | return; | 
|  | 10127 |  | 
|  | 10128 | wpas_p2p_update_channel_list(wpa_s, | 
|  | 10129 | WPAS_P2P_CHANNEL_UPDATE_STATE_CHANGE); | 
|  | 10130 | } | 
|  | 10131 |  | 
|  | 10132 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10133 | void wpas_p2p_deinit_iface(struct wpa_supplicant *wpa_s) | 
|  | 10134 | { | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 10135 | if (wpa_s == wpa_s->global->p2p_init_wpa_s && wpa_s->global->p2p) { | 
|  | 10136 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disable P2P since removing " | 
|  | 10137 | "the management interface is being removed"); | 
|  | 10138 | wpas_p2p_deinit_global(wpa_s->global); | 
|  | 10139 | } | 
|  | 10140 | } | 
|  | 10141 |  | 
|  | 10142 |  | 
|  | 10143 | void wpas_p2p_ap_deinit(struct wpa_supplicant *wpa_s) | 
|  | 10144 | { | 
|  | 10145 | if (wpa_s->ap_iface->bss) | 
|  | 10146 | wpa_s->ap_iface->bss[0]->p2p_group = NULL; | 
|  | 10147 | wpas_p2p_group_deinit(wpa_s); | 
|  | 10148 | } | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10149 |  | 
|  | 10150 |  | 
|  | 10151 | int wpas_p2p_lo_start(struct wpa_supplicant *wpa_s, unsigned int freq, | 
|  | 10152 | unsigned int period, unsigned int interval, | 
|  | 10153 | unsigned int count) | 
|  | 10154 | { | 
|  | 10155 | struct p2p_data *p2p = wpa_s->global->p2p; | 
|  | 10156 | u8 *device_types; | 
|  | 10157 | size_t dev_types_len; | 
|  | 10158 | struct wpabuf *buf; | 
|  | 10159 | int ret; | 
|  | 10160 |  | 
|  | 10161 | if (wpa_s->p2p_lo_started) { | 
|  | 10162 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 10163 | "P2P Listen offload is already started"); | 
|  | 10164 | return 0; | 
|  | 10165 | } | 
|  | 10166 |  | 
|  | 10167 | if (wpa_s->global->p2p == NULL || | 
|  | 10168 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) { | 
|  | 10169 | wpa_printf(MSG_DEBUG, "P2P: Listen offload not supported"); | 
|  | 10170 | return -1; | 
|  | 10171 | } | 
|  | 10172 |  | 
|  | 10173 | if (!p2p_supported_freq(wpa_s->global->p2p, freq)) { | 
|  | 10174 | wpa_printf(MSG_ERROR, "P2P: Input channel not supported: %u", | 
|  | 10175 | freq); | 
|  | 10176 | return -1; | 
|  | 10177 | } | 
|  | 10178 |  | 
|  | 10179 | /* Get device type */ | 
|  | 10180 | dev_types_len = (wpa_s->conf->num_sec_device_types + 1) * | 
|  | 10181 | WPS_DEV_TYPE_LEN; | 
|  | 10182 | device_types = os_malloc(dev_types_len); | 
|  | 10183 | if (!device_types) | 
|  | 10184 | return -1; | 
|  | 10185 | os_memcpy(device_types, wpa_s->conf->device_type, WPS_DEV_TYPE_LEN); | 
|  | 10186 | os_memcpy(&device_types[WPS_DEV_TYPE_LEN], wpa_s->conf->sec_device_type, | 
|  | 10187 | wpa_s->conf->num_sec_device_types * WPS_DEV_TYPE_LEN); | 
|  | 10188 |  | 
|  | 10189 | /* Get Probe Response IE(s) */ | 
|  | 10190 | buf = p2p_build_probe_resp_template(p2p, freq); | 
|  | 10191 | if (!buf) { | 
|  | 10192 | os_free(device_types); | 
|  | 10193 | return -1; | 
|  | 10194 | } | 
|  | 10195 |  | 
|  | 10196 | ret = wpa_drv_p2p_lo_start(wpa_s, freq, period, interval, count, | 
|  | 10197 | device_types, dev_types_len, | 
|  | 10198 | wpabuf_mhead_u8(buf), wpabuf_len(buf)); | 
|  | 10199 | if (ret < 0) | 
|  | 10200 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 10201 | "P2P: Failed to start P2P listen offload"); | 
|  | 10202 |  | 
|  | 10203 | os_free(device_types); | 
|  | 10204 | wpabuf_free(buf); | 
|  | 10205 |  | 
|  | 10206 | if (ret == 0) { | 
|  | 10207 | wpa_s->p2p_lo_started = 1; | 
|  | 10208 |  | 
|  | 10209 | /* Stop current P2P listen if any */ | 
|  | 10210 | wpas_stop_listen(wpa_s); | 
|  | 10211 | } | 
|  | 10212 |  | 
|  | 10213 | return ret; | 
|  | 10214 | } | 
|  | 10215 |  | 
|  | 10216 |  | 
|  | 10217 | int wpas_p2p_lo_stop(struct wpa_supplicant *wpa_s) | 
|  | 10218 | { | 
|  | 10219 | int ret; | 
|  | 10220 |  | 
|  | 10221 | if (!wpa_s->p2p_lo_started) | 
|  | 10222 | return 0; | 
|  | 10223 |  | 
|  | 10224 | ret = wpa_drv_p2p_lo_stop(wpa_s); | 
|  | 10225 | if (ret < 0) | 
|  | 10226 | wpa_dbg(wpa_s, MSG_DEBUG, | 
|  | 10227 | "P2P: Failed to stop P2P listen offload"); | 
|  | 10228 |  | 
|  | 10229 | wpa_s->p2p_lo_started = 0; | 
|  | 10230 | return ret; | 
|  | 10231 | } |