p2p.doxygen 20 KB

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