p2p.h 69 KB

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