p2p.h 66 KB

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