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