P2P: Wait on GO Negotiation Confirm transmit
[mech_eap.git] / doc / p2p.doxygen
1 /**
2 \page p2p Wi-Fi Direct - P2P module
3
4 Wi-Fi Direct functionality is implemented any many levels in the WLAN
5 stack from low-level driver operations to high-level GUI design. This
6 document covers the parts that can be user by %wpa_supplicant. However,
7 it should be noted that alternative designs are also possible, so some
8 of the functionality may reside in other components in the system.
9
10 The driver (or WLAN firmware/hardware) is expected to handle low-level
11 operations related to P2P Power Management and channel scheduling. In
12 addition, support for virtual network interface and data frame
13 processing is done inside the driver. Configuration for these
14 low-level operations is defined in the driver interface:
15 src/drivers/driver.h. This defines both the commands and events used to
16 interact with the driver.
17
18 P2P module implements higher layer functionality for management P2P
19 groups. It takes care of Device Discovery, Service Discovery, Group
20 Owner Negotiation, P2P Invitation. In addition, it maintains
21 information about neighboring P2P Devices. This module could be used
22 in designs that do not use %wpa_supplicant and it could also reside
23 inside the driver/firmware component. P2P module API is defined in
24 src/p2p/p2p.h.
25
26 Provisioning step of Group Formation is implemented using WPS
27 (src/wps/wps.h).
28
29 %wpa_supplicant includes code in interact with both the P2P module
30 (wpa_supplicant/p2p_supplicant.c) and WPS
31 (wpa_supplicant/wps_supplicant.c). The driver operations are passed
32 through these files, i.e., core P2P or WPS code does not interact
33 directly with the driver interface.
34
35
36 \section p2p_arch P2P architecture
37
38 P2P functionality affects many areas of the system architecture. This
39 section shows couple of examples on the location of main P2P
40 components. In the diagrams below, green arrows are used to show
41 communication paths from the P2P module to upper layer management
42 functionality and all the way to a GUI that user could use to manage
43 P2P connections. Blue arrows show the path taken for lower layer
44 operations. Glue code is used to bind the P2P module API to the rest
45 of the system to provide access both towards upper and lower layer
46 functionality.
47
48 \subsection p2p_arch_mac80211 P2P architecture with Linux/mac80211/ath9k
49
50 An architecture where the P2P module resides inside the
51 %wpa_supplicant process is used with Linux mac80211-based drivers,
52 e.g., ath9k. The following diagram shows the main components related
53 to P2P functionality in such an architecture.
54
55 \image html p2p_arch.png "P2P module within wpa_supplicant"
56 \image latex p2p_arch.eps "P2P module within wpa_supplicant" width=15cm
57
58 \subsection p2p_arch_umac P2P architecture with UMAC
59
60 The following diagram shows the main components related to P2P
61 functionality in an architecture where the P2P module resides inside
62 the kernel IEEE 802.11 stack (UMAC in the figure).
63
64 \image html p2p_arch2.png "P2P module in kernel
65 \image latex p2p_arch2.eps "P2P module in kernel" width=15cm
66
67
68 \section p2p_module P2P module
69
70 P2P module manages discovery and group formation with a single state
71 machine, i.e., only a single operation per device can be in progress
72 at any given time. The following diagram describes the P2P state
73 machine. For clarity, it does not include state transitions on
74 operation timeouts to the IDLE state. The states that are marked with
75 dotted ellipse are listed for clarity to describe the protocol
76 functionality for Device Discovery phase, but are not used in the
77 implementation (the SEARCH state is used to manage the initial Scan
78 and the alternating Listen and Search states within Find).
79
80 \image html p2p_sm.png "P2P module state machine"
81 \image latex p2p_sm.eps "P2P module state machine" width=15cm
82
83 \subsection p2p_module_api P2P module API
84
85 P2P module API is defined in src/p2p/p2p.h. The API consists of
86 functions for requesting operations and for providing event
87 notifications. Similar set of callback functions are configured with
88 struct p2p_config to provide callback functions that P2P module can
89 use to request operations and to provide event notifications. In
90 addition, there are number of generic helper functions that can be
91 used for P2P related operations.
92
93 These are the main functions for an upper layer management entity to
94 request P2P operations:
95 - p2p_find()
96 - p2p_stop_find()
97 - p2p_listen()
98 - p2p_connect()
99 - p2p_reject()
100 - p2p_prov_disc_req()
101 - p2p_sd_request()
102 - p2p_sd_cancel_request()
103 - p2p_sd_response()
104 - p2p_sd_service_update()
105 - p2p_invite()
106
107 These are the main callback functions for P2P module to provide event
108 notifications to the upper layer management entity:
109
110 - p2p_config::dev_found()
111 - p2p_config::go_neg_req_rx()
112 - p2p_config::go_neg_completed()
113 - p2p_config::sd_request()
114 - p2p_config::sd_response()
115 - p2p_config::prov_disc_req()
116 - p2p_config::prov_disc_resp()
117 - p2p_config::invitation_process()
118 - p2p_config::invitation_received()
119 - p2p_config::invitation_result()
120
121 The P2P module uses following functions to request lower layer driver
122 operations:
123
124 - p2p_config::p2p_scan()
125 - p2p_config::send_probe_resp()
126 - p2p_config::send_action()
127 - p2p_config::send_action_done()
128 - p2p_config::start_listen()
129 - p2p_config::stop_listen()
130
131 Events from lower layer driver operations are delivered to the P2P
132 module with following functions:
133
134 - p2p_probe_req_rx()
135 - p2p_rx_action()
136 - p2p_scan_res_handler()
137 - p2p_scan_res_handled()
138 - p2p_send_action_cb()
139 - p2p_listen_cb()
140
141 In addition to the per-device state, the P2P module maintains
142 per-group state for group owners. This is initialized with a call to
143 p2p_group_init() when a group is created and deinitialized with
144 p2p_group_deinit(). The upper layer GO management entity uses
145 following functions to interact with the P2P per-group state:
146
147 - p2p_group_notif_assoc()
148 - p2p_group_notif_disassoc()
149 - p2p_group_notif_formation_done()
150 - p2p_group_match_dev_type()
151
152 The P2P module will use following callback function to update P2P IE
153 for GO Beacon and Probe Response frames:
154
155 - p2p_group_config::ie_update()
156
157
158 \section p2p_driver P2P driver operations (low-level interface)
159
160 The following driver wrapper functions are needed for P2P in addition
161 to the standard station/AP mode operations when the P2P module resides
162 within %wpa_supplicant:
163 - wpa_driver_ops::if_add()
164 - wpa_driver_ops::if_remove()
165 - wpa_driver_ops::alloc_interface_addr()
166 - wpa_driver_ops::release_interface_addr()
167 - wpa_driver_ops::remain_on_channel()
168 - wpa_driver_ops::cancel_remain_on_channel()
169 - wpa_driver_ops::send_action()
170 - wpa_driver_ops::probe_req_report()
171 - wpa_driver_ops::disable_11b_rates()
172
173 The following driver wrapper events are needed for P2P in addition to
174 the standard station/AP mode events when the P2P module resides within
175 %wpa_supplicant:
176 - wpa_event_type::EVENT_RX_ACTION
177 - wpa_event_type::EVENT_REMAIN_ON_CHANNEL
178 - wpa_event_type::EVENT_CANCEL_REMAIN_ON_CHANNEL
179 - wpa_event_type::EVENT_RX_PROBE_REQ
180
181
182 \section p2p_go_neg P2P device discovery and group formation
183
184 This section shows an example sequence of operations that can be used
185 to implement P2P device discovery and group formation. The function
186 calls are described based on the P2P module API. The exact design for
187 the glue code outside the P2P module depends on the architecture used
188 in the system.
189
190 An upper layer management entity starts P2P device discovery by
191 calling p2p_find(). The P2P module start the discovery by requesting a
192 full scan to be completed by calling p2p_config::p2p_scan(). Results
193 from the scan will be reported by calling p2p_scan_res_handler() and
194 after last result, the scan result processing is terminated with a
195 call to p2p_scan_res_handled(). The P2P peers that are found during
196 the full scan are reported with the p2p_config::dev_found() callback.
197
198 After the full scan, P2P module start alternating between Listen and
199 Search states until the device discovery operation times out or
200 terminated, e.g., with a call to p2p_stop_find().
201
202 When going into the Listen state, the P2P module requests the driver
203 to be configured to be awake on the listen channel with a call to
204 p2p_config::start_listen(). The glue code using the P2P module may
205 implement this, e.g., by using remain-on-channel low-level driver
206 functionality for off-channel operation. Once the driver is available
207 on the requested channel, notification of this is delivered by calling
208 p2p_listen_cb(). The Probe Request frames that are received during the
209 Listen period are delivered to the P2P module by calling
210 p2p_config::p2p_probe_req_rx() and P2P module request a response to
211 these to be sent by using p2p_config::send_probe_resp() callback
212 function. If a group owner negotiation from another P2P device is
213 received during the device discovery phase, that is indicated to the
214 upper layer code with the p2p_config::go_neg_req_tx() callback.
215
216 The Search state is implemented by using the normal scan interface,
217 i.e., the P2P module will call p2p_config::p2p_scan() just like in the
218 full scan phase described. Similarly, scan results from the search
219 operation will be delivered to the P2P module using the
220 p2p_scan_res_handler() and p2p_scan_res_handled() functions.
221
222 Once the upper layer management entity has found a peer with which it
223 wants to connect by forming a new group, it initiates group owner
224 negotiation by calling p2p_connect(). Before doing this, the upper
225 layer code is responsible for asking the user to provide the PIN to be
226 used during the provisioning step with the peer or the push button
227 press for PBC mode. The glue code will need to figure out the intended
228 interface address for the group before group owner negotiation can be
229 started.
230
231 Optional Provision Discovery mechanism can be used to request the peer
232 to display a PIN for the local device to enter (and vice versa). Upper
233 layer management entity can request the specific mechanism by calling
234 p2p_prov_disc_req(). The response to this will be reported with the
235 p2p_config::prov_disc_resp() callback. If the peer device started
236 Provision Discovery, an accepted request will be reported with the
237 p2p_config::prov_disc_req() callback. The P2P module will
238 automatically accept the Provision Discovery for display and keypad
239 methods, but it is up to the upper layer manegement entity to actually
240 generate the PIN and to configure it with following p2p_connect() call
241 to actually authorize the connection.
242
243 The P2P module will use p2p_config::send_action() callback to request
244 lower layer code to transmit an Action frame during group owner
245 negotiation. p2p_send_action_cb() is used to report the result of
246 transmission. If the peer is not reachable, the P2P module will try to
247 find it by alternating between Action frame send and Listen
248 states. The Listen state for this phase will be used similarly to the
249 Listen state during device discovery as described above.
250
251 Once the group owner negotiation has been completed, its results will
252 be reported with the p2p_config::go_neg_completed() callback. The
253 upper layer management code or the glue code using the P2P module API
254 is responsible for creating a new group interface and starting
255 provisioning step at this point by configuring WPS Registrar or
256 Enrollee functionality based on the reported group owner negotiation
257 results. The upper layer code is also responsible for timing out WPS
258 provisioning if it cannot be completed in 15 seconds.
259
260 Successful completion of the WPS provisioning is reported with a call
261 to p2p_wps_success_cb(). The P2P module will clear its group formation
262 state at this point and allows new group formation attempts to be
263 started. The upper layer management code is responsible for configuring
264 the GO to accept associations from devices and the client to connect to
265 the GO with the provisioned credentials. GO is also responsible for
266 calling p2p_group_notif_formation_done() as described below.
267
268 If the WPS provisioning step fails or times out, this is reported with
269 a call to p2p_group_formation_failed(). The P2P module will clear its
270 group formation state at this point and allows new group formation
271 attempts to be started. The upper layer management code is responsible
272 for removing the group interface for the failed group.
273
274
275 \section p2p_sd P2P service discovery
276
277 P2P protocol includes service discovery functionality that can be used
278 to discover which services are provided by the peers before forming a
279 group. This leverages the Generic Advertisement Service (GAS) protocol
280 from IEEE 802.11u and P2P vendor-specific contents inside the Native
281 GAS messages.
282
283 The P2P module takes care of GAS encapsulation, fragmentation, and
284 actual transmission and reception of the Action frames needed for
285 service discovery. The user of the P2P module is responsible for
286 providing P2P specific Service Request TLV(s) for queries and Service
287 Response TLV(s) for responses.
288
289 \subsection p2p_sd_query Quering services of peers
290
291 Service discovery is implemented by processing pending queries as a
292 part of the device discovery phase. p2p_sd_request() function is used
293 to schedule service discovery queries to a specific peer or to all
294 discovered peers. p2p_sd_cancel_request() can be used to cancel a
295 scheduled query. Queries that are specific to a single peer will be
296 removed automatically after the response has been received.
297
298 After the service discovery queries have been queued, device discovery
299 is started with a call to p2p_find(). The pending service discovery
300 queries are then sent whenever a peer is discovered during the find
301 operation. Responses to the queries will be reported with the
302 p2p_config::sd_response() callback.
303
304 \subsection p2p_sd_response Replying to service discovery queries from peers
305
306 The received service discovery requests will be indicated with the
307 p2p_config::sd_request() callback. The response to the query is sent
308 by calling p2p_sd_response().
309
310 \subsection p2p_sd_indicator Service update indicator
311
312 P2P service discovery provides a mechanism to notify peers about
313 changes in available services. This works by incrementing Service
314 Update Indicator value whenever there is a change in the
315 services. This value is included in all SD request and response
316 frames. The value received from the peers will be included in the
317 p2p_config::sd_request() and p2p_config::sd_response() callbacks. The
318 value to be sent to the peers is incremented with a call to
319 p2p_sd_service_update() whenever availibility of the local services
320 changes.
321
322
323 \section p2p_go P2P group owner
324
325 This section describes how P2P module can be used for managing
326 per-group information in a group owner. The function calls are
327 described based on the P2P module API. The exact design for the glue
328 code outside the P2P module depends on the architecture used in the
329 system.
330
331 When a P2P group interface is created in group owner role, per-group
332 data is initialized with p2p_group_init(). This call provides a
333 pointer to the per-device P2P module context and configures the
334 per-group operation. The configured p2p_group_config::ie_update()
335 callback is used to set the initial P2P IE for Beacon and Probe
336 Response frames in the group owner. The AP mode implementation may use
337 this information to add IEs into the frames.
338
339 Once the group formation has been completed (or if it is skipped in
340 case of manual group setup), p2p_group_notif_formation_done() is
341 called. This will allow the P2P module to update the P2P IE for
342 Beacon and Probe Response frames.
343
344 The SME/MLME code that managements IEEE 802.11 association processing
345 needs to inform P2P module whenever a P2P client associates or
346 disassociates with the group. This is done by calling
347 p2p_group_notif_assoc() and p2p_group_notif_disassoc(). The P2P module
348 manages a list of group members and updates the P2P Group Information
349 subelement in the P2P IE based on the information from the P2P
350 clients. The p2p_group_config::ie_update() callback is used whenever
351 the P2P IE in Probe Response frames needs to be changed.
352
353 The SME/MLME code that takes care of replying to Probe Request frames
354 can use p2p_group_match_dev_type() to check whether the Probe Request
355 frame request a reply only from groups that include a specific device
356 type in one of the clients or GO. A match will be reported if the
357 Probe Request does not request a specific device type, so this
358 function can be used to filter or received Probe Request frames and
359 only the ones that result in non-zero return value need to be replied.
360
361 When the P2P group interface for GO role is removed,
362 p2p_group_deinit() is used to deinitialize the per-group P2P module
363 state.
364
365
366 \section p2p_ctrl_iface P2P control interface
367
368 %wpa_supplicant \ref ctrl_iface_page "control interface" can be used
369 to manage P2P functionality from an external program (e.g., a GUI or a
370 system configuration manager). This interface can be used directly
371 through the control interface backend mechanism (e.g., local domain
372 sockets on Linux) or with help of wpa_cli (e.g., from a script).
373
374 The following P2P-related commands are available:
375 - \ref ctrl_iface_P2P_FIND P2P_FIND
376 - \ref ctrl_iface_P2P_STOP_FIND P2P_STOP_FIND
377 - \ref ctrl_iface_P2P_CONNECT P2P_CONNECT
378 - \ref ctrl_iface_P2P_LISTEN P2P_LISTEN
379 - \ref ctrl_iface_P2P_GROUP_REMOVE P2P_GROUP_REMOVE
380 - \ref ctrl_iface_P2P_GROUP_ADD P2P_GROUP_ADD
381 - \ref ctrl_iface_P2P_PROV_DISC P2P_PROV_DISC
382 - \ref ctrl_iface_P2P_SERV_DISC_REQ P2P_SERV_DISC_REQ
383 - \ref ctrl_iface_P2P_SERV_DISC_CANCEL_REQ P2P_SERV_DISC_CANCEL_REQ
384 - \ref ctrl_iface_P2P_SERV_DISC_RESP P2P_SERV_DISC_RESP
385 - \ref ctrl_iface_P2P_SERVICE_UPDATE P2P_SERVICE_UPDATE
386 - \ref ctrl_iface_P2P_SERV_DISC_EXTERNAL P2P_SERV_DISC_EXTERNAL
387 - \ref ctrl_iface_P2P_REJECT P2P_REJECT
388 - \ref ctrl_iface_P2P_INVITE P2P_INVITE
389
390 The following P2P-related events are used:
391 - \ref ctrl_iface_event_P2P_EVENT_DEVICE_FOUND P2P-DEVICE-FOUND
392 - \ref ctrl_iface_event_P2P_EVENT_GO_NEG_REQUEST P2P-GO-NEG-REQUEST
393 - \ref ctrl_iface_event_P2P_EVENT_GO_NEG_SUCCESS P2P-GO-NEG-SUCCESS
394 - \ref ctrl_iface_event_P2P_EVENT_GO_NEG_FAILURE P2P-GO-NEG-FAILURE
395 - \ref ctrl_iface_event_P2P_EVENT_GROUP_FORMATION_SUCCESS P2P-GROUP-FORMATION-SUCCESS
396 - \ref ctrl_iface_event_P2P_EVENT_GROUP_FORMATION_FAILURE P2P-GROUP-FORMATION-FAILURE
397 - \ref ctrl_iface_event_P2P_EVENT_GROUP_STARTED P2P-GROUP-STARTED
398 - \ref ctrl_iface_event_P2P_EVENT_GROUP_REMOVED P2P-GROUP-REMOVED
399 - \ref ctrl_iface_event_P2P_EVENT_PROV_DISC_SHOW_PIN P2P-PROV-DISC-SHOW-PIN
400 - \ref ctrl_iface_event_P2P_EVENT_PROV_DISC_ENTER_PIN P2P-PROV-DISC-ENTER-PIN
401 - \ref ctrl_iface_event_P2P_EVENT_SERV_DISC_REQ P2P-SERV-DISC-REQ
402 - \ref ctrl_iface_event_P2P_EVENT_SERV_DISC_RESP P2P-SERV-DISC-RESP
403 - \ref ctrl_iface_event_P2P_EVENT_INVITATION_RECEIVED P2P-INVITATION-RECEIVED
404 - \ref ctrl_iface_event_P2P_EVENT_INVITATION_RESULT P2P-INVITATION-RESULT
405
406
407 \subsection p2p_wpa_gui GUI example (wpa_gui)
408
409 wpa_gui has an example implementation of a GUI that could be used to
410 manage P2P operations. The P2P related functionality is contained
411 mostly in wpa_supplicant/wpa_gui-qt4/peers.cpp and it shows how the
412 control interface commands and events can be used.
413
414
415 \subsection p2p_wpa_cli wpa_cli example
416
417 wpa_cli can be used to control %wpa_supplicant in interactive
418 mode. The following sessions show examples of commands used for
419 device discovery and group formation. The lines starting with "> " are
420 commands from the user (followed by command result indication) and
421 lines starting with "<2>" are event messages from %wpa_supplicant.
422
423 P2P device "Wireless Client":
424
425 \verbatim
426 > p2p_find
427 OK
428 > <2>P2P-DEVICE-FOUND 02:40:61:c2:f3:b7 p2p_dev_addr=02:40:61:c2:f3:b7
429 pri_dev_type=1-0050F204-1 name='Wireless Client 2' config_methods=0x18c
430 dev_capab=0x1 group_capab=0x0
431 <2>P2P-GO-NEG-REQUEST 02:40:61:c2:f3:b7
432 <2>P2P-GO-NEG-REQUEST 02:40:61:c2:f3:b7
433 > p2p_connect 02:40:61:c2:f3:b7 pbc
434 OK
435 <2>P2P-GO-NEG-SUCCESS 
436 <2>P2P-GROUP-FORMATION-SUCCESS 
437 <2>P2P-GROUP-STARTED sta0-p2p-0 client DIRECT-vM
438 > interface
439 Available interfaces:
440 sta0-p2p-0
441 sta0
442 > p2p_group_remove sta0-p2p-0
443 <2>P2P-GROUP-REMOVED sta0-p2p-0 client
444 OK
445 > term
446 OK
447 \endverbatim
448
449
450 P2P device "Wireless Client2" (which ended up operating in GO role):
451
452 \verbatim
453 > p2p_find
454 OK
455 <2>P2P-DEVICE-FOUND 02:f0:bc:44:87:62 p2p_dev_addr=02:f0:bc:44:87:62
456 pri_dev_type=1-0050F204-1 name='Wireless Client' config_methods=0x18c
457 dev_capab=0x1 group_capab=0x0
458 > p2p_connect 02:f0:bc:44:87:62 pbc
459 OK
460 <2>P2P-GO-NEG-SUCCESS 
461 <2>P2P-GROUP-FORMATION-SUCCESS 
462 <2>P2P-GROUP-STARTED sta1-p2p-0 GO DIRECT-vM
463 > interface
464 Available interfaces:
465 sta1-p2p-0
466 sta1
467 > p2p_group_remove sta1-p2p-0
468 <2>P2P-GROUP-REMOVED sta1-p2p-0 GO
469 OK
470 > term
471 OK
472 \endverbatim
473
474 */