p2p.doxygen 20 KB

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