p2p.h 50 KB

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