p2p.h 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025
  1. /*
  2. * Wi-Fi Direct - P2P module
  3. * Copyright (c) 2009-2010, Atheros Communications
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #ifndef P2P_H
  9. #define P2P_H
  10. #include "wps/wps_defs.h"
  11. /**
  12. * P2P_MAX_REG_CLASSES - Maximum number of regulatory classes
  13. */
  14. #define P2P_MAX_REG_CLASSES 10
  15. /**
  16. * P2P_MAX_REG_CLASS_CHANNELS - Maximum number of channels per regulatory class
  17. */
  18. #define P2P_MAX_REG_CLASS_CHANNELS 20
  19. /**
  20. * struct p2p_channels - List of supported channels
  21. */
  22. struct p2p_channels {
  23. /**
  24. * struct p2p_reg_class - Supported regulatory class
  25. */
  26. struct p2p_reg_class {
  27. /**
  28. * reg_class - Regulatory class (IEEE 802.11-2007, Annex J)
  29. */
  30. u8 reg_class;
  31. /**
  32. * channel - Supported channels
  33. */
  34. u8 channel[P2P_MAX_REG_CLASS_CHANNELS];
  35. /**
  36. * channels - Number of channel entries in use
  37. */
  38. size_t channels;
  39. } reg_class[P2P_MAX_REG_CLASSES];
  40. /**
  41. * reg_classes - Number of reg_class entries in use
  42. */
  43. size_t reg_classes;
  44. };
  45. enum p2p_wps_method {
  46. WPS_NOT_READY, WPS_PIN_DISPLAY, WPS_PIN_KEYPAD, WPS_PBC, WPS_NFC
  47. };
  48. /**
  49. * struct p2p_go_neg_results - P2P Group Owner Negotiation results
  50. */
  51. struct p2p_go_neg_results {
  52. /**
  53. * status - Negotiation result (Status Code)
  54. *
  55. * 0 (P2P_SC_SUCCESS) indicates success. Non-zero values indicate
  56. * failed negotiation.
  57. */
  58. int status;
  59. /**
  60. * role_go - Whether local end is Group Owner
  61. */
  62. int role_go;
  63. /**
  64. * freq - Frequency of the group operational channel in MHz
  65. */
  66. int freq;
  67. int ht40;
  68. int vht;
  69. /**
  70. * ssid - SSID of the group
  71. */
  72. u8 ssid[32];
  73. /**
  74. * ssid_len - Length of SSID in octets
  75. */
  76. size_t ssid_len;
  77. /**
  78. * psk - WPA pre-shared key (256 bits) (GO only)
  79. */
  80. u8 psk[32];
  81. /**
  82. * psk_set - Whether PSK field is configured (GO only)
  83. */
  84. int psk_set;
  85. /**
  86. * passphrase - WPA2-Personal passphrase for the group (GO only)
  87. */
  88. char passphrase[64];
  89. /**
  90. * peer_device_addr - P2P Device Address of the peer
  91. */
  92. u8 peer_device_addr[ETH_ALEN];
  93. /**
  94. * peer_interface_addr - P2P Interface Address of the peer
  95. */
  96. u8 peer_interface_addr[ETH_ALEN];
  97. /**
  98. * wps_method - WPS method to be used during provisioning
  99. */
  100. enum p2p_wps_method wps_method;
  101. #define P2P_MAX_CHANNELS 50
  102. /**
  103. * freq_list - Zero-terminated list of possible operational channels
  104. */
  105. int freq_list[P2P_MAX_CHANNELS];
  106. /**
  107. * persistent_group - Whether the group should be made persistent
  108. * 0 = not persistent
  109. * 1 = persistent group without persistent reconnect
  110. * 2 = persistent group with persistent reconnect
  111. */
  112. int persistent_group;
  113. /**
  114. * peer_config_timeout - Peer configuration timeout (in 10 msec units)
  115. */
  116. unsigned int peer_config_timeout;
  117. };
  118. struct p2p_data;
  119. enum p2p_scan_type {
  120. P2P_SCAN_SOCIAL,
  121. P2P_SCAN_FULL,
  122. P2P_SCAN_SOCIAL_PLUS_ONE
  123. };
  124. #define P2P_MAX_WPS_VENDOR_EXT 10
  125. /**
  126. * struct p2p_peer_info - P2P peer information
  127. */
  128. struct p2p_peer_info {
  129. /**
  130. * p2p_device_addr - P2P Device Address of the peer
  131. */
  132. u8 p2p_device_addr[ETH_ALEN];
  133. /**
  134. * pri_dev_type - Primary Device Type
  135. */
  136. u8 pri_dev_type[8];
  137. /**
  138. * device_name - Device Name (0..32 octets encoded in UTF-8)
  139. */
  140. char device_name[33];
  141. /**
  142. * manufacturer - Manufacturer (0..64 octets encoded in UTF-8)
  143. */
  144. char manufacturer[65];
  145. /**
  146. * model_name - Model Name (0..32 octets encoded in UTF-8)
  147. */
  148. char model_name[33];
  149. /**
  150. * model_number - Model Number (0..32 octets encoded in UTF-8)
  151. */
  152. char model_number[33];
  153. /**
  154. * serial_number - Serial Number (0..32 octets encoded in UTF-8)
  155. */
  156. char serial_number[33];
  157. /**
  158. * level - Signal level
  159. */
  160. int level;
  161. /**
  162. * config_methods - WPS Configuration Methods
  163. */
  164. u16 config_methods;
  165. /**
  166. * dev_capab - Device Capabilities
  167. */
  168. u8 dev_capab;
  169. /**
  170. * group_capab - Group Capabilities
  171. */
  172. u8 group_capab;
  173. /**
  174. * wps_sec_dev_type_list - WPS secondary device type list
  175. *
  176. * This list includes from 0 to 16 Secondary Device Types as indicated
  177. * by wps_sec_dev_type_list_len (8 * number of types).
  178. */
  179. u8 wps_sec_dev_type_list[128];
  180. /**
  181. * wps_sec_dev_type_list_len - Length of secondary device type list
  182. */
  183. size_t wps_sec_dev_type_list_len;
  184. struct wpabuf *wps_vendor_ext[P2P_MAX_WPS_VENDOR_EXT];
  185. /**
  186. * wfd_subelems - Wi-Fi Display subelements from WFD IE(s)
  187. */
  188. struct wpabuf *wfd_subelems;
  189. /**
  190. * vendor_elems - Unrecognized vendor elements
  191. *
  192. * This buffer includes any other vendor element than P2P, WPS, and WFD
  193. * IE(s) from the frame that was used to discover the peer.
  194. */
  195. struct wpabuf *vendor_elems;
  196. };
  197. enum p2p_prov_disc_status {
  198. P2P_PROV_DISC_SUCCESS,
  199. P2P_PROV_DISC_TIMEOUT,
  200. P2P_PROV_DISC_REJECTED,
  201. P2P_PROV_DISC_TIMEOUT_JOIN,
  202. };
  203. struct p2p_channel {
  204. u8 op_class;
  205. u8 chan;
  206. };
  207. /**
  208. * struct p2p_config - P2P configuration
  209. *
  210. * This configuration is provided to the P2P module during initialization with
  211. * p2p_init().
  212. */
  213. struct p2p_config {
  214. /**
  215. * country - Country code to use in P2P operations
  216. */
  217. char country[3];
  218. /**
  219. * reg_class - Regulatory class for own listen channel
  220. */
  221. u8 reg_class;
  222. /**
  223. * channel - Own listen channel
  224. */
  225. u8 channel;
  226. /**
  227. * channel_forced - the listen channel was forced by configuration
  228. * or by control interface and cannot be overridden
  229. */
  230. u8 channel_forced;
  231. /**
  232. * Regulatory class for own operational channel
  233. */
  234. u8 op_reg_class;
  235. /**
  236. * op_channel - Own operational channel
  237. */
  238. u8 op_channel;
  239. /**
  240. * cfg_op_channel - Whether op_channel is hardcoded in configuration
  241. */
  242. u8 cfg_op_channel;
  243. /**
  244. * channels - Own supported regulatory classes and channels
  245. *
  246. * List of supposerted channels per regulatory class. The regulatory
  247. * classes are defined in IEEE Std 802.11-2007 Annex J and the
  248. * numbering of the clases depends on the configured country code.
  249. */
  250. struct p2p_channels channels;
  251. /**
  252. * cli_channels - Additional client channels
  253. *
  254. * This list of channels (if any) will be used when advertising local
  255. * channels during GO Negotiation or Invitation for the cases where the
  256. * local end may become the client. This may allow the peer to become a
  257. * GO on additional channels if it supports these options. The main use
  258. * case for this is to include passive-scan channels on devices that may
  259. * not know their current location and have configured most channels to
  260. * not allow initiation of radition (i.e., another device needs to take
  261. * master responsibilities).
  262. */
  263. struct p2p_channels cli_channels;
  264. /**
  265. * num_pref_chan - Number of pref_chan entries
  266. */
  267. unsigned int num_pref_chan;
  268. /**
  269. * pref_chan - Preferred channels for GO Negotiation
  270. */
  271. struct p2p_channel *pref_chan;
  272. /**
  273. * pri_dev_type - Primary Device Type (see WPS)
  274. */
  275. u8 pri_dev_type[8];
  276. /**
  277. * P2P_SEC_DEVICE_TYPES - Maximum number of secondary device types
  278. */
  279. #define P2P_SEC_DEVICE_TYPES 5
  280. /**
  281. * sec_dev_type - Optional secondary device types
  282. */
  283. u8 sec_dev_type[P2P_SEC_DEVICE_TYPES][8];
  284. /**
  285. * num_sec_dev_types - Number of sec_dev_type entries
  286. */
  287. size_t num_sec_dev_types;
  288. /**
  289. * dev_addr - P2P Device Address
  290. */
  291. u8 dev_addr[ETH_ALEN];
  292. /**
  293. * dev_name - Device Name
  294. */
  295. char *dev_name;
  296. char *manufacturer;
  297. char *model_name;
  298. char *model_number;
  299. char *serial_number;
  300. u8 uuid[16];
  301. u16 config_methods;
  302. /**
  303. * concurrent_operations - Whether concurrent operations are supported
  304. */
  305. int concurrent_operations;
  306. /**
  307. * max_peers - Maximum number of discovered peers to remember
  308. *
  309. * If more peers are discovered, older entries will be removed to make
  310. * room for the new ones.
  311. */
  312. size_t max_peers;
  313. /**
  314. * p2p_intra_bss - Intra BSS communication is supported
  315. */
  316. int p2p_intra_bss;
  317. /**
  318. * ssid_postfix - Postfix data to add to the SSID
  319. *
  320. * This data will be added to the end of the SSID after the
  321. * DIRECT-<random two octets> prefix.
  322. */
  323. u8 ssid_postfix[32 - 9];
  324. /**
  325. * ssid_postfix_len - Length of the ssid_postfix data
  326. */
  327. size_t ssid_postfix_len;
  328. /**
  329. * max_listen - Maximum listen duration in ms
  330. */
  331. unsigned int max_listen;
  332. /**
  333. * passphrase_len - Passphrase length (8..63)
  334. *
  335. * This parameter controls the length of the random passphrase that is
  336. * generated at the GO.
  337. */
  338. unsigned int passphrase_len;
  339. /**
  340. * cb_ctx - Context to use with callback functions
  341. */
  342. void *cb_ctx;
  343. /**
  344. * debug_print - Debug print
  345. * @ctx: Callback context from cb_ctx
  346. * @level: Debug verbosity level (MSG_*)
  347. * @msg: Debug message
  348. */
  349. void (*debug_print)(void *ctx, int level, const char *msg);
  350. /* Callbacks to request lower layer driver operations */
  351. /**
  352. * p2p_scan - Request a P2P scan/search
  353. * @ctx: Callback context from cb_ctx
  354. * @type: Scan type
  355. * @freq: Specific frequency (MHz) to scan or 0 for no restriction
  356. * @num_req_dev_types: Number of requested device types
  357. * @req_dev_types: Array containing requested device types
  358. * @dev_id: Device ID to search for or %NULL to find all devices
  359. * @pw_id: Device Password ID
  360. * Returns: 0 on success, -1 on failure
  361. *
  362. * This callback function is used to request a P2P scan or search
  363. * operation to be completed. Type type argument specifies which type
  364. * of scan is to be done. @P2P_SCAN_SOCIAL indicates that only the
  365. * social channels (1, 6, 11) should be scanned. @P2P_SCAN_FULL
  366. * indicates that all channels are to be scanned.
  367. * @P2P_SCAN_SOCIAL_PLUS_ONE request scan of all the social channels
  368. * plus one extra channel specified by freq.
  369. *
  370. * The full scan is used for the initial scan to find group owners from
  371. * all. The other types are used during search phase scan of the social
  372. * channels (with potential variation if the Listen channel of the
  373. * target peer is known or if other channels are scanned in steps).
  374. *
  375. * The scan results are returned after this call by calling
  376. * p2p_scan_res_handler() for each scan result that has a P2P IE and
  377. * then calling p2p_scan_res_handled() to indicate that all scan
  378. * results have been indicated.
  379. */
  380. int (*p2p_scan)(void *ctx, enum p2p_scan_type type, int freq,
  381. unsigned int num_req_dev_types,
  382. const u8 *req_dev_types, const u8 *dev_id, u16 pw_id);
  383. /**
  384. * send_probe_resp - Transmit a Probe Response frame
  385. * @ctx: Callback context from cb_ctx
  386. * @buf: Probe Response frame (including the header and body)
  387. * Returns: 0 on success, -1 on failure
  388. *
  389. * This function is used to reply to Probe Request frames that were
  390. * indicated with a call to p2p_probe_req_rx(). The response is to be
  391. * sent on the same channel or to be dropped if the driver is not
  392. * anymore listening to Probe Request frames.
  393. *
  394. * Alternatively, the responsibility for building the Probe Response
  395. * frames in Listen state may be in another system component in which
  396. * case this function need to be implemented (i.e., the function
  397. * pointer can be %NULL). The WPS and P2P IEs to be added for Probe
  398. * Response frames in such a case are available from the
  399. * start_listen() callback. It should be noted that the received Probe
  400. * Request frames must be indicated by calling p2p_probe_req_rx() even
  401. * if this send_probe_resp() is not used.
  402. */
  403. int (*send_probe_resp)(void *ctx, const struct wpabuf *buf);
  404. /**
  405. * send_action - Transmit an Action frame
  406. * @ctx: Callback context from cb_ctx
  407. * @freq: Frequency in MHz for the channel on which to transmit
  408. * @dst: Destination MAC address (Address 1)
  409. * @src: Source MAC address (Address 2)
  410. * @bssid: BSSID (Address 3)
  411. * @buf: Frame body (starting from Category field)
  412. * @len: Length of buf in octets
  413. * @wait_time: How many msec to wait for a response frame
  414. * Returns: 0 on success, -1 on failure
  415. *
  416. * The Action frame may not be transmitted immediately and the status
  417. * of the transmission must be reported by calling
  418. * p2p_send_action_cb() once the frame has either been transmitted or
  419. * it has been dropped due to excessive retries or other failure to
  420. * transmit.
  421. */
  422. int (*send_action)(void *ctx, unsigned int freq, const u8 *dst,
  423. const u8 *src, const u8 *bssid, const u8 *buf,
  424. size_t len, unsigned int wait_time);
  425. /**
  426. * send_action_done - Notify that Action frame sequence was completed
  427. * @ctx: Callback context from cb_ctx
  428. *
  429. * This function is called when the Action frame sequence that was
  430. * started with send_action() has been completed, i.e., when there is
  431. * no need to wait for a response from the destination peer anymore.
  432. */
  433. void (*send_action_done)(void *ctx);
  434. /**
  435. * start_listen - Start Listen state
  436. * @ctx: Callback context from cb_ctx
  437. * @freq: Frequency of the listen channel in MHz
  438. * @duration: Duration for the Listen state in milliseconds
  439. * @probe_resp_ie: IE(s) to be added to Probe Response frames
  440. * Returns: 0 on success, -1 on failure
  441. *
  442. * This Listen state may not start immediately since the driver may
  443. * have other pending operations to complete first. Once the Listen
  444. * state has started, p2p_listen_cb() must be called to notify the P2P
  445. * module. Once the Listen state is stopped, p2p_listen_end() must be
  446. * called to notify the P2P module that the driver is not in the Listen
  447. * state anymore.
  448. *
  449. * If the send_probe_resp() is not used for generating the response,
  450. * the IEs from probe_resp_ie need to be added to the end of the Probe
  451. * Response frame body. If send_probe_resp() is used, the probe_resp_ie
  452. * information can be ignored.
  453. */
  454. int (*start_listen)(void *ctx, unsigned int freq,
  455. unsigned int duration,
  456. const struct wpabuf *probe_resp_ie);
  457. /**
  458. * stop_listen - Stop Listen state
  459. * @ctx: Callback context from cb_ctx
  460. *
  461. * This callback can be used to stop a Listen state operation that was
  462. * previously requested with start_listen().
  463. */
  464. void (*stop_listen)(void *ctx);
  465. /**
  466. * get_noa - Get current Notice of Absence attribute payload
  467. * @ctx: Callback context from cb_ctx
  468. * @interface_addr: P2P Interface Address of the GO
  469. * @buf: Buffer for returning NoA
  470. * @buf_len: Buffer length in octets
  471. * Returns: Number of octets used in buf, 0 to indicate no NoA is being
  472. * advertized, or -1 on failure
  473. *
  474. * This function is used to fetch the current Notice of Absence
  475. * attribute value from GO.
  476. */
  477. int (*get_noa)(void *ctx, const u8 *interface_addr, u8 *buf,
  478. size_t buf_len);
  479. /* Callbacks to notify events to upper layer management entity */
  480. /**
  481. * dev_found - Notification of a found P2P Device
  482. * @ctx: Callback context from cb_ctx
  483. * @addr: Source address of the message triggering this notification
  484. * @info: P2P peer information
  485. * @new_device: Inform if the peer is newly found
  486. *
  487. * This callback is used to notify that a new P2P Device has been
  488. * found. This may happen, e.g., during Search state based on scan
  489. * results or during Listen state based on receive Probe Request and
  490. * Group Owner Negotiation Request.
  491. */
  492. void (*dev_found)(void *ctx, const u8 *addr,
  493. const struct p2p_peer_info *info,
  494. int new_device);
  495. /**
  496. * dev_lost - Notification of a lost P2P Device
  497. * @ctx: Callback context from cb_ctx
  498. * @dev_addr: P2P Device Address of the lost P2P Device
  499. *
  500. * This callback is used to notify that a P2P Device has been deleted.
  501. */
  502. void (*dev_lost)(void *ctx, const u8 *dev_addr);
  503. /**
  504. * find_stopped - Notification of a p2p_find operation stopping
  505. * @ctx: Callback context from cb_ctx
  506. */
  507. void (*find_stopped)(void *ctx);
  508. /**
  509. * go_neg_req_rx - Notification of a receive GO Negotiation Request
  510. * @ctx: Callback context from cb_ctx
  511. * @src: Source address of the message triggering this notification
  512. * @dev_passwd_id: WPS Device Password ID
  513. *
  514. * This callback is used to notify that a P2P Device is requesting
  515. * group owner negotiation with us, but we do not have all the
  516. * necessary information to start GO Negotiation. This indicates that
  517. * the local user has not authorized the connection yet by providing a
  518. * PIN or PBC button press. This information can be provided with a
  519. * call to p2p_connect().
  520. */
  521. void (*go_neg_req_rx)(void *ctx, const u8 *src, u16 dev_passwd_id);
  522. /**
  523. * go_neg_completed - Notification of GO Negotiation results
  524. * @ctx: Callback context from cb_ctx
  525. * @res: GO Negotiation results
  526. *
  527. * This callback is used to notify that Group Owner Negotiation has
  528. * been completed. Non-zero struct p2p_go_neg_results::status indicates
  529. * failed negotiation. In case of success, this function is responsible
  530. * for creating a new group interface (or using the existing interface
  531. * depending on driver features), setting up the group interface in
  532. * proper mode based on struct p2p_go_neg_results::role_go and
  533. * initializing WPS provisioning either as a Registrar (if GO) or as an
  534. * Enrollee. Successful WPS provisioning must be indicated by calling
  535. * p2p_wps_success_cb(). The callee is responsible for timing out group
  536. * formation if WPS provisioning cannot be completed successfully
  537. * within 15 seconds.
  538. */
  539. void (*go_neg_completed)(void *ctx, struct p2p_go_neg_results *res);
  540. /**
  541. * sd_request - Callback on Service Discovery Request
  542. * @ctx: Callback context from cb_ctx
  543. * @freq: Frequency (in MHz) of the channel
  544. * @sa: Source address of the request
  545. * @dialog_token: Dialog token
  546. * @update_indic: Service Update Indicator from the source of request
  547. * @tlvs: P2P Service Request TLV(s)
  548. * @tlvs_len: Length of tlvs buffer in octets
  549. *
  550. * This callback is used to indicate reception of a service discovery
  551. * request. Response to the query must be indicated by calling
  552. * p2p_sd_response() with the context information from the arguments to
  553. * this callback function.
  554. *
  555. * This callback handler can be set to %NULL to indicate that service
  556. * discovery is not supported.
  557. */
  558. void (*sd_request)(void *ctx, int freq, const u8 *sa, u8 dialog_token,
  559. u16 update_indic, const u8 *tlvs, size_t tlvs_len);
  560. /**
  561. * sd_response - Callback on Service Discovery Response
  562. * @ctx: Callback context from cb_ctx
  563. * @sa: Source address of the request
  564. * @update_indic: Service Update Indicator from the source of response
  565. * @tlvs: P2P Service Response TLV(s)
  566. * @tlvs_len: Length of tlvs buffer in octets
  567. *
  568. * This callback is used to indicate reception of a service discovery
  569. * response. This callback handler can be set to %NULL if no service
  570. * discovery requests are used. The information provided with this call
  571. * is replies to the queries scheduled with p2p_sd_request().
  572. */
  573. void (*sd_response)(void *ctx, const u8 *sa, u16 update_indic,
  574. const u8 *tlvs, size_t tlvs_len);
  575. /**
  576. * prov_disc_req - Callback on Provisiong Discovery Request
  577. * @ctx: Callback context from cb_ctx
  578. * @peer: Source address of the request
  579. * @config_methods: Requested WPS Config Method
  580. * @dev_addr: P2P Device Address of the found P2P Device
  581. * @pri_dev_type: Primary Device Type
  582. * @dev_name: Device Name
  583. * @supp_config_methods: Supported configuration Methods
  584. * @dev_capab: Device Capabilities
  585. * @group_capab: Group Capabilities
  586. * @group_id: P2P Group ID (or %NULL if not included)
  587. * @group_id_len: Length of P2P Group ID
  588. *
  589. * This callback is used to indicate reception of a Provision Discovery
  590. * Request frame that the P2P module accepted.
  591. */
  592. void (*prov_disc_req)(void *ctx, const u8 *peer, u16 config_methods,
  593. const u8 *dev_addr, const u8 *pri_dev_type,
  594. const char *dev_name, u16 supp_config_methods,
  595. u8 dev_capab, u8 group_capab,
  596. const u8 *group_id, size_t group_id_len);
  597. /**
  598. * prov_disc_resp - Callback on Provisiong Discovery Response
  599. * @ctx: Callback context from cb_ctx
  600. * @peer: Source address of the response
  601. * @config_methods: Value from p2p_prov_disc_req() or 0 on failure
  602. *
  603. * This callback is used to indicate reception of a Provision Discovery
  604. * Response frame for a pending request scheduled with
  605. * p2p_prov_disc_req(). This callback handler can be set to %NULL if
  606. * provision discovery is not used.
  607. */
  608. void (*prov_disc_resp)(void *ctx, const u8 *peer, u16 config_methods);
  609. /**
  610. * prov_disc_fail - Callback on Provision Discovery failure
  611. * @ctx: Callback context from cb_ctx
  612. * @peer: Source address of the response
  613. * @status: Cause of failure, will not be %P2P_PROV_DISC_SUCCESS
  614. *
  615. * This callback is used to indicate either a failure or no response
  616. * to an earlier provision discovery request.
  617. *
  618. * This callback handler can be set to %NULL if provision discovery
  619. * is not used or failures do not need to be indicated.
  620. */
  621. void (*prov_disc_fail)(void *ctx, const u8 *peer,
  622. enum p2p_prov_disc_status status);
  623. /**
  624. * invitation_process - Optional callback for processing Invitations
  625. * @ctx: Callback context from cb_ctx
  626. * @sa: Source address of the Invitation Request
  627. * @bssid: P2P Group BSSID from the request or %NULL if not included
  628. * @go_dev_addr: GO Device Address from P2P Group ID
  629. * @ssid: SSID from P2P Group ID
  630. * @ssid_len: Length of ssid buffer in octets
  631. * @go: Variable for returning whether the local end is GO in the group
  632. * @group_bssid: Buffer for returning P2P Group BSSID (if local end GO)
  633. * @force_freq: Variable for returning forced frequency for the group
  634. * @persistent_group: Whether this is an invitation to reinvoke a
  635. * persistent group (instead of invitation to join an active
  636. * group)
  637. * @channels: Available operating channels for the group
  638. * @dev_pw_id: Device Password ID for NFC static handover or -1 if not
  639. * used
  640. * Returns: Status code (P2P_SC_*)
  641. *
  642. * This optional callback can be used to implement persistent reconnect
  643. * by allowing automatic restarting of persistent groups without user
  644. * interaction. If this callback is not implemented (i.e., is %NULL),
  645. * the received Invitation Request frames are replied with
  646. * %P2P_SC_REQ_RECEIVED status and indicated to upper layer with the
  647. * invitation_result() callback.
  648. *
  649. * If the requested parameters are acceptable and the group is known,
  650. * %P2P_SC_SUCCESS may be returned. If the requested group is unknown,
  651. * %P2P_SC_FAIL_UNKNOWN_GROUP should be returned. %P2P_SC_REQ_RECEIVED
  652. * can be returned if there is not enough data to provide immediate
  653. * response, i.e., if some sort of user interaction is needed. The
  654. * invitation_received() callback will be called in that case
  655. * immediately after this call.
  656. */
  657. u8 (*invitation_process)(void *ctx, const u8 *sa, const u8 *bssid,
  658. const u8 *go_dev_addr, const u8 *ssid,
  659. size_t ssid_len, int *go, u8 *group_bssid,
  660. int *force_freq, int persistent_group,
  661. const struct p2p_channels *channels,
  662. int dev_pw_id);
  663. /**
  664. * invitation_received - Callback on Invitation Request RX
  665. * @ctx: Callback context from cb_ctx
  666. * @sa: Source address of the Invitation Request
  667. * @bssid: P2P Group BSSID or %NULL if not received
  668. * @ssid: SSID of the group
  669. * @ssid_len: Length of ssid in octets
  670. * @go_dev_addr: GO Device Address
  671. * @status: Response Status
  672. * @op_freq: Operational frequency for the group
  673. *
  674. * This callback is used to indicate sending of an Invitation Response
  675. * for a received Invitation Request. If status == 0 (success), the
  676. * upper layer code is responsible for starting the group. status == 1
  677. * indicates need to get user authorization for the group. Other status
  678. * values indicate that the invitation request was rejected.
  679. */
  680. void (*invitation_received)(void *ctx, const u8 *sa, const u8 *bssid,
  681. const u8 *ssid, size_t ssid_len,
  682. const u8 *go_dev_addr, u8 status,
  683. int op_freq);
  684. /**
  685. * invitation_result - Callback on Invitation result
  686. * @ctx: Callback context from cb_ctx
  687. * @status: Negotiation result (Status Code)
  688. * @bssid: P2P Group BSSID or %NULL if not received
  689. * @channels: Available operating channels for the group
  690. * @addr: Peer address
  691. * @freq: Frequency (in MHz) indicated during invitation or 0
  692. * @peer_oper_freq: Operating frequency (in MHz) advertized by the peer
  693. * during invitation or 0
  694. *
  695. * This callback is used to indicate result of an Invitation procedure
  696. * started with a call to p2p_invite(). The indicated status code is
  697. * the value received from the peer in Invitation Response with 0
  698. * (P2P_SC_SUCCESS) indicating success or -1 to indicate a timeout or a
  699. * local failure in transmitting the Invitation Request.
  700. */
  701. void (*invitation_result)(void *ctx, int status, const u8 *bssid,
  702. const struct p2p_channels *channels,
  703. const u8 *addr, int freq, int peer_oper_freq);
  704. /**
  705. * go_connected - Check whether we are connected to a GO
  706. * @ctx: Callback context from cb_ctx
  707. * @dev_addr: P2P Device Address of a GO
  708. * Returns: 1 if we are connected as a P2P client to the specified GO
  709. * or 0 if not.
  710. */
  711. int (*go_connected)(void *ctx, const u8 *dev_addr);
  712. /**
  713. * presence_resp - Callback on Presence Response
  714. * @ctx: Callback context from cb_ctx
  715. * @src: Source address (GO's P2P Interface Address)
  716. * @status: Result of the request (P2P_SC_*)
  717. * @noa: Returned NoA value
  718. * @noa_len: Length of the NoA buffer in octets
  719. */
  720. void (*presence_resp)(void *ctx, const u8 *src, u8 status,
  721. const u8 *noa, size_t noa_len);
  722. /**
  723. * is_concurrent_session_active - Check whether concurrent session is
  724. * active on other virtual interfaces
  725. * @ctx: Callback context from cb_ctx
  726. * Returns: 1 if concurrent session is active on other virtual interface
  727. * or 0 if not.
  728. */
  729. int (*is_concurrent_session_active)(void *ctx);
  730. /**
  731. * is_p2p_in_progress - Check whether P2P operation is in progress
  732. * @ctx: Callback context from cb_ctx
  733. * Returns: 1 if P2P operation (e.g., group formation) is in progress
  734. * or 0 if not.
  735. */
  736. int (*is_p2p_in_progress)(void *ctx);
  737. };
  738. /* P2P module initialization/deinitialization */
  739. /**
  740. * p2p_init - Initialize P2P module
  741. * @cfg: P2P module configuration
  742. * Returns: Pointer to private data or %NULL on failure
  743. *
  744. * This function is used to initialize global P2P module context (one per
  745. * device). The P2P module will keep a copy of the configuration data, so the
  746. * caller does not need to maintain this structure. However, the callback
  747. * functions and the context parameters to them must be kept available until
  748. * the P2P module is deinitialized with p2p_deinit().
  749. */
  750. struct p2p_data * p2p_init(const struct p2p_config *cfg);
  751. /**
  752. * p2p_deinit - Deinitialize P2P module
  753. * @p2p: P2P module context from p2p_init()
  754. */
  755. void p2p_deinit(struct p2p_data *p2p);
  756. /**
  757. * p2p_flush - Flush P2P module state
  758. * @p2p: P2P module context from p2p_init()
  759. *
  760. * This command removes the P2P module state like peer device entries.
  761. */
  762. void p2p_flush(struct p2p_data *p2p);
  763. /**
  764. * p2p_unauthorize - Unauthorize the specified peer device
  765. * @p2p: P2P module context from p2p_init()
  766. * @addr: P2P peer entry to be unauthorized
  767. * Returns: 0 on success, -1 on failure
  768. *
  769. * This command removes any connection authorization from the specified P2P
  770. * peer device address. This can be used, e.g., to cancel effect of a previous
  771. * p2p_authorize() or p2p_connect() call that has not yet resulted in completed
  772. * GO Negotiation.
  773. */
  774. int p2p_unauthorize(struct p2p_data *p2p, const u8 *addr);
  775. /**
  776. * p2p_set_dev_name - Set device name
  777. * @p2p: P2P module context from p2p_init()
  778. * Returns: 0 on success, -1 on failure
  779. *
  780. * This function can be used to update the P2P module configuration with
  781. * information that was not available at the time of the p2p_init() call.
  782. */
  783. int p2p_set_dev_name(struct p2p_data *p2p, const char *dev_name);
  784. int p2p_set_manufacturer(struct p2p_data *p2p, const char *manufacturer);
  785. int p2p_set_model_name(struct p2p_data *p2p, const char *model_name);
  786. int p2p_set_model_number(struct p2p_data *p2p, const char *model_number);
  787. int p2p_set_serial_number(struct p2p_data *p2p, const char *serial_number);
  788. void p2p_set_config_methods(struct p2p_data *p2p, u16 config_methods);
  789. void p2p_set_uuid(struct p2p_data *p2p, const u8 *uuid);
  790. /**
  791. * p2p_set_pri_dev_type - Set primary device type
  792. * @p2p: P2P module context from p2p_init()
  793. * Returns: 0 on success, -1 on failure
  794. *
  795. * This function can be used to update the P2P module configuration with
  796. * information that was not available at the time of the p2p_init() call.
  797. */
  798. int p2p_set_pri_dev_type(struct p2p_data *p2p, const u8 *pri_dev_type);
  799. /**
  800. * p2p_set_sec_dev_types - Set secondary device types
  801. * @p2p: P2P module context from p2p_init()
  802. * Returns: 0 on success, -1 on failure
  803. *
  804. * This function can be used to update the P2P module configuration with
  805. * information that was not available at the time of the p2p_init() call.
  806. */
  807. int p2p_set_sec_dev_types(struct p2p_data *p2p, const u8 dev_types[][8],
  808. size_t num_dev_types);
  809. int p2p_set_country(struct p2p_data *p2p, const char *country);
  810. /* Commands from upper layer management entity */
  811. enum p2p_discovery_type {
  812. P2P_FIND_START_WITH_FULL,
  813. P2P_FIND_ONLY_SOCIAL,
  814. P2P_FIND_PROGRESSIVE
  815. };
  816. /**
  817. * p2p_find - Start P2P Find (Device Discovery)
  818. * @p2p: P2P module context from p2p_init()
  819. * @timeout: Timeout for find operation in seconds or 0 for no timeout
  820. * @type: Device Discovery type
  821. * @num_req_dev_types: Number of requested device types
  822. * @req_dev_types: Requested device types array, must be an array
  823. * containing num_req_dev_types * WPS_DEV_TYPE_LEN bytes; %NULL if no
  824. * requested device types.
  825. * @dev_id: Device ID to search for or %NULL to find all devices
  826. * @search_delay: Extra delay in milliseconds between search iterations
  827. * Returns: 0 on success, -1 on failure
  828. */
  829. int p2p_find(struct p2p_data *p2p, unsigned int timeout,
  830. enum p2p_discovery_type type,
  831. unsigned int num_req_dev_types, const u8 *req_dev_types,
  832. const u8 *dev_id, unsigned int search_delay);
  833. /**
  834. * p2p_stop_find - Stop P2P Find (Device Discovery)
  835. * @p2p: P2P module context from p2p_init()
  836. */
  837. void p2p_stop_find(struct p2p_data *p2p);
  838. /**
  839. * p2p_stop_find_for_freq - Stop P2P Find for next oper on specific freq
  840. * @p2p: P2P module context from p2p_init()
  841. * @freq: Frequency in MHz for next operation
  842. *
  843. * This is like p2p_stop_find(), but Listen state is not stopped if we are
  844. * already on the same frequency.
  845. */
  846. void p2p_stop_find_for_freq(struct p2p_data *p2p, int freq);
  847. /**
  848. * p2p_listen - Start P2P Listen state for specified duration
  849. * @p2p: P2P module context from p2p_init()
  850. * @timeout: Listen state duration in milliseconds
  851. * Returns: 0 on success, -1 on failure
  852. *
  853. * This function can be used to request the P2P module to keep the device
  854. * discoverable on the listen channel for an extended set of time. At least in
  855. * its current form, this is mainly used for testing purposes and may not be of
  856. * much use for normal P2P operations.
  857. */
  858. int p2p_listen(struct p2p_data *p2p, unsigned int timeout);
  859. /**
  860. * p2p_stop_listen - Stop P2P Listen
  861. * @p2p: P2P module context from p2p_init()
  862. */
  863. void p2p_stop_listen(struct p2p_data *p2p);
  864. /**
  865. * p2p_connect - Start P2P group formation (GO negotiation)
  866. * @p2p: P2P module context from p2p_init()
  867. * @peer_addr: MAC address of the peer P2P client
  868. * @wps_method: WPS method to be used in provisioning
  869. * @go_intent: Local GO intent value (1..15)
  870. * @own_interface_addr: Intended interface address to use with the group
  871. * @force_freq: The only allowed channel frequency in MHz or 0
  872. * @persistent_group: Whether to create a persistent group (0 = no, 1 =
  873. * persistent group without persistent reconnect, 2 = persistent group with
  874. * persistent reconnect)
  875. * @force_ssid: Forced SSID for the group if we become GO or %NULL to generate
  876. * a new SSID
  877. * @force_ssid_len: Length of $force_ssid buffer
  878. * @pd_before_go_neg: Whether to send Provision Discovery prior to GO
  879. * Negotiation as an interoperability workaround when initiating group
  880. * formation
  881. * @pref_freq: Preferred operating frequency in MHz or 0 (this is only used if
  882. * force_freq == 0)
  883. * Returns: 0 on success, -1 on failure
  884. */
  885. int p2p_connect(struct p2p_data *p2p, const u8 *peer_addr,
  886. enum p2p_wps_method wps_method,
  887. int go_intent, const u8 *own_interface_addr,
  888. unsigned int force_freq, int persistent_group,
  889. const u8 *force_ssid, size_t force_ssid_len,
  890. int pd_before_go_neg, unsigned int pref_freq, u16 oob_pw_id);
  891. /**
  892. * p2p_authorize - Authorize P2P group formation (GO negotiation)
  893. * @p2p: P2P module context from p2p_init()
  894. * @peer_addr: MAC address of the peer P2P client
  895. * @wps_method: WPS method to be used in provisioning
  896. * @go_intent: Local GO intent value (1..15)
  897. * @own_interface_addr: Intended interface address to use with the group
  898. * @force_freq: The only allowed channel frequency in MHz or 0
  899. * @persistent_group: Whether to create a persistent group (0 = no, 1 =
  900. * persistent group without persistent reconnect, 2 = persistent group with
  901. * persistent reconnect)
  902. * @force_ssid: Forced SSID for the group if we become GO or %NULL to generate
  903. * a new SSID
  904. * @force_ssid_len: Length of $force_ssid buffer
  905. * @pref_freq: Preferred operating frequency in MHz or 0 (this is only used if
  906. * force_freq == 0)
  907. * Returns: 0 on success, -1 on failure
  908. *
  909. * This is like p2p_connect(), but the actual group negotiation is not
  910. * initiated automatically, i.e., the other end is expected to do that.
  911. */
  912. int p2p_authorize(struct p2p_data *p2p, const u8 *peer_addr,
  913. enum p2p_wps_method wps_method,
  914. int go_intent, const u8 *own_interface_addr,
  915. unsigned int force_freq, int persistent_group,
  916. const u8 *force_ssid, size_t force_ssid_len,
  917. unsigned int pref_freq, u16 oob_pw_id);
  918. /**
  919. * p2p_reject - Reject peer device (explicitly block connection attempts)
  920. * @p2p: P2P module context from p2p_init()
  921. * @peer_addr: MAC address of the peer P2P client
  922. * Returns: 0 on success, -1 on failure
  923. */
  924. int p2p_reject(struct p2p_data *p2p, const u8 *peer_addr);
  925. /**
  926. * p2p_prov_disc_req - Send Provision Discovery Request
  927. * @p2p: P2P module context from p2p_init()
  928. * @peer_addr: MAC address of the peer P2P client
  929. * @config_methods: WPS Config Methods value (only one bit set)
  930. * @join: Whether this is used by a client joining an active group
  931. * @force_freq: Forced TX frequency for the frame (mainly for the join case)
  932. * @user_initiated_pd: Flag to indicate if initiated by user or not
  933. * Returns: 0 on success, -1 on failure
  934. *
  935. * This function can be used to request a discovered P2P peer to display a PIN
  936. * (config_methods = WPS_CONFIG_DISPLAY) or be prepared to enter a PIN from us
  937. * (config_methods = WPS_CONFIG_KEYPAD). The Provision Discovery Request frame
  938. * is transmitted once immediately and if no response is received, the frame
  939. * will be sent again whenever the target device is discovered during device
  940. * dsicovery (start with a p2p_find() call). Response from the peer is
  941. * indicated with the p2p_config::prov_disc_resp() callback.
  942. */
  943. int p2p_prov_disc_req(struct p2p_data *p2p, const u8 *peer_addr,
  944. u16 config_methods, int join, int force_freq,
  945. int user_initiated_pd);
  946. /**
  947. * p2p_sd_request - Schedule a service discovery query
  948. * @p2p: P2P module context from p2p_init()
  949. * @dst: Destination peer or %NULL to apply for all peers
  950. * @tlvs: P2P Service Query TLV(s)
  951. * Returns: Reference to the query or %NULL on failure
  952. *
  953. * Response to the query is indicated with the p2p_config::sd_response()
  954. * callback.
  955. */
  956. void * p2p_sd_request(struct p2p_data *p2p, const u8 *dst,
  957. const struct wpabuf *tlvs);
  958. #ifdef CONFIG_WIFI_DISPLAY
  959. void * p2p_sd_request_wfd(struct p2p_data *p2p, const u8 *dst,
  960. const struct wpabuf *tlvs);
  961. #endif /* CONFIG_WIFI_DISPLAY */
  962. /**
  963. * p2p_sd_cancel_request - Cancel a pending service discovery query
  964. * @p2p: P2P module context from p2p_init()
  965. * @req: Query reference from p2p_sd_request()
  966. * Returns: 0 if request for cancelled; -1 if not found
  967. */
  968. int p2p_sd_cancel_request(struct p2p_data *p2p, void *req);
  969. /**
  970. * p2p_sd_response - Send response to a service discovery query
  971. * @p2p: P2P module context from p2p_init()
  972. * @freq: Frequency from p2p_config::sd_request() callback
  973. * @dst: Destination address from p2p_config::sd_request() callback
  974. * @dialog_token: Dialog token from p2p_config::sd_request() callback
  975. * @resp_tlvs: P2P Service Response TLV(s)
  976. *
  977. * This function is called as a response to the request indicated with
  978. * p2p_config::sd_request() callback.
  979. */
  980. void p2p_sd_response(struct p2p_data *p2p, int freq, const u8 *dst,
  981. u8 dialog_token, const struct wpabuf *resp_tlvs);
  982. /**
  983. * p2p_sd_service_update - Indicate a change in local services
  984. * @p2p: P2P module context from p2p_init()
  985. *
  986. * This function needs to be called whenever there is a change in availability
  987. * of the local services. This will increment the Service Update Indicator
  988. * value which will be used in SD Request and Response frames.
  989. */
  990. void p2p_sd_service_update(struct p2p_data *p2p);
  991. enum p2p_invite_role {
  992. P2P_INVITE_ROLE_GO,
  993. P2P_INVITE_ROLE_ACTIVE_GO,
  994. P2P_INVITE_ROLE_CLIENT
  995. };
  996. /**
  997. * p2p_invite - Invite a P2P Device into a group
  998. * @p2p: P2P module context from p2p_init()
  999. * @peer: Device Address of the peer P2P Device
  1000. * @role: Local role in the group
  1001. * @bssid: Group BSSID or %NULL if not known
  1002. * @ssid: Group SSID
  1003. * @ssid_len: Length of ssid in octets
  1004. * @force_freq: The only allowed channel frequency in MHz or 0
  1005. * @go_dev_addr: Forced GO Device Address or %NULL if none
  1006. * @persistent_group: Whether this is to reinvoke a persistent group
  1007. * @pref_freq: Preferred operating frequency in MHz or 0 (this is only used if
  1008. * force_freq == 0)
  1009. * @dev_pw_id: Device Password ID from OOB Device Password (NFC) static handover
  1010. * case or -1 if not used
  1011. * Returns: 0 on success, -1 on failure
  1012. */
  1013. int p2p_invite(struct p2p_data *p2p, const u8 *peer, enum p2p_invite_role role,
  1014. const u8 *bssid, const u8 *ssid, size_t ssid_len,
  1015. unsigned int force_freq, const u8 *go_dev_addr,
  1016. int persistent_group, unsigned int pref_freq, int dev_pw_id);
  1017. /**
  1018. * p2p_presence_req - Request GO presence
  1019. * @p2p: P2P module context from p2p_init()
  1020. * @go_interface_addr: GO P2P Interface Address
  1021. * @own_interface_addr: Own P2P Interface Address for this group
  1022. * @freq: Group operating frequence (in MHz)
  1023. * @duration1: Preferred presence duration in microseconds
  1024. * @interval1: Preferred presence interval in microseconds
  1025. * @duration2: Acceptable presence duration in microseconds
  1026. * @interval2: Acceptable presence interval in microseconds
  1027. * Returns: 0 on success, -1 on failure
  1028. *
  1029. * If both duration and interval values are zero, the parameter pair is not
  1030. * specified (i.e., to remove Presence Request, use duration1 = interval1 = 0).
  1031. */
  1032. int p2p_presence_req(struct p2p_data *p2p, const u8 *go_interface_addr,
  1033. const u8 *own_interface_addr, unsigned int freq,
  1034. u32 duration1, u32 interval1, u32 duration2,
  1035. u32 interval2);
  1036. /**
  1037. * p2p_ext_listen - Set Extended Listen Timing
  1038. * @p2p: P2P module context from p2p_init()
  1039. * @freq: Group operating frequence (in MHz)
  1040. * @period: Availability period in milliseconds (1-65535; 0 to disable)
  1041. * @interval: Availability interval in milliseconds (1-65535; 0 to disable)
  1042. * Returns: 0 on success, -1 on failure
  1043. *
  1044. * This function can be used to enable or disable (period = interval = 0)
  1045. * Extended Listen Timing. When enabled, the P2P Device will become
  1046. * discoverable (go into Listen State) every @interval milliseconds for at
  1047. * least @period milliseconds.
  1048. */
  1049. int p2p_ext_listen(struct p2p_data *p2p, unsigned int period,
  1050. unsigned int interval);
  1051. /* Event notifications from upper layer management operations */
  1052. /**
  1053. * p2p_wps_success_cb - Report successfully completed WPS provisioning
  1054. * @p2p: P2P module context from p2p_init()
  1055. * @mac_addr: Peer address
  1056. *
  1057. * This function is used to report successfully completed WPS provisioning
  1058. * during group formation in both GO/Registrar and client/Enrollee roles.
  1059. */
  1060. void p2p_wps_success_cb(struct p2p_data *p2p, const u8 *mac_addr);
  1061. /**
  1062. * p2p_group_formation_failed - Report failed WPS provisioning
  1063. * @p2p: P2P module context from p2p_init()
  1064. *
  1065. * This function is used to report failed group formation. This can happen
  1066. * either due to failed WPS provisioning or due to 15 second timeout during
  1067. * the provisioning phase.
  1068. */
  1069. void p2p_group_formation_failed(struct p2p_data *p2p);
  1070. /**
  1071. * p2p_get_provisioning_info - Get any stored provisioning info
  1072. * @p2p: P2P module context from p2p_init()
  1073. * @addr: Peer P2P Device Address
  1074. * Returns: WPS provisioning information (WPS config method) or 0 if no
  1075. * information is available
  1076. *
  1077. * This function is used to retrieve stored WPS provisioning info for the given
  1078. * peer.
  1079. */
  1080. u16 p2p_get_provisioning_info(struct p2p_data *p2p, const u8 *addr);
  1081. /**
  1082. * p2p_clear_provisioning_info - Clear any stored provisioning info
  1083. * @p2p: P2P module context from p2p_init()
  1084. * @iface_addr: Peer P2P Device Address
  1085. *
  1086. * This function is used to clear stored WPS provisioning info for the given
  1087. * peer.
  1088. */
  1089. void p2p_clear_provisioning_info(struct p2p_data *p2p, const u8 *addr);
  1090. /* Event notifications from lower layer driver operations */
  1091. /**
  1092. * enum p2p_probe_req_status
  1093. *
  1094. * @P2P_PREQ_MALFORMED: frame was not well-formed
  1095. * @P2P_PREQ_NOT_LISTEN: device isn't in listen state, frame ignored
  1096. * @P2P_PREQ_NOT_P2P: frame was not a P2P probe request
  1097. * @P2P_PREQ_P2P_NOT_PROCESSED: frame was P2P but wasn't processed
  1098. * @P2P_PREQ_P2P_PROCESSED: frame has been processed by P2P
  1099. */
  1100. enum p2p_probe_req_status {
  1101. P2P_PREQ_MALFORMED,
  1102. P2P_PREQ_NOT_LISTEN,
  1103. P2P_PREQ_NOT_P2P,
  1104. P2P_PREQ_NOT_PROCESSED,
  1105. P2P_PREQ_PROCESSED
  1106. };
  1107. /**
  1108. * p2p_probe_req_rx - Report reception of a Probe Request frame
  1109. * @p2p: P2P module context from p2p_init()
  1110. * @addr: Source MAC address
  1111. * @dst: Destination MAC address if available or %NULL
  1112. * @bssid: BSSID if available or %NULL
  1113. * @ie: Information elements from the Probe Request frame body
  1114. * @ie_len: Length of ie buffer in octets
  1115. * Returns: value indicating the type and status of the probe request
  1116. */
  1117. enum p2p_probe_req_status
  1118. p2p_probe_req_rx(struct p2p_data *p2p, const u8 *addr, const u8 *dst,
  1119. const u8 *bssid, const u8 *ie, size_t ie_len);
  1120. /**
  1121. * p2p_rx_action - Report received Action frame
  1122. * @p2p: P2P module context from p2p_init()
  1123. * @da: Destination address of the received Action frame
  1124. * @sa: Source address of the received Action frame
  1125. * @bssid: Address 3 of the received Action frame
  1126. * @category: Category of the received Action frame
  1127. * @data: Action frame body after the Category field
  1128. * @len: Length of the data buffer in octets
  1129. * @freq: Frequency (in MHz) on which the frame was received
  1130. */
  1131. void p2p_rx_action(struct p2p_data *p2p, const u8 *da, const u8 *sa,
  1132. const u8 *bssid, u8 category,
  1133. const u8 *data, size_t len, int freq);
  1134. /**
  1135. * p2p_scan_res_handler - Indicate a P2P scan results
  1136. * @p2p: P2P module context from p2p_init()
  1137. * @bssid: BSSID of the scan result
  1138. * @freq: Frequency of the channel on which the device was found in MHz
  1139. * @rx_time: Time when the result was received
  1140. * @level: Signal level (signal strength of the received Beacon/Probe Response
  1141. * frame)
  1142. * @ies: Pointer to IEs from the scan result
  1143. * @ies_len: Length of the ies buffer
  1144. * Returns: 0 to continue or 1 to stop scan result indication
  1145. *
  1146. * This function is called to indicate a scan result entry with P2P IE from a
  1147. * scan requested with struct p2p_config::p2p_scan(). This can be called during
  1148. * the actual scan process (i.e., whenever a new device is found) or as a
  1149. * sequence of calls after the full scan has been completed. The former option
  1150. * can result in optimized operations, but may not be supported by all
  1151. * driver/firmware designs. The ies buffer need to include at least the P2P IE,
  1152. * but it is recommended to include all IEs received from the device. The
  1153. * caller does not need to check that the IEs contain a P2P IE before calling
  1154. * this function since frames will be filtered internally if needed.
  1155. *
  1156. * This function will return 1 if it wants to stop scan result iteration (and
  1157. * scan in general if it is still in progress). This is used to allow faster
  1158. * start of a pending operation, e.g., to start a pending GO negotiation.
  1159. */
  1160. int p2p_scan_res_handler(struct p2p_data *p2p, const u8 *bssid, int freq,
  1161. struct os_reltime *rx_time, int level, const u8 *ies,
  1162. size_t ies_len);
  1163. /**
  1164. * p2p_scan_res_handled - Indicate end of scan results
  1165. * @p2p: P2P module context from p2p_init()
  1166. *
  1167. * This function is called to indicate that all P2P scan results from a scan
  1168. * have been reported with zero or more calls to p2p_scan_res_handler(). This
  1169. * function must be called as a response to successful
  1170. * struct p2p_config::p2p_scan() call if none of the p2p_scan_res_handler()
  1171. * calls stopped iteration.
  1172. */
  1173. void p2p_scan_res_handled(struct p2p_data *p2p);
  1174. enum p2p_send_action_result {
  1175. P2P_SEND_ACTION_SUCCESS /* Frame was send and acknowledged */,
  1176. P2P_SEND_ACTION_NO_ACK /* Frame was sent, but not acknowledged */,
  1177. P2P_SEND_ACTION_FAILED /* Frame was not sent due to a failure */
  1178. };
  1179. /**
  1180. * p2p_send_action_cb - Notify TX status of an Action frame
  1181. * @p2p: P2P module context from p2p_init()
  1182. * @freq: Channel frequency in MHz
  1183. * @dst: Destination MAC address (Address 1)
  1184. * @src: Source MAC address (Address 2)
  1185. * @bssid: BSSID (Address 3)
  1186. * @result: Result of the transmission attempt
  1187. *
  1188. * This function is used to indicate the result of an Action frame transmission
  1189. * that was requested with struct p2p_config::send_action() callback.
  1190. */
  1191. void p2p_send_action_cb(struct p2p_data *p2p, unsigned int freq, const u8 *dst,
  1192. const u8 *src, const u8 *bssid,
  1193. enum p2p_send_action_result result);
  1194. /**
  1195. * p2p_listen_cb - Indicate the start of a requested Listen state
  1196. * @p2p: P2P module context from p2p_init()
  1197. * @freq: Listen channel frequency in MHz
  1198. * @duration: Duration for the Listen state in milliseconds
  1199. *
  1200. * This function is used to indicate that a Listen state requested with
  1201. * struct p2p_config::start_listen() callback has started.
  1202. */
  1203. void p2p_listen_cb(struct p2p_data *p2p, unsigned int freq,
  1204. unsigned int duration);
  1205. /**
  1206. * p2p_listen_end - Indicate the end of a requested Listen state
  1207. * @p2p: P2P module context from p2p_init()
  1208. * @freq: Listen channel frequency in MHz
  1209. * Returns: 0 if no operations were started, 1 if an operation was started
  1210. *
  1211. * This function is used to indicate that a Listen state requested with
  1212. * struct p2p_config::start_listen() callback has ended.
  1213. */
  1214. int p2p_listen_end(struct p2p_data *p2p, unsigned int freq);
  1215. void p2p_deauth_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code,
  1216. const u8 *ie, size_t ie_len);
  1217. void p2p_disassoc_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code,
  1218. const u8 *ie, size_t ie_len);
  1219. /* Per-group P2P state for GO */
  1220. struct p2p_group;
  1221. /**
  1222. * struct p2p_group_config - P2P group configuration
  1223. *
  1224. * This configuration is provided to the P2P module during initialization of
  1225. * the per-group information with p2p_group_init().
  1226. */
  1227. struct p2p_group_config {
  1228. /**
  1229. * persistent_group - Whether the group is persistent
  1230. * 0 = not a persistent group
  1231. * 1 = persistent group without persistent reconnect
  1232. * 2 = persistent group with persistent reconnect
  1233. */
  1234. int persistent_group;
  1235. /**
  1236. * interface_addr - P2P Interface Address of the group
  1237. */
  1238. u8 interface_addr[ETH_ALEN];
  1239. /**
  1240. * max_clients - Maximum number of clients in the group
  1241. */
  1242. unsigned int max_clients;
  1243. /**
  1244. * ssid - Group SSID
  1245. */
  1246. u8 ssid[32];
  1247. /**
  1248. * ssid_len - Length of SSID
  1249. */
  1250. size_t ssid_len;
  1251. /**
  1252. * freq - Operating channel of the group
  1253. */
  1254. int freq;
  1255. /**
  1256. * cb_ctx - Context to use with callback functions
  1257. */
  1258. void *cb_ctx;
  1259. /**
  1260. * ie_update - Notification of IE update
  1261. * @ctx: Callback context from cb_ctx
  1262. * @beacon_ies: P2P IE for Beacon frames or %NULL if no change
  1263. * @proberesp_ies: P2P Ie for Probe Response frames
  1264. *
  1265. * P2P module uses this callback function to notify whenever the P2P IE
  1266. * in Beacon or Probe Response frames should be updated based on group
  1267. * events.
  1268. *
  1269. * The callee is responsible for freeing the returned buffer(s) with
  1270. * wpabuf_free().
  1271. */
  1272. void (*ie_update)(void *ctx, struct wpabuf *beacon_ies,
  1273. struct wpabuf *proberesp_ies);
  1274. /**
  1275. * idle_update - Notification of changes in group idle state
  1276. * @ctx: Callback context from cb_ctx
  1277. * @idle: Whether the group is idle (no associated stations)
  1278. */
  1279. void (*idle_update)(void *ctx, int idle);
  1280. };
  1281. /**
  1282. * p2p_group_init - Initialize P2P group
  1283. * @p2p: P2P module context from p2p_init()
  1284. * @config: P2P group configuration (will be freed by p2p_group_deinit())
  1285. * Returns: Pointer to private data or %NULL on failure
  1286. *
  1287. * This function is used to initialize per-group P2P module context. Currently,
  1288. * this is only used to manage GO functionality and P2P clients do not need to
  1289. * create an instance of this per-group information.
  1290. */
  1291. struct p2p_group * p2p_group_init(struct p2p_data *p2p,
  1292. struct p2p_group_config *config);
  1293. /**
  1294. * p2p_group_deinit - Deinitialize P2P group
  1295. * @group: P2P group context from p2p_group_init()
  1296. */
  1297. void p2p_group_deinit(struct p2p_group *group);
  1298. /**
  1299. * p2p_group_notif_assoc - Notification of P2P client association with GO
  1300. * @group: P2P group context from p2p_group_init()
  1301. * @addr: Interface address of the P2P client
  1302. * @ie: IEs from the (Re)association Request frame
  1303. * @len: Length of the ie buffer in octets
  1304. * Returns: 0 on success, -1 on failure
  1305. */
  1306. int p2p_group_notif_assoc(struct p2p_group *group, const u8 *addr,
  1307. const u8 *ie, size_t len);
  1308. /**
  1309. * p2p_group_assoc_resp_ie - Build P2P IE for (re)association response
  1310. * @group: P2P group context from p2p_group_init()
  1311. * @status: Status value (P2P_SC_SUCCESS if association succeeded)
  1312. * Returns: P2P IE for (Re)association Response or %NULL on failure
  1313. *
  1314. * The caller is responsible for freeing the returned buffer with
  1315. * wpabuf_free().
  1316. */
  1317. struct wpabuf * p2p_group_assoc_resp_ie(struct p2p_group *group, u8 status);
  1318. /**
  1319. * p2p_group_notif_disassoc - Notification of P2P client disassociation from GO
  1320. * @group: P2P group context from p2p_group_init()
  1321. * @addr: Interface address of the P2P client
  1322. */
  1323. void p2p_group_notif_disassoc(struct p2p_group *group, const u8 *addr);
  1324. /**
  1325. * p2p_group_notif_formation_done - Notification of completed group formation
  1326. * @group: P2P group context from p2p_group_init()
  1327. */
  1328. void p2p_group_notif_formation_done(struct p2p_group *group);
  1329. /**
  1330. * p2p_group_notif_noa - Notification of NoA change
  1331. * @group: P2P group context from p2p_group_init()
  1332. * @noa: Notice of Absence attribute payload, %NULL if none
  1333. * @noa_len: Length of noa buffer in octets
  1334. * Returns: 0 on success, -1 on failure
  1335. *
  1336. * Notify the P2P group management about a new NoA contents. This will be
  1337. * inserted into the P2P IEs in Beacon and Probe Response frames with rest of
  1338. * the group information.
  1339. */
  1340. int p2p_group_notif_noa(struct p2p_group *group, const u8 *noa,
  1341. size_t noa_len);
  1342. /**
  1343. * p2p_group_match_dev_type - Match device types in group with requested type
  1344. * @group: P2P group context from p2p_group_init()
  1345. * @wps: WPS TLVs from Probe Request frame (concatenated WPS IEs)
  1346. * Returns: 1 on match, 0 on mismatch
  1347. *
  1348. * This function can be used to match the Requested Device Type attribute in
  1349. * WPS IE with the device types of a group member for deciding whether a GO
  1350. * should reply to a Probe Request frame. Match will be reported if the WPS IE
  1351. * is not requested any specific device type.
  1352. */
  1353. int p2p_group_match_dev_type(struct p2p_group *group, struct wpabuf *wps);
  1354. /**
  1355. * p2p_group_match_dev_id - Match P2P Device Address in group with requested device id
  1356. */
  1357. int p2p_group_match_dev_id(struct p2p_group *group, struct wpabuf *p2p);
  1358. /**
  1359. * p2p_group_go_discover - Send GO Discoverability Request to a group client
  1360. * @group: P2P group context from p2p_group_init()
  1361. * Returns: 0 on success (frame scheduled); -1 if client was not found
  1362. */
  1363. int p2p_group_go_discover(struct p2p_group *group, const u8 *dev_id,
  1364. const u8 *searching_dev, int rx_freq);
  1365. /* Generic helper functions */
  1366. /**
  1367. * p2p_ie_text - Build text format description of P2P IE
  1368. * @p2p_ie: P2P IE
  1369. * @buf: Buffer for returning text
  1370. * @end: Pointer to the end of the buf area
  1371. * Returns: Number of octets written to the buffer or -1 on failure
  1372. *
  1373. * This function can be used to parse P2P IE contents into text format
  1374. * field=value lines.
  1375. */
  1376. int p2p_ie_text(struct wpabuf *p2p_ie, char *buf, char *end);
  1377. /**
  1378. * p2p_scan_result_text - Build text format description of P2P IE
  1379. * @ies: Information elements from scan results
  1380. * @ies_len: ies buffer length in octets
  1381. * @buf: Buffer for returning text
  1382. * @end: Pointer to the end of the buf area
  1383. * Returns: Number of octets written to the buffer or -1 on failure
  1384. *
  1385. * This function can be used to parse P2P IE contents into text format
  1386. * field=value lines.
  1387. */
  1388. int p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf, char *end);
  1389. /**
  1390. * p2p_parse_dev_addr_in_p2p_ie - Parse P2P Device Address from a concatenated
  1391. * P2P IE
  1392. * @p2p_ie: P2P IE
  1393. * @dev_addr: Buffer for returning P2P Device Address
  1394. * Returns: 0 on success or -1 if P2P Device Address could not be parsed
  1395. */
  1396. int p2p_parse_dev_addr_in_p2p_ie(struct wpabuf *p2p_ie, u8 *dev_addr);
  1397. /**
  1398. * p2p_parse_dev_addr - Parse P2P Device Address from P2P IE(s)
  1399. * @ies: Information elements from scan results
  1400. * @ies_len: ies buffer length in octets
  1401. * @dev_addr: Buffer for returning P2P Device Address
  1402. * Returns: 0 on success or -1 if P2P Device Address could not be parsed
  1403. */
  1404. int p2p_parse_dev_addr(const u8 *ies, size_t ies_len, u8 *dev_addr);
  1405. /**
  1406. * p2p_assoc_req_ie - Build P2P IE for (Re)Association Request frame
  1407. * @p2p: P2P module context from p2p_init()
  1408. * @bssid: BSSID
  1409. * @buf: Buffer for writing the P2P IE
  1410. * @len: Maximum buf length in octets
  1411. * @p2p_group: Whether this is for association with a P2P GO
  1412. * @p2p_ie: Reassembled P2P IE data from scan results or %NULL if none
  1413. * Returns: Number of octets written into buf or -1 on failure
  1414. */
  1415. int p2p_assoc_req_ie(struct p2p_data *p2p, const u8 *bssid, u8 *buf,
  1416. size_t len, int p2p_group, struct wpabuf *p2p_ie);
  1417. /**
  1418. * p2p_scan_ie - Build P2P IE for Probe Request
  1419. * @p2p: P2P module context from p2p_init()
  1420. * @ies: Buffer for writing P2P IE
  1421. * @dev_id: Device ID to search for or %NULL for any
  1422. */
  1423. void p2p_scan_ie(struct p2p_data *p2p, struct wpabuf *ies, const u8 *dev_id);
  1424. /**
  1425. * p2p_scan_ie_buf_len - Get maximum buffer length needed for p2p_scan_ie
  1426. * @p2p: P2P module context from p2p_init()
  1427. * Returns: Number of octets that p2p_scan_ie() may add to the buffer
  1428. */
  1429. size_t p2p_scan_ie_buf_len(struct p2p_data *p2p);
  1430. /**
  1431. * p2p_go_params - Generate random P2P group parameters
  1432. * @p2p: P2P module context from p2p_init()
  1433. * @params: Buffer for parameters
  1434. * Returns: 0 on success, -1 on failure
  1435. */
  1436. int p2p_go_params(struct p2p_data *p2p, struct p2p_go_neg_results *params);
  1437. /**
  1438. * p2p_get_group_capab - Get Group Capability from P2P IE data
  1439. * @p2p_ie: P2P IE(s) contents
  1440. * Returns: Group Capability
  1441. */
  1442. u8 p2p_get_group_capab(const struct wpabuf *p2p_ie);
  1443. /**
  1444. * p2p_get_cross_connect_disallowed - Does WLAN AP disallows cross connection
  1445. * @p2p_ie: P2P IE(s) contents
  1446. * Returns: 0 if cross connection is allow, 1 if not
  1447. */
  1448. int p2p_get_cross_connect_disallowed(const struct wpabuf *p2p_ie);
  1449. /**
  1450. * p2p_get_go_dev_addr - Get P2P Device Address from P2P IE data
  1451. * @p2p_ie: P2P IE(s) contents
  1452. * Returns: Pointer to P2P Device Address or %NULL if not included
  1453. */
  1454. const u8 * p2p_get_go_dev_addr(const struct wpabuf *p2p_ie);
  1455. /**
  1456. * p2p_get_peer_info - Get P2P peer information
  1457. * @p2p: P2P module context from p2p_init()
  1458. * @addr: P2P Device Address of the peer or %NULL to indicate the first peer
  1459. * @next: Whether to select the peer entry following the one indicated by addr
  1460. * Returns: Pointer to peer info or %NULL if not found
  1461. */
  1462. const struct p2p_peer_info * p2p_get_peer_info(struct p2p_data *p2p,
  1463. const u8 *addr, int next);
  1464. /**
  1465. * p2p_get_peer_info_txt - Get internal P2P peer information in text format
  1466. * @info: Pointer to P2P peer info from p2p_get_peer_info()
  1467. * @buf: Buffer for returning text
  1468. * @buflen: Maximum buffer length
  1469. * Returns: Number of octets written to the buffer or -1 on failure
  1470. *
  1471. * Note: This information is internal to the P2P module and subject to change.
  1472. * As such, this should not really be used by external programs for purposes
  1473. * other than debugging.
  1474. */
  1475. int p2p_get_peer_info_txt(const struct p2p_peer_info *info,
  1476. char *buf, size_t buflen);
  1477. /**
  1478. * p2p_peer_known - Check whether P2P peer is known
  1479. * @p2p: P2P module context from p2p_init()
  1480. * @addr: P2P Device Address of the peer
  1481. * Returns: 1 if the specified device is in the P2P peer table or 0 if not
  1482. */
  1483. int p2p_peer_known(struct p2p_data *p2p, const u8 *addr);
  1484. /**
  1485. * p2p_set_client_discoverability - Set client discoverability capability
  1486. * @p2p: P2P module context from p2p_init()
  1487. * @enabled: Whether client discoverability will be enabled
  1488. *
  1489. * This function can be used to disable (and re-enable) client discoverability.
  1490. * This capability is enabled by default and should not be disabled in normal
  1491. * use cases, i.e., this is mainly for testing purposes.
  1492. */
  1493. void p2p_set_client_discoverability(struct p2p_data *p2p, int enabled);
  1494. /**
  1495. * p2p_set_managed_oper - Set managed P2P Device operations capability
  1496. * @p2p: P2P module context from p2p_init()
  1497. * @enabled: Whether managed P2P Device operations will be enabled
  1498. */
  1499. void p2p_set_managed_oper(struct p2p_data *p2p, int enabled);
  1500. /**
  1501. * p2p_config_get_random_social - Return a random social channel
  1502. * @p2p: P2P config
  1503. * @op_class: Selected operating class
  1504. * @op_channel: Selected social channel
  1505. * Returns: 0 on success, -1 on failure
  1506. *
  1507. * This function is used before p2p_init is called. A random social channel
  1508. * from supports bands 2.4 GHz (channels 1,6,11) and 60 GHz (channel 2) is
  1509. * returned on success.
  1510. */
  1511. int p2p_config_get_random_social(struct p2p_config *p2p, u8 *op_class,
  1512. u8 *op_channel);
  1513. int p2p_set_listen_channel(struct p2p_data *p2p, u8 reg_class, u8 channel,
  1514. u8 forced);
  1515. u8 p2p_get_listen_channel(struct p2p_data *p2p);
  1516. int p2p_set_ssid_postfix(struct p2p_data *p2p, const u8 *postfix, size_t len);
  1517. int p2p_get_interface_addr(struct p2p_data *p2p, const u8 *dev_addr,
  1518. u8 *iface_addr);
  1519. int p2p_get_dev_addr(struct p2p_data *p2p, const u8 *iface_addr,
  1520. u8 *dev_addr);
  1521. void p2p_set_peer_filter(struct p2p_data *p2p, const u8 *addr);
  1522. /**
  1523. * p2p_set_cross_connect - Set cross connection capability
  1524. * @p2p: P2P module context from p2p_init()
  1525. * @enabled: Whether cross connection will be enabled
  1526. */
  1527. void p2p_set_cross_connect(struct p2p_data *p2p, int enabled);
  1528. int p2p_get_oper_freq(struct p2p_data *p2p, const u8 *iface_addr);
  1529. /**
  1530. * p2p_set_intra_bss_dist - Set intra BSS distribution
  1531. * @p2p: P2P module context from p2p_init()
  1532. * @enabled: Whether intra BSS distribution will be enabled
  1533. */
  1534. void p2p_set_intra_bss_dist(struct p2p_data *p2p, int enabled);
  1535. int p2p_channels_includes_freq(const struct p2p_channels *channels,
  1536. unsigned int freq);
  1537. int p2p_channels_to_freqs(const struct p2p_channels *channels,
  1538. int *freq_list, unsigned int max_len);
  1539. /**
  1540. * p2p_supported_freq - Check whether channel is supported for P2P
  1541. * @p2p: P2P module context from p2p_init()
  1542. * @freq: Channel frequency in MHz
  1543. * Returns: 0 if channel not usable for P2P, 1 if usable for P2P
  1544. */
  1545. int p2p_supported_freq(struct p2p_data *p2p, unsigned int freq);
  1546. /**
  1547. * p2p_supported_freq_go - Check whether channel is supported for P2P GO operation
  1548. * @p2p: P2P module context from p2p_init()
  1549. * @freq: Channel frequency in MHz
  1550. * Returns: 0 if channel not usable for P2P, 1 if usable for P2P
  1551. */
  1552. int p2p_supported_freq_go(struct p2p_data *p2p, unsigned int freq);
  1553. /**
  1554. * p2p_supported_freq_cli - Check whether channel is supported for P2P client operation
  1555. * @p2p: P2P module context from p2p_init()
  1556. * @freq: Channel frequency in MHz
  1557. * Returns: 0 if channel not usable for P2P, 1 if usable for P2P
  1558. */
  1559. int p2p_supported_freq_cli(struct p2p_data *p2p, unsigned int freq);
  1560. /**
  1561. * p2p_get_pref_freq - Get channel from preferred channel list
  1562. * @p2p: P2P module context from p2p_init()
  1563. * @channels: List of channels
  1564. * Returns: Preferred channel
  1565. */
  1566. unsigned int p2p_get_pref_freq(struct p2p_data *p2p,
  1567. const struct p2p_channels *channels);
  1568. void p2p_update_channel_list(struct p2p_data *p2p,
  1569. const struct p2p_channels *chan,
  1570. const struct p2p_channels *cli_chan);
  1571. /**
  1572. * p2p_set_best_channels - Update best channel information
  1573. * @p2p: P2P module context from p2p_init()
  1574. * @freq_24: Frequency (MHz) of best channel in 2.4 GHz band
  1575. * @freq_5: Frequency (MHz) of best channel in 5 GHz band
  1576. * @freq_overall: Frequency (MHz) of best channel overall
  1577. */
  1578. void p2p_set_best_channels(struct p2p_data *p2p, int freq_24, int freq_5,
  1579. int freq_overall);
  1580. /**
  1581. * p2p_set_own_freq_preference - Set own preference for channel
  1582. * @p2p: P2P module context from p2p_init()
  1583. * @freq: Frequency (MHz) of the preferred channel or 0 if no preference
  1584. *
  1585. * This function can be used to set a preference on the operating channel based
  1586. * on frequencies used on the other virtual interfaces that share the same
  1587. * radio. If non-zero, this is used to try to avoid multi-channel concurrency.
  1588. */
  1589. void p2p_set_own_freq_preference(struct p2p_data *p2p, int freq);
  1590. const u8 * p2p_get_go_neg_peer(struct p2p_data *p2p);
  1591. /**
  1592. * p2p_get_group_num_members - Get number of members in group
  1593. * @group: P2P group context from p2p_group_init()
  1594. * Returns: Number of members in the group
  1595. */
  1596. unsigned int p2p_get_group_num_members(struct p2p_group *group);
  1597. /**
  1598. * p2p_iterate_group_members - Iterate group members
  1599. * @group: P2P group context from p2p_group_init()
  1600. * @next: iteration pointer, must be a pointer to a void * that is set to %NULL
  1601. * on the first call and not modified later
  1602. * Returns: A P2P Device Address for each call and %NULL for no more members
  1603. */
  1604. const u8 * p2p_iterate_group_members(struct p2p_group *group, void **next);
  1605. /**
  1606. * p2p_group_get_dev_addr - Get a P2P Device Address of a client in a group
  1607. * @group: P2P group context from p2p_group_init()
  1608. * @addr: P2P Interface Address of the client
  1609. * Returns: P2P Device Address of the client if found or %NULL if no match
  1610. * found
  1611. */
  1612. const u8 * p2p_group_get_dev_addr(struct p2p_group *group, const u8 *addr);
  1613. /**
  1614. * p2p_group_is_client_connected - Check whether a specific client is connected
  1615. * @group: P2P group context from p2p_group_init()
  1616. * @addr: P2P Device Address of the client
  1617. * Returns: 1 if client is connected or 0 if not
  1618. */
  1619. int p2p_group_is_client_connected(struct p2p_group *group, const u8 *dev_addr);
  1620. /**
  1621. * p2p_group_get_config - Get the group configuration
  1622. * @group: P2P group context from p2p_group_init()
  1623. * Returns: The group configuration pointer
  1624. */
  1625. const struct p2p_group_config * p2p_group_get_config(struct p2p_group *group);
  1626. /**
  1627. * p2p_loop_on_all_groups - Run the given callback on all groups
  1628. * @p2p: P2P module context from p2p_init()
  1629. * @group_callback: The callback function pointer
  1630. * @user_data: Some user data pointer which can be %NULL
  1631. *
  1632. * The group_callback function can stop the iteration by returning 0.
  1633. */
  1634. void p2p_loop_on_all_groups(struct p2p_data *p2p,
  1635. int (*group_callback)(struct p2p_group *group,
  1636. void *user_data),
  1637. void *user_data);
  1638. /**
  1639. * p2p_get_peer_found - Get P2P peer info structure of a found peer
  1640. * @p2p: P2P module context from p2p_init()
  1641. * @addr: P2P Device Address of the peer or %NULL to indicate the first peer
  1642. * @next: Whether to select the peer entry following the one indicated by addr
  1643. * Returns: The first P2P peer info available or %NULL if no such peer exists
  1644. */
  1645. const struct p2p_peer_info *
  1646. p2p_get_peer_found(struct p2p_data *p2p, const u8 *addr, int next);
  1647. /**
  1648. * p2p_remove_wps_vendor_extensions - Remove WPS vendor extensions
  1649. * @p2p: P2P module context from p2p_init()
  1650. */
  1651. void p2p_remove_wps_vendor_extensions(struct p2p_data *p2p);
  1652. /**
  1653. * p2p_add_wps_vendor_extension - Add a WPS vendor extension
  1654. * @p2p: P2P module context from p2p_init()
  1655. * @vendor_ext: The vendor extensions to add
  1656. * Returns: 0 on success, -1 on failure
  1657. *
  1658. * The wpabuf structures in the array are owned by the P2P
  1659. * module after this call.
  1660. */
  1661. int p2p_add_wps_vendor_extension(struct p2p_data *p2p,
  1662. const struct wpabuf *vendor_ext);
  1663. /**
  1664. * p2p_set_oper_channel - Set the P2P operating channel
  1665. * @p2p: P2P module context from p2p_init()
  1666. * @op_reg_class: Operating regulatory class to set
  1667. * @op_channel: operating channel to set
  1668. * @cfg_op_channel : Whether op_channel is hardcoded in configuration
  1669. * Returns: 0 on success, -1 on failure
  1670. */
  1671. int p2p_set_oper_channel(struct p2p_data *p2p, u8 op_reg_class, u8 op_channel,
  1672. int cfg_op_channel);
  1673. /**
  1674. * p2p_set_pref_chan - Set P2P preferred channel list
  1675. * @p2p: P2P module context from p2p_init()
  1676. * @num_pref_chan: Number of entries in pref_chan list
  1677. * @pref_chan: Preferred channels or %NULL to remove preferences
  1678. * Returns: 0 on success, -1 on failure
  1679. */
  1680. int p2p_set_pref_chan(struct p2p_data *p2p, unsigned int num_pref_chan,
  1681. const struct p2p_channel *pref_chan);
  1682. /**
  1683. * p2p_set_no_go_freq - Set no GO channel ranges
  1684. * @p2p: P2P module context from p2p_init()
  1685. * @list: Channel ranges or %NULL to remove restriction
  1686. * Returns: 0 on success, -1 on failure
  1687. */
  1688. int p2p_set_no_go_freq(struct p2p_data *p2p,
  1689. const struct wpa_freq_range_list *list);
  1690. /**
  1691. * p2p_in_progress - Check whether a P2P operation is progress
  1692. * @p2p: P2P module context from p2p_init()
  1693. * Returns: 0 if P2P module is idle or 1 if an operation is in progress
  1694. */
  1695. int p2p_in_progress(struct p2p_data *p2p);
  1696. const char * p2p_wps_method_text(enum p2p_wps_method method);
  1697. /**
  1698. * p2p_set_config_timeout - Set local config timeouts
  1699. * @p2p: P2P module context from p2p_init()
  1700. * @go_timeout: Time in 10 ms units it takes to start the GO mode
  1701. * @client_timeout: Time in 10 ms units it takes to start the client mode
  1702. */
  1703. void p2p_set_config_timeout(struct p2p_data *p2p, u8 go_timeout,
  1704. u8 client_timeout);
  1705. int p2p_set_wfd_ie_beacon(struct p2p_data *p2p, struct wpabuf *ie);
  1706. int p2p_set_wfd_ie_probe_req(struct p2p_data *p2p, struct wpabuf *ie);
  1707. int p2p_set_wfd_ie_probe_resp(struct p2p_data *p2p, struct wpabuf *ie);
  1708. int p2p_set_wfd_ie_assoc_req(struct p2p_data *p2p, struct wpabuf *ie);
  1709. int p2p_set_wfd_ie_invitation(struct p2p_data *p2p, struct wpabuf *ie);
  1710. int p2p_set_wfd_ie_prov_disc_req(struct p2p_data *p2p, struct wpabuf *ie);
  1711. int p2p_set_wfd_ie_prov_disc_resp(struct p2p_data *p2p, struct wpabuf *ie);
  1712. int p2p_set_wfd_ie_go_neg(struct p2p_data *p2p, struct wpabuf *ie);
  1713. int p2p_set_wfd_dev_info(struct p2p_data *p2p, const struct wpabuf *elem);
  1714. int p2p_set_wfd_assoc_bssid(struct p2p_data *p2p, const struct wpabuf *elem);
  1715. int p2p_set_wfd_coupled_sink_info(struct p2p_data *p2p,
  1716. const struct wpabuf *elem);
  1717. struct wpabuf * wifi_display_encaps(struct wpabuf *subelems);
  1718. /**
  1719. * p2p_set_disc_int - Set min/max discoverable interval for p2p_find
  1720. * @p2p: P2P module context from p2p_init()
  1721. * @min_disc_int: minDiscoverableInterval (in units of 100 TU); default 1
  1722. * @max_disc_int: maxDiscoverableInterval (in units of 100 TU); default 3
  1723. * @max_disc_tu: Maximum number of TUs (1.024 ms) for discoverable interval; or
  1724. * -1 not to limit
  1725. * Returns: 0 on success, or -1 on failure
  1726. *
  1727. * This function can be used to configure minDiscoverableInterval and
  1728. * maxDiscoverableInterval parameters for the Listen state during device
  1729. * discovery (p2p_find). A random number of 100 TU units is picked for each
  1730. * Listen state iteration from [min_disc_int,max_disc_int] range.
  1731. *
  1732. * max_disc_tu can be used to futher limit the discoverable duration. However,
  1733. * it should be noted that use of this parameter is not recommended since it
  1734. * would not be compliant with the P2P specification.
  1735. */
  1736. int p2p_set_disc_int(struct p2p_data *p2p, int min_disc_int, int max_disc_int,
  1737. int max_disc_tu);
  1738. /**
  1739. * p2p_get_state_txt - Get current P2P state for debug purposes
  1740. * @p2p: P2P module context from p2p_init()
  1741. * Returns: Name of the current P2P module state
  1742. *
  1743. * It should be noted that the P2P module state names are internal information
  1744. * and subject to change at any point, i.e., this information should be used
  1745. * mainly for debugging purposes.
  1746. */
  1747. const char * p2p_get_state_txt(struct p2p_data *p2p);
  1748. struct wpabuf * p2p_build_nfc_handover_req(struct p2p_data *p2p,
  1749. int client_freq,
  1750. const u8 *go_dev_addr,
  1751. const u8 *ssid, size_t ssid_len);
  1752. struct wpabuf * p2p_build_nfc_handover_sel(struct p2p_data *p2p,
  1753. int client_freq,
  1754. const u8 *go_dev_addr,
  1755. const u8 *ssid, size_t ssid_len);
  1756. struct p2p_nfc_params {
  1757. int sel;
  1758. const u8 *wsc_attr;
  1759. size_t wsc_len;
  1760. const u8 *p2p_attr;
  1761. size_t p2p_len;
  1762. enum {
  1763. NO_ACTION, JOIN_GROUP, AUTH_JOIN, INIT_GO_NEG, RESP_GO_NEG,
  1764. BOTH_GO, PEER_CLIENT
  1765. } next_step;
  1766. struct p2p_peer_info *peer;
  1767. u8 oob_dev_pw[WPS_OOB_PUBKEY_HASH_LEN + 2 +
  1768. WPS_OOB_DEVICE_PASSWORD_LEN];
  1769. size_t oob_dev_pw_len;
  1770. int go_freq;
  1771. u8 go_dev_addr[ETH_ALEN];
  1772. u8 go_ssid[32];
  1773. size_t go_ssid_len;
  1774. };
  1775. int p2p_process_nfc_connection_handover(struct p2p_data *p2p,
  1776. struct p2p_nfc_params *params);
  1777. void p2p_set_authorized_oob_dev_pw_id(struct p2p_data *p2p, u16 dev_pw_id,
  1778. int go_intent,
  1779. const u8 *own_interface_addr);
  1780. int p2p_set_passphrase_len(struct p2p_data *p2p, unsigned int len);
  1781. void p2p_loop_on_known_peers(struct p2p_data *p2p,
  1782. void (*peer_callback)(struct p2p_peer_info *peer,
  1783. void *user_data),
  1784. void *user_data);
  1785. void p2p_set_vendor_elems(struct p2p_data *p2p, struct wpabuf **vendor_elem);
  1786. #endif /* P2P_H */