Home | History | Annotate | Line # | Download | only in common
      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 
     58 struct nan_de * nan_de_init(const u8 *nmi, bool ap,
     59 			    const struct nan_callbacks *cb);
     60 void nan_de_flush(struct nan_de *de);
     61 void nan_de_deinit(struct nan_de *de);
     62 
     63 void nan_de_listen_started(struct nan_de *de, unsigned int freq,
     64 			   unsigned int duration);
     65 void nan_de_listen_ended(struct nan_de *de, unsigned int freq);
     66 void nan_de_tx_status(struct nan_de *de, unsigned int freq, const u8 *dst);
     67 void nan_de_tx_wait_ended(struct nan_de *de);
     68 
     69 void nan_de_rx_sdf(struct nan_de *de, const u8 *peer_addr, unsigned int freq,
     70 		   const u8 *buf, size_t len);
     71 
     72 struct nan_publish_params {
     73 	/* configuration_parameters */
     74 
     75 	/* Publish type */
     76 	bool unsolicited;
     77 	bool solicited;
     78 
     79 	/* Solicited transmission type */
     80 	bool solicited_multicast;
     81 
     82 	/* Time to live (in seconds); 0 = one TX only */
     83 	unsigned int ttl;
     84 
     85 	/* Event conditions */
     86 	bool disable_events;
     87 
     88 	/* Further Service Discovery flag */
     89 	bool fsd;
     90 
     91 	/* Further Service Discovery function */
     92 	bool fsd_gas;
     93 
     94 	/* Default frequency (defaultPublishChannel) */
     95 	unsigned int freq;
     96 
     97 	/* Multi-channel frequencies (publishChannelList) */
     98 	const int *freq_list;
     99 
    100 	/* Announcement period in ms; 0 = use default */
    101 	unsigned int announcement_period;
    102 };
    103 
    104 /* Returns -1 on failure or >0 publish_id */
    105 int nan_de_publish(struct nan_de *de, const char *service_name,
    106 		   enum nan_service_protocol_type srv_proto_type,
    107 		   const struct wpabuf *ssi, const struct wpabuf *elems,
    108 		   struct nan_publish_params *params);
    109 
    110 void nan_de_cancel_publish(struct nan_de *de, int publish_id);
    111 
    112 int nan_de_update_publish(struct nan_de *de, int publish_id,
    113 			  const struct wpabuf *ssi);
    114 
    115 struct nan_subscribe_params {
    116 	/* configuration_parameters */
    117 
    118 	/* Subscribe type */
    119 	bool active;
    120 
    121 	/* Time to live (in seconds); 0 = until first result */
    122 	unsigned int ttl;
    123 
    124 	/* Selected frequency */
    125 	unsigned int freq;
    126 
    127 	/* Query period in ms; 0 = use default */
    128 	unsigned int query_period;
    129 };
    130 
    131 /* Returns -1 on failure or >0 subscribe_id */
    132 int nan_de_subscribe(struct nan_de *de, const char *service_name,
    133 		     enum nan_service_protocol_type srv_proto_type,
    134 		     const struct wpabuf *ssi, const struct wpabuf *elems,
    135 		     struct nan_subscribe_params *params);
    136 
    137 void nan_de_cancel_subscribe(struct nan_de *de, int subscribe_id);
    138 
    139 /* handle = publish_id or subscribe_id
    140  * req_instance_id = peer publish_id or subscribe_id */
    141 int nan_de_transmit(struct nan_de *de, int handle,
    142 		    const struct wpabuf *ssi, const struct wpabuf *elems,
    143 		    const u8 *peer_addr, u8 req_instance_id);
    144 
    145 #endif /* NAN_DE_H */
    146