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