1 /* 2 * NAN Discovery Engine 3 * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 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_defs.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_discovery_result { 28 int subscribe_id; 29 enum nan_service_protocol_type srv_proto_type; 30 const u8 *ssi; 31 size_t ssi_len; 32 int peer_publish_id; 33 const u8 *peer_addr; 34 bool fsd; 35 bool fsd_gas; 36 bool data_path; 37 bool security_required; 38 const u8 *pmkid_list; 39 unsigned int pmkid_count; 40 const u8 *cipher_suites; 41 unsigned int n_cipher_suites; 42 bool pairing_setup_supp; 43 bool npk_nik_caching_supp; 44 u16 pbm; 45 }; 46 47 struct nan_callbacks { 48 void *ctx; 49 50 int (*tx)(void *ctx, unsigned int freq, unsigned int wait_time, 51 const u8 *dst, const u8 *src, const u8 *bssid, 52 const struct wpabuf *buf); 53 int (*listen)(void *ctx, unsigned int freq, unsigned int duration, 54 const u8 *forced_addr); 55 56 /* NAN DE Events */ 57 void (*discovery_result)(void *ctx, struct nan_discovery_result *res); 58 59 void (*replied)(void *ctx, int publish_id, const u8 *peer_addr, 60 int peer_subscribe_id, 61 enum nan_service_protocol_type srv_proto_type, 62 const u8 *ssi, size_t ssi_len); 63 64 void (*publish_terminated)(void *ctx, int publish_id, 65 enum nan_de_reason reason); 66 67 void (*subscribe_terminated)(void *ctx, int subscribe_id, 68 enum nan_de_reason reason); 69 70 void (*offload_cancel_publish)(void *ctx, int publish_id); 71 void (*offload_cancel_subscribe)(void *ctx, int subscribe_id); 72 73 void (*receive)(void *ctx, int id, int peer_instance_id, 74 const u8 *ssi, size_t ssi_len, 75 const u8 *peer_addr, 76 const u8 *buf, size_t len); 77 78 void (*process_p2p_usd_elems)(void *ctx, const u8 *buf, 79 u16 buf_len, const u8 *peer_addr, 80 unsigned int freq); 81 82 void (*process_pr_usd_elems)(void *ctx, const u8 *buf, 83 u16 buf_len, const u8 *peer_addr, 84 unsigned int freq); 85 void (*add_extra_attrs)(void *ctx, struct wpabuf *buf); 86 bool (*is_peer_paired)(void *ctx, const u8 *addr); 87 void (*transmit_req_status)(void *ctx, u32 cookie, bool ack); 88 }; 89 90 extern const u8 nan_network_id[ETH_ALEN]; 91 extern const u8 p2p_network_id[ETH_ALEN]; 92 93 bool nan_de_is_nan_network_id(const u8 *addr); 94 bool nan_de_is_p2p_network_id(const u8 *addr); 95 struct nan_de * nan_de_init(const u8 *nmi, bool offload, bool ap, 96 unsigned int max_listen, 97 const struct nan_callbacks *cb); 98 void nan_de_flush(struct nan_de *de); 99 void nan_de_deinit(struct nan_de *de); 100 101 void nan_de_listen_started(struct nan_de *de, unsigned int freq, 102 unsigned int duration); 103 void nan_de_listen_ended(struct nan_de *de, unsigned int freq); 104 void nan_de_update_nmi(struct nan_de *de, const u8 *nmi); 105 void nan_de_tx_status(struct nan_de *de, unsigned int freq, const u8 *dst, 106 const u8 *data, size_t data_len, bool ack); 107 void nan_de_tx_wait_ended(struct nan_de *de); 108 109 bool nan_de_rx_sdf(struct nan_de *de, const u8 *peer_addr, const u8 *a3, 110 unsigned int freq, const u8 *buf, size_t len, int rssi); 111 const u8 * nan_de_get_service_id(struct nan_de *de, int id); 112 113 struct nan_publish_params { 114 /* configuration_parameters */ 115 116 /* Publish type */ 117 bool unsolicited; 118 bool solicited; 119 120 /* Solicited transmission type */ 121 bool solicited_multicast; 122 123 /* Time to live (in seconds); 0 = one TX only */ 124 unsigned int ttl; 125 126 /* Event conditions */ 127 bool disable_events; 128 129 /* Further Service Discovery flag */ 130 bool fsd; 131 132 /* Further Service Discovery function */ 133 bool fsd_gas; 134 135 /* Default frequency (defaultPublishChannel) */ 136 unsigned int freq; 137 138 /* Multi-channel frequencies (publishChannelList) */ 139 const int *freq_list; 140 141 /* Announcement period in ms; 0 = use default */ 142 unsigned int announcement_period; 143 144 /* Proximity ranging flag */ 145 bool proximity_ranging; 146 147 /* Synchronized discovery */ 148 bool sync; 149 150 /* 151 * Null-terminated string containing the hex-encoded 152 * representation of the matching filters. 153 */ 154 const char *match_filter_tx; 155 const char *match_filter_rx; 156 157 /* RSSI range limit */ 158 bool close_proximity; 159 160 /* Source MAC address for this service (optional) */ 161 const u8 *forced_addr; 162 163 /* 164 * Pairing Bootstrapping Methods as defined in Wi-Fi Aware spec v4.0, 165 * Table 128 166 */ 167 u16 pbm; 168 169 /* int_array of cipher suites */ 170 const int *cipher_suites_list; 171 172 /* Bitmap of NAN_CS_INFO_CAPA_* */ 173 u8 security_capab; 174 175 /* ND-PMK to use for creating a list of PMKIDs for the service */ 176 const u8 *nd_pmk; 177 178 /* 179 * GTK protection required for group-addressed Data frames transmitted 180 * and received for the service 181 */ 182 bool gtk_required; 183 184 /* Request NAN Data Path */ 185 bool data_path; 186 187 bool security_required; 188 }; 189 190 /* Returns -1 on failure or >0 publish_id */ 191 int nan_de_publish(struct nan_de *de, const char *service_name, 192 enum nan_service_protocol_type srv_proto_type, 193 const struct wpabuf *ssi, const struct wpabuf *elems, 194 struct nan_publish_params *params, bool p2p, 195 const u8 *addr); 196 197 void nan_de_cancel_publish(struct nan_de *de, int publish_id); 198 199 int nan_de_update_publish(struct nan_de *de, int publish_id, 200 const struct wpabuf *ssi); 201 202 int nan_de_unpause_publish(struct nan_de *de, int publish_id, 203 u8 peer_instance_id, const u8 *peer_addr); 204 205 struct nan_subscribe_params { 206 /* configuration_parameters */ 207 208 /* Subscribe type */ 209 bool active; 210 211 /* Time to live (in seconds); 0 = until first result */ 212 unsigned int ttl; 213 214 /* Selected frequency */ 215 unsigned int freq; 216 217 /* Multi-channel frequencies (publishChannelList) */ 218 const int *freq_list; 219 220 /* Query period in ms; 0 = use default */ 221 unsigned int query_period; 222 223 /* Proximity ranging flag */ 224 bool proximity_ranging; 225 226 /* Synchronized discovery */ 227 bool sync; 228 229 /* 230 * Null-terminated string containing the hex-encoded 231 * representation of the matching filters. 232 */ 233 const char *match_filter_tx; 234 const char *match_filter_rx; 235 236 /* Service response filter include flag */ 237 bool srf_include; 238 239 /* Service response filter MAC list */ 240 const char *srf_mac_list; 241 242 /* Bloom filter length in octets. If 0, MAC list is used instead */ 243 u8 srf_bf_len; 244 245 /* Bloom filter index (0-3) */ 246 u8 srf_bf_idx; 247 248 /* RSSI range limit */ 249 bool close_proximity; 250 251 /* Source MAC address for this service (optional) */ 252 const u8 *forced_addr; 253 254 /* 255 * Pairing Bootstrapping Methods as defined in Wi-Fi Aware spec v4.0, 256 * Table 128 257 */ 258 u16 pbm; 259 260 /* 261 * GTK protection required for group-addressed Data frames transmitted 262 * and received for the service 263 */ 264 bool gtk_required; 265 }; 266 267 /* Returns -1 on failure or >0 subscribe_id */ 268 int nan_de_subscribe(struct nan_de *de, const char *service_name, 269 enum nan_service_protocol_type srv_proto_type, 270 const struct wpabuf *ssi, const struct wpabuf *elems, 271 struct nan_subscribe_params *params, bool p2p, 272 const u8 *addr); 273 274 void nan_de_cancel_subscribe(struct nan_de *de, int subscribe_id); 275 276 /* handle = publish_id or subscribe_id 277 * req_instance_id = peer publish_id or subscribe_id */ 278 int nan_de_transmit(struct nan_de *de, int handle, 279 const struct wpabuf *ssi, const struct wpabuf *elems, 280 const u8 *peer_addr, u8 req_instance_id, 281 const struct wpabuf *nan_attrs, u32 *cookie); 282 283 void nan_de_dw_trigger(struct nan_de *de, int freq); 284 void nan_de_set_cluster_id(struct nan_de *de, const u8 *cluster_id); 285 bool nan_de_is_valid_instance_id(struct nan_de *de, int handle, 286 bool publish, u8 *service_id); 287 u16 nan_de_get_service_bootstrap_methods(struct nan_de *de, int handle); 288 bool nan_de_service_supports_csid(struct nan_de *de, int handle, int csid); 289 void nan_de_set_tx_mcast_follow_up_prot(struct nan_de *de, bool prot); 290 int nan_de_get_status(struct nan_de *de, char *buf, size_t buflen); 291 292 int nan_de_stop_listen(struct nan_de *de, int handle); 293 294 struct nan_de_cfg { 295 /* N and M minimal and maximal values */ 296 u32 n_min, n_max; 297 298 /* When not in pause state, stop the DE radio usage for 'suspend' ms 299 * every 'cycle' ms. 300 */ 301 u32 suspend, cycle; 302 }; 303 304 int nan_de_config(struct nan_de *de, struct nan_de_cfg *cfg); 305 306 #endif /* NAN_DE_H */ 307