]>
Commit | Line | Data |
---|---|---|
b22128ef JM |
1 | /* |
2 | * Wi-Fi Direct - P2P module | |
3 | * Copyright (c) 2009-2010, Atheros Communications | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License version 2 as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * Alternatively, this software may be distributed under the terms of BSD | |
10 | * license. | |
11 | * | |
12 | * See README and COPYING for more details. | |
13 | */ | |
14 | ||
15 | #ifndef P2P_H | |
16 | #define P2P_H | |
17 | ||
18 | /** | |
19 | * P2P_MAX_REG_CLASSES - Maximum number of regulatory classes | |
20 | */ | |
21 | #define P2P_MAX_REG_CLASSES 10 | |
22 | ||
23 | /** | |
24 | * P2P_MAX_REG_CLASS_CHANNELS - Maximum number of channels per regulatory class | |
25 | */ | |
26 | #define P2P_MAX_REG_CLASS_CHANNELS 20 | |
27 | ||
28 | /** | |
29 | * struct p2p_channels - List of supported channels | |
30 | */ | |
31 | struct p2p_channels { | |
32 | /** | |
33 | * struct p2p_reg_class - Supported regulatory class | |
34 | */ | |
35 | struct p2p_reg_class { | |
36 | /** | |
37 | * reg_class - Regulatory class (IEEE 802.11-2007, Annex J) | |
38 | */ | |
39 | u8 reg_class; | |
40 | ||
41 | /** | |
42 | * channel - Supported channels | |
43 | */ | |
44 | u8 channel[P2P_MAX_REG_CLASS_CHANNELS]; | |
45 | ||
46 | /** | |
47 | * channels - Number of channel entries in use | |
48 | */ | |
49 | size_t channels; | |
50 | } reg_class[P2P_MAX_REG_CLASSES]; | |
51 | ||
52 | /** | |
53 | * reg_classes - Number of reg_class entries in use | |
54 | */ | |
55 | size_t reg_classes; | |
56 | }; | |
57 | ||
58 | enum p2p_wps_method { | |
59 | WPS_NOT_READY, WPS_PIN_LABEL, WPS_PIN_DISPLAY, WPS_PIN_KEYPAD, WPS_PBC | |
60 | }; | |
61 | ||
62 | /** | |
63 | * struct p2p_go_neg_results - P2P Group Owner Negotiation results | |
64 | */ | |
65 | struct p2p_go_neg_results { | |
66 | /** | |
67 | * status - Negotiation result (Status Code) | |
68 | * | |
69 | * 0 (P2P_SC_SUCCESS) indicates success. Non-zero values indicate | |
70 | * failed negotiation. | |
71 | */ | |
72 | int status; | |
73 | ||
74 | /** | |
75 | * role_go - Whether local end is Group Owner | |
76 | */ | |
77 | int role_go; | |
78 | ||
79 | /** | |
80 | * freq - Frequency of the group operational channel in MHz | |
81 | */ | |
82 | int freq; | |
83 | ||
84 | /** | |
85 | * ssid - SSID of the group | |
86 | */ | |
87 | u8 ssid[32]; | |
88 | ||
89 | /** | |
90 | * ssid_len - Length of SSID in octets | |
91 | */ | |
92 | size_t ssid_len; | |
93 | ||
94 | /** | |
95 | * passphrase - WPA2-Personal passphrase for the group (GO only) | |
96 | */ | |
97 | char passphrase[64]; | |
98 | ||
99 | /** | |
100 | * peer_device_addr - P2P Device Address of the peer | |
101 | */ | |
102 | u8 peer_device_addr[ETH_ALEN]; | |
103 | ||
104 | /** | |
105 | * peer_interface_addr - P2P Interface Address of the peer | |
106 | */ | |
107 | u8 peer_interface_addr[ETH_ALEN]; | |
108 | ||
109 | /** | |
110 | * wps_method - WPS method to be used during provisioning | |
111 | */ | |
112 | enum p2p_wps_method wps_method; | |
113 | ||
114 | #define P2P_MAX_CHANNELS 50 | |
115 | ||
116 | /** | |
117 | * freq_list - Zero-terminated list of possible operational channels | |
118 | */ | |
119 | int freq_list[P2P_MAX_CHANNELS]; | |
120 | ||
121 | /** | |
122 | * persistent_group - Whether the group should be made persistent | |
123 | */ | |
124 | int persistent_group; | |
ae3e3421 JM |
125 | |
126 | /** | |
127 | * peer_config_timeout - Peer configuration timeout (in 10 msec units) | |
128 | */ | |
129 | unsigned int peer_config_timeout; | |
b22128ef JM |
130 | }; |
131 | ||
132 | struct p2p_data; | |
133 | ||
134 | enum p2p_scan_type { | |
135 | P2P_SCAN_SOCIAL, | |
136 | P2P_SCAN_FULL, | |
137 | P2P_SCAN_SPECIFIC, | |
138 | P2P_SCAN_SOCIAL_PLUS_ONE | |
139 | }; | |
140 | ||
141 | /** | |
142 | * struct p2p_config - P2P configuration | |
143 | * | |
144 | * This configuration is provided to the P2P module during initialization with | |
145 | * p2p_init(). | |
146 | */ | |
147 | struct p2p_config { | |
148 | /** | |
149 | * country - Country code to use in P2P operations | |
150 | */ | |
151 | char country[3]; | |
152 | ||
153 | /** | |
154 | * reg_class - Regulatory class for own listen channel | |
155 | */ | |
156 | u8 reg_class; | |
157 | ||
158 | /** | |
159 | * channel - Own listen channel | |
160 | */ | |
161 | u8 channel; | |
162 | ||
163 | /** | |
164 | * Regulatory class for own operational channel | |
165 | */ | |
166 | u8 op_reg_class; | |
167 | ||
168 | /** | |
169 | * op_channel - Own operational channel | |
170 | */ | |
171 | u8 op_channel; | |
172 | ||
173 | /** | |
174 | * channels - Own supported regulatory classes and channels | |
175 | * | |
176 | * List of supposerted channels per regulatory class. The regulatory | |
177 | * classes are defined in IEEE Std 802.11-2007 Annex J and the | |
178 | * numbering of the clases depends on the configured country code. | |
179 | */ | |
180 | struct p2p_channels channels; | |
181 | ||
182 | /** | |
183 | * pri_dev_type - Primary Device Type (see WPS) | |
184 | */ | |
185 | u8 pri_dev_type[8]; | |
186 | ||
187 | /** | |
188 | * P2P_SEC_DEVICE_TYPES - Maximum number of secondary device types | |
189 | */ | |
190 | #define P2P_SEC_DEVICE_TYPES 5 | |
191 | ||
192 | /** | |
193 | * sec_dev_type - Optional secondary device types | |
194 | */ | |
195 | u8 sec_dev_type[P2P_SEC_DEVICE_TYPES][8]; | |
196 | ||
197 | /** | |
198 | * dev_addr - P2P Device Address | |
199 | */ | |
200 | u8 dev_addr[ETH_ALEN]; | |
201 | ||
202 | /** | |
203 | * dev_name - Device Name | |
204 | */ | |
205 | char *dev_name; | |
206 | ||
207 | /** | |
208 | * num_sec_dev_types - Number of sec_dev_type entries | |
209 | */ | |
210 | size_t num_sec_dev_types; | |
211 | ||
212 | /** | |
213 | * concurrent_operations - Whether concurrent operations are supported | |
214 | */ | |
215 | int concurrent_operations; | |
216 | ||
217 | /** | |
218 | * max_peers - Maximum number of discovered peers to remember | |
219 | * | |
220 | * If more peers are discovered, older entries will be removed to make | |
221 | * room for the new ones. | |
222 | */ | |
223 | size_t max_peers; | |
224 | ||
0f66abd2 SS |
225 | /** |
226 | * p2p_intra_bss - Intra BSS communication is supported | |
227 | */ | |
228 | int p2p_intra_bss; | |
229 | ||
b22128ef JM |
230 | /** |
231 | * ssid_postfix - Postfix data to add to the SSID | |
232 | * | |
233 | * This data will be added to the end of the SSID after the | |
234 | * DIRECT-<random two octets> prefix. | |
235 | */ | |
236 | u8 ssid_postfix[32 - 9]; | |
237 | ||
238 | /** | |
239 | * ssid_postfix_len - Length of the ssid_postfix data | |
240 | */ | |
241 | size_t ssid_postfix_len; | |
242 | ||
243 | /** | |
244 | * msg_ctx - Context to use with wpa_msg() calls | |
245 | */ | |
246 | void *msg_ctx; | |
247 | ||
248 | /** | |
249 | * cb_ctx - Context to use with callback functions | |
250 | */ | |
251 | void *cb_ctx; | |
252 | ||
253 | ||
254 | /* Callbacks to request lower layer driver operations */ | |
255 | ||
256 | /** | |
257 | * p2p_scan - Request a P2P scan/search | |
258 | * @ctx: Callback context from cb_ctx | |
259 | * @type: Scan type | |
260 | * @freq: Specific frequency (MHz) to scan or 0 for no restriction | |
261 | * Returns: 0 on success, -1 on failure | |
262 | * | |
263 | * This callback function is used to request a P2P scan or search | |
264 | * operation to be completed. Type type argument specifies which type | |
265 | * of scan is to be done. @P2P_SCAN_SOCIAL indicates that only the | |
266 | * social channels (1, 6, 11) should be scanned. @P2P_SCAN_FULL | |
267 | * indicates that all channels are to be scanned. @P2P_SCAN_SPECIFIC | |
268 | * request a scan of a single channel specified by freq. | |
269 | * @P2P_SCAN_SOCIAL_PLUS_ONE request scan of all the social channels | |
270 | * plus one extra channel specified by freq. | |
271 | * | |
272 | * The full scan is used for the initial scan to find group owners from | |
273 | * all. The other types are used during search phase scan of the social | |
274 | * channels (with potential variation if the Listen channel of the | |
275 | * target peer is known or if other channels are scanned in steps). | |
276 | * | |
277 | * The scan results are returned after this call by calling | |
278 | * p2p_scan_res_handler() for each scan result that has a P2P IE and | |
279 | * then calling p2p_scan_res_handled() to indicate that all scan | |
280 | * results have been indicated. | |
281 | */ | |
282 | int (*p2p_scan)(void *ctx, enum p2p_scan_type type, int freq); | |
283 | ||
284 | /** | |
285 | * send_probe_resp - Transmit a Probe Response frame | |
286 | * @ctx: Callback context from cb_ctx | |
287 | * @buf: Probe Response frame (including the header and body) | |
288 | * Returns: 0 on success, -1 on failure | |
289 | * | |
290 | * This function is used to reply to Probe Request frames that were | |
291 | * indicated with a call to p2p_probe_req_rx(). The response is to be | |
292 | * sent on the same channel or to be dropped if the driver is not | |
293 | * anymore listening to Probe Request frames. | |
294 | * | |
295 | * Alternatively, the responsibility for building the Probe Response | |
296 | * frames in Listen state may be in another system component in which | |
297 | * case this function need to be implemented (i.e., the function | |
298 | * pointer can be %NULL). The WPS and P2P IEs to be added for Probe | |
299 | * Response frames in such a case are available from the | |
300 | * start_listen() callback. It should be noted that the received Probe | |
301 | * Request frames must be indicated by calling p2p_probe_req_rx() even | |
302 | * if this send_probe_resp() is not used. | |
303 | */ | |
304 | int (*send_probe_resp)(void *ctx, const struct wpabuf *buf); | |
305 | ||
306 | /** | |
307 | * send_action - Transmit an Action frame | |
308 | * @ctx: Callback context from cb_ctx | |
309 | * @freq: Frequency in MHz for the channel on which to transmit | |
310 | * @dst: Destination MAC address (Address 1) | |
311 | * @src: Source MAC address (Address 2) | |
312 | * @bssid: BSSID (Address 3) | |
313 | * @buf: Frame body (starting from Category field) | |
314 | * @len: Length of buf in octets | |
315 | * @wait_time: How many msec to wait for a response frame | |
316 | * Returns: 0 on success, -1 on failure | |
317 | * | |
318 | * The Action frame may not be transmitted immediately and the status | |
319 | * of the transmission must be reported by calling | |
320 | * p2p_send_action_cb() once the frame has either been transmitted or | |
321 | * it has been dropped due to excessive retries or other failure to | |
322 | * transmit. | |
323 | */ | |
324 | int (*send_action)(void *ctx, unsigned int freq, const u8 *dst, | |
325 | const u8 *src, const u8 *bssid, const u8 *buf, | |
326 | size_t len, unsigned int wait_time); | |
327 | ||
328 | /** | |
329 | * send_action_done - Notify that Action frame sequence was completed | |
330 | * @ctx: Callback context from cb_ctx | |
331 | * | |
332 | * This function is called when the Action frame sequence that was | |
333 | * started with send_action() has been completed, i.e., when there is | |
334 | * no need to wait for a response from the destination peer anymore. | |
335 | */ | |
336 | void (*send_action_done)(void *ctx); | |
337 | ||
338 | /** | |
339 | * start_listen - Start Listen state | |
340 | * @ctx: Callback context from cb_ctx | |
341 | * @freq: Frequency of the listen channel in MHz | |
342 | * @duration: Duration for the Listen state in milliseconds | |
343 | * @probe_resp_ie: IE(s) to be added to Probe Response frames | |
344 | * Returns: 0 on success, -1 on failure | |
345 | * | |
346 | * This Listen state may not start immediately since the driver may | |
347 | * have other pending operations to complete first. Once the Listen | |
348 | * state has started, p2p_listen_cb() must be called to notify the P2P | |
349 | * module. Once the Listen state is stopped, p2p_listen_end() must be | |
350 | * called to notify the P2P module that the driver is not in the Listen | |
351 | * state anymore. | |
352 | * | |
353 | * If the send_probe_resp() is not used for generating the response, | |
354 | * the IEs from probe_resp_ie need to be added to the end of the Probe | |
355 | * Response frame body. If send_probe_resp() is used, the probe_resp_ie | |
356 | * information can be ignored. | |
357 | */ | |
358 | int (*start_listen)(void *ctx, unsigned int freq, | |
359 | unsigned int duration, | |
360 | const struct wpabuf *probe_resp_ie); | |
361 | /** | |
362 | * stop_listen - Stop Listen state | |
363 | * @ctx: Callback context from cb_ctx | |
364 | * | |
365 | * This callback can be used to stop a Listen state operation that was | |
366 | * previously requested with start_listen(). | |
367 | */ | |
368 | void (*stop_listen)(void *ctx); | |
369 | ||
370 | /** | |
371 | * get_noa - Get current Notice of Absence attribute payload | |
372 | * @ctx: Callback context from cb_ctx | |
373 | * @interface_addr: P2P Interface Address of the GO | |
374 | * @buf: Buffer for returning NoA | |
375 | * @buf_len: Buffer length in octets | |
376 | * Returns: Number of octets used in buf, 0 to indicate no NoA is being | |
377 | * advertized, or -1 on failure | |
378 | * | |
379 | * This function is used to fetch the current Notice of Absence | |
380 | * attribute value from GO. | |
381 | */ | |
382 | int (*get_noa)(void *ctx, const u8 *interface_addr, u8 *buf, | |
383 | size_t buf_len); | |
384 | ||
385 | /* Callbacks to notify events to upper layer management entity */ | |
386 | ||
387 | /** | |
388 | * dev_found - Notification of a found P2P Device | |
389 | * @ctx: Callback context from cb_ctx | |
390 | * @addr: Source address of the message triggering this notification | |
391 | * @dev_addr: P2P Device Address of the found P2P Device | |
392 | * @pri_dev_type: Primary Device Type | |
393 | * @dev_name: Device Name | |
394 | * @config_methods: Configuration Methods | |
395 | * @dev_capab: Device Capabilities | |
396 | * @group_capab: Group Capabilities | |
397 | * | |
398 | * This callback is used to notify that a new P2P Device has been | |
399 | * found. This may happen, e.g., during Search state based on scan | |
400 | * results or during Listen state based on receive Probe Request and | |
401 | * Group Owner Negotiation Request. | |
402 | */ | |
403 | void (*dev_found)(void *ctx, const u8 *addr, const u8 *dev_addr, | |
404 | const u8 *pri_dev_type, const char *dev_name, | |
405 | u16 config_methods, u8 dev_capab, u8 group_capab); | |
406 | ||
407 | /** | |
408 | * go_neg_req_rx - Notification of a receive GO Negotiation Request | |
409 | * @ctx: Callback context from cb_ctx | |
410 | * @src: Source address of the message triggering this notification | |
3dfda83d | 411 | * @dev_passwd_id: WPS Device Password ID |
b22128ef JM |
412 | * |
413 | * This callback is used to notify that a P2P Device is requesting | |
414 | * group owner negotiation with us, but we do not have all the | |
415 | * necessary information to start GO Negotiation. This indicates that | |
416 | * the local user has not authorized the connection yet by providing a | |
417 | * PIN or PBC button press. This information can be provided with a | |
418 | * call to p2p_connect(). | |
419 | */ | |
3dfda83d | 420 | void (*go_neg_req_rx)(void *ctx, const u8 *src, u16 dev_passwd_id); |
b22128ef JM |
421 | |
422 | /** | |
423 | * go_neg_completed - Notification of GO Negotiation results | |
424 | * @ctx: Callback context from cb_ctx | |
425 | * @res: GO Negotiation results | |
426 | * | |
427 | * This callback is used to notify that Group Owner Negotiation has | |
428 | * been completed. Non-zero struct p2p_go_neg_results::status indicates | |
429 | * failed negotiation. In case of success, this function is responsible | |
430 | * for creating a new group interface (or using the existing interface | |
431 | * depending on driver features), setting up the group interface in | |
432 | * proper mode based on struct p2p_go_neg_results::role_go and | |
433 | * initializing WPS provisioning either as a Registrar (if GO) or as an | |
434 | * Enrollee. Successful WPS provisioning must be indicated by calling | |
435 | * p2p_wps_success_cb(). The callee is responsible for timing out group | |
436 | * formation if WPS provisioning cannot be completed successfully | |
437 | * within 15 seconds. | |
438 | */ | |
439 | void (*go_neg_completed)(void *ctx, struct p2p_go_neg_results *res); | |
440 | ||
441 | /** | |
442 | * sd_request - Callback on Service Discovery Request | |
443 | * @ctx: Callback context from cb_ctx | |
444 | * @freq: Frequency (in MHz) of the channel | |
445 | * @sa: Source address of the request | |
446 | * @dialog_token: Dialog token | |
447 | * @update_indic: Service Update Indicator from the source of request | |
448 | * @tlvs: P2P Service Request TLV(s) | |
449 | * @tlvs_len: Length of tlvs buffer in octets | |
450 | * | |
451 | * This callback is used to indicate reception of a service discovery | |
452 | * request. Response to the query must be indicated by calling | |
453 | * p2p_sd_response() with the context information from the arguments to | |
454 | * this callback function. | |
455 | * | |
456 | * This callback handler can be set to %NULL to indicate that service | |
457 | * discovery is not supported. | |
458 | */ | |
459 | void (*sd_request)(void *ctx, int freq, const u8 *sa, u8 dialog_token, | |
460 | u16 update_indic, const u8 *tlvs, size_t tlvs_len); | |
461 | ||
462 | /** | |
463 | * sd_response - Callback on Service Discovery Response | |
464 | * @ctx: Callback context from cb_ctx | |
465 | * @sa: Source address of the request | |
466 | * @update_indic: Service Update Indicator from the source of response | |
467 | * @tlvs: P2P Service Response TLV(s) | |
468 | * @tlvs_len: Length of tlvs buffer in octets | |
469 | * | |
470 | * This callback is used to indicate reception of a service discovery | |
471 | * response. This callback handler can be set to %NULL if no service | |
472 | * discovery requests are used. The information provided with this call | |
473 | * is replies to the queries scheduled with p2p_sd_request(). | |
474 | */ | |
475 | void (*sd_response)(void *ctx, const u8 *sa, u16 update_indic, | |
476 | const u8 *tlvs, size_t tlvs_len); | |
477 | ||
478 | /** | |
479 | * prov_disc_req - Callback on Provisiong Discovery Request | |
480 | * @ctx: Callback context from cb_ctx | |
481 | * @peer: Source address of the request | |
482 | * @config_methods: Requested WPS Config Method | |
483 | * @dev_addr: P2P Device Address of the found P2P Device | |
484 | * @pri_dev_type: Primary Device Type | |
485 | * @dev_name: Device Name | |
486 | * @supp_config_methods: Supported configuration Methods | |
487 | * @dev_capab: Device Capabilities | |
488 | * @group_capab: Group Capabilities | |
489 | * | |
490 | * This callback is used to indicate reception of a Provision Discovery | |
491 | * Request frame that the P2P module accepted. | |
492 | */ | |
493 | void (*prov_disc_req)(void *ctx, const u8 *peer, u16 config_methods, | |
494 | const u8 *dev_addr, const u8 *pri_dev_type, | |
495 | const char *dev_name, u16 supp_config_methods, | |
496 | u8 dev_capab, u8 group_capab); | |
497 | ||
498 | /** | |
499 | * prov_disc_resp - Callback on Provisiong Discovery Response | |
500 | * @ctx: Callback context from cb_ctx | |
501 | * @peer: Source address of the response | |
502 | * @config_methods: Value from p2p_prov_disc_req() or 0 on failure | |
503 | * | |
504 | * This callback is used to indicate reception of a Provision Discovery | |
505 | * Response frame for a pending request scheduled with | |
506 | * p2p_prov_disc_req(). This callback handler can be set to %NULL if | |
507 | * provision discovery is not used. | |
508 | */ | |
509 | void (*prov_disc_resp)(void *ctx, const u8 *peer, u16 config_methods); | |
510 | ||
511 | /** | |
512 | * invitation_process - Optional callback for processing Invitations | |
513 | * @ctx: Callback context from cb_ctx | |
514 | * @sa: Source address of the Invitation Request | |
515 | * @bssid: P2P Group BSSID from the request or %NULL if not included | |
516 | * @go_dev_addr: GO Device Address from P2P Group ID | |
517 | * @ssid: SSID from P2P Group ID | |
518 | * @ssid_len: Length of ssid buffer in octets | |
519 | * @go: Variable for returning whether the local end is GO in the group | |
520 | * @group_bssid: Buffer for returning P2P Group BSSID (if local end GO) | |
521 | * @force_freq: Variable for returning forced frequency for the group | |
522 | * @persistent_group: Whether this is an invitation to reinvoke a | |
523 | * persistent group (instead of invitation to join an active | |
524 | * group) | |
525 | * Returns: Status code (P2P_SC_*) | |
526 | * | |
527 | * This optional callback can be used to implement persistent reconnect | |
528 | * by allowing automatic restarting of persistent groups without user | |
529 | * interaction. If this callback is not implemented (i.e., is %NULL), | |
530 | * the received Invitation Request frames are replied with | |
531 | * %P2P_SC_REQ_RECEIVED status and indicated to upper layer with the | |
532 | * invitation_result() callback. | |
533 | * | |
534 | * If the requested parameters are acceptable and the group is known, | |
535 | * %P2P_SC_SUCCESS may be returned. If the requested group is unknown, | |
536 | * %P2P_SC_FAIL_UNKNOWN_GROUP should be returned. %P2P_SC_REQ_RECEIVED | |
537 | * can be returned if there is not enough data to provide immediate | |
538 | * response, i.e., if some sort of user interaction is needed. The | |
539 | * invitation_received() callback will be called in that case | |
540 | * immediately after this call. | |
541 | */ | |
542 | u8 (*invitation_process)(void *ctx, const u8 *sa, const u8 *bssid, | |
543 | const u8 *go_dev_addr, const u8 *ssid, | |
544 | size_t ssid_len, int *go, u8 *group_bssid, | |
545 | int *force_freq, int persistent_group); | |
546 | ||
547 | /** | |
548 | * invitation_received - Callback on Invitation Request RX | |
549 | * @ctx: Callback context from cb_ctx | |
550 | * @sa: Source address of the Invitation Request | |
551 | * @bssid: P2P Group BSSID or %NULL if not received | |
552 | * @ssid: SSID of the group | |
553 | * @ssid_len: Length of ssid in octets | |
554 | * @go_dev_addr: GO Device Address | |
555 | * @status: Response Status | |
556 | * @op_freq: Operational frequency for the group | |
557 | * | |
558 | * This callback is used to indicate sending of an Invitation Response | |
559 | * for a received Invitation Request. If status == 0 (success), the | |
560 | * upper layer code is responsible for starting the group. status == 1 | |
561 | * indicates need to get user authorization for the group. Other status | |
562 | * values indicate that the invitation request was rejected. | |
563 | */ | |
564 | void (*invitation_received)(void *ctx, const u8 *sa, const u8 *bssid, | |
565 | const u8 *ssid, size_t ssid_len, | |
566 | const u8 *go_dev_addr, u8 status, | |
567 | int op_freq); | |
568 | ||
569 | /** | |
570 | * invitation_result - Callback on Invitation result | |
571 | * @ctx: Callback context from cb_ctx | |
572 | * @status: Negotiation result (Status Code) | |
573 | * @bssid: P2P Group BSSID or %NULL if not received | |
574 | * | |
575 | * This callback is used to indicate result of an Invitation procedure | |
576 | * started with a call to p2p_invite(). The indicated status code is | |
577 | * the value received from the peer in Invitation Response with 0 | |
578 | * (P2P_SC_SUCCESS) indicating success or -1 to indicate a timeout or a | |
579 | * local failure in transmitting the Invitation Request. | |
580 | */ | |
581 | void (*invitation_result)(void *ctx, int status, const u8 *bssid); | |
582 | }; | |
583 | ||
584 | ||
585 | /* P2P module initialization/deinitialization */ | |
586 | ||
587 | /** | |
588 | * p2p_init - Initialize P2P module | |
589 | * @cfg: P2P module configuration | |
590 | * Returns: Pointer to private data or %NULL on failure | |
591 | * | |
592 | * This function is used to initialize global P2P module context (one per | |
593 | * device). The P2P module will keep a copy of the configuration data, so the | |
594 | * caller does not need to maintain this structure. However, the callback | |
595 | * functions and the context parameters to them must be kept available until | |
596 | * the P2P module is deinitialized with p2p_deinit(). | |
597 | */ | |
598 | struct p2p_data * p2p_init(const struct p2p_config *cfg); | |
599 | ||
600 | /** | |
601 | * p2p_deinit - Deinitialize P2P module | |
602 | * @p2p: P2P module context from p2p_init() | |
603 | */ | |
604 | void p2p_deinit(struct p2p_data *p2p); | |
605 | ||
606 | /** | |
607 | * p2p_flush - Flush P2P module state | |
608 | * @p2p: P2P module context from p2p_init() | |
609 | * | |
610 | * This command removes the P2P module state like peer device entries. | |
611 | */ | |
612 | void p2p_flush(struct p2p_data *p2p); | |
613 | ||
614 | /** | |
615 | * p2p_set_dev_name - Set device name | |
616 | * @p2p: P2P module context from p2p_init() | |
617 | * Returns: 0 on success, -1 on failure | |
618 | * | |
619 | * This function can be used to update the P2P module configuration with | |
620 | * information that was not available at the time of the p2p_init() call. | |
621 | */ | |
622 | int p2p_set_dev_name(struct p2p_data *p2p, const char *dev_name); | |
623 | ||
624 | /** | |
625 | * p2p_set_pri_dev_type - Set primary device type | |
626 | * @p2p: P2P module context from p2p_init() | |
627 | * Returns: 0 on success, -1 on failure | |
628 | * | |
629 | * This function can be used to update the P2P module configuration with | |
630 | * information that was not available at the time of the p2p_init() call. | |
631 | */ | |
632 | int p2p_set_pri_dev_type(struct p2p_data *p2p, const u8 *pri_dev_type); | |
633 | ||
634 | /** | |
635 | * p2p_set_sec_dev_types - Set secondary device types | |
636 | * @p2p: P2P module context from p2p_init() | |
637 | * Returns: 0 on success, -1 on failure | |
638 | * | |
639 | * This function can be used to update the P2P module configuration with | |
640 | * information that was not available at the time of the p2p_init() call. | |
641 | */ | |
642 | int p2p_set_sec_dev_types(struct p2p_data *p2p, const u8 dev_types[][8], | |
643 | size_t num_dev_types); | |
644 | ||
645 | int p2p_set_country(struct p2p_data *p2p, const char *country); | |
646 | ||
647 | ||
648 | /* Commands from upper layer management entity */ | |
649 | ||
650 | enum p2p_discovery_type { | |
651 | P2P_FIND_START_WITH_FULL, | |
652 | P2P_FIND_ONLY_SOCIAL, | |
653 | P2P_FIND_PROGRESSIVE | |
654 | }; | |
655 | ||
656 | /** | |
657 | * p2p_find - Start P2P Find (Device Discovery) | |
658 | * @p2p: P2P module context from p2p_init() | |
659 | * @timeout: Timeout for find operation in seconds or 0 for no timeout | |
660 | * @type: Device Discovery type | |
661 | * Returns: 0 on success, -1 on failure | |
662 | */ | |
663 | int p2p_find(struct p2p_data *p2p, unsigned int timeout, | |
664 | enum p2p_discovery_type type); | |
665 | ||
666 | /** | |
667 | * p2p_stop_find - Stop P2P Find (Device Discovery) | |
668 | * @p2p: P2P module context from p2p_init() | |
669 | */ | |
670 | void p2p_stop_find(struct p2p_data *p2p); | |
671 | ||
0b8889d8 JM |
672 | /** |
673 | * p2p_stop_find_for_freq - Stop P2P Find for next oper on specific freq | |
674 | * @p2p: P2P module context from p2p_init() | |
675 | * @freq: Frequency in MHz for next operation | |
676 | * | |
677 | * This is like p2p_stop_find(), but Listen state is not stopped if we are | |
678 | * already on the same frequency. | |
679 | */ | |
680 | void p2p_stop_find_for_freq(struct p2p_data *p2p, int freq); | |
681 | ||
b22128ef JM |
682 | /** |
683 | * p2p_listen - Start P2P Listen state for specified duration | |
684 | * @p2p: P2P module context from p2p_init() | |
685 | * @timeout: Listen state duration in milliseconds | |
686 | * Returns: 0 on success, -1 on failure | |
687 | * | |
688 | * This function can be used to request the P2P module to keep the device | |
689 | * discoverable on the listen channel for an extended set of time. At least in | |
690 | * its current form, this is mainly used for testing purposes and may not be of | |
691 | * much use for normal P2P operations. | |
692 | */ | |
693 | int p2p_listen(struct p2p_data *p2p, unsigned int timeout); | |
694 | ||
695 | /** | |
696 | * p2p_connect - Start P2P group formation (GO negotiation) | |
697 | * @p2p: P2P module context from p2p_init() | |
698 | * @peer_addr: MAC address of the peer P2P client | |
699 | * @wps_method: WPS method to be used in provisioning | |
700 | * @go_intent: Local GO intent value (1..15) | |
701 | * @own_interface_addr: Intended interface address to use with the group | |
702 | * @force_freq: The only allowed channel frequency in MHz or 0 | |
703 | * @persistent_group: Whether to create a persistent group | |
704 | * Returns: 0 on success, -1 on failure | |
705 | */ | |
706 | int p2p_connect(struct p2p_data *p2p, const u8 *peer_addr, | |
707 | enum p2p_wps_method wps_method, | |
708 | int go_intent, const u8 *own_interface_addr, | |
709 | unsigned int force_freq, int persistent_group); | |
710 | ||
711 | /** | |
712 | * p2p_authorize - Authorize P2P group formation (GO negotiation) | |
713 | * @p2p: P2P module context from p2p_init() | |
714 | * @peer_addr: MAC address of the peer P2P client | |
715 | * @wps_method: WPS method to be used in provisioning | |
716 | * @go_intent: Local GO intent value (1..15) | |
717 | * @own_interface_addr: Intended interface address to use with the group | |
718 | * @force_freq: The only allowed channel frequency in MHz or 0 | |
719 | * @persistent_group: Whether to create a persistent group | |
720 | * Returns: 0 on success, -1 on failure | |
721 | * | |
722 | * This is like p2p_connect(), but the actual group negotiation is not | |
723 | * initiated automatically, i.e., the other end is expected to do that. | |
724 | */ | |
725 | int p2p_authorize(struct p2p_data *p2p, const u8 *peer_addr, | |
726 | enum p2p_wps_method wps_method, | |
727 | int go_intent, const u8 *own_interface_addr, | |
728 | unsigned int force_freq, int persistent_group); | |
729 | ||
730 | /** | |
731 | * p2p_reject - Reject peer device (explicitly block connection attempts) | |
732 | * @p2p: P2P module context from p2p_init() | |
733 | * @peer_addr: MAC address of the peer P2P client | |
734 | * Returns: 0 on success, -1 on failure | |
735 | */ | |
736 | int p2p_reject(struct p2p_data *p2p, const u8 *peer_addr); | |
737 | ||
738 | /** | |
739 | * p2p_prov_disc_req - Send Provision Discovery Request | |
740 | * @p2p: P2P module context from p2p_init() | |
741 | * @peer_addr: MAC address of the peer P2P client | |
742 | * @config_methods: WPS Config Methods value (only one bit set) | |
743 | * @join: Whether this is used by a client joining an active group | |
744 | * Returns: 0 on success, -1 on failure | |
745 | * | |
746 | * This function can be used to request a discovered P2P peer to display a PIN | |
747 | * (config_methods = WPS_CONFIG_DISPLAY) or be prepared to enter a PIN from us | |
748 | * (config_methods = WPS_CONFIG_KEYPAD). The Provision Discovery Request frame | |
749 | * is transmitted once immediately and if no response is received, the frame | |
750 | * will be sent again whenever the target device is discovered during device | |
751 | * dsicovery (start with a p2p_find() call). Response from the peer is | |
752 | * indicated with the p2p_config::prov_disc_resp() callback. | |
753 | */ | |
754 | int p2p_prov_disc_req(struct p2p_data *p2p, const u8 *peer_addr, | |
755 | u16 config_methods, int join); | |
756 | ||
757 | /** | |
758 | * p2p_sd_request - Schedule a service discovery query | |
759 | * @p2p: P2P module context from p2p_init() | |
760 | * @dst: Destination peer or %NULL to apply for all peers | |
761 | * @tlvs: P2P Service Query TLV(s) | |
762 | * Returns: Reference to the query or %NULL on failure | |
763 | * | |
764 | * Response to the query is indicated with the p2p_config::sd_response() | |
765 | * callback. | |
766 | */ | |
767 | void * p2p_sd_request(struct p2p_data *p2p, const u8 *dst, | |
768 | const struct wpabuf *tlvs); | |
769 | ||
770 | /** | |
771 | * p2p_sd_cancel_request - Cancel a pending service discovery query | |
772 | * @p2p: P2P module context from p2p_init() | |
773 | * @req: Query reference from p2p_sd_request() | |
774 | * Returns: 0 if request for cancelled; -1 if not found | |
775 | */ | |
776 | int p2p_sd_cancel_request(struct p2p_data *p2p, void *req); | |
777 | ||
778 | /** | |
779 | * p2p_sd_response - Send response to a service discovery query | |
780 | * @p2p: P2P module context from p2p_init() | |
781 | * @freq: Frequency from p2p_config::sd_request() callback | |
782 | * @dst: Destination address from p2p_config::sd_request() callback | |
783 | * @dialog_token: Dialog token from p2p_config::sd_request() callback | |
784 | * @resp_tlvs: P2P Service Response TLV(s) | |
785 | * | |
786 | * This function is called as a response to the request indicated with | |
787 | * p2p_config::sd_request() callback. | |
788 | */ | |
789 | void p2p_sd_response(struct p2p_data *p2p, int freq, const u8 *dst, | |
790 | u8 dialog_token, const struct wpabuf *resp_tlvs); | |
791 | ||
792 | /** | |
793 | * p2p_sd_service_update - Indicate a change in local services | |
794 | * @p2p: P2P module context from p2p_init() | |
795 | * | |
796 | * This function needs to be called whenever there is a change in availability | |
797 | * of the local services. This will increment the Service Update Indicator | |
798 | * value which will be used in SD Request and Response frames. | |
799 | */ | |
800 | void p2p_sd_service_update(struct p2p_data *p2p); | |
801 | ||
802 | ||
803 | enum p2p_invite_role { | |
804 | P2P_INVITE_ROLE_GO, | |
805 | P2P_INVITE_ROLE_ACTIVE_GO, | |
806 | P2P_INVITE_ROLE_CLIENT | |
807 | }; | |
808 | ||
809 | /** | |
810 | * p2p_invite - Invite a P2P Device into a group | |
811 | * @p2p: P2P module context from p2p_init() | |
812 | * @peer: Device Address of the peer P2P Device | |
813 | * @role: Local role in the group | |
814 | * @bssid: Group BSSID or %NULL if not known | |
815 | * @ssid: Group SSID | |
816 | * @ssid_len: Length of ssid in octets | |
817 | * @force_freq: The only allowed channel frequency in MHz or 0 | |
818 | * @go_dev_addr: Forced GO Device Address or %NULL if none | |
819 | * @persistent_group: Whether this is to reinvoke a persistent group | |
820 | * Returns: 0 on success, -1 on failure | |
821 | */ | |
822 | int p2p_invite(struct p2p_data *p2p, const u8 *peer, enum p2p_invite_role role, | |
823 | const u8 *bssid, const u8 *ssid, size_t ssid_len, | |
824 | unsigned int force_freq, const u8 *go_dev_addr, | |
825 | int persistent_group); | |
826 | ||
827 | /** | |
828 | * p2p_presence_req - Request GO presence | |
829 | * @p2p: P2P module context from p2p_init() | |
830 | * @go_interface_addr: GO P2P Interface Address | |
831 | * @own_interface_addr: Own P2P Interface Address for this group | |
832 | * @freq: Group operating frequence (in MHz) | |
833 | * @duration1: Preferred presence duration in microseconds | |
834 | * @interval1: Preferred presence interval in microseconds | |
835 | * @duration2: Acceptable presence duration in microseconds | |
836 | * @interval2: Acceptable presence interval in microseconds | |
837 | * Returns: 0 on success, -1 on failure | |
838 | * | |
839 | * If both duration and interval values are zero, the parameter pair is not | |
840 | * specified (i.e., to remove Presence Request, use duration1 = interval1 = 0). | |
841 | */ | |
842 | int p2p_presence_req(struct p2p_data *p2p, const u8 *go_interface_addr, | |
843 | const u8 *own_interface_addr, unsigned int freq, | |
844 | u32 duration1, u32 interval1, u32 duration2, | |
845 | u32 interval2); | |
846 | ||
847 | /** | |
848 | * p2p_ext_listen - Set Extended Listen Timing | |
849 | * @p2p: P2P module context from p2p_init() | |
850 | * @freq: Group operating frequence (in MHz) | |
851 | * @period: Availability period in milliseconds (1-65535; 0 to disable) | |
852 | * @interval: Availability interval in milliseconds (1-65535; 0 to disable) | |
853 | * Returns: 0 on success, -1 on failure | |
854 | * | |
855 | * This function can be used to enable or disable (period = interval = 0) | |
856 | * Extended Listen Timing. When enabled, the P2P Device will become | |
857 | * discoverable (go into Listen State) every @interval milliseconds for at | |
858 | * least @period milliseconds. | |
859 | */ | |
860 | int p2p_ext_listen(struct p2p_data *p2p, unsigned int period, | |
861 | unsigned int interval); | |
862 | ||
863 | /* Event notifications from upper layer management operations */ | |
864 | ||
865 | /** | |
866 | * p2p_wps_success_cb - Report successfully completed WPS provisioning | |
867 | * @p2p: P2P module context from p2p_init() | |
868 | * @mac_addr: Peer address | |
869 | * | |
870 | * This function is used to report successfully completed WPS provisioning | |
871 | * during group formation in both GO/Registrar and client/Enrollee roles. | |
872 | */ | |
873 | void p2p_wps_success_cb(struct p2p_data *p2p, const u8 *mac_addr); | |
874 | ||
875 | /** | |
876 | * p2p_group_formation_failed - Report failed WPS provisioning | |
877 | * @p2p: P2P module context from p2p_init() | |
878 | * | |
879 | * This function is used to report failed group formation. This can happen | |
880 | * either due to failed WPS provisioning or due to 15 second timeout during | |
881 | * the provisioning phase. | |
882 | */ | |
883 | void p2p_group_formation_failed(struct p2p_data *p2p); | |
884 | ||
885 | ||
886 | /* Event notifications from lower layer driver operations */ | |
887 | ||
888 | /** | |
889 | * p2p_probe_req_rx - Report reception of a Probe Request frame | |
890 | * @p2p: P2P module context from p2p_init() | |
891 | * @addr: Source MAC address | |
892 | * @ie: Information elements from the Probe Request frame body | |
893 | * @ie_len: Length of ie buffer in octets | |
894 | * Returns: 0 to indicate the frame was not processed or 1 if it was | |
895 | */ | |
896 | int p2p_probe_req_rx(struct p2p_data *p2p, const u8 *addr, const u8 *ie, | |
897 | size_t ie_len); | |
898 | ||
899 | /** | |
900 | * p2p_rx_action - Report received Action frame | |
901 | * @p2p: P2P module context from p2p_init() | |
902 | * @da: Destination address of the received Action frame | |
903 | * @sa: Source address of the received Action frame | |
904 | * @bssid: Address 3 of the received Action frame | |
905 | * @category: Category of the received Action frame | |
906 | * @data: Action frame body after the Category field | |
907 | * @len: Length of the data buffer in octets | |
908 | * @freq: Frequency (in MHz) on which the frame was received | |
909 | */ | |
910 | void p2p_rx_action(struct p2p_data *p2p, const u8 *da, const u8 *sa, | |
911 | const u8 *bssid, u8 category, | |
912 | const u8 *data, size_t len, int freq); | |
913 | ||
914 | /** | |
915 | * p2p_scan_res_handler - Indicate a P2P scan results | |
916 | * @p2p: P2P module context from p2p_init() | |
917 | * @bssid: BSSID of the scan result | |
918 | * @freq: Frequency of the channel on which the device was found in MHz | |
919 | * @level: Signal level (signal strength of the received Beacon/Probe Response | |
920 | * frame) | |
921 | * @ies: Pointer to IEs from the scan result | |
922 | * @ies_len: Length of the ies buffer | |
923 | * Returns: 0 to continue or 1 to stop scan result indication | |
924 | * | |
925 | * This function is called to indicate a scan result entry with P2P IE from a | |
926 | * scan requested with struct p2p_config::p2p_scan(). This can be called during | |
927 | * the actual scan process (i.e., whenever a new device is found) or as a | |
928 | * sequence of calls after the full scan has been completed. The former option | |
929 | * can result in optimized operations, but may not be supported by all | |
930 | * driver/firmware designs. The ies buffer need to include at least the P2P IE, | |
931 | * but it is recommended to include all IEs received from the device. The | |
932 | * caller does not need to check that the IEs contain a P2P IE before calling | |
933 | * this function since frames will be filtered internally if needed. | |
934 | * | |
935 | * This function will return 1 if it wants to stop scan result iteration (and | |
936 | * scan in general if it is still in progress). This is used to allow faster | |
937 | * start of a pending operation, e.g., to start a pending GO negotiation. | |
938 | */ | |
939 | int p2p_scan_res_handler(struct p2p_data *p2p, const u8 *bssid, int freq, | |
940 | int level, const u8 *ies, size_t ies_len); | |
941 | ||
942 | /** | |
943 | * p2p_scan_res_handled - Indicate end of scan results | |
944 | * @p2p: P2P module context from p2p_init() | |
945 | * | |
946 | * This function is called to indicate that all P2P scan results from a scan | |
947 | * have been reported with zero or more calls to p2p_scan_res_handler(). This | |
948 | * function must be called as a response to successful | |
949 | * struct p2p_config::p2p_scan() call if none of the p2p_scan_res_handler() | |
950 | * calls stopped iteration. | |
951 | */ | |
952 | void p2p_scan_res_handled(struct p2p_data *p2p); | |
953 | ||
93b7ddd0 JM |
954 | enum p2p_send_action_result { |
955 | P2P_SEND_ACTION_SUCCESS /* Frame was send and acknowledged */, | |
956 | P2P_SEND_ACTION_NO_ACK /* Frame was sent, but not acknowledged */, | |
957 | P2P_SEND_ACTION_FAILED /* Frame was not sent due to a failure */ | |
958 | }; | |
959 | ||
b22128ef JM |
960 | /** |
961 | * p2p_send_action_cb - Notify TX status of an Action frame | |
962 | * @p2p: P2P module context from p2p_init() | |
963 | * @freq: Channel frequency in MHz | |
964 | * @dst: Destination MAC address (Address 1) | |
965 | * @src: Source MAC address (Address 2) | |
966 | * @bssid: BSSID (Address 3) | |
93b7ddd0 | 967 | * @result: Result of the transmission attempt |
b22128ef JM |
968 | * |
969 | * This function is used to indicate the result of an Action frame transmission | |
970 | * that was requested with struct p2p_config::send_action() callback. | |
971 | */ | |
972 | void p2p_send_action_cb(struct p2p_data *p2p, unsigned int freq, const u8 *dst, | |
93b7ddd0 JM |
973 | const u8 *src, const u8 *bssid, |
974 | enum p2p_send_action_result result); | |
b22128ef JM |
975 | |
976 | /** | |
977 | * p2p_listen_cb - Indicate the start of a requested Listen state | |
978 | * @p2p: P2P module context from p2p_init() | |
979 | * @freq: Listen channel frequency in MHz | |
980 | * @duration: Duration for the Listen state in milliseconds | |
981 | * | |
982 | * This function is used to indicate that a Listen state requested with | |
983 | * struct p2p_config::start_listen() callback has started. | |
984 | */ | |
985 | void p2p_listen_cb(struct p2p_data *p2p, unsigned int freq, | |
986 | unsigned int duration); | |
987 | ||
988 | /** | |
989 | * p2p_listen_end - Indicate the end of a requested Listen state | |
990 | * @p2p: P2P module context from p2p_init() | |
991 | * @freq: Listen channel frequency in MHz | |
992 | * Returns: 0 if no operations were started, 1 if an operation was started | |
993 | * | |
994 | * This function is used to indicate that a Listen state requested with | |
995 | * struct p2p_config::start_listen() callback has ended. | |
996 | */ | |
997 | int p2p_listen_end(struct p2p_data *p2p, unsigned int freq); | |
998 | ||
999 | void p2p_deauth_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code, | |
1000 | const u8 *ie, size_t ie_len); | |
1001 | ||
1002 | void p2p_disassoc_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code, | |
1003 | const u8 *ie, size_t ie_len); | |
1004 | ||
1005 | ||
1006 | /* Per-group P2P state for GO */ | |
1007 | ||
1008 | struct p2p_group; | |
1009 | ||
1010 | /** | |
1011 | * struct p2p_group_config - P2P group configuration | |
1012 | * | |
1013 | * This configuration is provided to the P2P module during initialization of | |
1014 | * the per-group information with p2p_group_init(). | |
1015 | */ | |
1016 | struct p2p_group_config { | |
1017 | /** | |
1018 | * persistent_group - Whether the group is persistent | |
1019 | */ | |
1020 | int persistent_group; | |
1021 | ||
1022 | /** | |
1023 | * interface_addr - P2P Interface Address of the group | |
1024 | */ | |
1025 | u8 interface_addr[ETH_ALEN]; | |
1026 | ||
3f4ce13f JM |
1027 | /** |
1028 | * max_clients - Maximum number of clients in the group | |
1029 | */ | |
1030 | unsigned int max_clients; | |
1031 | ||
b22128ef JM |
1032 | /** |
1033 | * cb_ctx - Context to use with callback functions | |
1034 | */ | |
1035 | void *cb_ctx; | |
1036 | ||
1037 | /** | |
1038 | * ie_update - Notification of IE update | |
1039 | * @ctx: Callback context from cb_ctx | |
1040 | * @beacon_ies: P2P IE for Beacon frames or %NULL if no change | |
1041 | * @proberesp_ies: P2P Ie for Probe Response frames | |
1042 | * | |
1043 | * P2P module uses this callback function to notify whenever the P2P IE | |
1044 | * in Beacon or Probe Response frames should be updated based on group | |
1045 | * events. | |
1046 | * | |
1047 | * The callee is responsible for freeing the returned buffer(s) with | |
1048 | * wpabuf_free(). | |
1049 | */ | |
1050 | void (*ie_update)(void *ctx, struct wpabuf *beacon_ies, | |
1051 | struct wpabuf *proberesp_ies); | |
3071e181 JM |
1052 | |
1053 | /** | |
1054 | * idle_update - Notification of changes in group idle state | |
1055 | * @ctx: Callback context from cb_ctx | |
1056 | * @idle: Whether the group is idle (no associated stations) | |
1057 | */ | |
1058 | void (*idle_update)(void *ctx, int idle); | |
b22128ef JM |
1059 | }; |
1060 | ||
1061 | /** | |
1062 | * p2p_group_init - Initialize P2P group | |
1063 | * @p2p: P2P module context from p2p_init() | |
1064 | * @config: P2P group configuration (will be freed by p2p_group_deinit()) | |
1065 | * Returns: Pointer to private data or %NULL on failure | |
1066 | * | |
1067 | * This function is used to initialize per-group P2P module context. Currently, | |
1068 | * this is only used to manage GO functionality and P2P clients do not need to | |
1069 | * create an instance of this per-group information. | |
1070 | */ | |
1071 | struct p2p_group * p2p_group_init(struct p2p_data *p2p, | |
1072 | struct p2p_group_config *config); | |
1073 | ||
1074 | /** | |
1075 | * p2p_group_deinit - Deinitialize P2P group | |
1076 | * @group: P2P group context from p2p_group_init() | |
1077 | */ | |
1078 | void p2p_group_deinit(struct p2p_group *group); | |
1079 | ||
1080 | /** | |
1081 | * p2p_group_notif_assoc - Notification of P2P client association with GO | |
1082 | * @group: P2P group context from p2p_group_init() | |
1083 | * @addr: Interface address of the P2P client | |
1084 | * @ie: IEs from the (Re)association Request frame | |
1085 | * @len: Length of the ie buffer in octets | |
1086 | * Returns: 0 on success, -1 on failure | |
1087 | */ | |
1088 | int p2p_group_notif_assoc(struct p2p_group *group, const u8 *addr, | |
1089 | const u8 *ie, size_t len); | |
1090 | ||
1091 | /** | |
1092 | * p2p_group_assoc_resp_ie - Build P2P IE for (re)association response | |
1093 | * @group: P2P group context from p2p_group_init() | |
1094 | * @status: Status value (P2P_SC_SUCCESS if association succeeded) | |
1095 | * Returns: P2P IE for (Re)association Response or %NULL on failure | |
1096 | * | |
1097 | * The caller is responsible for freeing the returned buffer with | |
1098 | * wpabuf_free(). | |
1099 | */ | |
1100 | struct wpabuf * p2p_group_assoc_resp_ie(struct p2p_group *group, u8 status); | |
1101 | ||
1102 | /** | |
1103 | * p2p_group_notif_disassoc - Notification of P2P client disassociation from GO | |
1104 | * @group: P2P group context from p2p_group_init() | |
1105 | * @addr: Interface address of the P2P client | |
1106 | */ | |
1107 | void p2p_group_notif_disassoc(struct p2p_group *group, const u8 *addr); | |
1108 | ||
1109 | /** | |
1110 | * p2p_group_notif_formation_done - Notification of completed group formation | |
1111 | * @group: P2P group context from p2p_group_init() | |
1112 | */ | |
1113 | void p2p_group_notif_formation_done(struct p2p_group *group); | |
1114 | ||
1115 | /** | |
1116 | * p2p_group_notif_noa - Notification of NoA change | |
1117 | * @group: P2P group context from p2p_group_init() | |
1118 | * @noa: Notice of Absence attribute payload, %NULL if none | |
1119 | * @noa_len: Length of noa buffer in octets | |
1120 | * Returns: 0 on success, -1 on failure | |
1121 | * | |
1122 | * Notify the P2P group management about a new NoA contents. This will be | |
1123 | * inserted into the P2P IEs in Beacon and Probe Response frames with rest of | |
1124 | * the group information. | |
1125 | */ | |
1126 | int p2p_group_notif_noa(struct p2p_group *group, const u8 *noa, | |
1127 | size_t noa_len); | |
1128 | ||
1129 | /** | |
1130 | * p2p_group_match_dev_type - Match device types in group with requested type | |
1131 | * @group: P2P group context from p2p_group_init() | |
1132 | * @wps: WPS TLVs from Probe Request frame (concatenated WPS IEs) | |
1133 | * Returns: 1 on match, 0 on mismatch | |
1134 | * | |
1135 | * This function can be used to match the Requested Device Type attribute in | |
1136 | * WPS IE with the device types of a group member for deciding whether a GO | |
1137 | * should reply to a Probe Request frame. Match will be reported if the WPS IE | |
1138 | * is not requested any specific device type. | |
1139 | */ | |
1140 | int p2p_group_match_dev_type(struct p2p_group *group, struct wpabuf *wps); | |
1141 | ||
1142 | /** | |
1143 | * p2p_group_go_discover - Send GO Discoverability Request to a group client | |
1144 | * @group: P2P group context from p2p_group_init() | |
1145 | * Returns: 0 on success (frame scheduled); -1 if client was not found | |
1146 | */ | |
1147 | int p2p_group_go_discover(struct p2p_group *group, const u8 *dev_id, | |
1148 | const u8 *searching_dev, int rx_freq); | |
1149 | ||
1150 | ||
1151 | /* Generic helper functions */ | |
1152 | ||
1153 | /** | |
1154 | * p2p_ie_text - Build text format description of P2P IE | |
1155 | * @p2p_ie: P2P IE | |
1156 | * @buf: Buffer for returning text | |
1157 | * @end: Pointer to the end of the buf area | |
1158 | * Returns: Number of octets written to the buffer or -1 on failure | |
1159 | * | |
1160 | * This function can be used to parse P2P IE contents into text format | |
1161 | * field=value lines. | |
1162 | */ | |
1163 | int p2p_ie_text(struct wpabuf *p2p_ie, char *buf, char *end); | |
1164 | ||
1165 | /** | |
1166 | * p2p_scan_result_text - Build text format description of P2P IE | |
1167 | * @ies: Information elements from scan results | |
1168 | * @ies_len: ies buffer length in octets | |
1169 | * @buf: Buffer for returning text | |
1170 | * @end: Pointer to the end of the buf area | |
1171 | * Returns: Number of octets written to the buffer or -1 on failure | |
1172 | * | |
1173 | * This function can be used to parse P2P IE contents into text format | |
1174 | * field=value lines. | |
1175 | */ | |
1176 | int p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf, char *end); | |
1177 | ||
1178 | /** | |
1179 | * p2p_assoc_req_ie - Build P2P IE for (Re)Association Request frame | |
1180 | * @p2p: P2P module context from p2p_init() | |
1181 | * @bssid: BSSID | |
1182 | * @buf: Buffer for writing the P2P IE | |
1183 | * @len: Maximum buf length in octets | |
1184 | * @p2p_group: Whether this is for association with a P2P GO | |
4c08c0bd | 1185 | * @p2p_ie: Reassembled P2P IE data from scan results or %NULL if none |
b22128ef JM |
1186 | * Returns: Number of octets written into buf or -1 on failure |
1187 | */ | |
1188 | int p2p_assoc_req_ie(struct p2p_data *p2p, const u8 *bssid, u8 *buf, | |
4c08c0bd | 1189 | size_t len, int p2p_group, struct wpabuf *p2p_ie); |
b22128ef JM |
1190 | |
1191 | /** | |
1192 | * p2p_scan_ie - Build P2P IE for Probe Request | |
1193 | * @p2p: P2P module context from p2p_init() | |
1194 | * @ies: Buffer for writing P2P IE | |
1195 | */ | |
1196 | void p2p_scan_ie(struct p2p_data *p2p, struct wpabuf *ies); | |
1197 | ||
1198 | /** | |
1199 | * p2p_go_params - Generate random P2P group parameters | |
1200 | * @p2p: P2P module context from p2p_init() | |
1201 | * @params: Buffer for parameters | |
1202 | * Returns: 0 on success, -1 on failure | |
1203 | */ | |
1204 | int p2p_go_params(struct p2p_data *p2p, struct p2p_go_neg_results *params); | |
1205 | ||
1206 | /** | |
1207 | * p2p_get_group_capab - Get Group Capability from P2P IE data | |
1208 | * @p2p_ie: P2P IE(s) contents | |
1209 | * Returns: Group Capability | |
1210 | */ | |
1211 | u8 p2p_get_group_capab(const struct wpabuf *p2p_ie); | |
1212 | ||
72044390 JM |
1213 | /** |
1214 | * p2p_get_cross_connect_disallowed - Does WLAN AP disallows cross connection | |
1215 | * @p2p_ie: P2P IE(s) contents | |
1216 | * Returns: 0 if cross connection is allow, 1 if not | |
1217 | */ | |
1218 | int p2p_get_cross_connect_disallowed(const struct wpabuf *p2p_ie); | |
1219 | ||
b22128ef JM |
1220 | /** |
1221 | * p2p_get_go_dev_addr - Get P2P Device Address from P2P IE data | |
1222 | * @p2p_ie: P2P IE(s) contents | |
1223 | * Returns: Pointer to P2P Device Address or %NULL if not included | |
1224 | */ | |
1225 | const u8 * p2p_get_go_dev_addr(const struct wpabuf *p2p_ie); | |
1226 | ||
1227 | /** | |
1228 | * p2p_get_peer_info - Get P2P peer information in text format | |
1229 | * @p2p: P2P module context from p2p_init() | |
1230 | * @addr: P2P Device Address of the peer or %NULL to indicate the first peer | |
1231 | * @next: Whether to select the peer entry following the one indicated by addr | |
1232 | * @buf: Buffer for returning text | |
1233 | * @buflen: Maximum buffer length | |
1234 | * Returns: Number of octets written to the buffer or -1 on failure | |
1235 | */ | |
1236 | int p2p_get_peer_info(struct p2p_data *p2p, const u8 *addr, int next, | |
1237 | char *buf, size_t buflen); | |
1238 | ||
1239 | /** | |
1240 | * p2p_set_client_discoverability - Set client discoverability capability | |
1241 | * @p2p: P2P module context from p2p_init() | |
1242 | * @enabled: Whether client discoverability will be enabled | |
1243 | * | |
1244 | * This function can be used to disable (and re-enable) client discoverability. | |
1245 | * This capability is enabled by default and should not be disabled in normal | |
1246 | * use cases, i.e., this is mainly for testing purposes. | |
1247 | */ | |
1248 | void p2p_set_client_discoverability(struct p2p_data *p2p, int enabled); | |
1249 | ||
1250 | /** | |
1251 | * p2p_set_manageD_oper - Set managed P2P Device operations capability | |
1252 | * @p2p: P2P module context from p2p_init() | |
1253 | * @enabled: Whether managed P2P Device operations will be enabled | |
1254 | */ | |
1255 | void p2p_set_managed_oper(struct p2p_data *p2p, int enabled); | |
1256 | ||
1257 | int p2p_set_listen_channel(struct p2p_data *p2p, u8 reg_class, u8 channel); | |
1258 | ||
1259 | int p2p_set_ssid_postfix(struct p2p_data *p2p, const u8 *postfix, size_t len); | |
1260 | ||
1261 | int p2p_get_interface_addr(struct p2p_data *p2p, const u8 *dev_addr, | |
1262 | u8 *iface_addr); | |
4147a2cc JM |
1263 | int p2p_get_dev_addr(struct p2p_data *p2p, const u8 *iface_addr, |
1264 | u8 *dev_addr); | |
b22128ef | 1265 | |
80c9582a JM |
1266 | void p2p_set_peer_filter(struct p2p_data *p2p, const u8 *addr); |
1267 | ||
72044390 JM |
1268 | /** |
1269 | * p2p_set_cross_connect - Set cross connection capability | |
1270 | * @p2p: P2P module context from p2p_init() | |
1271 | * @enabled: Whether cross connection will be enabled | |
1272 | */ | |
1273 | void p2p_set_cross_connect(struct p2p_data *p2p, int enabled); | |
1274 | ||
f8d0131a JM |
1275 | int p2p_get_oper_freq(struct p2p_data *p2p, const u8 *iface_addr); |
1276 | ||
17bef1e9 AC |
1277 | int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq, int level, |
1278 | const u8 *ies, size_t ies_len); | |
1279 | ||
0f66abd2 SS |
1280 | /** |
1281 | * p2p_set_intra_bss_dist - Set intra BSS distribution | |
1282 | * @p2p: P2P module context from p2p_init() | |
1283 | * @enabled: Whether intra BSS distribution will be enabled | |
1284 | */ | |
1285 | void p2p_set_intra_bss_dist(struct p2p_data *p2p, int enabled); | |
1286 | ||
d054a462 JM |
1287 | /** |
1288 | * p2p_supported_freq - Check whether channel is supported for P2P | |
1289 | * @p2p: P2P module context from p2p_init() | |
1290 | * @freq: Channel frequency in MHz | |
1291 | * Returns: 0 if channel not usable for P2P, 1 if usable for P2P | |
1292 | */ | |
1293 | int p2p_supported_freq(struct p2p_data *p2p, unsigned int freq); | |
1294 | ||
b5c9da8d JM |
1295 | void p2p_update_channel_list(struct p2p_data *p2p, struct p2p_channels *chan); |
1296 | ||
b22128ef | 1297 | #endif /* P2P_H */ |