5 #include <sys/socket.h>
6 #include <netlink/genl/genl.h>
7 #include <netlink/genl/family.h>
8 #include <netlink/genl/ctrl.h>
9 #include <linux/rtnetlink.h>
10 #include <netpacket/packet.h>
11 #include <linux/filter.h>
12 #include <linux/errqueue.h>
13 #include <linux/pkt_sched.h>
14 #include <netlink/object-api.h>
15 #include <netlink/netlink.h>
16 #include <netlink/socket.h>
17 #include <netlink/handlers.h>
21 #include <utils/Log.h>
25 #include "cpp_bindings.h"
27 #include "nan_common.h"
29 #define SLSI_WIFI_HAL_NAN_VERSION 1
31 class NanCommand
: public WifiCommand
{
32 static NanCallbackHandler callbackEventHandler
;
37 NanCapabilities capabilities
;
38 NanDataCommand datacmd
;
40 void registerNanEvents(void) {
41 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_PUBLISH_TERMINATED
);
42 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_MATCH
);
43 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_MATCH_EXPIRED
);
44 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED
);
45 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_FOLLOWUP
);
46 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_DISCOVERY_ENGINE
);
47 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS
);
48 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_NDP_REQ
);
49 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_NDP_CFM
);
50 registerVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_NDP_END
);
53 void unregisterNanEvents(void) {
54 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_PUBLISH_TERMINATED
);
55 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_MATCH
);
56 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_MATCH_EXPIRED
);
57 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED
);
58 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_FOLLOWUP
);
59 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_DISCOVERY_ENGINE
);
60 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS
);
61 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_NDP_REQ
);
62 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_NDP_CFM
);
63 unregisterVendorHandler(GOOGLE_OUI
, SLSI_NAN_EVENT_NDP_END
);
66 static const u8
*getEventName(int event
) {
68 case SLSI_NAN_EVENT_RESPONSE
:
69 return (const u8
*)"SLSI_NAN_EVENT_RESPONSE";
70 case SLSI_NAN_EVENT_PUBLISH_TERMINATED
:
71 return (const u8
*)"SLSI_NAN_EVENT_PUBLISH_TERMINATED";
72 case SLSI_NAN_EVENT_MATCH
:
73 return (const u8
*)"SLSI_NAN_EVENT_MATCH";
74 case SLSI_NAN_EVENT_MATCH_EXPIRED
:
75 return (const u8
*)"SLSI_NAN_EVENT_MATCH_EXPIRED";
76 case SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED
:
77 return (const u8
*)"SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED";
78 case SLSI_NAN_EVENT_FOLLOWUP
:
79 return (const u8
*)"SLSI_NAN_EVENT_FOLLOWUP";
80 case SLSI_NAN_EVENT_DISCOVERY_ENGINE
:
81 return (const u8
*)"SLSI_NAN_EVENT_DISCOVERY_ENGINE";
82 case SLSI_NAN_EVENT_DISABLED
:
83 return (const u8
*)"SLSI_NAN_EVENT_DISABLED";
84 case SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS
:
85 return (const u8
*)"SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS";
86 case SLSI_NAN_EVENT_NDP_REQ
:
87 return (const u8
*)"SLSI_NAN_EVENT_NDP_REQ";
88 case SLSI_NAN_EVENT_NDP_CFM
:
89 return (const u8
*)"SLSI_NAN_EVENT_NDP_CFM";
90 case SLSI_NAN_EVENT_NDP_END
:
91 return (const u8
*)"SLSI_NAN_EVENT_NDP_END";
93 return (const u8
*)"UNKNOWN event";
95 return (const u8
*)"UNKNOWN event";
98 int processResponse(WifiEvent
&reply
, NanResponseMsg
*response
) {
99 NanCapabilities
*capabilities
= &response
->body
.nan_capabilities
;
100 nlattr
*vendor_data
= reply
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
102 transaction_id id
= 0;
104 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
105 switch(nl_itr
.get_type()) {
106 case NAN_REPLY_ATTR_STATUS_TYPE
:
107 response
->status
= NanStatusType(nl_itr
.get_u32());
109 case NAN_REPLY_ATTR_VALUE
:
110 val
= nl_itr
.get_u32();
112 strncpy(response
->nan_error
, "Lower_layer_error",NAN_ERROR_STR_LEN
);
115 case NAN_REPLY_ATTR_RESPONSE_TYPE
:
116 response
->response_type
= NanResponseType(nl_itr
.get_u32());
118 case NAN_REPLY_ATTR_PUBLISH_SUBSCRIBE_TYPE
:
119 response
->body
.publish_response
.publish_id
= nl_itr
.get_u16();
121 case NAN_REPLY_ATTR_NDP_INSTANCE_ID
:
122 response
->body
.data_request_response
.ndp_instance_id
= nl_itr
.get_u32();
124 case NAN_REPLY_ATTR_CAP_MAX_CONCURRENT_CLUSTER
:
125 capabilities
->max_concurrent_nan_clusters
= nl_itr
.get_u32();
127 case NAN_REPLY_ATTR_CAP_MAX_PUBLISHES
:
128 capabilities
->max_publishes
= nl_itr
.get_u32();
130 case NAN_REPLY_ATTR_CAP_MAX_SUBSCRIBES
:
131 capabilities
->max_subscribes
= nl_itr
.get_u32();
133 case NAN_REPLY_ATTR_CAP_MAX_SERVICE_NAME_LEN
:
134 capabilities
->max_service_name_len
= nl_itr
.get_u32();
136 case NAN_REPLY_ATTR_CAP_MAX_MATCH_FILTER_LEN
:
137 capabilities
->max_match_filter_len
= nl_itr
.get_u32();
139 case NAN_REPLY_ATTR_CAP_MAX_TOTAL_MATCH_FILTER_LEN
:
140 capabilities
->max_total_match_filter_len
= nl_itr
.get_u32();
142 case NAN_REPLY_ATTR_CAP_MAX_SERVICE_SPECIFIC_INFO_LEN
:
143 capabilities
->max_service_specific_info_len
= nl_itr
.get_u32();
145 case NAN_REPLY_ATTR_CAP_MAX_VSA_DATA_LEN
:
146 capabilities
->max_vsa_data_len
= nl_itr
.get_u32();
148 case NAN_REPLY_ATTR_CAP_MAX_MESH_DATA_LEN
:
149 capabilities
->max_mesh_data_len
= nl_itr
.get_u32();
151 case NAN_REPLY_ATTR_CAP_MAX_NDI_INTERFACES
:
152 capabilities
->max_ndi_interfaces
= nl_itr
.get_u32();
154 case NAN_REPLY_ATTR_CAP_MAX_NDP_SESSIONS
:
155 capabilities
->max_ndp_sessions
= nl_itr
.get_u32();
157 case NAN_REPLY_ATTR_CAP_MAX_APP_INFO_LEN
:
158 capabilities
->max_app_info_len
= nl_itr
.get_u32();
161 case NAN_REPLY_ATTR_CAP_MAX_QUEUED_TRANSMIT_FOLLOWUP_MGS
:
162 capabilities
->max_queued_transmit_followup_msgs
= nl_itr
.get_u32();
164 case NAN_REPLY_ATTR_CAP_MAX_NDP_SUPPORTED_BANDS
:
165 capabilities
->ndp_supported_bands
= nl_itr
.get_u32();
167 case NAN_REPLY_ATTR_CAP_MAX_CIPHER_SUITES_SUPPORTED
:
168 capabilities
->cipher_suites_supported
= nl_itr
.get_u32();
170 case NAN_REPLY_ATTR_CAP_MAX_SCID_LEN
:
171 capabilities
->max_scid_len
= nl_itr
.get_u32();
173 case NAN_REPLY_ATTR_CAP_NDP_SECURITY_SUPPORTED
:
174 capabilities
->is_ndp_security_supported
= (bool)nl_itr
.get_u32();
176 case NAN_REPLY_ATTR_CAP_MAX_SDEA_SERVICE_SPECIFIC_INFO_LEN
:
177 capabilities
->max_sdea_service_specific_info_len
= nl_itr
.get_u32();
179 case NAN_REPLY_ATTR_CAP_MAX_SUBSCRIBE_ADDRESS
:
180 capabilities
->max_subscribe_address
= nl_itr
.get_u32();
182 case NAN_REPLY_ATTR_CAP_NDPE_ATTR_SUPPORTED
:
183 capabilities
->ndpe_attr_supported
= nl_itr
.get_u32();
185 case NAN_REPLY_ATTR_HAL_TRANSACTION_ID
:
186 id
= nl_itr
.get_u16();
189 ALOGE("received unknown type(%d) in response", nl_itr
.get_type());
193 this->capabilities
= *capabilities
;
197 int processMatchEvent(WifiEvent
&event
) {
199 memset(&ind
,0,sizeof(NanMatchInd
));
200 int famchan_idx
= 0, disc_idx
= 0;
201 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
203 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
204 switch(nl_itr
.get_type()) {
205 case NAN_EVT_ATTR_MATCH_PUBLISH_SUBSCRIBE_ID
:
206 ind
.publish_subscribe_id
= nl_itr
.get_u16();
208 case NAN_EVT_ATTR_MATCH_REQUESTOR_INSTANCE_ID
:
209 ind
.requestor_instance_id
= nl_itr
.get_u32();
211 case NAN_EVT_ATTR_MATCH_ADDR
:
212 memcpy(ind
.addr
, nl_itr
.get_data(), NAN_MAC_ADDR_LEN
);
214 case NAN_EVT_ATTR_MATCH_SERVICE_SPECIFIC_INFO_LEN
:
215 ind
.service_specific_info_len
= nl_itr
.get_u16();
217 case NAN_EVT_ATTR_MATCH_SERVICE_SPECIFIC_INFO
:
218 memcpy(ind
.service_specific_info
, nl_itr
.get_data(), ind
.service_specific_info_len
);
220 case NAN_EVT_ATTR_MATCH_SDF_MATCH_FILTER_LEN
:
221 ind
.sdf_match_filter_len
= nl_itr
.get_u16();
223 case NAN_EVT_ATTR_MATCH_SDF_MATCH_FILTER
:
224 memcpy(ind
.sdf_match_filter
, nl_itr
.get_data(), ind
.sdf_match_filter_len
);
226 case NAN_EVT_ATTR_MATCH_MATCH_OCCURED_FLAG
:
227 ind
.match_occured_flag
= nl_itr
.get_u8();
229 case NAN_EVT_ATTR_MATCH_OUT_OF_RESOURCE_FLAG
:
230 ind
.out_of_resource_flag
= nl_itr
.get_u8();
232 case NAN_EVT_ATTR_MATCH_RSSI_VALUE
:
233 ind
.rssi_value
= nl_itr
.get_u8();
235 case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_IBSS_SUPPORTED
:
236 ind
.conn_capability
.is_ibss_supported
= nl_itr
.get_u8();
238 case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_WFD_SUPPORTED
:
239 ind
.conn_capability
.is_wfd_supported
= nl_itr
.get_u8();
241 case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_WFDS_SUPPORTED
:
242 ind
.conn_capability
.is_wfds_supported
= nl_itr
.get_u8();
244 case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_TDLS_SUPPORTED
:
245 ind
.conn_capability
.is_tdls_supported
= nl_itr
.get_u8();
247 case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_IS_MESH_SUPPORTED
:
248 ind
.conn_capability
.is_mesh_supported
= nl_itr
.get_u8();
250 case NAN_EVT_ATTR_MATCH_CONN_CAPABILITY_WLAN_INFRA_FIELD
:
251 ind
.conn_capability
.wlan_infra_field
= nl_itr
.get_u8();
253 case NAN_EVT_ATTR_MATCH_NUM_RX_DISCOVERY_ATTR
:
254 ind
.num_rx_discovery_attr
= nl_itr
.get_u8();
256 case NAN_EVT_ATTR_MATCH_RX_DISCOVERY_ATTR
:
257 NanReceivePostDiscovery
*disc_attr
;
258 disc_attr
= &ind
.discovery_attr
[disc_idx
];
260 for(nl_iterator
nl_nested_itr((struct nlattr
*)nl_itr
.get_data()); nl_nested_itr
.has_next(); nl_nested_itr
.next()) {
261 switch(nl_nested_itr
.get_type()) {
262 case NAN_EVT_ATTR_MATCH_DISC_ATTR_TYPE
:
263 disc_attr
->type
= (NanConnectionType
)nl_nested_itr
.get_u8();
265 case NAN_EVT_ATTR_MATCH_DISC_ATTR_ROLE
:
266 disc_attr
->role
= (NanDeviceRole
)nl_nested_itr
.get_u8();
268 case NAN_EVT_ATTR_MATCH_DISC_ATTR_DURATION
:
269 disc_attr
->duration
= (NanAvailDuration
)nl_nested_itr
.get_u8();
271 case NAN_EVT_ATTR_MATCH_DISC_ATTR_AVAIL_INTERVAL_BITMAP
:
272 disc_attr
->avail_interval_bitmap
= nl_nested_itr
.get_u32();
274 case NAN_EVT_ATTR_MATCH_DISC_ATTR_MAPID
:
275 disc_attr
->mapid
= nl_nested_itr
.get_u8();
277 case NAN_EVT_ATTR_MATCH_DISC_ATTR_ADDR
:
278 memcpy(disc_attr
->addr
, nl_nested_itr
.get_data(), NAN_MAC_ADDR_LEN
);
280 case NAN_EVT_ATTR_MATCH_DISC_ATTR_MESH_ID_LEN
:
281 disc_attr
->mesh_id_len
= nl_nested_itr
.get_u8();
283 case NAN_EVT_ATTR_MATCH_DISC_ATTR_MESH_ID
:
284 memcpy(disc_attr
->mesh_id
, nl_nested_itr
.get_data(), disc_attr
->mesh_id_len
);
286 case NAN_EVT_ATTR_MATCH_DISC_ATTR_INFRASTRUCTURE_SSID_LEN
:
287 disc_attr
->infrastructure_ssid_len
= nl_nested_itr
.get_u16();
289 case NAN_EVT_ATTR_MATCH_DISC_ATTR_INFRASTRUCTURE_SSID_VAL
:
290 memcpy(disc_attr
->infrastructure_ssid_val
, nl_nested_itr
.get_data(), disc_attr
->infrastructure_ssid_len
);
295 case NAN_EVT_ATTR_MATCH_NUM_CHANS
:
296 ind
.num_chans
= nl_itr
.get_u8();
298 case NAN_EVT_ATTR_MATCH_FAMCHAN
:
299 NanFurtherAvailabilityChannel
*famchan
;
300 famchan
= &ind
.famchan
[famchan_idx
];
302 for(nl_iterator
nl_nested_itr((struct nlattr
*)nl_itr
.get_data()); nl_nested_itr
.has_next(); nl_nested_itr
.next()) {
303 switch(nl_nested_itr
.get_type()) {
304 case NAN_EVT_ATTR_MATCH_FAM_ENTRY_CONTROL
:
305 famchan
->entry_control
= (NanAvailDuration
)nl_nested_itr
.get_u8();
307 case NAN_EVT_ATTR_MATCH_FAM_CLASS_VAL
:
308 famchan
->class_val
= nl_nested_itr
.get_u8();
310 case NAN_EVT_ATTR_MATCH_FAM_CHANNEL
:
311 famchan
->channel
= nl_nested_itr
.get_u8();
313 case NAN_EVT_ATTR_MATCH_FAM_MAPID
:
314 famchan
->mapid
= nl_nested_itr
.get_u8();
316 case NAN_EVT_ATTR_MATCH_FAM_AVAIL_INTERVAL_BITMAP
:
317 famchan
->avail_interval_bitmap
= nl_nested_itr
.get_u32();
322 case NAN_EVT_ATTR_MATCH_CLUSTER_ATTRIBUTE_LEN
:
323 ind
.cluster_attribute_len
= nl_itr
.get_u8();
325 case NAN_EVT_ATTR_MATCH_CLUSTER_ATTRIBUTE
:
326 memcpy(ind
.cluster_attribute
, nl_itr
.get_data(), ind
.cluster_attribute_len
);
328 case NAN_EVT_ATTR_SDEA_LEN
:
329 ind
.sdea_service_specific_info_len
= nl_itr
.get_u16();
331 case NAN_EVT_ATTR_SDEA
:
332 memcpy(ind
.sdea_service_specific_info
, nl_itr
.get_data(), ind
.sdea_service_specific_info_len
);
334 case NAN_EVT_ATTR_SCID_LEN
:
335 ind
.scid_len
= nl_itr
.get_u32();
337 case NAN_EVT_ATTR_SCID
:
338 memcpy(ind
.scid
, nl_itr
.get_data(), ind
.scid_len
);
340 case NAN_EVT_ATTR_SDEA_PARAM_CONFIG_NAN_DATA_PATH
:
341 ind
.peer_sdea_params
.config_nan_data_path
= nl_itr
.get_u8();
343 case NAN_EVT_ATTR_SDEA_PARAM_NDP_TYPE
:
344 ind
.peer_sdea_params
.ndp_type
= (NdpType
)nl_itr
.get_u8();
346 case NAN_EVT_ATTR_SDEA_PARAM_SECURITY_CONFIG
:
347 ind
.peer_sdea_params
.security_cfg
= (NanDataPathSecurityCfgStatus
)nl_itr
.get_u8();
349 case NAN_EVT_ATTR_SDEA_PARAM_RANGE_STATE
:
350 ind
.peer_sdea_params
.ranging_state
= (NanRangingState
)nl_itr
.get_u8();
352 case NAN_EVT_ATTR_SDEA_PARAM_RANGE_REPORT
:
353 ind
.peer_sdea_params
.range_report
= (NanRangeReport
)nl_itr
.get_u8();
355 case NAN_EVT_ATTR_SDEA_PARAM_QOS_CFG
:
356 ind
.peer_sdea_params
.qos_cfg
= (NanQosCfgStatus
)nl_itr
.get_u8();
358 case NAN_EVT_ATTR_RANGE_MEASUREMENT_MM
:
359 ind
.range_info
.range_measurement_mm
= nl_itr
.get_u32();
361 case NAN_EVT_ATTR_RANGEING_EVENT_TYPE
:
362 ind
.range_info
.ranging_event_type
= nl_itr
.get_u32();
367 if (this->callbackEventHandler
.EventMatch
)
368 this->callbackEventHandler
.EventMatch(&ind
);
372 int processMatchExpiredEvent(WifiEvent
&event
) {
373 NanMatchExpiredInd ind
;
374 memset(&ind
,0,sizeof(NanMatchExpiredInd
));
376 for(nl_iterator
nl_itr((struct nlattr
*)event
.get_vendor_data()); nl_itr
.has_next(); nl_itr
.next()) {
377 switch(nl_itr
.get_type()) {
378 case NAN_EVT_ATTR_MATCH_PUBLISH_SUBSCRIBE_ID
:
379 ind
.publish_subscribe_id
= nl_itr
.get_u16();
381 case NAN_EVT_ATTR_MATCH_REQUESTOR_INSTANCE_ID
:
382 ind
.requestor_instance_id
= nl_itr
.get_u32();
385 ALOGE("processMatchExpiredEvent: unknown attribute(%d)", nl_itr
.get_type());
390 if (callbackEventHandler
.EventMatchExpired
)
391 callbackEventHandler
.EventMatchExpired(&ind
);
396 int processPublishTerminatedEvent(WifiEvent
&event
) {
397 NanPublishTerminatedInd ind
;
398 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
399 memset(&ind
,0,sizeof(ind
));
401 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
402 switch(nl_itr
.get_type()) {
403 case NAN_EVT_ATTR_PUBLISH_ID
:
404 ind
.publish_id
= nl_itr
.get_u16();
406 case NAN_EVT_ATTR_PUBLISH_REASON
:
407 ind
.reason
= (NanStatusType
)nl_itr
.get_u32();
409 case NAN_EVT_ATTR_STATUS
:
412 ALOGE("processPublishTerminatedEvent: unknown attribute(%d)", nl_itr
.get_type());
417 if (callbackEventHandler
.EventPublishTerminated
)
418 callbackEventHandler
.EventPublishTerminated(&ind
);
424 int processSubscribeTerminatedEvent(WifiEvent
&event
) {
425 NanSubscribeTerminatedInd ind
;
426 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
427 memset(&ind
,0,sizeof(ind
));
429 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
430 switch(nl_itr
.get_type()) {
431 case NAN_EVT_ATTR_SUBSCRIBE_ID
:
432 ind
.subscribe_id
= nl_itr
.get_u16();
434 case NAN_EVT_ATTR_SUBSCRIBE_REASON
:
435 ind
.reason
= (NanStatusType
)nl_itr
.get_u32();
437 case NAN_EVT_ATTR_STATUS
:
440 ALOGE("processSubscribeTerminatedEvent: unknown attribute(%d)", nl_itr
.get_type());
445 if (callbackEventHandler
.EventSubscribeTerminated
)
446 callbackEventHandler
.EventSubscribeTerminated(&ind
);
451 int processFollowupEvent(WifiEvent
&event
) {
453 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
454 memset(&ind
,0,sizeof(ind
));
456 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
457 switch(nl_itr
.get_type()) {
458 case NAN_EVT_ATTR_FOLLOWUP_PUBLISH_SUBSCRIBE_ID
:
459 ind
.publish_subscribe_id
= nl_itr
.get_u16();
461 case NAN_EVT_ATTR_FOLLOWUP_REQUESTOR_INSTANCE_ID
:
462 ind
.requestor_instance_id
= nl_itr
.get_u32();
464 case NAN_EVT_ATTR_FOLLOWUP_ADDR
:
465 memcpy(ind
.addr
, nl_itr
.get_data(), NAN_MAC_ADDR_LEN
);
467 case NAN_EVT_ATTR_FOLLOWUP_DW_OR_FAW
:
468 ind
.dw_or_faw
= nl_itr
.get_u8();
470 case NAN_EVT_ATTR_FOLLOWUP_SERVICE_SPECIFIC_INFO_LEN
:
471 ind
.service_specific_info_len
= nl_itr
.get_u16();
473 case NAN_EVT_ATTR_FOLLOWUP_SERVICE_SPECIFIC_INFO
:
474 memcpy(ind
.service_specific_info
, nl_itr
.get_data(), ind
.service_specific_info_len
);
476 case NAN_EVT_ATTR_SDEA_LEN
:
477 ind
.sdea_service_specific_info_len
= nl_itr
.get_u16();
479 case NAN_EVT_ATTR_SDEA
:
480 memcpy(ind
.sdea_service_specific_info
, nl_itr
.get_data(), ind
.sdea_service_specific_info_len
);
483 ALOGE("processNanDisabledEvent: unknown attribute(%d)", nl_itr
.get_type());
488 if (callbackEventHandler
.EventFollowup
)
489 callbackEventHandler
.EventFollowup(&ind
);
494 int processNanDisabledEvent(WifiEvent
&event
) {
496 memset(&ind
,0,sizeof(ind
));
497 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
498 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
499 switch(nl_itr
.get_type()) {
500 case NAN_EVT_ATTR_DISABLED_REASON
:
501 ind
.reason
= (NanStatusType
)nl_itr
.get_u32();
504 ALOGE("processNanDisabledEvent: unknown attribute(%d)", nl_itr
.get_type());
509 if (callbackEventHandler
.EventDisabled
)
510 callbackEventHandler
.EventDisabled(&ind
);
515 int processNanDiscoveryEvent(WifiEvent
&event
) {
516 NanDiscEngEventInd ind
;
517 memset(&ind
,0,sizeof(ind
));
519 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
520 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
521 switch(nl_itr
.get_type()) {
522 case NAN_EVT_ATTR_DISCOVERY_ENGINE_EVT_TYPE
:
523 ind
.event_type
= (NanDiscEngEventType
)nl_itr
.get_u16();
525 case NAN_EVT_ATTR_DISCOVERY_ENGINE_MAC_ADDR
:
526 addr
= (u8
*)nl_itr
.get_data();
528 case NAN_EVT_ATTR_STATUS
:
531 ALOGE("processNanDiscoveryEvent: unknown attribute(%d)", nl_itr
.get_type());
536 if (ind
.event_type
== NAN_EVENT_ID_DISC_MAC_ADDR
)
537 memcpy(ind
.data
.mac_addr
.addr
, addr
, NAN_MAC_ADDR_LEN
);
539 memcpy(ind
.data
.cluster
.addr
, addr
, NAN_MAC_ADDR_LEN
);
541 ALOGE("processNanDiscoveryEvent: No Mac/cluster Address");
544 if (callbackEventHandler
.EventDiscEngEvent
)
545 callbackEventHandler
.EventDiscEngEvent(&ind
);
550 int processNanFollowupStatus(WifiEvent
&event
) {
551 NanTransmitFollowupInd ind
;
552 memset(&ind
,0,sizeof(ind
));
553 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
554 for(nl_iterator
nl_itr(vendor_data
); nl_itr
.has_next(); nl_itr
.next()) {
555 if (nl_itr
.get_type() == NAN_EVT_ATTR_STATUS
) {
556 ind
.reason
= (NanStatusType
)nl_itr
.get_u16();
557 } else if(nl_itr
.get_type() == NAN_EVT_ATTR_HAL_TRANSACTION_ID
) {
558 ind
.id
= nl_itr
.get_u16();
560 ALOGE("processNanFollowupStatus: unknown attribute(%d)", nl_itr
.get_type());
565 if (callbackEventHandler
.EventTransmitFollowup
)
566 callbackEventHandler
.EventTransmitFollowup(&ind
);
571 int putSdeaParams(NanSdeaCtrlParams
*sdea_params
, WifiRequest
*request
)
575 if (!sdea_params
->config_nan_data_path
)
578 result
= request
->put_u8(NAN_REQ_ATTR_SDEA_PARAM_NDP_TYPE
, sdea_params
->ndp_type
);
579 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put SDEA PARAM ndp_type");
581 result
= request
->put_u8(NAN_REQ_ATTR_SDEA_PARAM_SECURITY_CFG
, sdea_params
->security_cfg
);
582 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put SDEA PARAM security_cfg");
584 result
= request
->put_u8(NAN_REQ_ATTR_SDEA_PARAM_RANGING_STATE
, sdea_params
->ranging_state
);
585 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put SDEA PARAM ranging_state");
587 result
= request
->put_u8(NAN_REQ_ATTR_SDEA_PARAM_RANGE_REPORT
, sdea_params
->range_report
);
588 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put SDEA PARAM range_report");
590 result
= request
->put_u8(NAN_REQ_ATTR_SDEA_PARAM_QOS_CFG
, sdea_params
->qos_cfg
);
591 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put SDEA PARAM qos_cfg");
596 int putRangingCfg(NanRangingCfg
*ranging_cfg
, WifiRequest
*request
)
600 result
= request
->put_u32(NAN_REQ_ATTR_RANGING_CFG_INTERVAL
, ranging_cfg
->ranging_interval_msec
);
601 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put Ranging CFG ranging_interval_msec");
603 result
= request
->put_u32(NAN_REQ_ATTR_RANGING_CFG_INDICATION
, ranging_cfg
->config_ranging_indications
);
604 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put Ranging CFG config_ranging_indications");
606 result
= request
->put_u32(NAN_REQ_ATTR_RANGING_CFG_INGRESS_MM
, ranging_cfg
->distance_ingress_mm
);
607 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put Ranging CFG distance_ingress_mm");
609 result
= request
->put_u32(NAN_REQ_ATTR_RANGING_CFG_EGRESS_MM
, ranging_cfg
->distance_egress_mm
);
610 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put Ranging CFG distance_egress_mm");
615 int putRangeResponseCfg(NanRangeResponseCfg
*range_resp_cfg
, WifiRequest
*request
)
619 result
= request
->put_u16(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_PUBLISH_ID
, range_resp_cfg
->publish_id
);
620 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "Failed to put range response cfg::publish_id");
622 result
= request
->put_u32(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_REQUESTOR_ID
, range_resp_cfg
->requestor_instance_id
);
623 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "Failed to put range response cfg::requestor_instance_id");
625 result
= request
->put_addr(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_PEER_ADDR
, range_resp_cfg
->peer_addr
);
626 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "Failed to put range response cfg::peer_addr");
628 result
= request
->put_u16(NAN_REQ_ATTR_RANGE_RESPONSE_CFG_RANGING_RESPONSE
, range_resp_cfg
->ranging_response
);
629 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "Failed to put range response cfg::ranging_response");
635 NanCommand(wifi_interface_handle iface
, int id
)
636 : WifiCommand(iface
, id
), datacmd()
646 memset(&capabilities
, 0, sizeof(capabilities
));
649 int enable(transaction_id id
, NanEnableRequest
*msg
) {
650 ALOGD("NAN enable id:%d", id
);
651 WifiRequest
request(familyId(), ifaceId());
653 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_ENABLE
);
654 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to create WifiRequest");
656 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
658 ALOGE("enable: request.attr_start fail");
659 return WIFI_ERROR_OUT_OF_MEMORY
;
661 /* Valid master pref values are 2-254 */
663 if (msg
->master_pref
< 2)
665 else if (msg
->master_pref
> 254)
668 master_pref
= msg
->master_pref
;
669 result
= request
.put_u8(NAN_REQ_ATTR_MASTER_PREF
, master_pref
);
670 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put master_pref");
672 result
= request
.put_u16(NAN_REQ_ATTR_CLUSTER_LOW
, msg
->cluster_low
);
673 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put cluster_low");
675 result
= request
.put_u16(NAN_REQ_ATTR_CLUSTER_HIGH
, msg
->cluster_high
);
676 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "enable:Failed to put cluster_high");
678 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_support_5g
, msg
->support_5g_val
,
679 NAN_REQ_ATTR_SUPPORT_5G_VAL
, request
, result
, "enable:Failed to put support_5g_val");
681 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_sid_beacon
, msg
->sid_beacon_val
,
682 NAN_REQ_ATTR_SID_BEACON_VAL
, request
, result
, "enable:Failed to put sid_beacon_val");
684 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_2dot4g_rssi_close
, msg
->rssi_close_2dot4g_val
,
685 NAN_REQ_ATTR_RSSI_CLOSE_2G4_VAL
, request
, result
, "enable:Failed to put rssi_close_2dot4g_val");
687 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_2dot4g_rssi_middle
, msg
->rssi_middle_2dot4g_val
,
688 NAN_REQ_ATTR_RSSI_MIDDLE_2G4_VAL
, request
, result
, "enable:Failed to put rssi_middle_2dot4g_val");
690 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_2dot4g_rssi_proximity
, msg
->rssi_proximity_2dot4g_val
,
691 NAN_REQ_ATTR_RSSI_PROXIMITY_2G4_VAL
, request
, result
, "enable:Failed to put rssi_proximity_2dot4g_val");
693 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_hop_count_limit
, msg
->hop_count_limit_val
,
694 NAN_REQ_ATTR_HOP_COUNT_LIMIT_VAL
, request
, result
, "enable:Failed to put hop_count_limit_val");
696 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_2dot4g_support
, msg
->support_2dot4g_val
,
697 NAN_REQ_ATTR_SUPPORT_2G4_VAL
, request
, result
, "enable:Failed to put support_2dot4g_val");
699 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_2dot4g_beacons
, msg
->beacon_2dot4g_val
,
700 NAN_REQ_ATTR_BEACONS_2G4_VAL
, request
, result
, "enable:Failed to put beacon_2dot4g_val");
702 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_2dot4g_sdf
, msg
->sdf_2dot4g_val
,
703 NAN_REQ_ATTR_SDF_2G4_VAL
, request
, result
, "enable:Failed to put sdf_2dot4g_val");
705 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_5g_beacons
, msg
->beacon_5g_val
,
706 NAN_REQ_ATTR_BEACON_5G_VAL
, request
, result
, "enable:Failed to put beacon_5g_val");
708 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_5g_sdf
, msg
->sdf_5g_val
,
709 NAN_REQ_ATTR_SDF_5G_VAL
, request
, result
, "enable:Failed to put sdf_5g_val");
711 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_5g_rssi_close
, msg
->rssi_close_5g_val
,
712 NAN_REQ_ATTR_RSSI_CLOSE_5G_VAL
, request
, result
, "enable:Failed to put rssi_close_5g_val");
714 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_5g_rssi_middle
, msg
->rssi_middle_5g_val
,
715 NAN_REQ_ATTR_RSSI_MIDDLE_5G_VAL
, request
, result
, "enable:Failed to put rssi_middle_5g_val");
717 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_5g_rssi_close_proximity
, msg
->rssi_close_proximity_5g_val
,
718 NAN_REQ_ATTR_RSSI_CLOSE_PROXIMITY_5G_VAL
, request
, result
, "enable:Failed to put rssi_close_proximity_5g_val");
720 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_rssi_window_size
, msg
->rssi_window_size_val
,
721 NAN_REQ_ATTR_RSSI_WINDOW_SIZE_VAL
, request
, result
, "enable:Failed to put rssi_window_size_val");
723 CHECK_CONFIG_PUT_32_RETURN_FAIL(msg
->config_oui
, msg
->oui_val
,
724 NAN_REQ_ATTR_OUI_VAL
, request
, result
, "enable:Failed to put oui_val");
726 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->config_intf_addr
, msg
->intf_addr_val
, NAN_MAC_ADDR_LEN
,
727 NAN_REQ_ATTR_MAC_ADDR_VAL
, request
, result
, "enable:Failed to put intf_addr_val");
729 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->config_cluster_attribute_val
,
730 NAN_REQ_ATTR_CLUSTER_VAL
, request
, result
, "enable:Failed to put config_cluster_attribute_val");
732 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->config_scan_params
, msg
->scan_params_val
.dwell_time
, sizeof(msg
->scan_params_val
.dwell_time
),
733 NAN_REQ_ATTR_SOCIAL_CH_SCAN_DWELL_TIME
, request
, result
, "enable:Failed to put scan_params_val.dwell_time");
735 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->config_scan_params
, msg
->scan_params_val
.scan_period
, sizeof(msg
->scan_params_val
.scan_period
),
736 NAN_REQ_ATTR_SOCIAL_CH_SCAN_PERIOD
, request
, result
, "enable:Failed to put scan_params_val.scan_period");
738 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_random_factor_force
, msg
->random_factor_force_val
,
739 NAN_REQ_ATTR_RANDOM_FACTOR_FORCE_VAL
, request
, result
, "enable:Failed to put random_factor_force_val");
741 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_hop_count_force
, msg
->hop_count_force_val
,
742 NAN_REQ_ATTR_HOP_COUNT_FORCE_VAL
, request
, result
, "enable:Failed to put hop_count_force_val");
744 CHECK_CONFIG_PUT_32_RETURN_FAIL(msg
->config_24g_channel
, msg
->channel_24g_val
,
745 NAN_REQ_ATTR_CHANNEL_2G4_MHZ_VAL
, request
, result
, "enable:Failed to put channel_24g_val");
747 CHECK_CONFIG_PUT_32_RETURN_FAIL(msg
->config_5g_channel
, msg
->channel_5g_val
,
748 NAN_REQ_ATTR_CHANNEL_5G_MHZ_VAL
, request
, result
, "enable:Failed to put channel_5g_val");
750 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_subscribe_sid_beacon
, msg
->subscribe_sid_beacon_val
,
751 NAN_REQ_ATTR_SUBSCRIBE_SID_BEACON_VAL
, request
, result
, "enable:Failed to put subscribe_sid_beacon_val");
753 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_dw
.config_2dot4g_dw_band
, msg
->config_dw
.dw_2dot4g_interval_val
,
754 NAN_REQ_ATTR_DW_2G4_INTERVAL
, request
, result
, "enable:Failed to put dw_2dot4g_interval_val");
756 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_dw
.config_5g_dw_band
, msg
->config_dw
.dw_5g_interval_val
,
757 NAN_REQ_ATTR_DW_5G_INTERVAL
, request
, result
, "enable:Failed to put dw_5g_interval_val");
759 CHECK_CONFIG_PUT_32_RETURN_FAIL(msg
->config_disc_mac_addr_randomization
, msg
->disc_mac_addr_rand_interval_sec
,
760 NAN_REQ_ATTR_DISC_MAC_ADDR_RANDOM_INTERVAL
, request
, result
, "enable:Failed to put disc_mac_addr_rand_interval_sec");
762 CHECK_CONFIG_PUT_32_RETURN_FAIL(msg
->config_ndpe_attr
, msg
->use_ndpe_attr
,
763 NAN_REQ_ATTR_USE_NDPE_ATTR
, request
, result
, "enable:Failed to put use_ndpe_attr");
765 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id
, NAN_REQ_ATTR_HAL_TRANSACTION_ID
, request
, result
, "enable:Failed to put transaction id");
767 request
.attr_end(data
);
770 result
= requestResponse(request
);
771 if (result
!= WIFI_SUCCESS
) {
772 ALOGE("failed to NAN; result = %d", result
);
773 unregisterNanEvents();
775 ALOGD("Start NAN...success");
780 int disable(transaction_id id
)
782 ALOGD("NAN disable id:%d", id
);
783 WifiRequest
request(familyId(), ifaceId());
785 unregisterNanEvents();
787 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_DISABLE
);
788 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "disable:Failed to create WifiRequest");
790 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
792 ALOGE("enable: request.attr_start fail");
793 return WIFI_ERROR_OUT_OF_MEMORY
;
795 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id
, NAN_REQ_ATTR_HAL_TRANSACTION_ID
, request
, result
, "disable:Failed to put transaction id");
796 request
.attr_end(data
);
797 result
= requestResponse(request
);
798 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "disable:Failed to requestResponse");
802 int config(transaction_id id
, NanConfigRequest
*msg
) {
803 ALOGD("NAN config id:%d", id
);
804 WifiRequest
request(familyId(), ifaceId());
806 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_CONFIG
);
807 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "config:Failed to create WifiRequest");
809 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
811 ALOGE("config: request.attr_start fail");
812 return WIFI_ERROR_OUT_OF_MEMORY
;
815 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_sid_beacon
, msg
->sid_beacon
,
816 NAN_REQ_ATTR_SID_BEACON_VAL
, request
, result
, "config:Failed to put sid_beacon");
818 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_rssi_proximity
, msg
->rssi_proximity
,
819 NAN_REQ_ATTR_RSSI_PROXIMITY_2G4_VAL
, request
, result
, "config:Failed to put rssi_proximity");
821 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_master_pref
, msg
->master_pref
,
822 NAN_REQ_ATTR_MASTER_PREF
, request
, result
, "config:Failed to put master_pref");
824 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_5g_rssi_close_proximity
, msg
->rssi_close_proximity_5g_val
,
825 NAN_REQ_ATTR_RSSI_CLOSE_PROXIMITY_5G_VAL
, request
, result
, "config:Failed to put rssi_close_proximity_5g_val");
827 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_rssi_window_size
, msg
->rssi_window_size_val
,
828 NAN_REQ_ATTR_RSSI_WINDOW_SIZE_VAL
, request
, result
, "config:Failed to put rssi_window_size_val");
830 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->config_cluster_attribute_val
,
831 NAN_REQ_ATTR_CLUSTER_VAL
, request
, result
, "config:Failed to put config_cluster_attribute_val");
833 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->config_scan_params
, msg
->scan_params_val
.dwell_time
, sizeof(msg
->scan_params_val
.dwell_time
),
834 NAN_REQ_ATTR_SOCIAL_CH_SCAN_DWELL_TIME
, request
, result
, "config:Failed to put scan_params_val.dwell_time");
836 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->config_scan_params
, msg
->scan_params_val
.scan_period
, sizeof(msg
->scan_params_val
.scan_period
),
837 NAN_REQ_ATTR_SOCIAL_CH_SCAN_PERIOD
, request
, result
, "config:Failed to put scan_params_val.scan_period");
839 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_random_factor_force
, msg
->random_factor_force_val
,
840 NAN_REQ_ATTR_RANDOM_FACTOR_FORCE_VAL
, request
, result
, "config:Failed to put random_factor_force_val");
842 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_hop_count_force
, msg
->hop_count_force_val
,
843 NAN_REQ_ATTR_HOP_COUNT_FORCE_VAL
, request
, result
, "config:Failed to put hop_count_force_val");
845 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.payload_transmit_flag
,
846 NAN_REQ_ATTR_CONN_CAPABILITY_PAYLOAD_TX
, request
, result
, "config:Failed to put payload_transmit_flag");
848 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.is_wfd_supported
,
849 NAN_REQ_ATTR_CONN_CAPABILITY_WFD
, request
, result
, "config:Failed to put is_wfd_supported");
851 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.is_wfds_supported
,
852 NAN_REQ_ATTR_CONN_CAPABILITY_WFDS
, request
, result
, "config:Failed to put is_wfds_supported");
854 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.is_tdls_supported
,
855 NAN_REQ_ATTR_CONN_CAPABILITY_TDLS
, request
, result
, "config:Failed to put is_tdls_supported");
857 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.is_ibss_supported
,
858 NAN_REQ_ATTR_CONN_CAPABILITY_IBSS
, request
, result
, "config:Failed to put is_ibss_supported");
860 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.is_mesh_supported
,
861 NAN_REQ_ATTR_CONN_CAPABILITY_MESH
, request
, result
, "config:Failed to put is_mesh_supported");
863 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_conn_capability
, msg
->conn_capability_val
.wlan_infra_field
,
864 NAN_REQ_ATTR_CONN_CAPABILITY_WLAN_INFRA
, request
, result
, "config:Failed to put wlan_infra_field");
866 if (msg
->num_config_discovery_attr
) {
867 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->num_config_discovery_attr
,
868 NAN_REQ_ATTR_DISCOVERY_ATTR_NUM_ENTRIES
, request
, result
, "config:Failed to put msg->num_config_discovery_attr");
869 for (int i
= 0; i
< msg
->num_config_discovery_attr
; i
++) {
870 nlattr
*nl_disc_attribute
= request
.attr_start(NAN_REQ_ATTR_DISCOVERY_ATTR_VAL
);
871 NanTransmitPostDiscovery
*discovery_attr
= &msg
->discovery_attr_val
[i
];
872 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr
->type
,
873 NAN_REQ_ATTR_CONN_TYPE
, request
, result
, "config:Failed to put discovery_attr->type");
874 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr
->role
,
875 NAN_REQ_ATTR_NAN_ROLE
, request
, result
, "config:Failed to put discovery_attr->role");
876 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr
->transmit_freq
,
877 NAN_REQ_ATTR_TRANSMIT_FREQ
, request
, result
, "config:Failed to put discovery_attr->transmit_freq");
878 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, discovery_attr
->duration
,
879 NAN_REQ_ATTR_AVAILABILITY_DURATION
, request
, result
, "config:Failed to put discovery_attr->duration");
880 CHECK_CONFIG_PUT_32_RETURN_FAIL(1, discovery_attr
->avail_interval_bitmap
,
881 NAN_REQ_ATTR_AVAILABILITY_INTERVAL
, request
, result
, "config:Failed to put discovery_attr->avail_interval_bitmap");
882 CHECK_CONFIG_PUT_RETURN_FAIL(1, discovery_attr
->addr
, NAN_MAC_ADDR_LEN
,
883 NAN_REQ_ATTR_MAC_ADDR_VAL
, request
, result
, "config:Failed to put discovery_attr->addr");
884 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, discovery_attr
->mesh_id_len
,
885 NAN_REQ_ATTR_MESH_ID_LEN
, request
, result
, "config:Failed to put discovery_attr->mesh_id");
886 CHECK_CONFIG_PUT_RETURN_FAIL(discovery_attr
->mesh_id_len
, discovery_attr
->mesh_id
, discovery_attr
->mesh_id_len
,
887 NAN_REQ_ATTR_MESH_ID
, request
, result
, "config:Failed to put discovery_attr->mesh_id");
888 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, discovery_attr
->infrastructure_ssid_len
,
889 NAN_REQ_ATTR_INFRASTRUCTURE_SSID_LEN
, request
, result
, "config:Failed to put discovery_attr->infrastructure_ssid_val");
890 CHECK_CONFIG_PUT_RETURN_FAIL(discovery_attr
->infrastructure_ssid_len
, discovery_attr
->infrastructure_ssid_val
, discovery_attr
->infrastructure_ssid_len
,
891 NAN_REQ_ATTR_INFRASTRUCTURE_SSID
, request
, result
, "config:Failed to put discovery_attr->infrastructure_ssid_val");
892 request
.attr_end(nl_disc_attribute
);
896 if (msg
->config_fam
) {
897 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->fam_val
.numchans
,
898 NAN_REQ_ATTR_FURTHER_AVAIL_NUM_ENTRIES
, request
, result
, "config:Failed to put msg->fam_val.numchans");
899 for (int i
= 0; i
< msg
->fam_val
.numchans
; i
++) {
900 nlattr
*nl_fam_attribute
= request
.attr_start(NAN_REQ_ATTR_FURTHER_AVAIL_VAL
);
901 NanFurtherAvailabilityChannel
*further_avail_chan
= &msg
->fam_val
.famchan
[i
];
902 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan
->entry_control
,
903 NAN_REQ_ATTR_FURTHER_AVAIL_ENTRY_CTRL
, request
, result
, "config:Failed to put further_avail_chan->entry_control");
904 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan
->class_val
,
905 NAN_REQ_ATTR_FURTHER_AVAIL_CHAN_CLASS
, request
, result
, "config:Failed to put further_avail_chan->class_val");
906 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan
->channel
,
907 NAN_REQ_ATTR_FURTHER_AVAIL_CHAN
, request
, result
, "config:Failed to put further_avail_chan->channel");
908 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, further_avail_chan
->mapid
,
909 NAN_REQ_ATTR_FURTHER_AVAIL_CHAN_MAPID
, request
, result
, "config:Failed to put further_avail_chan->mapid");
910 CHECK_CONFIG_PUT_32_RETURN_FAIL(1, further_avail_chan
->avail_interval_bitmap
,
911 NAN_REQ_ATTR_FURTHER_AVAIL_INTERVAL_BITMAP
, request
, result
, "config:Failed to put further_avail_chan->avail_interval_bitmap");
912 request
.attr_end(nl_fam_attribute
);
916 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_subscribe_sid_beacon
, msg
->subscribe_sid_beacon_val
,
917 NAN_REQ_ATTR_SUBSCRIBE_SID_BEACON_VAL
, request
, result
, "config:Failed to put subscribe_sid_beacon_val");
919 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_dw
.config_2dot4g_dw_band
, msg
->config_dw
.dw_2dot4g_interval_val
,
920 NAN_REQ_ATTR_DW_2G4_INTERVAL
, request
, result
, "config:Failed to put dw_2dot4g_interval_val");
922 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_dw
.config_5g_dw_band
, msg
->config_dw
.dw_5g_interval_val
,
923 NAN_REQ_ATTR_DW_5G_INTERVAL
, request
, result
, "config:Failed to put dw_5g_interval_val");
925 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->config_disc_mac_addr_randomization
, msg
->disc_mac_addr_rand_interval_sec
,
926 NAN_REQ_ATTR_DISC_MAC_ADDR_RANDOM_INTERVAL
, request
, result
, "config:Failed to put disc_mac_addr_rand_interval_sec");
928 CHECK_CONFIG_PUT_32_RETURN_FAIL(msg
->config_ndpe_attr
, msg
->use_ndpe_attr
,
929 NAN_REQ_ATTR_USE_NDPE_ATTR
, request
, result
, "config:Failed to put use_ndpe_attr");
931 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id
, NAN_REQ_ATTR_HAL_TRANSACTION_ID
, request
, result
, "config:Failed to put transaction id");
933 request
.attr_end(data
);
934 result
= requestResponse(request
);
935 if (result
!= WIFI_SUCCESS
) {
936 ALOGE("failed to set_config; result = %d", result
);
938 ALOGD("NAN config...success");
943 static int setCallbackHandler(NanCallbackHandler handlers
) {
944 callbackEventHandler
= handlers
;
948 static int getVersion(NanVersion
*version
) {
949 *version
= SLSI_WIFI_HAL_NAN_VERSION
;
953 int publish(transaction_id id
, NanPublishRequest
*msg
) {
954 ALOGD("NAN publish transId:%d publishId:%d publishType:%d", id
, msg
->publish_id
, msg
->publish_type
);
955 WifiRequest
request(familyId(), ifaceId());
957 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_PUBLISH
);
958 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "publish:Failed to create WifiRequest");
960 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
962 ALOGE("publish: request.attr_start fail");
963 return WIFI_ERROR_OUT_OF_MEMORY
;
966 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->publish_id
, msg
->publish_id
,
967 NAN_REQ_ATTR_PUBLISH_ID
, request
, result
, "publish:Failed to put msg->publish_id");
969 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->ttl
, msg
->ttl
,
970 NAN_REQ_ATTR_PUBLISH_TTL
, request
, result
, "publish:Failed to put msg->ttl");
972 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->period
,
973 NAN_REQ_ATTR_PUBLISH_PERIOD
, request
, result
, "publish:Failed to put msg->period");
975 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->publish_type
,
976 NAN_REQ_ATTR_PUBLISH_TYPE
, request
, result
, "publish:Failed to put msg->publish_type");
978 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->tx_type
,
979 NAN_REQ_ATTR_PUBLISH_TX_TYPE
, request
, result
, "publish:Failed to put msg->tx_type");
981 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->publish_count
,
982 NAN_REQ_ATTR_PUBLISH_COUNT
, request
, result
, "publish:Failed to put msg->publish_count");
984 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->service_name_len
, msg
->service_name_len
,
985 NAN_REQ_ATTR_PUBLISH_SERVICE_NAME_LEN
, request
, result
, "publish:Failed to put msg->service_name_len");
987 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->service_name_len
, msg
->service_name
, msg
->service_name_len
,
988 NAN_REQ_ATTR_PUBLISH_SERVICE_NAME
, request
, result
, "publish:Failed to put msg->service_name");
990 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->publish_match_indicator
,
991 NAN_REQ_ATTR_PUBLISH_MATCH_ALGO
, request
, result
, "publish:Failed to put msg->publish_match_indicator");
993 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->service_specific_info_len
, msg
->service_specific_info_len
,
994 NAN_REQ_ATTR_PUBLISH_SERVICE_INFO_LEN
, request
, result
, "publish:Failed to put msg->service_specific_info_len");
996 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->service_specific_info_len
, msg
->service_specific_info
, msg
->service_specific_info_len
,
997 NAN_REQ_ATTR_PUBLISH_SERVICE_INFO
, request
, result
, "publish:Failed to put msg->service_specific_info");
999 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->rx_match_filter_len
, msg
->rx_match_filter_len
,
1000 NAN_REQ_ATTR_PUBLISH_RX_MATCH_FILTER_LEN
, request
, result
, "publish:Failed to put msg->rx_match_filter_len");
1002 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->rx_match_filter_len
, msg
->rx_match_filter
, msg
->rx_match_filter_len
,
1003 NAN_REQ_ATTR_PUBLISH_RX_MATCH_FILTER
, request
, result
, "publish:Failed to put msg->rx_match_filter");
1005 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->tx_match_filter_len
, msg
->tx_match_filter_len
,
1006 NAN_REQ_ATTR_PUBLISH_TX_MATCH_FILTER_LEN
, request
, result
, "publish:Failed to put msg->tx_match_filter_len");
1008 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->tx_match_filter_len
, msg
->tx_match_filter
, msg
->tx_match_filter_len
,
1009 NAN_REQ_ATTR_PUBLISH_TX_MATCH_FILTER
, request
, result
, "publish:Failed to put msg->tx_match_filter");
1011 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->rssi_threshold_flag
,
1012 NAN_REQ_ATTR_PUBLISH_RSSI_THRESHOLD_FLAG
, request
, result
, "publish:Failed to put msg->rssi_threshold_flag");
1014 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->connmap
,
1015 NAN_REQ_ATTR_PUBLISH_CONN_MAP
, request
, result
, "publish:Failed to put msg->connmap");
1017 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->recv_indication_cfg
,
1018 NAN_REQ_ATTR_PUBLISH_RECV_IND_CFG
, request
, result
, "publish:Failed to put msg->recv_indication_cfg");
1020 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->sdea_service_specific_info_len
,
1021 NAN_REQ_ATTR_PUBLISH_SDEA_LEN
, request
, result
, "publish:Failed to put msg->sdea_service_specific_info_len");
1023 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->sdea_service_specific_info_len
, msg
->sdea_service_specific_info
, msg
->sdea_service_specific_info_len
,
1024 NAN_REQ_ATTR_PUBLISH_SDEA
, request
, result
, "publish:Failed to put msg->sdea_service_specific_info");
1026 result
= request
.put_u8(NAN_REQ_ATTR_RANGING_AUTO_RESPONSE
, msg
->ranging_auto_response
);
1027 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "publish:Failed to put ranging_auto_response");
1029 result
= putSdeaParams(&msg
->sdea_params
, &request
);
1032 result
= putRangingCfg(&msg
->ranging_cfg
, &request
);
1035 result
= NanDataCommand::putSecurityInfo(msg
->cipher_type
, &msg
->key_info
, msg
->scid_len
, msg
->scid
, &request
);
1038 result
= putRangeResponseCfg(&msg
->range_response_cfg
, &request
);
1042 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id
, NAN_REQ_ATTR_HAL_TRANSACTION_ID
, request
, result
, "publish:Failed to put transaction id");
1044 request
.attr_end(data
);
1045 result
= requestResponse(request
);
1046 if (result
!= WIFI_SUCCESS
) {
1047 ALOGE("failed to publish; result = %d", result
);
1049 ALOGD("NAN publish...success");
1054 int publishCancel(transaction_id id
, NanPublishCancelRequest
*msg
) {
1055 ALOGD("NAN publishCancel transId:%d, publish_id:%d", id
, msg
->publish_id
);
1056 WifiRequest
request(familyId(), ifaceId());
1058 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_PUBLISHCANCEL
);
1059 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "publishCancel:Failed to create WifiRequest");
1061 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
1063 ALOGE("publishCancel: request.attr_start fail");
1064 return WIFI_ERROR_OUT_OF_MEMORY
;
1067 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->publish_id
,
1068 NAN_REQ_ATTR_PUBLISH_ID
, request
, result
, "publishCancel:Failed to put msg->publish_id");
1070 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id
, NAN_REQ_ATTR_HAL_TRANSACTION_ID
, request
, result
, "publishCancel:Failed to put transaction id");
1072 request
.attr_end(data
);
1073 result
= requestResponse(request
);
1074 if (result
!= WIFI_SUCCESS
) {
1075 ALOGE("failed to publishCancel; result = %d", result
);
1077 ALOGD("NAN publishCancel...success");
1083 int subscribe(transaction_id id
, NanSubscribeRequest
*msg
) {
1084 ALOGD("NAN subscribe trans_id:%d subscribe_id:%d subscribetype:%d", id
, msg
->subscribe_id
, msg
->subscribe_type
);
1085 WifiRequest
request(familyId(), ifaceId());
1087 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_SUBSCRIBE
);
1088 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "subscribe:Failed to create WifiRequest");
1090 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
1092 ALOGE("subscribe: request.attr_start fail");
1093 return WIFI_ERROR_OUT_OF_MEMORY
;
1096 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->subscribe_id
, msg
->subscribe_id
,
1097 NAN_REQ_ATTR_SUBSCRIBE_ID
, request
, result
, "subscribe:Failed to put msg->publish_id");
1099 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->ttl
,
1100 NAN_REQ_ATTR_SUBSCRIBE_TTL
, request
, result
, "subscribe:Failed to put msg->ttl");
1102 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->period
,
1103 NAN_REQ_ATTR_SUBSCRIBE_PERIOD
, request
, result
, "subscribe:Failed to put msg->period");
1105 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->subscribe_type
,
1106 NAN_REQ_ATTR_SUBSCRIBE_TYPE
, request
, result
, "subscribe:Failed to put msg->subscribe_type");
1108 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->serviceResponseFilter
,
1109 NAN_REQ_ATTR_SUBSCRIBE_RESP_FILTER_TYPE
, request
, result
, "subscribe:Failed to put msg->serviceResponseFilter");
1111 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->serviceResponseInclude
,
1112 NAN_REQ_ATTR_SUBSCRIBE_RESP_INCLUDE
, request
, result
, "subscribe:Failed to put msg->serviceResponseInclude");
1114 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->useServiceResponseFilter
,
1115 NAN_REQ_ATTR_SUBSCRIBE_USE_RESP_FILTER
, request
, result
, "subscribe:Failed to put msg->useServiceResponseFilter");
1117 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->ssiRequiredForMatchIndication
,
1118 NAN_REQ_ATTR_SUBSCRIBE_SSI_REQUIRED
, request
, result
, "subscribe:Failed to put msg->ssiRequiredForMatchIndication");
1120 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->subscribe_match_indicator
,
1121 NAN_REQ_ATTR_SUBSCRIBE_MATCH_INDICATOR
, request
, result
, "subscribe:Failed to put msg->subscribe_match_indicator");
1123 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->subscribe_count
,
1124 NAN_REQ_ATTR_SUBSCRIBE_COUNT
, request
, result
, "subscribe:Failed to put msg->subscribe_count");
1126 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->service_name_len
, msg
->service_name_len
,
1127 NAN_REQ_ATTR_SUBSCRIBE_SERVICE_NAME_LEN
, request
, result
, "subscribe:Failed to put msg->service_name_len");
1129 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->service_name_len
, msg
->service_name
, msg
->service_name_len
,
1130 NAN_REQ_ATTR_SUBSCRIBE_SERVICE_NAME
, request
, result
, "subscribe:Failed to put msg->service_name");
1132 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->service_specific_info_len
, msg
->service_specific_info_len
,
1133 NAN_REQ_ATTR_SUBSCRIBE_SERVICE_INFO_LEN
, request
, result
, "subscribe:Failed to put msg->service_specific_info_len");
1135 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->service_specific_info_len
, msg
->service_specific_info
, msg
->service_specific_info_len
,
1136 NAN_REQ_ATTR_SUBSCRIBE_SERVICE_INFO
, request
, result
, "subscribe:Failed to put msg->service_specific_info");
1138 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->rx_match_filter_len
, msg
->rx_match_filter_len
,
1139 NAN_REQ_ATTR_SUBSCRIBE_RX_MATCH_FILTER_LEN
, request
, result
, "subscribe:Failed to put msg->rx_match_filter_len");
1141 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->rx_match_filter_len
, msg
->rx_match_filter
, msg
->rx_match_filter_len
,
1142 NAN_REQ_ATTR_SUBSCRIBE_RX_MATCH_FILTER
, request
, result
, "subscribe:Failed to put msg->rx_match_filter");
1144 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->tx_match_filter_len
, msg
->tx_match_filter_len
,
1145 NAN_REQ_ATTR_SUBSCRIBE_TX_MATCH_FILTER_LEN
, request
, result
, "subscribe:Failed to put msg->tx_match_filter_len");
1147 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->tx_match_filter_len
, msg
->tx_match_filter
, msg
->tx_match_filter_len
,
1148 NAN_REQ_ATTR_SUBSCRIBE_TX_MATCH_FILTER
, request
, result
, "subscribe:Failed to put msg->tx_match_filter");
1150 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->rssi_threshold_flag
,
1151 NAN_REQ_ATTR_SUBSCRIBE_RSSI_THRESHOLD_FLAG
, request
, result
, "subscribe:Failed to put msg->rssi_threshold_flag");
1153 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->connmap
,
1154 NAN_REQ_ATTR_SUBSCRIBE_CONN_MAP
, request
, result
, "subscribe:Failed to put msg->connmap");
1156 CHECK_CONFIG_PUT_8_RETURN_FAIL(msg
->num_intf_addr_present
, msg
->num_intf_addr_present
,
1157 NAN_REQ_ATTR_SUBSCRIBE_NUM_INTF_ADDR_PRESENT
, request
, result
, "subscribe:Failed to put msg->num_intf_addr_present");
1159 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->num_intf_addr_present
, msg
->intf_addr
, NAN_MAC_ADDR_LEN
* msg
->num_intf_addr_present
,
1160 NAN_REQ_ATTR_SUBSCRIBE_INTF_ADDR
, request
, result
, "subscribe:Failed to put msg->intf_addr");
1162 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->recv_indication_cfg
,
1163 NAN_REQ_ATTR_SUBSCRIBE_RECV_IND_CFG
, request
, result
, "subscribe:Failed to put msg->recv_indication_cfg");
1165 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->sdea_service_specific_info_len
,
1166 NAN_REQ_ATTR_PUBLISH_SDEA_LEN
, request
, result
, "subscribe:Failed to put msg->sdea_service_specific_info_len");
1168 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->sdea_service_specific_info_len
, msg
->sdea_service_specific_info
, msg
->sdea_service_specific_info_len
,
1169 NAN_REQ_ATTR_PUBLISH_SDEA
, request
, result
, "subscribe:Failed to put msg->sdea_service_specific_info");
1171 result
= request
.put_u8(NAN_REQ_ATTR_RANGING_AUTO_RESPONSE
, msg
->ranging_auto_response
);
1172 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "subscribe:Failed to put ranging_auto_response");
1174 result
= putSdeaParams(&msg
->sdea_params
, &request
);
1177 result
= putRangingCfg(&msg
->ranging_cfg
, &request
);
1180 result
= NanDataCommand::putSecurityInfo(msg
->cipher_type
, &msg
->key_info
, msg
->scid_len
, msg
->scid
, &request
);
1183 result
= putRangeResponseCfg(&msg
->range_response_cfg
, &request
);
1187 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id
, NAN_REQ_ATTR_HAL_TRANSACTION_ID
, request
, result
, "subscribe:Failed to put transaction id");
1189 request
.attr_end(data
);
1190 result
= requestResponse(request
);
1191 if (result
!= WIFI_SUCCESS
) {
1192 ALOGE("failed to subscribe; result = %d", result
);
1194 ALOGD("NAN subscribe...success");
1200 int subscribeCancel(transaction_id id
, NanSubscribeCancelRequest
*msg
) {
1201 ALOGD("NAN subscribeCancel transId:%d subscribeId:%d", id
, msg
->subscribe_id
);
1202 WifiRequest
request(familyId(), ifaceId());
1204 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_SUBSCRIBECANCEL
);
1205 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "subscribeCancel:Failed to create WifiRequest");
1207 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
1209 ALOGE("subscribeCancel: request.attr_start fail");
1210 return WIFI_ERROR_OUT_OF_MEMORY
;
1213 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->subscribe_id
,
1214 NAN_REQ_ATTR_SUBSCRIBE_ID
, request
, result
, "subscribeCancel:Failed to put msg->subscribe_id");
1216 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id
, NAN_REQ_ATTR_HAL_TRANSACTION_ID
, request
, result
, "subscribeCancel:Failed to put transaction id");
1218 request
.attr_end(data
);
1219 result
= requestResponse(request
);
1220 if (result
!= WIFI_SUCCESS
) {
1221 ALOGE("failed to subscribeCancel; result = %d", result
);
1223 ALOGD("NAN subscribeCancel...success");
1228 int followup(transaction_id id
, NanTransmitFollowupRequest
*msg
) {
1229 ALOGD("NAN followup transid:%d pub/subId:%d reqInstId:%d", id
, msg
->publish_subscribe_id
, msg
->requestor_instance_id
);
1230 WifiRequest
request(familyId(), ifaceId());
1232 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_TXFOLLOWUP
);
1233 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "followup:Failed to create WifiRequest");
1235 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
1237 ALOGE("followup: request.attr_start fail");
1238 return WIFI_ERROR_OUT_OF_MEMORY
;
1241 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->publish_subscribe_id
,
1242 NAN_REQ_ATTR_FOLLOWUP_ID
, request
, result
, "followup:Failed to put msg->publish_subscribe_id");
1244 CHECK_CONFIG_PUT_32_RETURN_FAIL(1, msg
->requestor_instance_id
,
1245 NAN_REQ_ATTR_FOLLOWUP_REQUESTOR_ID
, request
, result
, "followup:Failed to put msg->requestor_instance_id");
1247 CHECK_CONFIG_PUT_RETURN_FAIL(1, msg
->addr
, NAN_MAC_ADDR_LEN
,
1248 NAN_REQ_ATTR_FOLLOWUP_ADDR
, request
, result
, "followup:Failed to put msg->addr");
1250 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->priority
,
1251 NAN_REQ_ATTR_FOLLOWUP_PRIORITY
, request
, result
, "followup:Failed to put msg->priority");
1253 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->dw_or_faw
,
1254 NAN_REQ_ATTR_FOLLOWUP_TX_WINDOW
, request
, result
, "followup:Failed to put msg->dw_or_faw");
1256 CHECK_CONFIG_PUT_16_RETURN_FAIL(msg
->service_specific_info_len
, msg
->service_specific_info_len
,
1257 NAN_REQ_ATTR_FOLLOWUP_SERVICE_NAME_LEN
, request
, result
, "followup:Failed to put msg->service_specific_info_len");
1259 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->service_specific_info_len
, msg
->service_specific_info
, msg
->service_specific_info_len
,
1260 NAN_REQ_ATTR_FOLLOWUP_SERVICE_NAME
, request
, result
, "followup:Failed to put msg->service_specific_info");
1262 CHECK_CONFIG_PUT_8_RETURN_FAIL(1, msg
->recv_indication_cfg
,
1263 NAN_REQ_ATTR_FOLLOWUP_RECV_IND_CFG
, request
, result
, "followup:Failed to put msg->recv_indication_cfg");
1265 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, msg
->sdea_service_specific_info_len
,
1266 NAN_REQ_ATTR_PUBLISH_SDEA_LEN
, request
, result
, "publish:Failed to put msg->sdea_service_specific_info_len");
1268 CHECK_CONFIG_PUT_RETURN_FAIL(msg
->sdea_service_specific_info_len
, msg
->sdea_service_specific_info
, msg
->sdea_service_specific_info_len
,
1269 NAN_REQ_ATTR_PUBLISH_SDEA
, request
, result
, "publish:Failed to put msg->sdea_service_specific_info");
1271 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id
, NAN_REQ_ATTR_HAL_TRANSACTION_ID
, request
, result
, "followup:Failed to put transaction id");
1273 request
.attr_end(data
);
1274 result
= requestResponse(request
);
1275 if (result
!= WIFI_SUCCESS
) {
1276 ALOGE("failed to followup; result = %d", result
);
1278 ALOGD("NAN followup...success");
1284 int getCapabilities(transaction_id id
) {
1285 ALOGD("NAN getCapabilities transId:%d", id
);
1286 WifiRequest
request(familyId(), ifaceId());
1288 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_NAN_CAPABILITIES
);
1289 CHECK_WIFI_STATUS_RETURN_FAIL(result
, "getCapabilities:Failed to create WifiRequest");
1291 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
1293 ALOGE("enable: request.attr_start fail");
1294 return WIFI_ERROR_OUT_OF_MEMORY
;
1296 CHECK_CONFIG_PUT_16_RETURN_FAIL(1, id
, NAN_REQ_ATTR_HAL_TRANSACTION_ID
, request
, result
, "getCapabilities:Failed to put transaction id");
1297 request
.attr_end(data
);
1298 result
= requestResponse(request
);
1299 if (result
!= WIFI_SUCCESS
) {
1300 ALOGE("failed to getCapabilities; result = %d", result
);
1302 ALOGD("NAN getCapabilities...success");
1307 int handleEvent(WifiEvent
&event
) {
1310 if (event
.get_cmd() != NL80211_CMD_VENDOR
) {
1311 ALOGD("NAN %s Ignoring event with cmd = %d", __func__
, event
.get_cmd());
1315 int id
= event
.get_vendor_id();
1316 int subcmd
= event
.get_vendor_subcmd();
1318 ALOGI("NAN %s Id = 0x%x, subcmd = %s(0x%x)", __func__
, id
, getEventName(subcmd
), subcmd
);
1321 case SLSI_NAN_EVENT_MATCH
:
1322 ret
= processMatchEvent(event
);
1324 case SLSI_NAN_EVENT_MATCH_EXPIRED
:
1325 ret
= processMatchExpiredEvent(event
);
1327 case SLSI_NAN_EVENT_PUBLISH_TERMINATED
:
1328 ret
= processPublishTerminatedEvent(event
);
1330 case SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED
:
1331 ret
= processSubscribeTerminatedEvent(event
);
1333 case SLSI_NAN_EVENT_FOLLOWUP
:
1334 ret
= processFollowupEvent(event
);
1336 case SLSI_NAN_EVENT_DISABLED
:
1337 ret
= processNanDisabledEvent(event
);
1339 case SLSI_NAN_EVENT_DISCOVERY_ENGINE
:
1340 ret
= processNanDiscoveryEvent(event
);
1342 case SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS
:
1343 ret
= processNanFollowupStatus(event
);
1346 return datacmd
.handleEvent(event
, callbackEventHandler
);
1352 int handleResponse(WifiEvent
&reply
) {
1353 if (reply
.get_cmd() != NL80211_CMD_VENDOR
) {
1354 ALOGD("NAN %s Ignoring reply with cmd = %d", __func__
, reply
.get_cmd());
1358 NanResponseMsg response
;
1359 memset(&response
, 0, sizeof(response
));
1361 transaction_id id
= processResponse(reply
, &response
);
1365 ALOGD("NAN %s transId:%d status:%d, response:%d", __func__
, id
, response
.status
, response
.response_type
);
1366 if (callbackEventHandler
.NotifyResponse
)
1367 callbackEventHandler
.NotifyResponse(id
, &response
);
1371 int dataPathReq(u16 id
, void *data
, int subcmd
) {
1373 WifiRequest
request(familyId(), ifaceId());
1375 ALOGI("NAN DATA-PATH req subcmd:%s(0x%x) transaction_id:%d", datacmd
.getCmdName(subcmd
), subcmd
, id
);
1377 result
= datacmd
.getDataPathNLMsg(id
, data
, subcmd
, request
);
1378 if (result
!= WIFI_SUCCESS
) {
1381 result
= requestResponse(request
);
1382 if (result
!= WIFI_SUCCESS
) {
1383 ALOGE("NAN DATA-PATH req subcmd:%s(0x%x)...failed(%d)", datacmd
.getCmdName(subcmd
), subcmd
, result
);
1384 unregisterNanEvents();
1386 datacmd
.requestSuccess(id
, data
, subcmd
);
1387 ALOGD("NAN DATA-PATH req subcmd:%s(0x%x)...success", datacmd
.getCmdName(subcmd
), subcmd
);
1393 NanCallbackHandler
NanCommand::callbackEventHandler
;
1395 NanCommand
*nan_get_object(transaction_id id
,
1396 wifi_interface_handle iface
) {
1397 wifi_handle handle
= getWifiHandle(iface
);
1398 NanCommand
*nanRequest
= (NanCommand
*)wifi_get_nan_cmd(handle
);
1400 nanRequest
= new NanCommand(iface
, id
);
1402 ALOGE("Could not alloc NanCommand");
1409 wifi_error
nan_enable_request(transaction_id id
,
1410 wifi_interface_handle iface
,
1411 NanEnableRequest
*msg
) {
1412 wifi_handle handle
= getWifiHandle(iface
);
1415 NanCommand
*nanRequest
= new NanCommand(iface
, id
);
1417 ALOGE("nan_enable_request:: Unable to create NanCommand");
1418 return WIFI_ERROR_OUT_OF_MEMORY
;
1421 wifi_set_nan_cmd(handle
, nanRequest
);
1422 ret
= (wifi_error
)nanRequest
->enable(id
, msg
);
1423 if (ret
!= WIFI_SUCCESS
) {
1424 wifi_reset_nan_cmd(handle
);
1430 /* Disable NAN functionality. */
1431 wifi_error
nan_disable_request(transaction_id id
, wifi_interface_handle iface
) {
1432 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1436 return WIFI_ERROR_OUT_OF_MEMORY
;
1438 ret
= (wifi_error
)nanRequest
->disable(id
);
1439 wifi_reset_nan_cmd(getWifiHandle(iface
));
1444 /* Publish request to advertize a service. */
1445 wifi_error
nan_publish_request(transaction_id id
,
1446 wifi_interface_handle iface
,
1447 NanPublishRequest
*msg
) {
1448 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1450 return WIFI_ERROR_OUT_OF_MEMORY
;
1452 return (wifi_error
)nanRequest
->publish(id
, msg
);
1455 /* Cancel previous publish requests. */
1456 wifi_error
nan_publish_cancel_request(transaction_id id
,
1457 wifi_interface_handle iface
,
1458 NanPublishCancelRequest
*msg
) {
1459 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1461 return WIFI_ERROR_OUT_OF_MEMORY
;
1463 return (wifi_error
)nanRequest
->publishCancel(id
, msg
);
1466 /* Subscribe request to search for a service. */
1467 wifi_error
nan_subscribe_request(transaction_id id
,
1468 wifi_interface_handle iface
,
1469 NanSubscribeRequest
*msg
) {
1470 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1472 return WIFI_ERROR_OUT_OF_MEMORY
;
1474 return (wifi_error
)nanRequest
->subscribe(id
, msg
);
1477 /* Cancel previous subscribe requests. */
1478 wifi_error
nan_subscribe_cancel_request(transaction_id id
,
1479 wifi_interface_handle iface
,
1480 NanSubscribeCancelRequest
*msg
) {
1481 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1483 return WIFI_ERROR_OUT_OF_MEMORY
;
1485 return (wifi_error
)nanRequest
->subscribeCancel(id
, msg
);
1488 /* NAN transmit follow up request. */
1489 wifi_error
nan_transmit_followup_request(transaction_id id
,
1490 wifi_interface_handle iface
,
1491 NanTransmitFollowupRequest
*msg
) {
1492 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1494 return WIFI_ERROR_OUT_OF_MEMORY
;
1496 return (wifi_error
)nanRequest
->followup(id
, msg
);
1499 /* NAN configuration request. */
1500 wifi_error
nan_config_request(transaction_id id
,
1501 wifi_interface_handle iface
,
1502 NanConfigRequest
*msg
) {
1503 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1505 return WIFI_ERROR_OUT_OF_MEMORY
;
1507 return (wifi_error
)nanRequest
->config(id
, msg
);
1510 /* Register NAN callbacks. */
1511 wifi_error
nan_register_handler(wifi_interface_handle iface
,
1512 NanCallbackHandler handlers
) {
1513 return (wifi_error
)NanCommand::setCallbackHandler(handlers
);
1516 /* Get NAN HAL version. */
1517 wifi_error
nan_get_version(wifi_handle handle
,
1518 NanVersion
*version
) {
1519 return (wifi_error
)NanCommand::getVersion(version
);
1522 /* Get NAN capabilities. */
1523 wifi_error
nan_get_capabilities(transaction_id id
,
1524 wifi_interface_handle iface
) {
1525 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1527 return WIFI_ERROR_OUT_OF_MEMORY
;
1529 return (wifi_error
)nanRequest
->getCapabilities(id
);
1532 wifi_error
nan_data_interface_create(transaction_id id
,
1533 wifi_interface_handle iface
,
1535 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1537 return WIFI_ERROR_OUT_OF_MEMORY
;
1539 return (wifi_error
)nanRequest
->dataPathReq(id
, iface_name
,
1540 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_INTERFACE_CREATE
);
1543 wifi_error
nan_data_interface_delete(transaction_id id
,
1544 wifi_interface_handle iface
,
1546 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1548 return WIFI_ERROR_OUT_OF_MEMORY
;
1550 return (wifi_error
)nanRequest
->dataPathReq(id
, iface_name
,
1551 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_INTERFACE_DELETE
);
1555 wifi_error
nan_data_request_initiator(transaction_id id
,
1556 wifi_interface_handle iface
,
1557 NanDataPathInitiatorRequest
* msg
) {
1558 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1560 return WIFI_ERROR_OUT_OF_MEMORY
;
1562 return (wifi_error
)nanRequest
->dataPathReq(id
, msg
,
1563 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_REQUEST_INITIATOR
);
1567 wifi_error
nan_data_indication_response(transaction_id id
,
1568 wifi_interface_handle iface
,
1569 NanDataPathIndicationResponse
* msg
) {
1570 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1572 return WIFI_ERROR_OUT_OF_MEMORY
;
1574 return (wifi_error
)nanRequest
->dataPathReq(id
, msg
,
1575 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_INDICATION_RESPONSE
);
1579 wifi_error
nan_data_end(transaction_id id
,
1580 wifi_interface_handle iface
,
1581 NanDataPathEndRequest
* msg
) {
1582 NanCommand
*nanRequest
= nan_get_object(id
, iface
);
1584 return WIFI_ERROR_OUT_OF_MEMORY
;
1586 return (wifi_error
)nanRequest
->dataPathReq(id
, msg
,
1587 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_END
);