]>
Commit | Line | Data |
---|---|---|
b22128ef JM |
1 | /* |
2 | * Wi-Fi Direct - P2P module | |
3 | * Copyright (c) 2009-2010, Atheros Communications | |
4 | * | |
e22d4d95 JM |
5 | * This software may be distributed under the terms of the BSD license. |
6 | * See README for more details. | |
b22128ef JM |
7 | */ |
8 | ||
9 | #include "includes.h" | |
10 | ||
11 | #include "common.h" | |
12 | #include "eloop.h" | |
13 | #include "common/ieee802_11_defs.h" | |
14 | #include "common/ieee802_11_common.h" | |
15 | #include "wps/wps_i.h" | |
16 | #include "p2p_i.h" | |
17 | #include "p2p.h" | |
18 | ||
19 | ||
20 | static void p2p_state_timeout(void *eloop_ctx, void *timeout_ctx); | |
21 | static void p2p_device_free(struct p2p_data *p2p, struct p2p_device *dev); | |
22 | static void p2p_process_presence_req(struct p2p_data *p2p, const u8 *da, | |
23 | const u8 *sa, const u8 *data, size_t len, | |
24 | int rx_freq); | |
25 | static void p2p_process_presence_resp(struct p2p_data *p2p, const u8 *da, | |
26 | const u8 *sa, const u8 *data, | |
27 | size_t len); | |
28 | static void p2p_ext_listen_timeout(void *eloop_ctx, void *timeout_ctx); | |
40c03fd4 | 29 | static void p2p_scan_timeout(void *eloop_ctx, void *timeout_ctx); |
b22128ef JM |
30 | |
31 | ||
40c03fd4 JM |
32 | /* |
33 | * p2p_scan recovery timeout | |
34 | * | |
35 | * Many drivers are using 30 second timeout on scan results. Allow a bit larger | |
36 | * timeout for this to avoid hitting P2P timeout unnecessarily. | |
37 | */ | |
38 | #define P2P_SCAN_TIMEOUT 35 | |
39 | ||
b22128ef JM |
40 | /** |
41 | * P2P_PEER_EXPIRATION_AGE - Number of seconds after which inactive peer | |
42 | * entries will be removed | |
43 | */ | |
dcdd3838 DS |
44 | #ifndef P2P_PEER_EXPIRATION_AGE |
45 | #define P2P_PEER_EXPIRATION_AGE 60 | |
46 | #endif /* P2P_PEER_EXPIRATION_AGE */ | |
b22128ef JM |
47 | |
48 | #define P2P_PEER_EXPIRATION_INTERVAL (P2P_PEER_EXPIRATION_AGE / 2) | |
49 | ||
50 | static void p2p_expire_peers(struct p2p_data *p2p) | |
51 | { | |
52 | struct p2p_device *dev, *n; | |
acb69cec | 53 | struct os_reltime now; |
1d277f02 | 54 | size_t i; |
b22128ef | 55 | |
acb69cec | 56 | os_get_reltime(&now); |
b22128ef JM |
57 | dl_list_for_each_safe(dev, n, &p2p->devices, struct p2p_device, list) { |
58 | if (dev->last_seen.sec + P2P_PEER_EXPIRATION_AGE >= now.sec) | |
59 | continue; | |
b1aebbc4 | 60 | |
a691d99f JJ |
61 | if (dev == p2p->go_neg_peer) { |
62 | /* | |
63 | * GO Negotiation is in progress with the peer, so | |
64 | * don't expire the peer entry until GO Negotiation | |
65 | * fails or times out. | |
66 | */ | |
67 | continue; | |
68 | } | |
69 | ||
b1aebbc4 JM |
70 | if (p2p->cfg->go_connected && |
71 | p2p->cfg->go_connected(p2p->cfg->cb_ctx, | |
72 | dev->info.p2p_device_addr)) { | |
73 | /* | |
74 | * We are connected as a client to a group in which the | |
75 | * peer is the GO, so do not expire the peer entry. | |
76 | */ | |
acb69cec | 77 | os_get_reltime(&dev->last_seen); |
b1aebbc4 JM |
78 | continue; |
79 | } | |
80 | ||
1d277f02 JM |
81 | for (i = 0; i < p2p->num_groups; i++) { |
82 | if (p2p_group_is_client_connected( | |
83 | p2p->groups[i], dev->info.p2p_device_addr)) | |
84 | break; | |
85 | } | |
86 | if (i < p2p->num_groups) { | |
87 | /* | |
88 | * The peer is connected as a client in a group where | |
89 | * we are the GO, so do not expire the peer entry. | |
90 | */ | |
acb69cec | 91 | os_get_reltime(&dev->last_seen); |
1d277f02 JM |
92 | continue; |
93 | } | |
94 | ||
ed496f13 JM |
95 | p2p_dbg(p2p, "Expiring old peer entry " MACSTR, |
96 | MAC2STR(dev->info.p2p_device_addr)); | |
b22128ef JM |
97 | dl_list_del(&dev->list); |
98 | p2p_device_free(p2p, dev); | |
99 | } | |
100 | } | |
101 | ||
102 | ||
103 | static void p2p_expiration_timeout(void *eloop_ctx, void *timeout_ctx) | |
104 | { | |
105 | struct p2p_data *p2p = eloop_ctx; | |
106 | p2p_expire_peers(p2p); | |
107 | eloop_register_timeout(P2P_PEER_EXPIRATION_INTERVAL, 0, | |
108 | p2p_expiration_timeout, p2p, NULL); | |
109 | } | |
110 | ||
111 | ||
112 | static const char * p2p_state_txt(int state) | |
113 | { | |
114 | switch (state) { | |
115 | case P2P_IDLE: | |
116 | return "IDLE"; | |
117 | case P2P_SEARCH: | |
118 | return "SEARCH"; | |
119 | case P2P_CONNECT: | |
120 | return "CONNECT"; | |
121 | case P2P_CONNECT_LISTEN: | |
122 | return "CONNECT_LISTEN"; | |
123 | case P2P_GO_NEG: | |
124 | return "GO_NEG"; | |
125 | case P2P_LISTEN_ONLY: | |
126 | return "LISTEN_ONLY"; | |
127 | case P2P_WAIT_PEER_CONNECT: | |
128 | return "WAIT_PEER_CONNECT"; | |
129 | case P2P_WAIT_PEER_IDLE: | |
130 | return "WAIT_PEER_IDLE"; | |
131 | case P2P_SD_DURING_FIND: | |
132 | return "SD_DURING_FIND"; | |
133 | case P2P_PROVISIONING: | |
134 | return "PROVISIONING"; | |
135 | case P2P_PD_DURING_FIND: | |
136 | return "PD_DURING_FIND"; | |
137 | case P2P_INVITE: | |
138 | return "INVITE"; | |
139 | case P2P_INVITE_LISTEN: | |
140 | return "INVITE_LISTEN"; | |
141 | default: | |
142 | return "?"; | |
143 | } | |
144 | } | |
145 | ||
146 | ||
4c559019 JM |
147 | const char * p2p_get_state_txt(struct p2p_data *p2p) |
148 | { | |
149 | return p2p_state_txt(p2p->state); | |
150 | } | |
151 | ||
152 | ||
ec437d9e JJ |
153 | u16 p2p_get_provisioning_info(struct p2p_data *p2p, const u8 *addr) |
154 | { | |
155 | struct p2p_device *dev = NULL; | |
156 | ||
157 | if (!addr || !p2p) | |
158 | return 0; | |
159 | ||
160 | dev = p2p_get_device(p2p, addr); | |
161 | if (dev) | |
162 | return dev->wps_prov_info; | |
163 | else | |
164 | return 0; | |
165 | } | |
166 | ||
167 | ||
10531d21 | 168 | void p2p_clear_provisioning_info(struct p2p_data *p2p, const u8 *addr) |
ec437d9e JJ |
169 | { |
170 | struct p2p_device *dev = NULL; | |
171 | ||
10531d21 | 172 | if (!addr || !p2p) |
ec437d9e JJ |
173 | return; |
174 | ||
10531d21 | 175 | dev = p2p_get_device(p2p, addr); |
ec437d9e JJ |
176 | if (dev) |
177 | dev->wps_prov_info = 0; | |
178 | } | |
179 | ||
180 | ||
b22128ef JM |
181 | void p2p_set_state(struct p2p_data *p2p, int new_state) |
182 | { | |
ed496f13 | 183 | p2p_dbg(p2p, "State %s -> %s", |
b22128ef JM |
184 | p2p_state_txt(p2p->state), p2p_state_txt(new_state)); |
185 | p2p->state = new_state; | |
186 | } | |
187 | ||
188 | ||
189 | void p2p_set_timeout(struct p2p_data *p2p, unsigned int sec, unsigned int usec) | |
190 | { | |
ed496f13 | 191 | p2p_dbg(p2p, "Set timeout (state=%s): %u.%06u sec", |
b22128ef JM |
192 | p2p_state_txt(p2p->state), sec, usec); |
193 | eloop_cancel_timeout(p2p_state_timeout, p2p, NULL); | |
194 | eloop_register_timeout(sec, usec, p2p_state_timeout, p2p, NULL); | |
195 | } | |
196 | ||
197 | ||
198 | void p2p_clear_timeout(struct p2p_data *p2p) | |
199 | { | |
ed496f13 | 200 | p2p_dbg(p2p, "Clear timeout (state=%s)", p2p_state_txt(p2p->state)); |
b22128ef JM |
201 | eloop_cancel_timeout(p2p_state_timeout, p2p, NULL); |
202 | } | |
203 | ||
204 | ||
205 | void p2p_go_neg_failed(struct p2p_data *p2p, struct p2p_device *peer, | |
206 | int status) | |
207 | { | |
208 | struct p2p_go_neg_results res; | |
209 | p2p_clear_timeout(p2p); | |
210 | p2p_set_state(p2p, P2P_IDLE); | |
fb8984fd JM |
211 | if (p2p->go_neg_peer) { |
212 | p2p->go_neg_peer->flags &= ~P2P_DEV_PEER_WAITING_RESPONSE; | |
eb916eb8 | 213 | p2p->go_neg_peer->wps_method = WPS_NOT_READY; |
ab9e3442 | 214 | p2p->go_neg_peer->oob_pw_id = 0; |
fb8984fd | 215 | } |
b22128ef JM |
216 | p2p->go_neg_peer = NULL; |
217 | ||
218 | os_memset(&res, 0, sizeof(res)); | |
219 | res.status = status; | |
220 | if (peer) { | |
0e0e1e56 NS |
221 | wpabuf_free(peer->go_neg_conf); |
222 | peer->go_neg_conf = NULL; | |
c5db8e51 | 223 | os_memcpy(res.peer_device_addr, peer->info.p2p_device_addr, |
b22128ef JM |
224 | ETH_ALEN); |
225 | os_memcpy(res.peer_interface_addr, peer->intended_addr, | |
226 | ETH_ALEN); | |
227 | } | |
228 | p2p->cfg->go_neg_completed(p2p->cfg->cb_ctx, &res); | |
229 | } | |
230 | ||
231 | ||
96beff11 | 232 | static void p2p_listen_in_find(struct p2p_data *p2p, int dev_disc) |
b22128ef JM |
233 | { |
234 | unsigned int r, tu; | |
235 | int freq; | |
236 | struct wpabuf *ies; | |
237 | ||
ed496f13 | 238 | p2p_dbg(p2p, "Starting short listen state (state=%s)", |
b22128ef JM |
239 | p2p_state_txt(p2p->state)); |
240 | ||
9ccd9165 | 241 | freq = p2p_channel_to_freq(p2p->cfg->reg_class, p2p->cfg->channel); |
b22128ef | 242 | if (freq < 0) { |
ed496f13 | 243 | p2p_dbg(p2p, "Unknown regulatory class/channel"); |
b22128ef JM |
244 | return; |
245 | } | |
246 | ||
247 | os_get_random((u8 *) &r, sizeof(r)); | |
248 | tu = (r % ((p2p->max_disc_int - p2p->min_disc_int) + 1) + | |
249 | p2p->min_disc_int) * 100; | |
96beff11 JM |
250 | if (p2p->max_disc_tu >= 0 && tu > (unsigned int) p2p->max_disc_tu) |
251 | tu = p2p->max_disc_tu; | |
252 | if (!dev_disc && tu < 100) | |
253 | tu = 100; /* Need to wait in non-device discovery use cases */ | |
254 | if (p2p->cfg->max_listen && 1024 * tu / 1000 > p2p->cfg->max_listen) | |
255 | tu = p2p->cfg->max_listen * 1000 / 1024; | |
256 | ||
257 | if (tu == 0) { | |
ed496f13 | 258 | p2p_dbg(p2p, "Skip listen state since duration was 0 TU"); |
96beff11 JM |
259 | p2p_set_timeout(p2p, 0, 0); |
260 | return; | |
261 | } | |
b22128ef JM |
262 | |
263 | p2p->pending_listen_freq = freq; | |
264 | p2p->pending_listen_sec = 0; | |
265 | p2p->pending_listen_usec = 1024 * tu; | |
266 | ||
267 | ies = p2p_build_probe_resp_ies(p2p); | |
268 | if (ies == NULL) | |
269 | return; | |
270 | ||
271 | if (p2p->cfg->start_listen(p2p->cfg->cb_ctx, freq, 1024 * tu / 1000, | |
272 | ies) < 0) { | |
ed496f13 | 273 | p2p_dbg(p2p, "Failed to start listen mode"); |
b22128ef JM |
274 | p2p->pending_listen_freq = 0; |
275 | } | |
276 | wpabuf_free(ies); | |
277 | } | |
278 | ||
279 | ||
280 | int p2p_listen(struct p2p_data *p2p, unsigned int timeout) | |
281 | { | |
282 | int freq; | |
283 | struct wpabuf *ies; | |
284 | ||
ed496f13 | 285 | p2p_dbg(p2p, "Going to listen(only) state"); |
b22128ef | 286 | |
9ccd9165 | 287 | freq = p2p_channel_to_freq(p2p->cfg->reg_class, p2p->cfg->channel); |
b22128ef | 288 | if (freq < 0) { |
ed496f13 | 289 | p2p_dbg(p2p, "Unknown regulatory class/channel"); |
b22128ef JM |
290 | return -1; |
291 | } | |
292 | ||
293 | p2p->pending_listen_freq = freq; | |
294 | p2p->pending_listen_sec = timeout / 1000; | |
295 | p2p->pending_listen_usec = (timeout % 1000) * 1000; | |
296 | ||
297 | if (p2p->p2p_scan_running) { | |
5b9cecaf | 298 | if (p2p->start_after_scan == P2P_AFTER_SCAN_CONNECT) { |
ed496f13 | 299 | p2p_dbg(p2p, "p2p_scan running - connect is already pending - skip listen"); |
d9bdba9f JM |
300 | return 0; |
301 | } | |
ed496f13 | 302 | p2p_dbg(p2p, "p2p_scan running - delay start of listen state"); |
b22128ef JM |
303 | p2p->start_after_scan = P2P_AFTER_SCAN_LISTEN; |
304 | return 0; | |
305 | } | |
306 | ||
307 | ies = p2p_build_probe_resp_ies(p2p); | |
308 | if (ies == NULL) | |
309 | return -1; | |
310 | ||
311 | if (p2p->cfg->start_listen(p2p->cfg->cb_ctx, freq, timeout, ies) < 0) { | |
ed496f13 | 312 | p2p_dbg(p2p, "Failed to start listen mode"); |
b22128ef JM |
313 | p2p->pending_listen_freq = 0; |
314 | wpabuf_free(ies); | |
315 | return -1; | |
316 | } | |
317 | wpabuf_free(ies); | |
318 | ||
319 | p2p_set_state(p2p, P2P_LISTEN_ONLY); | |
320 | ||
321 | return 0; | |
322 | } | |
323 | ||
324 | ||
325 | static void p2p_device_clear_reported(struct p2p_data *p2p) | |
326 | { | |
327 | struct p2p_device *dev; | |
328 | dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) | |
329 | dev->flags &= ~P2P_DEV_REPORTED; | |
330 | } | |
331 | ||
332 | ||
333 | /** | |
334 | * p2p_get_device - Fetch a peer entry | |
335 | * @p2p: P2P module context from p2p_init() | |
336 | * @addr: P2P Device Address of the peer | |
337 | * Returns: Pointer to the device entry or %NULL if not found | |
338 | */ | |
339 | struct p2p_device * p2p_get_device(struct p2p_data *p2p, const u8 *addr) | |
340 | { | |
341 | struct p2p_device *dev; | |
342 | dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) { | |
c5db8e51 | 343 | if (os_memcmp(dev->info.p2p_device_addr, addr, ETH_ALEN) == 0) |
b22128ef JM |
344 | return dev; |
345 | } | |
346 | return NULL; | |
347 | } | |
348 | ||
349 | ||
350 | /** | |
351 | * p2p_get_device_interface - Fetch a peer entry based on P2P Interface Address | |
352 | * @p2p: P2P module context from p2p_init() | |
353 | * @addr: P2P Interface Address of the peer | |
354 | * Returns: Pointer to the device entry or %NULL if not found | |
355 | */ | |
356 | struct p2p_device * p2p_get_device_interface(struct p2p_data *p2p, | |
357 | const u8 *addr) | |
358 | { | |
359 | struct p2p_device *dev; | |
360 | dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) { | |
361 | if (os_memcmp(dev->interface_addr, addr, ETH_ALEN) == 0) | |
362 | return dev; | |
363 | } | |
364 | return NULL; | |
365 | } | |
366 | ||
367 | ||
368 | /** | |
369 | * p2p_create_device - Create a peer entry | |
370 | * @p2p: P2P module context from p2p_init() | |
371 | * @addr: P2P Device Address of the peer | |
372 | * Returns: Pointer to the device entry or %NULL on failure | |
373 | * | |
374 | * If there is already an entry for the peer, it will be returned instead of | |
375 | * creating a new one. | |
376 | */ | |
377 | static struct p2p_device * p2p_create_device(struct p2p_data *p2p, | |
378 | const u8 *addr) | |
379 | { | |
380 | struct p2p_device *dev, *oldest = NULL; | |
381 | size_t count = 0; | |
382 | ||
383 | dev = p2p_get_device(p2p, addr); | |
384 | if (dev) | |
385 | return dev; | |
386 | ||
387 | dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) { | |
388 | count++; | |
389 | if (oldest == NULL || | |
acb69cec | 390 | os_reltime_before(&dev->last_seen, &oldest->last_seen)) |
b22128ef JM |
391 | oldest = dev; |
392 | } | |
393 | if (count + 1 > p2p->cfg->max_peers && oldest) { | |
ed496f13 | 394 | p2p_dbg(p2p, "Remove oldest peer entry to make room for a new peer"); |
b22128ef JM |
395 | dl_list_del(&oldest->list); |
396 | p2p_device_free(p2p, oldest); | |
397 | } | |
398 | ||
399 | dev = os_zalloc(sizeof(*dev)); | |
400 | if (dev == NULL) | |
401 | return NULL; | |
402 | dl_list_add(&p2p->devices, &dev->list); | |
c5db8e51 | 403 | os_memcpy(dev->info.p2p_device_addr, addr, ETH_ALEN); |
b22128ef JM |
404 | |
405 | return dev; | |
406 | } | |
407 | ||
408 | ||
409 | static void p2p_copy_client_info(struct p2p_device *dev, | |
410 | struct p2p_client_info *cli) | |
411 | { | |
c5db8e51 KRK |
412 | os_memcpy(dev->info.device_name, cli->dev_name, cli->dev_name_len); |
413 | dev->info.device_name[cli->dev_name_len] = '\0'; | |
414 | dev->info.dev_capab = cli->dev_capab; | |
415 | dev->info.config_methods = cli->config_methods; | |
416 | os_memcpy(dev->info.pri_dev_type, cli->pri_dev_type, 8); | |
e57ae6e1 JMB |
417 | dev->info.wps_sec_dev_type_list_len = 8 * cli->num_sec_dev_types; |
418 | os_memcpy(dev->info.wps_sec_dev_type_list, cli->sec_dev_types, | |
419 | dev->info.wps_sec_dev_type_list_len); | |
b22128ef JM |
420 | } |
421 | ||
422 | ||
423 | static int p2p_add_group_clients(struct p2p_data *p2p, const u8 *go_dev_addr, | |
424 | const u8 *go_interface_addr, int freq, | |
425 | const u8 *gi, size_t gi_len) | |
426 | { | |
427 | struct p2p_group_info info; | |
428 | size_t c; | |
429 | struct p2p_device *dev; | |
430 | ||
431 | if (gi == NULL) | |
432 | return 0; | |
433 | ||
434 | if (p2p_group_info_parse(gi, gi_len, &info) < 0) | |
435 | return -1; | |
436 | ||
437 | /* | |
438 | * Clear old data for this group; if the devices are still in the | |
439 | * group, the information will be restored in the loop following this. | |
440 | */ | |
441 | dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) { | |
b5472a45 | 442 | if (os_memcmp(dev->member_in_go_iface, go_interface_addr, |
b22128ef JM |
443 | ETH_ALEN) == 0) { |
444 | os_memset(dev->member_in_go_iface, 0, ETH_ALEN); | |
445 | os_memset(dev->member_in_go_dev, 0, ETH_ALEN); | |
446 | } | |
447 | } | |
448 | ||
449 | for (c = 0; c < info.num_clients; c++) { | |
450 | struct p2p_client_info *cli = &info.client[c]; | |
2f0c8936 MK |
451 | if (os_memcmp(cli->p2p_device_addr, p2p->cfg->dev_addr, |
452 | ETH_ALEN) == 0) | |
453 | continue; /* ignore our own entry */ | |
b22128ef JM |
454 | dev = p2p_get_device(p2p, cli->p2p_device_addr); |
455 | if (dev) { | |
b22128ef | 456 | if (dev->flags & (P2P_DEV_GROUP_CLIENT_ONLY | |
f33bc035 JM |
457 | P2P_DEV_PROBE_REQ_ONLY)) { |
458 | /* | |
459 | * Update information since we have not | |
460 | * received this directly from the client. | |
461 | */ | |
b22128ef | 462 | p2p_copy_client_info(dev, cli); |
f33bc035 JM |
463 | } else { |
464 | /* | |
465 | * Need to update P2P Client Discoverability | |
466 | * flag since it is valid only in P2P Group | |
467 | * Info attribute. | |
468 | */ | |
469 | dev->info.dev_capab &= | |
470 | ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY; | |
471 | dev->info.dev_capab |= | |
472 | cli->dev_capab & | |
473 | P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY; | |
474 | } | |
b22128ef JM |
475 | if (dev->flags & P2P_DEV_PROBE_REQ_ONLY) { |
476 | dev->flags &= ~P2P_DEV_PROBE_REQ_ONLY; | |
477 | } | |
478 | } else { | |
479 | dev = p2p_create_device(p2p, cli->p2p_device_addr); | |
480 | if (dev == NULL) | |
481 | continue; | |
482 | dev->flags |= P2P_DEV_GROUP_CLIENT_ONLY; | |
483 | p2p_copy_client_info(dev, cli); | |
484 | dev->oper_freq = freq; | |
c5db8e51 KRK |
485 | p2p->cfg->dev_found(p2p->cfg->cb_ctx, |
486 | dev->info.p2p_device_addr, | |
8fd7dc1b JB |
487 | &dev->info, 1); |
488 | dev->flags |= P2P_DEV_REPORTED | P2P_DEV_REPORTED_ONCE; | |
b22128ef JM |
489 | } |
490 | ||
491 | os_memcpy(dev->interface_addr, cli->p2p_interface_addr, | |
492 | ETH_ALEN); | |
acb69cec | 493 | os_get_reltime(&dev->last_seen); |
b22128ef JM |
494 | os_memcpy(dev->member_in_go_dev, go_dev_addr, ETH_ALEN); |
495 | os_memcpy(dev->member_in_go_iface, go_interface_addr, | |
496 | ETH_ALEN); | |
497 | } | |
498 | ||
499 | return 0; | |
500 | } | |
501 | ||
502 | ||
ed496f13 JM |
503 | static void p2p_copy_wps_info(struct p2p_data *p2p, struct p2p_device *dev, |
504 | int probe_req, const struct p2p_message *msg) | |
b67d0d9e JM |
505 | { |
506 | os_memcpy(dev->info.device_name, msg->device_name, | |
507 | sizeof(dev->info.device_name)); | |
508 | ||
509 | if (msg->manufacturer && | |
510 | msg->manufacturer_len < sizeof(dev->info.manufacturer)) { | |
511 | os_memset(dev->info.manufacturer, 0, | |
512 | sizeof(dev->info.manufacturer)); | |
513 | os_memcpy(dev->info.manufacturer, msg->manufacturer, | |
514 | msg->manufacturer_len); | |
515 | } | |
516 | ||
517 | if (msg->model_name && | |
518 | msg->model_name_len < sizeof(dev->info.model_name)) { | |
519 | os_memset(dev->info.model_name, 0, | |
520 | sizeof(dev->info.model_name)); | |
521 | os_memcpy(dev->info.model_name, msg->model_name, | |
522 | msg->model_name_len); | |
523 | } | |
524 | ||
525 | if (msg->model_number && | |
526 | msg->model_number_len < sizeof(dev->info.model_number)) { | |
527 | os_memset(dev->info.model_number, 0, | |
528 | sizeof(dev->info.model_number)); | |
529 | os_memcpy(dev->info.model_number, msg->model_number, | |
530 | msg->model_number_len); | |
531 | } | |
532 | ||
533 | if (msg->serial_number && | |
534 | msg->serial_number_len < sizeof(dev->info.serial_number)) { | |
535 | os_memset(dev->info.serial_number, 0, | |
536 | sizeof(dev->info.serial_number)); | |
537 | os_memcpy(dev->info.serial_number, msg->serial_number, | |
538 | msg->serial_number_len); | |
539 | } | |
540 | ||
541 | if (msg->pri_dev_type) | |
542 | os_memcpy(dev->info.pri_dev_type, msg->pri_dev_type, | |
543 | sizeof(dev->info.pri_dev_type)); | |
544 | else if (msg->wps_pri_dev_type) | |
545 | os_memcpy(dev->info.pri_dev_type, msg->wps_pri_dev_type, | |
546 | sizeof(dev->info.pri_dev_type)); | |
547 | ||
548 | if (msg->wps_sec_dev_type_list) { | |
549 | os_memcpy(dev->info.wps_sec_dev_type_list, | |
550 | msg->wps_sec_dev_type_list, | |
551 | msg->wps_sec_dev_type_list_len); | |
552 | dev->info.wps_sec_dev_type_list_len = | |
553 | msg->wps_sec_dev_type_list_len; | |
554 | } | |
555 | ||
556 | if (msg->capability) { | |
f33bc035 JM |
557 | /* |
558 | * P2P Client Discoverability bit is reserved in all frames | |
559 | * that use this function, so do not change its value here. | |
560 | */ | |
561 | dev->info.dev_capab &= P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY; | |
562 | dev->info.dev_capab |= msg->capability[0] & | |
563 | ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY; | |
b67d0d9e JM |
564 | dev->info.group_capab = msg->capability[1]; |
565 | } | |
566 | ||
567 | if (msg->ext_listen_timing) { | |
568 | dev->ext_listen_period = WPA_GET_LE16(msg->ext_listen_timing); | |
569 | dev->ext_listen_interval = | |
570 | WPA_GET_LE16(msg->ext_listen_timing + 2); | |
571 | } | |
572 | ||
573 | if (!probe_req) { | |
954ee628 JM |
574 | u16 new_config_methods; |
575 | new_config_methods = msg->config_methods ? | |
b67d0d9e | 576 | msg->config_methods : msg->wps_config_methods; |
954ee628 JM |
577 | if (new_config_methods && |
578 | dev->info.config_methods != new_config_methods) { | |
ed496f13 JM |
579 | p2p_dbg(p2p, "Update peer " MACSTR |
580 | " config_methods 0x%x -> 0x%x", | |
581 | MAC2STR(dev->info.p2p_device_addr), | |
582 | dev->info.config_methods, | |
583 | new_config_methods); | |
954ee628 JM |
584 | dev->info.config_methods = new_config_methods; |
585 | } | |
b67d0d9e JM |
586 | } |
587 | } | |
588 | ||
589 | ||
b22128ef | 590 | /** |
c98b83f2 | 591 | * p2p_add_device - Add peer entries based on scan results or P2P frames |
b22128ef JM |
592 | * @p2p: P2P module context from p2p_init() |
593 | * @addr: Source address of Beacon or Probe Response frame (may be either | |
594 | * P2P Device Address or P2P Interface Address) | |
595 | * @level: Signal level (signal strength of the received frame from the peer) | |
596 | * @freq: Frequency on which the Beacon or Probe Response frame was received | |
c5f10e80 | 597 | * @rx_time: Time when the result was received |
b22128ef JM |
598 | * @ies: IEs from the Beacon or Probe Response frame |
599 | * @ies_len: Length of ies buffer in octets | |
c98b83f2 | 600 | * @scan_res: Whether this was based on scan results |
b22128ef JM |
601 | * Returns: 0 on success, -1 on failure |
602 | * | |
603 | * If the scan result is for a GO, the clients in the group will also be added | |
17bef1e9 AC |
604 | * to the peer table. This function can also be used with some other frames |
605 | * like Provision Discovery Request that contains P2P Capability and P2P Device | |
606 | * Info attributes. | |
b22128ef | 607 | */ |
3dfd0484 | 608 | int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq, |
acb69cec | 609 | struct os_reltime *rx_time, int level, const u8 *ies, |
3dfd0484 | 610 | size_t ies_len, int scan_res) |
b22128ef JM |
611 | { |
612 | struct p2p_device *dev; | |
613 | struct p2p_message msg; | |
614 | const u8 *p2p_dev_addr; | |
6f2c0607 | 615 | int i; |
acb69cec | 616 | struct os_reltime time_now; |
b22128ef JM |
617 | |
618 | os_memset(&msg, 0, sizeof(msg)); | |
619 | if (p2p_parse_ies(ies, ies_len, &msg)) { | |
ed496f13 | 620 | p2p_dbg(p2p, "Failed to parse P2P IE for a device entry"); |
b22128ef JM |
621 | p2p_parse_free(&msg); |
622 | return -1; | |
623 | } | |
624 | ||
625 | if (msg.p2p_device_addr) | |
626 | p2p_dev_addr = msg.p2p_device_addr; | |
627 | else if (msg.device_id) | |
628 | p2p_dev_addr = msg.device_id; | |
629 | else { | |
ed496f13 | 630 | p2p_dbg(p2p, "Ignore scan data without P2P Device Info or P2P Device Id"); |
b22128ef JM |
631 | p2p_parse_free(&msg); |
632 | return -1; | |
633 | } | |
634 | ||
80c9582a JM |
635 | if (!is_zero_ether_addr(p2p->peer_filter) && |
636 | os_memcmp(p2p_dev_addr, p2p->peer_filter, ETH_ALEN) != 0) { | |
ed496f13 JM |
637 | p2p_dbg(p2p, "Do not add peer filter for " MACSTR |
638 | " due to peer filter", MAC2STR(p2p_dev_addr)); | |
f96c1d76 | 639 | p2p_parse_free(&msg); |
80c9582a JM |
640 | return 0; |
641 | } | |
642 | ||
b22128ef JM |
643 | dev = p2p_create_device(p2p, p2p_dev_addr); |
644 | if (dev == NULL) { | |
645 | p2p_parse_free(&msg); | |
646 | return -1; | |
647 | } | |
3dfd0484 | 648 | |
c5f10e80 | 649 | if (rx_time == NULL) { |
acb69cec | 650 | os_get_reltime(&time_now); |
c5f10e80 JM |
651 | rx_time = &time_now; |
652 | } | |
3dfd0484 YD |
653 | |
654 | /* | |
655 | * Update the device entry only if the new peer | |
656 | * entry is newer than the one previously stored. | |
657 | */ | |
c5f10e80 | 658 | if (dev->last_seen.sec > 0 && |
acb69cec | 659 | os_reltime_before(rx_time, &dev->last_seen)) { |
ed496f13 | 660 | p2p_dbg(p2p, "Do not update peer entry based on old frame (rx_time=%u.%06u last_seen=%u.%06u)", |
c5f10e80 JM |
661 | (unsigned int) rx_time->sec, |
662 | (unsigned int) rx_time->usec, | |
663 | (unsigned int) dev->last_seen.sec, | |
664 | (unsigned int) dev->last_seen.usec); | |
f96c1d76 | 665 | p2p_parse_free(&msg); |
3dfd0484 | 666 | return -1; |
f96c1d76 | 667 | } |
3dfd0484 | 668 | |
acb69cec | 669 | os_memcpy(&dev->last_seen, rx_time, sizeof(struct os_reltime)); |
3dfd0484 | 670 | |
b22128ef JM |
671 | dev->flags &= ~(P2P_DEV_PROBE_REQ_ONLY | P2P_DEV_GROUP_CLIENT_ONLY); |
672 | ||
673 | if (os_memcmp(addr, p2p_dev_addr, ETH_ALEN) != 0) | |
674 | os_memcpy(dev->interface_addr, addr, ETH_ALEN); | |
675 | if (msg.ssid && | |
676 | (msg.ssid[1] != P2P_WILDCARD_SSID_LEN || | |
677 | os_memcmp(msg.ssid + 2, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) | |
678 | != 0)) { | |
679 | os_memcpy(dev->oper_ssid, msg.ssid + 2, msg.ssid[1]); | |
680 | dev->oper_ssid_len = msg.ssid[1]; | |
681 | } | |
682 | ||
683 | if (freq >= 2412 && freq <= 2484 && msg.ds_params && | |
684 | *msg.ds_params >= 1 && *msg.ds_params <= 14) { | |
685 | int ds_freq; | |
686 | if (*msg.ds_params == 14) | |
687 | ds_freq = 2484; | |
688 | else | |
689 | ds_freq = 2407 + *msg.ds_params * 5; | |
690 | if (freq != ds_freq) { | |
ed496f13 | 691 | p2p_dbg(p2p, "Update Listen frequency based on DS Parameter Set IE: %d -> %d MHz", |
b22128ef JM |
692 | freq, ds_freq); |
693 | freq = ds_freq; | |
694 | } | |
695 | } | |
696 | ||
c98b83f2 | 697 | if (dev->listen_freq && dev->listen_freq != freq && scan_res) { |
ed496f13 JM |
698 | p2p_dbg(p2p, "Update Listen frequency based on scan results (" |
699 | MACSTR " %d -> %d MHz (DS param %d)", | |
c5db8e51 KRK |
700 | MAC2STR(dev->info.p2p_device_addr), dev->listen_freq, |
701 | freq, msg.ds_params ? *msg.ds_params : -1); | |
b22128ef | 702 | } |
c98b83f2 JM |
703 | if (scan_res) { |
704 | dev->listen_freq = freq; | |
705 | if (msg.group_info) | |
706 | dev->oper_freq = freq; | |
707 | } | |
6402fc43 | 708 | dev->info.level = level; |
b22128ef | 709 | |
ed496f13 | 710 | p2p_copy_wps_info(p2p, dev, 0, &msg); |
e57ae6e1 | 711 | |
10c5d2a5 | 712 | for (i = 0; i < P2P_MAX_WPS_VENDOR_EXT; i++) { |
6f2c0607 JMB |
713 | wpabuf_free(dev->info.wps_vendor_ext[i]); |
714 | dev->info.wps_vendor_ext[i] = NULL; | |
715 | } | |
716 | ||
10c5d2a5 | 717 | for (i = 0; i < P2P_MAX_WPS_VENDOR_EXT; i++) { |
6f2c0607 JMB |
718 | if (msg.wps_vendor_ext[i] == NULL) |
719 | break; | |
720 | dev->info.wps_vendor_ext[i] = wpabuf_alloc_copy( | |
721 | msg.wps_vendor_ext[i], msg.wps_vendor_ext_len[i]); | |
722 | if (dev->info.wps_vendor_ext[i] == NULL) | |
723 | break; | |
724 | } | |
725 | ||
9675ce35 JM |
726 | if (msg.wfd_subelems) { |
727 | wpabuf_free(dev->info.wfd_subelems); | |
728 | dev->info.wfd_subelems = wpabuf_dup(msg.wfd_subelems); | |
729 | } | |
730 | ||
c98b83f2 JM |
731 | if (scan_res) { |
732 | p2p_add_group_clients(p2p, p2p_dev_addr, addr, freq, | |
733 | msg.group_info, msg.group_info_len); | |
734 | } | |
b22128ef JM |
735 | |
736 | p2p_parse_free(&msg); | |
737 | ||
b22128ef JM |
738 | if (dev->flags & P2P_DEV_REPORTED) |
739 | return 0; | |
740 | ||
ed496f13 JM |
741 | p2p_dbg(p2p, "Peer found with Listen frequency %d MHz (rx_time=%u.%06u)", |
742 | freq, (unsigned int) rx_time->sec, | |
c5f10e80 | 743 | (unsigned int) rx_time->usec); |
b22128ef | 744 | if (dev->flags & P2P_DEV_USER_REJECTED) { |
ed496f13 | 745 | p2p_dbg(p2p, "Do not report rejected device"); |
b22128ef JM |
746 | return 0; |
747 | } | |
8fd7dc1b | 748 | |
8b2b2a70 JM |
749 | if (dev->info.config_methods == 0 && |
750 | (freq == 2412 || freq == 2437 || freq == 2462)) { | |
751 | /* | |
752 | * If we have only seen a Beacon frame from a GO, we do not yet | |
753 | * know what WPS config methods it supports. Since some | |
754 | * applications use config_methods value from P2P-DEVICE-FOUND | |
755 | * events, postpone reporting this peer until we've fully | |
756 | * discovered its capabilities. | |
757 | * | |
758 | * At least for now, do this only if the peer was detected on | |
759 | * one of the social channels since that peer can be easily be | |
760 | * found again and there are no limitations of having to use | |
761 | * passive scan on this channels, so this can be done through | |
762 | * Probe Response frame that includes the config_methods | |
763 | * information. | |
764 | */ | |
ed496f13 JM |
765 | p2p_dbg(p2p, "Do not report peer " MACSTR |
766 | " with unknown config methods", MAC2STR(addr)); | |
8b2b2a70 JM |
767 | return 0; |
768 | } | |
769 | ||
8fd7dc1b JB |
770 | p2p->cfg->dev_found(p2p->cfg->cb_ctx, addr, &dev->info, |
771 | !(dev->flags & P2P_DEV_REPORTED_ONCE)); | |
772 | dev->flags |= P2P_DEV_REPORTED | P2P_DEV_REPORTED_ONCE; | |
b22128ef JM |
773 | |
774 | return 0; | |
775 | } | |
776 | ||
777 | ||
778 | static void p2p_device_free(struct p2p_data *p2p, struct p2p_device *dev) | |
779 | { | |
6f2c0607 JMB |
780 | int i; |
781 | ||
5cfda25e JJ |
782 | if (p2p->go_neg_peer == dev) { |
783 | /* | |
784 | * If GO Negotiation is in progress, report that it has failed. | |
785 | */ | |
786 | p2p_go_neg_failed(p2p, dev, -1); | |
b22128ef | 787 | p2p->go_neg_peer = NULL; |
5cfda25e | 788 | } |
b22128ef JM |
789 | if (p2p->invite_peer == dev) |
790 | p2p->invite_peer = NULL; | |
791 | if (p2p->sd_peer == dev) | |
792 | p2p->sd_peer = NULL; | |
793 | if (p2p->pending_client_disc_go == dev) | |
794 | p2p->pending_client_disc_go = NULL; | |
795 | ||
f5fc6032 AC |
796 | /* dev_lost() device, but only if it was previously dev_found() */ |
797 | if (dev->flags & P2P_DEV_REPORTED_ONCE) | |
798 | p2p->cfg->dev_lost(p2p->cfg->cb_ctx, | |
799 | dev->info.p2p_device_addr); | |
56eeb8f2 | 800 | |
10c5d2a5 | 801 | for (i = 0; i < P2P_MAX_WPS_VENDOR_EXT; i++) { |
6f2c0607 JMB |
802 | wpabuf_free(dev->info.wps_vendor_ext[i]); |
803 | dev->info.wps_vendor_ext[i] = NULL; | |
804 | } | |
805 | ||
9675ce35 | 806 | wpabuf_free(dev->info.wfd_subelems); |
0e0e1e56 | 807 | wpabuf_free(dev->go_neg_conf); |
9675ce35 | 808 | |
b22128ef JM |
809 | os_free(dev); |
810 | } | |
811 | ||
812 | ||
813 | static int p2p_get_next_prog_freq(struct p2p_data *p2p) | |
814 | { | |
815 | struct p2p_channels *c; | |
816 | struct p2p_reg_class *cla; | |
817 | size_t cl, ch; | |
818 | int found = 0; | |
819 | u8 reg_class; | |
820 | u8 channel; | |
821 | int freq; | |
822 | ||
823 | c = &p2p->cfg->channels; | |
824 | for (cl = 0; cl < c->reg_classes; cl++) { | |
825 | cla = &c->reg_class[cl]; | |
826 | if (cla->reg_class != p2p->last_prog_scan_class) | |
827 | continue; | |
828 | for (ch = 0; ch < cla->channels; ch++) { | |
829 | if (cla->channel[ch] == p2p->last_prog_scan_chan) { | |
830 | found = 1; | |
831 | break; | |
832 | } | |
833 | } | |
834 | if (found) | |
835 | break; | |
836 | } | |
837 | ||
838 | if (!found) { | |
839 | /* Start from beginning */ | |
840 | reg_class = c->reg_class[0].reg_class; | |
841 | channel = c->reg_class[0].channel[0]; | |
842 | } else { | |
843 | /* Pick the next channel */ | |
844 | ch++; | |
845 | if (ch == cla->channels) { | |
846 | cl++; | |
847 | if (cl == c->reg_classes) | |
848 | cl = 0; | |
849 | ch = 0; | |
850 | } | |
851 | reg_class = c->reg_class[cl].reg_class; | |
852 | channel = c->reg_class[cl].channel[ch]; | |
853 | } | |
854 | ||
9ccd9165 | 855 | freq = p2p_channel_to_freq(reg_class, channel); |
ed496f13 | 856 | p2p_dbg(p2p, "Next progressive search channel: reg_class %u channel %u -> %d MHz", |
b22128ef JM |
857 | reg_class, channel, freq); |
858 | p2p->last_prog_scan_class = reg_class; | |
859 | p2p->last_prog_scan_chan = channel; | |
860 | ||
861 | if (freq == 2412 || freq == 2437 || freq == 2462) | |
862 | return 0; /* No need to add social channels */ | |
863 | return freq; | |
864 | } | |
865 | ||
866 | ||
867 | static void p2p_search(struct p2p_data *p2p) | |
868 | { | |
869 | int freq = 0; | |
870 | enum p2p_scan_type type; | |
360182ed | 871 | u16 pw_id = DEV_PW_DEFAULT; |
99fcd404 | 872 | int res; |
b22128ef JM |
873 | |
874 | if (p2p->drv_in_listen) { | |
ed496f13 | 875 | p2p_dbg(p2p, "Driver is still in Listen state - wait for it to end before continuing"); |
b22128ef JM |
876 | return; |
877 | } | |
878 | p2p->cfg->stop_listen(p2p->cfg->cb_ctx); | |
879 | ||
e6ecfc4f JB |
880 | if (p2p->find_type == P2P_FIND_PROGRESSIVE && |
881 | (freq = p2p_get_next_prog_freq(p2p)) > 0) { | |
b22128ef | 882 | type = P2P_SCAN_SOCIAL_PLUS_ONE; |
ed496f13 | 883 | p2p_dbg(p2p, "Starting search (+ freq %u)", freq); |
b22128ef JM |
884 | } else { |
885 | type = P2P_SCAN_SOCIAL; | |
ed496f13 | 886 | p2p_dbg(p2p, "Starting search"); |
b22128ef JM |
887 | } |
888 | ||
99fcd404 JM |
889 | res = p2p->cfg->p2p_scan(p2p->cfg->cb_ctx, type, freq, |
890 | p2p->num_req_dev_types, p2p->req_dev_types, | |
891 | p2p->find_dev_id, pw_id); | |
892 | if (res < 0) { | |
ed496f13 | 893 | p2p_dbg(p2p, "Scan request failed"); |
b22128ef | 894 | p2p_continue_find(p2p); |
40c03fd4 | 895 | } else { |
ed496f13 | 896 | p2p_dbg(p2p, "Running p2p_scan"); |
40c03fd4 JM |
897 | p2p->p2p_scan_running = 1; |
898 | eloop_cancel_timeout(p2p_scan_timeout, p2p, NULL); | |
899 | eloop_register_timeout(P2P_SCAN_TIMEOUT, 0, p2p_scan_timeout, | |
900 | p2p, NULL); | |
b22128ef JM |
901 | } |
902 | } | |
903 | ||
904 | ||
905 | static void p2p_find_timeout(void *eloop_ctx, void *timeout_ctx) | |
906 | { | |
907 | struct p2p_data *p2p = eloop_ctx; | |
ed496f13 | 908 | p2p_dbg(p2p, "Find timeout -> stop"); |
b22128ef JM |
909 | p2p_stop_find(p2p); |
910 | } | |
911 | ||
912 | ||
913 | static int p2p_run_after_scan(struct p2p_data *p2p) | |
914 | { | |
915 | struct p2p_device *dev; | |
916 | enum p2p_after_scan op; | |
917 | ||
3f9285ff | 918 | if (p2p->after_scan_tx) { |
63a965c3 | 919 | p2p->after_scan_tx_in_progress = 1; |
ed496f13 | 920 | p2p_dbg(p2p, "Send pending Action frame at p2p_scan completion"); |
46eeedac JM |
921 | p2p->cfg->send_action(p2p->cfg->cb_ctx, |
922 | p2p->after_scan_tx->freq, | |
923 | p2p->after_scan_tx->dst, | |
924 | p2p->after_scan_tx->src, | |
925 | p2p->after_scan_tx->bssid, | |
926 | (u8 *) (p2p->after_scan_tx + 1), | |
927 | p2p->after_scan_tx->len, | |
928 | p2p->after_scan_tx->wait_time); | |
3f9285ff JM |
929 | os_free(p2p->after_scan_tx); |
930 | p2p->after_scan_tx = NULL; | |
931 | return 1; | |
932 | } | |
933 | ||
b22128ef JM |
934 | op = p2p->start_after_scan; |
935 | p2p->start_after_scan = P2P_AFTER_SCAN_NOTHING; | |
936 | switch (op) { | |
937 | case P2P_AFTER_SCAN_NOTHING: | |
938 | break; | |
939 | case P2P_AFTER_SCAN_LISTEN: | |
ed496f13 | 940 | p2p_dbg(p2p, "Start previously requested Listen state"); |
b22128ef JM |
941 | p2p_listen(p2p, p2p->pending_listen_sec * 1000 + |
942 | p2p->pending_listen_usec / 1000); | |
943 | return 1; | |
944 | case P2P_AFTER_SCAN_CONNECT: | |
ed496f13 | 945 | p2p_dbg(p2p, "Start previously requested connect with " MACSTR, |
b22128ef JM |
946 | MAC2STR(p2p->after_scan_peer)); |
947 | dev = p2p_get_device(p2p, p2p->after_scan_peer); | |
948 | if (dev == NULL) { | |
ed496f13 | 949 | p2p_dbg(p2p, "Peer not known anymore"); |
b22128ef JM |
950 | break; |
951 | } | |
952 | p2p_connect_send(p2p, dev); | |
953 | return 1; | |
954 | } | |
955 | ||
956 | return 0; | |
957 | } | |
958 | ||
959 | ||
b22128ef JM |
960 | static void p2p_scan_timeout(void *eloop_ctx, void *timeout_ctx) |
961 | { | |
962 | struct p2p_data *p2p = eloop_ctx; | |
963 | int running; | |
ed496f13 | 964 | p2p_dbg(p2p, "p2p_scan timeout (running=%d)", p2p->p2p_scan_running); |
b22128ef JM |
965 | running = p2p->p2p_scan_running; |
966 | /* Make sure we recover from missed scan results callback */ | |
967 | p2p->p2p_scan_running = 0; | |
968 | ||
969 | if (running) | |
970 | p2p_run_after_scan(p2p); | |
971 | } | |
972 | ||
973 | ||
046ef4aa JMB |
974 | static void p2p_free_req_dev_types(struct p2p_data *p2p) |
975 | { | |
976 | p2p->num_req_dev_types = 0; | |
977 | os_free(p2p->req_dev_types); | |
978 | p2p->req_dev_types = NULL; | |
979 | } | |
980 | ||
981 | ||
b22128ef | 982 | int p2p_find(struct p2p_data *p2p, unsigned int timeout, |
046ef4aa | 983 | enum p2p_discovery_type type, |
6d92fa6e | 984 | unsigned int num_req_dev_types, const u8 *req_dev_types, |
37448ede | 985 | const u8 *dev_id, unsigned int search_delay) |
b22128ef JM |
986 | { |
987 | int res; | |
988 | ||
ed496f13 | 989 | p2p_dbg(p2p, "Starting find (type=%d)", type); |
acb69cec | 990 | os_get_reltime(&p2p->find_start); |
b22128ef | 991 | if (p2p->p2p_scan_running) { |
ed496f13 | 992 | p2p_dbg(p2p, "p2p_scan is already running"); |
b22128ef | 993 | } |
046ef4aa JMB |
994 | |
995 | p2p_free_req_dev_types(p2p); | |
996 | if (req_dev_types && num_req_dev_types) { | |
997 | p2p->req_dev_types = os_malloc(num_req_dev_types * | |
998 | WPS_DEV_TYPE_LEN); | |
999 | if (p2p->req_dev_types == NULL) | |
1000 | return -1; | |
1001 | os_memcpy(p2p->req_dev_types, req_dev_types, | |
1002 | num_req_dev_types * WPS_DEV_TYPE_LEN); | |
1003 | p2p->num_req_dev_types = num_req_dev_types; | |
1004 | } | |
1005 | ||
6d92fa6e JM |
1006 | if (dev_id) { |
1007 | os_memcpy(p2p->find_dev_id_buf, dev_id, ETH_ALEN); | |
1008 | p2p->find_dev_id = p2p->find_dev_id_buf; | |
1009 | } else | |
1010 | p2p->find_dev_id = NULL; | |
1011 | ||
b22128ef JM |
1012 | p2p->start_after_scan = P2P_AFTER_SCAN_NOTHING; |
1013 | p2p_clear_timeout(p2p); | |
1014 | p2p->cfg->stop_listen(p2p->cfg->cb_ctx); | |
1015 | p2p->find_type = type; | |
1016 | p2p_device_clear_reported(p2p); | |
1017 | p2p_set_state(p2p, P2P_SEARCH); | |
37448ede JM |
1018 | p2p->search_delay = search_delay; |
1019 | p2p->in_search_delay = 0; | |
b22128ef | 1020 | eloop_cancel_timeout(p2p_find_timeout, p2p, NULL); |
39185dfa | 1021 | p2p->last_p2p_find_timeout = timeout; |
b22128ef JM |
1022 | if (timeout) |
1023 | eloop_register_timeout(timeout, 0, p2p_find_timeout, | |
1024 | p2p, NULL); | |
1025 | switch (type) { | |
1026 | case P2P_FIND_START_WITH_FULL: | |
1027 | case P2P_FIND_PROGRESSIVE: | |
046ef4aa JMB |
1028 | res = p2p->cfg->p2p_scan(p2p->cfg->cb_ctx, P2P_SCAN_FULL, 0, |
1029 | p2p->num_req_dev_types, | |
360182ed JM |
1030 | p2p->req_dev_types, dev_id, |
1031 | DEV_PW_DEFAULT); | |
b22128ef JM |
1032 | break; |
1033 | case P2P_FIND_ONLY_SOCIAL: | |
046ef4aa JMB |
1034 | res = p2p->cfg->p2p_scan(p2p->cfg->cb_ctx, P2P_SCAN_SOCIAL, 0, |
1035 | p2p->num_req_dev_types, | |
360182ed JM |
1036 | p2p->req_dev_types, dev_id, |
1037 | DEV_PW_DEFAULT); | |
b22128ef JM |
1038 | break; |
1039 | default: | |
1040 | return -1; | |
1041 | } | |
1042 | ||
1043 | if (res == 0) { | |
ed496f13 | 1044 | p2p_dbg(p2p, "Running p2p_scan"); |
b22128ef JM |
1045 | p2p->p2p_scan_running = 1; |
1046 | eloop_cancel_timeout(p2p_scan_timeout, p2p, NULL); | |
1047 | eloop_register_timeout(P2P_SCAN_TIMEOUT, 0, p2p_scan_timeout, | |
1048 | p2p, NULL); | |
1b5d4714 JM |
1049 | } else if (p2p->p2p_scan_running) { |
1050 | p2p_dbg(p2p, "Failed to start p2p_scan - another p2p_scan was already running"); | |
1051 | /* wait for the previous p2p_scan to complete */ | |
825fb6b2 | 1052 | res = 0; /* do not report failure */ |
b22128ef | 1053 | } else { |
ed496f13 | 1054 | p2p_dbg(p2p, "Failed to start p2p_scan"); |
0c96fd6d JM |
1055 | p2p_set_state(p2p, P2P_IDLE); |
1056 | eloop_cancel_timeout(p2p_find_timeout, p2p, NULL); | |
b22128ef JM |
1057 | } |
1058 | ||
1059 | return res; | |
1060 | } | |
1061 | ||
1062 | ||
0b8889d8 | 1063 | void p2p_stop_find_for_freq(struct p2p_data *p2p, int freq) |
b22128ef | 1064 | { |
ed496f13 | 1065 | p2p_dbg(p2p, "Stopping find"); |
b22128ef JM |
1066 | eloop_cancel_timeout(p2p_find_timeout, p2p, NULL); |
1067 | p2p_clear_timeout(p2p); | |
1b5d4714 | 1068 | if (p2p->state == P2P_SEARCH) |
710ae9ac | 1069 | p2p->cfg->find_stopped(p2p->cfg->cb_ctx); |
b22128ef | 1070 | p2p_set_state(p2p, P2P_IDLE); |
046ef4aa | 1071 | p2p_free_req_dev_types(p2p); |
b22128ef | 1072 | p2p->start_after_scan = P2P_AFTER_SCAN_NOTHING; |
3a2a7c3d | 1073 | if (p2p->go_neg_peer) |
fb8984fd | 1074 | p2p->go_neg_peer->flags &= ~P2P_DEV_PEER_WAITING_RESPONSE; |
b22128ef JM |
1075 | p2p->go_neg_peer = NULL; |
1076 | p2p->sd_peer = NULL; | |
1077 | p2p->invite_peer = NULL; | |
1a9c618d JM |
1078 | p2p_stop_listen_for_freq(p2p, freq); |
1079 | } | |
1080 | ||
1081 | ||
1082 | void p2p_stop_listen_for_freq(struct p2p_data *p2p, int freq) | |
1083 | { | |
0b8889d8 | 1084 | if (freq > 0 && p2p->drv_in_listen == freq && p2p->in_listen) { |
ed496f13 | 1085 | p2p_dbg(p2p, "Skip stop_listen since we are on correct channel for response"); |
0b8889d8 JM |
1086 | return; |
1087 | } | |
1a9c618d JM |
1088 | if (p2p->in_listen) { |
1089 | p2p->in_listen = 0; | |
1090 | p2p_clear_timeout(p2p); | |
1091 | } | |
54b8f994 JM |
1092 | if (p2p->drv_in_listen) { |
1093 | /* | |
1094 | * The driver may not deliver callback to p2p_listen_end() | |
1095 | * when the operation gets canceled, so clear the internal | |
1096 | * variable that is tracking driver state. | |
1097 | */ | |
ed496f13 | 1098 | p2p_dbg(p2p, "Clear drv_in_listen (%d)", p2p->drv_in_listen); |
54b8f994 JM |
1099 | p2p->drv_in_listen = 0; |
1100 | } | |
b22128ef JM |
1101 | p2p->cfg->stop_listen(p2p->cfg->cb_ctx); |
1102 | } | |
1103 | ||
1104 | ||
0b5fb86a SADR |
1105 | void p2p_stop_listen(struct p2p_data *p2p) |
1106 | { | |
1107 | if (p2p->state != P2P_LISTEN_ONLY) { | |
1108 | p2p_dbg(p2p, "Skip stop_listen since not in listen_only state."); | |
1109 | return; | |
1110 | } | |
1111 | ||
1112 | p2p_stop_listen_for_freq(p2p, 0); | |
1113 | p2p_set_state(p2p, P2P_IDLE); | |
1114 | } | |
1115 | ||
1116 | ||
0b8889d8 JM |
1117 | void p2p_stop_find(struct p2p_data *p2p) |
1118 | { | |
1119 | p2p_stop_find_for_freq(p2p, 0); | |
1120 | } | |
1121 | ||
1122 | ||
e28c226d JM |
1123 | static int p2p_prepare_channel_pref(struct p2p_data *p2p, |
1124 | unsigned int force_freq, | |
51e9f228 | 1125 | unsigned int pref_freq, int go) |
e28c226d JM |
1126 | { |
1127 | u8 op_class, op_channel; | |
1128 | unsigned int freq = force_freq ? force_freq : pref_freq; | |
1129 | ||
51e9f228 JM |
1130 | p2p_dbg(p2p, "Prepare channel pref - force_freq=%u pref_freq=%u go=%d", |
1131 | force_freq, pref_freq, go); | |
9ccd9165 | 1132 | if (p2p_freq_to_channel(freq, &op_class, &op_channel) < 0) { |
ed496f13 | 1133 | p2p_dbg(p2p, "Unsupported frequency %u MHz", freq); |
e28c226d JM |
1134 | return -1; |
1135 | } | |
1136 | ||
51e9f228 JM |
1137 | if (!p2p_channels_includes(&p2p->cfg->channels, op_class, op_channel) && |
1138 | (go || !p2p_channels_includes(&p2p->cfg->cli_channels, op_class, | |
1139 | op_channel))) { | |
ed496f13 JM |
1140 | p2p_dbg(p2p, "Frequency %u MHz (oper_class %u channel %u) not allowed for P2P", |
1141 | freq, op_class, op_channel); | |
e28c226d JM |
1142 | return -1; |
1143 | } | |
1144 | ||
1145 | p2p->op_reg_class = op_class; | |
1146 | p2p->op_channel = op_channel; | |
1147 | ||
1148 | if (force_freq) { | |
1149 | p2p->channels.reg_classes = 1; | |
1150 | p2p->channels.reg_class[0].channels = 1; | |
1151 | p2p->channels.reg_class[0].reg_class = p2p->op_reg_class; | |
1152 | p2p->channels.reg_class[0].channel[0] = p2p->op_channel; | |
1153 | } else { | |
1154 | os_memcpy(&p2p->channels, &p2p->cfg->channels, | |
1155 | sizeof(struct p2p_channels)); | |
1156 | } | |
1157 | ||
1158 | return 0; | |
1159 | } | |
1160 | ||
1161 | ||
1162 | static void p2p_prepare_channel_best(struct p2p_data *p2p) | |
1163 | { | |
1164 | u8 op_class, op_channel; | |
00043740 JM |
1165 | const int op_classes_5ghz[] = { 124, 115, 0 }; |
1166 | const int op_classes_ht40[] = { 126, 127, 116, 117, 0 }; | |
384bdd02 | 1167 | const int op_classes_vht[] = { 128, 0 }; |
e28c226d | 1168 | |
99d7c762 JM |
1169 | p2p_dbg(p2p, "Prepare channel best"); |
1170 | ||
e28c226d JM |
1171 | if (!p2p->cfg->cfg_op_channel && p2p->best_freq_overall > 0 && |
1172 | p2p_supported_freq(p2p, p2p->best_freq_overall) && | |
9ccd9165 JM |
1173 | p2p_freq_to_channel(p2p->best_freq_overall, &op_class, &op_channel) |
1174 | == 0) { | |
ed496f13 | 1175 | p2p_dbg(p2p, "Select best overall channel as operating channel preference"); |
e28c226d JM |
1176 | p2p->op_reg_class = op_class; |
1177 | p2p->op_channel = op_channel; | |
1178 | } else if (!p2p->cfg->cfg_op_channel && p2p->best_freq_5 > 0 && | |
1179 | p2p_supported_freq(p2p, p2p->best_freq_5) && | |
9ccd9165 JM |
1180 | p2p_freq_to_channel(p2p->best_freq_5, &op_class, &op_channel) |
1181 | == 0) { | |
ed496f13 | 1182 | p2p_dbg(p2p, "Select best 5 GHz channel as operating channel preference"); |
e28c226d JM |
1183 | p2p->op_reg_class = op_class; |
1184 | p2p->op_channel = op_channel; | |
1185 | } else if (!p2p->cfg->cfg_op_channel && p2p->best_freq_24 > 0 && | |
1186 | p2p_supported_freq(p2p, p2p->best_freq_24) && | |
9ccd9165 JM |
1187 | p2p_freq_to_channel(p2p->best_freq_24, &op_class, |
1188 | &op_channel) == 0) { | |
ed496f13 | 1189 | p2p_dbg(p2p, "Select best 2.4 GHz channel as operating channel preference"); |
e28c226d JM |
1190 | p2p->op_reg_class = op_class; |
1191 | p2p->op_channel = op_channel; | |
6701fdc3 JM |
1192 | } else if (p2p->cfg->num_pref_chan > 0 && |
1193 | p2p_channels_includes(&p2p->cfg->channels, | |
1194 | p2p->cfg->pref_chan[0].op_class, | |
1195 | p2p->cfg->pref_chan[0].chan)) { | |
1196 | p2p_dbg(p2p, "Select first pref_chan entry as operating channel preference"); | |
1197 | p2p->op_reg_class = p2p->cfg->pref_chan[0].op_class; | |
1198 | p2p->op_channel = p2p->cfg->pref_chan[0].chan; | |
384bdd02 JM |
1199 | } else if (p2p_channel_select(&p2p->cfg->channels, op_classes_vht, |
1200 | &p2p->op_reg_class, &p2p->op_channel) == | |
1201 | 0) { | |
1202 | p2p_dbg(p2p, "Select possible VHT channel (op_class %u channel %u) as operating channel preference", | |
1203 | p2p->op_reg_class, p2p->op_channel); | |
a30d50b3 JM |
1204 | } else if (p2p_channel_select(&p2p->cfg->channels, op_classes_ht40, |
1205 | &p2p->op_reg_class, &p2p->op_channel) == | |
1206 | 0) { | |
1207 | p2p_dbg(p2p, "Select possible HT40 channel (op_class %u channel %u) as operating channel preference", | |
1208 | p2p->op_reg_class, p2p->op_channel); | |
f2407107 JM |
1209 | } else if (p2p_channel_select(&p2p->cfg->channels, op_classes_5ghz, |
1210 | &p2p->op_reg_class, &p2p->op_channel) == | |
1211 | 0) { | |
1212 | p2p_dbg(p2p, "Select possible 5 GHz channel (op_class %u channel %u) as operating channel preference", | |
1213 | p2p->op_reg_class, p2p->op_channel); | |
94b84bc7 AH |
1214 | } else if (p2p_channels_includes(&p2p->cfg->channels, |
1215 | p2p->cfg->op_reg_class, | |
1216 | p2p->cfg->op_channel)) { | |
99d7c762 | 1217 | p2p_dbg(p2p, "Select pre-configured channel as operating channel preference"); |
e28c226d JM |
1218 | p2p->op_reg_class = p2p->cfg->op_reg_class; |
1219 | p2p->op_channel = p2p->cfg->op_channel; | |
6ace13a9 JM |
1220 | } else if (p2p_channel_random_social(&p2p->cfg->channels, |
1221 | &p2p->op_reg_class, | |
1222 | &p2p->op_channel) == 0) { | |
1223 | p2p_dbg(p2p, "Select random available social channel %d from 2.4 GHz band as operating channel preference", | |
1224 | p2p->op_channel); | |
94b84bc7 | 1225 | } else { |
6ace13a9 JM |
1226 | /* Select any random available channel from the first available |
1227 | * operating class */ | |
1228 | p2p_channel_select(&p2p->cfg->channels, NULL, | |
1229 | &p2p->op_reg_class, | |
1230 | &p2p->op_channel); | |
1231 | p2p_dbg(p2p, "Select random available channel %d from operating class %d as operating channel preference", | |
1232 | p2p->op_channel, p2p->op_reg_class); | |
e28c226d JM |
1233 | } |
1234 | ||
1235 | os_memcpy(&p2p->channels, &p2p->cfg->channels, | |
1236 | sizeof(struct p2p_channels)); | |
1237 | } | |
1238 | ||
1239 | ||
a5830ede JM |
1240 | /** |
1241 | * p2p_prepare_channel - Select operating channel for GO Negotiation | |
1242 | * @p2p: P2P module context from p2p_init() | |
1243 | * @dev: Selected peer device | |
1244 | * @force_freq: Forced frequency in MHz or 0 if not forced | |
1245 | * @pref_freq: Preferred frequency in MHz or 0 if no preference | |
51e9f228 | 1246 | * @go: Whether the local end will be forced to be GO |
a5830ede JM |
1247 | * Returns: 0 on success, -1 on failure (channel not supported for P2P) |
1248 | * | |
1249 | * This function is used to do initial operating channel selection for GO | |
1250 | * Negotiation prior to having received peer information. The selected channel | |
1251 | * may be further optimized in p2p_reselect_channel() once the peer information | |
1252 | * is available. | |
1253 | */ | |
79879f4a | 1254 | int p2p_prepare_channel(struct p2p_data *p2p, struct p2p_device *dev, |
51e9f228 | 1255 | unsigned int force_freq, unsigned int pref_freq, int go) |
b22128ef | 1256 | { |
51e9f228 JM |
1257 | p2p_dbg(p2p, "Prepare channel - force_freq=%u pref_freq=%u go=%d", |
1258 | force_freq, pref_freq, go); | |
04a3e69d | 1259 | if (force_freq || pref_freq) { |
51e9f228 JM |
1260 | if (p2p_prepare_channel_pref(p2p, force_freq, pref_freq, go) < |
1261 | 0) | |
1e19f734 | 1262 | return -1; |
b22128ef | 1263 | } else { |
e28c226d | 1264 | p2p_prepare_channel_best(p2p); |
b22128ef | 1265 | } |
51e9f228 JM |
1266 | p2p_channels_dump(p2p, "prepared channels", &p2p->channels); |
1267 | if (go) | |
1268 | p2p_channels_remove_freqs(&p2p->channels, &p2p->no_go_freq); | |
1269 | else if (!force_freq) | |
1270 | p2p_channels_union(&p2p->channels, &p2p->cfg->cli_channels, | |
1271 | &p2p->channels); | |
1272 | p2p_channels_dump(p2p, "after go/cli filter/add", &p2p->channels); | |
1273 | ||
ed496f13 | 1274 | p2p_dbg(p2p, "Own preference for operation channel: Operating Class %u Channel %u%s", |
b22128ef JM |
1275 | p2p->op_reg_class, p2p->op_channel, |
1276 | force_freq ? " (forced)" : ""); | |
1277 | ||
92ac756c JM |
1278 | if (force_freq) |
1279 | dev->flags |= P2P_DEV_FORCE_FREQ; | |
1280 | else | |
1281 | dev->flags &= ~P2P_DEV_FORCE_FREQ; | |
1282 | ||
7861cb08 JM |
1283 | return 0; |
1284 | } | |
1285 | ||
1286 | ||
acc247b2 JM |
1287 | static void p2p_set_dev_persistent(struct p2p_device *dev, |
1288 | int persistent_group) | |
1289 | { | |
1290 | switch (persistent_group) { | |
1291 | case 0: | |
1292 | dev->flags &= ~(P2P_DEV_PREFER_PERSISTENT_GROUP | | |
1293 | P2P_DEV_PREFER_PERSISTENT_RECONN); | |
1294 | break; | |
1295 | case 1: | |
1296 | dev->flags |= P2P_DEV_PREFER_PERSISTENT_GROUP; | |
1297 | dev->flags &= ~P2P_DEV_PREFER_PERSISTENT_RECONN; | |
1298 | break; | |
1299 | case 2: | |
1300 | dev->flags |= P2P_DEV_PREFER_PERSISTENT_GROUP | | |
1301 | P2P_DEV_PREFER_PERSISTENT_RECONN; | |
1302 | break; | |
1303 | } | |
1304 | } | |
1305 | ||
1306 | ||
7861cb08 JM |
1307 | int p2p_connect(struct p2p_data *p2p, const u8 *peer_addr, |
1308 | enum p2p_wps_method wps_method, | |
1309 | int go_intent, const u8 *own_interface_addr, | |
23c84252 | 1310 | unsigned int force_freq, int persistent_group, |
3bc462cb | 1311 | const u8 *force_ssid, size_t force_ssid_len, |
ab9e3442 | 1312 | int pd_before_go_neg, unsigned int pref_freq, u16 oob_pw_id) |
7861cb08 JM |
1313 | { |
1314 | struct p2p_device *dev; | |
1315 | ||
ed496f13 | 1316 | p2p_dbg(p2p, "Request to start group negotiation - peer=" MACSTR |
7861cb08 | 1317 | " GO Intent=%d Intended Interface Address=" MACSTR |
ab9e3442 JM |
1318 | " wps_method=%d persistent_group=%d pd_before_go_neg=%d " |
1319 | "oob_pw_id=%u", | |
7861cb08 | 1320 | MAC2STR(peer_addr), go_intent, MAC2STR(own_interface_addr), |
ab9e3442 | 1321 | wps_method, persistent_group, pd_before_go_neg, oob_pw_id); |
7861cb08 | 1322 | |
b22128ef JM |
1323 | dev = p2p_get_device(p2p, peer_addr); |
1324 | if (dev == NULL || (dev->flags & P2P_DEV_PROBE_REQ_ONLY)) { | |
ed496f13 | 1325 | p2p_dbg(p2p, "Cannot connect to unknown P2P Device " MACSTR, |
b22128ef JM |
1326 | MAC2STR(peer_addr)); |
1327 | return -1; | |
1328 | } | |
1329 | ||
51e9f228 JM |
1330 | if (p2p_prepare_channel(p2p, dev, force_freq, pref_freq, |
1331 | go_intent == 15) < 0) | |
92ac756c JM |
1332 | return -1; |
1333 | ||
b22128ef | 1334 | if (dev->flags & P2P_DEV_GROUP_CLIENT_ONLY) { |
c5db8e51 KRK |
1335 | if (!(dev->info.dev_capab & |
1336 | P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY)) { | |
ed496f13 | 1337 | p2p_dbg(p2p, "Cannot connect to P2P Device " MACSTR |
b22128ef JM |
1338 | " that is in a group and is not discoverable", |
1339 | MAC2STR(peer_addr)); | |
1340 | return -1; | |
1341 | } | |
1342 | if (dev->oper_freq <= 0) { | |
ed496f13 | 1343 | p2p_dbg(p2p, "Cannot connect to P2P Device " MACSTR |
b22128ef JM |
1344 | " with incomplete information", |
1345 | MAC2STR(peer_addr)); | |
1346 | return -1; | |
1347 | } | |
1348 | ||
1349 | /* | |
1350 | * First, try to connect directly. If the peer does not | |
1351 | * acknowledge frames, assume it is sleeping and use device | |
1352 | * discoverability via the GO at that point. | |
1353 | */ | |
1354 | } | |
1355 | ||
23c84252 JM |
1356 | p2p->ssid_set = 0; |
1357 | if (force_ssid) { | |
1358 | wpa_hexdump_ascii(MSG_DEBUG, "P2P: Forced SSID", | |
1359 | force_ssid, force_ssid_len); | |
1360 | os_memcpy(p2p->ssid, force_ssid, force_ssid_len); | |
1361 | p2p->ssid_len = force_ssid_len; | |
1362 | p2p->ssid_set = 1; | |
1363 | } | |
1364 | ||
b22128ef JM |
1365 | dev->flags &= ~P2P_DEV_NOT_YET_READY; |
1366 | dev->flags &= ~P2P_DEV_USER_REJECTED; | |
1367 | dev->flags &= ~P2P_DEV_WAIT_GO_NEG_RESPONSE; | |
1368 | dev->flags &= ~P2P_DEV_WAIT_GO_NEG_CONFIRM; | |
3bc462cb JM |
1369 | if (pd_before_go_neg) |
1370 | dev->flags |= P2P_DEV_PD_BEFORE_GO_NEG; | |
624b4d5a | 1371 | else { |
3bc462cb | 1372 | dev->flags &= ~P2P_DEV_PD_BEFORE_GO_NEG; |
624b4d5a | 1373 | /* |
003c4580 JM |
1374 | * Assign dialog token and tie breaker here to use the same |
1375 | * values in each retry within the same GO Negotiation exchange. | |
624b4d5a SD |
1376 | */ |
1377 | dev->dialog_token++; | |
1378 | if (dev->dialog_token == 0) | |
1379 | dev->dialog_token = 1; | |
003c4580 JM |
1380 | dev->tie_breaker = p2p->next_tie_breaker; |
1381 | p2p->next_tie_breaker = !p2p->next_tie_breaker; | |
624b4d5a | 1382 | } |
9dac8c3e | 1383 | dev->connect_reqs = 0; |
b22128ef JM |
1384 | dev->go_neg_req_sent = 0; |
1385 | dev->go_state = UNKNOWN_GO; | |
acc247b2 | 1386 | p2p_set_dev_persistent(dev, persistent_group); |
b22128ef JM |
1387 | p2p->go_intent = go_intent; |
1388 | os_memcpy(p2p->intended_addr, own_interface_addr, ETH_ALEN); | |
1389 | ||
1390 | if (p2p->state != P2P_IDLE) | |
1391 | p2p_stop_find(p2p); | |
1392 | ||
f44ae207 JM |
1393 | if (p2p->after_scan_tx) { |
1394 | /* | |
1395 | * We need to drop the pending frame to avoid issues with the | |
1396 | * new GO Negotiation, e.g., when the pending frame was from a | |
1397 | * previous attempt at starting a GO Negotiation. | |
1398 | */ | |
ed496f13 | 1399 | p2p_dbg(p2p, "Dropped previous pending Action frame TX that was waiting for p2p_scan completion"); |
f44ae207 JM |
1400 | os_free(p2p->after_scan_tx); |
1401 | p2p->after_scan_tx = NULL; | |
1402 | } | |
1403 | ||
b22128ef | 1404 | dev->wps_method = wps_method; |
ab9e3442 | 1405 | dev->oob_pw_id = oob_pw_id; |
b22128ef | 1406 | dev->status = P2P_SC_SUCCESS; |
d5b20a73 | 1407 | |
b22128ef | 1408 | if (p2p->p2p_scan_running) { |
ed496f13 | 1409 | p2p_dbg(p2p, "p2p_scan running - delay connect send"); |
b22128ef JM |
1410 | p2p->start_after_scan = P2P_AFTER_SCAN_CONNECT; |
1411 | os_memcpy(p2p->after_scan_peer, peer_addr, ETH_ALEN); | |
1412 | return 0; | |
1413 | } | |
1414 | p2p->start_after_scan = P2P_AFTER_SCAN_NOTHING; | |
1415 | ||
1416 | return p2p_connect_send(p2p, dev); | |
1417 | } | |
1418 | ||
1419 | ||
1420 | int p2p_authorize(struct p2p_data *p2p, const u8 *peer_addr, | |
1421 | enum p2p_wps_method wps_method, | |
1422 | int go_intent, const u8 *own_interface_addr, | |
23c84252 | 1423 | unsigned int force_freq, int persistent_group, |
04a3e69d | 1424 | const u8 *force_ssid, size_t force_ssid_len, |
ab9e3442 | 1425 | unsigned int pref_freq, u16 oob_pw_id) |
b22128ef JM |
1426 | { |
1427 | struct p2p_device *dev; | |
1428 | ||
ed496f13 | 1429 | p2p_dbg(p2p, "Request to authorize group negotiation - peer=" MACSTR |
b22128ef | 1430 | " GO Intent=%d Intended Interface Address=" MACSTR |
ab9e3442 | 1431 | " wps_method=%d persistent_group=%d oob_pw_id=%u", |
b22128ef | 1432 | MAC2STR(peer_addr), go_intent, MAC2STR(own_interface_addr), |
ab9e3442 | 1433 | wps_method, persistent_group, oob_pw_id); |
b22128ef | 1434 | |
b22128ef JM |
1435 | dev = p2p_get_device(p2p, peer_addr); |
1436 | if (dev == NULL) { | |
ed496f13 | 1437 | p2p_dbg(p2p, "Cannot authorize unknown P2P Device " MACSTR, |
b22128ef JM |
1438 | MAC2STR(peer_addr)); |
1439 | return -1; | |
1440 | } | |
1441 | ||
51e9f228 JM |
1442 | if (p2p_prepare_channel(p2p, dev, force_freq, pref_freq, go_intent == |
1443 | 15) < 0) | |
92ac756c JM |
1444 | return -1; |
1445 | ||
23c84252 JM |
1446 | p2p->ssid_set = 0; |
1447 | if (force_ssid) { | |
1448 | wpa_hexdump_ascii(MSG_DEBUG, "P2P: Forced SSID", | |
1449 | force_ssid, force_ssid_len); | |
1450 | os_memcpy(p2p->ssid, force_ssid, force_ssid_len); | |
1451 | p2p->ssid_len = force_ssid_len; | |
1452 | p2p->ssid_set = 1; | |
1453 | } | |
1454 | ||
b22128ef JM |
1455 | dev->flags &= ~P2P_DEV_NOT_YET_READY; |
1456 | dev->flags &= ~P2P_DEV_USER_REJECTED; | |
1457 | dev->go_neg_req_sent = 0; | |
1458 | dev->go_state = UNKNOWN_GO; | |
acc247b2 | 1459 | p2p_set_dev_persistent(dev, persistent_group); |
b22128ef JM |
1460 | p2p->go_intent = go_intent; |
1461 | os_memcpy(p2p->intended_addr, own_interface_addr, ETH_ALEN); | |
1462 | ||
1463 | dev->wps_method = wps_method; | |
ab9e3442 | 1464 | dev->oob_pw_id = oob_pw_id; |
b22128ef JM |
1465 | dev->status = P2P_SC_SUCCESS; |
1466 | ||
1467 | return 0; | |
1468 | } | |
1469 | ||
1470 | ||
1471 | void p2p_add_dev_info(struct p2p_data *p2p, const u8 *addr, | |
1472 | struct p2p_device *dev, struct p2p_message *msg) | |
1473 | { | |
acb69cec | 1474 | os_get_reltime(&dev->last_seen); |
b22128ef | 1475 | |
ed496f13 | 1476 | p2p_copy_wps_info(p2p, dev, 0, msg); |
e57ae6e1 | 1477 | |
b22128ef JM |
1478 | if (msg->listen_channel) { |
1479 | int freq; | |
9ccd9165 | 1480 | freq = p2p_channel_to_freq(msg->listen_channel[3], |
b22128ef JM |
1481 | msg->listen_channel[4]); |
1482 | if (freq < 0) { | |
ed496f13 | 1483 | p2p_dbg(p2p, "Unknown peer Listen channel: " |
b22128ef JM |
1484 | "country=%c%c(0x%02x) reg_class=%u channel=%u", |
1485 | msg->listen_channel[0], | |
1486 | msg->listen_channel[1], | |
1487 | msg->listen_channel[2], | |
1488 | msg->listen_channel[3], | |
1489 | msg->listen_channel[4]); | |
1490 | } else { | |
ed496f13 JM |
1491 | p2p_dbg(p2p, "Update peer " MACSTR |
1492 | " Listen channel: %u -> %u MHz", | |
c5db8e51 | 1493 | MAC2STR(dev->info.p2p_device_addr), |
b22128ef JM |
1494 | dev->listen_freq, freq); |
1495 | dev->listen_freq = freq; | |
1496 | } | |
1497 | } | |
b22128ef | 1498 | |
9675ce35 JM |
1499 | if (msg->wfd_subelems) { |
1500 | wpabuf_free(dev->info.wfd_subelems); | |
1501 | dev->info.wfd_subelems = wpabuf_dup(msg->wfd_subelems); | |
1502 | } | |
1503 | ||
b22128ef JM |
1504 | if (dev->flags & P2P_DEV_PROBE_REQ_ONLY) { |
1505 | dev->flags &= ~P2P_DEV_PROBE_REQ_ONLY; | |
ed496f13 | 1506 | p2p_dbg(p2p, "Completed device entry based on data from GO Negotiation Request"); |
b22128ef | 1507 | } else { |
ed496f13 | 1508 | p2p_dbg(p2p, "Created device entry based on GO Neg Req: " |
b22128ef JM |
1509 | MACSTR " dev_capab=0x%x group_capab=0x%x name='%s' " |
1510 | "listen_freq=%d", | |
c5db8e51 KRK |
1511 | MAC2STR(dev->info.p2p_device_addr), |
1512 | dev->info.dev_capab, dev->info.group_capab, | |
1513 | dev->info.device_name, dev->listen_freq); | |
b22128ef JM |
1514 | } |
1515 | ||
1516 | dev->flags &= ~P2P_DEV_GROUP_CLIENT_ONLY; | |
1517 | ||
1518 | if (dev->flags & P2P_DEV_USER_REJECTED) { | |
ed496f13 | 1519 | p2p_dbg(p2p, "Do not report rejected device"); |
b22128ef JM |
1520 | return; |
1521 | } | |
1522 | ||
8fd7dc1b JB |
1523 | p2p->cfg->dev_found(p2p->cfg->cb_ctx, addr, &dev->info, |
1524 | !(dev->flags & P2P_DEV_REPORTED_ONCE)); | |
1525 | dev->flags |= P2P_DEV_REPORTED | P2P_DEV_REPORTED_ONCE; | |
b22128ef JM |
1526 | } |
1527 | ||
1528 | ||
1529 | void p2p_build_ssid(struct p2p_data *p2p, u8 *ssid, size_t *ssid_len) | |
1530 | { | |
1531 | os_memcpy(ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN); | |
1532 | p2p_random((char *) &ssid[P2P_WILDCARD_SSID_LEN], 2); | |
1533 | os_memcpy(&ssid[P2P_WILDCARD_SSID_LEN + 2], | |
1534 | p2p->cfg->ssid_postfix, p2p->cfg->ssid_postfix_len); | |
1535 | *ssid_len = P2P_WILDCARD_SSID_LEN + 2 + p2p->cfg->ssid_postfix_len; | |
1536 | } | |
1537 | ||
1538 | ||
1539 | int p2p_go_params(struct p2p_data *p2p, struct p2p_go_neg_results *params) | |
1540 | { | |
1541 | p2p_build_ssid(p2p, params->ssid, ¶ms->ssid_len); | |
1542 | p2p_random(params->passphrase, 8); | |
1543 | return 0; | |
1544 | } | |
1545 | ||
1546 | ||
1547 | void p2p_go_complete(struct p2p_data *p2p, struct p2p_device *peer) | |
1548 | { | |
1549 | struct p2p_go_neg_results res; | |
1550 | int go = peer->go_state == LOCAL_GO; | |
1551 | struct p2p_channels intersection; | |
1552 | int freqs; | |
1553 | size_t i, j; | |
1554 | ||
ed496f13 JM |
1555 | p2p_dbg(p2p, "GO Negotiation with " MACSTR " completed (%s will be GO)", |
1556 | MAC2STR(peer->info.p2p_device_addr), go ? "local end" : "peer"); | |
b22128ef JM |
1557 | |
1558 | os_memset(&res, 0, sizeof(res)); | |
1559 | res.role_go = go; | |
c5db8e51 | 1560 | os_memcpy(res.peer_device_addr, peer->info.p2p_device_addr, ETH_ALEN); |
b22128ef JM |
1561 | os_memcpy(res.peer_interface_addr, peer->intended_addr, ETH_ALEN); |
1562 | res.wps_method = peer->wps_method; | |
acc247b2 JM |
1563 | if (peer->flags & P2P_DEV_PREFER_PERSISTENT_GROUP) { |
1564 | if (peer->flags & P2P_DEV_PREFER_PERSISTENT_RECONN) | |
1565 | res.persistent_group = 2; | |
1566 | else | |
1567 | res.persistent_group = 1; | |
1568 | } | |
b22128ef JM |
1569 | |
1570 | if (go) { | |
1571 | /* Setup AP mode for WPS provisioning */ | |
9ccd9165 | 1572 | res.freq = p2p_channel_to_freq(p2p->op_reg_class, |
b22128ef JM |
1573 | p2p->op_channel); |
1574 | os_memcpy(res.ssid, p2p->ssid, p2p->ssid_len); | |
1575 | res.ssid_len = p2p->ssid_len; | |
1576 | p2p_random(res.passphrase, 8); | |
e9a7ae41 | 1577 | } else { |
b22128ef | 1578 | res.freq = peer->oper_freq; |
e9a7ae41 JM |
1579 | if (p2p->ssid_len) { |
1580 | os_memcpy(res.ssid, p2p->ssid, p2p->ssid_len); | |
1581 | res.ssid_len = p2p->ssid_len; | |
1582 | } | |
1583 | } | |
b22128ef | 1584 | |
556b30da JM |
1585 | p2p_channels_dump(p2p, "own channels", &p2p->channels); |
1586 | p2p_channels_dump(p2p, "peer channels", &peer->channels); | |
b22128ef JM |
1587 | p2p_channels_intersect(&p2p->channels, &peer->channels, |
1588 | &intersection); | |
556b30da JM |
1589 | if (go) { |
1590 | p2p_channels_remove_freqs(&intersection, &p2p->no_go_freq); | |
1591 | p2p_channels_dump(p2p, "intersection after no-GO removal", | |
1592 | &intersection); | |
1593 | } | |
b22128ef JM |
1594 | freqs = 0; |
1595 | for (i = 0; i < intersection.reg_classes; i++) { | |
1596 | struct p2p_reg_class *c = &intersection.reg_class[i]; | |
1597 | if (freqs + 1 == P2P_MAX_CHANNELS) | |
1598 | break; | |
1599 | for (j = 0; j < c->channels; j++) { | |
1600 | int freq; | |
1601 | if (freqs + 1 == P2P_MAX_CHANNELS) | |
1602 | break; | |
9ccd9165 | 1603 | freq = p2p_channel_to_freq(c->reg_class, c->channel[j]); |
b22128ef JM |
1604 | if (freq < 0) |
1605 | continue; | |
1606 | res.freq_list[freqs++] = freq; | |
1607 | } | |
1608 | } | |
1609 | ||
ae3e3421 JM |
1610 | res.peer_config_timeout = go ? peer->client_timeout : peer->go_timeout; |
1611 | ||
b22128ef | 1612 | p2p_clear_timeout(p2p); |
4458d915 | 1613 | p2p->ssid_set = 0; |
b22128ef JM |
1614 | peer->go_neg_req_sent = 0; |
1615 | peer->wps_method = WPS_NOT_READY; | |
ab9e3442 | 1616 | peer->oob_pw_id = 0; |
0e0e1e56 NS |
1617 | wpabuf_free(peer->go_neg_conf); |
1618 | peer->go_neg_conf = NULL; | |
b22128ef JM |
1619 | |
1620 | p2p_set_state(p2p, P2P_PROVISIONING); | |
1621 | p2p->cfg->go_neg_completed(p2p->cfg->cb_ctx, &res); | |
1622 | } | |
1623 | ||
1624 | ||
1625 | static void p2p_rx_p2p_action(struct p2p_data *p2p, const u8 *sa, | |
1626 | const u8 *data, size_t len, int rx_freq) | |
1627 | { | |
ed496f13 | 1628 | p2p_dbg(p2p, "RX P2P Public Action from " MACSTR, MAC2STR(sa)); |
b22128ef JM |
1629 | wpa_hexdump(MSG_MSGDUMP, "P2P: P2P Public Action contents", data, len); |
1630 | ||
1631 | if (len < 1) | |
1632 | return; | |
1633 | ||
1634 | switch (data[0]) { | |
1635 | case P2P_GO_NEG_REQ: | |
1636 | p2p_process_go_neg_req(p2p, sa, data + 1, len - 1, rx_freq); | |
1637 | break; | |
1638 | case P2P_GO_NEG_RESP: | |
1639 | p2p_process_go_neg_resp(p2p, sa, data + 1, len - 1, rx_freq); | |
1640 | break; | |
1641 | case P2P_GO_NEG_CONF: | |
1642 | p2p_process_go_neg_conf(p2p, sa, data + 1, len - 1); | |
1643 | break; | |
1644 | case P2P_INVITATION_REQ: | |
1645 | p2p_process_invitation_req(p2p, sa, data + 1, len - 1, | |
1646 | rx_freq); | |
1647 | break; | |
1648 | case P2P_INVITATION_RESP: | |
dc46fd66 | 1649 | p2p->cfg->send_action_done(p2p->cfg->cb_ctx); |
b22128ef JM |
1650 | p2p_process_invitation_resp(p2p, sa, data + 1, len - 1); |
1651 | break; | |
1652 | case P2P_PROV_DISC_REQ: | |
1653 | p2p_process_prov_disc_req(p2p, sa, data + 1, len - 1, rx_freq); | |
1654 | break; | |
1655 | case P2P_PROV_DISC_RESP: | |
1656 | p2p_process_prov_disc_resp(p2p, sa, data + 1, len - 1); | |
1657 | break; | |
1658 | case P2P_DEV_DISC_REQ: | |
1659 | p2p_process_dev_disc_req(p2p, sa, data + 1, len - 1, rx_freq); | |
1660 | break; | |
1661 | case P2P_DEV_DISC_RESP: | |
1662 | p2p_process_dev_disc_resp(p2p, sa, data + 1, len - 1); | |
1663 | break; | |
1664 | default: | |
ed496f13 | 1665 | p2p_dbg(p2p, "Unsupported P2P Public Action frame type %d", |
b22128ef JM |
1666 | data[0]); |
1667 | break; | |
1668 | } | |
1669 | } | |
1670 | ||
1671 | ||
19df9b07 JM |
1672 | static void p2p_rx_action_public(struct p2p_data *p2p, const u8 *da, |
1673 | const u8 *sa, const u8 *bssid, const u8 *data, | |
1674 | size_t len, int freq) | |
b22128ef JM |
1675 | { |
1676 | if (len < 1) | |
1677 | return; | |
1678 | ||
1679 | switch (data[0]) { | |
1680 | case WLAN_PA_VENDOR_SPECIFIC: | |
1681 | data++; | |
1682 | len--; | |
8bc4372f | 1683 | if (len < 4) |
b22128ef | 1684 | return; |
8bc4372f | 1685 | if (WPA_GET_BE32(data) != P2P_IE_VENDOR_TYPE) |
b22128ef JM |
1686 | return; |
1687 | ||
8bc4372f RJ |
1688 | data += 4; |
1689 | len -= 4; | |
b22128ef | 1690 | |
8bc4372f | 1691 | p2p_rx_p2p_action(p2p, sa, data, len, freq); |
b22128ef JM |
1692 | break; |
1693 | case WLAN_PA_GAS_INITIAL_REQ: | |
1694 | p2p_rx_gas_initial_req(p2p, sa, data + 1, len - 1, freq); | |
1695 | break; | |
1696 | case WLAN_PA_GAS_INITIAL_RESP: | |
18708aad JM |
1697 | p2p_rx_gas_initial_resp(p2p, sa, data + 1, len - 1, freq); |
1698 | break; | |
1699 | case WLAN_PA_GAS_COMEBACK_REQ: | |
1700 | p2p_rx_gas_comeback_req(p2p, sa, data + 1, len - 1, freq); | |
1701 | break; | |
1702 | case WLAN_PA_GAS_COMEBACK_RESP: | |
1703 | p2p_rx_gas_comeback_resp(p2p, sa, data + 1, len - 1, freq); | |
b22128ef JM |
1704 | break; |
1705 | } | |
1706 | } | |
1707 | ||
1708 | ||
1709 | void p2p_rx_action(struct p2p_data *p2p, const u8 *da, const u8 *sa, | |
1710 | const u8 *bssid, u8 category, | |
1711 | const u8 *data, size_t len, int freq) | |
1712 | { | |
1713 | if (category == WLAN_ACTION_PUBLIC) { | |
1714 | p2p_rx_action_public(p2p, da, sa, bssid, data, len, freq); | |
1715 | return; | |
1716 | } | |
1717 | ||
1718 | if (category != WLAN_ACTION_VENDOR_SPECIFIC) | |
1719 | return; | |
1720 | ||
1721 | if (len < 4) | |
1722 | return; | |
1723 | ||
8bc4372f | 1724 | if (WPA_GET_BE32(data) != P2P_IE_VENDOR_TYPE) |
b22128ef | 1725 | return; |
8bc4372f RJ |
1726 | data += 4; |
1727 | len -= 4; | |
b22128ef JM |
1728 | |
1729 | /* P2P action frame */ | |
ed496f13 | 1730 | p2p_dbg(p2p, "RX P2P Action from " MACSTR, MAC2STR(sa)); |
b22128ef JM |
1731 | wpa_hexdump(MSG_MSGDUMP, "P2P: P2P Action contents", data, len); |
1732 | ||
1733 | if (len < 1) | |
1734 | return; | |
1735 | switch (data[0]) { | |
1736 | case P2P_NOA: | |
ed496f13 | 1737 | p2p_dbg(p2p, "Received P2P Action - Notice of Absence"); |
b22128ef JM |
1738 | /* TODO */ |
1739 | break; | |
1740 | case P2P_PRESENCE_REQ: | |
1741 | p2p_process_presence_req(p2p, da, sa, data + 1, len - 1, freq); | |
1742 | break; | |
1743 | case P2P_PRESENCE_RESP: | |
1744 | p2p_process_presence_resp(p2p, da, sa, data + 1, len - 1); | |
1745 | break; | |
1746 | case P2P_GO_DISC_REQ: | |
1747 | p2p_process_go_disc_req(p2p, da, sa, data + 1, len - 1, freq); | |
1748 | break; | |
1749 | default: | |
ed496f13 | 1750 | p2p_dbg(p2p, "Received P2P Action - unknown type %u", data[0]); |
b22128ef JM |
1751 | break; |
1752 | } | |
1753 | } | |
1754 | ||
1755 | ||
1756 | static void p2p_go_neg_start(void *eloop_ctx, void *timeout_ctx) | |
1757 | { | |
1758 | struct p2p_data *p2p = eloop_ctx; | |
1759 | if (p2p->go_neg_peer == NULL) | |
1760 | return; | |
1761 | p2p->cfg->stop_listen(p2p->cfg->cb_ctx); | |
1762 | p2p->go_neg_peer->status = P2P_SC_SUCCESS; | |
1763 | p2p_connect_send(p2p, p2p->go_neg_peer); | |
1764 | } | |
1765 | ||
1766 | ||
1767 | static void p2p_invite_start(void *eloop_ctx, void *timeout_ctx) | |
1768 | { | |
1769 | struct p2p_data *p2p = eloop_ctx; | |
1770 | if (p2p->invite_peer == NULL) | |
1771 | return; | |
1772 | p2p->cfg->stop_listen(p2p->cfg->cb_ctx); | |
8e9f53c3 JM |
1773 | p2p_invite_send(p2p, p2p->invite_peer, p2p->invite_go_dev_addr, |
1774 | p2p->invite_dev_pw_id); | |
b22128ef JM |
1775 | } |
1776 | ||
1777 | ||
1778 | static void p2p_add_dev_from_probe_req(struct p2p_data *p2p, const u8 *addr, | |
1779 | const u8 *ie, size_t ie_len) | |
1780 | { | |
1781 | struct p2p_message msg; | |
1782 | struct p2p_device *dev; | |
1783 | ||
1784 | os_memset(&msg, 0, sizeof(msg)); | |
1785 | if (p2p_parse_ies(ie, ie_len, &msg) < 0 || msg.p2p_attributes == NULL) | |
1786 | { | |
1787 | p2p_parse_free(&msg); | |
1788 | return; /* not a P2P probe */ | |
1789 | } | |
1790 | ||
1791 | if (msg.ssid == NULL || msg.ssid[1] != P2P_WILDCARD_SSID_LEN || | |
1792 | os_memcmp(msg.ssid + 2, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) | |
1793 | != 0) { | |
1794 | /* The Probe Request is not part of P2P Device Discovery. It is | |
1795 | * not known whether the source address of the frame is the P2P | |
1796 | * Device Address or P2P Interface Address. Do not add a new | |
1797 | * peer entry based on this frames. | |
1798 | */ | |
1799 | p2p_parse_free(&msg); | |
1800 | return; | |
1801 | } | |
1802 | ||
1803 | dev = p2p_get_device(p2p, addr); | |
1804 | if (dev) { | |
1805 | if (dev->country[0] == 0 && msg.listen_channel) | |
1806 | os_memcpy(dev->country, msg.listen_channel, 3); | |
acb69cec | 1807 | os_get_reltime(&dev->last_seen); |
b22128ef JM |
1808 | p2p_parse_free(&msg); |
1809 | return; /* already known */ | |
1810 | } | |
1811 | ||
1812 | dev = p2p_create_device(p2p, addr); | |
1813 | if (dev == NULL) { | |
1814 | p2p_parse_free(&msg); | |
1815 | return; | |
1816 | } | |
1817 | ||
acb69cec | 1818 | os_get_reltime(&dev->last_seen); |
b22128ef JM |
1819 | dev->flags |= P2P_DEV_PROBE_REQ_ONLY; |
1820 | ||
b22128ef JM |
1821 | if (msg.listen_channel) { |
1822 | os_memcpy(dev->country, msg.listen_channel, 3); | |
9ccd9165 | 1823 | dev->listen_freq = p2p_channel_to_freq(msg.listen_channel[3], |
b22128ef JM |
1824 | msg.listen_channel[4]); |
1825 | } | |
1826 | ||
ed496f13 | 1827 | p2p_copy_wps_info(p2p, dev, 1, &msg); |
e57ae6e1 | 1828 | |
9675ce35 JM |
1829 | if (msg.wfd_subelems) { |
1830 | wpabuf_free(dev->info.wfd_subelems); | |
1831 | dev->info.wfd_subelems = wpabuf_dup(msg.wfd_subelems); | |
1832 | } | |
1833 | ||
b22128ef JM |
1834 | p2p_parse_free(&msg); |
1835 | ||
ed496f13 | 1836 | p2p_dbg(p2p, "Created device entry based on Probe Req: " MACSTR |
b22128ef | 1837 | " dev_capab=0x%x group_capab=0x%x name='%s' listen_freq=%d", |
c5db8e51 KRK |
1838 | MAC2STR(dev->info.p2p_device_addr), dev->info.dev_capab, |
1839 | dev->info.group_capab, dev->info.device_name, | |
1840 | dev->listen_freq); | |
b22128ef JM |
1841 | } |
1842 | ||
1843 | ||
1844 | struct p2p_device * p2p_add_dev_from_go_neg_req(struct p2p_data *p2p, | |
1845 | const u8 *addr, | |
1846 | struct p2p_message *msg) | |
1847 | { | |
1848 | struct p2p_device *dev; | |
1849 | ||
1850 | dev = p2p_get_device(p2p, addr); | |
1851 | if (dev) { | |
acb69cec | 1852 | os_get_reltime(&dev->last_seen); |
b22128ef JM |
1853 | return dev; /* already known */ |
1854 | } | |
1855 | ||
1856 | dev = p2p_create_device(p2p, addr); | |
1857 | if (dev == NULL) | |
1858 | return NULL; | |
1859 | ||
1860 | p2p_add_dev_info(p2p, addr, dev, msg); | |
1861 | ||
1862 | return dev; | |
1863 | } | |
1864 | ||
1865 | ||
1866 | static int dev_type_match(const u8 *dev_type, const u8 *req_dev_type) | |
1867 | { | |
1868 | if (os_memcmp(dev_type, req_dev_type, WPS_DEV_TYPE_LEN) == 0) | |
1869 | return 1; | |
1870 | if (os_memcmp(dev_type, req_dev_type, 2) == 0 && | |
1871 | WPA_GET_BE32(&req_dev_type[2]) == 0 && | |
1872 | WPA_GET_BE16(&req_dev_type[6]) == 0) | |
1873 | return 1; /* Category match with wildcard OUI/sub-category */ | |
1874 | return 0; | |
1875 | } | |
1876 | ||
1877 | ||
1878 | int dev_type_list_match(const u8 *dev_type, const u8 *req_dev_type[], | |
1879 | size_t num_req_dev_type) | |
1880 | { | |
1881 | size_t i; | |
1882 | for (i = 0; i < num_req_dev_type; i++) { | |
1883 | if (dev_type_match(dev_type, req_dev_type[i])) | |
1884 | return 1; | |
1885 | } | |
1886 | return 0; | |
1887 | } | |
1888 | ||
1889 | ||
1890 | /** | |
1891 | * p2p_match_dev_type - Match local device type with requested type | |
1892 | * @p2p: P2P module context from p2p_init() | |
1893 | * @wps: WPS TLVs from Probe Request frame (concatenated WPS IEs) | |
1894 | * Returns: 1 on match, 0 on mismatch | |
1895 | * | |
1896 | * This function can be used to match the Requested Device Type attribute in | |
1897 | * WPS IE with the local device types for deciding whether to reply to a Probe | |
1898 | * Request frame. | |
1899 | */ | |
1900 | int p2p_match_dev_type(struct p2p_data *p2p, struct wpabuf *wps) | |
1901 | { | |
1902 | struct wps_parse_attr attr; | |
1903 | size_t i; | |
1904 | ||
1905 | if (wps_parse_msg(wps, &attr)) | |
1906 | return 1; /* assume no Requested Device Type attributes */ | |
1907 | ||
1908 | if (attr.num_req_dev_type == 0) | |
1909 | return 1; /* no Requested Device Type attributes -> match */ | |
1910 | ||
1911 | if (dev_type_list_match(p2p->cfg->pri_dev_type, attr.req_dev_type, | |
1912 | attr.num_req_dev_type)) | |
1913 | return 1; /* Own Primary Device Type matches */ | |
1914 | ||
1915 | for (i = 0; i < p2p->cfg->num_sec_dev_types; i++) | |
1916 | if (dev_type_list_match(p2p->cfg->sec_dev_type[i], | |
1917 | attr.req_dev_type, | |
1918 | attr.num_req_dev_type)) | |
1919 | return 1; /* Own Secondary Device Type matches */ | |
1920 | ||
1921 | /* No matching device type found */ | |
1922 | return 0; | |
1923 | } | |
1924 | ||
1925 | ||
1926 | struct wpabuf * p2p_build_probe_resp_ies(struct p2p_data *p2p) | |
1927 | { | |
1928 | struct wpabuf *buf; | |
1929 | u8 *len; | |
360182ed | 1930 | int pw_id = -1; |
9675ce35 | 1931 | size_t extra = 0; |
b22128ef | 1932 | |
9675ce35 JM |
1933 | #ifdef CONFIG_WIFI_DISPLAY |
1934 | if (p2p->wfd_ie_probe_resp) | |
1935 | extra = wpabuf_len(p2p->wfd_ie_probe_resp); | |
1936 | #endif /* CONFIG_WIFI_DISPLAY */ | |
1937 | ||
1938 | buf = wpabuf_alloc(1000 + extra); | |
b22128ef JM |
1939 | if (buf == NULL) |
1940 | return NULL; | |
1941 | ||
360182ed JM |
1942 | if (p2p->go_neg_peer) { |
1943 | /* Advertise immediate availability of WPS credential */ | |
1944 | pw_id = p2p_wps_method_pw_id(p2p->go_neg_peer->wps_method); | |
1945 | } | |
1946 | ||
33183761 JM |
1947 | if (p2p_build_wps_ie(p2p, buf, pw_id, 1) < 0) { |
1948 | p2p_dbg(p2p, "Failed to build WPS IE for Probe Response"); | |
1949 | wpabuf_free(buf); | |
1950 | return NULL; | |
1951 | } | |
b22128ef | 1952 | |
9675ce35 JM |
1953 | #ifdef CONFIG_WIFI_DISPLAY |
1954 | if (p2p->wfd_ie_probe_resp) | |
1955 | wpabuf_put_buf(buf, p2p->wfd_ie_probe_resp); | |
1956 | #endif /* CONFIG_WIFI_DISPLAY */ | |
1957 | ||
b22128ef JM |
1958 | /* P2P IE */ |
1959 | len = p2p_buf_add_ie_hdr(buf); | |
18485b54 MH |
1960 | p2p_buf_add_capability(buf, p2p->dev_capab & |
1961 | ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY, 0); | |
b22128ef JM |
1962 | if (p2p->ext_listen_interval) |
1963 | p2p_buf_add_ext_listen_timing(buf, p2p->ext_listen_period, | |
1964 | p2p->ext_listen_interval); | |
1965 | p2p_buf_add_device_info(buf, p2p, NULL); | |
1966 | p2p_buf_update_ie_hdr(buf, len); | |
1967 | ||
1968 | return buf; | |
1969 | } | |
1970 | ||
1971 | ||
2d43d37f JB |
1972 | static enum p2p_probe_req_status |
1973 | p2p_reply_probe(struct p2p_data *p2p, const u8 *addr, const u8 *dst, | |
1974 | const u8 *bssid, const u8 *ie, size_t ie_len) | |
b22128ef JM |
1975 | { |
1976 | struct ieee802_11_elems elems; | |
1977 | struct wpabuf *buf; | |
1978 | struct ieee80211_mgmt *resp; | |
97c5b3c4 | 1979 | struct p2p_message msg; |
b22128ef JM |
1980 | struct wpabuf *ies; |
1981 | ||
1982 | if (!p2p->in_listen || !p2p->drv_in_listen) { | |
1983 | /* not in Listen state - ignore Probe Request */ | |
211d7ab3 JM |
1984 | p2p_dbg(p2p, "Not in Listen state (in_listen=%d drv_in_listen=%d) - ignore Probe Request", |
1985 | p2p->in_listen, p2p->drv_in_listen); | |
2d43d37f | 1986 | return P2P_PREQ_NOT_LISTEN; |
b22128ef JM |
1987 | } |
1988 | ||
1989 | if (ieee802_11_parse_elems((u8 *) ie, ie_len, &elems, 0) == | |
1990 | ParseFailed) { | |
1991 | /* Ignore invalid Probe Request frames */ | |
a5527a49 | 1992 | p2p_dbg(p2p, "Could not parse Probe Request frame - ignore it"); |
2d43d37f | 1993 | return P2P_PREQ_MALFORMED; |
b22128ef JM |
1994 | } |
1995 | ||
1996 | if (elems.p2p == NULL) { | |
1997 | /* not a P2P probe - ignore it */ | |
a5527a49 | 1998 | p2p_dbg(p2p, "Not a P2P probe - ignore it"); |
2d43d37f | 1999 | return P2P_PREQ_NOT_P2P; |
b22128ef JM |
2000 | } |
2001 | ||
04a85e44 JM |
2002 | if (dst && !is_broadcast_ether_addr(dst) && |
2003 | os_memcmp(dst, p2p->cfg->dev_addr, ETH_ALEN) != 0) { | |
2004 | /* Not sent to the broadcast address or our P2P Device Address | |
2005 | */ | |
a5527a49 JM |
2006 | p2p_dbg(p2p, "Probe Req DA " MACSTR " not ours - ignore it", |
2007 | MAC2STR(dst)); | |
2d43d37f | 2008 | return P2P_PREQ_NOT_PROCESSED; |
04a85e44 JM |
2009 | } |
2010 | ||
2011 | if (bssid && !is_broadcast_ether_addr(bssid)) { | |
2012 | /* Not sent to the Wildcard BSSID */ | |
a5527a49 JM |
2013 | p2p_dbg(p2p, "Probe Req BSSID " MACSTR " not wildcard - ignore it", |
2014 | MAC2STR(bssid)); | |
2d43d37f | 2015 | return P2P_PREQ_NOT_PROCESSED; |
04a85e44 JM |
2016 | } |
2017 | ||
b22128ef JM |
2018 | if (elems.ssid == NULL || elems.ssid_len != P2P_WILDCARD_SSID_LEN || |
2019 | os_memcmp(elems.ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) != | |
2020 | 0) { | |
2021 | /* not using P2P Wildcard SSID - ignore */ | |
a5527a49 | 2022 | p2p_dbg(p2p, "Probe Req not using P2P Wildcard SSID - ignore it"); |
2d43d37f | 2023 | return P2P_PREQ_NOT_PROCESSED; |
b22128ef JM |
2024 | } |
2025 | ||
e1d52629 JM |
2026 | if (supp_rates_11b_only(&elems)) { |
2027 | /* Indicates support for 11b rates only */ | |
a5527a49 | 2028 | p2p_dbg(p2p, "Probe Req with 11b rates only supported - ignore it"); |
2d43d37f | 2029 | return P2P_PREQ_NOT_P2P; |
e1d52629 JM |
2030 | } |
2031 | ||
97c5b3c4 JM |
2032 | os_memset(&msg, 0, sizeof(msg)); |
2033 | if (p2p_parse_ies(ie, ie_len, &msg) < 0) { | |
2034 | /* Could not parse P2P attributes */ | |
a5527a49 | 2035 | p2p_dbg(p2p, "Could not parse P2P attributes in Probe Req - ignore it"); |
2d43d37f | 2036 | return P2P_PREQ_NOT_P2P; |
97c5b3c4 JM |
2037 | } |
2038 | ||
2039 | if (msg.device_id && | |
1c7447d0 | 2040 | os_memcmp(msg.device_id, p2p->cfg->dev_addr, ETH_ALEN) != 0) { |
97c5b3c4 | 2041 | /* Device ID did not match */ |
a5527a49 JM |
2042 | p2p_dbg(p2p, "Probe Req requested Device ID " MACSTR " did not match - ignore it", |
2043 | MAC2STR(msg.device_id)); | |
97c5b3c4 | 2044 | p2p_parse_free(&msg); |
2d43d37f | 2045 | return P2P_PREQ_NOT_PROCESSED; |
97c5b3c4 JM |
2046 | } |
2047 | ||
b22128ef | 2048 | /* Check Requested Device Type match */ |
97c5b3c4 JM |
2049 | if (msg.wps_attributes && |
2050 | !p2p_match_dev_type(p2p, msg.wps_attributes)) { | |
b22128ef | 2051 | /* No match with Requested Device Type */ |
a5527a49 | 2052 | p2p_dbg(p2p, "Probe Req requestred Device Type did not match - ignore it"); |
97c5b3c4 | 2053 | p2p_parse_free(&msg); |
2d43d37f | 2054 | return P2P_PREQ_NOT_PROCESSED; |
b22128ef | 2055 | } |
97c5b3c4 | 2056 | p2p_parse_free(&msg); |
b22128ef | 2057 | |
2d43d37f JB |
2058 | if (!p2p->cfg->send_probe_resp) { |
2059 | /* Response generated elsewhere */ | |
a5527a49 | 2060 | p2p_dbg(p2p, "Probe Resp generated elsewhere - do not generate additional response"); |
2d43d37f JB |
2061 | return P2P_PREQ_NOT_PROCESSED; |
2062 | } | |
b22128ef | 2063 | |
ed496f13 | 2064 | p2p_dbg(p2p, "Reply to P2P Probe Request in Listen state"); |
b22128ef JM |
2065 | |
2066 | /* | |
2067 | * We do not really have a specific BSS that this frame is advertising, | |
2068 | * so build a frame that has some information in valid format. This is | |
2069 | * really only used for discovery purposes, not to learn exact BSS | |
2070 | * parameters. | |
2071 | */ | |
2072 | ies = p2p_build_probe_resp_ies(p2p); | |
2073 | if (ies == NULL) | |
2d43d37f | 2074 | return P2P_PREQ_NOT_PROCESSED; |
b22128ef JM |
2075 | |
2076 | buf = wpabuf_alloc(200 + wpabuf_len(ies)); | |
2077 | if (buf == NULL) { | |
2078 | wpabuf_free(ies); | |
2d43d37f | 2079 | return P2P_PREQ_NOT_PROCESSED; |
b22128ef JM |
2080 | } |
2081 | ||
2082 | resp = NULL; | |
2083 | resp = wpabuf_put(buf, resp->u.probe_resp.variable - (u8 *) resp); | |
2084 | ||
2085 | resp->frame_control = host_to_le16((WLAN_FC_TYPE_MGMT << 2) | | |
2086 | (WLAN_FC_STYPE_PROBE_RESP << 4)); | |
2087 | os_memcpy(resp->da, addr, ETH_ALEN); | |
2088 | os_memcpy(resp->sa, p2p->cfg->dev_addr, ETH_ALEN); | |
2089 | os_memcpy(resp->bssid, p2p->cfg->dev_addr, ETH_ALEN); | |
2090 | resp->u.probe_resp.beacon_int = host_to_le16(100); | |
2091 | /* hardware or low-level driver will setup seq_ctrl and timestamp */ | |
2092 | resp->u.probe_resp.capab_info = | |
2093 | host_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE | | |
2094 | WLAN_CAPABILITY_PRIVACY | | |
2095 | WLAN_CAPABILITY_SHORT_SLOT_TIME); | |
2096 | ||
2097 | wpabuf_put_u8(buf, WLAN_EID_SSID); | |
2098 | wpabuf_put_u8(buf, P2P_WILDCARD_SSID_LEN); | |
2099 | wpabuf_put_data(buf, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN); | |
2100 | ||
2101 | wpabuf_put_u8(buf, WLAN_EID_SUPP_RATES); | |
2102 | wpabuf_put_u8(buf, 8); | |
2103 | wpabuf_put_u8(buf, (60 / 5) | 0x80); | |
2104 | wpabuf_put_u8(buf, 90 / 5); | |
2105 | wpabuf_put_u8(buf, (120 / 5) | 0x80); | |
2106 | wpabuf_put_u8(buf, 180 / 5); | |
2107 | wpabuf_put_u8(buf, (240 / 5) | 0x80); | |
2108 | wpabuf_put_u8(buf, 360 / 5); | |
2109 | wpabuf_put_u8(buf, 480 / 5); | |
2110 | wpabuf_put_u8(buf, 540 / 5); | |
2111 | ||
2112 | wpabuf_put_u8(buf, WLAN_EID_DS_PARAMS); | |
2113 | wpabuf_put_u8(buf, 1); | |
2114 | wpabuf_put_u8(buf, p2p->cfg->channel); | |
2115 | ||
2116 | wpabuf_put_buf(buf, ies); | |
2117 | wpabuf_free(ies); | |
2118 | ||
2119 | p2p->cfg->send_probe_resp(p2p->cfg->cb_ctx, buf); | |
2120 | ||
2121 | wpabuf_free(buf); | |
2d43d37f JB |
2122 | |
2123 | return P2P_PREQ_NOT_PROCESSED; | |
b22128ef JM |
2124 | } |
2125 | ||
2126 | ||
2d43d37f JB |
2127 | enum p2p_probe_req_status |
2128 | p2p_probe_req_rx(struct p2p_data *p2p, const u8 *addr, const u8 *dst, | |
2129 | const u8 *bssid, const u8 *ie, size_t ie_len) | |
b22128ef | 2130 | { |
2d43d37f JB |
2131 | enum p2p_probe_req_status res; |
2132 | ||
b22128ef JM |
2133 | p2p_add_dev_from_probe_req(p2p, addr, ie, ie_len); |
2134 | ||
2d43d37f | 2135 | res = p2p_reply_probe(p2p, addr, dst, bssid, ie, ie_len); |
b22128ef JM |
2136 | |
2137 | if ((p2p->state == P2P_CONNECT || p2p->state == P2P_CONNECT_LISTEN) && | |
2138 | p2p->go_neg_peer && | |
c5db8e51 | 2139 | os_memcmp(addr, p2p->go_neg_peer->info.p2p_device_addr, ETH_ALEN) |
c03e2113 JM |
2140 | == 0 && |
2141 | !(p2p->go_neg_peer->flags & P2P_DEV_WAIT_GO_NEG_CONFIRM)) { | |
b22128ef | 2142 | /* Received a Probe Request from GO Negotiation peer */ |
ed496f13 | 2143 | p2p_dbg(p2p, "Found GO Negotiation peer - try to start GO negotiation from timeout"); |
8cee87ab | 2144 | eloop_cancel_timeout(p2p_go_neg_start, p2p, NULL); |
b22128ef | 2145 | eloop_register_timeout(0, 0, p2p_go_neg_start, p2p, NULL); |
2d43d37f | 2146 | return P2P_PREQ_PROCESSED; |
b22128ef JM |
2147 | } |
2148 | ||
2149 | if ((p2p->state == P2P_INVITE || p2p->state == P2P_INVITE_LISTEN) && | |
2150 | p2p->invite_peer && | |
a05e236b | 2151 | (p2p->invite_peer->flags & P2P_DEV_WAIT_INV_REQ_ACK) && |
c5db8e51 KRK |
2152 | os_memcmp(addr, p2p->invite_peer->info.p2p_device_addr, ETH_ALEN) |
2153 | == 0) { | |
b22128ef | 2154 | /* Received a Probe Request from Invite peer */ |
ed496f13 | 2155 | p2p_dbg(p2p, "Found Invite peer - try to start Invite from timeout"); |
aef5047a | 2156 | eloop_cancel_timeout(p2p_invite_start, p2p, NULL); |
b22128ef | 2157 | eloop_register_timeout(0, 0, p2p_invite_start, p2p, NULL); |
2d43d37f | 2158 | return P2P_PREQ_PROCESSED; |
b22128ef JM |
2159 | } |
2160 | ||
2d43d37f | 2161 | return res; |
b22128ef JM |
2162 | } |
2163 | ||
2164 | ||
2165 | static int p2p_assoc_req_ie_wlan_ap(struct p2p_data *p2p, const u8 *bssid, | |
4c08c0bd | 2166 | u8 *buf, size_t len, struct wpabuf *p2p_ie) |
b22128ef JM |
2167 | { |
2168 | struct wpabuf *tmp; | |
2169 | u8 *lpos; | |
2170 | size_t tmplen; | |
2171 | int res; | |
72044390 | 2172 | u8 group_capab; |
b22128ef | 2173 | |
4c08c0bd JM |
2174 | if (p2p_ie == NULL) |
2175 | return 0; /* WLAN AP is not a P2P manager */ | |
b22128ef JM |
2176 | |
2177 | /* | |
2178 | * (Re)Association Request - P2P IE | |
2179 | * P2P Capability attribute (shall be present) | |
4c08c0bd JM |
2180 | * P2P Interface attribute (present if concurrent device and |
2181 | * P2P Management is enabled) | |
b22128ef JM |
2182 | */ |
2183 | tmp = wpabuf_alloc(200); | |
2184 | if (tmp == NULL) | |
2185 | return -1; | |
2186 | ||
2187 | lpos = p2p_buf_add_ie_hdr(tmp); | |
72044390 JM |
2188 | group_capab = 0; |
2189 | if (p2p->num_groups > 0) { | |
2190 | group_capab |= P2P_GROUP_CAPAB_GROUP_OWNER; | |
2191 | if ((p2p->dev_capab & P2P_DEV_CAPAB_CONCURRENT_OPER) && | |
2192 | (p2p->dev_capab & P2P_DEV_CAPAB_INFRA_MANAGED) && | |
2193 | p2p->cross_connect) | |
2194 | group_capab |= P2P_GROUP_CAPAB_CROSS_CONN; | |
2195 | } | |
2196 | p2p_buf_add_capability(tmp, p2p->dev_capab, group_capab); | |
4c08c0bd JM |
2197 | if ((p2p->dev_capab & P2P_DEV_CAPAB_CONCURRENT_OPER) && |
2198 | (p2p->dev_capab & P2P_DEV_CAPAB_INFRA_MANAGED)) | |
b22128ef JM |
2199 | p2p_buf_add_p2p_interface(tmp, p2p); |
2200 | p2p_buf_update_ie_hdr(tmp, lpos); | |
2201 | ||
2202 | tmplen = wpabuf_len(tmp); | |
2203 | if (tmplen > len) | |
2204 | res = -1; | |
2205 | else { | |
2206 | os_memcpy(buf, wpabuf_head(tmp), tmplen); | |
2207 | res = tmplen; | |
2208 | } | |
2209 | wpabuf_free(tmp); | |
2210 | ||
2211 | return res; | |
2212 | } | |
2213 | ||
2214 | ||
2215 | int p2p_assoc_req_ie(struct p2p_data *p2p, const u8 *bssid, u8 *buf, | |
4c08c0bd | 2216 | size_t len, int p2p_group, struct wpabuf *p2p_ie) |
b22128ef JM |
2217 | { |
2218 | struct wpabuf *tmp; | |
2219 | u8 *lpos; | |
2220 | struct p2p_device *peer; | |
2221 | size_t tmplen; | |
2222 | int res; | |
9675ce35 | 2223 | size_t extra = 0; |
b22128ef JM |
2224 | |
2225 | if (!p2p_group) | |
4c08c0bd | 2226 | return p2p_assoc_req_ie_wlan_ap(p2p, bssid, buf, len, p2p_ie); |
b22128ef | 2227 | |
9675ce35 JM |
2228 | #ifdef CONFIG_WIFI_DISPLAY |
2229 | if (p2p->wfd_ie_assoc_req) | |
2230 | extra = wpabuf_len(p2p->wfd_ie_assoc_req); | |
2231 | #endif /* CONFIG_WIFI_DISPLAY */ | |
2232 | ||
b22128ef JM |
2233 | /* |
2234 | * (Re)Association Request - P2P IE | |
2235 | * P2P Capability attribute (shall be present) | |
2236 | * Extended Listen Timing (may be present) | |
2237 | * P2P Device Info attribute (shall be present) | |
2238 | */ | |
9675ce35 | 2239 | tmp = wpabuf_alloc(200 + extra); |
b22128ef JM |
2240 | if (tmp == NULL) |
2241 | return -1; | |
2242 | ||
9675ce35 JM |
2243 | #ifdef CONFIG_WIFI_DISPLAY |
2244 | if (p2p->wfd_ie_assoc_req) | |
2245 | wpabuf_put_buf(tmp, p2p->wfd_ie_assoc_req); | |
2246 | #endif /* CONFIG_WIFI_DISPLAY */ | |
2247 | ||
b22128ef JM |
2248 | peer = bssid ? p2p_get_device(p2p, bssid) : NULL; |
2249 | ||
2250 | lpos = p2p_buf_add_ie_hdr(tmp); | |
2251 | p2p_buf_add_capability(tmp, p2p->dev_capab, 0); | |
5be5305b JM |
2252 | if (p2p->ext_listen_interval) |
2253 | p2p_buf_add_ext_listen_timing(tmp, p2p->ext_listen_period, | |
2254 | p2p->ext_listen_interval); | |
b22128ef JM |
2255 | p2p_buf_add_device_info(tmp, p2p, peer); |
2256 | p2p_buf_update_ie_hdr(tmp, lpos); | |
2257 | ||
2258 | tmplen = wpabuf_len(tmp); | |
2259 | if (tmplen > len) | |
2260 | res = -1; | |
2261 | else { | |
2262 | os_memcpy(buf, wpabuf_head(tmp), tmplen); | |
2263 | res = tmplen; | |
2264 | } | |
2265 | wpabuf_free(tmp); | |
2266 | ||
2267 | return res; | |
2268 | } | |
2269 | ||
2270 | ||
2271 | int p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf, char *end) | |
2272 | { | |
2273 | struct wpabuf *p2p_ie; | |
2274 | int ret; | |
2275 | ||
2276 | p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len, P2P_IE_VENDOR_TYPE); | |
2277 | if (p2p_ie == NULL) | |
2278 | return 0; | |
2279 | ||
2280 | ret = p2p_attr_text(p2p_ie, buf, end); | |
2281 | wpabuf_free(p2p_ie); | |
2282 | return ret; | |
2283 | } | |
2284 | ||
2285 | ||
c2d76aa6 | 2286 | int p2p_parse_dev_addr_in_p2p_ie(struct wpabuf *p2p_ie, u8 *dev_addr) |
0a70f34f | 2287 | { |
0a70f34f JM |
2288 | struct p2p_message msg; |
2289 | ||
0a70f34f | 2290 | os_memset(&msg, 0, sizeof(msg)); |
c2d76aa6 | 2291 | if (p2p_parse_p2p_ie(p2p_ie, &msg)) |
0a70f34f | 2292 | return -1; |
0a70f34f | 2293 | |
526ec4ae JM |
2294 | if (msg.p2p_device_addr) { |
2295 | os_memcpy(dev_addr, msg.p2p_device_addr, ETH_ALEN); | |
c2d76aa6 | 2296 | return 0; |
526ec4ae JM |
2297 | } else if (msg.device_id) { |
2298 | os_memcpy(dev_addr, msg.device_id, ETH_ALEN); | |
c2d76aa6 | 2299 | return 0; |
0a70f34f | 2300 | } |
c2d76aa6 MH |
2301 | return -1; |
2302 | } | |
0a70f34f | 2303 | |
c2d76aa6 MH |
2304 | |
2305 | int p2p_parse_dev_addr(const u8 *ies, size_t ies_len, u8 *dev_addr) | |
2306 | { | |
2307 | struct wpabuf *p2p_ie; | |
2308 | int ret; | |
2309 | ||
2310 | p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len, | |
2311 | P2P_IE_VENDOR_TYPE); | |
2312 | if (p2p_ie == NULL) | |
2313 | return -1; | |
2314 | ret = p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr); | |
0a70f34f | 2315 | wpabuf_free(p2p_ie); |
526ec4ae | 2316 | return ret; |
0a70f34f JM |
2317 | } |
2318 | ||
2319 | ||
b22128ef JM |
2320 | static void p2p_clear_go_neg(struct p2p_data *p2p) |
2321 | { | |
2322 | p2p->go_neg_peer = NULL; | |
2323 | p2p_clear_timeout(p2p); | |
2324 | p2p_set_state(p2p, P2P_IDLE); | |
2325 | } | |
2326 | ||
2327 | ||
2328 | void p2p_wps_success_cb(struct p2p_data *p2p, const u8 *mac_addr) | |
2329 | { | |
2330 | if (p2p->go_neg_peer == NULL) { | |
ed496f13 | 2331 | p2p_dbg(p2p, "No pending Group Formation - ignore WPS registration success notification"); |
b22128ef JM |
2332 | return; /* No pending Group Formation */ |
2333 | } | |
2334 | ||
2335 | if (os_memcmp(mac_addr, p2p->go_neg_peer->intended_addr, ETH_ALEN) != | |
2336 | 0) { | |
ed496f13 JM |
2337 | p2p_dbg(p2p, "Ignore WPS registration success notification for " |
2338 | MACSTR " (GO Negotiation peer " MACSTR ")", | |
b22128ef JM |
2339 | MAC2STR(mac_addr), |
2340 | MAC2STR(p2p->go_neg_peer->intended_addr)); | |
2341 | return; /* Ignore unexpected peer address */ | |
2342 | } | |
2343 | ||
ed496f13 | 2344 | p2p_dbg(p2p, "Group Formation completed successfully with " MACSTR, |
b22128ef JM |
2345 | MAC2STR(mac_addr)); |
2346 | ||
2347 | p2p_clear_go_neg(p2p); | |
2348 | } | |
2349 | ||
2350 | ||
2351 | void p2p_group_formation_failed(struct p2p_data *p2p) | |
2352 | { | |
2353 | if (p2p->go_neg_peer == NULL) { | |
ed496f13 | 2354 | p2p_dbg(p2p, "No pending Group Formation - ignore group formation failure notification"); |
b22128ef JM |
2355 | return; /* No pending Group Formation */ |
2356 | } | |
2357 | ||
ed496f13 | 2358 | p2p_dbg(p2p, "Group Formation failed with " MACSTR, |
b22128ef JM |
2359 | MAC2STR(p2p->go_neg_peer->intended_addr)); |
2360 | ||
2361 | p2p_clear_go_neg(p2p); | |
2362 | } | |
2363 | ||
2364 | ||
2365 | struct p2p_data * p2p_init(const struct p2p_config *cfg) | |
2366 | { | |
2367 | struct p2p_data *p2p; | |
2368 | ||
2369 | if (cfg->max_peers < 1) | |
2370 | return NULL; | |
2371 | ||
2372 | p2p = os_zalloc(sizeof(*p2p) + sizeof(*cfg)); | |
2373 | if (p2p == NULL) | |
2374 | return NULL; | |
2375 | p2p->cfg = (struct p2p_config *) (p2p + 1); | |
2376 | os_memcpy(p2p->cfg, cfg, sizeof(*cfg)); | |
2377 | if (cfg->dev_name) | |
2378 | p2p->cfg->dev_name = os_strdup(cfg->dev_name); | |
b6e01800 JM |
2379 | if (cfg->manufacturer) |
2380 | p2p->cfg->manufacturer = os_strdup(cfg->manufacturer); | |
2381 | if (cfg->model_name) | |
2382 | p2p->cfg->model_name = os_strdup(cfg->model_name); | |
2383 | if (cfg->model_number) | |
2384 | p2p->cfg->model_number = os_strdup(cfg->model_number); | |
2385 | if (cfg->serial_number) | |
2386 | p2p->cfg->serial_number = os_strdup(cfg->serial_number); | |
21d996f7 JM |
2387 | if (cfg->pref_chan) { |
2388 | p2p->cfg->pref_chan = os_malloc(cfg->num_pref_chan * | |
2389 | sizeof(struct p2p_channel)); | |
2390 | if (p2p->cfg->pref_chan) { | |
2391 | os_memcpy(p2p->cfg->pref_chan, cfg->pref_chan, | |
2392 | cfg->num_pref_chan * | |
2393 | sizeof(struct p2p_channel)); | |
2394 | } else | |
2395 | p2p->cfg->num_pref_chan = 0; | |
2396 | } | |
b22128ef JM |
2397 | |
2398 | p2p->min_disc_int = 1; | |
2399 | p2p->max_disc_int = 3; | |
96beff11 | 2400 | p2p->max_disc_tu = -1; |
b22128ef JM |
2401 | |
2402 | os_get_random(&p2p->next_tie_breaker, 1); | |
2403 | p2p->next_tie_breaker &= 0x01; | |
2404 | if (cfg->sd_request) | |
2405 | p2p->dev_capab |= P2P_DEV_CAPAB_SERVICE_DISCOVERY; | |
2406 | p2p->dev_capab |= P2P_DEV_CAPAB_INVITATION_PROCEDURE; | |
2407 | if (cfg->concurrent_operations) | |
2408 | p2p->dev_capab |= P2P_DEV_CAPAB_CONCURRENT_OPER; | |
2409 | p2p->dev_capab |= P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY; | |
2410 | ||
2411 | dl_list_init(&p2p->devices); | |
2412 | ||
2413 | eloop_register_timeout(P2P_PEER_EXPIRATION_INTERVAL, 0, | |
2414 | p2p_expiration_timeout, p2p, NULL); | |
2415 | ||
4f219667 JM |
2416 | p2p->go_timeout = 100; |
2417 | p2p->client_timeout = 20; | |
f667e031 | 2418 | p2p->num_p2p_sd_queries = 0; |
4f219667 | 2419 | |
51e9f228 JM |
2420 | p2p_dbg(p2p, "initialized"); |
2421 | p2p_channels_dump(p2p, "channels", &p2p->cfg->channels); | |
2422 | p2p_channels_dump(p2p, "cli_channels", &p2p->cfg->cli_channels); | |
2423 | ||
b22128ef JM |
2424 | return p2p; |
2425 | } | |
2426 | ||
2427 | ||
2428 | void p2p_deinit(struct p2p_data *p2p) | |
2429 | { | |
9675ce35 JM |
2430 | #ifdef CONFIG_WIFI_DISPLAY |
2431 | wpabuf_free(p2p->wfd_ie_beacon); | |
2432 | wpabuf_free(p2p->wfd_ie_probe_req); | |
2433 | wpabuf_free(p2p->wfd_ie_probe_resp); | |
2434 | wpabuf_free(p2p->wfd_ie_assoc_req); | |
2435 | wpabuf_free(p2p->wfd_ie_invitation); | |
2436 | wpabuf_free(p2p->wfd_ie_prov_disc_req); | |
2437 | wpabuf_free(p2p->wfd_ie_prov_disc_resp); | |
2438 | wpabuf_free(p2p->wfd_ie_go_neg); | |
2439 | wpabuf_free(p2p->wfd_dev_info); | |
2440 | wpabuf_free(p2p->wfd_assoc_bssid); | |
2441 | wpabuf_free(p2p->wfd_coupled_sink_info); | |
2442 | #endif /* CONFIG_WIFI_DISPLAY */ | |
2443 | ||
b22128ef JM |
2444 | eloop_cancel_timeout(p2p_expiration_timeout, p2p, NULL); |
2445 | eloop_cancel_timeout(p2p_ext_listen_timeout, p2p, NULL); | |
2446 | eloop_cancel_timeout(p2p_scan_timeout, p2p, NULL); | |
8cee87ab | 2447 | eloop_cancel_timeout(p2p_go_neg_start, p2p, NULL); |
b22128ef | 2448 | p2p_flush(p2p); |
046ef4aa | 2449 | p2p_free_req_dev_types(p2p); |
b22128ef | 2450 | os_free(p2p->cfg->dev_name); |
b6e01800 JM |
2451 | os_free(p2p->cfg->manufacturer); |
2452 | os_free(p2p->cfg->model_name); | |
2453 | os_free(p2p->cfg->model_number); | |
2454 | os_free(p2p->cfg->serial_number); | |
21d996f7 | 2455 | os_free(p2p->cfg->pref_chan); |
b22128ef | 2456 | os_free(p2p->groups); |
18708aad | 2457 | wpabuf_free(p2p->sd_resp); |
3f9285ff | 2458 | os_free(p2p->after_scan_tx); |
f95cac27 | 2459 | p2p_remove_wps_vendor_extensions(p2p); |
556b30da | 2460 | os_free(p2p->no_go_freq.range); |
b22128ef JM |
2461 | os_free(p2p); |
2462 | } | |
2463 | ||
2464 | ||
2465 | void p2p_flush(struct p2p_data *p2p) | |
2466 | { | |
2467 | struct p2p_device *dev, *prev; | |
78db55b8 | 2468 | p2p_stop_find(p2p); |
b22128ef JM |
2469 | dl_list_for_each_safe(dev, prev, &p2p->devices, struct p2p_device, |
2470 | list) { | |
2471 | dl_list_del(&dev->list); | |
2472 | p2p_device_free(p2p, dev); | |
2473 | } | |
2474 | p2p_free_sd_queries(p2p); | |
f44ae207 JM |
2475 | os_free(p2p->after_scan_tx); |
2476 | p2p->after_scan_tx = NULL; | |
b22128ef JM |
2477 | } |
2478 | ||
2479 | ||
9d562b79 SS |
2480 | int p2p_unauthorize(struct p2p_data *p2p, const u8 *addr) |
2481 | { | |
2482 | struct p2p_device *dev; | |
2483 | ||
2484 | dev = p2p_get_device(p2p, addr); | |
2485 | if (dev == NULL) | |
2486 | return -1; | |
2487 | ||
ed496f13 | 2488 | p2p_dbg(p2p, "Unauthorizing " MACSTR, MAC2STR(addr)); |
9d562b79 SS |
2489 | |
2490 | if (p2p->go_neg_peer == dev) | |
2491 | p2p->go_neg_peer = NULL; | |
2492 | ||
2493 | dev->wps_method = WPS_NOT_READY; | |
ab9e3442 | 2494 | dev->oob_pw_id = 0; |
9d562b79 SS |
2495 | dev->flags &= ~P2P_DEV_WAIT_GO_NEG_RESPONSE; |
2496 | dev->flags &= ~P2P_DEV_WAIT_GO_NEG_CONFIRM; | |
2497 | ||
2498 | /* Check if after_scan_tx is for this peer. If so free it */ | |
2499 | if (p2p->after_scan_tx && | |
2500 | os_memcmp(addr, p2p->after_scan_tx->dst, ETH_ALEN) == 0) { | |
2501 | os_free(p2p->after_scan_tx); | |
2502 | p2p->after_scan_tx = NULL; | |
2503 | } | |
2504 | ||
2505 | return 0; | |
2506 | } | |
2507 | ||
2508 | ||
b22128ef JM |
2509 | int p2p_set_dev_name(struct p2p_data *p2p, const char *dev_name) |
2510 | { | |
2511 | os_free(p2p->cfg->dev_name); | |
2512 | if (dev_name) { | |
2513 | p2p->cfg->dev_name = os_strdup(dev_name); | |
2514 | if (p2p->cfg->dev_name == NULL) | |
2515 | return -1; | |
2516 | } else | |
2517 | p2p->cfg->dev_name = NULL; | |
2518 | return 0; | |
2519 | } | |
2520 | ||
2521 | ||
b6e01800 JM |
2522 | int p2p_set_manufacturer(struct p2p_data *p2p, const char *manufacturer) |
2523 | { | |
2524 | os_free(p2p->cfg->manufacturer); | |
2525 | p2p->cfg->manufacturer = NULL; | |
2526 | if (manufacturer) { | |
2527 | p2p->cfg->manufacturer = os_strdup(manufacturer); | |
2528 | if (p2p->cfg->manufacturer == NULL) | |
2529 | return -1; | |
2530 | } | |
2531 | ||
2532 | return 0; | |
2533 | } | |
2534 | ||
2535 | ||
2536 | int p2p_set_model_name(struct p2p_data *p2p, const char *model_name) | |
2537 | { | |
2538 | os_free(p2p->cfg->model_name); | |
2539 | p2p->cfg->model_name = NULL; | |
2540 | if (model_name) { | |
2541 | p2p->cfg->model_name = os_strdup(model_name); | |
2542 | if (p2p->cfg->model_name == NULL) | |
2543 | return -1; | |
2544 | } | |
2545 | ||
2546 | return 0; | |
2547 | } | |
2548 | ||
2549 | ||
2550 | int p2p_set_model_number(struct p2p_data *p2p, const char *model_number) | |
2551 | { | |
2552 | os_free(p2p->cfg->model_number); | |
2553 | p2p->cfg->model_number = NULL; | |
2554 | if (model_number) { | |
2555 | p2p->cfg->model_number = os_strdup(model_number); | |
2556 | if (p2p->cfg->model_number == NULL) | |
2557 | return -1; | |
2558 | } | |
2559 | ||
2560 | return 0; | |
2561 | } | |
2562 | ||
2563 | ||
2564 | int p2p_set_serial_number(struct p2p_data *p2p, const char *serial_number) | |
2565 | { | |
2566 | os_free(p2p->cfg->serial_number); | |
2567 | p2p->cfg->serial_number = NULL; | |
2568 | if (serial_number) { | |
2569 | p2p->cfg->serial_number = os_strdup(serial_number); | |
2570 | if (p2p->cfg->serial_number == NULL) | |
2571 | return -1; | |
2572 | } | |
2573 | ||
2574 | return 0; | |
2575 | } | |
2576 | ||
2577 | ||
2578 | void p2p_set_config_methods(struct p2p_data *p2p, u16 config_methods) | |
2579 | { | |
2580 | p2p->cfg->config_methods = config_methods; | |
2581 | } | |
2582 | ||
2583 | ||
2584 | void p2p_set_uuid(struct p2p_data *p2p, const u8 *uuid) | |
2585 | { | |
2586 | os_memcpy(p2p->cfg->uuid, uuid, 16); | |
2587 | } | |
2588 | ||
2589 | ||
b22128ef JM |
2590 | int p2p_set_pri_dev_type(struct p2p_data *p2p, const u8 *pri_dev_type) |
2591 | { | |
2592 | os_memcpy(p2p->cfg->pri_dev_type, pri_dev_type, 8); | |
2593 | return 0; | |
2594 | } | |
2595 | ||
2596 | ||
2597 | int p2p_set_sec_dev_types(struct p2p_data *p2p, const u8 dev_types[][8], | |
2598 | size_t num_dev_types) | |
2599 | { | |
2600 | if (num_dev_types > P2P_SEC_DEVICE_TYPES) | |
2601 | num_dev_types = P2P_SEC_DEVICE_TYPES; | |
2602 | p2p->cfg->num_sec_dev_types = num_dev_types; | |
2603 | os_memcpy(p2p->cfg->sec_dev_type, dev_types, num_dev_types * 8); | |
2604 | return 0; | |
2605 | } | |
2606 | ||
2607 | ||
f95cac27 JMB |
2608 | void p2p_remove_wps_vendor_extensions(struct p2p_data *p2p) |
2609 | { | |
2610 | int i; | |
2611 | ||
10c5d2a5 | 2612 | for (i = 0; i < P2P_MAX_WPS_VENDOR_EXT; i++) { |
f95cac27 JMB |
2613 | wpabuf_free(p2p->wps_vendor_ext[i]); |
2614 | p2p->wps_vendor_ext[i] = NULL; | |
2615 | } | |
2616 | } | |
2617 | ||
2618 | ||
2619 | int p2p_add_wps_vendor_extension(struct p2p_data *p2p, | |
2620 | const struct wpabuf *vendor_ext) | |
2621 | { | |
2622 | int i; | |
2623 | ||
2624 | if (vendor_ext == NULL) | |
2625 | return -1; | |
2626 | ||
10c5d2a5 | 2627 | for (i = 0; i < P2P_MAX_WPS_VENDOR_EXT; i++) { |
f95cac27 JMB |
2628 | if (p2p->wps_vendor_ext[i] == NULL) |
2629 | break; | |
2630 | } | |
10c5d2a5 | 2631 | if (i >= P2P_MAX_WPS_VENDOR_EXT) |
f95cac27 JMB |
2632 | return -1; |
2633 | ||
2634 | p2p->wps_vendor_ext[i] = wpabuf_dup(vendor_ext); | |
2635 | if (p2p->wps_vendor_ext[i] == NULL) | |
2636 | return -1; | |
2637 | ||
2638 | return 0; | |
2639 | } | |
2640 | ||
2641 | ||
b22128ef JM |
2642 | int p2p_set_country(struct p2p_data *p2p, const char *country) |
2643 | { | |
2644 | os_memcpy(p2p->cfg->country, country, 3); | |
2645 | return 0; | |
2646 | } | |
2647 | ||
2648 | ||
2649 | void p2p_continue_find(struct p2p_data *p2p) | |
2650 | { | |
2651 | struct p2p_device *dev; | |
2652 | p2p_set_state(p2p, P2P_SEARCH); | |
2653 | dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) { | |
f667e031 JJ |
2654 | if (dev->sd_pending_bcast_queries == 0) { |
2655 | /* Initialize with total number of registered broadcast | |
2656 | * SD queries. */ | |
2657 | dev->sd_pending_bcast_queries = p2p->num_p2p_sd_queries; | |
2658 | } | |
2659 | ||
2660 | if (p2p_start_sd(p2p, dev) == 0) | |
2661 | return; | |
2662 | if (dev->req_config_methods && | |
2663 | !(dev->flags & P2P_DEV_PD_FOR_JOIN)) { | |
ed496f13 | 2664 | p2p_dbg(p2p, "Send pending Provision Discovery Request to " |
10c4edde | 2665 | MACSTR " (config methods 0x%x)", |
c5db8e51 | 2666 | MAC2STR(dev->info.p2p_device_addr), |
10c4edde | 2667 | dev->req_config_methods); |
1ef2f7ff | 2668 | if (p2p_send_prov_disc_req(p2p, dev, 0, 0) == 0) |
b22128ef JM |
2669 | return; |
2670 | } | |
2671 | } | |
2672 | ||
96beff11 | 2673 | p2p_listen_in_find(p2p, 1); |
b22128ef JM |
2674 | } |
2675 | ||
2676 | ||
2677 | static void p2p_sd_cb(struct p2p_data *p2p, int success) | |
2678 | { | |
ed496f13 | 2679 | p2p_dbg(p2p, "Service Discovery Query TX callback: success=%d", |
b22128ef JM |
2680 | success); |
2681 | p2p->pending_action_state = P2P_NO_PENDING_ACTION; | |
2682 | ||
2683 | if (!success) { | |
f667e031 | 2684 | p2p->sd_peer = NULL; |
b22128ef JM |
2685 | p2p_continue_find(p2p); |
2686 | return; | |
2687 | } | |
2688 | ||
2689 | if (p2p->sd_peer == NULL) { | |
ed496f13 | 2690 | p2p_dbg(p2p, "No SD peer entry known"); |
b22128ef JM |
2691 | p2p_continue_find(p2p); |
2692 | return; | |
2693 | } | |
2694 | ||
2695 | /* Wait for response from the peer */ | |
2696 | p2p_set_state(p2p, P2P_SD_DURING_FIND); | |
2697 | p2p_set_timeout(p2p, 0, 200000); | |
2698 | } | |
2699 | ||
6b56cc2d JS |
2700 | |
2701 | /** | |
2702 | * p2p_retry_pd - Retry any pending provision disc requests in IDLE state | |
2703 | * @p2p: P2P module context from p2p_init() | |
2704 | */ | |
19df9b07 | 2705 | static void p2p_retry_pd(struct p2p_data *p2p) |
6b56cc2d JS |
2706 | { |
2707 | struct p2p_device *dev; | |
2708 | ||
2709 | if (p2p->state != P2P_IDLE) | |
2710 | return; | |
2711 | ||
2712 | /* | |
2713 | * Retry the prov disc req attempt only for the peer that the user had | |
175171ac | 2714 | * requested. |
6b56cc2d JS |
2715 | */ |
2716 | ||
2717 | dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) { | |
2718 | if (os_memcmp(p2p->pending_pd_devaddr, | |
2719 | dev->info.p2p_device_addr, ETH_ALEN) != 0) | |
2720 | continue; | |
2721 | if (!dev->req_config_methods) | |
2722 | continue; | |
6b56cc2d | 2723 | |
ed496f13 | 2724 | p2p_dbg(p2p, "Send pending Provision Discovery Request to " |
6b56cc2d JS |
2725 | MACSTR " (config methods 0x%x)", |
2726 | MAC2STR(dev->info.p2p_device_addr), | |
2727 | dev->req_config_methods); | |
175171ac | 2728 | p2p_send_prov_disc_req(p2p, dev, |
8d82c210 JM |
2729 | dev->flags & P2P_DEV_PD_FOR_JOIN, |
2730 | p2p->pd_force_freq); | |
6b56cc2d JS |
2731 | return; |
2732 | } | |
2733 | } | |
2734 | ||
2735 | ||
b22128ef JM |
2736 | static void p2p_prov_disc_cb(struct p2p_data *p2p, int success) |
2737 | { | |
ed496f13 | 2738 | p2p_dbg(p2p, "Provision Discovery Request TX callback: success=%d", |
b22128ef | 2739 | success); |
6b56cc2d JS |
2740 | |
2741 | /* | |
2742 | * Postpone resetting the pending action state till after we actually | |
2743 | * time out. This allows us to take some action like notifying any | |
2744 | * interested parties about no response to the request. | |
2745 | * | |
2746 | * When the timer (below) goes off we check in IDLE, SEARCH, or | |
2747 | * LISTEN_ONLY state, which are the only allowed states to issue a PD | |
2748 | * requests in, if this was still pending and then raise notification. | |
2749 | */ | |
b22128ef JM |
2750 | |
2751 | if (!success) { | |
6b56cc2d JS |
2752 | p2p->pending_action_state = P2P_NO_PENDING_ACTION; |
2753 | ||
488f4a71 JM |
2754 | if (p2p->user_initiated_pd && |
2755 | (p2p->state == P2P_SEARCH || p2p->state == P2P_LISTEN_ONLY)) | |
2756 | { | |
2757 | /* Retry request from timeout to avoid busy loops */ | |
2758 | p2p->pending_action_state = P2P_PENDING_PD; | |
2759 | p2p_set_timeout(p2p, 0, 50000); | |
2760 | } else if (p2p->state != P2P_IDLE) | |
b22128ef | 2761 | p2p_continue_find(p2p); |
6b56cc2d JS |
2762 | else if (p2p->user_initiated_pd) { |
2763 | p2p->pending_action_state = P2P_PENDING_PD; | |
2764 | p2p_set_timeout(p2p, 0, 300000); | |
2765 | } | |
b22128ef JM |
2766 | return; |
2767 | } | |
2768 | ||
6b56cc2d JS |
2769 | /* |
2770 | * This postponing, of resetting pending_action_state, needs to be | |
2771 | * done only for user initiated PD requests and not internal ones. | |
2772 | */ | |
2773 | if (p2p->user_initiated_pd) | |
2774 | p2p->pending_action_state = P2P_PENDING_PD; | |
2775 | else | |
2776 | p2p->pending_action_state = P2P_NO_PENDING_ACTION; | |
2777 | ||
b22128ef JM |
2778 | /* Wait for response from the peer */ |
2779 | if (p2p->state == P2P_SEARCH) | |
2780 | p2p_set_state(p2p, P2P_PD_DURING_FIND); | |
2781 | p2p_set_timeout(p2p, 0, 200000); | |
2782 | } | |
2783 | ||
2784 | ||
2785 | int p2p_scan_res_handler(struct p2p_data *p2p, const u8 *bssid, int freq, | |
acb69cec | 2786 | struct os_reltime *rx_time, int level, const u8 *ies, |
3dfd0484 | 2787 | size_t ies_len) |
b22128ef | 2788 | { |
acb69cec | 2789 | if (os_reltime_before(rx_time, &p2p->find_start)) { |
a5b5e830 JM |
2790 | /* |
2791 | * The driver may have cached (e.g., in cfg80211 BSS table) the | |
2792 | * scan results for relatively long time. To avoid reporting | |
2793 | * stale information, update P2P peers only based on results | |
2794 | * that have based on frames received after the last p2p_find | |
2795 | * operation was started. | |
2796 | */ | |
ed496f13 JM |
2797 | p2p_dbg(p2p, "Ignore old scan result for " MACSTR |
2798 | " (rx_time=%u.%06u)", | |
a5b5e830 JM |
2799 | MAC2STR(bssid), (unsigned int) rx_time->sec, |
2800 | (unsigned int) rx_time->usec); | |
2801 | return 0; | |
2802 | } | |
2803 | ||
c5f10e80 | 2804 | p2p_add_device(p2p, bssid, freq, rx_time, level, ies, ies_len, 1); |
b22128ef | 2805 | |
b22128ef JM |
2806 | return 0; |
2807 | } | |
2808 | ||
2809 | ||
2810 | void p2p_scan_res_handled(struct p2p_data *p2p) | |
2811 | { | |
2812 | if (!p2p->p2p_scan_running) { | |
ed496f13 | 2813 | p2p_dbg(p2p, "p2p_scan was not running, but scan results received"); |
b22128ef JM |
2814 | } |
2815 | p2p->p2p_scan_running = 0; | |
2816 | eloop_cancel_timeout(p2p_scan_timeout, p2p, NULL); | |
2817 | ||
2818 | if (p2p_run_after_scan(p2p)) | |
2819 | return; | |
2820 | if (p2p->state == P2P_SEARCH) | |
2821 | p2p_continue_find(p2p); | |
2822 | } | |
2823 | ||
2824 | ||
6d92fa6e | 2825 | void p2p_scan_ie(struct p2p_data *p2p, struct wpabuf *ies, const u8 *dev_id) |
b22128ef | 2826 | { |
9675ce35 JM |
2827 | u8 *len; |
2828 | ||
2829 | #ifdef CONFIG_WIFI_DISPLAY | |
2830 | if (p2p->wfd_ie_probe_req) | |
2831 | wpabuf_put_buf(ies, p2p->wfd_ie_probe_req); | |
2832 | #endif /* CONFIG_WIFI_DISPLAY */ | |
2833 | ||
2834 | len = p2p_buf_add_ie_hdr(ies); | |
18485b54 MH |
2835 | p2p_buf_add_capability(ies, p2p->dev_capab & |
2836 | ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY, 0); | |
6d92fa6e JM |
2837 | if (dev_id) |
2838 | p2p_buf_add_device_id(ies, dev_id); | |
b22128ef JM |
2839 | if (p2p->cfg->reg_class && p2p->cfg->channel) |
2840 | p2p_buf_add_listen_channel(ies, p2p->cfg->country, | |
2841 | p2p->cfg->reg_class, | |
2842 | p2p->cfg->channel); | |
2843 | if (p2p->ext_listen_interval) | |
2844 | p2p_buf_add_ext_listen_timing(ies, p2p->ext_listen_period, | |
2845 | p2p->ext_listen_interval); | |
2846 | /* TODO: p2p_buf_add_operating_channel() if GO */ | |
2847 | p2p_buf_update_ie_hdr(ies, len); | |
2848 | } | |
2849 | ||
2850 | ||
206e1f42 JM |
2851 | size_t p2p_scan_ie_buf_len(struct p2p_data *p2p) |
2852 | { | |
9675ce35 JM |
2853 | size_t len = 100; |
2854 | ||
2855 | #ifdef CONFIG_WIFI_DISPLAY | |
2856 | if (p2p && p2p->wfd_ie_probe_req) | |
2857 | len += wpabuf_len(p2p->wfd_ie_probe_req); | |
2858 | #endif /* CONFIG_WIFI_DISPLAY */ | |
2859 | ||
2860 | return len; | |
206e1f42 JM |
2861 | } |
2862 | ||
2863 | ||
b22128ef JM |
2864 | int p2p_ie_text(struct wpabuf *p2p_ie, char *buf, char *end) |
2865 | { | |
2866 | return p2p_attr_text(p2p_ie, buf, end); | |
2867 | } | |
2868 | ||
2869 | ||
2870 | static void p2p_go_neg_req_cb(struct p2p_data *p2p, int success) | |
2871 | { | |
2872 | struct p2p_device *dev = p2p->go_neg_peer; | |
fb8984fd | 2873 | int timeout; |
b22128ef | 2874 | |
ed496f13 | 2875 | p2p_dbg(p2p, "GO Negotiation Request TX callback: success=%d", success); |
b22128ef JM |
2876 | |
2877 | if (dev == NULL) { | |
ed496f13 | 2878 | p2p_dbg(p2p, "No pending GO Negotiation"); |
b22128ef JM |
2879 | return; |
2880 | } | |
2881 | ||
2882 | if (success) { | |
b22128ef JM |
2883 | if (dev->flags & P2P_DEV_USER_REJECTED) { |
2884 | p2p_set_state(p2p, P2P_IDLE); | |
2885 | return; | |
2886 | } | |
a1d2ab32 NKG |
2887 | } else if (dev->go_neg_req_sent) { |
2888 | /* Cancel the increment from p2p_connect_send() on failure */ | |
2889 | dev->go_neg_req_sent--; | |
b22128ef JM |
2890 | } |
2891 | ||
2892 | if (!success && | |
c5db8e51 | 2893 | (dev->info.dev_capab & P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY) && |
b22128ef | 2894 | !is_zero_ether_addr(dev->member_in_go_dev)) { |
ed496f13 | 2895 | p2p_dbg(p2p, "Peer " MACSTR " did not acknowledge request - try to use device discoverability through its GO", |
c5db8e51 | 2896 | MAC2STR(dev->info.p2p_device_addr)); |
b22128ef JM |
2897 | p2p->cfg->send_action_done(p2p->cfg->cb_ctx); |
2898 | p2p_send_dev_disc_req(p2p, dev); | |
2899 | return; | |
2900 | } | |
2901 | ||
2902 | /* | |
2903 | * Use P2P find, if needed, to find the other device from its listen | |
2904 | * channel. | |
2905 | */ | |
2906 | p2p_set_state(p2p, P2P_CONNECT); | |
fb8984fd JM |
2907 | timeout = success ? 500000 : 100000; |
2908 | if (!success && p2p->go_neg_peer && | |
2909 | (p2p->go_neg_peer->flags & P2P_DEV_PEER_WAITING_RESPONSE)) { | |
2910 | unsigned int r; | |
2911 | /* | |
2912 | * Peer is expected to wait our response and we will skip the | |
2913 | * listen phase. Add some randomness to the wait time here to | |
2914 | * make it less likely to hit cases where we could end up in | |
2915 | * sync with peer not listening. | |
2916 | */ | |
2917 | os_get_random((u8 *) &r, sizeof(r)); | |
2918 | timeout += r % 100000; | |
2919 | } | |
2920 | p2p_set_timeout(p2p, 0, timeout); | |
b22128ef JM |
2921 | } |
2922 | ||
2923 | ||
2924 | static void p2p_go_neg_resp_cb(struct p2p_data *p2p, int success) | |
2925 | { | |
ed496f13 | 2926 | p2p_dbg(p2p, "GO Negotiation Response TX callback: success=%d", |
b22128ef JM |
2927 | success); |
2928 | if (!p2p->go_neg_peer && p2p->state == P2P_PROVISIONING) { | |
ed496f13 | 2929 | p2p_dbg(p2p, "Ignore TX callback event - GO Negotiation is not running anymore"); |
b22128ef JM |
2930 | return; |
2931 | } | |
2932 | p2p_set_state(p2p, P2P_CONNECT); | |
8e4839ce | 2933 | p2p_set_timeout(p2p, 0, 500000); |
b22128ef JM |
2934 | } |
2935 | ||
2936 | ||
7800d45c JM |
2937 | static void p2p_go_neg_resp_failure_cb(struct p2p_data *p2p, int success, |
2938 | const u8 *addr) | |
b22128ef | 2939 | { |
ed496f13 | 2940 | p2p_dbg(p2p, "GO Negotiation Response (failure) TX callback: success=%d", success); |
fbe70272 JM |
2941 | if (p2p->go_neg_peer && p2p->go_neg_peer->status != P2P_SC_SUCCESS) { |
2942 | p2p_go_neg_failed(p2p, p2p->go_neg_peer, | |
2943 | p2p->go_neg_peer->status); | |
7800d45c JM |
2944 | } else if (success) { |
2945 | struct p2p_device *dev; | |
2946 | dev = p2p_get_device(p2p, addr); | |
2947 | if (dev && | |
2948 | dev->status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) | |
2949 | dev->flags |= P2P_DEV_PEER_WAITING_RESPONSE; | |
fbe70272 | 2950 | } |
b22128ef JM |
2951 | } |
2952 | ||
2953 | ||
93b7ddd0 JM |
2954 | static void p2p_go_neg_conf_cb(struct p2p_data *p2p, |
2955 | enum p2p_send_action_result result) | |
b22128ef JM |
2956 | { |
2957 | struct p2p_device *dev; | |
2958 | ||
ed496f13 | 2959 | p2p_dbg(p2p, "GO Negotiation Confirm TX callback: result=%d", result); |
93b7ddd0 | 2960 | if (result == P2P_SEND_ACTION_FAILED) { |
0e0e1e56 | 2961 | p2p->cfg->send_action_done(p2p->cfg->cb_ctx); |
93b7ddd0 JM |
2962 | p2p_go_neg_failed(p2p, p2p->go_neg_peer, -1); |
2963 | return; | |
2964 | } | |
0e0e1e56 NS |
2965 | |
2966 | dev = p2p->go_neg_peer; | |
2967 | ||
93b7ddd0 | 2968 | if (result == P2P_SEND_ACTION_NO_ACK) { |
0e0e1e56 NS |
2969 | /* |
2970 | * Retry GO Negotiation Confirmation | |
2971 | * P2P_GO_NEG_CNF_MAX_RETRY_COUNT times if we did not receive | |
2972 | * ACK for confirmation. | |
2973 | */ | |
2974 | if (dev && dev->go_neg_conf && | |
2975 | dev->go_neg_conf_sent <= P2P_GO_NEG_CNF_MAX_RETRY_COUNT) { | |
2976 | p2p_dbg(p2p, "GO Negotiation Confirm retry %d", | |
2977 | dev->go_neg_conf_sent); | |
2978 | p2p->pending_action_state = P2P_PENDING_GO_NEG_CONFIRM; | |
2979 | if (p2p_send_action(p2p, dev->go_neg_conf_freq, | |
2980 | dev->info.p2p_device_addr, | |
2981 | p2p->cfg->dev_addr, | |
2982 | dev->info.p2p_device_addr, | |
2983 | wpabuf_head(dev->go_neg_conf), | |
2984 | wpabuf_len(dev->go_neg_conf), 0) >= | |
2985 | 0) { | |
2986 | dev->go_neg_conf_sent++; | |
2987 | return; | |
2988 | } | |
2989 | p2p_dbg(p2p, "Failed to re-send Action frame"); | |
2990 | ||
2991 | /* | |
2992 | * Continue with the assumption that the first attempt | |
2993 | * went through and just the ACK frame was lost. | |
2994 | */ | |
2995 | } | |
2996 | ||
b22128ef JM |
2997 | /* |
2998 | * It looks like the TX status for GO Negotiation Confirm is | |
2999 | * often showing failure even when the peer has actually | |
3000 | * received the frame. Since the peer may change channels | |
3001 | * immediately after having received the frame, we may not see | |
3002 | * an Ack for retries, so just dropping a single frame may | |
3003 | * trigger this. To allow the group formation to succeed if the | |
3004 | * peer did indeed receive the frame, continue regardless of | |
3005 | * the TX status. | |
3006 | */ | |
ed496f13 | 3007 | p2p_dbg(p2p, "Assume GO Negotiation Confirm TX was actually received by the peer even though Ack was not reported"); |
b22128ef JM |
3008 | } |
3009 | ||
0e0e1e56 NS |
3010 | p2p->cfg->send_action_done(p2p->cfg->cb_ctx); |
3011 | ||
b22128ef JM |
3012 | if (dev == NULL) |
3013 | return; | |
3014 | ||
3015 | p2p_go_complete(p2p, dev); | |
3016 | } | |
3017 | ||
3018 | ||
3019 | void p2p_send_action_cb(struct p2p_data *p2p, unsigned int freq, const u8 *dst, | |
93b7ddd0 JM |
3020 | const u8 *src, const u8 *bssid, |
3021 | enum p2p_send_action_result result) | |
b22128ef JM |
3022 | { |
3023 | enum p2p_pending_action_state state; | |
93b7ddd0 | 3024 | int success; |
b22128ef | 3025 | |
ed496f13 | 3026 | p2p_dbg(p2p, "Action frame TX callback (state=%d freq=%u dst=" MACSTR |
93b7ddd0 | 3027 | " src=" MACSTR " bssid=" MACSTR " result=%d", |
b22128ef | 3028 | p2p->pending_action_state, freq, MAC2STR(dst), MAC2STR(src), |
93b7ddd0 JM |
3029 | MAC2STR(bssid), result); |
3030 | success = result == P2P_SEND_ACTION_SUCCESS; | |
b22128ef JM |
3031 | state = p2p->pending_action_state; |
3032 | p2p->pending_action_state = P2P_NO_PENDING_ACTION; | |
3033 | switch (state) { | |
3034 | case P2P_NO_PENDING_ACTION: | |
c5c2d942 JM |
3035 | if (p2p->send_action_in_progress) { |
3036 | p2p->send_action_in_progress = 0; | |
3037 | p2p->cfg->send_action_done(p2p->cfg->cb_ctx); | |
3038 | } | |
63a965c3 JM |
3039 | if (p2p->after_scan_tx_in_progress) { |
3040 | p2p->after_scan_tx_in_progress = 0; | |
3041 | if (p2p->start_after_scan != P2P_AFTER_SCAN_NOTHING && | |
3042 | p2p_run_after_scan(p2p)) | |
3043 | break; | |
3044 | if (p2p->state == P2P_SEARCH) { | |
ed496f13 | 3045 | p2p_dbg(p2p, "Continue find after after_scan_tx completion"); |
63a965c3 JM |
3046 | p2p_continue_find(p2p); |
3047 | } | |
3048 | } | |
b22128ef JM |
3049 | break; |
3050 | case P2P_PENDING_GO_NEG_REQUEST: | |
3051 | p2p_go_neg_req_cb(p2p, success); | |
3052 | break; | |
3053 | case P2P_PENDING_GO_NEG_RESPONSE: | |
3054 | p2p_go_neg_resp_cb(p2p, success); | |
3055 | break; | |
3056 | case P2P_PENDING_GO_NEG_RESPONSE_FAILURE: | |
7800d45c | 3057 | p2p_go_neg_resp_failure_cb(p2p, success, dst); |
b22128ef JM |
3058 | break; |
3059 | case P2P_PENDING_GO_NEG_CONFIRM: | |
93b7ddd0 | 3060 | p2p_go_neg_conf_cb(p2p, result); |
b22128ef JM |
3061 | break; |
3062 | case P2P_PENDING_SD: | |
3063 | p2p_sd_cb(p2p, success); | |
3064 | break; | |
3065 | case P2P_PENDING_PD: | |
3066 | p2p_prov_disc_cb(p2p, success); | |
3067 | break; | |
3068 | case P2P_PENDING_INVITATION_REQUEST: | |
3069 | p2p_invitation_req_cb(p2p, success); | |
3070 | break; | |
3071 | case P2P_PENDING_INVITATION_RESPONSE: | |
3072 | p2p_invitation_resp_cb(p2p, success); | |
3073 | break; | |
3074 | case P2P_PENDING_DEV_DISC_REQUEST: | |
3075 | p2p_dev_disc_req_cb(p2p, success); | |
3076 | break; | |
3077 | case P2P_PENDING_DEV_DISC_RESPONSE: | |
3078 | p2p_dev_disc_resp_cb(p2p, success); | |
3079 | break; | |
3080 | case P2P_PENDING_GO_DISC_REQ: | |
3081 | p2p_go_disc_req_cb(p2p, success); | |
3082 | break; | |
3083 | } | |
63a965c3 JM |
3084 | |
3085 | p2p->after_scan_tx_in_progress = 0; | |
b22128ef JM |
3086 | } |
3087 | ||
3088 | ||
3089 | void p2p_listen_cb(struct p2p_data *p2p, unsigned int freq, | |
3090 | unsigned int duration) | |
3091 | { | |
3092 | if (freq == p2p->pending_client_disc_freq) { | |
ed496f13 | 3093 | p2p_dbg(p2p, "Client discoverability remain-awake completed"); |
b22128ef JM |
3094 | p2p->pending_client_disc_freq = 0; |
3095 | return; | |
3096 | } | |
3097 | ||
3098 | if (freq != p2p->pending_listen_freq) { | |
ed496f13 | 3099 | p2p_dbg(p2p, "Unexpected listen callback for freq=%u duration=%u (pending_listen_freq=%u)", |
b22128ef JM |
3100 | freq, duration, p2p->pending_listen_freq); |
3101 | return; | |
3102 | } | |
3103 | ||
ed496f13 | 3104 | p2p_dbg(p2p, "Starting Listen timeout(%u,%u) on freq=%u based on callback", |
b22128ef JM |
3105 | p2p->pending_listen_sec, p2p->pending_listen_usec, |
3106 | p2p->pending_listen_freq); | |
3107 | p2p->in_listen = 1; | |
0b8889d8 | 3108 | p2p->drv_in_listen = freq; |
b22128ef JM |
3109 | if (p2p->pending_listen_sec || p2p->pending_listen_usec) { |
3110 | /* | |
3111 | * Add 20 msec extra wait to avoid race condition with driver | |
3112 | * remain-on-channel end event, i.e., give driver more time to | |
3113 | * complete the operation before our timeout expires. | |
3114 | */ | |
3115 | p2p_set_timeout(p2p, p2p->pending_listen_sec, | |
3116 | p2p->pending_listen_usec + 20000); | |
3117 | } | |
3118 | ||
3119 | p2p->pending_listen_freq = 0; | |
3120 | } | |
3121 | ||
3122 | ||
3123 | int p2p_listen_end(struct p2p_data *p2p, unsigned int freq) | |
3124 | { | |
ed496f13 | 3125 | p2p_dbg(p2p, "Driver ended Listen state (freq=%u)", freq); |
b22128ef JM |
3126 | p2p->drv_in_listen = 0; |
3127 | if (p2p->in_listen) | |
3128 | return 0; /* Internal timeout will trigger the next step */ | |
3129 | ||
3130 | if (p2p->state == P2P_CONNECT_LISTEN && p2p->go_neg_peer) { | |
e24cf97c | 3131 | if (p2p->go_neg_peer->connect_reqs >= 120) { |
ed496f13 | 3132 | p2p_dbg(p2p, "Timeout on sending GO Negotiation Request without getting response"); |
e24cf97c JM |
3133 | p2p_go_neg_failed(p2p, p2p->go_neg_peer, -1); |
3134 | return 0; | |
3135 | } | |
3136 | ||
b22128ef JM |
3137 | p2p_set_state(p2p, P2P_CONNECT); |
3138 | p2p_connect_send(p2p, p2p->go_neg_peer); | |
3139 | return 1; | |
3140 | } else if (p2p->state == P2P_SEARCH) { | |
59acfe87 JM |
3141 | if (p2p->p2p_scan_running) { |
3142 | /* | |
3143 | * Search is already in progress. This can happen if | |
3144 | * an Action frame RX is reported immediately after | |
3145 | * the end of a remain-on-channel operation and the | |
3146 | * response frame to that is sent using an offchannel | |
3147 | * operation while in p2p_find. Avoid an attempt to | |
3148 | * restart a scan here. | |
3149 | */ | |
ed496f13 | 3150 | p2p_dbg(p2p, "p2p_scan already in progress - do not try to start a new one"); |
59acfe87 JM |
3151 | return 1; |
3152 | } | |
3fe8b68d JM |
3153 | if (p2p->pending_listen_freq) { |
3154 | /* | |
3155 | * Better wait a bit if the driver is unable to start | |
3156 | * offchannel operation for some reason. p2p_search() | |
3157 | * will be started from internal timeout. | |
3158 | */ | |
ed496f13 | 3159 | p2p_dbg(p2p, "Listen operation did not seem to start - delay search phase to avoid busy loop"); |
3fe8b68d JM |
3160 | p2p_set_timeout(p2p, 0, 100000); |
3161 | return 1; | |
3162 | } | |
37448ede | 3163 | if (p2p->search_delay) { |
ed496f13 | 3164 | p2p_dbg(p2p, "Delay search operation by %u ms", |
37448ede JM |
3165 | p2p->search_delay); |
3166 | p2p_set_timeout(p2p, p2p->search_delay / 1000, | |
3167 | (p2p->search_delay % 1000) * 1000); | |
3168 | return 1; | |
3169 | } | |
b22128ef JM |
3170 | p2p_search(p2p); |
3171 | return 1; | |
3172 | } | |
3173 | ||
3174 | return 0; | |
3175 | } | |
3176 | ||
3177 | ||
3178 | static void p2p_timeout_connect(struct p2p_data *p2p) | |
3179 | { | |
3180 | p2p->cfg->send_action_done(p2p->cfg->cb_ctx); | |
579a8098 JM |
3181 | if (p2p->go_neg_peer && |
3182 | (p2p->go_neg_peer->flags & P2P_DEV_WAIT_GO_NEG_CONFIRM)) { | |
ed496f13 | 3183 | p2p_dbg(p2p, "Wait for GO Negotiation Confirm timed out - assume GO Negotiation failed"); |
579a8098 JM |
3184 | p2p_go_neg_failed(p2p, p2p->go_neg_peer, -1); |
3185 | return; | |
3186 | } | |
fb8984fd JM |
3187 | if (p2p->go_neg_peer && |
3188 | (p2p->go_neg_peer->flags & P2P_DEV_PEER_WAITING_RESPONSE) && | |
3189 | p2p->go_neg_peer->connect_reqs < 120) { | |
ed496f13 | 3190 | p2p_dbg(p2p, "Peer expected to wait our response - skip listen"); |
fb8984fd JM |
3191 | p2p_connect_send(p2p, p2p->go_neg_peer); |
3192 | return; | |
3193 | } | |
fdd48ff6 JM |
3194 | if (p2p->go_neg_peer && p2p->go_neg_peer->oob_go_neg_freq > 0) { |
3195 | p2p_dbg(p2p, "Skip connect-listen since GO Neg channel known (OOB)"); | |
3196 | p2p_set_state(p2p, P2P_CONNECT_LISTEN); | |
3197 | p2p_set_timeout(p2p, 0, 30000); | |
3198 | return; | |
3199 | } | |
b22128ef | 3200 | p2p_set_state(p2p, P2P_CONNECT_LISTEN); |
96beff11 | 3201 | p2p_listen_in_find(p2p, 0); |
b22128ef JM |
3202 | } |
3203 | ||
3204 | ||
3205 | static void p2p_timeout_connect_listen(struct p2p_data *p2p) | |
3206 | { | |
3207 | if (p2p->go_neg_peer) { | |
3208 | if (p2p->drv_in_listen) { | |
ed496f13 | 3209 | p2p_dbg(p2p, "Driver is still in Listen state; wait for it to complete"); |
b22128ef JM |
3210 | return; |
3211 | } | |
9dac8c3e FM |
3212 | |
3213 | if (p2p->go_neg_peer->connect_reqs >= 120) { | |
ed496f13 | 3214 | p2p_dbg(p2p, "Timeout on sending GO Negotiation Request without getting response"); |
9dac8c3e FM |
3215 | p2p_go_neg_failed(p2p, p2p->go_neg_peer, -1); |
3216 | return; | |
3217 | } | |
3218 | ||
b22128ef JM |
3219 | p2p_set_state(p2p, P2P_CONNECT); |
3220 | p2p_connect_send(p2p, p2p->go_neg_peer); | |
3221 | } else | |
3222 | p2p_set_state(p2p, P2P_IDLE); | |
3223 | } | |
3224 | ||
3225 | ||
3226 | static void p2p_timeout_wait_peer_connect(struct p2p_data *p2p) | |
3227 | { | |
b22128ef | 3228 | p2p_set_state(p2p, P2P_WAIT_PEER_IDLE); |
a2d63657 RR |
3229 | |
3230 | if (p2p->cfg->is_concurrent_session_active && | |
3231 | p2p->cfg->is_concurrent_session_active(p2p->cfg->cb_ctx)) | |
3232 | p2p_set_timeout(p2p, 0, 500000); | |
3233 | else | |
3234 | p2p_set_timeout(p2p, 0, 200000); | |
b22128ef JM |
3235 | } |
3236 | ||
3237 | ||
3238 | static void p2p_timeout_wait_peer_idle(struct p2p_data *p2p) | |
3239 | { | |
3240 | struct p2p_device *dev = p2p->go_neg_peer; | |
3241 | ||
3242 | if (dev == NULL) { | |
ed496f13 | 3243 | p2p_dbg(p2p, "Unknown GO Neg peer - stop GO Neg wait"); |
b22128ef JM |
3244 | return; |
3245 | } | |
3246 | ||
3247 | dev->wait_count++; | |
3248 | if (dev->wait_count >= 120) { | |
ed496f13 | 3249 | p2p_dbg(p2p, "Timeout on waiting peer to become ready for GO Negotiation"); |
b22128ef JM |
3250 | p2p_go_neg_failed(p2p, dev, -1); |
3251 | return; | |
3252 | } | |
3253 | ||
ed496f13 | 3254 | p2p_dbg(p2p, "Go to Listen state while waiting for the peer to become ready for GO Negotiation"); |
b22128ef | 3255 | p2p_set_state(p2p, P2P_WAIT_PEER_CONNECT); |
96beff11 | 3256 | p2p_listen_in_find(p2p, 0); |
b22128ef JM |
3257 | } |
3258 | ||
3259 | ||
3260 | static void p2p_timeout_sd_during_find(struct p2p_data *p2p) | |
3261 | { | |
ed496f13 | 3262 | p2p_dbg(p2p, "Service Discovery Query timeout"); |
b22128ef JM |
3263 | if (p2p->sd_peer) { |
3264 | p2p->cfg->send_action_done(p2p->cfg->cb_ctx); | |
b22128ef JM |
3265 | p2p->sd_peer = NULL; |
3266 | } | |
3267 | p2p_continue_find(p2p); | |
3268 | } | |
3269 | ||
3270 | ||
3271 | static void p2p_timeout_prov_disc_during_find(struct p2p_data *p2p) | |
3272 | { | |
ed496f13 | 3273 | p2p_dbg(p2p, "Provision Discovery Request timeout"); |
b22128ef JM |
3274 | p2p->cfg->send_action_done(p2p->cfg->cb_ctx); |
3275 | p2p_continue_find(p2p); | |
3276 | } | |
3277 | ||
3278 | ||
6b56cc2d JS |
3279 | static void p2p_timeout_prov_disc_req(struct p2p_data *p2p) |
3280 | { | |
3281 | p2p->pending_action_state = P2P_NO_PENDING_ACTION; | |
3282 | ||
3283 | /* | |
3284 | * For user initiated PD requests that we have not gotten any responses | |
3285 | * for while in IDLE state, we retry them a couple of times before | |
3286 | * giving up. | |
3287 | */ | |
3288 | if (!p2p->user_initiated_pd) | |
3289 | return; | |
3290 | ||
ed496f13 | 3291 | p2p_dbg(p2p, "User initiated Provision Discovery Request timeout"); |
6b56cc2d JS |
3292 | |
3293 | if (p2p->pd_retries) { | |
3294 | p2p->pd_retries--; | |
3295 | p2p_retry_pd(p2p); | |
3296 | } else { | |
175171ac JM |
3297 | struct p2p_device *dev; |
3298 | int for_join = 0; | |
3299 | ||
3300 | dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) { | |
3301 | if (os_memcmp(p2p->pending_pd_devaddr, | |
3302 | dev->info.p2p_device_addr, ETH_ALEN) != 0) | |
3303 | continue; | |
3304 | if (dev->req_config_methods && | |
3305 | (dev->flags & P2P_DEV_PD_FOR_JOIN)) | |
3306 | for_join = 1; | |
3307 | } | |
3308 | ||
349b213c JS |
3309 | if (p2p->cfg->prov_disc_fail) |
3310 | p2p->cfg->prov_disc_fail(p2p->cfg->cb_ctx, | |
3311 | p2p->pending_pd_devaddr, | |
175171ac JM |
3312 | for_join ? |
3313 | P2P_PROV_DISC_TIMEOUT_JOIN : | |
349b213c | 3314 | P2P_PROV_DISC_TIMEOUT); |
6b56cc2d JS |
3315 | p2p_reset_pending_pd(p2p); |
3316 | } | |
3317 | } | |
3318 | ||
3319 | ||
b22128ef JM |
3320 | static void p2p_timeout_invite(struct p2p_data *p2p) |
3321 | { | |
3322 | p2p->cfg->send_action_done(p2p->cfg->cb_ctx); | |
3323 | p2p_set_state(p2p, P2P_INVITE_LISTEN); | |
04d8dad5 JM |
3324 | if (p2p->inv_role == P2P_INVITE_ROLE_ACTIVE_GO) { |
3325 | /* | |
3326 | * Better remain on operating channel instead of listen channel | |
3327 | * when running a group. | |
3328 | */ | |
ed496f13 | 3329 | p2p_dbg(p2p, "Inviting in active GO role - wait on operating channel"); |
04d8dad5 JM |
3330 | p2p_set_timeout(p2p, 0, 100000); |
3331 | return; | |
3332 | } | |
96beff11 | 3333 | p2p_listen_in_find(p2p, 0); |
b22128ef JM |
3334 | } |
3335 | ||
3336 | ||
3337 | static void p2p_timeout_invite_listen(struct p2p_data *p2p) | |
3338 | { | |
3339 | if (p2p->invite_peer && p2p->invite_peer->invitation_reqs < 100) { | |
3340 | p2p_set_state(p2p, P2P_INVITE); | |
3341 | p2p_invite_send(p2p, p2p->invite_peer, | |
8e9f53c3 | 3342 | p2p->invite_go_dev_addr, p2p->invite_dev_pw_id); |
b22128ef JM |
3343 | } else { |
3344 | if (p2p->invite_peer) { | |
ed496f13 | 3345 | p2p_dbg(p2p, "Invitation Request retry limit reached"); |
b22128ef JM |
3346 | if (p2p->cfg->invitation_result) |
3347 | p2p->cfg->invitation_result( | |
dbca75f8 | 3348 | p2p->cfg->cb_ctx, -1, NULL, NULL, |
dcd25d4c | 3349 | p2p->invite_peer->info.p2p_device_addr, |
41d5ce9e | 3350 | 0, 0); |
b22128ef JM |
3351 | } |
3352 | p2p_set_state(p2p, P2P_IDLE); | |
3353 | } | |
3354 | } | |
3355 | ||
3356 | ||
3357 | static void p2p_state_timeout(void *eloop_ctx, void *timeout_ctx) | |
3358 | { | |
3359 | struct p2p_data *p2p = eloop_ctx; | |
3360 | ||
ed496f13 | 3361 | p2p_dbg(p2p, "Timeout (state=%s)", p2p_state_txt(p2p->state)); |
b22128ef JM |
3362 | |
3363 | p2p->in_listen = 0; | |
3364 | ||
3365 | switch (p2p->state) { | |
3366 | case P2P_IDLE: | |
6b56cc2d JS |
3367 | /* Check if we timed out waiting for PD req */ |
3368 | if (p2p->pending_action_state == P2P_PENDING_PD) | |
3369 | p2p_timeout_prov_disc_req(p2p); | |
b22128ef JM |
3370 | break; |
3371 | case P2P_SEARCH: | |
6b56cc2d JS |
3372 | /* Check if we timed out waiting for PD req */ |
3373 | if (p2p->pending_action_state == P2P_PENDING_PD) | |
3374 | p2p_timeout_prov_disc_req(p2p); | |
37448ede | 3375 | if (p2p->search_delay && !p2p->in_search_delay) { |
ed496f13 | 3376 | p2p_dbg(p2p, "Delay search operation by %u ms", |
37448ede JM |
3377 | p2p->search_delay); |
3378 | p2p->in_search_delay = 1; | |
3379 | p2p_set_timeout(p2p, p2p->search_delay / 1000, | |
3380 | (p2p->search_delay % 1000) * 1000); | |
3381 | break; | |
3382 | } | |
3383 | p2p->in_search_delay = 0; | |
b22128ef JM |
3384 | p2p_search(p2p); |
3385 | break; | |
3386 | case P2P_CONNECT: | |
3387 | p2p_timeout_connect(p2p); | |
3388 | break; | |
3389 | case P2P_CONNECT_LISTEN: | |
3390 | p2p_timeout_connect_listen(p2p); | |
3391 | break; | |
3392 | case P2P_GO_NEG: | |
3393 | break; | |
3394 | case P2P_LISTEN_ONLY: | |
6b56cc2d JS |
3395 | /* Check if we timed out waiting for PD req */ |
3396 | if (p2p->pending_action_state == P2P_PENDING_PD) | |
3397 | p2p_timeout_prov_disc_req(p2p); | |
3398 | ||
b22128ef | 3399 | if (p2p->ext_listen_only) { |
ed496f13 | 3400 | p2p_dbg(p2p, "Extended Listen Timing - Listen State completed"); |
b22128ef JM |
3401 | p2p->ext_listen_only = 0; |
3402 | p2p_set_state(p2p, P2P_IDLE); | |
3403 | } | |
3404 | break; | |
3405 | case P2P_WAIT_PEER_CONNECT: | |
3406 | p2p_timeout_wait_peer_connect(p2p); | |
3407 | break; | |
3408 | case P2P_WAIT_PEER_IDLE: | |
3409 | p2p_timeout_wait_peer_idle(p2p); | |
3410 | break; | |
3411 | case P2P_SD_DURING_FIND: | |
3412 | p2p_timeout_sd_during_find(p2p); | |
3413 | break; | |
3414 | case P2P_PROVISIONING: | |
3415 | break; | |
3416 | case P2P_PD_DURING_FIND: | |
3417 | p2p_timeout_prov_disc_during_find(p2p); | |
3418 | break; | |
3419 | case P2P_INVITE: | |
3420 | p2p_timeout_invite(p2p); | |
3421 | break; | |
3422 | case P2P_INVITE_LISTEN: | |
3423 | p2p_timeout_invite_listen(p2p); | |
3424 | break; | |
3425 | } | |
3426 | } | |
3427 | ||
3428 | ||
3429 | int p2p_reject(struct p2p_data *p2p, const u8 *peer_addr) | |
3430 | { | |
3431 | struct p2p_device *dev; | |
3432 | ||
3433 | dev = p2p_get_device(p2p, peer_addr); | |
ed496f13 JM |
3434 | p2p_dbg(p2p, "Local request to reject connection attempts by peer " |
3435 | MACSTR, MAC2STR(peer_addr)); | |
b22128ef | 3436 | if (dev == NULL) { |
ed496f13 | 3437 | p2p_dbg(p2p, "Peer " MACSTR " unknown", MAC2STR(peer_addr)); |
b22128ef JM |
3438 | return -1; |
3439 | } | |
3440 | dev->status = P2P_SC_FAIL_REJECTED_BY_USER; | |
3441 | dev->flags |= P2P_DEV_USER_REJECTED; | |
3442 | return 0; | |
3443 | } | |
3444 | ||
3445 | ||
e5a359cf | 3446 | const char * p2p_wps_method_text(enum p2p_wps_method method) |
b22128ef JM |
3447 | { |
3448 | switch (method) { | |
3449 | case WPS_NOT_READY: | |
3450 | return "not-ready"; | |
b22128ef JM |
3451 | case WPS_PIN_DISPLAY: |
3452 | return "Display"; | |
3453 | case WPS_PIN_KEYPAD: | |
3454 | return "Keypad"; | |
3455 | case WPS_PBC: | |
3456 | return "PBC"; | |
c00ab85f JM |
3457 | case WPS_NFC: |
3458 | return "NFC"; | |
b22128ef JM |
3459 | } |
3460 | ||
3461 | return "??"; | |
3462 | } | |
3463 | ||
3464 | ||
3465 | static const char * p2p_go_state_text(enum p2p_go_state go_state) | |
3466 | { | |
3467 | switch (go_state) { | |
3468 | case UNKNOWN_GO: | |
3469 | return "unknown"; | |
3470 | case LOCAL_GO: | |
3471 | return "local"; | |
3472 | case REMOTE_GO: | |
3473 | return "remote"; | |
3474 | } | |
3475 | ||
3476 | return "??"; | |
3477 | } | |
3478 | ||
3479 | ||
b3ffc80b JM |
3480 | const struct p2p_peer_info * p2p_get_peer_info(struct p2p_data *p2p, |
3481 | const u8 *addr, int next) | |
b22128ef JM |
3482 | { |
3483 | struct p2p_device *dev; | |
b22128ef JM |
3484 | |
3485 | if (addr) | |
3486 | dev = p2p_get_device(p2p, addr); | |
3487 | else | |
3488 | dev = dl_list_first(&p2p->devices, struct p2p_device, list); | |
3489 | ||
3490 | if (dev && next) { | |
3491 | dev = dl_list_first(&dev->list, struct p2p_device, list); | |
3492 | if (&dev->list == &p2p->devices) | |
3493 | dev = NULL; | |
3494 | } | |
3495 | ||
3496 | if (dev == NULL) | |
b3ffc80b JM |
3497 | return NULL; |
3498 | ||
3499 | return &dev->info; | |
3500 | } | |
3501 | ||
3502 | ||
3503 | int p2p_get_peer_info_txt(const struct p2p_peer_info *info, | |
3504 | char *buf, size_t buflen) | |
3505 | { | |
3506 | struct p2p_device *dev; | |
3507 | int res; | |
3508 | char *pos, *end; | |
acb69cec | 3509 | struct os_reltime now; |
b3ffc80b JM |
3510 | |
3511 | if (info == NULL) | |
b22128ef JM |
3512 | return -1; |
3513 | ||
b3ffc80b JM |
3514 | dev = (struct p2p_device *) (((u8 *) info) - |
3515 | offsetof(struct p2p_device, info)); | |
3516 | ||
b22128ef JM |
3517 | pos = buf; |
3518 | end = buf + buflen; | |
3519 | ||
acb69cec | 3520 | os_get_reltime(&now); |
b22128ef JM |
3521 | res = os_snprintf(pos, end - pos, |
3522 | "age=%d\n" | |
3523 | "listen_freq=%d\n" | |
b22128ef JM |
3524 | "wps_method=%s\n" |
3525 | "interface_addr=" MACSTR "\n" | |
3526 | "member_in_go_dev=" MACSTR "\n" | |
3527 | "member_in_go_iface=" MACSTR "\n" | |
b22128ef JM |
3528 | "go_neg_req_sent=%d\n" |
3529 | "go_state=%s\n" | |
3530 | "dialog_token=%u\n" | |
3531 | "intended_addr=" MACSTR "\n" | |
3532 | "country=%c%c\n" | |
3533 | "oper_freq=%d\n" | |
3534 | "req_config_methods=0x%x\n" | |
f667e031 | 3535 | "flags=%s%s%s%s%s%s%s%s%s%s%s%s%s\n" |
b22128ef JM |
3536 | "status=%d\n" |
3537 | "wait_count=%u\n" | |
3538 | "invitation_reqs=%u\n", | |
3539 | (int) (now.sec - dev->last_seen.sec), | |
3540 | dev->listen_freq, | |
b22128ef JM |
3541 | p2p_wps_method_text(dev->wps_method), |
3542 | MAC2STR(dev->interface_addr), | |
3543 | MAC2STR(dev->member_in_go_dev), | |
3544 | MAC2STR(dev->member_in_go_iface), | |
b22128ef JM |
3545 | dev->go_neg_req_sent, |
3546 | p2p_go_state_text(dev->go_state), | |
3547 | dev->dialog_token, | |
3548 | MAC2STR(dev->intended_addr), | |
3549 | dev->country[0] ? dev->country[0] : '_', | |
3550 | dev->country[1] ? dev->country[1] : '_', | |
3551 | dev->oper_freq, | |
3552 | dev->req_config_methods, | |
3553 | dev->flags & P2P_DEV_PROBE_REQ_ONLY ? | |
3554 | "[PROBE_REQ_ONLY]" : "", | |
3555 | dev->flags & P2P_DEV_REPORTED ? "[REPORTED]" : "", | |
3556 | dev->flags & P2P_DEV_NOT_YET_READY ? | |
3557 | "[NOT_YET_READY]" : "", | |
b22128ef JM |
3558 | dev->flags & P2P_DEV_PD_PEER_DISPLAY ? |
3559 | "[PD_PEER_DISPLAY]" : "", | |
3560 | dev->flags & P2P_DEV_PD_PEER_KEYPAD ? | |
3561 | "[PD_PEER_KEYPAD]" : "", | |
3562 | dev->flags & P2P_DEV_USER_REJECTED ? | |
3563 | "[USER_REJECTED]" : "", | |
3564 | dev->flags & P2P_DEV_PEER_WAITING_RESPONSE ? | |
3565 | "[PEER_WAITING_RESPONSE]" : "", | |
3566 | dev->flags & P2P_DEV_PREFER_PERSISTENT_GROUP ? | |
3567 | "[PREFER_PERSISTENT_GROUP]" : "", | |
3568 | dev->flags & P2P_DEV_WAIT_GO_NEG_RESPONSE ? | |
3569 | "[WAIT_GO_NEG_RESPONSE]" : "", | |
3570 | dev->flags & P2P_DEV_WAIT_GO_NEG_CONFIRM ? | |
3571 | "[WAIT_GO_NEG_CONFIRM]" : "", | |
3572 | dev->flags & P2P_DEV_GROUP_CLIENT_ONLY ? | |
3573 | "[GROUP_CLIENT_ONLY]" : "", | |
d5b20a73 | 3574 | dev->flags & P2P_DEV_FORCE_FREQ ? |
10c4edde JM |
3575 | "[FORCE_FREQ]" : "", |
3576 | dev->flags & P2P_DEV_PD_FOR_JOIN ? | |
3577 | "[PD_FOR_JOIN]" : "", | |
b22128ef JM |
3578 | dev->status, |
3579 | dev->wait_count, | |
3580 | dev->invitation_reqs); | |
3581 | if (res < 0 || res >= end - pos) | |
3582 | return pos - buf; | |
3583 | pos += res; | |
3584 | ||
3585 | if (dev->ext_listen_period) { | |
3586 | res = os_snprintf(pos, end - pos, | |
3587 | "ext_listen_period=%u\n" | |
3588 | "ext_listen_interval=%u\n", | |
3589 | dev->ext_listen_period, | |
3590 | dev->ext_listen_interval); | |
3591 | if (res < 0 || res >= end - pos) | |
3592 | return pos - buf; | |
3593 | pos += res; | |
3594 | } | |
3595 | ||
3596 | if (dev->oper_ssid_len) { | |
3597 | res = os_snprintf(pos, end - pos, | |
3598 | "oper_ssid=%s\n", | |
3599 | wpa_ssid_txt(dev->oper_ssid, | |
3600 | dev->oper_ssid_len)); | |
3601 | if (res < 0 || res >= end - pos) | |
3602 | return pos - buf; | |
3603 | pos += res; | |
3604 | } | |
3605 | ||
9675ce35 JM |
3606 | #ifdef CONFIG_WIFI_DISPLAY |
3607 | if (dev->info.wfd_subelems) { | |
3608 | res = os_snprintf(pos, end - pos, "wfd_subelems="); | |
3609 | if (res < 0 || res >= end - pos) | |
3610 | return pos - buf; | |
3611 | pos += res; | |
3612 | ||
3613 | pos += wpa_snprintf_hex(pos, end - pos, | |
3614 | wpabuf_head(dev->info.wfd_subelems), | |
3615 | wpabuf_len(dev->info.wfd_subelems)); | |
3616 | ||
3617 | res = os_snprintf(pos, end - pos, "\n"); | |
3618 | if (res < 0 || res >= end - pos) | |
3619 | return pos - buf; | |
3620 | pos += res; | |
3621 | } | |
3622 | #endif /* CONFIG_WIFI_DISPLAY */ | |
3623 | ||
b22128ef JM |
3624 | return pos - buf; |
3625 | } | |
3626 | ||
3627 | ||
b3bcc0f5 JM |
3628 | int p2p_peer_known(struct p2p_data *p2p, const u8 *addr) |
3629 | { | |
3630 | return p2p_get_device(p2p, addr) != NULL; | |
3631 | } | |
3632 | ||
3633 | ||
b22128ef JM |
3634 | void p2p_set_client_discoverability(struct p2p_data *p2p, int enabled) |
3635 | { | |
3636 | if (enabled) { | |
ed496f13 | 3637 | p2p_dbg(p2p, "Client discoverability enabled"); |
b22128ef JM |
3638 | p2p->dev_capab |= P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY; |
3639 | } else { | |
ed496f13 | 3640 | p2p_dbg(p2p, "Client discoverability disabled"); |
b22128ef JM |
3641 | p2p->dev_capab &= ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY; |
3642 | } | |
3643 | } | |
3644 | ||
3645 | ||
3646 | static struct wpabuf * p2p_build_presence_req(u32 duration1, u32 interval1, | |
3647 | u32 duration2, u32 interval2) | |
3648 | { | |
3649 | struct wpabuf *req; | |
3650 | struct p2p_noa_desc desc1, desc2, *ptr1 = NULL, *ptr2 = NULL; | |
3651 | u8 *len; | |
3652 | ||
3653 | req = wpabuf_alloc(100); | |
3654 | if (req == NULL) | |
3655 | return NULL; | |
3656 | ||
3657 | if (duration1 || interval1) { | |
3658 | os_memset(&desc1, 0, sizeof(desc1)); | |
3659 | desc1.count_type = 1; | |
3660 | desc1.duration = duration1; | |
3661 | desc1.interval = interval1; | |
3662 | ptr1 = &desc1; | |
3663 | ||
3664 | if (duration2 || interval2) { | |
3665 | os_memset(&desc2, 0, sizeof(desc2)); | |
3666 | desc2.count_type = 2; | |
3667 | desc2.duration = duration2; | |
3668 | desc2.interval = interval2; | |
3669 | ptr2 = &desc2; | |
3670 | } | |
3671 | } | |
3672 | ||
3673 | p2p_buf_add_action_hdr(req, P2P_PRESENCE_REQ, 1); | |
3674 | len = p2p_buf_add_ie_hdr(req); | |
3675 | p2p_buf_add_noa(req, 0, 0, 0, ptr1, ptr2); | |
3676 | p2p_buf_update_ie_hdr(req, len); | |
3677 | ||
3678 | return req; | |
3679 | } | |
3680 | ||
3681 | ||
3682 | int p2p_presence_req(struct p2p_data *p2p, const u8 *go_interface_addr, | |
3683 | const u8 *own_interface_addr, unsigned int freq, | |
3684 | u32 duration1, u32 interval1, u32 duration2, | |
3685 | u32 interval2) | |
3686 | { | |
3687 | struct wpabuf *req; | |
3688 | ||
ed496f13 JM |
3689 | p2p_dbg(p2p, "Send Presence Request to GO " MACSTR |
3690 | " (own interface " MACSTR ") freq=%u dur1=%u int1=%u " | |
3691 | "dur2=%u int2=%u", | |
b22128ef JM |
3692 | MAC2STR(go_interface_addr), MAC2STR(own_interface_addr), |
3693 | freq, duration1, interval1, duration2, interval2); | |
3694 | ||
3695 | req = p2p_build_presence_req(duration1, interval1, duration2, | |
3696 | interval2); | |
3697 | if (req == NULL) | |
3698 | return -1; | |
3699 | ||
3700 | p2p->pending_action_state = P2P_NO_PENDING_ACTION; | |
3f9285ff JM |
3701 | if (p2p_send_action(p2p, freq, go_interface_addr, own_interface_addr, |
3702 | go_interface_addr, | |
3703 | wpabuf_head(req), wpabuf_len(req), 200) < 0) { | |
ed496f13 | 3704 | p2p_dbg(p2p, "Failed to send Action frame"); |
b22128ef JM |
3705 | } |
3706 | wpabuf_free(req); | |
3707 | ||
3708 | return 0; | |
3709 | } | |
3710 | ||
3711 | ||
3712 | static struct wpabuf * p2p_build_presence_resp(u8 status, const u8 *noa, | |
3713 | size_t noa_len, u8 dialog_token) | |
3714 | { | |
3715 | struct wpabuf *resp; | |
3716 | u8 *len; | |
3717 | ||
3718 | resp = wpabuf_alloc(100 + noa_len); | |
3719 | if (resp == NULL) | |
3720 | return NULL; | |
3721 | ||
3722 | p2p_buf_add_action_hdr(resp, P2P_PRESENCE_RESP, dialog_token); | |
3723 | len = p2p_buf_add_ie_hdr(resp); | |
3724 | p2p_buf_add_status(resp, status); | |
3725 | if (noa) { | |
3726 | wpabuf_put_u8(resp, P2P_ATTR_NOTICE_OF_ABSENCE); | |
3727 | wpabuf_put_le16(resp, noa_len); | |
3728 | wpabuf_put_data(resp, noa, noa_len); | |
3729 | } else | |
3730 | p2p_buf_add_noa(resp, 0, 0, 0, NULL, NULL); | |
3731 | p2p_buf_update_ie_hdr(resp, len); | |
3732 | ||
3733 | return resp; | |
3734 | } | |
3735 | ||
3736 | ||
3737 | static void p2p_process_presence_req(struct p2p_data *p2p, const u8 *da, | |
3738 | const u8 *sa, const u8 *data, size_t len, | |
3739 | int rx_freq) | |
3740 | { | |
3741 | struct p2p_message msg; | |
3742 | u8 status; | |
3743 | struct wpabuf *resp; | |
3744 | size_t g; | |
3745 | struct p2p_group *group = NULL; | |
3746 | int parsed = 0; | |
3747 | u8 noa[50]; | |
3748 | int noa_len; | |
3749 | ||
ed496f13 | 3750 | p2p_dbg(p2p, "Received P2P Action - P2P Presence Request"); |
b22128ef JM |
3751 | |
3752 | for (g = 0; g < p2p->num_groups; g++) { | |
3753 | if (os_memcmp(da, p2p_group_get_interface_addr(p2p->groups[g]), | |
3754 | ETH_ALEN) == 0) { | |
3755 | group = p2p->groups[g]; | |
3756 | break; | |
3757 | } | |
3758 | } | |
3759 | if (group == NULL) { | |
ed496f13 | 3760 | p2p_dbg(p2p, "Ignore P2P Presence Request for unknown group " |
b22128ef JM |
3761 | MACSTR, MAC2STR(da)); |
3762 | return; | |
3763 | } | |
3764 | ||
3765 | if (p2p_parse(data, len, &msg) < 0) { | |
ed496f13 | 3766 | p2p_dbg(p2p, "Failed to parse P2P Presence Request"); |
b22128ef JM |
3767 | status = P2P_SC_FAIL_INVALID_PARAMS; |
3768 | goto fail; | |
3769 | } | |
3770 | parsed = 1; | |
3771 | ||
3772 | if (msg.noa == NULL) { | |
ed496f13 | 3773 | p2p_dbg(p2p, "No NoA attribute in P2P Presence Request"); |
b22128ef JM |
3774 | status = P2P_SC_FAIL_INVALID_PARAMS; |
3775 | goto fail; | |
3776 | } | |
3777 | ||
3778 | status = p2p_group_presence_req(group, sa, msg.noa, msg.noa_len); | |
3779 | ||
3780 | fail: | |
3781 | if (p2p->cfg->get_noa) | |
3782 | noa_len = p2p->cfg->get_noa(p2p->cfg->cb_ctx, da, noa, | |
3783 | sizeof(noa)); | |
3784 | else | |
3785 | noa_len = -1; | |
3786 | resp = p2p_build_presence_resp(status, noa_len > 0 ? noa : NULL, | |
3787 | noa_len > 0 ? noa_len : 0, | |
3788 | msg.dialog_token); | |
3789 | if (parsed) | |
3790 | p2p_parse_free(&msg); | |
3791 | if (resp == NULL) | |
3792 | return; | |
3793 | ||
3794 | p2p->pending_action_state = P2P_NO_PENDING_ACTION; | |
3f9285ff JM |
3795 | if (p2p_send_action(p2p, rx_freq, sa, da, da, |
3796 | wpabuf_head(resp), wpabuf_len(resp), 200) < 0) { | |
ed496f13 | 3797 | p2p_dbg(p2p, "Failed to send Action frame"); |
b22128ef JM |
3798 | } |
3799 | wpabuf_free(resp); | |
3800 | } | |
3801 | ||
3802 | ||
3803 | static void p2p_process_presence_resp(struct p2p_data *p2p, const u8 *da, | |
3804 | const u8 *sa, const u8 *data, size_t len) | |
3805 | { | |
3806 | struct p2p_message msg; | |
3807 | ||
ed496f13 | 3808 | p2p_dbg(p2p, "Received P2P Action - P2P Presence Response"); |
b22128ef JM |
3809 | |
3810 | if (p2p_parse(data, len, &msg) < 0) { | |
ed496f13 | 3811 | p2p_dbg(p2p, "Failed to parse P2P Presence Response"); |
b22128ef JM |
3812 | return; |
3813 | } | |
3814 | ||
3815 | if (msg.status == NULL || msg.noa == NULL) { | |
ed496f13 | 3816 | p2p_dbg(p2p, "No Status or NoA attribute in P2P Presence Response"); |
b22128ef JM |
3817 | p2p_parse_free(&msg); |
3818 | return; | |
3819 | } | |
3820 | ||
c64e3a08 JM |
3821 | if (p2p->cfg->presence_resp) { |
3822 | p2p->cfg->presence_resp(p2p->cfg->cb_ctx, sa, *msg.status, | |
3823 | msg.noa, msg.noa_len); | |
3824 | } | |
3825 | ||
b22128ef | 3826 | if (*msg.status) { |
ed496f13 | 3827 | p2p_dbg(p2p, "P2P Presence Request was rejected: status %u", |
b22128ef JM |
3828 | *msg.status); |
3829 | p2p_parse_free(&msg); | |
3830 | return; | |
3831 | } | |
3832 | ||
ed496f13 | 3833 | p2p_dbg(p2p, "P2P Presence Request was accepted"); |
b22128ef JM |
3834 | wpa_hexdump(MSG_DEBUG, "P2P: P2P Presence Response - NoA", |
3835 | msg.noa, msg.noa_len); | |
3836 | /* TODO: process NoA */ | |
3837 | p2p_parse_free(&msg); | |
3838 | } | |
3839 | ||
3840 | ||
3841 | static void p2p_ext_listen_timeout(void *eloop_ctx, void *timeout_ctx) | |
3842 | { | |
3843 | struct p2p_data *p2p = eloop_ctx; | |
3844 | ||
3845 | if (p2p->ext_listen_interval) { | |
3846 | /* Schedule next extended listen timeout */ | |
3847 | eloop_register_timeout(p2p->ext_listen_interval_sec, | |
3848 | p2p->ext_listen_interval_usec, | |
3849 | p2p_ext_listen_timeout, p2p, NULL); | |
3850 | } | |
3851 | ||
f7a69057 JM |
3852 | if (p2p->state == P2P_LISTEN_ONLY && p2p->ext_listen_only) { |
3853 | /* | |
3854 | * This should not really happen, but it looks like the Listen | |
3855 | * command may fail is something else (e.g., a scan) was | |
3856 | * running at an inconvenient time. As a workaround, allow new | |
3857 | * Extended Listen operation to be started. | |
3858 | */ | |
ed496f13 | 3859 | p2p_dbg(p2p, "Previous Extended Listen operation had not been completed - try again"); |
f7a69057 JM |
3860 | p2p->ext_listen_only = 0; |
3861 | p2p_set_state(p2p, P2P_IDLE); | |
3862 | } | |
3863 | ||
b22128ef | 3864 | if (p2p->state != P2P_IDLE) { |
ed496f13 | 3865 | p2p_dbg(p2p, "Skip Extended Listen timeout in active state (%s)", p2p_state_txt(p2p->state)); |
b22128ef JM |
3866 | return; |
3867 | } | |
3868 | ||
ed496f13 | 3869 | p2p_dbg(p2p, "Extended Listen timeout"); |
b22128ef JM |
3870 | p2p->ext_listen_only = 1; |
3871 | if (p2p_listen(p2p, p2p->ext_listen_period) < 0) { | |
ed496f13 | 3872 | p2p_dbg(p2p, "Failed to start Listen state for Extended Listen Timing"); |
b22128ef JM |
3873 | p2p->ext_listen_only = 0; |
3874 | } | |
3875 | } | |
3876 | ||
3877 | ||
3878 | int p2p_ext_listen(struct p2p_data *p2p, unsigned int period, | |
3879 | unsigned int interval) | |
3880 | { | |
3881 | if (period > 65535 || interval > 65535 || period > interval || | |
3882 | (period == 0 && interval > 0) || (period > 0 && interval == 0)) { | |
ed496f13 JM |
3883 | p2p_dbg(p2p, "Invalid Extended Listen Timing request: period=%u interval=%u", |
3884 | period, interval); | |
b22128ef JM |
3885 | return -1; |
3886 | } | |
3887 | ||
3888 | eloop_cancel_timeout(p2p_ext_listen_timeout, p2p, NULL); | |
3889 | ||
3890 | if (interval == 0) { | |
ed496f13 | 3891 | p2p_dbg(p2p, "Disabling Extended Listen Timing"); |
b22128ef JM |
3892 | p2p->ext_listen_period = 0; |
3893 | p2p->ext_listen_interval = 0; | |
3894 | return 0; | |
3895 | } | |
3896 | ||
ed496f13 JM |
3897 | p2p_dbg(p2p, "Enabling Extended Listen Timing: period %u msec, interval %u msec", |
3898 | period, interval); | |
b22128ef JM |
3899 | p2p->ext_listen_period = period; |
3900 | p2p->ext_listen_interval = interval; | |
3901 | p2p->ext_listen_interval_sec = interval / 1000; | |
3902 | p2p->ext_listen_interval_usec = (interval % 1000) * 1000; | |
3903 | ||
3904 | eloop_register_timeout(p2p->ext_listen_interval_sec, | |
3905 | p2p->ext_listen_interval_usec, | |
3906 | p2p_ext_listen_timeout, p2p, NULL); | |
3907 | ||
3908 | return 0; | |
3909 | } | |
3910 | ||
3911 | ||
3912 | void p2p_deauth_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code, | |
3913 | const u8 *ie, size_t ie_len) | |
3914 | { | |
3915 | struct p2p_message msg; | |
3916 | ||
3917 | if (bssid == NULL || ie == NULL) | |
3918 | return; | |
3919 | ||
3920 | os_memset(&msg, 0, sizeof(msg)); | |
3921 | if (p2p_parse_ies(ie, ie_len, &msg)) | |
3922 | return; | |
04c366cb EL |
3923 | if (msg.minor_reason_code == NULL) { |
3924 | p2p_parse_free(&msg); | |
b22128ef | 3925 | return; |
04c366cb | 3926 | } |
b22128ef | 3927 | |
ed496f13 | 3928 | p2p_dbg(p2p, "Deauthentication notification BSSID " MACSTR |
b22128ef JM |
3929 | " reason_code=%u minor_reason_code=%u", |
3930 | MAC2STR(bssid), reason_code, *msg.minor_reason_code); | |
3931 | ||
3932 | p2p_parse_free(&msg); | |
3933 | } | |
3934 | ||
3935 | ||
3936 | void p2p_disassoc_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code, | |
3937 | const u8 *ie, size_t ie_len) | |
3938 | { | |
3939 | struct p2p_message msg; | |
3940 | ||
3941 | if (bssid == NULL || ie == NULL) | |
3942 | return; | |
3943 | ||
3944 | os_memset(&msg, 0, sizeof(msg)); | |
3945 | if (p2p_parse_ies(ie, ie_len, &msg)) | |
3946 | return; | |
04c366cb EL |
3947 | if (msg.minor_reason_code == NULL) { |
3948 | p2p_parse_free(&msg); | |
b22128ef | 3949 | return; |
04c366cb | 3950 | } |
b22128ef | 3951 | |
ed496f13 | 3952 | p2p_dbg(p2p, "Disassociation notification BSSID " MACSTR |
b22128ef JM |
3953 | " reason_code=%u minor_reason_code=%u", |
3954 | MAC2STR(bssid), reason_code, *msg.minor_reason_code); | |
3955 | ||
3956 | p2p_parse_free(&msg); | |
3957 | } | |
3958 | ||
3959 | ||
3960 | void p2p_set_managed_oper(struct p2p_data *p2p, int enabled) | |
3961 | { | |
3962 | if (enabled) { | |
ed496f13 | 3963 | p2p_dbg(p2p, "Managed P2P Device operations enabled"); |
b22128ef JM |
3964 | p2p->dev_capab |= P2P_DEV_CAPAB_INFRA_MANAGED; |
3965 | } else { | |
ed496f13 | 3966 | p2p_dbg(p2p, "Managed P2P Device operations disabled"); |
b22128ef JM |
3967 | p2p->dev_capab &= ~P2P_DEV_CAPAB_INFRA_MANAGED; |
3968 | } | |
3969 | } | |
3970 | ||
3971 | ||
3972 | int p2p_set_listen_channel(struct p2p_data *p2p, u8 reg_class, u8 channel) | |
3973 | { | |
9ccd9165 | 3974 | if (p2p_channel_to_freq(reg_class, channel) < 0) |
b22128ef JM |
3975 | return -1; |
3976 | ||
ed496f13 JM |
3977 | p2p_dbg(p2p, "Set Listen channel: reg_class %u channel %u", |
3978 | reg_class, channel); | |
b22128ef JM |
3979 | p2p->cfg->reg_class = reg_class; |
3980 | p2p->cfg->channel = channel; | |
3981 | ||
3982 | return 0; | |
3983 | } | |
3984 | ||
3985 | ||
3986 | int p2p_set_ssid_postfix(struct p2p_data *p2p, const u8 *postfix, size_t len) | |
3987 | { | |
ed496f13 | 3988 | p2p_dbg(p2p, "New SSID postfix: %s", wpa_ssid_txt(postfix, len)); |
b22128ef JM |
3989 | if (postfix == NULL) { |
3990 | p2p->cfg->ssid_postfix_len = 0; | |
3991 | return 0; | |
3992 | } | |
3993 | if (len > sizeof(p2p->cfg->ssid_postfix)) | |
3994 | return -1; | |
3995 | os_memcpy(p2p->cfg->ssid_postfix, postfix, len); | |
3996 | p2p->cfg->ssid_postfix_len = len; | |
3997 | return 0; | |
3998 | } | |
3999 | ||
4000 | ||
2463ba70 JS |
4001 | int p2p_set_oper_channel(struct p2p_data *p2p, u8 op_reg_class, u8 op_channel, |
4002 | int cfg_op_channel) | |
4003 | { | |
9ccd9165 | 4004 | if (p2p_channel_to_freq(op_reg_class, op_channel) < 0) |
2463ba70 JS |
4005 | return -1; |
4006 | ||
ed496f13 JM |
4007 | p2p_dbg(p2p, "Set Operating channel: reg_class %u channel %u", |
4008 | op_reg_class, op_channel); | |
2463ba70 JS |
4009 | p2p->cfg->op_reg_class = op_reg_class; |
4010 | p2p->cfg->op_channel = op_channel; | |
4011 | p2p->cfg->cfg_op_channel = cfg_op_channel; | |
4012 | return 0; | |
4013 | } | |
4014 | ||
4015 | ||
21d996f7 JM |
4016 | int p2p_set_pref_chan(struct p2p_data *p2p, unsigned int num_pref_chan, |
4017 | const struct p2p_channel *pref_chan) | |
4018 | { | |
4019 | struct p2p_channel *n; | |
4020 | ||
4021 | if (pref_chan) { | |
4022 | n = os_malloc(num_pref_chan * sizeof(struct p2p_channel)); | |
4023 | if (n == NULL) | |
4024 | return -1; | |
4025 | os_memcpy(n, pref_chan, | |
4026 | num_pref_chan * sizeof(struct p2p_channel)); | |
4027 | } else | |
4028 | n = NULL; | |
4029 | ||
4030 | os_free(p2p->cfg->pref_chan); | |
4031 | p2p->cfg->pref_chan = n; | |
4032 | p2p->cfg->num_pref_chan = num_pref_chan; | |
4033 | ||
4034 | return 0; | |
4035 | } | |
4036 | ||
4037 | ||
556b30da JM |
4038 | int p2p_set_no_go_freq(struct p2p_data *p2p, |
4039 | const struct wpa_freq_range_list *list) | |
4040 | { | |
4041 | struct wpa_freq_range *tmp; | |
4042 | ||
4043 | if (list == NULL || list->num == 0) { | |
4044 | os_free(p2p->no_go_freq.range); | |
4045 | p2p->no_go_freq.range = NULL; | |
4046 | p2p->no_go_freq.num = 0; | |
4047 | return 0; | |
4048 | } | |
4049 | ||
4050 | tmp = os_calloc(list->num, sizeof(struct wpa_freq_range)); | |
4051 | if (tmp == NULL) | |
4052 | return -1; | |
4053 | os_memcpy(tmp, list->range, list->num * sizeof(struct wpa_freq_range)); | |
4054 | os_free(p2p->no_go_freq.range); | |
4055 | p2p->no_go_freq.range = tmp; | |
4056 | p2p->no_go_freq.num = list->num; | |
4057 | p2p_dbg(p2p, "Updated no GO chan list"); | |
4058 | ||
4059 | return 0; | |
4060 | } | |
4061 | ||
4062 | ||
b22128ef JM |
4063 | int p2p_get_interface_addr(struct p2p_data *p2p, const u8 *dev_addr, |
4064 | u8 *iface_addr) | |
4065 | { | |
4066 | struct p2p_device *dev = p2p_get_device(p2p, dev_addr); | |
4067 | if (dev == NULL || is_zero_ether_addr(dev->interface_addr)) | |
4068 | return -1; | |
4069 | os_memcpy(iface_addr, dev->interface_addr, ETH_ALEN); | |
4070 | return 0; | |
4071 | } | |
80c9582a JM |
4072 | |
4073 | ||
4147a2cc JM |
4074 | int p2p_get_dev_addr(struct p2p_data *p2p, const u8 *iface_addr, |
4075 | u8 *dev_addr) | |
4076 | { | |
4077 | struct p2p_device *dev = p2p_get_device_interface(p2p, iface_addr); | |
4078 | if (dev == NULL) | |
4079 | return -1; | |
c5db8e51 | 4080 | os_memcpy(dev_addr, dev->info.p2p_device_addr, ETH_ALEN); |
4147a2cc JM |
4081 | return 0; |
4082 | } | |
4083 | ||
4084 | ||
80c9582a JM |
4085 | void p2p_set_peer_filter(struct p2p_data *p2p, const u8 *addr) |
4086 | { | |
4087 | os_memcpy(p2p->peer_filter, addr, ETH_ALEN); | |
4088 | if (is_zero_ether_addr(p2p->peer_filter)) | |
ed496f13 | 4089 | p2p_dbg(p2p, "Disable peer filter"); |
80c9582a | 4090 | else |
ed496f13 JM |
4091 | p2p_dbg(p2p, "Enable peer filter for " MACSTR, |
4092 | MAC2STR(p2p->peer_filter)); | |
80c9582a | 4093 | } |
72044390 JM |
4094 | |
4095 | ||
4096 | void p2p_set_cross_connect(struct p2p_data *p2p, int enabled) | |
4097 | { | |
ed496f13 | 4098 | p2p_dbg(p2p, "Cross connection %s", enabled ? "enabled" : "disabled"); |
72044390 JM |
4099 | if (p2p->cross_connect == enabled) |
4100 | return; | |
4101 | p2p->cross_connect = enabled; | |
4102 | /* TODO: may need to tear down any action group where we are GO(?) */ | |
4103 | } | |
f8d0131a JM |
4104 | |
4105 | ||
4106 | int p2p_get_oper_freq(struct p2p_data *p2p, const u8 *iface_addr) | |
4107 | { | |
4108 | struct p2p_device *dev = p2p_get_device_interface(p2p, iface_addr); | |
4109 | if (dev == NULL) | |
4110 | return -1; | |
4111 | if (dev->oper_freq <= 0) | |
4112 | return -1; | |
4113 | return dev->oper_freq; | |
4114 | } | |
0f66abd2 SS |
4115 | |
4116 | ||
4117 | void p2p_set_intra_bss_dist(struct p2p_data *p2p, int enabled) | |
4118 | { | |
ed496f13 | 4119 | p2p_dbg(p2p, "Intra BSS distribution %s", |
0f66abd2 SS |
4120 | enabled ? "enabled" : "disabled"); |
4121 | p2p->cfg->p2p_intra_bss = enabled; | |
4122 | } | |
b5c9da8d JM |
4123 | |
4124 | ||
51e9f228 JM |
4125 | void p2p_update_channel_list(struct p2p_data *p2p, |
4126 | const struct p2p_channels *chan, | |
4127 | const struct p2p_channels *cli_chan) | |
b5c9da8d | 4128 | { |
ed496f13 | 4129 | p2p_dbg(p2p, "Update channel list"); |
b5c9da8d | 4130 | os_memcpy(&p2p->cfg->channels, chan, sizeof(struct p2p_channels)); |
51e9f228 JM |
4131 | p2p_channels_dump(p2p, "channels", &p2p->cfg->channels); |
4132 | os_memcpy(&p2p->cfg->cli_channels, cli_chan, | |
4133 | sizeof(struct p2p_channels)); | |
4134 | p2p_channels_dump(p2p, "cli_channels", &p2p->cfg->cli_channels); | |
b5c9da8d | 4135 | } |
3f9285ff JM |
4136 | |
4137 | ||
4138 | int p2p_send_action(struct p2p_data *p2p, unsigned int freq, const u8 *dst, | |
4139 | const u8 *src, const u8 *bssid, const u8 *buf, | |
4140 | size_t len, unsigned int wait_time) | |
4141 | { | |
4142 | if (p2p->p2p_scan_running) { | |
ed496f13 | 4143 | p2p_dbg(p2p, "Delay Action frame TX until p2p_scan completes"); |
3f9285ff | 4144 | if (p2p->after_scan_tx) { |
ed496f13 | 4145 | p2p_dbg(p2p, "Dropped previous pending Action frame TX"); |
3f9285ff JM |
4146 | os_free(p2p->after_scan_tx); |
4147 | } | |
4148 | p2p->after_scan_tx = os_malloc(sizeof(*p2p->after_scan_tx) + | |
4149 | len); | |
4150 | if (p2p->after_scan_tx == NULL) | |
4151 | return -1; | |
4152 | p2p->after_scan_tx->freq = freq; | |
4153 | os_memcpy(p2p->after_scan_tx->dst, dst, ETH_ALEN); | |
4154 | os_memcpy(p2p->after_scan_tx->src, src, ETH_ALEN); | |
4155 | os_memcpy(p2p->after_scan_tx->bssid, bssid, ETH_ALEN); | |
4156 | p2p->after_scan_tx->len = len; | |
4157 | p2p->after_scan_tx->wait_time = wait_time; | |
4158 | os_memcpy(p2p->after_scan_tx + 1, buf, len); | |
4159 | return 0; | |
4160 | } | |
4161 | ||
4162 | return p2p->cfg->send_action(p2p->cfg->cb_ctx, freq, dst, src, bssid, | |
4163 | buf, len, wait_time); | |
4164 | } | |
7cfc4ac3 AGS |
4165 | |
4166 | ||
4167 | void p2p_set_best_channels(struct p2p_data *p2p, int freq_24, int freq_5, | |
4168 | int freq_overall) | |
4169 | { | |
ed496f13 JM |
4170 | p2p_dbg(p2p, "Best channel: 2.4 GHz: %d, 5 GHz: %d, overall: %d", |
4171 | freq_24, freq_5, freq_overall); | |
7cfc4ac3 AGS |
4172 | p2p->best_freq_24 = freq_24; |
4173 | p2p->best_freq_5 = freq_5; | |
4174 | p2p->best_freq_overall = freq_overall; | |
4175 | } | |
231bbd03 SS |
4176 | |
4177 | ||
6cb27aa8 JM |
4178 | void p2p_set_own_freq_preference(struct p2p_data *p2p, int freq) |
4179 | { | |
ed496f13 | 4180 | p2p_dbg(p2p, "Own frequency preference: %d MHz", freq); |
6cb27aa8 JM |
4181 | p2p->own_freq_preference = freq; |
4182 | } | |
4183 | ||
4184 | ||
231bbd03 SS |
4185 | const u8 * p2p_get_go_neg_peer(struct p2p_data *p2p) |
4186 | { | |
4187 | if (p2p == NULL || p2p->go_neg_peer == NULL) | |
4188 | return NULL; | |
c5db8e51 | 4189 | return p2p->go_neg_peer->info.p2p_device_addr; |
231bbd03 | 4190 | } |
c165d81e JB |
4191 | |
4192 | ||
4193 | const struct p2p_peer_info * | |
4194 | p2p_get_peer_found(struct p2p_data *p2p, const u8 *addr, int next) | |
4195 | { | |
4196 | struct p2p_device *dev; | |
4197 | ||
4198 | if (addr) { | |
4199 | dev = p2p_get_device(p2p, addr); | |
4200 | if (!dev) | |
4201 | return NULL; | |
4202 | ||
4203 | if (!next) { | |
4204 | if (dev->flags & P2P_DEV_PROBE_REQ_ONLY) | |
4205 | return NULL; | |
4206 | ||
4207 | return &dev->info; | |
4208 | } else { | |
4209 | do { | |
4210 | dev = dl_list_first(&dev->list, | |
4211 | struct p2p_device, | |
4212 | list); | |
0bceb8d6 | 4213 | if (!dev || &dev->list == &p2p->devices) |
c165d81e JB |
4214 | return NULL; |
4215 | } while (dev->flags & P2P_DEV_PROBE_REQ_ONLY); | |
4216 | } | |
4217 | } else { | |
4218 | dev = dl_list_first(&p2p->devices, struct p2p_device, list); | |
4219 | if (!dev) | |
4220 | return NULL; | |
4221 | while (dev->flags & P2P_DEV_PROBE_REQ_ONLY) { | |
4222 | dev = dl_list_first(&dev->list, | |
4223 | struct p2p_device, | |
4224 | list); | |
0bceb8d6 | 4225 | if (!dev || &dev->list == &p2p->devices) |
c165d81e JB |
4226 | return NULL; |
4227 | } | |
4228 | } | |
4229 | ||
4230 | return &dev->info; | |
4231 | } | |
303f60d3 JM |
4232 | |
4233 | ||
4234 | int p2p_in_progress(struct p2p_data *p2p) | |
4235 | { | |
4236 | if (p2p == NULL) | |
4237 | return 0; | |
1b5d4714 | 4238 | if (p2p->state == P2P_SEARCH) |
99fcd404 | 4239 | return 2; |
fc6997b3 | 4240 | return p2p->state != P2P_IDLE && p2p->state != P2P_PROVISIONING; |
303f60d3 | 4241 | } |
4f219667 JM |
4242 | |
4243 | ||
4244 | void p2p_set_config_timeout(struct p2p_data *p2p, u8 go_timeout, | |
4245 | u8 client_timeout) | |
4246 | { | |
4247 | if (p2p) { | |
4248 | p2p->go_timeout = go_timeout; | |
4249 | p2p->client_timeout = client_timeout; | |
4250 | } | |
4251 | } | |
99fcd404 JM |
4252 | |
4253 | ||
9675ce35 JM |
4254 | #ifdef CONFIG_WIFI_DISPLAY |
4255 | ||
4256 | static void p2p_update_wfd_ie_groups(struct p2p_data *p2p) | |
4257 | { | |
4258 | size_t g; | |
4259 | struct p2p_group *group; | |
4260 | ||
4261 | for (g = 0; g < p2p->num_groups; g++) { | |
4262 | group = p2p->groups[g]; | |
3342c263 | 4263 | p2p_group_force_beacon_update_ies(group); |
9675ce35 JM |
4264 | } |
4265 | } | |
4266 | ||
4267 | ||
4268 | int p2p_set_wfd_ie_beacon(struct p2p_data *p2p, struct wpabuf *ie) | |
4269 | { | |
4270 | wpabuf_free(p2p->wfd_ie_beacon); | |
4271 | p2p->wfd_ie_beacon = ie; | |
4272 | p2p_update_wfd_ie_groups(p2p); | |
4273 | return 0; | |
4274 | } | |
4275 | ||
4276 | ||
4277 | int p2p_set_wfd_ie_probe_req(struct p2p_data *p2p, struct wpabuf *ie) | |
4278 | { | |
4279 | wpabuf_free(p2p->wfd_ie_probe_req); | |
4280 | p2p->wfd_ie_probe_req = ie; | |
4281 | return 0; | |
4282 | } | |
4283 | ||
4284 | ||
4285 | int p2p_set_wfd_ie_probe_resp(struct p2p_data *p2p, struct wpabuf *ie) | |
4286 | { | |
4287 | wpabuf_free(p2p->wfd_ie_probe_resp); | |
4288 | p2p->wfd_ie_probe_resp = ie; | |
4289 | p2p_update_wfd_ie_groups(p2p); | |
4290 | return 0; | |
4291 | } | |
4292 | ||
4293 | ||
4294 | int p2p_set_wfd_ie_assoc_req(struct p2p_data *p2p, struct wpabuf *ie) | |
4295 | { | |
4296 | wpabuf_free(p2p->wfd_ie_assoc_req); | |
4297 | p2p->wfd_ie_assoc_req = ie; | |
4298 | return 0; | |
4299 | } | |
4300 | ||
4301 | ||
4302 | int p2p_set_wfd_ie_invitation(struct p2p_data *p2p, struct wpabuf *ie) | |
4303 | { | |
4304 | wpabuf_free(p2p->wfd_ie_invitation); | |
4305 | p2p->wfd_ie_invitation = ie; | |
4306 | return 0; | |
4307 | } | |
4308 | ||
4309 | ||
4310 | int p2p_set_wfd_ie_prov_disc_req(struct p2p_data *p2p, struct wpabuf *ie) | |
4311 | { | |
4312 | wpabuf_free(p2p->wfd_ie_prov_disc_req); | |
4313 | p2p->wfd_ie_prov_disc_req = ie; | |
4314 | return 0; | |
4315 | } | |
4316 | ||
4317 | ||
4318 | int p2p_set_wfd_ie_prov_disc_resp(struct p2p_data *p2p, struct wpabuf *ie) | |
4319 | { | |
4320 | wpabuf_free(p2p->wfd_ie_prov_disc_resp); | |
4321 | p2p->wfd_ie_prov_disc_resp = ie; | |
4322 | return 0; | |
4323 | } | |
4324 | ||
4325 | ||
4326 | int p2p_set_wfd_ie_go_neg(struct p2p_data *p2p, struct wpabuf *ie) | |
4327 | { | |
4328 | wpabuf_free(p2p->wfd_ie_go_neg); | |
4329 | p2p->wfd_ie_go_neg = ie; | |
4330 | return 0; | |
4331 | } | |
4332 | ||
4333 | ||
4334 | int p2p_set_wfd_dev_info(struct p2p_data *p2p, const struct wpabuf *elem) | |
4335 | { | |
4336 | wpabuf_free(p2p->wfd_dev_info); | |
4337 | if (elem) { | |
4338 | p2p->wfd_dev_info = wpabuf_dup(elem); | |
4339 | if (p2p->wfd_dev_info == NULL) | |
4340 | return -1; | |
4341 | } else | |
4342 | p2p->wfd_dev_info = NULL; | |
4343 | ||
4344 | return 0; | |
4345 | } | |
4346 | ||
4347 | ||
4348 | int p2p_set_wfd_assoc_bssid(struct p2p_data *p2p, const struct wpabuf *elem) | |
4349 | { | |
4350 | wpabuf_free(p2p->wfd_assoc_bssid); | |
4351 | if (elem) { | |
4352 | p2p->wfd_assoc_bssid = wpabuf_dup(elem); | |
4353 | if (p2p->wfd_assoc_bssid == NULL) | |
4354 | return -1; | |
4355 | } else | |
4356 | p2p->wfd_assoc_bssid = NULL; | |
4357 | ||
4358 | return 0; | |
4359 | } | |
4360 | ||
4361 | ||
4362 | int p2p_set_wfd_coupled_sink_info(struct p2p_data *p2p, | |
4363 | const struct wpabuf *elem) | |
4364 | { | |
4365 | wpabuf_free(p2p->wfd_coupled_sink_info); | |
4366 | if (elem) { | |
4367 | p2p->wfd_coupled_sink_info = wpabuf_dup(elem); | |
4368 | if (p2p->wfd_coupled_sink_info == NULL) | |
4369 | return -1; | |
4370 | } else | |
4371 | p2p->wfd_coupled_sink_info = NULL; | |
4372 | ||
4373 | return 0; | |
4374 | } | |
4375 | ||
4376 | #endif /* CONFIG_WIFI_DISPLAY */ | |
96beff11 JM |
4377 | |
4378 | ||
4379 | int p2p_set_disc_int(struct p2p_data *p2p, int min_disc_int, int max_disc_int, | |
4380 | int max_disc_tu) | |
4381 | { | |
4382 | if (min_disc_int > max_disc_int || min_disc_int < 0 || max_disc_int < 0) | |
4383 | return -1; | |
4384 | ||
4385 | p2p->min_disc_int = min_disc_int; | |
4386 | p2p->max_disc_int = max_disc_int; | |
4387 | p2p->max_disc_tu = max_disc_tu; | |
ed496f13 JM |
4388 | p2p_dbg(p2p, "Set discoverable interval: min=%d max=%d max_tu=%d", |
4389 | min_disc_int, max_disc_int, max_disc_tu); | |
96beff11 JM |
4390 | |
4391 | return 0; | |
4392 | } | |
ed496f13 JM |
4393 | |
4394 | ||
4395 | void p2p_dbg(struct p2p_data *p2p, const char *fmt, ...) | |
4396 | { | |
4397 | va_list ap; | |
4398 | char buf[500]; | |
4399 | ||
4400 | if (!p2p->cfg->debug_print) | |
4401 | return; | |
4402 | ||
4403 | va_start(ap, fmt); | |
4404 | vsnprintf(buf, sizeof(buf), fmt, ap); | |
4405 | buf[sizeof(buf) - 1] = '\0'; | |
4406 | va_end(ap); | |
4407 | p2p->cfg->debug_print(p2p->cfg->cb_ctx, MSG_DEBUG, buf); | |
4408 | } | |
4409 | ||
4410 | ||
4411 | void p2p_info(struct p2p_data *p2p, const char *fmt, ...) | |
4412 | { | |
4413 | va_list ap; | |
4414 | char buf[500]; | |
4415 | ||
4416 | if (!p2p->cfg->debug_print) | |
4417 | return; | |
4418 | ||
4419 | va_start(ap, fmt); | |
4420 | vsnprintf(buf, sizeof(buf), fmt, ap); | |
4421 | buf[sizeof(buf) - 1] = '\0'; | |
4422 | va_end(ap); | |
4423 | p2p->cfg->debug_print(p2p->cfg->cb_ctx, MSG_INFO, buf); | |
4424 | } | |
4425 | ||
4426 | ||
4427 | void p2p_err(struct p2p_data *p2p, const char *fmt, ...) | |
4428 | { | |
4429 | va_list ap; | |
4430 | char buf[500]; | |
4431 | ||
4432 | if (!p2p->cfg->debug_print) | |
4433 | return; | |
4434 | ||
4435 | va_start(ap, fmt); | |
4436 | vsnprintf(buf, sizeof(buf), fmt, ap); | |
4437 | buf[sizeof(buf) - 1] = '\0'; | |
4438 | va_end(ap); | |
4439 | p2p->cfg->debug_print(p2p->cfg->cb_ctx, MSG_ERROR, buf); | |
4440 | } | |
93588780 JM |
4441 | |
4442 | ||
4443 | #ifdef CONFIG_WPS_NFC | |
4444 | ||
59b45d1a | 4445 | static struct wpabuf * p2p_build_nfc_handover(struct p2p_data *p2p, |
abe44e3c JM |
4446 | int client_freq, |
4447 | const u8 *go_dev_addr, | |
4448 | const u8 *ssid, size_t ssid_len) | |
93588780 JM |
4449 | { |
4450 | struct wpabuf *buf; | |
4451 | u8 op_class, channel; | |
4452 | enum p2p_role_indication role = P2P_DEVICE_NOT_IN_GROUP; | |
4453 | ||
4454 | buf = wpabuf_alloc(1000); | |
4455 | if (buf == NULL) | |
4456 | return NULL; | |
4457 | ||
4458 | op_class = p2p->cfg->reg_class; | |
4459 | channel = p2p->cfg->channel; | |
4460 | ||
4461 | p2p_buf_add_capability(buf, p2p->dev_capab & | |
4462 | ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY, 0); | |
4463 | p2p_buf_add_device_info(buf, p2p, NULL); | |
4464 | ||
4465 | if (p2p->num_groups > 0) { | |
d06e9ac5 | 4466 | int freq = p2p_group_get_freq(p2p->groups[0]); |
93588780 | 4467 | role = P2P_GO_IN_A_GROUP; |
d06e9ac5 JM |
4468 | if (p2p_freq_to_channel(freq, &op_class, &channel) < 0) { |
4469 | p2p_dbg(p2p, | |
4470 | "Unknown GO operating frequency %d MHz for NFC handover", | |
4471 | freq); | |
4472 | wpabuf_free(buf); | |
4473 | return NULL; | |
4474 | } | |
59b45d1a JM |
4475 | } else if (client_freq > 0) { |
4476 | role = P2P_CLIENT_IN_A_GROUP; | |
d06e9ac5 JM |
4477 | if (p2p_freq_to_channel(client_freq, &op_class, &channel) < 0) { |
4478 | p2p_dbg(p2p, | |
4479 | "Unknown client operating frequency %d MHz for NFC handover", | |
4480 | client_freq); | |
4481 | wpabuf_free(buf); | |
4482 | return NULL; | |
4483 | } | |
93588780 JM |
4484 | } |
4485 | ||
4486 | p2p_buf_add_oob_go_neg_channel(buf, p2p->cfg->country, op_class, | |
4487 | channel, role); | |
4488 | ||
4489 | if (p2p->num_groups > 0) { | |
4490 | /* Limit number of clients to avoid very long message */ | |
4491 | p2p_buf_add_group_info(p2p->groups[0], buf, 5); | |
4492 | p2p_group_buf_add_id(p2p->groups[0], buf); | |
abe44e3c JM |
4493 | } else if (client_freq > 0 && |
4494 | go_dev_addr && !is_zero_ether_addr(go_dev_addr) && | |
4495 | ssid && ssid_len > 0) { | |
4496 | /* | |
4497 | * Add the optional P2P Group ID to indicate in which group this | |
4498 | * device is a P2P Client. | |
4499 | */ | |
4500 | p2p_buf_add_group_id(buf, go_dev_addr, ssid, ssid_len); | |
93588780 JM |
4501 | } |
4502 | ||
4503 | return buf; | |
4504 | } | |
4505 | ||
4506 | ||
59b45d1a | 4507 | struct wpabuf * p2p_build_nfc_handover_req(struct p2p_data *p2p, |
abe44e3c JM |
4508 | int client_freq, |
4509 | const u8 *go_dev_addr, | |
4510 | const u8 *ssid, size_t ssid_len) | |
93588780 | 4511 | { |
abe44e3c JM |
4512 | return p2p_build_nfc_handover(p2p, client_freq, go_dev_addr, ssid, |
4513 | ssid_len); | |
93588780 JM |
4514 | } |
4515 | ||
4516 | ||
59b45d1a | 4517 | struct wpabuf * p2p_build_nfc_handover_sel(struct p2p_data *p2p, |
abe44e3c JM |
4518 | int client_freq, |
4519 | const u8 *go_dev_addr, | |
4520 | const u8 *ssid, size_t ssid_len) | |
93588780 | 4521 | { |
abe44e3c JM |
4522 | return p2p_build_nfc_handover(p2p, client_freq, go_dev_addr, ssid, |
4523 | ssid_len); | |
93588780 JM |
4524 | } |
4525 | ||
db6ae69e JM |
4526 | |
4527 | int p2p_process_nfc_connection_handover(struct p2p_data *p2p, | |
4528 | struct p2p_nfc_params *params) | |
4529 | { | |
4530 | struct p2p_message msg; | |
4531 | struct p2p_device *dev; | |
4532 | const u8 *p2p_dev_addr; | |
59b45d1a JM |
4533 | int freq; |
4534 | enum p2p_role_indication role; | |
db6ae69e JM |
4535 | |
4536 | params->next_step = NO_ACTION; | |
4537 | ||
4538 | if (p2p_parse_ies_separate(params->wsc_attr, params->wsc_len, | |
4539 | params->p2p_attr, params->p2p_len, &msg)) { | |
4540 | p2p_dbg(p2p, "Failed to parse WSC/P2P attributes from NFC"); | |
4541 | p2p_parse_free(&msg); | |
4542 | return -1; | |
4543 | } | |
4544 | ||
4545 | if (msg.p2p_device_addr) | |
4546 | p2p_dev_addr = msg.p2p_device_addr; | |
4547 | else if (msg.device_id) | |
4548 | p2p_dev_addr = msg.device_id; | |
4549 | else { | |
4550 | p2p_dbg(p2p, "Ignore scan data without P2P Device Info or P2P Device Id"); | |
4551 | p2p_parse_free(&msg); | |
4552 | return -1; | |
4553 | } | |
4554 | ||
4555 | if (msg.oob_dev_password) { | |
4556 | os_memcpy(params->oob_dev_pw, msg.oob_dev_password, | |
4557 | msg.oob_dev_password_len); | |
4558 | params->oob_dev_pw_len = msg.oob_dev_password_len; | |
4559 | } | |
4560 | ||
4561 | dev = p2p_create_device(p2p, p2p_dev_addr); | |
4562 | if (dev == NULL) { | |
4563 | p2p_parse_free(&msg); | |
4564 | return -1; | |
4565 | } | |
4566 | ||
4567 | params->peer = &dev->info; | |
4568 | ||
4569 | os_get_reltime(&dev->last_seen); | |
4570 | dev->flags &= ~(P2P_DEV_PROBE_REQ_ONLY | P2P_DEV_GROUP_CLIENT_ONLY); | |
4571 | p2p_copy_wps_info(p2p, dev, 0, &msg); | |
4572 | ||
59b45d1a JM |
4573 | if (!msg.oob_go_neg_channel) { |
4574 | p2p_dbg(p2p, "OOB GO Negotiation Channel attribute not included"); | |
4575 | return -1; | |
4576 | } | |
db6ae69e | 4577 | |
59b45d1a JM |
4578 | if (msg.oob_go_neg_channel[3] == 0 && |
4579 | msg.oob_go_neg_channel[4] == 0) | |
4580 | freq = 0; | |
4581 | else | |
4582 | freq = p2p_channel_to_freq(msg.oob_go_neg_channel[3], | |
4583 | msg.oob_go_neg_channel[4]); | |
4584 | if (freq < 0) { | |
4585 | p2p_dbg(p2p, "Unknown peer OOB GO Neg channel"); | |
4586 | return -1; | |
59b45d1a | 4587 | } |
23318bea | 4588 | role = msg.oob_go_neg_channel[5]; |
db6ae69e | 4589 | |
23318bea JM |
4590 | if (role == P2P_GO_IN_A_GROUP) { |
4591 | p2p_dbg(p2p, "Peer OOB GO operating channel: %u MHz", freq); | |
4592 | params->go_freq = freq; | |
abe44e3c JM |
4593 | } else if (role == P2P_CLIENT_IN_A_GROUP) { |
4594 | p2p_dbg(p2p, "Peer (client) OOB GO operating channel: %u MHz", | |
4595 | freq); | |
4596 | params->go_freq = freq; | |
23318bea JM |
4597 | } else |
4598 | p2p_dbg(p2p, "Peer OOB GO Neg channel: %u MHz", freq); | |
4599 | dev->oob_go_neg_freq = freq; | |
4600 | ||
4601 | if (!params->sel && role != P2P_GO_IN_A_GROUP) { | |
59b45d1a JM |
4602 | freq = p2p_channel_to_freq(p2p->cfg->reg_class, |
4603 | p2p->cfg->channel); | |
4604 | if (freq < 0) { | |
4605 | p2p_dbg(p2p, "Own listen channel not known"); | |
4606 | return -1; | |
4607 | } | |
4608 | p2p_dbg(p2p, "Use own Listen channel as OOB GO Neg channel: %u MHz", freq); | |
4609 | dev->oob_go_neg_freq = freq; | |
db6ae69e JM |
4610 | } |
4611 | ||
23318bea JM |
4612 | if (msg.group_id) { |
4613 | os_memcpy(params->go_dev_addr, msg.group_id, ETH_ALEN); | |
4614 | params->go_ssid_len = msg.group_id_len - ETH_ALEN; | |
4615 | os_memcpy(params->go_ssid, msg.group_id + ETH_ALEN, | |
4616 | params->go_ssid_len); | |
4617 | } | |
59b45d1a | 4618 | |
db6ae69e JM |
4619 | p2p_parse_free(&msg); |
4620 | ||
4621 | if (dev->flags & P2P_DEV_USER_REJECTED) { | |
4622 | p2p_dbg(p2p, "Do not report rejected device"); | |
4623 | return 0; | |
4624 | } | |
4625 | ||
4626 | if (!(dev->flags & P2P_DEV_REPORTED)) { | |
4627 | p2p->cfg->dev_found(p2p->cfg->cb_ctx, p2p_dev_addr, &dev->info, | |
4628 | !(dev->flags & P2P_DEV_REPORTED_ONCE)); | |
4629 | dev->flags |= P2P_DEV_REPORTED | P2P_DEV_REPORTED_ONCE; | |
4630 | } | |
4631 | ||
59b45d1a | 4632 | if (role == P2P_GO_IN_A_GROUP && p2p->num_groups > 0) |
74df9ecd | 4633 | params->next_step = BOTH_GO; |
59b45d1a | 4634 | else if (role == P2P_GO_IN_A_GROUP) |
db6ae69e | 4635 | params->next_step = JOIN_GROUP; |
59b45d1a JM |
4636 | else if (role == P2P_CLIENT_IN_A_GROUP) { |
4637 | dev->flags |= P2P_DEV_GROUP_CLIENT_ONLY; | |
4638 | params->next_step = PEER_CLIENT; | |
4639 | } else if (p2p->num_groups > 0) | |
db6ae69e JM |
4640 | params->next_step = AUTH_JOIN; |
4641 | else if (params->sel) | |
4642 | params->next_step = INIT_GO_NEG; | |
4643 | else | |
4644 | params->next_step = RESP_GO_NEG; | |
4645 | ||
4646 | return 0; | |
4647 | } | |
4648 | ||
c4f87a70 JM |
4649 | |
4650 | void p2p_set_authorized_oob_dev_pw_id(struct p2p_data *p2p, u16 dev_pw_id, | |
4651 | int go_intent, | |
4652 | const u8 *own_interface_addr) | |
4653 | { | |
4654 | ||
4655 | p2p->authorized_oob_dev_pw_id = dev_pw_id; | |
4656 | if (dev_pw_id == 0) { | |
4657 | p2p_dbg(p2p, "NFC OOB Password unauthorized for static handover"); | |
4658 | return; | |
4659 | } | |
4660 | ||
4661 | p2p_dbg(p2p, "NFC OOB Password (id=%u) authorized for static handover", | |
4662 | dev_pw_id); | |
4663 | ||
4664 | p2p->go_intent = go_intent; | |
4665 | os_memcpy(p2p->intended_addr, own_interface_addr, ETH_ALEN); | |
4666 | } | |
4667 | ||
93588780 | 4668 | #endif /* CONFIG_WPS_NFC */ |