xref: /aosp_15_r20/external/wpa_supplicant_8/src/common/nan_de.h (revision 03f9172ca588f91df233974f4258bab95191f931)
1 /*
2  * NAN Discovery Engine
3  * Copyright (c) 2024, Qualcomm Innovation Center, Inc.
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 
9 #ifndef NAN_DE_H
10 #define NAN_DE_H
11 
12 #include "nan.h"
13 
14 /* Maximum number of active local publish and subscribe instances */
15 #ifndef NAN_DE_MAX_SERVICE
16 #define NAN_DE_MAX_SERVICE 20
17 #endif /* NAN_DE_MAX_SERVICE */
18 
19 struct nan_de;
20 
21 enum nan_de_reason {
22 	NAN_DE_REASON_TIMEOUT,
23 	NAN_DE_REASON_USER_REQUEST,
24 	NAN_DE_REASON_FAILURE,
25 };
26 
27 struct nan_callbacks {
28 	void *ctx;
29 
30 	int (*tx)(void *ctx, unsigned int freq, unsigned int wait_time,
31 		  const u8 *dst, const u8 *src, const u8 *bssid,
32 		  const struct wpabuf *buf);
33 	int (*listen)(void *ctx, unsigned int freq, unsigned int duration);
34 
35 	/* NAN DE Events */
36 	void (*discovery_result)(void *ctx, int subscribe_id,
37 				 enum nan_service_protocol_type srv_proto_type,
38 				 const u8 *ssi, size_t ssi_len,
39 				 int peer_publish_id,
40 				 const u8 *peer_addr, bool fsd, bool fsd_gas);
41 
42 	void (*replied)(void *ctx, int publish_id, const u8 *peer_addr,
43 			int peer_subscribe_id,
44 			enum nan_service_protocol_type srv_proto_type,
45 			const u8 *ssi, size_t ssi_len);
46 
47 	void (*publish_terminated)(void *ctx, int publish_id,
48 				    enum nan_de_reason reason);
49 
50 	void (*subscribe_terminated)(void *ctx, int subscribe_id,
51 				     enum nan_de_reason reason);
52 
53 	void (*receive)(void *ctx, int id, int peer_instance_id,
54 			const u8 *ssi, size_t ssi_len,
55 			const u8 *peer_addr);
56 
57 	void (*process_p2p_usd_elems)(void *ctx, const u8 *buf,
58 				      u16 buf_len, const u8 *peer_addr,
59 				      unsigned int freq);
60 };
61 
62 struct nan_de * nan_de_init(const u8 *nmi, bool offload, bool ap,
63 			    const struct nan_callbacks *cb);
64 void nan_de_flush(struct nan_de *de);
65 void nan_de_deinit(struct nan_de *de);
66 
67 void nan_de_listen_started(struct nan_de *de, unsigned int freq,
68 			   unsigned int duration);
69 void nan_de_listen_ended(struct nan_de *de, unsigned int freq);
70 void nan_de_tx_status(struct nan_de *de, unsigned int freq, const u8 *dst);
71 void nan_de_tx_wait_ended(struct nan_de *de);
72 
73 void nan_de_rx_sdf(struct nan_de *de, const u8 *peer_addr, unsigned int freq,
74 		   const u8 *buf, size_t len);
75 const u8 * nan_de_get_service_id(struct nan_de *de, int id);
76 
77 struct nan_publish_params {
78 	/* configuration_parameters */
79 
80 	/* Publish type */
81 	bool unsolicited;
82 	bool solicited;
83 
84 	/* Solicited transmission type */
85 	bool solicited_multicast;
86 
87 	/* Time to live (in seconds); 0 = one TX only */
88 	unsigned int ttl;
89 
90 	/* Event conditions */
91 	bool disable_events;
92 
93 	/* Further Service Discovery flag */
94 	bool fsd;
95 
96 	/* Further Service Discovery function */
97 	bool fsd_gas;
98 
99 	/* Default frequency (defaultPublishChannel) */
100 	unsigned int freq;
101 
102 	/* Multi-channel frequencies (publishChannelList) */
103 	const int *freq_list;
104 
105 	/* Announcement period in ms; 0 = use default */
106 	unsigned int announcement_period;
107 };
108 
109 /* Returns -1 on failure or >0 publish_id */
110 int nan_de_publish(struct nan_de *de, const char *service_name,
111 		   enum nan_service_protocol_type srv_proto_type,
112 		   const struct wpabuf *ssi, const struct wpabuf *elems,
113 		   struct nan_publish_params *params, bool p2p);
114 
115 void nan_de_cancel_publish(struct nan_de *de, int publish_id);
116 
117 int nan_de_update_publish(struct nan_de *de, int publish_id,
118 			  const struct wpabuf *ssi);
119 
120 struct nan_subscribe_params {
121 	/* configuration_parameters */
122 
123 	/* Subscribe type */
124 	bool active;
125 
126 	/* Time to live (in seconds); 0 = until first result */
127 	unsigned int ttl;
128 
129 	/* Selected frequency */
130 	unsigned int freq;
131 
132 	/* Multi-channel frequencies (publishChannelList) */
133 	const int *freq_list;
134 
135 	/* Query period in ms; 0 = use default */
136 	unsigned int query_period;
137 };
138 
139 /* Returns -1 on failure or >0 subscribe_id */
140 int nan_de_subscribe(struct nan_de *de, const char *service_name,
141 		     enum nan_service_protocol_type srv_proto_type,
142 		     const struct wpabuf *ssi, const struct wpabuf *elems,
143 		     struct nan_subscribe_params *params, bool p2p);
144 
145 void nan_de_cancel_subscribe(struct nan_de *de, int subscribe_id);
146 
147 /* handle = publish_id or subscribe_id
148  * req_instance_id = peer publish_id or subscribe_id */
149 int nan_de_transmit(struct nan_de *de, int handle,
150 		    const struct wpabuf *ssi, const struct wpabuf *elems,
151 		    const u8 *peer_addr, u8 req_instance_id);
152 
153 #endif /* NAN_DE_H */
154