p2p.doxygen 21 KB

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