Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Wi-Fi Direct - P2P Invitation procedure |
| 3 | * Copyright (c) 2010, Atheros Communications |
| 4 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5 | * This software may be distributed under the terms of the BSD license. |
| 6 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include "includes.h" |
| 10 | |
| 11 | #include "common.h" |
| 12 | #include "common/ieee802_11_defs.h" |
| 13 | #include "p2p_i.h" |
| 14 | #include "p2p.h" |
| 15 | |
| 16 | |
| 17 | static struct wpabuf * p2p_build_invitation_req(struct p2p_data *p2p, |
| 18 | struct p2p_device *peer, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 19 | const u8 *go_dev_addr, |
| 20 | int dev_pw_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 21 | { |
| 22 | struct wpabuf *buf; |
| 23 | u8 *len; |
| 24 | const u8 *dev_addr; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 25 | size_t extra = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 26 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 27 | #ifdef CONFIG_WIFI_DISPLAY |
| 28 | struct wpabuf *wfd_ie = p2p->wfd_ie_invitation; |
| 29 | if (wfd_ie && p2p->inv_role == P2P_INVITE_ROLE_ACTIVE_GO) { |
| 30 | size_t i; |
| 31 | for (i = 0; i < p2p->num_groups; i++) { |
| 32 | struct p2p_group *g = p2p->groups[i]; |
| 33 | struct wpabuf *ie; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 34 | if (os_memcmp(p2p_group_get_interface_addr(g), |
| 35 | p2p->inv_bssid, ETH_ALEN) != 0) |
| 36 | continue; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 37 | ie = p2p_group_get_wfd_ie(g); |
| 38 | if (ie) { |
| 39 | wfd_ie = ie; |
| 40 | break; |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | if (wfd_ie) |
| 45 | extra = wpabuf_len(wfd_ie); |
| 46 | #endif /* CONFIG_WIFI_DISPLAY */ |
| 47 | |
| 48 | buf = wpabuf_alloc(1000 + extra); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 49 | if (buf == NULL) |
| 50 | return NULL; |
| 51 | |
| 52 | peer->dialog_token++; |
| 53 | if (peer->dialog_token == 0) |
| 54 | peer->dialog_token = 1; |
| 55 | p2p_buf_add_public_action_hdr(buf, P2P_INVITATION_REQ, |
| 56 | peer->dialog_token); |
| 57 | |
| 58 | len = p2p_buf_add_ie_hdr(buf); |
| 59 | if (p2p->inv_role == P2P_INVITE_ROLE_ACTIVE_GO || !p2p->inv_persistent) |
| 60 | p2p_buf_add_config_timeout(buf, 0, 0); |
| 61 | else |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 62 | p2p_buf_add_config_timeout(buf, p2p->go_timeout, |
| 63 | p2p->client_timeout); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 64 | p2p_buf_add_invitation_flags(buf, p2p->inv_persistent ? |
| 65 | P2P_INVITATION_FLAGS_TYPE : 0); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 66 | if (p2p->inv_role != P2P_INVITE_ROLE_CLIENT || |
| 67 | !(peer->flags & P2P_DEV_NO_PREF_CHAN)) |
| 68 | p2p_buf_add_operating_channel(buf, p2p->cfg->country, |
| 69 | p2p->op_reg_class, |
| 70 | p2p->op_channel); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 71 | if (p2p->inv_bssid_set) |
| 72 | p2p_buf_add_group_bssid(buf, p2p->inv_bssid); |
Irfan Sheriff | 069fa2c | 2012-09-24 23:59:04 -0700 | [diff] [blame] | 73 | p2p_buf_add_channel_list(buf, p2p->cfg->country, &p2p->channels); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 74 | if (go_dev_addr) |
| 75 | dev_addr = go_dev_addr; |
| 76 | else if (p2p->inv_role == P2P_INVITE_ROLE_CLIENT) |
| 77 | dev_addr = peer->info.p2p_device_addr; |
| 78 | else |
| 79 | dev_addr = p2p->cfg->dev_addr; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 80 | p2p_buf_add_group_id(buf, dev_addr, p2p->inv_ssid, p2p->inv_ssid_len); |
| 81 | p2p_buf_add_device_info(buf, p2p, peer); |
| 82 | p2p_buf_update_ie_hdr(buf, len); |
| 83 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 84 | #ifdef CONFIG_WIFI_DISPLAY |
| 85 | if (wfd_ie) |
| 86 | wpabuf_put_buf(buf, wfd_ie); |
| 87 | #endif /* CONFIG_WIFI_DISPLAY */ |
| 88 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 89 | if (dev_pw_id >= 0) { |
| 90 | /* WSC IE in Invitation Request for NFC static handover */ |
| 91 | p2p_build_wps_ie(p2p, buf, dev_pw_id, 0); |
| 92 | } |
| 93 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 94 | return buf; |
| 95 | } |
| 96 | |
| 97 | |
| 98 | static struct wpabuf * p2p_build_invitation_resp(struct p2p_data *p2p, |
| 99 | struct p2p_device *peer, |
| 100 | u8 dialog_token, u8 status, |
| 101 | const u8 *group_bssid, |
| 102 | u8 reg_class, u8 channel, |
| 103 | struct p2p_channels *channels) |
| 104 | { |
| 105 | struct wpabuf *buf; |
| 106 | u8 *len; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 107 | size_t extra = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 108 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 109 | #ifdef CONFIG_WIFI_DISPLAY |
| 110 | struct wpabuf *wfd_ie = p2p->wfd_ie_invitation; |
| 111 | if (wfd_ie && group_bssid) { |
| 112 | size_t i; |
| 113 | for (i = 0; i < p2p->num_groups; i++) { |
| 114 | struct p2p_group *g = p2p->groups[i]; |
| 115 | struct wpabuf *ie; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 116 | if (os_memcmp(p2p_group_get_interface_addr(g), |
| 117 | group_bssid, ETH_ALEN) != 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 118 | continue; |
| 119 | ie = p2p_group_get_wfd_ie(g); |
| 120 | if (ie) { |
| 121 | wfd_ie = ie; |
| 122 | break; |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | if (wfd_ie) |
| 127 | extra = wpabuf_len(wfd_ie); |
| 128 | #endif /* CONFIG_WIFI_DISPLAY */ |
| 129 | |
| 130 | buf = wpabuf_alloc(1000 + extra); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 131 | if (buf == NULL) |
| 132 | return NULL; |
| 133 | |
| 134 | p2p_buf_add_public_action_hdr(buf, P2P_INVITATION_RESP, |
| 135 | dialog_token); |
| 136 | |
| 137 | len = p2p_buf_add_ie_hdr(buf); |
| 138 | p2p_buf_add_status(buf, status); |
| 139 | p2p_buf_add_config_timeout(buf, 0, 0); /* FIX */ |
| 140 | if (reg_class && channel) |
| 141 | p2p_buf_add_operating_channel(buf, p2p->cfg->country, |
| 142 | reg_class, channel); |
| 143 | if (group_bssid) |
| 144 | p2p_buf_add_group_bssid(buf, group_bssid); |
Irfan Sheriff | 069fa2c | 2012-09-24 23:59:04 -0700 | [diff] [blame] | 145 | if (channels) |
| 146 | p2p_buf_add_channel_list(buf, p2p->cfg->country, channels); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 147 | p2p_buf_update_ie_hdr(buf, len); |
| 148 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 149 | #ifdef CONFIG_WIFI_DISPLAY |
| 150 | if (wfd_ie) |
| 151 | wpabuf_put_buf(buf, wfd_ie); |
| 152 | #endif /* CONFIG_WIFI_DISPLAY */ |
| 153 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 154 | return buf; |
| 155 | } |
| 156 | |
| 157 | |
| 158 | void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa, |
| 159 | const u8 *data, size_t len, int rx_freq) |
| 160 | { |
| 161 | struct p2p_device *dev; |
| 162 | struct p2p_message msg; |
| 163 | struct wpabuf *resp = NULL; |
| 164 | u8 status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; |
| 165 | int freq; |
| 166 | int go = 0; |
| 167 | u8 group_bssid[ETH_ALEN], *bssid; |
| 168 | int op_freq = 0; |
| 169 | u8 reg_class = 0, channel = 0; |
| 170 | struct p2p_channels intersection, *channels = NULL; |
| 171 | int persistent; |
| 172 | |
| 173 | os_memset(group_bssid, 0, sizeof(group_bssid)); |
| 174 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 175 | p2p_dbg(p2p, "Received Invitation Request from " MACSTR " (freq=%d)", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 176 | MAC2STR(sa), rx_freq); |
| 177 | |
| 178 | if (p2p_parse(data, len, &msg)) |
| 179 | return; |
| 180 | |
| 181 | dev = p2p_get_device(p2p, sa); |
| 182 | if (dev == NULL || (dev->flags & P2P_DEV_PROBE_REQ_ONLY)) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 183 | p2p_dbg(p2p, "Invitation Request from unknown peer " MACSTR, |
| 184 | MAC2STR(sa)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 185 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 186 | if (p2p_add_device(p2p, sa, rx_freq, NULL, 0, data + 1, len - 1, |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 187 | 0)) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 188 | p2p_dbg(p2p, "Invitation Request add device failed " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 189 | MACSTR, MAC2STR(sa)); |
| 190 | status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; |
| 191 | goto fail; |
| 192 | } |
| 193 | |
| 194 | dev = p2p_get_device(p2p, sa); |
| 195 | if (dev == NULL) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 196 | p2p_dbg(p2p, "Reject Invitation Request from unknown peer " |
| 197 | MACSTR, MAC2STR(sa)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 198 | status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; |
| 199 | goto fail; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | if (!msg.group_id || !msg.channel_list) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 204 | p2p_dbg(p2p, "Mandatory attribute missing in Invitation Request from " |
| 205 | MACSTR, MAC2STR(sa)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 206 | status = P2P_SC_FAIL_INVALID_PARAMS; |
| 207 | goto fail; |
| 208 | } |
| 209 | |
| 210 | if (msg.invitation_flags) |
| 211 | persistent = *msg.invitation_flags & P2P_INVITATION_FLAGS_TYPE; |
| 212 | else { |
| 213 | /* Invitation Flags is a mandatory attribute starting from P2P |
| 214 | * spec 1.06. As a backwards compatibility mechanism, assume |
| 215 | * the request was for a persistent group if the attribute is |
| 216 | * missing. |
| 217 | */ |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 218 | p2p_dbg(p2p, "Mandatory Invitation Flags attribute missing from Invitation Request"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 219 | persistent = 1; |
| 220 | } |
| 221 | |
| 222 | if (p2p_peer_channels_check(p2p, &p2p->cfg->channels, dev, |
| 223 | msg.channel_list, msg.channel_list_len) < |
| 224 | 0) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 225 | p2p_dbg(p2p, "No common channels found"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 226 | status = P2P_SC_FAIL_NO_COMMON_CHANNELS; |
| 227 | goto fail; |
| 228 | } |
| 229 | |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame^] | 230 | p2p_channels_dump(p2p, "own channels", &p2p->cfg->channels); |
| 231 | p2p_channels_dump(p2p, "peer channels", &dev->channels); |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 232 | p2p_channels_intersect(&p2p->cfg->channels, &dev->channels, |
| 233 | &intersection); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame^] | 234 | p2p_channels_dump(p2p, "intersection", &intersection); |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 235 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 236 | if (p2p->cfg->invitation_process) { |
| 237 | status = p2p->cfg->invitation_process( |
| 238 | p2p->cfg->cb_ctx, sa, msg.group_bssid, msg.group_id, |
| 239 | msg.group_id + ETH_ALEN, msg.group_id_len - ETH_ALEN, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 240 | &go, group_bssid, &op_freq, persistent, &intersection, |
| 241 | msg.dev_password_id_present ? msg.dev_password_id : -1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | if (op_freq) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 245 | p2p_dbg(p2p, "Invitation processing forced frequency %d MHz", |
| 246 | op_freq); |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 247 | if (p2p_freq_to_channel(op_freq, ®_class, &channel) < 0) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 248 | p2p_dbg(p2p, "Unknown forced freq %d MHz from invitation_process()", |
| 249 | op_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 250 | status = P2P_SC_FAIL_NO_COMMON_CHANNELS; |
| 251 | goto fail; |
| 252 | } |
| 253 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 254 | if (!p2p_channels_includes(&intersection, reg_class, channel)) |
| 255 | { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 256 | p2p_dbg(p2p, "forced freq %d MHz not in the supported channels interaction", |
| 257 | op_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 258 | status = P2P_SC_FAIL_NO_COMMON_CHANNELS; |
| 259 | goto fail; |
| 260 | } |
| 261 | |
| 262 | if (status == P2P_SC_SUCCESS) |
| 263 | channels = &intersection; |
| 264 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 265 | p2p_dbg(p2p, "No forced channel from invitation processing - figure out best one to use"); |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 266 | |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 267 | /* Default to own configuration as a starting point */ |
| 268 | p2p->op_reg_class = p2p->cfg->op_reg_class; |
| 269 | p2p->op_channel = p2p->cfg->op_channel; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 270 | p2p_dbg(p2p, "Own default op_class %d channel %d", |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 271 | p2p->op_reg_class, p2p->op_channel); |
| 272 | |
| 273 | /* Use peer preference if specified and compatible */ |
| 274 | if (msg.operating_channel) { |
| 275 | int req_freq; |
| 276 | req_freq = p2p_channel_to_freq( |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 277 | msg.operating_channel[3], |
| 278 | msg.operating_channel[4]); |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 279 | p2p_dbg(p2p, "Peer operating channel preference: %d MHz", |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 280 | req_freq); |
| 281 | if (req_freq > 0 && |
| 282 | p2p_channels_includes(&intersection, |
| 283 | msg.operating_channel[3], |
| 284 | msg.operating_channel[4])) { |
| 285 | p2p->op_reg_class = msg.operating_channel[3]; |
| 286 | p2p->op_channel = msg.operating_channel[4]; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 287 | p2p_dbg(p2p, "Use peer preference op_class %d channel %d", |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 288 | p2p->op_reg_class, p2p->op_channel); |
| 289 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 290 | p2p_dbg(p2p, "Cannot use peer channel preference"); |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 294 | /* Reselect the channel only for the case of the GO */ |
| 295 | if (go && |
| 296 | !p2p_channels_includes(&intersection, p2p->op_reg_class, |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 297 | p2p->op_channel)) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 298 | p2p_dbg(p2p, "Initially selected channel (op_class %d channel %d) not in channel intersection - try to reselect", |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 299 | p2p->op_reg_class, p2p->op_channel); |
| 300 | p2p_reselect_channel(p2p, &intersection); |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 301 | p2p_dbg(p2p, "Re-selection result: op_class %d channel %d", |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 302 | p2p->op_reg_class, p2p->op_channel); |
| 303 | if (!p2p_channels_includes(&intersection, |
| 304 | p2p->op_reg_class, |
| 305 | p2p->op_channel)) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 306 | p2p_dbg(p2p, "Peer does not support selected operating channel (reg_class=%u channel=%u)", |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 307 | p2p->op_reg_class, p2p->op_channel); |
| 308 | status = P2P_SC_FAIL_NO_COMMON_CHANNELS; |
| 309 | goto fail; |
| 310 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 311 | } else if (go && !(dev->flags & P2P_DEV_FORCE_FREQ) && |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 312 | !p2p->cfg->cfg_op_channel) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 313 | p2p_dbg(p2p, "Try to reselect channel selection with peer information received; previously selected op_class %u channel %u", |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 314 | p2p->op_reg_class, p2p->op_channel); |
| 315 | p2p_reselect_channel(p2p, &intersection); |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 318 | op_freq = p2p_channel_to_freq(p2p->op_reg_class, |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 319 | p2p->op_channel); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 320 | if (op_freq < 0) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 321 | p2p_dbg(p2p, "Unknown operational channel (country=%c%c reg_class=%u channel=%u)", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 322 | p2p->cfg->country[0], p2p->cfg->country[1], |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 323 | p2p->op_reg_class, p2p->op_channel); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 324 | status = P2P_SC_FAIL_NO_COMMON_CHANNELS; |
| 325 | goto fail; |
| 326 | } |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 327 | p2p_dbg(p2p, "Selected operating channel - %d MHz", op_freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 328 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 329 | if (status == P2P_SC_SUCCESS) { |
Dmitry Shmidt | 91c40cd | 2012-09-25 14:23:53 -0700 | [diff] [blame] | 330 | reg_class = p2p->op_reg_class; |
| 331 | channel = p2p->op_channel; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 332 | channels = &intersection; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | fail: |
| 337 | if (go && status == P2P_SC_SUCCESS && !is_zero_ether_addr(group_bssid)) |
| 338 | bssid = group_bssid; |
| 339 | else |
| 340 | bssid = NULL; |
| 341 | resp = p2p_build_invitation_resp(p2p, dev, msg.dialog_token, status, |
| 342 | bssid, reg_class, channel, channels); |
| 343 | |
| 344 | if (resp == NULL) |
| 345 | goto out; |
| 346 | |
| 347 | if (rx_freq > 0) |
| 348 | freq = rx_freq; |
| 349 | else |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 350 | freq = p2p_channel_to_freq(p2p->cfg->reg_class, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 351 | p2p->cfg->channel); |
| 352 | if (freq < 0) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 353 | p2p_dbg(p2p, "Unknown regulatory class/channel"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 354 | goto out; |
| 355 | } |
| 356 | |
| 357 | /* |
| 358 | * Store copy of invitation data to be used when processing TX status |
| 359 | * callback for the Acton frame. |
| 360 | */ |
| 361 | os_memcpy(p2p->inv_sa, sa, ETH_ALEN); |
| 362 | if (msg.group_bssid) { |
| 363 | os_memcpy(p2p->inv_group_bssid, msg.group_bssid, ETH_ALEN); |
| 364 | p2p->inv_group_bssid_ptr = p2p->inv_group_bssid; |
| 365 | } else |
| 366 | p2p->inv_group_bssid_ptr = NULL; |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 367 | if (msg.group_id) { |
| 368 | if (msg.group_id_len - ETH_ALEN <= 32) { |
| 369 | os_memcpy(p2p->inv_ssid, msg.group_id + ETH_ALEN, |
| 370 | msg.group_id_len - ETH_ALEN); |
| 371 | p2p->inv_ssid_len = msg.group_id_len - ETH_ALEN; |
| 372 | } |
| 373 | os_memcpy(p2p->inv_go_dev_addr, msg.group_id, ETH_ALEN); |
| 374 | } else { |
| 375 | p2p->inv_ssid_len = 0; |
| 376 | os_memset(p2p->inv_go_dev_addr, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 377 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 378 | p2p->inv_status = status; |
| 379 | p2p->inv_op_freq = op_freq; |
| 380 | |
| 381 | p2p->pending_action_state = P2P_PENDING_INVITATION_RESPONSE; |
| 382 | if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr, |
| 383 | p2p->cfg->dev_addr, |
| 384 | wpabuf_head(resp), wpabuf_len(resp), 200) < 0) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 385 | p2p_dbg(p2p, "Failed to send Action frame"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | out: |
| 389 | wpabuf_free(resp); |
| 390 | p2p_parse_free(&msg); |
| 391 | } |
| 392 | |
| 393 | |
| 394 | void p2p_process_invitation_resp(struct p2p_data *p2p, const u8 *sa, |
| 395 | const u8 *data, size_t len) |
| 396 | { |
| 397 | struct p2p_device *dev; |
| 398 | struct p2p_message msg; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 399 | struct p2p_channels intersection, *channels = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 400 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 401 | p2p_dbg(p2p, "Received Invitation Response from " MACSTR, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 402 | MAC2STR(sa)); |
| 403 | |
| 404 | dev = p2p_get_device(p2p, sa); |
| 405 | if (dev == NULL) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 406 | p2p_dbg(p2p, "Ignore Invitation Response from unknown peer " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 407 | MACSTR, MAC2STR(sa)); |
| 408 | return; |
| 409 | } |
| 410 | |
| 411 | if (dev != p2p->invite_peer) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 412 | p2p_dbg(p2p, "Ignore unexpected Invitation Response from peer " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 413 | MACSTR, MAC2STR(sa)); |
| 414 | return; |
| 415 | } |
| 416 | |
| 417 | if (p2p_parse(data, len, &msg)) |
| 418 | return; |
| 419 | |
| 420 | if (!msg.status) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 421 | p2p_dbg(p2p, "Mandatory Status attribute missing in Invitation Response from " |
| 422 | MACSTR, MAC2STR(sa)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 423 | p2p_parse_free(&msg); |
| 424 | return; |
| 425 | } |
| 426 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 427 | if (!msg.channel_list && *msg.status == P2P_SC_SUCCESS) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 428 | p2p_dbg(p2p, "Mandatory Channel List attribute missing in Invitation Response from " |
| 429 | MACSTR, MAC2STR(sa)); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 430 | #ifdef CONFIG_P2P_STRICT |
| 431 | p2p_parse_free(&msg); |
| 432 | return; |
| 433 | #endif /* CONFIG_P2P_STRICT */ |
| 434 | /* Try to survive without peer channel list */ |
| 435 | channels = &p2p->channels; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 436 | } else if (!msg.channel_list) { |
| 437 | /* Non-success cases are not required to include Channel List */ |
| 438 | channels = &p2p->channels; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 439 | } else if (p2p_peer_channels_check(p2p, &p2p->channels, dev, |
| 440 | msg.channel_list, |
| 441 | msg.channel_list_len) < 0) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 442 | p2p_dbg(p2p, "No common channels found"); |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 443 | p2p_parse_free(&msg); |
| 444 | return; |
| 445 | } else { |
| 446 | p2p_channels_intersect(&p2p->channels, &dev->channels, |
| 447 | &intersection); |
| 448 | channels = &intersection; |
| 449 | } |
| 450 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 451 | if (p2p->cfg->invitation_result) { |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 452 | int peer_oper_freq = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 453 | int freq = p2p_channel_to_freq(p2p->op_reg_class, |
| 454 | p2p->op_channel); |
| 455 | if (freq < 0) |
| 456 | freq = 0; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 457 | |
| 458 | if (msg.operating_channel) { |
| 459 | peer_oper_freq = p2p_channel_to_freq( |
| 460 | msg.operating_channel[3], |
| 461 | msg.operating_channel[4]); |
| 462 | if (peer_oper_freq < 0) |
| 463 | peer_oper_freq = 0; |
| 464 | } |
| 465 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 466 | p2p->cfg->invitation_result(p2p->cfg->cb_ctx, *msg.status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 467 | msg.group_bssid, channels, sa, |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 468 | freq, peer_oper_freq); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 469 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 470 | |
| 471 | p2p_parse_free(&msg); |
| 472 | |
| 473 | p2p_clear_timeout(p2p); |
| 474 | p2p_set_state(p2p, P2P_IDLE); |
| 475 | p2p->invite_peer = NULL; |
| 476 | } |
| 477 | |
| 478 | |
| 479 | int p2p_invite_send(struct p2p_data *p2p, struct p2p_device *dev, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 480 | const u8 *go_dev_addr, int dev_pw_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 481 | { |
| 482 | struct wpabuf *req; |
| 483 | int freq; |
| 484 | |
| 485 | freq = dev->listen_freq > 0 ? dev->listen_freq : dev->oper_freq; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 486 | if (freq <= 0) |
| 487 | freq = dev->oob_go_neg_freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 488 | if (freq <= 0) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 489 | p2p_dbg(p2p, "No Listen/Operating frequency known for the peer " |
| 490 | MACSTR " to send Invitation Request", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 491 | MAC2STR(dev->info.p2p_device_addr)); |
| 492 | return -1; |
| 493 | } |
| 494 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 495 | req = p2p_build_invitation_req(p2p, dev, go_dev_addr, dev_pw_id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 496 | if (req == NULL) |
| 497 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 498 | if (p2p->state != P2P_IDLE) |
| 499 | p2p_stop_listen_for_freq(p2p, freq); |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 500 | p2p_dbg(p2p, "Sending Invitation Request"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 501 | p2p_set_state(p2p, P2P_INVITE); |
| 502 | p2p->pending_action_state = P2P_PENDING_INVITATION_REQUEST; |
| 503 | p2p->invite_peer = dev; |
| 504 | dev->invitation_reqs++; |
| 505 | if (p2p_send_action(p2p, freq, dev->info.p2p_device_addr, |
| 506 | p2p->cfg->dev_addr, dev->info.p2p_device_addr, |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 507 | wpabuf_head(req), wpabuf_len(req), 500) < 0) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 508 | p2p_dbg(p2p, "Failed to send Action frame"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 509 | /* Use P2P find to recover and retry */ |
| 510 | p2p_set_timeout(p2p, 0, 0); |
Dmitry Shmidt | 3c47937 | 2014-02-04 10:50:36 -0800 | [diff] [blame] | 511 | } else { |
| 512 | dev->flags |= P2P_DEV_WAIT_INV_REQ_ACK; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | wpabuf_free(req); |
| 516 | |
| 517 | return 0; |
| 518 | } |
| 519 | |
| 520 | |
| 521 | void p2p_invitation_req_cb(struct p2p_data *p2p, int success) |
| 522 | { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 523 | p2p_dbg(p2p, "Invitation Request TX callback: success=%d", success); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 524 | |
| 525 | if (p2p->invite_peer == NULL) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 526 | p2p_dbg(p2p, "No pending Invite"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 527 | return; |
| 528 | } |
| 529 | |
Dmitry Shmidt | 3c47937 | 2014-02-04 10:50:36 -0800 | [diff] [blame] | 530 | if (success) |
| 531 | p2p->invite_peer->flags &= ~P2P_DEV_WAIT_INV_REQ_ACK; |
| 532 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 533 | /* |
| 534 | * Use P2P find, if needed, to find the other device from its listen |
| 535 | * channel. |
| 536 | */ |
| 537 | p2p_set_state(p2p, P2P_INVITE); |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 538 | p2p_set_timeout(p2p, 0, success ? 500000 : 100000); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | |
| 542 | void p2p_invitation_resp_cb(struct p2p_data *p2p, int success) |
| 543 | { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 544 | p2p_dbg(p2p, "Invitation Response TX callback: success=%d", success); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 545 | p2p->cfg->send_action_done(p2p->cfg->cb_ctx); |
| 546 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 547 | if (!success) |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 548 | p2p_dbg(p2p, "Assume Invitation Response was actually received by the peer even though Ack was not reported"); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 549 | |
| 550 | if (p2p->cfg->invitation_received) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 551 | p2p->cfg->invitation_received(p2p->cfg->cb_ctx, |
| 552 | p2p->inv_sa, |
| 553 | p2p->inv_group_bssid_ptr, |
| 554 | p2p->inv_ssid, p2p->inv_ssid_len, |
| 555 | p2p->inv_go_dev_addr, |
| 556 | p2p->inv_status, |
| 557 | p2p->inv_op_freq); |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | |
| 562 | int p2p_invite(struct p2p_data *p2p, const u8 *peer, enum p2p_invite_role role, |
| 563 | const u8 *bssid, const u8 *ssid, size_t ssid_len, |
| 564 | unsigned int force_freq, const u8 *go_dev_addr, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 565 | int persistent_group, unsigned int pref_freq, int dev_pw_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 566 | { |
| 567 | struct p2p_device *dev; |
| 568 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 569 | p2p_dbg(p2p, "Request to invite peer " MACSTR " role=%d persistent=%d " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 570 | "force_freq=%u", |
| 571 | MAC2STR(peer), role, persistent_group, force_freq); |
| 572 | if (bssid) |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 573 | p2p_dbg(p2p, "Invitation for BSSID " MACSTR, MAC2STR(bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 574 | if (go_dev_addr) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 575 | p2p_dbg(p2p, "Invitation for GO Device Address " MACSTR, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 576 | MAC2STR(go_dev_addr)); |
| 577 | os_memcpy(p2p->invite_go_dev_addr_buf, go_dev_addr, ETH_ALEN); |
| 578 | p2p->invite_go_dev_addr = p2p->invite_go_dev_addr_buf; |
| 579 | } else |
| 580 | p2p->invite_go_dev_addr = NULL; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 581 | wpa_hexdump_ascii(MSG_DEBUG, "Invitation for SSID", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 582 | ssid, ssid_len); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 583 | if (dev_pw_id >= 0) { |
| 584 | p2p_dbg(p2p, "Invitation to use Device Password ID %d", |
| 585 | dev_pw_id); |
| 586 | } |
| 587 | p2p->invite_dev_pw_id = dev_pw_id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 588 | |
| 589 | dev = p2p_get_device(p2p, peer); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 590 | if (dev == NULL || (dev->listen_freq <= 0 && dev->oper_freq <= 0 && |
| 591 | dev->oob_go_neg_freq <= 0)) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 592 | p2p_dbg(p2p, "Cannot invite unknown P2P Device " MACSTR, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 593 | MAC2STR(peer)); |
| 594 | return -1; |
| 595 | } |
| 596 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 597 | if (p2p_prepare_channel(p2p, dev, force_freq, pref_freq, |
| 598 | role != P2P_INVITE_ROLE_CLIENT) < 0) |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 599 | return -1; |
| 600 | |
| 601 | if (persistent_group && role == P2P_INVITE_ROLE_CLIENT && !force_freq && |
| 602 | !pref_freq) |
| 603 | dev->flags |= P2P_DEV_NO_PREF_CHAN; |
| 604 | else |
| 605 | dev->flags &= ~P2P_DEV_NO_PREF_CHAN; |
| 606 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 607 | if (dev->flags & P2P_DEV_GROUP_CLIENT_ONLY) { |
| 608 | if (!(dev->info.dev_capab & |
| 609 | P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY)) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 610 | p2p_dbg(p2p, "Cannot invite a P2P Device " MACSTR |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 611 | " that is in a group and is not discoverable", |
| 612 | MAC2STR(peer)); |
| 613 | } |
| 614 | /* TODO: use device discoverability request through GO */ |
| 615 | } |
| 616 | |
| 617 | dev->invitation_reqs = 0; |
| 618 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 619 | if (p2p->state != P2P_IDLE) |
| 620 | p2p_stop_find(p2p); |
| 621 | |
| 622 | p2p->inv_role = role; |
| 623 | p2p->inv_bssid_set = bssid != NULL; |
| 624 | if (bssid) |
| 625 | os_memcpy(p2p->inv_bssid, bssid, ETH_ALEN); |
| 626 | os_memcpy(p2p->inv_ssid, ssid, ssid_len); |
| 627 | p2p->inv_ssid_len = ssid_len; |
| 628 | p2p->inv_persistent = persistent_group; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 629 | return p2p_invite_send(p2p, dev, go_dev_addr, dev_pw_id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 630 | } |